@andco/protocol 0.0.3 → 0.0.5
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 +1 -1
- package/README.md +51 -3
- package/dist/api-errors.d.ts +114 -0
- package/dist/api-errors.d.ts.map +1 -0
- package/dist/api-errors.js +116 -0
- package/dist/authorization-preparation.d.ts +52 -543
- package/dist/authorization-preparation.d.ts.map +1 -1
- package/dist/authorization-preparation.js +19 -42
- package/dist/authorization.d.ts +64 -22
- package/dist/authorization.d.ts.map +1 -1
- package/dist/authorization.js +136 -55
- package/dist/consent.d.ts +5 -8
- package/dist/consent.d.ts.map +1 -1
- package/dist/consent.js +5 -62
- package/dist/constants.d.ts +19 -3
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +19 -3
- package/dist/errors.d.ts +154 -58
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +174 -57
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/intent-input.d.ts +1022 -288
- package/dist/intent-input.d.ts.map +1 -1
- package/dist/intent-input.js +284 -40
- package/dist/messages/error.d.ts +1 -2
- package/dist/messages/error.d.ts.map +1 -1
- package/dist/messages/error.js +5 -2
- package/dist/messages/index.d.ts +1 -1
- package/dist/native-copy.d.ts +23 -2
- package/dist/native-copy.d.ts.map +1 -1
- package/dist/native-copy.js +65 -117
- package/dist/native-intent.d.ts +126 -75
- package/dist/native-intent.d.ts.map +1 -1
- package/dist/native-intent.js +140 -48
- package/dist/rar/account-matchers.d.ts +579 -0
- package/dist/rar/account-matchers.d.ts.map +1 -0
- package/dist/rar/account-matchers.js +480 -0
- package/dist/rar/bank.d.ts +1549 -0
- package/dist/rar/bank.d.ts.map +1 -0
- package/dist/rar/bank.js +379 -0
- package/dist/rar/catalog.d.ts +1155 -0
- package/dist/rar/catalog.d.ts.map +1 -0
- package/dist/rar/catalog.js +175 -0
- package/dist/rar/detail.d.ts +39 -0
- package/dist/rar/detail.d.ts.map +1 -0
- package/dist/rar/detail.js +44 -0
- package/dist/rar/index.d.ts +9 -0
- package/dist/rar/index.d.ts.map +1 -0
- package/dist/rar/index.js +8 -0
- package/dist/rar/money.d.ts +58 -0
- package/dist/rar/money.d.ts.map +1 -0
- package/dist/rar/money.js +61 -0
- package/dist/rar/project-users.d.ts +43 -0
- package/dist/rar/project-users.d.ts.map +1 -0
- package/dist/rar/project-users.js +63 -0
- package/dist/rar/subject-data.d.ts +170 -0
- package/dist/rar/subject-data.d.ts.map +1 -0
- package/dist/rar/subject-data.js +127 -0
- package/dist/rar/subject.d.ts +166 -0
- package/dist/rar/subject.d.ts.map +1 -0
- package/dist/rar/subject.js +119 -0
- package/dist/scopes.d.ts +5 -30
- package/dist/scopes.d.ts.map +1 -1
- package/dist/scopes.js +0 -13
- package/dist/service-grants.d.ts +44 -0
- package/dist/service-grants.d.ts.map +1 -0
- package/dist/service-grants.js +45 -0
- package/dist/signing.d.ts +56 -0
- package/dist/signing.d.ts.map +1 -0
- package/dist/signing.js +233 -0
- package/dist/transport/financial-events.d.ts +90 -35
- package/dist/transport/financial-events.d.ts.map +1 -1
- package/dist/transport/financial-events.js +7 -1
- package/dist/transport/generated/oauth-api.d.ts +932 -441
- package/dist/transport/generated/oauth-api.d.ts.map +1 -1
- package/dist/transport/index.d.ts +0 -1
- package/dist/transport/index.d.ts.map +1 -1
- package/dist/transport/index.js +0 -1
- package/dist/transport/intents.d.ts +155 -23
- package/dist/transport/intents.d.ts.map +1 -1
- package/dist/transport/intents.js +192 -59
- package/dist/transport/rest.d.ts +19 -8
- package/dist/transport/rest.d.ts.map +1 -1
- package/dist/transport/rest.js +1 -1
- package/dist/urls.d.ts.map +1 -1
- package/dist/urls.js +1 -1
- package/dist/userinfo.d.ts +10 -1
- package/dist/userinfo.d.ts.map +1 -1
- package/dist/userinfo.js +10 -1
- package/dist/utils.d.ts +15 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +31 -0
- package/dist/webhooks.d.ts +154 -0
- package/dist/webhooks.d.ts.map +1 -0
- package/dist/webhooks.js +249 -0
- package/package.json +21 -2
- package/dist/automatic-charge.d.ts +0 -314
- package/dist/automatic-charge.d.ts.map +0 -1
- package/dist/automatic-charge.js +0 -126
- package/dist/bank-account-authorization.d.ts +0 -6
- package/dist/bank-account-authorization.d.ts.map +0 -1
- package/dist/bank-account-authorization.js +0 -13
- package/dist/transport/webhooks.d.ts +0 -27
- package/dist/transport/webhooks.d.ts.map +0 -1
- package/dist/transport/webhooks.js +0 -68
- package/dist/webhook-input.d.ts +0 -22
- package/dist/webhook-input.d.ts.map +0 -1
- package/dist/webhook-input.js +0 -11
- package/dist/webhook-signature.d.ts +0 -54
- package/dist/webhook-signature.d.ts.map +0 -1
- package/dist/webhook-signature.js +0 -74
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../../src/rar/catalog.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
import { ANDCO_API_ERROR_CODES } from "../api-errors.js";
|
|
3
|
+
import { ErrorExtendable } from "../errors.js";
|
|
4
|
+
import { BANK_ACCOUNT_ACTIONS, BANK_ACCOUNT_GRANT_JSON_SCHEMA, BANK_ACCOUNT_GRANT_REQUEST_JSON_SCHEMA, BANK_DEPOSIT_ACTIONS, BANK_DEPOSIT_GRANT_JSON_SCHEMA, BANK_DEPOSIT_GRANT_REQUEST_JSON_SCHEMA, BANK_TRANSACTION_ACTIONS, BANK_TRANSACTION_GRANT_JSON_SCHEMA, BANK_TRANSACTION_GRANT_REQUEST_JSON_SCHEMA, BANK_TRANSFER_ACTIONS, BANK_TRANSFER_GRANT_JSON_SCHEMA, BANK_TRANSFER_GRANT_REQUEST_JSON_SCHEMA, BankAccountGrantRequestSchema, BankAccountGrantSchema, BankDepositGrantRequestSchema, BankDepositGrantSchema, BankTransactionGrantRequestSchema, BankTransactionGrantSchema, BankTransferGrantRequestSchema, BankTransferGrantSchema, } from "./bank.js";
|
|
5
|
+
import { PROJECT_USERS_ACTIONS, PROJECT_USERS_GRANT_JSON_SCHEMA, PROJECT_USERS_GRANT_REQUEST_JSON_SCHEMA, ProjectUsersGrantRequestSchema, ProjectUsersGrantSchema, } from "./project-users.js";
|
|
6
|
+
import { ADDRESS_ACTIONS, ADDRESS_GRANT_JSON_SCHEMA, ADDRESS_GRANT_REQUEST_JSON_SCHEMA, AddressGrantRequestSchema, AddressGrantSchema, IDENTITY_ACTIONS, IDENTITY_GRANT_JSON_SCHEMA, IDENTITY_GRANT_REQUEST_JSON_SCHEMA, IdentityGrantRequestSchema, IdentityGrantSchema, ORGANIZATION_ACTIONS, ORGANIZATION_GRANT_JSON_SCHEMA, ORGANIZATION_GRANT_REQUEST_JSON_SCHEMA, OrganizationGrantRequestSchema, OrganizationGrantSchema, PROFILE_ACTIONS, PROFILE_GRANT_JSON_SCHEMA, PROFILE_GRANT_REQUEST_JSON_SCHEMA, ProfileGrantRequestSchema, ProfileGrantSchema, } from "./subject-data.js";
|
|
7
|
+
/** Every authorization detail type Andco's Resource Server implements. */
|
|
8
|
+
export const ANDCO_RAR_TYPES = [
|
|
9
|
+
"bank_account",
|
|
10
|
+
"bank_transaction",
|
|
11
|
+
"bank_transfer",
|
|
12
|
+
"bank_deposit",
|
|
13
|
+
"identity",
|
|
14
|
+
"address",
|
|
15
|
+
"organization",
|
|
16
|
+
"profile",
|
|
17
|
+
"project_users",
|
|
18
|
+
];
|
|
19
|
+
/**
|
|
20
|
+
* Types that belong to the model but are not built yet. A detail naming one is rejected with
|
|
21
|
+
* `not_implemented` rather than `invalid_request`, because it is valid and expected to be supported.
|
|
22
|
+
*/
|
|
23
|
+
export const ANDCO_RESERVED_RAR_TYPES = ["bank_beneficiaries", "identity_documents"];
|
|
24
|
+
/**
|
|
25
|
+
* The whole Andco authorization detail catalog, keyed by type. The gate's seeds store
|
|
26
|
+
* `grantRequestJsonSchema` as each type's request schema and `actions` as its registered actions;
|
|
27
|
+
* a guard test compares them against this object.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* const { grantRequestJsonSchema, actions } = ANDCO_RAR_CATALOG.bank_transfer;
|
|
31
|
+
*/
|
|
32
|
+
export const ANDCO_RAR_CATALOG = {
|
|
33
|
+
bank_account: {
|
|
34
|
+
actions: BANK_ACCOUNT_ACTIONS,
|
|
35
|
+
grantRequest: BankAccountGrantRequestSchema,
|
|
36
|
+
grant: BankAccountGrantSchema,
|
|
37
|
+
grantRequestJsonSchema: BANK_ACCOUNT_GRANT_REQUEST_JSON_SCHEMA,
|
|
38
|
+
grantJsonSchema: BANK_ACCOUNT_GRANT_JSON_SCHEMA,
|
|
39
|
+
},
|
|
40
|
+
bank_transaction: {
|
|
41
|
+
actions: BANK_TRANSACTION_ACTIONS,
|
|
42
|
+
grantRequest: BankTransactionGrantRequestSchema,
|
|
43
|
+
grant: BankTransactionGrantSchema,
|
|
44
|
+
grantRequestJsonSchema: BANK_TRANSACTION_GRANT_REQUEST_JSON_SCHEMA,
|
|
45
|
+
grantJsonSchema: BANK_TRANSACTION_GRANT_JSON_SCHEMA,
|
|
46
|
+
},
|
|
47
|
+
bank_transfer: {
|
|
48
|
+
actions: BANK_TRANSFER_ACTIONS,
|
|
49
|
+
grantRequest: BankTransferGrantRequestSchema,
|
|
50
|
+
grant: BankTransferGrantSchema,
|
|
51
|
+
grantRequestJsonSchema: BANK_TRANSFER_GRANT_REQUEST_JSON_SCHEMA,
|
|
52
|
+
grantJsonSchema: BANK_TRANSFER_GRANT_JSON_SCHEMA,
|
|
53
|
+
},
|
|
54
|
+
bank_deposit: {
|
|
55
|
+
actions: BANK_DEPOSIT_ACTIONS,
|
|
56
|
+
grantRequest: BankDepositGrantRequestSchema,
|
|
57
|
+
grant: BankDepositGrantSchema,
|
|
58
|
+
grantRequestJsonSchema: BANK_DEPOSIT_GRANT_REQUEST_JSON_SCHEMA,
|
|
59
|
+
grantJsonSchema: BANK_DEPOSIT_GRANT_JSON_SCHEMA,
|
|
60
|
+
},
|
|
61
|
+
identity: {
|
|
62
|
+
actions: IDENTITY_ACTIONS,
|
|
63
|
+
grantRequest: IdentityGrantRequestSchema,
|
|
64
|
+
grant: IdentityGrantSchema,
|
|
65
|
+
grantRequestJsonSchema: IDENTITY_GRANT_REQUEST_JSON_SCHEMA,
|
|
66
|
+
grantJsonSchema: IDENTITY_GRANT_JSON_SCHEMA,
|
|
67
|
+
},
|
|
68
|
+
address: {
|
|
69
|
+
actions: ADDRESS_ACTIONS,
|
|
70
|
+
grantRequest: AddressGrantRequestSchema,
|
|
71
|
+
grant: AddressGrantSchema,
|
|
72
|
+
grantRequestJsonSchema: ADDRESS_GRANT_REQUEST_JSON_SCHEMA,
|
|
73
|
+
grantJsonSchema: ADDRESS_GRANT_JSON_SCHEMA,
|
|
74
|
+
},
|
|
75
|
+
organization: {
|
|
76
|
+
actions: ORGANIZATION_ACTIONS,
|
|
77
|
+
grantRequest: OrganizationGrantRequestSchema,
|
|
78
|
+
grant: OrganizationGrantSchema,
|
|
79
|
+
grantRequestJsonSchema: ORGANIZATION_GRANT_REQUEST_JSON_SCHEMA,
|
|
80
|
+
grantJsonSchema: ORGANIZATION_GRANT_JSON_SCHEMA,
|
|
81
|
+
},
|
|
82
|
+
profile: {
|
|
83
|
+
actions: PROFILE_ACTIONS,
|
|
84
|
+
grantRequest: ProfileGrantRequestSchema,
|
|
85
|
+
grant: ProfileGrantSchema,
|
|
86
|
+
grantRequestJsonSchema: PROFILE_GRANT_REQUEST_JSON_SCHEMA,
|
|
87
|
+
grantJsonSchema: PROFILE_GRANT_JSON_SCHEMA,
|
|
88
|
+
},
|
|
89
|
+
project_users: {
|
|
90
|
+
actions: PROJECT_USERS_ACTIONS,
|
|
91
|
+
grantRequest: ProjectUsersGrantRequestSchema,
|
|
92
|
+
grant: ProjectUsersGrantSchema,
|
|
93
|
+
grantRequestJsonSchema: PROJECT_USERS_GRANT_REQUEST_JSON_SCHEMA,
|
|
94
|
+
grantJsonSchema: PROJECT_USERS_GRANT_JSON_SCHEMA,
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* An authorization detail that cannot be used: `invalid_request` when it breaks the contract,
|
|
99
|
+
* `not_implemented` when it names a reserved type. The codes are the API's own, so the SDK fails
|
|
100
|
+
* locally with the error the server would have answered.
|
|
101
|
+
*/
|
|
102
|
+
export class AndcoRarError extends ErrorExtendable {
|
|
103
|
+
code;
|
|
104
|
+
type;
|
|
105
|
+
issues;
|
|
106
|
+
constructor(code, type, issues = [], options) {
|
|
107
|
+
super(`${code}: ${type ?? "authorization detail"}`, options);
|
|
108
|
+
this.code = code;
|
|
109
|
+
this.type = type;
|
|
110
|
+
this.issues = issues;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/** Whether `type` is one of {@link ANDCO_RAR_TYPES}. */
|
|
114
|
+
export function isAndcoRarType(type) {
|
|
115
|
+
return typeof type === "string" && ANDCO_RAR_TYPES.includes(type);
|
|
116
|
+
}
|
|
117
|
+
/** Whether `type` is one of {@link ANDCO_RESERVED_RAR_TYPES}. */
|
|
118
|
+
export function isAndcoReservedRarType(type) {
|
|
119
|
+
return typeof type === "string" && ANDCO_RESERVED_RAR_TYPES.includes(type);
|
|
120
|
+
}
|
|
121
|
+
function typeOf(detail) {
|
|
122
|
+
if (typeof detail !== "object" || detail === null)
|
|
123
|
+
return undefined;
|
|
124
|
+
const type = detail.type;
|
|
125
|
+
return typeof type === "string" ? type : undefined;
|
|
126
|
+
}
|
|
127
|
+
function parseForm(detail, form, caller) {
|
|
128
|
+
const type = typeOf(detail);
|
|
129
|
+
if (isAndcoReservedRarType(type)) {
|
|
130
|
+
console.debug("[%s] reserved type %s is not implemented", caller, type);
|
|
131
|
+
throw new AndcoRarError(ANDCO_API_ERROR_CODES.NOT_IMPLEMENTED, type);
|
|
132
|
+
}
|
|
133
|
+
if (!isAndcoRarType(type)) {
|
|
134
|
+
console.debug("[%s] unknown authorization detail type %o", caller, type);
|
|
135
|
+
throw new AndcoRarError(ANDCO_API_ERROR_CODES.INVALID_REQUEST, type);
|
|
136
|
+
}
|
|
137
|
+
const result = v.safeParse(ANDCO_RAR_CATALOG[type][form], detail);
|
|
138
|
+
if (!result.success) {
|
|
139
|
+
console.debug("[%s] %s does not satisfy its contract %o", caller, type, v.flatten(result.issues));
|
|
140
|
+
throw new AndcoRarError(ANDCO_API_ERROR_CODES.INVALID_REQUEST, type, result.issues);
|
|
141
|
+
}
|
|
142
|
+
return result.output;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Validates one Andco authorization detail in its Grant Request form, dispatching on `type`.
|
|
146
|
+
* Throws {@link AndcoRarError}: `not_implemented` for a reserved type, `invalid_request` otherwise.
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* const detail = parseAndcoGrantRequest({
|
|
150
|
+
* type: "bank_transfer",
|
|
151
|
+
* actions: ["create"],
|
|
152
|
+
* locations: ["https://api.andco.com"],
|
|
153
|
+
* subject: { type: "profile" },
|
|
154
|
+
* currency: "CLP",
|
|
155
|
+
* transactions: { value: "25990" },
|
|
156
|
+
* });
|
|
157
|
+
*/
|
|
158
|
+
export function parseAndcoGrantRequest(detail) {
|
|
159
|
+
return parseForm(detail, "grantRequest", "parseAndcoGrantRequest");
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Validates one Andco authorization detail in its Grant form, as `GET /authorization` returns it.
|
|
163
|
+
* Throws {@link AndcoRarError} like {@link parseAndcoGrantRequest}.
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* const grant = parseAndcoGrant({
|
|
167
|
+
* type: "identity",
|
|
168
|
+
* actions: ["read"],
|
|
169
|
+
* locations: ["https://api.andco.com"],
|
|
170
|
+
* subject: { type: "organization", identifier: "42" },
|
|
171
|
+
* });
|
|
172
|
+
*/
|
|
173
|
+
export function parseAndcoGrant(detail) {
|
|
174
|
+
return parseForm(detail, "grant", "parseAndcoGrant");
|
|
175
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
/** The `locations` every Andco authorization detail carries: Andco's Resource Server, alone. */
|
|
3
|
+
export declare const ANDCO_RAR_LOCATIONS: readonly ["https://api.andco.com"];
|
|
4
|
+
/** Valibot schema of {@link ANDCO_RAR_LOCATIONS}. */
|
|
5
|
+
export declare const AndcoRarLocationsSchema: v.TupleSchema<[v.LiteralSchema<"https://api.andco.com", undefined>], undefined>;
|
|
6
|
+
/** A non-empty list of distinct actions drawn from `options`. */
|
|
7
|
+
export declare function actionSet<const Options extends readonly [string, ...string[]]>(options: Options): v.SchemaWithPipe<readonly [v.ArraySchema<v.PicklistSchema<Options, undefined>, undefined>, v.MinLengthAction<Options[number][], 1, undefined>, v.CheckAction<Options[number][], "duplicate_action">]>;
|
|
8
|
+
/** Wraps a JSON Schema so that `null` is also accepted, the JSON form of valibot's `nullish`. */
|
|
9
|
+
export declare function nullableJson<Schema extends object>(schema: Schema): {
|
|
10
|
+
anyOf: (Schema | {
|
|
11
|
+
type: string;
|
|
12
|
+
})[];
|
|
13
|
+
};
|
|
14
|
+
/** JSON Schema mirror of {@link actionSet}. */
|
|
15
|
+
export declare function actionSetJson(options: readonly string[]): {
|
|
16
|
+
type: string;
|
|
17
|
+
minItems: number;
|
|
18
|
+
uniqueItems: boolean;
|
|
19
|
+
items: {
|
|
20
|
+
enum: string[];
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
/** JSON Schema mirror of {@link AndcoRarLocationsSchema}. */
|
|
24
|
+
export declare const ANDCO_RAR_LOCATIONS_JSON_SCHEMA: {
|
|
25
|
+
type: string;
|
|
26
|
+
minItems: number;
|
|
27
|
+
maxItems: number;
|
|
28
|
+
items: {
|
|
29
|
+
const: "https://api.andco.com";
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
/** One form of an authorization detail as a closed JSON Schema object. */
|
|
33
|
+
export declare function detailFormJson(type: string, actions: object, properties: Record<string, object>, required: readonly string[]): Record<string, unknown>;
|
|
34
|
+
/**
|
|
35
|
+
* The JSON Schema document of one authorization detail type: a single form, or the forms a type
|
|
36
|
+
* splits into by action family. It is what a seed stores as the type's request schema.
|
|
37
|
+
*/
|
|
38
|
+
export declare function detailTypeJson(forms: readonly Record<string, unknown>[]): Record<string, unknown>;
|
|
39
|
+
//# sourceMappingURL=detail.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detail.d.ts","sourceRoot":"","sources":["../../src/rar/detail.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAG7B,gGAAgG;AAChG,eAAO,MAAM,mBAAmB,oCAA8B,CAAC;AAE/D,qDAAqD;AACrD,eAAO,MAAM,uBAAuB,iFAAyD,CAAC;AAE9F,iEAAiE;AACjE,wBAAgB,SAAS,CAAC,KAAK,CAAC,OAAO,SAAS,SAAS,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,OAAO,yMAM/F;AAED,iGAAiG;AACjG,wBAAgB,YAAY,CAAC,MAAM,SAAS,MAAM,EAAE,MAAM,EAAE,MAAM;;;;EAEjE;AAED,+CAA+C;AAC/C,wBAAgB,aAAa,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE;;;;;;;EAEvD;AAED,6DAA6D;AAC7D,eAAO,MAAM,+BAA+B;;;;;;;CAK3C,CAAC;AAEF,0EAA0E;AAC1E,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAClC,QAAQ,EAAE,SAAS,MAAM,EAAE,GAC1B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAOzB;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAIjG"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
import { ANDCO_API_ORIGIN } from "../constants.js";
|
|
3
|
+
/** The `locations` every Andco authorization detail carries: Andco's Resource Server, alone. */
|
|
4
|
+
export const ANDCO_RAR_LOCATIONS = [ANDCO_API_ORIGIN];
|
|
5
|
+
/** Valibot schema of {@link ANDCO_RAR_LOCATIONS}. */
|
|
6
|
+
export const AndcoRarLocationsSchema = /* @__PURE__ */ v.tuple([v.literal(ANDCO_API_ORIGIN)]);
|
|
7
|
+
/** A non-empty list of distinct actions drawn from `options`. */
|
|
8
|
+
export function actionSet(options) {
|
|
9
|
+
return v.pipe(v.array(v.picklist(options)), v.minLength(1), v.check((actions) => new Set(actions).size === actions.length, "duplicate_action"));
|
|
10
|
+
}
|
|
11
|
+
/** Wraps a JSON Schema so that `null` is also accepted, the JSON form of valibot's `nullish`. */
|
|
12
|
+
export function nullableJson(schema) {
|
|
13
|
+
return { anyOf: [{ type: "null" }, schema] };
|
|
14
|
+
}
|
|
15
|
+
/** JSON Schema mirror of {@link actionSet}. */
|
|
16
|
+
export function actionSetJson(options) {
|
|
17
|
+
return { type: "array", minItems: 1, uniqueItems: true, items: { enum: [...options] } };
|
|
18
|
+
}
|
|
19
|
+
/** JSON Schema mirror of {@link AndcoRarLocationsSchema}. */
|
|
20
|
+
export const ANDCO_RAR_LOCATIONS_JSON_SCHEMA = {
|
|
21
|
+
type: "array",
|
|
22
|
+
minItems: 1,
|
|
23
|
+
maxItems: 1,
|
|
24
|
+
items: { const: ANDCO_API_ORIGIN },
|
|
25
|
+
};
|
|
26
|
+
/** One form of an authorization detail as a closed JSON Schema object. */
|
|
27
|
+
export function detailFormJson(type, actions, properties, required) {
|
|
28
|
+
return {
|
|
29
|
+
type: "object",
|
|
30
|
+
additionalProperties: false,
|
|
31
|
+
required: ["type", "actions", "locations", ...required],
|
|
32
|
+
properties: { type: { const: type }, actions, locations: ANDCO_RAR_LOCATIONS_JSON_SCHEMA, ...properties },
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The JSON Schema document of one authorization detail type: a single form, or the forms a type
|
|
37
|
+
* splits into by action family. It is what a seed stores as the type's request schema.
|
|
38
|
+
*/
|
|
39
|
+
export function detailTypeJson(forms) {
|
|
40
|
+
const [only] = forms;
|
|
41
|
+
if (forms.length === 1 && only !== undefined)
|
|
42
|
+
return { $schema: "http://json-schema.org/draft-07/schema#", ...only };
|
|
43
|
+
return { $schema: "http://json-schema.org/draft-07/schema#", anyOf: forms };
|
|
44
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./account-matchers.js";
|
|
2
|
+
export * from "./bank.js";
|
|
3
|
+
export * from "./catalog.js";
|
|
4
|
+
export { ANDCO_RAR_LOCATIONS, AndcoRarLocationsSchema } from "./detail.js";
|
|
5
|
+
export * from "./money.js";
|
|
6
|
+
export * from "./project-users.js";
|
|
7
|
+
export * from "./subject.js";
|
|
8
|
+
export * from "./subject-data.js";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/rar/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAC3E,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./account-matchers.js";
|
|
2
|
+
export * from "./bank.js";
|
|
3
|
+
export * from "./catalog.js";
|
|
4
|
+
export { ANDCO_RAR_LOCATIONS, AndcoRarLocationsSchema } from "./detail.js";
|
|
5
|
+
export * from "./money.js";
|
|
6
|
+
export * from "./project-users.js";
|
|
7
|
+
export * from "./subject.js";
|
|
8
|
+
export * from "./subject-data.js";
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
/**
|
|
3
|
+
* Syntax of the monetary scalar carried as a string everywhere CLP moves: `MonetaryValue` in the
|
|
4
|
+
* OpenAPI contract, strictly positive -- an amount that actually moves.
|
|
5
|
+
*
|
|
6
|
+
* Fifteen digits, not sixteen, and not because that is the largest value `Number.isSafeInteger`
|
|
7
|
+
* tolerates -- `9999999999999999` (sixteen digits) already passes that check today and still turns
|
|
8
|
+
* into a different number the moment something calls `Number()` on it. The real ceiling is set by
|
|
9
|
+
* the weaker of the two engines that evaluate this same scalar: valibot here, and the JSON Schema
|
|
10
|
+
* mirrors of every authorization detail, which travel into the Postgres seeds that are the only
|
|
11
|
+
* place an authorization detail is actually gated. JSON Schema's `pattern` matches a string; its
|
|
12
|
+
* `maximum` matches a number. There is nowhere in those seeds to hang a `Number.isSafeInteger`-shaped
|
|
13
|
+
* check on a string field, so the only bound JSON Schema can enforce here is a digit count baked into
|
|
14
|
+
* the regex itself. If valibot's bound and the regex's bound ever disagree, whichever side is looser
|
|
15
|
+
* decides what the gate actually accepts. Fifteen digits is the largest count both sides can enforce
|
|
16
|
+
* identically today.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* new RegExp(MONEY_PATTERN).test("25990"); // true
|
|
20
|
+
* new RegExp(MONEY_PATTERN).test("0"); // false
|
|
21
|
+
*/
|
|
22
|
+
export declare const MONEY_PATTERN = "^[1-9][0-9]{0,14}$";
|
|
23
|
+
/**
|
|
24
|
+
* {@link MONEY_PATTERN}, additionally admitting `"0"`. A quantity of money that may legitimately be
|
|
25
|
+
* absent -- an initial withdrawal fee, a deposit that has not yet been credited -- uses this scalar
|
|
26
|
+
* instead of retyping the pattern with the zero case folded in by hand.
|
|
27
|
+
*/
|
|
28
|
+
export declare const MONEY_OR_ZERO_PATTERN = "^(0|[1-9][0-9]{0,14})$";
|
|
29
|
+
/** A strictly positive monetary value. See {@link MONEY_PATTERN}. */
|
|
30
|
+
export declare const MoneySchema: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>;
|
|
31
|
+
/** A monetary value that may be zero. See {@link MONEY_OR_ZERO_PATTERN}. */
|
|
32
|
+
export declare const MoneyOrZeroSchema: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>;
|
|
33
|
+
/** Money is always a decimal string of whole CLP, never a `number`. */
|
|
34
|
+
export type Money = string;
|
|
35
|
+
/**
|
|
36
|
+
* Absolute floor of every amount an authorization detail bounds: no `value`, `minimum` or `maximum`
|
|
37
|
+
* of a Transfer permission may be below it.
|
|
38
|
+
*/
|
|
39
|
+
export declare const MINIMUM_TRANSACTION_AMOUNT = "1000";
|
|
40
|
+
/**
|
|
41
|
+
* {@link MONEY_PATTERN} restricted to amounts of at least {@link MINIMUM_TRANSACTION_AMOUNT}: four to
|
|
42
|
+
* fifteen digits without a leading zero. It is a separate scalar, not a change to `MONEY_PATTERN`,
|
|
43
|
+
* because only the limits of a permission carry the floor; a Transaction read back from the ledger
|
|
44
|
+
* may be smaller.
|
|
45
|
+
*
|
|
46
|
+
* The floor lives in the regex, rather than in a numeric comparison, because the JSON Schema mirror
|
|
47
|
+
* has no numeric comparison over strings: this way both engines enforce the same bound.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* new RegExp(TRANSACTION_LIMIT_PATTERN).test("1000"); // true
|
|
51
|
+
* new RegExp(TRANSACTION_LIMIT_PATTERN).test("999"); // false
|
|
52
|
+
*/
|
|
53
|
+
export declare const TRANSACTION_LIMIT_PATTERN = "^[1-9][0-9]{3,14}$";
|
|
54
|
+
/** A permission's amount limit: {@link MoneySchema} at or above {@link MINIMUM_TRANSACTION_AMOUNT}. */
|
|
55
|
+
export declare const TransactionLimitSchema: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, "amount_below_minimum_or_malformed">]>;
|
|
56
|
+
/** Compares two strings that already passed {@link MoneySchema}, without ever calling `Number()`. */
|
|
57
|
+
export declare function compareMoney(left: Money, right: Money): -1 | 0 | 1;
|
|
58
|
+
//# sourceMappingURL=money.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"money.d.ts","sourceRoot":"","sources":["../../src/rar/money.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAE7B;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,aAAa,uBAAuB,CAAC;AAElD;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,2BAA2B,CAAC;AAE9D,qEAAqE;AACrE,eAAO,MAAM,WAAW,0FAAyE,CAAC;AAClG,4EAA4E;AAC5E,eAAO,MAAM,iBAAiB,0FAAiF,CAAC;AAEhH,uEAAuE;AACvE,MAAM,MAAM,KAAK,GAAG,MAAM,CAAC;AAE3B;;;GAGG;AACH,eAAO,MAAM,0BAA0B,SAAS,CAAC;AAEjD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,yBAAyB,uBAAuB,CAAC;AAE9D,uGAAuG;AACvG,eAAO,MAAM,sBAAsB,oHAGlC,CAAC;AAEF,qGAAqG;AACrG,wBAAgB,YAAY,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAKlE"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
/**
|
|
3
|
+
* Syntax of the monetary scalar carried as a string everywhere CLP moves: `MonetaryValue` in the
|
|
4
|
+
* OpenAPI contract, strictly positive -- an amount that actually moves.
|
|
5
|
+
*
|
|
6
|
+
* Fifteen digits, not sixteen, and not because that is the largest value `Number.isSafeInteger`
|
|
7
|
+
* tolerates -- `9999999999999999` (sixteen digits) already passes that check today and still turns
|
|
8
|
+
* into a different number the moment something calls `Number()` on it. The real ceiling is set by
|
|
9
|
+
* the weaker of the two engines that evaluate this same scalar: valibot here, and the JSON Schema
|
|
10
|
+
* mirrors of every authorization detail, which travel into the Postgres seeds that are the only
|
|
11
|
+
* place an authorization detail is actually gated. JSON Schema's `pattern` matches a string; its
|
|
12
|
+
* `maximum` matches a number. There is nowhere in those seeds to hang a `Number.isSafeInteger`-shaped
|
|
13
|
+
* check on a string field, so the only bound JSON Schema can enforce here is a digit count baked into
|
|
14
|
+
* the regex itself. If valibot's bound and the regex's bound ever disagree, whichever side is looser
|
|
15
|
+
* decides what the gate actually accepts. Fifteen digits is the largest count both sides can enforce
|
|
16
|
+
* identically today.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* new RegExp(MONEY_PATTERN).test("25990"); // true
|
|
20
|
+
* new RegExp(MONEY_PATTERN).test("0"); // false
|
|
21
|
+
*/
|
|
22
|
+
export const MONEY_PATTERN = "^[1-9][0-9]{0,14}$";
|
|
23
|
+
/**
|
|
24
|
+
* {@link MONEY_PATTERN}, additionally admitting `"0"`. A quantity of money that may legitimately be
|
|
25
|
+
* absent -- an initial withdrawal fee, a deposit that has not yet been credited -- uses this scalar
|
|
26
|
+
* instead of retyping the pattern with the zero case folded in by hand.
|
|
27
|
+
*/
|
|
28
|
+
export const MONEY_OR_ZERO_PATTERN = "^(0|[1-9][0-9]{0,14})$";
|
|
29
|
+
/** A strictly positive monetary value. See {@link MONEY_PATTERN}. */
|
|
30
|
+
export const MoneySchema = /* @__PURE__ */ v.pipe(v.string(), v.regex(new RegExp(MONEY_PATTERN)));
|
|
31
|
+
/** A monetary value that may be zero. See {@link MONEY_OR_ZERO_PATTERN}. */
|
|
32
|
+
export const MoneyOrZeroSchema = /* @__PURE__ */ v.pipe(v.string(), v.regex(new RegExp(MONEY_OR_ZERO_PATTERN)));
|
|
33
|
+
/**
|
|
34
|
+
* Absolute floor of every amount an authorization detail bounds: no `value`, `minimum` or `maximum`
|
|
35
|
+
* of a Transfer permission may be below it.
|
|
36
|
+
*/
|
|
37
|
+
export const MINIMUM_TRANSACTION_AMOUNT = "1000";
|
|
38
|
+
/**
|
|
39
|
+
* {@link MONEY_PATTERN} restricted to amounts of at least {@link MINIMUM_TRANSACTION_AMOUNT}: four to
|
|
40
|
+
* fifteen digits without a leading zero. It is a separate scalar, not a change to `MONEY_PATTERN`,
|
|
41
|
+
* because only the limits of a permission carry the floor; a Transaction read back from the ledger
|
|
42
|
+
* may be smaller.
|
|
43
|
+
*
|
|
44
|
+
* The floor lives in the regex, rather than in a numeric comparison, because the JSON Schema mirror
|
|
45
|
+
* has no numeric comparison over strings: this way both engines enforce the same bound.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* new RegExp(TRANSACTION_LIMIT_PATTERN).test("1000"); // true
|
|
49
|
+
* new RegExp(TRANSACTION_LIMIT_PATTERN).test("999"); // false
|
|
50
|
+
*/
|
|
51
|
+
export const TRANSACTION_LIMIT_PATTERN = "^[1-9][0-9]{3,14}$";
|
|
52
|
+
/** A permission's amount limit: {@link MoneySchema} at or above {@link MINIMUM_TRANSACTION_AMOUNT}. */
|
|
53
|
+
export const TransactionLimitSchema = /* @__PURE__ */ v.pipe(v.string(), v.regex(new RegExp(TRANSACTION_LIMIT_PATTERN), "amount_below_minimum_or_malformed"));
|
|
54
|
+
/** Compares two strings that already passed {@link MoneySchema}, without ever calling `Number()`. */
|
|
55
|
+
export function compareMoney(left, right) {
|
|
56
|
+
const a = BigInt(left);
|
|
57
|
+
const b = BigInt(right);
|
|
58
|
+
if (a === b)
|
|
59
|
+
return 0;
|
|
60
|
+
return a < b ? -1 : 1;
|
|
61
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
/** Reading the Profiles of a Project's users: `GET /projects/{project_id}/profiles`. */
|
|
3
|
+
export declare const PROJECT_USERS_ACTIONS: readonly ["read"];
|
|
4
|
+
/** The Profile fields a `project_users` detail may expose. An empty or absent list means all of them. */
|
|
5
|
+
export declare const PROJECT_USERS_FIELDS: readonly ["id", "name", "email", "avatar", "phone", "identities", "addresses"];
|
|
6
|
+
/**
|
|
7
|
+
* `project_users` Grant Request, only for `service` clients: read the users of the client's
|
|
8
|
+
* Projects. It has no subject: the Projects are the boundary. An empty or absent `project_ids`,
|
|
9
|
+
* `client_ids` or `fields` means all of them.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const admin: ProjectUsersGrantRequest = {
|
|
13
|
+
* type: "project_users",
|
|
14
|
+
* actions: ["read"],
|
|
15
|
+
* locations: ["https://api.andco.com"],
|
|
16
|
+
* project_ids: [],
|
|
17
|
+
* fields: ["id", "name", "email", "phone"],
|
|
18
|
+
* };
|
|
19
|
+
*/
|
|
20
|
+
export declare const ProjectUsersGrantRequestSchema: v.StrictObjectSchema<{
|
|
21
|
+
readonly type: v.LiteralSchema<"project_users", undefined>;
|
|
22
|
+
readonly actions: v.SchemaWithPipe<readonly [v.ArraySchema<v.PicklistSchema<readonly ["read"], undefined>, undefined>, v.MinLengthAction<"read"[], 1, undefined>, v.CheckAction<"read"[], "duplicate_action">]>;
|
|
23
|
+
readonly locations: v.TupleSchema<[v.LiteralSchema<"https://api.andco.com", undefined>], undefined>;
|
|
24
|
+
readonly project_ids: v.NullishSchema<v.SchemaWithPipe<readonly [v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>, undefined>, v.MaxLengthAction<string[], 100, undefined>, v.CheckAction<string[], "duplicate_identifier">]>, undefined>;
|
|
25
|
+
readonly client_ids: v.NullishSchema<v.SchemaWithPipe<readonly [v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>, undefined>, v.MaxLengthAction<string[], 100, undefined>, v.CheckAction<string[], "duplicate_identifier">]>, undefined>;
|
|
26
|
+
readonly fields: v.NullishSchema<v.SchemaWithPipe<readonly [v.ArraySchema<v.PicklistSchema<readonly ["id", "name", "email", "avatar", "phone", "identities", "addresses"], undefined>, undefined>, v.CheckAction<("email" | "phone" | "id" | "name" | "avatar" | "identities" | "addresses")[], "duplicate_field">]>, undefined>;
|
|
27
|
+
}, undefined>;
|
|
28
|
+
export type ProjectUsersGrantRequest = v.InferInput<typeof ProjectUsersGrantRequestSchema>;
|
|
29
|
+
/** `project_users` Grant: the three lists always present, an empty one still meaning all. */
|
|
30
|
+
export declare const ProjectUsersGrantSchema: v.StrictObjectSchema<{
|
|
31
|
+
readonly type: v.LiteralSchema<"project_users", undefined>;
|
|
32
|
+
readonly actions: v.SchemaWithPipe<readonly [v.ArraySchema<v.PicklistSchema<readonly ["read"], undefined>, undefined>, v.MinLengthAction<"read"[], 1, undefined>, v.CheckAction<"read"[], "duplicate_action">]>;
|
|
33
|
+
readonly locations: v.TupleSchema<[v.LiteralSchema<"https://api.andco.com", undefined>], undefined>;
|
|
34
|
+
readonly project_ids: v.SchemaWithPipe<readonly [v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>, undefined>, v.MaxLengthAction<string[], 100, undefined>, v.CheckAction<string[], "duplicate_identifier">]>;
|
|
35
|
+
readonly client_ids: v.SchemaWithPipe<readonly [v.ArraySchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.RegexAction<string, undefined>]>, undefined>, v.MaxLengthAction<string[], 100, undefined>, v.CheckAction<string[], "duplicate_identifier">]>;
|
|
36
|
+
readonly fields: v.SchemaWithPipe<readonly [v.ArraySchema<v.PicklistSchema<readonly ["id", "name", "email", "avatar", "phone", "identities", "addresses"], undefined>, undefined>, v.CheckAction<("email" | "phone" | "id" | "name" | "avatar" | "identities" | "addresses")[], "duplicate_field">]>;
|
|
37
|
+
}, undefined>;
|
|
38
|
+
export type ProjectUsersGrant = v.InferOutput<typeof ProjectUsersGrantSchema>;
|
|
39
|
+
/** JSON Schema mirror of {@link ProjectUsersGrantRequestSchema}. */
|
|
40
|
+
export declare const PROJECT_USERS_GRANT_REQUEST_JSON_SCHEMA: Record<string, unknown>;
|
|
41
|
+
/** JSON Schema mirror of {@link ProjectUsersGrantSchema}. */
|
|
42
|
+
export declare const PROJECT_USERS_GRANT_JSON_SCHEMA: Record<string, unknown>;
|
|
43
|
+
//# sourceMappingURL=project-users.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project-users.d.ts","sourceRoot":"","sources":["../../src/rar/project-users.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAC;AAU7B,wFAAwF;AACxF,eAAO,MAAM,qBAAqB,mBAAoB,CAAC;AAEvD,yGAAyG;AACzG,eAAO,MAAM,oBAAoB,gFAAiF,CAAC;AAmBnH;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,8BAA8B;;;;;;;aAOzC,CAAC;AACH,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,UAAU,CAAC,OAAO,8BAA8B,CAAC,CAAC;AAE3F,6FAA6F;AAC7F,eAAO,MAAM,uBAAuB;;;;;;;aAOlC,CAAC;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAU9E,oEAAoE;AACpE,eAAO,MAAM,uCAAuC,yBAWlD,CAAC;AACH,6DAA6D;AAC7D,eAAO,MAAM,+BAA+B,yBAO1C,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
2
|
+
import { AndcoRarLocationsSchema, actionSet, actionSetJson, detailFormJson, detailTypeJson, nullableJson, } from "./detail.js";
|
|
3
|
+
/** Reading the Profiles of a Project's users: `GET /projects/{project_id}/profiles`. */
|
|
4
|
+
export const PROJECT_USERS_ACTIONS = ["read"];
|
|
5
|
+
/** The Profile fields a `project_users` detail may expose. An empty or absent list means all of them. */
|
|
6
|
+
export const PROJECT_USERS_FIELDS = ["id", "name", "email", "avatar", "phone", "identities", "addresses"];
|
|
7
|
+
/** Upper bound of the `project_ids` and `client_ids` lists. */
|
|
8
|
+
const PROJECT_USERS_LIST_CEILING = 100;
|
|
9
|
+
/** Project and Client ids are UUID-shaped; no version digit is checked, as with Profile identifiers. */
|
|
10
|
+
const UUID_PATTERN = "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$";
|
|
11
|
+
const distinct = (values) => new Set(values).size === values.length;
|
|
12
|
+
const uuidList = /* @__PURE__ */ v.pipe(v.array(v.pipe(v.string(), v.regex(new RegExp(UUID_PATTERN)))), v.maxLength(PROJECT_USERS_LIST_CEILING), v.check((values) => distinct(values), "duplicate_identifier"));
|
|
13
|
+
const fieldList = /* @__PURE__ */ v.pipe(v.array(v.picklist(PROJECT_USERS_FIELDS)), v.check((values) => distinct(values), "duplicate_field"));
|
|
14
|
+
/**
|
|
15
|
+
* `project_users` Grant Request, only for `service` clients: read the users of the client's
|
|
16
|
+
* Projects. It has no subject: the Projects are the boundary. An empty or absent `project_ids`,
|
|
17
|
+
* `client_ids` or `fields` means all of them.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const admin: ProjectUsersGrantRequest = {
|
|
21
|
+
* type: "project_users",
|
|
22
|
+
* actions: ["read"],
|
|
23
|
+
* locations: ["https://api.andco.com"],
|
|
24
|
+
* project_ids: [],
|
|
25
|
+
* fields: ["id", "name", "email", "phone"],
|
|
26
|
+
* };
|
|
27
|
+
*/
|
|
28
|
+
export const ProjectUsersGrantRequestSchema = /* @__PURE__ */ v.strictObject({
|
|
29
|
+
type: v.literal("project_users"),
|
|
30
|
+
actions: actionSet(PROJECT_USERS_ACTIONS),
|
|
31
|
+
locations: AndcoRarLocationsSchema,
|
|
32
|
+
project_ids: v.nullish(uuidList),
|
|
33
|
+
client_ids: v.nullish(uuidList),
|
|
34
|
+
fields: v.nullish(fieldList),
|
|
35
|
+
});
|
|
36
|
+
/** `project_users` Grant: the three lists always present, an empty one still meaning all. */
|
|
37
|
+
export const ProjectUsersGrantSchema = /* @__PURE__ */ v.strictObject({
|
|
38
|
+
type: v.literal("project_users"),
|
|
39
|
+
actions: actionSet(PROJECT_USERS_ACTIONS),
|
|
40
|
+
locations: AndcoRarLocationsSchema,
|
|
41
|
+
project_ids: uuidList,
|
|
42
|
+
client_ids: uuidList,
|
|
43
|
+
fields: fieldList,
|
|
44
|
+
});
|
|
45
|
+
const uuidListJson = {
|
|
46
|
+
type: "array",
|
|
47
|
+
maxItems: PROJECT_USERS_LIST_CEILING,
|
|
48
|
+
uniqueItems: true,
|
|
49
|
+
items: { type: "string", pattern: UUID_PATTERN },
|
|
50
|
+
};
|
|
51
|
+
const fieldListJson = { type: "array", uniqueItems: true, items: { enum: [...PROJECT_USERS_FIELDS] } };
|
|
52
|
+
/** JSON Schema mirror of {@link ProjectUsersGrantRequestSchema}. */
|
|
53
|
+
export const PROJECT_USERS_GRANT_REQUEST_JSON_SCHEMA = /* @__PURE__ */ detailTypeJson([
|
|
54
|
+
detailFormJson("project_users", actionSetJson(PROJECT_USERS_ACTIONS), {
|
|
55
|
+
project_ids: nullableJson(uuidListJson),
|
|
56
|
+
client_ids: nullableJson(uuidListJson),
|
|
57
|
+
fields: nullableJson(fieldListJson),
|
|
58
|
+
}, []),
|
|
59
|
+
]);
|
|
60
|
+
/** JSON Schema mirror of {@link ProjectUsersGrantSchema}. */
|
|
61
|
+
export const PROJECT_USERS_GRANT_JSON_SCHEMA = /* @__PURE__ */ detailTypeJson([
|
|
62
|
+
detailFormJson("project_users", actionSetJson(PROJECT_USERS_ACTIONS), { project_ids: uuidListJson, client_ids: uuidListJson, fields: fieldListJson }, ["project_ids", "client_ids", "fields"]),
|
|
63
|
+
]);
|