@picked/config 0.0.1-dev.1788925875333 → 0.0.1-dev.1793753513002
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/LICENSE +1 -0
- package/README.md +28 -15
- package/dist/.tsbuildinfo +1 -1
- package/dist/cjs/index.js +3 -3
- package/dist/esm/index.js +197 -73
- package/dist/types/config.d.ts +13 -0
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/index.d.ts +3 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/load-config.d.ts +6 -3
- package/dist/types/load-config.d.ts.map +1 -1
- package/dist/types/snapshot.d.ts +110 -0
- package/dist/types/snapshot.d.ts.map +1 -0
- package/package.json +11 -4
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");function
|
|
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=`
|
|
2
2
|
# Picked codegen intermediates
|
|
3
3
|
.picked/
|
|
4
|
-
`;function
|
|
5
|
-
`,`utf8`)
|
|
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;
|
package/dist/esm/index.js
CHANGED
|
@@ -3,48 +3,45 @@ import { appendFile as t, chmod as n, mkdir as r, readFile as i, writeFile as a
|
|
|
3
3
|
import { dirname as o, join as s, resolve as c } from "node:path";
|
|
4
4
|
import { createJiti as l } from "jiti";
|
|
5
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";
|
|
6
7
|
//#region src/config.ts
|
|
7
|
-
function
|
|
8
|
+
function ne(e) {
|
|
8
9
|
return e;
|
|
9
10
|
}
|
|
10
11
|
//#endregion
|
|
11
12
|
//#region src/manifest.ts
|
|
12
|
-
var
|
|
13
|
-
function
|
|
13
|
+
var re = "manifest.json", ie = "schema.json", ae = "schema-manifest.json", oe = "\n# Picked codegen intermediates\n.picked/\n";
|
|
14
|
+
function p(e) {
|
|
14
15
|
let t = s(e, ".picked");
|
|
15
16
|
return {
|
|
16
17
|
pickedDir: t,
|
|
17
|
-
manifestPath: s(t,
|
|
18
|
-
schemaPath: s(t,
|
|
19
|
-
codegenManifestPath: s(t,
|
|
18
|
+
manifestPath: s(t, re),
|
|
19
|
+
schemaPath: s(t, ie),
|
|
20
|
+
codegenManifestPath: s(t, ae)
|
|
20
21
|
};
|
|
21
22
|
}
|
|
22
|
-
function
|
|
23
|
+
function m(e) {
|
|
23
24
|
return u("sha256").update(e).digest("hex");
|
|
24
25
|
}
|
|
25
|
-
function
|
|
26
|
+
function h(e) {
|
|
26
27
|
return typeof e != "object" || !e ? !1 : "schemaHash" in e && typeof e.schemaHash == "string";
|
|
27
28
|
}
|
|
28
|
-
async function
|
|
29
|
+
async function g(t) {
|
|
29
30
|
if (!e(t)) return null;
|
|
30
31
|
let n = await i(t, "utf8"), r = JSON.parse(n);
|
|
31
|
-
return
|
|
32
|
+
return h(r) ? r : null;
|
|
32
33
|
}
|
|
33
|
-
async function
|
|
34
|
-
let t =
|
|
34
|
+
async function _(e) {
|
|
35
|
+
let t = p(e.projectRoot);
|
|
35
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");
|
|
36
37
|
}
|
|
37
|
-
async function
|
|
38
|
+
async function v(n) {
|
|
38
39
|
let r = s(n, ".gitignore");
|
|
39
|
-
|
|
40
|
-
await a(r, ".picked/\n", "utf8");
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
(await i(r, "utf8")).includes(".picked/") || await t(r, h, "utf8");
|
|
40
|
+
e(r) ? (await i(r, "utf8")).includes(".picked/") || await t(r, oe, "utf8") : await a(r, ".picked/\n", "utf8");
|
|
44
41
|
}
|
|
45
42
|
//#endregion
|
|
46
43
|
//#region src/url-safety.ts
|
|
47
|
-
function
|
|
44
|
+
function y(e) {
|
|
48
45
|
let t;
|
|
49
46
|
try {
|
|
50
47
|
t = new URL(e);
|
|
@@ -55,69 +52,88 @@ function S(e) {
|
|
|
55
52
|
if (t.protocol !== "https:" && !n) throw Error(`Refusing to use a non-HTTPS Picked API URL (${e}); tokens must not be sent over cleartext.`);
|
|
56
53
|
return e;
|
|
57
54
|
}
|
|
58
|
-
function
|
|
59
|
-
return new URL(
|
|
55
|
+
function b(e) {
|
|
56
|
+
return new URL(y(e)).origin;
|
|
60
57
|
}
|
|
61
58
|
//#endregion
|
|
62
59
|
//#region src/settings.ts
|
|
63
|
-
var
|
|
64
|
-
function
|
|
65
|
-
return s(e, ".picked",
|
|
60
|
+
var se = "settings.json", x = 384;
|
|
61
|
+
function S(e) {
|
|
62
|
+
return s(e, ".picked", se);
|
|
66
63
|
}
|
|
67
|
-
function
|
|
64
|
+
function ce(e) {
|
|
68
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");
|
|
69
66
|
}
|
|
70
|
-
function
|
|
71
|
-
return typeof e != "object" || !e || !("projectId" in e) || typeof e.projectId != "string" ? !1 : !("workspace" in e) || e.workspace === void 0 ||
|
|
67
|
+
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);
|
|
72
69
|
}
|
|
73
|
-
function
|
|
74
|
-
return typeof e != "object" || !e ? !1 : Object.values(e).every(
|
|
70
|
+
function ue(e) {
|
|
71
|
+
return typeof e != "object" || !e ? !1 : Object.values(e).every(le);
|
|
75
72
|
}
|
|
76
|
-
async function
|
|
77
|
-
let n =
|
|
73
|
+
async function C(t) {
|
|
74
|
+
let n = S(t);
|
|
78
75
|
if (!e(n)) return {};
|
|
79
76
|
try {
|
|
80
77
|
let e = JSON.parse(await i(n, "utf8"));
|
|
81
|
-
return
|
|
78
|
+
return ue(e) ? e : {};
|
|
82
79
|
} catch {
|
|
83
80
|
return {};
|
|
84
81
|
}
|
|
85
82
|
}
|
|
86
|
-
async function
|
|
87
|
-
return (await
|
|
83
|
+
async function w(e, t) {
|
|
84
|
+
return (await C(e))[b(t)] ?? null;
|
|
88
85
|
}
|
|
89
|
-
async function
|
|
90
|
-
let s =
|
|
91
|
-
...await
|
|
92
|
-
[
|
|
86
|
+
async function de(e, t, i) {
|
|
87
|
+
let s = S(e), c = {
|
|
88
|
+
...await C(e),
|
|
89
|
+
[b(t)]: i
|
|
93
90
|
};
|
|
94
|
-
await r(o(s), { recursive: !0 }), await
|
|
91
|
+
await r(o(s), { recursive: !0 }), await v(e), await a(s, `${JSON.stringify(c, null, 2)}\n`, {
|
|
95
92
|
encoding: "utf8",
|
|
96
|
-
mode:
|
|
97
|
-
}), await n(s,
|
|
93
|
+
mode: x
|
|
94
|
+
}), await n(s, x);
|
|
98
95
|
}
|
|
99
96
|
//#endregion
|
|
100
97
|
//#region src/load-config.ts
|
|
101
|
-
var
|
|
98
|
+
var T = "https://api.picked.app", E = "./src/picked-env.d.ts", D = [
|
|
102
99
|
"picked.config.ts",
|
|
103
100
|
"picked.config.js",
|
|
104
101
|
"picked.config.json"
|
|
105
102
|
];
|
|
106
|
-
function
|
|
103
|
+
function O(e) {
|
|
107
104
|
return typeof e == "object" && !!e;
|
|
108
105
|
}
|
|
109
|
-
function
|
|
110
|
-
return
|
|
106
|
+
function k(e) {
|
|
107
|
+
return O(e) && typeof e.projectId == "string" && e.projectId.length > 0;
|
|
111
108
|
}
|
|
112
|
-
function
|
|
109
|
+
function A(e) {
|
|
113
110
|
return e === "preview" ? "preview" : "published";
|
|
114
111
|
}
|
|
115
|
-
|
|
112
|
+
var j = /* @__PURE__ */ new Set([
|
|
113
|
+
"bundle",
|
|
114
|
+
"api",
|
|
115
|
+
"snapshot"
|
|
116
|
+
]);
|
|
117
|
+
function M(e) {
|
|
118
|
+
return typeof e == "string" && j.has(e);
|
|
119
|
+
}
|
|
120
|
+
function N(e) {
|
|
121
|
+
let t = process.env.PICKED_DATA;
|
|
122
|
+
if (t !== void 0 && t !== "") {
|
|
123
|
+
if (!M(t)) throw Error(`PICKED_DATA is "${t}"; it takes 'bundle', 'api' or 'snapshot'.`);
|
|
124
|
+
return t;
|
|
125
|
+
}
|
|
126
|
+
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'.`);
|
|
128
|
+
return e;
|
|
129
|
+
}
|
|
130
|
+
function P(e, t, n) {
|
|
116
131
|
let r = process.env.PICKED_PREVIEW_TOKEN ?? null, i = process.env.PICKED_PROJECT_ID, a = {
|
|
117
|
-
apiUrl:
|
|
118
|
-
typesOutput: c(t, e.typesOutput ??
|
|
132
|
+
apiUrl: y(e.apiUrl ?? T),
|
|
133
|
+
typesOutput: c(t, e.typesOutput ?? E),
|
|
119
134
|
projectRoot: t,
|
|
120
|
-
telemetry: e.telemetry ?? !1
|
|
135
|
+
telemetry: e.telemetry ?? !1,
|
|
136
|
+
data: N(e.data)
|
|
121
137
|
};
|
|
122
138
|
if (n) {
|
|
123
139
|
let t = i ?? n.projectId;
|
|
@@ -137,7 +153,7 @@ function z(e, t, n) {
|
|
|
137
153
|
previewToken: null
|
|
138
154
|
};
|
|
139
155
|
}
|
|
140
|
-
let o =
|
|
156
|
+
let o = A(e.source), s = o === "preview" ? r ?? e.previewToken ?? null : null;
|
|
141
157
|
return {
|
|
142
158
|
...a,
|
|
143
159
|
projectId: i ?? e.projectId,
|
|
@@ -145,37 +161,38 @@ function z(e, t, n) {
|
|
|
145
161
|
previewToken: s
|
|
146
162
|
};
|
|
147
163
|
}
|
|
148
|
-
async function
|
|
149
|
-
for (let n of
|
|
164
|
+
async function F(t = process.cwd()) {
|
|
165
|
+
for (let n of D) {
|
|
150
166
|
let r = s(t, n);
|
|
151
167
|
if (!e(r)) continue;
|
|
152
168
|
if (n.endsWith(".json")) {
|
|
153
169
|
let e = await i(r, "utf8"), t = JSON.parse(e);
|
|
154
|
-
if (
|
|
170
|
+
if (k(t)) return t;
|
|
155
171
|
throw Error(`Invalid picked.config.json at ${r}`);
|
|
156
172
|
}
|
|
157
|
-
let a = await l(import.meta.url, { interopDefault: !0 }).import(r), o =
|
|
158
|
-
if (
|
|
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;
|
|
159
175
|
throw Error(`Invalid ${n} at ${r}`);
|
|
160
176
|
}
|
|
161
177
|
return null;
|
|
162
178
|
}
|
|
163
|
-
function
|
|
179
|
+
function I(e, t) {
|
|
164
180
|
let n = e?.projectId ?? t?.projectId;
|
|
165
181
|
return n === void 0 || n.length === 0 ? null : {
|
|
166
182
|
...t,
|
|
167
183
|
...e,
|
|
168
184
|
projectId: n,
|
|
169
|
-
apiUrl: e?.apiUrl ?? t?.apiUrl
|
|
185
|
+
apiUrl: e?.apiUrl ?? t?.apiUrl,
|
|
186
|
+
data: e?.data ?? t?.data
|
|
170
187
|
};
|
|
171
188
|
}
|
|
172
|
-
async function
|
|
173
|
-
let n =
|
|
174
|
-
return n ?
|
|
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;
|
|
175
192
|
}
|
|
176
193
|
//#endregion
|
|
177
194
|
//#region src/host-environment.ts
|
|
178
|
-
var
|
|
195
|
+
var R = {
|
|
179
196
|
VERCEL: "vercel",
|
|
180
197
|
NETLIFY: "netlify",
|
|
181
198
|
CF_PAGES: "cloudflare-pages",
|
|
@@ -184,9 +201,9 @@ var U = {
|
|
|
184
201
|
CIRCLECI: "circleci",
|
|
185
202
|
BITBUCKET_BUILD_NUMBER: "bitbucket-pipelines"
|
|
186
203
|
};
|
|
187
|
-
function
|
|
204
|
+
function z() {
|
|
188
205
|
let e = !!process.env.CI;
|
|
189
|
-
for (let [e, t] of Object.entries(
|
|
206
|
+
for (let [e, t] of Object.entries(R)) if (process.env[e]) return {
|
|
190
207
|
provider: t,
|
|
191
208
|
ci: !0
|
|
192
209
|
};
|
|
@@ -197,19 +214,126 @@ function W() {
|
|
|
197
214
|
}
|
|
198
215
|
//#endregion
|
|
199
216
|
//#region src/telemetry-config.ts
|
|
200
|
-
var
|
|
201
|
-
function
|
|
217
|
+
var B = /* @__PURE__ */ new Set(["1", "true"]), V = /* @__PURE__ */ new Set(["0", "false"]);
|
|
218
|
+
function H(e) {
|
|
202
219
|
let t = e?.trim().toLowerCase();
|
|
203
220
|
if (t !== void 0) {
|
|
204
|
-
if (
|
|
205
|
-
if (
|
|
221
|
+
if (B.has(t)) return !0;
|
|
222
|
+
if (V.has(t)) return !1;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
function U() {
|
|
226
|
+
return H(process.env.PICKED_TELEMETRY) === !1 || H(process.env.DO_NOT_TRACK) === !0;
|
|
227
|
+
}
|
|
228
|
+
function fe(e, t) {
|
|
229
|
+
return U() ? !1 : t === void 0 ? H(process.env.PICKED_TELEMETRY) === !0 || e.telemetry : t;
|
|
230
|
+
}
|
|
231
|
+
//#endregion
|
|
232
|
+
//#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
|
+
}
|
|
237
|
+
function q(e) {
|
|
238
|
+
let t = /* @__PURE__ */ new Set();
|
|
239
|
+
for (let n of e.steps) n.layoutContentId && t.add(n.id);
|
|
240
|
+
return t.size === 0 ? [] : e.experiences.filter((e) => e.nodes.some((e) => e.type === "step" && t.has(e.stepId))).map((e) => e.id);
|
|
241
|
+
}
|
|
242
|
+
function me(e, t) {
|
|
243
|
+
return e === t ? 0 : e < t ? -1 : 1;
|
|
244
|
+
}
|
|
245
|
+
function J(e) {
|
|
246
|
+
let t = {};
|
|
247
|
+
for (let n of Object.keys(e.experiences).sort(me)) {
|
|
248
|
+
let r = e.experiences[n];
|
|
249
|
+
r !== void 0 && (t[n] = r);
|
|
206
250
|
}
|
|
251
|
+
let n = {
|
|
252
|
+
snapshotVersion: e.snapshotVersion,
|
|
253
|
+
projectId: e.projectId,
|
|
254
|
+
workspaceId: e.workspaceId,
|
|
255
|
+
projectVersionId: e.projectVersionId,
|
|
256
|
+
source: e.source,
|
|
257
|
+
schema: e.schema,
|
|
258
|
+
projectConfig: e.projectConfig,
|
|
259
|
+
experiences: t
|
|
260
|
+
};
|
|
261
|
+
return `${JSON.stringify(n, null, 2)}\n`;
|
|
262
|
+
}
|
|
263
|
+
function Y(e) {
|
|
264
|
+
return typeof e == "object" && !!e;
|
|
207
265
|
}
|
|
208
|
-
function
|
|
209
|
-
return
|
|
266
|
+
function he(e) {
|
|
267
|
+
return Y(e) && typeof e.id == "string" && Array.isArray(e.features) && Array.isArray(e.experiences) && Array.isArray(e.steps);
|
|
210
268
|
}
|
|
211
|
-
function
|
|
212
|
-
return
|
|
269
|
+
function ge(e) {
|
|
270
|
+
return Y(e) && Object.values(e).every((e) => Y(e) && typeof e.experienceId == "string" && Array.isArray(e.content));
|
|
271
|
+
}
|
|
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);
|
|
274
|
+
}
|
|
275
|
+
async function X(t) {
|
|
276
|
+
let n = K(t);
|
|
277
|
+
if (!e(n)) return null;
|
|
278
|
+
let r;
|
|
279
|
+
try {
|
|
280
|
+
r = JSON.parse(await i(n, "utf8"));
|
|
281
|
+
} catch {
|
|
282
|
+
throw Error(`${n} is not valid JSON. ${G}`);
|
|
283
|
+
}
|
|
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}`);
|
|
292
|
+
return t;
|
|
293
|
+
}
|
|
294
|
+
async function Z(e, t) {
|
|
295
|
+
await a(K(e), J(t), "utf8");
|
|
296
|
+
}
|
|
297
|
+
async function Q(e, t) {
|
|
298
|
+
let n = [], r = await t((e) => {
|
|
299
|
+
n.push(e);
|
|
300
|
+
});
|
|
301
|
+
if (r === null) {
|
|
302
|
+
let t = n.at(-1) ?? "no response";
|
|
303
|
+
throw Error(`Could not fetch ${e}: ${t}`);
|
|
304
|
+
}
|
|
305
|
+
return r;
|
|
306
|
+
}
|
|
307
|
+
function $(e, t, n) {
|
|
308
|
+
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
|
+
}
|
|
310
|
+
async function ye(e) {
|
|
311
|
+
let { apiUrl: t, projectId: n, source: r, previewToken: i, headers: a } = e, o = {
|
|
312
|
+
previewToken: i,
|
|
313
|
+
headers: a
|
|
314
|
+
}, s = await Q(`the workspace schema for "${n}" from ${t}`, (e) => d(t, n, {
|
|
315
|
+
...o,
|
|
316
|
+
onWarn: e
|
|
317
|
+
})), c = await Q(`the project config for "${n}" from ${t}`, (e) => te(t, n, {
|
|
318
|
+
...o,
|
|
319
|
+
onWarn: e
|
|
320
|
+
})), l = c.versionId;
|
|
321
|
+
$(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, {
|
|
323
|
+
...o,
|
|
324
|
+
onWarn: r
|
|
325
|
+
}))])), f = {};
|
|
326
|
+
for (let [e, t] of u) $(l, t.versionId, `content for experience "${e}"`), f[e] = t;
|
|
327
|
+
return {
|
|
328
|
+
snapshotVersion: 1,
|
|
329
|
+
projectId: n,
|
|
330
|
+
workspaceId: c.workspaceId,
|
|
331
|
+
projectVersionId: l,
|
|
332
|
+
source: r,
|
|
333
|
+
schema: s,
|
|
334
|
+
projectConfig: c,
|
|
335
|
+
experiences: f
|
|
336
|
+
};
|
|
213
337
|
}
|
|
214
338
|
//#endregion
|
|
215
|
-
export {
|
|
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 };
|
package/dist/types/config.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
/** @file Configuration types for Picked tooling. */
|
|
2
2
|
/** Schema source for codegen — published or live preview. */
|
|
3
3
|
export type PickedConfigSource = 'published' | 'preview';
|
|
4
|
+
/**
|
|
5
|
+
* Where a build's project config and CMS content come from. `'bundle'` fetches them on every
|
|
6
|
+
* build and embeds them; `'api'` embeds nothing and leaves the SDK to fetch at runtime;
|
|
7
|
+
* `'snapshot'` embeds the committed `picked.snapshot.json` and fetches nothing.
|
|
8
|
+
*/
|
|
9
|
+
export type PickedDataMode = 'bundle' | 'api' | 'snapshot';
|
|
4
10
|
/** User-facing picked.config shape. */
|
|
5
11
|
export interface PickedConfig {
|
|
6
12
|
/** Picked project that schema and content are read from. */
|
|
@@ -24,6 +30,11 @@ export interface PickedConfig {
|
|
|
24
30
|
* `1`/`0` or `true`/`false`.
|
|
25
31
|
*/
|
|
26
32
|
telemetry?: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Where a build's project config and CMS content come from. Defaults to `'bundle'`.
|
|
35
|
+
* Overridden for one run by `PICKED_DATA`.
|
|
36
|
+
*/
|
|
37
|
+
data?: PickedDataMode;
|
|
27
38
|
}
|
|
28
39
|
/** Fully resolved configuration with defaults applied. */
|
|
29
40
|
export interface ResolvedPickedConfig {
|
|
@@ -41,6 +52,8 @@ export interface ResolvedPickedConfig {
|
|
|
41
52
|
projectRoot: string;
|
|
42
53
|
/** The committed telemetry setting, as read through `isTelemetryEnabled`. */
|
|
43
54
|
telemetry: boolean;
|
|
55
|
+
/** Where a build's project config and CMS content come from, after `PICKED_DATA`. */
|
|
56
|
+
data: PickedDataMode;
|
|
44
57
|
}
|
|
45
58
|
/** Manifest written under `.picked/` after a schema fetch. */
|
|
46
59
|
export interface PickedCodegenManifest {
|
|
@@ -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,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;
|
|
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"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** @file Public exports for `\@picked/config`. */
|
|
2
2
|
export { defineConfig } from './config';
|
|
3
|
-
export type { PickedCodegenManifest, PickedConfig, PickedConfigSource, ResolvedPickedConfig, } from './config';
|
|
3
|
+
export type { PickedCodegenManifest, PickedConfig, PickedConfigSource, PickedDataMode, ResolvedPickedConfig, } from './config';
|
|
4
4
|
export { loadPickedConfig, loadResolvedPickedConfig, resolvePickedConfig } from './load-config';
|
|
5
5
|
export { appendPickedGitignore, hashSchemaJson, readCodegenManifest, resolvePickedPaths, writeCodegenArtifacts, } from './manifest';
|
|
6
6
|
export { detectHostEnvironment } from './host-environment';
|
|
@@ -9,4 +9,6 @@ export { isTelemetryEnabled, isTelemetryForcedOffByEnvironment } from './telemet
|
|
|
9
9
|
export { readActiveSelection, resolveSettingsPath, writeActiveSelection } from './settings';
|
|
10
10
|
export type { ActiveSelection, ActiveWorkspaceSelection, WorkspaceStatus } from './settings';
|
|
11
11
|
export { assertSecureApiUrl, normalizeApiUrl } from './url-safety';
|
|
12
|
+
export { SNAPSHOT_FILENAME, SNAPSHOT_VERSION, collectCmsExperienceIds, fetchSnapshot, readSnapshot, requireSnapshot, resolveSnapshotPath, serializeSnapshot, writeSnapshot, } from './snapshot';
|
|
13
|
+
export type { FetchSnapshotOptions, PickedSnapshot } from './snapshot';
|
|
12
14
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AACvC,YAAY,EACV,qBAAqB,EACrB,YAAY,EACZ,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AAC/F,OAAO,EACL,qBAAqB,EACrB,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,qBAAqB,GACtB,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAC1D,YAAY,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACvE,OAAO,EAAE,kBAAkB,EAAE,iCAAiC,EAAE,MAAM,oBAAoB,CAAA;AAC1F,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAC3F,YAAY,EAAE,eAAe,EAAE,wBAAwB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAC5F,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AACvC,YAAY,EACV,qBAAqB,EACrB,YAAY,EACZ,kBAAkB,EAClB,cAAc,EACd,oBAAoB,GACrB,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AAC/F,OAAO,EACL,qBAAqB,EACrB,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,qBAAqB,GACtB,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAC1D,YAAY,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACvE,OAAO,EAAE,kBAAkB,EAAE,iCAAiC,EAAE,MAAM,oBAAoB,CAAA;AAC1F,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAC3F,YAAY,EAAE,eAAe,EAAE,wBAAwB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAC5F,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAClE,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,uBAAuB,EACvB,aAAa,EACb,YAAY,EACZ,eAAe,EACf,mBAAmB,EACnB,iBAAiB,EACjB,aAAa,GACd,MAAM,YAAY,CAAA;AACnB,YAAY,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA"}
|
|
@@ -4,7 +4,8 @@ import type { ActiveSelection } from './settings';
|
|
|
4
4
|
* Resolves a user config with defaults, an optional persisted selection, and env overrides.
|
|
5
5
|
*
|
|
6
6
|
* Precedence: an active selection (`.picked/settings.json`) overrides `projectId`/`source`;
|
|
7
|
-
* `PICKED_PROJECT_ID` / `PICKED_PREVIEW_TOKEN` env vars override on top for
|
|
7
|
+
* `PICKED_PROJECT_ID` / `PICKED_PREVIEW_TOKEN` / `PICKED_DATA` env vars override on top for
|
|
8
|
+
* CI/headless.
|
|
8
9
|
* The preview token resolves env first, then the selected workspace's token, then the
|
|
9
10
|
* config's own `previewToken`, so a committed default stays in force until a developer
|
|
10
11
|
* selects a workspace or a CI run supplies its own.
|
|
@@ -13,6 +14,7 @@ import type { ActiveSelection } from './settings';
|
|
|
13
14
|
* @param {string} projectRoot - Absolute project root directory.
|
|
14
15
|
* @param {ActiveSelection | null} [selection] - Persisted active selection, if any.
|
|
15
16
|
* @returns {ResolvedPickedConfig} Fully resolved configuration.
|
|
17
|
+
* @throws {Error} When `data` or `PICKED_DATA` names no mode, or the API URL is insecure.
|
|
16
18
|
* @example
|
|
17
19
|
* resolvePickedConfig({ projectId: 'p1' }, process.cwd())
|
|
18
20
|
*/
|
|
@@ -30,8 +32,9 @@ export declare function loadPickedConfig(projectRoot?: string): Promise<PickedCo
|
|
|
30
32
|
* Loads and resolves `picked.config` from the project root.
|
|
31
33
|
*
|
|
32
34
|
* `fallback` supplies the fields the config file omits, which lets a caller that already
|
|
33
|
-
* holds project identity — the Vite plugin's deprecated `projectId
|
|
34
|
-
* resolve through the same precedence as everything else, config file
|
|
35
|
+
* holds project identity or a data mode — the Vite plugin's deprecated `projectId`, `apiUrl`
|
|
36
|
+
* and `mode` options — resolve through the same precedence as everything else, config file
|
|
37
|
+
* included.
|
|
35
38
|
*
|
|
36
39
|
* @param {string} [projectRoot] - Directory to search; defaults to `process.cwd()`.
|
|
37
40
|
* @param {Partial<PickedConfig>} [fallback] - Values to use for the fields the file omits.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-config.d.ts","sourceRoot":"","sources":["../../src/load-config.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"load-config.d.ts","sourceRoot":"","sources":["../../src/load-config.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,YAAY,EAGZ,oBAAoB,EACrB,MAAM,UAAU,CAAA;AAEjB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AA0FjD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,YAAY,EACpB,WAAW,EAAE,MAAM,EACnB,SAAS,CAAC,EAAE,eAAe,GAAG,IAAI,GACjC,oBAAoB,CA0BtB;AAED;;;;;;;GAOG;AACH,wBAAsB,gBAAgB,CAAC,WAAW,SAAgB,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CA6BhG;AAiCD;;;;;;;;;;;;;GAaG;AACH,wBAAsB,wBAAwB,CAC5C,WAAW,SAAgB,EAC3B,QAAQ,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,GAC/B,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC,CAQtC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { type ExperienceContentResponse, type ProjectConfig, type WorkspaceSchema } from '@picked/delivery-api-client';
|
|
2
|
+
import type { PickedConfigSource, ResolvedPickedConfig } from './config';
|
|
3
|
+
/** File name of the snapshot, in the directory holding `picked.config`. */
|
|
4
|
+
export declare const SNAPSHOT_FILENAME = "picked.snapshot.json";
|
|
5
|
+
/** Format version written to `snapshotVersion`. A reader refuses any other. */
|
|
6
|
+
export declare const SNAPSHOT_VERSION = 1;
|
|
7
|
+
/** The contents of `picked.snapshot.json`. */
|
|
8
|
+
export interface PickedSnapshot {
|
|
9
|
+
/** Format version; see {@link SNAPSHOT_VERSION}. */
|
|
10
|
+
snapshotVersion: number;
|
|
11
|
+
/** Project the snapshot was pulled from. */
|
|
12
|
+
projectId: string;
|
|
13
|
+
/** Workspace the snapshot was pulled from. */
|
|
14
|
+
workspaceId: string;
|
|
15
|
+
/** Workspace version every payload was served at; `null` for preview data, which has none. */
|
|
16
|
+
projectVersionId: string | null;
|
|
17
|
+
/** Whether the snapshot holds published or preview data. */
|
|
18
|
+
source: PickedConfigSource;
|
|
19
|
+
/** The workspace schema that type generation reads. */
|
|
20
|
+
schema: WorkspaceSchema;
|
|
21
|
+
/** The project config the SDK runs on. */
|
|
22
|
+
projectConfig: ProjectConfig;
|
|
23
|
+
/** Content for every experience whose steps reference CMS content, keyed by experience id. */
|
|
24
|
+
experiences: Record<string, ExperienceContentResponse>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Returns the absolute path of `picked.snapshot.json` in a project root.
|
|
28
|
+
*
|
|
29
|
+
* @param {string} projectRoot - Directory holding `picked.config`.
|
|
30
|
+
* @returns {string} Absolute snapshot path.
|
|
31
|
+
* @example
|
|
32
|
+
* resolveSnapshotPath('/app') // '/app/picked.snapshot.json'
|
|
33
|
+
*/
|
|
34
|
+
export declare function resolveSnapshotPath(projectRoot: string): string;
|
|
35
|
+
/**
|
|
36
|
+
* Returns the ids of experiences whose steps reference CMS content, in config order.
|
|
37
|
+
*
|
|
38
|
+
* @param {ProjectConfig} config - Project config to walk.
|
|
39
|
+
* @returns {string[]} Ids of the CMS-using experiences.
|
|
40
|
+
* @example
|
|
41
|
+
* collectCmsExperienceIds(config) // ['exp-a', 'exp-b']
|
|
42
|
+
*/
|
|
43
|
+
export declare function collectCmsExperienceIds(config: ProjectConfig): string[];
|
|
44
|
+
/**
|
|
45
|
+
* Serialises a snapshot: top-level fields in a fixed order, experiences by id, two-space
|
|
46
|
+
* indentation and a trailing newline. Payloads keep the key order the API served them in, so
|
|
47
|
+
* unchanged data serialises to the same bytes.
|
|
48
|
+
*
|
|
49
|
+
* @param {PickedSnapshot} snapshot - Snapshot to serialise.
|
|
50
|
+
* @returns {string} The file contents.
|
|
51
|
+
* @example
|
|
52
|
+
* await writeFile(path, serializeSnapshot(snapshot))
|
|
53
|
+
*/
|
|
54
|
+
export declare function serializeSnapshot(snapshot: PickedSnapshot): string;
|
|
55
|
+
/**
|
|
56
|
+
* Reads `picked.snapshot.json` from a project root.
|
|
57
|
+
*
|
|
58
|
+
* @param {string} projectRoot - Directory holding `picked.config`.
|
|
59
|
+
* @returns {Promise<PickedSnapshot | null>} The snapshot, or `null` when the file does not exist.
|
|
60
|
+
* @throws {Error} When the file is not JSON, is in another format version, or lacks a field.
|
|
61
|
+
* @example
|
|
62
|
+
* const snapshot = await readSnapshot('/app')
|
|
63
|
+
*/
|
|
64
|
+
export declare function readSnapshot(projectRoot: string): Promise<PickedSnapshot | null>;
|
|
65
|
+
/**
|
|
66
|
+
* Reads the snapshot a `data: 'snapshot'` run builds from, and checks it is for the project in
|
|
67
|
+
* force.
|
|
68
|
+
*
|
|
69
|
+
* @param {Pick<ResolvedPickedConfig, 'projectRoot' | 'projectId'>} config - The resolved config.
|
|
70
|
+
* @returns {Promise<PickedSnapshot>} The snapshot.
|
|
71
|
+
* @throws {Error} When the snapshot is missing, unreadable, or for another project.
|
|
72
|
+
* @example
|
|
73
|
+
* const snapshot = await requireSnapshot(resolvedConfig)
|
|
74
|
+
*/
|
|
75
|
+
export declare function requireSnapshot(config: Pick<ResolvedPickedConfig, 'projectRoot' | 'projectId'>): Promise<PickedSnapshot>;
|
|
76
|
+
/**
|
|
77
|
+
* Writes `picked.snapshot.json` to a project root.
|
|
78
|
+
*
|
|
79
|
+
* @param {string} projectRoot - Directory holding `picked.config`.
|
|
80
|
+
* @param {PickedSnapshot} snapshot - Snapshot to write.
|
|
81
|
+
* @returns {Promise<void>} Resolves once the file is written.
|
|
82
|
+
* @example
|
|
83
|
+
* await writeSnapshot('/app', snapshot)
|
|
84
|
+
*/
|
|
85
|
+
export declare function writeSnapshot(projectRoot: string, snapshot: PickedSnapshot): Promise<void>;
|
|
86
|
+
/** Options for {@link fetchSnapshot}. */
|
|
87
|
+
export interface FetchSnapshotOptions {
|
|
88
|
+
/** Origin of the Picked API. */
|
|
89
|
+
apiUrl: string;
|
|
90
|
+
/** Project to pull. */
|
|
91
|
+
projectId: string;
|
|
92
|
+
/** Whether the pull reads published or preview data. Recorded in the snapshot. */
|
|
93
|
+
source: PickedConfigSource;
|
|
94
|
+
/** Workspace preview token, sent with every request and never written to the snapshot. */
|
|
95
|
+
previewToken?: string;
|
|
96
|
+
/** Headers to send with every request, such as `Picked-Client`. */
|
|
97
|
+
headers?: Record<string, string>;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Fetches a snapshot from the delivery API: the workspace schema, the project config, and the
|
|
101
|
+
* content of every experience whose steps reference CMS content.
|
|
102
|
+
*
|
|
103
|
+
* @param {FetchSnapshotOptions} options - What to pull, and from where.
|
|
104
|
+
* @returns {Promise<PickedSnapshot>} The snapshot.
|
|
105
|
+
* @throws {Error} When a request fails, or the payloads come from different versions.
|
|
106
|
+
* @example
|
|
107
|
+
* const snapshot = await fetchSnapshot({ apiUrl, projectId, source: 'published' })
|
|
108
|
+
*/
|
|
109
|
+
export declare function fetchSnapshot(options: FetchSnapshotOptions): Promise<PickedSnapshot>;
|
|
110
|
+
//# sourceMappingURL=snapshot.d.ts.map
|