@sesamy/sesamy-js 1.21.7 → 1.21.8

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/README.md CHANGED
@@ -934,9 +934,10 @@ The transform configuration is defined within the `Config` interface. The follow
934
934
  Each rule object contains the following properties:
935
935
 
936
936
  - `selector` (string): A CSS selector to target elements on the page.
937
- - `transform` (string): The type of transformation to apply. Valid values are 'insert', 'replace', and 'remove'.
937
+ - `transform` (string): The type of transformation to apply. Valid values are 'insert', 'replace', 'remove' and 'gradient'.
938
938
  - `content` (string, optional): The content to insert or replace. Required for 'insert' and 'replace' transforms.
939
- - `contentType` (string): Specifies the type of content. Valid values are 'html', 'selector', and 'url'.
939
+ - 'insertPosition' (string, optional): The position to insert the content. Valid values are 'before', 'after' and 'insider'.
940
+ - `contentType` (string, optional): Specifies the type of content. Valid values are 'html', 'selector', and 'url'.
940
941
  - `path` (string, optional): A regular expression to match the URL path. If provided, the rule will only apply when the path matches the current URL.
941
942
  - `entitlement` (string, optional): Specifies an entitlement required for the rule to apply.
942
943
  - `authenticated` (boolean, optional): Specifies if the rule should only apply to authenticated users.
