Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@descope-int/react-dynamic-sdk

Package Overview
Dependencies
Maintainers
0
Versions
141
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@descope-int/react-dynamic-sdk - npm Package Compare versions

Comparing version 1.0.116 to 1.0.126

155

dist/cjs/index.cjs.js

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

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var reactSdk = require('@descope/react-sdk');
var React = require('react');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
function _interopNamespace(e) {
if (e && e.__esModule) return e;
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n["default"] = e;
return Object.freeze(n);
}
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
// @ts-ignore
const BASE_CONTENT_URL_KEY = 'base.content.url';
const BASE_CONTENT_URL = localStorage?.getItem(BASE_CONTENT_URL_KEY) ||
'https://static.descope.com/pages';
const ASSETS_FOLDER = 'v2-beta';
const CONFIG_FILENAME = 'config.json';
const WC_NAME = 'descope-wc';
const FLOWS_V2_SDK_URL = 'https://cdn.jsdelivr.net/npm/@descope/web-component@3.16.2';
// this lib allows us to re-register a custom element with the same name/class
// eslint-disable-next-line import/extensions
const pathJoin = (...paths) => paths.join('/').replace(/\/+/g, '/');
const getSdkVersion = async (projectId) => {
const configUrl = new URL(BASE_CONTENT_URL);
configUrl.pathname = pathJoin(configUrl.pathname, projectId, ASSETS_FOLDER, CONFIG_FILENAME);
const res = await fetch(configUrl, { cache: 'default' });
return res.ok ? 'v2' : 'v1';
};
const loadSdkV2 = () =>
// @ts-ignore
// eslint-disable-next-line import/no-unresolved, import/extensions
(function (t) { return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(t)); }); })(/* webpackIgnore: true */ FLOWS_V2_SDK_URL);
// this fn patch the custom elements define fn when called,
// it prevents from descope-wc to be registered, and resolves with the descope-wc class
const getDescopeWcDefineClass = () => new Promise((resolve) => {
const origDefine = customElements.define;
const origGet = customElements.get;
customElements.define = (...args) => {
if (args[0] === WC_NAME) {
resolve(args[1]);
customElements.define = origDefine;
customElements.get = origGet;
}
else {
origDefine.apply(customElements, args);
}
};
customElements.get = (...args) => {
if (args[0] === WC_NAME) {
customElements.get = origGet;
return null;
}
return origGet.apply(customElements, args);
};
});
/* eslint-disable no-underscore-dangle */
// v1 is loaded by react-sdk
const v1Class = getDescopeWcDefineClass();
const getSdkVersionMemo = (() => {
let prevProjectId = '';
let prevResult = Promise.resolve('');
return (projectId) => {
if (projectId !== prevProjectId) {
prevProjectId = projectId;
prevResult = getSdkVersion(projectId);
}
return prevResult;
};
})();
const useDynamicSdk = ({ projectId, sdkVersion }) => {
const currentSdkVersion = React.useRef('');
const [state, setState] = React.useState({
projectId,
sdkVersion: sdkVersion || currentSdkVersion.current
});
const classes = React.useRef({ v1: undefined, v2: undefined });
React.useMemo(() => {
(async () => {
if (!classes.current.v1) {
classes.current.v1 = await v1Class;
const sdkV1ComponentName = `${WC_NAME}-v1`;
if (!customElements.get(sdkV1ComponentName)) {
// we should re-register the component under a different name so we can run flows in different versions on the same app (console-app)
customElements.define(sdkV1ComponentName, classes.current.v1);
}
}
const sdkVer = await getSdkVersionMemo(projectId);
if (sdkVer && sdkVer !== currentSdkVersion.current) {
currentSdkVersion.current = sdkVer;
if (!classes.current[sdkVer]) {
// so if we got here, it means that we need to load v2
const v2Class = getDescopeWcDefineClass();
await loadSdkV2();
classes.current[sdkVer] = await v2Class;
const sdkV2ComponentName = `${WC_NAME}-v2`;
if (!customElements.get(sdkV2ComponentName)) {
// we should re-register the component under a different name so we can run flows in different versions on the same app (console-app)
customElements.define(`${WC_NAME}-v2`, classes.current.v2);
}
}
if (!customElements.get(WC_NAME)) {
class Wrapper extends classes.current[sdkVer] {
}
customElements.define(WC_NAME, Wrapper);
}
}
setState({ projectId, sdkVersion: currentSdkVersion.current });
})();
}, [projectId, sdkVersion]);
return state;
};
const Context = React.createContext(undefined);
// eslint-disable-next-line react/prop-types
const AuthProvider = ({
// eslint-disable-next-line react/prop-types
projectId, sdkVersion, ...props }) => {
const dynamicSdk = useDynamicSdk({ projectId, sdkVersion });
return (React__default["default"].createElement(Context.Provider, { value: dynamicSdk.sdkVersion + dynamicSdk.projectId },
React__default["default"].createElement(reactSdk.AuthProvider, { projectId: dynamicSdk.projectId, ...props })));
};
const Descope = (props) => {
const key = React.useContext(Context);
return React__default["default"].createElement(reactSdk.Descope, { ...props, key: key });
};
exports.AuthProvider = AuthProvider;
exports.Descope = Descope;
Object.keys(reactSdk).forEach(function (k) {
if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
enumerable: true,
get: function () { return reactSdk[k]; }
});
});
"use strict";var e=require("@descope/react-sdk"),t=require("react");const s=localStorage?.getItem("base.content.url")||"https://static.descope.com/pages",r="descope-wc",n=()=>new Promise((e=>{const t=customElements.define,s=customElements.get;customElements.define=(...n)=>{n[0]===r?(e(n[1]),customElements.define=t,customElements.get=s):t.apply(customElements,n)},customElements.get=(...e)=>e[0]===r?(customElements.get=s,null):s.apply(customElements,e)})),c=n(),o=(()=>{let e="",t=Promise.resolve("");return r=>(r!==e&&(e=r,t=(async e=>{const t=new URL(s);return t.pathname=((...e)=>e.join("/").replace(/\/+/g,"/"))(t.pathname,e,"v2-beta","config.json"),(await fetch(t,{cache:"default"})).ok?"v2":"v1"})(r)),t)})(),u=({projectId:e,sdkVersion:s})=>{const u=t.useRef(""),[m,a]=t.useState({projectId:e,sdkVersion:s||u.current}),i=t.useRef({v1:void 0,v2:void 0});return t.useMemo((()=>{(async()=>{if(!i.current.v1){i.current.v1=await c;const e=`${r}-v1`;customElements.get(e)||customElements.define(e,i.current.v1)}const t=await o(e);if(t&&t!==u.current){if(u.current=t,!i.current[t]){const e=n();await import("https://cdn.jsdelivr.net/npm/@descope/web-component@3.17.5"),i.current[t]=await e;const s=`${r}-v2`;customElements.get(s)||customElements.define(`${r}-v2`,i.current.v2)}if(!customElements.get(r)){class e extends i.current[t]{}customElements.define(r,e)}}a({projectId:e,sdkVersion:u.current})})()}),[e,s]),m},m=t.createContext(void 0);exports.AuthProvider=({projectId:s,sdkVersion:r,...n})=>{const c=u({projectId:s,sdkVersion:r});return t.createElement(m.Provider,{value:c.sdkVersion+c.projectId},t.createElement(e.AuthProvider,{projectId:c.projectId,...n}))},exports.Descope=s=>{const r=t.useContext(m);return t.createElement(e.Descope,{...s,key:r})},Object.keys(e).forEach((function(t){"default"===t||Object.prototype.hasOwnProperty.call(exports,t)||Object.defineProperty(exports,t,{enumerable:!0,get:function(){return e[t]}})}));
//# sourceMappingURL=index.cjs.js.map

