@andco/protocol 0.0.11 → 0.0.13
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/api-errors.d.ts +5 -128
- package/dist/api-errors.d.ts.map +1 -1
- package/dist/api-errors.js +5 -131
- package/dist/authorization-preparation.d.ts +3 -3
- package/dist/authorization-preparation.d.ts.map +1 -1
- package/dist/authorization-preparation.js +4 -0
- package/dist/authorization.js +2 -2
- package/dist/errors.d.ts +111 -16
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +124 -12
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/intent-input.d.ts +1791 -725
- package/dist/intent-input.d.ts.map +1 -1
- package/dist/intent-input.js +325 -157
- package/dist/issues.d.ts +62 -0
- package/dist/issues.d.ts.map +1 -0
- package/dist/issues.js +61 -0
- package/dist/messages/index.d.ts +2 -2
- package/dist/messages/index.d.ts.map +1 -1
- package/dist/messages/index.js +10 -3
- package/dist/messages/set-preferences.d.ts +13 -1
- package/dist/messages/set-preferences.d.ts.map +1 -1
- package/dist/messages/set-preferences.js +31 -9
- package/dist/miniapp-manifest.d.ts +2 -2
- package/dist/miniapp-manifest.d.ts.map +1 -1
- package/dist/miniapp-manifest.js +1 -1
- package/dist/native-intent.d.ts +48 -28
- package/dist/native-intent.d.ts.map +1 -1
- package/dist/native-intent.js +76 -24
- package/dist/pagination.d.ts +37 -31
- package/dist/pagination.d.ts.map +1 -1
- package/dist/pagination.js +72 -24
- package/dist/rar/account-matchers.d.ts +47 -240
- package/dist/rar/account-matchers.d.ts.map +1 -1
- package/dist/rar/account-matchers.js +52 -131
- package/dist/rar/bank.d.ts +280 -392
- package/dist/rar/bank.d.ts.map +1 -1
- package/dist/rar/bank.js +68 -137
- package/dist/rar/catalog.d.ts +305 -288
- package/dist/rar/catalog.d.ts.map +1 -1
- package/dist/rar/catalog.js +69 -29
- package/dist/rar/detail.d.ts +15 -32
- package/dist/rar/detail.d.ts.map +1 -1
- package/dist/rar/detail.js +14 -34
- package/dist/rar/index.d.ts +2 -1
- package/dist/rar/index.d.ts.map +1 -1
- package/dist/rar/index.js +2 -1
- package/dist/rar/json-schemas.generated.d.ts +4 -0
- package/dist/rar/json-schemas.generated.d.ts.map +1 -0
- package/dist/rar/json-schemas.generated.js +3570 -0
- package/dist/rar/money.d.ts +5 -5
- package/dist/rar/money.d.ts.map +1 -1
- package/dist/rar/money.js +5 -5
- package/dist/rar/project-users.d.ts +40 -14
- package/dist/rar/project-users.d.ts.map +1 -1
- package/dist/rar/project-users.js +20 -23
- package/dist/rar/subject-data.d.ts +96 -48
- package/dist/rar/subject-data.d.ts.map +1 -1
- package/dist/rar/subject-data.js +61 -34
- package/dist/rar/subject.d.ts +18 -85
- package/dist/rar/subject.d.ts.map +1 -1
- package/dist/rar/subject.js +23 -51
- package/dist/rest/accounts.d.ts +347 -0
- package/dist/rest/accounts.d.ts.map +1 -0
- package/dist/rest/accounts.js +108 -0
- package/dist/rest/addresses.d.ts +581 -0
- package/dist/rest/addresses.d.ts.map +1 -0
- package/dist/rest/addresses.js +190 -0
- package/dist/rest/api-error.d.ts +104 -0
- package/dist/rest/api-error.d.ts.map +1 -0
- package/dist/rest/api-error.js +103 -0
- package/dist/rest/authorization.d.ts +123 -0
- package/dist/rest/authorization.d.ts.map +1 -0
- package/dist/rest/authorization.js +62 -0
- package/dist/rest/catalog.d.ts +199 -0
- package/dist/rest/catalog.d.ts.map +1 -0
- package/dist/rest/catalog.js +63 -0
- package/dist/rest/common.d.ts +637 -0
- package/dist/rest/common.d.ts.map +1 -0
- package/dist/rest/common.js +172 -0
- package/dist/rest/contract.d.ts +3480 -0
- package/dist/rest/contract.d.ts.map +1 -0
- package/dist/rest/contract.js +120 -0
- package/dist/rest/events.d.ts +145 -0
- package/dist/rest/events.d.ts.map +1 -0
- package/dist/rest/events.js +42 -0
- package/dist/rest/http.d.ts +49 -0
- package/dist/rest/http.d.ts.map +1 -0
- package/dist/rest/http.js +25 -0
- package/dist/rest/identity.d.ts +627 -0
- package/dist/rest/identity.d.ts.map +1 -0
- package/dist/rest/identity.js +128 -0
- package/dist/rest/index.d.ts +14 -0
- package/dist/rest/index.d.ts.map +1 -0
- package/dist/rest/index.js +13 -0
- package/dist/rest/intents.d.ts +4556 -0
- package/dist/rest/intents.d.ts.map +1 -0
- package/dist/rest/intents.js +551 -0
- package/dist/rest/signatures.d.ts +110 -0
- package/dist/rest/signatures.d.ts.map +1 -0
- package/dist/rest/signatures.js +113 -0
- package/dist/rest/subjects.d.ts +14 -0
- package/dist/rest/subjects.d.ts.map +1 -0
- package/dist/rest/subjects.js +22 -0
- package/dist/service-grants.d.ts +2 -2
- package/dist/service-grants.d.ts.map +1 -1
- package/dist/service-grants.js +1 -1
- package/dist/transport/generated/oauth-api.d.ts +5547 -1448
- package/dist/transport/generated/oauth-api.d.ts.map +1 -1
- package/dist/transport/intents.d.ts +9 -134
- package/dist/transport/intents.d.ts.map +1 -1
- package/dist/transport/intents.js +21 -405
- package/dist/transport/rest.d.ts +15 -5
- package/dist/transport/rest.d.ts.map +1 -1
- package/dist/userinfo.d.ts +22 -9
- package/dist/userinfo.d.ts.map +1 -1
- package/dist/userinfo.js +17 -12
- package/package.json +13 -2
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { oc } from "@orpc/contract";
|
|
2
|
+
import * as v from "valibot";
|
|
3
|
+
import { AndcoAPIError, errors } from "./api-error.js";
|
|
4
|
+
import { connection, InvalidRequest, PageQuery, PayloadTooLarge } from "./common.js";
|
|
5
|
+
import { http } from "./http.js";
|
|
6
|
+
import { OrganizationIdParameter, ProfileIdParameter, SubjectErrors } from "./subjects.js";
|
|
7
|
+
/** The identifier of an address, in `…/addresses/{address_id}`. */
|
|
8
|
+
export const AddressIdParameter = /* @__PURE__ */ v.pipe(v.string(), v.uuid());
|
|
9
|
+
const AddressCountry = /* @__PURE__ */ v.pipe(v.string(), v.minLength(1), v.maxLength(16));
|
|
10
|
+
const AddressLevel = /* @__PURE__ */ v.nullable(v.pipe(v.string(), v.minLength(1), v.maxLength(128)));
|
|
11
|
+
const AddressStreet = /* @__PURE__ */ v.nullable(v.pipe(v.string(), v.minLength(1), v.maxLength(200)));
|
|
12
|
+
const AddressLabelKind = /* @__PURE__ */ v.picklist(["home", "work", "vacation", "other"]);
|
|
13
|
+
const AddressLabelName = /* @__PURE__ */ v.nullable(v.pipe(v.string(), v.minLength(1), v.maxLength(100)));
|
|
14
|
+
const AddressPriority = /* @__PURE__ */ v.pipe(v.number(), v.integer(), v.minValue(-2147483648), v.maxValue(2147483647));
|
|
15
|
+
/** An address of a Profile or of an Organization, as the API reads it. */
|
|
16
|
+
export const Address = /* @__PURE__ */ v.object({
|
|
17
|
+
id: v.pipe(v.string(), v.uuid()),
|
|
18
|
+
country: v.string(),
|
|
19
|
+
level1: v.nullable(v.string()),
|
|
20
|
+
level2: v.nullable(v.string()),
|
|
21
|
+
level3: v.nullable(v.string()),
|
|
22
|
+
street_address: v.nullable(v.string()),
|
|
23
|
+
label_kind: AddressLabelKind,
|
|
24
|
+
label_name: v.nullable(v.string()),
|
|
25
|
+
priority: AddressPriority,
|
|
26
|
+
});
|
|
27
|
+
/** One page of addresses. */
|
|
28
|
+
export const AddressPage = /* @__PURE__ */ connection(Address, "A standard connection. Edge cursors remain present on nonempty terminal pages. Reads are live; offset positions can shift under concurrent changes.");
|
|
29
|
+
/** What a request to create an address carries. */
|
|
30
|
+
export const AddressCreate = /* @__PURE__ */ v.strictObject({
|
|
31
|
+
country: AddressCountry,
|
|
32
|
+
level1: v.optional(AddressLevel),
|
|
33
|
+
level2: v.optional(AddressLevel),
|
|
34
|
+
level3: v.optional(AddressLevel),
|
|
35
|
+
street_address: v.optional(AddressStreet),
|
|
36
|
+
label_kind: AddressLabelKind,
|
|
37
|
+
label_name: v.optional(AddressLabelName),
|
|
38
|
+
priority: v.optional(AddressPriority),
|
|
39
|
+
});
|
|
40
|
+
/**
|
|
41
|
+
* What a request to update an address carries: any of the fields of {@link AddressCreate}, and at
|
|
42
|
+
* least one of them (see {@link addressUpdateIssues}).
|
|
43
|
+
*/
|
|
44
|
+
export const AddressUpdate = /* @__PURE__ */ v.pipe(v.partial(AddressCreate), v.description("At least one address field must be provided."));
|
|
45
|
+
/** The identifier of the address a request created or updated. */
|
|
46
|
+
export const AddressMutationResult = /* @__PURE__ */ v.object({ id: v.pipe(v.string(), v.uuid()) });
|
|
47
|
+
/**
|
|
48
|
+
* The rule no schema can say: an update has to change something.
|
|
49
|
+
*
|
|
50
|
+
* @returns One issue when the update carries no field, none otherwise.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* addressUpdateIssues({}); // [{ type: "address_update_empty", path: [] }]
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export function addressUpdateIssues(update) {
|
|
58
|
+
if (Object.values(update).some((field) => field !== undefined)) {
|
|
59
|
+
return [];
|
|
60
|
+
}
|
|
61
|
+
return [{ type: "address_update_empty", path: [] }];
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The address could not be created: the values are well formed but the store refused them (a
|
|
65
|
+
* country or level it does not know, for instance). Nothing was created.
|
|
66
|
+
*/
|
|
67
|
+
export class AddressNotCreated extends /* @__PURE__ */ AndcoAPIError.define("address_not_created", 422, v.pipe(v.object({}), v.description("The address was well formed but could not be created."))) {
|
|
68
|
+
constructor(message) {
|
|
69
|
+
super({}, message);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The address could not be updated: the values are well formed but the store refused them. The
|
|
74
|
+
* address stays as it was.
|
|
75
|
+
*/
|
|
76
|
+
export class AddressNotUpdated extends /* @__PURE__ */ AndcoAPIError.define("address_not_updated", 422, v.pipe(v.object({}), v.description("The address was well formed but could not be updated."))) {
|
|
77
|
+
constructor(message) {
|
|
78
|
+
super({}, message);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/** List a Profile's addresses. */
|
|
82
|
+
export const listProfileAddresses = /* @__PURE__ */ oc
|
|
83
|
+
.meta(http({
|
|
84
|
+
method: "GET",
|
|
85
|
+
path: "/profiles/{profile_id}/addresses",
|
|
86
|
+
summary: "List a Profile's addresses",
|
|
87
|
+
description: "Granted by an `address` authorization detail with `read` whose subject is this Profile. Returns edges and camelCase pageInfo. Cursor and offset argument families cannot be mixed.",
|
|
88
|
+
successDescription: "One page of the Profile's active addresses",
|
|
89
|
+
}))
|
|
90
|
+
.errors(errors(...SubjectErrors, InvalidRequest))
|
|
91
|
+
.input(v.object({ profile_id: ProfileIdParameter, ...PageQuery }))
|
|
92
|
+
.output(AddressPage);
|
|
93
|
+
/** Create an address for a Profile. */
|
|
94
|
+
export const createProfileAddress = /* @__PURE__ */ oc
|
|
95
|
+
.meta(http({
|
|
96
|
+
method: "POST",
|
|
97
|
+
path: "/profiles/{profile_id}/addresses",
|
|
98
|
+
summary: "Create an address for a Profile",
|
|
99
|
+
description: "Granted by an `address` authorization detail with `create` whose subject is this Profile.",
|
|
100
|
+
successDescription: "Address created",
|
|
101
|
+
successStatus: 201,
|
|
102
|
+
inputStructure: "detailed",
|
|
103
|
+
}))
|
|
104
|
+
.errors(errors(...SubjectErrors, InvalidRequest, AddressNotCreated, PayloadTooLarge))
|
|
105
|
+
.input(v.object({ params: v.object({ profile_id: ProfileIdParameter }), body: AddressCreate }))
|
|
106
|
+
.output(AddressMutationResult);
|
|
107
|
+
/** Update one of a Profile's addresses. */
|
|
108
|
+
export const updateProfileAddress = /* @__PURE__ */ oc
|
|
109
|
+
.meta(http({
|
|
110
|
+
method: "PATCH",
|
|
111
|
+
path: "/profiles/{profile_id}/addresses/{address_id}",
|
|
112
|
+
summary: "Update one of a Profile's addresses",
|
|
113
|
+
description: "Granted by an `address` authorization detail with `update` whose subject is this Profile.",
|
|
114
|
+
successDescription: "Address updated",
|
|
115
|
+
inputStructure: "detailed",
|
|
116
|
+
}))
|
|
117
|
+
.errors(errors(...SubjectErrors, InvalidRequest, AddressNotUpdated, PayloadTooLarge))
|
|
118
|
+
.input(v.object({
|
|
119
|
+
params: v.object({ profile_id: ProfileIdParameter, address_id: AddressIdParameter }),
|
|
120
|
+
body: AddressUpdate,
|
|
121
|
+
}))
|
|
122
|
+
.output(AddressMutationResult);
|
|
123
|
+
/** Soft-delete one of a Profile's addresses. */
|
|
124
|
+
export const deleteProfileAddress = /* @__PURE__ */ oc
|
|
125
|
+
.meta(http({
|
|
126
|
+
method: "DELETE",
|
|
127
|
+
path: "/profiles/{profile_id}/addresses/{address_id}",
|
|
128
|
+
summary: "Soft-delete one of a Profile's addresses",
|
|
129
|
+
description: "Granted by an `address` authorization detail with `delete` whose subject is this Profile.",
|
|
130
|
+
successDescription: "Address deleted",
|
|
131
|
+
successStatus: 204,
|
|
132
|
+
inputStructure: "detailed",
|
|
133
|
+
}))
|
|
134
|
+
.errors(errors(...SubjectErrors))
|
|
135
|
+
.input(v.object({ params: v.object({ profile_id: ProfileIdParameter, address_id: AddressIdParameter }) }));
|
|
136
|
+
/** List an Organization's addresses. */
|
|
137
|
+
export const listOrganizationAddresses = /* @__PURE__ */ oc
|
|
138
|
+
.meta(http({
|
|
139
|
+
method: "GET",
|
|
140
|
+
path: "/organizations/{organization_id}/addresses",
|
|
141
|
+
summary: "List an Organization's addresses",
|
|
142
|
+
description: "Granted by an `address` authorization detail with `read` whose subject is this Organization. Returns edges and camelCase pageInfo. Cursor and offset argument families cannot be mixed.",
|
|
143
|
+
successDescription: "One page of the Organization's active addresses",
|
|
144
|
+
}))
|
|
145
|
+
.errors(errors(...SubjectErrors, InvalidRequest))
|
|
146
|
+
.input(v.object({ organization_id: OrganizationIdParameter, ...PageQuery }))
|
|
147
|
+
.output(AddressPage);
|
|
148
|
+
/** Create an address for an Organization. */
|
|
149
|
+
export const createOrganizationAddress = /* @__PURE__ */ oc
|
|
150
|
+
.meta(http({
|
|
151
|
+
method: "POST",
|
|
152
|
+
path: "/organizations/{organization_id}/addresses",
|
|
153
|
+
summary: "Create an address for an Organization",
|
|
154
|
+
description: "Granted by an `address` authorization detail with `create` whose subject is this Organization.",
|
|
155
|
+
successDescription: "Address created",
|
|
156
|
+
successStatus: 201,
|
|
157
|
+
inputStructure: "detailed",
|
|
158
|
+
}))
|
|
159
|
+
.errors(errors(...SubjectErrors, InvalidRequest, AddressNotCreated, PayloadTooLarge))
|
|
160
|
+
.input(v.object({ params: v.object({ organization_id: OrganizationIdParameter }), body: AddressCreate }))
|
|
161
|
+
.output(AddressMutationResult);
|
|
162
|
+
/** Update one of an Organization's addresses. */
|
|
163
|
+
export const updateOrganizationAddress = /* @__PURE__ */ oc
|
|
164
|
+
.meta(http({
|
|
165
|
+
method: "PATCH",
|
|
166
|
+
path: "/organizations/{organization_id}/addresses/{address_id}",
|
|
167
|
+
summary: "Update one of an Organization's addresses",
|
|
168
|
+
description: "Granted by an `address` authorization detail with `update` whose subject is this Organization.",
|
|
169
|
+
successDescription: "Address updated",
|
|
170
|
+
inputStructure: "detailed",
|
|
171
|
+
}))
|
|
172
|
+
.errors(errors(...SubjectErrors, InvalidRequest, AddressNotUpdated, PayloadTooLarge))
|
|
173
|
+
.input(v.object({
|
|
174
|
+
params: v.object({ organization_id: OrganizationIdParameter, address_id: AddressIdParameter }),
|
|
175
|
+
body: AddressUpdate,
|
|
176
|
+
}))
|
|
177
|
+
.output(AddressMutationResult);
|
|
178
|
+
/** Soft-delete one of an Organization's addresses. */
|
|
179
|
+
export const deleteOrganizationAddress = /* @__PURE__ */ oc
|
|
180
|
+
.meta(http({
|
|
181
|
+
method: "DELETE",
|
|
182
|
+
path: "/organizations/{organization_id}/addresses/{address_id}",
|
|
183
|
+
summary: "Soft-delete one of an Organization's addresses",
|
|
184
|
+
description: "Granted by an `address` authorization detail with `delete` whose subject is this Organization.",
|
|
185
|
+
successDescription: "Address deleted",
|
|
186
|
+
successStatus: 204,
|
|
187
|
+
inputStructure: "detailed",
|
|
188
|
+
}))
|
|
189
|
+
.errors(errors(...SubjectErrors))
|
|
190
|
+
.input(v.object({ params: v.object({ organization_id: OrganizationIdParameter, address_id: AddressIdParameter }) }));
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { type RouterContract } from "@orpc/contract";
|
|
2
|
+
import type * as v from "valibot";
|
|
3
|
+
/**
|
|
4
|
+
* An error the Andco API answers, as a class: its `error` code, its HTTP status and the schema of
|
|
5
|
+
* its data are declared once with {@link AndcoAPIError.define}, next to the operations that answer
|
|
6
|
+
* it, and the generated OpenAPI and the server's status map are read from those declarations.
|
|
7
|
+
*
|
|
8
|
+
* An application decides on `error` and on the error's data. `message` is an optional English
|
|
9
|
+
* sentence for the developer reading a log or a response, and `hint` an optional English sentence
|
|
10
|
+
* suggesting what to do about it: never branch on either, never show them to a person.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* /** The Account Key names an account of the subject. *\/
|
|
15
|
+
* export class AccountKeyTaken extends AndcoAPIError.define(
|
|
16
|
+
* "account_key_taken",
|
|
17
|
+
* 409,
|
|
18
|
+
* v.object({ reason: v.picklist(["held_by_subject", "closed"]) }),
|
|
19
|
+
* ) {
|
|
20
|
+
* constructor(reason: "held_by_subject" | "closed") {
|
|
21
|
+
* super({ reason }, `The Account Key names an account of the subject (${reason}).`);
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare abstract class AndcoAPIError<Code extends string = string, Data = unknown> extends Error {
|
|
27
|
+
/** The error's structured data, answered beside `error`. */
|
|
28
|
+
readonly data: Data;
|
|
29
|
+
/** The code the API answers in `{ "error": "..." }`. */
|
|
30
|
+
abstract readonly error: Code;
|
|
31
|
+
/** An English sentence suggesting to the developer what to do about the error, when there is one. */
|
|
32
|
+
readonly hint?: string;
|
|
33
|
+
constructor(
|
|
34
|
+
/** The error's structured data, answered beside `error`. */
|
|
35
|
+
data: Data, message?: string, hint?: string);
|
|
36
|
+
/**
|
|
37
|
+
* Declares an error: the base class of one concrete error, which adds a constructor that says how
|
|
38
|
+
* that error is built.
|
|
39
|
+
*
|
|
40
|
+
* @param error The code answered in `{ "error": "..." }`, in lower snake_case.
|
|
41
|
+
* @param status The HTTP status the error is answered with. One code has one status everywhere.
|
|
42
|
+
* @param data The shape of the error's data: a Valibot object schema, `v.object({})` when it has none.
|
|
43
|
+
* It must not declare `error`, `message` or `hint`, which every error already has.
|
|
44
|
+
*/
|
|
45
|
+
static define<const Code extends string, const Status extends number, Data extends AndcoAPIErrorDataSchema>(error: Code, status: Status, data: Data): (abstract new (data: v.InferOutput<Data>, message?: string, hint?: string) => {
|
|
46
|
+
readonly error: Code;
|
|
47
|
+
/** An English sentence suggesting to the developer what to do about the error, when there is one. */
|
|
48
|
+
readonly hint?: string;
|
|
49
|
+
/** The error's structured data, answered beside `error`. */
|
|
50
|
+
readonly data: v.InferOutput<Data>;
|
|
51
|
+
name: string;
|
|
52
|
+
message: string;
|
|
53
|
+
stack?: string;
|
|
54
|
+
cause?: unknown;
|
|
55
|
+
}) & {
|
|
56
|
+
readonly error: Code;
|
|
57
|
+
readonly status: Status;
|
|
58
|
+
readonly data: Data;
|
|
59
|
+
define<const Code extends string, const Status extends number, Data extends AndcoAPIErrorDataSchema>(error: Code, status: Status, data: Data): /*elided*/ any;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The schema of an error's data: an object, so its fields sit beside `error`, `message` and `hint`,
|
|
64
|
+
* and one that declares none of them, so no data can shadow them.
|
|
65
|
+
*/
|
|
66
|
+
export type AndcoAPIErrorDataSchema = v.GenericSchema<Record<string, unknown> & {
|
|
67
|
+
error?: never;
|
|
68
|
+
message?: never;
|
|
69
|
+
hint?: never;
|
|
70
|
+
}>;
|
|
71
|
+
/** A class made by {@link AndcoAPIError.define}, read by {@link errors} and {@link errorStatusOf}. */
|
|
72
|
+
export interface AndcoAPIErrorClass<Code extends string = string, Status extends number = number, Data extends AndcoAPIErrorDataSchema = AndcoAPIErrorDataSchema> {
|
|
73
|
+
readonly error: Code;
|
|
74
|
+
readonly status: Status;
|
|
75
|
+
readonly data: Data;
|
|
76
|
+
}
|
|
77
|
+
/** The entry of an oRPC error map for one {@link AndcoAPIError}, which also carries its status. */
|
|
78
|
+
export interface AndcoAPIErrorMapItem<Status extends number, Data extends AndcoAPIErrorDataSchema> {
|
|
79
|
+
readonly status: Status;
|
|
80
|
+
readonly data: Data;
|
|
81
|
+
}
|
|
82
|
+
/** The oRPC error map {@link errors} builds from the classes it receives. */
|
|
83
|
+
export type AndcoAPIErrorMap<Classes extends readonly AndcoAPIErrorClass[]> = {
|
|
84
|
+
[Class in Classes[number] as Class["error"]]: AndcoAPIErrorMapItem<Class["status"], Class["data"]>;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* The errors an operation answers, as the error map oRPC's `.errors(...)` takes.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* oc.meta(http({ method: "POST", path: "/accounts" })).errors(errors(InvalidRequest, InvalidToken, AccountKeyTaken));
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
export declare function errors<const Classes extends readonly AndcoAPIErrorClass[]>(...classes: Classes): AndcoAPIErrorMap<Classes>;
|
|
95
|
+
/**
|
|
96
|
+
* The HTTP status of every error a contract declares, by code: the `errorStatusMap` that oRPC's
|
|
97
|
+
* handler and OpenAPI generator take. It is collected from the operations instead of kept in a table,
|
|
98
|
+
* so an error is declared only where it is used (ADR 0040).
|
|
99
|
+
*
|
|
100
|
+
* @throws {Error} When two operations declare one code with different statuses: oRPC answers a code
|
|
101
|
+
* with one status, so they have to be two errors.
|
|
102
|
+
*/
|
|
103
|
+
export declare function errorStatusOf(contract: RouterContract): Record<string, number>;
|
|
104
|
+
//# sourceMappingURL=api-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-error.d.ts","sourceRoot":"","sources":["../../src/rest/api-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,KAAK,KAAK,CAAC,MAAM,SAAS,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,8BAAsB,aAAa,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM,EAAE,IAAI,GAAG,OAAO,CAAE,SAAQ,KAAK;IAQ3F,4DAA4D;IAC5D,QAAQ,CAAC,IAAI,EAAE,IAAI;IARrB,wDAAwD;IACxD,QAAQ,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC;IAE9B,qGAAqG;IACrG,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;;IAGrB,4DAA4D;IACnD,IAAI,EAAE,IAAI,EACnB,OAAO,CAAC,EAAE,MAAM,EAChB,IAAI,CAAC,EAAE,MAAM;IAOf;;;;;;;;OAQG;IACH,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,SAAS,MAAM,EAAE,KAAK,CAAC,MAAM,SAAS,MAAM,EAAE,IAAI,SAAS,uBAAuB,EACxG,KAAK,EAAE,IAAI,EACX,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,IAAI,uDApBA,MAAM,SACT,MAAM;;QAPf,qGAAqG;wBACrF,MAAM;QAGpB,4DAA4D;;;;;;;;;;qBAmB1C,IAAI,SAAS,MAAM,QAAQ,MAAM,SAAS,MAAM,EAAE,IAAI,SAAS,uBAAuB,SACjG,IAAI,UACH,MAAM,QACR,IAAI;;CAUb;AAED;;;GAGG;AACH,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,aAAa,CACnD,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IAAE,KAAK,CAAC,EAAE,KAAK,CAAC;IAAC,OAAO,CAAC,EAAE,KAAK,CAAC;IAAC,IAAI,CAAC,EAAE,KAAK,CAAA;CAAE,CAC3E,CAAC;AAEF,sGAAsG;AACtG,MAAM,WAAW,kBAAkB,CACjC,IAAI,SAAS,MAAM,GAAG,MAAM,EAC5B,MAAM,SAAS,MAAM,GAAG,MAAM,EAC9B,IAAI,SAAS,uBAAuB,GAAG,uBAAuB;IAE9D,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;CACrB;AAED,mGAAmG;AACnG,MAAM,WAAW,oBAAoB,CAAC,MAAM,SAAS,MAAM,EAAE,IAAI,SAAS,uBAAuB;IAC/F,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;CACrB;AAED,6EAA6E;AAC7E,MAAM,MAAM,gBAAgB,CAAC,OAAO,SAAS,SAAS,kBAAkB,EAAE,IAAI;KAC3E,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,oBAAoB,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CACnG,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAAC,KAAK,CAAC,OAAO,SAAS,SAAS,kBAAkB,EAAE,EACxE,GAAG,OAAO,EAAE,OAAO,GAClB,gBAAgB,CAAC,OAAO,CAAC,CAM3B;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAI9E"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { ProcedureContract } from "@orpc/contract";
|
|
2
|
+
/**
|
|
3
|
+
* An error the Andco API answers, as a class: its `error` code, its HTTP status and the schema of
|
|
4
|
+
* its data are declared once with {@link AndcoAPIError.define}, next to the operations that answer
|
|
5
|
+
* it, and the generated OpenAPI and the server's status map are read from those declarations.
|
|
6
|
+
*
|
|
7
|
+
* An application decides on `error` and on the error's data. `message` is an optional English
|
|
8
|
+
* sentence for the developer reading a log or a response, and `hint` an optional English sentence
|
|
9
|
+
* suggesting what to do about it: never branch on either, never show them to a person.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* /** The Account Key names an account of the subject. *\/
|
|
14
|
+
* export class AccountKeyTaken extends AndcoAPIError.define(
|
|
15
|
+
* "account_key_taken",
|
|
16
|
+
* 409,
|
|
17
|
+
* v.object({ reason: v.picklist(["held_by_subject", "closed"]) }),
|
|
18
|
+
* ) {
|
|
19
|
+
* constructor(reason: "held_by_subject" | "closed") {
|
|
20
|
+
* super({ reason }, `The Account Key names an account of the subject (${reason}).`);
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export class AndcoAPIError extends Error {
|
|
26
|
+
data;
|
|
27
|
+
/** An English sentence suggesting to the developer what to do about the error, when there is one. */
|
|
28
|
+
hint;
|
|
29
|
+
constructor(
|
|
30
|
+
/** The error's structured data, answered beside `error`. */
|
|
31
|
+
data, message, hint) {
|
|
32
|
+
super(message);
|
|
33
|
+
this.data = data;
|
|
34
|
+
this.name = new.target.name;
|
|
35
|
+
this.hint = hint;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Declares an error: the base class of one concrete error, which adds a constructor that says how
|
|
39
|
+
* that error is built.
|
|
40
|
+
*
|
|
41
|
+
* @param error The code answered in `{ "error": "..." }`, in lower snake_case.
|
|
42
|
+
* @param status The HTTP status the error is answered with. One code has one status everywhere.
|
|
43
|
+
* @param data The shape of the error's data: a Valibot object schema, `v.object({})` when it has none.
|
|
44
|
+
* It must not declare `error`, `message` or `hint`, which every error already has.
|
|
45
|
+
*/
|
|
46
|
+
static define(error, status, data) {
|
|
47
|
+
class Defined extends AndcoAPIError {
|
|
48
|
+
static error = error;
|
|
49
|
+
static status = status;
|
|
50
|
+
static data = data;
|
|
51
|
+
error = error;
|
|
52
|
+
}
|
|
53
|
+
return Defined;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The errors an operation answers, as the error map oRPC's `.errors(...)` takes.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* oc.meta(http({ method: "POST", path: "/accounts" })).errors(errors(InvalidRequest, InvalidToken, AccountKeyTaken));
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export function errors(...classes) {
|
|
65
|
+
const map = {};
|
|
66
|
+
for (const errorClass of classes) {
|
|
67
|
+
map[errorClass.error] = { status: errorClass.status, data: errorClass.data };
|
|
68
|
+
}
|
|
69
|
+
return map;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The HTTP status of every error a contract declares, by code: the `errorStatusMap` that oRPC's
|
|
73
|
+
* handler and OpenAPI generator take. It is collected from the operations instead of kept in a table,
|
|
74
|
+
* so an error is declared only where it is used (ADR 0040).
|
|
75
|
+
*
|
|
76
|
+
* @throws {Error} When two operations declare one code with different statuses: oRPC answers a code
|
|
77
|
+
* with one status, so they have to be two errors.
|
|
78
|
+
*/
|
|
79
|
+
export function errorStatusOf(contract) {
|
|
80
|
+
const statuses = {};
|
|
81
|
+
collectErrorStatuses(contract, statuses);
|
|
82
|
+
return statuses;
|
|
83
|
+
}
|
|
84
|
+
function collectErrorStatuses(router, statuses) {
|
|
85
|
+
if (!(router instanceof ProcedureContract)) {
|
|
86
|
+
for (const child of Object.values(router)) {
|
|
87
|
+
collectErrorStatuses(child, statuses);
|
|
88
|
+
}
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const errorMap = router["~orpc"].errorMap;
|
|
92
|
+
for (const [code, item] of Object.entries(errorMap)) {
|
|
93
|
+
const status = item?.status;
|
|
94
|
+
if (typeof status !== "number") {
|
|
95
|
+
throw new Error(`The error ${code} has no status: declare it with AndcoAPIError.define and list it with errors().`);
|
|
96
|
+
}
|
|
97
|
+
const known = statuses[code];
|
|
98
|
+
if (known !== undefined && known !== status) {
|
|
99
|
+
throw new Error(`The error ${code} is declared with the statuses ${known} and ${status}; a code has one status.`);
|
|
100
|
+
}
|
|
101
|
+
statuses[code] = status;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
import { InvalidOrigin, InvalidToken, ServerError, TemporarilyUnavailable, UnsupportedVersion } from "./common.js";
|
|
3
|
+
/** The Profile whose resources a Grant reaches. */
|
|
4
|
+
export declare const ProfileGrantHolder: v.StrictObjectSchema<{
|
|
5
|
+
readonly type: v.LiteralSchema<"profile", undefined>;
|
|
6
|
+
readonly identifier: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UuidAction<string, undefined>]>;
|
|
7
|
+
}, undefined>;
|
|
8
|
+
/** The Organization (Company) whose resources a Grant reaches. */
|
|
9
|
+
export declare const OrganizationGrantHolder: v.StrictObjectSchema<{
|
|
10
|
+
readonly type: v.LiteralSchema<"organization", undefined>;
|
|
11
|
+
readonly identifier: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>, v.DescriptionAction<string, "The Organization's identifier, the same value `authorizationDetails[].subject.identifier` carries: a positive decimal integer, as a string.">]>;
|
|
12
|
+
}, undefined>;
|
|
13
|
+
/**
|
|
14
|
+
* Whose resources the Grant reaches: the Profile, or the Organization (Company) the person consented
|
|
15
|
+
* for. It is the only place this response names an Organization outside `authorizationDetails`,
|
|
16
|
+
* because for an Organization the `subject` is the application. It carries the identifier and no
|
|
17
|
+
* identity data; the RUT and the legal name are read from the identities of the Organization.
|
|
18
|
+
*/
|
|
19
|
+
export declare const GrantHolder: v.SchemaWithPipe<readonly [v.VariantSchema<"type", [v.StrictObjectSchema<{
|
|
20
|
+
readonly type: v.LiteralSchema<"profile", undefined>;
|
|
21
|
+
readonly identifier: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UuidAction<string, undefined>]>;
|
|
22
|
+
}, undefined>, v.StrictObjectSchema<{
|
|
23
|
+
readonly type: v.LiteralSchema<"organization", undefined>;
|
|
24
|
+
readonly identifier: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>, v.DescriptionAction<string, "The Organization's identifier, the same value `authorizationDetails[].subject.identifier` carries: a positive decimal integer, as a string.">]>;
|
|
25
|
+
}, undefined>], undefined>, v.DescriptionAction<{
|
|
26
|
+
type: "profile";
|
|
27
|
+
identifier: string;
|
|
28
|
+
} | {
|
|
29
|
+
type: "organization";
|
|
30
|
+
identifier: string;
|
|
31
|
+
}, "Whose resources the Grant reaches: the Profile, or the Organization (Company) the person consented for. It is the only place this response names an Organization outside `authorizationDetails`, because for an Organization the `subject` is the application. It carries the identifier and no identity data; the RUT and the legal name are read from the identities of the Organization.">]>;
|
|
32
|
+
/** The Profile that consented to the Grant. */
|
|
33
|
+
export declare const GrantActor: v.StrictObjectSchema<{
|
|
34
|
+
readonly type: v.LiteralSchema<"profile", undefined>;
|
|
35
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UuidAction<string, undefined>]>;
|
|
36
|
+
}, undefined>;
|
|
37
|
+
/** The credential's principal when it is a Profile. */
|
|
38
|
+
export declare const ProfileGrantSubject: v.StrictObjectSchema<{
|
|
39
|
+
readonly type: v.LiteralSchema<"profile", undefined>;
|
|
40
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UuidAction<string, undefined>]>;
|
|
41
|
+
}, undefined>;
|
|
42
|
+
/** The credential's principal when it is the application, because an Organization consented. */
|
|
43
|
+
export declare const ApplicationGrantSubject: v.StrictObjectSchema<{
|
|
44
|
+
readonly type: v.LiteralSchema<"application", undefined>;
|
|
45
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UuidAction<string, undefined>]>;
|
|
46
|
+
}, undefined>;
|
|
47
|
+
/** The credential's principal: the Profile, or the application when an Organization consented. */
|
|
48
|
+
export declare const GrantSubject: v.VariantSchema<"type", [v.StrictObjectSchema<{
|
|
49
|
+
readonly type: v.LiteralSchema<"profile", undefined>;
|
|
50
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UuidAction<string, undefined>]>;
|
|
51
|
+
}, undefined>, v.StrictObjectSchema<{
|
|
52
|
+
readonly type: v.LiteralSchema<"application", undefined>;
|
|
53
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UuidAction<string, undefined>]>;
|
|
54
|
+
}, undefined>], undefined>;
|
|
55
|
+
/** The active Grant a bearer token carries, as a Resource Server reads it. */
|
|
56
|
+
export declare const GrantAuthorization: v.StrictObjectSchema<{
|
|
57
|
+
readonly active: v.LiteralSchema<true, undefined>;
|
|
58
|
+
readonly actor: v.StrictObjectSchema<{
|
|
59
|
+
readonly type: v.LiteralSchema<"profile", undefined>;
|
|
60
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UuidAction<string, undefined>]>;
|
|
61
|
+
}, undefined>;
|
|
62
|
+
readonly authorizationDetails: v.ArraySchema<v.RecordSchema<v.StringSchema<undefined>, v.UnknownSchema, undefined>, undefined>;
|
|
63
|
+
readonly clientId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UuidAction<string, undefined>]>;
|
|
64
|
+
readonly grantId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UuidAction<string, undefined>]>;
|
|
65
|
+
readonly holder: v.SchemaWithPipe<readonly [v.VariantSchema<"type", [v.StrictObjectSchema<{
|
|
66
|
+
readonly type: v.LiteralSchema<"profile", undefined>;
|
|
67
|
+
readonly identifier: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UuidAction<string, undefined>]>;
|
|
68
|
+
}, undefined>, v.StrictObjectSchema<{
|
|
69
|
+
readonly type: v.LiteralSchema<"organization", undefined>;
|
|
70
|
+
readonly identifier: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>, v.DescriptionAction<string, "The Organization's identifier, the same value `authorizationDetails[].subject.identifier` carries: a positive decimal integer, as a string.">]>;
|
|
71
|
+
}, undefined>], undefined>, v.DescriptionAction<{
|
|
72
|
+
type: "profile";
|
|
73
|
+
identifier: string;
|
|
74
|
+
} | {
|
|
75
|
+
type: "organization";
|
|
76
|
+
identifier: string;
|
|
77
|
+
}, "Whose resources the Grant reaches: the Profile, or the Organization (Company) the person consented for. It is the only place this response names an Organization outside `authorizationDetails`, because for an Organization the `subject` is the application. It carries the identifier and no identity data; the RUT and the legal name are read from the identities of the Organization.">]>;
|
|
78
|
+
readonly resource: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UrlAction<string, undefined>]>;
|
|
79
|
+
readonly scopes: v.ArraySchema<v.StringSchema<undefined>, undefined>;
|
|
80
|
+
readonly subject: v.VariantSchema<"type", [v.StrictObjectSchema<{
|
|
81
|
+
readonly type: v.LiteralSchema<"profile", undefined>;
|
|
82
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UuidAction<string, undefined>]>;
|
|
83
|
+
}, undefined>, v.StrictObjectSchema<{
|
|
84
|
+
readonly type: v.LiteralSchema<"application", undefined>;
|
|
85
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UuidAction<string, undefined>]>;
|
|
86
|
+
}, undefined>], undefined>;
|
|
87
|
+
}, undefined>;
|
|
88
|
+
/** The active Grant a bearer token carries. */
|
|
89
|
+
export type GrantAuthorization = v.InferOutput<typeof GrantAuthorization>;
|
|
90
|
+
/** Reads the active Grant the bearer token carries. */
|
|
91
|
+
export declare const getGrantAuthorization: import("@orpc/contract").ProcedureContractBuilderWithOutput<v.StrictObjectSchema<{
|
|
92
|
+
readonly active: v.LiteralSchema<true, undefined>;
|
|
93
|
+
readonly actor: v.StrictObjectSchema<{
|
|
94
|
+
readonly type: v.LiteralSchema<"profile", undefined>;
|
|
95
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UuidAction<string, undefined>]>;
|
|
96
|
+
}, undefined>;
|
|
97
|
+
readonly authorizationDetails: v.ArraySchema<v.RecordSchema<v.StringSchema<undefined>, v.UnknownSchema, undefined>, undefined>;
|
|
98
|
+
readonly clientId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UuidAction<string, undefined>]>;
|
|
99
|
+
readonly grantId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UuidAction<string, undefined>]>;
|
|
100
|
+
readonly holder: v.SchemaWithPipe<readonly [v.VariantSchema<"type", [v.StrictObjectSchema<{
|
|
101
|
+
readonly type: v.LiteralSchema<"profile", undefined>;
|
|
102
|
+
readonly identifier: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UuidAction<string, undefined>]>;
|
|
103
|
+
}, undefined>, v.StrictObjectSchema<{
|
|
104
|
+
readonly type: v.LiteralSchema<"organization", undefined>;
|
|
105
|
+
readonly identifier: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>, v.DescriptionAction<string, "The Organization's identifier, the same value `authorizationDetails[].subject.identifier` carries: a positive decimal integer, as a string.">]>;
|
|
106
|
+
}, undefined>], undefined>, v.DescriptionAction<{
|
|
107
|
+
type: "profile";
|
|
108
|
+
identifier: string;
|
|
109
|
+
} | {
|
|
110
|
+
type: "organization";
|
|
111
|
+
identifier: string;
|
|
112
|
+
}, "Whose resources the Grant reaches: the Profile, or the Organization (Company) the person consented for. It is the only place this response names an Organization outside `authorizationDetails`, because for an Organization the `subject` is the application. It carries the identifier and no identity data; the RUT and the legal name are read from the identities of the Organization.">]>;
|
|
113
|
+
readonly resource: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UrlAction<string, undefined>]>;
|
|
114
|
+
readonly scopes: v.ArraySchema<v.StringSchema<undefined>, undefined>;
|
|
115
|
+
readonly subject: v.VariantSchema<"type", [v.StrictObjectSchema<{
|
|
116
|
+
readonly type: v.LiteralSchema<"profile", undefined>;
|
|
117
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UuidAction<string, undefined>]>;
|
|
118
|
+
}, undefined>, v.StrictObjectSchema<{
|
|
119
|
+
readonly type: v.LiteralSchema<"application", undefined>;
|
|
120
|
+
readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.UuidAction<string, undefined>]>;
|
|
121
|
+
}, undefined>], undefined>;
|
|
122
|
+
}, undefined>, import("./api-error.js").AndcoAPIErrorMap<readonly [typeof InvalidToken, typeof InvalidOrigin, typeof UnsupportedVersion, typeof ServerError, typeof TemporarilyUnavailable]>>;
|
|
123
|
+
//# sourceMappingURL=authorization.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorization.d.ts","sourceRoot":"","sources":["../../src/rest/authorization.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAE7B,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,WAAW,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAGnH,mDAAmD;AACnD,eAAO,MAAM,kBAAkB;;;aAG7B,CAAC;AAEH,kEAAkE;AAClE,eAAO,MAAM,uBAAuB;;;aASlC,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,WAAW;;;;;;;;;;;;mYAKvB,CAAC;AAEF,+CAA+C;AAC/C,eAAO,MAAM,UAAU;;;aAGrB,CAAC;AAEH,uDAAuD;AACvD,eAAO,MAAM,mBAAmB;;;aAG9B,CAAC;AAEH,gGAAgG;AAChG,eAAO,MAAM,uBAAuB;;;aAGlC,CAAC;AAEH,kGAAkG;AAClG,eAAO,MAAM,YAAY;;;;;;0BAAoF,CAAC;AAE9G,8EAA8E;AAC9E,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aAU7B,CAAC;AAEH,+CAA+C;AAC/C,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE1E,uDAAuD;AACvD,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6LAYL,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { oc } from "@orpc/contract";
|
|
2
|
+
import * as v from "valibot";
|
|
3
|
+
import { errors } from "./api-error.js";
|
|
4
|
+
import { InvalidOrigin, InvalidToken, ServerError, TemporarilyUnavailable, UnsupportedVersion } from "./common.js";
|
|
5
|
+
import { http } from "./http.js";
|
|
6
|
+
/** The Profile whose resources a Grant reaches. */
|
|
7
|
+
export const ProfileGrantHolder = /* @__PURE__ */ v.strictObject({
|
|
8
|
+
type: v.literal("profile"),
|
|
9
|
+
identifier: v.pipe(v.string(), v.uuid()),
|
|
10
|
+
});
|
|
11
|
+
/** The Organization (Company) whose resources a Grant reaches. */
|
|
12
|
+
export const OrganizationGrantHolder = /* @__PURE__ */ v.strictObject({
|
|
13
|
+
type: v.literal("organization"),
|
|
14
|
+
identifier: v.pipe(v.string(), v.regex(/^[1-9][0-9]{0,9}$/), v.description("The Organization's identifier, the same value `authorizationDetails[].subject.identifier` carries: a positive decimal integer, as a string.")),
|
|
15
|
+
});
|
|
16
|
+
/**
|
|
17
|
+
* Whose resources the Grant reaches: the Profile, or the Organization (Company) the person consented
|
|
18
|
+
* for. It is the only place this response names an Organization outside `authorizationDetails`,
|
|
19
|
+
* because for an Organization the `subject` is the application. It carries the identifier and no
|
|
20
|
+
* identity data; the RUT and the legal name are read from the identities of the Organization.
|
|
21
|
+
*/
|
|
22
|
+
export const GrantHolder = /* @__PURE__ */ v.pipe(v.variant("type", [ProfileGrantHolder, OrganizationGrantHolder]), v.description("Whose resources the Grant reaches: the Profile, or the Organization (Company) the person consented for. It is the only place this response names an Organization outside `authorizationDetails`, because for an Organization the `subject` is the application. It carries the identifier and no identity data; the RUT and the legal name are read from the identities of the Organization."));
|
|
23
|
+
/** The Profile that consented to the Grant. */
|
|
24
|
+
export const GrantActor = /* @__PURE__ */ v.strictObject({
|
|
25
|
+
type: v.literal("profile"),
|
|
26
|
+
id: v.pipe(v.string(), v.uuid()),
|
|
27
|
+
});
|
|
28
|
+
/** The credential's principal when it is a Profile. */
|
|
29
|
+
export const ProfileGrantSubject = /* @__PURE__ */ v.strictObject({
|
|
30
|
+
type: v.literal("profile"),
|
|
31
|
+
id: v.pipe(v.string(), v.uuid()),
|
|
32
|
+
});
|
|
33
|
+
/** The credential's principal when it is the application, because an Organization consented. */
|
|
34
|
+
export const ApplicationGrantSubject = /* @__PURE__ */ v.strictObject({
|
|
35
|
+
type: v.literal("application"),
|
|
36
|
+
id: v.pipe(v.string(), v.uuid()),
|
|
37
|
+
});
|
|
38
|
+
/** The credential's principal: the Profile, or the application when an Organization consented. */
|
|
39
|
+
export const GrantSubject = /* @__PURE__ */ v.variant("type", [ProfileGrantSubject, ApplicationGrantSubject]);
|
|
40
|
+
/** The active Grant a bearer token carries, as a Resource Server reads it. */
|
|
41
|
+
export const GrantAuthorization = /* @__PURE__ */ v.strictObject({
|
|
42
|
+
active: v.literal(true),
|
|
43
|
+
actor: GrantActor,
|
|
44
|
+
authorizationDetails: v.array(v.record(v.string(), v.unknown())),
|
|
45
|
+
clientId: v.pipe(v.string(), v.uuid()),
|
|
46
|
+
grantId: v.pipe(v.string(), v.uuid()),
|
|
47
|
+
holder: GrantHolder,
|
|
48
|
+
resource: v.pipe(v.string(), v.url()),
|
|
49
|
+
scopes: v.array(v.string()),
|
|
50
|
+
subject: GrantSubject,
|
|
51
|
+
});
|
|
52
|
+
/** Reads the active Grant the bearer token carries. */
|
|
53
|
+
export const getGrantAuthorization = /* @__PURE__ */ oc
|
|
54
|
+
.meta(http({
|
|
55
|
+
method: "GET",
|
|
56
|
+
path: "/authorization",
|
|
57
|
+
summary: "Get the active Grant carried by the bearer token",
|
|
58
|
+
description: "`subject` is the credential's principal: the Profile, or the application when an Organization consented. `holder` is whose resources the Grant reaches, the Profile or the Organization, so a Resource Server learns which Company authorized without reading it out of the details.",
|
|
59
|
+
successDescription: "Active Grant context for a Resource Server",
|
|
60
|
+
}))
|
|
61
|
+
.errors(errors(InvalidToken, InvalidOrigin, UnsupportedVersion, ServerError, TemporarilyUnavailable))
|
|
62
|
+
.output(GrantAuthorization);
|