@apotech-os/cli 2.1.0 → 2.3.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/dist/index.js +513 -48
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -6372,7 +6372,7 @@ var {
|
|
|
6372
6372
|
} = import_index.default;
|
|
6373
6373
|
|
|
6374
6374
|
// src/index.ts
|
|
6375
|
-
var
|
|
6375
|
+
var import_fs9 = require("fs");
|
|
6376
6376
|
var import_path6 = require("path");
|
|
6377
6377
|
|
|
6378
6378
|
// ../../node_modules/.pnpm/chokidar@4.0.3/node_modules/chokidar/esm/index.js
|
|
@@ -22724,14 +22724,51 @@ var FunctionTriggerSchema = external_exports.discriminatedUnion("type", [
|
|
|
22724
22724
|
type: external_exports.literal("httpRoute"),
|
|
22725
22725
|
path: external_exports.string(),
|
|
22726
22726
|
method: external_exports.enum(["GET", "POST", "PUT", "PATCH", "DELETE", "ALL"]),
|
|
22727
|
+
/**
|
|
22728
|
+
* HISTORICAL form of `auth`, kept because it shipped in 2.1.0 and is what
|
|
22729
|
+
* already-published manifests declare. `false` means "webhook, gated by an
|
|
22730
|
+
* HMAC signature"; `true`/absent means "authenticated session".
|
|
22731
|
+
* Equivalent to `auth: 'hmac'` / `auth: 'session'`. Declaring BOTH is
|
|
22732
|
+
* rejected by the refinement on FunctionDefSchema — two ways to say the
|
|
22733
|
+
* same thing is two ways to disagree.
|
|
22734
|
+
*/
|
|
22727
22735
|
isAuthRequired: external_exports.boolean().optional(),
|
|
22736
|
+
/**
|
|
22737
|
+
* How the caller proves its right to this route. Absent, it is derived from
|
|
22738
|
+
* `isAuthRequired` — always read it through `resolveHttpRouteAuth`, never
|
|
22739
|
+
* off the raw field, so a route cannot be guarded one way and documented
|
|
22740
|
+
* another.
|
|
22741
|
+
* - 'session' — an authenticated session AND `minRole` on this app.
|
|
22742
|
+
* - 'hmac' — HMAC-SHA256 over the raw body (inbound provider webhooks).
|
|
22743
|
+
* - 'apiKey' — an `AppApiKey` (`wopilo_app_…`) scoped to THIS app, for a
|
|
22744
|
+
* third-party SaaS that cannot sign. The key carries the
|
|
22745
|
+
* app; the app carries its manifest role.
|
|
22746
|
+
*/
|
|
22747
|
+
auth: external_exports.enum(["session", "hmac", "apiKey"]).optional(),
|
|
22748
|
+
/**
|
|
22749
|
+
* What the HTTP response carries.
|
|
22750
|
+
* - 'runId' — default. Dispatches an Inngest event and answers with the
|
|
22751
|
+
* run id; the handler's return value is discarded.
|
|
22752
|
+
* - 'result' — runs the handler IN-PROCESS and returns its value as the
|
|
22753
|
+
* response body. No durable Inngest function is registered
|
|
22754
|
+
* for such a route (see app-inngest-functions.ts).
|
|
22755
|
+
*/
|
|
22756
|
+
response: external_exports.enum(["runId", "result"]).optional(),
|
|
22757
|
+
/**
|
|
22758
|
+
* Wall-clock budget in ms. Only meaningful with `response: 'result'` — the
|
|
22759
|
+
* durable path has no wall clock by design — and rejected without it by the
|
|
22760
|
+
* refinement on FunctionDefSchema. Same bounds and server-side clamp as
|
|
22761
|
+
* `uiInvoke`.
|
|
22762
|
+
*/
|
|
22763
|
+
timeoutMs: external_exports.number().int().min(1e3).max(3e4).optional(),
|
|
22728
22764
|
/**
|
|
22729
22765
|
* Minimum role the calling session must hold on this app
|
|
22730
22766
|
* (contextId = manifest.slug). Defaults to EDITOR — fail-closed, like
|
|
22731
22767
|
* `uiInvoke` and for the same reason: the handler runs with the app's FULL
|
|
22732
22768
|
* manifest role, not the caller's.
|
|
22733
|
-
*
|
|
22734
|
-
* the
|
|
22769
|
+
* Only meaningful in `session` mode: with `hmac` or `apiKey` there is no
|
|
22770
|
+
* session to hold a role, and the signature/key governs — rejected by the
|
|
22771
|
+
* refinement on FunctionDefSchema.
|
|
22735
22772
|
*/
|
|
22736
22773
|
minRole: external_exports.enum(["VIEWER", "EDITOR", "ADMIN"]).optional()
|
|
22737
22774
|
}),
|
|
@@ -22850,7 +22887,15 @@ var FunctionDefFieldsSchema = external_exports.object({
|
|
|
22850
22887
|
* the platform, not the app — declaring an input schema there is always a
|
|
22851
22888
|
* mistake and is rejected by the refinement below.
|
|
22852
22889
|
*/
|
|
22853
|
-
input: external_exports.array(FieldDefSchema).optional()
|
|
22890
|
+
input: external_exports.array(FieldDefSchema).optional(),
|
|
22891
|
+
/**
|
|
22892
|
+
* Purely descriptive narratives rendered in the automations catalogue
|
|
22893
|
+
* ("Déclencheur & effet"), mirroring `AutomationManifest.when` / `.then`
|
|
22894
|
+
* carried by the platform's own jobs. No runtime effect whatsoever: an app
|
|
22895
|
+
* function without them behaves identically, its card simply stays empty.
|
|
22896
|
+
*/
|
|
22897
|
+
when: external_exports.string().min(1).describe('Human "quand" narrative \u2014 what makes this function run (UI only).').optional(),
|
|
22898
|
+
then: external_exports.string().min(1).describe('Human "alors" narrative \u2014 what this function does when it runs (UI only).').optional()
|
|
22854
22899
|
});
|
|
22855
22900
|
var FunctionDefSchema = FunctionDefFieldsSchema.superRefine((fn, ctx) => {
|
|
22856
22901
|
if (fn.input && fn.trigger.type !== "uiInvoke" && fn.trigger.type !== "httpRoute") {
|
|
@@ -22867,6 +22912,30 @@ var FunctionDefSchema = FunctionDefFieldsSchema.superRefine((fn, ctx) => {
|
|
|
22867
22912
|
message: '"minRole" is meaningless on an unauthenticated webhook route (isAuthRequired: false)'
|
|
22868
22913
|
});
|
|
22869
22914
|
}
|
|
22915
|
+
if (fn.trigger.type === "httpRoute") {
|
|
22916
|
+
const { auth, isAuthRequired, minRole, response, timeoutMs } = fn.trigger;
|
|
22917
|
+
if (auth !== void 0 && isAuthRequired !== void 0) {
|
|
22918
|
+
ctx.addIssue({
|
|
22919
|
+
code: "custom",
|
|
22920
|
+
path: ["trigger", "auth"],
|
|
22921
|
+
message: `"auth" and "isAuthRequired" cannot both be declared \u2014 they are two ways to say the same thing. Keep "auth: '${auth}'" and drop "isAuthRequired".`
|
|
22922
|
+
});
|
|
22923
|
+
}
|
|
22924
|
+
if (auth !== void 0 && auth !== "session" && minRole !== void 0) {
|
|
22925
|
+
ctx.addIssue({
|
|
22926
|
+
code: "custom",
|
|
22927
|
+
path: ["trigger", "minRole"],
|
|
22928
|
+
message: `"minRole" is meaningless with auth: '${auth}' \u2014 there is no session to hold a role`
|
|
22929
|
+
});
|
|
22930
|
+
}
|
|
22931
|
+
if (timeoutMs !== void 0 && (response ?? "runId") !== "result") {
|
|
22932
|
+
ctx.addIssue({
|
|
22933
|
+
code: "custom",
|
|
22934
|
+
path: ["trigger", "timeoutMs"],
|
|
22935
|
+
message: `"timeoutMs" is only meaningful with response: 'result' \u2014 the fire-and-forget path answers before the handler runs, so it has no wall clock to budget`
|
|
22936
|
+
});
|
|
22937
|
+
}
|
|
22938
|
+
}
|
|
22870
22939
|
});
|
|
22871
22940
|
var AppRoleSchema = external_exports.object({
|
|
22872
22941
|
reads: external_exports.array(external_exports.string()),
|
|
@@ -23211,7 +23280,10 @@ var CoreShopifyOrderLineItemSchema = external_exports.object({
|
|
|
23211
23280
|
taxLines: external_exports.array(ShopifyTaxLineSchema),
|
|
23212
23281
|
requiresShipping: external_exports.boolean(),
|
|
23213
23282
|
isGiftCard: external_exports.boolean(),
|
|
23214
|
-
customAttributes: external_exports.array(ShopifyCustomAttributeSchema)
|
|
23283
|
+
customAttributes: external_exports.array(ShopifyCustomAttributeSchema),
|
|
23284
|
+
/** The PARENT ORDER's dates, denormalized — see the conventions above. */
|
|
23285
|
+
orderCreatedAt: external_exports.coerce.date().nullish(),
|
|
23286
|
+
orderUpdatedAt: external_exports.coerce.date().nullish()
|
|
23215
23287
|
}).strict();
|
|
23216
23288
|
var coreShopifyOrderLineItem = {
|
|
23217
23289
|
key: "shopify-order-line-item",
|
|
@@ -23240,7 +23312,10 @@ var CoreShopifyRefundSchema = external_exports.object({
|
|
|
23240
23312
|
note: external_exports.string().nullable(),
|
|
23241
23313
|
totalRefundedCents: external_exports.number().int(),
|
|
23242
23314
|
refundLineItems: external_exports.array(ShopifyRefundLineItemSchema),
|
|
23243
|
-
orderAdjustments: external_exports.array(ShopifyOrderAdjustmentSchema)
|
|
23315
|
+
orderAdjustments: external_exports.array(ShopifyOrderAdjustmentSchema),
|
|
23316
|
+
/** The PARENT ORDER's dates, denormalized — see the conventions above. */
|
|
23317
|
+
orderCreatedAt: external_exports.coerce.date().nullish(),
|
|
23318
|
+
orderUpdatedAt: external_exports.coerce.date().nullish()
|
|
23244
23319
|
}).strict();
|
|
23245
23320
|
var coreShopifyRefund = {
|
|
23246
23321
|
key: "shopify-refund",
|
|
@@ -23265,7 +23340,10 @@ var CoreShopifyReturnSchema = external_exports.object({
|
|
|
23265
23340
|
totalQuantity: external_exports.number().int(),
|
|
23266
23341
|
returnLineItems: external_exports.array(ShopifyReturnLineItemSchema),
|
|
23267
23342
|
declineReason: external_exports.string().nullable(),
|
|
23268
|
-
declineNote: external_exports.string().nullable()
|
|
23343
|
+
declineNote: external_exports.string().nullable(),
|
|
23344
|
+
/** The PARENT ORDER's dates, denormalized — see the conventions above. */
|
|
23345
|
+
orderCreatedAt: external_exports.coerce.date().nullish(),
|
|
23346
|
+
orderUpdatedAt: external_exports.coerce.date().nullish()
|
|
23269
23347
|
}).strict();
|
|
23270
23348
|
var coreShopifyReturn = {
|
|
23271
23349
|
key: "shopify-return",
|
|
@@ -23297,7 +23375,10 @@ var CoreShopifyFulfillmentSchema = external_exports.object({
|
|
|
23297
23375
|
estimatedDeliveryAt: external_exports.coerce.date().nullable(),
|
|
23298
23376
|
trackingInfo: external_exports.array(ShopifyTrackingInfoSchema),
|
|
23299
23377
|
locationName: external_exports.string().nullable(),
|
|
23300
|
-
fulfillmentLineItems: external_exports.array(ShopifyFulfillmentLineItemSchema)
|
|
23378
|
+
fulfillmentLineItems: external_exports.array(ShopifyFulfillmentLineItemSchema),
|
|
23379
|
+
/** The PARENT ORDER's dates, denormalized — see the conventions above. */
|
|
23380
|
+
orderCreatedAt: external_exports.coerce.date().nullish(),
|
|
23381
|
+
orderUpdatedAt: external_exports.coerce.date().nullish()
|
|
23301
23382
|
}).strict();
|
|
23302
23383
|
var coreShopifyFulfillment = {
|
|
23303
23384
|
key: "shopify-fulfillment",
|
|
@@ -23843,6 +23924,7 @@ async function fetchRuns(opts) {
|
|
|
23843
23924
|
const params = new URLSearchParams();
|
|
23844
23925
|
if (opts.appSlug) params.set("appSlug", opts.appSlug);
|
|
23845
23926
|
if (opts.functionName) params.set("functionName", opts.functionName);
|
|
23927
|
+
if (opts.slug) params.set("slug", opts.slug);
|
|
23846
23928
|
if (opts.status) params.set("status", opts.status);
|
|
23847
23929
|
if (opts.limit !== void 0) params.set("limit", String(opts.limit));
|
|
23848
23930
|
if (opts.cursor) params.set("cursor", opts.cursor);
|
|
@@ -23860,12 +23942,37 @@ async function fetchRunDetail(opts) {
|
|
|
23860
23942
|
opts.apiKey
|
|
23861
23943
|
);
|
|
23862
23944
|
}
|
|
23945
|
+
async function fetchJobs(opts) {
|
|
23946
|
+
return getJson(opts.baseUrl, "/jobs", void 0, opts.apiKey);
|
|
23947
|
+
}
|
|
23948
|
+
async function lookupRun(opts) {
|
|
23949
|
+
const params = new URLSearchParams({ ref: opts.ref });
|
|
23950
|
+
return getJson(opts.baseUrl, "/runs/lookup", params, opts.apiKey);
|
|
23951
|
+
}
|
|
23952
|
+
async function triggerJob(opts) {
|
|
23953
|
+
return postJson(
|
|
23954
|
+
opts.baseUrl,
|
|
23955
|
+
`/jobs/${encodeURIComponent(opts.key)}/run`,
|
|
23956
|
+
{ data: opts.data },
|
|
23957
|
+
opts.apiKey
|
|
23958
|
+
);
|
|
23959
|
+
}
|
|
23863
23960
|
async function getJson(baseUrl, path, params, apiKey) {
|
|
23864
23961
|
const query = params?.toString();
|
|
23865
23962
|
const url2 = `${baseUrl.replace(/\/$/, "")}${path}${query ? `?${query}` : ""}`;
|
|
23866
23963
|
const headers = {};
|
|
23867
23964
|
if (apiKey) headers["Authorization"] = `Bearer ${apiKey}`;
|
|
23868
|
-
|
|
23965
|
+
return readJsonOrThrow(await fetch(url2, { headers }));
|
|
23966
|
+
}
|
|
23967
|
+
async function postJson(baseUrl, path, body, apiKey) {
|
|
23968
|
+
const url2 = `${baseUrl.replace(/\/$/, "")}${path}`;
|
|
23969
|
+
const headers = { "Content-Type": "application/json" };
|
|
23970
|
+
if (apiKey) headers["Authorization"] = `Bearer ${apiKey}`;
|
|
23971
|
+
return readJsonOrThrow(
|
|
23972
|
+
await fetch(url2, { method: "POST", headers, body: JSON.stringify(body) })
|
|
23973
|
+
);
|
|
23974
|
+
}
|
|
23975
|
+
async function readJsonOrThrow(res) {
|
|
23869
23976
|
const body = await res.json().catch(() => ({ message: res.statusText }));
|
|
23870
23977
|
if (!res.ok) {
|
|
23871
23978
|
const code = extractCode(body);
|
|
@@ -24517,7 +24624,7 @@ function openBrowser(url2) {
|
|
|
24517
24624
|
function sleep(ms) {
|
|
24518
24625
|
return new Promise((resolve4) => setTimeout(resolve4, ms));
|
|
24519
24626
|
}
|
|
24520
|
-
async function
|
|
24627
|
+
async function postJson2(url2, body) {
|
|
24521
24628
|
const res = await fetch(url2, {
|
|
24522
24629
|
method: "POST",
|
|
24523
24630
|
headers: { "Content-Type": "application/json" },
|
|
@@ -24534,7 +24641,7 @@ async function promptForKey(remote) {
|
|
|
24534
24641
|
console.log(`Credentials stored for remote "${remote}".`);
|
|
24535
24642
|
}
|
|
24536
24643
|
async function browserLogin(remote, baseUrl) {
|
|
24537
|
-
const device = await
|
|
24644
|
+
const device = await postJson2(`${baseUrl.replace(/\/$/, "")}/platform/cli-auth/device`, {
|
|
24538
24645
|
clientLabel: clientLabel()
|
|
24539
24646
|
});
|
|
24540
24647
|
if (device.status === 404) {
|
|
@@ -24562,7 +24669,7 @@ async function pollForKey(baseUrl, auth) {
|
|
|
24562
24669
|
while (Date.now() < deadline) {
|
|
24563
24670
|
await sleep(auth.interval * 1e3);
|
|
24564
24671
|
if (Date.now() >= deadline) break;
|
|
24565
|
-
const res = await
|
|
24672
|
+
const res = await postJson2(tokenUrl, { deviceCode: auth.deviceCode });
|
|
24566
24673
|
const result = res.body;
|
|
24567
24674
|
if (result?.status === "approved") {
|
|
24568
24675
|
console.log("\u2713");
|
|
@@ -24648,18 +24755,47 @@ function buildInstallCommand() {
|
|
|
24648
24755
|
}
|
|
24649
24756
|
|
|
24650
24757
|
// src/duration.ts
|
|
24651
|
-
var RELATIVE_DURATION = /^(\d+)(m|h|d)$/;
|
|
24758
|
+
var RELATIVE_DURATION = /^(\d+)(s|m|h|d)$/;
|
|
24652
24759
|
var UNIT_TO_MS = {
|
|
24760
|
+
s: 1e3,
|
|
24653
24761
|
m: 6e4,
|
|
24654
24762
|
h: 36e5,
|
|
24655
24763
|
d: 864e5
|
|
24656
24764
|
};
|
|
24657
|
-
function
|
|
24765
|
+
function parseDurationMs(value) {
|
|
24658
24766
|
const match = RELATIVE_DURATION.exec(value);
|
|
24659
|
-
if (!match) return
|
|
24767
|
+
if (!match) return void 0;
|
|
24660
24768
|
const amount = Number(match[1]);
|
|
24661
24769
|
const unit = match[2];
|
|
24662
|
-
return
|
|
24770
|
+
return amount * UNIT_TO_MS[unit];
|
|
24771
|
+
}
|
|
24772
|
+
function parseSince(value) {
|
|
24773
|
+
const ms = parseDurationMs(value);
|
|
24774
|
+
if (ms === void 0) return value;
|
|
24775
|
+
return new Date(Date.now() - ms).toISOString();
|
|
24776
|
+
}
|
|
24777
|
+
function formatDurationMs(ms) {
|
|
24778
|
+
if (ms < 1e3) return `${ms}ms`;
|
|
24779
|
+
const totalSeconds = Math.floor(ms / 1e3);
|
|
24780
|
+
const minutes = Math.floor(totalSeconds / 60);
|
|
24781
|
+
const seconds = totalSeconds % 60;
|
|
24782
|
+
return minutes === 0 ? `${seconds}s` : `${minutes}m${seconds}s`;
|
|
24783
|
+
}
|
|
24784
|
+
function formatRunDuration(run) {
|
|
24785
|
+
if (!run.startedAt) return "-";
|
|
24786
|
+
const end = run.endedAt ?? (run.status === "RUNNING" ? (/* @__PURE__ */ new Date()).toISOString() : void 0);
|
|
24787
|
+
if (!end) return "-";
|
|
24788
|
+
return formatDurationMs(new Date(end).getTime() - new Date(run.startedAt).getTime());
|
|
24789
|
+
}
|
|
24790
|
+
|
|
24791
|
+
// src/follow-poll.ts
|
|
24792
|
+
var FOLLOW_MIN_INTERVAL_MS = 1e3;
|
|
24793
|
+
var FOLLOW_MAX_INTERVAL_MS = 5e3;
|
|
24794
|
+
var FOLLOW_BACKOFF_FACTOR = 1.5;
|
|
24795
|
+
function nextFollowInterval({ current, hadActivity, hadError }) {
|
|
24796
|
+
if (hadError) return FOLLOW_MAX_INTERVAL_MS;
|
|
24797
|
+
if (hadActivity) return FOLLOW_MIN_INTERVAL_MS;
|
|
24798
|
+
return Math.min(current * FOLLOW_BACKOFF_FACTOR, FOLLOW_MAX_INTERVAL_MS);
|
|
24663
24799
|
}
|
|
24664
24800
|
|
|
24665
24801
|
// src/log-format.ts
|
|
@@ -24687,12 +24823,12 @@ function formatLogLine(line) {
|
|
|
24687
24823
|
];
|
|
24688
24824
|
return columns.filter((c) => c !== "").join(" ");
|
|
24689
24825
|
}
|
|
24826
|
+
function printLogLine(line, json2) {
|
|
24827
|
+
console.log(json2 ? JSON.stringify(line) : formatLogLine(line));
|
|
24828
|
+
}
|
|
24690
24829
|
|
|
24691
24830
|
// src/commands/logs.ts
|
|
24692
24831
|
var LEVELS = ["debug", "info", "warn", "error"];
|
|
24693
|
-
var FOLLOW_MIN_INTERVAL_MS = 1e3;
|
|
24694
|
-
var FOLLOW_MAX_INTERVAL_MS = 5e3;
|
|
24695
|
-
var FOLLOW_BACKOFF_FACTOR = 1.5;
|
|
24696
24832
|
function parseLevel(value) {
|
|
24697
24833
|
if (!LEVELS.includes(value)) {
|
|
24698
24834
|
throw new Error(`Invalid --level "${value}" \u2014 expected one of: ${LEVELS.join(", ")}.`);
|
|
@@ -24711,9 +24847,6 @@ function buildFetchOptions(appSlug, opts, baseUrl, apiKey) {
|
|
|
24711
24847
|
limit: Number(opts.limit)
|
|
24712
24848
|
};
|
|
24713
24849
|
}
|
|
24714
|
-
function printLine(line, json2) {
|
|
24715
|
-
console.log(json2 ? JSON.stringify(line) : formatLogLine(line));
|
|
24716
|
-
}
|
|
24717
24850
|
function warnIfEvicted(since, oldestAvailableAt) {
|
|
24718
24851
|
if (!since || !oldestAvailableAt) return;
|
|
24719
24852
|
if (new Date(since) < new Date(oldestAvailableAt)) {
|
|
@@ -24729,20 +24862,19 @@ function followLogs(fetchOptions, startSeq, json2) {
|
|
|
24729
24862
|
const poll = async () => {
|
|
24730
24863
|
try {
|
|
24731
24864
|
const page = await fetchLogs({ ...fetchOptions, afterSeq: nextSeq });
|
|
24732
|
-
|
|
24733
|
-
|
|
24734
|
-
|
|
24735
|
-
intervalMs
|
|
24736
|
-
|
|
24737
|
-
|
|
24738
|
-
}
|
|
24865
|
+
for (const line of page.lines) printLogLine(line, json2);
|
|
24866
|
+
if (page.lines.length > 0) nextSeq = page.nextSeq;
|
|
24867
|
+
intervalMs = nextFollowInterval({
|
|
24868
|
+
current: intervalMs,
|
|
24869
|
+
hadActivity: page.lines.length > 0
|
|
24870
|
+
});
|
|
24739
24871
|
} catch (err) {
|
|
24740
24872
|
if (err instanceof ApiError && (err.status === 401 || err.status === 503)) {
|
|
24741
24873
|
reportApiError(err);
|
|
24742
24874
|
}
|
|
24743
24875
|
const message = err instanceof Error ? err.message : String(err);
|
|
24744
24876
|
console.error(`warning: poll failed (${message}) \u2014 retrying`);
|
|
24745
|
-
intervalMs =
|
|
24877
|
+
intervalMs = nextFollowInterval({ current: intervalMs, hadActivity: false, hadError: true });
|
|
24746
24878
|
}
|
|
24747
24879
|
setTimeout(() => void poll(), intervalMs);
|
|
24748
24880
|
};
|
|
@@ -24762,7 +24894,7 @@ function buildLogsCommand() {
|
|
|
24762
24894
|
}
|
|
24763
24895
|
try {
|
|
24764
24896
|
const initial = await fetchLogs(fetchOptions);
|
|
24765
|
-
for (const line of initial.lines)
|
|
24897
|
+
for (const line of initial.lines) printLogLine(line, json2);
|
|
24766
24898
|
if (opts.follow) {
|
|
24767
24899
|
followLogs(fetchOptions, initial.nextSeq, json2);
|
|
24768
24900
|
return;
|
|
@@ -24774,6 +24906,351 @@ function buildLogsCommand() {
|
|
|
24774
24906
|
});
|
|
24775
24907
|
}
|
|
24776
24908
|
|
|
24909
|
+
// src/commands/runs-start.ts
|
|
24910
|
+
var import_fs8 = require("fs");
|
|
24911
|
+
var RUN_LOOKUP_INTERVAL_MS = 1e3;
|
|
24912
|
+
var RUN_LOOKUP_BUDGET_MS = 3e4;
|
|
24913
|
+
function fail(code, ...lines) {
|
|
24914
|
+
for (const line of lines) console.error(line);
|
|
24915
|
+
process.exit(code);
|
|
24916
|
+
}
|
|
24917
|
+
function sleep2(ms) {
|
|
24918
|
+
return new Promise((resolve4) => setTimeout(resolve4, ms));
|
|
24919
|
+
}
|
|
24920
|
+
function parseTarget(target) {
|
|
24921
|
+
const [appSlug, functionName, ...rest] = target.split("/");
|
|
24922
|
+
if (!appSlug || !functionName || rest.length > 0) {
|
|
24923
|
+
fail(2, `Error: expected <appSlug>/<functionName>, got "${target}".`);
|
|
24924
|
+
}
|
|
24925
|
+
return { appSlug, functionName };
|
|
24926
|
+
}
|
|
24927
|
+
function readDataFile(path) {
|
|
24928
|
+
try {
|
|
24929
|
+
return path === "-" ? (0, import_fs8.readFileSync)(0, "utf8") : (0, import_fs8.readFileSync)(path, "utf8");
|
|
24930
|
+
} catch (err) {
|
|
24931
|
+
const detail = err instanceof Error ? err.message : String(err);
|
|
24932
|
+
fail(2, `Error: cannot read --data-file "${path}": ${detail}`);
|
|
24933
|
+
}
|
|
24934
|
+
}
|
|
24935
|
+
function parseJsonObject(raw, flag) {
|
|
24936
|
+
let parsed;
|
|
24937
|
+
try {
|
|
24938
|
+
parsed = JSON.parse(raw);
|
|
24939
|
+
} catch (err) {
|
|
24940
|
+
const detail = err instanceof Error ? err.message : String(err);
|
|
24941
|
+
fail(2, `Error: ${flag} is not valid JSON: ${detail}`);
|
|
24942
|
+
}
|
|
24943
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
24944
|
+
fail(2, `Error: ${flag} must be a JSON object.`);
|
|
24945
|
+
}
|
|
24946
|
+
return parsed;
|
|
24947
|
+
}
|
|
24948
|
+
function resolvePayload(opts) {
|
|
24949
|
+
if (opts.data !== void 0 && opts.dataFile !== void 0) {
|
|
24950
|
+
fail(2, "Error: --data and --data-file are mutually exclusive.");
|
|
24951
|
+
}
|
|
24952
|
+
if (opts.data !== void 0) return parseJsonObject(opts.data, "--data");
|
|
24953
|
+
if (opts.dataFile !== void 0)
|
|
24954
|
+
return parseJsonObject(readDataFile(opts.dataFile), "--data-file");
|
|
24955
|
+
return void 0;
|
|
24956
|
+
}
|
|
24957
|
+
function parseTimeoutMs(raw) {
|
|
24958
|
+
const ms = parseDurationMs(raw);
|
|
24959
|
+
if (ms === void 0) {
|
|
24960
|
+
fail(2, `Error: invalid --timeout "${raw}" \u2014 expected a duration like 90s, 10m, 2h.`);
|
|
24961
|
+
}
|
|
24962
|
+
return ms;
|
|
24963
|
+
}
|
|
24964
|
+
function ensureNonInteractiveConsent(yes) {
|
|
24965
|
+
if (!process.stdin.isTTY && !yes) {
|
|
24966
|
+
fail(2, "Error: refusing to trigger without --yes in non-interactive mode.");
|
|
24967
|
+
}
|
|
24968
|
+
}
|
|
24969
|
+
function classifyAndFail(err, appSlug, remote) {
|
|
24970
|
+
if (!(err instanceof ApiError)) {
|
|
24971
|
+
if (err instanceof TypeError && err.cause !== void 0) {
|
|
24972
|
+
const cause = err.cause instanceof Error ? err.cause.message : String(err.cause);
|
|
24973
|
+
fail(1, `Error: could not reach ${remote ? `remote "${remote}"` : "the server"}: ${cause}`);
|
|
24974
|
+
}
|
|
24975
|
+
throw err;
|
|
24976
|
+
}
|
|
24977
|
+
if (err.status === 401 || err.status === 403) {
|
|
24978
|
+
const remoteHint = remote ? ` --remote ${remote}` : "";
|
|
24979
|
+
fail(
|
|
24980
|
+
4,
|
|
24981
|
+
`Server error (${err.status}): ${err.message}`,
|
|
24982
|
+
`Run "apotech-os login${remoteHint}" to (re)authenticate.`
|
|
24983
|
+
);
|
|
24984
|
+
}
|
|
24985
|
+
const code = extractCode(err.body);
|
|
24986
|
+
if (err.status === 409 && code === "APP_NOT_RUNNABLE") {
|
|
24987
|
+
fail(
|
|
24988
|
+
9,
|
|
24989
|
+
`Error: app "${appSlug}" is not in a runnable state. Check "apotech-os plan" / reinstall the app.`
|
|
24990
|
+
);
|
|
24991
|
+
}
|
|
24992
|
+
if (err.status === 404 && code === "JOB_NOT_FOUND" || err.status === 400 && code === "JOB_NOT_MANUALLY_TRIGGERABLE") {
|
|
24993
|
+
fail(3, `Server error (${err.status}): ${err.message}`);
|
|
24994
|
+
}
|
|
24995
|
+
reportApiError(err);
|
|
24996
|
+
}
|
|
24997
|
+
function isTriggerable(job) {
|
|
24998
|
+
return job.appTrigger?.type === "cron" || job.appTrigger?.type === "event";
|
|
24999
|
+
}
|
|
25000
|
+
function formatTriggerableList(appSlug, candidates) {
|
|
25001
|
+
const triggerable = candidates.filter(isTriggerable);
|
|
25002
|
+
if (triggerable.length === 0) {
|
|
25003
|
+
return `Triggerable functions of "${appSlug}": none.`;
|
|
25004
|
+
}
|
|
25005
|
+
const list = triggerable.map((job) => `${job.title} (${job.appTrigger?.type})`).join(", ");
|
|
25006
|
+
return `Triggerable functions of "${appSlug}": ${list}`;
|
|
25007
|
+
}
|
|
25008
|
+
function failTriggerGate(appSlug, candidates, message) {
|
|
25009
|
+
fail(3, message, formatTriggerableList(appSlug, candidates));
|
|
25010
|
+
}
|
|
25011
|
+
function notTriggerableMessage(appSlug, functionName) {
|
|
25012
|
+
return `Error: no triggerable function "${functionName}" in app "${appSlug}" \u2014 it may not exist, or it may be a uiInvoke function (those run inline in the app UI; the CLI cannot start them in v1).`;
|
|
25013
|
+
}
|
|
25014
|
+
async function resolveFunction(baseUrl, apiKey, appSlug, functionName) {
|
|
25015
|
+
const { jobs } = await fetchJobs({ baseUrl, apiKey });
|
|
25016
|
+
const candidates = jobs.filter((job2) => job2.source === "app" && job2.appSlug === appSlug);
|
|
25017
|
+
if (candidates.length === 0) {
|
|
25018
|
+
fail(3, `Error: app "${appSlug}" has no functions in the catalogue \u2014 is it installed?`);
|
|
25019
|
+
}
|
|
25020
|
+
const job = candidates.find((candidate) => candidate.title === functionName);
|
|
25021
|
+
if (!job) {
|
|
25022
|
+
failTriggerGate(appSlug, candidates, notTriggerableMessage(appSlug, functionName));
|
|
25023
|
+
}
|
|
25024
|
+
const trigger = job.appTrigger;
|
|
25025
|
+
if (!trigger) {
|
|
25026
|
+
failTriggerGate(
|
|
25027
|
+
appSlug,
|
|
25028
|
+
candidates,
|
|
25029
|
+
'Error: this server does not report function trigger kinds \u2014 upgrade the server to use "runs start".'
|
|
25030
|
+
);
|
|
25031
|
+
}
|
|
25032
|
+
if (isTriggerable(job)) {
|
|
25033
|
+
return job.id;
|
|
25034
|
+
}
|
|
25035
|
+
if (trigger.type === "dbEvent") {
|
|
25036
|
+
failTriggerGate(
|
|
25037
|
+
appSlug,
|
|
25038
|
+
candidates,
|
|
25039
|
+
`Error: function "${functionName}" runs when a "${trigger.objectRef}" record is ${trigger.operation} \u2014 trigger the data change instead.`
|
|
25040
|
+
);
|
|
25041
|
+
}
|
|
25042
|
+
if (trigger.type === "httpRoute") {
|
|
25043
|
+
failTriggerGate(
|
|
25044
|
+
appSlug,
|
|
25045
|
+
candidates,
|
|
25046
|
+
`Error: function "${functionName}" is an HTTP route \u2014 call ${trigger.method} /api/s/${appSlug}${trigger.path} directly.`
|
|
25047
|
+
);
|
|
25048
|
+
}
|
|
25049
|
+
failTriggerGate(appSlug, candidates, notTriggerableMessage(appSlug, functionName));
|
|
25050
|
+
}
|
|
25051
|
+
async function preflightCheck(baseUrl, apiKey, functionKey, ifIdle, json2) {
|
|
25052
|
+
const page = await fetchRuns({
|
|
25053
|
+
baseUrl,
|
|
25054
|
+
apiKey,
|
|
25055
|
+
slug: functionKey,
|
|
25056
|
+
status: "RUNNING,QUEUED",
|
|
25057
|
+
limit: 1
|
|
25058
|
+
});
|
|
25059
|
+
const inFlight = page.runs[0];
|
|
25060
|
+
if (!inFlight) return;
|
|
25061
|
+
if (ifIdle) {
|
|
25062
|
+
if (json2) {
|
|
25063
|
+
console.log(JSON.stringify({ error: "ALREADY_RUNNING", inFlightRunId: inFlight.id }));
|
|
25064
|
+
process.exit(8);
|
|
25065
|
+
}
|
|
25066
|
+
fail(
|
|
25067
|
+
8,
|
|
25068
|
+
`Error: a run is already in flight (${inFlight.id}). Re-run without --if-idle to queue anyway.`
|
|
25069
|
+
);
|
|
25070
|
+
}
|
|
25071
|
+
console.error(
|
|
25072
|
+
`note: a run of this function is already ${inFlight.status} (${inFlight.id}); triggering another one anyway.`
|
|
25073
|
+
);
|
|
25074
|
+
}
|
|
25075
|
+
async function confirmTrigger(appSlug, functionName, remote) {
|
|
25076
|
+
const confirmMod = await Promise.resolve().then(() => (init_esm4(), esm_exports));
|
|
25077
|
+
const confirm = confirmMod.default;
|
|
25078
|
+
return confirm({
|
|
25079
|
+
message: `Trigger ${appSlug}/${functionName} on remote "${remote ?? "default"}"?`,
|
|
25080
|
+
default: false
|
|
25081
|
+
});
|
|
25082
|
+
}
|
|
25083
|
+
async function resolveRunId(baseUrl, apiKey, eventId, budgetMs) {
|
|
25084
|
+
const lookupDeadline = Date.now() + budgetMs;
|
|
25085
|
+
for (; ; ) {
|
|
25086
|
+
const { runId } = await lookupRun({ baseUrl, apiKey, ref: eventId });
|
|
25087
|
+
if (runId !== null) return runId;
|
|
25088
|
+
if (Date.now() >= lookupDeadline) return null;
|
|
25089
|
+
await sleep2(RUN_LOOKUP_INTERVAL_MS);
|
|
25090
|
+
}
|
|
25091
|
+
}
|
|
25092
|
+
var TERMINAL_EXIT_CODE = {
|
|
25093
|
+
COMPLETED: 0,
|
|
25094
|
+
FAILED: 5,
|
|
25095
|
+
CANCELLED: 6,
|
|
25096
|
+
SKIPPED: 6
|
|
25097
|
+
};
|
|
25098
|
+
function isTerminalRunStatus(status) {
|
|
25099
|
+
return status in TERMINAL_EXIT_CODE;
|
|
25100
|
+
}
|
|
25101
|
+
function reportTransientPollError(err) {
|
|
25102
|
+
if (err instanceof ApiError && err.status === 401) throw err;
|
|
25103
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
25104
|
+
console.error(`warning: poll failed (${message}) \u2014 retrying`);
|
|
25105
|
+
}
|
|
25106
|
+
async function drainFinalLogs(baseUrl, apiKey, runId, afterSeq, json2) {
|
|
25107
|
+
try {
|
|
25108
|
+
const page = await fetchLogs({ baseUrl, apiKey, run: runId, afterSeq });
|
|
25109
|
+
for (const line of page.lines) printLogLine(line, json2);
|
|
25110
|
+
} catch {
|
|
25111
|
+
}
|
|
25112
|
+
}
|
|
25113
|
+
function readableRunError(error51) {
|
|
25114
|
+
try {
|
|
25115
|
+
const parsed = JSON.parse(error51);
|
|
25116
|
+
if (parsed && typeof parsed === "object" && "message" in parsed) {
|
|
25117
|
+
const message = parsed["message"];
|
|
25118
|
+
if (typeof message === "string" && message.length > 0) return message;
|
|
25119
|
+
}
|
|
25120
|
+
} catch {
|
|
25121
|
+
}
|
|
25122
|
+
return error51;
|
|
25123
|
+
}
|
|
25124
|
+
function exitForTerminalStatus(detail, json2) {
|
|
25125
|
+
const dur = formatRunDuration(detail);
|
|
25126
|
+
if (json2) {
|
|
25127
|
+
console.log(JSON.stringify(detail));
|
|
25128
|
+
} else if (detail.status === "COMPLETED") {
|
|
25129
|
+
console.log(`Run ${detail.id} COMPLETED in ${dur}.`);
|
|
25130
|
+
} else if (detail.status === "FAILED") {
|
|
25131
|
+
const errSuffix = detail.error ? `: ${readableRunError(detail.error)}` : ".";
|
|
25132
|
+
console.error(`Run ${detail.id} FAILED after ${dur}${errSuffix}`);
|
|
25133
|
+
} else {
|
|
25134
|
+
console.error(`Run ${detail.id} ${detail.status} after ${dur}.`);
|
|
25135
|
+
}
|
|
25136
|
+
process.exit(TERMINAL_EXIT_CODE[detail.status] ?? 6);
|
|
25137
|
+
}
|
|
25138
|
+
async function followRun(baseUrl, apiKey, runId, deadline, timeoutRaw, json2) {
|
|
25139
|
+
process.on("SIGINT", () => {
|
|
25140
|
+
fail(
|
|
25141
|
+
130,
|
|
25142
|
+
`Interrupted; run ${runId} continues. Follow up with: apotech-os runs show ${runId} --logs`
|
|
25143
|
+
);
|
|
25144
|
+
});
|
|
25145
|
+
let afterSeq;
|
|
25146
|
+
let intervalMs = FOLLOW_MIN_INTERVAL_MS;
|
|
25147
|
+
let logsDisabled = false;
|
|
25148
|
+
let lastKnownStatus;
|
|
25149
|
+
for (; ; ) {
|
|
25150
|
+
let newLogLines = false;
|
|
25151
|
+
let hadError = false;
|
|
25152
|
+
if (!logsDisabled) {
|
|
25153
|
+
try {
|
|
25154
|
+
const page = await fetchLogs({ baseUrl, apiKey, run: runId, afterSeq });
|
|
25155
|
+
for (const line of page.lines) printLogLine(line, json2);
|
|
25156
|
+
if (page.lines.length > 0) {
|
|
25157
|
+
newLogLines = true;
|
|
25158
|
+
afterSeq = page.nextSeq;
|
|
25159
|
+
}
|
|
25160
|
+
} catch (err) {
|
|
25161
|
+
if (err instanceof ApiError && err.status === 503 && extractCode(err.body) === "LOGS_NOT_CONFIGURED") {
|
|
25162
|
+
logsDisabled = true;
|
|
25163
|
+
console.error(
|
|
25164
|
+
"note: server has no log file configured (APP_LOGS_FILE); following status only"
|
|
25165
|
+
);
|
|
25166
|
+
} else {
|
|
25167
|
+
reportTransientPollError(err);
|
|
25168
|
+
hadError = true;
|
|
25169
|
+
}
|
|
25170
|
+
}
|
|
25171
|
+
}
|
|
25172
|
+
let detail;
|
|
25173
|
+
try {
|
|
25174
|
+
detail = await fetchRunDetail({ baseUrl, apiKey, runId });
|
|
25175
|
+
lastKnownStatus = detail.status;
|
|
25176
|
+
} catch (err) {
|
|
25177
|
+
reportTransientPollError(err);
|
|
25178
|
+
hadError = true;
|
|
25179
|
+
}
|
|
25180
|
+
if (detail && isTerminalRunStatus(detail.status)) {
|
|
25181
|
+
if (!logsDisabled) await drainFinalLogs(baseUrl, apiKey, runId, afterSeq, json2);
|
|
25182
|
+
exitForTerminalStatus(detail, json2);
|
|
25183
|
+
}
|
|
25184
|
+
if (Date.now() >= deadline) {
|
|
25185
|
+
fail(
|
|
25186
|
+
7,
|
|
25187
|
+
`Timed out after ${timeoutRaw}; run ${runId} is still ${lastKnownStatus ?? "unknown"} on the server. Follow up with: apotech-os runs show ${runId} --logs`
|
|
25188
|
+
);
|
|
25189
|
+
}
|
|
25190
|
+
intervalMs = nextFollowInterval({ current: intervalMs, hadActivity: newLogLines, hadError });
|
|
25191
|
+
await sleep2(intervalMs);
|
|
25192
|
+
}
|
|
25193
|
+
}
|
|
25194
|
+
function buildRunsStartCommand() {
|
|
25195
|
+
return new Command("start").description("Trigger an app function; with --follow, block until it reaches a terminal status").argument("<target>", "<appSlug>/<functionName>").option("--data <json>", "Inline JSON object \u2192 request body.data").option("--data-file <path>", "Read JSON from file; '-' reads stdin").option("--follow", "Stream logs and block until the run reaches a terminal status").option("--timeout <duration>", "Max wall time in follow mode (e.g. 90s, 10m, 2h)", "30m").option("--if-idle", "Refuse if a run of this function is already RUNNING or QUEUED").option("-y, --yes", "Skip the confirmation prompt").option("--json", "Machine-readable output").option("--remote <name>", "Named remote server to target").action(async (target, opts) => {
|
|
25196
|
+
ensureNonInteractiveConsent(opts.yes);
|
|
25197
|
+
const { appSlug, functionName } = parseTarget(target);
|
|
25198
|
+
const payload = resolvePayload(opts);
|
|
25199
|
+
const timeoutMs = parseTimeoutMs(opts.timeout);
|
|
25200
|
+
const baseUrl = opts.remote ? getRemoteUrl(opts.remote) : DEFAULT_REMOTE_URL;
|
|
25201
|
+
const apiKey = resolveApiKey(opts.remote);
|
|
25202
|
+
const json2 = opts.json ?? false;
|
|
25203
|
+
try {
|
|
25204
|
+
const functionKey = await resolveFunction(baseUrl, apiKey, appSlug, functionName);
|
|
25205
|
+
await preflightCheck(baseUrl, apiKey, functionKey, opts.ifIdle ?? false, json2);
|
|
25206
|
+
if (!opts.yes) {
|
|
25207
|
+
const confirmed = await confirmTrigger(appSlug, functionName, opts.remote);
|
|
25208
|
+
if (!confirmed) {
|
|
25209
|
+
fail(1, "Aborted.");
|
|
25210
|
+
}
|
|
25211
|
+
}
|
|
25212
|
+
const { runId: triggeredRunId, eventId } = await triggerJob({
|
|
25213
|
+
baseUrl,
|
|
25214
|
+
apiKey,
|
|
25215
|
+
key: functionKey,
|
|
25216
|
+
data: payload
|
|
25217
|
+
});
|
|
25218
|
+
const deadline = Date.now() + timeoutMs;
|
|
25219
|
+
let runId = triggeredRunId;
|
|
25220
|
+
if (runId === null) {
|
|
25221
|
+
if (eventId === null) {
|
|
25222
|
+
fail(1, "Error: the server accepted the trigger but returned no event id.");
|
|
25223
|
+
}
|
|
25224
|
+
const lookupBudgetMs = opts.follow ? Math.min(RUN_LOOKUP_BUDGET_MS, timeoutMs) : RUN_LOOKUP_BUDGET_MS;
|
|
25225
|
+
runId = await resolveRunId(baseUrl, apiKey, eventId, lookupBudgetMs);
|
|
25226
|
+
}
|
|
25227
|
+
if (json2 && !opts.follow) {
|
|
25228
|
+
console.log(JSON.stringify({ runId, eventId, status: "accepted" }));
|
|
25229
|
+
return;
|
|
25230
|
+
}
|
|
25231
|
+
if (!json2) {
|
|
25232
|
+
console.log(`Event ${eventId} accepted.`);
|
|
25233
|
+
if (runId) console.log(`Run ${runId} started.`);
|
|
25234
|
+
}
|
|
25235
|
+
if (!opts.follow) {
|
|
25236
|
+
if (!json2 && !runId) {
|
|
25237
|
+
console.log(`Run not linked yet; follow up with: apotech-os runs show ${eventId}`);
|
|
25238
|
+
}
|
|
25239
|
+
return;
|
|
25240
|
+
}
|
|
25241
|
+
if (!runId) {
|
|
25242
|
+
fail(
|
|
25243
|
+
7,
|
|
25244
|
+
`Timed out after ${opts.timeout}; the run has not been linked yet. Follow up with: apotech-os runs show ${eventId}`
|
|
25245
|
+
);
|
|
25246
|
+
}
|
|
25247
|
+
await followRun(baseUrl, apiKey, runId, deadline, opts.timeout, json2);
|
|
25248
|
+
} catch (err) {
|
|
25249
|
+
classifyAndFail(err, appSlug, opts.remote);
|
|
25250
|
+
}
|
|
25251
|
+
});
|
|
25252
|
+
}
|
|
25253
|
+
|
|
24777
25254
|
// src/commands/runs.ts
|
|
24778
25255
|
var STATUS_ALIASES = Object.fromEntries(
|
|
24779
25256
|
FUNCTION_RUN_STATUSES.map((status) => [status.toLowerCase(), status])
|
|
@@ -24781,19 +25258,6 @@ var STATUS_ALIASES = Object.fromEntries(
|
|
|
24781
25258
|
function mapStatusCsv(csv) {
|
|
24782
25259
|
return csv.split(",").map((raw) => raw.trim()).filter((s) => s.length > 0).map((s) => STATUS_ALIASES[s.toLowerCase()] ?? s.toUpperCase()).join(",");
|
|
24783
25260
|
}
|
|
24784
|
-
function formatDurationMs(ms) {
|
|
24785
|
-
if (ms < 1e3) return `${ms}ms`;
|
|
24786
|
-
const totalSeconds = Math.floor(ms / 1e3);
|
|
24787
|
-
const minutes = Math.floor(totalSeconds / 60);
|
|
24788
|
-
const seconds = totalSeconds % 60;
|
|
24789
|
-
return minutes === 0 ? `${seconds}s` : `${minutes}m${seconds}s`;
|
|
24790
|
-
}
|
|
24791
|
-
function formatDuration(run) {
|
|
24792
|
-
if (!run.startedAt) return "-";
|
|
24793
|
-
const end = run.endedAt ?? (run.status === "RUNNING" ? (/* @__PURE__ */ new Date()).toISOString() : void 0);
|
|
24794
|
-
if (!end) return "-";
|
|
24795
|
-
return formatDurationMs(new Date(end).getTime() - new Date(run.startedAt).getTime());
|
|
24796
|
-
}
|
|
24797
25261
|
function appFunctionLabel(run) {
|
|
24798
25262
|
if (run.source === "app") return `${run.appSlug ?? "?"}/${run.functionName ?? run.functionId}`;
|
|
24799
25263
|
return run.functionSlug ?? run.functionId;
|
|
@@ -24820,7 +25284,7 @@ function renderRunsTable(runs) {
|
|
|
24820
25284
|
appFunctionLabel(run),
|
|
24821
25285
|
triggerLabel(run),
|
|
24822
25286
|
formatLocalTimestamp(run.startedAt ?? run.queuedAt),
|
|
24823
|
-
|
|
25287
|
+
formatRunDuration(run)
|
|
24824
25288
|
]);
|
|
24825
25289
|
return renderTable(headers, rows);
|
|
24826
25290
|
}
|
|
@@ -24833,7 +25297,7 @@ function renderRunDetail(detail) {
|
|
|
24833
25297
|
`Queued: ${formatLocalTimestamp(detail.queuedAt)}`,
|
|
24834
25298
|
`Started: ${detail.startedAt ? formatLocalTimestamp(detail.startedAt) : "-"}`,
|
|
24835
25299
|
`Ended: ${detail.endedAt ? formatLocalTimestamp(detail.endedAt) : "-"}`,
|
|
24836
|
-
`Duration: ${
|
|
25300
|
+
`Duration: ${formatRunDuration(detail)}`
|
|
24837
25301
|
];
|
|
24838
25302
|
if (detail.error) {
|
|
24839
25303
|
lines.push("", `Error: ${detail.error}`);
|
|
@@ -24897,16 +25361,17 @@ function buildShowCommand() {
|
|
|
24897
25361
|
});
|
|
24898
25362
|
}
|
|
24899
25363
|
function buildRunsCommand() {
|
|
24900
|
-
const runs = new Command("runs").description("Inspect job/function runs");
|
|
25364
|
+
const runs = new Command("runs").description("Inspect and trigger job/function runs");
|
|
24901
25365
|
runs.addCommand(buildListCommand());
|
|
24902
25366
|
runs.addCommand(buildShowCommand());
|
|
25367
|
+
runs.addCommand(buildRunsStartCommand());
|
|
24903
25368
|
return runs;
|
|
24904
25369
|
}
|
|
24905
25370
|
|
|
24906
25371
|
// src/index.ts
|
|
24907
25372
|
function readVersion() {
|
|
24908
25373
|
try {
|
|
24909
|
-
const pkg = (0,
|
|
25374
|
+
const pkg = (0, import_fs9.readFileSync)((0, import_path6.join)(__dirname, "..", "package.json"), "utf8");
|
|
24910
25375
|
return JSON.parse(pkg).version ?? "0.0.0";
|
|
24911
25376
|
} catch {
|
|
24912
25377
|
return "0.0.0";
|