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