@picked/client 0.0.65-next.3 → 0.0.65
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/api-B4atkKWy.cjs +1 -0
- package/dist/{api-BKpqWJH7.js → api-C3RQgr4k.js} +1 -1
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/plugins/dynamic-experiences/index.js +1 -1
- package/dist/cjs/server/index.js +1 -1
- package/dist/docs/content/asset-library.mdx +43 -0
- package/dist/esm/index.js +214 -187
- package/dist/esm/plugins/dynamic-experiences/index.js +2 -2
- package/dist/esm/server/index.js +1 -1
- package/dist/{plugin-Bv6xMnkt.js → plugin--FaLYDgu.js} +1 -1
- package/dist/{plugin-DfQQmpnX.cjs → plugin-B0aVJl2T.cjs} +1 -1
- package/dist/types/exports.d.ts +3 -0
- package/dist/types/exports.d.ts.map +1 -1
- package/dist/types/utils/html-asset-value.d.ts +20 -0
- package/dist/types/utils/html-asset-value.d.ts.map +1 -0
- package/dist/types/utils/rehydrate-scripts.d.ts +35 -0
- package/dist/types/utils/rehydrate-scripts.d.ts.map +1 -0
- package/package.json +1 -1
- package/dist/api-DqWHooZI.cjs +0 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { i as e } from "../../../api-
|
|
2
|
-
import { n as t, r as n, t as r } from "../../../plugin
|
|
1
|
+
import { i as e } from "../../../api-C3RQgr4k.js";
|
|
2
|
+
import { n as t, r as n, t as r } from "../../../plugin--FaLYDgu.js";
|
|
3
3
|
export { e as createClientHeaders, r as dynamicExperiencesPlugin, t as fetchExperienceContent, n as fetchProject };
|
package/dist/esm/server/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as e, c as t, i as n, o as r, s as i, t as a, u as o } from "../../experience-instance-DCcKZrdI.js";
|
|
2
|
-
import { i as s, n as c } from "../../plugin
|
|
2
|
+
import { i as s, n as c } from "../../plugin--FaLYDgu.js";
|
|
3
3
|
import { attach as l, createEffect as u, createEvent as d, createStore as f, sample as p } from "effector";
|
|
4
4
|
//#region src/server/serialize.ts
|
|
5
5
|
var m = 1e4;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require("./logger-CSTvAyyB.cjs");const e=require("./api-
|
|
1
|
+
require("./logger-CSTvAyyB.cjs");const e=require("./api-B4atkKWy.cjs");let t=require("effector");function n(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return t>>>0}function r(e){return n(e)%100}function i(e,t){return t<=0?!1:t>=100?!0:e<t}function a(e){return typeof e==`object`&&!!e&&`features`in e&&Array.isArray(e.features)}function o(e,t){if(Array.isArray(t.conditions))for(let n of t.conditions)e.registerCondition(n)}function s(e,t){e.registerExperience({id:t.id,key:t.key,name:t.name,targets:t.targets,nodes:t.nodes,edges:t.edges,condition:t.condition,initializeOpen:t.initializeOpen,componentName:t.componentName})}function c(e,t){if(Array.isArray(t.fields))for(let n of t.fields)e.registerField(n)}function l(e,t){if(!Array.isArray(t.steps))return;let n=new Map(t.fields.map(e=>[e.id,e.key]));for(let r of t.steps){let t=[];for(let e of r.fieldIds??[]){let i=n.get(e);if(i===void 0){`${r.key}${e}`;continue}t.push(i)}let i=r.layoutContentId?e.contents.getById(r.layoutContentId):null;e.registerStep({id:r.id,key:r.key,name:r.name,fieldKeys:t,layoutName:r.layoutName,...r.layoutContentId!==void 0&&{layoutContentId:r.layoutContentId,layoutContentStore:i}})}}function u(e,t){if(Array.isArray(t.experiences))for(let n of t.experiences)s(e,n)}function d(e,t,n){m(e,t,n.isPreview,n.sessionId),o(e,t),c(e,t),l(e,t),u(e,t)}function f(e){let t=e.searchParams[`preview-token`];if(t&&t.length>0)return t[0]}function p(e){let t=new Set,n=e.searchParams.feature;if(!n)return t;for(let e of n){let n=e.indexOf(`:`);n>0&&t.add(e.substring(0,n))}return t}function m(e,t,n,i){let a=p(e),o=r(i);for(let r of t.features)a.has(r.id)||h(e,r,n,o)}function h(e,t,n,r){e.registerFeature(t.id,{key:`v${t.version}`,name:t.name,storage:n?`session`:`local`,decide:()=>t.enabled?i(r,t.weight):!1})}function g(e){try{let t=new URL(e).hostname;return t===`localhost`||t===`127.0.0.1`||t===`::1`}catch{return!1}}function _(e){if(typeof e!=`object`||!e||!(`cause`in e))return!1;let{cause:t}=e;return typeof t!=`object`||!t||!(`code`in t)?!1:t.code===`ECONNREFUSED`}async function v(t,n,r){let i=r?.previewToken?`projects/${n}?preview_token=${encodeURIComponent(r.previewToken)}`:`projects/${n}`,o;try{o=await e.t(t,i,r?.headers)}catch(e){return g(t)&&_(e),null}if(!o.ok)return`${o.status.toString()}`,null;let s;try{s=await o.json()}catch{return null}return a(s)?s:null}function y(e){return typeof e!=`object`||!e||!(`experienceId`in e)||!(`content`in e)?!1:Array.isArray(e.content)}async function b(t,n,r,i){let a=i?.previewToken?`projects/${n}/experiences/${r}/content?preview_token=${encodeURIComponent(i.previewToken)}`:`projects/${n}/experiences/${r}/content`,o;try{o=await e.t(t,a,i?.headers,i?.signal)}catch(e){return g(t)&&_(e)||`${r}`,null}if(!o.ok)return`${r}${o.status.toString()}`,null;let s;try{s=await o.json()}catch{return`${r}`,null}return y(s)?s:(`${r}`,null)}function x(e,t){for(let n of t.content)e.registerContent({id:n.id,contentModelKey:n.contentModelKey,data:n.data})}function S(e){if(typeof e!=`object`||!e||!(`projectConfig`in e)||!(`experienceContent`in e)||!(`manifestMetadata`in e))return!1;let{experienceContent:t}=e;return typeof t==`function`}async function C(){try{let e=await import(`virtual:picked/data`);return S(e)?e:null}catch{return null}}function w(e,t,n){return r=>b(e,t,r.id,n?{previewToken:n}:void 0)}function T(e,t){return n=>e(n,t?{previewToken:t}:void 0)}function E(e){return(t,n)=>e.experienceContent(t,n)}function D(e,t){let n=new Map;return(r,i)=>{let a=n.get(r.id);if(a)return a;let o=(async()=>{try{let n=await t(r,i);return n&&x(e,n),n}finally{n.delete(r.id)}})();return n.set(r.id,o),o}}function O(e,t){let n=new Set(t&&Array.isArray(t.experiences)?t.experiences.map(e=>e.id):[]);return(t,r)=>n.has(t.id)?e(t,r):Promise.resolve(null)}async function k(e){let{client:t,apiUrl:n,options:r}=e,i=f(t),a=!!i,o=r?.projectConfig??null,s=r?.getContent?T(r.getContent,i):null,c=null;if(i)return o??=await v(n,t.projectId,{previewToken:i}),s??=w(n,t.projectId,i),{config:o,contentLoader:s,dataSource:c,isPreview:a};if(o&&s)return{config:o,contentLoader:s,dataSource:c,isPreview:a};let l=await C();return l?(o??=l.projectConfig,s??=E(l),c=l.manifestMetadata,{config:o,contentLoader:s,dataSource:c,isPreview:a}):(o??=await v(n,t.projectId),s??=w(n,t.projectId),{config:o,contentLoader:s,dataSource:c,isPreview:a})}function A(e){return{name:`dynamic-experiences`,setup:n=>{let r=e?.apiUrl??n.apiUrl;return{onStart:(0,t.attach)({source:n.session.store.map(e=>e.id),effect:async t=>{let{config:i,contentLoader:a,dataSource:o,isPreview:s}=await k({client:n,apiUrl:r,options:e});a&&(n.contentLoader=D(n,O(a,i))),n.dataSource=o,i&&d(n,i,{isPreview:s,sessionId:t})}})}}}}Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return A}});
|
package/dist/types/exports.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { CreateClientOptions } from './client';
|
|
2
2
|
import { Picked } from './picked';
|
|
3
3
|
export { isPickedRoot } from './utils/dom';
|
|
4
|
+
export { rehydrateScripts, buildRehydrateBootstrap, PICKED_SCRIPT_TYPE, PICKED_MODULE_SCRIPT_TYPE, PICKED_HYDRATED_ATTR, } from './utils/rehydrate-scripts';
|
|
5
|
+
export { isHtmlAssetValue } from './utils/html-asset-value';
|
|
6
|
+
export type { HtmlAssetValue } from './utils/html-asset-value';
|
|
4
7
|
export * from './utils/supports';
|
|
5
8
|
export * from './utils/storage';
|
|
6
9
|
export type * from './utils/storage';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exports.d.ts","sourceRoot":"","sources":["../../src/exports.ts"],"names":[],"mappings":"AAAA,8IAA8I;AAC9I,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAGjC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"exports.d.ts","sourceRoot":"","sources":["../../src/exports.ts"],"names":[],"mappings":"AAAA,8IAA8I;AAC9I,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAGjC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EACL,gBAAgB,EAChB,uBAAuB,EACvB,kBAAkB,EAClB,yBAAyB,EACzB,oBAAoB,GACrB,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAC3D,YAAY,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAE9D,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA;AAC/B,mBAAmB,iBAAiB,CAAA;AACpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAA;AAChF,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAE7D;;;;;;;;;;GAUG;AACH,eAAO,MAAM,YAAY,GAAI,SAAS,mBAAmB,KAAG,MAI3D,CAAA;AAED,YAAY,EACV,uBAAuB,EACvB,qBAAqB,GACtB,MAAM,kCAAkC,CAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** @file Resolved CMS `html-asset` field value delivered inline to consumers. */
|
|
2
|
+
/**
|
|
3
|
+
* A resolved `html-asset` content field. The API inlines the file's text at `content` server-side
|
|
4
|
+
* (`content: null` when the underlying file could not be resolved); there is no separate URL to fetch.
|
|
5
|
+
*/
|
|
6
|
+
export interface HtmlAssetValue {
|
|
7
|
+
readonly id: string;
|
|
8
|
+
readonly content: string | null;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Narrows an untyped resolved content-field value (for example `content.body` from `getStepContent()` /
|
|
12
|
+
* `useStepContent()`) to {@link HtmlAssetValue}.
|
|
13
|
+
*
|
|
14
|
+
* @param {unknown} value - A field value from the resolved content blob.
|
|
15
|
+
* @returns {value is HtmlAssetValue} True when `value` is `{ id: string; content: string | null }`.
|
|
16
|
+
* @example
|
|
17
|
+
* if (isHtmlAssetValue(content.body)) render(content.body.content)
|
|
18
|
+
*/
|
|
19
|
+
export declare function isHtmlAssetValue(value: unknown): value is HtmlAssetValue;
|
|
20
|
+
//# sourceMappingURL=html-asset-value.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html-asset-value.d.ts","sourceRoot":"","sources":["../../../src/utils/html-asset-value.ts"],"names":[],"mappings":"AAAA,iFAAiF;AAEjF;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;CAChC;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc,CASxE"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** @file Re-executes Picked-tagged <script> elements that innerHTML left inert. */
|
|
2
|
+
/** Inert script type the Picked transform stamps on classic scripts it blesses for rehydration. */
|
|
3
|
+
export declare const PICKED_SCRIPT_TYPE = "application/picked-javascript";
|
|
4
|
+
/** Inert script type the Picked transform stamps on `type="module"` scripts it blesses for rehydration. */
|
|
5
|
+
export declare const PICKED_MODULE_SCRIPT_TYPE = "application/picked-module";
|
|
6
|
+
/** Marker set on resurrected scripts so rehydration is idempotent. */
|
|
7
|
+
export declare const PICKED_HYDRATED_ATTR = "data-picked-hydrated";
|
|
8
|
+
/**
|
|
9
|
+
* Re-creates every Picked-tagged (`type="application/picked-javascript"` or
|
|
10
|
+
* `type="application/picked-module"`) script under `root` as a fresh, executable element, so
|
|
11
|
+
* scripts inserted via `innerHTML` (which never run) execute — restored as `type="module"` for the
|
|
12
|
+
* latter. Untagged scripts, including data blocks such as `application/json` or `importmap`, are left
|
|
13
|
+
* untouched. In-place replacement preserves document order and
|
|
14
|
+
* `document.currentScript.getRootNode()`, so shadow-scoped page scripts find their own root.
|
|
15
|
+
*
|
|
16
|
+
* This function intentionally references only globals and its own parameter, never the exported
|
|
17
|
+
* `PICKED_*` constants above, so {@link buildRehydrateBootstrap} can serialise it with `.toString()` for
|
|
18
|
+
* injection into a sandboxed iframe, where module imports are unavailable.
|
|
19
|
+
*
|
|
20
|
+
* @param {ParentNode} root - Element, ShadowRoot, or Document whose tagged scripts to rehydrate.
|
|
21
|
+
* @returns {Promise<void>} Resolves after external (`src`) scripts have settled (load or error).
|
|
22
|
+
* @example
|
|
23
|
+
* await rehydrateScripts(shadowRoot)
|
|
24
|
+
*/
|
|
25
|
+
export declare function rehydrateScripts(root: ParentNode): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Builds an inline `<script>` string that runs {@link rehydrateScripts} against the injected document.
|
|
28
|
+
* For splicing into an iframe `srcDoc` (or any HTML string) where module imports are unavailable.
|
|
29
|
+
*
|
|
30
|
+
* @returns {string} A self-contained `<script>…</script>` string.
|
|
31
|
+
* @example
|
|
32
|
+
* html.replace('</body>', buildRehydrateBootstrap() + '</body>')
|
|
33
|
+
*/
|
|
34
|
+
export declare function buildRehydrateBootstrap(): string;
|
|
35
|
+
//# sourceMappingURL=rehydrate-scripts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rehydrate-scripts.d.ts","sourceRoot":"","sources":["../../../src/utils/rehydrate-scripts.ts"],"names":[],"mappings":"AAAA,mFAAmF;AAEnF,mGAAmG;AACnG,eAAO,MAAM,kBAAkB,kCAAkC,CAAA;AACjE,2GAA2G;AAC3G,eAAO,MAAM,yBAAyB,8BAA8B,CAAA;AACpE,sEAAsE;AACtE,eAAO,MAAM,oBAAoB,yBAAyB,CAAA;AAE1D;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,gBAAgB,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CA6DtE;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,CAEhD"}
|
package/package.json
CHANGED
package/dist/api-DqWHooZI.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var e=`Picked-Client`,t=`Picked-Version`;function n(n,r){return{[e]:n,[t]:r}}var r=()=>`0.0.65-next.3`,i=`v1`;function a(e,t){return new URL(`/api/${i}/${t}`,e).toString()}function o(e){return{...n(`sdk`,r()),...e}}async function s(e,t,n,r){let i=a(e,t);return fetch(i,{headers:o(n),signal:r})}async function c(e,t,n,r){let i=a(e,t);return fetch(i,{method:`POST`,headers:{"Content-Type":`application/json`,...o(r)},body:JSON.stringify(n)})}Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return s}});
|