New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@descope/node-sdk

Package Overview
Dependencies
Maintainers
4
Versions
319
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@descope/node-sdk - npm Package Compare versions

Comparing version 1.0.4-alpha.4 to 1.0.4-alpha.5

2

dist/cjs/index.cjs.js

@@ -1,2 +0,2 @@

"use strict";var e=require("tslib"),t=require("@descope/core-js-sdk"),i=require("jose"),r=require("node-fetch");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=o(t),n=o(r);const a=(e,t)=>`${e}=${t};`,d=t=>(...i)=>e.__awaiter(void 0,void 0,void 0,(function*(){var e;const r=yield t(...i);let{sessionJwt:o,refreshJwt:s}=r.data,n=a("DS",o);return s?n+=a("DSR",s):(n+=(null===(e=r.response)||void 0===e?void 0:e.headers.get("set-cookie"))||"",s=((e,t)=>{const i=null==e?void 0:e.match(RegExp(`(?:^|;\\s*)${t}=([^;]*)`));return i?i[1]:null})(n,"DSR")),Object.assign(Object.assign({},r),{data:Object.assign(Object.assign({},r.data),{refreshJwt:s,cookies:n})})})),l=(e,t,i)=>{if(!e)return;const r="string"==typeof t?t.split("."):t,o=r.shift()||"";if(0===r.length||"*"===o){const t=t=>{if(!t||"function"!=typeof e[t])throw Error(`cannot wrap value at key "${t.toString()}"`);e[t]=i(e[t])};"*"===o?Object.keys(e).forEach(t):t(o)}else l(e[o],r,i)};globalThis.fetch||(globalThis.fetch=n.default,globalThis.Headers=r.Headers,globalThis.Request=r.Request,globalThis.Response=r.Response);const c=(...t)=>{const r=s.default(...t);var o,n;o=r,n=d,["otp.verify.*","magicLink.verify","magicLink.crossDevice.signUp.*","magicLink.crossDevice.signIn.*","oauth.exchange","saml.exchange","totp.verify","webauthn.signIn.finish","webauthn.signUp.finish","refresh"].forEach((e=>l(o,e,n)));const{projectId:a,logger:c}=t[0],u={};return Object.assign(Object.assign({},r),{getKey(t){return e.__awaiter(this,void 0,void 0,(function*(){if(!(null==t?void 0:t.kid))throw Error("header.kid must not be empty");if(u[t.kid])return u[t.kid];if(Object.assign(u,yield e.__awaiter(void 0,void 0,void 0,(function*(){const t=(yield r.httpClient.get(`keys/${a}`).then((e=>e.json())))||[];return(yield Promise.all(t.map((t=>e.__awaiter(void 0,void 0,void 0,(function*(){return[t.kid,yield i.importJWK(t)]})))))).reduce(((e,[t,i])=>t?Object.assign(Object.assign({},e),{[t.toString()]:i}):e),{})}))),!u[t.kid])throw Error("failed to fetch matching key");return u[t.kid]}))},validateToken(t){return e.__awaiter(this,void 0,void 0,(function*(){return{token:(yield i.jwtVerify(t,this.getKey,{algorithms:["ES384"]})).payload}}))},validateSession(t,i){return e.__awaiter(this,void 0,void 0,(function*(){if(!t)throw Error("session token must not be empty");try{return yield this.validateToken(t)}catch(e){try{return yield this.validateToken(i),(yield this.refresh(i)).data}catch(e){throw null==c||c.error("failed to validate refresh token",e),Error("could not validate tokens")}}}))}})};c.DeliveryMethods=s.default.DeliveryMethods,module.exports=c;
"use strict";var e=require("tslib"),t=require("@descope/core-js-sdk"),i=require("jose"),r=require("node-fetch");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=o(t),n=o(r);const a=(e,t)=>`${e}=${t};`,d=t=>(...i)=>e.__awaiter(void 0,void 0,void 0,(function*(){var e;const r=yield t(...i);if(!r.data)return r;let{sessionJwt:o,refreshJwt:s}=r.data,n=a("DS",o);return s?n+=a("DSR",s):(n+=(null===(e=r.response)||void 0===e?void 0:e.headers.get("set-cookie"))||"",s=((e,t)=>{const i=null==e?void 0:e.match(RegExp(`(?:^|;\\s*)${t}=([^;]*)`));return i?i[1]:null})(n,"DSR")),Object.assign(Object.assign({},r),{data:Object.assign(Object.assign({},r.data),{refreshJwt:s,cookies:n})})})),l=(e,t,i)=>{if(!e)return;const r="string"==typeof t?t.split("."):t,o=r.shift()||"";if(0===r.length||"*"===o){const t=t=>{if(!t||"function"!=typeof e[t])throw Error(`cannot wrap value at key "${t.toString()}"`);e[t]=i(e[t])};"*"===o?Object.keys(e).forEach(t):t(o)}else l(e[o],r,i)};globalThis.fetch||(globalThis.fetch=n.default,globalThis.Headers=r.Headers,globalThis.Request=r.Request,globalThis.Response=r.Response);const c=(...t)=>{const r=s.default(...t);var o,n;o=r,n=d,["otp.verify.*","magicLink.verify","magicLink.crossDevice.signUp.*","magicLink.crossDevice.signIn.*","oauth.exchange","saml.exchange","totp.verify","webauthn.signIn.finish","webauthn.signUp.finish","refresh"].forEach((e=>l(o,e,n)));const{projectId:a,logger:c}=t[0],u={};return Object.assign(Object.assign({},r),{getKey(t){return e.__awaiter(this,void 0,void 0,(function*(){if(!(null==t?void 0:t.kid))throw Error("header.kid must not be empty");if(u[t.kid])return u[t.kid];if(Object.assign(u,yield e.__awaiter(void 0,void 0,void 0,(function*(){const t=(yield r.httpClient.get(`keys/${a}`).then((e=>e.json())))||[];return(yield Promise.all(t.map((t=>e.__awaiter(void 0,void 0,void 0,(function*(){return[t.kid,yield i.importJWK(t)]})))))).reduce(((e,[t,i])=>t?Object.assign(Object.assign({},e),{[t.toString()]:i}):e),{})}))),!u[t.kid])throw Error("failed to fetch matching key");return u[t.kid]}))},validateToken(t){return e.__awaiter(this,void 0,void 0,(function*(){return{token:(yield i.jwtVerify(t,this.getKey,{algorithms:["ES384"]})).payload}}))},validateSession(t,i){return e.__awaiter(this,void 0,void 0,(function*(){if(!t)throw Error("session token must not be empty");try{return yield this.validateToken(t)}catch(e){try{return yield this.validateToken(i),(yield this.refresh(i)).data}catch(e){throw null==c||c.error("failed to validate refresh token",e),Error("could not validate tokens")}}}))}})};c.DeliveryMethods=s.default.DeliveryMethods,module.exports=c;
//# sourceMappingURL=index.cjs.js.map

