@picked/cli 0.0.107-next.3 → 0.0.107-next.5

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();
@@ -395,7 +396,7 @@ function Ze(e, t, n) {
395
396
  });
396
397
  });
397
398
  }
398
- async function z(e) {
399
+ async function H(e) {
399
400
  let t;
400
401
  try {
401
402
  t = await e.json();
@@ -410,7 +411,7 @@ async function z(e) {
410
411
  expiresIn: t.expires_in
411
412
  };
412
413
  }
413
- function Qe(e) {
414
+ function nt(e) {
414
415
  let t = e.split("."), n = t[1];
415
416
  if (t.length !== 3 || !n) return {};
416
417
  try {
@@ -423,10 +424,10 @@ function Qe(e) {
423
424
  return {};
424
425
  }
425
426
  }
426
- async function $e(e) {
427
- 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);
428
- 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());
429
- 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({
430
431
  grant_type: "authorization_code",
431
432
  code: l,
432
433
  redirect_uri: r,
@@ -438,18 +439,18 @@ async function $e(e) {
438
439
  body: u.toString()
439
440
  });
440
441
  if (!d.ok) throw Error(`Token exchange failed (${d.status.toString()}).`);
441
- let f = await z(d);
442
+ let f = await H(d);
442
443
  if (!f?.refreshToken) throw Error("Token exchange did not return a refresh token.");
443
444
  return {
444
445
  accessToken: f.accessToken,
445
446
  refreshToken: f.refreshToken,
446
447
  expiresAt: Date.now() + f.expiresIn * 1e3,
447
- user: Qe(f.accessToken)
448
+ user: nt(f.accessToken)
448
449
  };
449
450
  }
450
- async function et(e) {
451
+ async function it(e) {
451
452
  if (!e.client || !e.session) throw Error("Session expired. Run `picked login`.");
452
- let t = await R(e.apiUrl), n = new URLSearchParams({
453
+ let t = await V(e.apiUrl), n = new URLSearchParams({
453
454
  grant_type: "refresh_token",
454
455
  refresh_token: e.session.refreshToken,
455
456
  client_id: e.client.clientId
@@ -464,7 +465,7 @@ async function et(e) {
464
465
  throw Error("Session expired. Run `picked login`.");
465
466
  }
466
467
  if (!r.ok) throw Error("Session expired. Run `picked login`.");
467
- let i = await z(r);
468
+ let i = await H(r);
468
469
  if (!i) throw Error("Session expired. Run `picked login`.");
469
470
  return {
470
471
  accessToken: i.accessToken,
@@ -475,47 +476,47 @@ async function et(e) {
475
476
  }
476
477
  //#endregion
477
478
  //#region src/auth/session.ts
478
- var tt = 6e4;
479
- async function B(e) {
480
- let t = await N(e);
479
+ var at = 6e4;
480
+ async function U(e) {
481
+ let t = await L(e);
481
482
  if (!t?.session) throw Error(`Not logged in to ${e}. Run \`picked login\`.`);
482
- if (t.session.expiresAt - Date.now() > tt) return t.session.accessToken;
483
- let n = await et(t);
484
- 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;
485
486
  }
486
487
  //#endregion
487
488
  //#region src/lib/admin-client.ts
488
- function V() {
489
+ function W() {
489
490
  let e = process.env.PICKED_API_KEY?.trim();
490
491
  return e === "" ? void 0 : e;
491
492
  }
492
- async function H(e) {
493
- let t = V();
494
- return t ? he({
493
+ async function G(e) {
494
+ let t = W();
495
+ return t ? w({
495
496
  apiUrl: e,
496
497
  apiKey: t
497
- }) : (await B(e), he({
498
+ }) : (await U(e), w({
498
499
  apiUrl: e,
499
- token: () => B(e)
500
+ token: () => U(e)
500
501
  }));
501
502
  }
502
503
  //#endregion
503
504
  //#region src/lib/api-url.ts
504
- var nt = "https://api.picked.app";
505
- async function U(e = process.cwd()) {
505
+ var ot = "https://api.picked.app";
506
+ async function K(e = process.cwd()) {
506
507
  let t = process.env.PICKED_API_URL;
507
- if (t) return y(t);
508
- let n = await v(e);
509
- return y(n?.apiUrl ?? nt);
508
+ if (t) return x(t);
509
+ let n = await y(e);
510
+ return x(n?.apiUrl ?? ot);
510
511
  }
511
512
  //#endregion
512
513
  //#region src/commands/login.ts
513
- async function rt(e) {
514
- let t = await U(e?.cwd);
515
- 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;
516
517
  try {
517
- let e = await $e(t);
518
- await F(t, e);
518
+ let e = await rt(t);
519
+ await He(t, e);
519
520
  let n = e.user?.email ?? e.user?.id ?? "unknown user";
520
521
  return console.log(`Logged in as ${n} (${t})`), 0;
521
522
  } catch (e) {
@@ -525,16 +526,54 @@ async function rt(e) {
525
526
  }
526
527
  //#endregion
527
528
  //#region src/commands/logout.ts
528
- async function it(e) {
529
- let t = await U(e?.cwd);
530
- 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;
531
570
  }
532
571
  //#endregion
533
572
  //#region src/commands/status.ts
534
- async function at(e) {
535
- 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);
536
575
  if (!n) return console.error("No picked.config.{ts,js,json} found in the current directory."), 1;
537
- let r = await U(t);
576
+ let r = await K(t);
538
577
  console.log(`API: ${r}`), console.log(`Config default: project ${n.projectId} (source: ${n.source ?? "published"})`);
539
578
  let i = await ne(t, r);
540
579
  if (!i) return console.log("Active selection: none (using the config default)."), 0;
@@ -544,34 +583,34 @@ async function at(e) {
544
583
  }
545
584
  //#endregion
546
585
  //#region src/commands/whoami.ts
547
- async function ot(e) {
548
- let t = await U(e?.cwd);
549
- 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;
550
- 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);
551
590
  if (!n?.session) return console.error(`Not logged in to ${t}. Run \`picked login\`.`), 1;
552
591
  let { user: r } = n.session, i = r?.email ?? r?.id ?? "unknown user";
553
592
  return console.log(`${i} (${t})`), 0;
554
593
  }
555
594
  //#endregion
556
595
  //#region src/lib/bundle.ts
557
- var W = "bundle.json", G = "assets", st = /^[0-9a-f]{64}$/;
558
- function K(e, t, n) {
596
+ var J = "bundle.json", Y = "assets", mt = /^[0-9a-f]{64}$/;
597
+ function X(e, t, n) {
559
598
  let r = g(e), i = g(r, t);
560
599
  if (!i.startsWith(r.endsWith(_) ? r : r + _)) throw Error(`${n} ${t} must name a directory inside ${r}.`);
561
600
  return i;
562
601
  }
563
- function q(e) {
602
+ function Z(e) {
564
603
  return typeof e == "object" && !!e && !Array.isArray(e);
565
604
  }
566
- function ct(e) {
567
- return b("sha256").update(e).digest("hex");
605
+ function ht(e) {
606
+ return S("sha256").update(e).digest("hex");
568
607
  }
569
- function J(e, t) {
570
- return m(e, G, t);
608
+ function gt(e, t) {
609
+ return m(e, Y, t);
571
610
  }
572
- function lt(e, t) {
611
+ function _t(e, t) {
573
612
  let n = `bundle assets[${String(t)}]`;
574
- if (!q(e)) throw Error(`${n} is not an object.`);
613
+ if (!Z(e)) throw Error(`${n} is not an object.`);
575
614
  let { versionId: r, fileName: i, mimeType: a, sizeBytes: o, sha256: s, downloadUrl: c } = e;
576
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.`);
577
616
  if (s === null) return {
@@ -583,7 +622,7 @@ function lt(e, t) {
583
622
  downloadUrl: c
584
623
  };
585
624
  let l = typeof s == "string" ? s.toLowerCase() : "";
586
- 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.`);
587
626
  return {
588
627
  versionId: r,
589
628
  fileName: i,
@@ -593,22 +632,22 @@ function lt(e, t) {
593
632
  downloadUrl: c
594
633
  };
595
634
  }
596
- function Y(e) {
635
+ function vt(e) {
597
636
  let { assets: t } = e;
598
637
  if (!Array.isArray(t)) throw Error("The bundle has no assets array.");
599
- return t.map((e, t) => lt(e, t));
638
+ return t.map((e, t) => _t(e, t));
600
639
  }
601
- function X(e, t, n) {
640
+ function yt(e, t, n) {
602
641
  if (t.byteLength !== e.sizeBytes) throw Error(`${e.fileName} (${n}) has size ${String(t.byteLength)} bytes; the manifest says ${String(e.sizeBytes)}.`);
603
- let r = ct(t);
642
+ let r = ht(t);
604
643
  if (e.sha256 !== null && r !== e.sha256) throw Error(`${e.fileName} (${n}) has SHA-256 ${r}; the manifest says ${e.sha256}.`);
605
644
  return r;
606
645
  }
607
- function ut(e, t) {
646
+ function bt(e, t) {
608
647
  let n = Array.isArray(e.assets) ? e.assets : [];
609
648
  return {
610
649
  ...e,
611
- assets: n.map((e, n) => q(e) ? {
650
+ assets: n.map((e, n) => Z(e) ? {
612
651
  ...e,
613
652
  sha256: t[n]
614
653
  } : e)
@@ -616,30 +655,30 @@ function ut(e, t) {
616
655
  }
617
656
  //#endregion
618
657
  //#region src/lib/workspace-transfer.ts
619
- var dt = 12e4, ft = 3e5, Z = class extends Error {
658
+ var xt = 12e4, St = 3e5, Ct = class extends Error {
620
659
  name = "PayloadUserErrorsError";
621
660
  };
622
661
  function Q(e, t) {
623
- 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) => {
624
663
  let t = e.field?.length ? ` (${e.field.join(".")})` : "";
625
664
  return ` ${e.code}: ${e.message}${t}`;
626
665
  }).join("\n")}`);
627
666
  }
628
- async function pt(e, t) {
629
- 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 } });
630
669
  if (!n) throw Error(`Project ${t} was not found.`);
631
670
  let r = n.liveWorkspaceVersion;
632
671
  if (!r) throw Error(`Project ${t} has no published version.`);
633
672
  if (!r.snapshotWorkspaceId) throw Error(`The live version ${r.id} of project ${t} has no snapshot workspace to export. Publish the project again.`);
634
673
  return r.snapshotWorkspaceId;
635
674
  }
636
- async function mt(e, t) {
637
- let { workspaceExport: n } = await e.request(fe, { input: { workspaceId: t } });
638
- 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.`);
639
678
  return n.bundle;
640
679
  }
641
- async function ht(e, t) {
642
- 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: {
643
682
  projectId: n,
644
683
  fileName: r,
645
684
  contentType: i,
@@ -655,10 +694,10 @@ async function ht(e, t) {
655
694
  method: "PUT",
656
695
  headers: { "Content-Type": i },
657
696
  body: o,
658
- signal: AbortSignal.timeout(dt)
697
+ signal: AbortSignal.timeout(xt)
659
698
  });
660
699
  if (!c.ok) throw Error(`Upload of ${r} failed with status ${String(c.status)}: ${await c.text()}`);
661
- let { assetCommit: l } = await e.request(ce, { input: {
700
+ let { assetCommit: l } = await e.request(fe, { input: {
662
701
  projectId: n,
663
702
  assetId: s.assetId,
664
703
  versionId: s.versionId,
@@ -672,22 +711,22 @@ async function ht(e, t) {
672
711
  deduplicated: !1
673
712
  };
674
713
  }
675
- async function gt(e, t) {
676
- await e.request(le, { input: { id: t } });
714
+ async function Dt(e, t) {
715
+ await e.request(pe, { input: { id: t } });
677
716
  }
678
- async function _t(e, t) {
679
- 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 });
680
719
  if (Q(`Import into project ${t.projectId}`, n.userErrors), !n.workspace) throw Error(`Import into project ${t.projectId} returned no workspace.`);
681
720
  return n.workspace;
682
721
  }
683
- async function vt(e, t) {
684
- 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 } });
685
724
  Q(`Publish of workspace ${t}`, n.userErrors);
686
725
  }
687
726
  //#endregion
688
727
  //#region src/commands/workspace-export.ts
689
- var yt = 12e4;
690
- function bt(e, t) {
728
+ var At = 12e4;
729
+ function jt(e, t) {
691
730
  if (!e.project) throw Error("Missing --project <id>.");
692
731
  if (e.workspace && e.live) throw Error("Pass --workspace <id> or --live, not both.");
693
732
  if (!e.workspace && !e.live) throw Error("Pass --workspace <id> or --live.");
@@ -695,40 +734,40 @@ function bt(e, t) {
695
734
  return {
696
735
  projectId: e.project,
697
736
  workspaceId: e.workspace ?? null,
698
- outDir: K(t, e.out, "--out")
737
+ outDir: X(t, e.out, "--out")
699
738
  };
700
739
  }
701
- async function xt(e) {
740
+ async function Mt(e) {
702
741
  if ((await s(e).catch((e) => {
703
- if (q(e) && e.code === "ENOENT") return [];
742
+ if (Z(e) && e.code === "ENOENT") return [];
704
743
  throw e;
705
744
  })).length > 0) throw Error(`${e} is not empty. Export into a new or empty directory.`);
706
745
  }
707
- async function St(e) {
708
- 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) });
709
748
  if (!t.ok) throw Error(`Download of ${e.fileName} from ${e.downloadUrl} failed with status ${String(t.status)}.`);
710
749
  let n = new Uint8Array(await t.arrayBuffer());
711
750
  return {
712
751
  bytes: n,
713
- sha256: X(e, n, e.downloadUrl)
752
+ sha256: yt(e, n, e.downloadUrl)
714
753
  };
715
754
  }
716
- async function Ct(e, t, n) {
717
- await i(m(e, G));
755
+ async function Pt(e, t, n) {
756
+ await i(m(e, Y));
718
757
  let r = [];
719
758
  for (let t of n) {
720
- let { bytes: n, sha256: i } = await St(t);
721
- 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);
722
761
  }
723
- let a = ut(t, r);
724
- 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`);
725
764
  }
726
- async function wt(e, t, n) {
765
+ async function Ft(e, t, n) {
727
766
  await i(p(e), { recursive: !0 });
728
767
  let r = await a(m(p(e), `.${f(e)}.partial-`));
729
768
  try {
730
- await Ct(r, t, n), await u(e).catch((e) => {
731
- 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;
732
771
  }), await c(r, e);
733
772
  } catch (e) {
734
773
  throw await l(r, {
@@ -737,18 +776,18 @@ async function wt(e, t, n) {
737
776
  }), e;
738
777
  }
739
778
  }
740
- async function Tt(e, t) {
741
- 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;
742
781
  if (i !== t.projectId) throw Error(`Workspace ${n} belongs to project ${String(i)}, not ${t.projectId}.`);
743
782
  return r;
744
783
  }
745
- async function Et(e) {
784
+ async function Lt(e) {
746
785
  try {
747
- let t = bt(e, e.cwd ?? process.cwd());
748
- await xt(t.outDir);
749
- let n = await Tt(await H(await U(e.cwd)), t), r = Y(n);
750
- await wt(t.outDir, n, r);
751
- 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) : "";
752
791
  return console.log(`Exported workspace "${i}" with ${String(r.length)} assets to ${t.outDir}`), 0;
753
792
  } catch (e) {
754
793
  let t = e instanceof Error ? e.message : String(e);
@@ -757,30 +796,30 @@ async function Et(e) {
757
796
  }
758
797
  //#endregion
759
798
  //#region src/commands/workspace-import.ts
760
- async function Dt(e) {
761
- 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) => {
762
801
  throw Error(`Cannot read ${t}. Pass the directory \`picked workspace export\` wrote.`, { cause: e });
763
802
  }), r = JSON.parse(n);
764
- if (!q(r)) throw Error(`${t} is not a JSON object.`);
803
+ if (!Z(r)) throw Error(`${t} is not a JSON object.`);
765
804
  return r;
766
805
  }
767
- async function Ot(e, t) {
806
+ async function zt(e, t) {
768
807
  let n = [];
769
808
  for (let r of t) {
770
809
  if (r.sha256 === null) throw Error(`The manifest item for ${r.fileName} has no SHA-256. Export the bundle with \`picked workspace export\`.`);
771
- 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));
772
811
  n.push({
773
812
  asset: r,
774
- sha256: X(r, i, t),
813
+ sha256: yt(r, i, t),
775
814
  bytes: i
776
815
  });
777
816
  }
778
817
  return n;
779
818
  }
780
- async function kt(e, t, n, r) {
819
+ async function Bt(e, t, n, r) {
781
820
  let i = [];
782
821
  for (let { asset: a, sha256: o, bytes: s } of n) {
783
- let n = await ht(e, {
822
+ let n = await Et(e, {
784
823
  projectId: t,
785
824
  fileName: a.fileName,
786
825
  mimeType: a.mimeType,
@@ -795,60 +834,60 @@ async function kt(e, t, n, r) {
795
834
  }
796
835
  return i;
797
836
  }
798
- async function $(e, t) {
837
+ async function Vt(e, t) {
799
838
  let n = [], r = [];
800
839
  for (let i of t) try {
801
- await gt(e, i), n.push(i);
840
+ await Dt(e, i), n.push(i);
802
841
  } catch (e) {
803
842
  let t = e instanceof Error ? e.message : String(e);
804
843
  r.push(`Could not delete asset ${i} (${t}); delete it from the project by hand.`);
805
844
  }
806
845
  return [...n.length > 0 ? [`Deleted the ${String(n.length)} asset${n.length === 1 ? "" : "s"} this run uploaded: ${n.join(", ")}.`] : [], ...r].join("\n");
807
846
  }
808
- function At(e, t) {
847
+ function Ht(e, t) {
809
848
  let n = e instanceof Error ? e.message : String(e);
810
849
  return Error(t ? `${n}\n${t}` : n, { cause: e });
811
850
  }
812
- function jt(e) {
851
+ function Ut(e) {
813
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."];
814
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");
815
854
  }
816
- var Mt = /* @__PURE__ */ new Set([
855
+ var Wt = /* @__PURE__ */ new Set([
817
856
  "FORBIDDEN",
818
857
  "UNAUTHENTICATED",
819
858
  "BAD_USER_INPUT",
820
859
  "GRAPHQL_VALIDATION_FAILED"
821
860
  ]);
822
- function Nt(e) {
823
- 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));
824
863
  }
825
- async function Pt(e, t) {
826
- let n = [], r = await kt(e, t.projectId, t.assets, n).catch(async (t) => {
827
- 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));
828
867
  });
829
868
  return {
830
- workspace: await _t(e, {
869
+ workspace: await Ot(e, {
831
870
  projectId: t.projectId,
832
871
  name: t.name,
833
872
  bundle: t.bundle,
834
873
  assetMap: r
835
874
  }).catch(async (t) => {
836
- throw At(t, Nt(t) ? await $(e, n) : jt(n));
875
+ throw Ht(t, Gt(t) ? await Vt(e, n) : Ut(n));
837
876
  }),
838
877
  uploaded: n.length
839
878
  };
840
879
  }
841
- async function Ft(e) {
880
+ async function qt(e) {
842
881
  try {
843
882
  if (!e.project) throw Error("Missing --project <id>.");
844
883
  if (!e.in) throw Error("Missing --in <dir>.");
845
- 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, {
846
885
  projectId: t,
847
886
  name: e.name,
848
887
  bundle: r,
849
888
  assets: i
850
889
  });
851
- 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) => {
852
891
  let t = e instanceof Error ? e.message : String(e);
853
892
  throw Error(`Workspace ${o.id} was imported, but not published. ${t}`, { cause: e });
854
893
  }), console.log(`Published workspace ${o.id}.`)), 0;
@@ -859,9 +898,9 @@ async function Ft(e) {
859
898
  }
860
899
  //#endregion
861
900
  //#region src/lib/workspaces.ts
862
- 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");
863
- async function Rt(e) {
864
- 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, {});
865
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.");
866
905
  return t.user.organizations.edges.map((e) => {
867
906
  let t = e.node;
@@ -886,8 +925,8 @@ async function Rt(e) {
886
925
  };
887
926
  });
888
927
  }
889
- async function zt(e, t, n) {
890
- let r = (await e.request(Lt, {
928
+ async function Zt(e, t, n) {
929
+ let r = (await e.request(Yt, {
891
930
  id: n,
892
931
  projectId: t
893
932
  })).workspace;
@@ -900,7 +939,7 @@ async function zt(e, t, n) {
900
939
  }
901
940
  //#endregion
902
941
  //#region src/commands/workspace-list.ts
903
- function Bt(e) {
942
+ function Qt(e) {
904
943
  for (let t of e) {
905
944
  console.log(`${t.name} (${t.slug})`);
906
945
  for (let e of t.projects) {
@@ -912,10 +951,10 @@ function Bt(e) {
912
951
  }
913
952
  }
914
953
  }
915
- async function Vt(e) {
954
+ async function $t(e) {
916
955
  try {
917
- let t = await Rt(await H(await U(e?.cwd)));
918
- 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);
919
958
  } catch (e) {
920
959
  let t = e instanceof Error ? e.message : String(e);
921
960
  return console.error(t), 1;
@@ -923,14 +962,14 @@ async function Vt(e) {
923
962
  }
924
963
  //#endregion
925
964
  //#region src/lib/prompt.ts
926
- function Ht(e, t) {
965
+ function en(e, t) {
927
966
  return new Promise((n) => {
928
967
  e.question(t, n);
929
968
  });
930
969
  }
931
- async function Ut(e, t) {
970
+ async function tn(e, t) {
932
971
  if (t.length === 0) throw Error("No choices available to select from.");
933
- let n = ge({
972
+ let n = be({
934
973
  input: process.stdin,
935
974
  output: process.stderr
936
975
  });
@@ -939,7 +978,7 @@ async function Ut(e, t) {
939
978
  });
940
979
  try {
941
980
  for (;;) {
942
- 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;
943
982
  if (i) return i.value;
944
983
  process.stderr.write("Invalid choice, try again.\n");
945
984
  }
@@ -949,7 +988,7 @@ async function Ut(e, t) {
949
988
  }
950
989
  //#endregion
951
990
  //#region src/commands/workspace-use.ts
952
- function Wt(e, t, n) {
991
+ function $(e, t, n) {
953
992
  return {
954
993
  projectId: e,
955
994
  workspace: {
@@ -961,11 +1000,11 @@ function Wt(e, t, n) {
961
1000
  }
962
1001
  };
963
1002
  }
964
- async function Gt(e, t, n) {
965
- 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 };
966
1005
  }
967
- async function Kt(e) {
968
- 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) => ({
969
1008
  label: `${e.name} / ${t.name}`,
970
1009
  value: t
971
1010
  })))), n = t.workspaces.map((e) => ({
@@ -976,13 +1015,13 @@ async function Kt(e) {
976
1015
  label: "Published (live version)",
977
1016
  value: null
978
1017
  });
979
- let r = await Ut("Select a workspace", n);
1018
+ let r = await tn("Select a workspace", n);
980
1019
  if (!r) return { projectId: t.id };
981
1020
  r.status === "ARCHIVED" && console.error("Warning: archived workspaces may fail to load via the delivery API.");
982
- let i = await zt(e, t.id, r.id);
983
- return Wt(t.id, r.id, i);
1021
+ let i = await Zt(e, t.id, r.id);
1022
+ return $(t.id, r.id, i);
984
1023
  }
985
- function qt(e) {
1024
+ function an(e) {
986
1025
  if (!e.workspace) {
987
1026
  console.log(`Active workspace: live (published) in project ${e.projectId}`);
988
1027
  return;
@@ -990,15 +1029,15 @@ function qt(e) {
990
1029
  let { name: t, status: n, source: r } = e.workspace;
991
1030
  console.log(`Active workspace: ${t} [${n}] in project ${e.projectId} (source: ${r})`);
992
1031
  }
993
- async function Jt(e) {
1032
+ async function on(e) {
994
1033
  let t = e?.cwd ?? process.cwd();
995
1034
  try {
996
- let n = await U(t), r = await H(n), i = e?.project ? await Gt(r, e.project, e.workspace) : await Kt(r);
997
- 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;
998
1037
  } catch (e) {
999
1038
  let t = e instanceof Error ? e.message : String(e);
1000
1039
  return console.error(t), 1;
1001
1040
  }
1002
1041
  }
1003
1042
  //#endregion
1004
- 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 };