GithubHelp home page GithubHelp logo

shubham-kumar-2000 / protocol-registry Goto Github PK

View Code? Open in Web Editor NEW
63.0 63.0 14.0 379 KB

This module allows you to set custom protocol handler for your nodejs app.

License: MIT License

Shell 0.40% JavaScript 87.35% EJS 3.16% Objective-C 2.96% AppleScript 4.63% TypeScript 1.50%
cross-platform hacktoberfest linux macos nodejs npm-module protocol registry windows

protocol-registry's Introduction

Hi ๐Ÿ‘‹, I'm Shubham Kumar

ย  ย  About Me

Coding

Hello, I'm Shubham Kumar, A full stack web developer and ML enthusiast. I am working on Node JS and planning to Dive deep into latest technologies like serverless, Elixir, etc. I am curently working on Open Source. Looking for a time in life to really follow the loop :

while(alive){
    eat();
    code() || travel();
    sleep();
}

๐Ÿ› ๏ธ Languages & Tools:

HTML CSS Javascript Node MongoDB Redis

ReactJS Next.JS GraphQL

C++ Python Java

Git Linux Ubuntu

๐Ÿ“ˆ Github Stats:

Visitor's Count Visitor Count

๐Ÿ“ซ Link Tree:

Shubham-Kumar-2000 ย ย  Shubham-Kumar-2000ย ย  Shubham-Kumar-2000

protocol-registry's People

Contributors

adi-11 avatar dependabot[bot] avatar godbleak avatar mayank1307 avatar san-saha avatar shubham-kumar-2000 avatar simran2337 avatar snyk-bot avatar trimceski avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

protocol-registry's Issues

URL Schema

Hey,

Given the URL: testproto://test/example?var1=hello&var2=world
And parsing the arguments passed to my JS, the below happens...

image

I am looking for clarification as to examples of correctly formatted URLs.
Trying to figure out how I would go about parsing these into commands, and sub command and pass variables into my application via URL query.

Can you clarify the URL schema so I know what my options are please?

Issue when setting another protocol than the demo

On OSX when adding a new protocol (after setting previously another with your code example)

const ProtocolRegistry = require("protocol-registry");

console.log("Registering...");
// Registers the Protocol
ProtocolRegistry.register({
  protocol: "toto", // sets protocol for your command , testproto://**
  command: `/usr/local/bin/node ${path.join(__dirname, "./tester.js")} $_URL_`, // this will be executed with a extra argument %url from which it was initiated
  override: true, // Use this with caution as it will destroy all previous Registrations on this protocol
  terminal: true, // Use this to run your command inside a terminal
  script: false,
  scriptName: 'my-custom-script-name' // Custom script name.
}).then(async () => {
  console.log("Successfully registered");
});

produce

Registering...
/Users/quentinlamamy/dev/cafeine/customProtocol/node_modules/protocol-registry/src/macos/index.js:144
            throw new Error(scriptResult.stderr);
                  ^

Error: .: replacing existing signature
.: replacing existing signature

    at Object.register (/Users/quentinlamamy/dev/cafeine/customProtocol/node_modules/protocol-registry/src/macos/index.js:144:19)

Node.js v20.0.0

Bugs in MacOS

Describe the bug:

There are some bugs in the Mac OS directory.

To Reproduce:

Steps to reproduce the behavior:

  1. Run driver.js

Expected behavior:

To run successfully in macOS.

Absolute Path of Command is Required on MacOS when Terminal Mode is Off

Describe the bug:

On MacOS systems, (as mentioned in the bottom of the README) an absolute path is required to run commands when terminal mode is off.

To Reproduce:

Steps to reproduce the behavior:

  1. Set the command to use a non built-in command, such as "node ${path.join(__dirname, './tester.js')} $_URL_" (See how it uses node?)
  2. Set terminal to false in the configuration.
  3. Register the protocol.
  4. Go to the protocol in a browser.
  5. It will error and say that the command does not exist.

Expected behavior:

It should run the command like a user is doing so.


Falsy terminal option registers invalid command on Windows

Describe the bug:

When on Windows with Node 14 LTS, calling the register function with the terminal option set to false or undefined results in an invalid command being registered โ€“ the problem is in the following line:

(terminal && 'cmd /k ') + command

which produces commands that start with "false" or "undefined". Replacing it with

(terminal ? 'cmd /k ' : '') + command

makes the command work.

To Reproduce:

Step through the usage example with a debugger, pass false for the terminal option:

ProtocolRegistry.register({
    protocol: 'testproto', // sets protocol for your command , testproto://**
    command: `node ${path.join(__dirname, './tester.js')} $_URL_`, // this will be executed with a extra argument %url from which it was initiated
    override: true, // Use this with caution as it will destroy all previous Registrations on this protocol
    terminal: false, // Use this to run your command inside a terminal
    script: false
}).then(async () => {
    console.log('Successfully registered');
});

