@dalmore/api-contracts 1.0.5 → 1.0.6

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.
Files changed (137) hide show
  1. package/package.json +4 -5
  2. package/src/common/types/account-contact.types.ts +98 -0
  3. package/src/common/types/account-detail.types.ts +27 -0
  4. package/src/common/types/account-integration.types.ts +143 -0
  5. package/src/common/types/account-manager.types.ts +124 -0
  6. package/src/common/types/account.types.ts +296 -0
  7. package/src/common/types/activity.types.ts +274 -0
  8. package/src/common/types/address.spec.ts +203 -0
  9. package/src/common/types/address.types.ts +41 -0
  10. package/src/common/types/aic.types.ts +246 -0
  11. package/src/common/types/aml.types.ts +18 -0
  12. package/src/common/types/api-key-logs.types.ts +66 -0
  13. package/src/common/types/api-keys.types.ts +69 -0
  14. package/src/common/types/asset.types.ts +338 -0
  15. package/src/common/types/auth.types.ts +370 -0
  16. package/src/common/types/batch-jobs.types.ts +151 -0
  17. package/src/common/types/bonus-tier.types.ts +147 -0
  18. package/src/common/types/cart.types.ts +18 -0
  19. package/src/common/types/checklist-items.types.ts +70 -0
  20. package/src/common/types/checklist.types.ts +97 -0
  21. package/src/common/types/common.types.spec.ts +336 -0
  22. package/src/common/types/common.types.ts +1520 -0
  23. package/src/common/types/comply-advantage-api.types.ts +316 -0
  24. package/src/common/types/comply-advantage.types.ts +25 -0
  25. package/src/common/types/contact-us.types.ts +107 -0
  26. package/src/common/types/contract-helpers.ts +205 -0
  27. package/src/common/types/countries.types.ts +375 -0
  28. package/src/common/types/covered-person.types.ts +274 -0
  29. package/src/common/types/dashboard.types.ts +799 -0
  30. package/src/common/types/data-record.types.ts +325 -0
  31. package/src/common/types/data-room.types.ts +242 -0
  32. package/src/common/types/default-theme-config.types.ts +87 -0
  33. package/src/common/types/disbursement-adjustment.types.ts +32 -0
  34. package/src/common/types/disbursement-approval-user.types.ts +100 -0
  35. package/src/common/types/disbursement-review.types.ts +110 -0
  36. package/src/common/types/disbursement-transaction.types.ts +72 -0
  37. package/src/common/types/disbursements.types.ts +310 -0
  38. package/src/common/types/domain-filter.types.ts +55 -0
  39. package/src/common/types/email-theme.types.ts +442 -0
  40. package/src/common/types/entity.types.ts +15 -0
  41. package/src/common/types/error-responses.types.ts +135 -0
  42. package/src/common/types/escrow-account.types.ts +104 -0
  43. package/src/common/types/exchange-api-key.types.ts +121 -0
  44. package/src/common/types/exchange-import.types.ts +36 -0
  45. package/src/common/types/exchange-provider.types.ts +329 -0
  46. package/src/common/types/file.types.ts +461 -0
  47. package/src/common/types/files.types.spec.ts +154 -0
  48. package/src/common/types/health.types.ts +29 -0
  49. package/src/common/types/index.ts +48 -0
  50. package/src/common/types/individuals.types.ts +554 -0
  51. package/src/common/types/investor-account.types.ts +1239 -0
  52. package/src/common/types/investorAccountIdSchema.type.ts +0 -0
  53. package/src/common/types/investors-offering.types.ts +65 -0
  54. package/src/common/types/invite.types.ts +133 -0
  55. package/src/common/types/issuer-bank-account.types.ts +107 -0
  56. package/src/common/types/issuer-offering.types.ts +306 -0
  57. package/src/common/types/issuer-payment-method.types.spec.ts +612 -0
  58. package/src/common/types/issuer-payment-method.types.ts +341 -0
  59. package/src/common/types/issuer.types.ts +312 -0
  60. package/src/common/types/job-item.types.ts +119 -0
  61. package/src/common/types/jobs.types.ts +171 -0
  62. package/src/common/types/kyb.types.ts +53 -0
  63. package/src/common/types/kyc.types.ts +188 -0
  64. package/src/common/types/legal-entity.types.ts +185 -0
  65. package/src/common/types/login-history.types.ts +46 -0
  66. package/src/common/types/mail-template.types.ts +436 -0
  67. package/src/common/types/north-cap-integration.types.ts +190 -0
  68. package/src/common/types/note.types.ts +109 -0
  69. package/src/common/types/notification.types.ts +58 -0
  70. package/src/common/types/notion-api.types.ts +374 -0
  71. package/src/common/types/notion-database.types.ts +125 -0
  72. package/src/common/types/notion-page.types.ts +267 -0
  73. package/src/common/types/offering-reports.types.ts +153 -0
  74. package/src/common/types/offering-submission.types.ts +314 -0
  75. package/src/common/types/offering.types.spec.ts +91 -0
  76. package/src/common/types/offering.types.ts +590 -0
  77. package/src/common/types/page-revision.types.ts +86 -0
  78. package/src/common/types/page.types.ts +436 -0
  79. package/src/common/types/password.type.ts +15 -0
  80. package/src/common/types/payment-methods.types.ts +298 -0
  81. package/src/common/types/phone.spec.ts +76 -0
  82. package/src/common/types/phone.type.ts +27 -0
  83. package/src/common/types/portfolio.types.ts +50 -0
  84. package/src/common/types/privacy-policy-and-tos.types.ts +231 -0
  85. package/src/common/types/queue.types.ts +112 -0
  86. package/src/common/types/registered-reps.types.ts +25 -0
  87. package/src/common/types/rejection-reasons.types.ts +56 -0
  88. package/src/common/types/reminder-config.types.ts +40 -0
  89. package/src/common/types/review.types.ts +133 -0
  90. package/src/common/types/role.types.ts +26 -0
  91. package/src/common/types/secondary-customer.types.ts +66 -0
  92. package/src/common/types/secondary-issuer.types.ts +50 -0
  93. package/src/common/types/secondary-order.types.ts +58 -0
  94. package/src/common/types/secondary-security.types.ts +60 -0
  95. package/src/common/types/secondary-trade.entity.ts +16 -0
  96. package/src/common/types/secondary-trade.types.ts +95 -0
  97. package/src/common/types/secure-request.types.ts +68 -0
  98. package/src/common/types/signer.types.ts +651 -0
  99. package/src/common/types/site-link.types.spec.ts +134 -0
  100. package/src/common/types/site-link.types.ts +166 -0
  101. package/src/common/types/site-settings.types.ts +726 -0
  102. package/src/common/types/site.types.ts +270 -0
  103. package/src/common/types/sms.types.ts +30 -0
  104. package/src/common/types/state-machine.types.ts +177 -0
  105. package/src/common/types/states.types.ts +163 -0
  106. package/src/common/types/subdoc-preview.types.ts +35 -0
  107. package/src/common/types/task.types.ts +258 -0
  108. package/src/common/types/trade-adjustment.type.ts +33 -0
  109. package/src/common/types/trade-line-item.type.ts +132 -0
  110. package/src/common/types/trade.types.ts +929 -0
  111. package/src/common/types/transaction.types.ts +198 -0
  112. package/src/common/types/trusted-contact.types.ts +122 -0
  113. package/src/common/types/typography.types.ts +75 -0
  114. package/src/common/types/user-manual.types.ts +290 -0
  115. package/src/common/types/user-setting.types.ts +133 -0
  116. package/src/common/types/user.types.ts +320 -0
  117. package/src/common/types/webhook.types.ts +588 -0
  118. package/src/common/types/zip.type.ts +36 -0
  119. package/src/contracts/clients/accounts/index.ts +61 -0
  120. package/src/contracts/clients/aic/index.ts +59 -0
  121. package/src/contracts/clients/api-key-logs/index.ts +53 -0
  122. package/src/contracts/clients/api-keys/index.ts +73 -0
  123. package/src/contracts/clients/assets/index.ts +102 -0
  124. package/src/contracts/clients/auth/index.ts +50 -0
  125. package/src/contracts/clients/files/index.ts +166 -0
  126. package/src/contracts/clients/files-public/index.ts +166 -0
  127. package/src/contracts/clients/index.ts +44 -0
  128. package/src/contracts/clients/individuals/index.ts +93 -0
  129. package/src/contracts/clients/investor-accounts/index.ts +93 -0
  130. package/src/contracts/clients/issuers/index.ts +94 -0
  131. package/src/contracts/clients/legal-entities/index.ts +93 -0
  132. package/src/contracts/clients/offerings/index.ts +117 -0
  133. package/src/contracts/clients/secure-requests/index.ts +34 -0
  134. package/src/contracts/clients/sites/index.ts +56 -0
  135. package/src/contracts/clients/trades/index.ts +122 -0
  136. package/index.d.mts +0 -17
  137. package/index.d.ts +0 -17
