@andco/protocol 0.0.5 → 0.0.7
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/README.md +3 -1
- package/dist/authorization-preparation.d.ts +85 -2
- package/dist/authorization-preparation.d.ts.map +1 -1
- package/dist/authorization-preparation.js +42 -1
- package/dist/consent.d.ts +82 -7
- package/dist/consent.d.ts.map +1 -1
- package/dist/consent.js +63 -5
- package/dist/errors.d.ts +10 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +10 -0
- package/dist/native-copy.js +16 -0
- package/dist/service-grants.d.ts +2 -1
- package/dist/service-grants.d.ts.map +1 -1
- package/dist/service-grants.js +2 -1
- package/dist/webhooks.d.ts +77 -8
- package/dist/webhooks.d.ts.map +1 -1
- package/dist/webhooks.js +45 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -66,7 +66,9 @@ parseAndcoGrantRequest({
|
|
|
66
66
|
browser packages.
|
|
67
67
|
- `@andco/protocol/webhooks` contains `andcoWebhooks.verifier()`, which verifies
|
|
68
68
|
Andco's Ed25519-signed webhook deliveries against Andco's public JWKS (cached
|
|
69
|
-
by `kid`), and its header and error constants.
|
|
69
|
+
by `kid`), and its header and error constants. Grant lifecycle events
|
|
70
|
+
(`grant.revoked`, `grant.expired`, `grant.updated`) come back typed with a
|
|
71
|
+
checked payload; narrow with `andcoWebhooks.isGrantEvent(event)`.
|
|
70
72
|
- `@andco/protocol/server` contains server-only helpers for a confidential
|
|
71
73
|
client authenticated with `client_secret_basic`.
|
|
72
74
|
|
|
@@ -39,6 +39,27 @@ export declare const AndCoResourceConsentSchema: v.ObjectSchema<{
|
|
|
39
39
|
readonly resourceName: v.StringSchema<undefined>;
|
|
40
40
|
readonly resource: v.StringSchema<undefined>;
|
|
41
41
|
}, undefined>;
|
|
42
|
+
/**
|
|
43
|
+
* One Resource Server a pending authorization names (ADR 0033), in the order of its `resource`
|
|
44
|
+
* parameters: who it is, whether the person may leave it out of the consent (only in an
|
|
45
|
+
* authorization naming several, and only when the Client's policies on it list no required scope)
|
|
46
|
+
* and which requested authorization details are its own (zero-based request positions).
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* const optional = consent.resourceServers.filter((server) => server.resourceServerOptional);
|
|
50
|
+
*/
|
|
51
|
+
export declare const AndCoConsentResourceServerSchema: v.ObjectSchema<{
|
|
52
|
+
readonly resourceServerId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UuidAction<string, undefined>]>;
|
|
53
|
+
readonly resourcePosition: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
54
|
+
readonly resourceServerName: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 255, undefined>]>;
|
|
55
|
+
readonly resource: v.StringSchema<undefined>;
|
|
56
|
+
readonly resourceProjectId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UuidAction<string, undefined>]>;
|
|
57
|
+
readonly resourceProjectName: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 256, undefined>]>;
|
|
58
|
+
readonly resourceProjectHomeUri: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
59
|
+
readonly resourcePublisherName: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 256, undefined>]>;
|
|
60
|
+
readonly resourceServerOptional: v.BooleanSchema<undefined>;
|
|
61
|
+
readonly detailPositions: v.ArraySchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
|
|
62
|
+
}, undefined>;
|
|
42
63
|
/** Canonical state of one pending authorization, resolved once by the platform for every surface. */
|
|
43
64
|
export declare const AndCoAuthorizationPreparationSchema: v.VariantSchema<"status", [v.ObjectSchema<{
|
|
44
65
|
readonly status: v.LiteralSchema<"sign_in_required", undefined>;
|
|
@@ -99,7 +120,7 @@ export declare const AndCoAuthorizationPreparationSchema: v.VariantSchema<"statu
|
|
|
99
120
|
scope: string;
|
|
100
121
|
mode: "optional" | "default" | "required";
|
|
101
122
|
}[], 50, undefined>]>;
|
|
102
|
-
readonly
|
|
123
|
+
readonly resourceAuthorizations: v.SchemaWithPipe<readonly [v.ArraySchema<v.ObjectSchema<{
|
|
103
124
|
readonly allowed: v.BooleanSchema<undefined>;
|
|
104
125
|
readonly organizationId: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
105
126
|
readonly organizationName: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
@@ -119,7 +140,50 @@ export declare const AndCoAuthorizationPreparationSchema: v.VariantSchema<"statu
|
|
|
119
140
|
readonly resourcePublisherName: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
|
|
120
141
|
readonly resourceName: v.StringSchema<undefined>;
|
|
121
142
|
readonly resource: v.StringSchema<undefined>;
|
|
122
|
-
}, undefined>, undefined
|
|
143
|
+
}, undefined>, undefined>, v.MaxLengthAction<{
|
|
144
|
+
allowed: boolean;
|
|
145
|
+
organizationId: string | null;
|
|
146
|
+
organizationName: string | null;
|
|
147
|
+
details: {
|
|
148
|
+
name: string;
|
|
149
|
+
actions: {
|
|
150
|
+
id: string;
|
|
151
|
+
description: string;
|
|
152
|
+
}[];
|
|
153
|
+
}[];
|
|
154
|
+
errorCode: string | null;
|
|
155
|
+
clientProjectName: string;
|
|
156
|
+
resourceServerId?: string | undefined;
|
|
157
|
+
resourceProjectId: string;
|
|
158
|
+
resourceProjectName?: string | undefined;
|
|
159
|
+
resourceProjectHomeUri?: string | null | undefined;
|
|
160
|
+
resourcePublisherName?: string | undefined;
|
|
161
|
+
resourceName: string;
|
|
162
|
+
resource: string;
|
|
163
|
+
}[], 10, undefined>]>;
|
|
164
|
+
readonly resourceServers: v.SchemaWithPipe<readonly [v.ArraySchema<v.ObjectSchema<{
|
|
165
|
+
readonly resourceServerId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UuidAction<string, undefined>]>;
|
|
166
|
+
readonly resourcePosition: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
|
|
167
|
+
readonly resourceServerName: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 255, undefined>]>;
|
|
168
|
+
readonly resource: v.StringSchema<undefined>;
|
|
169
|
+
readonly resourceProjectId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UuidAction<string, undefined>]>;
|
|
170
|
+
readonly resourceProjectName: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 256, undefined>]>;
|
|
171
|
+
readonly resourceProjectHomeUri: v.NullableSchema<v.StringSchema<undefined>, undefined>;
|
|
172
|
+
readonly resourcePublisherName: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 256, undefined>]>;
|
|
173
|
+
readonly resourceServerOptional: v.BooleanSchema<undefined>;
|
|
174
|
+
readonly detailPositions: v.ArraySchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
|
|
175
|
+
}, undefined>, undefined>, v.MaxLengthAction<{
|
|
176
|
+
resourceServerId: string;
|
|
177
|
+
resourcePosition: number;
|
|
178
|
+
resourceServerName: string;
|
|
179
|
+
resource: string;
|
|
180
|
+
resourceProjectId: string;
|
|
181
|
+
resourceProjectName: string;
|
|
182
|
+
resourceProjectHomeUri: string | null;
|
|
183
|
+
resourcePublisherName: string;
|
|
184
|
+
resourceServerOptional: boolean;
|
|
185
|
+
detailPositions: number[];
|
|
186
|
+
}[], 10, undefined>]>;
|
|
123
187
|
readonly organizationSubject: v.OptionalSchema<v.ObjectSchema<{
|
|
124
188
|
readonly organizationId: v.NumberSchema<undefined>;
|
|
125
189
|
readonly organizationName: v.StringSchema<undefined>;
|
|
@@ -247,6 +311,21 @@ export declare const AndCoAuthorizationCompletionSchema: v.ObjectSchema<{
|
|
|
247
311
|
readonly decision: v.PicklistSchema<["approve", "deny"], undefined>;
|
|
248
312
|
readonly redirectUrl: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 8192, undefined>]>;
|
|
249
313
|
}, undefined>;
|
|
314
|
+
/**
|
|
315
|
+
* The decision a native Host submits for one pending authorization: the chosen scopes and the
|
|
316
|
+
* optional Resource Servers the person left out whole (their details and own scopes are dropped;
|
|
317
|
+
* Platform refuses leaving out a required one), or a denial.
|
|
318
|
+
*
|
|
319
|
+
* @example
|
|
320
|
+
* const decision: AndCoAuthorizationDecision = { decision: "approve", scopes: ["openid", "email"], omittedResourceServers: [casaNorteId] };
|
|
321
|
+
*/
|
|
322
|
+
export declare const AndCoAuthorizationDecisionSchema: v.VariantSchema<"decision", [v.ObjectSchema<{
|
|
323
|
+
readonly decision: v.LiteralSchema<"approve", undefined>;
|
|
324
|
+
readonly scopes: v.SchemaWithPipe<readonly [v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 128, undefined>]>, undefined>, v.MaxLengthAction<string[], 50, undefined>]>;
|
|
325
|
+
readonly omittedResourceServers: v.SchemaWithPipe<readonly [v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UuidAction<string, undefined>]>, undefined>, v.MaxLengthAction<string[], 10, undefined>]>;
|
|
326
|
+
}, undefined>, v.ObjectSchema<{
|
|
327
|
+
readonly decision: v.LiteralSchema<"deny", undefined>;
|
|
328
|
+
}, undefined>], undefined>;
|
|
250
329
|
export declare const AndCoAuthorizationErrorSchema: v.ObjectSchema<{
|
|
251
330
|
readonly error: v.ObjectSchema<{
|
|
252
331
|
readonly code: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 128, undefined>]>;
|
|
@@ -258,6 +337,10 @@ export declare const AndCoAuthorizationErrorSchema: v.ObjectSchema<{
|
|
|
258
337
|
export type AndCoAuthorizationPreparation = v.InferOutput<typeof AndCoAuthorizationPreparationSchema>;
|
|
259
338
|
/** Completed approve or deny result containing the safe OAuth continuation URL. */
|
|
260
339
|
export type AndCoAuthorizationCompletion = v.InferOutput<typeof AndCoAuthorizationCompletionSchema>;
|
|
340
|
+
/** One Resource Server of a pending authorization, as the consent groups it. */
|
|
341
|
+
export type AndCoConsentResourceServer = v.InferOutput<typeof AndCoConsentResourceServerSchema>;
|
|
342
|
+
/** Approve (with scopes and left-out Resource Servers) or deny, as a native Host submits it. */
|
|
343
|
+
export type AndCoAuthorizationDecision = v.InferOutput<typeof AndCoAuthorizationDecisionSchema>;
|
|
261
344
|
/** Typed API failure returned by the native authorization endpoints. */
|
|
262
345
|
export type AndCoAuthorizationError = v.InferOutput<typeof AndCoAuthorizationErrorSchema>["error"];
|
|
263
346
|
//# sourceMappingURL=authorization-preparation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authorization-preparation.d.ts","sourceRoot":"","sources":["../src/authorization-preparation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAG7B,uEAAuE;AACvE,eAAO,MAAM,uBAAuB;;;;;;;;;;;;aAkBlC,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;aAgBrC,CAAC;
|
|
1
|
+
{"version":3,"file":"authorization-preparation.d.ts","sourceRoot":"","sources":["../src/authorization-preparation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAG7B,uEAAuE;AACvE,eAAO,MAAM,uBAAuB;;;;;;;;;;;;aAkBlC,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;aAgBrC,CAAC;AAEH;;;;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resource Server a pending authorization names (ADR 0033), in the order of its `resource`
|
|
45
|
+
* parameters: who it is, whether the person may leave it out of the consent (only in an
|
|
46
|
+
* authorization naming several, and only when the Client's policies on it list no required scope)
|
|
47
|
+
* and which requested authorization details are its own (zero-based request positions).
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* const optional = consent.resourceServers.filter((server) => server.resourceServerOptional);
|
|
51
|
+
*/
|
|
52
|
+
export const AndCoConsentResourceServerSchema = /* @__PURE__ */ v.object({
|
|
53
|
+
resourceServerId: v.pipe(v.string(), v.uuid()),
|
|
54
|
+
resourcePosition: v.pipe(v.number(), v.integer(), v.minValue(0)),
|
|
55
|
+
resourceServerName: v.pipe(v.string(), v.maxLength(255)),
|
|
56
|
+
resource: v.string(),
|
|
57
|
+
resourceProjectId: v.pipe(v.string(), v.uuid()),
|
|
58
|
+
resourceProjectName: v.pipe(v.string(), v.maxLength(256)),
|
|
59
|
+
resourceProjectHomeUri: v.nullable(v.string()),
|
|
60
|
+
resourcePublisherName: v.pipe(v.string(), v.maxLength(256)),
|
|
61
|
+
resourceServerOptional: v.boolean(),
|
|
62
|
+
detailPositions: v.array(v.pipe(v.number(), v.integer(), v.minValue(0))),
|
|
63
|
+
});
|
|
43
64
|
const AndCoAuthorizationClientSchema = /* @__PURE__ */ v.object({
|
|
44
65
|
id: v.pipe(v.string(), v.minLength(1), v.maxLength(255)),
|
|
45
66
|
name: v.pipe(v.string(), v.minLength(1), v.maxLength(255)),
|
|
@@ -79,7 +100,11 @@ const AndCoAuthorizationConsentRequiredSchema = /* @__PURE__ */ v.object({
|
|
|
79
100
|
client: AndCoAuthorizationClientSchema,
|
|
80
101
|
redirectHost: v.pipe(v.string(), v.minLength(1), v.maxLength(255)),
|
|
81
102
|
scopes: v.pipe(v.array(AndCoConsentScopeSchema), v.maxLength(50)),
|
|
82
|
-
|
|
103
|
+
// One live decision per third-party Resource Server asked for authorization details; any refused
|
|
104
|
+
// one blocks approval unless the person leaves that Resource Server out.
|
|
105
|
+
resourceAuthorizations: v.pipe(v.array(AndCoResourceConsentSchema), v.maxLength(10)),
|
|
106
|
+
// Every Resource Server the authorization names; empty for a Client without registered policies.
|
|
107
|
+
resourceServers: v.pipe(v.array(AndCoConsentResourceServerSchema), v.maxLength(10)),
|
|
83
108
|
organizationSubject: v.optional(v.object({ organizationId: v.number(), organizationName: v.string() })),
|
|
84
109
|
// Kept alongside `organizationSubject` for the native producer's still-current selection UI (consent-drawer.tsx,
|
|
85
110
|
// Tauri app.tsx): `organization_subject_required` (reason: "selection") absorbs this case once the platform's
|
|
@@ -155,6 +180,22 @@ export const AndCoAuthorizationCompletionSchema = /* @__PURE__ */ v.object({
|
|
|
155
180
|
decision: v.picklist(["approve", "deny"]),
|
|
156
181
|
redirectUrl: v.pipe(v.string(), v.minLength(1), v.maxLength(8192)),
|
|
157
182
|
});
|
|
183
|
+
/**
|
|
184
|
+
* The decision a native Host submits for one pending authorization: the chosen scopes and the
|
|
185
|
+
* optional Resource Servers the person left out whole (their details and own scopes are dropped;
|
|
186
|
+
* Platform refuses leaving out a required one), or a denial.
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* const decision: AndCoAuthorizationDecision = { decision: "approve", scopes: ["openid", "email"], omittedResourceServers: [casaNorteId] };
|
|
190
|
+
*/
|
|
191
|
+
export const AndCoAuthorizationDecisionSchema = /* @__PURE__ */ v.variant("decision", [
|
|
192
|
+
v.object({
|
|
193
|
+
decision: v.literal("approve"),
|
|
194
|
+
scopes: v.pipe(v.array(v.pipe(v.string(), v.minLength(1), v.maxLength(128))), v.maxLength(50)),
|
|
195
|
+
omittedResourceServers: v.pipe(v.array(v.pipe(v.string(), v.uuid())), v.maxLength(10)),
|
|
196
|
+
}),
|
|
197
|
+
v.object({ decision: v.literal("deny") }),
|
|
198
|
+
]);
|
|
158
199
|
export const AndCoAuthorizationErrorSchema = /* @__PURE__ */ v.object({
|
|
159
200
|
error: v.object({
|
|
160
201
|
code: v.pipe(v.string(), v.minLength(1), v.maxLength(128)),
|
package/dist/consent.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type { AndCoAuthorizationPreparation } from "./authorization-preparation.js";
|
|
2
|
-
type
|
|
1
|
+
import type { AndCoAuthorizationDecision, AndCoAuthorizationPreparation } from "./authorization-preparation.js";
|
|
2
|
+
type PreparedConsent = Extract<AndCoAuthorizationPreparation, {
|
|
3
3
|
status: "consent_required";
|
|
4
|
-
}
|
|
4
|
+
}>;
|
|
5
|
+
type PreparedConsentScope = PreparedConsent["scopes"][number];
|
|
5
6
|
/**
|
|
6
7
|
* Whether a Scope's checkbox may not be cleared: the Client's Scope Policy requires it, or an
|
|
7
8
|
* active OAuth Grant on this Connection already covers it and clearing the box would promise a
|
|
@@ -37,9 +38,83 @@ export type AndCoConsentScope = ReturnType<typeof ANDCO_CONSENT_SCOPES>[number];
|
|
|
37
38
|
export declare function ANDCO_CONSENT_INITIAL_SCOPES(consent: Extract<AndCoAuthorizationPreparation, {
|
|
38
39
|
status: "consent_required";
|
|
39
40
|
}>): Set<string>;
|
|
40
|
-
/**
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Groups a consent by Resource Server, in the order of the request's `resource` parameters: each one
|
|
43
|
+
* with its own scopes and, for a third party asked for details, its live decision. OpenID Connect
|
|
44
|
+
* scopes come through the Andco API's policies but belong to the Identity Session, so the Andco API's
|
|
45
|
+
* group owns none of them; they stay in `consent.scopes` for the identity section.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* const groups = ANDCO_CONSENT_RESOURCE_SERVER_GROUPS(consent);
|
|
49
|
+
* groups.map((group) => group.server.resourceServerName); // ["Andco API", "Casa Norte Ecommerce"]
|
|
50
|
+
*/
|
|
51
|
+
export declare function ANDCO_CONSENT_RESOURCE_SERVER_GROUPS(consent: PreparedConsent): {
|
|
52
|
+
server: {
|
|
53
|
+
resourceServerId: string;
|
|
54
|
+
resourcePosition: number;
|
|
55
|
+
resourceServerName: string;
|
|
56
|
+
resource: string;
|
|
57
|
+
resourceProjectId: string;
|
|
58
|
+
resourceProjectName: string;
|
|
59
|
+
resourceProjectHomeUri: string | null;
|
|
60
|
+
resourcePublisherName: string;
|
|
61
|
+
resourceServerOptional: boolean;
|
|
62
|
+
detailPositions: number[];
|
|
63
|
+
};
|
|
64
|
+
scopes: {
|
|
65
|
+
resourceServerId?: string | undefined;
|
|
66
|
+
resourceServerName?: string | undefined;
|
|
67
|
+
resourceProjectId?: string | undefined;
|
|
68
|
+
resourceProjectName?: string | undefined;
|
|
69
|
+
resourceProjectHomeUri?: string | null | undefined;
|
|
70
|
+
resourcePublisherName?: string | undefined;
|
|
71
|
+
scopeDescription?: string | undefined;
|
|
72
|
+
grantedAt: string | null;
|
|
73
|
+
connectionHasPriorGrant: boolean;
|
|
74
|
+
scope: string;
|
|
75
|
+
mode: "optional" | "default" | "required";
|
|
76
|
+
}[];
|
|
77
|
+
resourceAuthorization: {
|
|
78
|
+
allowed: boolean;
|
|
79
|
+
organizationId: string | null;
|
|
80
|
+
organizationName: string | null;
|
|
81
|
+
details: {
|
|
82
|
+
name: string;
|
|
83
|
+
actions: {
|
|
84
|
+
id: string;
|
|
85
|
+
description: string;
|
|
86
|
+
}[];
|
|
87
|
+
}[];
|
|
88
|
+
errorCode: string | null;
|
|
89
|
+
clientProjectName: string;
|
|
90
|
+
resourceServerId?: string | undefined;
|
|
91
|
+
resourceProjectId: string;
|
|
92
|
+
resourceProjectName?: string | undefined;
|
|
93
|
+
resourceProjectHomeUri?: string | null | undefined;
|
|
94
|
+
resourcePublisherName?: string | undefined;
|
|
95
|
+
resourceName: string;
|
|
96
|
+
resource: string;
|
|
97
|
+
} | undefined;
|
|
98
|
+
}[];
|
|
99
|
+
/** One Resource Server group of a native consent; see {@link ANDCO_CONSENT_RESOURCE_SERVER_GROUPS}. */
|
|
100
|
+
export type AndCoConsentResourceServerGroup = ReturnType<typeof ANDCO_CONSENT_RESOURCE_SERVER_GROUPS>[number];
|
|
101
|
+
/**
|
|
102
|
+
* Whether the in-progress selection is complete enough to submit; the server still authorizes on
|
|
103
|
+
* submit. `omitted` holds the optional Resource Servers the person left out: their scopes stop
|
|
104
|
+
* counting and a refused decision of theirs stops blocking.
|
|
105
|
+
*/
|
|
106
|
+
export declare function ANDCO_CONSENT_CAN_SUBMIT(consent: PreparedConsent, scopes: ReadonlySet<string>, omitted?: ReadonlySet<string>): boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Builds the approval a native Host submits: the selected scopes without those of the Resource
|
|
109
|
+
* Servers left out, and the left-out ones by id. Throws when asked to leave out a Resource Server the
|
|
110
|
+
* consent does not name or one that is required; a surface only offers optional ones.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ANDCO_CONSENT_DECISION(consent, new Set(["openid", "email", "orders:read"]), new Set([casaNorteId]));
|
|
114
|
+
* // { decision: "approve", scopes: ["openid", "email"], omittedResourceServers: [casaNorteId] }
|
|
115
|
+
*/
|
|
116
|
+
export declare function ANDCO_CONSENT_DECISION(consent: PreparedConsent, scopes: ReadonlySet<string>, omitted?: ReadonlySet<string>): Extract<AndCoAuthorizationDecision, {
|
|
117
|
+
decision: "approve";
|
|
118
|
+
}>;
|
|
44
119
|
export {};
|
|
45
120
|
//# sourceMappingURL=consent.d.ts.map
|
package/dist/consent.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consent.d.ts","sourceRoot":"","sources":["../src/consent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"consent.d.ts","sourceRoot":"","sources":["../src/consent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,6BAA6B,EAAE,MAAM,gCAAgC,CAAC;AAYhH,KAAK,eAAe,GAAG,OAAO,CAAC,6BAA6B,EAAE;IAAE,MAAM,E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,EAAE;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,CAAC,CAc9D"}
|
package/dist/consent.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ANDCO_API_ORIGIN } from "./constants.js";
|
|
1
2
|
import { ANDCO_NATIVE_TEXT as t } from "./native-copy.js";
|
|
2
3
|
const SCOPE_LABELS = {
|
|
3
4
|
openid: "Identidad OpenID",
|
|
@@ -44,10 +45,67 @@ export function ANDCO_CONSENT_INITIAL_SCOPES(consent) {
|
|
|
44
45
|
.filter((scope) => scope.mode !== "optional" || scope.grantedAt !== null || scope.connectionHasPriorGrant)
|
|
45
46
|
.map((scope) => scope.scope));
|
|
46
47
|
}
|
|
47
|
-
/**
|
|
48
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Groups a consent by Resource Server, in the order of the request's `resource` parameters: each one
|
|
50
|
+
* with its own scopes and, for a third party asked for details, its live decision. OpenID Connect
|
|
51
|
+
* scopes come through the Andco API's policies but belong to the Identity Session, so the Andco API's
|
|
52
|
+
* group owns none of them; they stay in `consent.scopes` for the identity section.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* const groups = ANDCO_CONSENT_RESOURCE_SERVER_GROUPS(consent);
|
|
56
|
+
* groups.map((group) => group.server.resourceServerName); // ["Andco API", "Casa Norte Ecommerce"]
|
|
57
|
+
*/
|
|
58
|
+
export function ANDCO_CONSENT_RESOURCE_SERVER_GROUPS(consent) {
|
|
59
|
+
return [...consent.resourceServers]
|
|
60
|
+
.sort((left, right) => left.resourcePosition - right.resourcePosition)
|
|
61
|
+
.map((server) => ({
|
|
62
|
+
server,
|
|
63
|
+
scopes: server.resource === ANDCO_API_ORIGIN
|
|
64
|
+
? []
|
|
65
|
+
: consent.scopes.filter((scope) => scope.resourceServerId === server.resourceServerId),
|
|
66
|
+
resourceAuthorization: consent.resourceAuthorizations.find((authorization) => authorization.resourceServerId === server.resourceServerId),
|
|
67
|
+
}));
|
|
68
|
+
}
|
|
69
|
+
/** The scopes owned by the Resource Servers left out, which the decision never submits. */
|
|
70
|
+
function OMITTED_SCOPES(consent, omitted) {
|
|
71
|
+
return new Set(ANDCO_CONSENT_RESOURCE_SERVER_GROUPS(consent)
|
|
72
|
+
.filter((group) => omitted.has(group.server.resourceServerId))
|
|
73
|
+
.flatMap((group) => group.scopes.map((scope) => scope.scope)));
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Whether the in-progress selection is complete enough to submit; the server still authorizes on
|
|
77
|
+
* submit. `omitted` holds the optional Resource Servers the person left out: their scopes stop
|
|
78
|
+
* counting and a refused decision of theirs stops blocking.
|
|
79
|
+
*/
|
|
80
|
+
export function ANDCO_CONSENT_CAN_SUBMIT(consent, scopes, omitted = new Set()) {
|
|
81
|
+
const droppedScopes = OMITTED_SCOPES(consent, omitted);
|
|
82
|
+
const kept = consent.resourceAuthorizations.filter((authorization) => !omitted.has(authorization.resourceServerId ?? ""));
|
|
49
83
|
return (!consent.organizationSelection &&
|
|
50
|
-
(scopes.
|
|
51
|
-
(
|
|
52
|
-
consent.scopes.every((scope) => scope.mode !== "required" || scopes.has(scope.scope)));
|
|
84
|
+
([...scopes].some((scope) => !droppedScopes.has(scope)) || kept.length > 0) &&
|
|
85
|
+
kept.every((authorization) => authorization.allowed) &&
|
|
86
|
+
consent.scopes.every((scope) => scope.mode !== "required" || droppedScopes.has(scope.scope) || scopes.has(scope.scope)));
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Builds the approval a native Host submits: the selected scopes without those of the Resource
|
|
90
|
+
* Servers left out, and the left-out ones by id. Throws when asked to leave out a Resource Server the
|
|
91
|
+
* consent does not name or one that is required; a surface only offers optional ones.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ANDCO_CONSENT_DECISION(consent, new Set(["openid", "email", "orders:read"]), new Set([casaNorteId]));
|
|
95
|
+
* // { decision: "approve", scopes: ["openid", "email"], omittedResourceServers: [casaNorteId] }
|
|
96
|
+
*/
|
|
97
|
+
export function ANDCO_CONSENT_DECISION(consent, scopes, omitted = new Set()) {
|
|
98
|
+
for (const resourceServerId of omitted) {
|
|
99
|
+
const server = consent.resourceServers.find((candidate) => candidate.resourceServerId === resourceServerId);
|
|
100
|
+
if (!server?.resourceServerOptional) {
|
|
101
|
+
throw new TypeError(`[ANDCO_CONSENT_DECISION] Resource Server ${resourceServerId} is required or not named`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const droppedScopes = OMITTED_SCOPES(consent, omitted);
|
|
105
|
+
console.debug("[ANDCO_CONSENT_DECISION] approving %s without %o", consent.authorizationId, [...omitted]);
|
|
106
|
+
return {
|
|
107
|
+
decision: "approve",
|
|
108
|
+
scopes: [...scopes].filter((scope) => !droppedScopes.has(scope)),
|
|
109
|
+
omittedResourceServers: [...omitted],
|
|
110
|
+
};
|
|
53
111
|
}
|
package/dist/errors.d.ts
CHANGED
|
@@ -106,6 +106,11 @@ export declare const ANDCO_ERROR_CODES: {
|
|
|
106
106
|
readonly DEVICE_EXCHANGE_FAILED: "device_exchange_failed";
|
|
107
107
|
/** Exchanging a refresh token for a new session failed. The Grant may have been revoked. */
|
|
108
108
|
readonly REFRESH_FAILED: "refresh_failed";
|
|
109
|
+
/**
|
|
110
|
+
* `POST /oauth/revoke` (RFC 7009) did not answer 200: the token belongs to another client, the
|
|
111
|
+
* client could not authenticate, or the request never arrived. The token is kept, so retry.
|
|
112
|
+
*/
|
|
113
|
+
readonly REVOCATION_FAILED: "revocation_failed";
|
|
109
114
|
/** Fetching the OpenID Connect UserInfo endpoint failed. */
|
|
110
115
|
readonly USERINFO_FAILED: "userinfo_failed";
|
|
111
116
|
/** A callback could not be correlated with the transaction that started it, so it is not trusted. */
|
|
@@ -114,6 +119,11 @@ export declare const ANDCO_ERROR_CODES: {
|
|
|
114
119
|
readonly INVALID_TOKEN_RESPONSE: "invalid_token_response";
|
|
115
120
|
/** An operation that needs a session ran without one. Actionable: send the person to authorize. */
|
|
116
121
|
readonly SESSION_MISSING: "session_missing";
|
|
122
|
+
/**
|
|
123
|
+
* The session holds no Resource Token for the requested Resource Indicator. Never answered with
|
|
124
|
+
* the Identity Session's token or another audience's: authorize that Resource Server first.
|
|
125
|
+
*/
|
|
126
|
+
readonly NO_TOKEN_FOR_RESOURCE: "no_token_for_resource";
|
|
117
127
|
/** Reading or writing the session store failed -- private browsing, or storage the browser denied. */
|
|
118
128
|
readonly STORAGE_FAILED: "storage_failed";
|
|
119
129
|
/**
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;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,qEAAqE;;IAErE,0EAA0E;;IAE1E,6DAA6D;;IAE7D,gEAAgE;;IAEhE,8EAA8E;;IAE9E,4FAA4F;;IAE5F,4DAA4D;;IAE5D,qGAAqG;;IAErG,wGAAwG;;IAExG,mGAAmG;;IAEnG,sGAAsG;;IAGtG;;;OAGG;;IAEH,2FAA2F;;IAI3F;;;OAGG;;IAEH;;;;OAIG;;IAEH,yDAAyD;;IAIzD,qGAAqG;;C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EtF;;;OAGG;;IAEH;;;;OAIG;;IAIH,sGAAsG;;IAEtG,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;;;OAGG;;IAEH;;;;OAIG;;IAEH,yDAAyD;;IAIzD,qGAAqG;;CAE7F,CAAC;AAEX,6DAA6D;AAC7D,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,OAAO,iBAAiB,CAAC,CAAC;AAExF;;;;;;;;GAQG;AACH,eAAO,MAAM,wBAAwB,2UAgB3B,CAAC;AAEX,gEAAgE;AAChE,qBAAa,eAAgB,SAAQ,KAAK;gBACrB,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;IAM3D,+DAA+D;WACjD,EAAE,CAAC,CAAC,SAAS,eAAe,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,KAAK,IAAI,CAAC;CAG/G;AAED,oEAAoE;AACpE,qBAAa,aAAc,SAAQ,eAAe;IAChD,SAAgB,IAAI,EAAE,cAAc,CAAC;IACrC,SAAgB,OAAO,EAAE,OAAO,CAAC;gBAEd,IAAI,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,YAAY;CAKnF"}
|
package/dist/errors.js
CHANGED
|
@@ -112,6 +112,11 @@ export const ANDCO_ERROR_CODES = {
|
|
|
112
112
|
DEVICE_EXCHANGE_FAILED: "device_exchange_failed",
|
|
113
113
|
/** Exchanging a refresh token for a new session failed. The Grant may have been revoked. */
|
|
114
114
|
REFRESH_FAILED: "refresh_failed",
|
|
115
|
+
/**
|
|
116
|
+
* `POST /oauth/revoke` (RFC 7009) did not answer 200: the token belongs to another client, the
|
|
117
|
+
* client could not authenticate, or the request never arrived. The token is kept, so retry.
|
|
118
|
+
*/
|
|
119
|
+
REVOCATION_FAILED: "revocation_failed",
|
|
115
120
|
/** Fetching the OpenID Connect UserInfo endpoint failed. */
|
|
116
121
|
USERINFO_FAILED: "userinfo_failed",
|
|
117
122
|
/** A callback could not be correlated with the transaction that started it, so it is not trusted. */
|
|
@@ -120,6 +125,11 @@ export const ANDCO_ERROR_CODES = {
|
|
|
120
125
|
INVALID_TOKEN_RESPONSE: "invalid_token_response",
|
|
121
126
|
/** An operation that needs a session ran without one. Actionable: send the person to authorize. */
|
|
122
127
|
SESSION_MISSING: "session_missing",
|
|
128
|
+
/**
|
|
129
|
+
* The session holds no Resource Token for the requested Resource Indicator. Never answered with
|
|
130
|
+
* the Identity Session's token or another audience's: authorize that Resource Server first.
|
|
131
|
+
*/
|
|
132
|
+
NO_TOKEN_FOR_RESOURCE: "no_token_for_resource",
|
|
123
133
|
/** Reading or writing the session store failed -- private browsing, or storage the browser denied. */
|
|
124
134
|
STORAGE_FAILED: "storage_failed",
|
|
125
135
|
/**
|
package/dist/native-copy.js
CHANGED
|
@@ -279,6 +279,22 @@ const COPY = {
|
|
|
279
279
|
"Esta Miniapp podrá": ["This Miniapp will be able to", "Esta Miniapp poderá", "Esta Miniapp podrá"],
|
|
280
280
|
"Sin número visible": ["No visible number", "Sem número visível", "Sin número visible"],
|
|
281
281
|
Requerido: ["Required", "Obrigatório", "Requerido"],
|
|
282
|
+
"Compartir con {{name}}": ["Share with {{name}}", "Compartilhar com {{name}}", "Compartir con {{name}}"],
|
|
283
|
+
"Opcional: puedes autorizar sin este proveedor.": [
|
|
284
|
+
"Optional: you can authorize without this provider.",
|
|
285
|
+
"Opcional: você pode autorizar sem este provedor.",
|
|
286
|
+
"Opcional: puedes autorizar sin este proveedor.",
|
|
287
|
+
],
|
|
288
|
+
"No se compartirá nada con {{name}}.": [
|
|
289
|
+
"Nothing will be shared with {{name}}.",
|
|
290
|
+
"Nada será compartilhado com {{name}}.",
|
|
291
|
+
"No se compartirá nada con {{name}}.",
|
|
292
|
+
],
|
|
293
|
+
"Requerido: la aplicación necesita todos estos permisos.": [
|
|
294
|
+
"Required: the application needs all of these permissions.",
|
|
295
|
+
"Obrigatório: o aplicativo precisa de todas estas permissões.",
|
|
296
|
+
"Requerido: la aplicación necesita todos estos permisos.",
|
|
297
|
+
],
|
|
282
298
|
Preseleccionado: ["Preselected", "Pré-selecionado", "Preseleccionado"],
|
|
283
299
|
Opcional: ["Optional", "Opcional", "Opcional"],
|
|
284
300
|
"Concedido el {{date}}": ["Granted on {{date}}", "Concedido em {{date}}", "Concedido el {{date}}"],
|
package/dist/service-grants.d.ts
CHANGED
|
@@ -19,7 +19,8 @@ export declare const ServiceGrantSchema: v.ObjectSchema<{
|
|
|
19
19
|
}, undefined>;
|
|
20
20
|
readonly resource: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UrlAction<string, undefined>]>;
|
|
21
21
|
readonly createdAt: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.CheckAction<string, undefined>]>;
|
|
22
|
-
|
|
22
|
+
/** `expired`: its expiry passed (ADR 0034); like `revoked`, it stays in the authorizations history. */
|
|
23
|
+
readonly status: v.PicklistSchema<["active", "revoked", "expired"], undefined>;
|
|
23
24
|
readonly version: v.StringSchema<undefined>;
|
|
24
25
|
readonly scopes: v.ArraySchema<v.StringSchema<undefined>, undefined>;
|
|
25
26
|
readonly authorizationDetails: v.ArraySchema<v.RecordSchema<v.StringSchema<undefined>, v.UnknownSchema, undefined>, undefined>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service-grants.d.ts","sourceRoot":"","sources":["../src/service-grants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,gCAAgC,EAAE,MAAM,kBAAkB,CAAC;AAEpE;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB
|
|
1
|
+
{"version":3,"file":"service-grants.d.ts","sourceRoot":"","sources":["../src/service-grants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,gCAAgC,EAAE,MAAM,kBAAkB,CAAC;AAEpE;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;IAS7B,uGAAuG;;;;;aAKvG,CAAC;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,kBAAkB,CAAC,CAAC;AACpE,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,YAAY,EAAE,CAE1E;AACD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,gCAAgC,CAAC,CAE1G;AACD,eAAO,MAAM,kBAAkB;;;;;aAK7B,CAAC;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,kBAAkB,CAAC,CAE1F"}
|
package/dist/service-grants.js
CHANGED
|
@@ -16,7 +16,8 @@ export const ServiceGrantSchema = /* @__PURE__ */ v.object({
|
|
|
16
16
|
subject: GrantedOrganizationSubjectSchema,
|
|
17
17
|
resource: v.pipe(v.string(), v.url()),
|
|
18
18
|
createdAt: v.pipe(v.string(), v.check((date) => Number.isFinite(Date.parse(date)))),
|
|
19
|
-
|
|
19
|
+
/** `expired`: its expiry passed (ADR 0034); like `revoked`, it stays in the authorizations history. */
|
|
20
|
+
status: v.picklist(["active", "revoked", "expired"]),
|
|
20
21
|
version: v.string(),
|
|
21
22
|
scopes: v.array(v.string()),
|
|
22
23
|
authorizationDetails: v.array(v.record(v.string(), v.unknown())),
|
package/dist/webhooks.d.ts
CHANGED
|
@@ -41,7 +41,7 @@ export declare const ANDCO_WEBHOOK_ERROR_CODES: {
|
|
|
41
41
|
readonly UNKNOWN_KEY: "webhook_unknown_key";
|
|
42
42
|
/** The signature does not match the signed content. */
|
|
43
43
|
readonly INVALID_SIGNATURE: "webhook_invalid_signature";
|
|
44
|
-
/** The body is not an event,
|
|
44
|
+
/** The body is not an event, its `id` differs from `andco-event-id`, or a `grant.*` payload is malformed. */
|
|
45
45
|
readonly INVALID_PAYLOAD: "webhook_invalid_payload";
|
|
46
46
|
/** The JWKS could not be fetched or is not a JWKS. */
|
|
47
47
|
readonly JWKS_UNAVAILABLE: "webhook_jwks_unavailable";
|
|
@@ -67,14 +67,18 @@ export declare class AndcoWebhookError extends Error {
|
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
69
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
70
|
+
* The envelope every Andco webhook event shares, with its `type` and `payload`.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* type Paid = AndcoWebhookEnvelope<"deposit.completed", { intent_id: string }>;
|
|
75
|
+
* ```
|
|
72
76
|
*/
|
|
73
|
-
export type
|
|
77
|
+
export type AndcoWebhookEnvelope<T extends string, P> = {
|
|
74
78
|
/** Stable event id, equal to `andco-event-id`. Deduplicate durable effects by it. */
|
|
75
79
|
id: string;
|
|
76
|
-
/** Event type, such as `deposit.completed` or `
|
|
77
|
-
type:
|
|
80
|
+
/** Event type, such as `deposit.completed` or `grant.revoked`. */
|
|
81
|
+
type: T;
|
|
78
82
|
version: 1;
|
|
79
83
|
/** ISO 8601 instant of the fact. */
|
|
80
84
|
occurred_at: string;
|
|
@@ -85,8 +89,59 @@ export type AndcoWebhookEvent = {
|
|
|
85
89
|
/** Opaque position of the event in its subject's replay feed. */
|
|
86
90
|
cursor: string;
|
|
87
91
|
/** Event-specific facts. Money values are strings. */
|
|
88
|
-
payload:
|
|
92
|
+
payload: P;
|
|
89
93
|
};
|
|
94
|
+
/** Why a Grant was revoked: by the person (Platform, the native Host, Andco) or by the client (`/oauth/revoke`). */
|
|
95
|
+
export type AndcoGrantRevocationReason = "revoked_by_person" | "revoked_by_client";
|
|
96
|
+
/**
|
|
97
|
+
* A Grant was revoked (ADR 0034): its tokens are useless now; delete the ones you keep and ask for
|
|
98
|
+
* consent again.
|
|
99
|
+
*/
|
|
100
|
+
export type AndcoGrantRevokedEvent = AndcoWebhookEnvelope<"grant.revoked", {
|
|
101
|
+
grant_id: string;
|
|
102
|
+
client_id: string;
|
|
103
|
+
resource: string;
|
|
104
|
+
reason: AndcoGrantRevocationReason;
|
|
105
|
+
revoked_at: string;
|
|
106
|
+
}>;
|
|
107
|
+
/** A Grant reached the expiry the person chose: its tokens are useless now; ask for consent again. */
|
|
108
|
+
export type AndcoGrantExpiredEvent = AndcoWebhookEnvelope<"grant.expired", {
|
|
109
|
+
grant_id: string;
|
|
110
|
+
client_id: string;
|
|
111
|
+
resource: string;
|
|
112
|
+
expires_at: string;
|
|
113
|
+
}>;
|
|
114
|
+
/** The person changed a Grant's expiry; `expires_at` is `null` when they removed it. */
|
|
115
|
+
export type AndcoGrantUpdatedEvent = AndcoWebhookEnvelope<"grant.updated", {
|
|
116
|
+
grant_id: string;
|
|
117
|
+
client_id: string;
|
|
118
|
+
resource: string;
|
|
119
|
+
expires_at: string | null;
|
|
120
|
+
}>;
|
|
121
|
+
/**
|
|
122
|
+
* A Grant lifecycle event: the only events delivered although their Grant is no longer active.
|
|
123
|
+
* Narrow to it with `andcoWebhooks.isGrantEvent(event)`, then on `type`.
|
|
124
|
+
*/
|
|
125
|
+
export type AndcoGrantWebhookEvent = AndcoGrantRevokedEvent | AndcoGrantExpiredEvent | AndcoGrantUpdatedEvent;
|
|
126
|
+
/** The Grant lifecycle event types the verifier checks and types. */
|
|
127
|
+
export declare const ANDCO_WEBHOOK_GRANT_EVENT_TYPES: readonly ["grant.revoked", "grant.expired", "grant.updated"];
|
|
128
|
+
/**
|
|
129
|
+
* One Andco event as delivered to a Project's webhook endpoint. Every event of every client of the
|
|
130
|
+
* Project arrives at the same endpoint: filter by `client_id`, `grant_id` or `type` yourself.
|
|
131
|
+
*
|
|
132
|
+
* Grant lifecycle events arrive typed and their payload is checked; narrow with
|
|
133
|
+
* `andcoWebhooks.isGrantEvent(event)`, since a plain `type` comparison cannot rule out the untyped
|
|
134
|
+
* member. Every other event carries its payload as a record.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* const event = await verify(request);
|
|
139
|
+
* if (andcoWebhooks.isGrantEvent(event) && event.type === "grant.revoked") {
|
|
140
|
+
* await forgetTokens(event.payload.grant_id, event.payload.reason);
|
|
141
|
+
* }
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
export type AndcoWebhookEvent = AndcoGrantWebhookEvent | AndcoWebhookEnvelope<string, Record<string, unknown>>;
|
|
90
145
|
/** A raw delivery, for runtimes that do not hand the handler a Fetch `Request`. */
|
|
91
146
|
export type AndcoWebhookDelivery = {
|
|
92
147
|
/** The exact request body, before any JSON parsing. Re-serialized JSON does not verify. */
|
|
@@ -106,6 +161,18 @@ export type AndcoWebhookVerifierOptions = {
|
|
|
106
161
|
};
|
|
107
162
|
/** Verifies one delivery and returns its event, or throws {@link AndcoWebhookError}. */
|
|
108
163
|
export type AndcoWebhookVerify = (delivery: Request | AndcoWebhookDelivery) => Promise<AndcoWebhookEvent>;
|
|
164
|
+
/**
|
|
165
|
+
* Whether an event is a Grant lifecycle event (`grant.revoked`, `grant.expired`, `grant.updated`),
|
|
166
|
+
* whose payload the verifier already checked. Narrows the event so `type` then picks the payload.
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```ts
|
|
170
|
+
* if (andcoWebhooks.isGrantEvent(event)) {
|
|
171
|
+
* if (event.type === "grant.updated") console.log(event.payload.expires_at); // string | null
|
|
172
|
+
* }
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
declare function isGrantEvent(event: AndcoWebhookEvent): event is AndcoGrantWebhookEvent;
|
|
109
176
|
/**
|
|
110
177
|
* Creates a verifier for Andco webhook deliveries.
|
|
111
178
|
*
|
|
@@ -129,6 +196,7 @@ export type AndcoWebhookVerify = (delivery: Request | AndcoWebhookDelivery) => P
|
|
|
129
196
|
* export async function POST(request: Request) {
|
|
130
197
|
* const event = await verify(request);
|
|
131
198
|
* if (event.type === "deposit.completed") await markPaid(event.payload["intent_id"] as string);
|
|
199
|
+
* if (andcoWebhooks.isGrantEvent(event) && event.type !== "grant.updated") await forgetTokens(event.payload.grant_id);
|
|
132
200
|
* return new Response(null, { status: 204 });
|
|
133
201
|
* }
|
|
134
202
|
* ```
|
|
@@ -142,13 +210,14 @@ export type AndcoWebhookVerify = (delivery: Request | AndcoWebhookDelivery) => P
|
|
|
142
210
|
*/
|
|
143
211
|
declare function verifier(options?: AndcoWebhookVerifierOptions): AndcoWebhookVerify;
|
|
144
212
|
/**
|
|
145
|
-
* Receiving Andco webhooks. See {@link verifier}.
|
|
213
|
+
* Receiving Andco webhooks. See {@link verifier} and {@link isGrantEvent}.
|
|
146
214
|
*
|
|
147
215
|
* @example
|
|
148
216
|
* const verify = andcoWebhooks.verifier();
|
|
149
217
|
*/
|
|
150
218
|
export declare const andcoWebhooks: {
|
|
151
219
|
readonly verifier: typeof verifier;
|
|
220
|
+
readonly isGrantEvent: typeof isGrantEvent;
|
|
152
221
|
};
|
|
153
222
|
export {};
|
|
154
223
|
//# sourceMappingURL=webhooks.d.ts.map
|
package/dist/webhooks.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webhooks.d.ts","sourceRoot":"","sources":["../src/webhooks.ts"],"names":[],"mappings":"AAEA,uDAAuD;AACvD,eAAO,MAAM,qBAAqB;;;;CAIxB,CAAC;AAEX,wEAAwE;AACxE,eAAO,MAAM,uBAAuB,EAAG,SAAkB,CAAC;AAE1D,oFAAoF;AACpF,eAAO,MAAM,+BAA+B,M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AI,sBAAsB,CAE/E;AAuBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,iBAAS,QAAQ,CAAC,OAAO,GAAE,2BAAgC,GAAG,kBAAkB,CAiG/E;AAED;;;;;GAKG;AACH,eAAO,MAAM,aAAa;;;CAAsC,CAAC"}
|
package/dist/webhooks.js
CHANGED
|
@@ -46,7 +46,7 @@ export const ANDCO_WEBHOOK_ERROR_CODES = {
|
|
|
46
46
|
UNKNOWN_KEY: "webhook_unknown_key",
|
|
47
47
|
/** The signature does not match the signed content. */
|
|
48
48
|
INVALID_SIGNATURE: "webhook_invalid_signature",
|
|
49
|
-
/** The body is not an event,
|
|
49
|
+
/** The body is not an event, its `id` differs from `andco-event-id`, or a `grant.*` payload is malformed. */
|
|
50
50
|
INVALID_PAYLOAD: "webhook_invalid_payload",
|
|
51
51
|
/** The JWKS could not be fetched or is not a JWKS. */
|
|
52
52
|
JWKS_UNAVAILABLE: "webhook_jwks_unavailable",
|
|
@@ -71,6 +71,8 @@ export class AndcoWebhookError extends Error {
|
|
|
71
71
|
this.code = code;
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
|
+
/** The Grant lifecycle event types the verifier checks and types. */
|
|
75
|
+
export const ANDCO_WEBHOOK_GRANT_EVENT_TYPES = ["grant.revoked", "grant.expired", "grant.updated"];
|
|
74
76
|
const SIGNATURE_HEADER = /^\s*kid=([A-Za-z0-9._:-]{1,128})\s*,\s*alg=([A-Za-z0-9]+)\s*,\s*sig=([A-Za-z0-9_-]+)\s*$/;
|
|
75
77
|
/** A new `kid` triggers at most one JWKS refresh per this interval, so forged kids cannot flood Andco. */
|
|
76
78
|
const UNKNOWN_KID_REFRESH_MS = 60_000;
|
|
@@ -112,6 +114,41 @@ function isEvent(value) {
|
|
|
112
114
|
typeof event["payload"] === "object" &&
|
|
113
115
|
!Array.isArray(event["payload"]));
|
|
114
116
|
}
|
|
117
|
+
/**
|
|
118
|
+
* Whether an event is a Grant lifecycle event (`grant.revoked`, `grant.expired`, `grant.updated`),
|
|
119
|
+
* whose payload the verifier already checked. Narrows the event so `type` then picks the payload.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```ts
|
|
123
|
+
* if (andcoWebhooks.isGrantEvent(event)) {
|
|
124
|
+
* if (event.type === "grant.updated") console.log(event.payload.expires_at); // string | null
|
|
125
|
+
* }
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
function isGrantEvent(event) {
|
|
129
|
+
return ANDCO_WEBHOOK_GRANT_EVENT_TYPES.includes(event.type);
|
|
130
|
+
}
|
|
131
|
+
/** Whether a lifecycle event's payload has the shape its type promises; other events pass. */
|
|
132
|
+
function hasLifecyclePayload(event) {
|
|
133
|
+
if (!isGrantEvent(event))
|
|
134
|
+
return true;
|
|
135
|
+
const payload = event.payload;
|
|
136
|
+
const named = typeof payload["grant_id"] === "string" &&
|
|
137
|
+
typeof payload["client_id"] === "string" &&
|
|
138
|
+
typeof payload["resource"] === "string";
|
|
139
|
+
if (!named)
|
|
140
|
+
return false;
|
|
141
|
+
if (event.type === "grant.revoked") {
|
|
142
|
+
return ((payload["reason"] === "revoked_by_person" || payload["reason"] === "revoked_by_client") &&
|
|
143
|
+
typeof payload["revoked_at"] === "string");
|
|
144
|
+
}
|
|
145
|
+
else if (event.type === "grant.expired") {
|
|
146
|
+
return typeof payload["expires_at"] === "string";
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
return typeof payload["expires_at"] === "string" || payload["expires_at"] === null;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
115
152
|
/**
|
|
116
153
|
* Creates a verifier for Andco webhook deliveries.
|
|
117
154
|
*
|
|
@@ -135,6 +172,7 @@ function isEvent(value) {
|
|
|
135
172
|
* export async function POST(request: Request) {
|
|
136
173
|
* const event = await verify(request);
|
|
137
174
|
* if (event.type === "deposit.completed") await markPaid(event.payload["intent_id"] as string);
|
|
175
|
+
* if (andcoWebhooks.isGrantEvent(event) && event.type !== "grant.updated") await forgetTokens(event.payload.grant_id);
|
|
138
176
|
* return new Response(null, { status: 204 });
|
|
139
177
|
* }
|
|
140
178
|
* ```
|
|
@@ -237,13 +275,17 @@ function verifier(options = {}) {
|
|
|
237
275
|
}
|
|
238
276
|
if (!isEvent(event) || event.id !== eventId)
|
|
239
277
|
throw new AndcoWebhookError(ANDCO_WEBHOOK_ERROR_CODES.INVALID_PAYLOAD);
|
|
278
|
+
if (!hasLifecyclePayload(event)) {
|
|
279
|
+
console.debug("[andcoWebhooks.verify] %s %s has a payload that does not match its type", event.type, eventId);
|
|
280
|
+
throw new AndcoWebhookError(ANDCO_WEBHOOK_ERROR_CODES.INVALID_PAYLOAD);
|
|
281
|
+
}
|
|
240
282
|
return event;
|
|
241
283
|
};
|
|
242
284
|
}
|
|
243
285
|
/**
|
|
244
|
-
* Receiving Andco webhooks. See {@link verifier}.
|
|
286
|
+
* Receiving Andco webhooks. See {@link verifier} and {@link isGrantEvent}.
|
|
245
287
|
*
|
|
246
288
|
* @example
|
|
247
289
|
* const verify = andcoWebhooks.verifier();
|
|
248
290
|
*/
|
|
249
|
-
export const andcoWebhooks = { verifier };
|
|
291
|
+
export const andcoWebhooks = { verifier, isGrantEvent };
|