@picked/vite-plugin-picked 0.0.1-dev.1786070942751 → 0.0.1-dev.1786072899095

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,4 +1,4 @@
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("@picked/client/plugins/dynamic-experiences"),n=require("node:fs/promises"),r=require("node:path");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=>`
2
2
  <div class="feature-row">
3
3
  <label>
4
4
  <input type="checkbox" data-feature-id="${c(e.id)}" checked>
@@ -855,21 +855,14 @@ 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 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 h(e,t){return`${new Date().toLocaleTimeString()} [${t?`${l}:${t}`:l}] ${e}`}function g(e,t,n,r){if(!e.enabled)return;let i=h(t,r);e.log(e.color?e.color(i):i),n!==void 0&&e.log(n)}function _(e){let t=m[e],n=new Set;return Object.assign((e,n,r)=>{g(t,e,n,r)},{once(e,r,i){!t.enabled||n.has(e)||(n.add(e),g(t,e,r,i))}})}function ee(e){let t=p.indexOf(e);if(t===-1){g(m.error,`invalid log level: ${e}`);return}for(let[e,n]of p.entries())m[n].enabled=e>=t}var v=f(`\x1B[34m`),y=f(`\x1B[36m`);function b(){let e=[` ${v(`_`)} ${y(`_`)} _ _ _`,`${v(`(_)`)} ${y(`(_)`)} _ __(_)__| |_____ __| |`,` ${v(`_`)} ${v(`_`)} | '_ \\ / _| / / -_) _\` |`,`${v(`(_)`)} ${v(`(_)`)} | .__/_\\__|_\\_\\___\\__,_|`,` |_|
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 x={banner:b,debug:_(`debug`),info:_(`info`),warn:_(`warn`),error:_(`error`),setLevel:ee};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 S=`.picked/`;async function C(t,i){if(i)return;let a=(0,r.join)(t,`.gitignore`);if(!(0,e.existsSync)(a)){await(0,n.writeFile)(a,`${S}
861
+ `);return}let o=await(0,n.readFile)(a,`utf8`);if(w(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,re=5e3;function T(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 E(e){return new Promise(t=>{setTimeout(t,e)})}async function D(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=re*2**(i-1);t(i,w,a),await E(a),r=null;try{n=await e()}catch(e){r=e}if(n!==null)return n}if(r!==null)throw r;return null}function O(e){return Array.isArray(e)?e:[]}var k=1;function A(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,r.readFile)(t,`utf8`),n=JSON.parse(e);return j(n)?n:null}catch{return null}}function j(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 O(e.steps))n.layoutContentId&&t.add(n.id);if(t.size===0)return[];let n=[];for(let r of O(e.experiences))O(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=A(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 ie(l.manifestPath);if(t&&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:k,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=T(e)?await D(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 = {
865
- mode: 'api',
866
- fetchedAt: null,
867
- projectVersionId: null,
868
- workspaceId: null,
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(`
871
- `);return`import { registerPickedBundle } from '@picked/client/plugins/dynamic-experiences'
872
- import projectConfigJson from ${i(t)}
863
+ `:``}${S}
864
+ `;await(0,n.appendFile)(a,s)}function w(e){return e.split(/\r?\n/).map(e=>e.trim()).some(e=>e===S||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 ne(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<=T;i++){let a=E*2**(i-1);t(i,T,a),await ne(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 re=1;function A(e){let t=(0,r.join)(e,`.picked`);return{pickedDir:t,manifestPath:(0,r.join)(t,`manifest.json`),projectConfigPath:(0,r.join)(t,`project-config.json`),experiencesDir:(0,r.join)(t,`experiences`)}}async function j(t){if(!(0,e.existsSync)(t))return null;try{let e=await(0,n.readFile)(t,`utf8`),r=JSON.parse(e);return M(r)?r:null}catch{return null}}function M(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 N(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 P(e){let{apiUrl:t,projectId:i,projectRoot:a,headers:o,reuseWhenUnchanged:s=!0}=e,c=A(a),l=await I(t,i,o),u=N(l);if(s){let e=await j(c.manifestPath);if(e&&e.projectVersionId===l.versionId&&e.workspaceId===l.workspaceId)return{config:l,manifest:e,experienceContentPaths:F(c,u)}}await(0,n.mkdir)(c.experiencesDir,{recursive:!0}),await(0,n.writeFile)(c.projectConfigPath,JSON.stringify(l,null,2));let d=new Date().toISOString(),f=[];for(let e of u){let a=await L(t,i,e,o),s=(0,r.join)(c.experiencesDir,`${e}.json`);await(0,n.writeFile)(s,JSON.stringify(a,null,2)),f.push({id:e,fetchedAt:d})}let p={version:re,fetchedAt:d,projectVersionId:l.versionId,workspaceId:l.workspaceId,projectId:l.id,experiences:f};return await(0,n.writeFile)(c.manifestPath,JSON.stringify(p,null,2)),{config:l,manifest:p,experienceContentPaths:F(c,u)}}function F(e,t){let n={};for(let i of t)n[i]=(0,r.join)(e.experiencesDir,`${i}.json`);return n}async function I(e,n,r){let i=()=>(0,t.fetchProject)(e,n,{headers:r}),a;try{a=D(e)?await O(i,(e,t,n)=>{x.info(`project config not ready, retrying in ${(n/1e3).toString()}s (${e.toString()}/${t.toString()})`)}):await i()}catch(t){throw Error(`[picked] Build-time fetch of project config failed for "${n}" at ${e}: ${R(t)}`)}if(!a)throw Error(`[picked] Build-time fetch of project config returned no usable response for "${n}" at ${e}. Confirm the API is reachable and the project ID is correct.`);return a}async function L(e,n,r,i){let a;try{a=await(0,t.fetchExperienceContent)(e,n,r,{headers:i})}catch(t){throw Error(`[picked] Build-time fetch of content for experience "${r}" failed at ${e}: ${R(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 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(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(`
865
+ `);return`import projectConfigJson from ${i(t)}
873
866
 
874
867
  const experienceImporters = {
875
868
  ${a}
@@ -890,16 +883,12 @@ export async function experienceContent(experience, _options) {
890
883
  }
891
884
 
892
885
  export const manifestMetadata = ${JSON.stringify(r)}
893
-
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?`
896
- registerPickedBundle({ projectConfig, experienceContent, manifestMetadata })
897
- `:``;return`${i}
886
+ `}function B(e){let{apiUrl:t,projectId:n}=e;return`import { fetchProject, fetchExperienceContent } from '@picked/client/plugins/dynamic-experiences'
898
887
 
899
888
  const apiUrl = ${JSON.stringify(t)}
900
889
  const projectId = ${JSON.stringify(n)}
901
890
 
902
- ${a}
891
+ export const projectConfig = await fetchProject(apiUrl, projectId)
903
892
 
904
893
  export async function experienceContent(experience, options) {
905
894
  const id = typeof experience === 'string' ? experience : experience?.id
@@ -913,5 +902,5 @@ export const manifestMetadata = {
913
902
  projectVersionId: projectConfig?.versionId ?? null,
914
903
  workspaceId: projectConfig?.workspaceId ?? null,
915
904
  }
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.1786070942751`}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=A(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:O(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=T(i)?await D(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=O(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=O(e.features),r=O(e.experiences),i=O(e.steps),a=O(e.fields),o=O(e.conditions),s=O(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;
905
+ `}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(`
906
+ `))}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 Y(){return`0.0.1-dev.1786072899095`}var X=`https://api.picked.app`,Z=`virtual:picked/data`,Q=`\0${Z}`;function ie(n){let r=n.apiUrl??X,i=[],a=process.cwd(),s=`serve`,c,l=!1;return{name:`picked`,config:async(o,u)=>{s=u.command,a=process.cwd(),x.banner(),r!==X&&x.warn(`using custom API URL: ${r}`);let d=(0,t.createClientHeaders)(`vite-plugin`,Y());if(u.command===`build`){if(l)return;l=!0,x.info(`prefetching project config + content for "${n.projectId}"`);let t=A(a),o=(0,e.existsSync)(t.pickedDir),s=performance.now(),u=await P({apiUrl:r,projectId:n.projectId,projectRoot:a,headers:d}),f=(performance.now()-s).toFixed(0);await C(a,o);let p=u.config;i=k(p.features),$(p,f),c=z({projectConfigPath:t.projectConfigPath,experienceContentPaths:u.experienceContentPaths,manifestMetadata:{mode:`build`,fetchedAt:u.manifest.fetchedAt,projectVersionId:u.manifest.projectVersionId,workspaceId:u.manifest.workspaceId}})}else{x.info(`fetching project config for "${n.projectId}" (dev)`);let e=performance.now(),a=()=>(0,t.fetchProject)(r,n.projectId,{headers:d}),o=D(r)?await O(a,(e,t,n)=>{x.info(`local API not ready, retrying in ${(n/1e3).toString()}s (${e.toString()}/${t.toString()})`)}):await a(),s=(performance.now()-e).toFixed(0);o?(i=k(o.features),$(o,s)):x.warn(`failed to fetch project config for "${n.projectId}" (${s}ms)`)}},resolveId(e){if(e===Z)return Q},load(e){if(e===Q)return s===`build`?c:B({apiUrl:r,projectId:n.projectId})},configureServer(e){if(n.disableLauncher)return;e.middlewares.use(te(()=>o(i)));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(){n.disableLauncher||this.emitFile({type:`asset`,fileName:`index.html`,source:o(i)})}}}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(`, `);x.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),x.debug(`config size: ${c.toString()} bytes`)}exports.picked=ie;