Node.js Client TypeError [ERR_INVALID_URL]: Invalid URL

Options
fbi
fbi
Community Member

Hello, I am trying to deploy a 1Password Connect Server via Docker as per your instructions but, I am getting the following error whenever I run the nodejs app code.

Please, could you help me?

P.S.: Regarding the myVaultId shown in the URL below, I am using the vault id of the vault I gave permission to the integration server. I managed to get the vault id via 1Password CLI. it is a string with twenty-six characters.

TypeError [ERR_INVALID_URL]: Invalid URL
    at new NodeError (node:internal/errors:363:5)
    at onParseError (node:internal/url:536:9)
    at new URL (node:internal/url:612:5)
    at RequestAdapter.normalizeURL (D:\Downloads\nodejs\1Password-Secret-Automation\node_modules\@1password\connect\dist\lib\requests.js:56:41)
    at RequestAdapter.<anonymous> (D:\Downloads\nodejs\1Password-Secret-Automation\node_modules\@1password\connect\dist\lib\requests.js:45:53)
    at Generator.next (<anonymous>)
    at D:\Downloads\nodejs\1Password-Secret-Automation\node_modules\@1password\connect\dist\lib\requests.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (D:\Downloads\nodejs\1Password-Secret-Automation\node_modules\@1password\connect\dist\lib\requests.js:4:12)
    at RequestAdapter.sendRequest (D:\Downloads\nodejs\1Password-Secret-Automation\node_modules\@1password\connect\dist\lib\requests.js:39:16) {
  input: 'v1/vaults/myVaultId/items/',
  code: 'ERR_INVALID_URL'"

1Password Version: 7.7.810
Extension Version: Not Provided
OS Version: Microsoft Windows 10.0.19043.1081
Sync Type: Not Provided

Comments

  • David_ag
    edited June 2021
    Options

    Hi @fbi ! That's definitely frustrating, so thank you for reporting this issue.

    It looks like the module isn't able to parse the server URL you provided when initializing the SDK:

    import { OnePasswordConnect } from "@1password/connect";
    
    const op = OnePasswordConnect({
        serverURL: "http://localhost:8080", // this needs to be a valid URL with http:// or https:// 
        token: "my-token"
    });
    

    Could you confirm that the serverURL argument is a valid URL?

    I was able to reproduce the issue with this test script:

    # example.js
    const {OnePasswordConnect} = require("@1password/connect");
    
    const op = OnePasswordConnect({serverURL: "anInvalidUrl", token: "example"});
    
    op.listVaults().then(console.log).catch(console.error);
    # TypeError [ERR_INVALID_URL]: Invalid URL: anInvalidUrl
    
  • fbi
    fbi
    Community Member
    Options

    Hello @David_ag. Thanks for the reply. Apparently, the issue is related to the Microsoft Windows environment. I use the Docker Desktop app on my Windows 10 running Linux containers on my initial try. On this occasion, I received an invalid URL error. Although as soon as I tried the same files on my Mac, everything worked fine. So far, I am happy that I managed to see the vanilla code working, but I need to have it on the Windows environment as this is where the project will be deployed. Please, would you be able to guide me on how to set up the 1Password Secrets Automation on Windows?

  • Could you provide an example of how you're passing the server URL to the OnePasswordConnect function? Are you using environment variables or some other method?

  • fbi
    fbi
    Community Member
    Options

    Yes, I am passing it via a Windows environment variable. In reality, I am passing these variables (OP_CONNECT_HOST, OP_CONNECT_TOKEN, OP_VAULT, SECRET_STRING) as system environment variables.

  • Thanks for the information!

    It sounds like either the Windows environment variable is never set or there's a formatting issue with the environment variable. Have you tried doing a console.log() to print the OP_CONNECT_HOST variable in your script or app before you pass it to the Connect SDK instance?

    The log statement would help isolate whether Node is unable to read the environment variables in Windows or if some other process is modifying the OP_CONNECT_HOST environment variable you're setting.

  • fbi
    fbi
    Community Member
    edited July 2021
    Options

    Hello David_ag. Thanks for the support. I followed your advice, and the script printed the environment variables values correctly before it tries to connect to the SKD instance. However, the same error persists to happen.

    Edit: Apparently, I found the problem related to this code: 'ERR_INVALID_URL'. For the OP_CONNECT_HOST environment variable, I have been using localhost:8080, however, as soon as I added the http:// to the URL, it seems that the error is gone. Sorry for the drama, David_ag

  • Thanks so much for following up and sharing your solution. Please feel free to open an issue in the JS SDK to improve the error messaging in this case.

This discussion has been closed.