@gjsify/cli 0.64.37 → 0.64.40
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 +260 -260
- 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/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 +20 -20
|
@@ -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.40",
|
|
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": "^0.64.
|
|
146
|
-
"@gjsify/buffer": "^0.64.
|
|
147
|
-
"@gjsify/create-app": "^0.64.
|
|
148
|
-
"@gjsify/node-globals": "^0.64.
|
|
149
|
-
"@gjsify/node-polyfills": "^0.64.
|
|
150
|
-
"@gjsify/npm-registry": "^0.64.
|
|
151
|
-
"@gjsify/resolve-npm": "^0.64.
|
|
152
|
-
"@gjsify/rolldown-plugin-gjsify": "^0.64.
|
|
153
|
-
"@gjsify/vite-plugin-blueprint": "^0.64.
|
|
154
|
-
"@gjsify/rolldown-plugin-pnp": "^0.64.
|
|
155
|
-
"@gjsify/semver": "^0.64.
|
|
156
|
-
"@gjsify/tar": "^0.64.
|
|
157
|
-
"@gjsify/tsc": "^0.64.
|
|
158
|
-
"@gjsify/utils": "^0.64.
|
|
159
|
-
"@gjsify/web-polyfills": "^0.64.
|
|
160
|
-
"@gjsify/workspace": "^0.64.
|
|
145
|
+
"@gjsify/blueprint": "^0.64.40",
|
|
146
|
+
"@gjsify/buffer": "^0.64.40",
|
|
147
|
+
"@gjsify/create-app": "^0.64.40",
|
|
148
|
+
"@gjsify/node-globals": "^0.64.40",
|
|
149
|
+
"@gjsify/node-polyfills": "^0.64.40",
|
|
150
|
+
"@gjsify/npm-registry": "^0.64.40",
|
|
151
|
+
"@gjsify/resolve-npm": "^0.64.40",
|
|
152
|
+
"@gjsify/rolldown-plugin-gjsify": "^0.64.40",
|
|
153
|
+
"@gjsify/vite-plugin-blueprint": "^0.64.40",
|
|
154
|
+
"@gjsify/rolldown-plugin-pnp": "^0.64.40",
|
|
155
|
+
"@gjsify/semver": "^0.64.40",
|
|
156
|
+
"@gjsify/tar": "^0.64.40",
|
|
157
|
+
"@gjsify/tsc": "^0.64.40",
|
|
158
|
+
"@gjsify/utils": "^0.64.40",
|
|
159
|
+
"@gjsify/web-polyfills": "^0.64.40",
|
|
160
|
+
"@gjsify/workspace": "^0.64.40",
|
|
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": "^0.64.
|
|
169
|
+
"@gjsify/unit": "^0.64.40",
|
|
170
170
|
"@types/yargs": "^17.0.35",
|
|
171
171
|
"typescript": "^6.0.3"
|
|
172
172
|
},
|
|
173
173
|
"peerDependencies": {
|
|
174
|
-
"@gjsify/oxfmt-native": "^0.64.
|
|
175
|
-
"@gjsify/rolldown-native": "^0.64.
|
|
174
|
+
"@gjsify/oxfmt-native": "^0.64.40",
|
|
175
|
+
"@gjsify/rolldown-native": "^0.64.40"
|
|
176
176
|
},
|
|
177
177
|
"peerDependenciesMeta": {
|
|
178
178
|
"@gjsify/oxfmt-native": {
|