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
320
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.6 to 1.0.4-alpha.7

dist/cjs/examples/es6/src/index.d.ts

2

dist/cjs/index.cjs.js

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

"use strict";var e=require("@descope/core-js-sdk"),t=require("jose"),s=require("node-fetch"),i=require("tslib");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=o(e),r=o(s);const n=(e,t,s)=>`${e}=${t}; Domain=${(null==s?void 0:s.cookieDomain)||""}; Max-Age=${(null==s?void 0:s.cookieMaxAge)||""}; Path=${(null==s?void 0:s.cookiePath)||"/"}; HttpOnly; SameSite=Strict`,c=e=>async(...t)=>{var s,o,a;const r=await e(...t);if(!r.data)return r;let c=r.data,{sessionJwt:l,refreshJwt:h}=c,d=i.__rest(c,["sessionJwt","refreshJwt"]);const u=[n("DS",l,d)];return h?u.push(n("DSR",h,d)):(null===(s=r.response)||void 0===s?void 0:s.headers.get("set-cookie"))&&(h=((e,t)=>{const s=null==e?void 0:e.match(RegExp(`(?:^|;\\s*)${t}=([^;]*)`));return s?s[1]:null})(null===(o=r.response)||void 0===o?void 0:o.headers.get("set-cookie"),"DSR"),u.push(null===(a=r.response)||void 0===a?void 0:a.headers.get("set-cookie"))),Object.assign(Object.assign({},r),{data:Object.assign(Object.assign({},r.data),{refreshJwt:h,cookies:u})})},l=(e,t,s)=>{if(!e)return;const i="string"==typeof t?t.split("."):t,o=i.shift()||"";if(0===i.length||"*"===o){const t=t=>{if(!t||"function"!=typeof e[t])throw Error(`cannot wrap value at key "${t.toString()}"`);e[t]=s(e[t])};"*"===o?Object.keys(e).forEach(t):t(o)}else l(e[o],i,s)};globalThis.fetch||(globalThis.fetch=r.default,globalThis.Headers=s.Headers,globalThis.Request=s.Request,globalThis.Response=s.Response);const h=(...e)=>{const s=a.default(...e);var i,o;i=s,o=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(i,e,o)));const{projectId:r,logger:n}=e[0],h={};return Object.assign(Object.assign({},s),{async getKey(e){if(!(null==e?void 0:e.kid))throw Error("header.kid must not be empty");if(h[e.kid])return h[e.kid];if(Object.assign(h,await(async()=>{const e=await s.httpClient.get(`v1/keys/${r}`).then((e=>e.json()));return Array.isArray(e)?(await Promise.all(e.map((async e=>[e.kid,await t.importJWK(e)])))).reduce(((e,[t,s])=>t?Object.assign(Object.assign({},e),{[t.toString()]:s}):e),{}):{}})()),!h[e.kid])throw Error("failed to fetch matching key");return h[e.kid]},async validateToken(e){return{token:(await t.jwtVerify(e,this.getKey,{algorithms:["ES384"]})).payload}},async validateSession(e,t){if(!e)throw Error("session token must not be empty");try{return await this.validateToken(e)}catch(e){try{return await this.validateToken(t),(await this.refresh(t)).data}catch(e){throw null==n||n.error("failed to validate refresh token",e),Error("could not validate tokens")}}}})};h.DeliveryMethods=a.default.DeliveryMethods,h.RefreshTokenCookieName="DSR",h.SessionTokenCookieName="DS",module.exports=h;
"use strict";var e=require("@descope/core-js-sdk"),t=require("jose"),s=require("node-fetch"),o=require("tslib");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=r(e),n=r(s);const i=(e,t,s)=>`${e}=${t}; Domain=${(null==s?void 0:s.cookieDomain)||""}; Max-Age=${(null==s?void 0:s.cookieMaxAge)||""}; Path=${(null==s?void 0:s.cookiePath)||"/"}; HttpOnly; SameSite=Strict`,c=e=>async(...t)=>{var s,r,a;const n=await e(...t);if(!n.data)return n;let c=n.data,{sessionJwt:l,refreshJwt:d}=c,u=o.__rest(c,["sessionJwt","refreshJwt"]);const h=[i("DS",l,u)];return d?h.push(i("DSR",d,u)):(null===(s=n.response)||void 0===s?void 0:s.headers.get("set-cookie"))&&(d=((e,t)=>{const s=null==e?void 0:e.match(RegExp(`(?:^|;\\s*)${t}=([^;]*)`));return s?s[1]:null})(null===(r=n.response)||void 0===r?void 0:r.headers.get("set-cookie"),"DSR"),h.push(null===(a=n.response)||void 0===a?void 0:a.headers.get("set-cookie"))),Object.assign(Object.assign({},n),{data:Object.assign(Object.assign({},n.data),{refreshJwt:d,cookies:h})})},l=(e,t,s)=>{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]=s(e[t])};"*"===r?Object.keys(e).forEach(t):t(r)}else l(e[r],o,s)};function d(e,t,s){var o,r;const a=s?null===(r=null===(o=e.token.tenants)||void 0===o?void 0:o[s])||void 0===r?void 0:r[t]:e.token[t];return Array.isArray(a)?a:[]}globalThis.fetch||(globalThis.fetch=n.default,globalThis.Headers=s.Headers,globalThis.Request=s.Request,globalThis.Response=s.Response);const u=(...e)=>{const s=[...e];s[0].hooks=s[0].hooks||{};const o=s[0].hooks.beforeRequest;s[0].hooks.beforeRequest=e=>{var t;const s=e;return s.headers=Object.assign(Object.assign({},s.headers),{"x-descope-sdk-name":"nodejs","x-descope-sdk-node-version":(null===(t=null===process||void 0===process?void 0:process.versions)||void 0===t?void 0:t.node)||"","x-descope-sdk-version":"1.0.4-alpha.7"}),(null==o?void 0:o(s))||s};const r=a.default(...s);var n,i;n=r,i=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,i)));const{projectId:u,logger:h}=e[0],v={},f=Object.assign(Object.assign({},r),{async getKey(e){if(!(null==e?void 0:e.kid))throw Error("header.kid must not be empty");if(v[e.kid])return v[e.kid];if(Object.assign(v,await(async()=>{const e=await r.httpClient.get(`v1/keys/${u}`).then((e=>e.json()));return Array.isArray(e)?(await Promise.all(e.map((async e=>[e.kid,await t.importJWK(e)])))).reduce(((e,[t,s])=>t?Object.assign(Object.assign({},e),{[t.toString()]:s}):e),{}):{}})()),!v[e.kid])throw Error("failed to fetch matching key");return v[e.kid]},validateJwt:async e=>({jwt:e,token:(await t.jwtVerify(e,f.getKey,{issuer:u,clockTolerance:5})).payload}),async validateSession(e,t){var s,o;if(!e&&!t)throw Error("both refresh token and session token are empty");if(e)try{return await f.validateJwt(e)}catch(e){if(!t)throw null==h||h.error("failed to validate session token and no refresh token provided",e),Error("could not validate tokens")}if(t)try{await f.validateJwt(t);const e=await f.refresh(t);if(e.ok){return await f.validateJwt(null===(s=e.data)||void 0===s?void 0:s.sessionJwt)}throw Error(null===(o=e.error)||void 0===o?void 0:o.message)}catch(e){throw null==h||h.error("failed to validate refresh token",e),Error("could not validate tokens")}throw Error("could not validate token")},async exchangeAccessKey(e){if(!e)throw Error("access key must not be empty");let t;try{t=await f.accessKey.exchange(e)}catch(e){throw null==h||h.error("failed to exchange access key",e),Error("could not exchange access key")}const{sessionJwt:s}=t.data;if(!s)throw null==h||h.error("failed to parse exchange access key response"),Error("could not exchange access key");try{return await f.validateJwt(s)}catch(e){throw null==h||h.error("failed to parse jwt from access key",e),Error("could not exchange access key")}},validatePermissions:(e,t)=>f.validateTenantPermissions(e,null,t),validateTenantPermissions(e,t,s){const o=d(e,"permissions",t);return s.every((e=>o.includes(e)))},validateRoles:(e,t)=>f.validateTenantRoles(e,null,t),validateTenantRoles(e,t,s){const o=d(e,"roles",t);return s.every((e=>o.includes(e)))}});return f};u.DeliveryMethods=a.default.DeliveryMethods,u.RefreshTokenCookieName="DSR",u.SessionTokenCookieName="DS",module.exports=u;
//# sourceMappingURL=index.cjs.js.map
import * as _descope_core_js_sdk from '@descope/core-js-sdk';
import _descope_core_js_sdk__default from '@descope/core-js-sdk';
import _descope_core_js_sdk__default, { RequestConfig, SdkResponse, ExchangeAccessKeyResponse } from '@descope/core-js-sdk';
export { DeliveryMethod, OAuthProvider } from '@descope/core-js-sdk';
import { JWTHeaderParameters, KeyLike } from 'jose';
/** Parsed JWT token */
interface Token {

@@ -10,11 +11,32 @@ sub?: string;

iss?: string;
[claim: string]: unknown;
}
/** All information regarding token including the raw JWT, parsed JWT and cookies */
interface AuthenticationInfo {
token?: Token;
jwt: string;
token: Token;
cookies?: string[];
}
/** Refresh JWT cookie name */
declare const refreshTokenCookieName = "DSR";
/** Session JWT cookie name */
declare const sessionTokenCookieName = "DS";
/** Descope SDK client with delivery methods enum.
*
* Please see full documentation at {@link https://docs.descope.com/guides Descope Docs}
* @example Usage
*
* ```js
* import descopeSdk from '@descope/node-sdk';
*
* const myProjectId = 'xxx';
* const sdk = descopeSdk({ projectId: myProjectId });
*
* const userIdentifier = 'identifier';
* sdk.otp.signIn.email(userIdentifier);
* const jwtResponse = sdk.otp.verify.email(userIdentifier, codeFromEmail);
* ```
*/
declare const sdkWithAttributes: ((args_0: {

@@ -37,16 +59,71 @@ projectId: string;

baseUrl?: string;
hooks?: {
beforeRequest?: (config: RequestConfig) => RequestConfig;
afterRequest?: (req: RequestConfig, res: globalThis.Response) => void;
};
cookiePolicy?: RequestCredentials;
}) => {
/** Get the key that can validate the given JWT KID in the header. Can retrieve the public key from local cache or from Descope. */
getKey(header: JWTHeaderParameters): Promise<KeyLike | Uint8Array>;
validateToken(token: string): Promise<AuthenticationInfo>;
validateSession(sessionToken: string, refreshToken: string): Promise<AuthenticationInfo | undefined>;
/**
* Validate the given JWT with the right key and make sure the issuer is correct
* @param jwt the JWT string to parse and validate
* @returns AuthenticationInfo with the parsed token and JWT. Will throw an error if validation fails.
*/
validateJwt(jwt: string): Promise<AuthenticationInfo>;
/**
* Validate session based on at least one of session and refresh JWTs. You must provide at least one of them.
*
* @param sessionToken session JWT
* @param refreshToken refresh JWT
* @returns AuthenticationInfo promise or throws Error if there is an issue with JWTs
*/
validateSession(sessionToken?: string, refreshToken?: string): Promise<AuthenticationInfo>;
/**
* Exchange API key (access key) for a session key
* @param accessKey access key to exchange for a session JWT
* @returns AuthneticationInfo with session JWT data
*/
exchangeAccessKey(accessKey: string): Promise<AuthenticationInfo>;
/**
* Make sure that all given permissions exist on the parsed JWT top level claims
* @param authInfo JWT parsed info
* @param permissions list of permissions to make sure they exist on te JWT claims
* @returns true if all permissions exist, false otherwise
*/
validatePermissions(authInfo: AuthenticationInfo, permissions: string[]): boolean;
/**
* Make sure that all given permissions exist on the parsed JWT tenant claims
* @param authInfo JWT parsed info
* @param permissions list of permissions to make sure they exist on te JWT claims
* @returns true if all permissions exist, false otherwise
*/
validateTenantPermissions(authInfo: AuthenticationInfo, tenant: string, permissions: string[]): boolean;
/**
* Make sure that all given roles exist on the parsed JWT top level claims
* @param authInfo JWT parsed info
* @param roles list of roles to make sure they exist on te JWT claims
* @returns true if all roles exist, false otherwise
*/
validateRoles(authInfo: AuthenticationInfo, roles: string[]): boolean;
/**
* Make sure that all given roles exist on the parsed JWT tenant claims
* @param authInfo JWT parsed info
* @param roles list of roles to make sure they exist on te JWT claims
* @returns true if all roles exist, false otherwise
*/
validateTenantRoles(authInfo: AuthenticationInfo, tenant: string, roles: string[]): boolean;
accessKey: {
exchange: (accessKey: string) => Promise<SdkResponse<ExchangeAccessKeyResponse>>;
};
otp: {
verify: {
email: (identifier: string, code: string) => Promise<_descope_core_js_sdk.SdkResponse>;
sms: (identifier: string, code: string) => Promise<_descope_core_js_sdk.SdkResponse>;
whatsapp: (identifier: string, code: string) => Promise<_descope_core_js_sdk.SdkResponse>;
email: (identifier: string, code: string) => Promise<SdkResponse<_descope_core_js_sdk.JWTResponse>>;
sms: (identifier: string, code: string) => Promise<SdkResponse<_descope_core_js_sdk.JWTResponse>>;
whatsapp: (identifier: string, code: string) => Promise<SdkResponse<_descope_core_js_sdk.JWTResponse>>;
};
signIn: {
email: (identifier: string) => Promise<_descope_core_js_sdk.SdkResponse>;
sms: (identifier: string) => Promise<_descope_core_js_sdk.SdkResponse>;
whatsapp: (identifier: string) => Promise<_descope_core_js_sdk.SdkResponse>;
email: (identifier: string) => Promise<SdkResponse<never>>;
sms: (identifier: string) => Promise<SdkResponse<never>>;
whatsapp: (identifier: string) => Promise<SdkResponse<never>>;
};

@@ -58,3 +135,3 @@ signUp: {

phone?: string;
}) => Promise<_descope_core_js_sdk.SdkResponse>;
}) => Promise<SdkResponse<never>>;
sms: (identifier: string, user?: {

@@ -64,3 +141,3 @@ email?: string;

phone?: string;
}) => Promise<_descope_core_js_sdk.SdkResponse>;
}) => Promise<SdkResponse<never>>;
whatsapp: (identifier: string, user?: {

@@ -70,15 +147,15 @@ email?: string;

phone?: string;
}) => Promise<_descope_core_js_sdk.SdkResponse>;
}) => Promise<SdkResponse<never>>;
};
signUpOrIn: {
email: (identifier: string) => Promise<_descope_core_js_sdk.SdkResponse>;
sms: (identifier: string) => Promise<_descope_core_js_sdk.SdkResponse>;
whatsapp: (identifier: string) => Promise<_descope_core_js_sdk.SdkResponse>;
email: (identifier: string) => Promise<SdkResponse<never>>;
sms: (identifier: string) => Promise<SdkResponse<never>>;
whatsapp: (identifier: string) => Promise<SdkResponse<never>>;
};
update: {
email: (identifier: string, email: string, token?: string) => Promise<_descope_core_js_sdk.SdkResponse>;
email: (identifier: string, email: string, token?: string) => Promise<SdkResponse<never>>;
phone: {
email: (identifier: string, phone: string) => Promise<_descope_core_js_sdk.SdkResponse>;
sms: (identifier: string, phone: string) => Promise<_descope_core_js_sdk.SdkResponse>;
whatsapp: (identifier: string, phone: string) => Promise<_descope_core_js_sdk.SdkResponse>;
email: (identifier: string, phone: string) => Promise<SdkResponse<never>>;
sms: (identifier: string, phone: string) => Promise<SdkResponse<never>>;
whatsapp: (identifier: string, phone: string) => Promise<SdkResponse<never>>;
};

@@ -88,7 +165,7 @@ };

