@picked/config 0.0.111-next.3 → 0.0.111

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,5 +1,5 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("node:fs"),t=require("node:fs/promises"),n=require("node:path"),r=require("jiti"),i=require("node:crypto"),a=require("@picked/delivery-api-client");function o(e){return e}var s=`manifest.json`,c=`schema.json`,l=`schema-manifest.json`,u=`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../config-BqUv-9JF.cjs");let t=require("node:fs"),n=require("node:fs/promises"),r=require("node:path"),i=require("jiti"),a=require("node:crypto"),o=require("@picked/delivery-api-client");var s=`manifest.json`,c=`schema.json`,l=`schema-manifest.json`,u=`
2
2
  # Picked codegen intermediates
3
3
  .picked/
4
- `;function d(e){let t=(0,n.join)(e,`.picked`);return{pickedDir:t,manifestPath:(0,n.join)(t,s),schemaPath:(0,n.join)(t,c),codegenManifestPath:(0,n.join)(t,l)}}function f(e){return(0,i.createHash)(`sha256`).update(e).digest(`hex`)}function p(e){return typeof e!=`object`||!e?!1:`schemaHash`in e&&typeof e.schemaHash==`string`}async function m(n){if(!(0,e.existsSync)(n))return null;let r=await(0,t.readFile)(n,`utf8`),i=JSON.parse(r);return p(i)?i:null}async function h(e){let n=d(e.projectRoot);await(0,t.mkdir)(n.pickedDir,{recursive:!0}),await(0,t.writeFile)(n.schemaPath,e.schemaJson,`utf8`),await(0,t.writeFile)(n.codegenManifestPath,`${JSON.stringify(e.manifest,null,2)}\n`,`utf8`)}async function g(r){let i=(0,n.join)(r,`.gitignore`);(0,e.existsSync)(i)?(await(0,t.readFile)(i,`utf8`)).includes(`.picked/`)||await(0,t.appendFile)(i,u,`utf8`):await(0,t.writeFile)(i,`.picked/
5
- `,`utf8`)}function _(e){let t;try{t=new URL(e)}catch{throw Error(`Invalid Picked API URL: ${e}`)}let n=t.hostname===`localhost`||t.hostname===`127.0.0.1`||t.hostname===`[::1]`;if(t.protocol!==`https:`&&!n)throw Error(`Refusing to use a non-HTTPS Picked API URL (${e}); tokens must not be sent over cleartext.`);return e}function v(e){return new URL(_(e)).origin}var y=`settings.json`,b=384;function x(e){return(0,n.join)(e,`.picked`,y)}function ee(e){return!(typeof e!=`object`||!e||!(`id`in e)||typeof e.id!=`string`||!(`name`in e)||typeof e.name!=`string`||!(`status`in e)||typeof e.status!=`string`||!(`source`in e)||e.source!==`published`&&e.source!==`preview`)}function te(e){return typeof e!=`object`||!e||!(`projectId`in e)||typeof e.projectId!=`string`?!1:!(`workspace`in e)||e.workspace===void 0||ee(e.workspace)}function ne(e){return typeof e!=`object`||!e?!1:Object.values(e).every(te)}async function S(n){let r=x(n);if(!(0,e.existsSync)(r))return{};try{let e=JSON.parse(await(0,t.readFile)(r,`utf8`));return ne(e)?e:{}}catch{return{}}}async function C(e,t){return(await S(e))[v(t)]??null}async function w(e,r,i){let a=x(e),o={...await S(e),[v(r)]:i};await(0,t.mkdir)((0,n.dirname)(a),{recursive:!0}),await g(e),await(0,t.writeFile)(a,`${JSON.stringify(o,null,2)}\n`,{encoding:`utf8`,mode:b}),await(0,t.chmod)(a,b)}var T=`https://api.picked.app`,E=`./src/picked-env.d.ts`,D=[`picked.config.ts`,`picked.config.js`,`picked.config.json`];function O(e){return typeof e==`object`&&!!e}function k(e){return O(e)&&typeof e.projectId==`string`&&e.projectId.length>0}function re(e){return e===`preview`?`preview`:`published`}var ie=new Set([`bundle`,`api`,`snapshot`]);function A(e){return typeof e==`string`&&ie.has(e)}function ae(e){let t=process.env.PICKED_DATA;if(t!==void 0&&t!==``){if(!A(t))throw Error(`PICKED_DATA is "${t}"; it takes 'bundle', 'api' or 'snapshot'.`);return t}if(e===void 0)return`bundle`;if(!A(e))throw Error(`picked.config \`data\` is ${JSON.stringify(e)}; it takes 'bundle', 'api' or 'snapshot'.`);return e}function j(e,t,r){let i=process.env.PICKED_PREVIEW_TOKEN??null,a=process.env.PICKED_PROJECT_ID,o={apiUrl:_(e.apiUrl??T),typesOutput:(0,n.resolve)(t,e.typesOutput??E),projectRoot:t,telemetry:e.telemetry??!1,data:ae(e.data)};if(r){let t=a??r.projectId;if(r.workspace?.source===`preview`){let n=i??r.workspace.previewToken??e.previewToken??null;return{...o,projectId:t,source:`preview`,previewToken:n}}return{...o,projectId:t,source:`published`,previewToken:null}}let s=re(e.source),c=s===`preview`?i??e.previewToken??null:null;return{...o,projectId:a??e.projectId,source:s,previewToken:c}}async function M(i=process.cwd()){for(let a of D){let o=(0,n.join)(i,a);if(!(0,e.existsSync)(o))continue;if(a.endsWith(`.json`)){let e=await(0,t.readFile)(o,`utf8`),n=JSON.parse(e);if(k(n))return n;throw Error(`Invalid picked.config.json at ${o}`)}let s=await(0,r.createJiti)({}.url,{interopDefault:!0}).import(o),c=O(s)&&`default`in s?s.default:s;if(k(c))return c;throw Error(`Invalid ${a} at ${o}`)}return null}function N(e,t){let n=e?.projectId??t?.projectId;return n===void 0||n.length===0?null:{...t,...e,projectId:n,apiUrl:e?.apiUrl??t?.apiUrl,data:e?.data??t?.data}}async function P(e=process.cwd(),t){let n=N(await M(e),t);return n?j(n,e,await C(e,n.apiUrl??T)):null}var F={VERCEL:`vercel`,NETLIFY:`netlify`,CF_PAGES:`cloudflare-pages`,GITHUB_ACTIONS:`github-actions`,GITLAB_CI:`gitlab-ci`,CIRCLECI:`circleci`,BITBUCKET_BUILD_NUMBER:`bitbucket-pipelines`};function I(){let e=!!process.env.CI;for(let[e,t]of Object.entries(F))if(process.env[e])return{provider:t,ci:!0};return{provider:e?`unknown`:`local`,ci:e}}var L=new Set([`1`,`true`]),R=new Set([`0`,`false`]);function z(e){let t=e?.trim().toLowerCase();if(t!==void 0){if(L.has(t))return!0;if(R.has(t))return!1}}function B(){return z(process.env.PICKED_TELEMETRY)===!1||z(process.env.DO_NOT_TRACK)===!0}function V(e,t){return B()?!1:t===void 0?z(process.env.PICKED_TELEMETRY)===!0||e.telemetry:t}var H=`picked.snapshot.json`,U=1,W="Run `picked pull` to write a fresh one.";function G(e){return(0,n.join)(e,H)}function K(e){let t=new Set;for(let n of e.steps)n.layoutContentId&&t.add(n.id);return t.size===0?[]:e.experiences.filter(e=>e.nodes.some(e=>e.type===`step`&&t.has(e.stepId))).map(e=>e.id)}function q(e,t){return e===t?0:e<t?-1:1}function J(e){let t={};for(let n of Object.keys(e.experiences).sort(q)){let r=e.experiences[n];r!==void 0&&(t[n]=r)}let n={snapshotVersion:e.snapshotVersion,projectId:e.projectId,workspaceId:e.workspaceId,projectVersionId:e.projectVersionId,source:e.source,schema:e.schema,projectConfig:e.projectConfig,experiences:t};return`${JSON.stringify(n,null,2)}\n`}function Y(e){return typeof e==`object`&&!!e}function oe(e){return Y(e)&&typeof e.id==`string`&&Array.isArray(e.features)&&Array.isArray(e.experiences)&&Array.isArray(e.steps)}function se(e){return Y(e)&&Object.values(e).every(e=>Y(e)&&typeof e.experienceId==`string`&&Array.isArray(e.content))}function ce(e){return Y(e)&&typeof e.snapshotVersion==`number`&&typeof e.projectId==`string`&&typeof e.workspaceId==`string`&&(typeof e.projectVersionId==`string`||e.projectVersionId===null)&&(e.source===`published`||e.source===`preview`)&&(0,a.isWorkspaceSchema)(e.schema)&&oe(e.projectConfig)&&se(e.experiences)}async function X(n){let r=G(n);if(!(0,e.existsSync)(r))return null;let i;try{i=JSON.parse(await(0,t.readFile)(r,`utf8`))}catch{throw Error(`${r} is not valid JSON. ${W}`)}if(Y(i)&&typeof i.snapshotVersion==`number`&&i.snapshotVersion!==1)throw Error(`${r} is in snapshot format ${i.snapshotVersion.toString()}, and this SDK reads format 1. ${W}`);if(!ce(i))throw Error(`${r} is not a Picked snapshot. ${W}`);return i}async function Z(e){let t=await X(e.projectRoot);if(!t)throw Error(`picked.config sets \`data: 'snapshot'\`, and there is no ${H} in ${e.projectRoot}. Run \`picked pull\` to write one.`);if(t.projectId!==e.projectId)throw Error(`${H} holds project "${t.projectId}", and the project in force is "${e.projectId}". ${W}`);return t}async function le(e,n){await(0,t.writeFile)(G(e),J(n),`utf8`)}async function Q(e,t){let n=[],r=await t(e=>{n.push(e)});if(r===null){let t=n.at(-1)??`no response`;throw Error(`Could not fetch ${e}: ${t}`)}return r}function $(e,t,n){if(e!==null&&t!==null&&t!==e)throw Error(`The workspace was published while pulling: the project config is at version ${e} and ${n} at ${t}. Run \`picked pull\` again.`)}async function ue(e){let{apiUrl:t,projectId:n,source:r,previewToken:i,headers:o}=e,s={previewToken:i,headers:o},c=await Q(`the workspace schema for "${n}" from ${t}`,e=>(0,a.fetchSchema)(t,n,{...s,onWarn:e})),l=await Q(`the project config for "${n}" from ${t}`,e=>(0,a.fetchProject)(t,n,{...s,onWarn:e})),u=l.versionId;$(u,c[`x-picked-version-id`],`the workspace schema`);let d=await Promise.all(K(l).map(async e=>[e,await Q(`content for experience "${e}"`,r=>(0,a.fetchExperienceContent)(t,n,e,{...s,onWarn:r}))])),f={};for(let[e,t]of d)$(u,t.versionId,`content for experience "${e}"`),f[e]=t;return{snapshotVersion:1,projectId:n,workspaceId:l.workspaceId,projectVersionId:u,source:r,schema:c,projectConfig:l,experiences:f}}exports.SNAPSHOT_FILENAME=H,exports.SNAPSHOT_VERSION=U,exports.appendPickedGitignore=g,exports.assertSecureApiUrl=_,exports.collectCmsExperienceIds=K,exports.defineConfig=o,exports.detectHostEnvironment=I,exports.fetchSnapshot=ue,exports.hashSchemaJson=f,exports.isTelemetryEnabled=V,exports.isTelemetryForcedOffByEnvironment=B,exports.loadPickedConfig=M,exports.loadResolvedPickedConfig=P,exports.normalizeApiUrl=v,exports.readActiveSelection=C,exports.readCodegenManifest=m,exports.readSnapshot=X,exports.requireSnapshot=Z,exports.resolvePickedConfig=j,exports.resolvePickedPaths=d,exports.resolveSettingsPath=x,exports.resolveSnapshotPath=G,exports.serializeSnapshot=J,exports.writeActiveSelection=w,exports.writeCodegenArtifacts=h,exports.writeSnapshot=le;
4
+ `;function d(e){let t=(0,r.join)(e,`.picked`);return{pickedDir:t,manifestPath:(0,r.join)(t,s),schemaPath:(0,r.join)(t,c),codegenManifestPath:(0,r.join)(t,l)}}function f(e){return(0,a.createHash)(`sha256`).update(e).digest(`hex`)}function p(e){return typeof e!=`object`||!e?!1:`schemaHash`in e&&typeof e.schemaHash==`string`}async function m(e){if(!(0,t.existsSync)(e))return null;let r=await(0,n.readFile)(e,`utf8`),i=JSON.parse(r);return p(i)?i:null}async function ee(e){let t=d(e.projectRoot);await(0,n.mkdir)(t.pickedDir,{recursive:!0}),await(0,n.writeFile)(t.schemaPath,e.schemaJson,`utf8`),await(0,n.writeFile)(t.codegenManifestPath,`${JSON.stringify(e.manifest,null,2)}\n`,`utf8`)}async function h(e){let i=(0,r.join)(e,`.gitignore`);(0,t.existsSync)(i)?(await(0,n.readFile)(i,`utf8`)).includes(`.picked/`)||await(0,n.appendFile)(i,u,`utf8`):await(0,n.writeFile)(i,`.picked/
5
+ `,`utf8`)}function g(e){let t;try{t=new URL(e)}catch{throw Error(`Invalid Picked API URL: ${e}`)}let n=t.hostname===`localhost`||t.hostname===`127.0.0.1`||t.hostname===`[::1]`;if(t.protocol!==`https:`&&!n)throw Error(`Refusing to use a non-HTTPS Picked API URL (${e}); tokens must not be sent over cleartext.`);return e}function _(e){return new URL(g(e)).origin}var te=`settings.json`,v=384;function y(e){return(0,r.join)(e,`.picked`,te)}function ne(e){return!(typeof e!=`object`||!e||!(`id`in e)||typeof e.id!=`string`||!(`name`in e)||typeof e.name!=`string`||!(`status`in e)||typeof e.status!=`string`||!(`source`in e)||e.source!==`published`&&e.source!==`preview`)}function re(e){return typeof e!=`object`||!e||!(`projectId`in e)||typeof e.projectId!=`string`?!1:!(`workspace`in e)||e.workspace===void 0||ne(e.workspace)}function b(e){return typeof e!=`object`||!e?!1:Object.values(e).every(re)}async function x(e){let r=y(e);if(!(0,t.existsSync)(r))return{};try{let e=JSON.parse(await(0,n.readFile)(r,`utf8`));return b(e)?e:{}}catch{return{}}}async function S(e,t){return(await x(e))[_(t)]??null}async function C(e,t,i){let a=y(e),o={...await x(e),[_(t)]:i};await(0,n.mkdir)((0,r.dirname)(a),{recursive:!0}),await h(e),await(0,n.writeFile)(a,`${JSON.stringify(o,null,2)}\n`,{encoding:`utf8`,mode:v}),await(0,n.chmod)(a,v)}var w=`https://api.picked.app`,T=`./src/picked-env.d.ts`,ie=[`picked.config.ts`,`picked.config.js`,`picked.config.json`];function E(e){return typeof e==`object`&&!!e}function D(e){return typeof e.projectId==`string`&&e.projectId!==``&&(e.app===void 0||k(e.app))}function O(e){return k(e.app)&&(e.projectId===void 0||typeof e.projectId==`string`&&e.projectId!==``)}function k(e){return E(e)&&!Array.isArray(e)&&typeof e.handle==`string`&&e.handle!==``&&typeof e.name==`string`&&e.name!==``}function ae(e,t){if(!E(e)||Array.isArray(e))throw Error(`${t}: \`app\` must be the app manifest, an object.`);if(typeof e.handle!=`string`||e.handle===``)throw Error(`${t}: \`app.handle\` must be a non-empty string.`);if(typeof e.name!=`string`||e.name===``)throw Error(`${t}: \`app.name\` must be a non-empty string.`)}function A(e,t){if(!E(e)||Array.isArray(e))throw Error(`${t}: export a config object.`);if(e.projectId===void 0&&e.app===void 0)throw Error(`${t}: it sets neither \`projectId\` (a project) nor \`app\` (an app). Set one or both.`);if(e.projectId!==void 0&&(typeof e.projectId!=`string`||e.projectId===``))throw Error(`${t}: \`projectId\` must be a non-empty string.`);if(e.app!==void 0&&ae(e.app,t),e.apiUrl!==void 0&&(typeof e.apiUrl!=`string`||e.apiUrl===``))throw Error(`${t}: \`apiUrl\` must be the Picked API origin.`);if(D(e)||O(e))return e;throw Error(`${t}: export a config object.`)}function oe(e){return e===`preview`?`preview`:`published`}var se=new Set([`bundle`,`api`,`snapshot`]);function j(e){return typeof e==`string`&&se.has(e)}function M(e){let t=process.env.PICKED_DATA;if(t!==void 0&&t!==``){if(!j(t))throw Error(`PICKED_DATA is "${t}"; it takes 'bundle', 'api' or 'snapshot'.`);return t}if(e===void 0)return`bundle`;if(!j(e))throw Error(`picked.config \`data\` is ${JSON.stringify(e)}; it takes 'bundle', 'api' or 'snapshot'.`);return e}function N(e,t,n){let i=process.env.PICKED_PREVIEW_TOKEN??null,a=process.env.PICKED_PROJECT_ID,o={apiUrl:g(e.apiUrl??w),typesOutput:(0,r.resolve)(t,e.typesOutput??T),projectRoot:t,telemetry:e.telemetry??!1,data:M(e.data)};if(n){let t=a??n.projectId;if(n.workspace?.source===`preview`){let r=i??n.workspace.previewToken??e.previewToken??null;return{...o,projectId:t,source:`preview`,previewToken:r}}return{...o,projectId:t,source:`published`,previewToken:null}}let s=oe(e.source),c=s===`preview`?i??e.previewToken??null:null;return{...o,projectId:a??e.projectId,source:s,previewToken:c}}async function P(e=process.cwd()){for(let a of ie){let o=(0,r.join)(e,a);if(!(0,t.existsSync)(o))continue;if(a.endsWith(`.json`)){let e=await(0,n.readFile)(o,`utf8`);return A(JSON.parse(e),`Invalid picked.config.json at ${o}`)}let s=await(0,i.createJiti)({}.url,{interopDefault:!0}).import(o);return A(E(s)&&`default`in s?s.default:s,`Invalid ${a} at ${o}`)}return null}function F(e,t){let n=e?.projectId??t?.projectId;return n===void 0||n.length===0?null:{...t,...e,projectId:n,apiUrl:e?.apiUrl??t?.apiUrl,data:e?.data??t?.data}}async function I(t=process.cwd(),n){let r=await P(t),i=F(r,n);if(!i){if(r&&!e.r(r))throw Error(`picked.config in ${t} names no project. Add \`projectId\` beside its \`app\` section.`);return null}return N(i,t,await S(t,i.apiUrl??w))}var L={VERCEL:`vercel`,NETLIFY:`netlify`,CF_PAGES:`cloudflare-pages`,GITHUB_ACTIONS:`github-actions`,GITLAB_CI:`gitlab-ci`,CIRCLECI:`circleci`,BITBUCKET_BUILD_NUMBER:`bitbucket-pipelines`};function R(){let e=!!process.env.CI;for(let[e,t]of Object.entries(L))if(process.env[e])return{provider:t,ci:!0};return{provider:e?`unknown`:`local`,ci:e}}var z=new Set([`1`,`true`]),B=new Set([`0`,`false`]);function V(e){let t=e?.trim().toLowerCase();if(t!==void 0){if(z.has(t))return!0;if(B.has(t))return!1}}function H(){return V(process.env.PICKED_TELEMETRY)===!1||V(process.env.DO_NOT_TRACK)===!0}function U(e,t){return H()?!1:t===void 0?V(process.env.PICKED_TELEMETRY)===!0||e.telemetry:t}var W=`picked.snapshot.json`,G=1,K="Run `picked pull` to write a fresh one.";function q(e){return(0,r.join)(e,W)}function J(e){let t=new Set;for(let n of e.steps)n.layoutContentId&&t.add(n.id);return t.size===0?[]:e.experiences.filter(e=>e.nodes.some(e=>e.type===`step`&&t.has(e.stepId))).map(e=>e.id)}function ce(e,t){return e===t?0:e<t?-1:1}function Y(e){let t={};for(let n of Object.keys(e.experiences).sort(ce)){let r=e.experiences[n];r!==void 0&&(t[n]=r)}let n={snapshotVersion:e.snapshotVersion,projectId:e.projectId,workspaceId:e.workspaceId,projectVersionId:e.projectVersionId,source:e.source,schema:e.schema,projectConfig:e.projectConfig,experiences:t};return`${JSON.stringify(n,null,2)}\n`}function X(e){return typeof e==`object`&&!!e}function le(e){return X(e)&&typeof e.id==`string`&&Array.isArray(e.features)&&Array.isArray(e.experiences)&&Array.isArray(e.steps)}function ue(e){return X(e)&&Object.values(e).every(e=>X(e)&&typeof e.experienceId==`string`&&Array.isArray(e.content))}function de(e){return X(e)&&typeof e.snapshotVersion==`number`&&typeof e.projectId==`string`&&typeof e.workspaceId==`string`&&(typeof e.projectVersionId==`string`||e.projectVersionId===null)&&(e.source===`published`||e.source===`preview`)&&(0,o.isWorkspaceSchema)(e.schema)&&le(e.projectConfig)&&ue(e.experiences)}async function Z(e){let r=q(e);if(!(0,t.existsSync)(r))return null;let i;try{i=JSON.parse(await(0,n.readFile)(r,`utf8`))}catch{throw Error(`${r} is not valid JSON. ${K}`)}if(X(i)&&typeof i.snapshotVersion==`number`&&i.snapshotVersion!==1)throw Error(`${r} is in snapshot format ${i.snapshotVersion.toString()}, and this SDK reads format 1. ${K}`);if(!de(i))throw Error(`${r} is not a Picked snapshot. ${K}`);return i}async function fe(e){let t=await Z(e.projectRoot);if(!t)throw Error(`picked.config sets \`data: 'snapshot'\`, and there is no ${W} in ${e.projectRoot}. Run \`picked pull\` to write one.`);if(t.projectId!==e.projectId)throw Error(`${W} holds project "${t.projectId}", and the project in force is "${e.projectId}". ${K}`);return t}async function pe(e,t){await(0,n.writeFile)(q(e),Y(t),`utf8`)}async function Q(e,t){let n=[],r=await t(e=>{n.push(e)});if(r===null){let t=n.at(-1)??`no response`;throw Error(`Could not fetch ${e}: ${t}`)}return r}function $(e,t,n){if(e!==null&&t!==null&&t!==e)throw Error(`The workspace was published while pulling: the project config is at version ${e} and ${n} at ${t}. Run \`picked pull\` again.`)}async function me(e){let{apiUrl:t,projectId:n,source:r,previewToken:i,headers:a}=e,s={previewToken:i,headers:a},c=await Q(`the workspace schema for "${n}" from ${t}`,e=>(0,o.fetchSchema)(t,n,{...s,onWarn:e})),l=await Q(`the project config for "${n}" from ${t}`,e=>(0,o.fetchProject)(t,n,{...s,onWarn:e})),u=l.versionId;$(u,c[`x-picked-version-id`],`the workspace schema`);let d=await Promise.all(J(l).map(async e=>[e,await Q(`content for experience "${e}"`,r=>(0,o.fetchExperienceContent)(t,n,e,{...s,onWarn:r}))])),f={};for(let[e,t]of d)$(u,t.versionId,`content for experience "${e}"`),f[e]=t;return{snapshotVersion:1,projectId:n,workspaceId:l.workspaceId,projectVersionId:u,source:r,schema:c,projectConfig:l,experiences:f}}exports.SNAPSHOT_FILENAME=W,exports.SNAPSHOT_VERSION=G,exports.appendPickedGitignore=h,exports.assertSecureApiUrl=g,exports.collectCmsExperienceIds=J,exports.defineConfig=e.t,exports.detectHostEnvironment=R,exports.fetchSnapshot=me,exports.hasApp=e.n,exports.hasProject=e.r,exports.hashSchemaJson=f,exports.isTelemetryEnabled=U,exports.isTelemetryForcedOffByEnvironment=H,exports.loadPickedConfig=P,exports.loadResolvedPickedConfig=I,exports.normalizeApiUrl=_,exports.readActiveSelection=S,exports.readCodegenManifest=m,exports.readSnapshot=Z,exports.requireSnapshot=fe,exports.resolvePickedConfig=N,exports.resolvePickedPaths=d,exports.resolveSettingsPath=y,exports.resolveSnapshotPath=q,exports.serializeSnapshot=Y,exports.writeActiveSelection=C,exports.writeCodegenArtifacts=ee,exports.writeSnapshot=pe;
@@ -0,0 +1,12 @@
1
+ //#region src/config.ts
2
+ function e(e) {
3
+ return e.projectId !== void 0;
4
+ }
5
+ function t(e) {
6
+ return e.app !== void 0;
7
+ }
8
+ function n(e) {
9
+ return e;
10
+ }
11
+ //#endregion
12
+ export { t as n, e as r, n as t };
@@ -0,0 +1 @@
1
+ function e(e){return e.projectId!==void 0}function t(e){return e.app!==void 0}function n(e){return e}Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return e}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return n}});
@@ -0,0 +1 @@
1
+ export { t as defineConfig, n as hasApp, r as hasProject } from "../config-BHuvJukH.js";
package/dist/esm/index.js CHANGED
@@ -1,43 +1,39 @@
1
- import { existsSync as e } from "node:fs";
2
- import { appendFile as t, chmod as n, mkdir as r, readFile as i, writeFile as a } from "node:fs/promises";
3
- import { dirname as o, join as s, resolve as c } from "node:path";
4
- import { createJiti as l } from "jiti";
5
- import { createHash as u } from "node:crypto";
6
- import { fetchExperienceContent as ee, fetchProject as te, fetchSchema as d, isWorkspaceSchema as f } from "@picked/delivery-api-client";
7
- //#region src/config.ts
8
- function ne(e) {
9
- return e;
10
- }
11
- //#endregion
1
+ import { n as e, r as t, t as n } from "../config-BHuvJukH.js";
2
+ import { existsSync as r } from "node:fs";
3
+ import { appendFile as i, chmod as a, mkdir as o, readFile as s, writeFile as c } from "node:fs/promises";
4
+ import { dirname as l, join as u, resolve as d } from "node:path";
5
+ import { createJiti as ee } from "jiti";
6
+ import { createHash as te } from "node:crypto";
7
+ import { fetchExperienceContent as ne, fetchProject as re, fetchSchema as ie, isWorkspaceSchema as ae } from "@picked/delivery-api-client";
12
8
  //#region src/manifest.ts
