@picked/vite-plugin-picked 0.0.1-dev.1786405786333 → 0.0.1-dev.1786675074931

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/cjs/index.js CHANGED
@@ -1,15 +1,15 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("node:fs"),t=require("node:path"),n=require("@picked/client/plugins/dynamic-experiences"),r=require("node:fs/promises");function i(e,t){return t||=e.slice(0),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(t)}}))}var a;function o(e){let t=JSON.stringify(e),n=e.length>0?e.map(e=>`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("node:fs"),t=require("node:path"),n=require("@picked/delivery-api-client"),r=require("@picked/typegen"),i=require("@picked/config"),a=require("node:fs/promises");function o(e,t){return t||=e.slice(0),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(t)}}))}var s;function c(e){let t=JSON.stringify(e),n=e.length>0?e.map(e=>`
2
2
  <div class="feature-row">
3
3
  <label>
4
- <input type="checkbox" data-feature-id="${c(e.id)}" checked>
5
- <span class="feature-name">${s(e.name)}</span>
6
- <span class="feature-id">${s(e.id)}</span>
4
+ <input type="checkbox" data-feature-id="${u(e.id)}" checked>
5
+ <span class="feature-name">${l(e.name)}</span>
6
+ <span class="feature-id">${l(e.id)}</span>
7
7
  </label>
8
- <select data-value-for="${c(e.id)}">
8
+ <select data-value-for="${u(e.id)}">
9
9
  <option value="true" selected>true</option>
10
10
  <option value="false">false</option>
11
11
  </select>
12
- </div>`).join(``):`<p class="text no-features">No features configured for this project.</p>`;return String.raw(a||=i([`<!DOCTYPE html>
12
+ </div>`).join(``):`<p class="text no-features">No features configured for this project.</p>`;return String.raw(s||=o([`<!DOCTYPE html>
13
13
  <html lang="en">
14
14
  <head>
15
15
  <meta charset="UTF-8">
@@ -855,19 +855,19 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require
855
855
  <\/script>
856
856
  </main>
857
857
  </body>
858
- </html>`]),n,t)}function s(e){return e.replaceAll(`&`,`&amp;`).replaceAll(`<`,`&lt;`).replaceAll(`>`,`&gt;`).replaceAll(`"`,`&quot;`)}function c(e){return e.replaceAll(`&`,`&amp;`).replaceAll(`"`,`&quot;`).replaceAll(`<`,`&lt;`).replaceAll(`>`,`&gt;`)}var l=`picked`,u=`\x1B[0m`;function d(){let e=process.env.NO_COLOR;return e===`1`||e===`true`}function f(e){return t=>d()?t:`${e}${t}${u}`}var p=[`debug`,`info`,`warn`,`error`,`silent`],m={debug:{color:f(`\x1B[2m`),log:console.debug,enabled:!1},info:{color:f(`\x1B[36m`),log:console.log,enabled:!0},warn:{color:f(`\x1B[33m`),log:console.warn,enabled:!0},error:{color:f(`\x1B[31m`),log:console.error,enabled:!0},silent:{log:()=>{},enabled:!1}};function ee(e,t){return`${new Date().toLocaleTimeString()} [${t?`${l}:${t}`:l}] ${e}`}function h(e,t,n,r){if(!e.enabled)return;let i=ee(t,r);e.log(e.color?e.color(i):i),n!==void 0&&e.log(n)}function g(e){let t=m[e],n=new Set;return Object.assign((e,n,r)=>{h(t,e,n,r)},{once(e,r,i){!t.enabled||n.has(e)||(n.add(e),h(t,e,r,i))}})}function te(e){let t=p.indexOf(e);if(t===-1){h(m.error,`invalid log level: ${e}`);return}for(let[e,n]of p.entries())m[n].enabled=e>=t}var _=f(`\x1B[34m`),v=f(`\x1B[36m`);function y(){let e=[` ${_(`_`)} ${v(`_`)} _ _ _`,`${_(`(_)`)} ${v(`(_)`)} _ __(_)__| |_____ __| |`,` ${_(`_`)} ${_(`_`)} | '_ \\ / _| / / -_) _\` |`,`${_(`(_)`)} ${_(`(_)`)} | .__/_\\__|_\\_\\___\\__,_|`,` |_|
858
+ </html>`]),n,t)}function l(e){return e.replaceAll(`&`,`&amp;`).replaceAll(`<`,`&lt;`).replaceAll(`>`,`&gt;`).replaceAll(`"`,`&quot;`)}function u(e){return e.replaceAll(`&`,`&amp;`).replaceAll(`"`,`&quot;`).replaceAll(`<`,`&lt;`).replaceAll(`>`,`&gt;`)}var d=`picked`,f=`\x1B[0m`;function p(){let e=process.env.NO_COLOR;return e===`1`||e===`true`}function m(e){return t=>p()?t:`${e}${t}${f}`}var h=[`debug`,`info`,`warn`,`error`,`silent`],g={debug:{color:m(`\x1B[2m`),log:console.debug,enabled:!1},info:{color:m(`\x1B[36m`),log:console.log,enabled:!0},warn:{color:m(`\x1B[33m`),log:console.warn,enabled:!0},error:{color:m(`\x1B[31m`),log:console.error,enabled:!0},silent:{log:()=>{},enabled:!1}};function _(e,t){return`${new Date().toLocaleTimeString()} [${t?`${d}:${t}`:d}] ${e}`}function v(e,t,n,r){if(!e.enabled)return;let i=_(t,r);e.log(e.color?e.color(i):i),n!==void 0&&e.log(n)}function y(e){let t=g[e],n=new Set;return Object.assign((e,n,r)=>{v(t,e,n,r)},{once(e,r,i){!t.enabled||n.has(e)||(n.add(e),v(t,e,r,i))}})}function ee(e){let t=h.indexOf(e);if(t===-1){v(g.error,`invalid log level: ${e}`);return}for(let[e,n]of h.entries())g[n].enabled=e>=t}var b=m(`\x1B[34m`),x=m(`\x1B[36m`);function te(){let e=[` ${b(`_`)} ${x(`_`)} _ _ _`,`${b(`(_)`)} ${x(`(_)`)} _ __(_)__| |_____ __| |`,` ${b(`_`)} ${b(`_`)} | '_ \\ / _| / / -_) _\` |`,`${b(`(_)`)} ${b(`(_)`)} | .__/_\\__|_\\_\\___\\__,_|`,` |_|
859
859
  `];console.log(e.join(`
860
- `))}var b={banner:y,debug:g(`debug`),info:g(`info`),warn:g(`warn`),error:g(`error`),setLevel:te};function ne(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 x=`.picked/`;async function S(n,i){if(i)return;let a=(0,t.join)(n,`.gitignore`);if(!(0,e.existsSync)(a)){await(0,r.writeFile)(a,`${x}
861
- `);return}let o=await(0,r.readFile)(a,`utf8`);if(C(o))return;let s=`${o.length>0&&!o.endsWith(`
860
+ `))}var S={banner:te,debug:y(`debug`),info:y(`info`),warn:y(`warn`),error:y(`error`),setLevel:ee};function C(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 w=`.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,`${w}
861
+ `);return}let o=await(0,a.readFile)(i,`utf8`);if(re(o))return;let s=`${o.length>0&&!o.endsWith(`
862
862
  `)?`
863
- `:``}${x}
864
- `;await(0,r.appendFile)(a,s)}function C(e){return e.split(/\r?\n/).map(e=>e.trim()).some(e=>e===x||e===`.picked`)}var w=6,T=5e3;function E(e){let t;try{t=new URL(e).hostname}catch{return!1}return t===`localhost`||t===`127.0.0.1`||t===`::1`||t===`[::1]`||t!==`api.picked.app`&&t.endsWith(`.picked.app`)}function D(e){return new Promise(t=>{setTimeout(t,e)})}async function O(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<=w;i++){let a=T*2**(i-1);t(i,w,a),await D(a),r=null;try{n=await e()}catch(e){r=e}if(n!==null)return n}if(r!==null)throw r;return null}function k(e){return Array.isArray(e)?e:[]}var A=2;function j(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`),experiencesDir:(0,t.join)(n,`experiences`)}}async function re(t){if(!(0,e.existsSync)(t))return null;try{let e=await(0,r.readFile)(t,`utf8`),n=JSON.parse(e);return ie(n)?n:null}catch{return null}}function ie(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 M(e){let t=new Set;for(let n of k(e.steps))n.layoutContentId&&t.add(n.id);if(t.size===0)return[];let n=[];for(let r of k(e.experiences))k(r.nodes).some(e=>e.type===`step`&&t.has(e.stepId))&&n.push(r.id);return n}async function N(n){let{apiUrl:i,projectId:a,projectRoot:o,headers:s,reuseWhenUnchanged:c=!0}=n,l=j(o),u=await F(i,a,s),d=M(u);if(await(0,r.mkdir)(l.experiencesDir,{recursive:!0}),await(0,r.writeFile)(l.projectConfigPath,JSON.stringify(u,null,2)),c){let t=await re(l.manifestPath);if(t?.version===A&&t.projectVersionId===u.versionId&&t.workspaceId===u.workspaceId){let n=P(l,d);if(Object.values(n).every(t=>(0,e.existsSync)(t)))return{config:u,manifest:t,experienceContentPaths:n};b.info(`a manifest-referenced content file is missing; refetching every experience`)}}let f=new Date().toISOString(),p=[];for(let e of d){let n=await I(i,a,e,s),o=(0,t.join)(l.experiencesDir,`${e}.json`);await(0,r.writeFile)(o,JSON.stringify(n,null,2)),p.push({id:e,fetchedAt:f})}let m={version:A,fetchedAt:f,projectVersionId:u.versionId,workspaceId:u.workspaceId,projectId:u.id,experiences:p};return await(0,r.writeFile)(l.manifestPath,JSON.stringify(m,null,2)),{config:u,manifest:m,experienceContentPaths:P(l,d)}}function P(e,n){let r={};for(let i of n)r[i]=(0,t.join)(e.experiencesDir,`${i}.json`);return r}async function F(e,t,r){let i=()=>(0,n.fetchProject)(e,t,{headers:r}),a;try{a=E(e)?await O(i,(e,t,n)=>{b.info(`project config not ready, retrying in ${(n/1e3).toString()}s (${e.toString()}/${t.toString()})`)}):await i()}catch(n){throw Error(`[picked] Build-time fetch of project config failed for "${t}" at ${e}: ${L(n)}`)}if(!a)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 a}async function I(e,t,r,i){let a;try{a=await(0,n.fetchExperienceContent)(e,t,r,{headers:i})}catch(t){throw Error(`[picked] Build-time fetch of content for experience "${r}" failed at ${e}: ${L(t)}`)}if(!a)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 a}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`}}function R(){return`export const manifestMetadata = {
863
+ `:``}${w}
864
+ `;await(0,a.appendFile)(i,s)}function re(e){return e.split(/\r?\n/).map(e=>e.trim()).some(e=>e===w||e===`.picked`)}var T=6,E=5e3;function D(e){let t;try{t=new URL(e).hostname}catch{return!1}return t===`localhost`||t===`127.0.0.1`||t===`::1`||t===`[::1]`||t!==`api.picked.app`&&t.endsWith(`.picked.app`)}function O(e){return new Promise(t=>{setTimeout(t,e)})}async function k(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<=T;i++){let a=E*2**(i-1);t(i,T,a),await O(a),r=null;try{n=await e()}catch(e){r=e}if(n!==null)return n}if(r!==null)throw r;return null}function A(e){return Array.isArray(e)?e:[]}var j=2;function M(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`),experiencesDir:(0,t.join)(n,`experiences`)}}async function ie(t){if(!(0,e.existsSync)(t))return null;try{let e=await(0,a.readFile)(t,`utf8`),n=JSON.parse(e);return N(n)?n:null}catch{return null}}function N(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 P(e){let t=new Set;for(let n of A(e.steps))n.layoutContentId&&t.add(n.id);if(t.size===0)return[];let n=[];for(let r of A(e.experiences))A(r.nodes).some(e=>e.type===`step`&&t.has(e.stepId))&&n.push(r.id);return n}async function F(n){let{apiUrl:r,projectId:i,projectRoot:o,headers:s,previewToken:c,reuseWhenUnchanged:l=!0}=n,u=M(o),d=await L(r,i,s,c),f=P(d);if(await(0,a.mkdir)(u.experiencesDir,{recursive:!0}),await(0,a.writeFile)(u.projectConfigPath,JSON.stringify(d,null,2)),l){let t=await ie(u.manifestPath);if(t?.version===j&&t.projectVersionId===d.versionId&&t.workspaceId===d.workspaceId){let n=I(u,f);if(Object.values(n).every(t=>(0,e.existsSync)(t)))return{config:d,manifest:t,experienceContentPaths:n};S.info(`a manifest-referenced content file is missing; refetching every experience`)}}let p=new Date().toISOString(),m=[];for(let e of f){let n=await R(r,i,e,s,c),o=(0,t.join)(u.experiencesDir,`${e}.json`);await(0,a.writeFile)(o,JSON.stringify(n,null,2)),m.push({id:e,fetchedAt:p})}let h={version:j,fetchedAt:p,projectVersionId:d.versionId,workspaceId:d.workspaceId,projectId:d.id,experiences:m};return await(0,a.writeFile)(u.manifestPath,JSON.stringify(h,null,2)),{config:d,manifest:h,experienceContentPaths:I(u,f)}}function I(e,n){let r={};for(let i of n)r[i]=(0,t.join)(e.experiencesDir,`${i}.json`);return r}async function L(e,t,r,i){let a=()=>(0,n.fetchProject)(e,t,{headers:r,previewToken:i}),o;try{o=D(e)?await k(a,(e,t,n)=>{S.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}: ${z(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 R(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}: ${z(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 z(e){if(e instanceof Error)return e.message;if(typeof e==`string`)return e;try{return JSON.stringify(e)}catch{return`unknown error`}}function B(){return`export const manifestMetadata = {
865
865
  mode: 'api',
866
866
  fetchedAt: null,
867
867
  projectVersionId: null,
868
868
  workspaceId: null,
869
869
  }
870
- `}function z(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
+ `}function V(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(`
871
871
  `);return`import { registerPickedBundle } from '@picked/client/plugins/dynamic-experiences'
872
872
  import projectConfigJson from ${i(t)}
873
873
 
@@ -892,19 +892,20 @@ export async function experienceContent(experience, _options) {
892
892
  export const manifestMetadata = ${JSON.stringify(r)}
893
893
 
894
894
  registerPickedBundle({ projectConfig, experienceContent, manifestMetadata })
895
- `}function B(e){let{apiUrl:t,projectId:n,projectConfig:r}=e,i=r?`import { fetchExperienceContent, registerPickedBundle } from '@picked/client/plugins/dynamic-experiences'`:`import { fetchProject, fetchExperienceContent } from '@picked/client/plugins/dynamic-experiences'`,a=r?`export const projectConfig = ${JSON.stringify(r)}`:`export const projectConfig = await fetchProject(apiUrl, projectId)`,o=r?`
895
+ `}function H(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?`
896
896
  registerPickedBundle({ projectConfig, experienceContent, manifestMetadata })
897
- `:``;return`${i}
897
+ `:``;return`${a}
898
898
 
899
899
  const apiUrl = ${JSON.stringify(t)}
900
900
  const projectId = ${JSON.stringify(n)}
901
+ const previewToken = ${JSON.stringify(i??null)}
901
902
 
902
- ${a}
903
+ ${o}
903
904
 
904
905
  export async function experienceContent(experience, options) {
905
906
  const id = typeof experience === 'string' ? experience : experience?.id
906
907
  if (!id) return null
907
- return await fetchExperienceContent(apiUrl, projectId, id, options)
908
+ return await fetchExperienceContent(apiUrl, projectId, id, { previewToken: previewToken ?? undefined, ...options })
908
909
  }
909
910
 
910
911
  export const manifestMetadata = {
@@ -913,5 +914,5 @@ export const manifestMetadata = {
913
914
  projectVersionId: projectConfig?.versionId ?? null,
914
915
  workspaceId: projectConfig?.workspaceId ?? null,
915
916
  }
916
- ${o}`}var V=5;function H(e,t,n){if(t.length===0)return;if(t.length>V){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(`
917
- `))}function U(e,t){t.length!==0&&console.log(`\n ${e}: ${t.length.toString()} loaded\n`)}var W=[{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:`Weight`,value:e=>`${e.weight.toString()}%`.padStart(6)},{header:`Ver`,value:e=>`v${e.version.toString()}`}],G=[{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()}],K=[{header:`Name`,value:e=>e.name},{header:`Key`,value:e=>e.key},{header:`Fields`,value:e=>(e.fieldIds?.length??0).toString()}],q=[{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`}],J=[{header:`Name`,value:e=>e.name},{header:`Key`,value:e=>e.key}];function ae(){return`0.0.1-dev.1786405786333`}var Y=`https://api.picked.app`,X=`virtual:picked/data`,Z=`\0${X}`;function oe(e){for(let t of Object.values(e))if(t.type===`chunk`&&t.moduleIds.includes(Z))return t.fileName}function se(e,t){return e===``||e.endsWith(`/`)?`${e}${t}`:`${e}/${t}`}var Q=new Map;function ce(e,t,n){return JSON.stringify([e,t,n])}function le(r){let i=r.apiUrl??Y,a=r.mode??`bundle`,s=[],c=process.cwd(),l=`serve`,u=`/`,d,f,p=null;return{name:`picked`,config:async(o,u)=>{l=u.command,c=o.root===void 0?process.cwd():(0,t.resolve)(process.cwd(),o.root),b.banner(),i!==Y&&b.warn(`using custom API URL: ${i}`);let m=(0,n.createClientHeaders)(`vite-plugin`,ae());if(a===`api`)b.debug(`mode is 'api': skipping the project-config prefetch`);else if(u.command===`build`){let t=ce(i,r.projectId,c);d=t;let n=Q.get(t);n===void 0&&(n=(async()=>{b.info(`prefetching project config + content for "${r.projectId}"`);let t=j(c),n=(0,e.existsSync)(t.pickedDir),a=performance.now(),o=await N({apiUrl:i,projectId:r.projectId,projectRoot:c,headers:m}),s=(performance.now()-a).toFixed(0);await S(c,n);let l=o.config;return $(l,s),{virtualSource:z({projectConfigPath:t.projectConfigPath,experienceContentPaths:o.experienceContentPaths,manifestMetadata:{mode:`build`,fetchedAt:o.manifest.fetchedAt,projectVersionId:o.manifest.projectVersionId,workspaceId:o.manifest.workspaceId}}),features:k(l.features)}})(),n.catch(()=>Q.delete(t)),Q.set(t,n));let a=await n;f=a.virtualSource,s=a.features}else if(u.mode===`production`)b.debug(`skipping the dev project-config fetch for a production serve resolution`);else{b.info(`fetching project config for "${r.projectId}" (dev)`);let e=performance.now(),t=()=>(0,n.fetchProject)(i,r.projectId,{headers:m}),a=E(i)?await O(t,(e,t,n)=>{b.info(`local API not ready, retrying in ${(n/1e3).toString()}s (${e.toString()}/${t.toString()})`)}):await t(),o=(performance.now()-e).toFixed(0);p=a,a?(s=k(a.features),$(a,o)):b.warn(`failed to fetch project config for "${r.projectId}" (${o}ms)`)}},configResolved(e){u=e.base},closeBundle(){d!==void 0&&Q.delete(d)},transformIndexHtml:{order:`post`,handler(e,t){if(a===`api`||t.bundle===void 0)return;let n=oe(t.bundle);if(n===void 0)return;let r=se(u,n);if(!e.includes(`"${r}"`))return[{tag:`link`,attrs:{rel:`modulepreload`,crossorigin:!0,href:r},injectTo:`head`}]}},resolveId(e){if(e===X)return Z},load(e){if(e===Z)return a===`api`?R():l===`build`?f:B({apiUrl:i,projectId:r.projectId,projectConfig:p})},configureServer(e){if(r.disableLauncher)return;e.middlewares.use(ne(()=>o(s)));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){if(!r.disableLauncher){if(`index.html`in t){b.debug(`index.html came from the build; skipping the launcher page`);return}this.emitFile({type:`asset`,fileName:`index.html`,source:o(s)})}}}}}function $(e,t){let n=k(e.features),r=k(e.experiences),i=k(e.steps),a=k(e.fields),o=k(e.conditions),s=k(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(`, `);b.info(`fetched config in ${t}ms (${l})`),H(`Features`,n,W),H(`Experiences`,r,G),H(`Steps`,i,K),H(`Fields`,a,q),H(`Conditions`,o,J),U(`Actions`,s),b.debug(`config size: ${c.toString()} bytes`)}exports.picked=le;
917
+ ${s}`}var U=5;function W(e,t,n){if(t.length===0)return;if(t.length>U){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(`
918
+ `))}function G(e,t){t.length!==0&&console.log(`\n ${e}: ${t.length.toString()} loaded\n`)}var K=[{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:`Weight`,value:e=>`${e.weight.toString()}%`.padStart(6)},{header:`Ver`,value:e=>`v${e.version.toString()}`}],q=[{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()}],J=[{header:`Name`,value:e=>e.name},{header:`Key`,value:e=>e.key},{header:`Fields`,value:e=>(e.fieldIds?.length??0).toString()}],ae=[{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`}],oe=[{header:`Name`,value:e=>e.name},{header:`Key`,value:e=>e.key}];function se(){return`0.0.1-dev.1786675074931`}var ce=`https://api.picked.app`,Y=`virtual:picked/data`,X=`\0${Y}`;function Z(e){for(let t of Object.values(e))if(t.type===`chunk`&&t.moduleIds.includes(X))return t.fileName}function le(e,t){return e===``||e.endsWith(`/`)?`${e}${t}`:`${e}/${t}`}async function ue(e){try{let t=await(0,r.generate)({config:e});S.info(`generated types at ${t.typesOutput}`)}catch(e){let t=e instanceof Error?e.message:String(e);S.warn(`type generation failed: ${t}`)}}async function de(e){let t=await(0,i.loadResolvedPickedConfig)(e);if(!t)throw Error(`picked.config.{ts,js,json} is required. Add a picked.config.ts with projectId and apiUrl.`);return t}async function fe(e,t){let n=await(0,i.loadPickedConfig)(e);n&&n.projectId!==t&&S.warn(`using project "${t}" (picked.config default: "${n.projectId}") — run 'picked status' to inspect`)}var Q=new Map;function pe(e,t,n){return JSON.stringify([e,t,n])}function me(r={}){let i=r.mode??`bundle`,a=r.generateTypes??!0,o=[],s=process.cwd(),l=`serve`,u=`/`,d=null,f=!1,p,m,h=null;return{name:`picked`,config:async(r,c)=>{l=c.command,s=r.root===void 0?process.cwd():(0,t.resolve)(process.cwd(),r.root),d=await de(s);let{projectId:u,apiUrl:g,previewToken:_}=d;S.banner(),a&&!f&&(f=!0,await ue(d)),g!==ce&&S.warn(`using custom API URL: ${g}`),await fe(s,u);let v=(0,n.createClientHeaders)(`vite-plugin`,se());if(i===`api`)S.debug(`mode is 'api': skipping the project-config prefetch`);else if(c.command===`build`){let t=pe(g,u,s);p=t;let n=Q.get(t);n===void 0&&(n=(async()=>{S.info(`prefetching project config + content for "${u}"`);let t=M(s),n=(0,e.existsSync)(t.pickedDir),r=performance.now(),i=await F({apiUrl:g,projectId:u,projectRoot:s,headers:v,previewToken:_??void 0}),a=(performance.now()-r).toFixed(0);await ne(s,n);let o=i.config;return $(o,a),{virtualSource:V({projectConfigPath:t.projectConfigPath,experienceContentPaths:i.experienceContentPaths,manifestMetadata:{mode:`build`,fetchedAt:i.manifest.fetchedAt,projectVersionId:i.manifest.projectVersionId,workspaceId:i.manifest.workspaceId}}),features:A(o.features)}})(),n.catch(()=>Q.delete(t)),Q.set(t,n));let r=await n;m=r.virtualSource,o=r.features}else if(c.mode===`production`)S.debug(`skipping the dev project-config fetch for a production serve resolution`);else{S.info(`fetching project config for "${u}" (dev)`);let e=performance.now(),t=()=>(0,n.fetchProject)(g,u,{headers:v,previewToken:_??void 0}),r=D(g)?await k(t,(e,t,n)=>{S.info(`local API not ready, retrying in ${(n/1e3).toString()}s (${e.toString()}/${t.toString()})`)}):await t(),i=(performance.now()-e).toFixed(0);h=r,r?(o=A(r.features),$(r,i)):S.warn(`failed to fetch project config for "${u}" (${i}ms)`)}},configResolved(e){u=e.base},closeBundle(){p!==void 0&&Q.delete(p)},transformIndexHtml:{order:`post`,handler(e,t){if(i===`api`||t.bundle===void 0)return;let n=Z(t.bundle);if(n===void 0)return;let r=le(u,n);if(!e.includes(`"${r}"`))return[{tag:`link`,attrs:{rel:`modulepreload`,crossorigin:!0,href:r},injectTo:`head`}]}},resolveId(e){if(e===Y)return X},load(e){if(e===X){if(i===`api`)return B();if(l===`build`)return m;if(!d)throw Error(`picked plugin config hook must run before virtual module load`);return H({apiUrl:d.apiUrl,projectId:d.projectId,projectConfig:h,previewToken:d.previewToken??void 0})}},configureServer(e){if(r.disableLauncher)return;e.middlewares.use(C(()=>c(o)));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){if(!r.disableLauncher){if(`index.html`in t){S.debug(`index.html came from the build; skipping the launcher page`);return}this.emitFile({type:`asset`,fileName:`index.html`,source:c(o)})}}}}}function $(e,t){let n=A(e.features),r=A(e.experiences),i=A(e.steps),a=A(e.fields),o=A(e.conditions),s=A(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(`, `);S.info(`fetched config in ${t}ms (${l})`),W(`Features`,n,K),W(`Experiences`,r,q),W(`Steps`,i,J),W(`Fields`,a,ae),W(`Conditions`,o,oe),G(`Actions`,s),S.debug(`config size: ${c.toString()} bytes`)}exports.picked=me;