@@ -0,0 +1,929 @@
1
+ import { z } from 'zod';
2
+ import {
3
+ InvestmentType,
4
+ IPaginationMeta,
5
+ FundingStatus,
6
+ TxnCheck,
7
+ PaginationOptionsZod,
8
+ dateSchema,
9
+ BaseStatus,
10
+ ComplianceReview,
11
+ OfferingType,
12
+ ManagedByType,
13
+ SignatureStatus,
14
+ TradeType,
15
+ TradeStatus,
16
+ SortOrder,
17
+ SortBy,
18
+ AicStatus,
19
+ AMLStatus,
20
+ KYCStatus,
21
+ createDateSchema,
22
+ AccountStatus,
23
+ SavedQuery,
24
+ } from './common.types';
25
+ import { offeringIdSchema } from './offering.types';
26
+ import { IBaseEntity } from './entity.types';
27
+ import { extendZodWithOpenApi } from '@anatine/zod-openapi';
28
+ import { TypeID } from 'typeid-js';
29
+ import {
30
+ paymentMethodIdSchema,
31
+ PaymentMethodType,
32
+ } from './payment-methods.types';
33
+ import {
34
+ investorAccountIdSchema,
35
+ InvestorAccountExportFilters,
36
+ ComplianceInvestorAccountExportFilters,
37
+ RegisteredInvestorUserRawZod,
38
+ } from './investor-account.types';
39
+ import {
40
+ tradeLineItemIdSchema,
41
+ TradeLineItemZod,
42
+ } from './trade-line-item.type';
43
+ import { TradeAdjustmentZod } from './trade-adjustment.type';
44
+ import { TransactionZod } from './transaction.types';
45
+ import { accountIdSchema } from './account.types';
46
+ import { userIdSchema } from './user.types';
47
+ import { issuerIdSchema } from './issuer.types';
48
+ import {
49
+ GetSecondaryCustomerFiltersZod,
50
+ SecondaryCustomer,
51
+ } from './secondary-customer.types';
52
+ import {
53
+ SecondaryTrade,
54
+ SecondaryTradeFiltersZod,
55
+ } from './secondary-trade.types';
56
+ import { InvestorAccount } from '../../investor-accounts/entities/investor-account.entity';
57
+ import { Trade } from '../../trades/entities/trade.entity';
58
+
59
+ extendZodWithOpenApi(z);
60
+ export const CheckResultsSchema = z.object({
61
+ fundingStatus: z.boolean(),
62
+ agreementStatus: z.boolean(),
63
+ subscriptionAgreementCheck: z.boolean(),
64
+ kycStatus: z.boolean(),
65
+ sanctionsStatus: z.boolean(),
66
+ accreditationStatus: z.boolean(),
67
+ kybStatus: z.boolean(),
68
+ });
69
+ export type CheckResults = z.infer<typeof CheckResultsSchema>;
70
+
71
+ export const TradeIdPrefix = 'trade';
72
+
73
+ export const tradeIdSchema = z.string().refine(
74
+ (value) => {
75
+ try {
76
+ const tid = TypeID.fromString(value);
77
+ return tid.getType() === TradeIdPrefix;
78
+ } catch {
79
+ return false;
80
+ }
81
+ },
82
+ {
83
+ message:
84
+ 'Invalid trade ID format. Must be a valid TypeID with "trade" prefix. ex: trade_00041061050r3gg28a1c60t3gf',
85
+ },
86
+ );
87
+
88
+ export const tradeIdOrTidSchema = z.union([
89
+ z.string().refine(
90
+ (value) => {
91
+ try {
92
+ const tid = TypeID.fromString(value);
93
+ return tid.getType() === TradeIdPrefix;
94
+ } catch {
95
+ return false;
96
+ }
97
+ },
98
+ {
99
+ message:
100
+ 'Invalid trade ID format. Must be a valid TypeID with "trade" prefix. ex: trade_00041061050r3gg28a1c60t3gf',
101
+ },
102
+ ),
103
+ z
104
+ .string()
105
+ .min(1)
106
+ .max(50)
107
+ .openapi({ example: 'tid_00041061050r3gg28a1c60t3gf' }),
108
+ ]);
109
+
110
+ export enum SaStatus {
111
+ PENDING = BaseStatus.PENDING,
112
+ SIGNED = BaseStatus.SIGNED,
113
+ DECLINED = BaseStatus.DECLINED,
114
+ NEEDS_REVIEW = BaseStatus.NEEDS_REVIEW,
115
+ }
116
+
117
+ export enum TradeSystemLogType {
118
+ SUB_DOC_CHECK = 'Subscription Agreement Check',
119
+ ADDRESS_CHECK = 'Address Check',
120
+ COUNTRY_CHECK = 'Country Check',
121
+ CONCENTRATION_CHECK = 'Concentration Check',
122
+ KYC_CHECK = 'KYC Check',
123
+ AML_CHECK = 'AML Check',
124
+ AIC_CHECK = 'AIC Check',
125
+ USER_AGE_CHECK = 'User Age Check',
126
+ KYC_NAME_CHECK = 'KYC Name Check',
127
+ AML_NAME_CHECK = 'AML Name Check',
128
+ AIC_NAME_CHECK = 'AIC Name Check',
129
+ KYC_DOB_CHECK = 'KYC DOB Check',
130
+ AIC_SSN_CHECK = 'AIC SSN Check',
131
+ // Data Integrity Checks For Imported Trades
132
+ SHARES_CHECK = 'Shares Check',
133
+ PRICE_PER_UNIT_CHECK = 'Price Per Unit Check',
134
+ ISSUER_CHECK = 'Issuer Check',
135
+ INVESTOR_CHECK = 'Investor Check',
136
+ OFFERING_CHECK = 'Offering Check',
137
+ ASSETS_CHECK = 'Assets Check',
138
+ INDIVIDUALS_CHECK = 'Individuals Check',
139
+ }
140
+
141
+ export enum SaCheck {
142
+ PENDING = BaseStatus.PENDING,
143
+ NEEDS_REVIEW = BaseStatus.NEEDS_REVIEW,
144
+ APPROVED = BaseStatus.APPROVED,
145
+ REJECTED = BaseStatus.REJECTED,
146
+ }
147
+
148
+ // cart NEEDS_INFO PLACED IN_REVIEW AWAITING_FUNDING CANCELLED SETTLED
149
+
150
+ export enum SystemReviewCheck {
151
+ PENDING = BaseStatus.PENDING,
152
+ APPROVED = BaseStatus.APPROVED,
153
+ REJECTED = BaseStatus.REJECTED,
154
+ NEEDS_REVIEW = BaseStatus.NEEDS_REVIEW,
155
+ WARNING = BaseStatus.WARNING,
156
+ INCOMPLETE = BaseStatus.INCOMPLETE,
157
+ }
158
+
159
+ export enum Platforms {
160
+ DALMORE = 'DALMORE',
161
+ IMPORT = 'IMPORT',
162
+ }
163
+
164
+ export enum MatchResultStatus {
165
+ MATCHED = 'MATCHED',
166
+ UNMATCHED = 'UNMATCHED',
167
+ }
168
+
169
+ export enum TradeSystemReviewLogStatus {
170
+ PASSED = 'PASSED',
171
+ WARNING = 'WARNING',
172
+ }
173
+
174
+ export const matchResultSchema = z.object({
175
+ actual: z.string().min(1).max(200),
176
+ status: z.nativeEnum(MatchResultStatus),
177
+ extracted: z.string().min(1).max(200),
178
+ corrected: z.string().min(1).max(200).optional().nullable(),
179
+ });
180
+ export type matchResultSchema = z.infer<typeof matchResultSchema>;
181
+
182
+ const saLogItemSchema = z.object({
183
+ tradeLineItemId: tradeLineItemIdSchema,
184
+ signerName: matchResultSchema.optional(),
185
+ totalAmount: matchResultSchema.optional(),
186
+ investorName: matchResultSchema.optional(),
187
+ numberOfShares: matchResultSchema.optional(),
188
+ });
189
+
190
+ export type saLogItemSchema = z.infer<typeof saLogItemSchema>;
191
+
192
+ export const SaLogSchema = z.object({
193
+ finalStatus: z.nativeEnum(SaStatus),
194
+ matchResults: z.array(saLogItemSchema),
195
+ });
196
+
197
+ export type saLogSchema = z.infer<typeof SaLogSchema>;
198
+
199
+ export const PatchSaLogSchema = z.object({
200
+ matchResults: z.array(saLogItemSchema),
201
+ });
202
+
203
+ export type PatchSaLogSchema = z.infer<typeof PatchSaLogSchema>;
204
+
205
+ export const TradeZod = IBaseEntity.extend({
206
+ investorAccountId: z.lazy(() => investorAccountIdSchema.nullable()),
207
+ accountId: accountIdSchema.nullable(),
208
+ offeringId: z.lazy(() => offeringIdSchema.nullable()),
209
+ paymentMethodId: z.lazy(() => paymentMethodIdSchema).nullable(),
210
+ userId: z.lazy(() => userIdSchema.nullable()),
211
+ tradeNumber: z.string(),
212
+ ip: z.string().nullable(),
213
+ tid: z.string().nullable(),
214
+ investmentType: z.nativeEnum(InvestmentType),
215
+ numberOfShares: z.number().int(),
216
+ pricePerShare: z.number().multipleOf(0.01),
217
+ lineItems: z.array(z.lazy(() => TradeLineItemZod)),
218
+ adjustments: z.array(z.lazy(() => TradeAdjustmentZod)),
219
+ transactions: z.array(z.lazy(() => TransactionZod)),
220
+ totalAmount: z.number().multipleOf(0.01).nullable(),
221
+ tradeStatus: z.nativeEnum(TradeStatus),
222
+ tradeStatusUnmapped: z.string().nullable(),
223
+ tradeDate: z.date().nullable(),
224
+ saStatus: z.nativeEnum(SaStatus),
225
+ saStatusUnmapped: z.string().nullable(),
226
+ saUrl: z.string().nullable(),
227
+ saSignedAt: z.date().nullable(),
228
+ saExtractedNumberOfShares: z.string().nullable(),
229
+ saExtractedTotalAmount: z.string().nullable(),
230
+ saExtractedPricePerShare: z.string().nullable(),
231
+ saExtractedInvestorType: z.string().nullable(),
232
+ saExtractedSigner: z.string().nullable(),
233
+ saExtractedSignatureDate: z.date().nullable(),
234
+ saExtractedSigner2: z.string().nullable(),
235
+ saExtractedSignatureDate2: z.date().nullable(),
236
+ saCheck: z.nativeEnum(SaCheck),
237
+ saCheckedAt: z.date().nullable(),
238
+ saLog: SaLogSchema.nullable(),
239
+ txnTid: z.string().nullable(),
240
+ txnResponse: z.string().nullable(),
241
+ txnPaymentMethod: z.nativeEnum(PaymentMethodType).nullable(),
242
+ txnCurrencyCode: z.string().length(3).nullable(),
243
+ txnChargedAmount: z.number().multipleOf(0.01).nullable(),
244
+ txnDate: z.date().nullable(),
245
+ txnSettledDate: z.date().nullable(),
246
+ fundingStatus: z.nativeEnum(FundingStatus).nullable(),
247
+ fundingStatusUnmapped: z.string().nullable(),
248
+ txnCheck: z.nativeEnum(TxnCheck).nullable(),
249
+ txnCheckedAt: z.date().nullable(),
250
+ txnLog: z.string().nullable(),
251
+ systemReviewCheck: z.nativeEnum(SystemReviewCheck).nullable(),
252
+ systemReviewCheckedAt: z.date().nullable(),
253
+ systemReviewLog: z.string().nullable(),
254
+ complianceReview: z.nativeEnum(ComplianceReview).nullable(),
255
+ complianceReviewNotes: z.string().nullable(),
256
+ complianceReviewerId: z.string().nullable(),
257
+ issuerId: z.lazy(() => issuerIdSchema.nullable()),
258
+ complianceReviewName: z.string().nullable(),
259
+ complianceReviewAt: z.date().nullable(),
260
+ tradeType: z.nativeEnum(TradeType).nullable(),
261
+ placedAt: z.date().nullable(),
262
+ platform: z.string(),
263
+ cancelledAt: z.date().nullable(),
264
+ cancelledById: z.string().nullable(),
265
+ cancelledReason: z.string().nullable(),
266
+ cancellationPeriod: z.number().nullable(),
267
+ disbursed: z.boolean().optional(),
268
+ tradeAdjustments: z.number().nullable().optional(),
269
+ chargedAmount: z.number().nullable().optional(),
270
+ balance: z.number().nullable().optional(),
271
+ isUncleared24h: z.boolean(),
272
+ });
273
+ export type TradeZod = z.infer<typeof TradeZod>;
274
+
275
+ export const IPaginatedTrade = z.object({
276
+ items: z.array(TradeZod),
277
+ meta: IPaginationMeta,
278
+ });
279
+ export type IPaginatedTrade = z.infer<typeof IPaginatedTrade>;
280
+
281
+ export const IPaginatedReviewTrade = z.object({
282
+ totalCount: z.number().int(),
283
+ currentPosition: z.number().int(),
284
+ tradeIds: z.array(tradeIdSchema),
285
+ });
286
+ export type IPaginatedReviewTrade = z.infer<typeof IPaginatedReviewTrade>;
287
+
288
+ export const TradeSummaryZod = z.object({
289
+ accountId: accountIdSchema,
290
+ accountName: z.string(),
291
+ regACount: z.number().int(),
292
+ regCfCount: z.number().int(),
293
+ regDCount: z.number().int(),
294
+ totalCount: z.number().int(),
295
+ totalReadyToApproveCount: z.number().int(),
296
+ regAReadyToApproveCount: z.number().int(),
297
+ regCfReadyToApproveCount: z.number().int(),
298
+ regDReadyToApproveCount: z.number().int(),
299
+ });
300
+ export type TradeSummaryZod = z.infer<typeof TradeSummaryZod>;
301
+
302
+ export const IPaginatedTradeSummaryResponse = z.object({
303
+ items: z.array(TradeSummaryZod),
304
+ meta: IPaginationMeta,
305
+ });
306
+ export type IPaginatedTradeSummaryResponse = z.infer<
307
+ typeof IPaginatedTradeSummaryResponse
308
+ >;
309
+
310
+ export const TradeSummaryFilterZod = z.object({
311
+ reviewStatus: z.nativeEnum(ComplianceReview).optional(),
312
+ managedBy: z.nativeEnum(ManagedByType).optional(),
313
+ });
314
+
315
+ const tradeStatusValues = Object.values(TradeStatus) as string[];
316
+
317
+ export const TradeFiltersZod = z.object({
318
+ investmentType: z.nativeEnum(InvestmentType).optional(),
319
+ tradeStatus: z
320
+ .string()
321
+ .optional()
322
+ .transform((str) => (str ? str.split(',') : []))
323
+ .refine(
324
+ (statuses) =>
325
+ statuses.every((status) => tradeStatusValues.includes(status as any)),
326
+ {
327
+ message: `Invalid trade status option provided. Valid options are: ${tradeStatusValues.join(',')}`,
328
+ },
329
+ )
330
+ .openapi({
331
+ example: `${tradeStatusValues.join(',')}`,
332
+ }),
333
+ from: dateSchema.optional().openapi({ example: 'MM/DD/YYYY' }),
334
+ to: dateSchema.optional().openapi({ example: 'MM/DD/YYYY' }),
335
+ saStatus: z.nativeEnum(SaStatus).optional(),
336
+ saCheck: z.nativeEnum(SaCheck).optional(),
337
+ txnPaymentMethod: z.nativeEnum(PaymentMethodType).optional(),
338
+ fundingStatus: z.nativeEnum(FundingStatus).optional(),
339
+ txnCheck: z.nativeEnum(TxnCheck).optional(),
340
+ systemReviewCheck: z.nativeEnum(SystemReviewCheck).optional(),
341
+ complianceReview: z.nativeEnum(ComplianceReview).optional(),
342
+ beenDisbursed: z.enum(['true', 'false']).optional(),
343
+ search: z.string().max(50).optional(),
344
+ offeringId: z
345
+ .lazy(() => offeringIdSchema)
346
+ .optional()
347
+ .openapi({
348
+ example: 'offering_00041061050r3gg28a1c60t3gf',
349
+ }),
350
+ accountId: accountIdSchema.optional(),
351
+ issuerId: z
352
+ .lazy(() => issuerIdSchema)
353
+ .optional()
354
+ .openapi({
355
+ example: 'issuer_01jfw4q6qef30s6fpqtsxw94ya',
356
+ }),
357
+ offeringType: z.nativeEnum(OfferingType).optional(),
358
+ managedBy: z.nativeEnum(ManagedByType).optional(),
359
+ platform: z.nativeEnum(Platforms).optional(),
360
+ investorAccountId: z.lazy(() => investorAccountIdSchema).optional(),
361
+ });
362
+
363
+ export const ComplianceTradesFiltersZod = z.object({
364
+ kycStatus: z.nativeEnum(KYCStatus).optional(),
365
+ aicStatus: z.nativeEnum(AicStatus).optional(),
366
+ amlStatus: z.nativeEnum(AMLStatus).optional(),
367
+ accountStatus: z.nativeEnum(AccountStatus).optional(),
368
+ savedQuery: z.nativeEnum(SavedQuery).optional(),
369
+ });
370
+
371
+ export type ComplianceTradesFiltersZod = z.infer<
372
+ typeof ComplianceTradesFiltersZod
373
+ >;
374
+
375
+ export const TradeSortZod = z.object({
376
+ sort: z
377
+ .enum([SortBy.PLACEDAT, SortBy.CREATED_AT, SortBy.UPDATED_AT])
378
+ .optional(),
379
+ dir: z.nativeEnum(SortOrder).optional(),
380
+ });
381
+ export type TradeSortZod = z.infer<typeof TradeSortZod>;
382
+
383
+ export const reviewTrades = z.object({
384
+ complianceReview: z.nativeEnum(ComplianceReview),
385
+ force: z.boolean().optional(),
386
+ forceApprovals: z
387
+ .array(z.enum(['kyc', 'aic', 'aml', 'subdoc']))
388
+ .optional()
389
+ .openapi({
390
+ example: ['kyc', 'aml'],
391
+ }), // items we are trying to force approve along with the trade
392
+ trades: z
393
+ .array(tradeIdSchema)
394
+ .min(1, 'At least one trade is required')
395
+ .max(1000, 'Maximum of 1000 trades allowed')
396
+ .openapi({
397
+ example: [
398
+ 'trade_00041061050r3gg28a1c60t3gf',
399
+ 'trade_00041061050r3gg28a1c60t3g',
400
+ ],
401
+ }),
402
+ rejectionReason: z.string().min(1).max(1000).optional().nullable(),
403
+ });
404
+ export type reviewTrades = z.infer<typeof reviewTrades>;
405
+
406
+ export const reviewAllTrades = z.object({
407
+ complianceReview: z.enum([
408
+ ComplianceReview.APPROVED,
409
+ ]) /* only approved is supported for now */,
410
+ });
411
+ export type reviewAllTrades = z.infer<typeof reviewAllTrades>;
412
+
413
+ export const PatchTradeStatus = z.object({
414
+ tradeStatus: z.nativeEnum(TradeStatus),
415
+ });
416
+ export type PatchTradeStatus = z.infer<typeof PatchTradeStatus>;
417
+
418
+ export const tradesInclude = z.enum([
419
+ 'tradeDisbursements',
420
+ 'adjustments',
421
+ 'account',
422
+ 'issuer',
423
+ 'lineItems',
424
+ 'transactions',
425
+ 'investorAccount',
426
+ 'offering',
427
+ 'paymentMethod',
428
+ ]);
429
+
430
+ /**
431
+ * @description Query parameters for including related entities
432
+ * @xample in contract us as -> query: z.object({}).merge(UsersIncludeQuery),
433
+ */
434
+ export const TradesIncludeQuery = z.object({
435
+ include: z
436
+ .string()
437
+ .optional()
438
+ .transform((str) => (str ? str.split(',') : []))
439
+ .refine(
440
+ (includes) =>
441
+ includes.every((include) =>
442
+ tradesInclude.options.includes(include as any),
443
+ ),
444
+ {
445
+ message: `Invalid include option provided. Valid options are: ${tradesInclude.options.join(',')}`,
446
+ },
447
+ )
448
+ .openapi({
449
+ example: `${tradesInclude.options.join(',')}`,
450
+ }),
451
+ });
452
+
453
+ export interface TradesIncludeQuery
454
+ extends z.infer<typeof TradesIncludeQuery> {}
455
+
456
+ export enum TradeExportType {
457
+ PAGE = 'PAGE',
458
+ ALL = 'ALL',
459
+ }
460
+
461
+ export const ExportTradesQuery = PaginationOptionsZod.merge(TradeFiltersZod)
462
+ .merge(ComplianceTradesFiltersZod)
463
+ .merge(TradesIncludeQuery)
464
+ .merge(TradeSortZod)
465
+ .extend({
466
+ exportType: z
467
+ .nativeEnum(TradeExportType)
468
+ .optional()
469
+ .default(TradeExportType.PAGE),
470
+ });
471
+ export type ExportTradesQuery = z.infer<typeof ExportTradesQuery>;
472
+
473
+ const tradesColumn = z.enum([
474
+ 'id',
475
+ 'investorAccountId',
476
+ 'investorAccount',
477
+ 'accountId',
478
+ 'account',
479
+ 'offeringId',
480
+ 'offering',
481
+ 'paymentMethodId',
482
+ 'paymentMethod',
483
+ 'userId',
484
+ 'user',
485
+ 'disbursementId',
486
+ 'disbursement',
487
+ 'tradeNumber',
488
+ 'ip',
489
+ 'tid',
490
+ 'platform',
491
+ 'investmentType',
492
+ 'numberOfShares',
493
+ 'pricePerShare',
494
+ 'lineItems',
495
+ 'transactions',
496
+ 'totalAmount',
497
+ 'tradeStatus',
498
+ 'tradeStatusUnmapped',
499
+ 'tradeDate',
500
+ 'saStatus',
501
+ 'saStatusUnmapped',
502
+ 'saUrl',
503
+ 'saSignedAt',
504
+ 'saExtractedNumberOfShares',
505
+ 'saExtractedTotalAmount',
506
+ 'saExtractedPricePerShare',
507
+ 'saExtractedInvestorType',
508
+ 'saExtractedSigner',
509
+ 'saExtractedSignatureDate',
510
+ 'saExtractedSigner2',
511
+ 'saExtractedSignatureDate2',
512
+ 'saCheck',
513
+ 'saCheckedAt',
514
+ 'saLog',
515
+ 'txnTid',
516
+ 'txnResponse',
517
+ 'txnPaymentMethod',
518
+ 'txnCurrencyCode',
519
+ 'txnChargedAmount',
520
+ 'txnDate',
521
+ 'txnSettledDate',
522
+ 'fundingStatus',
523
+ 'fundingStatusUnmapped',
524
+ 'txnCheck',
525
+ 'txnCheckedAt',
526
+ 'txnLog',
527
+ 'systemReviewCheck',
528
+ 'systemReviewLog',
529
+ 'complianceReview',
530
+ 'complianceReviewNotes',
531
+ 'complianceReviewerId',
532
+ 'managedBy',
533
+ 'complianceReviewer',
534
+ 'issuer',
535
+ 'issuerId',
536
+ 'complianceReviewName',
537
+ 'complianceReviewAt',
538
+ 'tradeType',
539
+ 'placedAt',
540
+ 'cancelledAt',
541
+ 'cancelledById',
542
+ 'cancelledReason',
543
+ 'cancellationPeriod',
544
+ ]);
545
+
546
+ /**
547
+ * @description Query parameters for including related entities
548
+ * @xample in contract us as -> query: z.object({}).merge(UsersIncludeQuery),
549
+ */
550
+ export const TradesColumnQuery = z.object({
551
+ column: z
552
+ .string()
553
+ .optional()
554
+ .transform((str) => (str ? str.split(',') : []))
555
+ .refine(
556
+ (columns) =>
557
+ columns.every((col) => tradesColumn.options.includes(col as any)),
558
+ {
559
+ message: `Invalid column option provided. Valid options are: ${tradesColumn.options.join(',')}`,
560
+ },
561
+ )
562
+ .openapi({
563
+ example: `${tradesColumn.options.join(',')}`,
564
+ }),
565
+ });
566
+
567
+ export const InvestorsTradeFiltersZod = z.object({
568
+ investorAccountId: z.lazy(() => investorAccountIdSchema).optional(),
569
+ tradeStatus: z.nativeEnum(TradeStatus).optional(),
570
+ search: z.string().min(1).max(50).optional(),
571
+ });
572
+
573
+ const investorsTradesInclude = z.enum([
574
+ 'lineItems',
575
+ 'investorAccount',
576
+ 'issuer',
577
+ 'offering',
578
+ ]);
579
+
580
+ /**
581
+ * @description Query parameters for including related entities
582
+ * @xample in contract us as -> query: z.object({}).merge(UsersIncludeQuery),
583
+ */
584
+ export const InvestorsTradesIncludeQuery = z.object({
585
+ include: z
586
+ .string()
587
+ .optional()
588
+ .transform((str) => (str ? str.split(',') : []))
589
+ .refine(
590
+ (includes) =>
591
+ includes.every((include) =>
592
+ investorsTradesInclude.options.includes(include as any),
593
+ ),
594
+ {
595
+ message: `Invalid include option provided. Valid options are: ${investorsTradesInclude.options.join(',')}`,
596
+ },
597
+ )
598
+ .openapi({
599
+ example: `${investorsTradesInclude.options.join(',')}`,
600
+ }),
601
+ });
602
+ export interface InvestorsTradesIncludeQuery
603
+ extends z.infer<typeof InvestorsTradesIncludeQuery> {}
604
+
605
+ export const InvestorsGetTradesQuery = PaginationOptionsZod.merge(
606
+ InvestorsTradeFiltersZod,
607
+ ).merge(InvestorsTradesIncludeQuery);
608
+
609
+ export const UpdateTradeBody = z.object({
610
+ paymentMethodId: z.lazy(() => paymentMethodIdSchema),
611
+ });
612
+
613
+ export type UpdateTradeBodyType = z.infer<typeof UpdateTradeBody>;
614
+
615
+ export const PostTradeBody = z.object({
616
+ investorAccountId: z.lazy(() => investorAccountIdSchema).optional(),
617
+ investmentType: z.nativeEnum(InvestmentType).optional(),
618
+ });
619
+
620
+ export type PostTradeBodyType = z.infer<typeof PostTradeBody>;
621
+
622
+ export const InvestorsTradeResponse = IBaseEntity.extend({
623
+ investorAccountId: z.lazy(() => investorAccountIdSchema).nullable(),
624
+ accountId: z.string(),
625
+ offeringId: z.string().nullable(),
626
+ tid: z.string().nullable(),
627
+ investmentType: z.nativeEnum(InvestmentType),
628
+ numberOfShares: z.number().int(),
629
+ pricePerShare: z.number().multipleOf(0.01),
630
+ totalAmount: z.number().multipleOf(0.01).nullable(),
631
+ tradeStatus: z.nativeEnum(TradeStatus),
632
+ tradeStatusUnmapped: z.string().nullable(),
633
+ tradeDate: z.date().nullable(),
634
+ paymentMethodId: z.lazy(() => paymentMethodIdSchema).nullable(),
635
+ });
636
+
637
+ export const InvestorsPaginatedTrade = z.object({
638
+ items: z.array(InvestorsTradeResponse),
639
+ meta: IPaginationMeta,
640
+ });
641
+ export const IssuersTradeFiltersZod = z.object({
642
+ investmentType: z.nativeEnum(InvestmentType).optional(),
643
+ tradeStatus: z.nativeEnum(TradeStatus).optional(),
644
+ saStatus: z.nativeEnum(SaStatus).optional(),
645
+ saCheck: z.nativeEnum(SaCheck).optional(),
646
+ txnPaymentMethod: z.nativeEnum(PaymentMethodType).optional(),
647
+ fundingStatus: z.nativeEnum(FundingStatus).optional(),
648
+ txnCheck: z.nativeEnum(TxnCheck).optional(),
649
+ systemReviewCheck: z.nativeEnum(SystemReviewCheck).optional(),
650
+ complianceReview: z.nativeEnum(ComplianceReview).optional(),
651
+ beenDisbursed: z.enum(['true', 'false']).optional(),
652
+ search: z.string().optional().openapi({ example: 'Mike' }),
653
+ offeringId: z
654
+ .lazy(() => offeringIdSchema)
655
+ .optional()
656
+ .openapi({
657
+ example: 'offering_00041061050r3gg28a1c60t3gf',
658
+ }),
659
+ from: createDateSchema('START').optional().openapi({ example: 'MM/DD/YYYY' }),
660
+ to: createDateSchema('END').optional().openapi({ example: 'MM/DD/YYYY' }),
661
+ minAmount: z
662
+ .string()
663
+ .transform((num) => Number(num))
664
+ .pipe(z.number().multipleOf(0.01).min(0.01).max(10000000000))
665
+ .optional()
666
+ .openapi({ example: '2500.00' }),
667
+ maxAmount: z
668
+ .string()
669
+ .transform((num) => Number(num))
670
+ .pipe(z.number().multipleOf(0.01).min(0.01).max(10000000000))
671
+ .optional()
672
+ .openapi({ example: '15000000.50' }),
673
+ managedBy: z.nativeEnum(ManagedByType).optional(),
674
+ investorAccountId: z.lazy(() => investorAccountIdSchema).optional(),
675
+ });
676
+ export type IssuersTradeFiltersZod = z.infer<typeof IssuersTradeFiltersZod>;
677
+
678
+ /**
679
+ * Zod schema representing a union of all possible filter types based on portal type.
680
+ * This schema can be used for runtime validation of filter parameters.
681
+ */
682
+ export const GetTradeFiltersSchema = z.union([
683
+ TradeFiltersZod,
684
+ IssuersTradeFiltersZod,
685
+ InvestorsTradeFiltersZod,
686
+ ]);
687
+
688
+ /**
689
+ * Type representing the filters parameter for getTradeWithCalculatedFields.
690
+ * This is a union of all possible filter types based on portal type:
691
+ * - TradeFiltersZod (Compliance portal)
692
+ * - IssuersTradeFiltersZod (Issuer portal)
693
+ * - InvestorsTradeFiltersZod (Investor portal)
694
+ */
695
+ export type GetTradeFiltersType = z.infer<typeof GetTradeFiltersSchema>;
696
+
697
+ export const CancelTradeResponse = z.object({
698
+ message: z.string(),
699
+ });
700
+ export type CancelTradeResponse = z.infer<typeof CancelTradeResponse>;
701
+
702
+ export const FailedTradeZod = z.object({
703
+ id: tradeIdSchema,
704
+ tradeNo: z.string(),
705
+ errors: z.string().array(),
706
+ });
707
+
708
+ export type FailedTradeZod = z.infer<typeof FailedTradeZod>;
709
+
710
+ export const ReviewTradeZod = z.object({
711
+ success: z.boolean(),
712
+ message: z.string(),
713
+ failedTrades: z.array(FailedTradeZod),
714
+ });
715
+
716
+ export type ReviewTradeZod = z.infer<typeof ReviewTradeZod>;
717
+
718
+ export const CancelTradeZod = z.object({
719
+ reason: z
720
+ .string()
721
+ .min(2)
722
+ .max(1000)
723
+ .openapi({ example: 'cancellation reason' }),
724
+ });
725
+
726
+ export type CancelTradeZod = z.infer<typeof CancelTradeZod>;
727
+
728
+ export const ComplianceCancelTradeZod = z.object({
729
+ reason: z
730
+ .string()
731
+ .min(2)
732
+ .max(1000)
733
+ .openapi({ example: 'cancellation reason' }),
734
+ accountId: accountIdSchema.openapi({
735
+ example: 'account_00041061050r3gg28a1c60t3gf',
736
+ }),
737
+ });
738
+ export type ComplianceCancelTradeZod = z.infer<typeof ComplianceCancelTradeZod>;
739
+
740
+ export const ProcessPaymentZod = z.object({
741
+ tradeId: tradeIdSchema,
742
+ amount: z.number().min(0.01).max(10000000000),
743
+ });
744
+
745
+ export type ProcessPaymentZod = z.infer<typeof ProcessPaymentZod>;
746
+
747
+ export const ProcessPaymentResponse = z.object({
748
+ success: z.boolean(),
749
+ });
750
+
751
+ export type ProcessPaymentResponse = z.infer<typeof ProcessPaymentResponse>;
752
+
753
+ const TradeLineItemDataZod = z.object({
754
+ signaturePlatform: z.string(),
755
+ signatureDocumentId: z.string(),
756
+ signatureUrl: z.string(),
757
+ signatureStatus: z.nativeEnum(SignatureStatus),
758
+ });
759
+
760
+ export type TradeLineItemDataZod = z.infer<typeof TradeLineItemDataZod>;
761
+
762
+ export const TradeSystemReviewLogZod = z.object({
763
+ type: z.nativeEnum(TradeSystemLogType),
764
+ data: z.record(z.string(), z.any()),
765
+ error: z.string().nullable(),
766
+ message: z.string().nullable(),
767
+ status: z.nativeEnum(TradeSystemReviewLogStatus),
768
+ });
769
+ export type TradeSystemReviewLogZod = z.infer<typeof TradeSystemReviewLogZod>;
770
+
771
+ export enum BoldsignTemplateType {
772
+ INDIVIDUAL = 'INDIVIDUAL',
773
+ JOINT = 'JOINT',
774
+ ENTITY = 'ENTITY',
775
+ }
776
+
777
+ export const GetTemplateVariablesForTradeZod = z.object({
778
+ templateType: z.nativeEnum(BoldsignTemplateType),
779
+ templateId: z.string(),
780
+ mergeVars: z.array(
781
+ z.object({
782
+ field: z.string(),
783
+ value: z.string(),
784
+ }),
785
+ ),
786
+ });
787
+
788
+ export type GetTemplateVariablesForTradeZod = z.infer<
789
+ typeof GetTemplateVariablesForTradeZod
790
+ >;
791
+
792
+ /**
793
+ * Zod schema for CSV export data with all formatted fields ready for export
794
+ * All extraction and formatting logic is handled in trades.service.ts
795
+ */
796
+ export const TradeForCsvExportZod = z.object({
797
+ tradeNumber: z.string(),
798
+ investorName: z.string(),
799
+ signerName: z.string(),
800
+ offeringName: z.string(),
801
+ tradeType: z.string(),
802
+ numberOfShares: z.number(),
803
+ pricePerShare: z.string(), // Formatted with $ prefix
804
+ totalAmount: z.string(), // Formatted with $ prefix
805
+ tradeStatus: z.string(),
806
+ fundingStatus: z.string(),
807
+ kycStatus: z.boolean(),
808
+ amlStatus: z.boolean(),
809
+ aicStatus: z.boolean(),
810
+ saStatus: z.string(),
811
+ placedAt: z.string(), // Formatted date string
812
+ closedAt: z.string(), // Formatted date string
813
+ txnPaymentMethod: z.string(),
814
+ txnChargedAmount: z.string(), // Formatted with $ prefix
815
+ registeredRepId: z.string(),
816
+ managedBy: z.string(),
817
+ platform: z.string(),
818
+ // Entity fields (for LEGAL_ENTITY type)
819
+ entityName: z.string(),
820
+ entityEin: z.string(),
821
+ entityAddress: z.string(),
822
+ entityAddress2: z.string(),
823
+ entityCity: z.string(),
824
+ entityCountry: z.string(),
825
+ entityState: z.string(),
826
+ entityZip: z.string(),
827
+ entityEmail: z.string(),
828
+ entityPhone: z.string(),
829
+ entityCompanyType: z.string(),
830
+ // Primary individual fields
831
+ primaryFirstName: z.string(),
832
+ primaryLastName: z.string(),
833
+ primaryDob: z.string(), // Formatted date string
834
+ primarySsn: z.string(), // Formatted SSN
835
+ primaryAddress: z.string(),
836
+ primaryAddress2: z.string(),
837
+ primaryCity: z.string(),
838
+ primaryCountry: z.string(),
839
+ primaryState: z.string(),
840
+ primaryZip: z.string(),
841
+ primaryEmail: z.string(),
842
+ primaryPhone: z.string(),
843
+ // Secondary individual fields (for JOINT and LEGAL_ENTITY types)
844
+ secondaryFirstName: z.string(),
845
+ secondaryLastName: z.string(),
846
+ secondaryDob: z.string(), // Formatted date string
847
+ secondarySsn: z.string(), // Formatted SSN
848
+ secondaryAddress: z.string(),
849
+ secondaryAddress2: z.string(),
850
+ secondaryCity: z.string(),
851
+ secondaryCountry: z.string(),
852
+ secondaryState: z.string(),
853
+ secondaryZip: z.string(),
854
+ secondaryEmail: z.string(),
855
+ secondaryPhone: z.string(),
856
+ });
857
+
858
+ export type TradeForCsvExport = z.infer<typeof TradeForCsvExportZod>;
859
+
860
+ export const CANCELLABLE_TRADE_STATUSES = [
861
+ TradeStatus.PLACED,
862
+ TradeStatus.IN_REVIEW,
863
+ TradeStatus.NEEDS_INFO,
864
+ TradeStatus.FUNDING,
865
+ ];
866
+
867
+ export const NON_CANCELABLE_COMPLIANCE_REVIEW_STATUSES = [
868
+ ComplianceReview.APPROVED,
869
+ ComplianceReview.REJECTED,
870
+ ComplianceReview.CANCELLED,
871
+ ];
872
+
873
+ /**
874
+ * Filter type for Investor Account exports in workers
875
+ * Extends the base InvestorAccountExportFilters with additional optional fields needed for bulk exports
876
+ */
877
+ export type WorkerInvestorAccountExportFilters = Partial<
878
+ (InvestorAccountExportFilters | ComplianceInvestorAccountExportFilters) & {
879
+ isRegisteredUsersExport: boolean | null;
880
+ search: string | null;
881
+ startDate: Date | null;
882
+ endDate: Date | null;
883
+ userType: string | null;
884
+ accountId: string | null;
885
+ }
886
+ >;
887
+ /**
888
+ * Filter type for Trade exports
889
+ * Extends IssuersTradeFiltersZod with accountId
890
+ */
891
+ export type TradeExportFilters = Partial<
892
+ IssuersTradeFiltersZod & {
893
+ accountId: string | null;
894
+ }
895
+ >;
896
+
897
+ /**
898
+ * Filter type for Compliance Trade exports
899
+ */
900
+ export type ComplianceTradeExportFilters = Partial<ExportTradesQuery>;
901
+
902
+ /**
903
+ * Filter type for Secondary Customer exports
904
+ */
905
+ export type SecondaryCustomerExportFilters =
906
+ Partial<GetSecondaryCustomerFiltersZod>;
907
+
908
+ /**
909
+ * Filter type for Secondary Trade exports
910
+ */
911
+ export type SecondaryTradeExportFilters = Partial<SecondaryTradeFiltersZod>;
912
+
913
+ /**
914
+ * Combined filter type for all bulk export types
915
+ * Used in the ExportBulkDataDto
916
+ */
917
+ export type BulkExportFilters =
918
+ | WorkerInvestorAccountExportFilters
919
+ | TradeExportFilters
920
+ | ComplianceTradeExportFilters
921
+ | SecondaryCustomerExportFilters
922
+ | SecondaryTradeExportFilters;
923
+
924
+ export type BulkExportResponse =
925
+ | InvestorAccount[]
926
+ | RegisteredInvestorUserRawZod[]
927
+ | Trade[]
928
+ | SecondaryCustomer[]
929
+ | SecondaryTrade[];