Expected behavior:

Passing false for the terminal option should register a correct command.

Handling non-zero exit codes from `xdg-mime` incorrectly interprets absence of protocol as an error on KDE

Describe the bug:

When using the package to register custom protocols on a system running KDE, an error is thrown if the protocol isn't already registered. This behaviour stems from the xdg-mime utility's defapp_kde function treating a query for a non-existent protocol as a failure, thus returning an exit code of 4 ("The action failed"). This is then interpreted by protocol-registry as an error condition, even though this behaviour is expected and appropriate when checking for a non-existent protocol.

To Reproduce:

  1. Install and use the protocol-registry package in a Node.js application on a KDE-based system.
  2. Try to register a custom protocol that isn't already registered on the system.
  3. protocol-registry will throw an error, indicating that the xdg-mime query default x-scheme-handler/{protocol} command failed.

Expected behaviour:

protocol-registry should handle the exit code 4 from xdg-mime as an indication that the protocol does not exist, rather than as an error. No error should be thrown when attempting to register a new protocol that does not already have a handler.

Use `os.tmpDir()` and allow numbers on protocol

Hi! ๐Ÿ‘‹

Firstly, thanks for your work on this project! ๐Ÿ™‚

Today I used patch-package to patch [email protected] for the project I'm working on.

Essentially what I need is to allow numbers on protocol and use default OS temp dir instead of the node_moules one. This is much more reliable based on my experience.

Here is the diff that solved my problem:

diff --git a/node_modules/protocol-registry/src/linux/index.js b/node_modules/protocol-registry/src/linux/index.js
index e47f611..20fa07f 100644
--- a/node_modules/protocol-registry/src/linux/index.js
+++ b/node_modules/protocol-registry/src/linux/index.js
@@ -6,6 +6,7 @@ const { preProcessCommands } = require('../utils/processCommand');
 const constants = require('../config/constants');
 const validator = require('../utils/validator');
 const { registerSchema } = require('../validation/common');
