@andco/protocol 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +44 -0
- package/dist/authorization-preparation.d.ts +754 -0
- package/dist/authorization-preparation.d.ts.map +1 -0
- package/dist/authorization-preparation.js +187 -0
- package/dist/authorization.d.ts +99 -0
- package/dist/authorization.d.ts.map +1 -0
- package/dist/authorization.js +227 -0
- package/dist/automatic-charge.d.ts +314 -0
- package/dist/automatic-charge.d.ts.map +1 -0
- package/dist/automatic-charge.js +126 -0
- package/dist/bank-account-authorization.d.ts +6 -0
- package/dist/bank-account-authorization.d.ts.map +1 -0
- package/dist/bank-account-authorization.js +13 -0
- package/dist/callback-state.d.ts +10 -0
- package/dist/callback-state.d.ts.map +1 -0
- package/dist/callback-state.js +28 -0
- package/dist/consent.d.ts +48 -0
- package/dist/consent.d.ts.map +1 -0
- package/dist/consent.js +110 -0
- package/dist/constants.d.ts +17 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +20 -0
- package/dist/errors.d.ts +70 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +80 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/intent-input.d.ts +637 -0
- package/dist/intent-input.d.ts.map +1 -0
- package/dist/intent-input.js +101 -0
- package/dist/messages/authorization-response.d.ts +12 -0
- package/dist/messages/authorization-response.d.ts.map +1 -0
- package/dist/messages/authorization-response.js +9 -0
- package/dist/messages/base.d.ts +31 -0
- package/dist/messages/base.d.ts.map +1 -0
- package/dist/messages/base.js +30 -0
- package/dist/messages/click.d.ts +11 -0
- package/dist/messages/click.d.ts.map +1 -0
- package/dist/messages/click.js +8 -0
- package/dist/messages/error.d.ts +13 -0
- package/dist/messages/error.d.ts.map +1 -0
- package/dist/messages/error.js +9 -0
- package/dist/messages/index.d.ts +75 -0
- package/dist/messages/index.d.ts.map +1 -0
- package/dist/messages/index.js +27 -0
- package/dist/messages/init.d.ts +9 -0
- package/dist/messages/init.d.ts.map +1 -0
- package/dist/messages/init.js +6 -0
- package/dist/messages/popup.d.ts +108 -0
- package/dist/messages/popup.d.ts.map +1 -0
- package/dist/messages/popup.js +62 -0
- package/dist/messages/ready.d.ts +9 -0
- package/dist/messages/ready.d.ts.map +1 -0
- package/dist/messages/ready.js +6 -0
- package/dist/messages/set-preferences.d.ts +16 -0
- package/dist/messages/set-preferences.d.ts.map +1 -0
- package/dist/messages/set-preferences.js +20 -0
- package/dist/miniapp-icon.d.ts +4 -0
- package/dist/miniapp-icon.d.ts.map +1 -0
- package/dist/miniapp-icon.js +68 -0
- package/dist/miniapp-manifest.d.ts +71 -0
- package/dist/miniapp-manifest.d.ts.map +1 -0
- package/dist/miniapp-manifest.js +46 -0
- package/dist/native-copy.d.ts +7 -0
- package/dist/native-copy.d.ts.map +1 -0
- package/dist/native-copy.js +436 -0
- package/dist/native-intent.d.ts +402 -0
- package/dist/native-intent.d.ts.map +1 -0
- package/dist/native-intent.js +410 -0
- package/dist/native.d.ts +55 -0
- package/dist/native.d.ts.map +1 -0
- package/dist/native.js +53 -0
- package/dist/oauth.d.ts +4 -0
- package/dist/oauth.d.ts.map +1 -0
- package/dist/oauth.js +3 -0
- package/dist/release.d.ts +3 -0
- package/dist/release.d.ts.map +1 -0
- package/dist/release.js +2 -0
- package/dist/scopes.d.ts +35 -0
- package/dist/scopes.d.ts.map +1 -0
- package/dist/scopes.js +15 -0
- package/dist/server.d.ts +9 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +14 -0
- package/dist/transport/financial-events.d.ts +134 -0
- package/dist/transport/financial-events.d.ts.map +1 -0
- package/dist/transport/financial-events.js +120 -0
- package/dist/transport/generated/oauth-api.d.ts +1685 -0
- package/dist/transport/generated/oauth-api.d.ts.map +1 -0
- package/dist/transport/generated/oauth-api.js +5 -0
- package/dist/transport/index.d.ts +6 -0
- package/dist/transport/index.d.ts.map +1 -0
- package/dist/transport/index.js +5 -0
- package/dist/transport/intents.d.ts +81 -0
- package/dist/transport/intents.d.ts.map +1 -0
- package/dist/transport/intents.js +286 -0
- package/dist/transport/rest.d.ts +76 -0
- package/dist/transport/rest.d.ts.map +1 -0
- package/dist/transport/rest.js +48 -0
- package/dist/transport/runtime.d.ts +8 -0
- package/dist/transport/runtime.d.ts.map +1 -0
- package/dist/transport/runtime.js +16 -0
- package/dist/transport/webhooks.d.ts +27 -0
- package/dist/transport/webhooks.d.ts.map +1 -0
- package/dist/transport/webhooks.js +68 -0
- package/dist/urls.d.ts +71 -0
- package/dist/urls.d.ts.map +1 -0
- package/dist/urls.js +132 -0
- package/dist/userinfo.d.ts +11 -0
- package/dist/userinfo.d.ts.map +1 -0
- package/dist/userinfo.js +9 -0
- package/dist/utils.d.ts +20 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +45 -0
- package/dist/webhook-input.d.ts +22 -0
- package/dist/webhook-input.d.ts.map +1 -0
- package/dist/webhook-input.js +11 -0
- package/dist/webhook-signature.d.ts +54 -0
- package/dist/webhook-signature.d.ts.map +1 -0
- package/dist/webhook-signature.js +74 -0
- package/dist/window-features.d.ts +28 -0
- package/dist/window-features.d.ts.map +1 -0
- package/dist/window-features.js +55 -0
- package/package.json +63 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorization-preparation.d.ts","sourceRoot":"","sources":["../src/authorization-preparation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAQ7B,uEAAuE;AACvE,eAAO,MAAM,uBAAuB;;;;;;;;aAclC,CAAC;AAsBH,+EAA+E;AAC/E,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;aAarC,CAAC;AAEH,6FAA6F;AAC7F,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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 -0,0 +1,187 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
import { AutomaticChargeAuthorizationSchema } from "./automatic-charge.js";
|
|
3
|
+
import { BANK_ACCOUNT_AUTHORIZATION_ACTIONS, BankAccountAuthorizationActionSchema, } from "./bank-account-authorization.js";
|
|
4
|
+
import { AndCoOAuthScopePolicySchema } from "./miniapp-manifest.js";
|
|
5
|
+
/** Server-resolved scope policy and provider-owned consent content. */
|
|
6
|
+
export const AndCoConsentScopeSchema = /* @__PURE__ */ v.object({
|
|
7
|
+
...AndCoOAuthScopePolicySchema.entries,
|
|
8
|
+
resourceServerId: v.optional(v.string()),
|
|
9
|
+
resourceServerName: v.optional(v.pipe(v.string(), v.maxLength(255))),
|
|
10
|
+
scopeDescription: v.optional(v.pipe(v.string(), v.maxLength(1024))),
|
|
11
|
+
// Date of the active OAuth Grant on this Connection that already covers this Scope, null when none
|
|
12
|
+
// does. A fact of this person's history, not Client configuration -- kept separate from `mode`,
|
|
13
|
+
// which stays only the Client's Scope Policy. See ADR 0040.
|
|
14
|
+
grantedAt: v.nullable(v.string()),
|
|
15
|
+
// Whether this Connection already has ANY active Grant, regardless of scope: a step-up
|
|
16
|
+
// authorization on an already-connected Client, not the Subject's first-ever authorization with
|
|
17
|
+
// it. Drives pre-selecting an `optional` Scope requested for the first time in that step-up,
|
|
18
|
+
// without touching what `optional` means on a brand-new Connection. See ADR 0041.
|
|
19
|
+
connectionHasPriorGrant: v.boolean(),
|
|
20
|
+
});
|
|
21
|
+
const BankAccountAuthorizationSchema = /* @__PURE__ */ v.object({
|
|
22
|
+
actions: v.pipe(v.array(BankAccountAuthorizationActionSchema), v.minLength(1), v.maxLength(BANK_ACCOUNT_AUTHORIZATION_ACTIONS.length)),
|
|
23
|
+
accounts: v.pipe(v.array(v.object({
|
|
24
|
+
bankAccountId: v.pipe(v.string(), v.uuid()),
|
|
25
|
+
accountNumber: v.nullable(v.string()),
|
|
26
|
+
productName: v.nullable(v.string()),
|
|
27
|
+
currency: v.pipe(v.string(), v.minLength(1), v.maxLength(16)),
|
|
28
|
+
})), v.minLength(1), v.maxLength(100)),
|
|
29
|
+
});
|
|
30
|
+
/** Platform-resolved Company, installation and provider permission context. */
|
|
31
|
+
export const AndCoResourceConsentSchema = /* @__PURE__ */ v.object({
|
|
32
|
+
allowed: v.boolean(),
|
|
33
|
+
companyId: v.string(),
|
|
34
|
+
companyName: v.string(),
|
|
35
|
+
details: v.array(v.object({ name: v.string(), actions: v.array(v.object({ id: v.string(), description: v.string() })) })),
|
|
36
|
+
errorCode: v.nullable(v.string()),
|
|
37
|
+
installationStatus: v.picklist(["installed", "will_install"]),
|
|
38
|
+
installationProjectName: v.string(),
|
|
39
|
+
resourceProjectId: v.pipe(v.string(), v.uuid()),
|
|
40
|
+
resourceName: v.string(),
|
|
41
|
+
resource: v.string(),
|
|
42
|
+
});
|
|
43
|
+
/** Company accounts and immutable constraints resolved by Platform for automatic charges. */
|
|
44
|
+
export const AndCoChargeConsentSchema = /* @__PURE__ */ v.object({
|
|
45
|
+
orgId: v.pipe(v.number(), v.integer()),
|
|
46
|
+
companyName: v.string(),
|
|
47
|
+
projectId: v.pipe(v.string(), v.uuid()),
|
|
48
|
+
projectName: v.string(),
|
|
49
|
+
operatorName: v.string(),
|
|
50
|
+
request: AutomaticChargeAuthorizationSchema,
|
|
51
|
+
bindingAccountId: v.nullable(v.pipe(v.string(), v.uuid())),
|
|
52
|
+
openingName: v.optional(v.nullable(v.string())),
|
|
53
|
+
workflowId: v.nullable(v.pipe(v.string(), v.uuid())),
|
|
54
|
+
bankStatus: v.nullable(v.string()),
|
|
55
|
+
budgetAnchor: v.nullable(v.string()),
|
|
56
|
+
accounts: v.array(v.object({ id: v.pipe(v.string(), v.uuid()), number: v.nullable(v.string()), name: v.nullable(v.string()) })),
|
|
57
|
+
});
|
|
58
|
+
const AndCoAuthorizationClientSchema = /* @__PURE__ */ v.object({
|
|
59
|
+
id: v.pipe(v.string(), v.minLength(1), v.maxLength(255)),
|
|
60
|
+
name: v.pipe(v.string(), v.minLength(1), v.maxLength(255)),
|
|
61
|
+
uri: v.string(),
|
|
62
|
+
logoUri: v.string(),
|
|
63
|
+
});
|
|
64
|
+
const OAuthPrerequisiteRequirementSchema = /* @__PURE__ */ v.picklist([
|
|
65
|
+
"phone",
|
|
66
|
+
"personal_identity",
|
|
67
|
+
"address",
|
|
68
|
+
"bank_account",
|
|
69
|
+
]);
|
|
70
|
+
const AndCoAuthorizationSignInRequiredSchema = /* @__PURE__ */ v.object({
|
|
71
|
+
status: v.literal("sign_in_required"),
|
|
72
|
+
authorizationId: v.pipe(v.string(), v.minLength(1), v.maxLength(128)),
|
|
73
|
+
});
|
|
74
|
+
const AndCoAuthorizationPrerequisiteRequiredSchema = /* @__PURE__ */ v.object({
|
|
75
|
+
status: v.literal("prerequisite_required"),
|
|
76
|
+
authorizationId: v.pipe(v.string(), v.minLength(1), v.maxLength(128)),
|
|
77
|
+
client: AndCoAuthorizationClientSchema,
|
|
78
|
+
requirement: OAuthPrerequisiteRequirementSchema,
|
|
79
|
+
addressKind: v.nullable(v.picklist(["home", "work", "any"])),
|
|
80
|
+
progress: v.object({
|
|
81
|
+
completed: v.pipe(v.number(), v.integer(), v.minValue(0)),
|
|
82
|
+
total: v.pipe(v.number(), v.integer(), v.minValue(0)),
|
|
83
|
+
remaining: v.pipe(v.array(v.string()), v.maxLength(10)),
|
|
84
|
+
}),
|
|
85
|
+
reason: v.object({
|
|
86
|
+
code: v.pipe(v.string(), v.minLength(1), v.maxLength(128)),
|
|
87
|
+
relatedScopes: v.pipe(v.array(v.string()), v.maxLength(50)),
|
|
88
|
+
}),
|
|
89
|
+
resolutionUrl: v.pipe(v.string(), v.minLength(1), v.maxLength(8192)),
|
|
90
|
+
});
|
|
91
|
+
const AndCoAuthorizationConsentRequiredSchema = /* @__PURE__ */ v.object({
|
|
92
|
+
status: v.literal("consent_required"),
|
|
93
|
+
authorizationId: v.pipe(v.string(), v.minLength(1), v.maxLength(128)),
|
|
94
|
+
client: AndCoAuthorizationClientSchema,
|
|
95
|
+
redirectHost: v.pipe(v.string(), v.minLength(1), v.maxLength(255)),
|
|
96
|
+
scopes: v.pipe(v.array(AndCoConsentScopeSchema), v.maxLength(50)),
|
|
97
|
+
bankAccountAuthorization: v.optional(BankAccountAuthorizationSchema),
|
|
98
|
+
resourceAuthorization: v.optional(AndCoResourceConsentSchema),
|
|
99
|
+
chargeAuthorization: v.optional(AndCoChargeConsentSchema),
|
|
100
|
+
companySubject: v.optional(v.object({ organizationId: v.number(), organizationName: v.string() })),
|
|
101
|
+
// Kept alongside `companySubject` for the native producer's still-current selection UI (consent-drawer.tsx,
|
|
102
|
+
// Tauri app.tsx): `organization_subject_required` (reason: "selection") absorbs this case once the platform's
|
|
103
|
+
// decision module (Phase 4) derives it instead. Not part of the design session's consent_required shape.
|
|
104
|
+
organizationSelection: v.optional(v.object({
|
|
105
|
+
organizations: v.array(v.object({ organizationId: v.number(), organizationName: v.string() })),
|
|
106
|
+
selectedOrganizationId: v.nullable(v.number()),
|
|
107
|
+
})),
|
|
108
|
+
user: v.object({ email: v.pipe(v.string(), v.minLength(1), v.maxLength(320)) }),
|
|
109
|
+
});
|
|
110
|
+
const AndCoAuthorizationChargeAccountPreparationRequiredSchema = /* @__PURE__ */ v.object({
|
|
111
|
+
status: v.literal("charge_account_preparation_required"),
|
|
112
|
+
authorizationId: v.pipe(v.string(), v.minLength(1), v.maxLength(128)),
|
|
113
|
+
client: AndCoAuthorizationClientSchema,
|
|
114
|
+
charge: AndCoChargeConsentSchema,
|
|
115
|
+
});
|
|
116
|
+
const AndCoAuthorizationOrganizationSubjectRequiredSchema = /* @__PURE__ */ v.object({
|
|
117
|
+
status: v.literal("organization_subject_required"),
|
|
118
|
+
authorizationId: v.pipe(v.string(), v.minLength(1), v.maxLength(128)),
|
|
119
|
+
client: AndCoAuthorizationClientSchema,
|
|
120
|
+
reason: v.picklist(["selection", "identity", "mismatch"]),
|
|
121
|
+
organizations: v.array(v.object({ organizationId: v.number(), organizationName: v.string() })),
|
|
122
|
+
selectedOrganizationId: v.nullable(v.number()),
|
|
123
|
+
country: v.nullable(v.string()),
|
|
124
|
+
documentKind: v.nullable(v.string()),
|
|
125
|
+
documentValue: v.nullable(v.string()),
|
|
126
|
+
});
|
|
127
|
+
const AndCoAuthorizationAlreadyAuthorizedSchema = /* @__PURE__ */ v.object({
|
|
128
|
+
status: v.literal("already_authorized"),
|
|
129
|
+
redirectUrl: v.pipe(v.string(), v.minLength(1), v.maxLength(8192)),
|
|
130
|
+
});
|
|
131
|
+
// Produced when the request carries `prompt=consent` over an authorization an active Grant on the
|
|
132
|
+
// same Connection already covers exactly (see `oauth_authorization_grant_equivalent`). The person
|
|
133
|
+
// has nothing new to decide -- approving would reuse that Grant, not mint one -- so the renderer
|
|
134
|
+
// shows an honest confirmation (when they granted it, what it covers, one "Continue" CTA) instead
|
|
135
|
+
// of the full checkbox consent screen. Without `prompt=consent`, this member is never produced;
|
|
136
|
+
// resolving stays `consent_required` as it does today.
|
|
137
|
+
const AndCoAuthorizationConsentAlreadyGrantedSchema = /* @__PURE__ */ v.object({
|
|
138
|
+
status: v.literal("consent_already_granted"),
|
|
139
|
+
authorizationId: v.pipe(v.string(), v.minLength(1), v.maxLength(128)),
|
|
140
|
+
client: AndCoAuthorizationClientSchema,
|
|
141
|
+
redirectHost: v.pipe(v.string(), v.minLength(1), v.maxLength(255)),
|
|
142
|
+
grantedAt: v.pipe(v.string(), v.minLength(1), v.maxLength(64)),
|
|
143
|
+
scopes: v.pipe(v.array(AndCoConsentScopeSchema), v.maxLength(50)),
|
|
144
|
+
user: v.object({ email: v.pipe(v.string(), v.minLength(1), v.maxLength(320)) }),
|
|
145
|
+
});
|
|
146
|
+
// Admitted by the contract so incremental consent (a separate task) does not need a breaking change to add it.
|
|
147
|
+
// Not produced anywhere yet.
|
|
148
|
+
const AndCoAuthorizationPartiallyAuthorizedSchema = /* @__PURE__ */ v.object({
|
|
149
|
+
status: v.literal("partially_authorized"),
|
|
150
|
+
authorizationId: v.pipe(v.string(), v.minLength(1), v.maxLength(128)),
|
|
151
|
+
client: AndCoAuthorizationClientSchema,
|
|
152
|
+
redirectHost: v.pipe(v.string(), v.minLength(1), v.maxLength(255)),
|
|
153
|
+
scopes: v.pipe(v.array(AndCoConsentScopeSchema), v.maxLength(50)),
|
|
154
|
+
grantedScopes: v.pipe(v.array(v.string()), v.maxLength(50)),
|
|
155
|
+
user: v.object({ email: v.pipe(v.string(), v.minLength(1), v.maxLength(320)) }),
|
|
156
|
+
});
|
|
157
|
+
// Protocol or client-configuration failures only; the person has nothing actionable to do. Distinct from
|
|
158
|
+
// `AndCoAuthorizationErrorSchema`, the envelope returned by the native authorization HTTP endpoints today.
|
|
159
|
+
const AndCoAuthorizationPreparationErrorSchema = /* @__PURE__ */ v.object({
|
|
160
|
+
status: v.literal("error"),
|
|
161
|
+
code: v.pipe(v.string(), v.minLength(1), v.maxLength(128)),
|
|
162
|
+
message: v.pipe(v.string(), v.minLength(1), v.maxLength(512)),
|
|
163
|
+
});
|
|
164
|
+
/** Canonical state of one pending authorization, resolved once by the platform for every surface. */
|
|
165
|
+
export const AndCoAuthorizationPreparationSchema = /* @__PURE__ */ v.variant("status", [
|
|
166
|
+
AndCoAuthorizationSignInRequiredSchema,
|
|
167
|
+
AndCoAuthorizationPrerequisiteRequiredSchema,
|
|
168
|
+
AndCoAuthorizationConsentRequiredSchema,
|
|
169
|
+
AndCoAuthorizationChargeAccountPreparationRequiredSchema,
|
|
170
|
+
AndCoAuthorizationOrganizationSubjectRequiredSchema,
|
|
171
|
+
AndCoAuthorizationAlreadyAuthorizedSchema,
|
|
172
|
+
AndCoAuthorizationConsentAlreadyGrantedSchema,
|
|
173
|
+
AndCoAuthorizationPartiallyAuthorizedSchema,
|
|
174
|
+
AndCoAuthorizationPreparationErrorSchema,
|
|
175
|
+
]);
|
|
176
|
+
export const AndCoAuthorizationCompletionSchema = /* @__PURE__ */ v.object({
|
|
177
|
+
status: v.literal("completed"),
|
|
178
|
+
decision: v.picklist(["approve", "deny"]),
|
|
179
|
+
redirectUrl: v.pipe(v.string(), v.minLength(1), v.maxLength(8192)),
|
|
180
|
+
});
|
|
181
|
+
export const AndCoAuthorizationErrorSchema = /* @__PURE__ */ v.object({
|
|
182
|
+
error: v.object({
|
|
183
|
+
code: v.pipe(v.string(), v.minLength(1), v.maxLength(128)),
|
|
184
|
+
message: v.pipe(v.string(), v.minLength(1), v.maxLength(512)),
|
|
185
|
+
requirement: v.optional(OAuthPrerequisiteRequirementSchema),
|
|
186
|
+
}),
|
|
187
|
+
});
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/** Transport used to deliver one OAuth authorization request. */
|
|
2
|
+
export type AndCoAuthorizationTransportMode = "auto" | "get" | "par";
|
|
3
|
+
/** Configures direct GET versus Pushed Authorization Requests. */
|
|
4
|
+
export type AndCoAuthorizationTransportOptions = {
|
|
5
|
+
/** Selects GET, PAR, or the secure automatic heuristic. @default "auto" */
|
|
6
|
+
mode?: AndCoAuthorizationTransportMode;
|
|
7
|
+
/** Maximum direct authorization URL length before automatic PAR. @default 2048 */
|
|
8
|
+
maxGetUrlLength?: number;
|
|
9
|
+
/** Additional parameter names that make automatic authorization use PAR. */
|
|
10
|
+
sensitiveParameters?: Iterable<string>;
|
|
11
|
+
/** Receives redacted transport warnings. Defaults to `console.warn`. */
|
|
12
|
+
warn?: (message: string) => void;
|
|
13
|
+
};
|
|
14
|
+
/** OAuth parameter names that automatically require PAR. */
|
|
15
|
+
export declare const ANDCO_SENSITIVE_AUTHORIZATION_PARAMETERS: readonly ["authorization_details", "country", "document_kind", "document_value", "email", "external_id", "id", "login_hint", "subject"];
|
|
16
|
+
/** Fine-grained authorization detail contributed by one Resource Server. */
|
|
17
|
+
export type AndCoAuthorizationDetail = Readonly<Record<string, unknown>>;
|
|
18
|
+
/** Human Profile selected for a personal-resource authorization. */
|
|
19
|
+
export type AndCoAuthorizationSubject = {
|
|
20
|
+
readonly type: "profile";
|
|
21
|
+
readonly identifier?: string;
|
|
22
|
+
};
|
|
23
|
+
/** Explicit Company context; omission authorizes personal resources. */
|
|
24
|
+
export type AndCoOrganizationContext = {
|
|
25
|
+
readonly orgId?: string | "select";
|
|
26
|
+
};
|
|
27
|
+
/** Immutable authorization contribution created by a Resource Server definition. */
|
|
28
|
+
export type AndCoResourceAuthorization<Scope extends string = string, Detail extends AndCoAuthorizationDetail = AndCoAuthorizationDetail> = {
|
|
29
|
+
readonly orgId?: string;
|
|
30
|
+
readonly resourceServerId: string;
|
|
31
|
+
readonly resource: string;
|
|
32
|
+
readonly scopes: readonly Scope[];
|
|
33
|
+
readonly authorizationDetails: readonly Detail[];
|
|
34
|
+
};
|
|
35
|
+
/** Options shared by immutable Resource Server authorization builders. */
|
|
36
|
+
export type AndCoResourceAuthorizationOptions<Scope extends string, Detail extends AndCoAuthorizationDetail> = {
|
|
37
|
+
/** Exact scopes for this request. Omit to use the definition's initial scopes. */
|
|
38
|
+
scopes?: readonly Scope[];
|
|
39
|
+
/** RFC 9396 details requested from this Resource Server. */
|
|
40
|
+
authorizationDetails?: readonly Detail[];
|
|
41
|
+
};
|
|
42
|
+
/** Runtime-neutral client capability used by Resource Server packages. */
|
|
43
|
+
export type AndCoBoundResourceClient = {
|
|
44
|
+
/** Resolves an access token scoped to one Resource Server audience. */
|
|
45
|
+
accessTokenFor(resource: string): string | null | Promise<string | null>;
|
|
46
|
+
/** Fetch implementation shared with the owning AndCo client. */
|
|
47
|
+
fetch: typeof globalThis.fetch;
|
|
48
|
+
};
|
|
49
|
+
/** Immutable Resource Server definition that can bind itself to an AndCo session. */
|
|
50
|
+
export type AndCoResourceServerDefinition<Client> = {
|
|
51
|
+
use(client: AndCoBoundResourceClient): Client;
|
|
52
|
+
};
|
|
53
|
+
/** Complete normalized authorization plan contributed by Resource Servers. */
|
|
54
|
+
export type AndCoAuthorizationPlan = {
|
|
55
|
+
readonly orgId?: string;
|
|
56
|
+
readonly resources: readonly string[];
|
|
57
|
+
readonly scopes: readonly string[];
|
|
58
|
+
readonly authorizationDetails: readonly AndCoAuthorizationDetail[];
|
|
59
|
+
};
|
|
60
|
+
/** Result of resolving direct GET versus PAR. */
|
|
61
|
+
export type AndCoResolvedAuthorization = {
|
|
62
|
+
readonly url: URL;
|
|
63
|
+
readonly transport: "get" | "par";
|
|
64
|
+
readonly fellBackToGet: boolean;
|
|
65
|
+
};
|
|
66
|
+
/** Input used by the shared GET/PAR authorization resolver. */
|
|
67
|
+
export type AndCoResolveAuthorizationOptions = {
|
|
68
|
+
/** Complete direct authorization URL containing state, PKCE, scopes, and extensions. */
|
|
69
|
+
authorizationUrl: string | URL;
|
|
70
|
+
/** Exact configured OAuth authorization endpoint. */
|
|
71
|
+
authorizationEndpoint: string | URL;
|
|
72
|
+
/** Exact configured PAR endpoint. */
|
|
73
|
+
pushedAuthorizationRequestEndpoint: string | URL;
|
|
74
|
+
/** Headers added to the PAR request, including confidential client authentication when required. */
|
|
75
|
+
parHeaders?: HeadersInit;
|
|
76
|
+
/** Injectable transport for tests and specialized runtimes. */
|
|
77
|
+
fetch?: typeof globalThis.fetch;
|
|
78
|
+
/** Direct GET versus PAR policy. */
|
|
79
|
+
transport?: AndCoAuthorizationTransportOptions;
|
|
80
|
+
};
|
|
81
|
+
/** Error raised while validating or delivering an authorization request. */
|
|
82
|
+
export declare class AndCoAuthorizationRequestError extends Error {
|
|
83
|
+
readonly code: "invalid_authorization_request" | "sensitive_authorization_request" | "pushed_authorization_failed" | "invalid_pushed_authorization_response";
|
|
84
|
+
readonly status?: number | undefined;
|
|
85
|
+
constructor(code: "invalid_authorization_request" | "sensitive_authorization_request" | "pushed_authorization_failed" | "invalid_pushed_authorization_response", message?: string, status?: number | undefined);
|
|
86
|
+
}
|
|
87
|
+
/** Validates the opaque destination reference bound to an OAuth Client authorization. */
|
|
88
|
+
export declare function assertAndCoExternalId(value: string): void;
|
|
89
|
+
/** Validates an explicit Company context without changing the human OIDC identity. */
|
|
90
|
+
export declare function assertAndCoOrganizationContext(context: AndCoOrganizationContext): void;
|
|
91
|
+
/** Applies the Company's context exactly once to the authorization request. */
|
|
92
|
+
export declare function applyAndCoOrganizationContext(search: URLSearchParams, context: AndCoOrganizationContext): URLSearchParams;
|
|
93
|
+
/** Composes Resource Server contributions without losing their audience association. */
|
|
94
|
+
export declare function createAndCoAuthorizationPlan(authorizations?: readonly AndCoResourceAuthorization[]): AndCoAuthorizationPlan;
|
|
95
|
+
/** Returns a copy of OAuth authorization parameters with one normalized Resource Server plan applied. */
|
|
96
|
+
export declare function applyAndCoAuthorizationPlan(parameters: URLSearchParams, plan: AndCoAuthorizationPlan): URLSearchParams;
|
|
97
|
+
/** Resolves and executes the configured GET/PAR authorization transport. */
|
|
98
|
+
export declare function resolveAndCoAuthorization(options: AndCoResolveAuthorizationOptions): Promise<AndCoResolvedAuthorization>;
|
|
99
|
+
//# sourceMappingURL=authorization.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorization.d.ts","sourceRoot":"","sources":["../src/authorization.ts"],"names":[],"mappings":"AAGA,iEAAiE;AACjE,MAAM,MAAM,+BAA+B,GAAG,MAAM,GAAG,KAAK,GAAG,KAAK,CAAC;AAErE,kEAAkE;AAClE,MAAM,MAAM,kCAAkC,GAAG;IAC/C,2EAA2E;IAC3E,IAAI,CAAC,EAAE,+BAA+B,CAAC;IACvC,kFAAkF;IAClF,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,4EAA4E;IAC5E,mBAAmB,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IACvC,wEAAwE;IACxE,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CAClC,CAAC;AAEF,4DAA4D;AAC5D,eAAO,MAAM,wCAAwC,yIAU3C,CAAC;AAEX,4EAA4E;AAC5E,MAAM,MAAM,wBAAwB,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAA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E,MAAM,YAAA;CAIlC;AAED,yFAAyF;AACzF,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAOzD;AAED,sFAAsF;AACtF,wBAAgB,8BAA8B,CAAC,OAAO,EAAE,wBAAwB,GAAG,IAAI,CAWtF;AAED,+EAA+E;AAC/E,wBAAgB,6BAA6B,CAC3C,MAAM,EAAE,eAAe,EACvB,OAAO,EAAE,wBAAwB,GAChC,eAAe,CAUjB;AAOD,wFAAwF;AACxF,wBAAgB,4BAA4B,CAC1C,cAAc,GAAE,SAAS,0BAA0B,EAAO,GACzD,sBAAsB,CAgDxB;AAED,yGAAyG;AACzG,wBAAgB,2BAA2B,CACzC,UAAU,EAAE,eAAe,EAC3B,IAAI,EAAE,sBAAsB,GAC3B,eAAe,CAUjB;AAED,4EAA4E;AAC5E,wBAAsB,yBAAyB,CAC7C,OAAO,EAAE,gCAAgC,GACxC,OAAO,CAAC,0BAA0B,CAAC,CAiBrC"}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
import { SafeURL } from "./urls.js";
|
|
3
|
+
/** OAuth parameter names that automatically require PAR. */
|
|
4
|
+
export const ANDCO_SENSITIVE_AUTHORIZATION_PARAMETERS = [
|
|
5
|
+
"authorization_details",
|
|
6
|
+
"country",
|
|
7
|
+
"document_kind",
|
|
8
|
+
"document_value",
|
|
9
|
+
"email",
|
|
10
|
+
"external_id",
|
|
11
|
+
"id",
|
|
12
|
+
"login_hint",
|
|
13
|
+
"subject",
|
|
14
|
+
];
|
|
15
|
+
/** Error raised while validating or delivering an authorization request. */
|
|
16
|
+
export class AndCoAuthorizationRequestError extends Error {
|
|
17
|
+
code;
|
|
18
|
+
status;
|
|
19
|
+
constructor(code, message = code, status) {
|
|
20
|
+
super(message);
|
|
21
|
+
this.code = code;
|
|
22
|
+
this.status = status;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/** Validates the opaque destination reference bound to an OAuth Client authorization. */
|
|
26
|
+
export function assertAndCoExternalId(value) {
|
|
27
|
+
if (value.trim().length === 0 || new TextEncoder().encode(value).byteLength > 256) {
|
|
28
|
+
throw new AndCoAuthorizationRequestError("invalid_authorization_request", "externalId must be a non-blank UTF-8 string no longer than 256 bytes");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** Validates an explicit Company context without changing the human OIDC identity. */
|
|
32
|
+
export function assertAndCoOrganizationContext(context) {
|
|
33
|
+
if (context.orgId !== undefined &&
|
|
34
|
+
context.orgId !== "select" &&
|
|
35
|
+
(!/^[1-9][0-9]*$/.test(context.orgId) || Number(context.orgId) > 2147483647)) {
|
|
36
|
+
throw new AndCoAuthorizationRequestError("invalid_authorization_request", "orgId must be a positive Company ID or select");
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** Applies the Company's context exactly once to the authorization request. */
|
|
40
|
+
export function applyAndCoOrganizationContext(search, context) {
|
|
41
|
+
assertAndCoOrganizationContext(context);
|
|
42
|
+
const next = new URLSearchParams(search);
|
|
43
|
+
if (context.orgId !== undefined) {
|
|
44
|
+
if (next.has("org_id") && next.get("org_id") !== context.orgId) {
|
|
45
|
+
throw new AndCoAuthorizationRequestError("invalid_authorization_request", "Conflicting Company contexts");
|
|
46
|
+
}
|
|
47
|
+
next.set("org_id", context.orgId);
|
|
48
|
+
}
|
|
49
|
+
return next;
|
|
50
|
+
}
|
|
51
|
+
const PushedAuthorizationResponseSchema = /* @__PURE__ */ v.object({
|
|
52
|
+
expires_in: v.pipe(v.number(), v.integer(), v.minValue(1)),
|
|
53
|
+
request_uri: v.pipe(v.string(), v.regex(/^urn:ietf:params:oauth:request_uri:[A-Za-z0-9._~:+/-]{1,1900}$/)),
|
|
54
|
+
});
|
|
55
|
+
/** Composes Resource Server contributions without losing their audience association. */
|
|
56
|
+
export function createAndCoAuthorizationPlan(authorizations = []) {
|
|
57
|
+
let orgId;
|
|
58
|
+
const resources = new Set();
|
|
59
|
+
const scopes = new Set();
|
|
60
|
+
const authorizationDetails = [];
|
|
61
|
+
for (const authorization of authorizations) {
|
|
62
|
+
assertAndCoOrganizationContext(authorization);
|
|
63
|
+
if (authorization.orgId !== undefined) {
|
|
64
|
+
if (orgId !== undefined && orgId !== authorization.orgId)
|
|
65
|
+
throw new AndCoAuthorizationRequestError("invalid_authorization_request", "Conflicting Company contexts");
|
|
66
|
+
orgId = authorization.orgId;
|
|
67
|
+
}
|
|
68
|
+
new SafeURL(authorization.resource);
|
|
69
|
+
// A resource is an exact audience identifier, not a navigation URL to normalize.
|
|
70
|
+
const resource = authorization.resource;
|
|
71
|
+
if (resources.has(resource)) {
|
|
72
|
+
throw new AndCoAuthorizationRequestError("invalid_authorization_request", `Duplicate Resource Server authorization: ${authorization.resourceServerId}`);
|
|
73
|
+
}
|
|
74
|
+
resources.add(resource);
|
|
75
|
+
for (const scope of authorization.scopes) {
|
|
76
|
+
if (!/^[\x21\x23-\x5b\x5d-\x7e]{1,128}$/.test(scope)) {
|
|
77
|
+
throw new AndCoAuthorizationRequestError("invalid_authorization_request", "Invalid OAuth scope");
|
|
78
|
+
}
|
|
79
|
+
scopes.add(scope);
|
|
80
|
+
}
|
|
81
|
+
for (const detail of authorization.authorizationDetails) {
|
|
82
|
+
if (!detail || typeof detail !== "object" || Array.isArray(detail)) {
|
|
83
|
+
throw new AndCoAuthorizationRequestError("invalid_authorization_request", "Invalid authorization detail");
|
|
84
|
+
}
|
|
85
|
+
const locations = detail["locations"];
|
|
86
|
+
if (locations !== undefined &&
|
|
87
|
+
(!Array.isArray(locations) || locations.some((location) => location !== resource))) {
|
|
88
|
+
throw new AndCoAuthorizationRequestError("invalid_authorization_request", "Authorization detail locations must match its Resource Server");
|
|
89
|
+
}
|
|
90
|
+
authorizationDetails.push({ ...detail, locations: [resource] });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return { orgId, resources: [...resources], scopes: [...scopes], authorizationDetails };
|
|
94
|
+
}
|
|
95
|
+
/** Returns a copy of OAuth authorization parameters with one normalized Resource Server plan applied. */
|
|
96
|
+
export function applyAndCoAuthorizationPlan(parameters, plan) {
|
|
97
|
+
const next = applyAndCoOrganizationContext(parameters, plan);
|
|
98
|
+
for (const resource of plan.resources)
|
|
99
|
+
next.append("resource", resource);
|
|
100
|
+
const scopes = new Set((next.get("scope") ?? "").split(/\s+/).filter(Boolean));
|
|
101
|
+
for (const scope of plan.scopes)
|
|
102
|
+
scopes.add(scope);
|
|
103
|
+
if (scopes.size > 0)
|
|
104
|
+
next.set("scope", [...scopes].join(" "));
|
|
105
|
+
if (plan.authorizationDetails.length > 0) {
|
|
106
|
+
next.set("authorization_details", JSON.stringify(plan.authorizationDetails));
|
|
107
|
+
}
|
|
108
|
+
return next;
|
|
109
|
+
}
|
|
110
|
+
/** Resolves and executes the configured GET/PAR authorization transport. */
|
|
111
|
+
export async function resolveAndCoAuthorization(options) {
|
|
112
|
+
const authorizationUrl = ANDCO_AUTHORIZATION_URL_FROM(options.authorizationUrl, options.authorizationEndpoint);
|
|
113
|
+
const transport = ANDCO_AUTHORIZATION_TRANSPORT_FROM(authorizationUrl, options.transport);
|
|
114
|
+
if (transport === "get")
|
|
115
|
+
return { url: authorizationUrl, transport, fellBackToGet: false };
|
|
116
|
+
try {
|
|
117
|
+
const url = await PUSHED_AUTHORIZATION_URL_FROM(options, authorizationUrl);
|
|
118
|
+
return { url, transport: "par", fellBackToGet: false };
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
const mode = options.transport?.mode ?? "auto";
|
|
122
|
+
if (ANDCO_AUTHORIZATION_HAS_ENFORCED_SELECTOR(authorizationUrl))
|
|
123
|
+
throw error;
|
|
124
|
+
if (mode !== "auto" || !PAR_FAILURE_ALLOWS_GET(error))
|
|
125
|
+
throw error;
|
|
126
|
+
(options.transport?.warn ?? console.warn)("[AndCo OAuth] PAR is unavailable; falling back to a direct GET authorization request.");
|
|
127
|
+
return { url: authorizationUrl, transport: "get", fellBackToGet: true };
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/** Identity filters are an enforced matching contract and must never leak through GET fallback. */
|
|
131
|
+
function ANDCO_AUTHORIZATION_HAS_ENFORCED_SELECTOR(authorizationUrl) {
|
|
132
|
+
return ["country", "document_kind", "document_value", "email", "id"].some((parameter) => authorizationUrl.searchParams.has(parameter));
|
|
133
|
+
}
|
|
134
|
+
function ANDCO_AUTHORIZATION_URL_FROM(input, endpointInput) {
|
|
135
|
+
const url = new SafeURL(input);
|
|
136
|
+
const endpoint = new SafeURL(endpointInput);
|
|
137
|
+
if (url.origin !== endpoint.origin || url.pathname !== endpoint.pathname) {
|
|
138
|
+
throw new AndCoAuthorizationRequestError("invalid_authorization_request", "Unexpected authorization endpoint");
|
|
139
|
+
}
|
|
140
|
+
const required = ["response_type", "client_id", "redirect_uri", "state", "code_challenge"];
|
|
141
|
+
if (url.searchParams.get("response_type") !== "code" ||
|
|
142
|
+
url.searchParams.get("code_challenge_method") !== "S256" ||
|
|
143
|
+
required.some((parameter) => !url.searchParams.get(parameter))) {
|
|
144
|
+
throw new AndCoAuthorizationRequestError("invalid_authorization_request", "Incomplete authorization request");
|
|
145
|
+
}
|
|
146
|
+
if (!url.searchParams.get("scope")?.trim()) {
|
|
147
|
+
let details;
|
|
148
|
+
try {
|
|
149
|
+
details = JSON.parse(url.searchParams.get("authorization_details") ?? "null");
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
throw new AndCoAuthorizationRequestError("invalid_authorization_request", "Invalid authorization details");
|
|
153
|
+
}
|
|
154
|
+
if (!Array.isArray(details) || details.length === 0) {
|
|
155
|
+
throw new AndCoAuthorizationRequestError("invalid_authorization_request", "A scope or authorization detail is required");
|
|
156
|
+
}
|
|
157
|
+
url.searchParams.delete("scope");
|
|
158
|
+
}
|
|
159
|
+
return url;
|
|
160
|
+
}
|
|
161
|
+
function ANDCO_AUTHORIZATION_TRANSPORT_FROM(authorizationUrl, options = {}) {
|
|
162
|
+
const mode = options.mode ?? "auto";
|
|
163
|
+
const maxGetUrlLength = options.maxGetUrlLength ?? 2_048;
|
|
164
|
+
if (!Number.isSafeInteger(maxGetUrlLength) || maxGetUrlLength < 512 || maxGetUrlLength > 32_768) {
|
|
165
|
+
throw new RangeError("maxGetUrlLength must be an integer between 512 and 32768");
|
|
166
|
+
}
|
|
167
|
+
const sensitive = new Set(ANDCO_SENSITIVE_AUTHORIZATION_PARAMETERS);
|
|
168
|
+
for (const parameter of options.sensitiveParameters ?? []) {
|
|
169
|
+
if (!/^[A-Za-z][A-Za-z0-9_.-]{0,127}$/.test(parameter)) {
|
|
170
|
+
throw new TypeError("Invalid sensitive OAuth parameter name");
|
|
171
|
+
}
|
|
172
|
+
sensitive.add(parameter);
|
|
173
|
+
}
|
|
174
|
+
const hasSensitiveParameter = [...sensitive].some((parameter) => authorizationUrl.searchParams.has(parameter));
|
|
175
|
+
if (mode === "get") {
|
|
176
|
+
if (hasSensitiveParameter) {
|
|
177
|
+
throw new AndCoAuthorizationRequestError("sensitive_authorization_request", "Sensitive authorization parameters require PAR");
|
|
178
|
+
}
|
|
179
|
+
return "get";
|
|
180
|
+
}
|
|
181
|
+
if (mode === "par")
|
|
182
|
+
return "par";
|
|
183
|
+
return hasSensitiveParameter || authorizationUrl.href.length > maxGetUrlLength ? "par" : "get";
|
|
184
|
+
}
|
|
185
|
+
async function PUSHED_AUTHORIZATION_URL_FROM(options, authorizationUrl) {
|
|
186
|
+
const parEndpoint = new SafeURL(options.pushedAuthorizationRequestEndpoint);
|
|
187
|
+
const headers = new Headers(options.parHeaders);
|
|
188
|
+
headers.set("Accept", "application/json");
|
|
189
|
+
headers.set("Content-Type", "application/x-www-form-urlencoded");
|
|
190
|
+
let response;
|
|
191
|
+
try {
|
|
192
|
+
response = await (options.fetch ?? globalThis.fetch)(parEndpoint, {
|
|
193
|
+
body: new URLSearchParams(authorizationUrl.searchParams),
|
|
194
|
+
headers,
|
|
195
|
+
method: "POST",
|
|
196
|
+
redirect: "error",
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
catch {
|
|
200
|
+
throw new AndCoAuthorizationRequestError("pushed_authorization_failed", "PAR network request failed");
|
|
201
|
+
}
|
|
202
|
+
if (!response.ok) {
|
|
203
|
+
throw new AndCoAuthorizationRequestError("pushed_authorization_failed", `PAR returned HTTP ${response.status}`, response.status);
|
|
204
|
+
}
|
|
205
|
+
const parsed = v.safeParse(PushedAuthorizationResponseSchema, await response.json().catch(() => null));
|
|
206
|
+
if (!parsed.success) {
|
|
207
|
+
throw new AndCoAuthorizationRequestError("invalid_pushed_authorization_response", "PAR returned an invalid response", response.status);
|
|
208
|
+
}
|
|
209
|
+
const browserUrl = new SafeURL(options.authorizationEndpoint);
|
|
210
|
+
browserUrl.search = new URLSearchParams({
|
|
211
|
+
client_id: authorizationUrl.searchParams.get("client_id"),
|
|
212
|
+
request_uri: parsed.output.request_uri,
|
|
213
|
+
}).toString();
|
|
214
|
+
return browserUrl;
|
|
215
|
+
}
|
|
216
|
+
function PAR_FAILURE_ALLOWS_GET(error) {
|
|
217
|
+
if (!(error instanceof AndCoAuthorizationRequestError))
|
|
218
|
+
return false;
|
|
219
|
+
if (error.code === "invalid_pushed_authorization_response")
|
|
220
|
+
return true;
|
|
221
|
+
return (error.code === "pushed_authorization_failed" &&
|
|
222
|
+
(error.status === undefined ||
|
|
223
|
+
error.status === 404 ||
|
|
224
|
+
error.status === 405 ||
|
|
225
|
+
error.status === 501 ||
|
|
226
|
+
error.status >= 500));
|
|
227
|
+
}
|