@gjsify/cli 0.64.44 → 0.64.45

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.
@@ -1,8 +1,8 @@
1
1
  // `gjsify webext` — yargs subcommand-group dispatcher (ADR 0077).
2
2
  //
3
- // Wires {build, zip, dev, listing}; each is a self-contained `Command<>` in `subcommands.ts`,
3
+ // Wires {build, zip, dev, listing, submit}; each is a self-contained `Command<>` in `subcommands.ts`,
4
4
  // the same composition `flatpak/index.ts` uses.
5
- import { webextBuildCommand, webextDevCommand, webextListingCommand, webextZipCommand } from './subcommands.js';
5
+ import { webextBuildCommand, webextDevCommand, webextListingCommand, webextSubmitCommand, webextZipCommand, } from './subcommands.js';
6
6
  export const webextCommand = {
7
7
  command: 'webext <subcommand>',
8
8
  description: 'Browser extensions: build, zip and develop one WebExtension for Chrome, Edge, Firefox, Opera and Safari.',
@@ -11,6 +11,7 @@ export const webextCommand = {
11
11
  .command(webextZipCommand.command, webextZipCommand.description, webextZipCommand.builder, webextZipCommand.handler)
12
12
  .command(webextDevCommand.command, webextDevCommand.description, webextDevCommand.builder, webextDevCommand.handler)
13
13
  .command(webextListingCommand.command, webextListingCommand.description, webextListingCommand.builder, webextListingCommand.handler)
14
+ .command(webextSubmitCommand.command, webextSubmitCommand.description, webextSubmitCommand.builder, webextSubmitCommand.handler)
14
15
  .demandCommand(1)
15
16
  .strict(),
16
17
  };
@@ -27,4 +27,13 @@ interface ListingArgs {
27
27
  globals?: string;
28
28
  }
29
29
  export declare const webextListingCommand: Command<unknown, ListingArgs>;
30
+ interface SubmitArgs {
31
+ store: string;
32
+ zip?: string;
33
+ dryRun: boolean;
34
+ submit: boolean;
35
+ timeout?: number;
36
+ listingDir?: string;
37
+ }
38
+ export declare const webextSubmitCommand: Command<unknown, SubmitArgs>;
30
39
  export {};
@@ -6,6 +6,7 @@
6
6
  import { existsSync, mkdirSync, readdirSync, readFileSync } from 'node:fs';
7
7
  import { dirname, join, resolve, sep } from 'node:path';
8
8
  import { dispatchSite } from '../../utils/site-dispatch.js';
9
+ import { runSubmit } from '../../utils/webext/submit.js';
9
10
  import { buildWebext } from '../../utils/webext/build.js';
10
11
  import { resolveWebextConfig, selectTargets } from '../../utils/webext/config.js';
11
12
  import { defaultDevProfile, resolveWebExt, WEB_EXT_MISSING, webExtRunArgs, } from '../../utils/webext/launch.js';
@@ -271,3 +272,56 @@ export const webextListingCommand = {
271
272
  });
272
273
  },
273
274
  };
