@andco/protocol 0.0.13 → 0.0.14
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/constants.d.ts +15 -2
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +17 -3
- package/dist/errors.d.ts +29 -2
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +42 -4
- package/dist/miniapp-icon.js +1 -1
- package/dist/rest/subjects.d.ts +1 -1
- package/dist/rest/subjects.d.ts.map +1 -1
- package/dist/rest/subjects.js +3 -2
- package/dist/signing.d.ts +1 -0
- package/dist/signing.d.ts.map +1 -1
- package/dist/signing.js +7 -0
- package/dist/transport/rest.d.ts.map +1 -1
- package/dist/transport/rest.js +33 -4
- package/dist/urls.d.ts +25 -2
- package/dist/urls.d.ts.map +1 -1
- package/dist/urls.js +47 -4
- package/dist/webhooks.d.ts +5 -1
- package/dist/webhooks.d.ts.map +1 -1
- package/dist/webhooks.js +4 -2
- package/package.json +1 -1
package/dist/constants.d.ts
CHANGED
|
@@ -26,8 +26,21 @@ export declare const ANDCO_INTENT_PROPOSAL_MEDIA_TYPE: "application/json";
|
|
|
26
26
|
* server answers `400 idempotency_key_not_allowed` when a second candidate arrives beside it.
|
|
27
27
|
*/
|
|
28
28
|
export declare const ANDCO_SIGNED_INSTRUCTION_MEDIA_TYPE: "application/jwt";
|
|
29
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* Returns the base URL for one OAuth resource API version under an API endpoint, which keeps its own
|
|
31
|
+
* path. `_` resolves to the latest version.
|
|
32
|
+
*
|
|
33
|
+
* @throws {TypeError} When `endpoint` is not an {@link EndpointURL}.
|
|
34
|
+
* @example
|
|
35
|
+
* ANDCO_OAUTH_API_URL("https://api.andco.com/prefix"); // "https://api.andco.com/prefix/oauth/api/versions/_"
|
|
36
|
+
*/
|
|
30
37
|
export declare function ANDCO_OAUTH_API_URL(endpoint: string | URL, version?: string | number): string;
|
|
31
|
-
/** Returns the versioned OAuth UserInfo endpoint for an AndCo API
|
|
38
|
+
/** Returns the versioned OAuth UserInfo endpoint for an AndCo API endpoint. `_` resolves to the latest version. */
|
|
32
39
|
export declare function ANDCO_OAUTH_USERINFO_URL(endpoint: string | URL, version?: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* An Organization identifier as a path parameter: a positive integer, with no leading zero, up to
|
|
42
|
+
* `ANDCO_MAX_ORGANIZATION_ID` (2147483647). The bound is written digit by digit because JSON Schema
|
|
43
|
+
* cannot compare a string as a number (ADR 0037), and so the OpenAPI document carries it too.
|
|
44
|
+
*/
|
|
45
|
+
export declare const ORGANIZATION_ID_PARAMETER_PATTERN = "^(?:[1-9][0-9]{0,8}|1[0-9]{9}|20[0-9]{8}|21[0-3][0-9]{7}|214[0-6][0-9]{6}|2147[0-3][0-9]{5}|21474[0-7][0-9]{4}|214748[0-2][0-9]{3}|2147483[0-5][0-9]{2}|21474836[0-3][0-9]|214748364[0-7])$";
|
|
33
46
|
//# sourceMappingURL=constants.d.ts.map
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAEA,oDAAoD;AACpD,eAAO,MAAM,kBAAkB,EAAG,WAAoB,CAAC;AACvD,qDAAqD;AACrD,eAAO,MAAM,sBAAsB,EAAG,CAAU,CAAC;AACjD,wDAAwD;AACxD,eAAO,MAAM,iBAAiB,EAAG,wBAAiC,CAAC;AACnE,mDAAmD;AACnD,eAAO,MAAM,gBAAgB,EAAG,uBAAgC,CAAC;AACjE,4EAA4E;AAC5E,eAAO,MAAM,mBAAmB,EAAG,2BAAoC,CAAC;AACxE,gEAAgE;AAChE,eAAO,MAAM,uBAAuB,EAAG,YAAqB,CAAC;AAC7D;;;;;;GAMG;AACH,eAAO,MAAM,gCAAgC,EAAG,kBAA2B,CAAC;AAC5E;;;;;;GAMG;AACH,eAAO,MAAM,mCAAmC,EAAG,iBAA0B,CAAC;AAC9E;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,EAAE,OAAO,GAAE,MAAM,GAAG,MAAY,GAAG,MAAM,CAElG;AACD,mHAAmH;AACnH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,EAAE,OAAO,SAAM,GAAG,MAAM,CAEtF;AAED;;;;GAIG;AACH,eAAO,MAAM,iCAAiC,gMACiJ,CAAC"}
|
package/dist/constants.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { EndpointURL } from "./urls.js";
|
|
1
2
|
/** Protocol identifier used by the AndCo bridge. */
|
|
2
3
|
export const ANDCO_SDK_PROTOCOL = "andco:sdk";
|
|
3
4
|
/** Current version of the AndCo message protocol. */
|
|
@@ -26,11 +27,24 @@ export const ANDCO_INTENT_PROPOSAL_MEDIA_TYPE = "application/json";
|
|
|
26
27
|
* server answers `400 idempotency_key_not_allowed` when a second candidate arrives beside it.
|
|
27
28
|
*/
|
|
28
29
|
export const ANDCO_SIGNED_INSTRUCTION_MEDIA_TYPE = "application/jwt";
|
|
29
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* Returns the base URL for one OAuth resource API version under an API endpoint, which keeps its own
|
|
32
|
+
* path. `_` resolves to the latest version.
|
|
33
|
+
*
|
|
34
|
+
* @throws {TypeError} When `endpoint` is not an {@link EndpointURL}.
|
|
35
|
+
* @example
|
|
36
|
+
* ANDCO_OAUTH_API_URL("https://api.andco.com/prefix"); // "https://api.andco.com/prefix/oauth/api/versions/_"
|
|
37
|
+
*/
|
|
30
38
|
export function ANDCO_OAUTH_API_URL(endpoint, version = "_") {
|
|
31
|
-
return new
|
|
39
|
+
return new EndpointURL(endpoint).join(`oauth/api/versions/${version}`).href;
|
|
32
40
|
}
|
|
33
|
-
/** Returns the versioned OAuth UserInfo endpoint for an AndCo API
|
|
41
|
+
/** Returns the versioned OAuth UserInfo endpoint for an AndCo API endpoint. `_` resolves to the latest version. */
|
|
34
42
|
export function ANDCO_OAUTH_USERINFO_URL(endpoint, version = "_") {
|
|
35
43
|
return new URL(`${ANDCO_OAUTH_API_URL(endpoint, version)}/userinfo`).href;
|
|
36
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* An Organization identifier as a path parameter: a positive integer, with no leading zero, up to
|
|
47
|
+
* `ANDCO_MAX_ORGANIZATION_ID` (2147483647). The bound is written digit by digit because JSON Schema
|
|
48
|
+
* cannot compare a string as a number (ADR 0037), and so the OpenAPI document carries it too.
|
|
49
|
+
*/
|
|
50
|
+
export const ORGANIZATION_ID_PARAMETER_PATTERN = "^(?:[1-9][0-9]{0,8}|1[0-9]{9}|20[0-9]{8}|21[0-3][0-9]{7}|214[0-6][0-9]{6}|2147[0-3][0-9]{5}|21474[0-7][0-9]{4}|214748[0-2][0-9]{3}|2147483[0-5][0-9]{2}|21474836[0-3][0-9]|214748364[0-7])$";
|
package/dist/errors.d.ts
CHANGED
|
@@ -254,12 +254,39 @@ export declare const ANDCO_ACCESS_DENIED_WITHOUT_DECISION: readonly ["bank_accou
|
|
|
254
254
|
* condition rather than a person's decision. Such a redirect is an error, never a dismissal.
|
|
255
255
|
*/
|
|
256
256
|
export declare function isAuthorizationEndedWithoutDecision(error: string | null | undefined, description: string | null | undefined): description is (typeof ANDCO_ACCESS_DENIED_WITHOUT_DECISION)[number];
|
|
257
|
+
/**
|
|
258
|
+
* What an authorization callback's `error` must look like for the SDK to report it as the error's
|
|
259
|
+
* code: ASCII letters, digits, `_`, `.` and `-`, 1 to 128 of them. Any other value (empty, a
|
|
260
|
+
* character outside the set, or longer) is `invalid_callback`, and its message does not repeat the
|
|
261
|
+
* value, which the URL's author controls. Every Andco SDK (JavaScript, Go, Python and Ruby) checks
|
|
262
|
+
* the callback's `error` against this same pattern; the shared cases are the `oauth_error_code`
|
|
263
|
+
* section of the conformance vectors.
|
|
264
|
+
*
|
|
265
|
+
* @see https://github.com/haulmer/andco-sdk-js/blob/main/docs/adr/0042-check-the-oauth-callback-error-code-against-one-pattern-in-every-sdk.md
|
|
266
|
+
*/
|
|
267
|
+
export declare const OAUTH_ERROR_CODE_PATTERN = "^[A-Za-z0-9_.-]{1,128}$";
|
|
268
|
+
/**
|
|
269
|
+
* The authorization callback's parameters that carry one value: each appears at most once and, when
|
|
270
|
+
* it appears, is not empty. A callback that repeats one or leaves it empty is `invalid_callback`,
|
|
271
|
+
* whatever else it carries, since two readers of the same URL could otherwise act on different
|
|
272
|
+
* values. Every Andco SDK (JavaScript, Go, Python and Ruby) refuses such a callback the same way;
|
|
273
|
+
* the shared cases are the `oauth_callback_parameters` section of the conformance vectors.
|
|
274
|
+
*
|
|
275
|
+
* @see https://github.com/haulmer/andco-sdk-js/blob/main/docs/adr/0044-reject-a-repeated-or-empty-oauth-callback-parameter-in-every-sdk.md
|
|
276
|
+
*/
|
|
277
|
+
export declare const OAUTH_CALLBACK_SINGLE_VALUE_PARAMETERS: readonly ["state", "code", "error"];
|
|
278
|
+
/**
|
|
279
|
+
* Whether a callback's query repeats one of {@link OAUTH_CALLBACK_SINGLE_VALUE_PARAMETERS}, or of
|
|
280
|
+
* `names` when given, or leaves it empty.
|
|
281
|
+
*/
|
|
282
|
+
export declare function hasRepeatedOrEmptyCallbackParameter(parameters: URLSearchParams, names?: readonly string[]): boolean;
|
|
257
283
|
/**
|
|
258
284
|
* Builds the error for an authorization redirect that carries `error`.
|
|
259
285
|
*
|
|
260
286
|
* `access_denied` with one of {@link ANDCO_ACCESS_DENIED_WITHOUT_DECISION} becomes the stable code
|
|
261
|
-
* of the same name, keeping the OAuth error in `details.oauth_error`.
|
|
262
|
-
*
|
|
287
|
+
* of the same name, keeping the OAuth error in `details.oauth_error`. An error that matches
|
|
288
|
+
* {@link OAUTH_ERROR_CODE_PATTERN} becomes the code, with the description, cut to 2048 characters,
|
|
289
|
+
* as its message. Any other error is `invalid_callback`.
|
|
263
290
|
*/
|
|
264
291
|
export declare function andcoAuthorizationRedirectError(error: string, description: string | null | undefined): AndcoError;
|
|
265
292
|
/** Error base class that preserves its prototype at runtime. */
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AAEnE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,iBAAiB;IAE5B,uGAAuG;;IAEvG,6EAA6E;;IAE7E,uGAAuG;;IAEvG,6DAA6D;;IAE7D,wFAAwF;;IAMxF,+GAA+G;;IAE/G,wEAAwE;;IAExE,6DAA6D;;IAE7D,0DAA0D;;IAE1D,iEAAiE;;IAEjE,wGAAwG;;IAExG,mEAAmE;;IAEnE,8EAA8E;;IAE9E,uEAAuE;;IAEvE,8DAA8D;;IAE9D,6EAA6E;;IAE7E,uGAAuG;;IAIvG;;;OAGG;;IAEH,yFAAyF;;IAEzF,+EAA+E;;IAE/E,mEAAmE;;IAEnE,qEAAqE;;IAErE,sGAAsG;;IAEtG,sFAAsF;;IAEtF;;;OAGG;;IAEH;;;;OAIG;;IAIH,sGAAsG;;IAEtG;;;;;;OAMG;;IAEH;;;;;;;OAOG;;IAEH;;;;;;OAMG;;IAEH;;;;;;;OAOG;;IAEH,qEAAqE;;IAErE,0EAA0E;;IAE1E,6DAA6D;;IAE7D,gEAAgE;;IAEhE,8EAA8E;;IAE9E,4FAA4F;;IAE5F;;;OAGG;;IAEH,4DAA4D;;IAE5D,qGAAqG;;IAErG,wGAAwG;;IAExG,mGAAmG;;IAEnG;;;OAGG;;IAEH,sGAAsG;;IAGtG;;;OAGG;;IAEH,2FAA2F;;IAI3F;;;;OAIG;;IAEH;;;;OAIG;;IAEH;;;OAGG;;I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AAI,CAAC,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,cAAc,GAAG,UAAU;IAM5E,0CAA0C;WAC5B,EAAE,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU;IAIrD;;;;;;;;;;;;;;OAcG;WACW,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,qBAAqB;IAMhF;;;;;;;;;;;;;;;;;;;;;;OAsBG;WACW,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO;CAkB5D;AAED;;;;;;;;;GASG;AACH,qBAAa,+BAAgC,SAAQ,UAAU,CAAC,wBAAwB,CAAC;aAErE,OAAO,EAAE,0BAA0B;aACnC,QAAQ,EAAE,MAAM;gBADhB,OAAO,EAAE,0BAA0B,EACnC,QAAQ,EAAE,MAAM;CAOnC;AAED;;;;;GAKG;AACH,MAAM,MAAM,qBAAqB,GAAG,UAAU,CAAC,yBAAyB,CAAC,GAAG,+BAA+B,CAAC"}
|
package/dist/errors.js
CHANGED
|
@@ -290,18 +290,56 @@ export function isAuthorizationEndedWithoutDecision(error, description) {
|
|
|
290
290
|
return (error === "access_denied" &&
|
|
291
291
|
ANDCO_ACCESS_DENIED_WITHOUT_DECISION.includes(description));
|
|
292
292
|
}
|
|
293
|
+
/**
|
|
294
|
+
* What an authorization callback's `error` must look like for the SDK to report it as the error's
|
|
295
|
+
* code: ASCII letters, digits, `_`, `.` and `-`, 1 to 128 of them. Any other value (empty, a
|
|
296
|
+
* character outside the set, or longer) is `invalid_callback`, and its message does not repeat the
|
|
297
|
+
* value, which the URL's author controls. Every Andco SDK (JavaScript, Go, Python and Ruby) checks
|
|
298
|
+
* the callback's `error` against this same pattern; the shared cases are the `oauth_error_code`
|
|
299
|
+
* section of the conformance vectors.
|
|
300
|
+
*
|
|
301
|
+
* @see https://github.com/haulmer/andco-sdk-js/blob/main/docs/adr/0042-check-the-oauth-callback-error-code-against-one-pattern-in-every-sdk.md
|
|
302
|
+
*/
|
|
303
|
+
export const OAUTH_ERROR_CODE_PATTERN = "^[A-Za-z0-9_.-]{1,128}$";
|
|
304
|
+
const OAUTH_ERROR_CODE = /* @__PURE__ */ new RegExp(OAUTH_ERROR_CODE_PATTERN);
|
|
305
|
+
/**
|
|
306
|
+
* The authorization callback's parameters that carry one value: each appears at most once and, when
|
|
307
|
+
* it appears, is not empty. A callback that repeats one or leaves it empty is `invalid_callback`,
|
|
308
|
+
* whatever else it carries, since two readers of the same URL could otherwise act on different
|
|
309
|
+
* values. Every Andco SDK (JavaScript, Go, Python and Ruby) refuses such a callback the same way;
|
|
310
|
+
* the shared cases are the `oauth_callback_parameters` section of the conformance vectors.
|
|
311
|
+
*
|
|
312
|
+
* @see https://github.com/haulmer/andco-sdk-js/blob/main/docs/adr/0044-reject-a-repeated-or-empty-oauth-callback-parameter-in-every-sdk.md
|
|
313
|
+
*/
|
|
314
|
+
export const OAUTH_CALLBACK_SINGLE_VALUE_PARAMETERS = ["state", "code", "error"];
|
|
315
|
+
/**
|
|
316
|
+
* Whether a callback's query repeats one of {@link OAUTH_CALLBACK_SINGLE_VALUE_PARAMETERS}, or of
|
|
317
|
+
* `names` when given, or leaves it empty.
|
|
318
|
+
*/
|
|
319
|
+
export function hasRepeatedOrEmptyCallbackParameter(parameters, names = OAUTH_CALLBACK_SINGLE_VALUE_PARAMETERS) {
|
|
320
|
+
return names.some((name) => {
|
|
321
|
+
const values = parameters.getAll(name);
|
|
322
|
+
return values.length > 1 || values[0] === "";
|
|
323
|
+
});
|
|
324
|
+
}
|
|
293
325
|
/**
|
|
294
326
|
* Builds the error for an authorization redirect that carries `error`.
|
|
295
327
|
*
|
|
296
328
|
* `access_denied` with one of {@link ANDCO_ACCESS_DENIED_WITHOUT_DECISION} becomes the stable code
|
|
297
|
-
* of the same name, keeping the OAuth error in `details.oauth_error`.
|
|
298
|
-
*
|
|
329
|
+
* of the same name, keeping the OAuth error in `details.oauth_error`. An error that matches
|
|
330
|
+
* {@link OAUTH_ERROR_CODE_PATTERN} becomes the code, with the description, cut to 2048 characters,
|
|
331
|
+
* as its message. Any other error is `invalid_callback`.
|
|
299
332
|
*/
|
|
300
333
|
export function andcoAuthorizationRedirectError(error, description) {
|
|
301
|
-
if (
|
|
334
|
+
if (!OAUTH_ERROR_CODE.test(error)) {
|
|
335
|
+
return new AndcoError(ANDCO_ERROR_CODES.INVALID_CALLBACK, {
|
|
336
|
+
message: "the callback's error is not an OAuth error code",
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
else if (isAuthorizationEndedWithoutDecision(error, description)) {
|
|
302
340
|
return new AndcoError(description, { message: description, details: { oauth_error: error } });
|
|
303
341
|
}
|
|
304
|
-
return new AndcoError(error
|
|
342
|
+
return new AndcoError(error, { message: description?.slice(0, 2_048) ?? error });
|
|
305
343
|
}
|
|
306
344
|
/** Error base class that preserves its prototype at runtime. */
|
|
307
345
|
export class ErrorExtendable extends Error {
|
package/dist/miniapp-icon.js
CHANGED
|
@@ -4,7 +4,7 @@ export function resolveAndCoMiniappIconUrl(manifest, manifestUrl) {
|
|
|
4
4
|
const base = new SafeURL(manifestUrl);
|
|
5
5
|
for (const icon of manifest["icons"]) {
|
|
6
6
|
try {
|
|
7
|
-
const url = new SafeURL(
|
|
7
|
+
const url = new SafeURL(icon["src"], base);
|
|
8
8
|
if (url.origin === base.origin)
|
|
9
9
|
return url.href;
|
|
10
10
|
}
|
package/dist/rest/subjects.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as v from "valibot";
|
|
|
2
2
|
import { InsufficientAuthorization, InvalidIdentifier, InvalidOrigin, InvalidToken, NotFound, ServerError, TemporarilyUnavailable, UnsupportedVersion } from "./common.js";
|
|
3
3
|
/** The identifier of a Profile, in `/profiles/{profile_id}/…`. */
|
|
4
4
|
export declare const ProfileIdParameter: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UuidAction<string, undefined>]>, v.DescriptionAction<string, "The Profile the Grant's subject names.">]>;
|
|
5
|
-
/** The identifier of an Organization, in `/organizations/{organization_id}
|
|
5
|
+
/** The identifier of an Organization, in `/organizations/{organization_id}/…`, as {@link ORGANIZATION_ID_PARAMETER_PATTERN} says. */
|
|
6
6
|
export declare const OrganizationIdParameter: v.SchemaWithPipe<readonly [v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>, v.DescriptionAction<string, "The Organization the Grant's subject names.">]>;
|
|
7
7
|
/**
|
|
8
8
|
* The errors every route under `/profiles/{profile_id}` and `/organizations/{organization_id}`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subjects.d.ts","sourceRoot":"","sources":["../../src/rest/subjects.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"subjects.d.ts","sourceRoot":"","sources":["../../src/rest/subjects.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAE7B,OAAO,EACL,yBAAyB,EACzB,iBAAiB,EACjB,aAAa,EACb,YAAY,EACZ,QAAQ,EACR,WAAW,EACX,sBAAsB,EACtB,kBAAkB,EACnB,MAAM,aAAa,CAAC;AAErB,kEAAkE;AAClE,eAAO,MAAM,kBAAkB,6LAG9B,CAAC;AAEF,qIAAqI;AACrI,eAAO,MAAM,uBAAuB,mMAGnC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,aAAa,iNAShB,CAAC"}
|
package/dist/rest/subjects.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import * as v from "valibot";
|
|
2
|
+
import { ORGANIZATION_ID_PARAMETER_PATTERN } from "../constants.js";
|
|
2
3
|
import { InsufficientAuthorization, InvalidIdentifier, InvalidOrigin, InvalidToken, NotFound, ServerError, TemporarilyUnavailable, UnsupportedVersion, } from "./common.js";
|
|
3
4
|
/** The identifier of a Profile, in `/profiles/{profile_id}/…`. */
|
|
4
5
|
export const ProfileIdParameter = /* @__PURE__ */ v.pipe(v.pipe(v.string(), v.uuid()), v.description("The Profile the Grant's subject names."));
|
|
5
|
-
/** The identifier of an Organization, in `/organizations/{organization_id}
|
|
6
|
-
export const OrganizationIdParameter = /* @__PURE__ */ v.pipe(v.pipe(v.string(), v.regex(
|
|
6
|
+
/** The identifier of an Organization, in `/organizations/{organization_id}/…`, as {@link ORGANIZATION_ID_PARAMETER_PATTERN} says. */
|
|
7
|
+
export const OrganizationIdParameter = /* @__PURE__ */ v.pipe(v.pipe(v.string(), v.regex(new RegExp(ORGANIZATION_ID_PARAMETER_PATTERN))), v.description("The Organization the Grant's subject names."));
|
|
7
8
|
/**
|
|
8
9
|
* The errors every route under `/profiles/{profile_id}` and `/organizations/{organization_id}`
|
|
9
10
|
* answers, whatever it does: a malformed subject, a token that is not valid or whose Grant lacks the
|
package/dist/signing.d.ts
CHANGED
|
@@ -45,6 +45,7 @@ export declare class AndCoSignerError extends Error {
|
|
|
45
45
|
* The algorithm is read from the key itself -- an EC key's curve OID selects `ES256`/`ES384`/
|
|
46
46
|
* `ES512`, an RSA key signs `RS256`, and Ed25519 signs `EdDSA` -- so passing the wrong key never
|
|
47
47
|
* produces a mismatched header, and there is nothing about the algorithm for a caller to get wrong.
|
|
48
|
+
* An RSA key under 2048 bits throws {@link AndCoSignerError}.
|
|
48
49
|
*
|
|
49
50
|
* @example
|
|
50
51
|
* ```ts
|
package/dist/signing.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signing.d.ts","sourceRoot":"","sources":["../src/signing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,sFAAsF;AACtF,MAAM,MAAM,qBAAqB,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;AAEpF;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,gFAAgF;IAChF,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,mFAAmF;IACnF,QAAQ,CAAC,GAAG,EAAE,qBAAqB,CAAC;IACpC;;;;;OAKG;IACH,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACxD,CAAC;AAEF,mDAAmD;AACnD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,2CAA2C;IAC3C,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,mFAAmF;AACnF,qBAAa,gBAAiB,SAAQ,KAAK;gBACtB,OAAO,EAAE,MAAM;CAInC;
|
|
1
|
+
{"version":3,"file":"signing.d.ts","sourceRoot":"","sources":["../src/signing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,sFAAsF;AACtF,MAAM,MAAM,qBAAqB,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;AAEpF;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,gFAAgF;IAChF,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,mFAAmF;IACnF,QAAQ,CAAC,GAAG,EAAE,qBAAqB,CAAC;IACpC;;;;;OAKG;IACH,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACxD,CAAC;AAEF,mDAAmD;AACnD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,2CAA2C;IAC3C,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,mFAAmF;AACnF,qBAAa,gBAAiB,SAAQ,KAAK;gBACtB,OAAO,EAAE,MAAM;CAInC;AAoBD;;;;;;;;;;;;;GAaG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,WAAW,CAAC,CA4CzF"}
|
package/dist/signing.js
CHANGED
|
@@ -16,6 +16,8 @@ export class AndCoSignerError extends Error {
|
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
const PEM_PATTERN = /-----BEGIN PRIVATE KEY-----([\s\S]+?)-----END PRIVATE KEY-----/;
|
|
19
|
+
/** The smallest RSA modulus a signer accepts, in bits. */
|
|
20
|
+
const RSA_MINIMUM_BITS = 2048;
|
|
19
21
|
/** OIDs this signer recognizes, dotted-decimal, as DER encodes them inside PKCS8. */
|
|
20
22
|
const RSA_ENCRYPTION_OID = "1.2.840.113549.1.1.1";
|
|
21
23
|
const EC_PUBLIC_KEY_OID = "1.2.840.10045.2.1";
|
|
@@ -31,6 +33,7 @@ const CURVE_OIDS = {
|
|
|
31
33
|
* The algorithm is read from the key itself -- an EC key's curve OID selects `ES256`/`ES384`/
|
|
32
34
|
* `ES512`, an RSA key signs `RS256`, and Ed25519 signs `EdDSA` -- so passing the wrong key never
|
|
33
35
|
* produces a mismatched header, and there is nothing about the algorithm for a caller to get wrong.
|
|
36
|
+
* An RSA key under 2048 bits throws {@link AndCoSignerError}.
|
|
34
37
|
*
|
|
35
38
|
* @example
|
|
36
39
|
* ```ts
|
|
@@ -67,6 +70,10 @@ export async function createAndCoSigner(options) {
|
|
|
67
70
|
throw new AndCoSignerError(`unsupported private key algorithm: ${algorithmOid}`);
|
|
68
71
|
}
|
|
69
72
|
const key = await subtle.importKey("pkcs8", der, importAlgorithm, true, ["sign"]);
|
|
73
|
+
const { modulusLength } = key.algorithm;
|
|
74
|
+
if (alg === "RS256" && (modulusLength === undefined || modulusLength < RSA_MINIMUM_BITS)) {
|
|
75
|
+
throw new AndCoSignerError(`RSA keys must be at least ${RSA_MINIMUM_BITS} bits, got ${modulusLength ?? "unknown"}`);
|
|
76
|
+
}
|
|
70
77
|
const kid = await JWK_THUMBPRINT(subtle, key);
|
|
71
78
|
return {
|
|
72
79
|
kid,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rest.d.ts","sourceRoot":"","sources":["../../src/transport/rest.ts"],"names":[],"mappings":"AAAA,OAAqB,E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UAAU,CAAC,SAAS,CAAC,CAAC,wBAAwB,CAAC,CAAC;AAC1F,MAAM,MAAM,0BAA0B,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,uBAAuB,CAAC,CAAC;AAExF;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,0CAA0C;IAC1C,QAAQ,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;IACxB,mFAAmF;IACnF,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC7B,0EAA0E;IAC1E,WAAW,CAAC,EAAE,oBAAoB,CAAC;IACnC,+EAA+E;IAC/E,KAAK,CAAC,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;CAChC,CAAC;AA8BF;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,GAAE,sBAA2B,GAAG,eAAe,CA4B3F"}
|
package/dist/transport/rest.js
CHANGED
|
@@ -1,7 +1,35 @@
|
|
|
1
|
-
import createClient from "openapi-fetch";
|
|
2
|
-
import { ANDCO_API_ORIGIN, ANDCO_OAUTH_API_URL } from "../constants.js";
|
|
3
|
-
import {
|
|
1
|
+
import createClient, { defaultPathSerializer } from "openapi-fetch";
|
|
2
|
+
import { ANDCO_API_ORIGIN, ANDCO_OAUTH_API_URL, ORGANIZATION_ID_PARAMETER_PATTERN } from "../constants.js";
|
|
3
|
+
import { ANDCO_ERROR_CODES, AndcoError } from "../errors.js";
|
|
4
|
+
import { ACCOUNT_KEY_SYNTAX } from "../rar/account-matchers.js";
|
|
5
|
+
import { EndpointURL } from "../urls.js";
|
|
6
|
+
import { IS_UUID_SHAPED } from "./intents.js";
|
|
4
7
|
import { createRuntimeFetch } from "./runtime.js";
|
|
8
|
+
const ORGANIZATION_ID_PARAMETER = /* @__PURE__ */ new RegExp(ORGANIZATION_ID_PARAMETER_PATTERN);
|
|
9
|
+
const ACCOUNT_KEY = /* @__PURE__ */ new RegExp(ACCOUNT_KEY_SYNTAX);
|
|
10
|
+
/** The path parameters that are not always a UUID, and what each one must look like. */
|
|
11
|
+
const PATH_PARAMETER_CHECKS = {
|
|
12
|
+
organization_id: (value) => ORGANIZATION_ID_PARAMETER.test(value),
|
|
13
|
+
// `/accounts/{bank_account_id}/transactions` names the account by its UUID or its Account Key.
|
|
14
|
+
bank_account_id: (value) => IS_UUID_SHAPED(value) || ACCOUNT_KEY.test(value),
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Checks each path parameter before it becomes a segment: an Organization against
|
|
18
|
+
* {@link ORGANIZATION_ID_PARAMETER_PATTERN}, an account as a UUID or an Account Key, every other
|
|
19
|
+
* identifier as a UUID. `encodeURIComponent` leaves `.` and `..` as they are and the URL parser
|
|
20
|
+
* resolves them, so an unchecked identifier could send the request, with its token, to another
|
|
21
|
+
* route. A failure throws `invalid_identifier`, since no request was made to answer with
|
|
22
|
+
* `{ data, error }`.
|
|
23
|
+
*/
|
|
24
|
+
function checkedPathSerializer(pathname, pathParams) {
|
|
25
|
+
for (const [name, value] of Object.entries(pathParams)) {
|
|
26
|
+
const check = PATH_PARAMETER_CHECKS[name] ?? IS_UUID_SHAPED;
|
|
27
|
+
if (!check(String(value))) {
|
|
28
|
+
throw new AndcoError(ANDCO_ERROR_CODES.INVALID_IDENTIFIER, { message: `${name} is not a valid identifier` });
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return defaultPathSerializer(pathname, pathParams);
|
|
32
|
+
}
|
|
5
33
|
/**
|
|
6
34
|
* Creates a lightweight typed client for the OAuth resource API.
|
|
7
35
|
*
|
|
@@ -23,10 +51,11 @@ export function createAndCoRestClient(options = {}) {
|
|
|
23
51
|
if (version !== "_" && !/^\d{10}$/.test(version)) {
|
|
24
52
|
throw new TypeError("apiVersion must be `_` or a Unix timestamp in seconds");
|
|
25
53
|
}
|
|
26
|
-
const endpoint = new
|
|
54
|
+
const endpoint = new EndpointURL(options.endpoint ?? ANDCO_API_ORIGIN);
|
|
27
55
|
const client = createClient({
|
|
28
56
|
baseUrl: ANDCO_OAUTH_API_URL(endpoint, version),
|
|
29
57
|
fetch: options.fetch ?? createRuntimeFetch(),
|
|
58
|
+
pathSerializer: checkedPathSerializer,
|
|
30
59
|
});
|
|
31
60
|
const authorization = {
|
|
32
61
|
async onRequest({ request }) {
|
package/dist/urls.d.ts
CHANGED
|
@@ -48,8 +48,9 @@ export declare class BetterURL<const TUrl extends string | URL = string | URL> e
|
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
50
50
|
* A {@link BetterURL} that is HTTPS (or plaintext HTTP on a loopback development host), and carries no
|
|
51
|
-
* credentials or
|
|
52
|
-
* `password`, or `hash` afterward is not re-validated, so treat a SafeURL as safe
|
|
51
|
+
* credentials, fragment or `%` in its host. These checks run once, at construction: mutating `protocol`,
|
|
52
|
+
* `username`, `password`, `host`, or `hash` afterward is not re-validated, so treat a SafeURL as safe
|
|
53
|
+
* only until mutated.
|
|
53
54
|
*
|
|
54
55
|
* Because a fragment fails construction, `.hashParams` is always empty on a valid SafeURL.
|
|
55
56
|
*
|
|
@@ -59,6 +60,28 @@ export declare class BetterURL<const TUrl extends string | URL = string | URL> e
|
|
|
59
60
|
export declare class SafeURL<const TUrl extends string | URL = string | URL> extends BetterURL<TUrl> {
|
|
60
61
|
constructor(url: TUrl, base?: string | URL, overwrite?: BetterURLOverwrite<TUrl>);
|
|
61
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* A {@link SafeURL} for an Andco endpoint: a base URL the SDK joins a path to, such as the API or the
|
|
65
|
+
* Authorization Server. It carries no query or fragment, not even an empty `?` or `#`, since one would
|
|
66
|
+
* take the joined path. A URL the SDK adds query parameters to, such as an authorization endpoint, is a
|
|
67
|
+
* plain SafeURL. Every Andco SDK refuses the same endpoints and keeps an endpoint's path when it joins
|
|
68
|
+
* one; ADR 0043 records both rules.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* const api = new EndpointURL("https://api.andco.com");
|
|
72
|
+
*/
|
|
73
|
+
export declare class EndpointURL extends SafeURL {
|
|
74
|
+
constructor(url: string | URL);
|
|
75
|
+
/**
|
|
76
|
+
* Builds the URL of `path` under this endpoint. The endpoint's own path stays as a prefix, and a
|
|
77
|
+
* trailing slash on the endpoint changes nothing. The endpoint itself does not change.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* new EndpointURL("https://auth.localhost/auth/v1/").join("oauth/token").href;
|
|
81
|
+
* // "https://auth.localhost/auth/v1/oauth/token"
|
|
82
|
+
*/
|
|
83
|
+
join(path: string): URL;
|
|
84
|
+
}
|
|
62
85
|
/** Creates the AndCo Console URL for registering an OAuth project. */
|
|
63
86
|
export declare function ANDCO_PROJECT_URL({ redirectUris, clientName, clientType, framework, scopes, }: {
|
|
64
87
|
redirectUris: string[];
|
package/dist/urls.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"urls.d.ts","sourceRoot":"","sources":["../src/urls.ts"],"names":[],"mappings":"AAAA,oFAAoF;AACpF,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,WAKhD;AAED,QAAA,MAAM,iBAAiB,yGAUb,CAAC;AACX,KAAK,kBAAkB,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE7D,yEAAyE;AACzE,MAAM,MAAM,kBAAkB,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,SAAS,GAAG,MAAM,IAAI,MAAM,CAAC,IAAI,MAAM,IAAI,EAAE,GAC7F,CAAC,GAAG,kBAAkB,CAAC,IAAI,CAAC,GAC5B,KAAK,CAAC;AAEV,KAAK,gBAAgB,CAAC,IAAI,SAAS,MAAM,GAAG,GAAG,IAAI,IAAI,SAAS,MAAM,GAClE,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GACxC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,GAC/B,OAAO,CAAC,MAA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AAM,GACP,EAAE;IACD,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,cAAc,GAAG,QAAQ,CAAC;IACvC,SAAS,EAAE,QAAQ,GAAG,OAAO,GAAG,cAAc,GAAG,QAAQ,GAAG,KAAK,GAAG,SAAS,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,CAAC;IAC7G,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,EACD,OAAO,GAAE,MAAM,GAAG,GAA6B,GAC9C,GAAG,CAKL"}
|
package/dist/urls.js
CHANGED
|
@@ -104,8 +104,9 @@ export class BetterURL extends URL {
|
|
|
104
104
|
}
|
|
105
105
|
/**
|
|
106
106
|
* A {@link BetterURL} that is HTTPS (or plaintext HTTP on a loopback development host), and carries no
|
|
107
|
-
* credentials or
|
|
108
|
-
* `password`, or `hash` afterward is not re-validated, so treat a SafeURL as safe
|
|
107
|
+
* credentials, fragment or `%` in its host. These checks run once, at construction: mutating `protocol`,
|
|
108
|
+
* `username`, `password`, `host`, or `hash` afterward is not re-validated, so treat a SafeURL as safe
|
|
109
|
+
* only until mutated.
|
|
109
110
|
*
|
|
110
111
|
* Because a fragment fails construction, `.hashParams` is always empty on a valid SafeURL.
|
|
111
112
|
*
|
|
@@ -116,9 +117,51 @@ export class SafeURL extends BetterURL {
|
|
|
116
117
|
constructor(url, base, overwrite) {
|
|
117
118
|
super(url, base, overwrite);
|
|
118
119
|
const secureTransport = this.protocol === "https:" || (this.protocol === "http:" && IS_LOOPBACK_HOST(this.hostname));
|
|
119
|
-
|
|
120
|
-
|
|
120
|
+
// WHATWG URL percent-decodes a host: `ex%61mple.com` is `example.com` here, where other parsers keep
|
|
121
|
+
// the `%` or refuse it. Escaped as `%25`, a `%` in the host outlives that one decoding, and no host may
|
|
122
|
+
// hold one, so the escaped input fails to parse exactly when the host had a `%`.
|
|
123
|
+
let percentInHost = Boolean(overwrite?.host?.includes("%") || overwrite?.hostname?.includes("%"));
|
|
124
|
+
try {
|
|
125
|
+
new URL(String(url).replaceAll("%", "%25"), base === undefined ? undefined : String(base).replaceAll("%", "%25"));
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
percentInHost = true;
|
|
121
129
|
}
|
|
130
|
+
if (!secureTransport || this.username || this.password || this.hash || percentInHost) {
|
|
131
|
+
throw new TypeError("AndCo URLs require HTTPS, except for loopback development hosts, and cannot contain credentials, a fragment or a `%` in the host");
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* A {@link SafeURL} for an Andco endpoint: a base URL the SDK joins a path to, such as the API or the
|
|
137
|
+
* Authorization Server. It carries no query or fragment, not even an empty `?` or `#`, since one would
|
|
138
|
+
* take the joined path. A URL the SDK adds query parameters to, such as an authorization endpoint, is a
|
|
139
|
+
* plain SafeURL. Every Andco SDK refuses the same endpoints and keeps an endpoint's path when it joins
|
|
140
|
+
* one; ADR 0043 records both rules.
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* const api = new EndpointURL("https://api.andco.com");
|
|
144
|
+
*/
|
|
145
|
+
export class EndpointURL extends SafeURL {
|
|
146
|
+
constructor(url) {
|
|
147
|
+
super(url);
|
|
148
|
+
// `search` and `hash` are empty for a bare `?` or `#`, but the serialized URL keeps the character.
|
|
149
|
+
if (this.href.includes("?") || this.href.includes("#")) {
|
|
150
|
+
throw new TypeError("An Andco endpoint cannot contain a query or a fragment, not even an empty one");
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Builds the URL of `path` under this endpoint. The endpoint's own path stays as a prefix, and a
|
|
155
|
+
* trailing slash on the endpoint changes nothing. The endpoint itself does not change.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* new EndpointURL("https://auth.localhost/auth/v1/").join("oauth/token").href;
|
|
159
|
+
* // "https://auth.localhost/auth/v1/oauth/token"
|
|
160
|
+
*/
|
|
161
|
+
join(path) {
|
|
162
|
+
const url = new URL(this.href);
|
|
163
|
+
url.pathname = `${this.pathname.replace(/\/+$/, "")}/${path.replace(/^\/+/, "")}`;
|
|
164
|
+
return url;
|
|
122
165
|
}
|
|
123
166
|
}
|
|
124
167
|
/** Creates the AndCo Console URL for registering an OAuth project. */
|
package/dist/webhooks.d.ts
CHANGED
|
@@ -155,7 +155,11 @@ export type AndcoWebhookDelivery = {
|
|
|
155
155
|
headers: Headers | Record<string, string | string[] | undefined>;
|
|
156
156
|
};
|
|
157
157
|
export type AndcoWebhookVerifierOptions = {
|
|
158
|
-
/**
|
|
158
|
+
/**
|
|
159
|
+
* Where to fetch Andco's public webhook keys. Defaults to {@link ANDCO_WEBHOOK_JWKS_URL}. Like every
|
|
160
|
+
* Andco URL it must be HTTPS (plain HTTP only on a loopback development host) without credentials or a
|
|
161
|
+
* fragment: `verifier` throws a `TypeError` otherwise, before any delivery arrives.
|
|
162
|
+
*/
|
|
159
163
|
jwksUrl?: string | URL;
|
|
160
164
|
/** Accepted clock drift, in seconds. Defaults to {@link ANDCO_WEBHOOK_TOLERANCE_SECONDS}. */
|
|
161
165
|
toleranceSeconds?: number;
|
package/dist/webhooks.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhooks.d.ts","sourceRoot":"","sources":["../src/webhooks.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"webhooks.d.ts","sourceRoot":"","sources":["../src/webhooks.ts"],"names":[],"mappings":"AAGA,uDAAuD;AACvD,eAAO,MAAM,qBAAqB;;;;CAIxB,CAAC;AAEX,wEAAwE;AACxE,eAAO,MAAM,uBAAuB,EAAG,SAAkB,CAAC;AAE1D,oFAAoF;AACpF,eAAO,MAAM,+BAA+B,MAAM,CAAC;AAEnD,wFAAwF;AACxF,eAAO,MAAM,sBAAsB,uDAA+D,CAAC;AAEnG;;;GAGG;AACH,eAAO,MAAM,yBAAyB,QAAc,CAAC;AAErD;;;;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AAM,2BAA2B,GAAG;IACxC;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;IACvB,6FAA6F;IAC7F,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,+DAA+D;IAC/D,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB;;;OAGG;IACH,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IACnD;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+CAA+C;IAC/C,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB,CAAC;AAEF,wFAAwF;AACxF,MAAM,MAAM,kBAAkB,GAAG,CAAC,QAAQ,EAAE,OAAO,GAAG,oBAAoB,KAAK,OAAO,CAAC,iBAAiB,CAAC,CAAC;AA+C1G;;;;;;;;;;GAUG;AACH,iBAAS,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,KAAK,IAAI,sBAAsB,CAE/E;AAuBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,iBAAS,QAAQ,CAAC,OAAO,GAAE,2BAAgC,GAAG,kBAAkB,CA4H/E;AAED;;;;;GAKG;AACH,eAAO,MAAM,aAAa;;;CAAsC,CAAC"}
|
package/dist/webhooks.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ANDCO_API_ORIGIN } from "./constants.js";
|
|
2
|
+
import { SafeURL } from "./urls.js";
|
|
2
3
|
/** Header names of a signed Andco webhook delivery. */
|
|
3
4
|
export const ANDCO_WEBHOOK_HEADERS = {
|
|
4
5
|
eventId: "andco-event-id",
|
|
@@ -191,7 +192,7 @@ function hasLifecyclePayload(event) {
|
|
|
191
192
|
* ```
|
|
192
193
|
*/
|
|
193
194
|
function verifier(options = {}) {
|
|
194
|
-
const jwksUrl =
|
|
195
|
+
const jwksUrl = new SafeURL(options.jwksUrl ?? ANDCO_WEBHOOK_JWKS_URL).href;
|
|
195
196
|
const tolerance = options.toleranceSeconds ?? ANDCO_WEBHOOK_TOLERANCE_SECONDS;
|
|
196
197
|
const now = options.now ?? (() => Math.floor(Date.now() / 1000));
|
|
197
198
|
const ttl = options.keysTtlMs ?? ANDCO_WEBHOOK_KEYS_TTL_MS;
|
|
@@ -204,7 +205,8 @@ function verifier(options = {}) {
|
|
|
204
205
|
const fetchImpl = options.fetch ?? globalThis.fetch;
|
|
205
206
|
let response;
|
|
206
207
|
try {
|
|
207
|
-
|
|
208
|
+
// A redirect could lead the key fetch off HTTPS or to a host that does not speak for Andco.
|
|
209
|
+
response = await fetchImpl(jwksUrl, { headers: { Accept: "application/json" }, redirect: "error" });
|
|
208
210
|
}
|
|
209
211
|
catch (error) {
|
|
210
212
|
throw new AndcoWebhookError(ANDCO_WEBHOOK_ERROR_CODES.JWKS_UNAVAILABLE, `Could not fetch ${jwksUrl}`, {
|