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