@gjsify/cli 0.64.39 → 0.64.41-next.335
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/cli.gjs.mjs +311 -260
- package/lib/cli-app.js +2 -1
- package/lib/commands/flatpark.d.ts +11 -0
- package/lib/commands/flatpark.js +147 -0
- package/lib/commands/index.d.ts +1 -0
- package/lib/commands/index.js +1 -0
- package/lib/commands/ship.js +17 -0
- package/lib/commands/webext/subcommands.d.ts +1 -0
- package/lib/commands/webext/subcommands.js +5 -1
- package/lib/utils/ship/app-runtime.d.ts +29 -0
- package/lib/utils/ship/app-runtime.js +99 -2
- package/lib/utils/ship/flatpark.d.ts +84 -0
- package/lib/utils/ship/flatpark.js +298 -0
- package/lib/utils/ship/formats.js +80 -0
- package/lib/utils/ship/tarball.d.ts +25 -0
- package/lib/utils/ship/tarball.js +69 -0
- package/lib/utils/ship/types.d.ts +1 -1
- package/lib/utils/webext/stores/index.d.ts +227 -0
- package/lib/utils/webext/stores/index.js +252 -0
- package/package.json +22 -21
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/** The stores `webext submit` knows by name. A store it does not know is refused by name, not by a missing case. */
|
|
2
|
+
export type StoreId = 'chrome' | 'edge' | 'amo';
|
|
3
|
+
export declare const STORE_IDS: readonly StoreId[];
|
|
4
|
+
/** One environment variable a store needs, and whether its value may ever be printed. */
|
|
5
|
+
export interface StoreCredentialField {
|
|
6
|
+
/** The variable's name, as a CI secret and as a shell export. */
|
|
7
|
+
readonly env: string;
|
|
8
|
+
/**
|
|
9
|
+
* False for an identifier that appears in a URL anyway (a publisher, item or
|
|
10
|
+
* product id), true for anything that AUTHORISES. Only `secret: false` values
|
|
11
|
+
* are allowed into a message; the rest are replaced by {@link redactSecrets}.
|
|
12
|
+
*/
|
|
13
|
+
readonly secret: boolean;
|
|
14
|
+
/** What it is, in the words the vendor's dashboard uses — this is what a missing-credential error prints. */
|
|
15
|
+
readonly what: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Credentials per store, read from the environment and NEVER from
|
|
19
|
+
* `package.json#gjsify.webext`: that file is committed, and a token in a
|
|
20
|
+
* committed file is a token in the published package too.
|
|
21
|
+
*
|
|
22
|
+
* Deliberately NOT ADR 0126's `CREDENTIALS` table, which is keyed by `HostOs`
|
|
23
|
+
* because a signing identity is per host. A store credential is the same on every
|
|
24
|
+
* host and differs per STORE, it has no `install` counterpart (there is no
|
|
25
|
+
* keychain to build), and it can only touch one listing. The full argument, and
|
|
26
|
+
* the fact that `ship credentials` is accepted-but-unbuilt, is ADR 0077
|
|
27
|
+
* § Amendment 1.
|
|
28
|
+
*/
|
|
29
|
+
export declare const STORE_CREDENTIALS: Readonly<Record<StoreId, readonly StoreCredentialField[]>>;
|
|
30
|
+
export interface StoreDescriptor {
|
|
31
|
+
readonly id: StoreId;
|
|
32
|
+
/** As a message names it: "Chrome Web Store", not "chrome". */
|
|
33
|
+
readonly label: string;
|
|
34
|
+
/**
|
|
35
|
+
* False while no backend implements this store. `submit` reads this to refuse
|
|
36
|
+
* early with {@link StoreUnsupportedError} rather than after reading
|
|
37
|
+
* credentials it would not use.
|
|
38
|
+
*/
|
|
39
|
+
readonly implemented: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Whether the API can CREATE the listing. Both implemented stores answer no —
|
|
42
|
+
* a first version goes through the vendor's dashboard by hand — so `submit`
|
|
43
|
+
* says that in words instead of surfacing a 404 from an upload.
|
|
44
|
+
*/
|
|
45
|
+
readonly createsListings: false;
|
|
46
|
+
}
|
|
47
|
+
export declare const STORES: Readonly<Record<StoreId, StoreDescriptor>>;
|
|
48
|
+
/** `id` as a {@link StoreId}, or null — the caller owns the message, same contract as `parseWebextTarget`'s callers. */
|
|
49
|
+
export declare function asStoreId(id: string): StoreId | null;
|
|
50
|
+
/** A store's resolved credentials: `env` name → value, every field of its row present. */
|
|
51
|
+
export type StoreCredentials = Readonly<Record<string, string>>;
|
|
52
|
+
/** Just enough of an environment to resolve credentials from — `process.env` satisfies it on both runtimes. */
|
|
53
|
+
export type EnvLike = Readonly<Record<string, string | undefined>>;
|
|
54
|
+
/**
|
|
55
|
+
* Every variable a store's row names, or a refusal listing ALL the missing ones.
|
|
56
|
+
*
|
|
57
|
+
* One run per fix, not one per variable — the same reason `resolveWebextConfig`
|
|
58
|
+
* collects its problems before throwing. An empty string counts as missing: a CI
|
|
59
|
+
* secret that was never set expands to one, and treating that as a credential
|
|
60
|
+
* sends an `Authorization: ApiKey ` header whose 401 says nothing about the cause.
|
|
61
|
+
*/
|
|
62
|
+
export declare function resolveStoreCredentials(store: StoreId, env: EnvLike): StoreCredentials;
|
|
63
|
+
/** The values of a store's `secret: true` fields, for {@link redactSecrets}. */
|
|
64
|
+
export declare function secretValuesOf(store: StoreId, credentials: StoreCredentials): readonly string[];
|
|
65
|
+
export declare const REDACTED = "<redacted>";
|
|
66
|
+
/** Just enough of `Headers`/a plain object to redact — a backend may hold either. */
|
|
67
|
+
export type HeadersLike = Readonly<Record<string, string>>;
|
|
68
|
+
/**
|
|
69
|
+
* A copy of `headers` safe to print: every authorising value replaced, every
|
|
70
|
+
* other value verbatim, names lower-cased so two spellings of one header cannot
|
|
71
|
+
* disagree about whether they are secret.
|
|
72
|
+
*
|
|
73
|
+
* A name containing `token`, `secret` or `key` is redacted too, so a header added
|
|
74
|
+
* by a later backend is secret by DEFAULT and has to be named explicitly to be
|
|
75
|
+
* printed. The failure mode this prevents is the quiet one: a new header leaks
|
|
76
|
+
* because nobody edited a list.
|
|
77
|
+
*/
|
|
78
|
+
export declare function redactHeaders(headers: HeadersLike): Record<string, string>;
|
|
79
|
+
/**
|
|
80
|
+
* `text` with every value in `secrets` replaced, for a log line, a debug dump or
|
|
81
|
+
* the message of a thrown error.
|
|
82
|
+
*
|
|
83
|
+
* Longest first, because a short secret that is a substring of a long one would
|
|
84
|
+
* otherwise leave the long one's remainder in the text. Empty and one-character
|
|
85
|
+
* values are skipped: redacting those rewrites the whole message into noise and
|
|
86
|
+
* says nothing, and a credential that short is not a credential.
|
|
87
|
+
*/
|
|
88
|
+
export declare function redactSecrets(text: string, secrets: readonly string[]): string;
|
|
89
|
+
/** The store's row named variables this environment does not set. Lists all of them, with what each is. */
|
|
90
|
+
export declare class StoreCredentialsMissingError extends Error {
|
|
91
|
+
readonly store: StoreId;
|
|
92
|
+
readonly missing: readonly StoreCredentialField[];
|
|
93
|
+
constructor(store: StoreId, missing: readonly StoreCredentialField[]);
|
|
94
|
+
}
|
|
95
|
+
/** A store with a row and no backend — the AMO slot, or a store declared before its file exists. */
|
|
96
|
+
export declare class StoreUnsupportedError extends Error {
|
|
97
|
+
readonly store: StoreId;
|
|
98
|
+
constructor(store: StoreId, detail: string);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The store already holds this exact version, so there is nothing to do.
|
|
102
|
+
*
|
|
103
|
+
* NOT a failure. A `submit` retried after a dropped connection must be able to
|
|
104
|
+
* reach this and exit 0, because the alternative is a second upload against a
|
|
105
|
+
* draft whose state the client never read.
|
|
106
|
+
*/
|
|
107
|
+
export declare class StoreVersionAlreadyThereError extends Error {
|
|
108
|
+
readonly store: StoreId;
|
|
109
|
+
readonly version: string;
|
|
110
|
+
constructor(store: StoreId, version: string);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* A submission is in review, so this version cannot be uploaded or published now.
|
|
114
|
+
*
|
|
115
|
+
* Also not a failure of this run: the previous submit worked and the store is
|
|
116
|
+
* busy with it. Cancelling it is the user's decision (Chrome has
|
|
117
|
+
* `:cancelSubmission`; Edge does not document one), never this command's.
|
|
118
|
+
*/
|
|
119
|
+
export declare class StoreInReviewError extends Error {
|
|
120
|
+
readonly store: StoreId;
|
|
121
|
+
constructor(store: StoreId, detail: string);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* A real failure: a 4xx that is not one of the two above, a 5xx, a timeout, an
|
|
125
|
+
* answer that did not parse.
|
|
126
|
+
*
|
|
127
|
+
* `detail` is built by the backend and MUST have passed through
|
|
128
|
+
* {@link redactSecrets} — it is the one field that carries vendor text, and
|
|
129
|
+
* vendor text is where an echoed credential would appear.
|
|
130
|
+
*/
|
|
131
|
+
export declare class StoreApiError extends Error {
|
|
132
|
+
readonly store: StoreId;
|
|
133
|
+
readonly httpStatus: number | undefined;
|
|
134
|
+
constructor(store: StoreId, httpStatus: number | undefined, detail: string);
|
|
135
|
+
}
|
|
136
|
+
/** True for the two outcomes a retried `submit` may report and exit 0 on. */
|
|
137
|
+
export declare function isIdempotentSkip(error: unknown): error is StoreVersionAlreadyThereError | StoreInReviewError;
|
|
138
|
+
/** What a submission is doing, classified. `unknown` is a state, not an error — the store did not say. */
|
|
139
|
+
export type StoreSubmissionState =
|
|
140
|
+
/** Uploaded and not submitted: a draft the store holds. */
|
|
141
|
+
'draft'
|
|
142
|
+
/** The store is reviewing it. */
|
|
143
|
+
| 'in-review'
|
|
144
|
+
/** Live, or rolling out. */
|
|
145
|
+
| 'published'
|
|
146
|
+
/** The store refused it; `detail` carries the reason it gave. */
|
|
147
|
+
| 'rejected'
|
|
148
|
+
/**
|
|
149
|
+
* Nothing was established. Chrome's `lastAsyncUploadState` is only set for
|
|
150
|
+
* uploads from the past 24 h, so a poll that starts late legitimately has no
|
|
151
|
+
* state to read — reporting that as `draft` would invent a fact.
|
|
152
|
+
*/
|
|
153
|
+
| 'unknown';
|
|
154
|
+
export interface StoreStatusResult {
|
|
155
|
+
readonly state: StoreSubmissionState;
|
|
156
|
+
/** The version the store reports, when it reports one. */
|
|
157
|
+
readonly version?: string;
|
|
158
|
+
/** One line naming the evidence this state rests on — it goes in the report verbatim. */
|
|
159
|
+
readonly detail: string;
|
|
160
|
+
}
|
|
161
|
+
export interface StoreUploadResult {
|
|
162
|
+
/**
|
|
163
|
+
* The store's handle for this upload, when it has one: Chrome's item resource
|
|
164
|
+
* name, Edge's operation id from the `Location` header. A backend that polls
|
|
165
|
+
* its own operation passes this to {@link StoreBackend.status}.
|
|
166
|
+
*/
|
|
167
|
+
readonly operationId?: string;
|
|
168
|
+
/** True once the store has fully ingested the package, false while an async upload is still running. */
|
|
169
|
+
readonly ingested: boolean;
|
|
170
|
+
readonly detail: string;
|
|
171
|
+
}
|
|
172
|
+
export interface StorePublishResult {
|
|
173
|
+
readonly state: StoreSubmissionState;
|
|
174
|
+
readonly detail: string;
|
|
175
|
+
}
|
|
176
|
+
export interface StoreUploadInput {
|
|
177
|
+
/** Absolute path of the zip `webext zip` wrote. The backend reads it; it never builds one. */
|
|
178
|
+
readonly zipPath: string;
|
|
179
|
+
/** The version in the zip's manifest, for the "already there" check and for messages. */
|
|
180
|
+
readonly version: string;
|
|
181
|
+
}
|
|
182
|
+
export interface StorePublishInput {
|
|
183
|
+
readonly version: string;
|
|
184
|
+
/** What Chrome calls a staged rollout; a backend whose store has none refuses a value below 100. */
|
|
185
|
+
readonly deployPercentage?: number;
|
|
186
|
+
/** Edge's submission `notes`. Stores that take no note ignore it. */
|
|
187
|
+
readonly notes?: string;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* What every store backend answers to. Three verbs, because that is what both
|
|
191
|
+
* vendor APIs expose: push the package, ask for review, read what happened.
|
|
192
|
+
*
|
|
193
|
+
* Each verb either returns its result or throws one of the error classes above —
|
|
194
|
+
* a backend never returns a half-success, and never reports "published" from
|
|
195
|
+
* anything but a store answer that said so.
|
|
196
|
+
*/
|
|
197
|
+
export interface StoreBackend {
|
|
198
|
+
readonly store: StoreId;
|
|
199
|
+
upload(input: StoreUploadInput): Promise<StoreUploadResult>;
|
|
200
|
+
publish(input: StorePublishInput): Promise<StorePublishResult>;
|
|
201
|
+
status(): Promise<StoreStatusResult>;
|
|
202
|
+
}
|
|
203
|
+
/** What every backend's factory takes, beside its credentials. */
|
|
204
|
+
export interface StoreBackendOptions {
|
|
205
|
+
/** Injected in tests; resolved at call time so a `globalThis.fetch` stub is honoured (as in `publish-readback.ts`). */
|
|
206
|
+
readonly fetchImpl?: typeof fetch;
|
|
207
|
+
readonly sleep?: (ms: number) => Promise<void>;
|
|
208
|
+
readonly now?: () => number;
|
|
209
|
+
/** Called for each request under `GJSIFY_WEBEXT_DEBUG`. Whatever it prints has been redacted first. */
|
|
210
|
+
readonly log?: (msg: string) => void;
|
|
211
|
+
}
|
|
212
|
+
/** A store's backend factory, registered in {@link STORE_BACKENDS} by its own file. */
|
|
213
|
+
export type StoreBackendFactory = (credentials: StoreCredentials, options?: StoreBackendOptions) => StoreBackend;
|
|
214
|
+
/**
|
|
215
|
+
* Backend per store, EMPTY in this slice: the interface lands before the two
|
|
216
|
+
* implementations so they can be written against a file neither of them owns.
|
|
217
|
+
* `chrome.ts` and `edge.ts` each add their own row; nothing else changes.
|
|
218
|
+
*/
|
|
219
|
+
export declare const STORE_BACKENDS: Partial<Record<StoreId, StoreBackendFactory>>;
|
|
220
|
+
/**
|
|
221
|
+
* The backend for a store, with its credentials resolved from `env`.
|
|
222
|
+
*
|
|
223
|
+
* The order matters: a store with no backend is refused BEFORE credentials are
|
|
224
|
+
* read, so `submit --store amo` says "not implemented" rather than asking for two
|
|
225
|
+
* variables it would not use.
|
|
226
|
+
*/
|
|
227
|
+
export declare function createStoreBackend(store: StoreId, env: EnvLike, options?: StoreBackendOptions): StoreBackend;
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
// The store seam of `gjsify webext submit`: one `StoreBackend` per store, the
|
|
2
|
+
// credential names each one reads from the ENVIRONMENT, and the three outcomes a
|
|
3
|
+
// submission can have (ADR 0077 § 7 and § Amendment 1).
|
|
4
|
+
//
|
|
5
|
+
// THIS FILE IS THE INTERFACE AND NOTHING ELSE. The Chrome and Edge backends are
|
|
6
|
+
// written separately against it, so every type here is meant to be read by
|
|
7
|
+
// somebody who cannot change it: keep it small, add a store as a ROW in
|
|
8
|
+
// `STORES`/`STORE_CREDENTIALS` rather than a branch, and put a vendor's quirks in
|
|
9
|
+
// that vendor's file. What the two vendor references actually say — V2 endpoints,
|
|
10
|
+
// `UPLOAD_IN_PROGRESS`, Edge's 202 + `Location`, and the two claims that are
|
|
11
|
+
// documented nowhere — is in ADR 0077 § Amendment 1 and not repeated per backend.
|
|
12
|
+
//
|
|
13
|
+
// THREE THINGS THE SHAPE IS CHOSEN FOR, each from an incident in this tree rather
|
|
14
|
+
// than from taste:
|
|
15
|
+
//
|
|
16
|
+
// 1. `fetchImpl` is injected, the way `utils/publish-readback.ts` injects it, so
|
|
17
|
+
// a backend is testable with no network and no account. A store backend that
|
|
18
|
+
// can only be exercised against a live listing is a backend nobody exercises.
|
|
19
|
+
// 2. Submitting the same version twice is SURVIVABLE. A dropped connection after
|
|
20
|
+
// a 202 leaves a draft whose state the client did not read, so "already at
|
|
21
|
+
// this version" and "a submission is in review" are their own errors, not a
|
|
22
|
+
// non-zero exit: see {@link isIdempotentSkip}.
|
|
23
|
+
// 3. Credentials never reach a log, a debug dump or a thrown message. Everything
|
|
24
|
+
// a backend prints about a request goes through {@link redactHeaders} or
|
|
25
|
+
// {@link redactSecrets} first. `publish-readback.ts`'s rule carries over
|
|
26
|
+
// unchanged: never claim what was not established.
|
|
27
|
+
export const STORE_IDS = ['chrome', 'edge', 'amo'];
|
|
28
|
+
/**
|
|
29
|
+
* Credentials per store, read from the environment and NEVER from
|
|
30
|
+
* `package.json#gjsify.webext`: that file is committed, and a token in a
|
|
31
|
+
* committed file is a token in the published package too.
|
|
32
|
+
*
|
|
33
|
+
* Deliberately NOT ADR 0126's `CREDENTIALS` table, which is keyed by `HostOs`
|
|
34
|
+
* because a signing identity is per host. A store credential is the same on every
|
|
35
|
+
* host and differs per STORE, it has no `install` counterpart (there is no
|
|
36
|
+
* keychain to build), and it can only touch one listing. The full argument, and
|
|
37
|
+
* the fact that `ship credentials` is accepted-but-unbuilt, is ADR 0077
|
|
38
|
+
* § Amendment 1.
|
|
39
|
+
*/
|
|
40
|
+
export const STORE_CREDENTIALS = {
|
|
41
|
+
chrome: [
|
|
42
|
+
{ env: 'CHROME_WEB_STORE_PUBLISHER_ID', secret: false, what: 'the publisher the item belongs to' },
|
|
43
|
+
{ env: 'CHROME_WEB_STORE_ITEM_ID', secret: false, what: 'the item id from the Developer Dashboard' },
|
|
44
|
+
{ env: 'CHROME_WEB_STORE_CLIENT_ID', secret: false, what: 'the OAuth client id' },
|
|
45
|
+
{ env: 'CHROME_WEB_STORE_CLIENT_SECRET', secret: true, what: 'the OAuth client secret' },
|
|
46
|
+
{
|
|
47
|
+
env: 'CHROME_WEB_STORE_REFRESH_TOKEN',
|
|
48
|
+
secret: true,
|
|
49
|
+
what: 'the refresh token the access token is minted from',
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
edge: [
|
|
53
|
+
{ env: 'EDGE_ADDONS_PRODUCT_ID', secret: false, what: 'the product id from Partner Center' },
|
|
54
|
+
{ env: 'EDGE_ADDONS_CLIENT_ID', secret: false, what: 'the client id sent as X-ClientID' },
|
|
55
|
+
{ env: 'EDGE_ADDONS_API_KEY', secret: true, what: 'the API key sent as `Authorization: ApiKey …`' },
|
|
56
|
+
],
|
|
57
|
+
/**
|
|
58
|
+
* AMO has a ROW and no backend in this slice, on purpose: the shape of a third
|
|
59
|
+
* store is fixed before one is written, and `submit --store amo` then refuses
|
|
60
|
+
* with a sentence instead of falling off the end of a switch. `webext sign`
|
|
61
|
+
* keeps calling `web-ext`, which reads these two itself — they are listed so
|
|
62
|
+
* nobody adds a second spelling later.
|
|
63
|
+
*/
|
|
64
|
+
amo: [
|
|
65
|
+
{ env: 'WEB_EXT_API_KEY', secret: false, what: "the AMO JWT issuer (`web-ext`'s own name for it)" },
|
|
66
|
+
{ env: 'WEB_EXT_API_SECRET', secret: true, what: 'the AMO JWT secret' },
|
|
67
|
+
],
|
|
68
|
+
};
|
|
69
|
+
export const STORES = {
|
|
70
|
+
chrome: { id: 'chrome', label: 'Chrome Web Store', implemented: false, createsListings: false },
|
|
71
|
+
edge: { id: 'edge', label: 'Edge Add-ons', implemented: false, createsListings: false },
|
|
72
|
+
amo: { id: 'amo', label: 'addons.mozilla.org', implemented: false, createsListings: false },
|
|
73
|
+
};
|
|
74
|
+
/** `id` as a {@link StoreId}, or null — the caller owns the message, same contract as `parseWebextTarget`'s callers. */
|
|
75
|
+
export function asStoreId(id) {
|
|
76
|
+
return STORE_IDS.includes(id) ? id : null;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Every variable a store's row names, or a refusal listing ALL the missing ones.
|
|
80
|
+
*
|
|
81
|
+
* One run per fix, not one per variable — the same reason `resolveWebextConfig`
|
|
82
|
+
* collects its problems before throwing. An empty string counts as missing: a CI
|
|
83
|
+
* secret that was never set expands to one, and treating that as a credential
|
|
84
|
+
* sends an `Authorization: ApiKey ` header whose 401 says nothing about the cause.
|
|
85
|
+
*/
|
|
86
|
+
export function resolveStoreCredentials(store, env) {
|
|
87
|
+
const fields = STORE_CREDENTIALS[store];
|
|
88
|
+
const resolved = {};
|
|
89
|
+
const missing = [];
|
|
90
|
+
for (const field of fields) {
|
|
91
|
+
const value = env[field.env];
|
|
92
|
+
if (value === undefined || value === '')
|
|
93
|
+
missing.push(field);
|
|
94
|
+
else
|
|
95
|
+
resolved[field.env] = value;
|
|
96
|
+
}
|
|
97
|
+
if (missing.length > 0)
|
|
98
|
+
throw new StoreCredentialsMissingError(store, missing);
|
|
99
|
+
return resolved;
|
|
100
|
+
}
|
|
101
|
+
/** The values of a store's `secret: true` fields, for {@link redactSecrets}. */
|
|
102
|
+
export function secretValuesOf(store, credentials) {
|
|
103
|
+
return STORE_CREDENTIALS[store]
|
|
104
|
+
.filter((field) => field.secret)
|
|
105
|
+
.map((field) => credentials[field.env])
|
|
106
|
+
.filter((value) => value !== undefined && value !== '');
|
|
107
|
+
}
|
|
108
|
+
/* -------------------------------------------------------------------- redaction */
|
|
109
|
+
export const REDACTED = '<redacted>';
|
|
110
|
+
/**
|
|
111
|
+
* Header names whose VALUE is never printed, lower-cased.
|
|
112
|
+
*
|
|
113
|
+
* `x-clientid` is on the list although Edge's client id is not a secret on its
|
|
114
|
+
* own: the pair is what authenticates, and a log that carries one half invites
|
|
115
|
+
* pasting the other next to it. `x-goog-api-key` and `cookie` are here because a
|
|
116
|
+
* backend that grows one should not have to remember to extend this list.
|
|
117
|
+
*/
|
|
118
|
+
const SECRET_HEADERS = ['authorization', 'x-clientid', 'x-goog-api-key', 'cookie', 'set-cookie'];
|
|
119
|
+
/**
|
|
120
|
+
* A copy of `headers` safe to print: every authorising value replaced, every
|
|
121
|
+
* other value verbatim, names lower-cased so two spellings of one header cannot
|
|
122
|
+
* disagree about whether they are secret.
|
|
123
|
+
*
|
|
124
|
+
* A name containing `token`, `secret` or `key` is redacted too, so a header added
|
|
125
|
+
* by a later backend is secret by DEFAULT and has to be named explicitly to be
|
|
126
|
+
* printed. The failure mode this prevents is the quiet one: a new header leaks
|
|
127
|
+
* because nobody edited a list.
|
|
128
|
+
*/
|
|
129
|
+
export function redactHeaders(headers) {
|
|
130
|
+
const out = {};
|
|
131
|
+
for (const [name, value] of Object.entries(headers)) {
|
|
132
|
+
const key = name.toLowerCase();
|
|
133
|
+
const secret = SECRET_HEADERS.includes(key) || /token|secret|key/.test(key);
|
|
134
|
+
out[key] = secret ? REDACTED : value;
|
|
135
|
+
}
|
|
136
|
+
return out;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* `text` with every value in `secrets` replaced, for a log line, a debug dump or
|
|
140
|
+
* the message of a thrown error.
|
|
141
|
+
*
|
|
142
|
+
* Longest first, because a short secret that is a substring of a long one would
|
|
143
|
+
* otherwise leave the long one's remainder in the text. Empty and one-character
|
|
144
|
+
* values are skipped: redacting those rewrites the whole message into noise and
|
|
145
|
+
* says nothing, and a credential that short is not a credential.
|
|
146
|
+
*/
|
|
147
|
+
export function redactSecrets(text, secrets) {
|
|
148
|
+
let out = text;
|
|
149
|
+
for (const secret of [...secrets].filter((s) => s.length > 1).sort((a, b) => b.length - a.length)) {
|
|
150
|
+
out = out.split(secret).join(REDACTED);
|
|
151
|
+
}
|
|
152
|
+
return out;
|
|
153
|
+
}
|
|
154
|
+
/* ----------------------------------------------------------------------- errors */
|
|
155
|
+
/** The store's row named variables this environment does not set. Lists all of them, with what each is. */
|
|
156
|
+
export class StoreCredentialsMissingError extends Error {
|
|
157
|
+
store;
|
|
158
|
+
missing;
|
|
159
|
+
constructor(store, missing) {
|
|
160
|
+
super(`gjsify webext submit: ${STORES[store].label} needs ${missing.length} environment variable(s) this run does not set:\n` +
|
|
161
|
+
missing.map((field) => ` ${field.env} — ${field.what}`).join('\n') +
|
|
162
|
+
`\nSet them in the environment, never in package.json (ADR 0077 § Amendment 1).`);
|
|
163
|
+
this.store = store;
|
|
164
|
+
this.missing = missing;
|
|
165
|
+
this.name = 'StoreCredentialsMissingError';
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/** A store with a row and no backend — the AMO slot, or a store declared before its file exists. */
|
|
169
|
+
export class StoreUnsupportedError extends Error {
|
|
170
|
+
store;
|
|
171
|
+
constructor(store, detail) {
|
|
172
|
+
super(`gjsify webext submit: ${STORES[store].label} is not implemented — ${detail}`);
|
|
173
|
+
this.store = store;
|
|
174
|
+
this.name = 'StoreUnsupportedError';
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* The store already holds this exact version, so there is nothing to do.
|
|
179
|
+
*
|
|
180
|
+
* NOT a failure. A `submit` retried after a dropped connection must be able to
|
|
181
|
+
* reach this and exit 0, because the alternative is a second upload against a
|
|
182
|
+
* draft whose state the client never read.
|
|
183
|
+
*/
|
|
184
|
+
export class StoreVersionAlreadyThereError extends Error {
|
|
185
|
+
store;
|
|
186
|
+
version;
|
|
187
|
+
constructor(store, version) {
|
|
188
|
+
super(`${STORES[store].label}: version ${version} is already there — nothing to submit.`);
|
|
189
|
+
this.store = store;
|
|
190
|
+
this.version = version;
|
|
191
|
+
this.name = 'StoreVersionAlreadyThereError';
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* A submission is in review, so this version cannot be uploaded or published now.
|
|
196
|
+
*
|
|
197
|
+
* Also not a failure of this run: the previous submit worked and the store is
|
|
198
|
+
* busy with it. Cancelling it is the user's decision (Chrome has
|
|
199
|
+
* `:cancelSubmission`; Edge does not document one), never this command's.
|
|
200
|
+
*/
|
|
201
|
+
export class StoreInReviewError extends Error {
|
|
202
|
+
store;
|
|
203
|
+
constructor(store, detail) {
|
|
204
|
+
super(`${STORES[store].label}: a submission is in review — ${detail}`);
|
|
205
|
+
this.store = store;
|
|
206
|
+
this.name = 'StoreInReviewError';
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* A real failure: a 4xx that is not one of the two above, a 5xx, a timeout, an
|
|
211
|
+
* answer that did not parse.
|
|
212
|
+
*
|
|
213
|
+
* `detail` is built by the backend and MUST have passed through
|
|
214
|
+
* {@link redactSecrets} — it is the one field that carries vendor text, and
|
|
215
|
+
* vendor text is where an echoed credential would appear.
|
|
216
|
+
*/
|
|
217
|
+
export class StoreApiError extends Error {
|
|
218
|
+
store;
|
|
219
|
+
httpStatus;
|
|
220
|
+
constructor(store, httpStatus, detail) {
|
|
221
|
+
super(`${STORES[store].label}: ${httpStatus === undefined ? 'request failed' : `HTTP ${httpStatus}`} — ${detail}`);
|
|
222
|
+
this.store = store;
|
|
223
|
+
this.httpStatus = httpStatus;
|
|
224
|
+
this.name = 'StoreApiError';
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
/** True for the two outcomes a retried `submit` may report and exit 0 on. */
|
|
228
|
+
export function isIdempotentSkip(error) {
|
|
229
|
+
return error instanceof StoreVersionAlreadyThereError || error instanceof StoreInReviewError;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Backend per store, EMPTY in this slice: the interface lands before the two
|
|
233
|
+
* implementations so they can be written against a file neither of them owns.
|
|
234
|
+
* `chrome.ts` and `edge.ts` each add their own row; nothing else changes.
|
|
235
|
+
*/
|
|
236
|
+
export const STORE_BACKENDS = {};
|
|
237
|
+
/**
|
|
238
|
+
* The backend for a store, with its credentials resolved from `env`.
|
|
239
|
+
*
|
|
240
|
+
* The order matters: a store with no backend is refused BEFORE credentials are
|
|
241
|
+
* read, so `submit --store amo` says "not implemented" rather than asking for two
|
|
242
|
+
* variables it would not use.
|
|
243
|
+
*/
|
|
244
|
+
export function createStoreBackend(store, env, options) {
|
|
245
|
+
const factory = STORE_BACKENDS[store];
|
|
246
|
+
if (factory === undefined) {
|
|
247
|
+
throw new StoreUnsupportedError(store, store === 'amo'
|
|
248
|
+
? 'use `gjsify webext sign` for AMO; this slice ships the Chrome and Edge backends only (ADR 0077 § Amendment 1)'
|
|
249
|
+
: 'no backend is registered for it');
|
|
250
|
+
}
|
|
251
|
+
return factory(resolveStoreCredentials(store, env), options);
|
|
252
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/cli",
|
|
3
|
-
"version": "0.64.
|
|
3
|
+
"version": "0.64.41-next.335",
|
|
4
4
|
"description": "CLI for Gjsify",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -142,22 +142,22 @@
|
|
|
142
142
|
"cli"
|
|
143
143
|
],
|
|
144
144
|
"dependencies": {
|
|
145
|
-
"@gjsify/blueprint": "
|
|
146
|
-
"@gjsify/buffer": "
|
|
147
|
-
"@gjsify/create-app": "
|
|
148
|
-
"@gjsify/node-globals": "
|
|
149
|
-
"@gjsify/node-polyfills": "
|
|
150
|
-
"@gjsify/npm-registry": "
|
|
151
|
-
"@gjsify/resolve-npm": "
|
|
152
|
-
"@gjsify/rolldown-plugin-gjsify": "
|
|
153
|
-
"@gjsify/vite-plugin-blueprint": "
|
|
154
|
-
"@gjsify/rolldown-plugin-pnp": "
|
|
155
|
-
"@gjsify/semver": "
|
|
156
|
-
"@gjsify/tar": "
|
|
157
|
-
"@gjsify/tsc": "
|
|
158
|
-
"@gjsify/utils": "
|
|
159
|
-
"@gjsify/web-polyfills": "
|
|
160
|
-
"@gjsify/workspace": "
|
|
145
|
+
"@gjsify/blueprint": "0.64.41-next.335",
|
|
146
|
+
"@gjsify/buffer": "0.64.41-next.335",
|
|
147
|
+
"@gjsify/create-app": "0.64.41-next.335",
|
|
148
|
+
"@gjsify/node-globals": "0.64.41-next.335",
|
|
149
|
+
"@gjsify/node-polyfills": "0.64.41-next.335",
|
|
150
|
+
"@gjsify/npm-registry": "0.64.41-next.335",
|
|
151
|
+
"@gjsify/resolve-npm": "0.64.41-next.335",
|
|
152
|
+
"@gjsify/rolldown-plugin-gjsify": "0.64.41-next.335",
|
|
153
|
+
"@gjsify/vite-plugin-blueprint": "0.64.41-next.335",
|
|
154
|
+
"@gjsify/rolldown-plugin-pnp": "0.64.41-next.335",
|
|
155
|
+
"@gjsify/semver": "0.64.41-next.335",
|
|
156
|
+
"@gjsify/tar": "0.64.41-next.335",
|
|
157
|
+
"@gjsify/tsc": "0.64.41-next.335",
|
|
158
|
+
"@gjsify/utils": "0.64.41-next.335",
|
|
159
|
+
"@gjsify/web-polyfills": "0.64.41-next.335",
|
|
160
|
+
"@gjsify/workspace": "0.64.41-next.335",
|
|
161
161
|
"acorn": "^8.17.0",
|
|
162
162
|
"cosmiconfig": "^9.0.2",
|
|
163
163
|
"get-tsconfig": "^4.14.0",
|
|
@@ -166,13 +166,13 @@
|
|
|
166
166
|
"yargs": "^18.0.0"
|
|
167
167
|
},
|
|
168
168
|
"devDependencies": {
|
|
169
|
-
"@gjsify/unit": "
|
|
169
|
+
"@gjsify/unit": "0.64.41-next.335",
|
|
170
170
|
"@types/yargs": "^17.0.35",
|
|
171
171
|
"typescript": "^6.0.3"
|
|
172
172
|
},
|
|
173
173
|
"peerDependencies": {
|
|
174
|
-
"@gjsify/oxfmt-native": "
|
|
175
|
-
"@gjsify/rolldown-native": "
|
|
174
|
+
"@gjsify/oxfmt-native": "0.64.41-next.335",
|
|
175
|
+
"@gjsify/rolldown-native": "0.64.41-next.335"
|
|
176
176
|
},
|
|
177
177
|
"peerDependenciesMeta": {
|
|
178
178
|
"@gjsify/oxfmt-native": {
|
|
@@ -191,5 +191,6 @@
|
|
|
191
191
|
"bugs": {
|
|
192
192
|
"url": "https://github.com/gjsify/gjsify/issues"
|
|
193
193
|
},
|
|
194
|
-
"homepage": "https://github.com/gjsify/gjsify/tree/main/packages/infra/cli#readme"
|
|
194
|
+
"homepage": "https://github.com/gjsify/gjsify/tree/main/packages/infra/cli#readme",
|
|
195
|
+
"gitHead": "b42bb6c4b1b1b2344bd3695eb3c9f7c14498c7a0"
|
|
195
196
|
}
|