@sentientui/core 0.9.0 → 0.9.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/index-server.d.cts
CHANGED
|
@@ -20,7 +20,11 @@ type ServerAssignConfig = {
|
|
|
20
20
|
utmParams?: Record<string, string>;
|
|
21
21
|
/**
|
|
22
22
|
* Milliseconds to wait for the API before returning default variants.
|
|
23
|
-
* Prevents slow/cold API from blocking SSR. Defaults to
|
|
23
|
+
* Prevents slow/cold API from blocking SSR. Defaults to 1000 — the hot path
|
|
24
|
+
* is served from in-process caches and typically returns in well under
|
|
25
|
+
* 150 ms. The full 1 s budget is only reached on a cold start or an API
|
|
26
|
+
* geographically distant from your SSR host, after which defaults render
|
|
27
|
+
* with no layout shift. Lower it if your API is co-located and warm.
|
|
24
28
|
*/
|
|
25
29
|
timeoutMs?: number;
|
|
26
30
|
};
|
package/dist/index-server.d.ts
CHANGED
|
@@ -20,7 +20,11 @@ type ServerAssignConfig = {
|
|
|
20
20
|
utmParams?: Record<string, string>;
|
|
21
21
|
/**
|
|
22
22
|
* Milliseconds to wait for the API before returning default variants.
|
|
23
|
-
* Prevents slow/cold API from blocking SSR. Defaults to
|
|
23
|
+
* Prevents slow/cold API from blocking SSR. Defaults to 1000 — the hot path
|
|
24
|
+
* is served from in-process caches and typically returns in well under
|
|
25
|
+
* 150 ms. The full 1 s budget is only reached on a cold start or an API
|
|
26
|
+
* geographically distant from your SSR host, after which defaults render
|
|
27
|
+
* with no layout shift. Lower it if your API is co-located and warm.
|
|
24
28
|
*/
|
|
25
29
|
timeoutMs?: number;
|
|
26
30
|
};
|
package/dist/index-server.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var m=Object.defineProperty,k=Object.defineProperties,I=Object.getOwnPropertyDescriptor,$=Object.getOwnPropertyDescriptors,j=Object.getOwnPropertyNames,b=Object.getOwnPropertySymbols;var A=Object.prototype.hasOwnProperty,B=Object.prototype.propertyIsEnumerable;var w=(t,e,r)=>e in t?m(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,v=(t,e)=>{for(var r in e||(e={}))A.call(e,r)&&w(t,r,e[r]);if(b)for(var r of b(e))B.call(e,r)&&w(t,r,e[r]);return t},U=(t,e)=>k(t,$(e));var M=(t,e)=>{for(var r in e)m(t,r,{get:e[r],enumerable:!0})},L=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of j(e))!A.call(t,i)&&i!==r&&m(t,i,{get:()=>e[i],enumerable:!(s=I(e,i))||s.enumerable});return t};var _=t=>L(m({},"__esModule",{value:!0}),t);var z={};M(z,{buildSessionUpsertPayload:()=>g,deriveSessionSegment:()=>x,detectDeviceClass:()=>p,detectTimeOfDay:()=>S,detectTrafficSource:()=>y,preloadAssignments:()=>P,preloadDecisions:()=>O,readSessionCookie:()=>C,referrerDomainFromReferer:()=>h});module.exports=_(z);var E=["GPTBot","ChatGPT-User","OAI-SearchBot","ClaudeBot","Claude-User","Claude-SearchBot","PerplexityBot","Perplexity-User","Google-Extended","Applebot-Extended","Meta-ExternalAgent","Bytespider","CCBot","Amazonbot","cohere-ai","Diffbot"];function J(t){return N(t)!==null}function N(t){var r;if(!t)return null;let e=t.toLowerCase();return(r=E.find(s=>e.includes(s.toLowerCase())))!=null?r:null}function p(t){let e=t.toLowerCase();return/ipad|tablet|playbook|kindle|silk/.test(e)?"tablet":/mobi|iphone|ipod|android.*mobile|phone/.test(e)?"mobile":"desktop"}function y(t,e){if(!t)return"direct";try{let r=new URL(t);if(e)try{if(new URL(e).host===r.host)return"direct"}catch(i){}let s=r.hostname.toLowerCase();return/(^|\.)(google|bing|duckduckgo|yahoo)\./.test(s)?"search":/(^|\.)(twitter|x\.com|facebook|linkedin|reddit|t\.co)/.test(s)?"social":"referral"}catch(r){return"direct"}}function h(t){if(!t)return null;try{return new URL(t).hostname}catch(e){return null}}function S(t){let e=t.getHours();return e<6?"night":e<12?"morning":e<18?"afternoon":"evening"}function x(t){let e=g("__segment__",t);return`${e.deviceClass}:${e.trafficSource}`}function g(t,e){var a,l,c,o,n,d,u;let r=(l=(a=e==null?void 0:e.userAgent)==null?void 0:a.trim())!=null?l:"",s=(o=(c=e==null?void 0:e.referer)==null?void 0:c.trim())!=null?o:"",i=(n=e==null?void 0:e.now)!=null?n:new Date;return{sessionId:t,ephemeral:!1,utmParams:(d=e==null?void 0:e.utmParams)!=null?d:{},deviceClass:r?p(r):"desktop",trafficSource:s?y(s,e==null?void 0:e.appOrigin):"direct",referrerDomain:h(s),timeOfDay:S(i),dayOfWeek:(u=["sun","mon","tue","wed","thu","fri","sat"][i.getDay()])!=null?u:"sun",automation:(e==null?void 0:e.webdriver)===!0||J(r)}}var D=
|
|
1
|
+
"use strict";var m=Object.defineProperty,k=Object.defineProperties,I=Object.getOwnPropertyDescriptor,$=Object.getOwnPropertyDescriptors,j=Object.getOwnPropertyNames,b=Object.getOwnPropertySymbols;var A=Object.prototype.hasOwnProperty,B=Object.prototype.propertyIsEnumerable;var w=(t,e,r)=>e in t?m(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,v=(t,e)=>{for(var r in e||(e={}))A.call(e,r)&&w(t,r,e[r]);if(b)for(var r of b(e))B.call(e,r)&&w(t,r,e[r]);return t},U=(t,e)=>k(t,$(e));var M=(t,e)=>{for(var r in e)m(t,r,{get:e[r],enumerable:!0})},L=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of j(e))!A.call(t,i)&&i!==r&&m(t,i,{get:()=>e[i],enumerable:!(s=I(e,i))||s.enumerable});return t};var _=t=>L(m({},"__esModule",{value:!0}),t);var z={};M(z,{buildSessionUpsertPayload:()=>g,deriveSessionSegment:()=>x,detectDeviceClass:()=>p,detectTimeOfDay:()=>S,detectTrafficSource:()=>y,preloadAssignments:()=>P,preloadDecisions:()=>O,readSessionCookie:()=>C,referrerDomainFromReferer:()=>h});module.exports=_(z);var E=["GPTBot","ChatGPT-User","OAI-SearchBot","ClaudeBot","Claude-User","Claude-SearchBot","PerplexityBot","Perplexity-User","Google-Extended","Applebot-Extended","Meta-ExternalAgent","Bytespider","CCBot","Amazonbot","cohere-ai","Diffbot"];function J(t){return N(t)!==null}function N(t){var r;if(!t)return null;let e=t.toLowerCase();return(r=E.find(s=>e.includes(s.toLowerCase())))!=null?r:null}function p(t){let e=t.toLowerCase();return/ipad|tablet|playbook|kindle|silk/.test(e)?"tablet":/mobi|iphone|ipod|android.*mobile|phone/.test(e)?"mobile":"desktop"}function y(t,e){if(!t)return"direct";try{let r=new URL(t);if(e)try{if(new URL(e).host===r.host)return"direct"}catch(i){}let s=r.hostname.toLowerCase();return/(^|\.)(google|bing|duckduckgo|yahoo)\./.test(s)?"search":/(^|\.)(twitter|x\.com|facebook|linkedin|reddit|t\.co)/.test(s)?"social":"referral"}catch(r){return"direct"}}function h(t){if(!t)return null;try{return new URL(t).hostname}catch(e){return null}}function S(t){let e=t.getHours();return e<6?"night":e<12?"morning":e<18?"afternoon":"evening"}function x(t){let e=g("__segment__",t);return`${e.deviceClass}:${e.trafficSource}`}function g(t,e){var a,l,c,o,n,d,u;let r=(l=(a=e==null?void 0:e.userAgent)==null?void 0:a.trim())!=null?l:"",s=(o=(c=e==null?void 0:e.referer)==null?void 0:c.trim())!=null?o:"",i=(n=e==null?void 0:e.now)!=null?n:new Date;return{sessionId:t,ephemeral:!1,utmParams:(d=e==null?void 0:e.utmParams)!=null?d:{},deviceClass:r?p(r):"desktop",trafficSource:s?y(s,e==null?void 0:e.appOrigin):"direct",referrerDomain:h(s),timeOfDay:S(i),dayOfWeek:(u=["sun","mon","tue","wed","thu","fri","sat"][i.getDay()])!=null?u:"sun",automation:(e==null?void 0:e.webdriver)===!0||J(r)}}var D=1e3;function f(t,e,r){let s=new AbortController,i=setTimeout(()=>s.abort(),r);return fetch(t,U(v({},e),{signal:s.signal})).finally(()=>clearTimeout(i))}async function P(t,e,r){var o;let s=(o=r.timeoutMs)!=null?o:D,i={"Content-Type":"application/json",Authorization:`Bearer ${r.apiKey}`};r.origin&&(i.Origin=r.origin);let a=g(e,{userAgent:r.userAgent,referer:r.referer,utmParams:r.utmParams,appOrigin:r.origin});try{let n=await f(`${r.baseUrl}/sessions`,{method:"POST",headers:i,body:JSON.stringify(a)},s);if(n.status===402)console.warn("[SentientUI] Session limit exceeded for this project. The bandit will stop learning until the limit resets. Upgrade at sentient-ui.com/pricing");else if(!n.ok){let d=await n.json().catch(()=>({}));console.error(`[SentientUI] preloadAssignments: session upsert failed (${n.status})`,d)}}catch(n){console.error("[SentientUI] preloadAssignments: session upsert threw",n)}let l=await Promise.allSettled(t.map(async({id:n,variantIds:d})=>{let u=await f(`${r.baseUrl}/assign`,{method:"POST",headers:i,body:JSON.stringify({sessionId:e,componentId:n,variantIds:d})},s);if(!u.ok){let T=await u.json().catch(()=>({}));return console.error(`[SentientUI] preloadAssignments: assign failed for "${n}" (${u.status})`,T),null}let R=await u.json();return{id:n,variantId:R.variantId}})),c={};for(let n of l)n.status==="fulfilled"&&n.value&&(c[n.value.id]=n.value.variantId);return c}function C(t){var e,r;return(r=(e=t.get("_snt_uid"))==null?void 0:e.value)!=null?r:null}async function O(t,e,r){var c;let s=(c=r.timeoutMs)!=null?c:D,i={layoutOrder:t.sections,assignments:{},persona:"unknown",confidence:0},a={"Content-Type":"application/json",Authorization:`Bearer ${r.apiKey}`};r.origin&&(a.Origin=r.origin);let l=g(e,{userAgent:r.userAgent,referer:r.referer,utmParams:r.utmParams,appOrigin:r.origin});try{let o=await f(`${r.baseUrl}/sessions`,{method:"POST",headers:a,body:JSON.stringify(l)},s);if(!o.ok){let n=await o.json().catch(()=>({}));console.error(`[SentientUI] preloadDecisions: session upsert failed (${o.status})`,n)}}catch(o){console.error("[SentientUI] preloadDecisions: session upsert threw",o)}try{let o=await f(`${r.baseUrl}/decide`,{method:"POST",headers:a,body:JSON.stringify({sessionId:e,sections:t.sections.map(n=>({id:n})),components:t.components})},s);if(!o.ok){let n=await o.json().catch(()=>({}));return console.error(`[SentientUI] preloadDecisions: decide failed (${o.status})`,n),i}return await o.json()}catch(o){return console.error("[SentientUI] preloadDecisions: decide threw",o),i}}0&&(module.exports={buildSessionUpsertPayload,deriveSessionSegment,detectDeviceClass,detectTimeOfDay,detectTrafficSource,preloadAssignments,preloadDecisions,readSessionCookie,referrerDomainFromReferer});
|
package/dist/index-server.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as p,b as y,f as b,g as h,h as v,i as U,j as w,k as d}from"./chunk-CFXMEZCZ.mjs";var S=
|
|
1
|
+
import{a as p,b as y,f as b,g as h,h as v,i as U,j as w,k as d}from"./chunk-CFXMEZCZ.mjs";var S=1e3;function u(n,r,e){let i=new AbortController,o=setTimeout(()=>i.abort(),e);return fetch(n,y(p({},r),{signal:i.signal})).finally(()=>clearTimeout(o))}async function O(n,r,e){var t;let i=(t=e.timeoutMs)!=null?t:S,o={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`};e.origin&&(o.Origin=e.origin);let a=d(r,{userAgent:e.userAgent,referer:e.referer,utmParams:e.utmParams,appOrigin:e.origin});try{let s=await u(`${e.baseUrl}/sessions`,{method:"POST",headers:o,body:JSON.stringify(a)},i);if(s.status===402)console.warn("[SentientUI] Session limit exceeded for this project. The bandit will stop learning until the limit resets. Upgrade at sentient-ui.com/pricing");else if(!s.ok){let m=await s.json().catch(()=>({}));console.error(`[SentientUI] preloadAssignments: session upsert failed (${s.status})`,m)}}catch(s){console.error("[SentientUI] preloadAssignments: session upsert threw",s)}let g=await Promise.allSettled(n.map(async({id:s,variantIds:m})=>{let c=await u(`${e.baseUrl}/assign`,{method:"POST",headers:o,body:JSON.stringify({sessionId:r,componentId:s,variantIds:m})},i);if(!c.ok){let A=await c.json().catch(()=>({}));return console.error(`[SentientUI] preloadAssignments: assign failed for "${s}" (${c.status})`,A),null}let f=await c.json();return{id:s,variantId:f.variantId}})),l={};for(let s of g)s.status==="fulfilled"&&s.value&&(l[s.value.id]=s.value.variantId);return l}function P(n){var r,e;return(e=(r=n.get("_snt_uid"))==null?void 0:r.value)!=null?e:null}async function R(n,r,e){var l;let i=(l=e.timeoutMs)!=null?l:S,o={layoutOrder:n.sections,assignments:{},persona:"unknown",confidence:0},a={"Content-Type":"application/json",Authorization:`Bearer ${e.apiKey}`};e.origin&&(a.Origin=e.origin);let g=d(r,{userAgent:e.userAgent,referer:e.referer,utmParams:e.utmParams,appOrigin:e.origin});try{let t=await u(`${e.baseUrl}/sessions`,{method:"POST",headers:a,body:JSON.stringify(g)},i);if(!t.ok){let s=await t.json().catch(()=>({}));console.error(`[SentientUI] preloadDecisions: session upsert failed (${t.status})`,s)}}catch(t){console.error("[SentientUI] preloadDecisions: session upsert threw",t)}try{let t=await u(`${e.baseUrl}/decide`,{method:"POST",headers:a,body:JSON.stringify({sessionId:r,sections:n.sections.map(s=>({id:s})),components:n.components})},i);if(!t.ok){let s=await t.json().catch(()=>({}));return console.error(`[SentientUI] preloadDecisions: decide failed (${t.status})`,s),o}return await t.json()}catch(t){return console.error("[SentientUI] preloadDecisions: decide threw",t),o}}export{d as buildSessionUpsertPayload,w as deriveSessionSegment,b as detectDeviceClass,U as detectTimeOfDay,h as detectTrafficSource,O as preloadAssignments,R as preloadDecisions,P as readSessionCookie,v as referrerDomainFromReferer};
|