+const { tmpdir } = require('os');
 
 /**
  * Checks if the given protocal already exist on not
@@ -72,10 +73,10 @@ const register = async (options, cb) => {
         }
 
         const desktopFileName = `${protocol}.desktop`;
-        const desktopFilePath = join(__dirname, '../../temp', desktopFileName);
+        const desktopFilePath = join(tmpdir(), desktopFileName);
         const desktopTemplate = join(__dirname, './templates', 'desktop.ejs');
         const scriptTemplate = join(__dirname, './templates', 'script.ejs');
-        const scriptFilePath = join(__dirname, '../../temp', 'script.sh');
+        const scriptFilePath = join(tmpdir(), 'script.sh');
 
         command = await preProcessCommands(
             protocol,
diff --git a/node_modules/protocol-registry/src/macos/index.js b/node_modules/protocol-registry/src/macos/index.js
index 1b368c3..3c07345 100644
--- a/node_modules/protocol-registry/src/macos/index.js
+++ b/node_modules/protocol-registry/src/macos/index.js
@@ -77,19 +77,18 @@ const register = async (options, cb) => {
         const plistMutator = join(__dirname, 'plistMutator.js');
 
         const appTemplate = join(__dirname, './templates', 'app.ejs');
-        const appSource = join(__dirname, '../../temp', `app-${protocol}.txt`);
+        const appSource = join(tmpdir(), `app-${protocol}.txt`);
         const appPath = join(homedir, `APP-${protocol}.app`);
 
         const urlAppTemplate = join(__dirname, './templates', 'url-app.ejs');
         const urlAppSource = join(
-            __dirname,
-            '../../temp',
+            tmpdir(),
             `URL-${protocol}.txt`
         );
         const urlAppPath = join(homedir, `URL-${protocol}.app`);
 
         const scriptTemplate = join(__dirname, './templates', 'script.ejs');
-        const scriptFilePath = join(__dirname, '../../temp', 'script.sh');
+        const scriptFilePath = join(__dirname, tmpdir(), 'script.sh');
 
         const appSourceContent = await new Promise((resolve, reject) => {
             ejs.renderFile(
diff --git a/node_modules/protocol-registry/src/validation/common.js b/node_modules/protocol-registry/src/validation/common.js
index f1ab1cc..3a827de 100644
--- a/node_modules/protocol-registry/src/validation/common.js
+++ b/node_modules/protocol-registry/src/validation/common.js
@@ -2,7 +2,7 @@ const Joi = require('joi');
 
 exports.registerSchema = Joi.object({
     protocol: Joi.string()
-        .regex(/^[a-zA-Z]+$/)
+        .regex(/^[a-zA-Z0-9]+$/)
         .required(),
     command: Joi.string().required(),
     override: Joi.boolean(),

This issue body was partially generated by patch-package.

Deregister URL handler

Option to deregister a URL protocol, for people who are creating tools and need to be able to uninstall the app for their clients (including the registry entry). The override is good for development testing different configurations, but I don't see a documented way to remove the URL protocol handler other than deleting from registry.

Deno implementation

Hey, can you give me some tips on converting this for use with Deno? Is this planned for the future?

Reducing complexity for checkIfExist in macOS

  • I checked to make sure that this issue has not already been filed.

Expected Behavior:

To check if default app exists or not using appleScript.

Current Behavior:

It's been checked using a binary app of Objective-C.

Solution:

Reduce the module size by using Apple Script.

CheckIfExist function related support app

Prerequisites:

Please answer the following questions for yourself before submitting an issue. YOU MAY DELETE THE PREREQUISITES SECTION.

  • I checked to make sure that this issue has not already been filed.

Expected Behavior:

There should a xCode app to check if the default app exists for a given protocol.

Current Behavior:

No such app found.

Solution:

To make a xCode app to full-fill the requirements.

MAC documentation is absent.

Prerequisites:

Please answer the following questions for yourself before submitting an issue. YOU MAY DELETE THE PREREQUISITES SECTION.

  • I checked to make sure that this issue has not already been filed.

Expected Behavior:

Repo must contain documentation for registering a protocol in mac.

Current Behavior:

Doesn't contain any documentation regarding registering a protocol in mac.

Solution:

Add the documentation in mac directory inside assets.

Problem with spaces in path to script.sh

Describe the bug:

I'm on linux and the script I run for registering a protocol is on a path with a space in it. I get the following error:

Error: chmod: cannot access '/home/vuenc/Some': No such file or directory
chmod: cannot access 'Folder/node_modules/protocol-registry/temp/script.sh': No such file or directory

    at Object.register (/home/vuenc/Some Folder/node_modules/protocol-registry/src/linux/index.js:93:52)

The problem is that in src/linux/index.js in line 92, const chmod = await shell.exec('chmod +x ' + scriptFilePath);, the path is passed to the shell without escaping spaces.

To Reproduce:

  1. Create a directory "Some Folder" in your home directory and run npm install protocol-registry in it
  2. Create a file registerMyProtocol.js with the contents:
const ProtocolRegistry = require("protocol-registry");

ProtocolRegistry.register({
    protocol: "testprotocol", // sets protocol for your command , testproto://**
    command: "echo $_URL_", // this will be executed with a extra argument %url from which it was initiated
    override: true, // Use this with caution as it will destroy all previous Registrations on this protocol
    terminal: false, // Use this to run your command inside a terminal
    script: false,
})
.catch((e) => {console.log(e)})
  1. Run node registerMyProtocol.js

Remove Shelljs

Describe the bug:

Shelljs prevents proper functioning in electron.

To Reproduce:

Steps to reproduce the behavior:

  1. Go to a electron project.
  2. Import protocol-registry

Note:

  • For this issue we will be removing shelljs as a dependency.

Let us name the wrapper file.

Feature request:

Instead of automatically naming it {protocol}Wrapper.(bat/sh), let us choose a name for it.

Is your feature request related to a problem? Please describe. (optional): No

Describe alternatives you've considered:

I've considered just forking your package to make this change myself, but my application automatically downloads packages from NPM when a new one is required or one goes missing, which would cause issues.

Describe how this feature will be useful to our users:

It wouldn't look bad when you use the feature.


Note:

  • If you want to work on an issue, you should check if it has already been assigned to anyone.

Documentation Issue in readme.md

Describe the bug:

The Documentation had some grammatical errors and some understanding issues through the language of the documentation which caused some problems in understanding the working of the npm module.

To Reproduce:

Steps to reproduce the behavior:

  1. Go to 'readme.md'

Expected behavior:

It was expected to have a clear idea of the working npm module which failed at some places.

Configurable `temp` directory (or support for `pkg`)

Feature request:

I'd like a way to configure the temp directory, because right now it's in node_modules.

Is your feature request related to a problem? Please describe. (optional):

I'm trying to use pkg to create an executable file of my script, and we're getting the following error because pkg's snapshot filesystem doesn't seem to work well with it.

image

Describe the solution you'd like:

Adding a path to the options object would be good.

Describe alternatives you've considered:

Describe how this feature will be useful to our users:

Additional context:


Note:

  • If you want to work on an issue, you should check if it has already been assigned to anyone.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.