@sesamy/sesamy-js 1.115.1 → 1.116.1
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/auth0-plugin.d.ts +14 -0
- package/dist/bootstrap.d.ts +62 -0
- package/dist/bootstrap.iife.js +1 -1
- package/dist/bootstrap.mjs +8 -8
- package/dist/capsule-plugin.d.ts +2 -0
- package/dist/sesamy-js.cjs +1 -1
- package/dist/sesamy-js.iife.js +1 -1
- package/dist/sesamy-js.mjs +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AuthPlugin } from '@sesamy/sesamy-js';
|
|
2
|
+
export declare const ACCESS_TOKEN_KEY = "sesamyAccessToken";
|
|
3
|
+
export declare const REFRESH_TOKEN_KEY = "sesamyRefreshToken";
|
|
4
|
+
export declare const SILENT_AUTH_THROTTLE_KEY = "sesamySilentAuthThrottle";
|
|
5
|
+
export declare const SESSION_HINT_COOKIE = "sesamy_is_authenticated";
|
|
6
|
+
export declare const SILENT_REDIRECT_STATE_KEY = "sesamySilentRedirectState";
|
|
7
|
+
export interface JwtPayload {
|
|
8
|
+
sub: string;
|
|
9
|
+
exp: number;
|
|
10
|
+
iat: number;
|
|
11
|
+
iss: string;
|
|
12
|
+
vendor_id: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function createAuth0Plugin(): AuthPlugin;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sesamy bootstrap loader.
|
|
3
|
+
*
|
|
4
|
+
* A tiny dependency-free loader publishers embed inline in their page
|
|
5
|
+
* `<head>` before the main sesamy-js bundle. It has two jobs:
|
|
6
|
+
*
|
|
7
|
+
* 1. Kick off the `/auth/userinfo` request in parallel with the bundle
|
|
8
|
+
* download and stash the promise on `window.__sesamyBoot`. The main
|
|
9
|
+
* bundle picks this up instead of starting its own fetch, shaving the
|
|
10
|
+
* userinfo round-trip off the critical path.
|
|
11
|
+
*
|
|
12
|
+
* 2. Load the main bundle with an optional fallback origin — if the
|
|
13
|
+
* primary `<script>` errors out or does not install `window[namespace]`
|
|
14
|
+
* within `fallbackTimeoutMs`, a secondary origin is tried. Intended
|
|
15
|
+
* for multi-cloud resilience (e.g. Cloudflare primary + AWS fallback).
|
|
16
|
+
*
|
|
17
|
+
* `sesamyBootstrap` is self-contained so `renderBootstrapScript()` can
|
|
18
|
+
* serialise it via `.toString()` for inline embedding in SSR templates.
|
|
19
|
+
* Keep it byte-conscious — it ships inline on every page render.
|
|
20
|
+
*/
|
|
21
|
+
export interface BootstrapOptions {
|
|
22
|
+
/**
|
|
23
|
+
* Your Sesamy client id. When provided, the bundle URL defaults to
|
|
24
|
+
* `https://scripts.sesamy.com/s/{clientId}/sesamy-js/{version}.js` (the
|
|
25
|
+
* `.js` suffix selects the IIFE build — the bootstrap injects a classic
|
|
26
|
+
* `<script>`, which cannot parse the ESM served at the bare URL). Either
|
|
27
|
+
* `clientId` or an explicit `src` is required.
|
|
28
|
+
*/
|
|
29
|
+
clientId?: string;
|
|
30
|
+
/** Version channel served by scripts-host. Defaults to `stable`. */
|
|
31
|
+
version?: string;
|
|
32
|
+
/** Override the primary bundle URL. Takes precedence over `clientId`. */
|
|
33
|
+
src?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Which scripts-host origin to resolve `clientId` against. `'prod'`
|
|
36
|
+
* (default) uses `scripts.sesamy.com`; `'dev'` uses `scripts.sesamy.dev`.
|
|
37
|
+
* Ignored when `src` is set.
|
|
38
|
+
*/
|
|
39
|
+
environment?: 'dev' | 'prod';
|
|
40
|
+
/** Optional secondary origin loaded if the primary fails. */
|
|
41
|
+
fallbackSrc?: string;
|
|
42
|
+
/** Timeout before the fallback is attempted. Defaults to 3000. */
|
|
43
|
+
fallbackTimeoutMs?: number;
|
|
44
|
+
/** Base URL for the `/auth/userinfo` prefetch. Defaults to same origin. */
|
|
45
|
+
apiBaseUrl?: string;
|
|
46
|
+
/** Namespace the bundle installs on `window`. Defaults to `sesamy`. */
|
|
47
|
+
namespace?: string;
|
|
48
|
+
/** Skip the userinfo prefetch (e.g. when using SSR id-token injection). */
|
|
49
|
+
skipAuthPrefetch?: boolean;
|
|
50
|
+
}
|
|
51
|
+
declare global {
|
|
52
|
+
interface Window {
|
|
53
|
+
__sesamyBoot?: Promise<Record<string, unknown> | null>;
|
|
54
|
+
sesamyBootstrap?: (options: BootstrapOptions) => void;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export declare function sesamyBootstrap(o: BootstrapOptions): void;
|
|
58
|
+
/**
|
|
59
|
+
* Serialise `sesamyBootstrap` plus its options into an inline-ready script
|
|
60
|
+
* body for injection into a `<script>` tag in server-rendered HTML.
|
|
61
|
+
*/
|
|
62
|
+
export declare function renderBootstrapScript(options: BootstrapOptions): string;
|
package/dist/bootstrap.iife.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var sesamyBootstrap=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(e){let t=e.namespace||`sesamy`,n=e.fallbackSrc,r=e.
|
|
1
|
+
var sesamyBootstrap=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(e){let t=e.namespace||`sesamy`,n=e.fallbackSrc,r=e.environment===`dev`?`scripts.sesamy.dev`:`scripts.sesamy.com`,i=e.src||`https://`+r+`/s/`+e.clientId+`/sesamy-js/`+(e.version||`stable`)+`.js`,a=window;if(!e.skipAuthPrefetch&&!a.__sesamyBoot){let t=null;try{let e=sessionStorage.getItem(`sesamy:userinfo`);if(e){let n=JSON.parse(e),r=n._cachedAt;r&&Date.now()-r<=36e5&&(t=n)}}catch{}t?a.__sesamyBoot=Promise.resolve(t):(`; `+document.cookie).indexOf(`; sesamy_is_authenticated=true`)>=0&&(a.__sesamyBoot=fetch((e.apiBaseUrl||``)+`/auth/userinfo`,{credentials:`include`,headers:{Accept:`application/json`}}).then(e=>e.ok?e.json():null).catch(()=>null))}let o=!1,s=()=>{if(o||!n||a[t])return;o=!0;let e=document.createElement(`script`);e.src=n,e.async=!0,document.head.appendChild(e)},c=document.createElement(`script`);c.src=i,c.async=!0,c.onerror=s,document.head.appendChild(c),n&&setTimeout(s,e.fallbackTimeoutMs||3e3)}function n(e){return`(`+t.toString()+`)(`+JSON.stringify(e)+`);`}if(typeof window<`u`){window.sesamyBootstrap=t;try{let e=document.getElementById(`sesamy-js`),n=e&&e.textContent?JSON.parse(e.textContent):null;n&&n.clientId&&t({clientId:n.clientId})}catch{}}return e.renderBootstrapScript=n,e.sesamyBootstrap=t,e})({});
|
package/dist/bootstrap.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
//#region src/bootstrap.ts
|
|
2
2
|
function e(e) {
|
|
3
|
-
let t = e.namespace || "sesamy", n = e.fallbackSrc, r = e.
|
|
4
|
-
if (!e.skipAuthPrefetch && !
|
|
3
|
+
let t = e.namespace || "sesamy", n = e.fallbackSrc, r = e.environment === "dev" ? "scripts.sesamy.dev" : "scripts.sesamy.com", i = e.src || "https://" + r + "/s/" + e.clientId + "/sesamy-js/" + (e.version || "stable") + ".js", a = window;
|
|
4
|
+
if (!e.skipAuthPrefetch && !a.__sesamyBoot) {
|
|
5
5
|
let t = null;
|
|
6
6
|
try {
|
|
7
7
|
let e = sessionStorage.getItem("sesamy:userinfo");
|
|
@@ -10,18 +10,18 @@ function e(e) {
|
|
|
10
10
|
r && Date.now() - r <= 36e5 && (t = n);
|
|
11
11
|
}
|
|
12
12
|
} catch {}
|
|
13
|
-
t ?
|
|
13
|
+
t ? a.__sesamyBoot = Promise.resolve(t) : ("; " + document.cookie).indexOf("; sesamy_is_authenticated=true") >= 0 && (a.__sesamyBoot = fetch((e.apiBaseUrl || "") + "/auth/userinfo", {
|
|
14
14
|
credentials: "include",
|
|
15
15
|
headers: { Accept: "application/json" }
|
|
16
16
|
}).then((e) => e.ok ? e.json() : null).catch(() => null));
|
|
17
17
|
}
|
|
18
|
-
let
|
|
19
|
-
if (
|
|
20
|
-
|
|
18
|
+
let o = !1, s = () => {
|
|
19
|
+
if (o || !n || a[t]) return;
|
|
20
|
+
o = !0;
|
|
21
21
|
let e = document.createElement("script");
|
|
22
22
|
e.src = n, e.async = !0, document.head.appendChild(e);
|
|
23
|
-
},
|
|
24
|
-
|
|
23
|
+
}, c = document.createElement("script");
|
|
24
|
+
c.src = i, c.async = !0, c.onerror = s, document.head.appendChild(c), n && setTimeout(s, e.fallbackTimeoutMs || 3e3);
|
|
25
25
|
}
|
|
26
26
|
function t(t) {
|
|
27
27
|
return "(" + e.toString() + ")(" + JSON.stringify(t) + ");";
|