@rathnasgala2/adapter-github-pages 0.1.0 → 0.1.1
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/CHANGELOG.md +39 -0
- package/LICENSE +201 -0
- package/README.md +24 -9
- package/package.json +32 -12
- package/src/artifact-projection.js +12 -5
- package/src/capability.js +8 -3
- package/src/carrier.js +77 -33
- package/src/constants.js +7 -3
- package/src/deployment.js +61 -56
- package/src/errors.js +32 -0
- package/src/index.js +40 -36
- package/src/marker.js +4 -2
- package/src/oidc.js +97 -8
- package/src/public-read.js +4 -2
- package/src/recovery.js +6 -4
- package/src/redaction.js +8 -4
- package/src/request-catalog.js +7 -4
- package/src/rest.js +63 -24
- package/types/artifact-projection.d.ts +48 -0
- package/types/capability.d.ts +23 -0
- package/types/carrier.d.ts +49 -0
- package/types/constants.d.ts +86 -0
- package/types/deployment.d.ts +107 -0
- package/types/errors.d.ts +28 -0
- package/types/index.d.ts +299 -0
- package/types/marker.d.ts +26 -0
- package/types/oidc.d.ts +108 -0
- package/types/public-read.d.ts +33 -0
- package/types/recovery.d.ts +175 -0
- package/types/redaction.d.ts +38 -0
- package/types/request-catalog.d.ts +106 -0
- package/types/rest.d.ts +159 -0
- package/types/store.d.ts +66 -0
- package/src/index.d.ts +0 -246
package/src/public-read.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
* @module
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
import { PagesAdapterError } from './errors.js';
|
|
12
13
|
/** Maximum bytes any single public read will accept. */
|
|
13
14
|
export const MAXIMUM_PUBLIC_BODY_BYTES = 33554432;
|
|
14
15
|
|
|
@@ -53,8 +54,9 @@ export async function readPublic(context, artifactRelativePath) {
|
|
|
53
54
|
}
|
|
54
55
|
const bytes = Buffer.from(await response.arrayBuffer());
|
|
55
56
|
if (bytes.byteLength > MAXIMUM_PUBLIC_BODY_BYTES) {
|
|
56
|
-
throw new
|
|
57
|
-
`PAGES_PUBLIC_BODY_TOO_LARGE
|
|
57
|
+
throw new PagesAdapterError(
|
|
58
|
+
`PAGES_PUBLIC_BODY_TOO_LARGE`,
|
|
59
|
+
`${artifactRelativePath} returned ${bytes.byteLength} bytes`,
|
|
58
60
|
);
|
|
59
61
|
}
|
|
60
62
|
return { status: 200, bytes, etag };
|
package/src/recovery.js
CHANGED
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
* @module
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
|
+
import { PagesAdapterError } from './errors.js';
|
|
28
29
|
import {
|
|
29
30
|
canonicalizeJson,
|
|
30
31
|
domainDigest,
|
|
@@ -79,7 +80,7 @@ const RFC3339 =
|
|
|
79
80
|
* @returns {never} never returns
|
|
80
81
|
*/
|
|
81
82
|
function refuse(code, detail) {
|
|
82
|
-
throw new
|
|
83
|
+
throw new PagesAdapterError(code, detail);
|
|
83
84
|
}
|
|
84
85
|
|
|
85
86
|
/**
|
|
@@ -535,8 +536,9 @@ export function validateReconciliationRecovery(recovery, binding) {
|
|
|
535
536
|
*/
|
|
536
537
|
export function assertRecoveryModePermitted(mode) {
|
|
537
538
|
if (mode !== RECOVERY_MODE) {
|
|
538
|
-
|
|
539
|
-
|
|
539
|
+
refuse(
|
|
540
|
+
'PAGES_RECOVERY_CALL_FORBIDDEN',
|
|
541
|
+
`the recovery-prior call plan is admitted only in ${RECOVERY_MODE} mode, not ${JSON.stringify(mode)}`,
|
|
540
542
|
);
|
|
541
543
|
}
|
|
542
544
|
}
|
|
@@ -658,7 +660,7 @@ export async function resolvePriorAttempt(context, options = {}) {
|
|
|
658
660
|
first.status,
|
|
659
661
|
observed,
|
|
660
662
|
0,
|
|
661
|
-
'the prior attempt reported a status outside the
|
|
663
|
+
'the prior attempt reported a status outside the twelve accepted values; no current create is made',
|
|
662
664
|
);
|
|
663
665
|
}
|
|
664
666
|
if (first.status === SUCCESS_STATUS) {
|
package/src/redaction.js
CHANGED
|
@@ -16,8 +16,11 @@
|
|
|
16
16
|
* @module
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
import { REDACTION_PLACEHOLDER } from '@rathnasgala2/adapter-protocol';
|
|
20
|
+
|
|
21
|
+
import { PagesAdapterError } from './errors.js';
|
|
22
|
+
|
|
23
|
+
export { REDACTION_PLACEHOLDER };
|
|
21
24
|
|
|
22
25
|
/**
|
|
23
26
|
* Replace every occurrence of every secret in one string.
|
|
@@ -81,8 +84,9 @@ export function assertFreeOfSecrets(value, secrets, label) {
|
|
|
81
84
|
continue;
|
|
82
85
|
}
|
|
83
86
|
if (strings.some((candidate) => candidate.includes(secret))) {
|
|
84
|
-
throw new
|
|
85
|
-
`PAGES_SECRET_LEAK_DETECTED
|
|
87
|
+
throw new PagesAdapterError(
|
|
88
|
+
`PAGES_SECRET_LEAK_DETECTED`,
|
|
89
|
+
`a credential's bytes reached ${label}; DEC-097 section 7 forbids it`,
|
|
86
90
|
);
|
|
87
91
|
}
|
|
88
92
|
}
|
package/src/request-catalog.js
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
* @module
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
|
+
import { PagesAdapterError } from './errors.js';
|
|
26
27
|
import { canonicalizeJson } from '@rathnasgala2/adapter-protocol';
|
|
27
28
|
|
|
28
29
|
/** The exact request-template profile this adapter declares. */
|
|
@@ -259,8 +260,9 @@ export function callClassIdBinding(stage, callClass) {
|
|
|
259
260
|
(entry) => entry.stage === stage && entry.callClass === callClass,
|
|
260
261
|
);
|
|
261
262
|
if (row === undefined) {
|
|
262
|
-
throw new
|
|
263
|
-
`PAGES_CALL_NOT_IN_CATALOG
|
|
263
|
+
throw new PagesAdapterError(
|
|
264
|
+
`PAGES_CALL_NOT_IN_CATALOG`,
|
|
265
|
+
`(${JSON.stringify(stage)}, ${JSON.stringify(callClass)}) has no declared callClassBinding row`,
|
|
264
266
|
);
|
|
265
267
|
}
|
|
266
268
|
return row;
|
|
@@ -401,8 +403,9 @@ export function requireTemplate(templates, stage, callClass) {
|
|
|
401
403
|
(entry) => entry.stage === stage && entry.callClass === callClass,
|
|
402
404
|
);
|
|
403
405
|
if (found === undefined) {
|
|
404
|
-
throw new
|
|
405
|
-
`PAGES_CALL_NOT_IN_CATALOG
|
|
406
|
+
throw new PagesAdapterError(
|
|
407
|
+
`PAGES_CALL_NOT_IN_CATALOG`,
|
|
408
|
+
`(${JSON.stringify(stage)}, ${JSON.stringify(callClass)}) is not one of the nine admitted github-pages REST calls`,
|
|
406
409
|
);
|
|
407
410
|
}
|
|
408
411
|
return found;
|
package/src/rest.js
CHANGED
|
@@ -27,7 +27,9 @@
|
|
|
27
27
|
* @module
|
|
28
28
|
*/
|
|
29
29
|
|
|
30
|
+
import { PagesAdapterError } from './errors.js';
|
|
30
31
|
import { NORMAL_MODE, RECOVERY_MODE } from './constants.js';
|
|
32
|
+
import { REDACTION_PLACEHOLDER } from './redaction.js';
|
|
31
33
|
import { callClassIdBinding, requireTemplate } from './request-catalog.js';
|
|
32
34
|
|
|
33
35
|
/** Maximum response body this client will read, in bytes. */
|
|
@@ -96,8 +98,9 @@ export function renderRequestTarget(template, values) {
|
|
|
96
98
|
return template.replace(/\{([A-Za-z]+)\}/gu, (_match, key) => {
|
|
97
99
|
const value = values[key];
|
|
98
100
|
if (value === undefined) {
|
|
99
|
-
throw new
|
|
100
|
-
`PAGES_REQUEST_TARGET_PLACEHOLDER_UNBOUND
|
|
101
|
+
throw new PagesAdapterError(
|
|
102
|
+
`PAGES_REQUEST_TARGET_PLACEHOLDER_UNBOUND`,
|
|
103
|
+
`${JSON.stringify(key)} has no value`,
|
|
101
104
|
);
|
|
102
105
|
}
|
|
103
106
|
return encodeURIComponent(value);
|
|
@@ -129,8 +132,9 @@ export function selectDeploymentId(context, template) {
|
|
|
129
132
|
? 'pagesRecovery.priorPagesBuildVersion'
|
|
130
133
|
: "the intent's pagesBuildVersion";
|
|
131
134
|
if (typeof value !== 'string' || !BUILD_VERSION_PATTERN.test(value)) {
|
|
132
|
-
throw new
|
|
133
|
-
`PAGES_DEPLOYMENT_ID_SOURCE_UNAVAILABLE
|
|
135
|
+
throw new PagesAdapterError(
|
|
136
|
+
`PAGES_DEPLOYMENT_ID_SOURCE_UNAVAILABLE`,
|
|
137
|
+
`${String(template.stage)}/${String(template.callClass)} statically selects ${label}, which is absent or not 40 lowercase hex characters`,
|
|
134
138
|
);
|
|
135
139
|
}
|
|
136
140
|
return value;
|
|
@@ -150,8 +154,9 @@ export function assertModePermitsCall(context, tmpl) {
|
|
|
150
154
|
String(tmpl.callClass),
|
|
151
155
|
).recoveryOnly;
|
|
152
156
|
if (recoveryOnly && mode !== RECOVERY_MODE) {
|
|
153
|
-
throw new
|
|
154
|
-
`PAGES_RECOVERY_CALL_FORBIDDEN
|
|
157
|
+
throw new PagesAdapterError(
|
|
158
|
+
`PAGES_RECOVERY_CALL_FORBIDDEN`,
|
|
159
|
+
`${String(tmpl.stage)}/${String(tmpl.callClass)} is admitted only in ${RECOVERY_MODE} mode; ${JSON.stringify(mode)} forbids every recovery-prior call`,
|
|
155
160
|
);
|
|
156
161
|
}
|
|
157
162
|
}
|
|
@@ -193,26 +198,30 @@ export function buildHeaders(context, tmpl) {
|
|
|
193
198
|
*/
|
|
194
199
|
export function assertRequestMatchesTemplate(tmpl, request) {
|
|
195
200
|
if (request.method !== tmpl.method) {
|
|
196
|
-
throw new
|
|
197
|
-
`PAGES_REQUEST_DISAGREES_WITH_TEMPLATE
|
|
201
|
+
throw new PagesAdapterError(
|
|
202
|
+
`PAGES_REQUEST_DISAGREES_WITH_TEMPLATE`,
|
|
203
|
+
`method ${request.method} is not the cataloged ${String(tmpl.method)}`,
|
|
198
204
|
);
|
|
199
205
|
}
|
|
200
206
|
if (!request.url.startsWith(`${String(tmpl.origin)}/`)) {
|
|
201
|
-
throw new
|
|
202
|
-
`PAGES_REQUEST_DISAGREES_WITH_TEMPLATE
|
|
207
|
+
throw new PagesAdapterError(
|
|
208
|
+
`PAGES_REQUEST_DISAGREES_WITH_TEMPLATE`,
|
|
209
|
+
`the request URL is not on the cataloged origin ${String(tmpl.origin)}`,
|
|
203
210
|
);
|
|
204
211
|
}
|
|
205
212
|
if (new URL(request.url).search !== '') {
|
|
206
|
-
throw new
|
|
207
|
-
'PAGES_REQUEST_DISAGREES_WITH_TEMPLATE
|
|
213
|
+
throw new PagesAdapterError(
|
|
214
|
+
'PAGES_REQUEST_DISAGREES_WITH_TEMPLATE',
|
|
215
|
+
'canonicalQueryProfile is "none", so no query component is representable',
|
|
208
216
|
);
|
|
209
217
|
}
|
|
210
218
|
for (const fixed of /** @type {{name: string, value: string}[]} */ (
|
|
211
219
|
tmpl.fixedHeaders
|
|
212
220
|
)) {
|
|
213
221
|
if (request.headers[fixed.name] !== fixed.value) {
|
|
214
|
-
throw new
|
|
215
|
-
`PAGES_REQUEST_DISAGREES_WITH_TEMPLATE
|
|
222
|
+
throw new PagesAdapterError(
|
|
223
|
+
`PAGES_REQUEST_DISAGREES_WITH_TEMPLATE`,
|
|
224
|
+
`fixed header ${JSON.stringify(fixed.name)} is missing or not the cataloged value`,
|
|
216
225
|
);
|
|
217
226
|
}
|
|
218
227
|
}
|
|
@@ -225,19 +234,46 @@ export function assertRequestMatchesTemplate(tmpl, request) {
|
|
|
225
234
|
const permitted = new Set([...fixedNames, ...credentialNames]);
|
|
226
235
|
for (const name of Object.keys(request.headers)) {
|
|
227
236
|
if (!permitted.has(name)) {
|
|
228
|
-
throw new
|
|
229
|
-
`PAGES_REQUEST_DISAGREES_WITH_TEMPLATE
|
|
237
|
+
throw new PagesAdapterError(
|
|
238
|
+
`PAGES_REQUEST_DISAGREES_WITH_TEMPLATE`,
|
|
239
|
+
`header ${JSON.stringify(name)} is not declared by this template`,
|
|
230
240
|
);
|
|
231
241
|
}
|
|
232
242
|
}
|
|
233
243
|
const expectsBody = tmpl.requestBodyProfile !== 'empty';
|
|
234
244
|
if (expectsBody !== (request.body !== undefined)) {
|
|
235
|
-
throw new
|
|
236
|
-
`PAGES_REQUEST_DISAGREES_WITH_TEMPLATE
|
|
245
|
+
throw new PagesAdapterError(
|
|
246
|
+
`PAGES_REQUEST_DISAGREES_WITH_TEMPLATE`,
|
|
247
|
+
`requestBodyProfile is ${JSON.stringify(String(tmpl.requestBodyProfile))} but the request ${request.body === undefined ? 'has no' : 'has a'} body`,
|
|
237
248
|
);
|
|
238
249
|
}
|
|
239
250
|
}
|
|
240
251
|
|
|
252
|
+
/**
|
|
253
|
+
* The provider's own JSON `message`, for the unexpected-status diagnostic: a
|
|
254
|
+
* bounded, single-line text with every 40+ character token-like run replaced,
|
|
255
|
+
* so a credential echoed by a provider can never reach a message.
|
|
256
|
+
*
|
|
257
|
+
* @param {Buffer} rawBody the raw response body
|
|
258
|
+
* @returns {string} `: provider message: <message>` or the empty string
|
|
259
|
+
*/
|
|
260
|
+
export function providerMessageSuffix(rawBody) {
|
|
261
|
+
try {
|
|
262
|
+
const parsed = JSON.parse(rawBody.toString('utf8'));
|
|
263
|
+
const message = parsed === null ? undefined : parsed.message;
|
|
264
|
+
if (typeof message !== 'string' || message === '') {
|
|
265
|
+
return '';
|
|
266
|
+
}
|
|
267
|
+
const redacted = message
|
|
268
|
+
.replace(/[A-Za-z0-9_\-.~+/=]{40,}/gu, REDACTION_PLACEHOLDER)
|
|
269
|
+
.replace(/\s+/gu, ' ')
|
|
270
|
+
.slice(0, 200);
|
|
271
|
+
return `: provider message: ${redacted}`;
|
|
272
|
+
} catch {
|
|
273
|
+
return '';
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
241
277
|
/**
|
|
242
278
|
* Issue one cataloged provider call.
|
|
243
279
|
*
|
|
@@ -267,8 +303,9 @@ export async function callProvider(context, stage, callClass, options) {
|
|
|
267
303
|
tmpl.maximumRequestTargetBytes
|
|
268
304
|
);
|
|
269
305
|
if (Buffer.byteLength(requestTarget, 'utf8') > maximumTargetBytes) {
|
|
270
|
-
throw new
|
|
271
|
-
`PAGES_REQUEST_TARGET_TOO_LONG
|
|
306
|
+
throw new PagesAdapterError(
|
|
307
|
+
`PAGES_REQUEST_TARGET_TOO_LONG`,
|
|
308
|
+
`${requestTarget.length} characters exceed the cataloged ${maximumTargetBytes}-byte ceiling`,
|
|
272
309
|
);
|
|
273
310
|
}
|
|
274
311
|
|
|
@@ -292,13 +329,15 @@ export async function callProvider(context, stage, callClass, options) {
|
|
|
292
329
|
|
|
293
330
|
const rawBody = Buffer.from(await response.arrayBuffer());
|
|
294
331
|
if (rawBody.byteLength > MAXIMUM_RESPONSE_BODY_BYTES) {
|
|
295
|
-
throw new
|
|
296
|
-
`PAGES_RESPONSE_BODY_TOO_LARGE
|
|
332
|
+
throw new PagesAdapterError(
|
|
333
|
+
`PAGES_RESPONSE_BODY_TOO_LARGE`,
|
|
334
|
+
`${rawBody.byteLength} bytes exceed the ${MAXIMUM_RESPONSE_BODY_BYTES}-byte ceiling`,
|
|
297
335
|
);
|
|
298
336
|
}
|
|
299
337
|
if (!options.acceptStatuses.includes(response.status)) {
|
|
300
|
-
throw new
|
|
301
|
-
`PAGES_PROVIDER_STATUS_UNEXPECTED
|
|
338
|
+
throw new PagesAdapterError(
|
|
339
|
+
`PAGES_PROVIDER_STATUS_UNEXPECTED`,
|
|
340
|
+
`${stage}/${callClass} returned HTTP ${response.status}, expected one of ${options.acceptStatuses.join(', ')}${providerMessageSuffix(rawBody)}`,
|
|
302
341
|
);
|
|
303
342
|
}
|
|
304
343
|
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {Readonly<{path: string, byteLength: string, sha256: string}>} ArtifactEntry
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Project one `{path, bytes}` pair onto its manifest entry.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} entryPath the artifact-relative POSIX path
|
|
8
|
+
* @param {Buffer} bytes the file bytes
|
|
9
|
+
* @returns {ArtifactEntry} the projected entry
|
|
10
|
+
*/
|
|
11
|
+
export function projectEntry(entryPath: string, bytes: Buffer): ArtifactEntry;
|
|
12
|
+
/**
|
|
13
|
+
* Order a projected entry list by UTF-8 path.
|
|
14
|
+
*
|
|
15
|
+
* @param {readonly ArtifactEntry[]} entries the unordered entries
|
|
16
|
+
* @returns {ArtifactEntry[]} a new, path-ordered array
|
|
17
|
+
*/
|
|
18
|
+
export function orderEntries(entries: readonly ArtifactEntry[]): ArtifactEntry[];
|
|
19
|
+
/**
|
|
20
|
+
* Digest an already-projected, marker-excluding entry list.
|
|
21
|
+
*
|
|
22
|
+
* @param {readonly ArtifactEntry[]} entries the projected entries
|
|
23
|
+
* @returns {string} the `GALA-ARTIFACT-V2 ` artifact digest
|
|
24
|
+
*/
|
|
25
|
+
export function digestEntries(entries: readonly ArtifactEntry[]): string;
|
|
26
|
+
/**
|
|
27
|
+
* Compute the artifact digest for a complete in-memory file set, excluding
|
|
28
|
+
* the reserved marker coordinate. Exported so a caller (the workflow's
|
|
29
|
+
* composition root, or a conformance fixture) can pass `stage` a truthful
|
|
30
|
+
* `artifactDigest` without restating the projection.
|
|
31
|
+
*
|
|
32
|
+
* PUB-M5: excluding the marker is this package's own contribution; the
|
|
33
|
+
* digest formula itself delegates to `@rathnasgala2/adapter-protocol`'s
|
|
34
|
+
* `computeArtifactDigest`, the single implementation every S2 destination
|
|
35
|
+
* adapter verifies against.
|
|
36
|
+
*
|
|
37
|
+
* @param {readonly Readonly<{path: string, bytes: Buffer}>[]} files the file set
|
|
38
|
+
* @returns {string} the artifact digest
|
|
39
|
+
*/
|
|
40
|
+
export function computeArtifactDigest(files: readonly Readonly<{
|
|
41
|
+
path: string;
|
|
42
|
+
bytes: Buffer;
|
|
43
|
+
}>[]): string;
|
|
44
|
+
export type ArtifactEntry = Readonly<{
|
|
45
|
+
path: string;
|
|
46
|
+
byteLength: string;
|
|
47
|
+
sha256: string;
|
|
48
|
+
}>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build and validate the declaration for one bound destination.
|
|
3
|
+
*
|
|
4
|
+
* @param {{apiOrigin: string, fileCountCeiling?: number}} context the
|
|
5
|
+
* canonical GitHub REST origin this adapter is bound to
|
|
6
|
+
* @returns {Readonly<Record<string, unknown>>} the validated declaration
|
|
7
|
+
*/
|
|
8
|
+
export function describeCapabilities(context: {
|
|
9
|
+
apiOrigin: string;
|
|
10
|
+
fileCountCeiling?: number;
|
|
11
|
+
}): Readonly<Record<string, unknown>>;
|
|
12
|
+
/**
|
|
13
|
+
* The schema package's own `providerCallClassBinding` digest profile
|
|
14
|
+
* (2.8.1). The inventory is typed as an open record, so the profile is
|
|
15
|
+
* required here once, by name, and its absence is a refusal rather than an
|
|
16
|
+
* `undefined` digest.
|
|
17
|
+
*
|
|
18
|
+
* @type {NonNullable<(typeof ACTIVE_DIGEST_PROFILES)['providerCallClassBinding']>}
|
|
19
|
+
*/
|
|
20
|
+
export const CALL_CLASS_BINDING_PROFILE: NonNullable<(typeof ACTIVE_DIGEST_PROFILES)["providerCallClassBinding"]>;
|
|
21
|
+
/** This adapter's stable identity digest. */
|
|
22
|
+
export const ADAPTER_DIGEST: string;
|
|
23
|
+
import { ACTIVE_DIGEST_PROFILES } from '@rathnasgala2/schemas/digest-profiles';
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Split one POSIX path into the ustar `prefix`/`name` pair, refusing any
|
|
3
|
+
* path that cannot be represented without a GNU/PAX extension record (which
|
|
4
|
+
* would make the carrier writer-dependent rather than deterministic).
|
|
5
|
+
*
|
|
6
|
+
* @param {string} entryPath the artifact-relative POSIX path
|
|
7
|
+
* @returns {{name: string, prefix: string}} the split fields
|
|
8
|
+
*/
|
|
9
|
+
export function splitUstarPath(entryPath: string): {
|
|
10
|
+
name: string;
|
|
11
|
+
prefix: string;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Refuse any member path that would not extract inside the carrier root.
|
|
15
|
+
*
|
|
16
|
+
* The carrier is extracted by the provider, not by this process, so the
|
|
17
|
+
* only place an escaping member can be stopped is here, at the point it is
|
|
18
|
+
* written. Only regular-file (typeflag `0`) and directory (typeflag `5`)
|
|
19
|
+
* entries are ever emitted: this codec has no link or device entry, so a
|
|
20
|
+
* symlink/hardlink member cannot exist to be followed.
|
|
21
|
+
*
|
|
22
|
+
* @param {string} entryPath the artifact-relative POSIX path
|
|
23
|
+
* @returns {string} the accepted path
|
|
24
|
+
*/
|
|
25
|
+
export function requireContainedPath(entryPath: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* Encode a complete file set as deterministic uncompressed ustar
|
|
28
|
+
* carrier bytes (never gzip; see the module comment).
|
|
29
|
+
*
|
|
30
|
+
* @param {readonly CarrierFile[]} files the complete artifact file set,
|
|
31
|
+
* including the reserved public generation marker
|
|
32
|
+
* @returns {Buffer} the carrier bytes
|
|
33
|
+
*/
|
|
34
|
+
export function encodeCarrier(files: readonly CarrierFile[]): Buffer;
|
|
35
|
+
/**
|
|
36
|
+
* Decode carrier bytes back into the exact file set they were built from.
|
|
37
|
+
* The adapter itself never needs this (it only ever writes a carrier); it
|
|
38
|
+
* exists so a caller — the Pages provider, a conformance fixture or a
|
|
39
|
+
* codec golden test — can prove the round trip is lossless.
|
|
40
|
+
*
|
|
41
|
+
* @param {Buffer} carrier the carrier bytes
|
|
42
|
+
* @returns {CarrierFile[]} the decoded file set, in carrier order; directory
|
|
43
|
+
* entries (typeflag `5`) are skipped
|
|
44
|
+
*/
|
|
45
|
+
export function decodeCarrier(carrier: Buffer): CarrierFile[];
|
|
46
|
+
export type CarrierFile = Readonly<{
|
|
47
|
+
path: string;
|
|
48
|
+
bytes: Buffer;
|
|
49
|
+
}>;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This adapter's installed package version, read from its own `package.json`
|
|
3
|
+
* rather than restated by hand: DEC-097 section 3 requires the capability
|
|
4
|
+
* document's `adapter.adapterVersion` to byte-equal the locked package
|
|
5
|
+
* version, and the only value that can never drift from what a lock records
|
|
6
|
+
* for this package is the version the package manifest itself declares.
|
|
7
|
+
*/
|
|
8
|
+
export const ADAPTER_VERSION: string;
|
|
9
|
+
/**
|
|
10
|
+
* The reserved artifact-relative coordinate the public generation marker is
|
|
11
|
+
* staged at (brief section 5). Freeze rejects an artifact route colliding
|
|
12
|
+
* with it; this adapter adds it to the deterministic Pages carrier.
|
|
13
|
+
*/
|
|
14
|
+
export const GENERATION_MARKER_PATH: ".well-known/gala-generation.json";
|
|
15
|
+
/**
|
|
16
|
+
* The exact twelve accepted `GET /repos/{owner}/{repo}/pages/deployments/{id}`
|
|
17
|
+
* status values (brief section 6.2, plus `deployment_queued`, which GitHub's
|
|
18
|
+
* REST reference lists and a real run returned on 2026-10-06). Anything else
|
|
19
|
+
* is unknown and can never release the destination fence.
|
|
20
|
+
*/
|
|
21
|
+
export const PAGES_DEPLOYMENT_STATUSES: readonly string[];
|
|
22
|
+
/**
|
|
23
|
+
* Temporary statuses: polling continues and the fence stays held.
|
|
24
|
+
* `deployment_queued` is the state before `deployment_in_progress`, and
|
|
25
|
+
* `deployment_attempt_error` is temporary because GitHub retries it
|
|
26
|
+
* automatically (brief section 6.2).
|
|
27
|
+
*/
|
|
28
|
+
export const TEMPORARY_STATUSES: readonly string[];
|
|
29
|
+
/** Terminal failure statuses: the deployment can never later succeed. */
|
|
30
|
+
export const TERMINAL_FAILURE_STATUSES: readonly string[];
|
|
31
|
+
/** The single success status. */
|
|
32
|
+
export const SUCCESS_STATUS: "succeed";
|
|
33
|
+
/**
|
|
34
|
+
* The exact poll schedule in seconds: `5, 8, 12, 18, 27, 30`, then `30`
|
|
35
|
+
* repeatedly while the fixed budget permits (brief section 6.2).
|
|
36
|
+
*/
|
|
37
|
+
export const POLL_SCHEDULE_SECONDS: readonly number[];
|
|
38
|
+
/** The repeated tail wait, in seconds, once the schedule is exhausted. */
|
|
39
|
+
export const POLL_TAIL_SECONDS: 30;
|
|
40
|
+
/** Fixed activation-detection polling budget, in seconds. */
|
|
41
|
+
export const POLL_BUDGET_SECONDS: 1500;
|
|
42
|
+
/** Hard ceiling on the deterministic Pages carrier, in bytes. */
|
|
43
|
+
export const MAXIMUM_PAGES_CARRIER_BYTES: 1073741824;
|
|
44
|
+
/** Domain separator: `adapter-capability:2.0.0.capabilityDigest`. */
|
|
45
|
+
export const DOMAIN_ADAPTER_CAPABILITY: "GALA-ADAPTER-CAPABILITY-V2\0";
|
|
46
|
+
/** Domain separator shared with the template's artifact-manifest projection. */
|
|
47
|
+
export const DOMAIN_ARTIFACT: "GALA-ARTIFACT-V2 ";
|
|
48
|
+
/** Domain separator: this adapter's own identity digest. */
|
|
49
|
+
export const DOMAIN_ADAPTER_IDENTITY: "GALA-PAGES-ADAPTER-IDENTITY-V2\0";
|
|
50
|
+
/** Domain separator: the `pagesBuildVersion` projection (brief section 6.2). */
|
|
51
|
+
export const DOMAIN_PAGES_BUILD_VERSION: "GALA-PAGES-BUILD-VERSION-V2\0";
|
|
52
|
+
/** Domain separator: the physical Pages destination mutation key. */
|
|
53
|
+
export const DOMAIN_PAGES_DESTINATION: "GALA-PAGES-DESTINATION-V2\0";
|
|
54
|
+
/** Domain separator: the stage token projection. */
|
|
55
|
+
export const DOMAIN_PAGES_STAGE_TOKEN: "GALA-PAGES-STAGE-TOKEN-V2\0";
|
|
56
|
+
/** Domain separator: the frozen provider request-template catalog. */
|
|
57
|
+
export const DOMAIN_PAGES_REQUEST_CATALOG: "GALA-PAGES-REQUEST-CATALOG-V2\0";
|
|
58
|
+
/** Domain separator: the frozen provider response-profile catalog. */
|
|
59
|
+
export const DOMAIN_PAGES_RESPONSE_CATALOG: "GALA-PAGES-RESPONSE-CATALOG-V2\0";
|
|
60
|
+
/** Domain separator: the provider compatibility evidence record. */
|
|
61
|
+
export const DOMAIN_PAGES_COMPATIBILITY: "GALA-PAGES-COMPATIBILITY-V2\0";
|
|
62
|
+
/** Domain separator: the TLS profile record. */
|
|
63
|
+
export const DOMAIN_PAGES_TLS_PROFILE: "GALA-PAGES-TLS-PROFILE-V2\0";
|
|
64
|
+
/** Domain separator: the credential-egress profile record. */
|
|
65
|
+
export const DOMAIN_PAGES_CREDENTIAL_EGRESS: "GALA-PAGES-CREDENTIAL-EGRESS-V2\0";
|
|
66
|
+
/** Domain separator: an intervening run attempt's no-authority tombstone. */
|
|
67
|
+
export const DOMAIN_PAGES_NO_AUTHORITY_RUN_ATTEMPT: "GALA-PAGES-NO-AUTHORITY-RUN-ATTEMPT-V2\0";
|
|
68
|
+
/** Domain separator: the run-attempt gap proof record. */
|
|
69
|
+
export const DOMAIN_PAGES_RUN_ATTEMPT_GAP_PROOF: "GALA-PAGES-RUN-ATTEMPT-GAP-PROOF-V2\0";
|
|
70
|
+
/** Domain separator: the `pagesReconciliationRecovery` record. */
|
|
71
|
+
export const DOMAIN_PAGES_RECONCILIATION_RECOVERY: "GALA-PAGES-RECONCILIATION-RECOVERY-V2\0";
|
|
72
|
+
/**
|
|
73
|
+
* The two admitted `destinationMutationAuthority.mode` values (DEC-097
|
|
74
|
+
* section 6.2). `normal` forbids every `pages-recovery-*` call.
|
|
75
|
+
*/
|
|
76
|
+
export const NORMAL_MODE: "normal";
|
|
77
|
+
/** The recovery mode that admits the two `pages-recovery-*` call classes. */
|
|
78
|
+
export const RECOVERY_MODE: "pages-reconciliation-recovery";
|
|
79
|
+
/** The two admitted authority modes. */
|
|
80
|
+
export const AUTHORITY_MODES: readonly string[];
|
|
81
|
+
/**
|
|
82
|
+
* Bounded budget, in seconds, for the complete recovery-prior
|
|
83
|
+
* status/poll/cancel/poll sequence. Recovery authorization budgets this in
|
|
84
|
+
* addition to the ordinary fresh carrier/create/current poll sequence.
|
|
85
|
+
*/
|
|
86
|
+
export const RECOVERY_POLL_BUDGET_SECONDS: 300;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `pagesBuildVersion`: the workflow run's head commit SHA (`GITHUB_SHA`,
|
|
3
|
+
* the OIDC `sha` claim). GitHub validates `pages_build_version` as a commit
|
|
4
|
+
* of the repository (measured on 2026-10-04: any other 40-hex value, such as
|
|
5
|
+
* a synthetic hash, answers 404), so a synthetic derivation can never deploy.
|
|
6
|
+
* `pagesDeploymentId` must equal it exactly.
|
|
7
|
+
*
|
|
8
|
+
* @param {{headSha?: string | undefined}} projection the run's head commit
|
|
9
|
+
* @returns {string} the 40-character lowercase hexadecimal build version
|
|
10
|
+
*/
|
|
11
|
+
export function derivePagesBuildVersion(projection: {
|
|
12
|
+
headSha?: string | undefined;
|
|
13
|
+
}): string;
|
|
14
|
+
/**
|
|
15
|
+
* Refuse a create-body text that is not the exact compact JCS of the three
|
|
16
|
+
* admitted members. Exported so a fixture can prove a duplicated, extra,
|
|
17
|
+
* missing or reordered member is refused without reaching a provider.
|
|
18
|
+
*
|
|
19
|
+
* @param {string} bodyText the serialized request entity
|
|
20
|
+
* @returns {void}
|
|
21
|
+
*/
|
|
22
|
+
export function assertCanonicalCreateBody(bodyText: string): void;
|
|
23
|
+
/**
|
|
24
|
+
* Build the exact `gala-pages-create-deployment-jcs-v2` request entity.
|
|
25
|
+
*
|
|
26
|
+
* @param {{
|
|
27
|
+
* pagesArtifactId: string | number,
|
|
28
|
+
* pagesBuildVersion: string,
|
|
29
|
+
* oidcToken: string,
|
|
30
|
+
* githubToken: string
|
|
31
|
+
* }} input the body inputs
|
|
32
|
+
* @returns {Readonly<{bodyText: string, byteCount: number, artifactId: number}>}
|
|
33
|
+
* the canonical body text and its non-secret measurements
|
|
34
|
+
*/
|
|
35
|
+
export function buildCreateDeploymentBody(input: {
|
|
36
|
+
pagesArtifactId: string | number;
|
|
37
|
+
pagesBuildVersion: string;
|
|
38
|
+
oidcToken: string;
|
|
39
|
+
githubToken: string;
|
|
40
|
+
}): Readonly<{
|
|
41
|
+
bodyText: string;
|
|
42
|
+
byteCount: number;
|
|
43
|
+
artifactId: number;
|
|
44
|
+
}>;
|
|
45
|
+
/**
|
|
46
|
+
* Issue the single create-deployment call and return the closed provider
|
|
47
|
+
* identity projection. `createResponseStatusUrl` is carried only on the
|
|
48
|
+
* `createResponseObserved: true` branch and only when it equals the exact
|
|
49
|
+
* expected shape; it is evidence, never a URL this adapter follows.
|
|
50
|
+
*
|
|
51
|
+
* The OIDC token is verified against its expected bindings and then placed
|
|
52
|
+
* only in the body. Neither credential can reach the returned evidence: the
|
|
53
|
+
* whole projection is scanned before it is returned, and every failure
|
|
54
|
+
* message is scrubbed.
|
|
55
|
+
*
|
|
56
|
+
* @param {import('./rest.js').RestContext} context the bound REST context
|
|
57
|
+
* @param {{
|
|
58
|
+
* pagesArtifactId: string | number,
|
|
59
|
+
* pagesBuildVersion: string,
|
|
60
|
+
* oidcToken: string,
|
|
61
|
+
* oidcExpectation: import('./oidc.js').PagesOidcExpectation,
|
|
62
|
+
* stage?: string
|
|
63
|
+
* }} input the create inputs
|
|
64
|
+
* @returns {Promise<Readonly<Record<string, unknown>>>} the provider identity
|
|
65
|
+
*/
|
|
66
|
+
export function createDeployment(context: import("./rest.js").RestContext, input: {
|
|
67
|
+
pagesArtifactId: string | number;
|
|
68
|
+
pagesBuildVersion: string;
|
|
69
|
+
oidcToken: string;
|
|
70
|
+
oidcExpectation: import("./oidc.js").PagesOidcExpectation;
|
|
71
|
+
stage?: string;
|
|
72
|
+
}): Promise<Readonly<Record<string, unknown>>>;
|
|
73
|
+
/**
|
|
74
|
+
* Poll one deployment to a terminal state under the fixed budget, waiting
|
|
75
|
+
* exactly `5, 8, 12, 18, 27, 30` seconds and then repeating `30`.
|
|
76
|
+
*
|
|
77
|
+
* @param {import('./rest.js').RestContext} context the bound REST context
|
|
78
|
+
* @param {string} pagesDeploymentId the deployment identity, used only to
|
|
79
|
+
* name the deployment in diagnostics; the request target's segment is
|
|
80
|
+
* selected statically by the call class from the bound context
|
|
81
|
+
* @param {{
|
|
82
|
+
* sleep?: (seconds: number) => Promise<void>,
|
|
83
|
+
* budgetSeconds?: number,
|
|
84
|
+
* stage?: string
|
|
85
|
+
* }} options polling controls; `sleep` is injectable so a test proves the
|
|
86
|
+
* schedule without spending it in wall-clock time
|
|
87
|
+
* @returns {Promise<{
|
|
88
|
+
* status: string,
|
|
89
|
+
* succeeded: boolean,
|
|
90
|
+
* observedStatuses: string[],
|
|
91
|
+
* waitedSeconds: number[]
|
|
92
|
+
* }>} the terminal observation
|
|
93
|
+
*/
|
|
94
|
+
export function pollDeployment(context: import("./rest.js").RestContext, pagesDeploymentId: string, options: {
|
|
95
|
+
sleep?: (seconds: number) => Promise<void>;
|
|
96
|
+
budgetSeconds?: number;
|
|
97
|
+
stage?: string;
|
|
98
|
+
}): Promise<{
|
|
99
|
+
status: string;
|
|
100
|
+
succeeded: boolean;
|
|
101
|
+
observedStatuses: string[];
|
|
102
|
+
waitedSeconds: number[];
|
|
103
|
+
}>;
|
|
104
|
+
/** The exact three member names of the create request entity, in JCS order. */
|
|
105
|
+
export const CREATE_BODY_MEMBERS: readonly string[];
|
|
106
|
+
/** The inclusive upper bound on `artifact_id` (exact JSON/JCS identity). */
|
|
107
|
+
export const MAXIMUM_ARTIFACT_ID: 9007199254740991;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This adapter's one typed failure class (PUB-H6). Every refusal this
|
|
3
|
+
* package raises -- OIDC verification, the Pages REST catalog, the request
|
|
4
|
+
* catalog, carrier construction, capability declaration, recovery --
|
|
5
|
+
* throws `PagesAdapterError`, which carries a stable `code` as a real
|
|
6
|
+
* property so a consumer can discriminate
|
|
7
|
+
* `error.code === 'PAGES_OIDC_SUBJECT_MISMATCH'` without parsing
|
|
8
|
+
* `.message`. `.message` is `${code}: ${detail}`, so a log line or the
|
|
9
|
+
* credential-hygiene scan still matches a code inside the message.
|
|
10
|
+
*
|
|
11
|
+
* The closed code vocabulary this class carries is documented in
|
|
12
|
+
* `README.md`.
|
|
13
|
+
*
|
|
14
|
+
* @module
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* A typed failure this adapter raises, carrying a stable `code`
|
|
18
|
+
* alongside the ordinary `Error` message.
|
|
19
|
+
*/
|
|
20
|
+
export class PagesAdapterError extends Error {
|
|
21
|
+
/**
|
|
22
|
+
* @param {string} code stable, machine-readable failure code
|
|
23
|
+
* @param {string} detail human-readable detail (never a token byte)
|
|
24
|
+
*/
|
|
25
|
+
constructor(code: string, detail: string);
|
|
26
|
+
/** @type {string} */
|
|
27
|
+
code: string;
|
|
28
|
+
}
|