@sesamy/sesamy-js 1.116.1 → 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.
@@ -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 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).
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 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.
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
- /** Override the primary bundle URL. Takes precedence over `clientId`. */
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 primary fails. */
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 {
@@ -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`,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})({});
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})({});
@@ -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.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) {
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 ? a.__sesamyBoot = Promise.resolve(t) : ("; " + document.cookie).indexOf("; sesamy_is_authenticated=true") >= 0 && (a.__sesamyBoot = fetch((e.apiBaseUrl || "") + "/auth/userinfo", {
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
- let o = !1, s = () => {
19
- if (o || !n || a[t]) return;
20
- o = !0;
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
- }, c = document.createElement("script");
24
- c.src = i, c.async = !0, c.onerror = s, document.head.appendChild(c), n && setTimeout(s, e.fallbackTimeoutMs || 3e3);
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"), n = t && t.textContent ? JSON.parse(t.textContent) : null;
33
- n && n.clientId && e({ clientId: n.clientId });
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