@sentientui/react 0.4.0 → 0.6.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/README.md +15 -1
- package/dist/index.d.cts +21 -4
- package/dist/index.d.ts +21 -4
- package/dist/index.js +1 -514
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -478
- package/dist/index.mjs.map +1 -1
- package/dist/next/adaptive-root-client.js +1 -82
- package/dist/next/adaptive-root-client.js.map +1 -1
- package/dist/next/adaptive-root.d.ts +2 -1
- package/dist/next/adaptive-root.js +1 -152
- package/dist/next/adaptive-root.js.map +1 -1
- package/dist/server.d.cts +4 -4
- package/dist/server.d.ts +4 -4
- package/dist/server.js +1 -87
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +1 -51
- package/dist/server.mjs.map +1 -1
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -1,88 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/server.ts
|
|
31
|
-
var server_exports = {};
|
|
32
|
-
__export(server_exports, {
|
|
33
|
-
loadAdaptiveAssignments: () => loadAdaptiveAssignments,
|
|
34
|
-
loadAdaptiveDecision: () => loadAdaptiveDecision,
|
|
35
|
-
preloadAssignments: () => import_core.preloadAssignments,
|
|
36
|
-
preloadDecisions: () => import_core2.preloadDecisions,
|
|
37
|
-
readSessionCookie: () => import_core.readSessionCookie
|
|
38
|
-
});
|
|
39
|
-
module.exports = __toCommonJS(server_exports);
|
|
40
|
-
var import_core = require("@sentientui/core");
|
|
41
|
-
var import_core2 = require("@sentientui/core");
|
|
42
|
-
function defaultSessionId() {
|
|
43
|
-
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
44
|
-
return crypto.randomUUID();
|
|
45
|
-
}
|
|
46
|
-
return `snt-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
|
|
47
|
-
}
|
|
48
|
-
async function loadAdaptiveAssignments(components, options) {
|
|
49
|
-
var _a, _b, _c;
|
|
50
|
-
const sessionId = (_c = (_b = (0, import_core.readSessionCookie)(options.cookies)) != null ? _b : (_a = options.createSessionId) == null ? void 0 : _a.call(options)) != null ? _c : defaultSessionId();
|
|
51
|
-
return (0, import_core.preloadAssignments)(components, sessionId, {
|
|
52
|
-
apiKey: options.apiKey,
|
|
53
|
-
baseUrl: options.baseUrl,
|
|
54
|
-
origin: options.origin,
|
|
55
|
-
userAgent: options.userAgent,
|
|
56
|
-
referer: options.referer,
|
|
57
|
-
timeoutMs: options.timeoutMs
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
async function loadAdaptiveDecision(options) {
|
|
61
|
-
var _a, _b, _c, _d;
|
|
62
|
-
const { preloadDecisions: preloadDecisions2, readSessionCookie: readSessionCookie2 } = await import("@sentientui/core");
|
|
63
|
-
const sessionId = (_c = (_b = readSessionCookie2(options.cookies)) != null ? _b : (_a = options.createSessionId) == null ? void 0 : _a.call(options)) != null ? _c : defaultSessionId();
|
|
64
|
-
return preloadDecisions2(
|
|
65
|
-
{
|
|
66
|
-
sections: options.sections,
|
|
67
|
-
components: (_d = options.components) != null ? _d : []
|
|
68
|
-
},
|
|
69
|
-
sessionId,
|
|
70
|
-
{
|
|
71
|
-
apiKey: options.apiKey,
|
|
72
|
-
baseUrl: options.baseUrl,
|
|
73
|
-
origin: options.origin,
|
|
74
|
-
userAgent: options.userAgent,
|
|
75
|
-
referer: options.referer,
|
|
76
|
-
timeoutMs: options.timeoutMs
|
|
77
|
-
}
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
81
|
-
0 && (module.exports = {
|
|
82
|
-
loadAdaptiveAssignments,
|
|
83
|
-
loadAdaptiveDecision,
|
|
84
|
-
preloadAssignments,
|
|
85
|
-
preloadDecisions,
|
|
86
|
-
readSessionCookie
|
|
87
|
-
});
|
|
1
|
+
"use strict";var A=Object.create;var o=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,v=Object.prototype.hasOwnProperty;var l=(e,r)=>{for(var s in r)o(e,s,{get:r[s],enumerable:!0})},c=(e,r,s,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of y(r))!v.call(e,i)&&i!==s&&o(e,i,{get:()=>r[i],enumerable:!(n=p(r,i))||n.enumerable});return e};var S=(e,r,s)=>(s=e!=null?A(f(e)):{},c(r||!e||!e.__esModule?o(s,"default",{value:e,enumerable:!0}):s,e)),D=e=>c(o({},"__esModule",{value:!0}),e);var x={};l(x,{loadAdaptiveAssignments:()=>I,loadAdaptiveDecision:()=>U,preloadAssignments:()=>t.preloadAssignments,preloadDecisions:()=>u.preloadDecisions,readSessionCookie:()=>t.readSessionCookie});module.exports=D(x);var t=require("@sentientui/core/server"),u=require("@sentientui/core/server");function m(){return typeof crypto!="undefined"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`snt-${Date.now()}-${Math.random().toString(36).slice(2,11)}`}async function I(e,r){var n,i,a;let s=(a=(i=(0,t.readSessionCookie)(r.cookies))!=null?i:(n=r.createSessionId)==null?void 0:n.call(r))!=null?a:m();return(0,t.preloadAssignments)(e,s,{apiKey:r.apiKey,baseUrl:r.baseUrl,origin:r.origin,userAgent:r.userAgent,referer:r.referer,timeoutMs:r.timeoutMs})}async function U(e){var i,a,d,g;let{preloadDecisions:r,readSessionCookie:s}=await import("@sentientui/core/server"),n=(d=(a=s(e.cookies))!=null?a:(i=e.createSessionId)==null?void 0:i.call(e))!=null?d:m();return r({sections:e.sections,components:(g=e.components)!=null?g:[]},n,{apiKey:e.apiKey,baseUrl:e.baseUrl,origin:e.origin,userAgent:e.userAgent,referer:e.referer,timeoutMs:e.timeoutMs})}0&&(module.exports={loadAdaptiveAssignments,loadAdaptiveDecision,preloadAssignments,preloadDecisions,readSessionCookie});
|
|
88
2
|
//# sourceMappingURL=server.js.map
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/server.ts"],"sourcesContent":["/**\n * Server-only helpers for Next.js / SSR. No React or DOM APIs.\n */\nimport {\n preloadAssignments,\n readSessionCookie,\n type ServerAssignConfig,\n type ServerAssignments,\n} from '@sentientui/core';\n\nexport { preloadAssignments, readSessionCookie };\nexport type { ServerAssignConfig, ServerAssignments };\n\nexport type LoadAdaptiveAssignmentsOptions = {\n /** Next.js `cookies()` return value, or any object with `get(name)`. */\n cookies: { get(name: string): { value: string } | undefined };\n apiKey: string;\n baseUrl: string;\n /** Used when `_snt_uid` is absent (e.g. first visit, many crawlers). */\n createSessionId?: () => string;\n /** Must match a value in the project's `allowed_origins` (e.g. `http://localhost:3001`). */\n origin?: string;\n /** From Next.js `headers().get('user-agent')` — aligns SSR segment with the client. */\n userAgent?: string;\n /** From Next.js `headers().get('referer')`. */\n referer?: string;\n /** Milliseconds to wait for the API before returning default variants. Defaults to 1500. */\n timeoutMs?: number;\n};\n\nfunction defaultSessionId(): string {\n if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {\n return crypto.randomUUID();\n }\n return `snt-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;\n}\n\n/**\n * Fetches bandit assignments on the server for SEO-safe HTML.\n * Pass the result as `initialAssignments` on `<AdaptiveProvider>`.\n */\nexport async function loadAdaptiveAssignments(\n components: Array<{ id: string; variantIds: string[] }>,\n options: LoadAdaptiveAssignmentsOptions,\n): Promise<ServerAssignments> {\n const sessionId =\n readSessionCookie(options.cookies) ??\n options.createSessionId?.() ??\n defaultSessionId();\n\n return preloadAssignments(components, sessionId, {\n apiKey: options.apiKey,\n baseUrl: options.baseUrl,\n origin: options.origin,\n userAgent: options.userAgent,\n referer: options.referer,\n timeoutMs: options.timeoutMs,\n });\n}\n\nexport { preloadDecisions, type DecideResult } from '@sentientui/core';\n\nexport type LoadAdaptiveDecisionOptions = LoadAdaptiveAssignmentsOptions & {\n /** Section IDs in default order. Passed to /v1/decide as the candidate layout. */\n sections: string[];\n /** Components to assign in the same decide call. */\n components?: Array<{ id: string; variantIds?: string[] }>;\n};\n\n/**\n * SSR helper for pages with a declared section layout. Calls `/v1/decide`\n * instead of multiple `/v1/assign` round trips.\n */\nexport async function loadAdaptiveDecision(\n options: LoadAdaptiveDecisionOptions,\n): Promise<import('@sentientui/core').DecideResult> {\n const { preloadDecisions, readSessionCookie } = await import('@sentientui/core');\n\n const sessionId =\n readSessionCookie(options.cookies) ??\n options.createSessionId?.() ??\n defaultSessionId();\n\n return preloadDecisions(\n {\n sections: options.sections,\n components: options.components ?? [],\n },\n sessionId,\n {\n apiKey: options.apiKey,\n baseUrl: options.baseUrl,\n origin: options.origin,\n userAgent: options.userAgent,\n referer: options.referer,\n timeoutMs: options.timeoutMs,\n },\n );\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/server.ts"],"sourcesContent":["/**\n * Server-only helpers for Next.js / SSR. No React or DOM APIs.\n */\nimport {\n preloadAssignments,\n readSessionCookie,\n type ServerAssignConfig,\n type ServerAssignments,\n} from '@sentientui/core/server';\n\nexport { preloadAssignments, readSessionCookie };\nexport type { ServerAssignConfig, ServerAssignments };\n\nexport type LoadAdaptiveAssignmentsOptions = {\n /** Next.js `cookies()` return value, or any object with `get(name)`. */\n cookies: { get(name: string): { value: string } | undefined };\n apiKey: string;\n baseUrl: string;\n /** Used when `_snt_uid` is absent (e.g. first visit, many crawlers). */\n createSessionId?: () => string;\n /** Must match a value in the project's `allowed_origins` (e.g. `http://localhost:3001`). */\n origin?: string;\n /** From Next.js `headers().get('user-agent')` — aligns SSR segment with the client. */\n userAgent?: string;\n /** From Next.js `headers().get('referer')`. */\n referer?: string;\n /** Milliseconds to wait for the API before returning default variants. Defaults to 1500. */\n timeoutMs?: number;\n};\n\nfunction defaultSessionId(): string {\n if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {\n return crypto.randomUUID();\n }\n return `snt-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;\n}\n\n/**\n * Fetches bandit assignments on the server for SEO-safe HTML.\n * Pass the result as `initialAssignments` on `<AdaptiveProvider>`.\n */\nexport async function loadAdaptiveAssignments(\n components: Array<{ id: string; variantIds: string[] }>,\n options: LoadAdaptiveAssignmentsOptions,\n): Promise<ServerAssignments> {\n const sessionId =\n readSessionCookie(options.cookies) ??\n options.createSessionId?.() ??\n defaultSessionId();\n\n return preloadAssignments(components, sessionId, {\n apiKey: options.apiKey,\n baseUrl: options.baseUrl,\n origin: options.origin,\n userAgent: options.userAgent,\n referer: options.referer,\n timeoutMs: options.timeoutMs,\n });\n}\n\nexport { preloadDecisions, type DecideResult } from '@sentientui/core/server';\n\nexport type LoadAdaptiveDecisionOptions = LoadAdaptiveAssignmentsOptions & {\n /** Section IDs in default order. Passed to /v1/decide as the candidate layout. */\n sections: string[];\n /** Components to assign in the same decide call. */\n components?: Array<{ id: string; variantIds?: string[] }>;\n};\n\n/**\n * SSR helper for pages with a declared section layout. Calls `/v1/decide`\n * instead of multiple `/v1/assign` round trips.\n */\nexport async function loadAdaptiveDecision(\n options: LoadAdaptiveDecisionOptions,\n): Promise<import('@sentientui/core/server').DecideResult> {\n const { preloadDecisions, readSessionCookie } = await import('@sentientui/core/server');\n\n const sessionId =\n readSessionCookie(options.cookies) ??\n options.createSessionId?.() ??\n defaultSessionId();\n\n return preloadDecisions(\n {\n sections: options.sections,\n components: options.components ?? [],\n },\n sessionId,\n {\n apiKey: options.apiKey,\n baseUrl: options.baseUrl,\n origin: options.origin,\n userAgent: options.userAgent,\n referer: options.referer,\n timeoutMs: options.timeoutMs,\n },\n );\n}\n"],"mappings":"0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,6BAAAE,EAAA,yBAAAC,EAAA,+IAAAC,EAAAJ,GAGA,IAAAK,EAKO,mCAoDPA,EAAoD,mCA9BpD,SAASC,GAA2B,CAClC,OAAI,OAAO,QAAW,aAAe,OAAO,OAAO,YAAe,WACzD,OAAO,WAAW,EAEpB,OAAO,KAAK,IAAI,CAAC,IAAI,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,MAAM,EAAG,EAAE,CAAC,EACrE,CAMA,eAAsBC,EACpBC,EACAC,EAC4B,CA5C9B,IAAAC,EAAAC,EAAAC,EA6CE,IAAMC,GACJD,GAAAD,KAAA,qBAAkBF,EAAQ,OAAO,IAAjC,KAAAE,GACAD,EAAAD,EAAQ,kBAAR,YAAAC,EAAA,KAAAD,KADA,KAAAG,EAEAN,EAAiB,EAEnB,SAAO,sBAAmBE,EAAYK,EAAW,CAC/C,OAAQJ,EAAQ,OAChB,QAASA,EAAQ,QACjB,OAAQA,EAAQ,OAChB,UAAWA,EAAQ,UACnB,QAASA,EAAQ,QACjB,UAAWA,EAAQ,SACrB,CAAC,CACH,CAeA,eAAsBK,EACpBL,EACyD,CA3E3D,IAAAC,EAAAC,EAAAC,EAAAG,EA4EE,GAAM,CAAE,iBAAAC,EAAkB,kBAAAC,CAAkB,EAAI,KAAM,QAAO,yBAAyB,EAEhFJ,GACJD,GAAAD,EAAAM,EAAkBR,EAAQ,OAAO,IAAjC,KAAAE,GACAD,EAAAD,EAAQ,kBAAR,YAAAC,EAAA,KAAAD,KADA,KAAAG,EAEAN,EAAiB,EAEnB,OAAOU,EACL,CACE,SAAUP,EAAQ,SAClB,YAAYM,EAAAN,EAAQ,aAAR,KAAAM,EAAsB,CAAC,CACrC,EACAF,EACA,CACE,OAAQJ,EAAQ,OAChB,QAASA,EAAQ,QACjB,OAAQA,EAAQ,OAChB,UAAWA,EAAQ,UACnB,QAASA,EAAQ,QACjB,UAAWA,EAAQ,SACrB,CACF,CACF","names":["server_exports","__export","loadAdaptiveAssignments","loadAdaptiveDecision","__toCommonJS","import_server","defaultSessionId","loadAdaptiveAssignments","components","options","_a","_b","_c","sessionId","loadAdaptiveDecision","_d","preloadDecisions","readSessionCookie"]}
|
package/dist/server.mjs
CHANGED
|
@@ -1,52 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
preloadAssignments,
|
|
4
|
-
readSessionCookie
|
|
5
|
-
} from "@sentientui/core";
|
|
6
|
-
import { preloadDecisions } from "@sentientui/core";
|
|
7
|
-
function defaultSessionId() {
|
|
8
|
-
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
9
|
-
return crypto.randomUUID();
|
|
10
|
-
}
|
|
11
|
-
return `snt-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
|
|
12
|
-
}
|
|
13
|
-
async function loadAdaptiveAssignments(components, options) {
|
|
14
|
-
var _a, _b, _c;
|
|
15
|
-
const sessionId = (_c = (_b = readSessionCookie(options.cookies)) != null ? _b : (_a = options.createSessionId) == null ? void 0 : _a.call(options)) != null ? _c : defaultSessionId();
|
|
16
|
-
return preloadAssignments(components, sessionId, {
|
|
17
|
-
apiKey: options.apiKey,
|
|
18
|
-
baseUrl: options.baseUrl,
|
|
19
|
-
origin: options.origin,
|
|
20
|
-
userAgent: options.userAgent,
|
|
21
|
-
referer: options.referer,
|
|
22
|
-
timeoutMs: options.timeoutMs
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
async function loadAdaptiveDecision(options) {
|
|
26
|
-
var _a, _b, _c, _d;
|
|
27
|
-
const { preloadDecisions: preloadDecisions2, readSessionCookie: readSessionCookie2 } = await import("@sentientui/core");
|
|
28
|
-
const sessionId = (_c = (_b = readSessionCookie2(options.cookies)) != null ? _b : (_a = options.createSessionId) == null ? void 0 : _a.call(options)) != null ? _c : defaultSessionId();
|
|
29
|
-
return preloadDecisions2(
|
|
30
|
-
{
|
|
31
|
-
sections: options.sections,
|
|
32
|
-
components: (_d = options.components) != null ? _d : []
|
|
33
|
-
},
|
|
34
|
-
sessionId,
|
|
35
|
-
{
|
|
36
|
-
apiKey: options.apiKey,
|
|
37
|
-
baseUrl: options.baseUrl,
|
|
38
|
-
origin: options.origin,
|
|
39
|
-
userAgent: options.userAgent,
|
|
40
|
-
referer: options.referer,
|
|
41
|
-
timeoutMs: options.timeoutMs
|
|
42
|
-
}
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
export {
|
|
46
|
-
loadAdaptiveAssignments,
|
|
47
|
-
loadAdaptiveDecision,
|
|
48
|
-
preloadAssignments,
|
|
49
|
-
preloadDecisions,
|
|
50
|
-
readSessionCookie
|
|
51
|
-
};
|
|
1
|
+
import{preloadAssignments as g,readSessionCookie as c}from"@sentientui/core/server";import{preloadDecisions as f}from"@sentientui/core/server";function d(){return typeof crypto!="undefined"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`snt-${Date.now()}-${Math.random().toString(36).slice(2,11)}`}async function u(e,r){var n,s,i;let t=(i=(s=c(r.cookies))!=null?s:(n=r.createSessionId)==null?void 0:n.call(r))!=null?i:d();return g(e,t,{apiKey:r.apiKey,baseUrl:r.baseUrl,origin:r.origin,userAgent:r.userAgent,referer:r.referer,timeoutMs:r.timeoutMs})}async function A(e){var s,i,a,o;let{preloadDecisions:r,readSessionCookie:t}=await import("@sentientui/core/server"),n=(a=(i=t(e.cookies))!=null?i:(s=e.createSessionId)==null?void 0:s.call(e))!=null?a:d();return r({sections:e.sections,components:(o=e.components)!=null?o:[]},n,{apiKey:e.apiKey,baseUrl:e.baseUrl,origin:e.origin,userAgent:e.userAgent,referer:e.referer,timeoutMs:e.timeoutMs})}export{u as loadAdaptiveAssignments,A as loadAdaptiveDecision,g as preloadAssignments,f as preloadDecisions,c as readSessionCookie};
|
|
52
2
|
//# sourceMappingURL=server.mjs.map
|
package/dist/server.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/server.ts"],"sourcesContent":["/**\n * Server-only helpers for Next.js / SSR. No React or DOM APIs.\n */\nimport {\n preloadAssignments,\n readSessionCookie,\n type ServerAssignConfig,\n type ServerAssignments,\n} from '@sentientui/core';\n\nexport { preloadAssignments, readSessionCookie };\nexport type { ServerAssignConfig, ServerAssignments };\n\nexport type LoadAdaptiveAssignmentsOptions = {\n /** Next.js `cookies()` return value, or any object with `get(name)`. */\n cookies: { get(name: string): { value: string } | undefined };\n apiKey: string;\n baseUrl: string;\n /** Used when `_snt_uid` is absent (e.g. first visit, many crawlers). */\n createSessionId?: () => string;\n /** Must match a value in the project's `allowed_origins` (e.g. `http://localhost:3001`). */\n origin?: string;\n /** From Next.js `headers().get('user-agent')` — aligns SSR segment with the client. */\n userAgent?: string;\n /** From Next.js `headers().get('referer')`. */\n referer?: string;\n /** Milliseconds to wait for the API before returning default variants. Defaults to 1500. */\n timeoutMs?: number;\n};\n\nfunction defaultSessionId(): string {\n if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {\n return crypto.randomUUID();\n }\n return `snt-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;\n}\n\n/**\n * Fetches bandit assignments on the server for SEO-safe HTML.\n * Pass the result as `initialAssignments` on `<AdaptiveProvider>`.\n */\nexport async function loadAdaptiveAssignments(\n components: Array<{ id: string; variantIds: string[] }>,\n options: LoadAdaptiveAssignmentsOptions,\n): Promise<ServerAssignments> {\n const sessionId =\n readSessionCookie(options.cookies) ??\n options.createSessionId?.() ??\n defaultSessionId();\n\n return preloadAssignments(components, sessionId, {\n apiKey: options.apiKey,\n baseUrl: options.baseUrl,\n origin: options.origin,\n userAgent: options.userAgent,\n referer: options.referer,\n timeoutMs: options.timeoutMs,\n });\n}\n\nexport { preloadDecisions, type DecideResult } from '@sentientui/core';\n\nexport type LoadAdaptiveDecisionOptions = LoadAdaptiveAssignmentsOptions & {\n /** Section IDs in default order. Passed to /v1/decide as the candidate layout. */\n sections: string[];\n /** Components to assign in the same decide call. */\n components?: Array<{ id: string; variantIds?: string[] }>;\n};\n\n/**\n * SSR helper for pages with a declared section layout. Calls `/v1/decide`\n * instead of multiple `/v1/assign` round trips.\n */\nexport async function loadAdaptiveDecision(\n options: LoadAdaptiveDecisionOptions,\n): Promise<import('@sentientui/core').DecideResult> {\n const { preloadDecisions, readSessionCookie } = await import('@sentientui/core');\n\n const sessionId =\n readSessionCookie(options.cookies) ??\n options.createSessionId?.() ??\n defaultSessionId();\n\n return preloadDecisions(\n {\n sections: options.sections,\n components: options.components ?? [],\n },\n sessionId,\n {\n apiKey: options.apiKey,\n baseUrl: options.baseUrl,\n origin: options.origin,\n userAgent: options.userAgent,\n referer: options.referer,\n timeoutMs: options.timeoutMs,\n },\n );\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/server.ts"],"sourcesContent":["/**\n * Server-only helpers for Next.js / SSR. No React or DOM APIs.\n */\nimport {\n preloadAssignments,\n readSessionCookie,\n type ServerAssignConfig,\n type ServerAssignments,\n} from '@sentientui/core/server';\n\nexport { preloadAssignments, readSessionCookie };\nexport type { ServerAssignConfig, ServerAssignments };\n\nexport type LoadAdaptiveAssignmentsOptions = {\n /** Next.js `cookies()` return value, or any object with `get(name)`. */\n cookies: { get(name: string): { value: string } | undefined };\n apiKey: string;\n baseUrl: string;\n /** Used when `_snt_uid` is absent (e.g. first visit, many crawlers). */\n createSessionId?: () => string;\n /** Must match a value in the project's `allowed_origins` (e.g. `http://localhost:3001`). */\n origin?: string;\n /** From Next.js `headers().get('user-agent')` — aligns SSR segment with the client. */\n userAgent?: string;\n /** From Next.js `headers().get('referer')`. */\n referer?: string;\n /** Milliseconds to wait for the API before returning default variants. Defaults to 1500. */\n timeoutMs?: number;\n};\n\nfunction defaultSessionId(): string {\n if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {\n return crypto.randomUUID();\n }\n return `snt-${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;\n}\n\n/**\n * Fetches bandit assignments on the server for SEO-safe HTML.\n * Pass the result as `initialAssignments` on `<AdaptiveProvider>`.\n */\nexport async function loadAdaptiveAssignments(\n components: Array<{ id: string; variantIds: string[] }>,\n options: LoadAdaptiveAssignmentsOptions,\n): Promise<ServerAssignments> {\n const sessionId =\n readSessionCookie(options.cookies) ??\n options.createSessionId?.() ??\n defaultSessionId();\n\n return preloadAssignments(components, sessionId, {\n apiKey: options.apiKey,\n baseUrl: options.baseUrl,\n origin: options.origin,\n userAgent: options.userAgent,\n referer: options.referer,\n timeoutMs: options.timeoutMs,\n });\n}\n\nexport { preloadDecisions, type DecideResult } from '@sentientui/core/server';\n\nexport type LoadAdaptiveDecisionOptions = LoadAdaptiveAssignmentsOptions & {\n /** Section IDs in default order. Passed to /v1/decide as the candidate layout. */\n sections: string[];\n /** Components to assign in the same decide call. */\n components?: Array<{ id: string; variantIds?: string[] }>;\n};\n\n/**\n * SSR helper for pages with a declared section layout. Calls `/v1/decide`\n * instead of multiple `/v1/assign` round trips.\n */\nexport async function loadAdaptiveDecision(\n options: LoadAdaptiveDecisionOptions,\n): Promise<import('@sentientui/core/server').DecideResult> {\n const { preloadDecisions, readSessionCookie } = await import('@sentientui/core/server');\n\n const sessionId =\n readSessionCookie(options.cookies) ??\n options.createSessionId?.() ??\n defaultSessionId();\n\n return preloadDecisions(\n {\n sections: options.sections,\n components: options.components ?? [],\n },\n sessionId,\n {\n apiKey: options.apiKey,\n baseUrl: options.baseUrl,\n origin: options.origin,\n userAgent: options.userAgent,\n referer: options.referer,\n timeoutMs: options.timeoutMs,\n },\n );\n}\n"],"mappings":"AAGA,OACE,sBAAAA,EACA,qBAAAC,MAGK,0BAoDP,OAAS,oBAAAC,MAA2C,0BA9BpD,SAASC,GAA2B,CAClC,OAAI,OAAO,QAAW,aAAe,OAAO,OAAO,YAAe,WACzD,OAAO,WAAW,EAEpB,OAAO,KAAK,IAAI,CAAC,IAAI,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,MAAM,EAAG,EAAE,CAAC,EACrE,CAMA,eAAsBC,EACpBC,EACAC,EAC4B,CA5C9B,IAAAC,EAAAC,EAAAC,EA6CE,IAAMC,GACJD,GAAAD,EAAAG,EAAkBL,EAAQ,OAAO,IAAjC,KAAAE,GACAD,EAAAD,EAAQ,kBAAR,YAAAC,EAAA,KAAAD,KADA,KAAAG,EAEAN,EAAiB,EAEnB,OAAOS,EAAmBP,EAAYK,EAAW,CAC/C,OAAQJ,EAAQ,OAChB,QAASA,EAAQ,QACjB,OAAQA,EAAQ,OAChB,UAAWA,EAAQ,UACnB,QAASA,EAAQ,QACjB,UAAWA,EAAQ,SACrB,CAAC,CACH,CAeA,eAAsBO,EACpBP,EACyD,CA3E3D,IAAAC,EAAAC,EAAAC,EAAAK,EA4EE,GAAM,CAAE,iBAAAC,EAAkB,kBAAAJ,CAAkB,EAAI,KAAM,QAAO,yBAAyB,EAEhFD,GACJD,GAAAD,EAAAG,EAAkBL,EAAQ,OAAO,IAAjC,KAAAE,GACAD,EAAAD,EAAQ,kBAAR,YAAAC,EAAA,KAAAD,KADA,KAAAG,EAEAN,EAAiB,EAEnB,OAAOY,EACL,CACE,SAAUT,EAAQ,SAClB,YAAYQ,EAAAR,EAAQ,aAAR,KAAAQ,EAAsB,CAAC,CACrC,EACAJ,EACA,CACE,OAAQJ,EAAQ,OAChB,QAASA,EAAQ,QACjB,OAAQA,EAAQ,OAChB,UAAWA,EAAQ,UACnB,QAASA,EAAQ,QACjB,UAAWA,EAAQ,SACrB,CACF,CACF","names":["preloadAssignments","readSessionCookie","preloadDecisions","defaultSessionId","loadAdaptiveAssignments","components","options","_a","_b","_c","sessionId","readSessionCookie","preloadAssignments","loadAdaptiveDecision","_d","preloadDecisions"]}
|