@voyant-travel/auth 0.136.0 → 0.137.0
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/customer-business-accounts-contracts.d.ts +159 -0
- package/dist/customer-business-accounts-contracts.js +112 -0
- package/dist/customer-business-accounts-contracts.js.map +1 -0
- package/dist/customer-business-onboarding-graph-runtime.d.ts +13 -0
- package/dist/customer-business-onboarding-graph-runtime.js +8 -0
- package/dist/customer-business-onboarding-graph-runtime.js.map +1 -0
- package/dist/customer-business-onboarding-routes.d.ts +13 -0
- package/dist/customer-business-onboarding-routes.js +151 -0
- package/dist/customer-business-onboarding-routes.js.map +1 -0
- package/dist/customer-business-onboarding-runtime-port.d.ts +40 -0
- package/dist/customer-business-onboarding-runtime-port.js +25 -0
- package/dist/customer-business-onboarding-runtime-port.js.map +1 -0
- package/dist/customer-business-onboarding-service.d.ts +32 -0
- package/dist/customer-business-onboarding-service.js +237 -0
- package/dist/customer-business-onboarding-service.js.map +1 -0
- package/dist/customer-buyer-accounts.d.ts +0 -19
- package/dist/customer-buyer-accounts.js.map +1 -1
- package/dist/node-runtime.d.ts +13 -0
- package/dist/node-runtime.js +285 -1
- package/dist/node-runtime.js.map +1 -1
- package/dist/ports.d.ts +1 -0
- package/dist/ports.js +2 -0
- package/dist/ports.js.map +1 -0
- package/dist/server.d.ts +39 -3
- package/dist/server.js.map +1 -1
- package/dist/voyant.d.ts +1 -0
- package/dist/voyant.js +81 -0
- package/dist/voyant.js.map +1 -1
- package/openapi/admin/customer-business-accounts.json +44 -0
- package/package.json +30 -4
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const storefrontOriginSchema: z.ZodPipe<z.ZodURL, z.ZodTransform<string, string>>;
|
|
3
|
+
export declare const customerBusinessOnboardingModeSchema: z.ZodEnum<{
|
|
4
|
+
open: "open";
|
|
5
|
+
request: "request";
|
|
6
|
+
"invite-only": "invite-only";
|
|
7
|
+
}>;
|
|
8
|
+
export declare const customerBusinessAccountRoleSchema: z.ZodEnum<{
|
|
9
|
+
member: "member";
|
|
10
|
+
admin: "admin";
|
|
11
|
+
owner: "owner";
|
|
12
|
+
}>;
|
|
13
|
+
export declare const customerBusinessAccountRequestStatusSchema: z.ZodEnum<{
|
|
14
|
+
canceled: "canceled";
|
|
15
|
+
pending: "pending";
|
|
16
|
+
approved: "approved";
|
|
17
|
+
rejected: "rejected";
|
|
18
|
+
}>;
|
|
19
|
+
export declare const customerBusinessProfileSchema: z.ZodObject<{
|
|
20
|
+
name: z.ZodString;
|
|
21
|
+
legalName: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
|
|
22
|
+
taxId: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
|
|
23
|
+
website: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodURL>>>;
|
|
24
|
+
}, z.core.$strict>;
|
|
25
|
+
export declare const customerBusinessAccountRequestSchema: z.ZodObject<{
|
|
26
|
+
id: z.ZodString;
|
|
27
|
+
requesterUserId: z.ZodString;
|
|
28
|
+
requesterEmail: z.ZodNullable<z.ZodEmail>;
|
|
29
|
+
requesterName: z.ZodNullable<z.ZodString>;
|
|
30
|
+
storefrontOrigin: z.ZodPipe<z.ZodURL, z.ZodTransform<string, string>>;
|
|
31
|
+
mode: z.ZodEnum<{
|
|
32
|
+
open: "open";
|
|
33
|
+
request: "request";
|
|
34
|
+
"invite-only": "invite-only";
|
|
35
|
+
}>;
|
|
36
|
+
profile: z.ZodObject<{
|
|
37
|
+
name: z.ZodString;
|
|
38
|
+
legalName: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
|
|
39
|
+
taxId: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
|
|
40
|
+
website: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodURL>>>;
|
|
41
|
+
}, z.core.$strict>;
|
|
42
|
+
status: z.ZodEnum<{
|
|
43
|
+
canceled: "canceled";
|
|
44
|
+
pending: "pending";
|
|
45
|
+
approved: "approved";
|
|
46
|
+
rejected: "rejected";
|
|
47
|
+
}>;
|
|
48
|
+
idempotencyKey: z.ZodString;
|
|
49
|
+
authOrganizationId: z.ZodNullable<z.ZodString>;
|
|
50
|
+
relationshipOrganizationId: z.ZodNullable<z.ZodString>;
|
|
51
|
+
createdAt: z.ZodString;
|
|
52
|
+
updatedAt: z.ZodString;
|
|
53
|
+
decidedAt: z.ZodNullable<z.ZodString>;
|
|
54
|
+
decidedBy: z.ZodNullable<z.ZodString>;
|
|
55
|
+
decisionReason: z.ZodNullable<z.ZodString>;
|
|
56
|
+
}, z.core.$strict>;
|
|
57
|
+
export declare const customerBusinessAccountSchema: z.ZodObject<{
|
|
58
|
+
id: z.ZodString;
|
|
59
|
+
kind: z.ZodLiteral<"business">;
|
|
60
|
+
name: z.ZodString;
|
|
61
|
+
authOrganizationId: z.ZodString;
|
|
62
|
+
relationshipOrganizationId: z.ZodString;
|
|
63
|
+
relationshipPersonId: z.ZodNull;
|
|
64
|
+
membershipId: z.ZodString;
|
|
65
|
+
membershipRole: z.ZodEnum<{
|
|
66
|
+
member: "member";
|
|
67
|
+
admin: "admin";
|
|
68
|
+
owner: "owner";
|
|
69
|
+
}>;
|
|
70
|
+
}, z.core.$strict>;
|
|
71
|
+
export declare const customerBusinessAccountCapabilitiesSchema: z.ZodObject<{
|
|
72
|
+
viewRequests: z.ZodBoolean;
|
|
73
|
+
decideRequests: z.ZodBoolean;
|
|
74
|
+
provisionAccounts: z.ZodBoolean;
|
|
75
|
+
}, z.core.$strict>;
|
|
76
|
+
export declare const customerBusinessAccountCreateInputSchema: z.ZodObject<{
|
|
77
|
+
idempotencyKey: z.ZodString;
|
|
78
|
+
profile: z.ZodObject<{
|
|
79
|
+
name: z.ZodString;
|
|
80
|
+
legalName: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
|
|
81
|
+
taxId: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
|
|
82
|
+
website: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodURL>>>;
|
|
83
|
+
}, z.core.$strict>;
|
|
84
|
+
}, z.core.$strict>;
|
|
85
|
+
export declare const customerBusinessAccountRequestCreateInputSchema: z.ZodObject<{
|
|
86
|
+
idempotencyKey: z.ZodString;
|
|
87
|
+
profile: z.ZodObject<{
|
|
88
|
+
name: z.ZodString;
|
|
89
|
+
legalName: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
|
|
90
|
+
taxId: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
|
|
91
|
+
website: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodURL>>>;
|
|
92
|
+
}, z.core.$strict>;
|
|
93
|
+
}, z.core.$strict>;
|
|
94
|
+
export declare const customerBusinessAccountRequestListQuerySchema: z.ZodObject<{
|
|
95
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
96
|
+
canceled: "canceled";
|
|
97
|
+
pending: "pending";
|
|
98
|
+
approved: "approved";
|
|
99
|
+
rejected: "rejected";
|
|
100
|
+
}>>;
|
|
101
|
+
}, z.core.$strict>;
|
|
102
|
+
export declare const customerBusinessAccountDecisionInputSchema: z.ZodObject<{
|
|
103
|
+
reason: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
104
|
+
}, z.core.$strict>;
|
|
105
|
+
export declare const customerBusinessAccountProvisionInputSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
106
|
+
idempotencyKey: z.ZodString;
|
|
107
|
+
storefrontOrigin: z.ZodPipe<z.ZodURL, z.ZodTransform<string, string>>;
|
|
108
|
+
owner: z.ZodObject<{
|
|
109
|
+
userId: z.ZodOptional<z.ZodString>;
|
|
110
|
+
email: z.ZodOptional<z.ZodEmail>;
|
|
111
|
+
}, z.core.$strict>;
|
|
112
|
+
relationshipOrganizationId: z.ZodString;
|
|
113
|
+
profile: z.ZodOptional<z.ZodNever>;
|
|
114
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
115
|
+
idempotencyKey: z.ZodString;
|
|
116
|
+
storefrontOrigin: z.ZodPipe<z.ZodURL, z.ZodTransform<string, string>>;
|
|
117
|
+
owner: z.ZodObject<{
|
|
118
|
+
userId: z.ZodOptional<z.ZodString>;
|
|
119
|
+
email: z.ZodOptional<z.ZodEmail>;
|
|
120
|
+
}, z.core.$strict>;
|
|
121
|
+
relationshipOrganizationId: z.ZodOptional<z.ZodNever>;
|
|
122
|
+
profile: z.ZodObject<{
|
|
123
|
+
name: z.ZodString;
|
|
124
|
+
legalName: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
|
|
125
|
+
taxId: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodString>>>;
|
|
126
|
+
website: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodURL>>>;
|
|
127
|
+
}, z.core.$strict>;
|
|
128
|
+
}, z.core.$strict>]>;
|
|
129
|
+
export declare const customerBusinessInvitationAcceptInputSchema: z.ZodObject<{
|
|
130
|
+
invitationId: z.ZodString;
|
|
131
|
+
}, z.core.$strict>;
|
|
132
|
+
export declare const customerBusinessInvitationAcceptResultSchema: z.ZodObject<{
|
|
133
|
+
account: z.ZodObject<{
|
|
134
|
+
id: z.ZodString;
|
|
135
|
+
kind: z.ZodLiteral<"business">;
|
|
136
|
+
name: z.ZodString;
|
|
137
|
+
authOrganizationId: z.ZodString;
|
|
138
|
+
relationshipOrganizationId: z.ZodString;
|
|
139
|
+
relationshipPersonId: z.ZodNull;
|
|
140
|
+
membershipId: z.ZodString;
|
|
141
|
+
membershipRole: z.ZodEnum<{
|
|
142
|
+
member: "member";
|
|
143
|
+
admin: "admin";
|
|
144
|
+
owner: "owner";
|
|
145
|
+
}>;
|
|
146
|
+
}, z.core.$strict>;
|
|
147
|
+
}, z.core.$strict>;
|
|
148
|
+
export type CustomerBusinessOnboardingMode = z.infer<typeof customerBusinessOnboardingModeSchema>;
|
|
149
|
+
export type CustomerBusinessAccountRole = z.infer<typeof customerBusinessAccountRoleSchema>;
|
|
150
|
+
export type CustomerBusinessAccountRequestStatus = z.infer<typeof customerBusinessAccountRequestStatusSchema>;
|
|
151
|
+
export type CustomerBusinessProfile = z.infer<typeof customerBusinessProfileSchema>;
|
|
152
|
+
export type CustomerBusinessAccountRequestDto = z.infer<typeof customerBusinessAccountRequestSchema>;
|
|
153
|
+
export type CustomerBusinessAccountDto = z.infer<typeof customerBusinessAccountSchema>;
|
|
154
|
+
export type CustomerBusinessAccountCapabilitiesDto = z.infer<typeof customerBusinessAccountCapabilitiesSchema>;
|
|
155
|
+
export type CustomerBusinessAccountCreateInput = z.infer<typeof customerBusinessAccountCreateInputSchema>;
|
|
156
|
+
export type CustomerBusinessAccountDecisionInput = z.infer<typeof customerBusinessAccountDecisionInputSchema>;
|
|
157
|
+
export type CustomerBusinessAccountProvisionInput = z.infer<typeof customerBusinessAccountProvisionInputSchema>;
|
|
158
|
+
export type CustomerBusinessInvitationAcceptInput = z.infer<typeof customerBusinessInvitationAcceptInputSchema>;
|
|
159
|
+
export type CustomerBusinessInvitationAcceptResult = z.infer<typeof customerBusinessInvitationAcceptResultSchema>;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const nullableTrimmedString = (max) => z.string().trim().min(1).max(max).nullable();
|
|
3
|
+
export const storefrontOriginSchema = z
|
|
4
|
+
.url()
|
|
5
|
+
.refine((value) => {
|
|
6
|
+
const url = new URL(value);
|
|
7
|
+
return ((url.protocol === "http:" || url.protocol === "https:") &&
|
|
8
|
+
url.username === "" &&
|
|
9
|
+
url.password === "" &&
|
|
10
|
+
url.pathname === "/" &&
|
|
11
|
+
url.search === "" &&
|
|
12
|
+
url.hash === "");
|
|
13
|
+
}, "Must be an exact HTTP(S) origin without credentials, path, query, or hash")
|
|
14
|
+
.transform((value) => new URL(value).origin);
|
|
15
|
+
export const customerBusinessOnboardingModeSchema = z.enum(["open", "request", "invite-only"]);
|
|
16
|
+
export const customerBusinessAccountRoleSchema = z.enum(["owner", "admin", "member"]);
|
|
17
|
+
export const customerBusinessAccountRequestStatusSchema = z.enum([
|
|
18
|
+
"pending",
|
|
19
|
+
"approved",
|
|
20
|
+
"rejected",
|
|
21
|
+
"canceled",
|
|
22
|
+
]);
|
|
23
|
+
export const customerBusinessProfileSchema = z
|
|
24
|
+
.object({
|
|
25
|
+
name: z.string().trim().min(1).max(200),
|
|
26
|
+
legalName: nullableTrimmedString(240).optional().default(null),
|
|
27
|
+
taxId: nullableTrimmedString(100).optional().default(null),
|
|
28
|
+
website: z.url().max(2_048).nullable().optional().default(null),
|
|
29
|
+
})
|
|
30
|
+
.strict();
|
|
31
|
+
export const customerBusinessAccountRequestSchema = z
|
|
32
|
+
.object({
|
|
33
|
+
id: z.string().min(1),
|
|
34
|
+
requesterUserId: z.string().min(1),
|
|
35
|
+
requesterEmail: z.email().nullable(),
|
|
36
|
+
requesterName: z.string().nullable(),
|
|
37
|
+
storefrontOrigin: storefrontOriginSchema,
|
|
38
|
+
mode: customerBusinessOnboardingModeSchema,
|
|
39
|
+
profile: customerBusinessProfileSchema,
|
|
40
|
+
status: customerBusinessAccountRequestStatusSchema,
|
|
41
|
+
idempotencyKey: z.string().min(1),
|
|
42
|
+
authOrganizationId: z.string().nullable(),
|
|
43
|
+
relationshipOrganizationId: z.string().nullable(),
|
|
44
|
+
createdAt: z.string().datetime(),
|
|
45
|
+
updatedAt: z.string().datetime(),
|
|
46
|
+
decidedAt: z.string().datetime().nullable(),
|
|
47
|
+
decidedBy: z.string().nullable(),
|
|
48
|
+
decisionReason: z.string().nullable(),
|
|
49
|
+
})
|
|
50
|
+
.strict();
|
|
51
|
+
export const customerBusinessAccountSchema = z
|
|
52
|
+
.object({
|
|
53
|
+
id: z.string().min(1),
|
|
54
|
+
kind: z.literal("business"),
|
|
55
|
+
name: z.string(),
|
|
56
|
+
authOrganizationId: z.string().min(1),
|
|
57
|
+
relationshipOrganizationId: z.string().min(1),
|
|
58
|
+
relationshipPersonId: z.null(),
|
|
59
|
+
membershipId: z.string().min(1),
|
|
60
|
+
membershipRole: customerBusinessAccountRoleSchema,
|
|
61
|
+
})
|
|
62
|
+
.strict();
|
|
63
|
+
export const customerBusinessAccountCapabilitiesSchema = z
|
|
64
|
+
.object({
|
|
65
|
+
viewRequests: z.boolean(),
|
|
66
|
+
decideRequests: z.boolean(),
|
|
67
|
+
provisionAccounts: z.boolean(),
|
|
68
|
+
})
|
|
69
|
+
.strict();
|
|
70
|
+
export const customerBusinessAccountCreateInputSchema = z
|
|
71
|
+
.object({
|
|
72
|
+
idempotencyKey: z.string().trim().min(8).max(200),
|
|
73
|
+
profile: customerBusinessProfileSchema,
|
|
74
|
+
})
|
|
75
|
+
.strict();
|
|
76
|
+
export const customerBusinessAccountRequestCreateInputSchema = customerBusinessAccountCreateInputSchema;
|
|
77
|
+
export const customerBusinessAccountRequestListQuerySchema = z
|
|
78
|
+
.object({ status: customerBusinessAccountRequestStatusSchema.optional() })
|
|
79
|
+
.strict();
|
|
80
|
+
export const customerBusinessAccountDecisionInputSchema = z
|
|
81
|
+
.object({ reason: z.string().trim().min(1).max(2_000).nullable().optional() })
|
|
82
|
+
.strict();
|
|
83
|
+
const customerOwnerSelectorSchema = z
|
|
84
|
+
.object({ userId: z.string().min(1).optional(), email: z.email().optional() })
|
|
85
|
+
.strict()
|
|
86
|
+
.refine((value) => Number(Boolean(value.userId)) + Number(Boolean(value.email)) === 1, {
|
|
87
|
+
message: "Exactly one customer owner userId or email is required",
|
|
88
|
+
});
|
|
89
|
+
const customerBusinessAccountProvisionBaseSchema = z
|
|
90
|
+
.object({
|
|
91
|
+
idempotencyKey: z.string().trim().min(8).max(200),
|
|
92
|
+
storefrontOrigin: storefrontOriginSchema,
|
|
93
|
+
owner: customerOwnerSelectorSchema,
|
|
94
|
+
})
|
|
95
|
+
.strict();
|
|
96
|
+
export const customerBusinessAccountProvisionInputSchema = z.union([
|
|
97
|
+
customerBusinessAccountProvisionBaseSchema.extend({
|
|
98
|
+
relationshipOrganizationId: z.string().min(1),
|
|
99
|
+
profile: z.never().optional(),
|
|
100
|
+
}),
|
|
101
|
+
customerBusinessAccountProvisionBaseSchema.extend({
|
|
102
|
+
relationshipOrganizationId: z.never().optional(),
|
|
103
|
+
profile: customerBusinessProfileSchema,
|
|
104
|
+
}),
|
|
105
|
+
]);
|
|
106
|
+
export const customerBusinessInvitationAcceptInputSchema = z
|
|
107
|
+
.object({ invitationId: z.string().trim().min(1) })
|
|
108
|
+
.strict();
|
|
109
|
+
export const customerBusinessInvitationAcceptResultSchema = z
|
|
110
|
+
.object({ account: customerBusinessAccountSchema })
|
|
111
|
+
.strict();
|
|
112
|
+
//# sourceMappingURL=customer-business-accounts-contracts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customer-business-accounts-contracts.js","sourceRoot":"","sources":["../src/customer-business-accounts-contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,MAAM,qBAAqB,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAA;AAE3F,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC;KACpC,GAAG,EAAE;KACL,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;IAChB,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAA;IAC1B,OAAO,CACL,CAAC,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAAC;QACvD,GAAG,CAAC,QAAQ,KAAK,EAAE;QACnB,GAAG,CAAC,QAAQ,KAAK,EAAE;QACnB,GAAG,CAAC,QAAQ,KAAK,GAA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;AAEX,MAAM,CAAC,MAAM,4CAA4C,GAAG,CAAC;KAC1D,MAAM,CAAC,EAAE,OAAO,EAAE,6BAA6B,EAAE,CAAC;KAClD,MAAM,EAAE,CAAA","sourcesContent":["import { z } from \"zod\"\n\nconst nullableTrimmedString = (max: number) => z.string().trim().min(1).max(max).nullable()\n\nexport const storefrontOriginSchema = z\n .url()\n .refine((value) => {\n const url = new URL(value)\n return (\n (url.protocol === \"http:\" || url.protocol === \"https:\") &&\n url.username === \"\" &&\n url.password === \"\" &&\n url.pathname === \"/\" &&\n url.search === \"\" &&\n url.hash === \"\"\n )\n }, \"Must be an exact HTTP(S) origin without credentials, path, query, or hash\")\n .transform((value) => new URL(value).origin)\n\nexport const customerBusinessOnboardingModeSchema = z.enum([\"open\", \"request\", \"invite-only\"])\nexport const customerBusinessAccountRoleSchema = z.enum([\"owner\", \"admin\", \"member\"])\nexport const customerBusinessAccountRequestStatusSchema = z.enum([\n \"pending\",\n \"approved\",\n \"rejected\",\n \"canceled\",\n])\n\nexport const customerBusinessProfileSchema = z\n .object({\n name: z.string().trim().min(1).max(200),\n legalName: nullableTrimmedString(240).optional().default(null),\n taxId: nullableTrimmedString(100).optional().default(null),\n website: z.url().max(2_048).nullable().optional().default(null),\n })\n .strict()\n\nexport const customerBusinessAccountRequestSchema = z\n .object({\n id: z.string().min(1),\n requesterUserId: z.string().min(1),\n requesterEmail: z.email().nullable(),\n requesterName: z.string().nullable(),\n storefrontOrigin: storefrontOriginSchema,\n mode: customerBusinessOnboardingModeSchema,\n profile: customerBusinessProfileSchema,\n status: customerBusinessAccountRequestStatusSchema,\n idempotencyKey: z.string().min(1),\n authOrganizationId: z.string().nullable(),\n relationshipOrganizationId: z.string().nullable(),\n createdAt: z.string().datetime(),\n updatedAt: z.string().datetime(),\n decidedAt: z.string().datetime().nullable(),\n decidedBy: z.string().nullable(),\n decisionReason: z.string().nullable(),\n })\n .strict()\n\nexport const customerBusinessAccountSchema = z\n .object({\n id: z.string().min(1),\n kind: z.literal(\"business\"),\n name: z.string(),\n authOrganizationId: z.string().min(1),\n relationshipOrganizationId: z.string().min(1),\n relationshipPersonId: z.null(),\n membershipId: z.string().min(1),\n membershipRole: customerBusinessAccountRoleSchema,\n })\n .strict()\n\nexport const customerBusinessAccountCapabilitiesSchema = z\n .object({\n viewRequests: z.boolean(),\n decideRequests: z.boolean(),\n provisionAccounts: z.boolean(),\n })\n .strict()\n\nexport const customerBusinessAccountCreateInputSchema = z\n .object({\n idempotencyKey: z.string().trim().min(8).max(200),\n profile: customerBusinessProfileSchema,\n })\n .strict()\n\nexport const customerBusinessAccountRequestCreateInputSchema =\n customerBusinessAccountCreateInputSchema\n\nexport const customerBusinessAccountRequestListQuerySchema = z\n .object({ status: customerBusinessAccountRequestStatusSchema.optional() })\n .strict()\n\nexport const customerBusinessAccountDecisionInputSchema = z\n .object({ reason: z.string().trim().min(1).max(2_000).nullable().optional() })\n .strict()\n\nconst customerOwnerSelectorSchema = z\n .object({ userId: z.string().min(1).optional(), email: z.email().optional() })\n .strict()\n .refine((value) => Number(Boolean(value.userId)) + Number(Boolean(value.email)) === 1, {\n message: \"Exactly one customer owner userId or email is required\",\n })\n\nconst customerBusinessAccountProvisionBaseSchema = z\n .object({\n idempotencyKey: z.string().trim().min(8).max(200),\n storefrontOrigin: storefrontOriginSchema,\n owner: customerOwnerSelectorSchema,\n })\n .strict()\n\nexport const customerBusinessAccountProvisionInputSchema = z.union([\n customerBusinessAccountProvisionBaseSchema.extend({\n relationshipOrganizationId: z.string().min(1),\n profile: z.never().optional(),\n }),\n customerBusinessAccountProvisionBaseSchema.extend({\n relationshipOrganizationId: z.never().optional(),\n profile: customerBusinessProfileSchema,\n }),\n])\n\nexport const customerBusinessInvitationAcceptInputSchema = z\n .object({ invitationId: z.string().trim().min(1) })\n .strict()\n\nexport const customerBusinessInvitationAcceptResultSchema = z\n .object({ account: customerBusinessAccountSchema })\n .strict()\n\nexport type CustomerBusinessOnboardingMode = z.infer<typeof customerBusinessOnboardingModeSchema>\nexport type CustomerBusinessAccountRole = z.infer<typeof customerBusinessAccountRoleSchema>\nexport type CustomerBusinessAccountRequestStatus = z.infer<\n typeof customerBusinessAccountRequestStatusSchema\n>\nexport type CustomerBusinessProfile = z.infer<typeof customerBusinessProfileSchema>\nexport type CustomerBusinessAccountRequestDto = z.infer<typeof customerBusinessAccountRequestSchema>\nexport type CustomerBusinessAccountDto = z.infer<typeof customerBusinessAccountSchema>\nexport type CustomerBusinessAccountCapabilitiesDto = z.infer<\n typeof customerBusinessAccountCapabilitiesSchema\n>\nexport type CustomerBusinessAccountCreateInput = z.infer<\n typeof customerBusinessAccountCreateInputSchema\n>\nexport type CustomerBusinessAccountDecisionInput = z.infer<\n typeof customerBusinessAccountDecisionInputSchema\n>\nexport type CustomerBusinessAccountProvisionInput = z.infer<\n typeof customerBusinessAccountProvisionInputSchema\n>\nexport type CustomerBusinessInvitationAcceptInput = z.infer<\n typeof customerBusinessInvitationAcceptInputSchema\n>\nexport type CustomerBusinessInvitationAcceptResult = z.infer<\n typeof customerBusinessInvitationAcceptResultSchema\n>\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const createCustomerBusinessAccountVoyantRuntime: import("@voyant-travel/core/project").VoyantGraphRuntimeFactory<{
|
|
2
|
+
module: {
|
|
3
|
+
name: string;
|
|
4
|
+
};
|
|
5
|
+
adminRoutes: import("@hono/zod-openapi").OpenAPIHono<{
|
|
6
|
+
Bindings: Record<string, unknown>;
|
|
7
|
+
Variables: {
|
|
8
|
+
userId?: string;
|
|
9
|
+
scopes?: string[];
|
|
10
|
+
db: import("@voyant-travel/hono").VoyantDb;
|
|
11
|
+
};
|
|
12
|
+
}, {}, "/">;
|
|
13
|
+
}>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { defineGraphRuntimeFactory } from "@voyant-travel/core/project";
|
|
2
|
+
import { createCustomerBusinessAccountAdminRoutes } from "./customer-business-onboarding-routes.js";
|
|
3
|
+
import { customerBusinessAccountOnboardingRuntimePort } from "./customer-business-onboarding-runtime-port.js";
|
|
4
|
+
export const createCustomerBusinessAccountVoyantRuntime = defineGraphRuntimeFactory(async ({ getPort }) => ({
|
|
5
|
+
module: { name: "customer-business-accounts" },
|
|
6
|
+
adminRoutes: createCustomerBusinessAccountAdminRoutes(await getPort(customerBusinessAccountOnboardingRuntimePort)),
|
|
7
|
+
}));
|
|
8
|
+
//# sourceMappingURL=customer-business-onboarding-graph-runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customer-business-onboarding-graph-runtime.js","sourceRoot":"","sources":["../src/customer-business-onboarding-graph-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAA;AAEvE,OAAO,EAAE,wCAAwC,EAAE,MAAM,0CAA0C,CAAA;AACnG,OAAO,EAAE,4CAA4C,EAAE,MAAM,gDAAgD,CAAA;AAE7G,MAAM,CAAC,MAAM,0CAA0C,GAAG,yBAAyB,CACjF,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC;IACtB,MAAM,EAAE,EAAE,IAAI,EAAE,4BAA4B,EAAE;IAC9C,WAAW,EAAE,wCAAwC,CACnD,MAAM,OAAO,CAAC,4CAA4C,CAAC,CAC5D;CACF,CAAC,CACH,CAAA","sourcesContent":["import { defineGraphRuntimeFactory } from \"@voyant-travel/core/project\"\n\nimport { createCustomerBusinessAccountAdminRoutes } from \"./customer-business-onboarding-routes.js\"\nimport { customerBusinessAccountOnboardingRuntimePort } from \"./customer-business-onboarding-runtime-port.js\"\n\nexport const createCustomerBusinessAccountVoyantRuntime = defineGraphRuntimeFactory(\n async ({ getPort }) => ({\n module: { name: \"customer-business-accounts\" },\n adminRoutes: createCustomerBusinessAccountAdminRoutes(\n await getPort(customerBusinessAccountOnboardingRuntimePort),\n ),\n }),\n)\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { OpenAPIHono } from "@hono/zod-openapi";
|
|
2
|
+
import { type VoyantDb } from "@voyant-travel/hono";
|
|
3
|
+
import type { CustomerBusinessAccountOnboardingRuntimeProvider } from "./customer-business-onboarding-runtime-port.js";
|
|
4
|
+
type CustomerBusinessAdminEnv = {
|
|
5
|
+
Bindings: Record<string, unknown>;
|
|
6
|
+
Variables: {
|
|
7
|
+
userId?: string;
|
|
8
|
+
scopes?: string[];
|
|
9
|
+
db: VoyantDb;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export declare function createCustomerBusinessAccountAdminRoutes(runtime: CustomerBusinessAccountOnboardingRuntimeProvider): OpenAPIHono<CustomerBusinessAdminEnv, {}, "/">;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { createRoute, OpenAPIHono, z } from "@hono/zod-openapi";
|
|
2
|
+
import { openApiValidationHook, parseJsonBody, parseQuery, } from "@voyant-travel/hono";
|
|
3
|
+
import { hasApiKeyPermission, permissionStringsToPermissions } from "@voyant-travel/types/api-keys";
|
|
4
|
+
import { customerBusinessAccountDecisionInputSchema, customerBusinessAccountProvisionInputSchema, customerBusinessAccountRequestListQuerySchema, } from "./customer-business-accounts-contracts.js";
|
|
5
|
+
import { CustomerBusinessOnboardingConflictError, CustomerBusinessOnboardingNotFoundError, } from "./customer-business-onboarding-service.js";
|
|
6
|
+
const apiId = "@voyant-travel/auth#customer-business-accounts.api.admin";
|
|
7
|
+
const requestIdParams = z.object({ requestId: z.string().min(1) });
|
|
8
|
+
const provisionOpenApiSchema = z
|
|
9
|
+
.object({
|
|
10
|
+
idempotencyKey: z.string().min(8).max(200),
|
|
11
|
+
storefrontOrigin: z.url(),
|
|
12
|
+
owner: z.object({ userId: z.string().min(1).optional(), email: z.email().optional() }).strict(),
|
|
13
|
+
relationshipOrganizationId: z.string().min(1).optional(),
|
|
14
|
+
profile: z
|
|
15
|
+
.object({
|
|
16
|
+
name: z.string().min(1).max(200),
|
|
17
|
+
legalName: z.string().nullable().optional(),
|
|
18
|
+
taxId: z.string().nullable().optional(),
|
|
19
|
+
website: z.url().nullable().optional(),
|
|
20
|
+
})
|
|
21
|
+
.strict()
|
|
22
|
+
.optional(),
|
|
23
|
+
})
|
|
24
|
+
.strict();
|
|
25
|
+
const jsonBody = (schema) => ({
|
|
26
|
+
required: true,
|
|
27
|
+
content: { "application/json": { schema } },
|
|
28
|
+
});
|
|
29
|
+
const responses = (...statuses) => Object.fromEntries(statuses.map((status) => [status, { description: `HTTP ${status}` }]));
|
|
30
|
+
const adminRoute = (config) => createRoute({
|
|
31
|
+
method: config.method,
|
|
32
|
+
path: config.path,
|
|
33
|
+
operationId: config.operationId,
|
|
34
|
+
"x-voyant-api-id": apiId,
|
|
35
|
+
...(config.request ? { request: config.request } : {}),
|
|
36
|
+
responses: responses(...config.statuses),
|
|
37
|
+
});
|
|
38
|
+
const capabilitiesRoute = adminRoute({
|
|
39
|
+
method: "get",
|
|
40
|
+
path: "/capabilities",
|
|
41
|
+
operationId: "getCustomerBusinessAccountCapabilities",
|
|
42
|
+
statuses: [200, 401, 403],
|
|
43
|
+
});
|
|
44
|
+
const listRequestsRoute = adminRoute({
|
|
45
|
+
method: "get",
|
|
46
|
+
path: "/requests",
|
|
47
|
+
operationId: "listCustomerBusinessAccountRequests",
|
|
48
|
+
request: { query: customerBusinessAccountRequestListQuerySchema },
|
|
49
|
+
statuses: [200, 401, 403],
|
|
50
|
+
});
|
|
51
|
+
const approveRequestRoute = adminRoute({
|
|
52
|
+
method: "post",
|
|
53
|
+
path: "/requests/{requestId}/approve",
|
|
54
|
+
operationId: "approveCustomerBusinessAccountRequest",
|
|
55
|
+
request: {
|
|
56
|
+
params: requestIdParams,
|
|
57
|
+
body: jsonBody(customerBusinessAccountDecisionInputSchema),
|
|
58
|
+
},
|
|
59
|
+
statuses: [200, 400, 401, 403, 404, 409],
|
|
60
|
+
});
|
|
61
|
+
const rejectRequestRoute = adminRoute({
|
|
62
|
+
method: "post",
|
|
63
|
+
path: "/requests/{requestId}/reject",
|
|
64
|
+
operationId: "rejectCustomerBusinessAccountRequest",
|
|
65
|
+
request: {
|
|
66
|
+
params: requestIdParams,
|
|
67
|
+
body: jsonBody(customerBusinessAccountDecisionInputSchema),
|
|
68
|
+
},
|
|
69
|
+
statuses: [200, 400, 401, 403, 404, 409],
|
|
70
|
+
});
|
|
71
|
+
const provisionAccountRoute = adminRoute({
|
|
72
|
+
method: "post",
|
|
73
|
+
path: "/accounts",
|
|
74
|
+
operationId: "provisionCustomerBusinessAccount",
|
|
75
|
+
// The runtime parser below enforces the exact XOR/refinement contract. Keep
|
|
76
|
+
// the route schema OpenAPI-native because refined/transformed Zod pipes do
|
|
77
|
+
// not have an unambiguous JSON Schema representation.
|
|
78
|
+
request: { body: jsonBody(provisionOpenApiSchema) },
|
|
79
|
+
statuses: [201, 400, 401, 403, 404, 409],
|
|
80
|
+
});
|
|
81
|
+
function runtimeContext(c) {
|
|
82
|
+
const userId = c.get("userId");
|
|
83
|
+
if (!userId)
|
|
84
|
+
return c.json({ error: "Unauthorized" }, 401);
|
|
85
|
+
return { context: { bindings: c.env, db: c.get("db") }, userId };
|
|
86
|
+
}
|
|
87
|
+
function onboardingError(c, error) {
|
|
88
|
+
if (error instanceof CustomerBusinessOnboardingNotFoundError) {
|
|
89
|
+
return c.json({ error: error.message }, 404);
|
|
90
|
+
}
|
|
91
|
+
if (error instanceof CustomerBusinessOnboardingConflictError) {
|
|
92
|
+
return c.json({ error: error.message }, 409);
|
|
93
|
+
}
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
96
|
+
function canManageCustomerBusinessAccounts(c) {
|
|
97
|
+
return hasApiKeyPermission(permissionStringsToPermissions(c.get("scopes") ?? []), "customer-business-accounts", "write");
|
|
98
|
+
}
|
|
99
|
+
export function createCustomerBusinessAccountAdminRoutes(runtime) {
|
|
100
|
+
const routes = new OpenAPIHono({
|
|
101
|
+
defaultHook: openApiValidationHook,
|
|
102
|
+
});
|
|
103
|
+
const run = async (c, operation) => {
|
|
104
|
+
const resolved = runtimeContext(c);
|
|
105
|
+
if (resolved instanceof Response)
|
|
106
|
+
return resolved;
|
|
107
|
+
try {
|
|
108
|
+
return await operation(resolved.context, resolved.userId);
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
return onboardingError(c, error);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
routes.openapi(capabilitiesRoute, async (c) => {
|
|
115
|
+
const result = await run(c, (context) => runtime.getCapabilities(context));
|
|
116
|
+
if (result instanceof Response)
|
|
117
|
+
return result;
|
|
118
|
+
const canManage = canManageCustomerBusinessAccounts(c);
|
|
119
|
+
return c.json({
|
|
120
|
+
data: {
|
|
121
|
+
...result,
|
|
122
|
+
decideRequests: result.decideRequests && canManage,
|
|
123
|
+
provisionAccounts: result.provisionAccounts && canManage,
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
routes.openapi(listRequestsRoute, async (c) => {
|
|
128
|
+
const query = parseQuery(c, customerBusinessAccountRequestListQuerySchema);
|
|
129
|
+
const result = await run(c, (context) => runtime.listRequests(context, query));
|
|
130
|
+
return result instanceof Response ? result : c.json({ data: result });
|
|
131
|
+
});
|
|
132
|
+
routes.openapi(approveRequestRoute, async (c) => {
|
|
133
|
+
const { requestId } = c.req.param();
|
|
134
|
+
const input = await parseJsonBody(c, customerBusinessAccountDecisionInputSchema);
|
|
135
|
+
const result = await run(c, (context, decidedBy) => runtime.approveRequest(context, { requestId, decidedBy, reason: input.reason }));
|
|
136
|
+
return result instanceof Response ? result : c.json({ data: result });
|
|
137
|
+
});
|
|
138
|
+
routes.openapi(rejectRequestRoute, async (c) => {
|
|
139
|
+
const { requestId } = c.req.param();
|
|
140
|
+
const input = await parseJsonBody(c, customerBusinessAccountDecisionInputSchema);
|
|
141
|
+
const result = await run(c, (context, decidedBy) => runtime.rejectRequest(context, { requestId, decidedBy, reason: input.reason }));
|
|
142
|
+
return result instanceof Response ? result : c.json({ data: result });
|
|
143
|
+
});
|
|
144
|
+
routes.openapi(provisionAccountRoute, async (c) => {
|
|
145
|
+
const input = await parseJsonBody(c, customerBusinessAccountProvisionInputSchema);
|
|
146
|
+
const result = await run(c, (context, decidedBy) => runtime.provisionBusinessAccount(context, { ...input, decidedBy }));
|
|
147
|
+
return result instanceof Response ? result : c.json({ data: result }, 201);
|
|
148
|
+
});
|
|
149
|
+
return routes;
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=customer-business-onboarding-routes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customer-business-onboarding-routes.js","sourceRoot":"","sources":["../src/customer-business-onboarding-routes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,mBAAmB,CAAA;AAC/D,OAAO,EACL,qBAAqB,EACrB,aAAa,EACb,UAAU,GAEX,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,mBAAmB,EAAE,8BAA8B,EAAE,MAAM,+BAA+B,CAAA;AAGnG,OAAO,EACL,0CAA0C,EAC1C,2CAA2C,EAC3C,6CAA6C,GAC9C,MAAM,2CAA2C,CAAA;AAKlD,OAAO,EACL,uCAAuC,EACvC,uCAAuC,GACxC,MAAM,2CAA2C,CAAA;AAQlD,MAAM,KAAK,GAAG,0DAA0D,CAAA;AACxE,MAAM,eAAe,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;AAClE,MAAM,sBAAsB,GAAG,CAAC;KAC7B,MAAM,CAAC;IACN,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;IAC1C,gBAAgB,EAAE,CAAC,CAAC,GAAG,EAAE;IACzB,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,EAA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EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,CAAA;QACnC,MAAM,KAAK,GAAG,MAAM,aAAa,CAAC,CAAC,EAAE,0CAA0C,CAAC,CAAA;QAChF,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,CAAC,EAAE,CAAC,OAAO,EAAE,SAAS,EAAE,EAAE,CACjD,OAAO,CAAC,aAAa,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAC/E,CAAA;QACD,OAAO,MAAM,YAAY,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAA;IACvE,CAAC,CAAC,CAAA;IACF,MAAM,CAAC,OAAO,CAAC,qBAAqB,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;QAChD,MAAM,KAAK,GAAG,MAAM,aAAa,CAAC,CAAC,EAAE,2CAA2C,CAAC,CAAA;QACjF,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,CAAC,EAAE,CAAC,OAAO,EAAE,SAAS,EAAE,EAAE,CACjD,OAAO,CAAC,wBAAwB,CAAC,OAAO,EAAE,EAAE,GAAG,KAAK,EAAE,SAAS,EAAE,CAAC,CACnE,CAAA;QACD,OAAO,MAAM,YAAY,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,CAAC,CAAA;IAC5E,CAAC,CAAC,CAAA;IAEF,OAAO,MAAM,CAAA;AACf,CAAC","sourcesContent":["import { createRoute, OpenAPIHono, z } from \"@hono/zod-openapi\"\nimport {\n openApiValidationHook,\n parseJsonBody,\n parseQuery,\n type VoyantDb,\n} from \"@voyant-travel/hono\"\nimport { hasApiKeyPermission, permissionStringsToPermissions } from \"@voyant-travel/types/api-keys\"\nimport type { Context } from \"hono\"\n\nimport {\n customerBusinessAccountDecisionInputSchema,\n customerBusinessAccountProvisionInputSchema,\n customerBusinessAccountRequestListQuerySchema,\n} from \"./customer-business-accounts-contracts.js\"\nimport type {\n CustomerBusinessAccountOnboardingRuntimeProvider,\n CustomerBusinessOnboardingContext,\n} from \"./customer-business-onboarding-runtime-port.js\"\nimport {\n CustomerBusinessOnboardingConflictError,\n CustomerBusinessOnboardingNotFoundError,\n} from \"./customer-business-onboarding-service.js\"\n\ntype CustomerBusinessAdminEnv = {\n Bindings: Record<string, unknown>\n Variables: { userId?: string; scopes?: string[]; db: VoyantDb }\n}\ntype CustomerBusinessAdminContext = Context<CustomerBusinessAdminEnv>\n\nconst apiId = \"@voyant-travel/auth#customer-business-accounts.api.admin\"\nconst requestIdParams = z.object({ requestId: z.string().min(1) })\nconst provisionOpenApiSchema = z\n .object({\n idempotencyKey: z.string().min(8).max(200),\n storefrontOrigin: z.url(),\n owner: z.object({ userId: z.string().min(1).optional(), email: z.email().optional() }).strict(),\n relationshipOrganizationId: z.string().min(1).optional(),\n profile: z\n .object({\n name: z.string().min(1).max(200),\n legalName: z.string().nullable().optional(),\n taxId: z.string().nullable().optional(),\n website: z.url().nullable().optional(),\n })\n .strict()\n .optional(),\n })\n .strict()\nconst jsonBody = <T extends z.ZodTypeAny>(schema: T) => ({\n required: true,\n content: { \"application/json\": { schema } },\n})\nconst responses = (...statuses: number[]) =>\n Object.fromEntries(statuses.map((status) => [status, { description: `HTTP ${status}` }]))\nconst adminRoute = <M extends \"get\" | \"post\", P extends string>(config: {\n method: M\n path: P\n operationId: string\n request?: Record<string, unknown>\n statuses: number[]\n}) =>\n createRoute({\n method: config.method,\n path: config.path,\n operationId: config.operationId,\n \"x-voyant-api-id\": apiId,\n ...(config.request ? { request: config.request } : {}),\n responses: responses(...config.statuses),\n })\n\nconst capabilitiesRoute = adminRoute({\n method: \"get\",\n path: \"/capabilities\",\n operationId: \"getCustomerBusinessAccountCapabilities\",\n statuses: [200, 401, 403],\n})\nconst listRequestsRoute = adminRoute({\n method: \"get\",\n path: \"/requests\",\n operationId: \"listCustomerBusinessAccountRequests\",\n request: { query: customerBusinessAccountRequestListQuerySchema },\n statuses: [200, 401, 403],\n})\nconst approveRequestRoute = adminRoute({\n method: \"post\",\n path: \"/requests/{requestId}/approve\",\n operationId: \"approveCustomerBusinessAccountRequest\",\n request: {\n params: requestIdParams,\n body: jsonBody(customerBusinessAccountDecisionInputSchema),\n },\n statuses: [200, 400, 401, 403, 404, 409],\n})\nconst rejectRequestRoute = adminRoute({\n method: \"post\",\n path: \"/requests/{requestId}/reject\",\n operationId: \"rejectCustomerBusinessAccountRequest\",\n request: {\n params: requestIdParams,\n body: jsonBody(customerBusinessAccountDecisionInputSchema),\n },\n statuses: [200, 400, 401, 403, 404, 409],\n})\nconst provisionAccountRoute = adminRoute({\n method: \"post\",\n path: \"/accounts\",\n operationId: \"provisionCustomerBusinessAccount\",\n // The runtime parser below enforces the exact XOR/refinement contract. Keep\n // the route schema OpenAPI-native because refined/transformed Zod pipes do\n // not have an unambiguous JSON Schema representation.\n request: { body: jsonBody(provisionOpenApiSchema) },\n statuses: [201, 400, 401, 403, 404, 409],\n})\n\nfunction runtimeContext(\n c: CustomerBusinessAdminContext,\n): { context: CustomerBusinessOnboardingContext; userId: string } | Response {\n const userId = c.get(\"userId\")\n if (!userId) return c.json({ error: \"Unauthorized\" }, 401)\n return { context: { bindings: c.env, db: c.get(\"db\") }, userId }\n}\n\nfunction onboardingError(c: CustomerBusinessAdminContext, error: unknown): Response {\n if (error instanceof CustomerBusinessOnboardingNotFoundError) {\n return c.json({ error: error.message }, 404)\n }\n if (error instanceof CustomerBusinessOnboardingConflictError) {\n return c.json({ error: error.message }, 409)\n }\n throw error\n}\n\nfunction canManageCustomerBusinessAccounts(c: CustomerBusinessAdminContext) {\n return hasApiKeyPermission(\n permissionStringsToPermissions(c.get(\"scopes\") ?? []),\n \"customer-business-accounts\",\n \"write\",\n )\n}\n\nexport function createCustomerBusinessAccountAdminRoutes(\n runtime: CustomerBusinessAccountOnboardingRuntimeProvider,\n) {\n const routes = new OpenAPIHono<CustomerBusinessAdminEnv>({\n defaultHook: openApiValidationHook,\n })\n\n const run = async <T>(\n c: CustomerBusinessAdminContext,\n operation: (context: CustomerBusinessOnboardingContext, userId: string) => Promise<T>,\n ): Promise<T | Response> => {\n const resolved = runtimeContext(c)\n if (resolved instanceof Response) return resolved\n try {\n return await operation(resolved.context, resolved.userId)\n } catch (error) {\n return onboardingError(c, error)\n }\n }\n\n routes.openapi(capabilitiesRoute, async (c) => {\n const result = await run(c, (context) => runtime.getCapabilities(context))\n if (result instanceof Response) return result\n const canManage = canManageCustomerBusinessAccounts(c)\n return c.json({\n data: {\n ...result,\n decideRequests: result.decideRequests && canManage,\n provisionAccounts: result.provisionAccounts && canManage,\n },\n })\n })\n routes.openapi(listRequestsRoute, async (c) => {\n const query = parseQuery(c, customerBusinessAccountRequestListQuerySchema)\n const result = await run(c, (context) => runtime.listRequests(context, query))\n return result instanceof Response ? result : c.json({ data: result })\n })\n routes.openapi(approveRequestRoute, async (c) => {\n const { requestId } = c.req.param()\n const input = await parseJsonBody(c, customerBusinessAccountDecisionInputSchema)\n const result = await run(c, (context, decidedBy) =>\n runtime.approveRequest(context, { requestId, decidedBy, reason: input.reason }),\n )\n return result instanceof Response ? result : c.json({ data: result })\n })\n routes.openapi(rejectRequestRoute, async (c) => {\n const { requestId } = c.req.param()\n const input = await parseJsonBody(c, customerBusinessAccountDecisionInputSchema)\n const result = await run(c, (context, decidedBy) =>\n runtime.rejectRequest(context, { requestId, decidedBy, reason: input.reason }),\n )\n return result instanceof Response ? result : c.json({ data: result })\n })\n routes.openapi(provisionAccountRoute, async (c) => {\n const input = await parseJsonBody(c, customerBusinessAccountProvisionInputSchema)\n const result = await run(c, (context, decidedBy) =>\n runtime.provisionBusinessAccount(context, { ...input, decidedBy }),\n )\n return result instanceof Response ? result : c.json({ data: result }, 201)\n })\n\n return routes\n}\n"]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { VoyantDb } from "@voyant-travel/hono";
|
|
2
|
+
import type { CustomerBusinessAccountCapabilitiesDto, CustomerBusinessAccountDecisionInput, CustomerBusinessAccountDto, CustomerBusinessAccountProvisionInput, CustomerBusinessAccountRequestDto, CustomerBusinessAccountRequestStatus, CustomerBusinessProfile } from "./customer-business-accounts-contracts.js";
|
|
3
|
+
export interface CustomerBusinessOnboardingContext {
|
|
4
|
+
bindings: unknown;
|
|
5
|
+
db: VoyantDb;
|
|
6
|
+
}
|
|
7
|
+
export interface CustomerBusinessAccountOperationInput {
|
|
8
|
+
requesterUserId: string;
|
|
9
|
+
storefrontOrigin: string;
|
|
10
|
+
idempotencyKey: string;
|
|
11
|
+
profile: CustomerBusinessProfile;
|
|
12
|
+
}
|
|
13
|
+
export interface CustomerBusinessAccountOnboardingRuntimeProvider {
|
|
14
|
+
getCapabilities(context: CustomerBusinessOnboardingContext): Promise<CustomerBusinessAccountCapabilitiesDto>;
|
|
15
|
+
createBusinessAccount(context: CustomerBusinessOnboardingContext, input: CustomerBusinessAccountOperationInput): Promise<CustomerBusinessAccountDto>;
|
|
16
|
+
requestBusinessAccount(context: CustomerBusinessOnboardingContext, input: CustomerBusinessAccountOperationInput): Promise<CustomerBusinessAccountRequestDto>;
|
|
17
|
+
listRequests(context: CustomerBusinessOnboardingContext, input: {
|
|
18
|
+
requesterUserId?: string;
|
|
19
|
+
status?: CustomerBusinessAccountRequestStatus;
|
|
20
|
+
}): Promise<CustomerBusinessAccountRequestDto[]>;
|
|
21
|
+
cancelRequest(context: CustomerBusinessOnboardingContext, input: {
|
|
22
|
+
requestId: string;
|
|
23
|
+
requesterUserId: string;
|
|
24
|
+
}): Promise<CustomerBusinessAccountRequestDto>;
|
|
25
|
+
approveRequest(context: CustomerBusinessOnboardingContext, input: {
|
|
26
|
+
requestId: string;
|
|
27
|
+
decidedBy: string;
|
|
28
|
+
} & CustomerBusinessAccountDecisionInput): Promise<{
|
|
29
|
+
account: CustomerBusinessAccountDto;
|
|
30
|
+
request: CustomerBusinessAccountRequestDto;
|
|
31
|
+
}>;
|
|
32
|
+
rejectRequest(context: CustomerBusinessOnboardingContext, input: {
|
|
33
|
+
requestId: string;
|
|
34
|
+
decidedBy: string;
|
|
35
|
+
} & CustomerBusinessAccountDecisionInput): Promise<CustomerBusinessAccountRequestDto>;
|
|
36
|
+
provisionBusinessAccount(context: CustomerBusinessOnboardingContext, input: CustomerBusinessAccountProvisionInput & {
|
|
37
|
+
decidedBy: string;
|
|
38
|
+
}): Promise<CustomerBusinessAccountDto>;
|
|
39
|
+
}
|
|
40
|
+
export declare const customerBusinessAccountOnboardingRuntimePort: import("@voyant-travel/core/project").VoyantPort<CustomerBusinessAccountOnboardingRuntimeProvider>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { definePort } from "@voyant-travel/core/project";
|
|
2
|
+
const requiredMethods = [
|
|
3
|
+
"getCapabilities",
|
|
4
|
+
"createBusinessAccount",
|
|
5
|
+
"requestBusinessAccount",
|
|
6
|
+
"listRequests",
|
|
7
|
+
"cancelRequest",
|
|
8
|
+
"approveRequest",
|
|
9
|
+
"rejectRequest",
|
|
10
|
+
"provisionBusinessAccount",
|
|
11
|
+
];
|
|
12
|
+
export const customerBusinessAccountOnboardingRuntimePort = definePort({
|
|
13
|
+
id: "auth.customer-business-onboarding.runtime",
|
|
14
|
+
test(provider) {
|
|
15
|
+
if (provider === null || typeof provider !== "object") {
|
|
16
|
+
throw new Error("auth.customer-business-onboarding.runtime provider must be an object.");
|
|
17
|
+
}
|
|
18
|
+
for (const method of requiredMethods) {
|
|
19
|
+
if (typeof provider[method] !== "function") {
|
|
20
|
+
throw new Error(`auth.customer-business-onboarding.runtime provider must implement ${method}().`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
//# sourceMappingURL=customer-business-onboarding-runtime-port.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customer-business-onboarding-runtime-port.js","sourceRoot":"","sources":["../src/customer-business-onboarding-runtime-port.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AAiExD,MAAM,eAAe,GAAG;IACtB,iBAAiB;IACjB,uBAAuB;IACvB,wBAAwB;IACxB,cAAc;IACd,eAAe;IACf,gBAAgB;IAChB,eAAe;IACf,0BAA0B;CAClB,CAAA;AAEV,MAAM,CAAC,MAAM,4CAA4C,GACvD,UAAU,CAAmD;IAC3D,EAAE,EAAE,2CAA2C;IAC/C,IAAI,CAAC,QAAQ;QACX,IAAI,QAAQ,KAAK,IAAI,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE,CAAC;YACtD,MAAM,IAAI,KAAK,CAAC,uEAAuE,CAAC,CAAA;QAC1F,CAAC;QACD,KAAK,MAAM,MAAM,IAAI,eAAe,EAAE,CAAC;YACrC,IAAI,OAAO,QAAQ,CAAC,MAAM,CAAC,KAAK,UAAU,EAAE,CAAC;gBAC3C,MAAM,IAAI,KAAK,CACb,qEAAqE,MAAM,KAAK,CACjF,CAAA;YACH,CAAC;QACH,CAAC;IACH,CAAC;CACF,CAAC,CAAA","sourcesContent":["import { definePort } from \"@voyant-travel/core/project\"\nimport type { VoyantDb } from \"@voyant-travel/hono\"\n\nimport type {\n CustomerBusinessAccountCapabilitiesDto,\n CustomerBusinessAccountDecisionInput,\n CustomerBusinessAccountDto,\n CustomerBusinessAccountProvisionInput,\n CustomerBusinessAccountRequestDto,\n CustomerBusinessAccountRequestStatus,\n CustomerBusinessProfile,\n} from \"./customer-business-accounts-contracts.js\"\n\nexport interface CustomerBusinessOnboardingContext {\n bindings: unknown\n db: VoyantDb\n}\n\nexport interface CustomerBusinessAccountOperationInput {\n requesterUserId: string\n storefrontOrigin: string\n idempotencyKey: string\n profile: CustomerBusinessProfile\n}\n\nexport interface CustomerBusinessAccountOnboardingRuntimeProvider {\n getCapabilities(\n context: CustomerBusinessOnboardingContext,\n ): Promise<CustomerBusinessAccountCapabilitiesDto>\n createBusinessAccount(\n context: CustomerBusinessOnboardingContext,\n input: CustomerBusinessAccountOperationInput,\n ): Promise<CustomerBusinessAccountDto>\n requestBusinessAccount(\n context: CustomerBusinessOnboardingContext,\n input: CustomerBusinessAccountOperationInput,\n ): Promise<CustomerBusinessAccountRequestDto>\n listRequests(\n context: CustomerBusinessOnboardingContext,\n input: {\n requesterUserId?: string\n status?: CustomerBusinessAccountRequestStatus\n },\n ): Promise<CustomerBusinessAccountRequestDto[]>\n cancelRequest(\n context: CustomerBusinessOnboardingContext,\n input: { requestId: string; requesterUserId: string },\n ): Promise<CustomerBusinessAccountRequestDto>\n approveRequest(\n context: CustomerBusinessOnboardingContext,\n input: { requestId: string; decidedBy: string } & CustomerBusinessAccountDecisionInput,\n ): Promise<{\n account: CustomerBusinessAccountDto\n request: CustomerBusinessAccountRequestDto\n }>\n rejectRequest(\n context: CustomerBusinessOnboardingContext,\n input: { requestId: string; decidedBy: string } & CustomerBusinessAccountDecisionInput,\n ): Promise<CustomerBusinessAccountRequestDto>\n provisionBusinessAccount(\n context: CustomerBusinessOnboardingContext,\n input: CustomerBusinessAccountProvisionInput & { decidedBy: string },\n ): Promise<CustomerBusinessAccountDto>\n}\n\nconst requiredMethods = [\n \"getCapabilities\",\n \"createBusinessAccount\",\n \"requestBusinessAccount\",\n \"listRequests\",\n \"cancelRequest\",\n \"approveRequest\",\n \"rejectRequest\",\n \"provisionBusinessAccount\",\n] as const\n\nexport const customerBusinessAccountOnboardingRuntimePort =\n definePort<CustomerBusinessAccountOnboardingRuntimeProvider>({\n id: \"auth.customer-business-onboarding.runtime\",\n test(provider) {\n if (provider === null || typeof provider !== \"object\") {\n throw new Error(\"auth.customer-business-onboarding.runtime provider must be an object.\")\n }\n for (const method of requiredMethods) {\n if (typeof provider[method] !== \"function\") {\n throw new Error(\n `auth.customer-business-onboarding.runtime provider must implement ${method}().`,\n )\n }\n }\n },\n })\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { VoyantDb } from "@voyant-travel/hono";
|
|
2
|
+
import { type CustomerBusinessAccountDto, type CustomerBusinessAccountRequestDto, type CustomerBusinessAccountRequestStatus, type CustomerBusinessOnboardingMode, type CustomerBusinessProfile } from "./customer-business-accounts-contracts.js";
|
|
3
|
+
export declare class CustomerBusinessOnboardingConflictError extends Error {
|
|
4
|
+
}
|
|
5
|
+
export declare class CustomerBusinessOnboardingNotFoundError extends Error {
|
|
6
|
+
}
|
|
7
|
+
export declare function materializeCustomerBusinessAccount(db: VoyantDb, input: {
|
|
8
|
+
ownerUserId: string;
|
|
9
|
+
name: string;
|
|
10
|
+
relationshipOrganizationId: string;
|
|
11
|
+
}): Promise<CustomerBusinessAccountDto>;
|
|
12
|
+
export declare function createCustomerBusinessAccountRequest(db: VoyantDb, input: {
|
|
13
|
+
requesterUserId: string;
|
|
14
|
+
storefrontOrigin: string;
|
|
15
|
+
mode: CustomerBusinessOnboardingMode;
|
|
16
|
+
idempotencyKey: string;
|
|
17
|
+
profile: CustomerBusinessProfile;
|
|
18
|
+
}): Promise<CustomerBusinessAccountRequestDto>;
|
|
19
|
+
export declare function listCustomerBusinessAccountRequests(db: VoyantDb, input: {
|
|
20
|
+
requesterUserId?: string;
|
|
21
|
+
status?: CustomerBusinessAccountRequestStatus;
|
|
22
|
+
}): Promise<CustomerBusinessAccountRequestDto[]>;
|
|
23
|
+
export declare function getCustomerBusinessAccountRequestForUpdate(db: VoyantDb, requestId: string): Promise<CustomerBusinessAccountRequestDto>;
|
|
24
|
+
export declare function decideCustomerBusinessAccountRequest(db: VoyantDb, input: {
|
|
25
|
+
requestId: string;
|
|
26
|
+
fromStatus: "pending";
|
|
27
|
+
status: "approved" | "rejected" | "canceled";
|
|
28
|
+
decidedBy: string | null;
|
|
29
|
+
decisionReason?: string | null;
|
|
30
|
+
authOrganizationId?: string;
|
|
31
|
+
relationshipOrganizationId?: string;
|
|
32
|
+
}): Promise<CustomerBusinessAccountRequestDto>;
|