@@ -14,4 +14,4 @@ CAUSE: `+h.stack,$.response=w,$.status=w.status,$.url=c,w.type==="opaque")throw
14
14
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0), white);
15
15
  pointer-events: none;
16
16
  }
17
- `,document.head.appendChild(i)}async function gh(e){try{const t=await fetch(e);return t.ok?await t.text():(console.error(`Failed to fetch content from ${e}: ${t.statusText}`),null)}catch(t){return console.error(`Error fetching content from ${e}:`,t),null}}async function EE(e,t){if(t.contentType==="selector"&&t.content){const r=document.querySelector(t.content);r?e.innerHTML+=r.innerHTML:console.warn(`Source element for selector '${t.content}' not found`)}else if(t.contentType==="url"&&t.content){const r=await gh(t.content);r?e.innerHTML+=r:console.warn(`Failed to fetch content from URL '${t.content}'`)}else t.content&&(e.innerHTML+=t.content)}async function OE(e,t){if(t.contentType==="selector"&&t.content){const r=document.querySelector(t.content);r?e.innerHTML=r.innerHTML:console.warn(`Source element for selector '${t.content}' not found`)}else if(t.contentType==="url"&&t.content){const r=await gh(t.content);r?e.innerHTML=r:console.warn(`Failed to fetch content from URL '${t.content}'`)}else t.content&&(e.innerHTML=t.content)}async function kE({enabled:e=!1,rules:t}){if(!e)return;const r=await ra(),n=window.location.href;for(const a of t){const i=document.querySelectorAll(a.selector);if(!(a.path&&!new RegExp(a.path).test(n)))for(const o of i){const s=o;if(!(a.authenticated!==void 0&&a.authenticated!==r))switch(a.transform){case"insert":await EE(s,a);break;case"replace":await OE(s,a);break;case"remove":o.remove();break;case"gradient":PE(s,a);break;default:console.warn(`Unknown transform type: ${a.transform}`)}}}}function _E(){const e=new URLSearchParams(window.location.hash.substring(1)),t=e.get("access_token");if(t){Dd(t);const r=new URL(window.location.href);e.delete("access_token"),r.hash=e.toString(),window.history.replaceState(null,"",r)}}const vl="sesamy-refresh",pl="force-refetch-entitlements";function RE(){const e=new URLSearchParams(window.location.search),t=e.get(pl),r=e.get(vl);if(t!==null||r!==null){const n=new URL(window.location.href);e.delete(pl),e.delete(vl),n.search=e.toString(),Ie(),window.history.replaceState(null,"",n)}}function CE(e){const t=e.split(".")[1],r=atob(t);return JSON.parse(r)}function AE(){const e=new URLSearchParams(window.location.search),t=e.get("sesamy-token")||e.get("token");if(!t)return;try{const n=CE(t),a=new Date(n.exp*1e3),i={id:"",title:"Signed link",sku:n.s.toString(),purchaseOptionsId:n.pid.toString(),url:n.url.toString(),token:t,type:"article",expiresAt:a.toISOString(),createdAt:new Date(n.iat).toISOString(),updatedAt:new Date(n.iat).toISOString()};eP(i)}catch{}const r=new URL(window.location.href);r.searchParams.delete("ss"),r.searchParams.delete("se"),r.searchParams.delete("sp"),r.searchParams.delete("so"),r.searchParams.delete("token"),r.searchParams.delete("sesamy-token"),window.history.replaceState(null,"",r)}const ml="sesamy-user";async function jE(){var a;const t=(a=new URLSearchParams(window.location.search).get(ml))==null?void 0:a.toLowerCase();if(!t)return;const r=await DT();(r==null?void 0:r.email)!==t&&(Ie(),Xo({authorizationParams:{email_hint:t,login_hint:t}}));const n=new URL(window.location.href);n.searchParams.delete(ml),window.history.replaceState(null,"",n)}const gl="sesamy-purchase";function LE(){const e=new URLSearchParams(window.location.search),t=e.get(gl);if(t!==null){const r=new URL(window.location.href);e.delete(gl),r.search=e.toString(),Xe(Oe.PURCHASE,{itemSrc:t}),Ie(),window.history.replaceState(null,"",r)}}const yl="sesamy-login",NE="sesamy_login";async function xE(){const e=new URLSearchParams(window.location.search);if(!(e.get(yl)||e.get(NE)))return;await ra()||Xo();const n=new URL(window.location.href);n.searchParams.delete(yl),window.history.replaceState(null,"",n)}const UE=typeof window<"u";async function wl(e){pE({clientId:e.clientId,environment:e.environment,...e.analytics}),await UT({clientId:e.clientId,organization:e.organization,environment:e.environment,...e.auth}),e.transform&&await kE(e.transform),_E(),RE(),AE(),await xE(),await jE(),LE(),Xe(Oe.READY,{})}async function yh(e){const t=IE({clientId:e.clientId,environment:e.environment,...e.api});return UE&&(e.awaitAllServices?await wl(e):wl(e)),t}if(typeof document<"u"){const e=document.getElementById("sesamy-js");if(e!=null&&e.textContent)try{const t=JSON.parse(e.textContent);yh(t)}catch(t){console.error("Failed to parse config",t)}}exports.init=yh;
17
+ `,document.head.appendChild(i)}async function gh(e){try{const t=await fetch(e);return t.ok?await t.text():(console.error(`Failed to fetch content from ${e}: ${t.statusText}`),null)}catch(t){return console.error(`Error fetching content from ${e}:`,t),null}}async function EE(e,t,r="inside"){let n="";if(t.contentType==="selector"&&t.content){const a=document.querySelector(t.content);if(a)n=a.innerHTML;else{console.warn(`Source element for selector '${t.content}' not found`);return}}else if(t.contentType==="url"&&t.content){const a=await gh(t.content);if(a)n=a;else{console.warn(`Failed to fetch content from URL '${t.content}'`);return}}else t.content&&(n=t.content);switch(r){case"before":e.insertAdjacentHTML("beforebegin",n);break;case"after":e.insertAdjacentHTML("afterend",n);break;case"inside":default:e.innerHTML+=n;break}}async function OE(e,t){if(t.contentType==="selector"&&t.content){const r=document.querySelector(t.content);r?e.innerHTML=r.innerHTML:console.warn(`Source element for selector '${t.content}' not found`)}else if(t.contentType==="url"&&t.content){const r=await gh(t.content);r?e.innerHTML=r:console.warn(`Failed to fetch content from URL '${t.content}'`)}else t.content&&(e.innerHTML=t.content)}async function kE({enabled:e=!1,rules:t}){if(!e)return;const r=await ra(),n=window.location.href;for(const a of t){const i=document.querySelectorAll(a.selector);if(!(a.path&&!new RegExp(a.path).test(n)))for(const o of i){const s=o;if(!(a.authenticated!==void 0&&a.authenticated!==r))switch(a.transform){case"insert":await EE(s,a);break;case"replace":await OE(s,a);break;case"remove":o.remove();break;case"gradient":PE(s,a);break;default:console.warn(`Unknown transform type: ${a.transform}`)}}}}function _E(){const e=new URLSearchParams(window.location.hash.substring(1)),t=e.get("access_token");if(t){Dd(t);const r=new URL(window.location.href);e.delete("access_token"),r.hash=e.toString(),window.history.replaceState(null,"",r)}}const vl="sesamy-refresh",pl="force-refetch-entitlements";function RE(){const e=new URLSearchParams(window.location.search),t=e.get(pl),r=e.get(vl);if(t!==null||r!==null){const n=new URL(window.location.href);e.delete(pl),e.delete(vl),n.search=e.toString(),Ie(),window.history.replaceState(null,"",n)}}function CE(e){const t=e.split(".")[1],r=atob(t);return JSON.parse(r)}function AE(){const e=new URLSearchParams(window.location.search),t=e.get("sesamy-token")||e.get("token");if(!t)return;try{const n=CE(t),a=new Date(n.exp*1e3),i={id:"",title:"Signed link",sku:n.s.toString(),purchaseOptionsId:n.pid.toString(),url:n.url.toString(),token:t,type:"article",expiresAt:a.toISOString(),createdAt:new Date(n.iat).toISOString(),updatedAt:new Date(n.iat).toISOString()};eP(i)}catch{}const r=new URL(window.location.href);r.searchParams.delete("ss"),r.searchParams.delete("se"),r.searchParams.delete("sp"),r.searchParams.delete("so"),r.searchParams.delete("token"),r.searchParams.delete("sesamy-token"),window.history.replaceState(null,"",r)}const ml="sesamy-user";async function jE(){var a;const t=(a=new URLSearchParams(window.location.search).get(ml))==null?void 0:a.toLowerCase();if(!t)return;const r=await DT();(r==null?void 0:r.email)!==t&&(Ie(),Xo({authorizationParams:{email_hint:t,login_hint:t}}));const n=new URL(window.location.href);n.searchParams.delete(ml),window.history.replaceState(null,"",n)}const gl="sesamy-purchase";function LE(){const e=new URLSearchParams(window.location.search),t=e.get(gl);if(t!==null){const r=new URL(window.location.href);e.delete(gl),r.search=e.toString(),Xe(Oe.PURCHASE,{itemSrc:t}),Ie(),window.history.replaceState(null,"",r)}}const yl="sesamy-login",NE="sesamy_login";async function xE(){const e=new URLSearchParams(window.location.search);if(!(e.get(yl)||e.get(NE)))return;await ra()||Xo();const n=new URL(window.location.href);n.searchParams.delete(yl),window.history.replaceState(null,"",n)}const UE=typeof window<"u";async function wl(e){pE({clientId:e.clientId,environment:e.environment,...e.analytics}),await UT({clientId:e.clientId,organization:e.organization,environment:e.environment,...e.auth}),e.transform&&await kE(e.transform),_E(),RE(),AE(),await xE(),await jE(),LE(),Xe(Oe.READY,{})}async function yh(e){const t=IE({clientId:e.clientId,environment:e.environment,...e.api});return UE&&(e.awaitAllServices?await wl(e):wl(e)),t}if(typeof document<"u"){const e=document.getElementById("sesamy-js");if(e!=null&&e.textContent)try{const t=JSON.parse(e.textContent);yh(t)}catch(t){console.error("Failed to parse config",t)}}exports.init=yh;
@@ -41,6 +41,7 @@ export interface TransformRule {
41
41
  transform: "insert" | "replace" | "remove" | "gradient";
42
42
  content?: string;
43
43
  contentType: "html" | "selector" | "url";
44
+ insertionPoint?: "before" | "after" | "inside";
44
45
  path?: string;
45
46
  entitlement?: string;
46
47
  authenticated?: boolean;
@@ -14,4 +14,4 @@ CAUSE: `+h.stack,$.response=w,$.status=w.status,$.url=c,w.type==="opaque")throw
14
14
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0), white);
15
15
  pointer-events: none;
