@dalmore/api-contracts 1.0.7 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -2
- package/index.mjs +1 -4
- package/package.json +4 -4
- package/src/common/types/account-contact.types.ts +98 -0
- package/src/common/types/account-detail.types.ts +27 -0
- package/src/common/types/account-integration.types.ts +143 -0
- package/src/common/types/account-manager.types.ts +124 -0
- package/src/common/types/account.types.ts +296 -0
- package/src/common/types/activity.types.ts +274 -0
- package/src/common/types/address.spec.ts +203 -0
- package/src/common/types/address.types.ts +41 -0
- package/src/common/types/aic.types.ts +246 -0
- package/src/common/types/aml.types.ts +18 -0
- package/src/common/types/api-key-logs.types.ts +66 -0
- package/src/common/types/api-keys.types.ts +69 -0
- package/src/common/types/asset.types.ts +338 -0
- package/src/common/types/auth.types.ts +370 -0
- package/src/common/types/batch-jobs.types.ts +151 -0
- package/src/common/types/bonus-tier.types.ts +147 -0
- package/src/common/types/cart.types.ts +18 -0
- package/src/common/types/checklist-items.types.ts +70 -0
- package/src/common/types/checklist.types.ts +97 -0
- package/src/common/types/common.types.spec.ts +336 -0
- package/src/common/types/common.types.ts +1520 -0
- package/src/common/types/comply-advantage-api.types.ts +316 -0
- package/src/common/types/comply-advantage.types.ts +25 -0
- package/src/common/types/contact-us.types.ts +107 -0
- package/src/common/types/contract-helpers.ts +205 -0
- package/src/common/types/countries.types.ts +375 -0
- package/src/common/types/covered-person.types.ts +274 -0
- package/src/common/types/dashboard.types.ts +799 -0
- package/src/common/types/data-record.types.ts +325 -0
- package/src/common/types/data-room.types.ts +242 -0
- package/src/common/types/default-theme-config.types.ts +87 -0
- package/src/common/types/disbursement-adjustment.types.ts +32 -0
- package/src/common/types/disbursement-approval-user.types.ts +100 -0
- package/src/common/types/disbursement-review.types.ts +110 -0
- package/src/common/types/disbursement-transaction.types.ts +72 -0
- package/src/common/types/disbursements.types.ts +310 -0
- package/src/common/types/domain-filter.types.ts +55 -0
- package/src/common/types/email-theme.types.ts +442 -0
- package/src/common/types/entity.types.ts +15 -0
- package/src/common/types/error-responses.types.ts +135 -0
- package/src/common/types/escrow-account.types.ts +104 -0
- package/src/common/types/exchange-api-key.types.ts +121 -0
- package/src/common/types/exchange-import.types.ts +36 -0
- package/src/common/types/exchange-provider.types.ts +329 -0
- package/src/common/types/file.types.ts +461 -0
- package/src/common/types/files.types.spec.ts +154 -0
- package/src/common/types/health.types.ts +29 -0
- package/src/common/types/index.ts +48 -0
- package/src/common/types/individuals.types.ts +554 -0
- package/src/common/types/investor-account.types.ts +1239 -0
- package/src/common/types/investorAccountIdSchema.type.ts +0 -0
- package/src/common/types/investors-offering.types.ts +65 -0
- package/src/common/types/invite.types.ts +133 -0
- package/src/common/types/issuer-bank-account.types.ts +107 -0
- package/src/common/types/issuer-offering.types.ts +306 -0
- package/src/common/types/issuer-payment-method.types.spec.ts +612 -0
- package/src/common/types/issuer-payment-method.types.ts +341 -0
- package/src/common/types/issuer.types.ts +312 -0
- package/src/common/types/job-item.types.ts +119 -0
- package/src/common/types/jobs.types.ts +171 -0
- package/src/common/types/kyb.types.ts +53 -0
- package/src/common/types/kyc.types.ts +188 -0
- package/src/common/types/legal-entity.types.ts +185 -0
- package/src/common/types/login-history.types.ts +46 -0
- package/src/common/types/mail-template.types.ts +436 -0
- package/src/common/types/north-cap-integration.types.ts +190 -0
- package/src/common/types/note.types.ts +109 -0
- package/src/common/types/notification.types.ts +58 -0
- package/src/common/types/notion-api.types.ts +374 -0
- package/src/common/types/notion-database.types.ts +125 -0
- package/src/common/types/notion-page.types.ts +267 -0
- package/src/common/types/offering-reports.types.ts +153 -0
- package/src/common/types/offering-submission.types.ts +314 -0
- package/src/common/types/offering.types.spec.ts +91 -0
- package/src/common/types/offering.types.ts +590 -0
- package/src/common/types/page-revision.types.ts +86 -0
- package/src/common/types/page.types.ts +436 -0
- package/src/common/types/password.type.ts +15 -0
- package/src/common/types/payment-methods.types.ts +298 -0
- package/src/common/types/phone.spec.ts +76 -0
- package/src/common/types/phone.type.ts +27 -0
- package/src/common/types/portfolio.types.ts +50 -0
- package/src/common/types/privacy-policy-and-tos.types.ts +231 -0
- package/src/common/types/queue.types.ts +112 -0
- package/src/common/types/registered-reps.types.ts +25 -0
- package/src/common/types/rejection-reasons.types.ts +56 -0
- package/src/common/types/reminder-config.types.ts +40 -0
- package/src/common/types/review.types.ts +133 -0
- package/src/common/types/role.types.ts +26 -0
- package/src/common/types/secondary-customer.types.ts +66 -0
- package/src/common/types/secondary-issuer.types.ts +50 -0
- package/src/common/types/secondary-order.types.ts +58 -0
- package/src/common/types/secondary-security.types.ts +60 -0
- package/src/common/types/secondary-trade.entity.ts +16 -0
- package/src/common/types/secondary-trade.types.ts +95 -0
- package/src/common/types/secure-request.types.ts +68 -0
- package/src/common/types/signer.types.ts +651 -0
- package/src/common/types/site-link.types.spec.ts +134 -0
- package/src/common/types/site-link.types.ts +166 -0
- package/src/common/types/site-settings.types.ts +726 -0
- package/src/common/types/site.types.ts +270 -0
- package/src/common/types/sms.types.ts +30 -0
- package/src/common/types/state-machine.types.ts +177 -0
- package/src/common/types/states.types.ts +163 -0
- package/src/common/types/subdoc-preview.types.ts +35 -0
- package/src/common/types/task.types.ts +258 -0
- package/src/common/types/trade-adjustment.type.ts +33 -0
- package/src/common/types/trade-line-item.type.ts +132 -0
- package/src/common/types/trade.types.ts +912 -0
- package/src/common/types/transaction.types.ts +198 -0
- package/src/common/types/trusted-contact.types.ts +122 -0
- package/src/common/types/typography.types.ts +75 -0
- package/src/common/types/user-manual.types.ts +290 -0
- package/src/common/types/user-setting.types.ts +133 -0
- package/src/common/types/user.types.ts +320 -0
- package/src/common/types/webhook.types.ts +588 -0
- package/src/common/types/zip.type.ts +36 -0
- package/src/contracts/clients/accounts/index.ts +61 -0
- package/src/contracts/clients/aic/index.ts +59 -0
- package/src/contracts/clients/api-key-logs/index.ts +53 -0
- package/src/contracts/clients/api-keys/index.ts +73 -0
- package/src/contracts/clients/assets/index.ts +102 -0
- package/src/contracts/clients/auth/index.ts +50 -0
- package/src/contracts/clients/files/index.ts +166 -0
- package/src/contracts/clients/files-public/index.ts +166 -0
- package/src/contracts/clients/index.ts +44 -0
- package/src/contracts/clients/individuals/index.ts +93 -0
- package/src/contracts/clients/investor-accounts/index.ts +93 -0
- package/src/contracts/clients/issuers/index.ts +94 -0
- package/src/contracts/clients/legal-entities/index.ts +93 -0
- package/src/contracts/clients/offerings/index.ts +117 -0
- package/src/contracts/clients/secure-requests/index.ts +34 -0
- package/src/contracts/clients/sites/index.ts +56 -0
- package/src/contracts/clients/trades/index.ts +122 -0
- package/dist/contracts/clients/index.d.ts +0 -19
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import { extendZodWithOpenApi } from '@anatine/zod-openapi';
|
|
2
|
+
import { TypeID } from 'typeid-js';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { accountIdSchema } from './account.types';
|
|
5
|
+
import {
|
|
6
|
+
AccountZod,
|
|
7
|
+
AssetType,
|
|
8
|
+
DurationType,
|
|
9
|
+
IPaginationMeta,
|
|
10
|
+
SortBy,
|
|
11
|
+
SortOrder,
|
|
12
|
+
} from './common.types';
|
|
13
|
+
import { IBaseEntity } from './entity.types';
|
|
14
|
+
import { IOffering, offeringIdSchema } from './offering.types';
|
|
15
|
+
import { issuerIdSchema } from './issuer.types';
|
|
16
|
+
|
|
17
|
+
extendZodWithOpenApi(z);
|
|
18
|
+
|
|
19
|
+
export const assetIdSchema = z.string().refine(
|
|
20
|
+
(value) => {
|
|
21
|
+
try {
|
|
22
|
+
const tid = TypeID.fromString(value);
|
|
23
|
+
return tid.getType() === 'asset';
|
|
24
|
+
} catch {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
message: `Invalid asset ID format. Must be a valid TypeID with "asset" prefix. Example: asset_01j5y5ghx5fg68d663j1fvy2x7`,
|
|
30
|
+
},
|
|
31
|
+
);
|
|
32
|
+
export enum TemplateType {
|
|
33
|
+
STANDARD = 'STANDARD',
|
|
34
|
+
TIERED = 'TIERED',
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const IAsset = IBaseEntity.extend({
|
|
38
|
+
id: assetIdSchema,
|
|
39
|
+
name: z.string(),
|
|
40
|
+
type: z.nativeEnum(AssetType).nullable(),
|
|
41
|
+
pricePerUnit: z.number().nullable(),
|
|
42
|
+
totalUnits: z.number().nullable(),
|
|
43
|
+
totalAmount: z.number().nullable(),
|
|
44
|
+
yield: z.number().nullable(),
|
|
45
|
+
duration: z.number().nullable(),
|
|
46
|
+
durationType: z.nativeEnum(DurationType).nullable(),
|
|
47
|
+
accountId: z.string(),
|
|
48
|
+
account: AccountZod.optional().nullable(),
|
|
49
|
+
offeringId: z.string(),
|
|
50
|
+
offering: z
|
|
51
|
+
.lazy(() => IOffering)
|
|
52
|
+
.optional()
|
|
53
|
+
.nullable(), // Use z.lazy here
|
|
54
|
+
template: z.nativeEnum(TemplateType),
|
|
55
|
+
tiers: z.array(z.number().positive()).nullable(),
|
|
56
|
+
enableBonus: z.boolean(),
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
export type IAsset = z.infer<typeof IAsset>;
|
|
60
|
+
|
|
61
|
+
export const IPaginatedAsset = z.object({
|
|
62
|
+
items: z.array(IAsset),
|
|
63
|
+
meta: IPaginationMeta,
|
|
64
|
+
});
|
|
65
|
+
export type IPaginatedAsset = z.infer<typeof IPaginatedAsset>;
|
|
66
|
+
|
|
67
|
+
const PostAssetBase = z.object({
|
|
68
|
+
offeringId: z
|
|
69
|
+
.lazy(() => offeringIdSchema)
|
|
70
|
+
.openapi({ example: 'offering_01jayn2qkpeebav9gjpqx7xm8j' }),
|
|
71
|
+
name: z.string().min(2).max(50).openapi({ example: 'Asset name' }),
|
|
72
|
+
type: z.nativeEnum(AssetType).openapi({ example: AssetType.STOCK }),
|
|
73
|
+
pricePerUnit: z
|
|
74
|
+
.number()
|
|
75
|
+
.min(0.01)
|
|
76
|
+
.max(10000000000)
|
|
77
|
+
.nullable()
|
|
78
|
+
.openapi({ example: 2000 }),
|
|
79
|
+
totalUnits: z
|
|
80
|
+
.number()
|
|
81
|
+
.min(1)
|
|
82
|
+
.max(10000000000)
|
|
83
|
+
.nullable()
|
|
84
|
+
.openapi({ example: 5200 }),
|
|
85
|
+
yield: z
|
|
86
|
+
.number()
|
|
87
|
+
.min(0.01)
|
|
88
|
+
.max(10000000000)
|
|
89
|
+
.nullable()
|
|
90
|
+
.optional()
|
|
91
|
+
.openapi({ example: 1200 }),
|
|
92
|
+
duration: z
|
|
93
|
+
.number()
|
|
94
|
+
.min(1)
|
|
95
|
+
.max(1000)
|
|
96
|
+
.nullable()
|
|
97
|
+
.optional()
|
|
98
|
+
.openapi({ example: 1 }),
|
|
99
|
+
durationType: z
|
|
100
|
+
.nativeEnum(DurationType)
|
|
101
|
+
.nullable()
|
|
102
|
+
.optional()
|
|
103
|
+
.openapi({ example: DurationType.DAY }),
|
|
104
|
+
template: z
|
|
105
|
+
.nativeEnum(TemplateType)
|
|
106
|
+
.default(TemplateType.STANDARD)
|
|
107
|
+
.openapi({ example: TemplateType.STANDARD }),
|
|
108
|
+
tiers: z.array(z.number().positive()).nullable().optional(),
|
|
109
|
+
enableBonus: z.boolean().default(false).openapi({ example: false }),
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
const postAssetRefinement = (data: any, ctx: any) => {
|
|
113
|
+
// If type is bond, yield and duration must be provided (cannot be null or undefined)
|
|
114
|
+
if (data.type === AssetType.BOND) {
|
|
115
|
+
if (data.yield === null || data.yield === undefined) {
|
|
116
|
+
ctx.addIssue({
|
|
117
|
+
path: ['yield'],
|
|
118
|
+
message:
|
|
119
|
+
'Yield is required for bond type and cannot be null or undefined',
|
|
120
|
+
code: z.ZodIssueCode.custom,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
if (data.duration === null || data.duration === undefined) {
|
|
124
|
+
ctx.addIssue({
|
|
125
|
+
path: ['duration'],
|
|
126
|
+
message:
|
|
127
|
+
'Duration is required for bond type and cannot be null or undefined',
|
|
128
|
+
code: z.ZodIssueCode.custom,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
if (data.durationType === null || data.durationType === undefined) {
|
|
132
|
+
ctx.addIssue({
|
|
133
|
+
path: ['durationType'],
|
|
134
|
+
message:
|
|
135
|
+
'Duration type is required for bond type and cannot be null or undefined',
|
|
136
|
+
code: z.ZodIssueCode.custom,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// If type is stock, yield and duration must be either null or undefined
|
|
142
|
+
if (data.type === AssetType.STOCK) {
|
|
143
|
+
if (data.yield !== null && data.yield !== undefined) {
|
|
144
|
+
ctx.addIssue({
|
|
145
|
+
path: ['yield'],
|
|
146
|
+
message: 'Yield must not be provided for stock type',
|
|
147
|
+
code: z.ZodIssueCode.custom,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
if (data.duration !== null && data.duration !== undefined) {
|
|
151
|
+
ctx.addIssue({
|
|
152
|
+
path: ['duration'],
|
|
153
|
+
message: 'Duration must not be provided for stock type',
|
|
154
|
+
code: z.ZodIssueCode.custom,
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
if (data.durationType !== null && data.durationType !== undefined) {
|
|
158
|
+
ctx.addIssue({
|
|
159
|
+
path: ['durationType'],
|
|
160
|
+
message: 'Duration type must not be provided for stock type',
|
|
161
|
+
code: z.ZodIssueCode.custom,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (data.template === TemplateType.TIERED) {
|
|
166
|
+
if (data.tiers === null || data.tiers === undefined) {
|
|
167
|
+
ctx.addIssue({
|
|
168
|
+
path: ['tiers'],
|
|
169
|
+
message: 'Tiers must be provided for TIERED template',
|
|
170
|
+
code: z.ZodIssueCode.custom,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
// If template is STANDARD, tiers must be null or undefined
|
|
175
|
+
if (data.template === TemplateType.STANDARD) {
|
|
176
|
+
if (data.tiers !== null && data.tiers !== undefined) {
|
|
177
|
+
ctx.addIssue({
|
|
178
|
+
path: ['tiers'],
|
|
179
|
+
message: 'Tiers must not be provided for STANDARD template',
|
|
180
|
+
code: z.ZodIssueCode.custom,
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
export const PostAsset = PostAssetBase.superRefine(postAssetRefinement);
|
|
187
|
+
|
|
188
|
+
export type PostAsset = z.infer<typeof PostAsset>;
|
|
189
|
+
|
|
190
|
+
export const CompliancePostAsset = PostAssetBase.extend({
|
|
191
|
+
accountId: accountIdSchema,
|
|
192
|
+
}).superRefine(postAssetRefinement);
|
|
193
|
+
|
|
194
|
+
export type CompliancePostAsset = z.infer<typeof CompliancePostAsset>;
|
|
195
|
+
|
|
196
|
+
export const PutAsset = z.object({
|
|
197
|
+
name: z.string().min(2).max(50).optional().openapi({ example: 'Z' }),
|
|
198
|
+
type: z
|
|
199
|
+
.nativeEnum(AssetType)
|
|
200
|
+
.optional()
|
|
201
|
+
.openapi({ example: AssetType.STOCK }),
|
|
202
|
+
pricePerUnit: z
|
|
203
|
+
.number()
|
|
204
|
+
.min(0.01)
|
|
205
|
+
.max(10000000000)
|
|
206
|
+
.nullable()
|
|
207
|
+
.optional()
|
|
208
|
+
.openapi({ example: 2000 }),
|
|
209
|
+
totalUnits: z
|
|
210
|
+
.number()
|
|
211
|
+
.min(1)
|
|
212
|
+
.max(10000000000)
|
|
213
|
+
.nullable()
|
|
214
|
+
.optional()
|
|
215
|
+
.openapi({ example: 5200 }),
|
|
216
|
+
yield: z
|
|
217
|
+
.number()
|
|
218
|
+
.min(0.01)
|
|
219
|
+
.max(10000000000)
|
|
220
|
+
.nullable()
|
|
221
|
+
.optional()
|
|
222
|
+
.openapi({ example: 1200 }),
|
|
223
|
+
duration: z
|
|
224
|
+
.number()
|
|
225
|
+
.min(1)
|
|
226
|
+
.max(1000)
|
|
227
|
+
.nullable()
|
|
228
|
+
.optional()
|
|
229
|
+
.openapi({ example: 1 }),
|
|
230
|
+
durationType: z
|
|
231
|
+
.nativeEnum(DurationType)
|
|
232
|
+
.nullable()
|
|
233
|
+
.optional()
|
|
234
|
+
.openapi({ example: DurationType.DAY }),
|
|
235
|
+
template: z
|
|
236
|
+
.nativeEnum(TemplateType)
|
|
237
|
+
.default(TemplateType.STANDARD)
|
|
238
|
+
.openapi({ example: TemplateType.STANDARD })
|
|
239
|
+
.nullable()
|
|
240
|
+
.optional(),
|
|
241
|
+
tiers: z.array(z.number().positive()).nullable().optional(),
|
|
242
|
+
enableBonus: z.boolean().optional().openapi({ example: false }),
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
export type PutAsset = z.infer<typeof PutAsset>;
|
|
246
|
+
|
|
247
|
+
export const CompliancePutAsset = PutAsset.merge(
|
|
248
|
+
z.object({ accountId: accountIdSchema }),
|
|
249
|
+
);
|
|
250
|
+
export type CompliancePutAsset = z.infer<typeof CompliancePutAsset>;
|
|
251
|
+
|
|
252
|
+
const assetsInclude = z.enum(['account', 'offering', 'bonusTiers']);
|
|
253
|
+
|
|
254
|
+
export const AssetsIncludeQuery = z.object({
|
|
255
|
+
include: z
|
|
256
|
+
.string()
|
|
257
|
+
.optional()
|
|
258
|
+
.transform((str) => (str ? str.split(',') : []))
|
|
259
|
+
.refine(
|
|
260
|
+
(includes) =>
|
|
261
|
+
includes.every((include) =>
|
|
262
|
+
assetsInclude.options.includes(include as any),
|
|
263
|
+
),
|
|
264
|
+
{
|
|
265
|
+
message: `Invalid include option provided. Valid options are: ${assetsInclude.options.join(', ')}`,
|
|
266
|
+
},
|
|
267
|
+
)
|
|
268
|
+
.openapi({
|
|
269
|
+
example: `${assetsInclude.options.join(', ')}`,
|
|
270
|
+
}),
|
|
271
|
+
});
|
|
272
|
+
export interface AssetsIncludeQuery
|
|
273
|
+
extends z.infer<typeof AssetsIncludeQuery> {}
|
|
274
|
+
|
|
275
|
+
export const AssetFiltersZod = z.object({
|
|
276
|
+
name: z.string().optional(),
|
|
277
|
+
accountId: accountIdSchema.optional(),
|
|
278
|
+
offeringId: z
|
|
279
|
+
.lazy(() => offeringIdSchema)
|
|
280
|
+
.openapi({ example: 'offering_01jayn2qkpeebav9gjpqx7xm8j' })
|
|
281
|
+
.optional(),
|
|
282
|
+
issuerId: z.lazy(() => issuerIdSchema).optional(),
|
|
283
|
+
type: z.nativeEnum(AssetType).optional(),
|
|
284
|
+
});
|
|
285
|
+
export type AssetFiltersZod = z.infer<typeof AssetFiltersZod>;
|
|
286
|
+
|
|
287
|
+
export const AssetSortZod = z.object({
|
|
288
|
+
sort: z.enum([SortBy.NAME, SortBy.CREATED_AT, SortBy.UPDATED_AT]).optional(),
|
|
289
|
+
dir: z.nativeEnum(SortOrder).optional(),
|
|
290
|
+
});
|
|
291
|
+
export type AssetSortZod = z.infer<typeof AssetSortZod>;
|
|
292
|
+
|
|
293
|
+
const BaseAssetSummarySchema = z.object({
|
|
294
|
+
id: z.string(),
|
|
295
|
+
name: z.string(),
|
|
296
|
+
accountId: accountIdSchema,
|
|
297
|
+
offeringId: offeringIdSchema,
|
|
298
|
+
issuerId: z.lazy(() => issuerIdSchema).nullable(),
|
|
299
|
+
pricePerUnit: z.number().nullable(),
|
|
300
|
+
totalUnits: z.number().nullable(),
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
export const StockAssetSchema = BaseAssetSummarySchema.extend({
|
|
304
|
+
type: z.literal(AssetType.STOCK),
|
|
305
|
+
});
|
|
306
|
+
export type StockAssetSchema = z.infer<typeof StockAssetSchema>;
|
|
307
|
+
|
|
308
|
+
const BondAssetSchema = BaseAssetSummarySchema.extend({
|
|
309
|
+
type: z.literal(AssetType.BOND).nullable(),
|
|
310
|
+
yield: z.number().nullable(),
|
|
311
|
+
duration: z.number().nullable(),
|
|
312
|
+
durationType: z.nativeEnum(DurationType).nullable(),
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
export const AssetSummarySchema = z.discriminatedUnion('type', [
|
|
316
|
+
StockAssetSchema,
|
|
317
|
+
BondAssetSchema,
|
|
318
|
+
]);
|
|
319
|
+
export type AssetSummarySchema = z.infer<typeof AssetSummarySchema>;
|
|
320
|
+
|
|
321
|
+
export const IPaginatedAssetSummary = z.object({
|
|
322
|
+
items: z.array(AssetSummarySchema),
|
|
323
|
+
meta: IPaginationMeta,
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
export type IPaginatedAssetSummary = z.infer<typeof IPaginatedAssetSummary>;
|
|
327
|
+
|
|
328
|
+
export const AssetSummaryFiltersZod = z.object({
|
|
329
|
+
accountId: accountIdSchema.optional(),
|
|
330
|
+
issuerId: z.lazy(() => issuerIdSchema).optional(),
|
|
331
|
+
offeringId: z
|
|
332
|
+
.lazy(() => offeringIdSchema)
|
|
333
|
+
.openapi({ example: 'offering_01jayn2qkpeebav9gjpqx7xm8j' })
|
|
334
|
+
.optional(),
|
|
335
|
+
type: z.nativeEnum(AssetType),
|
|
336
|
+
name: z.string().optional(),
|
|
337
|
+
});
|
|
338
|
+
export type AssetSummaryFiltersZod = z.infer<typeof AssetSummaryFiltersZod>;
|
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { extendZodWithOpenApi } from '@anatine/zod-openapi';
|
|
3
|
+
import { accountIdSchema } from './account.types';
|
|
4
|
+
import { PasswordSchema } from './password.type';
|
|
5
|
+
import { inviteIdSchema } from './invite.types';
|
|
6
|
+
import {
|
|
7
|
+
PortalType,
|
|
8
|
+
ManagedByType,
|
|
9
|
+
UserRole,
|
|
10
|
+
createUrlSchema,
|
|
11
|
+
} from './common.types';
|
|
12
|
+
import { TypeID } from 'typeid-js';
|
|
13
|
+
import { TwoFactorMethod } from './sms.types';
|
|
14
|
+
import { PhoneZodSchema } from './phone.type';
|
|
15
|
+
|
|
16
|
+
extendZodWithOpenApi(z);
|
|
17
|
+
|
|
18
|
+
export const userLoginIdSchema = z.string().refine(
|
|
19
|
+
(value) => {
|
|
20
|
+
try {
|
|
21
|
+
const tid = TypeID.fromString(value);
|
|
22
|
+
return tid.getType() === 'user_login';
|
|
23
|
+
} catch {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
message:
|
|
29
|
+
'Invalid user ID format. Must be a valid TypeID with "user_login" prefix.',
|
|
30
|
+
},
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
export enum AuthProvider {
|
|
34
|
+
EMAIL = 'email',
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const isBase64 = (v: string) => {
|
|
38
|
+
if (v.length % 4 !== 0) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
return btoa(atob(v)) === v;
|
|
43
|
+
} catch (err) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const BaseAuthBody = z.object({
|
|
49
|
+
firstName: z
|
|
50
|
+
.string()
|
|
51
|
+
.min(2, 'firstName is less than 2 characters')
|
|
52
|
+
.max(20, 'firstName is more than 20 characters')
|
|
53
|
+
.openapi({
|
|
54
|
+
example: 'Neil',
|
|
55
|
+
}),
|
|
56
|
+
lastName: z
|
|
57
|
+
.string()
|
|
58
|
+
.min(2, 'lastName is less than 2 characters')
|
|
59
|
+
.max(20, 'lastName is more than 20 characters')
|
|
60
|
+
.openapi({
|
|
61
|
+
example: 'Armstrong',
|
|
62
|
+
}),
|
|
63
|
+
email: z
|
|
64
|
+
.string()
|
|
65
|
+
.email()
|
|
66
|
+
.transform((val) => val.toLowerCase())
|
|
67
|
+
.openapi({
|
|
68
|
+
example: 'neil@dalmoregroup.com',
|
|
69
|
+
}),
|
|
70
|
+
password: PasswordSchema,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
export const IRegisterBodyZod = BaseAuthBody.extend({
|
|
74
|
+
code: z
|
|
75
|
+
.string()
|
|
76
|
+
.refine(isBase64, {
|
|
77
|
+
message: 'Must be a valid base64 encoded string',
|
|
78
|
+
})
|
|
79
|
+
.openapi({
|
|
80
|
+
example: 'eyJpdiI6InhhTFIyVG9ETnhnUzQ1QzUyNzRJenc9PSIsI',
|
|
81
|
+
}),
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
export const IChangePasswordBodyZod = z
|
|
85
|
+
.object({
|
|
86
|
+
currentPassword: z.string().min(6).openapi({
|
|
87
|
+
example: 'Secretpassword6#',
|
|
88
|
+
}),
|
|
89
|
+
newPassword: PasswordSchema,
|
|
90
|
+
newPasswordConfirm: PasswordSchema,
|
|
91
|
+
})
|
|
92
|
+
.refine((data) => data.currentPassword !== data.newPassword, {
|
|
93
|
+
message: 'New password must be different from current password',
|
|
94
|
+
path: ['newPassword'],
|
|
95
|
+
})
|
|
96
|
+
.refine((data) => data.newPassword === data.newPasswordConfirm, {
|
|
97
|
+
message: 'Password confirmation does not match new password',
|
|
98
|
+
path: ['newPasswordConfirm'],
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
export const LoginBody = z.object({
|
|
102
|
+
email: z
|
|
103
|
+
.string()
|
|
104
|
+
.email()
|
|
105
|
+
.transform((val) => val.toLowerCase())
|
|
106
|
+
.openapi({
|
|
107
|
+
example: 'neil@dalmoregroup.com',
|
|
108
|
+
}),
|
|
109
|
+
password: z.string().openapi({
|
|
110
|
+
example: 'Secretpassword6#',
|
|
111
|
+
}),
|
|
112
|
+
rememberMe: z.boolean().optional().default(false).openapi({
|
|
113
|
+
example: true,
|
|
114
|
+
}),
|
|
115
|
+
twoFactorMethod: z.nativeEnum(TwoFactorMethod).optional().openapi({
|
|
116
|
+
example: 'SMS',
|
|
117
|
+
}),
|
|
118
|
+
});
|
|
119
|
+
export type LoginBody = z.infer<typeof LoginBody>;
|
|
120
|
+
|
|
121
|
+
export const LoginBody2FA = z.object({
|
|
122
|
+
token: z.string().min(6).max(14).openapi({
|
|
123
|
+
example: 'neil@dalmoregroup.com',
|
|
124
|
+
}),
|
|
125
|
+
temporaryToken: z.string().min(1).openapi({
|
|
126
|
+
example: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9',
|
|
127
|
+
}),
|
|
128
|
+
rememberMe: z.boolean().optional().default(false).openapi({
|
|
129
|
+
example: true,
|
|
130
|
+
}),
|
|
131
|
+
});
|
|
132
|
+
export type LoginBody2FA = z.infer<typeof LoginBody>;
|
|
133
|
+
|
|
134
|
+
export const LoginBodyInvestors = LoginBody.extend({
|
|
135
|
+
site: z.string().openapi({ site: 'example.com' }),
|
|
136
|
+
});
|
|
137
|
+
export type LoginBodyInvestors = z.infer<typeof LoginBodyInvestors>;
|
|
138
|
+
|
|
139
|
+
export const LoginBodyIssuers = LoginBody.extend({
|
|
140
|
+
accountId: accountIdSchema.openapi({
|
|
141
|
+
accountId: 'account_00041061050r3gg28a1c60t3gf',
|
|
142
|
+
}),
|
|
143
|
+
});
|
|
144
|
+
export type LoginBodyIssuers = z.infer<typeof LoginBodyIssuers>;
|
|
145
|
+
|
|
146
|
+
export const SelectAccountIssuers = LoginBody;
|
|
147
|
+
export type SelectAccountIssuers = z.infer<typeof SelectAccountIssuers>;
|
|
148
|
+
|
|
149
|
+
export const SelectAccountIssuersResponse = z.object({
|
|
150
|
+
invites: z.array(
|
|
151
|
+
z.object({
|
|
152
|
+
id: inviteIdSchema.openapi({
|
|
153
|
+
example: 'invite_00041061050r3gg28a1c60t3gf',
|
|
154
|
+
}),
|
|
155
|
+
name: z.string().openapi({ example: 'Example Account' }),
|
|
156
|
+
accountId: accountIdSchema.nullable().openapi({
|
|
157
|
+
example: 'account_00041061050r3gg28a1c60t3gf',
|
|
158
|
+
}),
|
|
159
|
+
role: z
|
|
160
|
+
.nativeEnum(UserRole)
|
|
161
|
+
.nullable()
|
|
162
|
+
.openapi({ example: UserRole.MARKETER }),
|
|
163
|
+
}),
|
|
164
|
+
),
|
|
165
|
+
accounts: z.array(
|
|
166
|
+
z.object({
|
|
167
|
+
id: accountIdSchema.openapi({
|
|
168
|
+
example: 'account_00041061050r3gg28a1c60t3gf',
|
|
169
|
+
}),
|
|
170
|
+
name: z.string().openapi({ example: 'Example Account' }),
|
|
171
|
+
firstName: z.string().openapi({ example: 'John' }),
|
|
172
|
+
lastName: z.string().openapi({ example: 'Doe' }),
|
|
173
|
+
}),
|
|
174
|
+
),
|
|
175
|
+
});
|
|
176
|
+
export type SelectAccountIssuersResponse = z.infer<
|
|
177
|
+
typeof SelectAccountIssuersResponse
|
|
178
|
+
>;
|
|
179
|
+
|
|
180
|
+
export const SwitchAccountIssuersBody = z.object({
|
|
181
|
+
accountId: accountIdSchema,
|
|
182
|
+
});
|
|
183
|
+
export type SwitchAccountIssuersBody = z.infer<typeof SwitchAccountIssuersBody>;
|
|
184
|
+
|
|
185
|
+
export const AccessTokenResponse = z.object({
|
|
186
|
+
accessToken: z.string().optional().openapi({
|
|
187
|
+
example: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9',
|
|
188
|
+
}),
|
|
189
|
+
requiresTwoFactor: z.boolean().optional().openapi({
|
|
190
|
+
example: true,
|
|
191
|
+
}),
|
|
192
|
+
temporaryToken: z.string().optional().openapi({
|
|
193
|
+
example: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9',
|
|
194
|
+
}),
|
|
195
|
+
requiresTwoFactorSetup: z.boolean().optional().openapi({
|
|
196
|
+
example: true,
|
|
197
|
+
}),
|
|
198
|
+
twoFactorMethod: z.nativeEnum(TwoFactorMethod).optional().openapi({
|
|
199
|
+
example: 'SMS',
|
|
200
|
+
}),
|
|
201
|
+
});
|
|
202
|
+
export type AccessTokenResponse = z.infer<typeof AccessTokenResponse>;
|
|
203
|
+
|
|
204
|
+
// Base schema for issuer registration (shared fields without refinements)
|
|
205
|
+
const BaseRegisterIssuerFields = BaseAuthBody.extend({
|
|
206
|
+
confirmPassword: PasswordSchema,
|
|
207
|
+
accountName: z
|
|
208
|
+
.string()
|
|
209
|
+
.min(1)
|
|
210
|
+
.max(150)
|
|
211
|
+
.openapi({
|
|
212
|
+
example: 'Example Account',
|
|
213
|
+
})
|
|
214
|
+
.nullable()
|
|
215
|
+
.optional(),
|
|
216
|
+
accountType: z
|
|
217
|
+
.nativeEnum(ManagedByType)
|
|
218
|
+
.optional()
|
|
219
|
+
.default(ManagedByType.DALMORE)
|
|
220
|
+
.openapi({
|
|
221
|
+
example: ManagedByType.DALMORE,
|
|
222
|
+
}),
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
// Full issuer registration schema with code (for invite-based registration)
|
|
226
|
+
export const IRegisterIssuerBodyZod = BaseRegisterIssuerFields.extend({
|
|
227
|
+
code: z
|
|
228
|
+
.string()
|
|
229
|
+
.refine(isBase64, {
|
|
230
|
+
message: 'Must be a valid base64 encoded string',
|
|
231
|
+
})
|
|
232
|
+
.optional()
|
|
233
|
+
.openapi({
|
|
234
|
+
example: 'eyJpdiI6InhhTFIyVG9ETnhnUzQ1QzUyNzRJenc9PSIsI',
|
|
235
|
+
}),
|
|
236
|
+
})
|
|
237
|
+
.refine((data) => data.password === data.confirmPassword, {
|
|
238
|
+
message: 'Passwords do not match',
|
|
239
|
+
path: ['confirmPassword'],
|
|
240
|
+
})
|
|
241
|
+
.refine(
|
|
242
|
+
(data) => {
|
|
243
|
+
// If code is not provided, accountName must be present and not empty/null
|
|
244
|
+
if (!data.code || data.code.length === 0) {
|
|
245
|
+
return (
|
|
246
|
+
data.accountName !== null &&
|
|
247
|
+
data.accountName !== undefined &&
|
|
248
|
+
data.accountName !== ''
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
// If code is provided, accountName is not required
|
|
252
|
+
return true;
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
message: 'Account name is required if code is not provided',
|
|
256
|
+
path: ['accountName'],
|
|
257
|
+
},
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
// Client issuer registration schema without code (for API key registration)
|
|
261
|
+
export const IRegisterClientIssuerBodyZod = BaseRegisterIssuerFields.refine(
|
|
262
|
+
(data) => data.password === data.confirmPassword,
|
|
263
|
+
{
|
|
264
|
+
message: 'Passwords do not match',
|
|
265
|
+
path: ['confirmPassword'],
|
|
266
|
+
},
|
|
267
|
+
).refine(
|
|
268
|
+
(data) => {
|
|
269
|
+
// For client registration, accountName is always required
|
|
270
|
+
return (
|
|
271
|
+
data.accountName !== null &&
|
|
272
|
+
data.accountName !== undefined &&
|
|
273
|
+
data.accountName !== ''
|
|
274
|
+
);
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
message: 'Account name is required',
|
|
278
|
+
path: ['accountName'],
|
|
279
|
+
},
|
|
280
|
+
);
|
|
281
|
+
|
|
282
|
+
// Investors are a special case in which they require phone number at the time of registration
|
|
283
|
+
// The phone number provided here is NOT validated and will still need to go thru the regular 2FA setup process
|
|
284
|
+
export const RegisterBodyInvestors = BaseAuthBody.extend({
|
|
285
|
+
confirmPassword: PasswordSchema,
|
|
286
|
+
phoneNumber: PhoneZodSchema.openapi({ example: '+12124567890' }).optional(),
|
|
287
|
+
site: z
|
|
288
|
+
.string()
|
|
289
|
+
.min(2, 'site is less than 2 characters')
|
|
290
|
+
.max(253, 'site is more than 253 characters')
|
|
291
|
+
.openapi({
|
|
292
|
+
example: 'func.co',
|
|
293
|
+
}),
|
|
294
|
+
}).refine((data) => data.password === data.confirmPassword, {
|
|
295
|
+
message: 'Passwords do not match',
|
|
296
|
+
path: ['confirmPassword'],
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
export const ResetPasswordVerifyBody = z.object({
|
|
300
|
+
email: z.string().email(),
|
|
301
|
+
code: z.string().length(6, 'code is not 6 characters').openapi({
|
|
302
|
+
example: '123456',
|
|
303
|
+
}),
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
export type ResetPasswordVerifyBodyType = z.infer<
|
|
307
|
+
typeof ResetPasswordVerifyBody
|
|
308
|
+
>;
|
|
309
|
+
export const ResetPasswordVerifyResponse = z.object({
|
|
310
|
+
valid: z.boolean(),
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
export type ResetPasswordVerifyResponseType = z.infer<
|
|
314
|
+
typeof ResetPasswordVerifyResponse
|
|
315
|
+
>;
|
|
316
|
+
|
|
317
|
+
export const ResetPasswordBody = z.object({
|
|
318
|
+
email: z.string().email(),
|
|
319
|
+
code: z.string().length(6, 'code is not 6 characters').openapi({
|
|
320
|
+
example: '123456',
|
|
321
|
+
}),
|
|
322
|
+
password: PasswordSchema,
|
|
323
|
+
});
|
|
324
|
+
export type ResetPasswordBodyType = z.infer<typeof ResetPasswordBody>;
|
|
325
|
+
|
|
326
|
+
export const AuthSuccessResponse = z.object({
|
|
327
|
+
success: z.boolean(),
|
|
328
|
+
});
|
|
329
|
+
export type AuthSuccessResponseType = z.infer<typeof AuthSuccessResponse>;
|
|
330
|
+
|
|
331
|
+
export const ClientAuthSuccessResponse = z.object({
|
|
332
|
+
userId: z.string().openapi({ example: 'user_01je6ht4b8fbmttkzh2hs82xqp' }),
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
export type ClientAuthSuccessResponse = z.infer<
|
|
336
|
+
typeof ClientAuthSuccessResponse
|
|
337
|
+
>;
|
|
338
|
+
|
|
339
|
+
export const AdminForgotPasswordRequestZod = z.object({
|
|
340
|
+
email: z.string().email(),
|
|
341
|
+
portal: z.nativeEnum(PortalType),
|
|
342
|
+
});
|
|
343
|
+
export type AdminForgotPasswordRequestZod = z.infer<
|
|
344
|
+
typeof AdminForgotPasswordRequestZod
|
|
345
|
+
>;
|
|
346
|
+
|
|
347
|
+
export const InvestorForgotPasswordRequestZod = z.object({
|
|
348
|
+
email: z.string().email(),
|
|
349
|
+
url: createUrlSchema({ strict: true }),
|
|
350
|
+
});
|
|
351
|
+
export type InvestorForgotPasswordRequestZod = z.infer<
|
|
352
|
+
typeof InvestorForgotPasswordRequestZod
|
|
353
|
+
>;
|
|
354
|
+
|
|
355
|
+
// Define paths that should be accessible EVEN with twoFactorPending
|
|
356
|
+
export const twoFactorPendingAllowedPaths = [
|
|
357
|
+
'/auth/login',
|
|
358
|
+
'/auth/register',
|
|
359
|
+
'/user-settings/valid-phone-number',
|
|
360
|
+
'/user-settings/setup-phone-number',
|
|
361
|
+
'/user-settings/verify-phone-number',
|
|
362
|
+
'/user-settings/send-verification-code',
|
|
363
|
+
'/user-settings/setup-authenticator',
|
|
364
|
+
'/user-settings/verify-authenticator',
|
|
365
|
+
];
|
|
366
|
+
|
|
367
|
+
export const lockedUserAllowedPathsAndMethods = [
|
|
368
|
+
{ path: '/users/me', method: 'GET' },
|
|
369
|
+
{ path: '/auth/login', method: 'POST' },
|
|
370
|
+
];
|