275
+ export const webextSubmitCommand = {
276
+ command: 'submit',
277
+ description: 'Upload the built zip to the Chrome Web Store or Edge Add-ons as a draft; --submit also asks for review (tags only).',
278
+ builder: (yargs) => yargs
279
+ .option('store', {
280
+ description: 'Which store (amo is not implemented: Firefox is distributed by the project itself).',
281
+ type: 'string',
282
+ choices: ['chrome', 'edge', 'amo'],
283
+ demandOption: true,
284
+ })
285
+ .option('zip', {
286
+ description: "The zip to upload (default: what `webext zip` writes for the store's target).",
287
+ type: 'string',
288
+ })
289
+ .option('dry-run', {
290
+ description: 'Check the credentials with one read call; upload nothing.',
291
+ type: 'boolean',
292
+ default: false,
293
+ })
294
+ .option('submit', {
295
+ description: 'Ask for review after the upload. Refused unless $GITHUB_REF is a tag.',
296
+ type: 'boolean',
297
+ default: false,
298
+ })
299
+ .option('timeout', {
300
+ description: 'Seconds to wait for the store to resolve an upload or submission (default: 600).',
301
+ type: 'number',
302
+ })
303
+ .option('listing-dir', {
304
+ description: 'Where `webext listing` wrote store.json (default: dist/listing).',
305
+ type: 'string',
306
+ })
307
+ .epilog('Credentials come from the environment only (see ADR 0077 § Amendment 1). Exit codes: 0 done or nothing to do, ' +
308
+ '1 rejected or failed, 3 accepted but unresolved (run again), 4 unverifiable. ' +
309
+ 'A submission stuck in review is cancelled in the Chrome dashboard (:cancelSubmission); this command never does.'),
310
+ handler: async (args) => {
311
+ const cwd = process.cwd();
312
+ const code = await runSubmit({
313
+ store: args.store,
314
+ zip: args.zip ? resolve(cwd, args.zip) : undefined,
315
+ dryRun: args.dryRun,
316
+ submit: args.submit,
317
+ timeoutSeconds: args.timeout,
318
+ listingDir: args.listingDir,
319
+ project: loadConfig(cwd),
320
+ env: process.env,
321
+ out: (line) => console.log(line),
322
+ err: (line) => console.error(line),
323
+ });
324
+ if (code !== 0)
325
+ process.exitCode = code;
326
+ },
327
+ };
@@ -0,0 +1,167 @@
1
+ import { type StoreBackend, type StoreId, type StorePublishInput, type StoreUploadInput } from './index.js';
2
+ /**
3
+ * What a drive ENDED as. Nine, because the store's three asynchronous answers
4
+ * ("busy", "accepted", "I cannot say") are facts a caller acts on differently
5
+ * and a boolean would throw all three away.
6
+ */
7
+ export type SubmitVerdict =
8
+ /** The draft holds this version and no publish was asked for — `submit` without `--submit`. */
9
+ 'uploaded'
10
+ /** The store confirms a submission for THIS version: Chrome `PENDING_REVIEW`, or Edge's publish operation `Succeeded`. */
11
+ | 'submitted'
12
+ /** The store reports this version as live. Chrome only; Edge has no endpoint that says so. */
13
+ | 'published'
14
+ /** The store was already on this version, so this run had nothing to do (`StoreVersionAlreadyThereError`). */
15
+ | 'already-there'
16
+ /** A submission is in review and this run changed nothing. Not a failure — see {@link SUBMIT_EXIT_CODES}. */
17
+ | 'in-review'
18
+ /** The store refused it: a 4xx that is not 408/429, or an operation it reported as failed. A re-run gets the same answer. */
19
+ | 'rejected'
20
+ /** A repeatable failure that kept repeating — a 5xx, a 429, a transport error — until the retries or the deadline ran out. */
21
+ | 'failed'
22
+ /** The store accepted something and never resolved it inside the deadline. The caller may call again later. */
23
+ | 'unresolved'
24
+ /** The store answered with a handle this client cannot read, so the outcome is not knowable from here. A gap in the backend, named as one. */
25
+ | 'unverifiable';
26
+ /**
27
+ * Exit code per verdict. The three decisions in it:
28
+ *
29
+ * **`in-review` exits 0.** The alternative — its own non-zero code — was
30
+ * considered and rejected. The state means the PREVIOUS submit worked and the
31
+ * store is busy with it; nothing in this run failed, nothing was corrupted, and
32
+ * the way out (Chrome's `:cancelSubmission`; Edge documents none) is the
33
+ * person's decision and never this command's. The step that calls `submit` sits
34
+ * behind a GitHub Environment with a required reviewer, so a red there costs a
35
+ * human a re-run of a workflow that did its job — and a check that cries wolf
36
+ * is one somebody switches off, the lesson `publish-readback.ts` paid for. What
37
+ * keeps that honest is that exit 0 here never CLAIMS a submission: the verdict
38
+ * is its own value, `detail` names which version is blocking, and a caller that
39
+ * wants a red can read `verdict` and decide. The plan behind this slice and
40
+ * ADR 0077 § Amendment 1 both say the same ("three outcomes, not one non-zero
41
+ * exit"), so this is also the already-recorded decision.
42
+ *
43
+ * **`failed` and `rejected` share exit 1** — the operator's next move is the
44
+ * same, look at `detail` — while `unresolved` gets its own code, because its
45
+ * next move is the opposite one: call again later, unchanged, and expect
46
+ * progress. Those two must never be one number.
47
+ *
48
+ * **`2` is not in this table.** `cli-app.ts`'s `.fail()` handler exits 2 for a
49
+ * usage error, so a store outcome spelled 2 would be indistinguishable from a
50
+ * mistyped flag.
51
+ */
52
+ export declare const SUBMIT_EXIT_CODES: Readonly<Record<SubmitVerdict, number>>;
53
+ /**
54
+ * Default deadline for the whole drive: 600 s.
55
+ *
56
+ * What this waits for is INGESTION and the resolution of an operation, never a
57
+ * review verdict — a review takes days at both stores and no CI job may sit on
58
+ * one. 600 s is `publish-readback.ts`'s budget, chosen there against measured
59
+ * registry lag; nothing comparable has been measured against a store, so the
60
+ * number is borrowed rather than derived, and `--timeout` is what a real
61
+ * observation changes. A non-positive value waits not at all: every async step
62
+ * is read exactly once and an unfinished one ends the drive at `unresolved`.
63
+ */
64
+ export declare const DEFAULT_SUBMIT_TIMEOUT_MS = 600000;
65
+ /** How often a repeatable failure of one call is repeated before the drive gives up. */
66
+ export declare const MAX_SAFE_RETRIES = 3;
67
+ /** Delay before the poll after `round` (0-based). */
68
+ export declare function pollBackoffFor(round: number): number;
69
+ /** Delay before retry `round` (0-based) of a repeatable failure; throttling gets its own, longer table. */
70
+ export declare function retryBackoffFor(round: number, throttled: boolean): number;
71
+ /** Which call failed, for {@link retryDecision}. A verb, not an endpoint: what matters is whether repeating it WRITES. */
72
+ export type StoreVerb = 'read' | 'upload' | 'publish';
73
+ /**
74
+ * Is this failure's CLASS one that a repeat of the same request could survive?
75
+ *
76
+ * Only {@link StoreApiError} can be: the two idempotent skips are answers, not
77
+ * failures, and anything else reaching here is a defect in this client, which a
78
+ * repeat cannot fix.
79
+ */
80
+ export declare function isRepeatableFailure(error: unknown): boolean;
81
+ /** True for the failure class whose remedy is specifically "wait longer than usual". */
82
+ export declare function isThrottled(error: unknown): boolean;
83
+ export type RetryDecision =
84
+ /** Send the same request again after a backoff. */
85
+ 'retry'
86
+ /** Do not resend. Ask the store what happened first — only `publish` reaches this. */
87
+ | 'verify-first'
88
+ /** The store has answered the question; a repeat gets the same answer. */
89
+ | 'fatal';
90
+ /**
91
+ * What to do about `error` from `verb`.
92
+ *
93
+ * The asymmetry between the two POSTs is the whole point: an `upload` writes the
94
+ * draft, which is a SLOT — sending the same zip twice leaves the same draft, so
95
+ * a repeat costs bytes. A `publish` CREATES a submission, so a repeat after a
96
+ * transport failure risks a second one against a store that already took the
97
+ * first; `status()` is the only thing allowed to decide that.
98
+ */
99
+ export declare function retryDecision(error: unknown, verb: StoreVerb): RetryDecision;
100
+ /** Where a drive was when a phase ended. */
101
+ export type SubmitPhaseName = 'upload' | 'await-upload' | 'publish' | 'await-publish' | 'confirm';
102
+ /** One phase of a drive, appended when it ends. The subcommand prints these in order. */
103
+ export interface SubmitPhase {
104
+ readonly phase: SubmitPhaseName;
105
+ /** Requests this phase sent, retries and polls included. */
106
+ readonly requests: number;
107
+ /** Milliseconds since the drive started, on the injected clock. */
108
+ readonly elapsedMs: number;
109
+ /** The store's own account of what happened, redacted. */
110
+ readonly detail: string;
111
+ }
112
+ /**
113
+ * What a drive established. A pure value: no printing, no exiting, no `process`
114
+ * — the subcommand (S6) renders it and exits {@link SubmitResult.exitCode}.
115
+ */
116
+ export interface SubmitResult {
117
+ readonly store: StoreId;
118
+ readonly version: string;
119
+ readonly verdict: SubmitVerdict;
120
+ /** `SUBMIT_EXIT_CODES[verdict]`, carried so a caller cannot re-derive it differently. */
121
+ readonly exitCode: number;
122
+ /** One line naming the evidence the verdict rests on, redacted. */
123
+ readonly detail: string;
124
+ readonly phases: readonly SubmitPhase[];
125
+ readonly elapsedMs: number;
126
+ /** Requests the whole drive sent. */
127
+ readonly requests: number;
128
+ /** How many of them were repeats of a failed one. */
129
+ readonly retries: number;
130
+ /** True when calling again later, unchanged, can make progress on its own. */
131
+ readonly retryable: boolean;
132
+ }
133
+ export interface SubmitDriveInput {
134
+ readonly backend: StoreBackend;
135
+ readonly upload: StoreUploadInput;
136
+ /**
137
+ * Absent = upload the draft and stop, which is `submit`'s default; `--submit`
138
+ * is what fills this in. A draft that is never submitted is a complete,
139
+ * successful outcome and not half of one.
140
+ */
141
+ readonly publish?: StorePublishInput;
142
+ }
143
+ export interface SubmitDriveOptions {
144
+ /** `--timeout`'s value in ms. Default {@link DEFAULT_SUBMIT_TIMEOUT_MS}; `<= 0` waits not at all. */
145
+ readonly timeoutMs?: number;
146
+ /** Injected in tests — nothing here calls `setTimeout` itself. */
147
+ readonly sleep?: (ms: number) => Promise<void>;
148
+ readonly now?: () => number;
149
+ /** Called per step under `GJSIFY_WEBEXT_DEBUG`. Already redacted. */
150
+ readonly log?: (msg: string) => void;
151
+ /**
152
+ * Values that may never appear in a phase detail, the result or a log line —
153
+ * `secretValuesOf(store, credentials)`. The backends redact their own
154
+ * messages; this is the second net, because a detail here is assembled from
155
+ * vendor text and vendor text is where an echoed credential turns up.
156
+ */
157
+ readonly secrets?: readonly string[];
158
+ }
159
+ /**
160
+ * Drive one version into one store and say what the store ended up at.
161
+ *
162
+ * upload → wait for the ingest → publish → wait for the submission, each step
163
+ * bounded by ONE shared deadline: two budgets would make the wall clock twice
164
+ * what `--timeout` promises, the same mistake `probeTimeoutFor` was written to
165
+ * stop in the read-back.
166
+ */
167
+ export declare function driveSubmission(input: SubmitDriveInput, options?: SubmitDriveOptions): Promise<SubmitResult>;