16
16
  }
17
- `,document.head.appendChild(i)}async function oh(e){try{const t=await fetch(e);return t.ok?await t.text():(console.error(`Failed to fetch content from ${e}: ${t.statusText}`),null)}catch(t){return console.error(`Error fetching content from ${e}:`,t),null}}async function TE(e,t){if(t.contentType==="selector"&&t.content){const r=document.querySelector(t.content);r?e.innerHTML+=r.innerHTML:console.warn(`Source element for selector '${t.content}' not found`)}else if(t.contentType==="url"&&t.content){const r=await oh(t.content);r?e.innerHTML+=r:console.warn(`Failed to fetch content from URL '${t.content}'`)}else t.content&&(e.innerHTML+=t.content)}async function PE(e,t){if(t.contentType==="selector"&&t.content){const r=document.querySelector(t.content);r?e.innerHTML=r.innerHTML:console.warn(`Source element for selector '${t.content}' not found`)}else if(t.contentType==="url"&&t.content){const r=await oh(t.content);r?e.innerHTML=r:console.warn(`Failed to fetch content from URL '${t.content}'`)}else t.content&&(e.innerHTML=t.content)}async function EE({enabled:e=!1,rules:t}){if(!e)return;const r=await Kn(),n=window.location.href;for(const a of t){const i=document.querySelectorAll(a.selector);if(!(a.path&&!new RegExp(a.path).test(n)))for(const o of i){const s=o;if(!(a.authenticated!==void 0&&a.authenticated!==r))switch(a.transform){case"insert":await TE(s,a);break;case"replace":await PE(s,a);break;case"remove":o.remove();break;case"gradient":IE(s,a);break;default:console.warn(`Unknown transform type: ${a.transform}`)}}}}function OE(){const e=new URLSearchParams(window.location.hash.substring(1)),t=e.get("access_token");if(t){Wf(t);const r=new URL(window.location.href);e.delete("access_token"),r.hash=e.toString(),window.history.replaceState(null,"",r)}}const sh="sesamy-refresh",ch="force-refetch-entitlements";function kE(){const e=new URLSearchParams(window.location.search),t=e.get(ch),r=e.get(sh);if(t!==null||r!==null){const n=new URL(window.location.href);e.delete(ch),e.delete(sh),n.search=e.toString(),Re(),window.history.replaceState(null,"",n)}}function _E(e){const t=e.split(".")[1],r=atob(t);return JSON.parse(r)}function RE(){const e=new URLSearchParams(window.location.search),t=e.get("sesamy-token")||e.get("token");if(!t)return;try{const n=_E(t),a=new Date(n.exp*1e3),i={id:"",title:"Signed link",sku:n.s.toString(),purchaseOptionsId:n.pid.toString(),url:n.url.toString(),token:t,type:"article",expiresAt:a.toISOString(),createdAt:new Date(n.iat).toISOString(),updatedAt:new Date(n.iat).toISOString()};qT(i)}catch{}const r=new URL(window.location.href);r.searchParams.delete("ss"),r.searchParams.delete("se"),r.searchParams.delete("sp"),r.searchParams.delete("so"),r.searchParams.delete("token"),r.searchParams.delete("sesamy-token"),window.history.replaceState(null,"",r)}const uh="sesamy-user";async function CE(){var a;const t=(a=new URLSearchParams(window.location.search).get(uh))==null?void 0:a.toLowerCase();if(!t)return;const r=await xT();(r==null?void 0:r.email)!==t&&(Re(),Do({authorizationParams:{email_hint:t,login_hint:t}}));const n=new URL(window.location.href);n.searchParams.delete(uh),window.history.replaceState(null,"",n)}const lh="sesamy-purchase";function AE(){const e=new URLSearchParams(window.location.search),t=e.get(lh);if(t!==null){const r=new URL(window.location.href);e.delete(lh),r.search=e.toString(),Je(_e.PURCHASE,{itemSrc:t}),Re(),window.history.replaceState(null,"",r)}}const fh="sesamy-login",jE="sesamy_login";async function LE(){const e=new URLSearchParams(window.location.search);if(!(e.get(fh)||e.get(jE)))return;await Kn()||Do();const n=new URL(window.location.href);n.searchParams.delete(fh),window.history.replaceState(null,"",n)}const NE=typeof window<"u";async function dh(e){hE({clientId:e.clientId,environment:e.environment,...e.analytics}),await NT({clientId:e.clientId,organization:e.organization,environment:e.environment,...e.auth}),e.transform&&await EE(e.transform),OE(),kE(),RE(),await LE(),await CE(),AE(),Je(_e.READY,{})}async function hh(e){const t=SE({clientId:e.clientId,environment:e.environment,...e.api});return NE&&(e.awaitAllServices?await dh(e):dh(e)),t}if(typeof document<"u"){const e=document.getElementById("sesamy-js");if(e!=null&&e.textContent)try{const t=JSON.parse(e.textContent);hh(t)}catch(t){console.error("Failed to parse config",t)}}return xe.init=hh,Object.defineProperty(xe,Symbol.toStringTag,{value:"Module"}),xe}({});
17
+ `,document.head.appendChild(i)}async function oh(e){try{const t=await fetch(e);return t.ok?await t.text():(console.error(`Failed to fetch content from ${e}: ${t.statusText}`),null)}catch(t){return console.error(`Error fetching content from ${e}:`,t),null}}async function TE(e,t,r="inside"){let n="";if(t.contentType==="selector"&&t.content){const a=document.querySelector(t.content);if(a)n=a.innerHTML;else{console.warn(`Source element for selector '${t.content}' not found`);return}}else if(t.contentType==="url"&&t.content){const a=await oh(t.content);if(a)n=a;else{console.warn(`Failed to fetch content from URL '${t.content}'`);return}}else t.content&&(n=t.content);switch(r){case"before":e.insertAdjacentHTML("beforebegin",n);break;case"after":e.insertAdjacentHTML("afterend",n);break;case"inside":default:e.innerHTML+=n;break}}async function PE(e,t){if(t.contentType==="selector"&&t.content){const r=document.querySelector(t.content);r?e.innerHTML=r.innerHTML:console.warn(`Source element for selector '${t.content}' not found`)}else if(t.contentType==="url"&&t.content){const r=await oh(t.content);r?e.innerHTML=r:console.warn(`Failed to fetch content from URL '${t.content}'`)}else t.content&&(e.innerHTML=t.content)}async function EE({enabled:e=!1,rules:t}){if(!e)return;const r=await Kn(),n=window.location.href;for(const a of t){const i=document.querySelectorAll(a.selector);if(!(a.path&&!new RegExp(a.path).test(n)))for(const o of i){const s=o;if(!(a.authenticated!==void 0&&a.authenticated!==r))switch(a.transform){case"insert":await TE(s,a);break;case"replace":await PE(s,a);break;case"remove":o.remove();break;case"gradient":IE(s,a);break;default:console.warn(`Unknown transform type: ${a.transform}`)}}}}function OE(){const e=new URLSearchParams(window.location.hash.substring(1)),t=e.get("access_token");if(t){Wf(t);const r=new URL(window.location.href);e.delete("access_token"),r.hash=e.toString(),window.history.replaceState(null,"",r)}}const sh="sesamy-refresh",ch="force-refetch-entitlements";function kE(){const e=new URLSearchParams(window.location.search),t=e.get(ch),r=e.get(sh);if(t!==null||r!==null){const n=new URL(window.location.href);e.delete(ch),e.delete(sh),n.search=e.toString(),Re(),window.history.replaceState(null,"",n)}}function _E(e){const t=e.split(".")[1],r=atob(t);return JSON.parse(r)}function RE(){const e=new URLSearchParams(window.location.search),t=e.get("sesamy-token")||e.get("token");if(!t)return;try{const n=_E(t),a=new Date(n.exp*1e3),i={id:"",title:"Signed link",sku:n.s.toString(),purchaseOptionsId:n.pid.toString(),url:n.url.toString(),token:t,type:"article",expiresAt:a.toISOString(),createdAt:new Date(n.iat).toISOString(),updatedAt:new Date(n.iat).toISOString()};qT(i)}catch{}const r=new URL(window.location.href);r.searchParams.delete("ss"),r.searchParams.delete("se"),r.searchParams.delete("sp"),r.searchParams.delete("so"),r.searchParams.delete("token"),r.searchParams.delete("sesamy-token"),window.history.replaceState(null,"",r)}const uh="sesamy-user";async function CE(){var a;const t=(a=new URLSearchParams(window.location.search).get(uh))==null?void 0:a.toLowerCase();if(!t)return;const r=await xT();(r==null?void 0:r.email)!==t&&(Re(),Do({authorizationParams:{email_hint:t,login_hint:t}}));const n=new URL(window.location.href);n.searchParams.delete(uh),window.history.replaceState(null,"",n)}const lh="sesamy-purchase";function AE(){const e=new URLSearchParams(window.location.search),t=e.get(lh);if(t!==null){const r=new URL(window.location.href);e.delete(lh),r.search=e.toString(),Je(_e.PURCHASE,{itemSrc:t}),Re(),window.history.replaceState(null,"",r)}}const fh="sesamy-login",jE="sesamy_login";async function LE(){const e=new URLSearchParams(window.location.search);if(!(e.get(fh)||e.get(jE)))return;await Kn()||Do();const n=new URL(window.location.href);n.searchParams.delete(fh),window.history.replaceState(null,"",n)}const NE=typeof window<"u";async function dh(e){hE({clientId:e.clientId,environment:e.environment,...e.analytics}),await NT({clientId:e.clientId,organization:e.organization,environment:e.environment,...e.auth}),e.transform&&await EE(e.transform),OE(),kE(),RE(),await LE(),await CE(),AE(),Je(_e.READY,{})}async function hh(e){const t=SE({clientId:e.clientId,environment:e.environment,...e.api});return NE&&(e.awaitAllServices?await dh(e):dh(e)),t}if(typeof document<"u"){const e=document.getElementById("sesamy-js");if(e!=null&&e.textContent)try{const t=JSON.parse(e.textContent);hh(t)}catch(t){console.error("Failed to parse config",t)}}return xe.init=hh,Object.defineProperty(xe,Symbol.toStringTag,{value:"Module"}),xe}({});
@@ -5591,14 +5591,37 @@ async function gh(e) {
5591
5591
  return console.error(`Error fetching content from ${e}:`, t), null;
5592
5592
  }
