@deessejs/cli 2.3.0 → 3.0.0
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 +26 -7
- package/dist/index.js +881 -208
- package/dist/index.js.map +1 -1
- package/package.json +12 -7
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Command } from 'commander';
|
|
3
3
|
import pc6 from 'picocolors';
|
|
4
|
-
import
|
|
4
|
+
import ora8 from 'ora';
|
|
5
5
|
import { setTimeout as setTimeout$1 } from 'timers/promises';
|
|
6
6
|
import { createAuthClient } from 'better-auth/client';
|
|
7
7
|
import { deviceAuthorizationClient } from 'better-auth/client/plugins';
|
|
@@ -18,8 +18,10 @@ import Qr, { EventEmitter } from 'events';
|
|
|
18
18
|
import { StringDecoder } from 'string_decoder';
|
|
19
19
|
import zi from 'assert';
|
|
20
20
|
import { Buffer as Buffer$1 } from 'buffer';
|
|
21
|
-
import { randomBytes } from 'crypto';
|
|
21
|
+
import { createHash, randomBytes } from 'crypto';
|
|
22
22
|
import * as crossSpawn from 'cross-spawn';
|
|
23
|
+
import { error as error$1 } from '@deessejs/errors';
|
|
24
|
+
import { ok, pipe as pipe$1, map as map$1, flatMap, err } from '@deessejs/fp';
|
|
23
25
|
import { createORPCClient, toORPCError } from '@orpc/client';
|
|
24
26
|
import { RetryAfterPlugin, ClientRetryPlugin } from '@orpc/client/plugins';
|
|
25
27
|
import { RPCLink } from '@orpc/client/fetch';
|
|
@@ -1798,8 +1800,8 @@ var require_picomatch = __commonJS({
|
|
|
1798
1800
|
try {
|
|
1799
1801
|
const opts = options || {};
|
|
1800
1802
|
return new RegExp(source, opts.flags || (opts.nocase ? "i" : ""));
|
|
1801
|
-
} catch (
|
|
1802
|
-
if (options && options.debug === true) throw
|
|
1803
|
+
} catch (err2) {
|
|
1804
|
+
if (options && options.debug === true) throw err2;
|
|
1803
1805
|
return /$^/;
|
|
1804
1806
|
}
|
|
1805
1807
|
};
|
|
@@ -1825,7 +1827,7 @@ var require_picomatch2 = __commonJS({
|
|
|
1825
1827
|
});
|
|
1826
1828
|
|
|
1827
1829
|
// src/api/self-version.ts
|
|
1828
|
-
var readPackageVersion = () => "
|
|
1830
|
+
var readPackageVersion = () => "3.0.0";
|
|
1829
1831
|
|
|
1830
1832
|
// src/constants/exit.ts
|
|
1831
1833
|
var EXIT_ERROR = 1;
|
|
@@ -1837,6 +1839,9 @@ var networkError = (detail) => new CliError(
|
|
|
1837
1839
|
detail
|
|
1838
1840
|
);
|
|
1839
1841
|
|
|
1842
|
+
// src/errors/parse.ts
|
|
1843
|
+
var parseError = (detail, message = "templates endpoint returned malformed data") => new CliError("parse_error", message, detail);
|
|
1844
|
+
|
|
1840
1845
|
// src/errors/not-found.ts
|
|
1841
1846
|
var notFound = (slug, available) => new CliError(
|
|
1842
1847
|
"not_found",
|
|
@@ -1862,8 +1867,8 @@ var cliDeviceExpired = (reason) => new CliError(
|
|
|
1862
1867
|
var CliError = class extends Error {
|
|
1863
1868
|
code;
|
|
1864
1869
|
hint;
|
|
1865
|
-
constructor(code, message, hint) {
|
|
1866
|
-
super(message);
|
|
1870
|
+
constructor(code, message, hint, cause) {
|
|
1871
|
+
super(message, cause ? { cause } : void 0);
|
|
1867
1872
|
this.name = "CliError";
|
|
1868
1873
|
this.code = code;
|
|
1869
1874
|
this.hint = hint;
|
|
@@ -1885,10 +1890,11 @@ var invalidTarget = (dir, detail) => new CliError(
|
|
|
1885
1890
|
`target path "${dir}" cannot be used safely`,
|
|
1886
1891
|
detail
|
|
1887
1892
|
);
|
|
1888
|
-
var templateInvalid = (repository, detail) => new CliError(
|
|
1893
|
+
var templateInvalid = (repository, detail, cause) => new CliError(
|
|
1889
1894
|
"template_invalid",
|
|
1890
1895
|
`template source "${repository}" cannot be installed`,
|
|
1891
|
-
detail
|
|
1896
|
+
detail,
|
|
1897
|
+
cause
|
|
1892
1898
|
);
|
|
1893
1899
|
var blockInvalid = (source, detail) => new CliError("block_invalid", `block source "${source}" is invalid`, detail);
|
|
1894
1900
|
var repositoryNotFound = (repository) => new CliError(
|
|
@@ -2000,11 +2006,11 @@ function readStringProperty(value, key) {
|
|
|
2000
2006
|
}
|
|
2001
2007
|
var requestDeviceCode = async () => {
|
|
2002
2008
|
const authClient = createCliAuthClient();
|
|
2003
|
-
const { data, error:
|
|
2009
|
+
const { data, error: error52 } = await authClient.device.code({
|
|
2004
2010
|
client_id: "deessejs-cli"
|
|
2005
2011
|
});
|
|
2006
|
-
if (
|
|
2007
|
-
const description = readStringProperty(
|
|
2012
|
+
if (error52 || !data) {
|
|
2013
|
+
const description = readStringProperty(error52, "error_description") ?? "unknown error";
|
|
2008
2014
|
throw cliDeviceExpired(`could not obtain a device code: ${description}`);
|
|
2009
2015
|
}
|
|
2010
2016
|
return {
|
|
@@ -2021,7 +2027,7 @@ var pollForToken = async (deviceCode, expiresBy) => {
|
|
|
2021
2027
|
}
|
|
2022
2028
|
await sleep(interval);
|
|
2023
2029
|
const authClient = createCliAuthClient();
|
|
2024
|
-
const { data, error:
|
|
2030
|
+
const { data, error: error52 } = await authClient.device.token({
|
|
2025
2031
|
grant_type: "urn:ietf:params:oauth:grant-type:device_code",
|
|
2026
2032
|
device_code: deviceCode,
|
|
2027
2033
|
client_id: "deessejs-cli"
|
|
@@ -2035,7 +2041,7 @@ var pollForToken = async (deviceCode, expiresBy) => {
|
|
|
2035
2041
|
}
|
|
2036
2042
|
return { accessToken: token };
|
|
2037
2043
|
}
|
|
2038
|
-
const code = readStringProperty(
|
|
2044
|
+
const code = readStringProperty(error52, "error");
|
|
2039
2045
|
if (!code) {
|
|
2040
2046
|
throw cliDeviceExpired(
|
|
2041
2047
|
"token endpoint returned no data and no error code"
|
|
@@ -2150,6 +2156,41 @@ var printTemplatesTable = (templates) => {
|
|
|
2150
2156
|
const rows = templates.map((t) => [t.slug, t.name, t.category, t.license]);
|
|
2151
2157
|
printAlignedTable([headers, ...rows]);
|
|
2152
2158
|
};
|
|
2159
|
+
var printOrganizationsTable = (organizations) => {
|
|
2160
|
+
if (organizations.length === 0) {
|
|
2161
|
+
process.stdout.write(pc6.dim("No organizations found.\n"));
|
|
2162
|
+
return;
|
|
2163
|
+
}
|
|
2164
|
+
const rows = organizations.map((organization) => [
|
|
2165
|
+
organization.name,
|
|
2166
|
+
organization.slug
|
|
2167
|
+
]);
|
|
2168
|
+
printAlignedTable([["name", "slug"], ...rows]);
|
|
2169
|
+
};
|
|
2170
|
+
var printOrganizationTemplatesTable = (templates) => {
|
|
2171
|
+
if (templates.length === 0) {
|
|
2172
|
+
process.stdout.write(pc6.dim("No organization templates found.\n"));
|
|
2173
|
+
return;
|
|
2174
|
+
}
|
|
2175
|
+
const headers = ["slug", "name", "ownership", "publication", "review"];
|
|
2176
|
+
const rows = templates.map((template) => [
|
|
2177
|
+
template.slug,
|
|
2178
|
+
template.name,
|
|
2179
|
+
"organization-owned",
|
|
2180
|
+
template.currentlyPublished ? "current" : template.publication?.publicationState ?? "unpublished",
|
|
2181
|
+
template.publication?.reviewStatus ?? "not submitted"
|
|
2182
|
+
]);
|
|
2183
|
+
printAlignedTable([headers, ...rows]);
|
|
2184
|
+
};
|
|
2185
|
+
var printOrganizationInfo = (organization) => {
|
|
2186
|
+
printKeyValueSection("Organization", [
|
|
2187
|
+
["name", organization.name],
|
|
2188
|
+
["slug", organization.slug],
|
|
2189
|
+
["role", organization.role],
|
|
2190
|
+
["id", organization.id],
|
|
2191
|
+
["logo", organization.logo ?? "(none)"]
|
|
2192
|
+
]);
|
|
2193
|
+
};
|
|
2153
2194
|
var printTemplateInfo = (descriptor, source) => {
|
|
2154
2195
|
const descriptorLines = [
|
|
2155
2196
|
["name", descriptor.name],
|
|
@@ -2288,18 +2329,18 @@ var printAlignedTable = (rows) => {
|
|
|
2288
2329
|
var printJson = (value) => {
|
|
2289
2330
|
process.stdout.write(JSON.stringify(value, null, 2) + "\n");
|
|
2290
2331
|
};
|
|
2291
|
-
var printError = (
|
|
2332
|
+
var printError = (err2) => {
|
|
2292
2333
|
process.stderr.write(
|
|
2293
|
-
`${pc6.red("Error")}: ${
|
|
2294
|
-
` + (
|
|
2295
|
-
` : "") + `${pc6.dim("Code")}: ${
|
|
2334
|
+
`${pc6.red("Error")}: ${err2.message}
|
|
2335
|
+
` + (err2.hint ? `${pc6.dim("Hint")}: ${err2.hint}
|
|
2336
|
+
` : "") + `${pc6.dim("Code")}: ${err2.code}
|
|
2296
2337
|
`
|
|
2297
2338
|
);
|
|
2298
2339
|
};
|
|
2299
2340
|
|
|
2300
2341
|
// src/commands/auth/login.ts
|
|
2301
2342
|
var loginCommand = new Command("login").description("Authorize this machine against the DeesseJS server").option("--json", "JSON output for scripting").action(async (opts) => {
|
|
2302
|
-
const spinner = opts.json ? null :
|
|
2343
|
+
const spinner = opts.json ? null : ora8("Requesting device code...").start();
|
|
2303
2344
|
try {
|
|
2304
2345
|
const issued = await requestDeviceCode();
|
|
2305
2346
|
spinner?.stop();
|
|
@@ -2314,7 +2355,7 @@ var loginCommand = new Command("login").description("Authorize this machine agai
|
|
|
2314
2355
|
console.log();
|
|
2315
2356
|
}
|
|
2316
2357
|
await openVerificationUrl(issued.url);
|
|
2317
|
-
const pollSpinner = opts.json ? null :
|
|
2358
|
+
const pollSpinner = opts.json ? null : ora8("Waiting for browser approval...").start();
|
|
2318
2359
|
try {
|
|
2319
2360
|
const token = await pollForToken(issued.deviceCode, issued.expiresBy);
|
|
2320
2361
|
const user = await fetchUserIdentity(token.accessToken);
|
|
@@ -2338,13 +2379,13 @@ var loginCommand = new Command("login").description("Authorize this machine agai
|
|
|
2338
2379
|
} catch (e) {
|
|
2339
2380
|
spinner?.stop();
|
|
2340
2381
|
if (e instanceof CliError) {
|
|
2341
|
-
const
|
|
2382
|
+
const err2 = e;
|
|
2342
2383
|
if (opts.json) {
|
|
2343
|
-
printJson({ ok: false, code:
|
|
2384
|
+
printJson({ ok: false, code: err2.code, message: err2.message });
|
|
2344
2385
|
} else {
|
|
2345
|
-
printError(
|
|
2386
|
+
printError(err2);
|
|
2346
2387
|
}
|
|
2347
|
-
throw
|
|
2388
|
+
throw err2;
|
|
2348
2389
|
}
|
|
2349
2390
|
throw e;
|
|
2350
2391
|
}
|
|
@@ -2390,7 +2431,7 @@ var statusCommand = new Command("status").description("Show the current CLI auth
|
|
|
2390
2431
|
}
|
|
2391
2432
|
return;
|
|
2392
2433
|
}
|
|
2393
|
-
const spinner = opts.json ? null :
|
|
2434
|
+
const spinner = opts.json ? null : ora8("Checking session...").start();
|
|
2394
2435
|
try {
|
|
2395
2436
|
const user = await validateSession(stored.access_token);
|
|
2396
2437
|
if (!user) {
|
|
@@ -2436,7 +2477,7 @@ var logoutCommand = new Command("logout").description("Sign out this machine and
|
|
|
2436
2477
|
}
|
|
2437
2478
|
return;
|
|
2438
2479
|
}
|
|
2439
|
-
const spinner = opts.json ? null :
|
|
2480
|
+
const spinner = opts.json ? null : ora8("Signing out...").start();
|
|
2440
2481
|
try {
|
|
2441
2482
|
const res = await bearerFetch("sign-out", stored.access_token, {
|
|
2442
2483
|
method: "POST",
|
|
@@ -3779,10 +3820,10 @@ var initializer = (inst, def) => {
|
|
|
3779
3820
|
};
|
|
3780
3821
|
var $ZodError = $constructor("$ZodError", initializer);
|
|
3781
3822
|
var $ZodRealError = $constructor("$ZodError", initializer, { Parent: Error });
|
|
3782
|
-
function flattenError(
|
|
3823
|
+
function flattenError(error52, mapper = (issue2) => issue2.message) {
|
|
3783
3824
|
const fieldErrors = {};
|
|
3784
3825
|
const formErrors = [];
|
|
3785
|
-
for (const sub of
|
|
3826
|
+
for (const sub of error52.issues) {
|
|
3786
3827
|
if (sub.path.length > 0) {
|
|
3787
3828
|
fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
|
|
3788
3829
|
fieldErrors[sub.path[0]].push(mapper(sub));
|
|
@@ -3792,10 +3833,10 @@ function flattenError(error51, mapper = (issue2) => issue2.message) {
|
|
|
3792
3833
|
}
|
|
3793
3834
|
return { formErrors, fieldErrors };
|
|
3794
3835
|
}
|
|
3795
|
-
function formatError(
|
|
3836
|
+
function formatError(error52, mapper = (issue2) => issue2.message) {
|
|
3796
3837
|
const fieldErrors = { _errors: [] };
|
|
3797
|
-
const processError = (
|
|
3798
|
-
for (const issue2 of
|
|
3838
|
+
const processError = (error53, path = []) => {
|
|
3839
|
+
for (const issue2 of error53.issues) {
|
|
3799
3840
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
3800
3841
|
issue2.errors.map((issues) => processError({ issues }, [...path, ...issue2.path]));
|
|
3801
3842
|
} else if (issue2.code === "invalid_key") {
|
|
@@ -3825,14 +3866,14 @@ function formatError(error51, mapper = (issue2) => issue2.message) {
|
|
|
3825
3866
|
}
|
|
3826
3867
|
}
|
|
3827
3868
|
};
|
|
3828
|
-
processError(
|
|
3869
|
+
processError(error52);
|
|
3829
3870
|
return fieldErrors;
|
|
3830
3871
|
}
|
|
3831
|
-
function treeifyError(
|
|
3872
|
+
function treeifyError(error52, mapper = (issue2) => issue2.message) {
|
|
3832
3873
|
const result = { errors: [] };
|
|
3833
|
-
const processError = (
|
|
3874
|
+
const processError = (error53, path = []) => {
|
|
3834
3875
|
var _a3, _b;
|
|
3835
|
-
for (const issue2 of
|
|
3876
|
+
for (const issue2 of error53.issues) {
|
|
3836
3877
|
if (issue2.code === "invalid_union" && issue2.errors.length) {
|
|
3837
3878
|
issue2.errors.map((issues) => processError({ issues }, [...path, ...issue2.path]));
|
|
3838
3879
|
} else if (issue2.code === "invalid_key") {
|
|
@@ -3867,7 +3908,7 @@ function treeifyError(error51, mapper = (issue2) => issue2.message) {
|
|
|
3867
3908
|
}
|
|
3868
3909
|
}
|
|
3869
3910
|
};
|
|
3870
|
-
processError(
|
|
3911
|
+
processError(error52);
|
|
3871
3912
|
return result;
|
|
3872
3913
|
}
|
|
3873
3914
|
function toDotPath(_path) {
|
|
@@ -3888,9 +3929,9 @@ function toDotPath(_path) {
|
|
|
3888
3929
|
}
|
|
3889
3930
|
return segs.join("");
|
|
3890
3931
|
}
|
|
3891
|
-
function prettifyError(
|
|
3932
|
+
function prettifyError(error52) {
|
|
3892
3933
|
const lines = [];
|
|
3893
|
-
const issues = [...
|
|
3934
|
+
const issues = [...error52.issues].sort((a, b2) => (a.path ?? []).length - (b2.path ?? []).length);
|
|
3894
3935
|
for (const issue2 of issues) {
|
|
3895
3936
|
lines.push(`\u2716 ${issue2.message}`);
|
|
3896
3937
|
if (issue2.path?.length)
|
|
@@ -5805,19 +5846,19 @@ var $ZodDiscriminatedUnion = /* @__PURE__ */ $constructor("$ZodDiscriminatedUnio
|
|
|
5805
5846
|
});
|
|
5806
5847
|
const disc = cached(() => {
|
|
5807
5848
|
const opts = def.options;
|
|
5808
|
-
const
|
|
5849
|
+
const map3 = /* @__PURE__ */ new Map();
|
|
5809
5850
|
for (const o of opts) {
|
|
5810
5851
|
const values = o._zod.propValues?.[def.discriminator];
|
|
5811
5852
|
if (!values || values.size === 0)
|
|
5812
5853
|
throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(o)}"`);
|
|
5813
5854
|
for (const v2 of values) {
|
|
5814
|
-
if (
|
|
5855
|
+
if (map3.has(v2)) {
|
|
5815
5856
|
throw new Error(`Duplicate discriminator value "${String(v2)}"`);
|
|
5816
5857
|
}
|
|
5817
|
-
|
|
5858
|
+
map3.set(v2, o);
|
|
5818
5859
|
}
|
|
5819
5860
|
}
|
|
5820
|
-
return
|
|
5861
|
+
return map3;
|
|
5821
5862
|
});
|
|
5822
5863
|
inst._zod.parse = (payload, ctx) => {
|
|
5823
5864
|
const input = payload.value;
|
|
@@ -16454,9 +16495,9 @@ var ZodIssueCode = {
|
|
|
16454
16495
|
invalid_value: "invalid_value",
|
|
16455
16496
|
custom: "custom"
|
|
16456
16497
|
};
|
|
16457
|
-
function setErrorMap(
|
|
16498
|
+
function setErrorMap(map3) {
|
|
16458
16499
|
config({
|
|
16459
|
-
customError:
|
|
16500
|
+
customError: map3
|
|
16460
16501
|
});
|
|
16461
16502
|
}
|
|
16462
16503
|
function getErrorMap() {
|
|
@@ -17052,9 +17093,9 @@ function isValidSemver(value) {
|
|
|
17052
17093
|
const numbers = core.split(".");
|
|
17053
17094
|
return numbers.length === 3 && numbers.every((number4) => /^(0|[1-9]\d*)$/.test(number4));
|
|
17054
17095
|
}
|
|
17055
|
-
function getSchemaDiagnostics(input,
|
|
17096
|
+
function getSchemaDiagnostics(input, error52) {
|
|
17056
17097
|
const diagnostics = [];
|
|
17057
|
-
for (const issue2 of
|
|
17098
|
+
for (const issue2 of error52.issues) {
|
|
17058
17099
|
if (issue2.code === "unrecognized_keys") {
|
|
17059
17100
|
diagnostics.push(...issue2.keys.map((key) => ({
|
|
17060
17101
|
code: "descriptor.unknown_field",
|
|
@@ -17285,9 +17326,9 @@ function parseTemplateDescriptor(input) {
|
|
|
17285
17326
|
})));
|
|
17286
17327
|
continue;
|
|
17287
17328
|
}
|
|
17288
|
-
const
|
|
17329
|
+
const isUnsupportedFormatVersion3 = isUnsupportedFormatVersionIssue(issue2.path, input);
|
|
17289
17330
|
diagnostics.push({
|
|
17290
|
-
code:
|
|
17331
|
+
code: isUnsupportedFormatVersion3 ? "descriptor.unsupported_format_version" : "descriptor.invalid_field",
|
|
17291
17332
|
message: issue2.message,
|
|
17292
17333
|
path: issue2.path.map(String)
|
|
17293
17334
|
});
|
|
@@ -20256,8 +20297,8 @@ function createTemplateSourceError(code, message, path) {
|
|
|
20256
20297
|
...path ? { path } : {}
|
|
20257
20298
|
});
|
|
20258
20299
|
}
|
|
20259
|
-
function isTemplateSourceError(
|
|
20260
|
-
return
|
|
20300
|
+
function isTemplateSourceError(error52) {
|
|
20301
|
+
return error52 instanceof Error && "code" in error52 && typeof error52.code === "string" && error52.code.startsWith("source.");
|
|
20261
20302
|
}
|
|
20262
20303
|
var GITHUB_API_BASE_URL = "https://api.github.com";
|
|
20263
20304
|
var GITHUB_API_VERSION = "2022-11-28";
|
|
@@ -20272,12 +20313,12 @@ async function retryWithBackoff(options) {
|
|
|
20272
20313
|
for (let attempt = 0; attempt <= options.retryCount; attempt += 1) {
|
|
20273
20314
|
try {
|
|
20274
20315
|
return await options.operation(attempt);
|
|
20275
|
-
} catch (
|
|
20276
|
-
lastError =
|
|
20277
|
-
if (!options.shouldRetry(
|
|
20278
|
-
throw
|
|
20316
|
+
} catch (error52) {
|
|
20317
|
+
lastError = error52;
|
|
20318
|
+
if (!options.shouldRetry(error52, attempt))
|
|
20319
|
+
throw error52;
|
|
20279
20320
|
if (attempt === options.retryCount)
|
|
20280
|
-
throw options.failure(
|
|
20321
|
+
throw options.failure(error52);
|
|
20281
20322
|
await new Promise((resolve4) => setTimeout(resolve4, 200 * 2 ** attempt));
|
|
20282
20323
|
}
|
|
20283
20324
|
}
|
|
@@ -20317,11 +20358,11 @@ async function downloadArchive(response, archivePath, maxArchiveSizeBytes) {
|
|
|
20317
20358
|
});
|
|
20318
20359
|
try {
|
|
20319
20360
|
await pipeline(Readable.fromWeb(response.body), limit, createWriteStream(archivePath, { flags: "wx" }));
|
|
20320
|
-
} catch (
|
|
20321
|
-
if (String(
|
|
20322
|
-
throw createTemplateSourceError("source.inventory_limit_exceeded", String(
|
|
20361
|
+
} catch (error52) {
|
|
20362
|
+
if (String(error52).includes("download limit")) {
|
|
20363
|
+
throw createTemplateSourceError("source.inventory_limit_exceeded", String(error52));
|
|
20323
20364
|
}
|
|
20324
|
-
throw
|
|
20365
|
+
throw error52;
|
|
20325
20366
|
}
|
|
20326
20367
|
}
|
|
20327
20368
|
async function decompressArchive(archivePath, root) {
|
|
@@ -20339,11 +20380,11 @@ async function decompressArchive(archivePath, root) {
|
|
|
20339
20380
|
});
|
|
20340
20381
|
try {
|
|
20341
20382
|
await pipeline(createReadStream(archivePath), createGunzip(), limit, createWriteStream(tarPath, { flags: "wx" }));
|
|
20342
|
-
} catch (
|
|
20343
|
-
if (String(
|
|
20344
|
-
throw createTemplateSourceError("source.inventory_limit_exceeded", String(
|
|
20383
|
+
} catch (error52) {
|
|
20384
|
+
if (String(error52).includes("expands beyond")) {
|
|
20385
|
+
throw createTemplateSourceError("source.inventory_limit_exceeded", String(error52));
|
|
20345
20386
|
}
|
|
20346
|
-
throw createTemplateSourceError("source.invalid_response", `GitHub returned an invalid gzip source archive: ${String(
|
|
20387
|
+
throw createTemplateSourceError("source.invalid_response", `GitHub returned an invalid gzip source archive: ${String(error52)}.`);
|
|
20347
20388
|
}
|
|
20348
20389
|
return tarPath;
|
|
20349
20390
|
}
|
|
@@ -20353,8 +20394,8 @@ async function readArchiveSnapshot(archivePath, root, repository, revision, expe
|
|
|
20353
20394
|
let archiveRoot;
|
|
20354
20395
|
const tarPath = await decompressArchive(archivePath, root);
|
|
20355
20396
|
let inventoryError;
|
|
20356
|
-
const failInventory = (
|
|
20357
|
-
inventoryError =
|
|
20397
|
+
const failInventory = (error52) => {
|
|
20398
|
+
inventoryError = error52;
|
|
20358
20399
|
};
|
|
20359
20400
|
await Ct({
|
|
20360
20401
|
file: tarPath,
|
|
@@ -20493,15 +20534,15 @@ function parseRepository(repository) {
|
|
|
20493
20534
|
function isSha(value) {
|
|
20494
20535
|
return typeof value === "string" && /^[a-f0-9]{40}$/i.test(value);
|
|
20495
20536
|
}
|
|
20496
|
-
function shouldRetryJsonRequest(
|
|
20497
|
-
if (!isTemplateSourceError(
|
|
20537
|
+
function shouldRetryJsonRequest(error52) {
|
|
20538
|
+
if (!isTemplateSourceError(error52))
|
|
20498
20539
|
return true;
|
|
20499
|
-
return
|
|
20540
|
+
return error52.message.includes("HTTP 429") || /HTTP 5\d\d/.test(error52.message);
|
|
20500
20541
|
}
|
|
20501
|
-
function shouldRetryDescriptorRequest(
|
|
20502
|
-
if (!isTemplateSourceError(
|
|
20542
|
+
function shouldRetryDescriptorRequest(error52) {
|
|
20543
|
+
if (!isTemplateSourceError(error52))
|
|
20503
20544
|
return true;
|
|
20504
|
-
return
|
|
20545
|
+
return error52.code === "source.unavailable" && (error52.message.includes("HTTP 429") || /HTTP 5\d\d/.test(error52.message));
|
|
20505
20546
|
}
|
|
20506
20547
|
async function requestJson(url2, request, timeoutMs, _attempt) {
|
|
20507
20548
|
const controller = new AbortController();
|
|
@@ -20532,7 +20573,7 @@ function createGitHubTemplateSourceAdapter(options = {}) {
|
|
|
20532
20573
|
retryCount,
|
|
20533
20574
|
operation: (attempt) => requestJson(url2, request, requestTimeoutMs),
|
|
20534
20575
|
shouldRetry: shouldRetryJsonRequest,
|
|
20535
|
-
failure: (
|
|
20576
|
+
failure: (error52) => isTemplateSourceError(error52) ? error52 : createTemplateSourceError("source.unavailable", `GitHub could not be reached after ${retryCount + 1} attempts: ${String(error52)}.`)
|
|
20536
20577
|
});
|
|
20537
20578
|
}
|
|
20538
20579
|
async function resolveRevision(repository, ref) {
|
|
@@ -20586,7 +20627,7 @@ function createGitHubTemplateSourceAdapter(options = {}) {
|
|
|
20586
20627
|
retryCount,
|
|
20587
20628
|
operation: () => fetchRemoteDescriptor(url2, repository, request, requestTimeoutMs),
|
|
20588
20629
|
shouldRetry: shouldRetryDescriptorRequest,
|
|
20589
|
-
failure: (
|
|
20630
|
+
failure: (error52) => isTemplateSourceError(error52) ? error52 : createTemplateSourceError("source.unavailable", `GitHub could not read the root descriptor from ${repository}${ref ? ` at ref ${ref}` : ""}: ${String(error52)}.`)
|
|
20590
20631
|
});
|
|
20591
20632
|
}
|
|
20592
20633
|
async function fetchRemoteDescriptor(url2, repository, fetcher, timeoutMs) {
|
|
@@ -20640,14 +20681,14 @@ function createGitHubTemplateSourceAdapter(options = {}) {
|
|
|
20640
20681
|
try {
|
|
20641
20682
|
const contents = await readRemoteDescriptor(canonical, source.ref);
|
|
20642
20683
|
return { repository: canonical, contents };
|
|
20643
|
-
} catch (
|
|
20644
|
-
if (!isTemplateSourceError(
|
|
20645
|
-
throw
|
|
20684
|
+
} catch (error52) {
|
|
20685
|
+
if (!isTemplateSourceError(error52) || error52.code !== "source.file_not_found") {
|
|
20686
|
+
throw error52;
|
|
20646
20687
|
}
|
|
20647
20688
|
if (!await repositoryExists(canonical)) {
|
|
20648
20689
|
throw createTemplateSourceError("source.repository_not_found", `GitHub repository "${canonical}" does not exist or is not publicly accessible.`);
|
|
20649
20690
|
}
|
|
20650
|
-
throw
|
|
20691
|
+
throw error52;
|
|
20651
20692
|
}
|
|
20652
20693
|
},
|
|
20653
20694
|
async resolve(source) {
|
|
@@ -20673,10 +20714,10 @@ function createGitHubTemplateSourceAdapter(options = {}) {
|
|
|
20673
20714
|
throw createTemplateSourceError("source.unavailable", `GitHub returned HTTP ${response.status} while downloading ${canonical}@${revision}.`);
|
|
20674
20715
|
}
|
|
20675
20716
|
await downloadArchive(response, archivePath, MAX_ARCHIVE_SIZE_BYTES);
|
|
20676
|
-
} catch (
|
|
20677
|
-
if (isTemplateSourceError(
|
|
20678
|
-
throw
|
|
20679
|
-
throw createTemplateSourceError("source.unavailable", `GitHub could not download ${canonical}@${revision}: ${String(
|
|
20717
|
+
} catch (error52) {
|
|
20718
|
+
if (isTemplateSourceError(error52))
|
|
20719
|
+
throw error52;
|
|
20720
|
+
throw createTemplateSourceError("source.unavailable", `GitHub could not download ${canonical}@${revision}: ${String(error52)}.`);
|
|
20680
20721
|
} finally {
|
|
20681
20722
|
clearTimeout(timeout);
|
|
20682
20723
|
}
|
|
@@ -20772,12 +20813,12 @@ async function readDescriptor(snapshot) {
|
|
|
20772
20813
|
try {
|
|
20773
20814
|
const bytes = await snapshot.readFile(DESCRIPTOR_PATH);
|
|
20774
20815
|
return parseDescriptorBytes(bytes);
|
|
20775
|
-
} catch (
|
|
20776
|
-
if (isTemplateSourceError(
|
|
20777
|
-
throw
|
|
20816
|
+
} catch (error52) {
|
|
20817
|
+
if (isTemplateSourceError(error52))
|
|
20818
|
+
throw error52;
|
|
20778
20819
|
return {
|
|
20779
20820
|
success: false,
|
|
20780
|
-
diagnostic: diagnostic("descriptor.invalid_json", `The root ${DESCRIPTOR_PATH} is not valid UTF-8 JSON: ${String(
|
|
20821
|
+
diagnostic: diagnostic("descriptor.invalid_json", `The root ${DESCRIPTOR_PATH} is not valid UTF-8 JSON: ${String(error52)}.`, [DESCRIPTOR_PATH])
|
|
20781
20822
|
};
|
|
20782
20823
|
}
|
|
20783
20824
|
}
|
|
@@ -20785,10 +20826,10 @@ function parseDescriptorBytes(bytes) {
|
|
|
20785
20826
|
try {
|
|
20786
20827
|
const json2 = new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
20787
20828
|
return { success: true, input: JSON.parse(json2) };
|
|
20788
|
-
} catch (
|
|
20829
|
+
} catch (error52) {
|
|
20789
20830
|
return {
|
|
20790
20831
|
success: false,
|
|
20791
|
-
diagnostic: diagnostic("descriptor.invalid_json", `The root ${DESCRIPTOR_PATH} is not valid UTF-8 JSON: ${String(
|
|
20832
|
+
diagnostic: diagnostic("descriptor.invalid_json", `The root ${DESCRIPTOR_PATH} is not valid UTF-8 JSON: ${String(error52)}.`, [DESCRIPTOR_PATH])
|
|
20792
20833
|
};
|
|
20793
20834
|
}
|
|
20794
20835
|
}
|
|
@@ -20811,9 +20852,9 @@ async function validateDescriptorRef(descriptor, snapshot, resolveRevision) {
|
|
|
20811
20852
|
return [
|
|
20812
20853
|
diagnostic("descriptor.source_ref_mismatch", `The descriptor ref "${descriptor.source.ref}" resolves to ${descriptorRevision}, while the selected source resolves to ${snapshot.revision}.`, ["source", "ref"])
|
|
20813
20854
|
];
|
|
20814
|
-
} catch (
|
|
20855
|
+
} catch (error52) {
|
|
20815
20856
|
return [
|
|
20816
|
-
diagnostic("descriptor.source_ref_mismatch", `The descriptor ref "${descriptor.source.ref}" could not be resolved against the selected repository: ${String(
|
|
20857
|
+
diagnostic("descriptor.source_ref_mismatch", `The descriptor ref "${descriptor.source.ref}" could not be resolved against the selected repository: ${String(error52)}.`, ["source", "ref"])
|
|
20817
20858
|
];
|
|
20818
20859
|
}
|
|
20819
20860
|
}
|
|
@@ -20869,11 +20910,11 @@ function validateSelectedEntry(entry) {
|
|
|
20869
20910
|
}
|
|
20870
20911
|
return null;
|
|
20871
20912
|
}
|
|
20872
|
-
function toDiagnostic(
|
|
20873
|
-
if (isTemplateSourceError(
|
|
20874
|
-
return diagnostic(
|
|
20913
|
+
function toDiagnostic(error52) {
|
|
20914
|
+
if (isTemplateSourceError(error52)) {
|
|
20915
|
+
return diagnostic(error52.code, error52.message, error52.path ? [error52.path] : []);
|
|
20875
20916
|
}
|
|
20876
|
-
return diagnostic("source.unavailable", `The template source could not be resolved: ${String(
|
|
20917
|
+
return diagnostic("source.unavailable", `The template source could not be resolved: ${String(error52)}.`);
|
|
20877
20918
|
}
|
|
20878
20919
|
async function validateDescriptorSnapshot(request, snapshot) {
|
|
20879
20920
|
const readResult = parseDescriptorBytes(snapshot.contents);
|
|
@@ -20902,8 +20943,8 @@ async function createTemplateDescriptorInfo(request, adapter) {
|
|
|
20902
20943
|
let snapshot;
|
|
20903
20944
|
try {
|
|
20904
20945
|
snapshot = await adapter.resolveDescriptor(request);
|
|
20905
|
-
} catch (
|
|
20906
|
-
if (isTemplateSourceError(
|
|
20946
|
+
} catch (error52) {
|
|
20947
|
+
if (isTemplateSourceError(error52) && error52.code === "source.file_not_found" && error52.path === DESCRIPTOR_PATH) {
|
|
20907
20948
|
return {
|
|
20908
20949
|
success: false,
|
|
20909
20950
|
diagnostics: [
|
|
@@ -20911,7 +20952,7 @@ async function createTemplateDescriptorInfo(request, adapter) {
|
|
|
20911
20952
|
]
|
|
20912
20953
|
};
|
|
20913
20954
|
}
|
|
20914
|
-
return { success: false, diagnostics: [toDiagnostic(
|
|
20955
|
+
return { success: false, diagnostics: [toDiagnostic(error52)] };
|
|
20915
20956
|
}
|
|
20916
20957
|
const validated = await validateDescriptorSnapshot(request, snapshot);
|
|
20917
20958
|
if (!validated.success)
|
|
@@ -20930,14 +20971,14 @@ async function createTemplateInstallationPlan(request, adapter) {
|
|
|
20930
20971
|
let snapshot;
|
|
20931
20972
|
try {
|
|
20932
20973
|
snapshot = await adapter.resolve(request);
|
|
20933
|
-
} catch (
|
|
20934
|
-
return { success: false, diagnostics: [toDiagnostic(
|
|
20974
|
+
} catch (error52) {
|
|
20975
|
+
return { success: false, diagnostics: [toDiagnostic(error52)] };
|
|
20935
20976
|
}
|
|
20936
20977
|
let descriptorResult;
|
|
20937
20978
|
try {
|
|
20938
20979
|
descriptorResult = await readDescriptor(snapshot);
|
|
20939
|
-
} catch (
|
|
20940
|
-
return { success: false, diagnostics: [toDiagnostic(
|
|
20980
|
+
} catch (error52) {
|
|
20981
|
+
return { success: false, diagnostics: [toDiagnostic(error52)] };
|
|
20941
20982
|
}
|
|
20942
20983
|
if (!descriptorResult.success) {
|
|
20943
20984
|
return { success: false, diagnostics: [descriptorResult.diagnostic] };
|
|
@@ -20990,8 +21031,8 @@ async function createTemplateInstallationPlan(request, adapter) {
|
|
|
20990
21031
|
};
|
|
20991
21032
|
}
|
|
20992
21033
|
files.push({ path: entry.path, contents });
|
|
20993
|
-
} catch (
|
|
20994
|
-
return { success: false, diagnostics: [toDiagnostic(
|
|
21034
|
+
} catch (error52) {
|
|
21035
|
+
return { success: false, diagnostics: [toDiagnostic(error52)] };
|
|
20995
21036
|
}
|
|
20996
21037
|
}
|
|
20997
21038
|
return {
|
|
@@ -21011,12 +21052,141 @@ var ROLE_IDENTIFIER_SCHEMA = external_exports.string().regex(ROLE_IDENTIFIER_PAT
|
|
|
21011
21052
|
var IMPORT_ROOT_SCHEMA = external_exports.string().min(1).regex(new RegExp("^\\P{Cc}+$", "u"));
|
|
21012
21053
|
var ProjectPathsV1Schema = external_exports.record(ROLE_IDENTIFIER_SCHEMA, external_exports.string().min(1));
|
|
21013
21054
|
var ProjectAliasesV1Schema = external_exports.record(ROLE_IDENTIFIER_SCHEMA, IMPORT_ROOT_SCHEMA);
|
|
21014
|
-
external_exports.strictObject({
|
|
21055
|
+
var ProjectConfigV1Schema = external_exports.strictObject({
|
|
21015
21056
|
$schema: external_exports.literal(PROJECT_CONFIG_SCHEMA_URL).optional(),
|
|
21016
21057
|
formatVersion: external_exports.literal(1),
|
|
21017
21058
|
paths: ProjectPathsV1Schema.optional(),
|
|
21018
21059
|
aliases: ProjectAliasesV1Schema.optional()
|
|
21019
21060
|
});
|
|
21061
|
+
function isRecord6(value) {
|
|
21062
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21063
|
+
}
|
|
21064
|
+
function isUnsupportedFormatVersion2(input) {
|
|
21065
|
+
if (!isRecord6(input))
|
|
21066
|
+
return false;
|
|
21067
|
+
return typeof input.formatVersion === "number" && input.formatVersion !== 1;
|
|
21068
|
+
}
|
|
21069
|
+
function hasGlobSyntax(value) {
|
|
21070
|
+
const globTokens = ["*", "?", "[", "]", "{", "}"];
|
|
21071
|
+
return globTokens.some((token) => value.includes(token));
|
|
21072
|
+
}
|
|
21073
|
+
function hasUnsafeProjectPathSyntax(value) {
|
|
21074
|
+
const unsafeChecks = [
|
|
21075
|
+
value.length === 0,
|
|
21076
|
+
value.startsWith("/"),
|
|
21077
|
+
/^[A-Za-z]:/.test(value),
|
|
21078
|
+
value.includes("\\"),
|
|
21079
|
+
value.includes("\0"),
|
|
21080
|
+
hasGlobSyntax(value)
|
|
21081
|
+
];
|
|
21082
|
+
return unsafeChecks.some((isUnsafe) => isUnsafe);
|
|
21083
|
+
}
|
|
21084
|
+
function normalizeProjectPath(value) {
|
|
21085
|
+
if (hasUnsafeProjectPathSyntax(value))
|
|
21086
|
+
return null;
|
|
21087
|
+
const segments = value.split("/").filter((segment) => {
|
|
21088
|
+
return segment.length > 0 && segment !== ".";
|
|
21089
|
+
});
|
|
21090
|
+
if (segments.some((segment) => segment === ".."))
|
|
21091
|
+
return null;
|
|
21092
|
+
return segments.length === 0 ? "." : segments.join("/");
|
|
21093
|
+
}
|
|
21094
|
+
function compareDiagnostics2(left, right) {
|
|
21095
|
+
const leftPath = left.path.join("/");
|
|
21096
|
+
const rightPath = right.path.join("/");
|
|
21097
|
+
if (leftPath < rightPath)
|
|
21098
|
+
return -1;
|
|
21099
|
+
if (leftPath > rightPath)
|
|
21100
|
+
return 1;
|
|
21101
|
+
if (left.code < right.code)
|
|
21102
|
+
return -1;
|
|
21103
|
+
if (left.code > right.code)
|
|
21104
|
+
return 1;
|
|
21105
|
+
return 0;
|
|
21106
|
+
}
|
|
21107
|
+
function isUnsupportedRegistryField(issue2, key) {
|
|
21108
|
+
return issue2.path.length === 0 && key === "registries";
|
|
21109
|
+
}
|
|
21110
|
+
function diagnosticForUnknownKey(issue2, key) {
|
|
21111
|
+
const unsupported = isUnsupportedRegistryField(issue2, key);
|
|
21112
|
+
return {
|
|
21113
|
+
code: unsupported ? "project_config.unsupported_field" : "project_config.unknown_field",
|
|
21114
|
+
message: unsupported ? 'The "registries" field is not supported by project config V1.' : 'Unknown field "' + key + '".',
|
|
21115
|
+
path: [...issue2.path.map(String), key]
|
|
21116
|
+
};
|
|
21117
|
+
}
|
|
21118
|
+
function isUnsupportedFormatVersionIssue2(issue2, input) {
|
|
21119
|
+
return issue2.path.length === 1 && issue2.path[0] === "formatVersion" && isUnsupportedFormatVersion2(input);
|
|
21120
|
+
}
|
|
21121
|
+
function diagnosticForSchemaIssue(issue2, input) {
|
|
21122
|
+
if (issue2.code === "unrecognized_keys") {
|
|
21123
|
+
return issue2.keys.map((key) => diagnosticForUnknownKey(issue2, key));
|
|
21124
|
+
}
|
|
21125
|
+
return [
|
|
21126
|
+
{
|
|
21127
|
+
code: isUnsupportedFormatVersionIssue2(issue2, input) ? "project_config.unsupported_format_version" : "project_config.invalid_field",
|
|
21128
|
+
message: issue2.message,
|
|
21129
|
+
path: issue2.path.map(String)
|
|
21130
|
+
}
|
|
21131
|
+
];
|
|
21132
|
+
}
|
|
21133
|
+
function diagnosticsForSchemaIssues(issues, input) {
|
|
21134
|
+
return issues.flatMap((issue2) => diagnosticForSchemaIssue(issue2, input)).sort(compareDiagnostics2);
|
|
21135
|
+
}
|
|
21136
|
+
function normalizeProjectPaths(paths) {
|
|
21137
|
+
const diagnostics = [];
|
|
21138
|
+
const normalizedPaths = {};
|
|
21139
|
+
for (const [role, path] of Object.entries(paths)) {
|
|
21140
|
+
const normalized = normalizeProjectPath(path);
|
|
21141
|
+
if (normalized === null) {
|
|
21142
|
+
diagnostics.push({
|
|
21143
|
+
code: "project_config.invalid_path",
|
|
21144
|
+
message: 'Path for role "' + role + '" must be a safe relative directory path.',
|
|
21145
|
+
path: ["paths", role]
|
|
21146
|
+
});
|
|
21147
|
+
continue;
|
|
21148
|
+
}
|
|
21149
|
+
normalizedPaths[role] = normalized;
|
|
21150
|
+
}
|
|
21151
|
+
return { diagnostics, normalizedPaths };
|
|
21152
|
+
}
|
|
21153
|
+
function diagnosticsForAliases(aliases, paths) {
|
|
21154
|
+
const diagnostics = [];
|
|
21155
|
+
for (const role of Object.keys(aliases)) {
|
|
21156
|
+
if (!Object.hasOwn(paths, role)) {
|
|
21157
|
+
diagnostics.push({
|
|
21158
|
+
code: "project_config.alias_without_path",
|
|
21159
|
+
message: 'Alias role "' + role + '" must also be declared in paths.',
|
|
21160
|
+
path: ["aliases", role]
|
|
21161
|
+
});
|
|
21162
|
+
}
|
|
21163
|
+
}
|
|
21164
|
+
return diagnostics;
|
|
21165
|
+
}
|
|
21166
|
+
function parseProjectConfig(input) {
|
|
21167
|
+
const result = ProjectConfigV1Schema.safeParse(input);
|
|
21168
|
+
if (!result.success) {
|
|
21169
|
+
return {
|
|
21170
|
+
success: false,
|
|
21171
|
+
diagnostics: diagnosticsForSchemaIssues(result.error.issues, input)
|
|
21172
|
+
};
|
|
21173
|
+
}
|
|
21174
|
+
const paths = result.data.paths ?? {};
|
|
21175
|
+
const aliases = result.data.aliases ?? {};
|
|
21176
|
+
const normalized = normalizeProjectPaths(paths);
|
|
21177
|
+
const diagnostics = [
|
|
21178
|
+
...normalized.diagnostics,
|
|
21179
|
+
...diagnosticsForAliases(aliases, paths)
|
|
21180
|
+
].sort(compareDiagnostics2);
|
|
21181
|
+
if (diagnostics.length > 0) {
|
|
21182
|
+
return { success: false, diagnostics };
|
|
21183
|
+
}
|
|
21184
|
+
const data = { ...result.data };
|
|
21185
|
+
if (result.data.paths !== void 0) {
|
|
21186
|
+
data.paths = normalized.normalizedPaths;
|
|
21187
|
+
}
|
|
21188
|
+
return { success: true, data };
|
|
21189
|
+
}
|
|
21020
21190
|
|
|
21021
21191
|
// src/utils/github-repository.ts
|
|
21022
21192
|
var OWNER_PATTERN = /^[A-Za-z0-9-]+$/;
|
|
@@ -21048,7 +21218,7 @@ var looksLikeUrl = (input) => /^[A-Za-z][A-Za-z0-9+.-]*:\/\//.test(input);
|
|
|
21048
21218
|
var GITHUB_API_BASE_URL2 = "https://api.github.com";
|
|
21049
21219
|
var MAX_BLOCK_JSON_BYTES = 1024 * 1024;
|
|
21050
21220
|
var REQUEST_TIMEOUT_MS = 15e3;
|
|
21051
|
-
function
|
|
21221
|
+
function isRecord7(value) {
|
|
21052
21222
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
21053
21223
|
}
|
|
21054
21224
|
function isSafeRelativePath3(value) {
|
|
@@ -21110,8 +21280,8 @@ async function fetchJson(url2, source, repositoryLookup = false) {
|
|
|
21110
21280
|
},
|
|
21111
21281
|
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
|
|
21112
21282
|
});
|
|
21113
|
-
} catch (
|
|
21114
|
-
throw networkError(
|
|
21283
|
+
} catch (error52) {
|
|
21284
|
+
throw networkError(error52 instanceof Error ? error52.message : String(error52));
|
|
21115
21285
|
}
|
|
21116
21286
|
if (response.status === 404) {
|
|
21117
21287
|
if (repositoryLookup) throw repositoryNotFound(source);
|
|
@@ -21141,8 +21311,8 @@ async function fetchRawFile(repository, revision, blockPath, filePath, sourceLab
|
|
|
21141
21311
|
response = await fetch(rawUrl, {
|
|
21142
21312
|
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
|
|
21143
21313
|
});
|
|
21144
|
-
} catch (
|
|
21145
|
-
throw networkError(
|
|
21314
|
+
} catch (error52) {
|
|
21315
|
+
throw networkError(error52 instanceof Error ? error52.message : String(error52));
|
|
21146
21316
|
}
|
|
21147
21317
|
if (response.status === 404) {
|
|
21148
21318
|
throw blockInvalid(
|
|
@@ -21196,7 +21366,7 @@ async function createGitHubBlockReader(input, refOverride) {
|
|
|
21196
21366
|
const repository = `${parsed.owner}/${parsed.repo}`;
|
|
21197
21367
|
const apiRepository = `${GITHUB_API_BASE_URL2}/repos/${encodeURIComponent(parsed.owner)}/${encodeURIComponent(parsed.repo)}`;
|
|
21198
21368
|
const repoPayload = await fetchJson(apiRepository, repository, true);
|
|
21199
|
-
const defaultBranch =
|
|
21369
|
+
const defaultBranch = isRecord7(repoPayload) && typeof repoPayload.default_branch === "string" ? repoPayload.default_branch : "";
|
|
21200
21370
|
const requestedRef = parsed.ref ?? defaultBranch;
|
|
21201
21371
|
if (!requestedRef) {
|
|
21202
21372
|
throw blockInvalid(input, "GitHub did not report a default branch");
|
|
@@ -21205,7 +21375,7 @@ async function createGitHubBlockReader(input, refOverride) {
|
|
|
21205
21375
|
`${apiRepository}/commits/${encodeURIComponent(requestedRef)}`,
|
|
21206
21376
|
input
|
|
21207
21377
|
);
|
|
21208
|
-
if (!
|
|
21378
|
+
if (!isRecord7(commit) || typeof commit.sha !== "string" || !/^[a-f0-9]{40}$/i.test(commit.sha)) {
|
|
21209
21379
|
throw networkError("GitHub returned an invalid commit response.");
|
|
21210
21380
|
}
|
|
21211
21381
|
const revision = commit.sha;
|
|
@@ -21234,8 +21404,8 @@ async function readSafeLocalFile(root, path, label) {
|
|
|
21234
21404
|
);
|
|
21235
21405
|
}
|
|
21236
21406
|
return contents.toString("utf8");
|
|
21237
|
-
} catch (
|
|
21238
|
-
if (
|
|
21407
|
+
} catch (error52) {
|
|
21408
|
+
if (error52 instanceof Error && error52.name === "CliError") throw error52;
|
|
21239
21409
|
throw blockInvalid(label, `source file "${path}" could not be read`);
|
|
21240
21410
|
}
|
|
21241
21411
|
}
|
|
@@ -21298,7 +21468,7 @@ function parseJson(text, path, source) {
|
|
|
21298
21468
|
}
|
|
21299
21469
|
function readDependencyMap(value, field, source) {
|
|
21300
21470
|
if (value === void 0) return {};
|
|
21301
|
-
if (!
|
|
21471
|
+
if (!isRecord7(value)) {
|
|
21302
21472
|
throw blockInvalid(source, `package.json "${field}" must be an object`);
|
|
21303
21473
|
}
|
|
21304
21474
|
const dependencies = {};
|
|
@@ -21315,7 +21485,7 @@ function readDependencyMap(value, field, source) {
|
|
|
21315
21485
|
}
|
|
21316
21486
|
function parsePackageInfo(manifestText, manifestPath, source, id, path) {
|
|
21317
21487
|
const manifest = parseJson(manifestText, manifestPath, source);
|
|
21318
|
-
if (!
|
|
21488
|
+
if (!isRecord7(manifest) || typeof manifest.name !== "string" || !manifest.name) {
|
|
21319
21489
|
throw blockInvalid(
|
|
21320
21490
|
source,
|
|
21321
21491
|
'"' + manifestPath + '" must declare a package name'
|
|
@@ -21355,9 +21525,9 @@ async function readPackageInfo(reader, descriptor, id, path) {
|
|
|
21355
21525
|
const manifestText = await reader.read(packageManifest.from);
|
|
21356
21526
|
return parsePackageInfo(manifestText, packageManifest.from, source, id, path);
|
|
21357
21527
|
}
|
|
21358
|
-
function getErrorDetail(
|
|
21359
|
-
if (
|
|
21360
|
-
return
|
|
21528
|
+
function getErrorDetail(error52) {
|
|
21529
|
+
if (error52 instanceof CliError && error52.hint) return error52.hint;
|
|
21530
|
+
return error52 instanceof Error ? error52.message : String(error52);
|
|
21361
21531
|
}
|
|
21362
21532
|
async function loadBlockDescriptor(input, options) {
|
|
21363
21533
|
const isRemoteSource = looksLikeUrl(input);
|
|
@@ -21426,12 +21596,12 @@ async function checkBlockSource(input = ".", options = {}) {
|
|
|
21426
21596
|
path: file2.from,
|
|
21427
21597
|
contents: await loaded.reader.read(file2.from)
|
|
21428
21598
|
};
|
|
21429
|
-
} catch (
|
|
21599
|
+
} catch (error52) {
|
|
21430
21600
|
return {
|
|
21431
21601
|
success: false,
|
|
21432
21602
|
diagnostic: {
|
|
21433
21603
|
code: "asset.unreadable",
|
|
21434
|
-
message: getErrorDetail(
|
|
21604
|
+
message: getErrorDetail(error52),
|
|
21435
21605
|
path: ["install", "files", String(index), "from"]
|
|
21436
21606
|
}
|
|
21437
21607
|
};
|
|
@@ -21467,10 +21637,10 @@ async function checkBlockSource(input = ".", options = {}) {
|
|
|
21467
21637
|
output.path
|
|
21468
21638
|
)
|
|
21469
21639
|
);
|
|
21470
|
-
} catch (
|
|
21640
|
+
} catch (error52) {
|
|
21471
21641
|
diagnostics.push({
|
|
21472
21642
|
code: "package_manifest.invalid",
|
|
21473
|
-
message: getErrorDetail(
|
|
21643
|
+
message: getErrorDetail(error52),
|
|
21474
21644
|
path: ["install", "packages", String(index)]
|
|
21475
21645
|
});
|
|
21476
21646
|
}
|
|
@@ -21496,7 +21666,7 @@ var blockInfoCommand = new Command("info").description("Show details for one blo
|
|
|
21496
21666
|
"--ref <git-ref>",
|
|
21497
21667
|
"Git ref to inspect (defaults to the URL ref or repository default branch)"
|
|
21498
21668
|
).option("--json", "JSON output for scripting").action(async (source, options) => {
|
|
21499
|
-
const spinner = options.json ? null :
|
|
21669
|
+
const spinner = options.json ? null : ora8("Reading block details...").start();
|
|
21500
21670
|
try {
|
|
21501
21671
|
const info = await resolveBlockDescriptorInfo(source, {
|
|
21502
21672
|
...options.ref ? { ref: options.ref } : {}
|
|
@@ -21511,22 +21681,22 @@ var blockInfoCommand = new Command("info").description("Show details for one blo
|
|
|
21511
21681
|
} else {
|
|
21512
21682
|
printBlockInfo(info);
|
|
21513
21683
|
}
|
|
21514
|
-
} catch (
|
|
21684
|
+
} catch (error52) {
|
|
21515
21685
|
spinner?.fail("Failed to read block details");
|
|
21516
|
-
if (
|
|
21686
|
+
if (error52 instanceof CliError) {
|
|
21517
21687
|
if (options.json) {
|
|
21518
21688
|
printJson({
|
|
21519
21689
|
ok: false,
|
|
21520
|
-
code:
|
|
21521
|
-
message:
|
|
21522
|
-
hint:
|
|
21690
|
+
code: error52.code,
|
|
21691
|
+
message: error52.message,
|
|
21692
|
+
hint: error52.hint
|
|
21523
21693
|
});
|
|
21524
21694
|
} else {
|
|
21525
|
-
printError(
|
|
21695
|
+
printError(error52);
|
|
21526
21696
|
}
|
|
21527
|
-
process.exit(
|
|
21697
|
+
process.exit(error52.exitCode());
|
|
21528
21698
|
}
|
|
21529
|
-
throw internal(
|
|
21699
|
+
throw internal(error52 instanceof Error ? error52.message : String(error52));
|
|
21530
21700
|
}
|
|
21531
21701
|
});
|
|
21532
21702
|
var blockCheckCommand = new Command("check").description("Validate a block descriptor and all referenced source files").argument(
|
|
@@ -21542,14 +21712,14 @@ var blockCheckCommand = new Command("check").description("Validate a block descr
|
|
|
21542
21712
|
blockCommand.addCommand(blockInfoCommand);
|
|
21543
21713
|
blockCommand.addCommand(blockCheckCommand);
|
|
21544
21714
|
async function runBlockCheck(source, options) {
|
|
21545
|
-
const spinner = options.json ? null :
|
|
21715
|
+
const spinner = options.json ? null : ora8("Checking block source...").start();
|
|
21546
21716
|
try {
|
|
21547
21717
|
const result = await checkBlockSource(source, {
|
|
21548
21718
|
...options.ref ? { ref: options.ref } : {}
|
|
21549
21719
|
});
|
|
21550
21720
|
reportBlockCheck(result, options.json ?? false, spinner);
|
|
21551
|
-
} catch (
|
|
21552
|
-
handleBlockCheckError(
|
|
21721
|
+
} catch (error52) {
|
|
21722
|
+
handleBlockCheckError(error52, options.json ?? false, spinner);
|
|
21553
21723
|
}
|
|
21554
21724
|
}
|
|
21555
21725
|
function reportBlockCheck(result, json2, spinner) {
|
|
@@ -21563,23 +21733,23 @@ function reportBlockCheck(result, json2, spinner) {
|
|
|
21563
21733
|
}
|
|
21564
21734
|
if (!valid) process.exitCode = 1;
|
|
21565
21735
|
}
|
|
21566
|
-
function handleBlockCheckError(
|
|
21736
|
+
function handleBlockCheckError(error52, json2, spinner) {
|
|
21567
21737
|
spinner?.fail("Failed to check block source");
|
|
21568
|
-
if (!(
|
|
21569
|
-
throw internal(
|
|
21738
|
+
if (!(error52 instanceof CliError)) {
|
|
21739
|
+
throw internal(error52 instanceof Error ? error52.message : String(error52));
|
|
21570
21740
|
}
|
|
21571
21741
|
if (json2) {
|
|
21572
21742
|
printJson({
|
|
21573
21743
|
ok: false,
|
|
21574
21744
|
command: "block check",
|
|
21575
|
-
code:
|
|
21576
|
-
message:
|
|
21577
|
-
hint:
|
|
21745
|
+
code: error52.code,
|
|
21746
|
+
message: error52.message,
|
|
21747
|
+
hint: error52.hint
|
|
21578
21748
|
});
|
|
21579
21749
|
} else {
|
|
21580
|
-
printError(
|
|
21750
|
+
printError(error52);
|
|
21581
21751
|
}
|
|
21582
|
-
process.exit(
|
|
21752
|
+
process.exit(error52.exitCode());
|
|
21583
21753
|
}
|
|
21584
21754
|
var detectPackageManager = (cwd) => {
|
|
21585
21755
|
const pkg = readPackageJson(cwd);
|
|
@@ -21637,7 +21807,7 @@ var spawn2 = (command, args, options = {}) => {
|
|
|
21637
21807
|
child.stdout?.pipe(process.stderr);
|
|
21638
21808
|
child.stderr?.pipe(process.stderr);
|
|
21639
21809
|
}
|
|
21640
|
-
child.on("error", (
|
|
21810
|
+
child.on("error", (err2) => rejectFn(err2));
|
|
21641
21811
|
child.on("exit", (code) => {
|
|
21642
21812
|
const exit = code ?? 1;
|
|
21643
21813
|
if (reject && exit !== 0) {
|
|
@@ -21648,11 +21818,11 @@ var spawn2 = (command, args, options = {}) => {
|
|
|
21648
21818
|
});
|
|
21649
21819
|
});
|
|
21650
21820
|
};
|
|
21651
|
-
function isMissingPathError(
|
|
21652
|
-
return
|
|
21821
|
+
function isMissingPathError(error52) {
|
|
21822
|
+
return error52 instanceof Error && "code" in error52 && error52.code === "ENOENT";
|
|
21653
21823
|
}
|
|
21654
|
-
function isExistsPathError(
|
|
21655
|
-
return
|
|
21824
|
+
function isExistsPathError(error52) {
|
|
21825
|
+
return error52 instanceof Error && "code" in error52 && error52.code === "EEXIST";
|
|
21656
21826
|
}
|
|
21657
21827
|
function getSafeRelativePath(path) {
|
|
21658
21828
|
if (path.length === 0) return null;
|
|
@@ -21748,10 +21918,10 @@ async function assertExistingParentsAreDirectories(target) {
|
|
|
21748
21918
|
`parent path "${current}" is not a regular directory`
|
|
21749
21919
|
);
|
|
21750
21920
|
}
|
|
21751
|
-
} catch (
|
|
21752
|
-
if (
|
|
21753
|
-
if (isMissingPathError(
|
|
21754
|
-
throw
|
|
21921
|
+
} catch (error52) {
|
|
21922
|
+
if (error52 instanceof CliError) throw error52;
|
|
21923
|
+
if (isMissingPathError(error52)) return;
|
|
21924
|
+
throw error52;
|
|
21755
21925
|
}
|
|
21756
21926
|
}
|
|
21757
21927
|
}
|
|
@@ -21768,10 +21938,10 @@ async function inspectTarget(target, force) {
|
|
|
21768
21938
|
if (!force) throw targetExists(target);
|
|
21769
21939
|
if ((await readdir(target)).length > 0) throw targetNotEmpty(target);
|
|
21770
21940
|
return { existed: true };
|
|
21771
|
-
} catch (
|
|
21772
|
-
if (
|
|
21773
|
-
if (isMissingPathError(
|
|
21774
|
-
throw
|
|
21941
|
+
} catch (error52) {
|
|
21942
|
+
if (error52 instanceof CliError) throw error52;
|
|
21943
|
+
if (isMissingPathError(error52)) return { existed: false };
|
|
21944
|
+
throw error52;
|
|
21775
21945
|
}
|
|
21776
21946
|
}
|
|
21777
21947
|
async function trackDirectory(path, createdDirectories) {
|
|
@@ -21807,8 +21977,8 @@ async function ensureDirectoryAtPath(current, target, targetState, createdDirect
|
|
|
21807
21977
|
let details;
|
|
21808
21978
|
try {
|
|
21809
21979
|
details = await lstat(current);
|
|
21810
|
-
} catch (
|
|
21811
|
-
if (!isMissingPathError(
|
|
21980
|
+
} catch (error52) {
|
|
21981
|
+
if (!isMissingPathError(error52)) throw error52;
|
|
21812
21982
|
try {
|
|
21813
21983
|
await mkdir(current);
|
|
21814
21984
|
await trackDirectory(current, createdDirectories);
|
|
@@ -21886,15 +22056,77 @@ async function materializeTemplatePlan(plan, targetDirectory, options = {}) {
|
|
|
21886
22056
|
await handle.close();
|
|
21887
22057
|
}
|
|
21888
22058
|
}
|
|
21889
|
-
} catch (
|
|
22059
|
+
} catch (error52) {
|
|
21890
22060
|
await cleanupCreatedPaths(createdFiles, createdDirectories);
|
|
21891
|
-
if (
|
|
22061
|
+
if (error52 instanceof CliError) throw error52;
|
|
21892
22062
|
throw materializeFailed(
|
|
21893
22063
|
target,
|
|
21894
|
-
|
|
22064
|
+
error52 instanceof Error ? error52.message : String(error52)
|
|
21895
22065
|
);
|
|
21896
22066
|
}
|
|
21897
22067
|
}
|
|
22068
|
+
var ProjectConfigError = error$1({
|
|
22069
|
+
name: "ProjectConfigError",
|
|
22070
|
+
message: "Project config {stage} validation failed: {detail}"
|
|
22071
|
+
});
|
|
22072
|
+
var isRootProjectConfig = (path) => {
|
|
22073
|
+
const normalized = process.platform === "win32" ? path.toLowerCase() : path;
|
|
22074
|
+
return normalized === "deesse.json";
|
|
22075
|
+
};
|
|
22076
|
+
var findProjectConfig = (plan) => {
|
|
22077
|
+
return plan.files.find((file2) => isRootProjectConfig(file2.path));
|
|
22078
|
+
};
|
|
22079
|
+
var createDefaultConfigFile = () => {
|
|
22080
|
+
const config2 = { $schema: PROJECT_CONFIG_SCHEMA_URL, formatVersion: 1 };
|
|
22081
|
+
const contents = `${JSON.stringify(config2, null, 2)}
|
|
22082
|
+
`;
|
|
22083
|
+
return { path: "deesse.json", contents: new TextEncoder().encode(contents) };
|
|
22084
|
+
};
|
|
22085
|
+
var addDefaultProjectConfig = (plan) => {
|
|
22086
|
+
return { ...plan, files: [...plan.files, createDefaultConfigFile()] };
|
|
22087
|
+
};
|
|
22088
|
+
var asError = (value) => value instanceof Error ? value : new Error(String(value));
|
|
22089
|
+
var projectConfigFailure = (stage, detail, cause) => {
|
|
22090
|
+
const failure = ProjectConfigError({ stage, detail });
|
|
22091
|
+
return cause ? failure.from(cause) : failure;
|
|
22092
|
+
};
|
|
22093
|
+
var decodeConfig = (contents) => {
|
|
22094
|
+
try {
|
|
22095
|
+
return ok(new TextDecoder("utf-8", { fatal: true }).decode(contents));
|
|
22096
|
+
} catch (error52) {
|
|
22097
|
+
const cause = asError(error52);
|
|
22098
|
+
return err(projectConfigFailure("utf8", cause.message, cause));
|
|
22099
|
+
}
|
|
22100
|
+
};
|
|
22101
|
+
var parseJson2 = (text) => {
|
|
22102
|
+
try {
|
|
22103
|
+
return ok(JSON.parse(text));
|
|
22104
|
+
} catch (error52) {
|
|
22105
|
+
const cause = asError(error52);
|
|
22106
|
+
return err(projectConfigFailure("json", cause.message, cause));
|
|
22107
|
+
}
|
|
22108
|
+
};
|
|
22109
|
+
var formatDiagnostic = (diagnostic2) => {
|
|
22110
|
+
return `${diagnostic2.code}: ${diagnostic2.message}`;
|
|
22111
|
+
};
|
|
22112
|
+
var validateConfig = (input) => {
|
|
22113
|
+
const result = parseProjectConfig(input);
|
|
22114
|
+
if (result.success) return ok(result.data);
|
|
22115
|
+
const details = result.diagnostics.map(formatDiagnostic).join("\n");
|
|
22116
|
+
return err(projectConfigFailure("schema", details));
|
|
22117
|
+
};
|
|
22118
|
+
var readProjectConfig = (contents) => pipe$1(contents, decodeConfig, flatMap(parseJson2), flatMap(validateConfig));
|
|
22119
|
+
var preserveProjectConfig = (plan, contents) => pipe$1(
|
|
22120
|
+
readProjectConfig(contents),
|
|
22121
|
+
map$1(() => ({ plan, generated: false }))
|
|
22122
|
+
);
|
|
22123
|
+
var resolveProjectConfig = (plan) => {
|
|
22124
|
+
const configFile = findProjectConfig(plan);
|
|
22125
|
+
if (!configFile) {
|
|
22126
|
+
return ok({ plan: addDefaultProjectConfig(plan), generated: true });
|
|
22127
|
+
}
|
|
22128
|
+
return preserveProjectConfig(plan, configFile.contents);
|
|
22129
|
+
};
|
|
21898
22130
|
|
|
21899
22131
|
// src/version/check.ts
|
|
21900
22132
|
var SEMVER_RE = /^\d+\.\d+\.\d+$/;
|
|
@@ -21969,12 +22201,28 @@ var link = new RPCLink({
|
|
|
21969
22201
|
new ClientRetryPlugin({
|
|
21970
22202
|
default: {
|
|
21971
22203
|
retry: 3,
|
|
21972
|
-
shouldRetry: ({ error:
|
|
22204
|
+
shouldRetry: ({ error: error52 }) => isTransientNetworkError(error52)
|
|
21973
22205
|
}
|
|
21974
22206
|
})
|
|
21975
22207
|
]
|
|
21976
22208
|
});
|
|
21977
22209
|
var orpc = createORPCClient(link);
|
|
22210
|
+
function createAuthenticatedORPCClient(accessToken) {
|
|
22211
|
+
const authenticatedLink = new RPCLink({
|
|
22212
|
+
url: new URL(API_RPC_PATH, resolveBaseURL2()).toString(),
|
|
22213
|
+
headers: () => ({ authorization: `Bearer ${accessToken}` }),
|
|
22214
|
+
plugins: [
|
|
22215
|
+
new RetryAfterPlugin(),
|
|
22216
|
+
new ClientRetryPlugin({
|
|
22217
|
+
default: {
|
|
22218
|
+
retry: 3,
|
|
22219
|
+
shouldRetry: ({ error: error52 }) => isTransientNetworkError(error52)
|
|
22220
|
+
}
|
|
22221
|
+
})
|
|
22222
|
+
]
|
|
22223
|
+
});
|
|
22224
|
+
return createORPCClient(authenticatedLink);
|
|
22225
|
+
}
|
|
21978
22226
|
|
|
21979
22227
|
// src/api/index.ts
|
|
21980
22228
|
var normaliseError = (e) => {
|
|
@@ -22009,9 +22257,9 @@ var resolveTemplateBySlug = async (slug) => {
|
|
|
22009
22257
|
async function fetchTemplatesForInfo() {
|
|
22010
22258
|
try {
|
|
22011
22259
|
return await fetchTemplates({ skipVersionCheck: true });
|
|
22012
|
-
} catch (
|
|
22013
|
-
if (
|
|
22014
|
-
const detail =
|
|
22260
|
+
} catch (error52) {
|
|
22261
|
+
if (error52 instanceof Error && error52.name === "CliError") throw error52;
|
|
22262
|
+
const detail = error52 instanceof Error && "code" in error52 ? `${String(error52.code)}: ${error52.message}` : error52 instanceof Error ? error52.message : String(error52);
|
|
22015
22263
|
throw networkError(detail);
|
|
22016
22264
|
}
|
|
22017
22265
|
}
|
|
@@ -22173,7 +22421,7 @@ function printMissingPackageManagerNotice() {
|
|
|
22173
22421
|
async function installDependencies(packageManager, dir, verbose, json2) {
|
|
22174
22422
|
const command = getInstallCommand(packageManager);
|
|
22175
22423
|
const [bin = "npm", ...args] = command.split(" ");
|
|
22176
|
-
const spinner = verbose || json2 ? void 0 :
|
|
22424
|
+
const spinner = verbose || json2 ? void 0 : ora8(
|
|
22177
22425
|
`Installing dependencies with ${pc6.cyan(packageManager.pm)}\u2026`
|
|
22178
22426
|
).start();
|
|
22179
22427
|
if (verbose && !json2) {
|
|
@@ -22213,14 +22461,25 @@ async function createTemplateProject(template, dir, ref, force, showProgress, ve
|
|
|
22213
22461
|
logVerbose(verbose, `Source repository: https://github.com/${repository}`);
|
|
22214
22462
|
logVerbose(verbose, `Requested ref: ${resolvedRef ?? "default branch"}`);
|
|
22215
22463
|
logVerbose(verbose, `Target directory: ${dir}`);
|
|
22216
|
-
const downloadSpinner = showProgress ?
|
|
22464
|
+
const downloadSpinner = showProgress ? ora8(`Downloading template from ${pc6.cyan(repository)}\u2026`).start() : void 0;
|
|
22217
22465
|
let plan;
|
|
22218
22466
|
try {
|
|
22219
22467
|
plan = await resolveTemplateInstallationPlan(repository, resolvedRef);
|
|
22220
|
-
} catch (
|
|
22468
|
+
} catch (error52) {
|
|
22221
22469
|
downloadSpinner?.fail("Template download failed");
|
|
22222
|
-
throw
|
|
22470
|
+
throw error52;
|
|
22223
22471
|
}
|
|
22472
|
+
const projectConfig = resolveProjectConfig(plan).match({
|
|
22473
|
+
ok: (value) => value,
|
|
22474
|
+
err: (error52) => {
|
|
22475
|
+
throw templateInvalid(template.slug, error52.message, error52);
|
|
22476
|
+
}
|
|
22477
|
+
});
|
|
22478
|
+
const projectPlan = projectConfig.plan;
|
|
22479
|
+
logVerbose(
|
|
22480
|
+
verbose,
|
|
22481
|
+
projectConfig.generated ? 'Generated a default "deesse.json"' : `Using the template's validated "deesse.json"`
|
|
22482
|
+
);
|
|
22224
22483
|
downloadSpinner?.succeed("Template downloaded");
|
|
22225
22484
|
logVerbose(verbose, `Resolved commit: ${plan.source.revision}`);
|
|
22226
22485
|
logVerbose(
|
|
@@ -22230,15 +22489,15 @@ async function createTemplateProject(template, dir, ref, force, showProgress, ve
|
|
|
22230
22489
|
if (showProgress) {
|
|
22231
22490
|
console.log(pc6.dim(` ${repository} \xB7 ${plan.source.revision.slice(0, 7)}`));
|
|
22232
22491
|
}
|
|
22233
|
-
const createSpinner = showProgress ?
|
|
22492
|
+
const createSpinner = showProgress ? ora8("Creating project files\u2026").start() : void 0;
|
|
22234
22493
|
try {
|
|
22235
|
-
await materializeTemplatePlan(
|
|
22494
|
+
await materializeTemplatePlan(projectPlan, dir, { force });
|
|
22236
22495
|
const revision = plan.source.revision;
|
|
22237
22496
|
createSpinner?.succeed("Project files created");
|
|
22238
22497
|
return revision;
|
|
22239
|
-
} catch (
|
|
22498
|
+
} catch (error52) {
|
|
22240
22499
|
createSpinner?.fail("Project file creation failed");
|
|
22241
|
-
throw
|
|
22500
|
+
throw error52;
|
|
22242
22501
|
}
|
|
22243
22502
|
}
|
|
22244
22503
|
var initCommand = new Command("init").description("Create a project from a template and install dependencies").argument(
|
|
@@ -22255,13 +22514,13 @@ var initCommand = new Command("init").description("Create a project from a templ
|
|
|
22255
22514
|
);
|
|
22256
22515
|
async function runInitCommand(slugOrUrl, options) {
|
|
22257
22516
|
try {
|
|
22258
|
-
const state = await
|
|
22517
|
+
const state = await loadTemplateState(slugOrUrl, options);
|
|
22259
22518
|
await installAndReport(state, options);
|
|
22260
|
-
} catch (
|
|
22261
|
-
reportInitError(
|
|
22519
|
+
} catch (error52) {
|
|
22520
|
+
reportInitError(error52, options.json ?? false);
|
|
22262
22521
|
}
|
|
22263
22522
|
}
|
|
22264
|
-
async function
|
|
22523
|
+
async function loadTemplateState(slugOrUrl, options) {
|
|
22265
22524
|
const { template, directRepository } = await resolveTemplateSource(slugOrUrl);
|
|
22266
22525
|
const projectName = directRepository?.repo ?? template.templateSlug ?? template.slug;
|
|
22267
22526
|
const dir = resolve(process.cwd(), options.dir ?? `./${projectName}`);
|
|
@@ -22327,32 +22586,32 @@ async function installAndReport(state, options) {
|
|
|
22327
22586
|
printNextSteps(dir, packageManager, false);
|
|
22328
22587
|
}
|
|
22329
22588
|
}
|
|
22330
|
-
function reportInitError(
|
|
22331
|
-
if (!(
|
|
22332
|
-
throw internal(
|
|
22589
|
+
function reportInitError(error52, json2) {
|
|
22590
|
+
if (!(error52 instanceof CliError)) {
|
|
22591
|
+
throw internal(error52 instanceof Error ? error52.message : String(error52));
|
|
22333
22592
|
}
|
|
22334
22593
|
if (json2) {
|
|
22335
22594
|
printJson({
|
|
22336
22595
|
ok: false,
|
|
22337
|
-
code:
|
|
22338
|
-
message:
|
|
22339
|
-
hint:
|
|
22596
|
+
code: error52.code,
|
|
22597
|
+
message: error52.message,
|
|
22598
|
+
hint: error52.hint
|
|
22340
22599
|
});
|
|
22341
22600
|
} else {
|
|
22342
|
-
printError(
|
|
22601
|
+
printError(error52);
|
|
22343
22602
|
}
|
|
22344
|
-
process.exit(
|
|
22603
|
+
process.exit(error52.exitCode());
|
|
22345
22604
|
}
|
|
22346
22605
|
var listCommand = new Command("list").description("List available templates").option("--category <name>", "filter to a single category").option("--json", "JSON output for scripting").action((options) => runListCommand(options));
|
|
22347
22606
|
async function runListCommand(options) {
|
|
22348
|
-
const spinner = options.json ? null :
|
|
22607
|
+
const spinner = options.json ? null : ora8("Fetching templates...").start();
|
|
22349
22608
|
try {
|
|
22350
22609
|
const all = await fetchTemplates();
|
|
22351
22610
|
const filtered = options.category ? all.filter((template) => template.category === options.category) : all;
|
|
22352
22611
|
spinner?.stop();
|
|
22353
22612
|
renderTemplates(filtered, options, spinner);
|
|
22354
|
-
} catch (
|
|
22355
|
-
reportListError(
|
|
22613
|
+
} catch (error52) {
|
|
22614
|
+
reportListError(error52, options.json ?? false, spinner);
|
|
22356
22615
|
}
|
|
22357
22616
|
}
|
|
22358
22617
|
function renderTemplates(templates, options, _spinner) {
|
|
@@ -22370,20 +22629,20 @@ function renderTemplates(templates, options, _spinner) {
|
|
|
22370
22629
|
)
|
|
22371
22630
|
);
|
|
22372
22631
|
}
|
|
22373
|
-
function reportListError(
|
|
22632
|
+
function reportListError(error52, json2, spinner) {
|
|
22374
22633
|
spinner?.fail("Failed to fetch templates");
|
|
22375
|
-
if (!(
|
|
22376
|
-
throw internal(
|
|
22634
|
+
if (!(error52 instanceof CliError)) {
|
|
22635
|
+
throw internal(error52 instanceof Error ? error52.message : String(error52));
|
|
22377
22636
|
}
|
|
22378
22637
|
if (json2) {
|
|
22379
22638
|
printJson({
|
|
22380
22639
|
ok: false,
|
|
22381
|
-
code:
|
|
22382
|
-
message:
|
|
22383
|
-
hint:
|
|
22640
|
+
code: error52.code,
|
|
22641
|
+
message: error52.message,
|
|
22642
|
+
hint: error52.hint
|
|
22384
22643
|
});
|
|
22385
22644
|
} else {
|
|
22386
|
-
printError(
|
|
22645
|
+
printError(error52);
|
|
22387
22646
|
}
|
|
22388
22647
|
process.exit(1);
|
|
22389
22648
|
}
|
|
@@ -22403,7 +22662,7 @@ var infoCommand = new Command("info").description("Show details for one template
|
|
|
22403
22662
|
"--ref <branch>",
|
|
22404
22663
|
"Git ref to inspect (default: the repository's default branch)"
|
|
22405
22664
|
).option("--json", "JSON output for scripting").action(async (slugOrUrl, opts) => {
|
|
22406
|
-
const spinner = opts.json ? null :
|
|
22665
|
+
const spinner = opts.json ? null : ora8("Fetching template details...").start();
|
|
22407
22666
|
try {
|
|
22408
22667
|
const resolved = await resolveTemplateSource(slugOrUrl, {
|
|
22409
22668
|
skipVersionCheck: true,
|
|
@@ -22428,24 +22687,437 @@ var infoCommand = new Command("info").description("Show details for one template
|
|
|
22428
22687
|
console.log();
|
|
22429
22688
|
console.log(`Install: ${installCommand}`);
|
|
22430
22689
|
}
|
|
22431
|
-
} catch (
|
|
22690
|
+
} catch (err2) {
|
|
22432
22691
|
spinner?.fail("Failed to fetch template details");
|
|
22433
|
-
if (
|
|
22692
|
+
if (err2 instanceof CliError) {
|
|
22434
22693
|
if (opts.json) {
|
|
22435
22694
|
printJson({
|
|
22436
22695
|
ok: false,
|
|
22437
|
-
code:
|
|
22438
|
-
message:
|
|
22439
|
-
hint:
|
|
22696
|
+
code: err2.code,
|
|
22697
|
+
message: err2.message,
|
|
22698
|
+
hint: err2.hint
|
|
22440
22699
|
});
|
|
22441
22700
|
} else {
|
|
22442
|
-
printError(
|
|
22701
|
+
printError(err2);
|
|
22443
22702
|
}
|
|
22444
|
-
process.exit(
|
|
22703
|
+
process.exit(err2.exitCode());
|
|
22445
22704
|
}
|
|
22446
|
-
throw internal(
|
|
22705
|
+
throw internal(err2 instanceof Error ? err2.message : String(err2));
|
|
22706
|
+
}
|
|
22707
|
+
});
|
|
22708
|
+
|
|
22709
|
+
// src/api/organizations.ts
|
|
22710
|
+
var isRecord8 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
22711
|
+
var hasOrganizationFields = (value) => {
|
|
22712
|
+
if (typeof value.id !== "string") return false;
|
|
22713
|
+
if (typeof value.name !== "string") return false;
|
|
22714
|
+
if (typeof value.slug !== "string") return false;
|
|
22715
|
+
if (value.logo !== null && typeof value.logo !== "string") return false;
|
|
22716
|
+
return true;
|
|
22717
|
+
};
|
|
22718
|
+
var readOrganization = (value) => {
|
|
22719
|
+
if (!isRecord8(value) || !hasOrganizationFields(value)) {
|
|
22720
|
+
throw parseError(
|
|
22721
|
+
"Expected organization id, name, slug and nullable logo fields.",
|
|
22722
|
+
"Better Auth returned malformed organization data"
|
|
22723
|
+
);
|
|
22724
|
+
}
|
|
22725
|
+
return {
|
|
22726
|
+
id: value.id,
|
|
22727
|
+
name: value.name,
|
|
22728
|
+
slug: value.slug,
|
|
22729
|
+
logo: value.logo
|
|
22730
|
+
};
|
|
22731
|
+
};
|
|
22732
|
+
var readError = async (response) => {
|
|
22733
|
+
try {
|
|
22734
|
+
const value = await response.json();
|
|
22735
|
+
return isRecord8(value) ? value : {};
|
|
22736
|
+
} catch {
|
|
22737
|
+
return {};
|
|
22738
|
+
}
|
|
22739
|
+
};
|
|
22740
|
+
async function fetchBetterAuthJson(path, accessToken) {
|
|
22741
|
+
let response;
|
|
22742
|
+
try {
|
|
22743
|
+
response = await bearerFetch(path, accessToken, { method: "GET" });
|
|
22744
|
+
} catch (error52) {
|
|
22745
|
+
throw new CliError(
|
|
22746
|
+
"network_error",
|
|
22747
|
+
"Could not reach the DeesseJS API.",
|
|
22748
|
+
error52 instanceof Error ? error52.message : "Check your network connection."
|
|
22749
|
+
);
|
|
22750
|
+
}
|
|
22751
|
+
if (response.status === 401) {
|
|
22752
|
+
throw new CliError(
|
|
22753
|
+
"auth_required",
|
|
22754
|
+
"Your CLI session has expired.",
|
|
22755
|
+
"Run `deessejs auth login` to sign in again."
|
|
22756
|
+
);
|
|
22757
|
+
}
|
|
22758
|
+
if (response.status === 403 || response.status === 404) {
|
|
22759
|
+
throw new CliError(
|
|
22760
|
+
"organization_not_found",
|
|
22761
|
+
"You cannot access that organization.",
|
|
22762
|
+
"Run `deessejs organization list` to see your organizations."
|
|
22763
|
+
);
|
|
22764
|
+
}
|
|
22765
|
+
if (!response.ok) {
|
|
22766
|
+
const body = await readError(response);
|
|
22767
|
+
const serverCode = typeof body.code === "string" ? body.code : void 0;
|
|
22768
|
+
throw new CliError(
|
|
22769
|
+
"organization_api_error",
|
|
22770
|
+
"The organization request failed.",
|
|
22771
|
+
serverCode ? `The server returned ${serverCode}.` : `HTTP ${response.status}.`
|
|
22772
|
+
);
|
|
22773
|
+
}
|
|
22774
|
+
try {
|
|
22775
|
+
return await response.json();
|
|
22776
|
+
} catch {
|
|
22777
|
+
throw parseError(
|
|
22778
|
+
"The response was not valid JSON.",
|
|
22779
|
+
"Better Auth returned malformed organization data"
|
|
22780
|
+
);
|
|
22447
22781
|
}
|
|
22782
|
+
}
|
|
22783
|
+
async function listOrganizations(accessToken) {
|
|
22784
|
+
const value = await fetchBetterAuthJson("organization/list", accessToken);
|
|
22785
|
+
if (!Array.isArray(value)) {
|
|
22786
|
+
throw parseError(
|
|
22787
|
+
"Expected an array of organizations.",
|
|
22788
|
+
"Better Auth returned malformed organization data"
|
|
22789
|
+
);
|
|
22790
|
+
}
|
|
22791
|
+
return value.map(readOrganization);
|
|
22792
|
+
}
|
|
22793
|
+
async function getOrganizationRole(organizationId, accessToken) {
|
|
22794
|
+
const query = new URLSearchParams({ organizationId });
|
|
22795
|
+
const value = await fetchBetterAuthJson(
|
|
22796
|
+
`organization/get-active-member-role?${query.toString()}`,
|
|
22797
|
+
accessToken
|
|
22798
|
+
);
|
|
22799
|
+
if (!isRecord8(value) || typeof value.role !== "string") {
|
|
22800
|
+
throw parseError(
|
|
22801
|
+
"Expected the current user's organization role.",
|
|
22802
|
+
"Better Auth returned malformed organization data"
|
|
22803
|
+
);
|
|
22804
|
+
}
|
|
22805
|
+
return value.role;
|
|
22806
|
+
}
|
|
22807
|
+
var SLUG_MAX_LENGTH = 38;
|
|
22808
|
+
var fallbackSlug = (name) => {
|
|
22809
|
+
const digest = createHash("sha256").update(name).digest("hex").slice(0, 8);
|
|
22810
|
+
return `org-${digest}`;
|
|
22811
|
+
};
|
|
22812
|
+
function organizationSlugFromName(name) {
|
|
22813
|
+
const runs = name.normalize("NFKD").toLowerCase().replace(new RegExp("\\p{M}", "gu"), "").split(/[^a-z0-9]+/).filter((run) => run !== "");
|
|
22814
|
+
const base = runs.join("-").slice(0, SLUG_MAX_LENGTH).replace(/-$/, "");
|
|
22815
|
+
return base.length >= 2 ? base : fallbackSlug(name);
|
|
22816
|
+
}
|
|
22817
|
+
|
|
22818
|
+
// src/commands/organization.ts
|
|
22819
|
+
var authRequired = () => new CliError(
|
|
22820
|
+
"auth_required",
|
|
22821
|
+
"This command requires an active CLI session.",
|
|
22822
|
+
"Run `deessejs auth login` to sign in."
|
|
22823
|
+
);
|
|
22824
|
+
var inaccessibleOrganization = () => new CliError(
|
|
22825
|
+
"organization_not_found",
|
|
22826
|
+
"Organization not found or you are not a member.",
|
|
22827
|
+
"Run `deessejs organization list` to see your organizations."
|
|
22828
|
+
);
|
|
22829
|
+
var isRecordWithCode = (error52) => typeof error52 === "object" && error52 !== null && "code" in error52;
|
|
22830
|
+
var organizationErrorFromCode = (code) => {
|
|
22831
|
+
if (code === "UNAUTHORIZED") return authRequired();
|
|
22832
|
+
if (code === "ORGANIZATION_ACCESS_DENIED" || code === "USER_IS_NOT_A_MEMBER_OF_THE_ORGANIZATION" || code === "ORGANIZATION_NOT_FOUND") {
|
|
22833
|
+
return inaccessibleOrganization();
|
|
22834
|
+
}
|
|
22835
|
+
if (code === "TEMPLATE_SLUG_CONFLICT")
|
|
22836
|
+
return new CliError(
|
|
22837
|
+
"organization_api_error",
|
|
22838
|
+
"This organization already has a template with that slug.",
|
|
22839
|
+
"Choose a different --slug value."
|
|
22840
|
+
);
|
|
22841
|
+
if (code === "TEMPLATE_GITHUB_SOURCE_INVALID")
|
|
22842
|
+
return new CliError(
|
|
22843
|
+
"organization_api_error",
|
|
22844
|
+
"Use a URL to a public GitHub repository.",
|
|
22845
|
+
"Check --repository and try again."
|
|
22846
|
+
);
|
|
22847
|
+
if (code === "TEMPLATE_GITHUB_FETCH_FAILED")
|
|
22848
|
+
return new CliError(
|
|
22849
|
+
"network_error",
|
|
22850
|
+
"GitHub data could not be fetched.",
|
|
22851
|
+
"Check the repository URL and retry."
|
|
22852
|
+
);
|
|
22853
|
+
if (code === "ORGANIZATION_EMAIL_VERIFICATION_REQUIRED") {
|
|
22854
|
+
return new CliError(
|
|
22855
|
+
"organization_api_error",
|
|
22856
|
+
"Verify your email before creating an organization.",
|
|
22857
|
+
"Open the verification email for your account, then retry."
|
|
22858
|
+
);
|
|
22859
|
+
}
|
|
22860
|
+
if (code === "ORGANIZATION_NAME_INVALID" || code === "ORGANIZATION_SLUG_INVALID") {
|
|
22861
|
+
return new CliError(
|
|
22862
|
+
"organization_api_error",
|
|
22863
|
+
"That organization name cannot be used.",
|
|
22864
|
+
"Choose a different name and try again."
|
|
22865
|
+
);
|
|
22866
|
+
}
|
|
22867
|
+
if (code === "ORGANIZATION_CREATE_IN_PROGRESS") {
|
|
22868
|
+
return new CliError(
|
|
22869
|
+
"organization_api_error",
|
|
22870
|
+
"An organization is already being created for this account.",
|
|
22871
|
+
"Wait a moment, then retry."
|
|
22872
|
+
);
|
|
22873
|
+
}
|
|
22874
|
+
if (code === "ORGANIZATION_CREATE_FAILED") {
|
|
22875
|
+
return new CliError(
|
|
22876
|
+
"organization_api_error",
|
|
22877
|
+
"The organization could not be created.",
|
|
22878
|
+
"Retry in a moment."
|
|
22879
|
+
);
|
|
22880
|
+
}
|
|
22881
|
+
};
|
|
22882
|
+
var organizationError = (error52) => {
|
|
22883
|
+
if (error52 instanceof CliError) return error52;
|
|
22884
|
+
if (isRecordWithCode(error52)) {
|
|
22885
|
+
const mapped = organizationErrorFromCode(error52.code);
|
|
22886
|
+
if (mapped) return mapped;
|
|
22887
|
+
}
|
|
22888
|
+
if (error52 instanceof TypeError) {
|
|
22889
|
+
return new CliError(
|
|
22890
|
+
"network_error",
|
|
22891
|
+
"Could not reach the DeesseJS API.",
|
|
22892
|
+
error52.message
|
|
22893
|
+
);
|
|
22894
|
+
}
|
|
22895
|
+
return internal("The organization request failed unexpectedly.");
|
|
22896
|
+
};
|
|
22897
|
+
function reportError(error52, json2) {
|
|
22898
|
+
const cliError = organizationError(error52);
|
|
22899
|
+
if (json2) {
|
|
22900
|
+
printJson({
|
|
22901
|
+
ok: false,
|
|
22902
|
+
code: cliError.code,
|
|
22903
|
+
message: cliError.message,
|
|
22904
|
+
hint: cliError.hint
|
|
22905
|
+
});
|
|
22906
|
+
} else {
|
|
22907
|
+
printError(cliError);
|
|
22908
|
+
}
|
|
22909
|
+
process.exit(cliError.exitCode());
|
|
22910
|
+
}
|
|
22911
|
+
var signedInToken = () => {
|
|
22912
|
+
const stored = readAuth();
|
|
22913
|
+
if (!stored) throw authRequired();
|
|
22914
|
+
return stored.access_token;
|
|
22915
|
+
};
|
|
22916
|
+
async function reportAction(action, json2, spinner) {
|
|
22917
|
+
try {
|
|
22918
|
+
const result = await action();
|
|
22919
|
+
spinner?.succeed();
|
|
22920
|
+
return result;
|
|
22921
|
+
} catch (error52) {
|
|
22922
|
+
spinner?.fail();
|
|
22923
|
+
reportError(error52, json2);
|
|
22924
|
+
}
|
|
22925
|
+
}
|
|
22926
|
+
var collectLabel = (value, previous = []) => [
|
|
22927
|
+
...previous,
|
|
22928
|
+
value
|
|
22929
|
+
];
|
|
22930
|
+
var completeBeforePrint = (complete, print) => {
|
|
22931
|
+
complete();
|
|
22932
|
+
print();
|
|
22933
|
+
};
|
|
22934
|
+
var organizationListCommand = new Command("list").description("List your organizations").option("--json", "JSON output for scripting").action(async (options) => {
|
|
22935
|
+
let token;
|
|
22936
|
+
try {
|
|
22937
|
+
token = signedInToken();
|
|
22938
|
+
} catch (error52) {
|
|
22939
|
+
reportError(error52, options.json ?? false);
|
|
22940
|
+
}
|
|
22941
|
+
const spinner = options.json ? null : ora8("Fetching organizations...").start();
|
|
22942
|
+
const organizations = await reportAction(
|
|
22943
|
+
() => listOrganizations(token),
|
|
22944
|
+
options.json ?? false,
|
|
22945
|
+
spinner
|
|
22946
|
+
);
|
|
22947
|
+
if (options.json) {
|
|
22948
|
+
printJson({ organizations });
|
|
22949
|
+
} else {
|
|
22950
|
+
printOrganizationsTable(organizations);
|
|
22951
|
+
}
|
|
22952
|
+
});
|
|
22953
|
+
var organizationInfoCommand = new Command("info").description("Show details for one of your organizations").argument("<slug>", "organization slug").option("--json", "JSON output for scripting").action(async (slug, options) => {
|
|
22954
|
+
let token;
|
|
22955
|
+
try {
|
|
22956
|
+
token = signedInToken();
|
|
22957
|
+
} catch (error52) {
|
|
22958
|
+
reportError(error52, options.json ?? false);
|
|
22959
|
+
}
|
|
22960
|
+
const spinner = options.json ? null : ora8("Fetching organization...").start();
|
|
22961
|
+
const organization = await reportAction(
|
|
22962
|
+
async () => {
|
|
22963
|
+
const memberships = await listOrganizations(token);
|
|
22964
|
+
const memberOrganization = memberships.find(
|
|
22965
|
+
(item) => item.slug === slug
|
|
22966
|
+
);
|
|
22967
|
+
if (!memberOrganization) throw inaccessibleOrganization();
|
|
22968
|
+
const role = await getOrganizationRole(memberOrganization.id, token);
|
|
22969
|
+
return { ...memberOrganization, role };
|
|
22970
|
+
},
|
|
22971
|
+
options.json ?? false,
|
|
22972
|
+
spinner
|
|
22973
|
+
);
|
|
22974
|
+
if (options.json) {
|
|
22975
|
+
printJson({ organization });
|
|
22976
|
+
} else {
|
|
22977
|
+
printOrganizationInfo(organization);
|
|
22978
|
+
}
|
|
22979
|
+
});
|
|
22980
|
+
var organizationCreateCommand = new Command("create").description("Create an organization").argument("<name>", "organization display name").option("--json", "JSON output for scripting").action(async (name, options) => {
|
|
22981
|
+
let client;
|
|
22982
|
+
try {
|
|
22983
|
+
client = createAuthenticatedORPCClient(signedInToken());
|
|
22984
|
+
} catch (error52) {
|
|
22985
|
+
reportError(error52, options.json ?? false);
|
|
22986
|
+
}
|
|
22987
|
+
const spinner = options.json ? null : ora8("Creating organization...").start();
|
|
22988
|
+
const organization = await reportAction(
|
|
22989
|
+
() => client.organization.create({
|
|
22990
|
+
name,
|
|
22991
|
+
slug: organizationSlugFromName(name)
|
|
22992
|
+
}),
|
|
22993
|
+
options.json ?? false,
|
|
22994
|
+
spinner
|
|
22995
|
+
);
|
|
22996
|
+
if (options.json) {
|
|
22997
|
+
printJson({ organization });
|
|
22998
|
+
} else {
|
|
22999
|
+
console.log(`Created ${organization.name} (${organization.slug}).`);
|
|
23000
|
+
}
|
|
23001
|
+
});
|
|
23002
|
+
var organizationTemplateCommand = new Command("template").description(
|
|
23003
|
+
"Manage templates owned by an organization"
|
|
23004
|
+
);
|
|
23005
|
+
organizationTemplateCommand.command("list").description("List templates owned by an organization").argument("<organization-slug>", "organization slug").option("--json", "JSON output for scripting").action(async (organizationSlug, options) => {
|
|
23006
|
+
await runOrganizationTemplateAction(
|
|
23007
|
+
options,
|
|
23008
|
+
"Fetching organization templates...",
|
|
23009
|
+
async (client, complete) => {
|
|
23010
|
+
const { templates } = await client.organization.templates.list({
|
|
23011
|
+
organizationSlug
|
|
23012
|
+
});
|
|
23013
|
+
completeBeforePrint(complete, () => {
|
|
23014
|
+
if (options.json) printJson({ templates });
|
|
23015
|
+
else printOrganizationTemplatesTable(templates);
|
|
23016
|
+
});
|
|
23017
|
+
}
|
|
23018
|
+
);
|
|
22448
23019
|
});
|
|
23020
|
+
organizationTemplateCommand.command("info").description("Show an organization-owned template").argument("<organization-slug>", "organization slug").argument("<template-slug>", "template slug").option("--json", "JSON output for scripting").action(
|
|
23021
|
+
async (organizationSlug, slug, options) => {
|
|
23022
|
+
await runOrganizationTemplateAction(
|
|
23023
|
+
options,
|
|
23024
|
+
"Fetching organization template...",
|
|
23025
|
+
async (client, complete) => {
|
|
23026
|
+
const { templates } = await client.organization.templates.list({
|
|
23027
|
+
organizationSlug
|
|
23028
|
+
});
|
|
23029
|
+
const template = templates.find((item) => item.slug === slug);
|
|
23030
|
+
if (!template)
|
|
23031
|
+
throw new CliError(
|
|
23032
|
+
"organization_api_error",
|
|
23033
|
+
`Template "${slug}" not found in organization "${organizationSlug}".`
|
|
23034
|
+
);
|
|
23035
|
+
completeBeforePrint(complete, () => {
|
|
23036
|
+
if (options.json) printJson({ template });
|
|
23037
|
+
else printOrganizationTemplateInfo(template);
|
|
23038
|
+
});
|
|
23039
|
+
}
|
|
23040
|
+
);
|
|
23041
|
+
}
|
|
23042
|
+
);
|
|
23043
|
+
organizationTemplateCommand.command("add").description("Add a template to an organization").argument("<organization-slug>", "organization slug").requiredOption("--slug <slug>", "template slug").requiredOption("--name <name>", "display name").requiredOption("--repository <url>", "public GitHub repository URL").option("--description <text>", "template description").requiredOption("--category <category>", "template category").option(
|
|
23044
|
+
"--label <label>",
|
|
23045
|
+
"template label (repeat for multiple labels)",
|
|
23046
|
+
collectLabel,
|
|
23047
|
+
[]
|
|
23048
|
+
).option("--license <license>", "license fallback").option("--json", "JSON output for scripting").action(
|
|
23049
|
+
async (organizationSlug, options) => {
|
|
23050
|
+
await runOrganizationTemplateAction(
|
|
23051
|
+
options,
|
|
23052
|
+
"Adding organization template...",
|
|
23053
|
+
async (client, complete) => {
|
|
23054
|
+
let template;
|
|
23055
|
+
try {
|
|
23056
|
+
template = await client.organization.templates.create({
|
|
23057
|
+
organizationSlug,
|
|
23058
|
+
slug: options.slug,
|
|
23059
|
+
name: options.name,
|
|
23060
|
+
repositoryUrl: options.repository,
|
|
23061
|
+
category: options.category,
|
|
23062
|
+
labels: options.label ?? [],
|
|
23063
|
+
...options.description === void 0 ? {} : { descriptionOverride: options.description },
|
|
23064
|
+
...options.license === void 0 ? {} : { licenseFallback: options.license }
|
|
23065
|
+
});
|
|
23066
|
+
} catch (error52) {
|
|
23067
|
+
if (isRecordWithCode(error52) && error52.code === "ORGANIZATION_ACCESS_DENIED") {
|
|
23068
|
+
throw new CliError(
|
|
23069
|
+
"organization_api_error",
|
|
23070
|
+
"Only organization owners and admins can add templates.",
|
|
23071
|
+
"Ask an organization owner or admin to run this command."
|
|
23072
|
+
);
|
|
23073
|
+
}
|
|
23074
|
+
throw error52;
|
|
23075
|
+
}
|
|
23076
|
+
completeBeforePrint(complete, () => {
|
|
23077
|
+
if (options.json)
|
|
23078
|
+
printJson({
|
|
23079
|
+
template,
|
|
23080
|
+
ownership: "organization",
|
|
23081
|
+
publication: "unpublished"
|
|
23082
|
+
});
|
|
23083
|
+
else
|
|
23084
|
+
console.log(
|
|
23085
|
+
`Added ${template.name} (${template.slug}) to ${organizationSlug}. It is organization-owned and not publicly published.`
|
|
23086
|
+
);
|
|
23087
|
+
});
|
|
23088
|
+
}
|
|
23089
|
+
);
|
|
23090
|
+
}
|
|
23091
|
+
);
|
|
23092
|
+
async function runOrganizationTemplateAction(options, message, action) {
|
|
23093
|
+
let client;
|
|
23094
|
+
try {
|
|
23095
|
+
client = createAuthenticatedORPCClient(signedInToken());
|
|
23096
|
+
} catch (error52) {
|
|
23097
|
+
reportError(error52, options.json ?? false);
|
|
23098
|
+
}
|
|
23099
|
+
const spinner = options.json ? null : ora8(message).start();
|
|
23100
|
+
await reportAction(
|
|
23101
|
+
() => action(client, () => spinner?.succeed()),
|
|
23102
|
+
options.json ?? false,
|
|
23103
|
+
null
|
|
23104
|
+
);
|
|
23105
|
+
}
|
|
23106
|
+
function printOrganizationTemplateInfo(template) {
|
|
23107
|
+
console.log(
|
|
23108
|
+
`Organization-owned template: ${template.name} (${template.slug})`
|
|
23109
|
+
);
|
|
23110
|
+
console.log(`Repository: ${template.canonicalUrl}`);
|
|
23111
|
+
console.log(
|
|
23112
|
+
`Publication state: ${template.currentlyPublished ? "current" : template.publication?.publicationState ?? "unpublished"}`
|
|
23113
|
+
);
|
|
23114
|
+
console.log(
|
|
23115
|
+
`Review status: ${template.publication?.reviewStatus ?? "not submitted"}`
|
|
23116
|
+
);
|
|
23117
|
+
if (template.publication?.reviewReason)
|
|
23118
|
+
console.log(`Review reason: ${template.publication.reviewReason}`);
|
|
23119
|
+
}
|
|
23120
|
+
var organizationCommand = new Command("organization").description("Manage your organizations").addCommand(organizationListCommand).addCommand(organizationInfoCommand).addCommand(organizationCreateCommand).addCommand(organizationTemplateCommand);
|
|
22449
23121
|
|
|
22450
23122
|
// src/index.ts
|
|
22451
23123
|
var program = new Command();
|
|
@@ -22454,6 +23126,7 @@ program.addCommand(listCommand);
|
|
|
22454
23126
|
program.addCommand(infoCommand);
|
|
22455
23127
|
program.addCommand(initCommand);
|
|
22456
23128
|
program.addCommand(blockCommand);
|
|
23129
|
+
program.addCommand(organizationCommand);
|
|
22457
23130
|
var authCommand = new Command("auth").description(
|
|
22458
23131
|
"Authenticate this machine against the DeesseJS server"
|
|
22459
23132
|
);
|
|
@@ -22461,19 +23134,19 @@ authCommand.addCommand(loginCommand);
|
|
|
22461
23134
|
authCommand.addCommand(statusCommand);
|
|
22462
23135
|
authCommand.addCommand(logoutCommand);
|
|
22463
23136
|
program.addCommand(authCommand);
|
|
22464
|
-
program.parseAsync(process.argv).catch((
|
|
22465
|
-
if (
|
|
22466
|
-
printError(
|
|
22467
|
-
process.exit(
|
|
23137
|
+
program.parseAsync(process.argv).catch((err2) => {
|
|
23138
|
+
if (err2 instanceof CliError) {
|
|
23139
|
+
printError(err2);
|
|
23140
|
+
process.exit(err2.exitCode());
|
|
22468
23141
|
}
|
|
22469
23142
|
process.stderr.write(
|
|
22470
|
-
`${pc6.red("Internal error")}: ${
|
|
23143
|
+
`${pc6.red("Internal error")}: ${err2 instanceof Error ? err2.message : String(err2)}
|
|
22471
23144
|
`
|
|
22472
23145
|
);
|
|
22473
23146
|
if (process.env.DEESSEJS_DEBUG) {
|
|
22474
23147
|
process.stderr.write(
|
|
22475
23148
|
`
|
|
22476
|
-
${
|
|
23149
|
+
${err2 instanceof Error && err2.stack ? err2.stack : ""}
|
|
22477
23150
|
`
|
|
22478
23151
|
);
|
|
22479
23152
|
}
|