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