@picked/vite-plugin-picked 0.0.1-dev.1795388735478 → 0.0.1-dev.1795648442182
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/client.d.ts +8 -1
- package/dist/.tsbuildinfo +1 -1
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +119 -8
- package/dist/cjs/prefetch.d.ts +11 -0
- package/dist/cjs/prefetch.d.ts.map +1 -1
- package/dist/cjs/virtual-module/api.d.ts +6 -4
- package/dist/cjs/virtual-module/api.d.ts.map +1 -1
- package/dist/cjs/virtual-module/build.d.ts +29 -1
- package/dist/cjs/virtual-module/build.d.ts.map +1 -1
- package/dist/cjs/virtual-module/dev.d.ts +12 -11
- package/dist/cjs/virtual-module/dev.d.ts.map +1 -1
- package/dist/cjs/virtual-module/flow.d.ts +23 -0
- package/dist/cjs/virtual-module/flow.d.ts.map +1 -0
- package/dist/cjs/virtual-module/snapshot.d.ts +12 -1
- package/dist/cjs/virtual-module/snapshot.d.ts.map +1 -1
- package/dist/esm/index.js +419 -249
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/prefetch.d.ts +11 -0
- package/dist/types/prefetch.d.ts.map +1 -1
- package/dist/types/virtual-module/api.d.ts +6 -4
- package/dist/types/virtual-module/api.d.ts.map +1 -1
- package/dist/types/virtual-module/build.d.ts +29 -1
- package/dist/types/virtual-module/build.d.ts.map +1 -1
- package/dist/types/virtual-module/dev.d.ts +12 -11
- package/dist/types/virtual-module/dev.d.ts.map +1 -1
- package/dist/types/virtual-module/flow.d.ts +23 -0
- package/dist/types/virtual-module/flow.d.ts.map +1 -0
- package/dist/types/virtual-module/snapshot.d.ts +12 -1
- package/dist/types/virtual-module/snapshot.d.ts.map +1 -1
- package/package.json +6 -6
package/dist/cjs/index.d.ts
CHANGED
|
@@ -19,6 +19,8 @@ export interface PickedPluginOptions {
|
|
|
19
19
|
* release drops it. Setting both to different values is an error.
|
|
20
20
|
*/
|
|
21
21
|
apiUrl?: string;
|
|
22
|
+
/** Extra headers on the plugin's Node-side requests to the Picked API. */
|
|
23
|
+
customHeaders?: Record<string, string>;
|
|
22
24
|
/** Disable the launcher HTML page (dev server + build output). Defaults to false. */
|
|
23
25
|
disableLauncher?: boolean;
|
|
24
26
|
/** Generate TypeScript types from the workspace schema on dev/build. Defaults to true. */
|
package/dist/cjs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAqB,MAAM,EAAU,MAAM,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAqB,MAAM,EAAU,MAAM,MAAM,CAAA;AAuc7D,MAAM,WAAW,mBAAmB;IAClC;;;;;OAKG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,0EAA0E;IAC1E,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACtC,qFAAqF;IACrF,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,0FAA0F;IAC1F,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB;;;;OAIG;IACH,IAAI,CAAC,EAAE,QAAQ,GAAG,KAAK,CAAA;CACxB;AA+BD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,MAAM,CAAC,OAAO,GAAE,mBAAwB,GAAG,MAAM,CAiYhE"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -854,19 +854,21 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require
|
|
|
854
854
|
<\/script>
|
|
855
855
|
</main>
|
|
856
856
|
</body>
|
|
857
|
-
</html>`]),n,t)}function m(e){return e.replaceAll(`&`,`&`).replaceAll(`<`,`<`).replaceAll(`>`,`>`).replaceAll(`"`,`"`)}function h(e){return e.replaceAll(`&`,`&`).replaceAll(`"`,`"`).replaceAll(`<`,`<`).replaceAll(`>`,`>`)}var g=`picked`,_=`\x1B[0m`;function v(){let e=process.env.NO_COLOR;return e===`1`||e===`true`}function y(e){return t=>v()?t:`${e}${t}${_}`}var b=[`debug`,`info`,`warn`,`error`,`silent`],x={debug:{color:y(`\x1B[2m`),log:console.debug,enabled:!1},info:{color:y(`\x1B[36m`),log:console.log,enabled:!0},warn:{color:y(`\x1B[33m`),log:console.warn,enabled:!0},error:{color:y(`\x1B[31m`),log:console.error,enabled:!0},silent:{log:()=>{},enabled:!1}};function S(e,t){return`${new Date().toLocaleTimeString()} [${t?`${g}:${t}`:g}] ${e}`}function C(e,t,n,r){if(!e.enabled)return;let i=S(t,r);e.log(e.color?e.color(i):i),n!==void 0&&e.log(n)}function w(e){let t=x[e],n=new Set;return Object.assign((e,n,r)=>{C(t,e,n,r)},{once(e,r,i){t.enabled&&!n.has(e)&&(n.add(e),C(t,e,r,i))}})}function
|
|
857
|
+
</html>`]),n,t)}function m(e){return e.replaceAll(`&`,`&`).replaceAll(`<`,`<`).replaceAll(`>`,`>`).replaceAll(`"`,`"`)}function h(e){return e.replaceAll(`&`,`&`).replaceAll(`"`,`"`).replaceAll(`<`,`<`).replaceAll(`>`,`>`)}var g=`picked`,_=`\x1B[0m`;function v(){let e=process.env.NO_COLOR;return e===`1`||e===`true`}function y(e){return t=>v()?t:`${e}${t}${_}`}var b=[`debug`,`info`,`warn`,`error`,`silent`],x={debug:{color:y(`\x1B[2m`),log:console.debug,enabled:!1},info:{color:y(`\x1B[36m`),log:console.log,enabled:!0},warn:{color:y(`\x1B[33m`),log:console.warn,enabled:!0},error:{color:y(`\x1B[31m`),log:console.error,enabled:!0},silent:{log:()=>{},enabled:!1}};function S(e,t){return`${new Date().toLocaleTimeString()} [${t?`${g}:${t}`:g}] ${e}`}function C(e,t,n,r){if(!e.enabled)return;let i=S(t,r);e.log(e.color?e.color(i):i),n!==void 0&&e.log(n)}function w(e){let t=x[e],n=new Set;return Object.assign((e,n,r)=>{C(t,e,n,r)},{once(e,r,i){t.enabled&&!n.has(e)&&(n.add(e),C(t,e,r,i))}})}function T(e){let t=b.indexOf(e);if(t===-1)C(x.error,`invalid log level: ${e}`);else for(let[e,n]of b.entries())x[n].enabled=e>=t}var E=y(`\x1B[34m`),D=y(`\x1B[36m`);function ee(){let e=[` ${E(`_`)} ${D(`_`)} _ _ _`,`${E(`(_)`)} ${D(`(_)`)} _ __(_)__| |_____ __| |`,` ${E(`_`)} ${E(`_`)} | '_ \\ / _| / / -_) _\` |`,`${E(`(_)`)} ${E(`(_)`)} | .__/_\\__|_\\_\\___\\__,_|`,` |_|
|
|
858
858
|
`];console.log(e.join(`
|
|
859
|
-
`))}var
|
|
859
|
+
`))}var O={banner:ee,debug:w(`debug`),info:w(`info`),warn:w(`warn`),error:w(`error`),setLevel:T};function te(e){return(t,n,r)=>{if(t.method!==`GET`){r();return}let i=(t.url??``).split(`?`)[0];if(i!==`/`&&i!==`/index.html`){r();return}let a=e();n.setHeader(`Content-Type`,`text/html`),n.statusCode=200,n.end(a)}}var k=`.picked/`;async function ne(n,r){if(r)return;let i=(0,t.join)(n,`.gitignore`);if(!(0,e.existsSync)(i)){await(0,a.writeFile)(i,`${k}
|
|
860
860
|
`);return}let o=await(0,a.readFile)(i,`utf8`);if(re(o))return;let s=`${o.length>0&&!o.endsWith(`
|
|
861
861
|
`)?`
|
|
862
862
|
`:``}${k}
|
|
863
|
-
`;await(0,a.appendFile)(i,s)}function re(e){return e.split(/\r?\n/).map(e=>e.trim()).some(e=>e===k||e===`.picked`)}var A=6,ie=5e3;function j(e){let t;try{t=new URL(e).hostname}catch{return!1}return t===`localhost`||t===`127.0.0.1`||t===`::1`||t===`[::1]`?!0:t===`api.picked.app`?!1:t.endsWith(`.picked.app`)||t.endsWith(`.picked-dev.app`)}function
|
|
863
|
+
`;await(0,a.appendFile)(i,s)}function re(e){return e.split(/\r?\n/).map(e=>e.trim()).some(e=>e===k||e===`.picked`)}var A=6,ie=5e3;function j(e){let t;try{t=new URL(e).hostname}catch{return!1}return t===`localhost`||t===`127.0.0.1`||t===`::1`||t===`[::1]`?!0:t===`api.picked.app`?!1:t.endsWith(`.picked.app`)||t.endsWith(`.picked-dev.app`)}function ae(e){return new Promise(t=>{setTimeout(t,e)})}async function M(e,t){let n=null,r=null;try{n=await e()}catch(e){r=e}if(n!==null)return n;for(let i=1;i<=A;i++){let a=ie*2**(i-1);t(i,A,a),await ae(a),r=null;try{n=await e()}catch(e){r=e}if(n!==null)return n}if(r!==null)throw r;return null}function N(e){return Array.isArray(e)?e:[]}function oe(e){let t=e.variants,n=(t??[]).reduce((e,t)=>e+t.weight,0);return!t||t.length===0||n===0?`${e.weight.toString()}%`:t.map(e=>{let t=Math.round(100*e.weight/n);return`${String(e.value)} ${t.toString()}%`}).join(`, `)}var P=2;function F(e){let n=(0,t.join)(e,`.picked`);return{pickedDir:n,manifestPath:(0,t.join)(n,`manifest.json`),projectConfigPath:(0,t.join)(n,`project-config.json`),projectManifestPath:(0,t.join)(n,`project-manifest.json`),flowsDir:(0,t.join)(n,`flows`),experiencesDir:(0,t.join)(n,`experiences`)}}async function se(t){if(!(0,e.existsSync)(t))return null;try{let e=await(0,a.readFile)(t,`utf8`),n=JSON.parse(e);return ce(n)?n:null}catch{return null}}function ce(e){return!(typeof e!=`object`||!e||!(`version`in e)||typeof e.version!=`number`||!(`projectVersionId`in e)||typeof e.projectVersionId!=`string`||!(`workspaceId`in e)||typeof e.workspaceId!=`string`||!(`experiences`in e)||!Array.isArray(e.experiences))}function le(e){let t=new Set;for(let n of N(e.steps))n.layoutContentId&&t.add(n.id);if(t.size===0)return[];let n=[];for(let r of N(e.experiences))N(r.nodes).some(e=>e.type===`step`&&t.has(e.stepId))&&n.push(r.id);return n}async function ue(n){let{apiUrl:r,projectId:i,projectRoot:o,headers:s,previewToken:c,reuseWhenUnchanged:l=!0,configLoading:u=`full`}=n,d=F(o),f=await fe(r,i,s,c),p=le(f);await(0,a.mkdir)(d.experiencesDir,{recursive:!0}),await(0,a.writeFile)(d.projectConfigPath,JSON.stringify(f,null,2));let m=u===`manifest`?await de(d,f):{};if(l){let t=await se(d.manifestPath);if(t?.version===P&&t.projectVersionId===f.versionId&&t.workspaceId===f.workspaceId){let n=I(d,p);if(Object.values(n).every(t=>(0,e.existsSync)(t)))return{config:f,manifest:t,experienceContentPaths:n,experienceFlowPaths:m};O.info(`a manifest-referenced content file is missing; refetching every experience`)}}let h=new Date().toISOString(),g=[];for(let e of p){let n=await pe(r,i,e,s,c),o=(0,t.join)(d.experiencesDir,`${e}.json`);await(0,a.writeFile)(o,JSON.stringify(n,null,2)),g.push({id:e,fetchedAt:h})}let _={version:P,fetchedAt:h,projectVersionId:f.versionId,workspaceId:f.workspaceId,projectId:f.id,experiences:g};return await(0,a.writeFile)(d.manifestPath,JSON.stringify(_,null,2)),{config:f,manifest:_,experienceContentPaths:I(d,p),experienceFlowPaths:m}}async function de(e,r){let{manifest:i,flows:o}=(0,n.splitProjectConfig)(r);await(0,a.writeFile)(e.projectManifestPath,JSON.stringify(i,null,2)),await(0,a.rm)(e.flowsDir,{recursive:!0,force:!0}),await(0,a.mkdir)(e.flowsDir,{recursive:!0});let s=await Promise.all([...o].map(async([n,r])=>{let i=(0,t.join)(e.flowsDir,`${n}.json`);return await(0,a.writeFile)(i,JSON.stringify(r,null,2)),[n,i]}));return Object.fromEntries(s)}function I(e,n){let r={};for(let i of n)r[i]=(0,t.join)(e.experiencesDir,`${i}.json`);return r}async function fe(e,t,r,i){let a=()=>(0,n.fetchProject)(e,t,{headers:r,previewToken:i}),o;try{o=j(e)?await M(a,(e,t,n)=>{O.info(`project config not ready, retrying in ${(n/1e3).toString()}s (${e.toString()}/${t.toString()})`)}):await a()}catch(n){throw Error(`[picked] Build-time fetch of project config failed for "${t}" at ${e}: ${L(n)}`)}if(!o)throw Error(`[picked] Build-time fetch of project config returned no usable response for "${t}" at ${e}. Confirm the API is reachable and the project ID is correct.`);return o}async function pe(e,t,r,i,a){let o;try{o=await(0,n.fetchExperienceContent)(e,t,r,{headers:i,previewToken:a})}catch(t){throw Error(`[picked] Build-time fetch of content for experience "${r}" failed at ${e}: ${L(t)}`)}if(!o)throw Error(`[picked] Build-time fetch of content for experience "${r}" returned no usable response. Confirm the experience id exists and the API is reachable.`);return o}function L(e){if(e instanceof Error)return e.message;if(typeof e==`string`)return e;try{return JSON.stringify(e)}catch{return`unknown error`}}var me=new Set([`resolveId`,`load`]);function he(e=(0,o.createTraceId)()){let t=(0,o.createSpanId)(),n=Date.now(),r=[],a=new Map;return{record:(n,i)=>{if(me.has(n)){let e=a.get(n)??{calls:0,totalMs:0};a.set(n,{calls:e.calls+1,totalMs:e.totalMs+i});return}let s=Date.now();r.push({name:`picked.vite.${n}`,traceId:e,spanId:(0,o.createSpanId)(),parentSpanId:t,startTimeUnixNano:(0,o.toUnixNano)(s-i),endTimeUnixNano:(0,o.toUnixNano)(s),attributes:{"picked.vite.hook":n},status:`ok`})},flush:async s=>{let c={};for(let[e,t]of a)c[`picked.vite.${e}.calls`]=t.calls,c[`picked.vite.${e}.total_ms`]=Math.round(t.totalMs);let l=(0,i.detectHostEnvironment)();r.push({name:`picked.vite.build`,traceId:e,spanId:t,startTimeUnixNano:(0,o.toUnixNano)(n),endTimeUnixNano:(0,o.toUnixNano)(Date.now()),attributes:{"picked.env.provider":l.provider,"picked.env.ci":l.ci,...s,...c},status:`ok`});try{let e=(0,o.createTelemetryEmitter)({resource:{"service.name":`picked-vite-plugin`},headers:{"Picked-Telemetry":`vite-plugin`},maxBatchSize:r.length});for(let t of r)e.record(t);await e.flush()}catch{}}}}function ge(e){return typeof e==`object`&&!!e&&`then`in e}function R(e,t,n){return function(...r){let i=performance.now(),a=()=>{n.record(e,performance.now()-i)},o=t.apply(this,r);return ge(o)?Promise.resolve(o).then(a,a):a(),o}}function z(e){return typeof e==`function`}function _e(e,t){if(!e)return t;for(let[n,r]of Object.entries(t))n!==`name`&&(z(r)?Reflect.set(t,n,R(n,r,e)):typeof r==`object`&&r&&`handler`in r&&z(r.handler)&&Reflect.set(r,`handler`,R(n,r.handler,e)));return t}function ve(e){return`export const configLoading = ${JSON.stringify(e)}
|
|
864
|
+
|
|
865
|
+
export const manifestMetadata = {
|
|
864
866
|
mode: 'api',
|
|
865
867
|
fetchedAt: null,
|
|
866
868
|
projectVersionId: null,
|
|
867
869
|
workspaceId: null,
|
|
868
870
|
}
|
|
869
|
-
`}function
|
|
871
|
+
`}function ye(e){let{projectConfigPath:t,experienceContentPaths:n,manifestMetadata:r}=e,i=e=>JSON.stringify(e),a=Object.entries(n).map(([e,t])=>` ${JSON.stringify(e)}: () => import(${i(t)}).then((m) => m.default ?? m),`).join(`
|
|
870
872
|
`);return`import { registerPickedBundle } from '@picked/client/plugins/dynamic-experiences'
|
|
871
873
|
import projectConfigJson from ${i(t)}
|
|
872
874
|
|
|
@@ -891,7 +893,46 @@ export async function experienceContent(experience, _options) {
|
|
|
891
893
|
export const manifestMetadata = ${JSON.stringify(r)}
|
|
892
894
|
|
|
893
895
|
registerPickedBundle({ projectConfig, experienceContent, manifestMetadata })
|
|
894
|
-
`}function
|
|
896
|
+
`}function B(e){return Object.entries(e).map(([e,t])=>` ${JSON.stringify(e)}: () => import(${JSON.stringify(t)}).then((m) => m.default ?? m),`).join(`
|
|
897
|
+
`)}function be(e){let{projectManifestPath:t,experienceFlowPaths:n,experienceContentPaths:r,manifestMetadata:i}=e;return`import { registerPickedBundle } from '@picked/client/plugins/dynamic-experiences'
|
|
898
|
+
import projectManifestJson from ${JSON.stringify(t)}
|
|
899
|
+
|
|
900
|
+
const flowImporters = {
|
|
901
|
+
${B(n)}
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
const experienceImporters = {
|
|
905
|
+
${B(r)}
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
/**
|
|
909
|
+
* Loads one lazily imported JSON file for an experience, or resolves \`null\` when it has none.
|
|
910
|
+
*/
|
|
911
|
+
async function importFor(importers, experience) {
|
|
912
|
+
const id = typeof experience === 'string' ? experience : experience?.id
|
|
913
|
+
if (!id || !Object.hasOwn(importers, id)) return null
|
|
914
|
+
try {
|
|
915
|
+
return await importers[id]()
|
|
916
|
+
} catch {
|
|
917
|
+
return null
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
export const projectManifest = projectManifestJson
|
|
922
|
+
|
|
923
|
+
export async function experienceFlow(experience) {
|
|
924
|
+
return importFor(flowImporters, experience)
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
export async function experienceContent(experience, _options) {
|
|
928
|
+
return importFor(experienceImporters, experience)
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
export const manifestMetadata = ${JSON.stringify(i)}
|
|
932
|
+
|
|
933
|
+
registerPickedBundle({ projectManifest, experienceFlow, experienceContent, manifestMetadata })
|
|
934
|
+
`}var V=`virtual:picked/data/flow/`;function H(e){return e.experiences.map((e,t)=>{let n=JSON.stringify(V+t.toString());return` ${JSON.stringify(e.id)}: () => import(${n}).then((m) => m.default),`}).join(`
|
|
935
|
+
`)}function U(e,t){let r=e&&/^\d+$/.test(t)?e.experiences[Number(t)]:void 0,i=e&&r?(0,n.splitProjectConfig)(e).flows.get(r.id)??null:null;return`export default ${JSON.stringify(i)}\n`}function xe(e){let{apiUrl:t,projectId:n,projectConfig:r,previewToken:i}=e,a=r?`import { fetchExperienceContent, registerPickedBundle } from '@picked/client/plugins/dynamic-experiences'`:`import { fetchProject, fetchExperienceContent } from '@picked/client/plugins/dynamic-experiences'`,o=r?`export const projectConfig = ${JSON.stringify(r)}`:`export const projectConfig = await fetchProject(apiUrl, projectId, { previewToken: previewToken ?? undefined })`,s=r?`
|
|
895
936
|
registerPickedBundle({ projectConfig, experienceContent, manifestMetadata })
|
|
896
937
|
`:``;return`${a}
|
|
897
938
|
|
|
@@ -913,7 +954,47 @@ export const manifestMetadata = {
|
|
|
913
954
|
projectVersionId: projectConfig?.versionId ?? null,
|
|
914
955
|
workspaceId: projectConfig?.workspaceId ?? null,
|
|
915
956
|
}
|
|
916
|
-
${s}`}
|
|
957
|
+
${s}`}function Se(e){let{apiUrl:t,projectId:r,projectConfig:i,previewToken:a}=e,o=i?(0,n.splitProjectConfig)(i):null,s=o?`import { fetchExperienceContent, registerPickedBundle } from '@picked/client/plugins/dynamic-experiences'`:`import { fetchProjectManifest, fetchExperienceFlow, fetchExperienceContent } from '@picked/client/plugins/dynamic-experiences'`,c=o?`export const projectManifest = ${JSON.stringify(o.manifest)}`:`export const projectManifest = await fetchProjectManifest(apiUrl, projectId, { previewToken: previewToken ?? undefined })`,l=i?`const flowImporters = {
|
|
958
|
+
${H(i)}
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
export async function experienceFlow(experience) {
|
|
962
|
+
const id = typeof experience === 'string' ? experience : experience?.id
|
|
963
|
+
if (!id || !Object.hasOwn(flowImporters, id)) return null
|
|
964
|
+
return await flowImporters[id]()
|
|
965
|
+
}`:`export async function experienceFlow(experience) {
|
|
966
|
+
if (!projectManifest || !experience?.id) return null
|
|
967
|
+
return await fetchExperienceFlow(
|
|
968
|
+
apiUrl,
|
|
969
|
+
projectId,
|
|
970
|
+
{ experienceId: experience.id, versionId: previewToken ? null : projectManifest.versionId },
|
|
971
|
+
{ previewToken: previewToken ?? undefined },
|
|
972
|
+
)
|
|
973
|
+
}`,u=o?`
|
|
974
|
+
registerPickedBundle({ projectManifest, experienceFlow, experienceContent, manifestMetadata })
|
|
975
|
+
`:``;return`${s}
|
|
976
|
+
|
|
977
|
+
const apiUrl = ${JSON.stringify(t)}
|
|
978
|
+
const projectId = ${JSON.stringify(r)}
|
|
979
|
+
const previewToken = ${JSON.stringify(a??null)}
|
|
980
|
+
|
|
981
|
+
${c}
|
|
982
|
+
|
|
983
|
+
${l}
|
|
984
|
+
|
|
985
|
+
export async function experienceContent(experience, options) {
|
|
986
|
+
const id = typeof experience === 'string' ? experience : experience?.id
|
|
987
|
+
if (!id) return null
|
|
988
|
+
return await fetchExperienceContent(apiUrl, projectId, id, { previewToken: previewToken ?? undefined, ...options })
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
export const manifestMetadata = {
|
|
992
|
+
mode: 'dev',
|
|
993
|
+
fetchedAt: null,
|
|
994
|
+
projectVersionId: projectManifest?.versionId ?? null,
|
|
995
|
+
workspaceId: projectManifest?.workspaceId ?? null,
|
|
996
|
+
}
|
|
997
|
+
${u}`}var W=`virtual:picked/data/experience/`;function Ce(e){let t=Object.keys(e.experiences).map((e,t)=>{let n=JSON.stringify(W+t.toString());return` ${JSON.stringify(e)}: () => import(${n}).then((m) => m.default),`}).join(`
|
|
917
998
|
`),n={mode:`snapshot`,fetchedAt:null,projectVersionId:e.projectVersionId,workspaceId:e.workspaceId};return`import { registerPickedBundle } from '@picked/client/plugins/dynamic-experiences'
|
|
918
999
|
|
|
919
1000
|
const experienceImporters = {
|
|
@@ -932,5 +1013,35 @@ export async function experienceContent(experience, _options) {
|
|
|
932
1013
|
export const manifestMetadata = ${JSON.stringify(n)}
|
|
933
1014
|
|
|
934
1015
|
registerPickedBundle({ projectConfig, experienceContent, manifestMetadata })
|
|
935
|
-
`}function
|
|
936
|
-
`)
|
|
1016
|
+
`}function we(e,t){let n=/^\d+$/.test(t)?Object.keys(e.experiences)[Number(t)]:void 0,r=n===void 0?null:e.experiences[n]??null;return`export default ${JSON.stringify(r)}\n`}function Te(e){let t=Object.keys(e.experiences).map((e,t)=>{let n=JSON.stringify(W+t.toString());return` ${JSON.stringify(e)}: () => import(${n}).then((m) => m.default),`}).join(`
|
|
1017
|
+
`),r=H(e.projectConfig),i={mode:`snapshot`,fetchedAt:null,projectVersionId:e.projectVersionId,workspaceId:e.workspaceId};return`import { registerPickedBundle } from '@picked/client/plugins/dynamic-experiences'
|
|
1018
|
+
|
|
1019
|
+
const experienceImporters = {
|
|
1020
|
+
${t}
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
const flowImporters = {
|
|
1024
|
+
${r}
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
export const projectManifest = ${JSON.stringify((0,n.splitProjectConfig)(e.projectConfig).manifest)}
|
|
1028
|
+
|
|
1029
|
+
export async function experienceFlow(experience) {
|
|
1030
|
+
const id = typeof experience === 'string' ? experience : experience?.id
|
|
1031
|
+
if (!id) return null
|
|
1032
|
+
if (!Object.hasOwn(flowImporters, id)) return null
|
|
1033
|
+
return await flowImporters[id]()
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
export async function experienceContent(experience, _options) {
|
|
1037
|
+
const id = typeof experience === 'string' ? experience : experience?.id
|
|
1038
|
+
if (!id) return null
|
|
1039
|
+
if (!Object.hasOwn(experienceImporters, id)) return null
|
|
1040
|
+
return await experienceImporters[id]()
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
export const manifestMetadata = ${JSON.stringify(i)}
|
|
1044
|
+
|
|
1045
|
+
registerPickedBundle({ projectManifest, experienceFlow, experienceContent, manifestMetadata })
|
|
1046
|
+
`}var Ee=5;function G(e,t,n){if(t.length===0)return;if(t.length>Ee){console.log(`\n ${e}: ${t.length.toString()} loaded\n`);return}let r=n.map(e=>Math.max(e.header.length,...t.map(t=>e.value(t).length))),i=(e,t)=>e.padEnd(r[t]??e.length),a=` ${n.map((e,t)=>i(e.header,t)).join(` `)}`,o=` ${r.map(e=>`─`.repeat(e)).join(` `)}`,s=t.map(e=>` ${n.map((t,n)=>i(t.value(e),n)).join(` `)}`);console.log([``,` ${e}:`,``,a,o,...s,``].join(`
|
|
1047
|
+
`))}function De(e,t){t.length!==0&&console.log(`\n ${e}: ${t.length.toString()} loaded\n`)}var Oe=[{header:`Name`,value:e=>e.name},{header:`ID`,value:e=>e.id},{header:`Status`,value:e=>e.enabled?`\x1B[32m enabled\x1B[0m`:`\x1B[2mdisabled\x1B[0m`},{header:`Split`,value:e=>oe(e)},{header:`Ver`,value:e=>`v${e.version.toString()}`}],ke=[{header:`Name`,value:e=>e.name},{header:`Key`,value:e=>e.key},{header:`Component`,value:e=>e.componentName},{header:`Nodes`,value:e=>e.nodes.length.toString()},{header:`Targets`,value:e=>e.targets.length.toString()}],Ae=[{header:`Name`,value:e=>e.name},{header:`Key`,value:e=>e.key},{header:`Fields`,value:e=>(e.fieldIds?.length??0).toString()}],je=[{header:`Name`,value:e=>e.name},{header:`Key`,value:e=>e.key},{header:`Type`,value:e=>e.type},{header:`Required`,value:e=>e.required?`yes`:`no`}],Me=[{header:`Name`,value:e=>e.name},{header:`Key`,value:e=>e.key}];function Ne(){return`0.0.1-dev.1795648442182`}var Pe=`https://api.picked.app`,K=`virtual:picked/data`,q=`\0${K}`,J=`\0${W}`,Y=`\0${V}`;function Fe(e){for(let t of Object.values(e))if(t.type===`chunk`&&t.moduleIds.includes(q))return t.fileName}function Ie(e,t){return e===``||e.endsWith(`/`)?`${e}${t}`:`${e}/${t}`}async function Le(e){try{let t=await(0,r.generate)({config:e,onWarn:e=>{O.warn(e)}});O.info(`generated types at ${t.typesOutput}`)}catch(e){let t=e instanceof Error?e.message:String(e);throw Error(`type generation failed: ${t}. Fix the schema source, or set \`generateTypes: false\` on the picked plugin to skip it.`)}}function Re(e,t,n){return e&&(0,i.isTelemetryEnabled)(t,n)?e:null}async function ze(e,t){let n=await(0,i.loadResolvedPickedConfig)(e,t);if(!n)throw Error(`picked.config.{ts,js,json} is required. Add a picked.config.ts with projectId and apiUrl.`);return n}function X(e,t,n,r){if(t===void 0||n===void 0||t===n)return;let i=r===void 0?`picked.config says "${n}"`:`picked.config \`${r}\` is "${n}"`;throw Error(`picked plugin option \`${e}\` is "${t}", and ${i}. Remove the plugin option; picked.config is the one place this belongs.`)}async function Z(e){let t=await(0,i.loadPickedConfig)(e);return t&&(0,i.hasProject)(t)?t:null}function Be(e){e.data!==void 0&&O.warn("picked plugin option `mode` is deprecated, and a future release drops it. Set `data` in picked.config instead, which the CLI and the type generator read from too.");let t=[];if(e.projectId!==void 0&&t.push("`projectId`"),e.apiUrl!==void 0&&t.push("`apiUrl`"),t.length===0)return;let n=t.length>1;O.warn(`picked plugin option${n?`s`:``} ${t.join(` and `)} ${n?`are`:`is`} deprecated, and a future release drops ${n?`them`:`it`}. Move ${n?`them`:`it`} to picked.config, which the CLI and the type generator read from too.`)}async function Ve(e,t){let n=await Z(e);n&&n.projectId!==t&&O.warn(`using project "${t}" (picked.config default: "${n.projectId}") — run 'picked status' to inspect`)}async function He(e,t){let n=await Z(e);return X(`projectId`,t.projectId,n?.projectId),X(`apiUrl`,t.apiUrl,n?.apiUrl),X(`mode`,t.data,n?.data,`data`),Be(t),ze(e,t)}async function Ue(t){if(t.data!==`snapshot`)return(0,e.existsSync)((0,i.resolveSnapshotPath)(t.projectRoot))&&O.warn(`${i.SNAPSHOT_FILENAME} is ignored: the data mode in force is '${t.data}'. Set \`data: 'snapshot'\` in picked.config to build from it, or delete it.`),null;let n=await(0,i.requireSnapshot)(t);return O.info(`serving ${i.SNAPSHOT_FILENAME}: project "${n.projectId}", version ${n.projectVersionId??`none (preview)`} — run \`picked pull\` to refresh`),n.source===`preview`?O.warn(`${i.SNAPSHOT_FILENAME} holds preview data, so this run serves unpublished content. Run \`picked pull\` against the published workspace before you release.`):t.source===`preview`&&O.warn(`the preview workspace in force is not read: ${i.SNAPSHOT_FILENAME} holds published data. Run \`picked pull --allow-preview\` to serve the preview.`),n}async function We(e,t,r,i){let a=()=>(0,n.fetchProject)(e,t,{headers:r,previewToken:i??void 0});return j(e)?M(a,(e,t,n)=>{O.info(`local API not ready, retrying in ${(n/1e3).toString()}s (${e.toString()}/${t.toString()})`)}):a()}var Q=new Map;function Ge(e,t,n){return JSON.stringify([e,t,n])}function Ke(r={}){let a=r.mode,o=a??`bundle`,s=null,c=r.generateTypes??!0,l=[],u=process.cwd(),d=`serve`,f=`/`,m=null,h=!1,g,_,v=null,y=(e,t)=>o===`snapshot`&&s&&m?(e.addWatchFile((0,i.resolveSnapshotPath)(m.projectRoot)),U(s.projectConfig,t)):U(v,t),b=(0,i.isTelemetryForcedOffByEnvironment)()?null:he();return _e(b,{name:`picked`,config:async(i,f)=>{d=f.command,u=i.root===void 0?process.cwd():(0,t.resolve)(process.cwd(),i.root);let{projectId:p,apiUrl:y}=r;m=await He(u,{projectId:p,apiUrl:y,data:a});let{projectId:x,apiUrl:S,previewToken:C,configLoading:w}=m;if(o=m.data,b=Re(b,m,r.telemetry),O.banner(),s=await Ue(m),s&&(l=N(s.projectConfig.features)),c&&!h&&(h=!0,await Le(m)),o===`snapshot`)return;S!==Pe&&O.warn(`using custom API URL: ${S}`),await Ve(u,x);let T=(0,n.createClientHeaders)(`vite-plugin`,Ne()),E=new Set(Object.keys(T).map(e=>e.toLowerCase())),D={...Object.fromEntries(Object.entries(r.customHeaders??{}).filter(([e])=>!E.has(e.toLowerCase()))),...T};if(o===`api`)O.debug(`data is 'api': skipping the project-config prefetch`);else if(f.command===`build`){let t=Ge(S,x,u);g=t;let n=Q.get(t);n===void 0&&(n=(async()=>{O.info(`prefetching project config + content for "${x}"`);let t=F(u),n=(0,e.existsSync)(t.pickedDir),r=performance.now(),i=await ue({apiUrl:S,projectId:x,projectRoot:u,headers:D,previewToken:C??void 0,configLoading:w}),a=(performance.now()-r).toFixed(0);await ne(u,n);let o=i.config;$(o,a);let s={mode:`build`,fetchedAt:i.manifest.fetchedAt,projectVersionId:i.manifest.projectVersionId,workspaceId:i.manifest.workspaceId};return{virtualSource:w===`manifest`?be({projectManifestPath:t.projectManifestPath,experienceFlowPaths:i.experienceFlowPaths,experienceContentPaths:i.experienceContentPaths,manifestMetadata:s}):ye({projectConfigPath:t.projectConfigPath,experienceContentPaths:i.experienceContentPaths,manifestMetadata:s}),features:N(o.features)}})(),n.catch(()=>Q.delete(t)),Q.set(t,n));let r=await n;_=r.virtualSource,l=r.features}else if(f.mode===`production`)O.debug(`skipping the dev project-config fetch for a production serve resolution`);else{O.info(`fetching project config for "${x}" (dev)`);let e=performance.now(),t=await We(S,x,D,C),n=(performance.now()-e).toFixed(0);v=t,t?(l=N(t.features),$(t,n)):O.warn(`failed to fetch project config for "${x}" (${n}ms)`)}},configResolved(e){f=e.base},async buildStart(){o===`snapshot`&&m&&d===`build`&&(s=await(0,i.requireSnapshot)(m))},closeBundle(){g!==void 0&&Q.delete(g),b?.flush({"picked.vite.command":d,"picked.data.mode":o,"picked.source":m?.source??`unknown`})},transformIndexHtml:{order:`post`,handler(e,t){if(o===`api`||t.bundle===void 0)return;let n=Fe(t.bundle);if(n===void 0)return;let r=Ie(f,n);if(!e.includes(`"${r}"`))return[{tag:`link`,attrs:{rel:`modulepreload`,crossorigin:!0,href:r},injectTo:`head`}]}},resolveId(e){if(e===K||e.startsWith(`virtual:picked/data/experience/`)||e.startsWith(`virtual:picked/data/flow/`))return`\0${e}`},load(e){if(e.startsWith(Y))return y(this,e.slice(Y.length));if(e.startsWith(J)&&s&&m)return this.addWatchFile((0,i.resolveSnapshotPath)(m.projectRoot)),we(s,e.slice(J.length));if(e!==q)return;if(o===`api`)return ve(m?.configLoading??`full`);if(o===`snapshot`){if(!s||!m)throw Error(`picked plugin config hook must run before virtual module load`);return this.addWatchFile((0,i.resolveSnapshotPath)(m.projectRoot)),m.configLoading===`manifest`?Te(s):Ce(s)}if(d===`build`)return _;if(!m)throw Error(`picked plugin config hook must run before virtual module load`);let t={apiUrl:m.apiUrl,projectId:m.projectId,projectConfig:v,previewToken:m.previewToken??void 0};return m.configLoading===`manifest`?Se(t):xe(t)},configureServer(e){if(o===`snapshot`&&m){let t=(0,i.resolveSnapshotPath)(m.projectRoot),n=n=>{n===t&&(O.info(`${i.SNAPSHOT_FILENAME} changed; restarting the dev server`),e.restart())};e.watcher.add(t),e.watcher.on(`add`,n),e.watcher.on(`change`,n),e.watcher.on(`unlink`,n)}if(r.disableLauncher)return;e.middlewares.use(te(()=>p(l)));let t=e.printUrls.bind(e);e.printUrls=()=>{let n=e.resolvedUrls?.local[0];if(n){let e=n.replace(/:(?<port>\d+)\//,(e,t)=>`:\x1b[1m${t}\x1b[22m/`);console.log(` \x1b[32m➜\x1b[0m \x1b[1mPicked\x1b[22m: \x1b[36m${e}\x1b[0m`)}t()}},generateBundle:{order:`post`,handler(e,t){r.disableLauncher||(`index.html`in t?O.debug(`index.html came from the build; skipping the launcher page`):this.emitFile({type:`asset`,fileName:`index.html`,source:p(l)}))}}})}function $(e,t){let n=N(e.features),r=N(e.experiences),i=N(e.steps),a=N(e.fields),o=N(e.conditions),s=N(e.actions),c=JSON.stringify(e).length,l=[`${n.length.toString()} features`,`${r.length.toString()} experiences`,`${i.length.toString()} steps`,`${a.length.toString()} fields`,`${o.length.toString()} conditions`,`${s.length.toString()} actions`].join(`, `);O.info(`fetched config in ${t}ms (${l})`),G(`Features`,n,Oe),G(`Experiences`,r,ke),G(`Steps`,i,Ae),G(`Fields`,a,je),G(`Conditions`,o,Me),De(`Actions`,s),O.debug(`config size: ${c.toString()} bytes`)}exports.picked=Ke;
|
package/dist/cjs/prefetch.d.ts
CHANGED
|
@@ -18,6 +18,10 @@ interface PrefetchPaths {
|
|
|
18
18
|
manifestPath: string;
|
|
19
19
|
/** Absolute path to `<root>/.picked/project-config.json`. */
|
|
20
20
|
projectConfigPath: string;
|
|
21
|
+
/** Absolute path to `<root>/.picked/project-manifest.json`. */
|
|
22
|
+
projectManifestPath: string;
|
|
23
|
+
/** Absolute path to `<root>/.picked/flows/`. */
|
|
24
|
+
flowsDir: string;
|
|
21
25
|
/** Absolute path to `<root>/.picked/experiences/`. */
|
|
22
26
|
experiencesDir: string;
|
|
23
27
|
}
|
|
@@ -26,6 +30,11 @@ interface PrefetchResult {
|
|
|
26
30
|
manifest: PickedManifest;
|
|
27
31
|
/** Map of experience id → absolute path to its `<id>.json`. */
|
|
28
32
|
experienceContentPaths: Record<string, string>;
|
|
33
|
+
/**
|
|
34
|
+
* Map of experience id → absolute path to its flow's `flows/<id>.json`, which only a
|
|
35
|
+
* `configLoading: 'manifest'` run writes. Empty otherwise.
|
|
36
|
+
*/
|
|
37
|
+
experienceFlowPaths: Record<string, string>;
|
|
29
38
|
}
|
|
30
39
|
/**
|
|
31
40
|
* Resolves the artefact paths under `<root>/.picked/`.
|
|
@@ -48,6 +57,8 @@ interface RunPrefetchOptions {
|
|
|
48
57
|
previewToken?: string;
|
|
49
58
|
/** When the existing manifest matches the API's versionId+workspaceId, skip per-experience fetches. */
|
|
50
59
|
reuseWhenUnchanged?: boolean;
|
|
60
|
+
/** Whether the run also writes the config's manifest and one file per flow. Defaults to `'full'`. */
|
|
61
|
+
configLoading?: 'full' | 'manifest';
|
|
51
62
|
}
|
|
52
63
|
/**
|
|
53
64
|
* Runs the full build-mode prefetch: fetches project config, walks CMS-using experiences,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prefetch.d.ts","sourceRoot":"","sources":["../../src/prefetch.ts"],"names":[],"mappings":"AAQA,OAAO,
|
|
1
|
+
{"version":3,"file":"prefetch.d.ts","sourceRoot":"","sources":["../../src/prefetch.ts"],"names":[],"mappings":"AAQA,OAAO,EAKL,KAAK,aAAa,EACnB,MAAM,6BAA6B,CAAA;AAepC,UAAU,uBAAuB;IAC/B,EAAE,EAAE,MAAM,CAAA;IACV,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,UAAU,cAAc;IACtB,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,gBAAgB,EAAE,MAAM,CAAA;IACxB,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,uBAAuB,EAAE,CAAA;CACvC;AAED,UAAU,aAAa;IACrB,0CAA0C;IAC1C,SAAS,EAAE,MAAM,CAAA;IACjB,uDAAuD;IACvD,YAAY,EAAE,MAAM,CAAA;IACpB,6DAA6D;IAC7D,iBAAiB,EAAE,MAAM,CAAA;IACzB,+DAA+D;IAC/D,mBAAmB,EAAE,MAAM,CAAA;IAC3B,gDAAgD;IAChD,QAAQ,EAAE,MAAM,CAAA;IAChB,sDAAsD;IACtD,cAAc,EAAE,MAAM,CAAA;CACvB;AAED,UAAU,cAAc;IACtB,MAAM,EAAE,aAAa,CAAA;IACrB,QAAQ,EAAE,cAAc,CAAA;IACxB,+DAA+D;IAC/D,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC9C;;;OAGG;IACH,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC5C;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,MAAM,GAAG,aAAa,CAUvE;AAsFD,UAAU,kBAAkB;IAC1B,MAAM,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,MAAM,CAAA;IACnB,yFAAyF;IACzF,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC/B,8FAA8F;IAC9F,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,uGAAuG;IACvG,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B,qGAAqG;IACrG,aAAa,CAAC,EAAE,MAAM,GAAG,UAAU,CAAA;CACpC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,cAAc,CAAC,CAiFtF"}
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file Synthesis for `virtual:picked/data` when the plugin runs with `mode: 'api'`.
|
|
3
3
|
*
|
|
4
|
-
* The module resolves, so an import a consumer wrote by hand still builds. It exports
|
|
5
|
-
* `manifestMetadata
|
|
4
|
+
* The module resolves, so an import a consumer wrote by hand still builds. It exports
|
|
5
|
+
* `manifestMetadata` and the `configLoading` picked.config sets, and no project data, so the SDK's
|
|
6
|
+
* shape guard refuses it and every read stays on the API path.
|
|
6
7
|
*/
|
|
7
8
|
/**
|
|
8
9
|
* Synthesises the source for the `mode: 'api'` `virtual:picked/data` module.
|
|
9
10
|
*
|
|
11
|
+
* @param {'full' | 'manifest'} configLoading - The config loading picked.config sets.
|
|
10
12
|
* @returns {string} JavaScript source as a string for Vite's `load` hook.
|
|
11
13
|
* @example
|
|
12
14
|
* ```typescript
|
|
13
|
-
* const src = apiModeVirtualModuleSource()
|
|
15
|
+
* const src = apiModeVirtualModuleSource('full')
|
|
14
16
|
* ```
|
|
15
17
|
*/
|
|
16
|
-
export declare function apiModeVirtualModuleSource(): string;
|
|
18
|
+
export declare function apiModeVirtualModuleSource(configLoading: 'full' | 'manifest'): string;
|
|
17
19
|
//# sourceMappingURL=api.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/virtual-module/api.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/virtual-module/api.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;;;GASG;AACH,wBAAgB,0BAA0B,CAAC,aAAa,EAAE,MAAM,GAAG,UAAU,GAAG,MAAM,CAUrF"}
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Generates a JavaScript module that statically imports the prefetched project config
|
|
5
5
|
* (so it's bundled into the customer's main chunk) and lazily imports each experience's
|
|
6
|
-
* content JSON on demand.
|
|
6
|
+
* content JSON on demand. Under `configLoading: 'manifest'` it statically imports the project manifest in
|
|
7
|
+
* place of the config, and lazily imports each experience's flow JSON too.
|
|
7
8
|
*/
|
|
8
9
|
interface BuildVirtualModuleOptions {
|
|
9
10
|
/** Absolute path to `<root>/.picked/project-config.json`. */
|
|
@@ -29,5 +30,32 @@ interface BuildVirtualModuleOptions {
|
|
|
29
30
|
* ```
|
|
30
31
|
*/
|
|
31
32
|
export declare function buildVirtualModuleSource(options: BuildVirtualModuleOptions): string;
|
|
33
|
+
interface BuildLazyVirtualModuleOptions {
|
|
34
|
+
/** Absolute path to `<root>/.picked/project-manifest.json`. */
|
|
35
|
+
projectManifestPath: string;
|
|
36
|
+
/** Map of experience id → absolute path to its flow JSON file. */
|
|
37
|
+
experienceFlowPaths: Record<string, string>;
|
|
38
|
+
/** Map of experience id → absolute path to its content JSON file. */
|
|
39
|
+
experienceContentPaths: Record<string, string>;
|
|
40
|
+
/** Manifest metadata that the synthesised module re-exports as `manifestMetadata`. */
|
|
41
|
+
manifestMetadata: {
|
|
42
|
+
mode: 'build';
|
|
43
|
+
fetchedAt: string | null;
|
|
44
|
+
projectVersionId: string | null;
|
|
45
|
+
workspaceId: string | null;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Synthesises the source code for the build-mode `virtual:picked/data` module under
|
|
50
|
+
* `configLoading: 'manifest'`: the manifest bundled, each flow and each content file in a chunk of its own.
|
|
51
|
+
*
|
|
52
|
+
* @param {BuildLazyVirtualModuleOptions} options - Build-mode synthesis inputs.
|
|
53
|
+
* @returns {string} JavaScript source as a string for Vite's `load` hook.
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* const src = buildLazyVirtualModuleSource({ projectManifestPath, experienceFlowPaths, experienceContentPaths, manifestMetadata })
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare function buildLazyVirtualModuleSource(options: BuildLazyVirtualModuleOptions): string;
|
|
32
60
|
export {};
|
|
33
61
|
//# sourceMappingURL=build.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/virtual-module/build.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/virtual-module/build.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,UAAU,yBAAyB;IACjC,6DAA6D;IAC7D,iBAAiB,EAAE,MAAM,CAAA;IACzB,qEAAqE;IACrE,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC9C,sFAAsF;IACtF,gBAAgB,EAAE;QAChB,IAAI,EAAE,OAAO,CAAA;QACb,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;QACxB,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAA;QAC/B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAA;KAC3B,CAAA;CACF;AAED;;;;;;;;;GASG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,MAAM,CAoCnF;AAED,UAAU,6BAA6B;IACrC,+DAA+D;IAC/D,mBAAmB,EAAE,MAAM,CAAA;IAC3B,kEAAkE;IAClE,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC3C,qEAAqE;IACrE,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC9C,sFAAsF;IACtF,gBAAgB,EAAE;QAChB,IAAI,EAAE,OAAO,CAAA;QACb,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;QACxB,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAA;QAC/B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAA;KAC3B,CAAA;CACF;AAmBD;;;;;;;;;;GAUG;AACH,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,6BAA6B,GAAG,MAAM,CA0C3F"}
|
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file Dev-mode synthesis for `virtual:picked/data`.
|
|
3
|
-
*
|
|
4
|
-
* Generates a JavaScript module exposing the project config the plugin's `config()` hook
|
|
5
|
-
* already fetched, and resolving per-experience content with per-call API requests. The
|
|
6
|
-
* config travels as a literal so module evaluation does not block on a network round trip:
|
|
7
|
-
* the module is reached by a dynamic `import()` from inside the SDK's `onStart` hook, and a
|
|
8
|
-
* top-level `await` there puts the fetch on the start-chain critical path.
|
|
9
|
-
*
|
|
10
|
-
* No filesystem writes; content behaviour matches the customer's runtime API behaviour.
|
|
11
|
-
*/
|
|
12
1
|
import type { ProjectConfig } from '@picked/client/plugins/dynamic-experiences';
|
|
13
2
|
interface DevVirtualModuleOptions {
|
|
14
3
|
/** Absolute API base URL (e.g. `https://api.picked.app`). */
|
|
@@ -35,5 +24,17 @@ interface DevVirtualModuleOptions {
|
|
|
35
24
|
* ```
|
|
36
25
|
*/
|
|
37
26
|
export declare function devVirtualModuleSource(options: DevVirtualModuleOptions): string;
|
|
27
|
+
/**
|
|
28
|
+
* Synthesises the source code for the dev-mode `virtual:picked/data` module under
|
|
29
|
+
* `configLoading: 'manifest'`.
|
|
30
|
+
*
|
|
31
|
+
* @param {DevVirtualModuleOptions} options - Dev-mode synthesis inputs.
|
|
32
|
+
* @returns {string} JavaScript source as a string for Vite's `load` hook.
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const src = devLazyVirtualModuleSource({ apiUrl: 'https://api.picked.app', projectId: 'p_1', projectConfig })
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function devLazyVirtualModuleSource(options: DevVirtualModuleOptions): string;
|
|
38
39
|
export {};
|
|
39
40
|
//# sourceMappingURL=dev.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../../src/virtual-module/dev.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../../../src/virtual-module/dev.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4CAA4C,CAAA;AAG/E,UAAU,uBAAuB;IAC/B,6DAA6D;IAC7D,MAAM,EAAE,MAAM,CAAA;IACd,kCAAkC;IAClC,SAAS,EAAE,MAAM,CAAA;IACjB;;;;OAIG;IACH,aAAa,EAAE,aAAa,GAAG,IAAI,CAAA;IACnC,8FAA8F;IAC9F,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB;AAED;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,uBAAuB,GAAG,MAAM,CAuC/E;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,uBAAuB,GAAG,MAAM,CA8DnF"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ProjectConfig } from '@picked/delivery-api-client';
|
|
2
|
+
/** Prefix of the per-experience flow modules. */
|
|
3
|
+
export declare const FLOW_MODULE_PREFIX = "virtual:picked/data/flow/";
|
|
4
|
+
/**
|
|
5
|
+
* Renders the object-literal entries of experience id → importer of that experience's flow module.
|
|
6
|
+
*
|
|
7
|
+
* @param {ProjectConfig} config - The config the data module is generated from.
|
|
8
|
+
* @returns {string} The entries, one per line.
|
|
9
|
+
* @example
|
|
10
|
+
* flowImporterEntries(config) // ' "exp_1": () => import("virtual:picked/data/flow/0")…,'
|
|
11
|
+
*/
|
|
12
|
+
export declare function flowImporterEntries(config: ProjectConfig): string;
|
|
13
|
+
/**
|
|
14
|
+
* Synthesises the source of one experience's flow module.
|
|
15
|
+
*
|
|
16
|
+
* @param {ProjectConfig | null} config - The config the data module was generated from.
|
|
17
|
+
* @param {string} position - The experience's position in `config.experiences`.
|
|
18
|
+
* @returns {string} A module whose default export is the flow, or `null` for no experience.
|
|
19
|
+
* @example
|
|
20
|
+
* flowModuleSource(config, '0')
|
|
21
|
+
*/
|
|
22
|
+
export declare function flowModuleSource(config: ProjectConfig | null, position: string): string;
|
|
23
|
+
//# sourceMappingURL=flow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flow.d.ts","sourceRoot":"","sources":["../../../src/virtual-module/flow.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAkB,aAAa,EAAE,MAAM,6BAA6B,CAAA;AAEhF,iDAAiD;AACjD,eAAO,MAAM,kBAAkB,8BAA8B,CAAA;AAE7D;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,CAOjE;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,aAAa,GAAG,IAAI,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAOvF"}
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
4
4
|
* The module inlines the snapshot's project config and reaches each experience's content
|
|
5
5
|
* through its own virtual module, so build output keeps content in lazy chunks and nothing is
|
|
6
|
-
* written to disk.
|
|
6
|
+
* written to disk. Under `configLoading: 'manifest'` it inlines the config's manifest in place of the config
|
|
7
|
+
* and reaches each experience's flow through a virtual module too. The same source serves build
|
|
8
|
+
* and serve.
|
|
7
9
|
*/
|
|
8
10
|
import type { PickedSnapshot } from '@picked/config';
|
|
9
11
|
/** Prefix of the per-experience content modules the snapshot module imports. */
|
|
@@ -28,4 +30,13 @@ export declare function snapshotVirtualModuleSource(snapshot: PickedSnapshot): s
|
|
|
28
30
|
* snapshotExperienceModuleSource(snapshot, '0')
|
|
29
31
|
*/
|
|
30
32
|
export declare function snapshotExperienceModuleSource(snapshot: PickedSnapshot, position: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* Synthesises the snapshot-mode `virtual:picked/data` module under `configLoading: 'manifest'`.
|
|
35
|
+
*
|
|
36
|
+
* @param {PickedSnapshot} snapshot - The snapshot the build serves.
|
|
37
|
+
* @returns {string} JavaScript source for Vite's `load` hook.
|
|
38
|
+
* @example
|
|
39
|
+
* const source = snapshotLazyVirtualModuleSource(snapshot)
|
|
40
|
+
*/
|
|
41
|
+
export declare function snapshotLazyVirtualModuleSource(snapshot: PickedSnapshot): string;
|
|
31
42
|
//# sourceMappingURL=snapshot.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snapshot.d.ts","sourceRoot":"","sources":["../../../src/virtual-module/snapshot.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"snapshot.d.ts","sourceRoot":"","sources":["../../../src/virtual-module/snapshot.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAKpD,gFAAgF;AAChF,eAAO,MAAM,iCAAiC,oCAAoC,CAAA;AAElF;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,cAAc,GAAG,MAAM,CAmC5E;AAED;;;;;;;;;GASG;AACH,wBAAgB,8BAA8B,CAAC,QAAQ,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAQjG;AAED;;;;;;;GAOG;AACH,wBAAgB,+BAA+B,CAAC,QAAQ,EAAE,cAAc,GAAG,MAAM,CAgDhF"}
|