2

dist/dts/src/constants.d.ts

@@ -5,2 +5,2 @@ export declare const BASE_CONTENT_URL: string;

export declare const WC_NAME = "descope-wc";
export declare const FLOWS_V2_SDK_URL = "https://cdn.jsdelivr.net/npm/@descope/web-component@3.16.2";
export declare const FLOWS_V2_SDK_URL = "https://cdn.jsdelivr.net/npm/@descope/web-component@3.17.5";

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

import { AuthProvider as AuthProvider$1, Descope as Descope$1 } from '@descope/react-sdk';
export * from '@descope/react-sdk';
import React, { useRef, useState, useMemo, createContext, useContext } from 'react';
// @ts-ignore
const BASE_CONTENT_URL_KEY = 'base.content.url';
const BASE_CONTENT_URL = localStorage?.getItem(BASE_CONTENT_URL_KEY) ||
'https://static.descope.com/pages';
const ASSETS_FOLDER = 'v2-beta';
const CONFIG_FILENAME = 'config.json';
const WC_NAME = 'descope-wc';
const FLOWS_V2_SDK_URL = 'https://cdn.jsdelivr.net/npm/@descope/web-component@3.16.2';
// this lib allows us to re-register a custom element with the same name/class
// eslint-disable-next-line import/extensions
const pathJoin = (...paths) => paths.join('/').replace(/\/+/g, '/');
const getSdkVersion = async (projectId) => {
const configUrl = new URL(BASE_CONTENT_URL);
configUrl.pathname = pathJoin(configUrl.pathname, projectId, ASSETS_FOLDER, CONFIG_FILENAME);
const res = await fetch(configUrl, { cache: 'default' });
return res.ok ? 'v2' : 'v1';
};
const loadSdkV2 = () =>
// @ts-ignore
// eslint-disable-next-line import/no-unresolved, import/extensions
import(/* webpackIgnore: true */ FLOWS_V2_SDK_URL);
// this fn patch the custom elements define fn when called,
// it prevents from descope-wc to be registered, and resolves with the descope-wc class
const getDescopeWcDefineClass = () => new Promise((resolve) => {
const origDefine = customElements.define;
const origGet = customElements.get;
customElements.define = (...args) => {
if (args[0] === WC_NAME) {
resolve(args[1]);
customElements.define = origDefine;
customElements.get = origGet;
}
else {
origDefine.apply(customElements, args);
}
};
customElements.get = (...args) => {
if (args[0] === WC_NAME) {
customElements.get = origGet;
return null;
}
return origGet.apply(customElements, args);
};
});
/* eslint-disable no-underscore-dangle */
// v1 is loaded by react-sdk
const v1Class = getDescopeWcDefineClass();
const getSdkVersionMemo = (() => {
let prevProjectId = '';
let prevResult = Promise.resolve('');
return (projectId) => {
if (projectId !== prevProjectId) {
prevProjectId = projectId;
prevResult = getSdkVersion(projectId);
}
return prevResult;
};
})();
const useDynamicSdk = ({ projectId, sdkVersion }) => {
const currentSdkVersion = useRef('');
const [state, setState] = useState({
projectId,
sdkVersion: sdkVersion || currentSdkVersion.current
});
const classes = useRef({ v1: undefined, v2: undefined });
useMemo(() => {
(async () => {
if (!classes.current.v1) {
classes.current.v1 = await v1Class;
const sdkV1ComponentName = `${WC_NAME}-v1`;
if (!customElements.get(sdkV1ComponentName)) {
// we should re-register the component under a different name so we can run flows in different versions on the same app (console-app)
customElements.define(sdkV1ComponentName, classes.current.v1);
}
}
const sdkVer = await getSdkVersionMemo(projectId);
if (sdkVer && sdkVer !== currentSdkVersion.current) {
currentSdkVersion.current = sdkVer;
if (!classes.current[sdkVer]) {
// so if we got here, it means that we need to load v2
const v2Class = getDescopeWcDefineClass();
await loadSdkV2();
classes.current[sdkVer] = await v2Class;
const sdkV2ComponentName = `${WC_NAME}-v2`;
if (!customElements.get(sdkV2ComponentName)) {
// we should re-register the component under a different name so we can run flows in different versions on the same app (console-app)
customElements.define(`${WC_NAME}-v2`, classes.current.v2);
}
}
if (!customElements.get(WC_NAME)) {
class Wrapper extends classes.current[sdkVer] {
}
customElements.define(WC_NAME, Wrapper);
}
}
setState({ projectId, sdkVersion: currentSdkVersion.current });
})();
}, [projectId, sdkVersion]);
return state;
};
const Context = createContext(undefined);
// eslint-disable-next-line react/prop-types
const AuthProvider = ({
// eslint-disable-next-line react/prop-types
projectId, sdkVersion, ...props }) => {
const dynamicSdk = useDynamicSdk({ projectId, sdkVersion });
return (React.createElement(Context.Provider, { value: dynamicSdk.sdkVersion + dynamicSdk.projectId },
React.createElement(AuthProvider$1, { projectId: dynamicSdk.projectId, ...props })));
};
const Descope = (props) => {
const key = useContext(Context);
return React.createElement(Descope$1, { ...props, key: key });
};
export { AuthProvider, Descope };
import{AuthProvider as e,Descope as t}from"@descope/react-sdk";export*from"@descope/react-sdk";import s,{useRef as n,useState as c,useMemo as o,createContext as r,useContext as m}from"react";const a=localStorage?.getItem("base.content.url")||"https://static.descope.com/pages",d="descope-wc",u=()=>new Promise((e=>{const t=customElements.define,s=customElements.get;customElements.define=(...n)=>{n[0]===d?(e(n[1]),customElements.define=t,customElements.get=s):t.apply(customElements,n)},customElements.get=(...e)=>e[0]===d?(customElements.get=s,null):s.apply(customElements,e)})),i=u(),l=(()=>{let e="",t=Promise.resolve("");return s=>(s!==e&&(e=s,t=(async e=>{const t=new URL(a);return t.pathname=((...e)=>e.join("/").replace(/\/+/g,"/"))(t.pathname,e,"v2-beta","config.json"),(await fetch(t,{cache:"default"})).ok?"v2":"v1"})(s)),t)})(),p=({projectId:e,sdkVersion:t})=>{const s=n(""),[r,m]=c({projectId:e,sdkVersion:t||s.current}),a=n({v1:void 0,v2:void 0});return o((()=>{(async()=>{if(!a.current.v1){a.current.v1=await i;const e=`${d}-v1`;customElements.get(e)||customElements.define(e,a.current.v1)}const t=await l(e);if(t&&t!==s.current){if(s.current=t,!a.current[t]){const e=u();await import("https://cdn.jsdelivr.net/npm/@descope/web-component@3.17.5"),a.current[t]=await e;const s=`${d}-v2`;customElements.get(s)||customElements.define(`${d}-v2`,a.current.v2)}if(!customElements.get(d)){class e extends a.current[t]{}customElements.define(d,e)}}m({projectId:e,sdkVersion:s.current})})()}),[e,t]),r},v=r(void 0),E=({projectId:t,sdkVersion:n,...c})=>{const o=p({projectId:t,sdkVersion:n});return s.createElement(v.Provider,{value:o.sdkVersion+o.projectId},s.createElement(e,{projectId:o.projectId,...c}))},f=e=>{const n=m(v);return s.createElement(t,{...e,key:n})};export{E as AuthProvider,f as Descope};
//# sourceMappingURL=index.esm.js.map
{
"name": "@descope-int/react-dynamic-sdk",
"version": "1.0.116",
"version": "1.0.126",
"description": "Descope Dynamic React SDK",

@@ -34,3 +34,3 @@ "author": "Descope Team <info@descope.com>",

"scripts": {
"build": "rollup -c",
"build": "rollup --config rollup.config.js",
"format": "prettier . -w --ignore-path .gitignore",

@@ -43,3 +43,3 @@ "format-check": "prettier . --check --ignore-path .gitignore",

"prepublishOnly": "npm run build",
"start": "rollup -c rollup.config.app.js -w",
"start": "rollup --config rollup.config.app.js -w",
"test": "exit 0"

@@ -57,17 +57,17 @@ },

"devDependencies": {
"@babel/core": "7.24.6",
"@babel/preset-env": "7.24.6",
"@babel/preset-react": "7.24.6",
"@babel/preset-typescript": "7.24.6",
"@babel/core": "7.24.7",
"@babel/preset-env": "7.24.7",
"@babel/preset-react": "7.24.7",
"@babel/preset-typescript": "7.24.7",
"@open-wc/rollup-plugin-html": "^1.2.5",
"@rollup/plugin-commonjs": "^25.0.0",
"@rollup/plugin-commonjs": "^26.0.0",
"@rollup/plugin-node-resolve": "^15.0.0",
"@rollup/plugin-replace": "^5.0.0",
"@rollup/plugin-typescript": "^11.1.2",
"@testing-library/jest-dom": "6.4.5",
"@testing-library/react": "15.0.7",
"@testing-library/jest-dom": "6.4.6",
"@testing-library/react": "16.0.0",
"@testing-library/react-hooks": "8.0.1",
"@testing-library/user-event": "14.5.2",
"@types/jest": "^29.0.0",
"@types/react": "17.0.80",
"@types/react": "18.3.3",
"@types/react-dom": "18.2.25",

@@ -102,6 +102,6 @@ "@types/react-router-dom": "^5.3.3",

"pretty-quick": "^4.0.0",
"react": "17.0.2",
"react-dom": "17.0.2",
"react": "18.3.1",
"react-dom": "18.3.1",
"react-router-dom": "6.23.1",
"rollup": "^2.62.0",
"rollup": "^4.0.0",
"rollup-plugin-auto-external": "^2.0.0",

@@ -115,3 +115,3 @@ "rollup-plugin-browsersync": "^1.3.3",

"rollup-plugin-serve": "^3.0.0",
"rollup-plugin-terser": "^7.0.2",
"@rollup/plugin-terser": "^0.4.0",
"ts-jest": "^29.0.0",

@@ -118,0 +118,0 @@ "ts-node": "10.9.2",

Sorry, the diff of this file is not supported yet

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