magicLink: {
verify: (token: string) => Promise<_descope_core_js_sdk.SdkResponse>;
verify: (token: string) => Promise<SdkResponse<_descope_core_js_sdk.JWTResponse>>;
signIn: {
email: (identifier: string, uri: string) => Promise<_descope_core_js_sdk.SdkResponse>;
sms: (identifier: string, uri: string) => Promise<_descope_core_js_sdk.SdkResponse>;
whatsapp: (identifier: string, uri: string) => Promise<_descope_core_js_sdk.SdkResponse>;
email: (identifier: string, uri: string) => Promise<SdkResponse<_descope_core_js_sdk.PendingRefResponse>>;
sms: (identifier: string, uri: string) => Promise<SdkResponse<_descope_core_js_sdk.PendingRefResponse>>;
whatsapp: (identifier: string, uri: string) => Promise<SdkResponse<_descope_core_js_sdk.PendingRefResponse>>;
};

@@ -100,3 +177,3 @@ signUp: {

phone?: string;
}) => Promise<_descope_core_js_sdk.SdkResponse>;
}) => Promise<SdkResponse<_descope_core_js_sdk.PendingRefResponse>>;
sms: (identifier: string, uri: string, user?: {

@@ -106,3 +183,3 @@ email?: string;

phone?: string;
}) => Promise<_descope_core_js_sdk.SdkResponse>;
}) => Promise<SdkResponse<_descope_core_js_sdk.PendingRefResponse>>;
whatsapp: (identifier: string, uri: string, user?: {

@@ -112,28 +189,28 @@ email?: string;

phone?: string;
}) => Promise<_descope_core_js_sdk.SdkResponse>;
}) => Promise<SdkResponse<_descope_core_js_sdk.PendingRefResponse>>;
};
signUpOrIn: {
email: (identifier: string, uri: string) => Promise<_descope_core_js_sdk.SdkResponse>;
sms: (identifier: string, uri: string) => Promise<_descope_core_js_sdk.SdkResponse>;
whatsapp: (identifier: string, uri: string) => Promise<_descope_core_js_sdk.SdkResponse>;
email: (identifier: string, uri: string) => Promise<SdkResponse<_descope_core_js_sdk.PendingRefResponse>>;
sms: (identifier: string, uri: string) => Promise<SdkResponse<_descope_core_js_sdk.PendingRefResponse>>;
whatsapp: (identifier: string, uri: string) => Promise<SdkResponse<_descope_core_js_sdk.PendingRefResponse>>;
};
update: {
email: (identifier: string, email: string, uri: string, token?: string) => Promise<_descope_core_js_sdk.SdkResponse>;
email: (identifier: string, email: string, uri: string, token?: string) => Promise<SdkResponse<never>>;
phone: {
email: (identifier: string, phone: string) => Promise<_descope_core_js_sdk.SdkResponse>;
sms: (identifier: string, phone: string) => Promise<_descope_core_js_sdk.SdkResponse>;
whatsapp: (identifier: string, phone: string) => Promise<_descope_core_js_sdk.SdkResponse>;
email: (identifier: string, phone: string) => Promise<SdkResponse<never>>;
sms: (identifier: string, phone: string) => Promise<SdkResponse<never>>;
whatsapp: (identifier: string, phone: string) => Promise<SdkResponse<never>>;
};
};
crossDevice: {
verify: (token: string) => Promise<_descope_core_js_sdk.SdkResponse>;
verify: (token: string) => Promise<SdkResponse<_descope_core_js_sdk.JWTResponse>>;
signIn: {
email: (identifier: string, uri: string) => Promise<_descope_core_js_sdk.SdkResponse>;
sms: (identifier: string, uri: string) => Promise<_descope_core_js_sdk.SdkResponse>;
whatsapp: (identifier: string, uri: string) => Promise<_descope_core_js_sdk.SdkResponse>;
email: (identifier: string, uri: string) => Promise<SdkResponse<_descope_core_js_sdk.PendingRefResponse>>;
sms: (identifier: string, uri: string) => Promise<SdkResponse<_descope_core_js_sdk.PendingRefResponse>>;
whatsapp: (identifier: string, uri: string) => Promise<SdkResponse<_descope_core_js_sdk.PendingRefResponse>>;
};
signUpOrIn: {
email: (identifier: string, uri: string) => Promise<_descope_core_js_sdk.SdkResponse>;
sms: (identifier: string, uri: string) => Promise<_descope_core_js_sdk.SdkResponse>;
whatsapp: (identifier: string, uri: string) => Promise<_descope_core_js_sdk.SdkResponse>;
email: (identifier: string, uri: string) => Promise<SdkResponse<_descope_core_js_sdk.PendingRefResponse>>;
sms: (identifier: string, uri: string) => Promise<SdkResponse<_descope_core_js_sdk.PendingRefResponse>>;
whatsapp: (identifier: string, uri: string) => Promise<SdkResponse<_descope_core_js_sdk.PendingRefResponse>>;
};

@@ -145,3 +222,3 @@ signUp: {

phone?: string;
}) => Promise<_descope_core_js_sdk.SdkResponse>;
}) => Promise<SdkResponse<_descope_core_js_sdk.PendingRefResponse>>;
sms: (identifier: string, uri: string, user?: {

@@ -151,3 +228,3 @@ email?: string;

phone?: string;
}) => Promise<_descope_core_js_sdk.SdkResponse>;
}) => Promise<SdkResponse<_descope_core_js_sdk.PendingRefResponse>>;
whatsapp: (identifier: string, uri: string, user?: {

@@ -157,3 +234,3 @@ email?: string;

phone?: string;
}) => Promise<_descope_core_js_sdk.SdkResponse>;
}) => Promise<SdkResponse<_descope_core_js_sdk.PendingRefResponse>>;
};

@@ -163,9 +240,14 @@ waitForSession: (pendingRef: string, config?: {

timeoutMs: number;
}) => Promise<_descope_core_js_sdk.SdkResponse>;
}) => Promise<SdkResponse<_descope_core_js_sdk.JWTResponse>>; /**
* Make sure that all given roles exist on the parsed JWT tenant claims
* @param authInfo JWT parsed info
* @param roles list of roles to make sure they exist on te JWT claims
* @returns true if all roles exist, false otherwise
*/
update: {
email: (identifier: string, email: string, uri: string, token?: string) => Promise<_descope_core_js_sdk.SdkResponse>;
email: (identifier: string, email: string, uri: string, token?: string) => Promise<SdkResponse<never>>;
phone: {
email: (identifier: string, phone: string) => Promise<_descope_core_js_sdk.SdkResponse>;
sms: (identifier: string, phone: string) => Promise<_descope_core_js_sdk.SdkResponse>;
whatsapp: (identifier: string, phone: string) => Promise<_descope_core_js_sdk.SdkResponse>;
email: (identifier: string, phone: string) => Promise<SdkResponse<never>>;
sms: (identifier: string, phone: string) => Promise<SdkResponse<never>>;
whatsapp: (identifier: string, phone: string) => Promise<SdkResponse<never>>;
};

@@ -176,3 +258,2 @@ };

oauth: {
exchange: (code: string) => Promise<_descope_core_js_sdk.SdkResponse>;
start: {

@@ -183,3 +264,3 @@ facebook: <B extends {

redirect: true;
} ? undefined : _descope_core_js_sdk.SdkResponse>;
} ? undefined : SdkResponse<_descope_core_js_sdk.URLResponse>>;
github: <B_1 extends {

@@ -189,3 +270,3 @@ redirect: boolean;

redirect: true;
} ? undefined : _descope_core_js_sdk.SdkResponse>;
} ? undefined : SdkResponse<_descope_core_js_sdk.URLResponse>>;
google: <B_2 extends {

@@ -195,3 +276,3 @@ redirect: boolean;

redirect: true;
} ? undefined : _descope_core_js_sdk.SdkResponse>;
} ? undefined : SdkResponse<_descope_core_js_sdk.URLResponse>>;
microsoft: <B_3 extends {

@@ -201,3 +282,3 @@ redirect: boolean;

redirect: true;
} ? undefined : _descope_core_js_sdk.SdkResponse>;
} ? undefined : SdkResponse<_descope_core_js_sdk.URLResponse>>;
gitlab: <B_4 extends {

@@ -207,3 +288,3 @@ redirect: boolean;

redirect: true;
} ? undefined : _descope_core_js_sdk.SdkResponse>;
} ? undefined : SdkResponse<_descope_core_js_sdk.URLResponse>>;
apple: <B_5 extends {

@@ -213,7 +294,10 @@ redirect: boolean;

redirect: true;
} ? undefined : _descope_core_js_sdk.SdkResponse>;
} ? undefined : SdkResponse<_descope_core_js_sdk.URLResponse>>;
};
exchange: (code: string, loginOptions?: {
stepup: boolean;
customClaims: Map<string, any>;
}, token?: string) => Promise<SdkResponse<_descope_core_js_sdk.JWTResponse>>;
};
saml: {
exchange: (code: string) => Promise<_descope_core_js_sdk.SdkResponse>;
start: <B_1 extends {

@@ -223,3 +307,7 @@ redirect: boolean;

redirect: true;
} ? undefined : _descope_core_js_sdk.SdkResponse>;
} ? undefined : SdkResponse<_descope_core_js_sdk.URLResponse>>;
exchange: (code: string, loginOptions?: {
stepup: boolean;
customClaims: Map<string, any>;
}, token?: string) => Promise<SdkResponse<_descope_core_js_sdk.JWTResponse>>;
};

@@ -231,27 +319,40 @@ totp: {

phone?: string;
}) => Promise<_descope_core_js_sdk.SdkResponse>;
verify: (identifier: string, code: string) => Promise<_descope_core_js_sdk.SdkResponse>;
update: (identifier: string, token?: string) => Promise<_descope_core_js_sdk.SdkResponse>;
}) => Promise<SdkResponse<_descope_core_js_sdk.TOTPResponse>>;
verify: (identifier: string, code: string, loginOptions?: {
stepup: boolean;
customClaims: Map<string, any>;
}, token?: string) => Promise<SdkResponse<_descope_core_js_sdk.JWTResponse>>;
update: (identifier: string, token?: string) => Promise<SdkResponse<_descope_core_js_sdk.TOTPResponse>>;
};
webauthn: {
signUp: {
start: (identifier: string, origin: string, name: string) => Promise<_descope_core_js_sdk.SdkResponse>;
finish: (transactionId: string, response: string) => Promise<_descope_core_js_sdk.SdkResponse>;
start: (identifier: string, origin: string, name: string) => Promise<SdkResponse<_descope_core_js_sdk.ResponseData>>;
finish: (transactionId: string, response: string, loginOptions?: {
stepup: boolean;
customClaims: Map<string, any>;
}, token?: string) => Promise<SdkResponse<_descope_core_js_sdk.ResponseData>>;
};
signIn: {
start: (identifier: string, origin: string) => Promise<_descope_core_js_sdk.SdkResponse>;
finish: (transactionId: string, response: string) => Promise<_descope_core_js_sdk.SdkResponse>;
start: (identifier: string, origin: string) => Promise<SdkResponse<_descope_core_js_sdk.ResponseData>>;
finish: (transactionId: string, response: string, loginOptions?: {
stepup: boolean;
customClaims: Map<string, any>;
}, token?: string) => Promise<SdkResponse<_descope_core_js_sdk.ResponseData>>;
};
add: {
start: (identifier: string, origin: string, token: string) => Promise<_descope_core_js_sdk.SdkResponse>;
finish: (transactionId: string, response: string) => Promise<_descope_core_js_sdk.SdkResponse>;
update: {
start: (identifier: string, origin: string, token: string) => Promise<SdkResponse<_descope_core_js_sdk.ResponseData>>;
finish: (transactionId: string, response: string) => Promise<SdkResponse<_descope_core_js_sdk.ResponseData>>;
};
};
flow: {
start: (flowId: string) => Promise<_descope_core_js_sdk.SdkResponse>;
next: (executionId: string, stepId: string, actionId: string, input?: Record<string, FormDataEntryValue>) => Promise<_descope_core_js_sdk.SdkResponse>;
start: (flowId: string) => Promise<SdkResponse<_descope_core_js_sdk.FlowResponse>>;
next: (executionId: string, stepId: string, interactionId: string, input?: Record<string, FormDataEntryValue>) => Promise<SdkResponse<_descope_core_js_sdk.FlowResponse>>;
};
refresh: (token?: string) => Promise<_descope_core_js_sdk.SdkResponse>;
logout: (token?: string) => Promise<_descope_core_js_sdk.SdkResponse>;
refresh: (token?: string) => Promise<SdkResponse<_descope_core_js_sdk.JWTResponse>>;
logout: (token?: string) => Promise<SdkResponse<never>>;
deleteCookies: (token?: string) => Promise<SdkResponse<never>>;
me: (token?: string) => Promise<SdkResponse<_descope_core_js_sdk.UserResponse>>;
isJwtExpired: (token: string) => boolean;
getJwtPermissions: (token: string, tenant?: string) => string[];
getJwtRoles: (token: string, tenant?: string) => string[];
httpClient: {

@@ -258,0 +359,0 @@ get: (path: string, config?: {

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

import e from"@descope/core-js-sdk";import{jwtVerify as t,importJWK as i}from"jose";import o,{Headers as s,Request as a,Response as r}from"node-fetch";import{__rest as n}from"tslib";const c=(e,t,i)=>`${e}=${t}; Domain=${(null==i?void 0:i.cookieDomain)||""}; Max-Age=${(null==i?void 0:i.cookieMaxAge)||""}; Path=${(null==i?void 0:i.cookiePath)||"/"}; HttpOnly; SameSite=Strict`,l=e=>async(...t)=>{var i,o,s;const a=await e(...t);if(!a.data)return a;let r=a.data,{sessionJwt:l,refreshJwt:h}=r,d=n(r,["sessionJwt","refreshJwt"]);const g=[c("DS",l,d)];return h?g.push(c("DSR",h,d)):(null===(i=a.response)||void 0===i?void 0:i.headers.get("set-cookie"))&&(h=((e,t)=>{const i=null==e?void 0:e.match(RegExp(`(?:^|;\\s*)${t}=([^;]*)`));return i?i[1]:null})(null===(o=a.response)||void 0===o?void 0:o.headers.get("set-cookie"),"DSR"),g.push(null===(s=a.response)||void 0===s?void 0:s.headers.get("set-cookie"))),Object.assign(Object.assign({},a),{data:Object.assign(Object.assign({},a.data),{refreshJwt:h,cookies:g})})},h=(e,t,i)=>{if(!e)return;const o="string"==typeof t?t.split("."):t,s=o.shift()||"";if(0===o.length||"*"===s){const t=t=>{if(!t||"function"!=typeof e[t])throw Error(`cannot wrap value at key "${t.toString()}"`);e[t]=i(e[t])};"*"===s?Object.keys(e).forEach(t):t(s)}else h(e[s],o,i)};globalThis.fetch||(globalThis.fetch=o,globalThis.Headers=s,globalThis.Request=a,globalThis.Response=r);const d=(...o)=>{const s=e(...o);var a,r;a=s,r=l,["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=>h(a,e,r)));const{projectId:n,logger:c}=o[0],d={};return Object.assign(Object.assign({},s),{async getKey(e){if(!(null==e?void 0:e.kid))throw Error("header.kid must not be empty");if(d[e.kid])return d[e.kid];if(Object.assign(d,await(async()=>{const e=await s.httpClient.get(`v1/keys/${n}`).then((e=>e.json()));return Array.isArray(e)?(await Promise.all(e.map((async e=>[e.kid,await i(e)])))).reduce(((e,[t,i])=>t?Object.assign(Object.assign({},e),{[t.toString()]:i}):e),{}):{}})()),!d[e.kid])throw Error("failed to fetch matching key");return d[e.kid]},async validateToken(e){return{token:(await t(e,this.getKey,{algorithms:["ES384"]})).payload}},async validateSession(e,t){if(!e)throw Error("session token must not be empty");try{return await this.validateToken(e)}catch(e){try{return await this.validateToken(t),(await this.refresh(t)).data}catch(e){throw null==c||c.error("failed to validate refresh token",e),Error("could not validate tokens")}}}})};d.DeliveryMethods=e.DeliveryMethods,d.RefreshTokenCookieName="DSR",d.SessionTokenCookieName="DS";export{d as default};
import e from"@descope/core-js-sdk";import{jwtVerify as o,importJWK as t}from"jose";import s,{Headers as r,Request as a,Response as n}from"node-fetch";import{__rest as i}from"tslib";const c=(e,o,t)=>`${e}=${o}; Domain=${(null==t?void 0:t.cookieDomain)||""}; Max-Age=${(null==t?void 0:t.cookieMaxAge)||""}; Path=${(null==t?void 0:t.cookiePath)||"/"}; HttpOnly; SameSite=Strict`,l=e=>async(...o)=>{var t,s,r;const a=await e(...o);if(!a.data)return a;let n=a.data,{sessionJwt:l,refreshJwt:d}=n,h=i(n,["sessionJwt","refreshJwt"]);const u=[c("DS",l,h)];return d?u.push(c("DSR",d,h)):(null===(t=a.response)||void 0===t?void 0:t.headers.get("set-cookie"))&&(d=((e,o)=>{const t=null==e?void 0:e.match(RegExp(`(?:^|;\\s*)${o}=([^;]*)`));return t?t[1]:null})(null===(s=a.response)||void 0===s?void 0:s.headers.get("set-cookie"),"DSR"),u.push(null===(r=a.response)||void 0===r?void 0:r.headers.get("set-cookie"))),Object.assign(Object.assign({},a),{data:Object.assign(Object.assign({},a.data),{refreshJwt:d,cookies:u})})},d=(e,o,t)=>{if(!e)return;const s="string"==typeof o?o.split("."):o,r=s.shift()||"";if(0===s.length||"*"===r){const o=o=>{if(!o||"function"!=typeof e[o])throw Error(`cannot wrap value at key "${o.toString()}"`);e[o]=t(e[o])};"*"===r?Object.keys(e).forEach(o):o(r)}else d(e[r],s,t)};function h(e,o,t){var s,r;const a=t?null===(r=null===(s=e.token.tenants)||void 0===s?void 0:s[t])||void 0===r?void 0:r[o]:e.token[o];return Array.isArray(a)?a:[]}globalThis.fetch||(globalThis.fetch=s,globalThis.Headers=r,globalThis.Request=a,globalThis.Response=n);const u=(...s)=>{const r=[...s];r[0].hooks=r[0].hooks||{};const a=r[0].hooks.beforeRequest;r[0].hooks.beforeRequest=e=>{var o;const t=e;return t.headers=Object.assign(Object.assign({},t.headers),{"x-descope-sdk-name":"nodejs","x-descope-sdk-node-version":(null===(o=null===process||void 0===process?void 0:process.versions)||void 0===o?void 0:o.node)||"","x-descope-sdk-version":"1.0.4-alpha.7"}),(null==a?void 0:a(t))||t};const n=e(...r);var i,c;i=n,c=l,["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=>d(i,e,c)));const{projectId:u,logger:v}=s[0],f={},k=Object.assign(Object.assign({},n),{async getKey(e){if(!(null==e?void 0:e.kid))throw Error("header.kid must not be empty");if(f[e.kid])return f[e.kid];if(Object.assign(f,await(async()=>{const e=await n.httpClient.get(`v1/keys/${u}`).then((e=>e.json()));return Array.isArray(e)?(await Promise.all(e.map((async e=>[e.kid,await t(e)])))).reduce(((e,[o,t])=>o?Object.assign(Object.assign({},e),{[o.toString()]:t}):e),{}):{}})()),!f[e.kid])throw Error("failed to fetch matching key");return f[e.kid]},validateJwt:async e=>({jwt:e,token:(await o(e,k.getKey,{issuer:u,clockTolerance:5})).payload}),async validateSession(e,o){var t,s;if(!e&&!o)throw Error("both refresh token and session token are empty");if(e)try{return await k.validateJwt(e)}catch(e){if(!o)throw null==v||v.error("failed to validate session token and no refresh token provided",e),Error("could not validate tokens")}if(o)try{await k.validateJwt(o);const e=await k.refresh(o);if(e.ok){return await k.validateJwt(null===(t=e.data)||void 0===t?void 0:t.sessionJwt)}throw Error(null===(s=e.error)||void 0===s?void 0:s.message)}catch(e){throw null==v||v.error("failed to validate refresh token",e),Error("could not validate tokens")}throw Error("could not validate token")},async exchangeAccessKey(e){if(!e)throw Error("access key must not be empty");let o;try{o=await k.accessKey.exchange(e)}catch(e){throw null==v||v.error("failed to exchange access key",e),Error("could not exchange access key")}const{sessionJwt:t}=o.data;if(!t)throw null==v||v.error("failed to parse exchange access key response"),Error("could not exchange access key");try{return await k.validateJwt(t)}catch(e){throw null==v||v.error("failed to parse jwt from access key",e),Error("could not exchange access key")}},validatePermissions:(e,o)=>k.validateTenantPermissions(e,null,o),validateTenantPermissions(e,o,t){const s=h(e,"permissions",o);return t.every((e=>s.includes(e)))},validateRoles:(e,o)=>k.validateTenantRoles(e,null,o),validateTenantRoles(e,o,t){const s=h(e,"roles",o);return t.every((e=>s.includes(e)))}});return k};u.DeliveryMethods=e.DeliveryMethods,u.RefreshTokenCookieName="DSR",u.SessionTokenCookieName="DS";export{u as default};
//# sourceMappingURL=index.esm.js.map
{
"name": "@descope/node-sdk",
"version": "1.0.4-alpha.6",
"version": "1.0.4-alpha.7",
"description": "Node.js library used to integrate with Descope",

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

"build": "rimraf dist && rollup -c",
"quick": "npm i && npm run build && npm run generateCerts && cd examples/es6/ && npm i && npm start",
"format": "prettier --write lib",
"check-format": "prettier --check lib",
"prepare": "husky install",
"quick": "npm i && npm run build && cd examples/es6/ && npm i && npm run generateCerts && npm start",
"format": "prettier . --write --ignore-path .gitignore",
"format-check": "prettier . --check --ignore-path .gitignore",
"format-lint": "pretty-quick --staged --ignore-path .gitignore && lint-staged",
"size": "npm run build && size-limit",

@@ -36,2 +38,7 @@ "lint": "eslint lib/**/*.ts --fix",

},
"lint-staged": {
"+(src|lib)/**/*.{js,ts,jsx,tsx}": [
"npm run lint"
]
},
"author": "Descope",

@@ -74,7 +81,10 @@ "bugs": {

"jsdoc": "^3.6.10",
"lint-staged": "^13.0.3",
"nock": "^13.2.4",
"prettier": "2.6.2",
"prettier": "^2.7.1",
"pretty-quick": "^3.1.3",
"rollup": "^2.62.0",
"rollup-plugin-auto-external": "^2.0.0",
"rollup-plugin-browsersync": "^1.3.3",
"rollup-plugin-define": "^1.0.1",
"rollup-plugin-delete": "^2.0.0",

@@ -90,16 +100,10 @@ "rollup-plugin-dts": "^4.2.2",

},
"size-limit": [
{
"limit": "100 kb",
"path": "dist/*",
"ignore": [
"node:*"
]
}
],
"dependencies": {
"@descope/core-js-sdk": "0.0.41-alpha.10",
"jose": "4.8.1",
"@descope/core-js-sdk": "0.0.41-alpha.24",
"jose": "4.10.0",
"node-fetch": "2.6.7"
},
"peerDependencies": {
"tslib": ">=1.14.1"
}
}

@@ -17,3 +17,3 @@ # Descope Node.js SDK

Click one of the following links to open the documentation for that specific functionality.
Click one of the following links to open the documentation for that specific functionality.

@@ -30,3 +30,3 @@ - [x] [One time passwords (OTP)](./docs/otp.md)

Run the following commands in your project. Replace any instance of `<ProjectID>` in the code below with your company's Project ID, which can be found in the [Descope console](https://app.descope.com).
Run the following commands in your project. Replace any instance of `<ProjectID>` in the code below with your company's Project ID, which can be found in the [Descope console](https://app.descope.com).

@@ -45,21 +45,24 @@ This commands will add the Descope NodeJS SDK as a project dependency, clone the SDK repository locally, and set the `DESCOPE_PROJECT_ID`.

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
```code bash
npm i
npm run build
cd examples/es6
npm i
npm start
```
```code bash
npm i && \
npm run build && \
cd examples/es6 && \
npm i && \
npm run generateCerts && \
npm start
```
2. Run this to start the commonjs example
```code bash
npm i
npm run build
cd examples/commonjs
npm i
npm start
```
```code bash
npm i && \
npm run build && \
cd examples/commonjs && \
npm i && \
npm run generateCerts && \
npm start
```

@@ -66,0 +69,0 @@ ## License

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