@picked/vite-plugin-picked 0.0.73 → 0.0.74-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/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 b(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 x=m(`\x1B[34m`),S=m(`\x1B[36m`);function C(){let e=[` ${x(`_`)} ${S(`_`)} _ _ _`,`${x(`(_)`)} ${S(`(_)`)} _ __(_)__| |_____ __| |`,` ${x(`_`)} ${x(`_`)} | '_ \\ / _| / / -_) _\` |`,`${x(`(_)`)} ${x(`(_)`)} | .__/_\\__|_\\_\\___\\__,_|`,` |_|
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 w={banner:C,debug:y(`debug`),info:y(`info`),warn:y(`warn`),error:y(`error`),setLevel:b};function T(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 E=`.picked/`;async function ee(n,r){if(r)return;let i=(0,t.join)(n,`.gitignore`);if(!(0,e.existsSync)(i)){await(0,a.writeFile)(i,`${E}
861
+ `);return}let o=await(0,a.readFile)(i,`utf8`);if(D(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
+ `:``}${E}
864
+ `;await(0,a.appendFile)(i,s)}function D(e){return e.split(/\r?\n/).map(e=>e.trim()).some(e=>e===E||e===`.picked`)}var O=6,te=5e3;function k(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 A(e){return new Promise(t=>{setTimeout(t,e)})}async function j(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<=O;i++){let a=te*2**(i-1);t(i,O,a),await A(a),r=null;try{n=await e()}catch(e){r=e}if(n!==null)return n}if(r!==null)throw r;return null}function M(e){return Array.isArray(e)?e:[]}var N=2;function P(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 ne(t){if(!(0,e.existsSync)(t))return null;try{let e=await(0,a.readFile)(t,`utf8`),n=JSON.parse(e);return re(n)?n:null}catch{return null}}function re(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 ie(e){let t=new Set;for(let n of M(e.steps))n.layoutContentId&&t.add(n.id);if(t.size===0)return[];let n=[];for(let r of M(e.experiences))M(r.nodes).some(e=>e.type===`step`&&t.has(e.stepId))&&n.push(r.id);return n}async function ae(n){let{apiUrl:r,projectId:i,projectRoot:o,headers:s,previewToken:c,reuseWhenUnchanged:l=!0}=n,u=P(o),d=await I(r,i,s,c),f=ie(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 ne(u.manifestPath);if(t?.version===N&&t.projectVersionId===d.versionId&&t.workspaceId===d.workspaceId){let n=F(u,f);if(Object.values(n).every(t=>(0,e.existsSync)(t)))return{config:d,manifest:t,experienceContentPaths:n};w.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 L(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:N,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:F(u,f)}}function F(e,n){let r={};for(let i of n)r[i]=(0,t.join)(e.experiencesDir,`${i}.json`);return r}async function I(e,t,r,i){let a=()=>(0,n.fetchProject)(e,t,{headers:r,previewToken:i}),o;try{o=k(e)?await j(a,(e,t,n)=>{w.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}: ${R(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 L(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}: ${R(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 R(e){if(e instanceof Error)return e.message;if(typeof e==`string`)return e;try{return JSON.stringify(e)}catch{return`unknown error`}}function z(){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 B(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 V(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.73`}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 H=5;function U(e,t,n){if(t.length===0)return;if(t.length>H){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 W(e,t){t.length!==0&&console.log(`\n ${e}: ${t.length.toString()} loaded\n`)}var G=[{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()}`}],K=[{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()}],q=[{header:`Name`,value:e=>e.name},{header:`Key`,value:e=>e.key},{header:`Fields`,value:e=>(e.fieldIds?.length??0).toString()}],oe=[{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`}],se=[{header:`Name`,value:e=>e.name},{header:`Key`,value:e=>e.key}];function ce(){return`0.0.74-next.1`}var le=`https://api.picked.app`,J=`virtual:picked/data`,Y=`\0${J}`;function X(e){for(let t of Object.values(e))if(t.type===`chunk`&&t.moduleIds.includes(Y))return t.fileName}function ue(e,t){return e===``||e.endsWith(`/`)?`${e}${t}`:`${e}/${t}`}async function de(e){try{let t=await(0,r.generate)({config:e,onWarn:e=>{w.warn(e)}});w.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.`)}}async function fe(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 Z(e,t,n){if(t!==void 0&&n!==void 0&&t!==n)throw Error(`picked plugin option \`${e}\` is "${t}", and picked.config says "${n}". Remove the plugin option; picked.config is the one place this belongs.`)}function pe(e){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;w.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 me(e,t){let n=await(0,i.loadPickedConfig)(e);n&&n.projectId!==t&&w.warn(`using project "${t}" (picked.config default: "${n.projectId}") — run 'picked status' to inspect`)}var Q=new Map;function he(e,t,n){return JSON.stringify([e,t,n])}function ge(r={}){let a=r.mode??`bundle`,o=r.generateTypes??!0,s=[],l=process.cwd(),u=`serve`,d=`/`,f=null,p=!1,m,h,g=null;return{name:`picked`,config:async(c,d)=>{u=d.command,l=c.root===void 0?process.cwd():(0,t.resolve)(process.cwd(),c.root);let{projectId:_,apiUrl:v}=r,y=await(0,i.loadPickedConfig)(l);Z(`projectId`,_,y?.projectId),Z(`apiUrl`,v,y?.apiUrl),pe({projectId:_,apiUrl:v}),f=await fe(l,{projectId:_,apiUrl:v});let{projectId:b,apiUrl:x,previewToken:S}=f;w.banner(),o&&!p&&(p=!0,await de(f)),x!==le&&w.warn(`using custom API URL: ${x}`),await me(l,b);let C=(0,n.createClientHeaders)(`vite-plugin`,ce());if(a===`api`)w.debug(`mode is 'api': skipping the project-config prefetch`);else if(d.command===`build`){let t=he(x,b,l);m=t;let n=Q.get(t);n===void 0&&(n=(async()=>{w.info(`prefetching project config + content for "${b}"`);let t=P(l),n=(0,e.existsSync)(t.pickedDir),r=performance.now(),i=await ae({apiUrl:x,projectId:b,projectRoot:l,headers:C,previewToken:S??void 0}),a=(performance.now()-r).toFixed(0);await ee(l,n);let o=i.config;return $(o,a),{virtualSource:B({projectConfigPath:t.projectConfigPath,experienceContentPaths:i.experienceContentPaths,manifestMetadata:{mode:`build`,fetchedAt:i.manifest.fetchedAt,projectVersionId:i.manifest.projectVersionId,workspaceId:i.manifest.workspaceId}}),features:M(o.features)}})(),n.catch(()=>Q.delete(t)),Q.set(t,n));let r=await n;h=r.virtualSource,s=r.features}else if(d.mode===`production`)w.debug(`skipping the dev project-config fetch for a production serve resolution`);else{w.info(`fetching project config for "${b}" (dev)`);let e=performance.now(),t=()=>(0,n.fetchProject)(x,b,{headers:C,previewToken:S??void 0}),r=k(x)?await j(t,(e,t,n)=>{w.info(`local API not ready, retrying in ${(n/1e3).toString()}s (${e.toString()}/${t.toString()})`)}):await t(),i=(performance.now()-e).toFixed(0);g=r,r?(s=M(r.features),$(r,i)):w.warn(`failed to fetch project config for "${b}" (${i}ms)`)}},configResolved(e){d=e.base},closeBundle(){m!==void 0&&Q.delete(m)},transformIndexHtml:{order:`post`,handler(e,t){if(a===`api`||t.bundle===void 0)return;let n=X(t.bundle);if(n===void 0)return;let r=ue(d,n);if(!e.includes(`"${r}"`))return[{tag:`link`,attrs:{rel:`modulepreload`,crossorigin:!0,href:r},injectTo:`head`}]}},resolveId(e){if(e===J)return Y},load(e){if(e===Y){if(a===`api`)return z();if(u===`build`)return h;if(!f)throw Error(`picked plugin config hook must run before virtual module load`);return V({apiUrl:f.apiUrl,projectId:f.projectId,projectConfig:g,previewToken:f.previewToken??void 0})}},configureServer(e){if(r.disableLauncher)return;e.middlewares.use(T(()=>c(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){w.debug(`index.html came from the build; skipping the launcher page`);return}this.emitFile({type:`asset`,fileName:`index.html`,source:c(s)})}}}}}function $(e,t){let n=M(e.features),r=M(e.experiences),i=M(e.steps),a=M(e.fields),o=M(e.conditions),s=M(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(`, `);w.info(`fetched config in ${t}ms (${l})`),U(`Features`,n,G),U(`Experiences`,r,K),U(`Steps`,i,q),U(`Fields`,a,oe),U(`Conditions`,o,se),W(`Actions`,s),w.debug(`config size: ${c.toString()} bytes`)}exports.picked=ge;