@@ -1,2 +0,2 @@

import{__awaiter as e}from"tslib";import t from"@descope/core-js-sdk";import{jwtVerify as i,importJWK as o}from"jose";import r,{Headers as s,Request as n,Response as a}from"node-fetch";const d=(e,t)=>`${e}=${t};`,c=t=>(...i)=>e(void 0,void 0,void 0,(function*(){var e;const o=yield t(...i);let{sessionJwt:r,refreshJwt:s}=o.data,n=d("DS",r);return s?n+=d("DSR",s):(n+=(null===(e=o.response)||void 0===e?void 0:e.headers.get("set-cookie"))||"",s=((e,t)=>{const i=null==e?void 0:e.match(RegExp(`(?:^|;\\s*)${t}=([^;]*)`));return i?i[1]:null})(n,"DSR")),Object.assign(Object.assign({},o),{data:Object.assign(Object.assign({},o.data),{refreshJwt:s,cookies:n})})})),l=(e,t,i)=>{if(!e)return;const o="string"==typeof t?t.split("."):t,r=o.shift()||"";if(0===o.length||"*"===r){const t=t=>{if(!t||"function"!=typeof e[t])throw Error(`cannot wrap value at key "${t.toString()}"`);e[t]=i(e[t])};"*"===r?Object.keys(e).forEach(t):t(r)}else l(e[r],o,i)};globalThis.fetch||(globalThis.fetch=r,globalThis.Headers=s,globalThis.Request=n,globalThis.Response=a);const h=(...r)=>{const s=t(...r);var n,a;n=s,a=c,["otp.verify.*","magicLink.verify","magicLink.crossDevice.signUp.*","magicLink.crossDevice.signIn.*","oauth.exchange","saml.exchange","totp.verify","webauthn.signIn.finish","webauthn.signUp.finish","refresh"].forEach((e=>l(n,e,a)));const{projectId:d,logger:h}=r[0],f={};return Object.assign(Object.assign({},s),{getKey(t){return e(this,void 0,void 0,(function*(){if(!(null==t?void 0:t.kid))throw Error("header.kid must not be empty");if(f[t.kid])return f[t.kid];if(Object.assign(f,yield e(void 0,void 0,void 0,(function*(){const t=(yield s.httpClient.get(`keys/${d}`).then((e=>e.json())))||[];return(yield Promise.all(t.map((t=>e(void 0,void 0,void 0,(function*(){return[t.kid,yield o(t)]})))))).reduce(((e,[t,i])=>t?Object.assign(Object.assign({},e),{[t.toString()]:i}):e),{})}))),!f[t.kid])throw Error("failed to fetch matching key");return f[t.kid]}))},validateToken(t){return e(this,void 0,void 0,(function*(){return{token:(yield i(t,this.getKey,{algorithms:["ES384"]})).payload}}))},validateSession(t,i){return e(this,void 0,void 0,(function*(){if(!t)throw Error("session token must not be empty");try{return yield this.validateToken(t)}catch(e){try{return yield this.validateToken(i),(yield this.refresh(i)).data}catch(e){throw null==h||h.error("failed to validate refresh token",e),Error("could not validate tokens")}}}))}})};h.DeliveryMethods=t.DeliveryMethods;export{h as default};
import{__awaiter as e}from"tslib";import t from"@descope/core-js-sdk";import{jwtVerify as i,importJWK as o}from"jose";import r,{Headers as n,Request as s,Response as a}from"node-fetch";const d=(e,t)=>`${e}=${t};`,c=t=>(...i)=>e(void 0,void 0,void 0,(function*(){var e;const o=yield t(...i);if(!o.data)return o;let{sessionJwt:r,refreshJwt:n}=o.data,s=d("DS",r);return n?s+=d("DSR",n):(s+=(null===(e=o.response)||void 0===e?void 0:e.headers.get("set-cookie"))||"",n=((e,t)=>{const i=null==e?void 0:e.match(RegExp(`(?:^|;\\s*)${t}=([^;]*)`));return i?i[1]:null})(s,"DSR")),Object.assign(Object.assign({},o),{data:Object.assign(Object.assign({},o.data),{refreshJwt:n,cookies:s})})})),l=(e,t,i)=>{if(!e)return;const o="string"==typeof t?t.split("."):t,r=o.shift()||"";if(0===o.length||"*"===r){const t=t=>{if(!t||"function"!=typeof e[t])throw Error(`cannot wrap value at key "${t.toString()}"`);e[t]=i(e[t])};"*"===r?Object.keys(e).forEach(t):t(r)}else l(e[r],o,i)};globalThis.fetch||(globalThis.fetch=r,globalThis.Headers=n,globalThis.Request=s,globalThis.Response=a);const h=(...r)=>{const n=t(...r);var s,a;s=n,a=c,["otp.verify.*","magicLink.verify","magicLink.crossDevice.signUp.*","magicLink.crossDevice.signIn.*","oauth.exchange","saml.exchange","totp.verify","webauthn.signIn.finish","webauthn.signUp.finish","refresh"].forEach((e=>l(s,e,a)));const{projectId:d,logger:h}=r[0],f={};return Object.assign(Object.assign({},n),{getKey(t){return e(this,void 0,void 0,(function*(){if(!(null==t?void 0:t.kid))throw Error("header.kid must not be empty");if(f[t.kid])return f[t.kid];if(Object.assign(f,yield e(void 0,void 0,void 0,(function*(){const t=(yield n.httpClient.get(`keys/${d}`).then((e=>e.json())))||[];return(yield Promise.all(t.map((t=>e(void 0,void 0,void 0,(function*(){return[t.kid,yield o(t)]})))))).reduce(((e,[t,i])=>t?Object.assign(Object.assign({},e),{[t.toString()]:i}):e),{})}))),!f[t.kid])throw Error("failed to fetch matching key");return f[t.kid]}))},validateToken(t){return e(this,void 0,void 0,(function*(){return{token:(yield i(t,this.getKey,{algorithms:["ES384"]})).payload}}))},validateSession(t,i){return e(this,void 0,void 0,(function*(){if(!t)throw Error("session token must not be empty");try{return yield this.validateToken(t)}catch(e){try{return yield this.validateToken(i),(yield this.refresh(i)).data}catch(e){throw null==h||h.error("failed to validate refresh token",e),Error("could not validate tokens")}}}))}})};h.DeliveryMethods=t.DeliveryMethods;export{h as default};
//# sourceMappingURL=index.esm.js.map
{
"name": "@descope/node-sdk",
"version": "1.0.4-alpha.4",
"version": "1.0.4-alpha.5",
"description": "Node.js library used to integrate with Descope",

@@ -5,0 +5,0 @@ "typings": "./dist/index.d.ts",

# Descope Node.js SDK
Use the Descope NodeJS SDK for NodeJS/Express to quickly and easily add user authentication to your application or website. If you need more background on how the ExpresSDKs work, [click here](/sdk/index.mdx).
Use the Descope NodeJS SDK for NodeJS/Express to quickly and easily add user authentication to your application or website.

@@ -35,3 +35,3 @@

```
or
or

@@ -109,3 +109,3 @@ ```javascript

```
or
or

@@ -176,3 +176,3 @@ ```javascript

```
or
or

@@ -207,3 +207,3 @@ ```javascript

### 4. Session Validation
### 3. Session Validation

@@ -214,3 +214,3 @@ Session validation checks to see that the visitor to your website or application is who they say they are, by comparing the value in the validation variables against the session data that is already stored.

const out = await descopeClient.validateSession(session_jwt, refresh_jwt);
if (out?.cookies) {
if (out.cookies) {
res.set('Set-Cookie', out.cookies);

@@ -220,2 +220,15 @@ }

### 4. Error handling
Each authentication function may return an error upon authentication failure or bad request. In case of an error, you will recieve an sdk response with `ok` equal to false and the error details are also included, such as the `errorCode` and the `errorDescription`. Needless to say, the `data` will be empty whenever an error occur.
```javascript
const out = await descopeClient.oauth.start.facebook();
if (!out.ok) {
console.log(`an error has occured [code: ${out.errorCode}] with message: "${out.errorDescription}"`)
} else {
...
}
```
## Run the Examples

@@ -240,3 +253,4 @@

1. Run this command in the root of the project to build the examples.
Run the following commands in the root of the project to build and run the examples.
1. Run this to start the ES6 typescript module example

@@ -251,3 +265,3 @@ ```code bash

2. Run a specific example
2. Run this to start the commonjs example

@@ -254,0 +268,0 @@ ```code bash

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc