@gjsify/cli 0.64.41-next.335 → 0.64.41
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 +185 -171
- package/lib/templates/install.mjs.tmpl +15 -1
- package/lib/utils/webext/stores/chrome.d.ts +2 -0
- package/lib/utils/webext/stores/chrome.js +214 -0
- package/lib/utils/webext/stores/edge.d.ts +7 -0
- package/lib/utils/webext/stores/edge.js +196 -0
- package/lib/utils/webext/stores/index.d.ts +22 -4
- package/lib/utils/webext/stores/index.js +11 -6
- package/package.json +21 -22
|
@@ -262,6 +262,9 @@ async function fetchOnce(session, startUrl, { forceHttp1 = false } = {}) {
|
|
|
262
262
|
if (status !== Soup.Status.OK) {
|
|
263
263
|
const err = new Error(`HTTP ${status} from ${url}`);
|
|
264
264
|
err.httpStatus = status;
|
|
265
|
+
// Who said no: a refusal from a redirect TARGET is the CDN's signed URL
|
|
266
|
+
// misbehaving; from the first hop it is the host we asked answering.
|
|
267
|
+
err.fromRedirect = hop > 0;
|
|
265
268
|
throw err;
|
|
266
269
|
}
|
|
267
270
|
return bytes.get_data();
|
|
@@ -286,6 +289,13 @@ async function fetchOnce(session, startUrl, { forceHttp1 = false } = {}) {
|
|
|
286
289
|
* is it saying no; retrying either would only delay the same result while making a real
|
|
287
290
|
* outage look like a hang.
|
|
288
291
|
*
|
|
292
|
+
* SECOND INCIDENT (2026-11-14, PR #2639): three CI attempts in a row died on `HTTP 403 from
|
|
293
|
+
* https://release-assets.githubusercontent.com/…`, for the `.sha256` and the bundle alike.
|
|
294
|
+
* github.com answers 302 to a short-lived SIGNED CDN URL and that CDN transiently answers
|
|
295
|
+
* 403. So a 403 from a REDIRECT TARGET (hop > 0) is a hiccup too and is retried — each
|
|
296
|
+
* retry restarts at the original URL, which mints a fresh signed URL. A 403 from the FIRST
|
|
297
|
+
* hop (the host we asked, github.com itself) stays an answer, exactly like a 404.
|
|
298
|
+
*
|
|
289
299
|
* FIVE attempts, not three, and the numbers come from a run rather than a preference:
|
|
290
300
|
* with three the CI log showed `retry 2/3` and `retry 3/3` and still failed, because each
|
|
291
301
|
* attempt takes ~20 s to give up — so the 500ms/1500ms backoff was noise beside it and the
|
|
@@ -308,7 +318,11 @@ async function fetchBytes(session, url) {
|
|
|
308
318
|
} catch (err) {
|
|
309
319
|
lastErr = err;
|
|
310
320
|
const status = err.httpStatus;
|
|
311
|
-
const retriable =
|
|
321
|
+
const retriable =
|
|
322
|
+
status === undefined ||
|
|
323
|
+
status === 429 ||
|
|
324
|
+
status >= 500 ||
|
|
325
|
+
(status === 403 && err.fromRedirect === true);
|
|
312
326
|
if (!retriable || attempt === attempts) break;
|
|
313
327
|
const wait = RETRY_BACKOFF_MS[Math.min(attempt - 1, RETRY_BACKOFF_MS.length - 1)];
|
|
314
328
|
info(`Fetch of ${url} failed (${err.message}) — retry ${attempt + 1}/${attempts} in ${wait}ms`);
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
// Chrome Web Store backend, Publish API V2 (ADR 0077 § Amendment 1).
|
|
2
|
+
//
|
|
3
|
+
// Everything here is DOCUMENTED, none of it MEASURED against a live item
|
|
4
|
+
// (developer.chrome.com/docs/webstore/api and /using-api, read 2026-11-13):
|
|
5
|
+
// refresh token → access token at oauth2.googleapis.com, `:upload` with the zip
|
|
6
|
+
// as the body, `:publish`, `:fetchStatus`. The upload is asynchronous
|
|
7
|
+
// (`uploadState: IN_PROGRESS`); this file reports that state and never polls —
|
|
8
|
+
// the shared poll loop owns the waiting.
|
|
9
|
+
import { readFileSync } from 'node:fs';
|
|
10
|
+
import { redactHeaders, redactSecrets, secretValuesOf, StoreApiError, StoreInReviewError, StoreVersionAlreadyThereError, } from './index.js';
|
|
11
|
+
const TOKEN_URL = 'https://oauth2.googleapis.com/token';
|
|
12
|
+
const API_ROOT = 'https://chromewebstore.googleapis.com';
|
|
13
|
+
const TOKEN_HINT = 'Create a new OAuth client in the Google Cloud Console (APIs & Services → Credentials) and a new refresh token ' +
|
|
14
|
+
'with the scope https://www.googleapis.com/auth/chromewebstore, e.g. in https://developers.google.com/oauthplayground ' +
|
|
15
|
+
'("Use your own OAuth credentials"); then update CHROME_WEB_STORE_CLIENT_ID, CHROME_WEB_STORE_CLIENT_SECRET and CHROME_WEB_STORE_REFRESH_TOKEN.';
|
|
16
|
+
const VISIBILITY_HINT = 'If the visibility was changed in the Developer Dashboard, the API refuses to publish until the item has been ' +
|
|
17
|
+
'published by hand once with the new visibility: publish once in the Developer Dashboard by hand (einmal im Dashboard von Hand veröffentlichen), then retry.';
|
|
18
|
+
const versionOf = (revision) => revision?.distributionChannels?.find((channel) => channel.crxVersion !== undefined)?.crxVersion;
|
|
19
|
+
export function createChromeBackend(credentials, options = {}) {
|
|
20
|
+
const publisher = credentials['CHROME_WEB_STORE_PUBLISHER_ID'];
|
|
21
|
+
const item = credentials['CHROME_WEB_STORE_ITEM_ID'];
|
|
22
|
+
const name = `publishers/${encodeURIComponent(publisher)}/items/${encodeURIComponent(item)}`;
|
|
23
|
+
const secrets = [...secretValuesOf('chrome', credentials)];
|
|
24
|
+
const doFetch = options.fetchImpl ?? ((...args) => globalThis.fetch(...args));
|
|
25
|
+
let accessToken;
|
|
26
|
+
const scrub = (text) => redactSecrets(text, secrets);
|
|
27
|
+
const fail = (status, detail) => new StoreApiError('chrome', status, scrub(detail));
|
|
28
|
+
/** The vendor's own error message when the body carries one, else a short slice of the text. */
|
|
29
|
+
const describe = async (res) => {
|
|
30
|
+
const text = await res.text().catch(() => '');
|
|
31
|
+
try {
|
|
32
|
+
const parsed = JSON.parse(text);
|
|
33
|
+
const message = typeof parsed.error === 'string'
|
|
34
|
+
? [parsed.error, parsed.error_description].filter(Boolean).join(': ')
|
|
35
|
+
: parsed.error?.message;
|
|
36
|
+
if (message)
|
|
37
|
+
return message.slice(0, 400);
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
// not JSON — fall through to the raw slice
|
|
41
|
+
}
|
|
42
|
+
return text.trim().slice(0, 200) || 'empty response';
|
|
43
|
+
};
|
|
44
|
+
const send = async (url, init) => {
|
|
45
|
+
options.log?.(`${init.method ?? 'GET'} ${url} ${JSON.stringify(redactHeaders(init.headers))}`);
|
|
46
|
+
try {
|
|
47
|
+
return await doFetch(url, init);
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
throw fail(undefined, error instanceof Error ? error.message : String(error));
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const token = async () => {
|
|
54
|
+
if (accessToken !== undefined)
|
|
55
|
+
return accessToken;
|
|
56
|
+
const body = new URLSearchParams({
|
|
57
|
+
client_id: credentials['CHROME_WEB_STORE_CLIENT_ID'],
|
|
58
|
+
client_secret: credentials['CHROME_WEB_STORE_CLIENT_SECRET'],
|
|
59
|
+
refresh_token: credentials['CHROME_WEB_STORE_REFRESH_TOKEN'],
|
|
60
|
+
grant_type: 'refresh_token',
|
|
61
|
+
});
|
|
62
|
+
const res = await send(TOKEN_URL, {
|
|
63
|
+
method: 'POST',
|
|
64
|
+
headers: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
65
|
+
body: body.toString(),
|
|
66
|
+
});
|
|
67
|
+
if (!res.ok) {
|
|
68
|
+
const detail = await describe(res);
|
|
69
|
+
const hint = res.status === 400 || res.status === 401 ? ` ${TOKEN_HINT}` : '';
|
|
70
|
+
throw fail(res.status, `token exchange refused: ${detail}.${hint}`);
|
|
71
|
+
}
|
|
72
|
+
const parsed = (await res.json().catch(() => ({})));
|
|
73
|
+
if (typeof parsed.access_token !== 'string' || parsed.access_token === '') {
|
|
74
|
+
throw fail(res.status, 'token exchange answered without an access_token');
|
|
75
|
+
}
|
|
76
|
+
accessToken = parsed.access_token;
|
|
77
|
+
secrets.push(accessToken);
|
|
78
|
+
return accessToken;
|
|
79
|
+
};
|
|
80
|
+
const call = async (url, init) => {
|
|
81
|
+
const bearer = await token();
|
|
82
|
+
return send(url, { ...init, headers: { ...init.headers, authorization: `Bearer ${bearer}` } });
|
|
83
|
+
};
|
|
84
|
+
const readStatus = async () => {
|
|
85
|
+
const res = await call(`${API_ROOT}/v2/${name}:fetchStatus`, { method: 'GET' });
|
|
86
|
+
if (!res.ok)
|
|
87
|
+
throw fail(res.status, `fetchStatus failed: ${await describe(res)}`);
|
|
88
|
+
return (await res.json().catch(() => {
|
|
89
|
+
throw fail(res.status, 'fetchStatus answered with something that is not JSON');
|
|
90
|
+
}));
|
|
91
|
+
};
|
|
92
|
+
/** The two idempotent outcomes, read from the store before anything is sent. */
|
|
93
|
+
const refuseIfBusy = (body, version) => {
|
|
94
|
+
const submitted = body.submittedItemRevisionStatus;
|
|
95
|
+
const submittedVersion = versionOf(submitted);
|
|
96
|
+
if (submitted?.state === 'PENDING_REVIEW') {
|
|
97
|
+
if (submittedVersion === version)
|
|
98
|
+
throw new StoreVersionAlreadyThereError('chrome', version);
|
|
99
|
+
throw new StoreInReviewError('chrome', `version ${submittedVersion ?? '(unknown)'} is pending review; wait for it or cancel it in the Developer Dashboard.`);
|
|
100
|
+
}
|
|
101
|
+
if (versionOf(body.publishedItemRevisionStatus) === version || submittedVersion === version) {
|
|
102
|
+
throw new StoreVersionAlreadyThereError('chrome', version);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
const classify = (state) => {
|
|
106
|
+
switch (state) {
|
|
107
|
+
case 'PENDING_REVIEW':
|
|
108
|
+
return 'in-review';
|
|
109
|
+
case 'PUBLISHED':
|
|
110
|
+
case 'PUBLISHED_TO_TESTERS':
|
|
111
|
+
return 'published';
|
|
112
|
+
case 'REJECTED':
|
|
113
|
+
return 'rejected';
|
|
114
|
+
// STAGED (approved, waiting for the developer) and CANCELLED both mean
|
|
115
|
+
// "nothing is in flight"; the detail line names which one.
|
|
116
|
+
case 'STAGED':
|
|
117
|
+
case 'CANCELLED':
|
|
118
|
+
return 'draft';
|
|
119
|
+
default:
|
|
120
|
+
return 'unknown';
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
return {
|
|
124
|
+
store: 'chrome',
|
|
125
|
+
async upload(input) {
|
|
126
|
+
refuseIfBusy(await readStatus(), input.version);
|
|
127
|
+
const res = await call(`${API_ROOT}/upload/v2/${name}:upload`, {
|
|
128
|
+
method: 'POST',
|
|
129
|
+
headers: { 'content-type': 'application/zip' },
|
|
130
|
+
body: readFileSync(input.zipPath),
|
|
131
|
+
});
|
|
132
|
+
if (!res.ok)
|
|
133
|
+
throw fail(res.status, `upload failed: ${await describe(res)}`);
|
|
134
|
+
const body = (await res.json().catch(() => ({})));
|
|
135
|
+
switch (body.uploadState) {
|
|
136
|
+
case 'SUCCEEDED':
|
|
137
|
+
return {
|
|
138
|
+
operationId: body.name,
|
|
139
|
+
ingested: true,
|
|
140
|
+
detail: `uploadState SUCCEEDED, crxVersion ${body.crxVersion ?? '(not reported)'}`,
|
|
141
|
+
};
|
|
142
|
+
case 'IN_PROGRESS':
|
|
143
|
+
return {
|
|
144
|
+
operationId: body.name,
|
|
145
|
+
ingested: false,
|
|
146
|
+
detail: 'uploadState IN_PROGRESS — poll fetchStatus',
|
|
147
|
+
};
|
|
148
|
+
case 'FAILED':
|
|
149
|
+
throw fail(res.status, 'upload accepted but the store reports uploadState FAILED; check the package in the Developer Dashboard');
|
|
150
|
+
default:
|
|
151
|
+
throw fail(res.status, `upload answered with uploadState ${body.uploadState ?? '(none)'}, which is not a state this client knows`);
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
async publish(input) {
|
|
155
|
+
const before = (await readStatus()).submittedItemRevisionStatus;
|
|
156
|
+
if (before?.state === 'PENDING_REVIEW') {
|
|
157
|
+
throw new StoreInReviewError('chrome', `version ${versionOf(before) ?? '(unknown)'} is pending review already.`);
|
|
158
|
+
}
|
|
159
|
+
const payload = input.deployPercentage !== undefined && input.deployPercentage < 100
|
|
160
|
+
? { deployInfos: [{ deployPercentage: input.deployPercentage }] }
|
|
161
|
+
: {};
|
|
162
|
+
const res = await call(`${API_ROOT}/v2/${name}:publish`, {
|
|
163
|
+
method: 'POST',
|
|
164
|
+
headers: { 'content-type': 'application/json' },
|
|
165
|
+
body: JSON.stringify(payload),
|
|
166
|
+
});
|
|
167
|
+
if (!res.ok) {
|
|
168
|
+
const detail = await describe(res);
|
|
169
|
+
const hint = res.status === 400 || res.status === 409 || res.status === 412 ? ` ${VISIBILITY_HINT}` : '';
|
|
170
|
+
throw fail(res.status, `publish refused: ${detail}.${hint}`);
|
|
171
|
+
}
|
|
172
|
+
const body = (await res.json().catch(() => ({})));
|
|
173
|
+
return { state: classify(body.state), detail: `publish answered state ${body.state ?? '(none)'}` };
|
|
174
|
+
},
|
|
175
|
+
async status() {
|
|
176
|
+
const body = await readStatus();
|
|
177
|
+
if (body.takenDown === true) {
|
|
178
|
+
return {
|
|
179
|
+
state: 'rejected',
|
|
180
|
+
detail: 'takenDown is true — a policy violation; see the Developer Dashboard',
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
if (body.lastAsyncUploadState === 'IN_PROGRESS') {
|
|
184
|
+
return { state: 'unknown', ingesting: true, detail: 'lastAsyncUploadState IN_PROGRESS' };
|
|
185
|
+
}
|
|
186
|
+
if (body.lastAsyncUploadState === 'FAILED') {
|
|
187
|
+
return {
|
|
188
|
+
state: 'rejected',
|
|
189
|
+
detail: 'lastAsyncUploadState FAILED — the store could not ingest the package',
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
const submitted = body.submittedItemRevisionStatus;
|
|
193
|
+
if (submitted?.state !== undefined) {
|
|
194
|
+
return {
|
|
195
|
+
state: classify(submitted.state),
|
|
196
|
+
version: versionOf(submitted),
|
|
197
|
+
detail: `submittedItemRevisionStatus.state ${submitted.state}`,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
const published = body.publishedItemRevisionStatus;
|
|
201
|
+
if (published?.state !== undefined) {
|
|
202
|
+
return {
|
|
203
|
+
state: classify(published.state),
|
|
204
|
+
version: versionOf(published),
|
|
205
|
+
detail: `publishedItemRevisionStatus.state ${published.state}`,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
return {
|
|
209
|
+
state: 'unknown',
|
|
210
|
+
detail: 'fetchStatus carried no revision status and no upload state in the past 24 h',
|
|
211
|
+
};
|
|
212
|
+
},
|
|
213
|
+
};
|
|
214
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type StoreBackendFactory } from './index.js';
|
|
2
|
+
/** How the publish body carries the certification notes. See the file header. */
|
|
3
|
+
export type PublishNotesFormat = 'json' | 'text';
|
|
4
|
+
export declare const PUBLISH_NOTES_FORMAT: PublishNotesFormat;
|
|
5
|
+
/** The last path segment of a `Location` value, or null when there is none. */
|
|
6
|
+
export declare function operationIdFrom(location: string | null): string | null;
|
|
7
|
+
export declare const createEdgeBackend: StoreBackendFactory;
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
// The Edge Add-ons backend: Update REST API v1.1 (ADR 0077 § Amendment 1).
|
|
2
|
+
//
|
|
3
|
+
// DOCUMENTED against learn.microsoft.com `microsoft-edge/extensions/update/api/`
|
|
4
|
+
// `using-addons-api` and `addons-api-reference` (ms.date 2024-09-19 / 2024-09-05),
|
|
5
|
+
// read 2026-11-13. Nothing here has been sent to Microsoft yet.
|
|
6
|
+
//
|
|
7
|
+
// Every write is a `202 Accepted` whose operation id is in the `Location` header,
|
|
8
|
+
// and the outcome is a SECOND request. This file performs one request per verb and
|
|
9
|
+
// POLLS NOTHING: {@link StoreBackend.operation} reads an operation once and says
|
|
10
|
+
// `in-progress` or `succeeded`, and the shared polling layer (step S5) loops on it.
|
|
11
|
+
//
|
|
12
|
+
// WHAT THE VENDOR PAGES DISAGREE ABOUT, and what this file does about it:
|
|
13
|
+
//
|
|
14
|
+
// - Publish body. The overview page says "Notes for certification, in JSON
|
|
15
|
+
// format" (and shows `{ "notes"="text value" }`, which is not valid JSON); the
|
|
16
|
+
// reference says "in plain text format". Both are the vendor's words, so the
|
|
17
|
+
// format is one constant, {@link PUBLISH_NOTES_FORMAT}. It is `json` because the
|
|
18
|
+
// ADR and the overview's endpoint description say so; if the first real
|
|
19
|
+
// submission answers 400, flip it to `text` and nothing else changes.
|
|
20
|
+
// - The `Location` value. The reference says `Location: {operationID}` and the
|
|
21
|
+
// PowerShell sample keeps the whole header. A real header might be a path or URL
|
|
22
|
+
// ending in the id, so {@link operationIdFrom} keeps the last path segment — an
|
|
23
|
+
// id that is already bare passes through unchanged.
|
|
24
|
+
// - Key lifetime. The pages show an "Expiry" column and state no lifetime. The
|
|
25
|
+
// 72 days in {@link expiredKeyHint} come from Microsoft's announcement as relayed
|
|
26
|
+
// to us and are UNVERIFIED against the docs.
|
|
27
|
+
// - The status codes of the two operation GETs: the reference says 200, the
|
|
28
|
+
// PowerShell sample tests for 202. Any 2xx is read.
|
|
29
|
+
import { readFileSync } from 'node:fs';
|
|
30
|
+
import { redactHeaders, redactSecrets, secretValuesOf, StoreApiError, StoreInReviewError, StoreVersionAlreadyThereError, } from './index.js';
|
|
31
|
+
const STORE = 'edge';
|
|
32
|
+
const API_ROOT = 'https://api.addons.microsoftedge.microsoft.com';
|
|
33
|
+
export const PUBLISH_NOTES_FORMAT = 'json';
|
|
34
|
+
/** An operation id no product has: a GET on it answers 404 for a live key and 401 for a dead one. */
|
|
35
|
+
const UNKNOWN_OPERATION_ID = '00000000-0000-0000-0000-000000000000';
|
|
36
|
+
/** Longest slice of vendor text a message carries. */
|
|
37
|
+
const MAX_VENDOR_TEXT = 400;
|
|
38
|
+
const expiredKeyHint = 'The API key was rejected. API keys expire (Microsoft announced 72 days — unverified in the API docs); ' +
|
|
39
|
+
'renew it in Partner Center → Microsoft Edge → Publish API → "Create API credentials", then update EDGE_ADDONS_API_KEY.';
|
|
40
|
+
/** The last path segment of a `Location` value, or null when there is none. */
|
|
41
|
+
export function operationIdFrom(location) {
|
|
42
|
+
if (location === null)
|
|
43
|
+
return null;
|
|
44
|
+
const segments = location.trim().split('?')[0].split('/').filter(Boolean);
|
|
45
|
+
return segments.length > 0 ? segments[segments.length - 1] : null;
|
|
46
|
+
}
|
|
47
|
+
function errorLines(errors) {
|
|
48
|
+
if (!Array.isArray(errors))
|
|
49
|
+
return [];
|
|
50
|
+
return errors.map((item) => {
|
|
51
|
+
if (typeof item === 'string')
|
|
52
|
+
return item;
|
|
53
|
+
if (typeof item === 'object' && item !== null && typeof item.message === 'string') {
|
|
54
|
+
return item.message;
|
|
55
|
+
}
|
|
56
|
+
return JSON.stringify(item);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
export const createEdgeBackend = (credentials, options = {}) => {
|
|
60
|
+
const productId = credentials['EDGE_ADDONS_PRODUCT_ID'];
|
|
61
|
+
const clientId = credentials['EDGE_ADDONS_CLIENT_ID'];
|
|
62
|
+
const apiKey = credentials['EDGE_ADDONS_API_KEY'];
|
|
63
|
+
const secrets = [...secretValuesOf(STORE, credentials), clientId];
|
|
64
|
+
const base = `${API_ROOT}/v1/products/${encodeURIComponent(productId)}`;
|
|
65
|
+
const clean = (text) => redactSecrets(text, secrets).slice(0, MAX_VENDOR_TEXT);
|
|
66
|
+
/** The operation published last by THIS backend, which `status()` reads. */
|
|
67
|
+
let lastPublish = null;
|
|
68
|
+
async function send(method, url, extra = {}) {
|
|
69
|
+
const headers = {
|
|
70
|
+
Authorization: `ApiKey ${apiKey}`,
|
|
71
|
+
'X-ClientID': clientId,
|
|
72
|
+
};
|
|
73
|
+
if (extra.contentType !== undefined)
|
|
74
|
+
headers['Content-Type'] = extra.contentType;
|
|
75
|
+
options.log?.(`${method} ${url} ${JSON.stringify(redactHeaders(headers))}`);
|
|
76
|
+
const fetchImpl = options.fetchImpl ?? globalThis.fetch;
|
|
77
|
+
let response;
|
|
78
|
+
try {
|
|
79
|
+
response = await fetchImpl(url, { method, headers, body: extra.body });
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
throw new StoreApiError(STORE, undefined, clean(error instanceof Error ? error.message : String(error)));
|
|
83
|
+
}
|
|
84
|
+
options.log?.(` → HTTP ${response.status}`);
|
|
85
|
+
if (response.status >= 200 && response.status < 300)
|
|
86
|
+
return response;
|
|
87
|
+
const text = await response.text().catch(() => '');
|
|
88
|
+
throw new StoreApiError(STORE, response.status, failureDetail(response.status, text));
|
|
89
|
+
}
|
|
90
|
+
function failureDetail(status, text) {
|
|
91
|
+
const body = clean(text.trim());
|
|
92
|
+
if (status === 401)
|
|
93
|
+
return body === '' ? expiredKeyHint : `${expiredKeyHint} Store said: ${body}`;
|
|
94
|
+
if (status === 404) {
|
|
95
|
+
return ('the product id or operation id is unknown, or the product is not yours — check EDGE_ADDONS_PRODUCT_ID.' +
|
|
96
|
+
(body === '' ? '' : ` Store said: ${body}`));
|
|
97
|
+
}
|
|
98
|
+
if (status === 429)
|
|
99
|
+
return 'throttled — too many requests; retry later.';
|
|
100
|
+
return body === '' ? 'the store gave no reason.' : body;
|
|
101
|
+
}
|
|
102
|
+
async function accepted(response, what) {
|
|
103
|
+
const operationId = operationIdFrom(response.headers.get('location'));
|
|
104
|
+
if (operationId === null) {
|
|
105
|
+
throw new StoreApiError(STORE, response.status, `${what} was accepted but the response has no Location header.`);
|
|
106
|
+
}
|
|
107
|
+
return operationId;
|
|
108
|
+
}
|
|
109
|
+
async function upload(input) {
|
|
110
|
+
const zip = new Uint8Array(readFileSync(input.zipPath));
|
|
111
|
+
const response = await send('POST', `${base}/submissions/draft/package`, {
|
|
112
|
+
contentType: 'application/zip',
|
|
113
|
+
body: zip,
|
|
114
|
+
});
|
|
115
|
+
const operationId = await accepted(response, 'the upload');
|
|
116
|
+
return {
|
|
117
|
+
operationId,
|
|
118
|
+
ingested: false,
|
|
119
|
+
detail: `HTTP ${response.status} accepted — upload operation ${operationId} is pending.`,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
async function publish(input) {
|
|
123
|
+
const notes = input.notes ?? '';
|
|
124
|
+
const body = PUBLISH_NOTES_FORMAT === 'json' ? JSON.stringify({ notes }) : notes;
|
|
125
|
+
const response = await send('POST', `${base}/submissions`, {
|
|
126
|
+
contentType: PUBLISH_NOTES_FORMAT === 'json' ? 'application/json' : 'text/plain',
|
|
127
|
+
body,
|
|
128
|
+
});
|
|
129
|
+
const operationId = await accepted(response, 'the publish request');
|
|
130
|
+
lastPublish = { operationId, version: input.version };
|
|
131
|
+
return {
|
|
132
|
+
state: 'unknown',
|
|
133
|
+
operationId,
|
|
134
|
+
detail: `HTTP ${response.status} accepted — publish operation ${operationId} is pending; the submission is not confirmed yet.`,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
async function operation(kind, operationId, version) {
|
|
138
|
+
const path = kind === 'upload' ? 'submissions/draft/package/operations' : 'submissions/operations';
|
|
139
|
+
const response = await send('GET', `${base}/${path}/${encodeURIComponent(operationId)}`);
|
|
140
|
+
const text = await response.text();
|
|
141
|
+
let parsed;
|
|
142
|
+
try {
|
|
143
|
+
parsed = JSON.parse(text);
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
throw new StoreApiError(STORE, response.status, `the ${kind} operation answered something that is not JSON.`);
|
|
147
|
+
}
|
|
148
|
+
const message = clean(parsed.message ?? '');
|
|
149
|
+
switch (parsed.status) {
|
|
150
|
+
case 'InProgress':
|
|
151
|
+
return { state: 'in-progress', detail: `${kind} operation ${operationId} is still running.` };
|
|
152
|
+
case 'Succeeded':
|
|
153
|
+
return { state: 'succeeded', detail: message === '' ? `${kind} operation succeeded.` : message };
|
|
154
|
+
case 'Failed':
|
|
155
|
+
throw failure(parsed, message, version);
|
|
156
|
+
default:
|
|
157
|
+
throw new StoreApiError(STORE, response.status, `the ${kind} operation has an unrecognised status: ${clean(String(parsed.status))}.`);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
function failure(parsed, message, version) {
|
|
161
|
+
const code = parsed.errorCode ?? '';
|
|
162
|
+
if (code === 'NoModulesUpdated')
|
|
163
|
+
return new StoreVersionAlreadyThereError(STORE, version ?? 'in the draft');
|
|
164
|
+
if (code === 'InProgressSubmission') {
|
|
165
|
+
return new StoreInReviewError(STORE, message === '' ? 'a submission is already in progress.' : message);
|
|
166
|
+
}
|
|
167
|
+
const lines = errorLines(parsed.errors).map(clean);
|
|
168
|
+
const detail = [code === '' ? null : `${code}:`, message === '' ? null : message, ...lines]
|
|
169
|
+
.filter((part) => part !== null)
|
|
170
|
+
.join(' ');
|
|
171
|
+
return new StoreApiError(STORE, 200, detail === '' ? 'the operation failed without a reason.' : detail);
|
|
172
|
+
}
|
|
173
|
+
async function status() {
|
|
174
|
+
if (lastPublish === null) {
|
|
175
|
+
return {
|
|
176
|
+
state: 'unknown',
|
|
177
|
+
detail: 'Edge Add-ons has no endpoint that reads a product; only an operation id can be read, and this run has none.',
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
const result = await operation('publish', lastPublish.operationId, lastPublish.version);
|
|
181
|
+
return result.state === 'succeeded'
|
|
182
|
+
? { state: 'in-review', version: lastPublish.version, detail: result.detail }
|
|
183
|
+
: { state: 'unknown', version: lastPublish.version, detail: result.detail };
|
|
184
|
+
}
|
|
185
|
+
async function verifyCredentials() {
|
|
186
|
+
try {
|
|
187
|
+
await send('GET', `${base}/submissions/operations/${UNKNOWN_OPERATION_ID}`);
|
|
188
|
+
}
|
|
189
|
+
catch (error) {
|
|
190
|
+
if (error instanceof StoreApiError && error.httpStatus === 404)
|
|
191
|
+
return;
|
|
192
|
+
throw error;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return { store: STORE, upload, publish, status, operation, verifyCredentials };
|
|
196
|
+
};
|
|
@@ -155,6 +155,8 @@ export interface StoreStatusResult {
|
|
|
155
155
|
readonly state: StoreSubmissionState;
|
|
156
156
|
/** The version the store reports, when it reports one. */
|
|
157
157
|
readonly version?: string;
|
|
158
|
+
/** True while the store is still ingesting an async upload (Chrome `lastAsyncUploadState: IN_PROGRESS`); the shared poll loop keeps waiting on it. */
|
|
159
|
+
readonly ingesting?: boolean;
|
|
158
160
|
/** One line naming the evidence this state rests on — it goes in the report verbatim. */
|
|
159
161
|
readonly detail: string;
|
|
160
162
|
}
|
|
@@ -171,6 +173,19 @@ export interface StoreUploadResult {
|
|
|
171
173
|
}
|
|
172
174
|
export interface StorePublishResult {
|
|
173
175
|
readonly state: StoreSubmissionState;
|
|
176
|
+
/** The store's handle for the pending publish, when it answers asynchronously (Edge's `Location`). */
|
|
177
|
+
readonly operationId?: string;
|
|
178
|
+
readonly detail: string;
|
|
179
|
+
}
|
|
180
|
+
/** Which of a store's two asynchronous steps an operation id belongs to. */
|
|
181
|
+
export type StoreOperationKind = 'upload' | 'publish';
|
|
182
|
+
/**
|
|
183
|
+
* One READ of an asynchronous operation, classified. A backend never polls; the
|
|
184
|
+
* shared layer loops on this. A failed operation is not a state here — it THROWS
|
|
185
|
+
* the matching error class, like every other verb.
|
|
186
|
+
*/
|
|
187
|
+
export interface StoreOperationResult {
|
|
188
|
+
readonly state: 'in-progress' | 'succeeded';
|
|
174
189
|
readonly detail: string;
|
|
175
190
|
}
|
|
176
191
|
export interface StoreUploadInput {
|
|
@@ -199,6 +214,10 @@ export interface StoreBackend {
|
|
|
199
214
|
upload(input: StoreUploadInput): Promise<StoreUploadResult>;
|
|
200
215
|
publish(input: StorePublishInput): Promise<StorePublishResult>;
|
|
201
216
|
status(): Promise<StoreStatusResult>;
|
|
217
|
+
/** Read an asynchronous operation once (Edge: the 202's `Location` id). Absent on a store whose uploads are not operations. */
|
|
218
|
+
operation?(kind: StoreOperationKind, operationId: string, version?: string): Promise<StoreOperationResult>;
|
|
219
|
+
/** A read-only call that proves the credentials work, for `--dry-run`. Resolves when they do, throws otherwise. */
|
|
220
|
+
verifyCredentials?(): Promise<void>;
|
|
202
221
|
}
|
|
203
222
|
/** What every backend's factory takes, beside its credentials. */
|
|
204
223
|
export interface StoreBackendOptions {
|
|
@@ -209,12 +228,11 @@ export interface StoreBackendOptions {
|
|
|
209
228
|
/** Called for each request under `GJSIFY_WEBEXT_DEBUG`. Whatever it prints has been redacted first. */
|
|
210
229
|
readonly log?: (msg: string) => void;
|
|
211
230
|
}
|
|
212
|
-
/** A store's backend factory, registered in {@link STORE_BACKENDS}
|
|
231
|
+
/** A store's backend factory, registered in {@link STORE_BACKENDS}. */
|
|
213
232
|
export type StoreBackendFactory = (credentials: StoreCredentials, options?: StoreBackendOptions) => StoreBackend;
|
|
214
233
|
/**
|
|
215
|
-
* Backend per store
|
|
216
|
-
*
|
|
217
|
-
* `chrome.ts` and `edge.ts` each add their own row; nothing else changes.
|
|
234
|
+
* Backend per store. AMO has none. Registered here rather than as an import side
|
|
235
|
+
* effect of each backend file, so a backend is never silently missing.
|
|
218
236
|
*/
|
|
219
237
|
export declare const STORE_BACKENDS: Partial<Record<StoreId, StoreBackendFactory>>;
|
|
220
238
|
/**
|
|
@@ -24,6 +24,9 @@
|
|
|
24
24
|
// a backend prints about a request goes through {@link redactHeaders} or
|
|
25
25
|
// {@link redactSecrets} first. `publish-readback.ts`'s rule carries over
|
|
26
26
|
// unchanged: never claim what was not established.
|
|
27
|
+
// The import cycle with `edge.ts` is safe: it uses this file's exports only inside functions.
|
|
28
|
+
import { createChromeBackend } from './chrome.js';
|
|
29
|
+
import { createEdgeBackend } from './edge.js';
|
|
27
30
|
export const STORE_IDS = ['chrome', 'edge', 'amo'];
|
|
28
31
|
/**
|
|
29
32
|
* Credentials per store, read from the environment and NEVER from
|
|
@@ -67,8 +70,8 @@ export const STORE_CREDENTIALS = {
|
|
|
67
70
|
],
|
|
68
71
|
};
|
|
69
72
|
export const STORES = {
|
|
70
|
-
chrome: { id: 'chrome', label: 'Chrome Web Store', implemented:
|
|
71
|
-
edge: { id: 'edge', label: 'Edge Add-ons', implemented:
|
|
73
|
+
chrome: { id: 'chrome', label: 'Chrome Web Store', implemented: true, createsListings: false },
|
|
74
|
+
edge: { id: 'edge', label: 'Edge Add-ons', implemented: true, createsListings: false },
|
|
72
75
|
amo: { id: 'amo', label: 'addons.mozilla.org', implemented: false, createsListings: false },
|
|
73
76
|
};
|
|
74
77
|
/** `id` as a {@link StoreId}, or null — the caller owns the message, same contract as `parseWebextTarget`'s callers. */
|
|
@@ -229,11 +232,13 @@ export function isIdempotentSkip(error) {
|
|
|
229
232
|
return error instanceof StoreVersionAlreadyThereError || error instanceof StoreInReviewError;
|
|
230
233
|
}
|
|
231
234
|
/**
|
|
232
|
-
* Backend per store
|
|
233
|
-
*
|
|
234
|
-
* `chrome.ts` and `edge.ts` each add their own row; nothing else changes.
|
|
235
|
+
* Backend per store. AMO has none. Registered here rather than as an import side
|
|
236
|
+
* effect of each backend file, so a backend is never silently missing.
|
|
235
237
|
*/
|
|
236
|
-
export const STORE_BACKENDS = {
|
|
238
|
+
export const STORE_BACKENDS = {
|
|
239
|
+
chrome: createChromeBackend,
|
|
240
|
+
edge: createEdgeBackend,
|
|
241
|
+
};
|
|
237
242
|
/**
|
|
238
243
|
* The backend for a store, with its credentials resolved from `env`.
|
|
239
244
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/cli",
|
|
3
|
-
"version": "0.64.41
|
|
3
|
+
"version": "0.64.41",
|
|
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.41
|
|
146
|
-
"@gjsify/buffer": "0.64.41
|
|
147
|
-
"@gjsify/create-app": "0.64.41
|
|
148
|
-
"@gjsify/node-globals": "0.64.41
|
|
149
|
-
"@gjsify/node-polyfills": "0.64.41
|
|
150
|
-
"@gjsify/npm-registry": "0.64.41
|
|
151
|
-
"@gjsify/resolve-npm": "0.64.41
|
|
152
|
-
"@gjsify/rolldown-plugin-gjsify": "0.64.41
|
|
153
|
-
"@gjsify/vite-plugin-blueprint": "0.64.41
|
|
154
|
-
"@gjsify/rolldown-plugin-pnp": "0.64.41
|
|
155
|
-
"@gjsify/semver": "0.64.41
|
|
156
|
-
"@gjsify/tar": "0.64.41
|
|
157
|
-
"@gjsify/tsc": "0.64.41
|
|
158
|
-
"@gjsify/utils": "0.64.41
|
|
159
|
-
"@gjsify/web-polyfills": "0.64.41
|
|
160
|
-
"@gjsify/workspace": "0.64.41
|
|
145
|
+
"@gjsify/blueprint": "^0.64.41",
|
|
146
|
+
"@gjsify/buffer": "^0.64.41",
|
|
147
|
+
"@gjsify/create-app": "^0.64.41",
|
|
148
|
+
"@gjsify/node-globals": "^0.64.41",
|
|
149
|
+
"@gjsify/node-polyfills": "^0.64.41",
|
|
150
|
+
"@gjsify/npm-registry": "^0.64.41",
|
|
151
|
+
"@gjsify/resolve-npm": "^0.64.41",
|
|
152
|
+
"@gjsify/rolldown-plugin-gjsify": "^0.64.41",
|
|
153
|
+
"@gjsify/vite-plugin-blueprint": "^0.64.41",
|
|
154
|
+
"@gjsify/rolldown-plugin-pnp": "^0.64.41",
|
|
155
|
+
"@gjsify/semver": "^0.64.41",
|
|
156
|
+
"@gjsify/tar": "^0.64.41",
|
|
157
|
+
"@gjsify/tsc": "^0.64.41",
|
|
158
|
+
"@gjsify/utils": "^0.64.41",
|
|
159
|
+
"@gjsify/web-polyfills": "^0.64.41",
|
|
160
|
+
"@gjsify/workspace": "^0.64.41",
|
|
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.41
|
|
169
|
+
"@gjsify/unit": "^0.64.41",
|
|
170
170
|
"@types/yargs": "^17.0.35",
|
|
171
171
|
"typescript": "^6.0.3"
|
|
172
172
|
},
|
|
173
173
|
"peerDependencies": {
|
|
174
|
-
"@gjsify/oxfmt-native": "0.64.41
|
|
175
|
-
"@gjsify/rolldown-native": "0.64.41
|
|
174
|
+
"@gjsify/oxfmt-native": "^0.64.41",
|
|
175
|
+
"@gjsify/rolldown-native": "^0.64.41"
|
|
176
176
|
},
|
|
177
177
|
"peerDependenciesMeta": {
|
|
178
178
|
"@gjsify/oxfmt-native": {
|
|
@@ -191,6 +191,5 @@
|
|
|
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"
|
|
195
|
-
"gitHead": "b42bb6c4b1b1b2344bd3695eb3c9f7c14498c7a0"
|
|
194
|
+
"homepage": "https://github.com/gjsify/gjsify/tree/main/packages/infra/cli#readme"
|
|
196
195
|
}
|