-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into oidc-client
- Loading branch information
Showing
106 changed files
with
3,508 additions
and
2,530 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,52 @@ | ||
{ | ||
"name": "@descope/sdk-mixins", | ||
"version": "0.4.0", | ||
"version": "0.6.0", | ||
"author": "Descope Team <[email protected]>", | ||
"homepage": "https://github.com/descope/sdk-mixins", | ||
"bugs": { | ||
"url": "https://github.com/descope/sdk-mixins/issues", | ||
"email": "[email protected]" | ||
}, | ||
"main": "dist/cjs/index.cjs.js", | ||
"module": "dist/index.esm.js", | ||
"types": "dist/index.d.ts", | ||
"main": "./dist/cjs/index.js", | ||
"module": "./dist/esm/index.js", | ||
"types": "./dist/index.d.ts", | ||
"exports": { | ||
"require": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/cjs/index.cjs.js" | ||
".": { | ||
"import": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/esm/index.js" | ||
}, | ||
"require": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/cjs/index.js" | ||
} | ||
}, | ||
"import": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/index.esm.js" | ||
"./theme-mixin": { | ||
"import": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/esm/mixins/themeMixin/index.js" | ||
}, | ||
"require": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/cjs/mixins/themeMixin/index.js" | ||
} | ||
}, | ||
"./static-resources-mixin": { | ||
"import": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/esm/mixins/staticResourcesMixin/index.js" | ||
}, | ||
"require": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/cjs/mixins/staticResourcesMixin/index.js" | ||
} | ||
} | ||
}, | ||
"type": "module", | ||
"description": "Descope JavaScript SDK mixins", | ||
"scripts": { | ||
"build": "rimraf dist && rollup -c", | ||
"test": "echo no tests yet", | ||
"test": "jest", | ||
"lint": "eslint '+(src|test|examples)/**/*.ts'" | ||
}, | ||
"license": "MIT", | ||
|
@@ -83,7 +105,8 @@ | |
"ts-node": "10.9.2", | ||
"typescript": "^5.0.2", | ||
"@reduxjs/toolkit": "^2.0.1", | ||
"redux": "5.0.1" | ||
"redux": "5.0.1", | ||
"rollup-plugin-no-emit": "1.2.1" | ||
}, | ||
"dependencies": { | ||
"@descope/sdk-helpers": "workspace:*", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './loggerMixin'; | ||
export type { Logger } from './types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
packages/libs/sdk-mixins/src/mixins/staticResourcesMixin/fetchWithFallbacks.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Logger } from '../loggerMixin'; | ||
|
||
type FetchParams = Parameters<typeof fetch>; | ||
const notLastMsgSuffix = 'Trying the next fallback URL...'; | ||
|
||
export const fetchWithFallbacks = async ( | ||
fallbacks: FetchParams['0'] | FetchParams['0'][], | ||
init: FetchParams['1'], | ||
{ | ||
logger, | ||
onSuccess, | ||
}: { logger?: Logger; onSuccess?: (urlIndex: number) => void }, | ||
): ReturnType<typeof fetch> => { | ||
const fallbacksArr = Array.isArray(fallbacks) ? fallbacks : [fallbacks]; | ||
|
||
for (let index = 0; index < fallbacksArr.length; index++) { | ||
const url = fallbacksArr[index]; | ||
const isLast = index === fallbacksArr.length - 1; | ||
|
||
try { | ||
const res = await fetch(url.toString(), init); | ||
if (res.ok) { | ||
onSuccess?.(index); | ||
return res; | ||
} | ||
|
||
const errMsg = `Error fetching URL ${url} [${res.status}]`; | ||
|
||
if (isLast) throw new Error(errMsg); | ||
|
||
logger?.debug(`${errMsg}. ${notLastMsgSuffix}`); | ||
} catch (e) { | ||
const errMsg = `Error fetching URL ${url} [${e.message}]`; | ||
|
||
if (isLast) throw new Error(errMsg); | ||
|
||
logger?.debug(`${errMsg}. ${notLastMsgSuffix}`); | ||
} | ||
} | ||
}; |
Oops, something went wrong.