5593
5593
  }
5594
- async function PE(e, t) {
5594
+ async function PE(e, t, r = "inside") {
5595
+ let n = "";
5595
5596
  if (t.contentType === "selector" && t.content) {
5596
- const r = document.querySelector(t.content);
5597
- r ? e.innerHTML += r.innerHTML : console.warn(`Source element for selector '${t.content}' not found`);
5597
+ const a = document.querySelector(t.content);
5598
+ if (a)
5599
+ n = a.innerHTML;
5600
+ else {
5601
+ console.warn(`Source element for selector '${t.content}' not found`);
5602
+ return;
5603
+ }
5598
5604
  } else if (t.contentType === "url" && t.content) {
5599
- const r = await gh(t.content);
5600
- r ? e.innerHTML += r : console.warn(`Failed to fetch content from URL '${t.content}'`);
5601
- } else t.content && (e.innerHTML += t.content);
5605
+ const a = await gh(t.content);
5606
+ if (a)
5607
+ n = a;
5608
+ else {
5609
+ console.warn(`Failed to fetch content from URL '${t.content}'`);
5610
+ return;
5611
+ }
5612
+ } else t.content && (n = t.content);
5613
+ switch (r) {
5614
+ case "before":
5615
+ e.insertAdjacentHTML("beforebegin", n);
5616
+ break;
5617
+ case "after":
5618
+ e.insertAdjacentHTML("afterend", n);
5619
+ break;
5620
+ case "inside":
5621
+ default:
5622
+ e.innerHTML += n;
5623
+ break;
5624
+ }
5602
5625
  }
5603
5626
  async function EE(e, t) {
5604
5627
  if (t.contentType === "selector" && t.content) {
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "registry": "https://registry.npmjs.org/",
7
7
  "tag": "latest"
8
8
  },
9
- "version": "1.21.7",
9
+ "version": "1.21.8",
10
10
  "main": "dist/sesamy-js.cjs",
11
11
  "module": "dist/sesamy-js.mjs",
12
12
  "types": "dist/sesamy-js.d.ts",