@picked/cli 0.0.107-next.2 → 0.0.107-next.4

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.
@@ -2,20 +2,21 @@ import { existsSync as e, readFileSync as t, realpathSync as n } from "node:fs";
2
2
  import { chmod as r, mkdir as i, mkdtemp as a, readFile as o, readdir as s, rename as c, rm as l, rmdir as u, writeFile as d } from "node:fs/promises";
3
3
  import { basename as f, dirname as p, join as m, relative as h, resolve as g, sep as _ } from "node:path";
4
4
  import { generate as ee } from "@picked/typegen";
5
- import { loadPickedConfig as v, loadResolvedPickedConfig as te, normalizeApiUrl as y, readActiveSelection as ne, writeActiveSelection as re } from "@picked/config";
6
- import { createServer as ie } from "node:http";
7
- import { spawn as ae } from "node:child_process";
8
- import { createHash as b, randomBytes as x } from "node:crypto";
9
- import { homedir as oe } from "node:os";
10
- import { AdminApiResponseError as se, AssetCommitDocument as ce, AssetDeleteDocument as le, AssetUploadInitDocument as ue, ProjectLiveVersionDocument as de, WorkspaceExportDocument as fe, WorkspaceImportDocument as pe, WorkspacePublishDocument as me, createAdminApiClient as he, graphql as S } from "@picked/admin-api-client";
11
- import { createInterface as ge } from "node:readline";
5
+ import { SNAPSHOT_FILENAME as v, fetchSnapshot as te, loadPickedConfig as y, loadResolvedPickedConfig as b, normalizeApiUrl as x, readActiveSelection as ne, readSnapshot as re, resolveSnapshotPath as ie, serializeSnapshot as ae, writeActiveSelection as oe, writeSnapshot as se } from "@picked/config";
6
+ import { createServer as ce } from "node:http";
7
+ import { spawn as le } from "node:child_process";
8
+ import { createHash as S, randomBytes as C } from "node:crypto";
9
+ import { homedir as ue } from "node:os";
10
+ import { AdminApiResponseError as de, AssetCommitDocument as fe, AssetDeleteDocument as pe, AssetUploadInitDocument as me, ProjectLiveVersionDocument as he, WorkspaceExportDocument as ge, WorkspaceImportDocument as _e, WorkspacePublishDocument as ve, createAdminApiClient as w, graphql as T } from "@picked/admin-api-client";
11
+ import { isDeepStrictEqual as ye } from "node:util";
12
+ import { createInterface as be } from "node:readline";
12
13
  //#region src/lib/docs.ts
