@sesamy/sesamy-js 1.117.0 → 1.118.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/bootstrap.d.ts +35 -11
- package/dist/bootstrap.iife.js +1 -1
- package/dist/bootstrap.mjs +40 -10
- 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
package/dist/bootstrap.d.ts
CHANGED
|
@@ -9,10 +9,13 @@
|
|
|
9
9
|
* bundle picks this up instead of starting its own fetch, shaving the
|
|
10
10
|
* userinfo round-trip off the critical path.
|
|
11
11
|
*
|
|
12
|
-
* 2. Load the
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
12
|
+
* 2. Load the script chain that publishers need to get a working sesamy-js
|
|
13
|
+
* app — the auth0-plugin (for SPA auth), capsule-plugin (when DCA is
|
|
14
|
+
* enabled), sesamy-components, and the sesamy-js core. The scripts are
|
|
15
|
+
* injected with `async = false` so the browser runs them in insertion
|
|
16
|
+
* order — core sees the plugin factories on `window` before auto-init.
|
|
17
|
+
* If the core fails or the primary origin never installs `window[ns]`
|
|
18
|
+
* within `fallbackTimeoutMs`, an optional fallback origin is tried.
|
|
16
19
|
*
|
|
17
20
|
* `sesamyBootstrap` is self-contained so `renderBootstrapScript()` can
|
|
18
21
|
* serialise it via `.toString()` for inline embedding in SSR templates.
|
|
@@ -20,16 +23,21 @@
|
|
|
20
23
|
*/
|
|
21
24
|
export interface BootstrapOptions {
|
|
22
25
|
/**
|
|
23
|
-
* Your Sesamy client id. When provided, the
|
|
24
|
-
* `https://scripts.sesamy.com/s/{clientId}/
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* `
|
|
26
|
+
* Your Sesamy client id. When provided, the script chain URLs default to
|
|
27
|
+
* `https://scripts.sesamy.com/s/{clientId}/{name}/{version}.js` (IIFE
|
|
28
|
+
* builds — the bootstrap injects classic `<script>` tags, which cannot
|
|
29
|
+
* parse the ESM served at the bare URL). Either `clientId` or an explicit
|
|
30
|
+
* `src` is required.
|
|
28
31
|
*/
|
|
29
32
|
clientId?: string;
|
|
30
33
|
/** Version channel served by scripts-host. Defaults to `stable`. */
|
|
31
34
|
version?: string;
|
|
32
|
-
/**
|
|
35
|
+
/**
|
|
36
|
+
* Override the primary core bundle URL. When set, the bootstrap loads
|
|
37
|
+
* only this one script and skips the plugin/components chain — intended
|
|
38
|
+
* as an escape hatch for custom CDNs or pre-assembled single-file
|
|
39
|
+
* bundles that include plugins themselves.
|
|
40
|
+
*/
|
|
33
41
|
src?: string;
|
|
34
42
|
/**
|
|
35
43
|
* Which scripts-host origin to resolve `clientId` against. `'prod'`
|
|
@@ -37,7 +45,7 @@ export interface BootstrapOptions {
|
|
|
37
45
|
* Ignored when `src` is set.
|
|
38
46
|
*/
|
|
39
47
|
environment?: 'dev' | 'prod';
|
|
40
|
-
/** Optional secondary origin loaded if the
|
|
48
|
+
/** Optional secondary origin loaded if the core script fails. */
|
|
41
49
|
fallbackSrc?: string;
|
|
42
50
|
/** Timeout before the fallback is attempted. Defaults to 3000. */
|
|
43
51
|
fallbackTimeoutMs?: number;
|
|
@@ -47,6 +55,22 @@ export interface BootstrapOptions {
|
|
|
47
55
|
namespace?: string;
|
|
48
56
|
/** Skip the userinfo prefetch (e.g. when using SSR id-token injection). */
|
|
49
57
|
skipAuthPrefetch?: boolean;
|
|
58
|
+
/** Skip automatic loading of sesamy-components. Defaults to false. */
|
|
59
|
+
skipComponents?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Override whether to load auth0-plugin. When undefined (the default), the
|
|
62
|
+
* bootstrap loads the plugin unless `auth.useHttpCookies === true` in the
|
|
63
|
+
* `<script id="sesamy-js">` config element. SSR templates that run the
|
|
64
|
+
* bootstrap before the config element is in the DOM should pass an explicit
|
|
65
|
+
* value here.
|
|
66
|
+
*/
|
|
67
|
+
loadAuth0Plugin?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Override whether to load capsule-plugin. When undefined (the default),
|
|
70
|
+
* the bootstrap loads the plugin when `capsule.enabled === true` in the
|
|
71
|
+
* config element. Same SSR caveat as `loadAuth0Plugin`.
|
|
72
|
+
*/
|
|
73
|
+
loadCapsulePlugin?: boolean;
|
|
50
74
|
}
|
|
51
75
|
declare global {
|
|
52
76
|
interface Window {
|
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.environment===`dev`?`scripts.sesamy.dev`:`scripts.sesamy.com`,
|
|
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.version||`stable`,i=e.environment===`dev`?`scripts.sesamy.dev`:`scripts.sesamy.com`,a={};try{let e=document.getElementById(`sesamy-js`);e&&e.textContent&&(a=JSON.parse(e.textContent)||{})}catch{}let o=e.clientId||a.clientId,s=o?`https://`+i+`/s/`+o:``,c=e.src||(o?s+`/sesamy-js/`+r+`.js`:void 0),l=!e.src&&!!s,u=window;if(!e.skipAuthPrefetch&&!u.__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?u.__sesamyBoot=Promise.resolve(t):(`; `+document.cookie).indexOf(`; sesamy_is_authenticated=true`)>=0&&(u.__sesamyBoot=fetch((e.apiBaseUrl||``)+`/auth/userinfo`,{credentials:`include`,headers:{Accept:`application/json`}}).then(e=>e.ok?e.json():null).catch(()=>null))}if(!c)return;let d=a.auth&&a.auth.useHttpCookies===!0,f=l&&(e.loadAuth0Plugin===void 0?!d:e.loadAuth0Plugin),p=l&&(e.loadCapsulePlugin===void 0?a.capsule&&a.capsule.enabled===!0:e.loadCapsulePlugin),m=l&&!e.skipComponents,h=[];f&&h.push(s+`/auth0-plugin/`+r+`.js`),p&&h.push(s+`/capsule-plugin/`+r+`.js`),m&&h.push(s+`/sesamy-components/`+r+`.js`),h.push(c);let g=!1,_=()=>{if(g||!n||u[t])return;g=!0;let e=document.createElement(`script`);e.src=n,e.async=!0,document.head.appendChild(e)},v=null;for(let e of h){let t=document.createElement(`script`);t.src=e,t.async=!1,document.head.appendChild(t),e===c&&(v=t)}v&&(v.onerror=_),n&&setTimeout(_,e.fallbackTimeoutMs||3e3)}function n(e){return`(`+t.toString()+`)(`+JSON.stringify(e)+`);`}var r=[`clientId`,`environment`,`version`,`src`,`fallbackSrc`,`fallbackTimeoutMs`,`apiBaseUrl`,`namespace`,`skipAuthPrefetch`,`skipComponents`,`loadAuth0Plugin`,`loadCapsulePlugin`];if(typeof window<`u`){window.sesamyBootstrap=t;try{let e=document.getElementById(`sesamy-js`),n=e&&e.textContent?JSON.parse(e.textContent):null;if(n&&(n.clientId||n.src)){let e={};for(let t of r)n[t]!==void 0&&(e[t]=n[t]);t(e)}}catch{}}return e.renderBootstrapScript=n,e.sesamyBootstrap=t,e})({});
|
package/dist/bootstrap.mjs
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
//#region src/bootstrap.ts
|
|
2
2
|
function e(e) {
|
|
3
|
-
let t = e.namespace || "sesamy", n = e.fallbackSrc, r = e.
|
|
4
|
-
|
|
3
|
+
let t = e.namespace || "sesamy", n = e.fallbackSrc, r = e.version || "stable", i = e.environment === "dev" ? "scripts.sesamy.dev" : "scripts.sesamy.com", a = {};
|
|
4
|
+
try {
|
|
5
|
+
let e = document.getElementById("sesamy-js");
|
|
6
|
+
e && e.textContent && (a = JSON.parse(e.textContent) || {});
|
|
7
|
+
} catch {}
|
|
8
|
+
let o = e.clientId || a.clientId, s = o ? "https://" + i + "/s/" + o : "", c = e.src || (o ? s + "/sesamy-js/" + r + ".js" : void 0), l = !e.src && !!s, u = window;
|
|
9
|
+
if (!e.skipAuthPrefetch && !u.__sesamyBoot) {
|
|
5
10
|
let t = null;
|
|
6
11
|
try {
|
|
7
12
|
let e = sessionStorage.getItem("sesamy:userinfo");
|
|
@@ -10,27 +15,52 @@ function e(e) {
|
|
|
10
15
|
r && Date.now() - r <= 36e5 && (t = n);
|
|
11
16
|
}
|
|
12
17
|
} catch {}
|
|
13
|
-
t ?
|
|
18
|
+
t ? u.__sesamyBoot = Promise.resolve(t) : ("; " + document.cookie).indexOf("; sesamy_is_authenticated=true") >= 0 && (u.__sesamyBoot = fetch((e.apiBaseUrl || "") + "/auth/userinfo", {
|
|
14
19
|
credentials: "include",
|
|
15
20
|
headers: { Accept: "application/json" }
|
|
16
21
|
}).then((e) => e.ok ? e.json() : null).catch(() => null));
|
|
17
22
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
23
|
+
if (!c) return;
|
|
24
|
+
let d = a.auth && a.auth.useHttpCookies === !0, f = l && (e.loadAuth0Plugin === void 0 ? !d : e.loadAuth0Plugin), p = l && (e.loadCapsulePlugin === void 0 ? a.capsule && a.capsule.enabled === !0 : e.loadCapsulePlugin), m = l && !e.skipComponents, h = [];
|
|
25
|
+
f && h.push(s + "/auth0-plugin/" + r + ".js"), p && h.push(s + "/capsule-plugin/" + r + ".js"), m && h.push(s + "/sesamy-components/" + r + ".js"), h.push(c);
|
|
26
|
+
let g = !1, _ = () => {
|
|
27
|
+
if (g || !n || u[t]) return;
|
|
28
|
+
g = !0;
|
|
21
29
|
let e = document.createElement("script");
|
|
22
30
|
e.src = n, e.async = !0, document.head.appendChild(e);
|
|
23
|
-
},
|
|
24
|
-
|
|
31
|
+
}, v = null;
|
|
32
|
+
for (let e of h) {
|
|
33
|
+
let t = document.createElement("script");
|
|
34
|
+
t.src = e, t.async = !1, document.head.appendChild(t), e === c && (v = t);
|
|
35
|
+
}
|
|
36
|
+
v && (v.onerror = _), n && setTimeout(_, e.fallbackTimeoutMs || 3e3);
|
|
25
37
|
}
|
|
26
38
|
function t(t) {
|
|
27
39
|
return "(" + e.toString() + ")(" + JSON.stringify(t) + ");";
|
|
28
40
|
}
|
|
41
|
+
var n = [
|
|
42
|
+
"clientId",
|
|
43
|
+
"environment",
|
|
44
|
+
"version",
|
|
45
|
+
"src",
|
|
46
|
+
"fallbackSrc",
|
|
47
|
+
"fallbackTimeoutMs",
|
|
48
|
+
"apiBaseUrl",
|
|
49
|
+
"namespace",
|
|
50
|
+
"skipAuthPrefetch",
|
|
51
|
+
"skipComponents",
|
|
52
|
+
"loadAuth0Plugin",
|
|
53
|
+
"loadCapsulePlugin"
|
|
54
|
+
];
|
|
29
55
|
if (typeof window < "u") {
|
|
30
56
|
window.sesamyBootstrap = e;
|
|
31
57
|
try {
|
|
32
|
-
let t = document.getElementById("sesamy-js"),
|
|
33
|
-
|
|
58
|
+
let t = document.getElementById("sesamy-js"), r = t && t.textContent ? JSON.parse(t.textContent) : null;
|
|
59
|
+
if (r && (r.clientId || r.src)) {
|
|
60
|
+
let t = {};
|
|
61
|
+
for (let e of n) r[e] !== void 0 && (t[e] = r[e]);
|
|
62
|
+
e(t);
|
|
63
|
+
}
|
|
34
64
|
} catch {}
|
|
35
65
|
}
|
|
36
66
|
//#endregion
|