-
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.
- Loading branch information
Showing
64 changed files
with
1,097 additions
and
601 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,6 +1,6 @@ | ||
{ | ||
"name": "@descope/sdk-mixins", | ||
"version": "0.5.1", | ||
"version": "0.6.0", | ||
"author": "Descope Team <[email protected]>", | ||
"homepage": "https://github.com/descope/sdk-mixins", | ||
"bugs": { | ||
|
@@ -21,7 +21,7 @@ | |
"default": "./dist/cjs/index.js" | ||
} | ||
}, | ||
"./themeMixin": { | ||
"./theme-mixin": { | ||
"import": { | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/esm/mixins/themeMixin/index.js" | ||
|
@@ -30,13 +30,23 @@ | |
"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", | ||
|
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
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}`); | ||
} | ||
} | ||
}; |
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
Oops, something went wrong.