@rathnasgala2/adapter-github-pages 0.1.0 → 0.1.2
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 +87 -0
- package/LICENSE +201 -0
- package/README.md +68 -10
- package/package.json +32 -12
- package/src/artifact-projection.js +12 -5
- package/src/capability.js +14 -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 +592 -66
- package/src/marker.js +4 -2
- package/src/oidc.js +97 -8
- package/src/public-read.js +107 -10
- 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/src/store.js +2 -1
- 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 +316 -0
- package/types/marker.d.ts +26 -0
- package/types/oidc.d.ts +108 -0
- package/types/public-read.d.ts +37 -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/types/oidc.d.ts
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decode one canonical unpadded base64url segment.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} segment the segment text
|
|
5
|
+
* @param {string} label the segment name, for the diagnostic
|
|
6
|
+
* @returns {Buffer} the decoded bytes
|
|
7
|
+
*/
|
|
8
|
+
export function decodeCanonicalBase64Url(segment: string, label: string): Buffer;
|
|
9
|
+
/**
|
|
10
|
+
* Parse one JSON object, refusing any duplicate member name at any depth.
|
|
11
|
+
*
|
|
12
|
+
* `JSON.parse` silently keeps the last of two identical member names, which
|
|
13
|
+
* would let a crafted token present one `sub` to a scanner and another to a
|
|
14
|
+
* parser. This scanner rejects that before the value is used.
|
|
15
|
+
*
|
|
16
|
+
* @param {string} text the JSON text
|
|
17
|
+
* @param {string} label the value's name, for the diagnostic
|
|
18
|
+
* @returns {Record<string, unknown>} the parsed object
|
|
19
|
+
*/
|
|
20
|
+
export function parseDuplicateKeyFreeJsonObject(text: string, label: string): Record<string, unknown>;
|
|
21
|
+
/**
|
|
22
|
+
* The two GitHub-supported default-environment subject forms, recomputed
|
|
23
|
+
* from the separately verified identity claims.
|
|
24
|
+
*
|
|
25
|
+
* @param {{
|
|
26
|
+
* owner: string,
|
|
27
|
+
* repository: string,
|
|
28
|
+
* repositoryId: string,
|
|
29
|
+
* repositoryOwnerId: string
|
|
30
|
+
* }} identity the verified identity claims
|
|
31
|
+
* @returns {{name: string, id: string}} the two admitted subject forms
|
|
32
|
+
*/
|
|
33
|
+
export function buildSubjectForms(identity: {
|
|
34
|
+
owner: string;
|
|
35
|
+
repository: string;
|
|
36
|
+
repositoryId: string;
|
|
37
|
+
repositoryOwnerId: string;
|
|
38
|
+
}): {
|
|
39
|
+
name: string;
|
|
40
|
+
id: string;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Verify one caller-supplied Pages OIDC JWT against its expected bindings.
|
|
44
|
+
*
|
|
45
|
+
* Performs no network call and no signature verification; see this module's
|
|
46
|
+
* header for why that is correct and where the real trust boundary is.
|
|
47
|
+
*
|
|
48
|
+
* @param {unknown} token the caller-supplied compact JWT
|
|
49
|
+
* @param {PagesOidcExpectation} expected the expected bindings
|
|
50
|
+
* @param {() => number} [now] the clock source used for the `exp`/`iat`/`nbf`
|
|
51
|
+
* checks, in epoch milliseconds. Defaults to `Date.now`; a test supplies a
|
|
52
|
+
* fixed function to check the {@link PAGES_OIDC_CLOCK_SKEW_SECONDS}
|
|
53
|
+
* boundary deterministically instead of racing the real clock.
|
|
54
|
+
* @returns {Readonly<{
|
|
55
|
+
* profile: string,
|
|
56
|
+
* subjectForm: 'name' | 'identifier',
|
|
57
|
+
* issuerSignatureVerified: false,
|
|
58
|
+
* tokenByteCount: number
|
|
59
|
+
* }>} non-secret evidence about the accepted token
|
|
60
|
+
*/
|
|
61
|
+
export function verifyPagesOidcToken(token: unknown, expected: PagesOidcExpectation, now?: () => number): Readonly<{
|
|
62
|
+
profile: string;
|
|
63
|
+
subjectForm: "name" | "identifier";
|
|
64
|
+
issuerSignatureVerified: false;
|
|
65
|
+
tokenByteCount: number;
|
|
66
|
+
}>;
|
|
67
|
+
/**
|
|
68
|
+
* Validate one caller-supplied expectation record before it is used.
|
|
69
|
+
*
|
|
70
|
+
* @param {unknown} expected the caller-supplied expectation
|
|
71
|
+
* @returns {PagesOidcExpectation} the validated expectation
|
|
72
|
+
*/
|
|
73
|
+
export function requireOidcExpectation(expected: unknown): PagesOidcExpectation;
|
|
74
|
+
/** The closed credential-source profile this module implements. */
|
|
75
|
+
export const PAGES_OIDC_PROFILE: "gala-pages-oidc-v2";
|
|
76
|
+
/** The exact required `iss` claim. */
|
|
77
|
+
export const PAGES_OIDC_ISSUER: "https://token.actions.githubusercontent.com";
|
|
78
|
+
/** The exact required `environment` claim and subject environment segment. */
|
|
79
|
+
export const PAGES_OIDC_ENVIRONMENT: "github-pages";
|
|
80
|
+
/** Inclusive byte bounds on the compact JWT (DEC-097 section 7). */
|
|
81
|
+
export const PAGES_OIDC_MINIMUM_BYTES: 1;
|
|
82
|
+
/**
|
|
83
|
+
* Inclusive upper byte bound on the compact JWT: a memory bound with headroom,
|
|
84
|
+
* not an expected size. GitHub controls the actual token size.
|
|
85
|
+
*/
|
|
86
|
+
export const PAGES_OIDC_MAXIMUM_BYTES: 32768;
|
|
87
|
+
/**
|
|
88
|
+
* PUB-L5: clock-skew tolerance, in seconds, for the belt-and-braces
|
|
89
|
+
* `exp`/`iat`/`nbf` checks below. GitHub Pages is the relying party that
|
|
90
|
+
* authoritatively rejects a stale or not-yet-valid token (this module's own
|
|
91
|
+
* header explains why that is the real trust boundary); this check exists
|
|
92
|
+
* only to fail closed earlier, with a clearer diagnostic, when it costs
|
|
93
|
+
* nothing to do so. 300 seconds is generous enough to absorb ordinary
|
|
94
|
+
* runner/host clock drift without weakening the check.
|
|
95
|
+
*/
|
|
96
|
+
export const PAGES_OIDC_CLOCK_SKEW_SECONDS: 300;
|
|
97
|
+
export type PagesOidcExpectation = Readonly<{
|
|
98
|
+
owner: string;
|
|
99
|
+
repository: string;
|
|
100
|
+
repositoryId: string | number;
|
|
101
|
+
repositoryOwnerId: string | number;
|
|
102
|
+
ref: string;
|
|
103
|
+
sha: string;
|
|
104
|
+
runId: string | number;
|
|
105
|
+
runAttempt: string | number;
|
|
106
|
+
jobWorkflowRef: string;
|
|
107
|
+
jobWorkflowSha: string;
|
|
108
|
+
}>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {Readonly<{
|
|
3
|
+
* publicBaseUrl: string,
|
|
4
|
+
* fetch?: typeof globalThis.fetch
|
|
5
|
+
* }>} PublicContext
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Join the canonical base path to an artifact-relative route exactly once.
|
|
9
|
+
*
|
|
10
|
+
* @param {string} publicBaseUrl the destination's public base URL
|
|
11
|
+
* @param {string} artifactRelativePath the artifact-relative POSIX path
|
|
12
|
+
* @returns {string} the absolute public URL
|
|
13
|
+
*/
|
|
14
|
+
export function publicUrlFor(publicBaseUrl: string, artifactRelativePath: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Read one public route.
|
|
17
|
+
*
|
|
18
|
+
* @param {PublicContext} context the public-origin context
|
|
19
|
+
* @param {string} artifactRelativePath the artifact-relative POSIX path
|
|
20
|
+
* @returns {Promise<{status: number | 'redirect', bytes: Buffer | null, etag: string | null, toHost?: string | null, location?: string | null}>}
|
|
21
|
+
* the bounded observation; `bytes` is `null` for any non-`200` status. A
|
|
22
|
+
* `'redirect'` status carries the `toHost` and absolute `location` the
|
|
23
|
+
* origin named (`null` when it named none that could be read).
|
|
24
|
+
*/
|
|
25
|
+
export function readPublic(context: PublicContext, artifactRelativePath: string): Promise<{
|
|
26
|
+
status: number | "redirect";
|
|
27
|
+
bytes: Buffer | null;
|
|
28
|
+
etag: string | null;
|
|
29
|
+
toHost?: string | null;
|
|
30
|
+
location?: string | null;
|
|
31
|
+
}>;
|
|
32
|
+
/** Maximum bytes any single public read will accept. */
|
|
33
|
+
export const MAXIMUM_PUBLIC_BODY_BYTES: 33554432;
|
|
34
|
+
export type PublicContext = Readonly<{
|
|
35
|
+
publicBaseUrl: string;
|
|
36
|
+
fetch?: typeof globalThis.fetch;
|
|
37
|
+
}>;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compute one intervening attempt's immutable tombstone digest:
|
|
3
|
+
* `SHA256(UTF8("GALA-PAGES-NO-AUTHORITY-RUN-ATTEMPT-V2\0") ||
|
|
4
|
+
* JCS({repositoryId,runId,runAttempt,authorityState}))`.
|
|
5
|
+
*
|
|
6
|
+
* @param {{
|
|
7
|
+
* repositoryId: string | number,
|
|
8
|
+
* runId: string | number,
|
|
9
|
+
* runAttempt: number
|
|
10
|
+
* }} input the tombstone coordinates
|
|
11
|
+
* @returns {string} the `decisionDigest`
|
|
12
|
+
*/
|
|
13
|
+
export function computeInterveningAttemptDigest(input: {
|
|
14
|
+
repositoryId: string | number;
|
|
15
|
+
runId: string | number;
|
|
16
|
+
runAttempt: number;
|
|
17
|
+
}): string;
|
|
18
|
+
/**
|
|
19
|
+
* Build the exact ordered tombstone set for one attempt fence: every integer
|
|
20
|
+
* strictly between the prior and claiming attempts, sorted by `runAttempt`.
|
|
21
|
+
* An adjacent claim carries the exact empty array.
|
|
22
|
+
*
|
|
23
|
+
* @param {{
|
|
24
|
+
* repositoryId: string | number,
|
|
25
|
+
* runId: string | number,
|
|
26
|
+
* priorRunAttempt: number,
|
|
27
|
+
* claimingRunAttempt: number
|
|
28
|
+
* }} input the fence coordinates
|
|
29
|
+
* @returns {readonly Readonly<{
|
|
30
|
+
* runAttempt: number,
|
|
31
|
+
* authorityState: string,
|
|
32
|
+
* decisionDigest: string
|
|
33
|
+
* }>[]} the ordered tombstone rows
|
|
34
|
+
*/
|
|
35
|
+
export function buildInterveningAttempts(input: {
|
|
36
|
+
repositoryId: string | number;
|
|
37
|
+
runId: string | number;
|
|
38
|
+
priorRunAttempt: number;
|
|
39
|
+
claimingRunAttempt: number;
|
|
40
|
+
}): readonly Readonly<{
|
|
41
|
+
runAttempt: number;
|
|
42
|
+
authorityState: string;
|
|
43
|
+
decisionDigest: string;
|
|
44
|
+
}>[];
|
|
45
|
+
/**
|
|
46
|
+
* Compute a gap proof's `proofDigest` over the record with `proofDigest`
|
|
47
|
+
* omitted.
|
|
48
|
+
*
|
|
49
|
+
* @param {Readonly<Record<string, unknown>>} proof the gap proof record
|
|
50
|
+
* @returns {string} the `proofDigest`
|
|
51
|
+
*/
|
|
52
|
+
export function computeGapProofDigest(proof: Readonly<Record<string, unknown>>): string;
|
|
53
|
+
/**
|
|
54
|
+
* Build the complete `pagesRunAttemptGapProof` the authorization
|
|
55
|
+
* transaction must have produced for one fence.
|
|
56
|
+
*
|
|
57
|
+
* @param {{
|
|
58
|
+
* repositoryId: string | number,
|
|
59
|
+
* runId: string | number,
|
|
60
|
+
* priorRunAttempt: number,
|
|
61
|
+
* claimingRunAttempt: number
|
|
62
|
+
* }} input the fence coordinates
|
|
63
|
+
* @returns {Readonly<Record<string, unknown>>} the complete gap proof
|
|
64
|
+
*/
|
|
65
|
+
export function buildRunAttemptGapProof(input: {
|
|
66
|
+
repositoryId: string | number;
|
|
67
|
+
runId: string | number;
|
|
68
|
+
priorRunAttempt: number;
|
|
69
|
+
claimingRunAttempt: number;
|
|
70
|
+
}): Readonly<Record<string, unknown>>;
|
|
71
|
+
/**
|
|
72
|
+
* Validate one server-supplied gap proof: exact member set, bounded
|
|
73
|
+
* coordinates, set equality of the intervening attempts with every integer
|
|
74
|
+
* strictly between the two coordinates, `runAttempt` ordering, every
|
|
75
|
+
* tombstone digest, and the `proofDigest` itself.
|
|
76
|
+
*
|
|
77
|
+
* @param {unknown} proof the candidate gap proof
|
|
78
|
+
* @param {{repositoryId: string | number}} binding the repository identity
|
|
79
|
+
* the tombstone digests are bound to
|
|
80
|
+
* @returns {Readonly<Record<string, unknown>>} the validated proof
|
|
81
|
+
*/
|
|
82
|
+
export function validateRunAttemptGapProof(proof: unknown, binding: {
|
|
83
|
+
repositoryId: string | number;
|
|
84
|
+
}): Readonly<Record<string, unknown>>;
|
|
85
|
+
/**
|
|
86
|
+
* Compute a recovery record's `recoveryDigest` over the record with
|
|
87
|
+
* `recoveryDigest` omitted.
|
|
88
|
+
*
|
|
89
|
+
* @param {Readonly<Record<string, unknown>>} recovery the recovery record
|
|
90
|
+
* @returns {string} the `recoveryDigest`
|
|
91
|
+
*/
|
|
92
|
+
export function computeRecoveryDigest(recovery: Readonly<Record<string, unknown>>): string;
|
|
93
|
+
/**
|
|
94
|
+
* Seal one otherwise complete recovery record by computing its digest. Only
|
|
95
|
+
* a fixture uses this: the real record is server-minted.
|
|
96
|
+
*
|
|
97
|
+
* @param {Readonly<Record<string, unknown>>} withoutDigest the record with no
|
|
98
|
+
* `recoveryDigest`
|
|
99
|
+
* @returns {Readonly<Record<string, unknown>>} the sealed record
|
|
100
|
+
*/
|
|
101
|
+
export function sealRecoveryRecord(withoutDigest: Readonly<Record<string, unknown>>): Readonly<Record<string, unknown>>;
|
|
102
|
+
/**
|
|
103
|
+
* Validate one server-supplied `pagesReconciliationRecovery` record. This
|
|
104
|
+
* adapter never mints one; a malformed record is refused before any provider
|
|
105
|
+
* call.
|
|
106
|
+
*
|
|
107
|
+
* @param {unknown} recovery the candidate record
|
|
108
|
+
* @param {{repositoryId: string | number}} binding the repository identity
|
|
109
|
+
* @returns {Readonly<Record<string, unknown>>} the validated record
|
|
110
|
+
*/
|
|
111
|
+
export function validateReconciliationRecovery(recovery: unknown, binding: {
|
|
112
|
+
repositoryId: string | number;
|
|
113
|
+
}): Readonly<Record<string, unknown>>;
|
|
114
|
+
/**
|
|
115
|
+
* Refuse a recovery-prior call outside recovery mode. `normal` forbids every
|
|
116
|
+
* recovery-prior call and does not reserve that branch's budget.
|
|
117
|
+
*
|
|
118
|
+
* @param {string} mode the authority mode
|
|
119
|
+
* @returns {void}
|
|
120
|
+
*/
|
|
121
|
+
export function assertRecoveryModePermitted(mode: string): void;
|
|
122
|
+
/**
|
|
123
|
+
* Resolve the prior attempt before any current carrier is uploaded or
|
|
124
|
+
* created (DEC-097 section 6.2).
|
|
125
|
+
*
|
|
126
|
+
* - terminal `succeed`: the same operation's proposed generation was already
|
|
127
|
+
* selected. No new create is performed and the current fence terminalizes
|
|
128
|
+
* as `terminal-candidate`.
|
|
129
|
+
* - a terminal non-success: immutable, so the prior create can never
|
|
130
|
+
* activate. The exact prior status is recorded and the caller proceeds
|
|
131
|
+
* with the fresh current carrier/create.
|
|
132
|
+
* - a temporary status or 404: exactly one cataloged cancel of that prior
|
|
133
|
+
* build version, then bounded polling.
|
|
134
|
+
* - still-temporary, 404, malformed, unknown or nonterminal at the recovery
|
|
135
|
+
* deadline: truthful evidence, no current create, authority returns to
|
|
136
|
+
* `reconciliation-required`.
|
|
137
|
+
*
|
|
138
|
+
* @param {import('./rest.js').RestContext} context a REST context already
|
|
139
|
+
* bound to `pages-reconciliation-recovery` mode and the prior build version
|
|
140
|
+
* @param {{
|
|
141
|
+
* sleep?: (seconds: number) => Promise<void>,
|
|
142
|
+
* budgetSeconds?: number
|
|
143
|
+
* }} [options] bounded polling controls
|
|
144
|
+
* @returns {Promise<PriorAttemptObservation>} the truthful observation
|
|
145
|
+
*/
|
|
146
|
+
export function resolvePriorAttempt(context: import("./rest.js").RestContext, options?: {
|
|
147
|
+
sleep?: (seconds: number) => Promise<void>;
|
|
148
|
+
budgetSeconds?: number;
|
|
149
|
+
}): Promise<PriorAttemptObservation>;
|
|
150
|
+
/** The `profile` const of a `pagesReconciliationRecovery` record. */
|
|
151
|
+
export const RECOVERY_RECORD_PROFILE: "gala-pages-reconciliation-recovery-v2";
|
|
152
|
+
/** The `profile` const of a `pagesRunAttemptGapProof` record. */
|
|
153
|
+
export const GAP_PROOF_PROFILE: "gala-pages-run-attempt-gap-proof-v2";
|
|
154
|
+
/** The single admitted `authorityState` of an intervening run attempt. */
|
|
155
|
+
export const NO_AUTHORITY_STATE: "closed-no-destination-authority";
|
|
156
|
+
/** The inclusive bounds DEC-097 places on the two fence coordinates. */
|
|
157
|
+
export const PRIOR_RUN_ATTEMPT_BOUNDS: Readonly<{
|
|
158
|
+
minimum: 1;
|
|
159
|
+
maximum: 50;
|
|
160
|
+
}>;
|
|
161
|
+
/** The inclusive bounds on a claiming run attempt. */
|
|
162
|
+
export const CLAIMING_RUN_ATTEMPT_BOUNDS: Readonly<{
|
|
163
|
+
minimum: 2;
|
|
164
|
+
maximum: 51;
|
|
165
|
+
}>;
|
|
166
|
+
export type PriorAttemptObservation = Readonly<{
|
|
167
|
+
profile: "gala-pages-recovery-observation-v2";
|
|
168
|
+
priorPagesBuildVersion: string;
|
|
169
|
+
outcome: "prior-succeeded" | "prior-terminal-failure" | "reconciliation-required";
|
|
170
|
+
authorityState: "terminal-candidate" | "proceed-with-fresh-create" | "reconciliation-required";
|
|
171
|
+
priorStatus: string | null;
|
|
172
|
+
observedStatuses: readonly string[];
|
|
173
|
+
cancelCallCount: number;
|
|
174
|
+
reason: string;
|
|
175
|
+
}>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Replace every occurrence of every secret in one string.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} text the text to scrub
|
|
5
|
+
* @param {readonly (string | undefined)[]} secrets the secret byte strings
|
|
6
|
+
* @returns {string} the scrubbed text
|
|
7
|
+
*/
|
|
8
|
+
export function scrubSecrets(text: string, secrets: readonly (string | undefined)[]): string;
|
|
9
|
+
/**
|
|
10
|
+
* Collect every string that appears anywhere in a JSON-like value, including
|
|
11
|
+
* object keys, so a secret cannot hide in a nested evidence member.
|
|
12
|
+
*
|
|
13
|
+
* @param {unknown} value the value to walk
|
|
14
|
+
* @param {string[]} [into] the accumulator
|
|
15
|
+
* @returns {string[]} every string found
|
|
16
|
+
*/
|
|
17
|
+
export function collectStrings(value: unknown, into?: string[]): string[];
|
|
18
|
+
/**
|
|
19
|
+
* Refuse a value that carries any secret's bytes anywhere inside it.
|
|
20
|
+
*
|
|
21
|
+
* @param {unknown} value the value to check (evidence, headers, a body text)
|
|
22
|
+
* @param {readonly (string | undefined)[]} secrets the secret byte strings
|
|
23
|
+
* @param {string} label where the value is bound for, for the diagnostic
|
|
24
|
+
* @returns {void}
|
|
25
|
+
* @throws {Error} `PAGES_SECRET_LEAK_DETECTED` when a secret is present
|
|
26
|
+
*/
|
|
27
|
+
export function assertFreeOfSecrets(value: unknown, secrets: readonly (string | undefined)[], label: string): void;
|
|
28
|
+
/**
|
|
29
|
+
* Run one function with every thrown message scrubbed of every secret.
|
|
30
|
+
*
|
|
31
|
+
* @template T
|
|
32
|
+
* @param {readonly (string | undefined)[]} secrets the secret byte strings
|
|
33
|
+
* @param {() => Promise<T>} run the function to run
|
|
34
|
+
* @returns {Promise<T>} the function's result
|
|
35
|
+
*/
|
|
36
|
+
export function withRedactedFailures<T>(secrets: readonly (string | undefined)[], run: () => Promise<T>): Promise<T>;
|
|
37
|
+
export { REDACTION_PLACEHOLDER };
|
|
38
|
+
import { REDACTION_PLACEHOLDER } from '@rathnasgala2/adapter-protocol';
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compare two rows by their member JCS bytes. DEC-097 section 7:
|
|
3
|
+
* `requestTemplates` is "sorted by member JCS bytes", and the
|
|
4
|
+
* `callClassBinding` rows follow the same order.
|
|
5
|
+
*
|
|
6
|
+
* @param {Readonly<Record<string, unknown>>} left the first row
|
|
7
|
+
* @param {Readonly<Record<string, unknown>>} right the second row
|
|
8
|
+
* @returns {number} the byte-order comparison
|
|
9
|
+
*/
|
|
10
|
+
export function compareTemplatesByJcsBytes(left: Readonly<Record<string, unknown>>, right: Readonly<Record<string, unknown>>): number;
|
|
11
|
+
/**
|
|
12
|
+
* Resolve the declared binding row for one `(stage, callClass)` pair.
|
|
13
|
+
*
|
|
14
|
+
* @param {string} stage the lifecycle stage
|
|
15
|
+
* @param {string} callClass the call class
|
|
16
|
+
* @returns {Readonly<{stage: string, callClass: string, pagesDeploymentIdSource: string, recoveryOnly: boolean}>}
|
|
17
|
+
* the binding row
|
|
18
|
+
*/
|
|
19
|
+
export function callClassIdBinding(stage: string, callClass: string): Readonly<{
|
|
20
|
+
stage: string;
|
|
21
|
+
callClass: string;
|
|
22
|
+
pagesDeploymentIdSource: string;
|
|
23
|
+
recoveryOnly: boolean;
|
|
24
|
+
}>;
|
|
25
|
+
/**
|
|
26
|
+
* Build the exact nine-template catalog bound to one API origin.
|
|
27
|
+
*
|
|
28
|
+
* @param {string} [apiOrigin] the canonical `https://` GitHub REST origin;
|
|
29
|
+
* defaults to the declared {@link GITHUB_API_ORIGIN}
|
|
30
|
+
* @returns {readonly Readonly<Record<string, unknown>>[]} the frozen catalog,
|
|
31
|
+
* sorted by member JCS bytes
|
|
32
|
+
*/
|
|
33
|
+
export function buildRequestTemplates(apiOrigin?: string): readonly Readonly<Record<string, unknown>>[];
|
|
34
|
+
/**
|
|
35
|
+
* Resolve one template by its `(stage, callClass)` pair. The same call class
|
|
36
|
+
* appears under several stages, so the pair — never the call class alone —
|
|
37
|
+
* is the catalog key.
|
|
38
|
+
*
|
|
39
|
+
* @param {readonly Readonly<Record<string, unknown>>[]} templates the catalog
|
|
40
|
+
* @param {string} stage the lifecycle stage issuing the call
|
|
41
|
+
* @param {string} callClass the call class to resolve
|
|
42
|
+
* @returns {Readonly<Record<string, unknown>>} the template
|
|
43
|
+
*/
|
|
44
|
+
export function requireTemplate(templates: readonly Readonly<Record<string, unknown>>[], stage: string, callClass: string): Readonly<Record<string, unknown>>;
|
|
45
|
+
/** The exact request-template profile this adapter declares. */
|
|
46
|
+
export const REQUEST_TEMPLATE_PROFILE: "gala-github-pages-http-v2";
|
|
47
|
+
/**
|
|
48
|
+
* The single origin every cataloged row targets. DEC-097 section 7: "Every
|
|
49
|
+
* row's origin is exactly `https://api.github.com`". The injectable
|
|
50
|
+
* `apiOrigin` exists only so a fixture can bind the identical code path to a
|
|
51
|
+
* local fake provider; the declared default is these exact bytes.
|
|
52
|
+
*/
|
|
53
|
+
export const GITHUB_API_ORIGIN: "https://api.github.com";
|
|
54
|
+
/**
|
|
55
|
+
* The GitHub REST API version header every call pins. DEC-097 section 7
|
|
56
|
+
* fixes it as the exact bytes below; it is not a free choice.
|
|
57
|
+
*/
|
|
58
|
+
export const GITHUB_API_VERSION: "2026-03-10";
|
|
59
|
+
/**
|
|
60
|
+
* The `pagesDeploymentId` source a row's call class statically selects.
|
|
61
|
+
* `none` means the row's request target has no `pagesDeploymentId` variable.
|
|
62
|
+
*/
|
|
63
|
+
export const DEPLOYMENT_ID_SOURCES: readonly string[];
|
|
64
|
+
/**
|
|
65
|
+
* The request-body profile of the only two rows that carry an entity.
|
|
66
|
+
* DEC-097 section 7: "Only `pages-create-deployment` carries
|
|
67
|
+
* `requestBodyProfile: gala-pages-create-deployment-jcs-v2`".
|
|
68
|
+
*/
|
|
69
|
+
export const CREATE_BODY_PROFILE: "gala-pages-create-deployment-jcs-v2";
|
|
70
|
+
/**
|
|
71
|
+
* The declared `callClassBinding` rows (`adapter-capability` 2.8.0,
|
|
72
|
+
* LOCAL-52 (2)): for every `(stage, callClass)` pair of the nine-row
|
|
73
|
+
* catalog, the `pagesDeploymentId` source its call class statically selects
|
|
74
|
+
* and whether the row is admitted only in `pages-reconciliation-recovery`
|
|
75
|
+
* mode.
|
|
76
|
+
*
|
|
77
|
+
* These two facts are contract-normative but cannot be members of the
|
|
78
|
+
* template rows themselves: `providerRequestTemplate` is closed with
|
|
79
|
+
* `additionalProperties: false`. Until schema 2.8.0 they lived here as an
|
|
80
|
+
* undeclared side table; they are now declared in the capability document
|
|
81
|
+
* under `limits.callClassBinding`, bound by their own
|
|
82
|
+
* `callClassBindingDigest` under `GALA-PROVIDER-CALL-CLASS-BINDING-V2\0`,
|
|
83
|
+
* and enforced in `rest.js`. The template catalog and its
|
|
84
|
+
* `requestTemplateCatalogDigest` are byte-identical to before.
|
|
85
|
+
*
|
|
86
|
+
* Sorted by member JCS bytes, like the template rows.
|
|
87
|
+
*
|
|
88
|
+
* @type {readonly Readonly<{stage: string, callClass: string, pagesDeploymentIdSource: string, recoveryOnly: boolean}>[]}
|
|
89
|
+
*/
|
|
90
|
+
export const CALL_CLASS_BINDING: readonly Readonly<{
|
|
91
|
+
stage: string;
|
|
92
|
+
callClass: string;
|
|
93
|
+
pagesDeploymentIdSource: string;
|
|
94
|
+
recoveryOnly: boolean;
|
|
95
|
+
}>[];
|
|
96
|
+
/**
|
|
97
|
+
* The exact nine `(stage, callClass)` pairs DEC-097 section 7 admits.
|
|
98
|
+
*
|
|
99
|
+
* @type {readonly Readonly<{stage: string, callClass: string}>[]}
|
|
100
|
+
*/
|
|
101
|
+
export const PAGES_CALL_PLAN: readonly Readonly<{
|
|
102
|
+
stage: string;
|
|
103
|
+
callClass: string;
|
|
104
|
+
}>[];
|
|
105
|
+
/** The exact closed response-profile catalog this adapter can parse. */
|
|
106
|
+
export const RESPONSE_PROFILES: readonly string[];
|
package/types/rest.d.ts
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {Readonly<{
|
|
3
|
+
* status: number,
|
|
4
|
+
* headers: Readonly<Record<string, string>>,
|
|
5
|
+
* body: unknown,
|
|
6
|
+
* rawByteCount: number
|
|
7
|
+
* }>} ProviderResponse
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* @typedef {Readonly<{
|
|
11
|
+
* apiOrigin: string,
|
|
12
|
+
* owner: string,
|
|
13
|
+
* repository: string,
|
|
14
|
+
* token: string,
|
|
15
|
+
* mode?: string,
|
|
16
|
+
* pagesBuildVersion?: string,
|
|
17
|
+
* priorPagesBuildVersion?: string,
|
|
18
|
+
* fetch?: typeof globalThis.fetch,
|
|
19
|
+
* requestTemplates: readonly Readonly<Record<string, unknown>>[]
|
|
20
|
+
* }>} RestContext
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* Bind the per-activation identities a call class may statically select.
|
|
24
|
+
*
|
|
25
|
+
* @param {RestContext} context the bound REST context
|
|
26
|
+
* @param {{
|
|
27
|
+
* mode?: string,
|
|
28
|
+
* pagesBuildVersion?: string,
|
|
29
|
+
* priorPagesBuildVersion?: string
|
|
30
|
+
* }} identity the identities this attempt is authorized for
|
|
31
|
+
* @returns {RestContext} a new frozen context
|
|
32
|
+
*/
|
|
33
|
+
export function bindIdentity(context: RestContext, identity: {
|
|
34
|
+
mode?: string;
|
|
35
|
+
pagesBuildVersion?: string;
|
|
36
|
+
priorPagesBuildVersion?: string;
|
|
37
|
+
}): RestContext;
|
|
38
|
+
/**
|
|
39
|
+
* Render a catalog template's request target by substituting only the closed
|
|
40
|
+
* placeholder set. An unknown placeholder is a programming error, not a
|
|
41
|
+
* caller-controlled value.
|
|
42
|
+
*
|
|
43
|
+
* @param {string} template the `requestTargetTemplate`
|
|
44
|
+
* @param {Readonly<Record<string, string>>} values placeholder values
|
|
45
|
+
* @returns {string} the rendered request target
|
|
46
|
+
*/
|
|
47
|
+
export function renderRequestTarget(template: string, values: Readonly<Record<string, string>>): string;
|
|
48
|
+
/**
|
|
49
|
+
* Resolve the `pagesDeploymentId` a row's call class statically selects.
|
|
50
|
+
*
|
|
51
|
+
* @param {RestContext} context the bound REST context
|
|
52
|
+
* @param {Readonly<Record<string, unknown>>} template the resolved template
|
|
53
|
+
* @returns {string | undefined} the selected ID, or `undefined` for a row
|
|
54
|
+
* whose request target has no `pagesDeploymentId` variable
|
|
55
|
+
*/
|
|
56
|
+
export function selectDeploymentId(context: RestContext, template: Readonly<Record<string, unknown>>): string | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* Refuse a recovery-prior call outside `pages-reconciliation-recovery` mode.
|
|
59
|
+
*
|
|
60
|
+
* @param {RestContext} context the bound REST context
|
|
61
|
+
* @param {Readonly<Record<string, unknown>>} tmpl the resolved template
|
|
62
|
+
* @returns {void}
|
|
63
|
+
*/
|
|
64
|
+
export function assertModePermitsCall(context: RestContext, tmpl: Readonly<Record<string, unknown>>): void;
|
|
65
|
+
/**
|
|
66
|
+
* Build the complete raw header map one cataloged call sends.
|
|
67
|
+
*
|
|
68
|
+
* @param {RestContext} context the bound REST context
|
|
69
|
+
* @param {Readonly<Record<string, unknown>>} tmpl the resolved template
|
|
70
|
+
* @returns {Record<string, string>} the header map, lower-case names
|
|
71
|
+
*/
|
|
72
|
+
export function buildHeaders(context: RestContext, tmpl: Readonly<Record<string, unknown>>): Record<string, string>;
|
|
73
|
+
/**
|
|
74
|
+
* Refuse a request that disagrees with the template it claims to implement.
|
|
75
|
+
*
|
|
76
|
+
* @param {Readonly<Record<string, unknown>>} tmpl the resolved template
|
|
77
|
+
* @param {{
|
|
78
|
+
* method: string,
|
|
79
|
+
* url: string,
|
|
80
|
+
* headers: Readonly<Record<string, string>>,
|
|
81
|
+
* body: string | undefined
|
|
82
|
+
* }} request the request about to be dispatched
|
|
83
|
+
* @returns {void}
|
|
84
|
+
*/
|
|
85
|
+
export function assertRequestMatchesTemplate(tmpl: Readonly<Record<string, unknown>>, request: {
|
|
86
|
+
method: string;
|
|
87
|
+
url: string;
|
|
88
|
+
headers: Readonly<Record<string, string>>;
|
|
89
|
+
body: string | undefined;
|
|
90
|
+
}): void;
|
|
91
|
+
/**
|
|
92
|
+
* The provider's own JSON `message`, for the unexpected-status diagnostic: a
|
|
93
|
+
* bounded, single-line text with every 40+ character token-like run replaced,
|
|
94
|
+
* so a credential echoed by a provider can never reach a message.
|
|
95
|
+
*
|
|
96
|
+
* @param {Buffer} rawBody the raw response body
|
|
97
|
+
* @returns {string} `: provider message: <message>` or the empty string
|
|
98
|
+
*/
|
|
99
|
+
export function providerMessageSuffix(rawBody: Buffer): string;
|
|
100
|
+
/**
|
|
101
|
+
* Issue one cataloged provider call.
|
|
102
|
+
*
|
|
103
|
+
* @param {RestContext} context the bound REST context
|
|
104
|
+
* @param {string} stage the lifecycle stage issuing the call
|
|
105
|
+
* @param {string} callClass the catalog `callClass` to issue
|
|
106
|
+
* @param {{
|
|
107
|
+
* bodyText?: string,
|
|
108
|
+
* acceptStatuses: readonly number[]
|
|
109
|
+
* }} options the call options; `bodyText` is already-canonical JCS text,
|
|
110
|
+
* because the create body's byte length is contract-visible
|
|
111
|
+
* @returns {Promise<ProviderResponse>} the parsed, bounded response
|
|
112
|
+
*/
|
|
113
|
+
export function callProvider(context: RestContext, stage: string, callClass: string, options: {
|
|
114
|
+
bodyText?: string;
|
|
115
|
+
acceptStatuses: readonly number[];
|
|
116
|
+
}): Promise<ProviderResponse>;
|
|
117
|
+
/**
|
|
118
|
+
* Independently construct the suffix-free poll URL for a deployment, rather
|
|
119
|
+
* than reusing a provider-supplied `status_url` (DEC-097 section 6.2: "The
|
|
120
|
+
* actual polling GET is the distinct suffix-free ... target constructed
|
|
121
|
+
* independently from the pre-authorized ID. Equality between those two URLs
|
|
122
|
+
* is forbidden.").
|
|
123
|
+
*
|
|
124
|
+
* @param {RestContext} context the bound REST context
|
|
125
|
+
* @param {string} pagesDeploymentId the deployment identity
|
|
126
|
+
* @param {string} [stage] the stage whose status row is used
|
|
127
|
+
* @returns {string} the canonical poll URL
|
|
128
|
+
*/
|
|
129
|
+
export function buildPollUrl(context: RestContext, pagesDeploymentId: string, stage?: string): string;
|
|
130
|
+
/**
|
|
131
|
+
* The exact `status_url` shape a create response is permitted to carry. A
|
|
132
|
+
* response whose `status_url` does not match is retained as evidence with
|
|
133
|
+
* `createResponseStatusUrl` absent rather than trusted. It is never followed
|
|
134
|
+
* and, by construction, never equal to {@link buildPollUrl}'s result.
|
|
135
|
+
*
|
|
136
|
+
* @param {RestContext} context the bound REST context
|
|
137
|
+
* @param {string} pagesDeploymentId the deployment identity
|
|
138
|
+
* @returns {string} the expected `status_url`
|
|
139
|
+
*/
|
|
140
|
+
export function expectedStatusUrl(context: RestContext, pagesDeploymentId: string): string;
|
|
141
|
+
/** Maximum response body this client will read, in bytes. */
|
|
142
|
+
export const MAXIMUM_RESPONSE_BODY_BYTES: 1048576;
|
|
143
|
+
export type ProviderResponse = Readonly<{
|
|
144
|
+
status: number;
|
|
145
|
+
headers: Readonly<Record<string, string>>;
|
|
146
|
+
body: unknown;
|
|
147
|
+
rawByteCount: number;
|
|
148
|
+
}>;
|
|
149
|
+
export type RestContext = Readonly<{
|
|
150
|
+
apiOrigin: string;
|
|
151
|
+
owner: string;
|
|
152
|
+
repository: string;
|
|
153
|
+
token: string;
|
|
154
|
+
mode?: string;
|
|
155
|
+
pagesBuildVersion?: string;
|
|
156
|
+
priorPagesBuildVersion?: string;
|
|
157
|
+
fetch?: typeof globalThis.fetch;
|
|
158
|
+
requestTemplates: readonly Readonly<Record<string, unknown>>[];
|
|
159
|
+
}>;
|