13
- var re = "manifest.json", ie = "schema.json", ae = "schema-manifest.json", oe = "\n# Picked codegen intermediates\n.picked/\n";
14
- function p(e) {
15
- let t = s(e, ".picked");
9
+ var f = "manifest.json", p = "schema.json", m = "schema-manifest.json", h = "\n# Picked codegen intermediates\n.picked/\n";
10
+ function g(e) {
11
+ let t = u(e, ".picked");
16
12
  return {
17
13
  pickedDir: t,
18
- manifestPath: s(t, re),
19
- schemaPath: s(t, ie),
20
- codegenManifestPath: s(t, ae)
14
+ manifestPath: u(t, f),
15
+ schemaPath: u(t, p),
16
+ codegenManifestPath: u(t, m)
21
17
  };
22
18
  }
23
- function m(e) {
24
- return u("sha256").update(e).digest("hex");
19
+ function _(e) {
20
+ return te("sha256").update(e).digest("hex");
25
21
  }
26
- function h(e) {
22
+ function oe(e) {
27
23
  return typeof e != "object" || !e ? !1 : "schemaHash" in e && typeof e.schemaHash == "string";
28
24
  }
29
- async function g(t) {
30
- if (!e(t)) return null;
31
- let n = await i(t, "utf8"), r = JSON.parse(n);
32
- return h(r) ? r : null;
25
+ async function se(e) {
26
+ if (!r(e)) return null;
27
+ let t = await s(e, "utf8"), n = JSON.parse(t);
28
+ return oe(n) ? n : null;
33
29
  }
34
- async function _(e) {
35
- let t = p(e.projectRoot);
36
- await r(t.pickedDir, { recursive: !0 }), await a(t.schemaPath, e.schemaJson, "utf8"), await a(t.codegenManifestPath, `${JSON.stringify(e.manifest, null, 2)}\n`, "utf8");
30
+ async function ce(e) {
31
+ let t = g(e.projectRoot);
32
+ await o(t.pickedDir, { recursive: !0 }), await c(t.schemaPath, e.schemaJson, "utf8"), await c(t.codegenManifestPath, `${JSON.stringify(e.manifest, null, 2)}\n`, "utf8");
37
33
  }
38
- async function v(n) {
39
- let r = s(n, ".gitignore");
40
- e(r) ? (await i(r, "utf8")).includes(".picked/") || await t(r, oe, "utf8") : await a(r, ".picked/\n", "utf8");
34
+ async function v(e) {
35
+ let t = u(e, ".gitignore");
36
+ r(t) ? (await s(t, "utf8")).includes(".picked/") || await i(t, h, "utf8") : await c(t, ".picked/\n", "utf8");
41
37
  }
42
38
  //#endregion
43
39
  //#region src/url-safety.ts
@@ -57,83 +53,102 @@ function b(e) {
57
53
  }
58
54
  //#endregion
59
55
  //#region src/settings.ts
60
- var se = "settings.json", x = 384;
61
- function S(e) {
62
- return s(e, ".picked", se);
63
- }
64
- function ce(e) {
65
- return !(typeof e != "object" || !e || !("id" in e) || typeof e.id != "string" || !("name" in e) || typeof e.name != "string" || !("status" in e) || typeof e.status != "string" || !("source" in e) || e.source !== "published" && e.source !== "preview");
56
+ var x = "settings.json", S = 384;
57
+ function C(e) {
58
+ return u(e, ".picked", x);
66
59
  }
67
60
  function le(e) {
68
- return typeof e != "object" || !e || !("projectId" in e) || typeof e.projectId != "string" ? !1 : !("workspace" in e) || e.workspace === void 0 || ce(e.workspace);
61
+ return !(typeof e != "object" || !e || !("id" in e) || typeof e.id != "string" || !("name" in e) || typeof e.name != "string" || !("status" in e) || typeof e.status != "string" || !("source" in e) || e.source !== "published" && e.source !== "preview");
69
62
  }
70
63
  function ue(e) {
71
- return typeof e != "object" || !e ? !1 : Object.values(e).every(le);
64
+ return typeof e != "object" || !e || !("projectId" in e) || typeof e.projectId != "string" ? !1 : !("workspace" in e) || e.workspace === void 0 || le(e.workspace);
72
65
  }
73
- async function C(t) {
74
- let n = S(t);
75
- if (!e(n)) return {};
66
+ function de(e) {
67
+ return typeof e != "object" || !e ? !1 : Object.values(e).every(ue);
68
+ }
69
+ async function w(e) {
70
+ let t = C(e);
71
+ if (!r(t)) return {};
76
72
  try {
77
- let e = JSON.parse(await i(n, "utf8"));
78
- return ue(e) ? e : {};
73
+ let e = JSON.parse(await s(t, "utf8"));
74
+ return de(e) ? e : {};
79
75
  } catch {
80
76
  return {};
81
77
  }
82
78
  }
83
- async function w(e, t) {
84
- return (await C(e))[b(t)] ?? null;
79
+ async function T(e, t) {
80
+ return (await w(e))[b(t)] ?? null;
85
81
  }
86
- async function de(e, t, i) {
87
- let s = S(e), c = {
88
- ...await C(e),
89
- [b(t)]: i
82
+ async function fe(e, t, n) {
83
+ let r = C(e), i = {
84
+ ...await w(e),
85
+ [b(t)]: n
90
86
  };
91
- await r(o(s), { recursive: !0 }), await v(e), await a(s, `${JSON.stringify(c, null, 2)}\n`, {
87
+ await o(l(r), { recursive: !0 }), await v(e), await c(r, `${JSON.stringify(i, null, 2)}\n`, {
92
88
  encoding: "utf8",
93
- mode: x
94
- }), await n(s, x);
89
+ mode: S
90
+ }), await a(r, S);
95
91
  }
96
92
  //#endregion
97
93
  //#region src/load-config.ts
98
- var T = "https://api.picked.app", E = "./src/picked-env.d.ts", D = [
94
+ var E = "https://api.picked.app", D = "./src/picked-env.d.ts", O = [
99
95
  "picked.config.ts",
100
96
  "picked.config.js",
101
97
  "picked.config.json"
102
98
  ];
103
- function O(e) {
104
- return typeof e == "object" && !!e;
105
- }
106
99
  function k(e) {
107
- return O(e) && typeof e.projectId == "string" && e.projectId.length > 0;
100
+ return typeof e == "object" && !!e;
108
101
  }
109
102
  function A(e) {
103
+ return typeof e.projectId == "string" && e.projectId !== "" && (e.app === void 0 || M(e.app));
104
+ }
105
+ function j(e) {
106
+ return M(e.app) && (e.projectId === void 0 || typeof e.projectId == "string" && e.projectId !== "");
107
+ }
108
+ function M(e) {
109
+ return k(e) && !Array.isArray(e) && typeof e.handle == "string" && e.handle !== "" && typeof e.name == "string" && e.name !== "";
110
+ }
111
+ function N(e, t) {
112
+ if (!k(e) || Array.isArray(e)) throw Error(`${t}: \`app\` must be the app manifest, an object.`);
113
+ if (typeof e.handle != "string" || e.handle === "") throw Error(`${t}: \`app.handle\` must be a non-empty string.`);
114
+ if (typeof e.name != "string" || e.name === "") throw Error(`${t}: \`app.name\` must be a non-empty string.`);
115
+ }
116
+ function P(e, t) {
117
+ if (!k(e) || Array.isArray(e)) throw Error(`${t}: export a config object.`);
118
+ if (e.projectId === void 0 && e.app === void 0) throw Error(`${t}: it sets neither \`projectId\` (a project) nor \`app\` (an app). Set one or both.`);
119
+ if (e.projectId !== void 0 && (typeof e.projectId != "string" || e.projectId === "")) throw Error(`${t}: \`projectId\` must be a non-empty string.`);
120
+ if (e.app !== void 0 && N(e.app, t), e.apiUrl !== void 0 && (typeof e.apiUrl != "string" || e.apiUrl === "")) throw Error(`${t}: \`apiUrl\` must be the Picked API origin.`);
121
+ if (A(e) || j(e)) return e;
122
+ throw Error(`${t}: export a config object.`);
123
+ }
124
+ function F(e) {
110
125
  return e === "preview" ? "preview" : "published";
111
126
  }
112
- var j = /* @__PURE__ */ new Set([
127
+ var I = /* @__PURE__ */ new Set([
113
128
  "bundle",
114
129
  "api",
115
130
  "snapshot"
116
131
  ]);
117
- function M(e) {
118
- return typeof e == "string" && j.has(e);
132
+ function L(e) {
133
+ return typeof e == "string" && I.has(e);
119
134
  }
120
- function N(e) {
135
+ function R(e) {
121
136
  let t = process.env.PICKED_DATA;
122
137
  if (t !== void 0 && t !== "") {
123
- if (!M(t)) throw Error(`PICKED_DATA is "${t}"; it takes 'bundle', 'api' or 'snapshot'.`);
138
+ if (!L(t)) throw Error(`PICKED_DATA is "${t}"; it takes 'bundle', 'api' or 'snapshot'.`);
124
139
  return t;
125
140
  }
126
141
  if (e === void 0) return "bundle";
127
- if (!M(e)) throw Error(`picked.config \`data\` is ${JSON.stringify(e)}; it takes 'bundle', 'api' or 'snapshot'.`);
142
+ if (!L(e)) throw Error(`picked.config \`data\` is ${JSON.stringify(e)}; it takes 'bundle', 'api' or 'snapshot'.`);
128
143
  return e;
129
144
  }
130
- function P(e, t, n) {
145
+ function z(e, t, n) {
131
146
  let r = process.env.PICKED_PREVIEW_TOKEN ?? null, i = process.env.PICKED_PROJECT_ID, a = {
132
- apiUrl: y(e.apiUrl ?? T),
133
- typesOutput: c(t, e.typesOutput ?? E),
147
+ apiUrl: y(e.apiUrl ?? E),
148
+ typesOutput: d(t, e.typesOutput ?? D),
134
149
  projectRoot: t,
135
150
  telemetry: e.telemetry ?? !1,
136
- data: N(e.data)
151
+ data: R(e.data)
137
152
  };
138
153
  if (n) {
139
154
  let t = i ?? n.projectId;
@@ -153,7 +168,7 @@ function P(e, t, n) {
153
168
  previewToken: null
154
169
  };
155
170
  }
156
- let o = A(e.source), s = o === "preview" ? r ?? e.previewToken ?? null : null;
171
+ let o = F(e.source), s = o === "preview" ? r ?? e.previewToken ?? null : null;
157
172
  return {
158
173
  ...a,
159
174
  projectId: i ?? e.projectId,
@@ -161,22 +176,20 @@ function P(e, t, n) {
161
176
  previewToken: s
162
177
  };
163
178
  }
164
- async function F(t = process.cwd()) {
165
- for (let n of D) {
166
- let r = s(t, n);
167
- if (!e(r)) continue;
168
- if (n.endsWith(".json")) {
169
- let e = await i(r, "utf8"), t = JSON.parse(e);
170
- if (k(t)) return t;
171
- throw Error(`Invalid picked.config.json at ${r}`);
179
+ async function B(e = process.cwd()) {
180
+ for (let t of O) {
181
+ let n = u(e, t);
182
+ if (!r(n)) continue;
183
+ if (t.endsWith(".json")) {
184
+ let e = await s(n, "utf8");
185
+ return P(JSON.parse(e), `Invalid picked.config.json at ${n}`);
172
186
  }
173
- let a = await l(import.meta.url, { interopDefault: !0 }).import(r), o = O(a) && "default" in a ? a.default : a;
174
- if (k(o)) return o;
175
- throw Error(`Invalid ${n} at ${r}`);
187
+ let i = await ee(import.meta.url, { interopDefault: !0 }).import(n);
188
+ return P(k(i) && "default" in i ? i.default : i, `Invalid ${t} at ${n}`);
176
189
  }
177
190
  return null;
178
191
  }
179
- function I(e, t) {
192
+ function V(e, t) {
180
193
  let n = e?.projectId ?? t?.projectId;
181
194
  return n === void 0 || n.length === 0 ? null : {
182
195
  ...t,
@@ -186,13 +199,17 @@ function I(e, t) {
186
199
  data: e?.data ?? t?.data
187
200
  };
188
201
  }
189
- async function L(e = process.cwd(), t) {
190
- let n = I(await F(e), t);
191
- return n ? P(n, e, await w(e, n.apiUrl ?? T)) : null;
202
+ async function H(e = process.cwd(), n) {
203
+ let r = await B(e), i = V(r, n);
204
+ if (!i) {
205
+ if (r && !t(r)) throw Error(`picked.config in ${e} names no project. Add \`projectId\` beside its \`app\` section.`);
206
+ return null;
207
+ }
208
+ return z(i, e, await T(e, i.apiUrl ?? E));
192
209
  }
193
210
  //#endregion
194
211
  //#region src/host-environment.ts
195
- var R = {
212
+ var pe = {
196
213
  VERCEL: "vercel",
197
214
  NETLIFY: "netlify",
198
215
  CF_PAGES: "cloudflare-pages",
@@ -201,9 +218,9 @@ var R = {
201
218
  CIRCLECI: "circleci",
202
219
  BITBUCKET_BUILD_NUMBER: "bitbucket-pipelines"
203
220
  };
204
- function z() {
221
+ function me() {
205
222
  let e = !!process.env.CI;
206
- for (let [e, t] of Object.entries(R)) if (process.env[e]) return {
223
+ for (let [e, t] of Object.entries(pe)) if (process.env[e]) return {
207
224
  provider: t,
208
225
  ci: !0
209
226
  };
@@ -214,37 +231,37 @@ function z() {
214
231
  }
215
232
  //#endregion
216
233
  //#region src/telemetry-config.ts
217
- var B = /* @__PURE__ */ new Set(["1", "true"]), V = /* @__PURE__ */ new Set(["0", "false"]);
218
- function H(e) {
234
+ var he = /* @__PURE__ */ new Set(["1", "true"]), ge = /* @__PURE__ */ new Set(["0", "false"]);
235
+ function U(e) {
219
236
  let t = e?.trim().toLowerCase();
220
237
  if (t !== void 0) {
221
- if (B.has(t)) return !0;
222
- if (V.has(t)) return !1;
238
+ if (he.has(t)) return !0;
239
+ if (ge.has(t)) return !1;
223
240
  }
224
241
  }
225
- function U() {
226
- return H(process.env.PICKED_TELEMETRY) === !1 || H(process.env.DO_NOT_TRACK) === !0;
242
+ function W() {
243
+ return U(process.env.PICKED_TELEMETRY) === !1 || U(process.env.DO_NOT_TRACK) === !0;
227
244
  }
228
- function fe(e, t) {
229
- return U() ? !1 : t === void 0 ? H(process.env.PICKED_TELEMETRY) === !0 || e.telemetry : t;
245
+ function _e(e, t) {
246
+ return W() ? !1 : t === void 0 ? U(process.env.PICKED_TELEMETRY) === !0 || e.telemetry : t;
230
247
  }
231
248
  //#endregion
232
249
  //#region src/snapshot.ts
233
- var W = "picked.snapshot.json", pe = 1, G = "Run `picked pull` to write a fresh one.";
234
- function K(e) {
235
- return s(e, W);
236
- }
250
+ var G = "picked.snapshot.json", ve = 1, K = "Run `picked pull` to write a fresh one.";
237
251
  function q(e) {
252
+ return u(e, G);
253
+ }
254
+ function J(e) {
238
255
  let t = /* @__PURE__ */ new Set();
239
256
  for (let n of e.steps) n.layoutContentId && t.add(n.id);
240
257
  return t.size === 0 ? [] : e.experiences.filter((e) => e.nodes.some((e) => e.type === "step" && t.has(e.stepId))).map((e) => e.id);
241
258
  }
242
- function me(e, t) {
259
+ function ye(e, t) {
243
260
  return e === t ? 0 : e < t ? -1 : 1;
244
261
  }
245
- function J(e) {
262
+ function Y(e) {
246
263
  let t = {};
247
- for (let n of Object.keys(e.experiences).sort(me)) {
264
+ for (let n of Object.keys(e.experiences).sort(ye)) {
248
265
  let r = e.experiences[n];
249
266
  r !== void 0 && (t[n] = r);
250
267
  }
@@ -260,39 +277,39 @@ function J(e) {
260
277
  };
261
278
  return `${JSON.stringify(n, null, 2)}\n`;
262
279
  }
263
- function Y(e) {
280
+ function X(e) {
264
281
  return typeof e == "object" && !!e;
265
282
  }
266
- function he(e) {
267
- return Y(e) && typeof e.id == "string" && Array.isArray(e.features) && Array.isArray(e.experiences) && Array.isArray(e.steps);
283
+ function be(e) {
284
+ return X(e) && typeof e.id == "string" && Array.isArray(e.features) && Array.isArray(e.experiences) && Array.isArray(e.steps);
268
285
  }
269
- function ge(e) {
270
- return Y(e) && Object.values(e).every((e) => Y(e) && typeof e.experienceId == "string" && Array.isArray(e.content));
286
+ function xe(e) {
287
+ return X(e) && Object.values(e).every((e) => X(e) && typeof e.experienceId == "string" && Array.isArray(e.content));
271
288
  }
272
- function _e(e) {
273
- return Y(e) && typeof e.snapshotVersion == "number" && typeof e.projectId == "string" && typeof e.workspaceId == "string" && (typeof e.projectVersionId == "string" || e.projectVersionId === null) && (e.source === "published" || e.source === "preview") && f(e.schema) && he(e.projectConfig) && ge(e.experiences);
289
+ function Se(e) {
290
+ return X(e) && typeof e.snapshotVersion == "number" && typeof e.projectId == "string" && typeof e.workspaceId == "string" && (typeof e.projectVersionId == "string" || e.projectVersionId === null) && (e.source === "published" || e.source === "preview") && ae(e.schema) && be(e.projectConfig) && xe(e.experiences);
274
291
  }
275
- async function X(t) {
276
- let n = K(t);
277
- if (!e(n)) return null;
278
- let r;
292
+ async function Z(e) {
293
+ let t = q(e);
294
+ if (!r(t)) return null;
295
+ let n;
279
296
  try {
280
- r = JSON.parse(await i(n, "utf8"));
297
+ n = JSON.parse(await s(t, "utf8"));
281
298
  } catch {
282
- throw Error(`${n} is not valid JSON. ${G}`);
299
+ throw Error(`${t} is not valid JSON. ${K}`);
283
300
  }
284
- if (Y(r) && typeof r.snapshotVersion == "number" && r.snapshotVersion !== 1) throw Error(`${n} is in snapshot format ${r.snapshotVersion.toString()}, and this SDK reads format 1. ${G}`);
285
- if (!_e(r)) throw Error(`${n} is not a Picked snapshot. ${G}`);
286
- return r;
287
- }
288
- async function ve(e) {
289
- let t = await X(e.projectRoot);
290
- if (!t) throw Error(`picked.config sets \`data: 'snapshot'\`, and there is no ${W} in ${e.projectRoot}. Run \`picked pull\` to write one.`);
291
- if (t.projectId !== e.projectId) throw Error(`${W} holds project "${t.projectId}", and the project in force is "${e.projectId}". ${G}`);
301
+ if (X(n) && typeof n.snapshotVersion == "number" && n.snapshotVersion !== 1) throw Error(`${t} is in snapshot format ${n.snapshotVersion.toString()}, and this SDK reads format 1. ${K}`);
302
+ if (!Se(n)) throw Error(`${t} is not a Picked snapshot. ${K}`);
303
+ return n;
304
+ }
305
+ async function Ce(e) {
306
+ let t = await Z(e.projectRoot);
307
+ if (!t) throw Error(`picked.config sets \`data: 'snapshot'\`, and there is no ${G} in ${e.projectRoot}. Run \`picked pull\` to write one.`);
308
+ if (t.projectId !== e.projectId) throw Error(`${G} holds project "${t.projectId}", and the project in force is "${e.projectId}". ${K}`);
292
309
  return t;
293
310
  }
294
- async function Z(e, t) {
295
- await a(K(e), J(t), "utf8");
311
+ async function we(e, t) {
312
+ await c(q(e), Y(t), "utf8");
296
313
  }
297
314
  async function Q(e, t) {
298
315
  let n = [], r = await t((e) => {
@@ -307,23 +324,23 @@ async function Q(e, t) {
307
324
  function $(e, t, n) {
308
325
  if (e !== null && t !== null && t !== e) throw Error(`The workspace was published while pulling: the project config is at version ${e} and ${n} at ${t}. Run \`picked pull\` again.`);
309
326
  }
310
- async function ye(e) {
327
+ async function Te(e) {
311
328
  let { apiUrl: t, projectId: n, source: r, previewToken: i, headers: a } = e, o = {
312
329
  previewToken: i,
313
330
  headers: a
314
- }, s = await Q(`the workspace schema for "${n}" from ${t}`, (e) => d(t, n, {
331
+ }, s = await Q(`the workspace schema for "${n}" from ${t}`, (e) => ie(t, n, {
315
332
  ...o,
316
333
  onWarn: e
317
- })), c = await Q(`the project config for "${n}" from ${t}`, (e) => te(t, n, {
334
+ })), c = await Q(`the project config for "${n}" from ${t}`, (e) => re(t, n, {
318
335
  ...o,
319
336
  onWarn: e
320
337
  })), l = c.versionId;
321
338
  $(l, s["x-picked-version-id"], "the workspace schema");
322
- let u = await Promise.all(q(c).map(async (e) => [e, await Q(`content for experience "${e}"`, (r) => ee(t, n, e, {
339
+ let u = await Promise.all(J(c).map(async (e) => [e, await Q(`content for experience "${e}"`, (r) => ne(t, n, e, {
323
340
  ...o,
324
341
  onWarn: r
325
- }))])), f = {};
326
- for (let [e, t] of u) $(l, t.versionId, `content for experience "${e}"`), f[e] = t;
342
+ }))])), d = {};
343
+ for (let [e, t] of u) $(l, t.versionId, `content for experience "${e}"`), d[e] = t;
327
344
  return {
328
345
  snapshotVersion: 1,
329
346
  projectId: n,
@@ -332,8 +349,8 @@ async function ye(e) {
332
349
  source: r,
333
350
  schema: s,
334
351
  projectConfig: c,
335
- experiences: f
352
+ experiences: d
336
353
  };
337
354
  }
338
355
  //#endregion
339
- export { W as SNAPSHOT_FILENAME, pe as SNAPSHOT_VERSION, v as appendPickedGitignore, y as assertSecureApiUrl, q as collectCmsExperienceIds, ne as defineConfig, z as detectHostEnvironment, ye as fetchSnapshot, m as hashSchemaJson, fe as isTelemetryEnabled, U as isTelemetryForcedOffByEnvironment, F as loadPickedConfig, L as loadResolvedPickedConfig, b as normalizeApiUrl, w as readActiveSelection, g as readCodegenManifest, X as readSnapshot, ve as requireSnapshot, P as resolvePickedConfig, p as resolvePickedPaths, S as resolveSettingsPath, K as resolveSnapshotPath, J as serializeSnapshot, de as writeActiveSelection, _ as writeCodegenArtifacts, Z as writeSnapshot };
356
+ export { G as SNAPSHOT_FILENAME, ve as SNAPSHOT_VERSION, v as appendPickedGitignore, y as assertSecureApiUrl, J as collectCmsExperienceIds, n as defineConfig, me as detectHostEnvironment, Te as fetchSnapshot, e as hasApp, t as hasProject, _ as hashSchemaJson, _e as isTelemetryEnabled, W as isTelemetryForcedOffByEnvironment, B as loadPickedConfig, H as loadResolvedPickedConfig, b as normalizeApiUrl, T as readActiveSelection, se as readCodegenManifest, Z as readSnapshot, Ce as requireSnapshot, z as resolvePickedConfig, g as resolvePickedPaths, C as resolveSettingsPath, q as resolveSnapshotPath, Y as serializeSnapshot, fe as writeActiveSelection, ce as writeCodegenArtifacts, we as writeSnapshot };
@@ -1,4 +1,5 @@
1
1
  /** @file Configuration types for Picked tooling. */
2
+ import type { AppManifest } from '@picked/app-kit';
2
3
  /** Schema source for codegen — published or live preview. */
3
4
  export type PickedConfigSource = 'published' | 'preview';
4
5
  /**
@@ -7,11 +8,9 @@ export type PickedConfigSource = 'published' | 'preview';
7
8
  * `'snapshot'` embeds the committed `picked.snapshot.json` and fetches nothing.
8
9
  */
9
10
  export type PickedDataMode = 'bundle' | 'api' | 'snapshot';
10
- /** User-facing picked.config shape. */
11
- export interface PickedConfig {
12
- /** Picked project that schema and content are read from. */
13
- projectId: string;
14
- /** Origin of the Picked API to call. Defaults to production. */
11
+ /** The `picked.config` fields a project config and an app config share. */
12
+ interface PickedConfigFields {
13
+ /** Origin of the Picked API to call. Defaults to production; `PICKED_API_URL` overrides it. */
15
14
  apiUrl?: string;
16
15
  /** Path the generated type declarations are written to. */
17
16
  typesOutput?: string;
@@ -36,6 +35,52 @@ export interface PickedConfig {
36
35
  */
37
36
  data?: PickedDataMode;
38
37
  }
38
+ /**
39
+ * A `picked.config` that names a project: the shape `picked generate types`, `picked pull` and
40
+ * the Vite plugin read. It may also hold an `app`.
41
+ */
42
+ export type PickedProjectConfig = PickedConfigFields & {
43
+ /** Picked project that schema and content are read from. */
44
+ projectId: string;
45
+ /**
46
+ * The app manifest `picked app deploy` and `picked app dev` deploy, exactly as Picked receives
47
+ * it and the app serves it at `/manifest.json`. It holds no secrets.
48
+ */
49
+ app?: AppManifest;
50
+ };
51
+ /**
52
+ * A `picked.config` that holds an app: the shape `picked app deploy` and `picked app dev` read.
53
+ * It may also name a project.
54
+ */
55
+ export type PickedAppConfig = PickedConfigFields & {
56
+ /** Picked project that schema and content are read from. */
57
+ projectId?: string;
58
+ /**
59
+ * The app manifest `picked app deploy` and `picked app dev` deploy, exactly as Picked receives
60
+ * it and the app serves it at `/manifest.json`. It holds no secrets.
61
+ */
62
+ app: AppManifest;
63
+ };
64
+ /** User-facing `picked.config` shape: it names a project, holds an app, or both. */
65
+ export type PickedConfig = PickedProjectConfig | PickedAppConfig;
66
+ /**
67
+ * Returns whether a config names a project.
68
+ *
69
+ * @param {PickedConfig} config - A loaded config.
70
+ * @returns {boolean} Whether `config` has a `projectId`.
71
+ * @example
72
+ * if (hasProject(config)) console.log(config.projectId)
73
+ */
74
+ export declare function hasProject(config: PickedConfig): config is PickedProjectConfig;
75
+ /**
76
+ * Returns whether a config holds an app.
77
+ *
78
+ * @param {PickedConfig} config - A loaded config.
79
+ * @returns {boolean} Whether `config` has an `app` manifest.
80
+ * @example
81
+ * if (hasApp(config)) console.log(config.app.handle)
82
+ */
83
+ export declare function hasApp(config: PickedConfig): config is PickedAppConfig;
39
84
  /** Fully resolved configuration with defaults applied. */
40
85
  export interface ResolvedPickedConfig {
41
86
  /** Picked project that schema and content are read from. */
@@ -73,12 +118,14 @@ export interface PickedCodegenManifest {
73
118
  emitFormatVersion?: number;
74
119
  }
75
120
  /**
76
- * Helper for authoring `picked.config.ts` with full type inference.
121
+ * Helper for authoring `picked.config.ts` with full type inference. It returns the config it is
122
+ * given.
77
123
  *
78
- * @param {PickedConfig} config - Consumer configuration object.
124
+ * @param {PickedConfig} config - A project's configuration, an app's, or both in one.
79
125
  * @returns {PickedConfig} The same configuration object.
80
126
  * @example
81
- * export default defineConfig({ projectId: 'abc', typesOutput: './src/picked-env.d.ts' })
127
+ * export default defineConfig({ projectId: 'abc', app: { handle: 'acme', name: 'Acme' } })
82
128
  */
83
129
  export declare function defineConfig(config: PickedConfig): PickedConfig;
130
+ export {};
84
131
  //# sourceMappingURL=config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,oDAAoD;AAEpD,6DAA6D;AAC7D,MAAM,MAAM,kBAAkB,GAAG,WAAW,GAAG,SAAS,CAAA;AAExD;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,KAAK,GAAG,UAAU,CAAA;AAE1D,uCAAuC;AACvC,MAAM,WAAW,YAAY;IAC3B,4DAA4D;IAC5D,SAAS,EAAE,MAAM,CAAA;IACjB,gEAAgE;IAChE,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,2DAA2D;IAC3D,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,sEAAsE;IACtE,MAAM,CAAC,EAAE,kBAAkB,CAAA;IAC3B;;;;;OAKG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB;;;OAGG;IACH,IAAI,CAAC,EAAE,cAAc,CAAA;CACtB;AAED,0DAA0D;AAC1D,MAAM,WAAW,oBAAoB;IACnC,4DAA4D;IAC5D,SAAS,EAAE,MAAM,CAAA;IACjB,wCAAwC;IACxC,MAAM,EAAE,MAAM,CAAA;IACd,oEAAoE;IACpE,WAAW,EAAE,MAAM,CAAA;IACnB,sEAAsE;IACtE,MAAM,EAAE,kBAAkB,CAAA;IAC1B,8EAA8E;IAC9E,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,wFAAwF;IACxF,WAAW,EAAE,MAAM,CAAA;IACnB,6EAA6E;IAC7E,SAAS,EAAE,OAAO,CAAA;IAClB,qFAAqF;IACrF,IAAI,EAAE,cAAc,CAAA;CACrB;AAED,8DAA8D;AAC9D,MAAM,WAAW,qBAAqB;IACpC,oFAAoF;IACpF,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,kFAAkF;IAClF,UAAU,EAAE,MAAM,CAAA;IAClB,6DAA6D;IAC7D,SAAS,EAAE,MAAM,CAAA;IACjB,0CAA0C;IAC1C,SAAS,EAAE,MAAM,CAAA;IACjB,oEAAoE;IACpE,MAAM,EAAE,kBAAkB,CAAA;IAC1B;;OAEG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAA;CAC3B;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,YAAY,GAAG,YAAY,CAE/D"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,oDAAoD;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAElD,6DAA6D;AAC7D,MAAM,MAAM,kBAAkB,GAAG,WAAW,GAAG,SAAS,CAAA;AAExD;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,KAAK,GAAG,UAAU,CAAA;AAE1D,2EAA2E;AAC3E,UAAU,kBAAkB;IAC1B,+FAA+F;IAC/F,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,2DAA2D;IAC3D,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,sEAAsE;IACtE,MAAM,CAAC,EAAE,kBAAkB,CAAA;IAC3B;;;;;OAKG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB;;;OAGG;IACH,IAAI,CAAC,EAAE,cAAc,CAAA;CACtB;AAED;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAAG,kBAAkB,GAAG;IACrD,4DAA4D;IAC5D,SAAS,EAAE,MAAM,CAAA;IACjB;;;OAGG;IACH,GAAG,CAAC,EAAE,WAAW,CAAA;CAClB,CAAA;AAED;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,kBAAkB,GAAG;IACjD,4DAA4D;IAC5D,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;OAGG;IACH,GAAG,EAAE,WAAW,CAAA;CACjB,CAAA;AAED,oFAAoF;AACpF,MAAM,MAAM,YAAY,GAAG,mBAAmB,GAAG,eAAe,CAAA;AAEhE;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,IAAI,mBAAmB,CAE9E;AAED;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,IAAI,eAAe,CAEtE;AAED,0DAA0D;AAC1D,MAAM,WAAW,oBAAoB;IACnC,4DAA4D;IAC5D,SAAS,EAAE,MAAM,CAAA;IACjB,wCAAwC;IACxC,MAAM,EAAE,MAAM,CAAA;IACd,oEAAoE;IACpE,WAAW,EAAE,MAAM,CAAA;IACnB,sEAAsE;IACtE,MAAM,EAAE,kBAAkB,CAAA;IAC1B,8EAA8E;IAC9E,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;IAC3B,wFAAwF;IACxF,WAAW,EAAE,MAAM,CAAA;IACnB,6EAA6E;IAC7E,SAAS,EAAE,OAAO,CAAA;IAClB,qFAAqF;IACrF,IAAI,EAAE,cAAc,CAAA;CACrB;AAED,8DAA8D;AAC9D,MAAM,WAAW,qBAAqB;IACpC,oFAAoF;IACpF,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,kFAAkF;IAClF,UAAU,EAAE,MAAM,CAAA;IAClB,6DAA6D;IAC7D,SAAS,EAAE,MAAM,CAAA;IACjB,0CAA0C;IAC1C,SAAS,EAAE,MAAM,CAAA;IACjB,oEAAoE;IACpE,MAAM,EAAE,kBAAkB,CAAA;IAC1B;;OAEG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAA;CAC3B;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,YAAY,GAAG,YAAY,CAE/D"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @file `@picked/config/define`: `defineConfig`, `hasApp`, `hasProject` and the config types. Nothing
3
+ * it imports reads files or loads a Node built-in.
4
+ */
5
+ export { defineConfig, hasApp, hasProject } from './config';
6
+ export type { PickedAppConfig, PickedConfig, PickedConfigSource, PickedDataMode, PickedProjectConfig, } from './config';
7
+ //# sourceMappingURL=define.d.ts.map