@tern-secure/shared 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-HATJQ74R.mjs +56 -0
- package/dist/chunk-HATJQ74R.mjs.map +1 -0
- package/dist/derivedAuthState.d.mts +9 -0
- package/dist/derivedAuthState.d.ts +9 -0
- package/dist/derivedAuthState.js +75 -0
- package/dist/derivedAuthState.js.map +1 -0
- package/dist/derivedAuthState.mjs +49 -0
- package/dist/derivedAuthState.mjs.map +1 -0
- package/dist/eventBus.d.mts +8 -0
- package/dist/eventBus.d.ts +8 -0
- package/dist/eventBus.js +54 -0
- package/dist/eventBus.js.map +1 -0
- package/dist/eventBus.mjs +29 -0
- package/dist/eventBus.mjs.map +1 -0
- package/dist/loadScript.d.mts +10 -0
- package/dist/loadScript.d.ts +10 -0
- package/dist/loadScript.js +80 -0
- package/dist/loadScript.js.map +1 -0
- package/dist/loadScript.mjs +7 -0
- package/dist/loadScript.mjs.map +1 -0
- package/dist/loadTernUIScript.d.mts +24 -0
- package/dist/loadTernUIScript.d.ts +24 -0
- package/dist/loadTernUIScript.js +140 -0
- package/dist/loadTernUIScript.js.map +1 -0
- package/dist/loadTernUIScript.mjs +63 -0
- package/dist/loadTernUIScript.mjs.map +1 -0
- package/dist/react/index.d.mts +54 -0
- package/dist/react/index.d.ts +54 -0
- package/dist/react/index.js +116 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/index.mjs +68 -0
- package/dist/react/index.mjs.map +1 -0
- package/dist/retry.d.mts +46 -0
- package/dist/retry.d.ts +46 -0
- package/dist/retry.js +85 -0
- package/dist/retry.js.map +1 -0
- package/dist/retry.mjs +60 -0
- package/dist/retry.mjs.map +1 -0
- package/dist/types/derivedAuthState.d.ts +7 -0
- package/dist/types/derivedAuthState.d.ts.map +1 -0
- package/dist/types/eventBus.d.ts +7 -0
- package/dist/types/eventBus.d.ts.map +1 -0
- package/dist/types/loadScript.d.ts +10 -0
- package/dist/types/loadScript.d.ts.map +1 -0
- package/dist/types/loadTernUIScript.d.ts +22 -0
- package/dist/types/loadTernUIScript.d.ts.map +1 -0
- package/dist/types/nextjs/client/auth-actions.d.ts +1 -0
- package/dist/types/nextjs/client/auth-actions.d.ts.map +1 -0
- package/dist/types/react/hooks/index.d.ts +2 -0
- package/dist/types/react/hooks/index.d.ts.map +1 -0
- package/dist/types/react/hooks/useTernSecure.d.ts +3 -0
- package/dist/types/react/hooks/useTernSecure.d.ts.map +1 -0
- package/dist/types/react/index.d.ts +4 -0
- package/dist/types/react/index.d.ts.map +1 -0
- package/dist/types/react/ternsecureCtx.d.ts +26 -0
- package/dist/types/react/ternsecureCtx.d.ts.map +1 -0
- package/dist/types/react/ternsecureProvider.d.ts +20 -0
- package/dist/types/react/ternsecureProvider.d.ts.map +1 -0
- package/dist/types/retry.d.ts +46 -0
- package/dist/types/retry.d.ts.map +1 -0
- package/package.json +88 -0
package/dist/retry.mjs
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// src/retry.ts
|
|
2
|
+
var defaultOptions = {
|
|
3
|
+
initialDelay: 125,
|
|
4
|
+
maxDelayBetweenRetries: 0,
|
|
5
|
+
factor: 2,
|
|
6
|
+
shouldRetry: (_, iteration) => iteration < 5,
|
|
7
|
+
retryImmediately: false,
|
|
8
|
+
jitter: true
|
|
9
|
+
};
|
|
10
|
+
var RETRY_IMMEDIATELY_DELAY = 100;
|
|
11
|
+
var sleep = async (ms) => new Promise((s) => setTimeout(s, ms));
|
|
12
|
+
var applyJitter = (delay, jitter) => {
|
|
13
|
+
return jitter ? delay * (1 + Math.random()) : delay;
|
|
14
|
+
};
|
|
15
|
+
var createExponentialDelayAsyncFn = (opts) => {
|
|
16
|
+
let timesCalled = 0;
|
|
17
|
+
const calculateDelayInMs = () => {
|
|
18
|
+
const constant = opts.initialDelay;
|
|
19
|
+
const base = opts.factor;
|
|
20
|
+
let delay = constant * Math.pow(base, timesCalled);
|
|
21
|
+
delay = applyJitter(delay, opts.jitter);
|
|
22
|
+
return Math.min(opts.maxDelayBetweenRetries || delay, delay);
|
|
23
|
+
};
|
|
24
|
+
return async () => {
|
|
25
|
+
await sleep(calculateDelayInMs());
|
|
26
|
+
timesCalled++;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
var retry = async (callback, options = {}) => {
|
|
30
|
+
let iterations = 0;
|
|
31
|
+
const { shouldRetry, initialDelay, maxDelayBetweenRetries, factor, retryImmediately, jitter } = {
|
|
32
|
+
...defaultOptions,
|
|
33
|
+
...options
|
|
34
|
+
};
|
|
35
|
+
const delay = createExponentialDelayAsyncFn({
|
|
36
|
+
initialDelay,
|
|
37
|
+
maxDelayBetweenRetries,
|
|
38
|
+
factor,
|
|
39
|
+
jitter
|
|
40
|
+
});
|
|
41
|
+
while (true) {
|
|
42
|
+
try {
|
|
43
|
+
return await callback();
|
|
44
|
+
} catch (e) {
|
|
45
|
+
iterations++;
|
|
46
|
+
if (!shouldRetry(e, iterations)) {
|
|
47
|
+
throw e;
|
|
48
|
+
}
|
|
49
|
+
if (retryImmediately && iterations === 1) {
|
|
50
|
+
await sleep(applyJitter(RETRY_IMMEDIATELY_DELAY, jitter));
|
|
51
|
+
} else {
|
|
52
|
+
await delay();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
export {
|
|
58
|
+
retry
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=retry.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/retry.ts"],"sourcesContent":["type Milliseconds = number;\n\ntype RetryOptions = Partial<{\n /**\n * The initial delay before the first retry.\n * @default 125\n */\n initialDelay: Milliseconds;\n /**\n * The maximum delay between retries.\n * The delay between retries will never exceed this value.\n * If set to 0, the delay will increase indefinitely.\n * @default 0\n */\n maxDelayBetweenRetries: Milliseconds;\n /**\n * The multiplier for the exponential backoff.\n * @default 2\n */\n factor: number;\n /**\n * A function to determine if the operation should be retried.\n * The callback accepts the error that was thrown and the number of iterations.\n * The iterations variable references the number of retries AFTER attempt\n * that caused the error and starts at 1 (as in, this is the 1st, 2nd, nth retry).\n * @default (error, iterations) => iterations < 5\n */\n shouldRetry: (error: unknown, iterations: number) => boolean;\n /**\n * Controls whether the helper should retry the operation immediately once before applying exponential backoff.\n * The delay for the immediate retry is 100ms.\n * @default false\n */\n retryImmediately: boolean;\n /**\n * If true, the intervals will be multiplied by a factor in the range of [1,2].\n * @default true\n */\n jitter: boolean;\n}>;\n\nconst defaultOptions: Required<RetryOptions> = {\n initialDelay: 125,\n maxDelayBetweenRetries: 0,\n factor: 2,\n shouldRetry: (_: unknown, iteration: number) => iteration < 5,\n retryImmediately: false,\n jitter: true,\n};\n\nconst RETRY_IMMEDIATELY_DELAY = 100;\n\nconst sleep = async (ms: Milliseconds) => new Promise(s => setTimeout(s, ms));\n\nconst applyJitter = (delay: Milliseconds, jitter: boolean) => {\n return jitter ? delay * (1 + Math.random()) : delay;\n};\n\nconst createExponentialDelayAsyncFn = (\n opts: Required<Pick<RetryOptions, 'initialDelay' | 'maxDelayBetweenRetries' | 'factor' | 'jitter'>>,\n) => {\n let timesCalled = 0;\n\n const calculateDelayInMs = () => {\n const constant = opts.initialDelay;\n const base = opts.factor;\n let delay = constant * Math.pow(base, timesCalled);\n delay = applyJitter(delay, opts.jitter);\n return Math.min(opts.maxDelayBetweenRetries || delay, delay);\n };\n\n return async (): Promise<void> => {\n await sleep(calculateDelayInMs());\n timesCalled++;\n };\n};\n\n/**\n * Retries a callback until it succeeds or the shouldRetry function returns false.\n * See {@link RetryOptions} for the available options.\n */\nexport const retry = async <T>(callback: () => T | Promise<T>, options: RetryOptions = {}): Promise<T> => {\n let iterations = 0;\n const { shouldRetry, initialDelay, maxDelayBetweenRetries, factor, retryImmediately, jitter } = {\n ...defaultOptions,\n ...options,\n };\n\n const delay = createExponentialDelayAsyncFn({\n initialDelay,\n maxDelayBetweenRetries,\n factor,\n jitter,\n });\n\n while (true) {\n try {\n return await callback();\n } catch (e) {\n iterations++;\n if (!shouldRetry(e, iterations)) {\n throw e;\n }\n if (retryImmediately && iterations === 1) {\n await sleep(applyJitter(RETRY_IMMEDIATELY_DELAY, jitter));\n } else {\n await delay();\n }\n }\n }\n};\n"],"mappings":";AAyCA,IAAM,iBAAyC;AAAA,EAC7C,cAAc;AAAA,EACd,wBAAwB;AAAA,EACxB,QAAQ;AAAA,EACR,aAAa,CAAC,GAAY,cAAsB,YAAY;AAAA,EAC5D,kBAAkB;AAAA,EAClB,QAAQ;AACV;AAEA,IAAM,0BAA0B;AAEhC,IAAM,QAAQ,OAAO,OAAqB,IAAI,QAAQ,OAAK,WAAW,GAAG,EAAE,CAAC;AAE5E,IAAM,cAAc,CAAC,OAAqB,WAAoB;AAC5D,SAAO,SAAS,SAAS,IAAI,KAAK,OAAO,KAAK;AAChD;AAEA,IAAM,gCAAgC,CACpC,SACG;AACH,MAAI,cAAc;AAElB,QAAM,qBAAqB,MAAM;AAC/B,UAAM,WAAW,KAAK;AACtB,UAAM,OAAO,KAAK;AAClB,QAAI,QAAQ,WAAW,KAAK,IAAI,MAAM,WAAW;AACjD,YAAQ,YAAY,OAAO,KAAK,MAAM;AACtC,WAAO,KAAK,IAAI,KAAK,0BAA0B,OAAO,KAAK;AAAA,EAC7D;AAEA,SAAO,YAA2B;AAChC,UAAM,MAAM,mBAAmB,CAAC;AAChC;AAAA,EACF;AACF;AAMO,IAAM,QAAQ,OAAU,UAAgC,UAAwB,CAAC,MAAkB;AACxG,MAAI,aAAa;AACjB,QAAM,EAAE,aAAa,cAAc,wBAAwB,QAAQ,kBAAkB,OAAO,IAAI;AAAA,IAC9F,GAAG;AAAA,IACH,GAAG;AAAA,EACL;AAEA,QAAM,QAAQ,8BAA8B;AAAA,IAC1C;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAED,SAAO,MAAM;AACX,QAAI;AACF,aAAO,MAAM,SAAS;AAAA,IACxB,SAAS,GAAG;AACV;AACA,UAAI,CAAC,YAAY,GAAG,UAAU,GAAG;AAC/B,cAAM;AAAA,MACR;AACA,UAAI,oBAAoB,eAAe,GAAG;AACxC,cAAM,MAAM,YAAY,yBAAyB,MAAM,CAAC;AAAA,MAC1D,OAAO;AACL,cAAM,MAAM;AAAA,MACd;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { TernSecureState } from "@tern-secure/types";
|
|
2
|
+
/**
|
|
3
|
+
* Default state for derived auth state
|
|
4
|
+
*/
|
|
5
|
+
export declare const DEFAULT_TERN_SECURE_STATE: TernSecureState;
|
|
6
|
+
export declare const deriveAuthState: (internalState: TernSecureState | undefined) => TernSecureState;
|
|
7
|
+
//# sourceMappingURL=derivedAuthState.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"derivedAuthState.d.ts","sourceRoot":"","sources":["../../src/derivedAuthState.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,eAAe,EAGlB,MAAM,oBAAoB,CAAC;AAG5B;;GAEG;AAGH,eAAO,MAAM,yBAAyB,EAAE,eAYvC,CAAC;AAGF,eAAO,MAAM,eAAe,GAAI,eAAe,eAAe,GAAG,SAAS,KAAI,eAgC7E,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare class EventEmitter {
|
|
2
|
+
private listeners;
|
|
3
|
+
on(eventName: string, listener: (...args: any[]) => void): () => void;
|
|
4
|
+
emit(eventName: string, ...args: any[]): void;
|
|
5
|
+
off(eventName: string, listener: (...args: any[]) => void): void;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=eventBus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eventBus.d.ts","sourceRoot":"","sources":["../../src/eventBus.ts"],"names":[],"mappings":"AAAA,qBAAa,YAAY;IACrB,OAAO,CAAC,SAAS,CAAgE;IAEjF,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,MAAM,IAAI;IAUrE,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI;IAM7C,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,IAAI;CAKnE"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type LoadScriptOptions = {
|
|
2
|
+
async?: boolean;
|
|
3
|
+
defer?: boolean;
|
|
4
|
+
crossOrigin?: 'anonymous' | 'use-credentials';
|
|
5
|
+
nonce?: string;
|
|
6
|
+
beforeLoad?: (script: HTMLScriptElement) => void;
|
|
7
|
+
};
|
|
8
|
+
export declare function loadScript(src: string | undefined, options: LoadScriptOptions): Promise<HTMLScriptElement>;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=loadScript.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadScript.d.ts","sourceRoot":"","sources":["../../src/loadScript.ts"],"names":[],"mappings":"AAEE,KAAK,iBAAiB,GAAG;IACvB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,WAAW,CAAC,EAAE,WAAW,GAAG,iBAAiB,CAAC;IAC9C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,IAAI,CAAC;CAClD,CAAC;AAEF,wBAAsB,UAAU,CAAC,GAAG,oBAAI,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAgEhG"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { TernSecureInstanceTreeOptions } from "@tern-secure/types";
|
|
2
|
+
export type LoadTernUISCriptOptions = TernSecureInstanceTreeOptions & {
|
|
3
|
+
apiKey?: string;
|
|
4
|
+
customDomain?: string;
|
|
5
|
+
proxyUrl?: string;
|
|
6
|
+
version?: string;
|
|
7
|
+
isLocalDev?: boolean;
|
|
8
|
+
scriptHost?: string;
|
|
9
|
+
localPort?: string;
|
|
10
|
+
nonce?: string;
|
|
11
|
+
};
|
|
12
|
+
export declare const loadTernUIScript: (options?: LoadTernUISCriptOptions) => Promise<unknown>;
|
|
13
|
+
export declare const ternUIgetScriptUrl: (options?: LoadTernUISCriptOptions) => string;
|
|
14
|
+
export declare const constructScriptAttributes: (options?: LoadTernUISCriptOptions) => {
|
|
15
|
+
nonce?: string | undefined;
|
|
16
|
+
'data-domain': string;
|
|
17
|
+
'data-apikey': string;
|
|
18
|
+
'data-environment': string;
|
|
19
|
+
'data-proxyUrl': string;
|
|
20
|
+
'data-version': string;
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=loadTernUIScript.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadTernUIScript.d.ts","sourceRoot":"","sources":["../../src/loadTernUIScript.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,oBAAoB,CAAC;AAIxE,MAAM,MAAM,uBAAuB,GAAG,6BAA6B,GAAG;IACpE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAA;AAED,eAAO,MAAM,gBAAgB,GAAU,UAAU,uBAAuB,qBA4BrE,CAAA;AAEH,eAAO,MAAM,kBAAkB,GAAI,UAAU,uBAAuB,WAiBnE,CAAA;AAWD,eAAO,MAAM,yBAAyB,GAAI,UAAU,uBAAuB;;;;;;;CAS1E,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=auth-actions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-actions.d.ts","sourceRoot":"","sources":["../../../../src/nextjs/client/auth-actions.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/react/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTernSecure.d.ts","sourceRoot":"","sources":["../../../../src/react/hooks/useTernSecure.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,sBAAsB,EACzB,MAAM,oBAAoB,CAAC;AAM5B,eAAO,MAAM,aAAa,QAAO,sBAYhC,CAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export * from './hooks';
|
|
2
|
+
export { useAssertWrappedByTernSecureProvider, useTernSecureInstanceContext, useTernSecureAuthContext, useSessionContext, useUserContext, SessionContext, UserContext, TernSecureAuthContext, TernSecureInstanceContext } from './ternsecureProvider';
|
|
3
|
+
export { assertContextExists, createContextAndHook } from './ternsecureCtx';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AAEvB,OAAO,EACH,oCAAoC,EACpC,4BAA4B,EAC5B,wBAAwB,EACxB,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,WAAW,EACX,qBAAqB,EACrB,yBAAyB,EAC5B,MAAM,sBAAsB,CAAA;AAE7B,OAAO,EACH,mBAAmB,EACnB,oBAAoB,EACvB,MAAM,iBAAiB,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Assert that the context value exists, otherwise throw an error.
|
|
4
|
+
*
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export declare function assertContextExists(contextVal: unknown, msgOrCtx: string | React.Context<any>): asserts contextVal;
|
|
8
|
+
type Options = {
|
|
9
|
+
assertCtxFn?: (v: unknown, msg: string) => void;
|
|
10
|
+
};
|
|
11
|
+
type ContextAndHook<T> = React.Context<{
|
|
12
|
+
value: T;
|
|
13
|
+
} | undefined>;
|
|
14
|
+
type UseCtxFn<T> = () => T;
|
|
15
|
+
/**
|
|
16
|
+
* Create and return a Context and two hooks that return the context value.
|
|
17
|
+
* The Context type is derived from the type passed in by the user.
|
|
18
|
+
*
|
|
19
|
+
* The first hook returned guarantees that the context exists so the returned value is always `CtxValue`
|
|
20
|
+
* The second hook makes no guarantees, so the returned value can be `CtxValue | undefined`
|
|
21
|
+
*
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export declare const createContextAndHook: <CtxValue>(displayName: string, options?: Options) => [ContextAndHook<CtxValue>, UseCtxFn<CtxValue>, UseCtxFn<CtxValue | Partial<CtxValue>>];
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=ternsecureCtx.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ternsecureCtx.d.ts","sourceRoot":"","sources":["../../../src/react/ternsecureCtx.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,UAAU,CAIlH;AACD,KAAK,OAAO,GAAG;IAAE,WAAW,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;CAAE,CAAC;AACnE,KAAK,cAAc,CAAC,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC;IAAE,KAAK,EAAE,CAAC,CAAA;CAAE,GAAG,SAAS,CAAC,CAAC;AACjE,KAAK,QAAQ,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC;AAE3B;;;;;;;;GAQG;AAEH,eAAO,MAAM,oBAAoB,GAAI,QAAQ,EAC3C,aAAa,MAAM,EACnB,UAAU,OAAO,KAChB,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,CAyBvF,CAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { TernSecureAuthProvider, TernSecureInstanceTree, TernSecureState } from '@tern-secure/types';
|
|
2
|
+
export type TernSecureAuthContextType = {
|
|
3
|
+
authProvider: TernSecureAuthProvider | null | undefined;
|
|
4
|
+
authState: TernSecureState;
|
|
5
|
+
};
|
|
6
|
+
declare const TernSecureInstanceContext: import("react").Context<{
|
|
7
|
+
value: TernSecureInstanceTree;
|
|
8
|
+
} | undefined>, useTernSecureInstanceContext: () => TernSecureInstanceTree;
|
|
9
|
+
declare const TernSecureAuthContext: import("react").Context<{
|
|
10
|
+
value: TernSecureAuthContextType;
|
|
11
|
+
} | undefined>, useTernSecureAuthContext: () => TernSecureAuthContextType;
|
|
12
|
+
declare const SessionContext: import("react").Context<{
|
|
13
|
+
value: import("@tern-secure/types").SignedInSession | null;
|
|
14
|
+
} | undefined>, useSessionContext: () => import("@tern-secure/types").SignedInSession | null;
|
|
15
|
+
declare const UserContext: import("react").Context<{
|
|
16
|
+
value: import("@tern-secure/types").TernSecureUser | null;
|
|
17
|
+
} | undefined>, useUserContext: () => import("@tern-secure/types").TernSecureUser | null;
|
|
18
|
+
declare function useAssertWrappedByTernSecureProvider(displayNameOrFn: string | (() => void)): void;
|
|
19
|
+
export { TernSecureInstanceContext, TernSecureAuthContext, SessionContext, UserContext, useTernSecureAuthContext, useSessionContext, useUserContext, useTernSecureInstanceContext, useAssertWrappedByTernSecureProvider };
|
|
20
|
+
//# sourceMappingURL=ternsecureProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ternsecureProvider.d.ts","sourceRoot":"","sources":["../../../src/react/ternsecureProvider.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,sBAAsB,EACtB,sBAAsB,EACtB,eAAe,EAChB,MAAM,oBAAoB,CAAC;AAG5B,MAAM,MAAM,yBAAyB,GAAG;IACtC,YAAY,EAAE,sBAAsB,GAAG,IAAI,GAAG,SAAS,CAAC;IACxD,SAAS,EAAE,eAAe,CAAC;CAC5B,CAAA;AAID,QAAA,MAAO,yBAAyB;;gBAAE,4BAA4B,8BACa,CAAC;AAE5E,QAAA,MAAO,qBAAqB;;gBAAE,wBAAwB,iCACoB,CAAC;AAE3E,QAAA,MAAO,cAAc;;gBAAE,iBAAiB,2DACyC,CAAC;AAElF,QAAA,MAAO,WAAW;;gBAAE,cAAc,0DACyC,CAAC;AAG5E,iBAAS,oCAAoC,CAAC,eAAe,EAAE,MAAM,GAAG,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAkB1F;AAGD,OAAO,EACL,yBAAyB,EACzB,qBAAqB,EACrB,cAAc,EACd,WAAW,EACX,wBAAwB,EACxB,iBAAiB,EACjB,cAAc,EACd,4BAA4B,EAC5B,oCAAoC,EACrC,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
type Milliseconds = number;
|
|
2
|
+
type RetryOptions = Partial<{
|
|
3
|
+
/**
|
|
4
|
+
* The initial delay before the first retry.
|
|
5
|
+
* @default 125
|
|
6
|
+
*/
|
|
7
|
+
initialDelay: Milliseconds;
|
|
8
|
+
/**
|
|
9
|
+
* The maximum delay between retries.
|
|
10
|
+
* The delay between retries will never exceed this value.
|
|
11
|
+
* If set to 0, the delay will increase indefinitely.
|
|
12
|
+
* @default 0
|
|
13
|
+
*/
|
|
14
|
+
maxDelayBetweenRetries: Milliseconds;
|
|
15
|
+
/**
|
|
16
|
+
* The multiplier for the exponential backoff.
|
|
17
|
+
* @default 2
|
|
18
|
+
*/
|
|
19
|
+
factor: number;
|
|
20
|
+
/**
|
|
21
|
+
* A function to determine if the operation should be retried.
|
|
22
|
+
* The callback accepts the error that was thrown and the number of iterations.
|
|
23
|
+
* The iterations variable references the number of retries AFTER attempt
|
|
24
|
+
* that caused the error and starts at 1 (as in, this is the 1st, 2nd, nth retry).
|
|
25
|
+
* @default (error, iterations) => iterations < 5
|
|
26
|
+
*/
|
|
27
|
+
shouldRetry: (error: unknown, iterations: number) => boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Controls whether the helper should retry the operation immediately once before applying exponential backoff.
|
|
30
|
+
* The delay for the immediate retry is 100ms.
|
|
31
|
+
* @default false
|
|
32
|
+
*/
|
|
33
|
+
retryImmediately: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* If true, the intervals will be multiplied by a factor in the range of [1,2].
|
|
36
|
+
* @default true
|
|
37
|
+
*/
|
|
38
|
+
jitter: boolean;
|
|
39
|
+
}>;
|
|
40
|
+
/**
|
|
41
|
+
* Retries a callback until it succeeds or the shouldRetry function returns false.
|
|
42
|
+
* See {@link RetryOptions} for the available options.
|
|
43
|
+
*/
|
|
44
|
+
export declare const retry: <T>(callback: () => T | Promise<T>, options?: RetryOptions) => Promise<T>;
|
|
45
|
+
export {};
|
|
46
|
+
//# sourceMappingURL=retry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../src/retry.ts"],"names":[],"mappings":"AAAA,KAAK,YAAY,GAAG,MAAM,CAAC;AAE3B,KAAK,YAAY,GAAG,OAAO,CAAC;IAC1B;;;OAGG;IACH,YAAY,EAAE,YAAY,CAAC;IAC3B;;;;;OAKG;IACH,sBAAsB,EAAE,YAAY,CAAC;IACrC;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;;;;;OAMG;IACH,WAAW,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC;IAC7D;;;;OAIG;IACH,gBAAgB,EAAE,OAAO,CAAC;IAC1B;;;OAGG;IACH,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC,CAAC;AAsCH;;;GAGG;AACH,eAAO,MAAM,KAAK,GAAU,CAAC,EAAE,UAAU,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,EAAE,UAAS,YAAiB,KAAG,OAAO,CAAC,CAAC,CA6BpG,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tern-secure/shared",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/TernSecure/typescript.git",
|
|
7
|
+
"directory": "packages/shared"
|
|
8
|
+
},
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public"
|
|
11
|
+
},
|
|
12
|
+
"author": "Pacifique Kamugisha",
|
|
13
|
+
"license": "ISC",
|
|
14
|
+
"description": "Shared types and utilities for TernSecure projects",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"derivedAuthState",
|
|
18
|
+
"eventBus",
|
|
19
|
+
"loadScript",
|
|
20
|
+
"loadTernUIScript",
|
|
21
|
+
"retry"
|
|
22
|
+
],
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"import": {
|
|
26
|
+
"types": "./dist/index.d.mts",
|
|
27
|
+
"default": "./dist/index.mjs"
|
|
28
|
+
},
|
|
29
|
+
"require": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"default": "./dist/index.js"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"./*": {
|
|
35
|
+
"import": {
|
|
36
|
+
"types": "./dist/*.d.mts",
|
|
37
|
+
"default": "./dist/*.mjs"
|
|
38
|
+
},
|
|
39
|
+
"require": {
|
|
40
|
+
"types": "./dist/*.d.ts",
|
|
41
|
+
"default": "./dist/*.js"
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"./react": {
|
|
45
|
+
"import": {
|
|
46
|
+
"types": "./dist/react/index.d.mts",
|
|
47
|
+
"default": "./dist/react/index.mjs"
|
|
48
|
+
},
|
|
49
|
+
"require": {
|
|
50
|
+
"types": "./dist/react/index.d.ts",
|
|
51
|
+
"default": "./dist/react/index.js"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"main": "./dist/index.js",
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"prettier": "^3.3.3",
|
|
58
|
+
"rimraf": "^6.0.1",
|
|
59
|
+
"tsup": "^8.3.5",
|
|
60
|
+
"typescript": "^5.7.2"
|
|
61
|
+
},
|
|
62
|
+
"dependencies": {
|
|
63
|
+
"tslib": "2.4.1",
|
|
64
|
+
"@tern-secure/types": "1.0.0"
|
|
65
|
+
},
|
|
66
|
+
"peerDependencies": {
|
|
67
|
+
"react": "^19",
|
|
68
|
+
"react-dom": "^19"
|
|
69
|
+
},
|
|
70
|
+
"peerDependenciesMeta": {
|
|
71
|
+
"react": {
|
|
72
|
+
"optional": true
|
|
73
|
+
},
|
|
74
|
+
"react-dom": {
|
|
75
|
+
"optional": true
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
"engines": {
|
|
79
|
+
"node": ">=20"
|
|
80
|
+
},
|
|
81
|
+
"scripts": {
|
|
82
|
+
"clean": "rimraf dist",
|
|
83
|
+
"build": "pnpm clean && tsup && tsc -p tsconfig.add.json",
|
|
84
|
+
"dev": "tsup --watch",
|
|
85
|
+
"lint": "eslint src",
|
|
86
|
+
"format": "prettier --write \"src/**/*.{ts,tsx}\""
|
|
87
|
+
}
|
|
88
|
+
}
|