@picked/cli 0.0.107-next.3 → 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.
- package/dist/.tsbuildinfo +1 -1
- package/dist/cjs/cli.js +3 -2
- package/dist/cjs/index.js +1 -1
- package/dist/esm/cli.js +50 -42
- package/dist/esm/index.js +1 -1
- package/dist/types/commands/pull.d.ts +19 -0
- package/dist/types/commands/pull.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/{workspace-use-Bmm7xoJ3.js → workspace-use-BlhQXU7t.js} +291 -252
- package/dist/workspace-use-CBVbT-DN.cjs +53 -0
- package/package.json +5 -5
- package/dist/workspace-use-CylqHKq0.cjs +0 -53
|
@@ -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 {
|
|
6
|
-
import { createServer as
|
|
7
|
-
import { spawn as
|
|
8
|
-
import { createHash as
|
|
9
|
-
import { homedir as
|
|
10
|
-
import { AdminApiResponseError as
|
|
11
|
-
import {
|
|
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
|
|
14
|
-
function
|
|
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
|
|
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
|
|
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
|
|
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
|
|
41
|
-
let t = async (t) => (await
|
|
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
|
|
46
|
+
let t = await k(e);
|
|
46
47
|
return (await Promise.all(t.map(async (t) => {
|
|
47
|
-
let { type: n, body: r } =
|
|
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(
|
|
59
|
-
return n ?
|
|
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
|
|
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
|
|
67
|
-
let t = `${
|
|
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
|
|
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 =
|
|
81
|
+
let t = D(e);
|
|
81
82
|
return (await r()).find((e) => e.path === t)?.body;
|
|
82
83
|
}
|
|
83
84
|
};
|
|
84
85
|
}
|
|
85
|
-
function
|
|
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
|
|
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 =
|
|
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
|
|
115
|
-
let t =
|
|
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 ?
|
|
121
|
+
return t ? Se(t) : we();
|
|
121
122
|
}
|
|
122
|
-
function
|
|
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
|
|
132
|
-
async function
|
|
133
|
-
let t = e.source ??
|
|
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}. ${
|
|
138
|
+
return console.error(`\n${String(i.length)} ${i.length === 1 ? "page" : "pages"} from ${t.location}. ${Oe}`), 0;
|
|
138
139
|
}
|
|
139
|
-
function
|
|
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
|
|
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 ??
|
|
152
|
+
let t = e.source ?? A(), n = D(e.page), r = await t.read(n);
|
|
152
153
|
if (r === void 0) {
|
|
153
|
-
let e =
|
|
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(`<!-- ${
|
|
161
|
+
return console.log(`<!-- ${E}${n === "/" ? "" : n} -->\n\n${r}`), 0;
|
|
161
162
|
}
|
|
162
|
-
function
|
|
163
|
+
function N(e) {
|
|
163
164
|
return e === void 0 || e === "list" || e === "ls";
|
|
164
165
|
}
|
|
165
|
-
function
|
|
166
|
-
return
|
|
166
|
+
function Ae(e) {
|
|
167
|
+
return N(e) ? "docs list" : "docs read";
|
|
167
168
|
}
|
|
168
|
-
async function
|
|
169
|
+
async function je(e) {
|
|
169
170
|
let [t, ...n] = e.args;
|
|
170
|
-
return
|
|
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
|
-
}) :
|
|
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
|
|
183
|
-
let t = e?.cwd ?? process.cwd(), n = await
|
|
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
|
|
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
|
|
219
|
-
let { command: t, args: n } =
|
|
219
|
+
function Ne(e) {
|
|
220
|
+
let { command: t, args: n } = Me(e);
|
|
220
221
|
try {
|
|
221
|
-
let e =
|
|
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
|
|
232
|
-
function
|
|
233
|
-
return m(
|
|
232
|
+
var Pe = 8;
|
|
233
|
+
function Fe() {
|
|
234
|
+
return m(ue(), ".picked");
|
|
234
235
|
}
|
|
235
|
-
function
|
|
236
|
-
let t =
|
|
237
|
-
return `${(r ? `${n}-${r}` : n).replace(/[^a-z0-9.-]/gi, "_")}-${
|
|
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
|
|
240
|
-
return m(
|
|
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
|
|
245
|
-
function
|
|
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
|
|
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
|
|
252
|
-
return !(typeof e != "object" || !e || !("apiUrl" in e) || typeof e.apiUrl != "string" || "client" in e && e.client !== void 0 && !
|
|
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
|
|
255
|
-
let n =
|
|
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
|
|
260
|
+
return ze(e) ? e : null;
|
|
260
261
|
} catch {
|
|
261
262
|
return null;
|
|
262
263
|
}
|
|
263
264
|
}
|
|
264
|
-
async function
|
|
265
|
-
let t =
|
|
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:
|
|
271
|
-
}), await r(n,
|
|
271
|
+
mode: I
|
|
272
|
+
}), await r(n, I), await c(n, t);
|
|
272
273
|
}
|
|
273
|
-
async function
|
|
274
|
-
let n = await
|
|
275
|
-
await
|
|
276
|
-
apiUrl:
|
|
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
|
|
283
|
-
await
|
|
283
|
+
async function Ve(e, t) {
|
|
284
|
+
await R(e, { client: t });
|
|
284
285
|
}
|
|
285
|
-
async function
|
|
286
|
-
await
|
|
286
|
+
async function He(e, t) {
|
|
287
|
+
await R(e, { session: t });
|
|
287
288
|
}
|
|
288
|
-
async function
|
|
289
|
-
await l(
|
|
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
|
|
294
|
-
function
|
|
294
|
+
var We = 32, Ge = 16;
|
|
295
|
+
function z(e) {
|
|
295
296
|
return e.toString("base64").replaceAll("+", "-").replaceAll("/", "_").replaceAll("=", "");
|
|
296
297
|
}
|
|
297
|
-
function
|
|
298
|
-
return
|
|
298
|
+
function Ke() {
|
|
299
|
+
return z(C(We));
|
|
299
300
|
}
|
|
300
|
-
function
|
|
301
|
-
return
|
|
301
|
+
function qe(e) {
|
|
302
|
+
return z(S("sha256").update(e).digest());
|
|
302
303
|
}
|
|
303
|
-
function
|
|
304
|
-
return
|
|
304
|
+
function Je() {
|
|
305
|
+
return z(C(Ge));
|
|
305
306
|
}
|
|
306
307
|
//#endregion
|
|
307
308
|
//#region src/auth/oauth.ts
|
|
308
|
-
var
|
|
309
|
+
var B = [
|
|
309
310
|
8976,
|
|
310
311
|
8977,
|
|
311
312
|
8988
|
|
312
|
-
],
|
|
313
|
-
async function
|
|
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
|
|
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
|
|
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
|
|
356
|
-
let r = (await
|
|
357
|
-
return r?.redirectUri === n ? r.clientId :
|
|
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
|
|
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
|
|
370
|
-
for (let t of
|
|
371
|
-
throw Error(`No loopback port available for the OAuth callback (tried ${
|
|
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
|
|
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
|
|
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
|
|
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
|
|
427
|
-
let t = await
|
|
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",
|
|
429
|
-
let { code: l } = await
|
|
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
|
|
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:
|
|
448
|
+
user: nt(f.accessToken)
|
|
448
449
|
};
|
|
449
450
|
}
|
|
450
|
-
async function
|
|
451
|
+
async function it(e) {
|
|
451
452
|
if (!e.client || !e.session) throw Error("Session expired. Run `picked login`.");
|
|
452
|
-
let t = await
|
|
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
|
|
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
|
|
479
|
-
async function
|
|
480
|
-
let t = await
|
|
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() >
|
|
483
|
-
let n = await
|
|
484
|
-
return await
|
|
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
|
|
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
|
|
493
|
-
let t =
|
|
494
|
-
return t ?
|
|
493
|
+
async function G(e) {
|
|
494
|
+
let t = W();
|
|
495
|
+
return t ? w({
|
|
495
496
|
apiUrl: e,
|
|
496
497
|
apiKey: t
|
|
497
|
-
}) : (await
|
|
498
|
+
}) : (await U(e), w({
|
|
498
499
|
apiUrl: e,
|
|
499
|
-
token: () =>
|
|
500
|
+
token: () => U(e)
|
|
500
501
|
}));
|
|
501
502
|
}
|
|
502
503
|
//#endregion
|
|
503
504
|
//#region src/lib/api-url.ts
|
|
504
|
-
var
|
|
505
|
-
async function
|
|
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
|
|
508
|
-
let n = await
|
|
509
|
-
return
|
|
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
|
|
514
|
-
let t = await
|
|
515
|
-
if (
|
|
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
|
|
518
|
-
await
|
|
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
|
|
529
|
-
let t = await
|
|
530
|
-
return await
|
|
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
|
|
535
|
-
let t = e?.cwd ?? process.cwd(), n = await
|
|
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
|
|
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
|
|
548
|
-
let t = await
|
|
549
|
-
if (
|
|
550
|
-
let n = await
|
|
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
|
|
558
|
-
function
|
|
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
|
|
602
|
+
function Z(e) {
|
|
564
603
|
return typeof e == "object" && !!e && !Array.isArray(e);
|
|
565
604
|
}
|
|
566
|
-
function
|
|
567
|
-
return
|
|
605
|
+
function ht(e) {
|
|
606
|
+
return S("sha256").update(e).digest("hex");
|
|
568
607
|
}
|
|
569
|
-
function
|
|
570
|
-
return m(e,
|
|
608
|
+
function gt(e, t) {
|
|
609
|
+
return m(e, Y, t);
|
|
571
610
|
}
|
|
572
|
-
function
|
|
611
|
+
function _t(e, t) {
|
|
573
612
|
let n = `bundle assets[${String(t)}]`;
|
|
574
|
-
if (!
|
|
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 (!
|
|
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
|
|
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) =>
|
|
638
|
+
return t.map((e, t) => _t(e, t));
|
|
600
639
|
}
|
|
601
|
-
function
|
|
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 =
|
|
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
|
|
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) =>
|
|
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
|
|
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
|
|
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
|
|
629
|
-
let { project: n } = await e.request(
|
|
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
|
|
637
|
-
let { workspaceExport: n } = await e.request(
|
|
638
|
-
if (Q(`Export of workspace ${t}`, n.userErrors), !
|
|
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
|
|
642
|
-
let { projectId: n, fileName: r, mimeType: i, sha256: a, bytes: o } = t, { assetUploadInit: s } = await e.request(
|
|
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(
|
|
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(
|
|
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
|
|
676
|
-
await e.request(
|
|
714
|
+
async function Dt(e, t) {
|
|
715
|
+
await e.request(pe, { input: { id: t } });
|
|
677
716
|
}
|
|
678
|
-
async function
|
|
679
|
-
let { workspaceImport: n } = await e.request(
|
|
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
|
|
684
|
-
let { workspacePublish: n } = await e.request(
|
|
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
|
|
690
|
-
function
|
|
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:
|
|
737
|
+
outDir: X(t, e.out, "--out")
|
|
699
738
|
};
|
|
700
739
|
}
|
|
701
|
-
async function
|
|
740
|
+
async function Mt(e) {
|
|
702
741
|
if ((await s(e).catch((e) => {
|
|
703
|
-
if (
|
|
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
|
|
708
|
-
let t = await fetch(e.downloadUrl, { signal: AbortSignal.timeout(
|
|
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:
|
|
752
|
+
sha256: yt(e, n, e.downloadUrl)
|
|
714
753
|
};
|
|
715
754
|
}
|
|
716
|
-
async function
|
|
717
|
-
await i(m(e,
|
|
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
|
|
721
|
-
await d(
|
|
759
|
+
let { bytes: n, sha256: i } = await Nt(t);
|
|
760
|
+
await d(gt(e, i), n), r.push(i);
|
|
722
761
|
}
|
|
723
|
-
let a =
|
|
724
|
-
await d(m(e,
|
|
762
|
+
let a = bt(t, r);
|
|
763
|
+
await d(m(e, J), `${JSON.stringify(a, null, 2)}\n`);
|
|
725
764
|
}
|
|
726
|
-
async function
|
|
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
|
|
731
|
-
if (!(
|
|
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
|
|
741
|
-
let n = t.workspaceId ?? await
|
|
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
|
|
784
|
+
async function Lt(e) {
|
|
746
785
|
try {
|
|
747
|
-
let t =
|
|
748
|
-
await
|
|
749
|
-
let n = await
|
|
750
|
-
await
|
|
751
|
-
let i =
|
|
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
|
|
761
|
-
let t = m(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 (!
|
|
803
|
+
if (!Z(r)) throw Error(`${t} is not a JSON object.`);
|
|
765
804
|
return r;
|
|
766
805
|
}
|
|
767
|
-
async function
|
|
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 =
|
|
810
|
+
let t = gt(e, r.sha256), i = new Uint8Array(await o(t));
|
|
772
811
|
n.push({
|
|
773
812
|
asset: r,
|
|
774
|
-
sha256:
|
|
813
|
+
sha256: yt(r, i, t),
|
|
775
814
|
bytes: i
|
|
776
815
|
});
|
|
777
816
|
}
|
|
778
817
|
return n;
|
|
779
818
|
}
|
|
780
|
-
async function
|
|
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
|
|
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
|
|
837
|
+
async function Vt(e, t) {
|
|
799
838
|
let n = [], r = [];
|
|
800
839
|
for (let i of t) try {
|
|
801
|
-
await
|
|
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
|
|
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
|
|
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
|
|
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
|
|
823
|
-
return e instanceof
|
|
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
|
|
826
|
-
let n = [], r = await
|
|
827
|
-
throw
|
|
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
|
|
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
|
|
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
|
|
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 =
|
|
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
|
|
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
|
|
863
|
-
async function
|
|
864
|
-
let t = await e.request(
|
|
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
|
|
890
|
-
let r = (await e.request(
|
|
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
|
|
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
|
|
954
|
+
async function $t(e) {
|
|
916
955
|
try {
|
|
917
|
-
let t = await
|
|
918
|
-
return e?.json ? (console.log(JSON.stringify(t, null, 2)), 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
|
|
965
|
+
function en(e, t) {
|
|
927
966
|
return new Promise((n) => {
|
|
928
967
|
e.question(t, n);
|
|
929
968
|
});
|
|
930
969
|
}
|
|
931
|
-
async function
|
|
970
|
+
async function tn(e, t) {
|
|
932
971
|
if (t.length === 0) throw Error("No choices available to select from.");
|
|
933
|
-
let n =
|
|
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
|
|
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
|
|
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
|
|
965
|
-
return n ?
|
|
1003
|
+
async function nn(e, t, n) {
|
|
1004
|
+
return n ? $(t, n, await Zt(e, t, n)) : { projectId: t };
|
|
966
1005
|
}
|
|
967
|
-
async function
|
|
968
|
-
let t = await
|
|
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
|
|
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
|
|
983
|
-
return
|
|
1021
|
+
let i = await Zt(e, t.id, r.id);
|
|
1022
|
+
return $(t.id, r.id, i);
|
|
984
1023
|
}
|
|
985
|
-
function
|
|
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
|
|
1032
|
+
async function on(e) {
|
|
994
1033
|
let t = e?.cwd ?? process.cwd();
|
|
995
1034
|
try {
|
|
996
|
-
let n = await
|
|
997
|
-
return await
|
|
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 {
|
|
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 };
|