13
- var C = "https://docs.picked.app";
14
- function w(e) {
14
+ var E = "https://docs.picked.app";
15
+ function D(e) {
15
16
  let t = e.trim().replace(/^https?:\/\/[^/]+/, ""), n = t.search(/[#?]/);
16
17
  return `/${((n === -1 ? t : t.slice(0, n)).split("node_modules/picked/docs/").pop() ?? "").replace(/\.mdx?$/, "").replace(/(?:^|\/)index$/, "").split("/").filter((e) => e !== "" && e !== ".").join("/")}`;
17
18
  }
18
- function T(e) {
19
+ function O(e) {
19
20
  let t = /^---\n(?<yaml>[\s\S]*?)\n---\n+/.exec(e);
20
21
  if (!t) return { body: e };
21
22
  let n = t.groups?.yaml && /^type:\s*(?<value>\S+)/m.exec(t.groups.yaml);
@@ -24,27 +25,27 @@ function T(e) {
24
25
  body: e.slice(t[0].length)
25
26
  };
26
27
  }
27
- function _e(e) {
28
+ function xe(e) {
28
29
  let t = e.split(/\n{2,}/).map((e) => e.trim()), n = t.findIndex((e) => e.startsWith("# "));
29
30
  return {
30
31
  title: n === -1 ? void 0 : t[n]?.slice(2).trim(),
31
32
  description: t.slice(n + 1).find((e) => e !== "" && !/^(?:#|:::|```|<|import |export |\||-|\d+\.)/.test(e))?.split("\n").map((e) => e.trim()).join(" ")
32
33
  };
33
34
  }
34
- async function ve(e) {
35
+ async function k(e) {
35
36
  return (await s(e, {
36
37
  recursive: !0,
37
38
  withFileTypes: !0
38
39
  })).filter((e) => e.isFile() && /\.mdx?$/.test(e.name)).map((e) => m(e.parentPath, e.name));
39
40
  }
40
- function ye(e) {
41
- let t = async (t) => (await ve(e)).find((n) => w(h(e, n).split(_).join("/")) === t);
41
+ function Se(e) {
42
+ let t = async (t) => (await k(e)).find((n) => D(h(e, n).split(_).join("/")) === t);
42
43
  return {
43
44
  location: e,
44
45
  list: async () => {
45
- let t = await ve(e);
46
+ let t = await k(e);
46
47
  return (await Promise.all(t.map(async (t) => {
47
- let { type: n, body: r } = T(await o(t, "utf8")), { title: i, description: a } = _e(r), s = w(h(e, t).split(_).join("/"));
48
+ let { type: n, body: r } = O(await o(t, "utf8")), { title: i, description: a } = xe(r), s = D(h(e, t).split(_).join("/"));
48
49
  return {
49
50
  path: s,
50
51
  title: i ?? s,
@@ -55,18 +56,18 @@ function ye(e) {
55
56
  }))).toSorted((e, t) => e.path.localeCompare(t.path));
56
57
  },
57
58
  read: async (e) => {
58
- let n = await t(w(e));
59
- return n ? T(await o(n, "utf8")).body : void 0;
59
+ let n = await t(D(e));
60
+ return n ? O(await o(n, "utf8")).body : void 0;
60
61
  }
61
62
  };
62
63
  }
63
- function be(e) {
64
+ function Ce(e) {
64
65
  return typeof e != "object" || !e || !("pages" in e) || !Array.isArray(e.pages) ? [] : e.pages.filter((e) => typeof e == "object" && !!e && "path" in e && typeof e.path == "string" && "title" in e && typeof e.title == "string" && "body" in e && typeof e.body == "string");
65
66
  }
66
- function xe(e = fetch) {
67
- let t = `${C}/docs-index.json`, n, r = () => (n ??= e(t).then(async (e) => {
67
+ function we(e = fetch) {
68
+ let t = `${E}/docs-index.json`, n, r = () => (n ??= e(t).then(async (e) => {
68
69
  if (!e.ok) throw Error(`Could not fetch ${t}: ${String(e.status)}`);
69
- return be(await e.json());
70
+ return Ce(await e.json());
70
71
  }), n);
71
72
  return {
72
73
  location: t,
@@ -77,12 +78,12 @@ function xe(e = fetch) {
77
78
  ...r && { description: r }
78
79
  })),
79
80
  read: async (e) => {
80
- let t = w(e);
81
+ let t = D(e);
81
82
  return (await r()).find((e) => e.path === t)?.body;
82
83
  }
83
84
  };
84
85
  }
85
- function Se(n) {
86
+ function Te(n) {
86
87
  for (let r = n;; r = p(r)) {
87
88
  let n = m(r, "package.json");
88
89
  if (e(n)) {
@@ -95,12 +96,12 @@ function Se(n) {
95
96
  if (p(r) === r) return;
96
97
  }
97
98
  }
98
- function Ce(t) {
99
+ function Ee(t) {
99
100
  return [
100
101
  t.env.PICKED_DOCS_DIR,
101
102
  (() => {
102
103
  if (!t.bin || !e(t.bin)) return;
103
- let r = Se(p(n(t.bin)));
104
+ let r = Te(p(n(t.bin)));
104
105
  return r?.name === "picked" ? m(r.dir, "docs") : void 0;
105
106
  })(),
106
107
  (() => {
@@ -111,15 +112,15 @@ function Ce(t) {
111
112
  })()
112
113
  ].find((t) => typeof t == "string" && e(t));
113
114
  }
114
- function E(e) {
115
- let t = Ce({
115
+ function A(e) {
116
+ let t = Ee({
116
117
  cwd: e?.cwd ?? process.cwd(),
117
118
  bin: process.argv[1],
118
119
  env: process.env
119
120
  });
120
- return t ? ye(t) : xe();
121
+ return t ? Se(t) : we();
121
122
  }
122
- function we(e, t) {
123
+ function De(e, t) {
123
124
  let n = t.toLowerCase().split(/[\s/-]+/).filter(Boolean);
124
125
  return e.filter((e) => {
125
126
  let t = `${e.path} ${e.title} ${e.description ?? ""}`.toLowerCase();
@@ -128,15 +129,15 @@ function we(e, t) {
128
129
  }
129
130
  //#endregion
130
131
  //#region src/commands/docs.ts
131
- var Te = "Read a page with `picked docs read <path>`.";
132
- async function D(e) {
133
- let t = e.source ?? E(), n = await t.list(), r = e.type ? n.filter((t) => t.type === e.type) : n, i = e.query ? we(r, e.query) : r;
132
+ var Oe = "Read a page with `picked docs read <path>`.";
133
+ async function j(e) {
134
+ let t = e.source ?? A(), n = await t.list(), r = e.type ? n.filter((t) => t.type === e.type) : n, i = e.query ? De(r, e.query) : r;
134
135
  if (i.length === 0) return console.error(`No documentation page matches. Run \`picked docs list\` to see all ${String(n.length)}.`), 1;
135
136
  if (e.json) return console.log(JSON.stringify(i, null, 2)), 0;
136
137
  for (let e of i) console.log(`${e.path}\t${e.title}`);
137
- return console.error(`\n${String(i.length)} ${i.length === 1 ? "page" : "pages"} from ${t.location}. ${Te}`), 0;
138
+ return console.error(`\n${String(i.length)} ${i.length === 1 ? "page" : "pages"} from ${t.location}. ${Oe}`), 0;
138
139
  }
139
- function Ee(e, t) {
140
+ function ke(e, t) {
140
141
  let n = t.toLowerCase().split(/[\s/-]+/).filter(Boolean), r = e.map((e) => {
141
142
  let t = `${e.path} ${e.title}`.toLowerCase();
142
143
  return {
@@ -146,41 +147,41 @@ function Ee(e, t) {
146
147
  }), i = Math.max(0, ...r.map(({ score: e }) => e));
147
148
  return r.filter(({ score: e }) => e > 0 && e === i).slice(0, 5).map(({ page: e }) => e);
148
149
  }
149
- async function O(e) {
150
+ async function M(e) {
150
151
  if (!e.page) return console.error("Usage: picked docs read <path>, for example `picked docs read /how-to/install-the-sdk`."), 1;
151
- let t = e.source ?? E(), n = w(e.page), r = await t.read(n);
152
+ let t = e.source ?? A(), n = D(e.page), r = await t.read(n);
152
153
  if (r === void 0) {
153
- let e = Ee(await t.list(), n).map((e) => ` ${e.path}\t${e.title}`);
154
+ let e = ke(await t.list(), n).map((e) => ` ${e.path}\t${e.title}`);
154
155
  return console.error([
155
156
  `No documentation page at ${n}.`,
156
157
  ...e.length > 0 ? ["Closest pages:", ...e] : [],
157
158
  "Run `picked docs list [words]` to find a page."
158
159
  ].join("\n")), 1;
159
160
  }
160
- return console.log(`<!-- ${C}${n === "/" ? "" : n} -->\n\n${r}`), 0;
161
+ return console.log(`<!-- ${E}${n === "/" ? "" : n} -->\n\n${r}`), 0;
161
162
  }
162
- function k(e) {
163
+ function N(e) {
163
164
  return e === void 0 || e === "list" || e === "ls";
164
165
  }
165
- function De(e) {
166
- return k(e) ? "docs list" : "docs read";
166
+ function Ae(e) {
167
+ return N(e) ? "docs list" : "docs read";
167
168
  }
168
- async function Oe(e) {
169
+ async function je(e) {
169
170
  let [t, ...n] = e.args;
170
- return k(t) ? D({
171
+ return N(t) ? j({
171
172
  query: n.join(" ") || void 0,
172
173
  type: e.type,
173
174
  json: e.json,
174
175
  source: e.source
175
- }) : O({
176
+ }) : M({
176
177
  page: t === "read" ? n[0] : t,
177
178
  source: e.source
178
179
  });
179
180
  }
180
181
  //#endregion
181
182
  //#region src/commands/generate-types.ts
182
- async function A(e) {
183
- let t = e?.cwd ?? process.cwd(), n = await te(t);
183
+ async function P(e) {
184
+ let t = e?.cwd ?? process.cwd(), n = await b(t);
184
185
  if (!n) return console.error("No picked.config.{ts,js,json} found in the current directory."), 1;
185
186
  try {
186
187
  let t = await ee({
@@ -198,7 +199,7 @@ async function A(e) {
198
199
  }
199
200
  //#endregion
200
201
  //#region src/lib/browser.ts
201
- function ke(e) {
202
+ function Me(e) {
202
203
  return process.platform === "darwin" ? {
203
204
  command: "open",
204
205
  args: [e]
@@ -215,10 +216,10 @@ function ke(e) {
215
216
  args: [e]
216
217
  };
217
218
  }
218
- function Ae(e) {
219
- let { command: t, args: n } = ke(e);
219
+ function Ne(e) {
220
+ let { command: t, args: n } = Me(e);
220
221
  try {
221
- let e = ae(t, n, {
222
+ let e = le(t, n, {
222
223
  detached: !0,
223
224
  stdio: "ignore"
224
225
  });
@@ -228,89 +229,89 @@ function Ae(e) {
228
229
  }
229
230
  //#endregion
230
231
  //#region src/lib/paths.ts
231
- var je = 8;
232
- function Me() {
233
- return m(oe(), ".picked");
232
+ var Pe = 8;
233
+ function Fe() {
234
+ return m(ue(), ".picked");
234
235
  }
235
- function Ne(e) {
236
- let t = y(e), { hostname: n, port: r } = new URL(t);
237
- return `${(r ? `${n}-${r}` : n).replace(/[^a-z0-9.-]/gi, "_")}-${b("sha256").update(t).digest("hex").slice(0, je)}`;
236
+ function Ie(e) {
237
+ let t = x(e), { hostname: n, port: r } = new URL(t);
238
+ return `${(r ? `${n}-${r}` : n).replace(/[^a-z0-9.-]/gi, "_")}-${S("sha256").update(t).digest("hex").slice(0, Pe)}`;
238
239
  }
239
- function j(e) {
240
- return m(Me(), "auth", `${Ne(e)}.json`);
240
+ function F(e) {
241
+ return m(Fe(), "auth", `${Ie(e)}.json`);
241
242
  }
242
243
  //#endregion
243
244
  //#region src/auth/token-store.ts
244
- var M = 384;
245
- function Pe(e) {
245
+ var I = 384;
246
+ function Le(e) {
246
247
  return typeof e == "object" && !!e && "clientId" in e && typeof e.clientId == "string" && "redirectUri" in e && typeof e.redirectUri == "string";
247
248
  }
248
- function Fe(e) {
249
+ function Re(e) {
249
250
  return !(typeof e != "object" || !e || !("accessToken" in e) || typeof e.accessToken != "string" || !("refreshToken" in e) || typeof e.refreshToken != "string" || !("expiresAt" in e) || typeof e.expiresAt != "number" || "user" in e && e.user !== void 0 && (typeof e.user != "object" || e.user === null));
250
251
  }
251
- function Ie(e) {
252
- return !(typeof e != "object" || !e || !("apiUrl" in e) || typeof e.apiUrl != "string" || "client" in e && e.client !== void 0 && !Pe(e.client) || "session" in e && e.session !== void 0 && !Fe(e.session));
252
+ function ze(e) {
253
+ return !(typeof e != "object" || !e || !("apiUrl" in e) || typeof e.apiUrl != "string" || "client" in e && e.client !== void 0 && !Le(e.client) || "session" in e && e.session !== void 0 && !Re(e.session));
253
254
  }
254
- async function N(t) {
255
- let n = j(t);
255
+ async function L(t) {
256
+ let n = F(t);
256
257
  if (!e(n)) return null;
257
258
  try {
258
259
  let e = JSON.parse(await o(n, "utf8"));
259
- return Ie(e) ? e : null;
260
+ return ze(e) ? e : null;
260
261
  } catch {
261
262
  return null;
262
263
  }
263
264
  }
264
- async function Le(e) {
265
- let t = j(e.apiUrl);
265
+ async function Be(e) {
266
+ let t = F(e.apiUrl);
266
267
  await i(p(t), { recursive: !0 });
267
268
  let n = `${t}.${process.pid.toString()}.tmp`;
268
269
  await d(n, `${JSON.stringify(e, null, 2)}\n`, {
269
270
  encoding: "utf8",
270
- mode: M
271
- }), await r(n, M), await c(n, t);
271
+ mode: I
272
+ }), await r(n, I), await c(n, t);
272
273
  }
273
- async function P(e, t) {
274
- let n = await N(e);
275
- await Le({
276
- apiUrl: y(e),
274
+ async function R(e, t) {
275
+ let n = await L(e);
276
+ await Be({
277
+ apiUrl: x(e),
277
278
  client: n?.client,
278
279
  session: n?.session,
279
280
  ...t
280
281
  });
281
282
  }
282
- async function Re(e, t) {
283
- await P(e, { client: t });
283
+ async function Ve(e, t) {
284
+ await R(e, { client: t });
284
285
  }
285
- async function F(e, t) {
286
- await P(e, { session: t });
286
+ async function He(e, t) {
287
+ await R(e, { session: t });
287
288
  }
288
- async function ze(e) {
289
- await l(j(e), { force: !0 });
289
+ async function Ue(e) {
290
+ await l(F(e), { force: !0 });
290
291
  }
291
292
  //#endregion
292
293
  //#region src/auth/pkce.ts
293
- var Be = 32, Ve = 16;
294
- function I(e) {
294
+ var We = 32, Ge = 16;
295
+ function z(e) {
295
296
  return e.toString("base64").replaceAll("+", "-").replaceAll("/", "_").replaceAll("=", "");
296
297
  }
297
- function He() {
298
- return I(x(Be));
298
+ function Ke() {
299
+ return z(C(We));
299
300
  }
300
- function Ue(e) {
301
- return I(b("sha256").update(e).digest());
301
+ function qe(e) {
302
+ return z(S("sha256").update(e).digest());
302
303
  }
303
- function We() {
304
- return I(x(Ve));
304
+ function Je() {
305
+ return z(C(Ge));
305
306
  }
306
307
  //#endregion
307
308
  //#region src/auth/oauth.ts
308
- var L = [
309
+ var B = [
309
310
  8976,
310
311
  8977,
311
312
  8988
312
- ], Ge = 18e4, Ke = "openid profile email";
313
- async function R(e) {
313
+ ], Ye = 18e4, Xe = "openid profile email";
314
+ async function V(e) {
314
315
  let t;
315
316
  try {
316
317
  t = await fetch(`${e}/.well-known/oauth-authorization-server`);
@@ -331,7 +332,7 @@ async function R(e) {
331
332
  codeChallengeMethods: i
332
333
  };
333
334
  }
334
- async function qe(e, t, n) {
335
+ async function Ze(e, t, n) {
335
336
  if (!t.registrationEndpoint) throw Error("OAuth client registration is not available for this Picked API.");
336
337
  let r = await fetch(t.registrationEndpoint, {
337
338
  method: "POST",
@@ -347,16 +348,16 @@ async function qe(e, t, n) {
347
348
  if (!r.ok) throw Error(`OAuth client registration failed (${r.status.toString()}).`);
348
349
  let i = await r.json();
349
350
  if (typeof i != "object" || !i || !("client_id" in i) || typeof i.client_id != "string") throw Error("OAuth client registration returned an unexpected response.");
350
- return await Re(e, {
351
+ return await Ve(e, {
351
352
  clientId: i.client_id,
352
353
  redirectUri: n
353
354
  }), i.client_id;
354
355
  }
355
- async function Je(e, t, n) {
356
- let r = (await N(e))?.client;
357
- return r?.redirectUri === n ? r.clientId : qe(e, t, n);
356
+ async function Qe(e, t, n) {
357
+ let r = (await L(e))?.client;
358
+ return r?.redirectUri === n ? r.clientId : Ze(e, t, n);
358
359
  }
359
- function Ye(e, t) {
360
+ function $e(e, t) {
360
361
  return new Promise((n) => {
361
362
  let r = () => {
362
363
  e.removeListener("error", r), n(!1);
@@ -366,11 +367,11 @@ function Ye(e, t) {
366
367
  });
367
368
  });
368
369
  }
369
- async function Xe(e) {
370
- for (let t of L) if (await Ye(e, t)) return t;
371
- throw Error(`No loopback port available for the OAuth callback (tried ${L.join(", ")}).`);
370
+ async function et(e) {
371
+ for (let t of B) if (await $e(e, t)) return t;
372
+ throw Error(`No loopback port available for the OAuth callback (tried ${B.join(", ")}).`);
372
373
  }
373
- function Ze(e, t, n) {
374
+ function tt(e, t, n) {
374
375
  return new Promise((r, i) => {
375
376
  let a = () => {
376
377
  clearTimeout(o), process.removeListener("SIGINT", s), e.close();
@@ -391,15 +392,11 @@ function Ze(e, t, n) {
391
392
  return;
392
393
  }
393
394
  let c = o.searchParams.get("code"), l = o.searchParams.get("state");
394
- if (!c || l !== t) {
395
- n.writeHead(400, { "content-type": "text/html" }), n.end("<html><body>Invalid sign-in response. Close this tab and try again.</body></html>"), a(), i(/* @__PURE__ */ Error("Invalid OAuth callback: missing code or state mismatch."));
396
- return;
397
- }
398
- n.writeHead(200, { "content-type": "text/html" }), n.end("<html><body>Signed in. You can close this tab and return to the terminal.</body></html>"), a(), r({ code: c });
395
+ !c || l !== t ? (n.writeHead(400, { "content-type": "text/html" }), n.end("<html><body>Invalid sign-in response. Close this tab and try again.</body></html>"), a(), i(/* @__PURE__ */ Error("Invalid OAuth callback: missing code or state mismatch."))) : (n.writeHead(200, { "content-type": "text/html" }), n.end("<html><body>Signed in. You can close this tab and return to the terminal.</body></html>"), a(), r({ code: c }));
399
396
  });
400
397
  });
401
398
  }
402
- async function z(e) {
399
+ async function H(e) {
403
400
  let t;
404
401
  try {
405
402
  t = await e.json();
@@ -414,7 +411,7 @@ async function z(e) {
414
411
  expiresIn: t.expires_in
415
412
  };
416
413
  }
417
- function Qe(e) {
414
+ function nt(e) {
418
415
  let t = e.split("."), n = t[1];
419
416
  if (t.length !== 3 || !n) return {};
420
417
  try {
@@ -427,10 +424,10 @@ function Qe(e) {
427
424
  return {};
428
425
  }
429
426
  }
430
- async function $e(e) {
431
- let t = await R(e), n = ie(), r = `http://127.0.0.1:${(await Xe(n)).toString()}/callback`, i = await Je(e, t, r), a = He(), o = Ue(a), s = We(), c = new URL(t.authorizationEndpoint);
432
- c.searchParams.set("response_type", "code"), c.searchParams.set("client_id", i), c.searchParams.set("redirect_uri", r), c.searchParams.set("code_challenge", o), c.searchParams.set("code_challenge_method", "S256"), c.searchParams.set("state", s), c.searchParams.set("scope", Ke), console.log(`Opening your browser to sign in...\n${c.toString()}`), await Ae(c.toString());
433
- let { code: l } = await Ze(n, s, Ge), u = new URLSearchParams({
427
+ async function rt(e) {
428
+ let t = await V(e), n = ce(), r = `http://127.0.0.1:${(await et(n)).toString()}/callback`, i = await Qe(e, t, r), a = Ke(), o = qe(a), s = Je(), c = new URL(t.authorizationEndpoint);
429
+ c.searchParams.set("response_type", "code"), c.searchParams.set("client_id", i), c.searchParams.set("redirect_uri", r), c.searchParams.set("code_challenge", o), c.searchParams.set("code_challenge_method", "S256"), c.searchParams.set("state", s), c.searchParams.set("scope", Xe), console.log(`Opening your browser to sign in...\n${c.toString()}`), await Ne(c.toString());
430
+ let { code: l } = await tt(n, s, Ye), u = new URLSearchParams({
434
431
  grant_type: "authorization_code",
435
432
  code: l,
436
433
  redirect_uri: r,
@@ -442,18 +439,18 @@ async function $e(e) {
442
439
  body: u.toString()
443
440
  });
444
441
  if (!d.ok) throw Error(`Token exchange failed (${d.status.toString()}).`);
445
- let f = await z(d);
442
+ let f = await H(d);
446
443
  if (!f?.refreshToken) throw Error("Token exchange did not return a refresh token.");
447
444
  return {
448
445
  accessToken: f.accessToken,
449
446
  refreshToken: f.refreshToken,
450
447
  expiresAt: Date.now() + f.expiresIn * 1e3,
451
- user: Qe(f.accessToken)
448
+ user: nt(f.accessToken)
452
449
  };
453
450
  }
454
- async function et(e) {
451
+ async function it(e) {
455
452
  if (!e.client || !e.session) throw Error("Session expired. Run `picked login`.");
456
- let t = await R(e.apiUrl), n = new URLSearchParams({
453
+ let t = await V(e.apiUrl), n = new URLSearchParams({
457
454
  grant_type: "refresh_token",
458
455
  refresh_token: e.session.refreshToken,
459
456
  client_id: e.client.clientId
@@ -468,7 +465,7 @@ async function et(e) {
468
465
  throw Error("Session expired. Run `picked login`.");
469
466
  }
470
467
  if (!r.ok) throw Error("Session expired. Run `picked login`.");
471
- let i = await z(r);
468
+ let i = await H(r);
472
469
  if (!i) throw Error("Session expired. Run `picked login`.");
473
470
  return {
474
471
  accessToken: i.accessToken,
@@ -479,47 +476,47 @@ async function et(e) {
479
476
  }
480
477
  //#endregion
481
478
  //#region src/auth/session.ts
482
- var tt = 6e4;
483
- async function B(e) {
484
- let t = await N(e);
479
+ var at = 6e4;
480
+ async function U(e) {
481
+ let t = await L(e);
485
482
  if (!t?.session) throw Error(`Not logged in to ${e}. Run \`picked login\`.`);
486
- if (t.session.expiresAt - Date.now() > tt) return t.session.accessToken;
487
- let n = await et(t);
488
- return await F(e, n), n.accessToken;
483
+ if (t.session.expiresAt - Date.now() > at) return t.session.accessToken;
484
+ let n = await it(t);
485
+ return await He(e, n), n.accessToken;
489
486
  }
490
487
  //#endregion
491
488
  //#region src/lib/admin-client.ts
492
- function V() {
489
+ function W() {
493
490
  let e = process.env.PICKED_API_KEY?.trim();
494
491
  return e === "" ? void 0 : e;
495
492
  }
496
- async function H(e) {
497
- let t = V();
498
- return t ? he({
493
+ async function G(e) {
494
+ let t = W();
495
+ return t ? w({
499
496
  apiUrl: e,
500
497
  apiKey: t
501
- }) : (await B(e), he({
498
+ }) : (await U(e), w({
502
499
  apiUrl: e,
503
- token: () => B(e)
500
+ token: () => U(e)
504
501
  }));
505
502
  }
506
503
  //#endregion
507
504
  //#region src/lib/api-url.ts
508
- var nt = "https://api.picked.app";
509
- async function U(e = process.cwd()) {
505
+ var ot = "https://api.picked.app";
506
+ async function K(e = process.cwd()) {
510
507
  let t = process.env.PICKED_API_URL;
511
- if (t) return y(t);
512
- let n = await v(e);
513
- return y(n?.apiUrl ?? nt);
508
+ if (t) return x(t);
509
+ let n = await y(e);
510
+ return x(n?.apiUrl ?? ot);
514
511
  }
515
512
  //#endregion
516
513
  //#region src/commands/login.ts
517
- async function rt(e) {
518
- let t = await U(e?.cwd);
519
- if (V()) return console.error(`\`picked login\` does not apply while PICKED_API_KEY is set: every command authenticates to ${t} with that API key. Unset PICKED_API_KEY to sign in as a user.`), 1;
514
+ async function st(e) {
515
+ let t = await K(e?.cwd);
516
+ if (W()) return console.error(`\`picked login\` does not apply while PICKED_API_KEY is set: every command authenticates to ${t} with that API key. Unset PICKED_API_KEY to sign in as a user.`), 1;
520
517
  try {
521
- let e = await $e(t);
522
- await F(t, e);
518
+ let e = await rt(t);
519
+ await He(t, e);
523
520
  let n = e.user?.email ?? e.user?.id ?? "unknown user";
524
521
  return console.log(`Logged in as ${n} (${t})`), 0;
525
522
  } catch (e) {
@@ -529,16 +526,54 @@ async function rt(e) {
529
526
  }
530
527
  //#endregion
531
528
  //#region src/commands/logout.ts
532
- async function it(e) {
533
- let t = await U(e?.cwd);
534
- return await ze(t), console.log(`Logged out of ${t}.`), 0;
529
+ async function ct(e) {
530
+ let t = await K(e?.cwd);
531
+ return await Ue(t), console.log(`Logged out of ${t}.`), 0;
532
+ }
533
+ //#endregion
534
+ //#region src/commands/pull.ts
535
+ function q(e) {
536
+ return e ? e.projectVersionId ?? "preview" : "none";
537
+ }
538
+ async function lt(e) {
539
+ try {
540
+ return await re(e);
541
+ } catch {
542
+ return null;
543
+ }
544
+ }
545
+ async function ut(t, n) {
546
+ let r = ie(t);
547
+ if (!e(r)) return console.error(`There is no ${v} to check. Run \`picked pull\` to write one.`), 1;
548
+ let i = await lt(t), a = JSON.parse(ae(n));
549
+ return ye(i, a) ? (console.log(`${v} is up to date (version ${q(n)}).`), 0) : (console.error(`${v} is out of date: it holds version ${q(i)}, and live is version ${q(n)}. Run \`picked pull\` to refresh it.`), 1);
550
+ }
551
+ async function dt(e) {
552
+ let t = await b(e?.cwd ?? process.cwd());
553
+ if (!t) return console.error("No picked.config.{ts,js,json} found in the current directory."), 1;
554
+ if (t.source === "preview" && e?.allowPreview !== !0) return console.error(`The source in force is preview, so ${v} would commit unpublished content. Select the live workspace with \`picked workspace use\`, or pass --allow-preview to pull it anyway.`), 1;
555
+ let n;
556
+ try {
557
+ n = await te({
558
+ apiUrl: t.apiUrl,
559
+ projectId: t.projectId,
560
+ source: t.source,
561
+ previewToken: t.previewToken ?? void 0
562
+ });
563
+ } catch (e) {
564
+ return console.error(e instanceof Error ? e.message : String(e)), 1;
565
+ }
566
+ if (e?.check === !0) return ut(t.projectRoot, n);
567
+ await se(t.projectRoot, n);
568
+ let r = Object.keys(n.experiences).length;
569
+ return console.log(`Wrote ${v}: project ${n.projectId}, version ${q(n)}, ${r.toString()} experience${r === 1 ? "" : "s"} with content.`), t.data !== "snapshot" && console.log(`The data mode in force is '${t.data}', so builds do not read it yet. Set \`data: 'snapshot'\` in picked.config to build from it.`), 0;
535
570
  }
536
571
  //#endregion
537
572
  //#region src/commands/status.ts
538
- async function at(e) {
539
- let t = e?.cwd ?? process.cwd(), n = await v(t);
573
+ async function ft(e) {
574
+ let t = e?.cwd ?? process.cwd(), n = await y(t);
540
575
  if (!n) return console.error("No picked.config.{ts,js,json} found in the current directory."), 1;
541
- let r = await U(t);
576
+ let r = await K(t);
542
577
  console.log(`API: ${r}`), console.log(`Config default: project ${n.projectId} (source: ${n.source ?? "published"})`);
543
578
  let i = await ne(t, r);
544
579
  if (!i) return console.log("Active selection: none (using the config default)."), 0;
@@ -548,34 +583,34 @@ async function at(e) {
548
583
  }
549
584
  //#endregion
550
585
  //#region src/commands/whoami.ts
551
- async function ot(e) {
552
- let t = await U(e?.cwd);
553
- if (V()) return console.error(`\`picked whoami\` does not apply while PICKED_API_KEY is set: an API key authenticates to ${t} as a project or organization, not as a user.`), 1;
554
- let n = await N(t);
586
+ async function pt(e) {
587
+ let t = await K(e?.cwd);
588
+ if (W()) return console.error(`\`picked whoami\` does not apply while PICKED_API_KEY is set: an API key authenticates to ${t} as a project or organization, not as a user.`), 1;
589
+ let n = await L(t);
555
590
  if (!n?.session) return console.error(`Not logged in to ${t}. Run \`picked login\`.`), 1;
556
591
  let { user: r } = n.session, i = r?.email ?? r?.id ?? "unknown user";
557
592
  return console.log(`${i} (${t})`), 0;
558
593
  }
559
594
  //#endregion
560
595
  //#region src/lib/bundle.ts
561
- var W = "bundle.json", G = "assets", st = /^[0-9a-f]{64}$/;
562
- function K(e, t, n) {
596
+ var J = "bundle.json", Y = "assets", mt = /^[0-9a-f]{64}$/;
597
+ function X(e, t, n) {
563
598
  let r = g(e), i = g(r, t);
564
599
  if (!i.startsWith(r.endsWith(_) ? r : r + _)) throw Error(`${n} ${t} must name a directory inside ${r}.`);
565
600
  return i;
566
601
  }
567
- function q(e) {
602
+ function Z(e) {
568
603
  return typeof e == "object" && !!e && !Array.isArray(e);
569
604
  }
570
- function ct(e) {
571
- return b("sha256").update(e).digest("hex");
605
+ function ht(e) {
606
+ return S("sha256").update(e).digest("hex");
572
607
  }
573
- function J(e, t) {
574
- return m(e, G, t);
608
+ function gt(e, t) {
609
+ return m(e, Y, t);
575
610
  }
576
- function lt(e, t) {
611
+ function _t(e, t) {
577
612
  let n = `bundle assets[${String(t)}]`;
578
- if (!q(e)) throw Error(`${n} is not an object.`);
613
+ if (!Z(e)) throw Error(`${n} is not an object.`);
579
614
  let { versionId: r, fileName: i, mimeType: a, sizeBytes: o, sha256: s, downloadUrl: c } = e;
580
615
  if (typeof r != "string" || typeof i != "string" || typeof a != "string" || typeof c != "string" || typeof o != "number" || !Number.isInteger(o) || o < 0) throw Error(`${n} needs a string versionId, fileName, mimeType and downloadUrl, and an integer sizeBytes.`);
581
616
  if (s === null) return {
@@ -587,7 +622,7 @@ function lt(e, t) {
587
622
  downloadUrl: c
588
623
  };
589
624
  let l = typeof s == "string" ? s.toLowerCase() : "";
590
- if (!st.test(l)) throw Error(`${n} (${i}) has a sha256 that is not a hex SHA-256 digest.`);
625
+ if (!mt.test(l)) throw Error(`${n} (${i}) has a sha256 that is not a hex SHA-256 digest.`);
591
626
  return {
592
627
  versionId: r,
593
628
  fileName: i,
@@ -597,22 +632,22 @@ function lt(e, t) {
597
632
  downloadUrl: c
598
633
  };
599
634
  }
600
- function Y(e) {
635
+ function vt(e) {
601
636
  let { assets: t } = e;
602
637
  if (!Array.isArray(t)) throw Error("The bundle has no assets array.");
603
- return t.map((e, t) => lt(e, t));
638
+ return t.map((e, t) => _t(e, t));
604
639
  }
605
- function X(e, t, n) {
640
+ function yt(e, t, n) {
606
641
  if (t.byteLength !== e.sizeBytes) throw Error(`${e.fileName} (${n}) has size ${String(t.byteLength)} bytes; the manifest says ${String(e.sizeBytes)}.`);
607
- let r = ct(t);
642
+ let r = ht(t);
608
643
  if (e.sha256 !== null && r !== e.sha256) throw Error(`${e.fileName} (${n}) has SHA-256 ${r}; the manifest says ${e.sha256}.`);
609
644
  return r;
610
645
  }
611
- function ut(e, t) {
646
+ function bt(e, t) {
612
647
  let n = Array.isArray(e.assets) ? e.assets : [];
613
648
  return {
614
649
  ...e,
615
- assets: n.map((e, n) => q(e) ? {
650
+ assets: n.map((e, n) => Z(e) ? {
616
651
  ...e,
617
652
  sha256: t[n]
618
653
  } : e)
@@ -620,30 +655,30 @@ function ut(e, t) {
620
655
  }
621
656
  //#endregion
622
657
  //#region src/lib/workspace-transfer.ts
623
- var dt = 12e4, ft = 3e5, Z = class extends Error {
658
+ var xt = 12e4, St = 3e5, Ct = class extends Error {
624
659
  name = "PayloadUserErrorsError";
625
660
  };
626
661
  function Q(e, t) {
627
- if (t.length !== 0) throw new Z(`${e} failed:\n${t.map((e) => {
662
+ if (t.length !== 0) throw new Ct(`${e} failed:\n${t.map((e) => {
628
663
  let t = e.field?.length ? ` (${e.field.join(".")})` : "";
629
664
  return ` ${e.code}: ${e.message}${t}`;
630
665
  }).join("\n")}`);
631
666
  }
632
- async function pt(e, t) {
633
- let { project: n } = await e.request(de, { input: { id: t } });
667
+ async function wt(e, t) {
668
+ let { project: n } = await e.request(he, { input: { id: t } });
634
669
  if (!n) throw Error(`Project ${t} was not found.`);
635
670
  let r = n.liveWorkspaceVersion;
636
671
  if (!r) throw Error(`Project ${t} has no published version.`);
637
672
  if (!r.snapshotWorkspaceId) throw Error(`The live version ${r.id} of project ${t} has no snapshot workspace to export. Publish the project again.`);
638
673
  return r.snapshotWorkspaceId;
639
674
  }
640
- async function mt(e, t) {
641
- let { workspaceExport: n } = await e.request(fe, { input: { workspaceId: t } });
642
- if (Q(`Export of workspace ${t}`, n.userErrors), !q(n.bundle)) throw Error(`Export of workspace ${t} returned no bundle.`);
675
+ async function Tt(e, t) {
676
+ let { workspaceExport: n } = await e.request(ge, { input: { workspaceId: t } });
677
+ if (Q(`Export of workspace ${t}`, n.userErrors), !Z(n.bundle)) throw Error(`Export of workspace ${t} returned no bundle.`);
643
678
  return n.bundle;
644
679
  }
645
- async function ht(e, t) {
646
- let { projectId: n, fileName: r, mimeType: i, sha256: a, bytes: o } = t, { assetUploadInit: s } = await e.request(ue, { input: {
680
+ async function Et(e, t) {
681
+ let { projectId: n, fileName: r, mimeType: i, sha256: a, bytes: o } = t, { assetUploadInit: s } = await e.request(me, { input: {
647
682
  projectId: n,
648
683
  fileName: r,
649
684
  contentType: i,
@@ -659,10 +694,10 @@ async function ht(e, t) {
659
694
  method: "PUT",
660
695
  headers: { "Content-Type": i },
661
696
  body: o,
662
- signal: AbortSignal.timeout(dt)
697
+ signal: AbortSignal.timeout(xt)
663
698
  });
664
699
  if (!c.ok) throw Error(`Upload of ${r} failed with status ${String(c.status)}: ${await c.text()}`);
665
- let { assetCommit: l } = await e.request(ce, { input: {
700
+ let { assetCommit: l } = await e.request(fe, { input: {
666
701
  projectId: n,
667
702
  assetId: s.assetId,
668
703
  versionId: s.versionId,
@@ -676,22 +711,22 @@ async function ht(e, t) {
676
711
  deduplicated: !1
677
712
  };
678
713
  }
679
- async function gt(e, t) {
680
- await e.request(le, { input: { id: t } });
714
+ async function Dt(e, t) {
715
+ await e.request(pe, { input: { id: t } });
681
716
  }
682
- async function _t(e, t) {
683
- let { workspaceImport: n } = await e.request(pe, { input: t }, { timeoutMs: ft });
717
+ async function Ot(e, t) {
718
+ let { workspaceImport: n } = await e.request(_e, { input: t }, { timeoutMs: St });
684
719
  if (Q(`Import into project ${t.projectId}`, n.userErrors), !n.workspace) throw Error(`Import into project ${t.projectId} returned no workspace.`);
685
720
  return n.workspace;
686
721
  }
687
- async function vt(e, t) {
688
- let { workspacePublish: n } = await e.request(me, { input: { workspaceId: t } });
722
+ async function kt(e, t) {
723
+ let { workspacePublish: n } = await e.request(ve, { input: { workspaceId: t } });
689
724
  Q(`Publish of workspace ${t}`, n.userErrors);
690
725
  }
691
726
  //#endregion
692
727
  //#region src/commands/workspace-export.ts
693
- var yt = 12e4;
694
- function bt(e, t) {
728
+ var At = 12e4;
729
+ function jt(e, t) {
695
730
  if (!e.project) throw Error("Missing --project <id>.");
696
731
  if (e.workspace && e.live) throw Error("Pass --workspace <id> or --live, not both.");
697
732
  if (!e.workspace && !e.live) throw Error("Pass --workspace <id> or --live.");
@@ -699,40 +734,40 @@ function bt(e, t) {
699
734
  return {
700
735
  projectId: e.project,
701
736
  workspaceId: e.workspace ?? null,
702
- outDir: K(t, e.out, "--out")
737
+ outDir: X(t, e.out, "--out")
703
738
  };
704
739
  }
705
- async function xt(e) {
740
+ async function Mt(e) {
706
741
  if ((await s(e).catch((e) => {
707
- if (q(e) && e.code === "ENOENT") return [];
742
+ if (Z(e) && e.code === "ENOENT") return [];
708
743
  throw e;
709
744
  })).length > 0) throw Error(`${e} is not empty. Export into a new or empty directory.`);
710
745
  }
711
- async function St(e) {
712
- let t = await fetch(e.downloadUrl, { signal: AbortSignal.timeout(yt) });
746
+ async function Nt(e) {
747
+ let t = await fetch(e.downloadUrl, { signal: AbortSignal.timeout(At) });
713
748
  if (!t.ok) throw Error(`Download of ${e.fileName} from ${e.downloadUrl} failed with status ${String(t.status)}.`);
714
749
  let n = new Uint8Array(await t.arrayBuffer());
715
750
  return {
716
751
  bytes: n,
717
- sha256: X(e, n, e.downloadUrl)
752
+ sha256: yt(e, n, e.downloadUrl)
718
753
  };
719
754
  }
720
- async function Ct(e, t, n) {
721
- await i(m(e, G));
755
+ async function Pt(e, t, n) {
756
+ await i(m(e, Y));
722
757
  let r = [];
723
758
  for (let t of n) {
724
- let { bytes: n, sha256: i } = await St(t);
725
- await d(J(e, i), n), r.push(i);
759
+ let { bytes: n, sha256: i } = await Nt(t);
760
+ await d(gt(e, i), n), r.push(i);
726
761
  }
727
- let a = ut(t, r);
728
- await d(m(e, W), `${JSON.stringify(a, null, 2)}\n`);
762
+ let a = bt(t, r);
763
+ await d(m(e, J), `${JSON.stringify(a, null, 2)}\n`);
729
764
  }
730
- async function wt(e, t, n) {
765
+ async function Ft(e, t, n) {
731
766
  await i(p(e), { recursive: !0 });
732
767
  let r = await a(m(p(e), `.${f(e)}.partial-`));
733
768
  try {
734
- await Ct(r, t, n), await u(e).catch((e) => {
735
- if (!(q(e) && e.code === "ENOENT")) throw e;
769
+ await Pt(r, t, n), await u(e).catch((e) => {
770
+ if (!(Z(e) && e.code === "ENOENT")) throw e;
736
771
  }), await c(r, e);
737
772
  } catch (e) {
738
773
  throw await l(r, {
@@ -741,18 +776,18 @@ async function wt(e, t, n) {
741
776
  }), e;
742
777
  }
743
778
  }
744
- async function Tt(e, t) {
745
- let n = t.workspaceId ?? await pt(e, t.projectId), r = await mt(e, n), i = q(r.source) ? r.source.projectId : void 0;
779
+ async function It(e, t) {
780
+ let n = t.workspaceId ?? await wt(e, t.projectId), r = await Tt(e, n), i = Z(r.source) ? r.source.projectId : void 0;
746
781
  if (i !== t.projectId) throw Error(`Workspace ${n} belongs to project ${String(i)}, not ${t.projectId}.`);
747
782
  return r;
748
783
  }
749
- async function Et(e) {
784
+ async function Lt(e) {
750
785
  try {
751
- let t = bt(e, e.cwd ?? process.cwd());
752
- await xt(t.outDir);
753
- let n = await Tt(await H(await U(e.cwd)), t), r = Y(n);
754
- await wt(t.outDir, n, r);
755
- let i = q(n.workspace) ? String(n.workspace.name) : "";
786
+ let t = jt(e, e.cwd ?? process.cwd());
787
+ await Mt(t.outDir);
788
+ let n = await It(await G(await K(e.cwd)), t), r = vt(n);
789
+ await Ft(t.outDir, n, r);
790
+ let i = Z(n.workspace) ? String(n.workspace.name) : "";
756
791
  return console.log(`Exported workspace "${i}" with ${String(r.length)} assets to ${t.outDir}`), 0;
757
792
  } catch (e) {
758
793
  let t = e instanceof Error ? e.message : String(e);
@@ -761,30 +796,30 @@ async function Et(e) {
761
796
  }
762
797
  //#endregion
763
798
  //#region src/commands/workspace-import.ts
764
- async function Dt(e) {
765
- let t = m(e, W), n = await o(t, "utf8").catch((e) => {
799
+ async function Rt(e) {
800
+ let t = m(e, J), n = await o(t, "utf8").catch((e) => {
766
801
  throw Error(`Cannot read ${t}. Pass the directory \`picked workspace export\` wrote.`, { cause: e });
767
802
  }), r = JSON.parse(n);
768
- if (!q(r)) throw Error(`${t} is not a JSON object.`);
803
+ if (!Z(r)) throw Error(`${t} is not a JSON object.`);
769
804
  return r;
770
805
  }
771
- async function Ot(e, t) {
806
+ async function zt(e, t) {
772
807
  let n = [];
773
808
  for (let r of t) {
774
809
  if (r.sha256 === null) throw Error(`The manifest item for ${r.fileName} has no SHA-256. Export the bundle with \`picked workspace export\`.`);
775
- let t = J(e, r.sha256), i = new Uint8Array(await o(t));
810
+ let t = gt(e, r.sha256), i = new Uint8Array(await o(t));
776
811
  n.push({
777
812
  asset: r,
778
- sha256: X(r, i, t),
813
+ sha256: yt(r, i, t),
779
814
  bytes: i
780
815
  });
781
816
  }
782
817
  return n;
783
818
  }
784
- async function kt(e, t, n, r) {
819
+ async function Bt(e, t, n, r) {
785
820
  let i = [];
786
821
  for (let { asset: a, sha256: o, bytes: s } of n) {
787
- let n = await ht(e, {
822
+ let n = await Et(e, {
788
823
  projectId: t,
789
824
  fileName: a.fileName,
790
825
  mimeType: a.mimeType,
@@ -799,60 +834,60 @@ async function kt(e, t, n, r) {
799
834
  }
800
835
  return i;
801
836
  }
802
- async function $(e, t) {
837
+ async function Vt(e, t) {
803
838
  let n = [], r = [];
804
839
  for (let i of t) try {
805
- await gt(e, i), n.push(i);
840
+ await Dt(e, i), n.push(i);
806
841
  } catch (e) {
807
842
  let t = e instanceof Error ? e.message : String(e);
808
843
  r.push(`Could not delete asset ${i} (${t}); delete it from the project by hand.`);
809
844
  }
810
845
  return [...n.length > 0 ? [`Deleted the ${String(n.length)} asset${n.length === 1 ? "" : "s"} this run uploaded: ${n.join(", ")}.`] : [], ...r].join("\n");
811
846
  }
812
- function At(e, t) {
847
+ function Ht(e, t) {
813
848
  let n = e instanceof Error ? e.message : String(e);
814
849
  return Error(t ? `${n}\n${t}` : n, { cause: e });
815
850
  }
816
- function jt(e) {
851
+ function Ut(e) {
817
852
  let t = ["The outcome of the import is unknown: the API may have created the workspace. Check the project for it before you import again."];
818
853
  return e.length > 0 && t.push(`Kept the ${String(e.length)} asset${e.length === 1 ? "" : "s"} this run uploaded: ${e.join(", ")}. If the project has no new workspace, delete them from the project.`), t.join("\n");
819
854
  }
820
- var Mt = /* @__PURE__ */ new Set([
855
+ var Wt = /* @__PURE__ */ new Set([
821
856
  "FORBIDDEN",
822
857
  "UNAUTHENTICATED",
823
858
  "BAD_USER_INPUT",
824
859
  "GRAPHQL_VALIDATION_FAILED"
825
860
  ]);
826
- function Nt(e) {
827
- return e instanceof Z || e instanceof se && e.codes.length > 0 && e.codes.every((e) => e !== void 0 && Mt.has(e));
861
+ function Gt(e) {
862
+ return e instanceof Ct || e instanceof de && e.codes.length > 0 && e.codes.every((e) => e !== void 0 && Wt.has(e));
828
863
  }
829
- async function Pt(e, t) {
830
- let n = [], r = await kt(e, t.projectId, t.assets, n).catch(async (t) => {
831
- throw At(t, await $(e, n));
864
+ async function Kt(e, t) {
865
+ let n = [], r = await Bt(e, t.projectId, t.assets, n).catch(async (t) => {
866
+ throw Ht(t, await Vt(e, n));
832
867
  });
833
868
  return {
834
- workspace: await _t(e, {
869
+ workspace: await Ot(e, {
835
870
  projectId: t.projectId,
836
871
  name: t.name,
837
872
  bundle: t.bundle,
838
873
  assetMap: r
839
874
  }).catch(async (t) => {
840
- throw At(t, Nt(t) ? await $(e, n) : jt(n));
875
+ throw Ht(t, Gt(t) ? await Vt(e, n) : Ut(n));
841
876
  }),
842
877
  uploaded: n.length
843
878
  };
844
879
  }
845
- async function Ft(e) {
880
+ async function qt(e) {
846
881
  try {
847
882
  if (!e.project) throw Error("Missing --project <id>.");
848
883
  if (!e.in) throw Error("Missing --in <dir>.");
849
- let t = e.project, n = K(e.cwd ?? process.cwd(), e.in, "--in"), r = await Dt(n), i = await Ot(n, Y(r)), a = await H(await U(e.cwd)), { workspace: o, uploaded: s } = await Pt(a, {
884
+ let t = e.project, n = X(e.cwd ?? process.cwd(), e.in, "--in"), r = await Rt(n), i = await zt(n, vt(r)), a = await G(await K(e.cwd)), { workspace: o, uploaded: s } = await Kt(a, {
850
885
  projectId: t,
851
886
  name: e.name,
852
887
  bundle: r,
853
888
  assets: i
854
889
  });
855
- return console.log(`Imported workspace "${o.name}" as ${o.id} into project ${t} (assets: ${String(s)} uploaded, ${String(i.length - s)} already in the project).`), e.publish && (await vt(a, o.id).catch((e) => {
890
+ return console.log(`Imported workspace "${o.name}" as ${o.id} into project ${t} (assets: ${String(s)} uploaded, ${String(i.length - s)} already in the project).`), e.publish && (await kt(a, o.id).catch((e) => {
856
891
  let t = e instanceof Error ? e.message : String(e);
857
892
  throw Error(`Workspace ${o.id} was imported, but not published. ${t}`, { cause: e });
858
893
  }), console.log(`Published workspace ${o.id}.`)), 0;
@@ -863,9 +898,9 @@ async function Ft(e) {
863
898
  }
864
899
  //#endregion
865
900
  //#region src/lib/workspaces.ts
866
- var It = S("\n query PickedWorkspaces {\n user {\n organizations(first: 50) {\n edges {\n node {\n id\n name\n slug\n projects(first: 100) {\n edges {\n node {\n id\n name\n liveWorkspace {\n id\n }\n liveWorkspaceVersion {\n id\n }\n workspaces(first: 100) {\n edges {\n node {\n id\n name\n status\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n"), Lt = S("\n query PickedPreviewToken($id: ID!, $projectId: ID!) {\n workspace(id: $id, projectId: $projectId) {\n id\n name\n status\n previewToken\n }\n }\n");
867
- async function Rt(e) {
868
- let t = await e.request(It, {});
901
+ var Jt = T("\n query PickedWorkspaces {\n user {\n organizations(first: 50) {\n edges {\n node {\n id\n name\n slug\n projects(first: 100) {\n edges {\n node {\n id\n name\n liveWorkspace {\n id\n }\n liveWorkspaceVersion {\n id\n }\n workspaces(first: 100) {\n edges {\n node {\n id\n name\n status\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }\n"), Yt = T("\n query PickedPreviewToken($id: ID!, $projectId: ID!) {\n workspace(id: $id, projectId: $projectId) {\n id\n name\n status\n previewToken\n }\n }\n");
902
+ async function Xt(e) {
903
+ let t = await e.request(Jt, {});
869
904
  if (!t.user) throw Error("Not signed in as a user, or no organizations are visible to this account. An API key has no organization list.");
870
905
  return t.user.organizations.edges.map((e) => {
871
906
  let t = e.node;
@@ -890,8 +925,8 @@ async function Rt(e) {
890
925
  };
891
926
  });
892
927
  }
893
- async function zt(e, t, n) {
894
- let r = (await e.request(Lt, {
928
+ async function Zt(e, t, n) {
929
+ let r = (await e.request(Yt, {
895
930
  id: n,
896
931
  projectId: t
897
932
  })).workspace;
@@ -904,7 +939,7 @@ async function zt(e, t, n) {
904
939
  }
905
940
  //#endregion
906
941
  //#region src/commands/workspace-list.ts
907
- function Bt(e) {
942
+ function Qt(e) {
908
943
  for (let t of e) {
909
944
  console.log(`${t.name} (${t.slug})`);
910
945
  for (let e of t.projects) {
@@ -916,10 +951,10 @@ function Bt(e) {
916
951
  }
917
952
  }
918
953
  }
919
- async function Vt(e) {
954
+ async function $t(e) {
920
955
  try {
921
- let t = await Rt(await H(await U(e?.cwd)));
922
- return e?.json ? (console.log(JSON.stringify(t, null, 2)), 0) : (Bt(t), 0);
956
+ let t = await Xt(await G(await K(e?.cwd)));
957
+ return e?.json ? (console.log(JSON.stringify(t, null, 2)), 0) : (Qt(t), 0);
923
958
  } catch (e) {
924
959
  let t = e instanceof Error ? e.message : String(e);
925
960
  return console.error(t), 1;
@@ -927,14 +962,14 @@ async function Vt(e) {
927
962
  }
928
963
  //#endregion
929
964
  //#region src/lib/prompt.ts
930
- function Ht(e, t) {
965
+ function en(e, t) {
931
966
  return new Promise((n) => {
932
967
  e.question(t, n);
933
968
  });
934
969
  }
935
- async function Ut(e, t) {
970
+ async function tn(e, t) {
936
971
  if (t.length === 0) throw Error("No choices available to select from.");
937
- let n = ge({
972
+ let n = be({
938
973
  input: process.stdin,
939
974
  output: process.stderr
940
975
  });
@@ -943,7 +978,7 @@ async function Ut(e, t) {
943
978
  });
944
979
  try {
945
980
  for (;;) {
946
- let e = await Ht(n, `Enter a number (1-${t.length.toString()}): `), r = Number.parseInt(e, 10), i = Number.isInteger(r) ? t[r - 1] : void 0;
981
+ let e = await en(n, `Enter a number (1-${t.length.toString()}): `), r = Number.parseInt(e, 10), i = Number.isInteger(r) ? t[r - 1] : void 0;
947
982
  if (i) return i.value;
948
983
  process.stderr.write("Invalid choice, try again.\n");
949
984
  }
@@ -953,7 +988,7 @@ async function Ut(e, t) {
953
988
  }
954
989
  //#endregion
955
990
  //#region src/commands/workspace-use.ts
956
- function Wt(e, t, n) {
991
+ function $(e, t, n) {
957
992
  return {
958
993
  projectId: e,
959
994
  workspace: {
@@ -965,11 +1000,11 @@ function Wt(e, t, n) {
965
1000
  }
966
1001
  };
967
1002
  }
968
- async function Gt(e, t, n) {
969
- return n ? Wt(t, n, await zt(e, t, n)) : { projectId: t };
1003
+ async function nn(e, t, n) {
1004
+ return n ? $(t, n, await Zt(e, t, n)) : { projectId: t };
970
1005
  }
971
- async function Kt(e) {
972
- let t = await Ut("Select a project", (await Rt(e)).flatMap((e) => e.projects.map((t) => ({
1006
+ async function rn(e) {
1007
+ let t = await tn("Select a project", (await Xt(e)).flatMap((e) => e.projects.map((t) => ({
973
1008
  label: `${e.name} / ${t.name}`,
974
1009
  value: t
975
1010
  })))), n = t.workspaces.map((e) => ({
@@ -980,13 +1015,13 @@ async function Kt(e) {
980
1015
  label: "Published (live version)",
981
1016
  value: null
982
1017
  });
983
- let r = await Ut("Select a workspace", n);
1018
+ let r = await tn("Select a workspace", n);
984
1019
  if (!r) return { projectId: t.id };
985
1020
  r.status === "ARCHIVED" && console.error("Warning: archived workspaces may fail to load via the delivery API.");
986
- let i = await zt(e, t.id, r.id);
987
- return Wt(t.id, r.id, i);
1021
+ let i = await Zt(e, t.id, r.id);
1022
+ return $(t.id, r.id, i);
988
1023
  }
989
- function qt(e) {
1024
+ function an(e) {
990
1025
  if (!e.workspace) {
991
1026
  console.log(`Active workspace: live (published) in project ${e.projectId}`);
992
1027
  return;
@@ -994,15 +1029,15 @@ function qt(e) {
994
1029
  let { name: t, status: n, source: r } = e.workspace;
995
1030
  console.log(`Active workspace: ${t} [${n}] in project ${e.projectId} (source: ${r})`);
996
1031
  }
997
- async function Jt(e) {
1032
+ async function on(e) {
998
1033
  let t = e?.cwd ?? process.cwd();
999
1034
  try {
1000
- let n = await U(t), r = await H(n), i = e?.project ? await Gt(r, e.project, e.workspace) : await Kt(r);
1001
- return await re(t, n, i), qt(i), e?.generate !== !1 && await A({ cwd: t }), 0;
1035
+ let n = await K(t), r = await G(n), i = e?.project ? await nn(r, e.project, e.workspace) : await rn(r);
1036
+ return await oe(t, n, i), an(i), e?.generate !== !1 && await P({ cwd: t }), 0;
1002
1037
  } catch (e) {
1003
1038
  let t = e instanceof Error ? e.message : String(e);
1004
1039
  return console.error(t), 1;
1005
1040
  }
1006
1041
  }
1007
1042
  //#endregion
1008
- export { ot as a, rt as c, Oe as d, D as f, Et as i, A as l, Vt as n, at as o, O as p, Ft as r, it as s, Jt as t, De as u };
1043
+ export { pt as a, ct as c, Ae as d, je as f, Lt as i, st as l, M as m, $t as n, ft as o, j as p, qt as r, dt as s, on as t, P as u };