Plugin: Seems library is not importing

We’re writing up a private plugin to generate JTW JOSE encrypted tokens, which we then need to use to call to a payment gateway:

The code is pretty basic:

function(properties, context) {
  const {JWT} = require('jose');

  // retrieve inputs
  const json_string = properties.json_string;
  const secret_key = properties.secret_key;
  const private_key = properties.private_key;
  const public_key = properties.public_key;

  // create JWT token
  const token = JWT.sign(json_string, JWT.parseJwk({
    kty: 'RSA',
    use: 'sig',
    d: private_key,
    e: 'AQAB',
    n: public_key,
  }), {
    algorithm: 'RS256',
    expiresIn: '1h',
    header: {
      typ: 'JWT'
    }
  });

  // return output
  return {jwt_token: token};
}

Dependencies declared below:

{
  "dependencies": {
    "jose": "latest"
  }
}

When running the action we get the following error message:

Workflow error - Plugin action JOSE Encrypt error: TypeError: Cannot read property ‘sign’ of undefined at eval (eval at build_function (/var/task/util/util_harness.js:34:12), :20:21) at eval (eval at build_function (/var/task/util/util_harness.js:34:12), :37:8) at /var/task/plugin_api_v3.js:250:27 at run_fn (/var/task/u.js:550:18)

Since JWT is undefined, it means the library import must have failed or something ? I’d need help troubleshooting please.

jose doesn’t have an export called JWT, so of course is undefined.
are you following some gpt hallucinations?
The documentatiom of the library explains how to use it, you probably want to read it.

1 Like

I didn’t code the javascript part myself, we outsourced it. Let me check this out and thanks for the tip.