@sesamy/sesamy-js 1.19.2 → 1.19.3

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.
@@ -1568,6 +1568,8 @@ for (var Qn in _u)
1568
1568
  Ru(fs[Qn] && fs[Qn].prototype, Qn);
1569
1569
  Ru(ew, "DOMTokenList");
1570
1570
  function ze(e, t) {
1571
+ if (typeof window > "u")
1572
+ return;
1571
1573
  const r = new CustomEvent(e, {
1572
1574
  detail: t,
1573
1575
  bubbles: !0,
@@ -4621,10 +4623,19 @@ function iS() {
4621
4623
  return e || (e = Math.random().toString(36).slice(2, 9), sessionStorage.setItem(tc, e)), e;
4622
4624
  }
4623
4625
  let bl = !1, Fa, rc, Zr;
4626
+ const Sl = /* @__PURE__ */ new Map();
4624
4627
  function oS({ clientId: e, enabled: t = !0, environment: r }) {
4625
4628
  if (Fa = e, rc = t, Zr = `${Ue("logs", r)}/events`, !rc)
4626
4629
  return;
4627
- Zb();
4630
+ window.addEventListener("beforeunload", () => {
4631
+ $l.forEach((a, i) => {
4632
+ a.bind(i)();
4633
+ }), cS();
4634
+ }), window.addEventListener("visibilitychange", () => {
4635
+ document.visibilityState !== "visible" && Sl.forEach((a, i) => {
4636
+ a.bind(i)();
4637
+ });
4638
+ }), Zb();
4628
4639
  const n = new aS({
4629
4640
  element: document.body,
4630
4641
  viewCallback: () => {
@@ -4661,7 +4672,7 @@ function oS({ clientId: e, enabled: t = !0, environment: r }) {
4661
4672
  await _e.track("logout", {}), ji.flush(), await _e.reset();
4662
4673
  });
4663
4674
  }
4664
- function Sl(e) {
4675
+ function Il(e) {
4665
4676
  return JSON.stringify(
4666
4677
  e.map((t) => ({
4667
4678
  ...t,
@@ -4690,7 +4701,7 @@ function Sl(e) {
4690
4701
  const ji = Kb(
4691
4702
  async (e) => {
4692
4703
  if (e.length > 0) {
4693
- const t = Sl(e);
4704
+ const t = Il(e);
4694
4705
  bl ? navigator.sendBeacon(Zr, t) : (await fetch(Zr, {
4695
4706
  method: "POST",
4696
4707
  body: t,
@@ -4711,7 +4722,7 @@ function la(e) {
4711
4722
  var t;
4712
4723
  if (e.anonymousId) if ((t = e.properties) != null && t.flushing) {
4713
4724
  const r = { ...e };
4714
- delete r.properties.flushing, navigator.sendBeacon(Zr, Sl([r]));
4725
+ delete r.properties.flushing, navigator.sendBeacon(Zr, Il([r]));
4715
4726
  } else
4716
4727
  ji.push(e);
4717
4728
  }
@@ -4760,24 +4771,13 @@ function sS(e, t) {
4760
4771
  function cS() {
4761
4772
  return bl = !0, ji.flush();
4762
4773
  }
4763
- const Il = /* @__PURE__ */ new Map();
4774
+ const $l = /* @__PURE__ */ new Map();
4764
4775
  function uS(e, t) {
4765
- Il.set(e, t);
4776
+ $l.set(e, t);
4766
4777
  }
4767
- window.addEventListener("beforeunload", () => {
4768
- Il.forEach((e, t) => {
4769
- e.bind(t)();
4770
- }), cS();
4771
- });
4772
- const $l = /* @__PURE__ */ new Map();
4773
4778
  function lS(e, t) {
4774
- $l.set(e, t);
4779
+ Sl.set(e, t);
4775
4780
  }
4776
- window.addEventListener("visibilitychange", () => {
4777
- document.visibilityState !== "visible" && $l.forEach((e, t) => {
4778
- e.bind(t)();
4779
- });
4780
- });
4781
4781
  const kl = "sesamySignedURLs";
4782
4782
  function Pl() {
4783
4783
  const e = sessionStorage.getItem(kl);
@@ -5002,8 +5002,10 @@ async function bS() {
5002
5002
  const n = new URL(window.location.href);
5003
5003
  n.searchParams.delete(cc), window.history.replaceState(null, "", n);
5004
5004
  }
5005
- async function SS(e) {
5006
- oS({
5005
+ const SS = typeof window < "u";
5006
+ async function IS(e) {
5007
+ const t = dS({ clientId: e.clientId, environment: e.environment, ...e.api });
5008
+ return ze(ye.READY, {}), SS && (oS({
5007
5009
  clientId: e.clientId,
5008
5010
  environment: e.environment,
5009
5011
  // The default client id can be overridden by the config
@@ -5014,20 +5016,18 @@ async function SS(e) {
5014
5016
  environment: e.environment,
5015
5017
  // The default client id can be overridden by the config
5016
5018
  ...e.auth
5017
- }), e.transform && await vS(e.transform);
5018
- const t = dS({ clientId: e.clientId, environment: e.environment, ...e.api });
5019
- return ze(ye.READY, {}), pS(), mS(), gS(), await bS(), await yS(), wS(), t;
5019
+ }), e.transform && await vS(e.transform), pS(), mS(), gS(), await bS(), await yS(), wS()), t;
5020
5020
  }
5021
5021
  if (typeof document < "u") {
5022
5022
  const e = document.getElementById("sesamy-js");
5023
5023
  if (e != null && e.textContent)
5024
5024
  try {
5025
5025
  const t = JSON.parse(e.textContent);
5026
- SS(t);
5026
+ IS(t);
5027
5027
  } catch (t) {
5028
5028
  console.error("Failed to parse config", t);
5029
5029
  }
5030
5030
  }
5031
5031
  export {
5032
- SS as init
5032
+ IS as init
5033
5033
  };
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "registry": "https://registry.npmjs.org/",
7
7
  "tag": "latest"
8
8
  },
9
- "version": "1.19.2",
9
+ "version": "1.19.3",
10
10
  "main": "dist/sesamy-js.cjs",
11
11
  "module": "dist/sesamy-js.mjs",
12
12
  "types": "dist/sesamy-js.d.ts",
@@ -22,6 +22,7 @@
22
22
  ],
23
23
  "scripts": {
24
24
  "dev": "vite",
25
+ "test": "vitest",
25
26
  "build": "rimraf build/**/* && tsc && vite build --config vite.dev.config.ts",
26
27
  "build:prod": "rimraf build/**/* && tsc && vite build && dts-bundle-generator --config ./dts-bundle-generator.config.ts && copyfiles ./package.json build && copyfiles ./README.md build",
27
28
  "preview": "vite preview",