@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,296 @@
1
+ import { extendZodWithOpenApi } from '@anatine/zod-openapi';
2
+ import { TypeID } from 'typeid-js';
3
+ import { z } from 'zod';
4
+ import {
5
+ AccountZod,
6
+ dateSchema,
7
+ IPaginationMeta,
8
+ IssuerOnboardingSetupType,
9
+ ManagedByType,
10
+ Platform,
11
+ SortBy,
12
+ SortOrder,
13
+ AccountStatus,
14
+ } from './common.types';
15
+ import { notionPageIdSchema } from './notion-page.types';
16
+
17
+ extendZodWithOpenApi(z);
18
+
19
+ export const accountIdSchema = z.string().refine(
20
+ (value) => {
21
+ try {
22
+ const tid = TypeID.fromString(value);
23
+ return tid.getType() === 'account';
24
+ } catch {
25
+ return false;
26
+ }
27
+ },
28
+ {
29
+ message:
30
+ 'Invalid account ID format. Must be a valid TypeID with "account" prefix.',
31
+ },
32
+ );
33
+
34
+ export const UpdateAccountZod = z.object({
35
+ name: z.string().min(1).max(100),
36
+ status: z.nativeEnum(AccountStatus).optional(),
37
+ platform: z
38
+ .nativeEnum(Platform)
39
+ .optional()
40
+ .openapi({ example: Platform.INTEGRATION }),
41
+ managedBy: z
42
+ .nativeEnum(ManagedByType)
43
+ .optional()
44
+ .openapi({ example: ManagedByType.DALMORE }),
45
+ approversCount: z.number().min(1).max(5).optional(),
46
+ });
47
+ export type UpdateAccountZod = z.infer<typeof UpdateAccountZod>;
48
+
49
+ export const CreateAccountZod = z.object({
50
+ name: z.string().min(1).max(100).openapi({ example: 'Name' }),
51
+ platform: z
52
+ .nativeEnum(Platform)
53
+ .optional()
54
+ .openapi({ example: Platform.INTEGRATION }),
55
+ managedBy: z
56
+ .nativeEnum(ManagedByType)
57
+ .optional()
58
+ .openapi({ example: ManagedByType.DALMORE }),
59
+ approversCount: z.number().min(1).max(5).optional().openapi({ example: 2 }),
60
+ hubspotCompany: z
61
+ .string()
62
+ .url()
63
+ .max(2048)
64
+ .nullable()
65
+ .optional()
66
+ .openapi({ example: 'https://www.google.com' }),
67
+ });
68
+ export type CreateAccountZod = z.infer<typeof CreateAccountZod>;
69
+
70
+ export const IPaginatedAccount = z.object({
71
+ items: z.array(AccountZod),
72
+ meta: IPaginationMeta,
73
+ });
74
+ export type IPaginatedAccount = z.infer<typeof IPaginatedAccount>;
75
+
76
+ export const AccountFiltersZod = z.object({
77
+ search: z.string().max(50).optional(),
78
+ status: z.nativeEnum(AccountStatus).optional(),
79
+ platform: z
80
+ .nativeEnum(Platform)
81
+ .optional()
82
+ .openapi({ example: Platform.INTEGRATION }),
83
+ managedBy: z
84
+ .nativeEnum(ManagedByType)
85
+ .optional()
86
+ .openapi({ example: ManagedByType.DALMORE }),
87
+ from: dateSchema.optional().openapi({ example: 'MM/DD/YYYY' }),
88
+ to: dateSchema.optional().openapi({ example: 'MM/DD/YYYY' }),
89
+ });
90
+
91
+ const accountsInclude = z.enum([
92
+ 'accountManager',
93
+ 'accountIntegrations',
94
+ 'apiKeys',
95
+ 'assets',
96
+ 'dataRooms',
97
+ 'individuals',
98
+ 'investorAccounts',
99
+ 'invites',
100
+ 'issuers',
101
+ 'legalEntities',
102
+ 'offerings',
103
+ 'sites',
104
+ 'trades',
105
+ 'users',
106
+ ]);
107
+
108
+ /**
109
+ * @description Query parameters for including related entities
110
+ * @xample in contract us as -> query: z.object({}).merge(AccountsIncludeQuery),
111
+ */
112
+ export const AccountsIncludeQuery = z.object({
113
+ include: z
114
+ .string()
115
+ .optional()
116
+ .transform((str) => (str ? str.split(',') : []))
117
+ .refine(
118
+ (includes) =>
119
+ includes.every((include) =>
120
+ accountsInclude.options.includes(include as any),
121
+ ),
122
+ {
123
+ message: `Invalid include option provided. Valid options are: ${accountsInclude.options.join(',')}`,
124
+ },
125
+ )
126
+ .openapi({
127
+ example: `${accountsInclude.options.join(',')}`,
128
+ }),
129
+ });
130
+ export interface AccountsIncludeQuery
131
+ extends z.infer<typeof AccountsIncludeQuery> {}
132
+
133
+ export const PatchAccountZod = z.object({
134
+ name: z.string().min(1).max(100),
135
+ approversCount: z.number().min(1).max(5).optional(),
136
+ managedBy: z.nativeEnum(ManagedByType).optional(),
137
+ platform: z.nativeEnum(Platform).optional(),
138
+ integrationGuideId: notionPageIdSchema.nullable().optional(),
139
+ productPrimaries: z.boolean().optional(),
140
+ productSecondaries: z.boolean().optional(),
141
+ featureDisbursements: z.boolean().optional(),
142
+ });
143
+ export type PatchAccountZod = z.infer<typeof PatchAccountZod>;
144
+
145
+ export const CompliancePatchAccountZod = PatchAccountZod.extend({
146
+ hubspotCompany: z
147
+ .string()
148
+ .url()
149
+ .max(2048)
150
+ .nullable()
151
+ .optional()
152
+ .openapi({ example: 'https://www.google.com' }),
153
+ });
154
+ export type CompliancePatchAccountZod = z.infer<
155
+ typeof CompliancePatchAccountZod
156
+ >;
157
+
158
+ export const PostAccountResponse = z.object({
159
+ id: z.string(),
160
+ });
161
+ export type PostAccountResponse = z.infer<typeof PostAccountResponse>;
162
+
163
+ export const GetAccountIssuersZod = z.object({
164
+ name: z.string().optional(),
165
+ accountId: accountIdSchema.optional(),
166
+ });
167
+ export type GetAccountIssuersZod = z.infer<typeof GetAccountIssuersZod>;
168
+
169
+ export const UpdateAccountIssuersStatusZod = z.object({
170
+ status: z.nativeEnum(AccountStatus),
171
+ });
172
+ export type UpdateAccountIssuersStatusZod = z.infer<
173
+ typeof UpdateAccountIssuersStatusZod
174
+ >;
175
+
176
+ export const UpdateAccountStatusReponse = z.object({
177
+ id: accountIdSchema,
178
+ status: z.nativeEnum(AccountStatus),
179
+ });
180
+ export type UpdateAccountStatusReponse = z.infer<
181
+ typeof UpdateAccountStatusReponse
182
+ >;
183
+
184
+ export const AccountsSummaryFilterZod = z.object({
185
+ search: z.string().trim().max(50).optional(),
186
+ status: z.nativeEnum(AccountStatus).optional(),
187
+ from: dateSchema.optional().openapi({ example: 'MM/DD/YYYY' }),
188
+ to: dateSchema.optional().openapi({ example: 'MM/DD/YYYY' }),
189
+ accountManagerIds: z
190
+ .string()
191
+ .optional()
192
+ .transform((val) => {
193
+ if (!val || typeof val !== 'string') return undefined;
194
+
195
+ const ids = val
196
+ .split(',')
197
+ .map((id: string) => id.trim())
198
+ .filter((id: string) => id.length > 0);
199
+
200
+ // Remove duplicates using Set
201
+ const uniqueIds = [...new Set(ids)];
202
+
203
+ return uniqueIds.length > 0 ? uniqueIds : undefined;
204
+ })
205
+ .pipe(
206
+ z
207
+ .array(
208
+ z.string().refine(
209
+ (value) => {
210
+ try {
211
+ const tid = TypeID.fromString(value);
212
+ return tid.getType() === 'account_manager';
213
+ } catch {
214
+ return false;
215
+ }
216
+ },
217
+ {
218
+ message: `Invalid account manager ID format. Must be a valid TypeID with "account_manager" prefix. Example: account_manager_01j5y5ghx5fg68d663j1fvy2x7`,
219
+ },
220
+ ),
221
+ )
222
+ .optional(),
223
+ ),
224
+ });
225
+ export type AccountsSummaryFilterZod = z.infer<typeof AccountsSummaryFilterZod>;
226
+
227
+ export const AccountSortZod = z.object({
228
+ sort: z.enum([SortBy.NAME, SortBy.CREATED_AT, SortBy.UPDATED_AT]).optional(),
229
+ dir: z.nativeEnum(SortOrder).optional(),
230
+ });
231
+ export type AccountSortZod = z.infer<typeof AccountSortZod>;
232
+
233
+ export const AccountsSummaryZod = z.object({
234
+ accountId: accountIdSchema,
235
+ accountName: z.string(),
236
+ issuers: z.number().int(),
237
+ offerings: z.number().int(),
238
+ assets: z.number().int(),
239
+ users: z.number().int(),
240
+ trades: z.number().int(),
241
+ accountManagerName: z.string(),
242
+ createdOn: z.string(),
243
+ status: z.string(),
244
+ });
245
+ export type AccountsSummaryZod = z.infer<typeof AccountsSummaryZod>;
246
+
247
+ export const IPaginatedAccountsSummaryResponse = z.object({
248
+ items: z.array(AccountsSummaryZod),
249
+ meta: IPaginationMeta,
250
+ });
251
+ export type IPaginatedAccountsSummaryResponse = z.infer<
252
+ typeof IPaginatedAccountsSummaryResponse
253
+ >;
254
+ export const PatchIssuerOnboardingStep = z.object({
255
+ step: z.nativeEnum(IssuerOnboardingSetupType),
256
+ });
257
+ export type PatchIssuerOnboardingStep = z.infer<
258
+ typeof PatchIssuerOnboardingStep
259
+ >;
260
+
261
+ export const IssuerOnboardingStepZod = z.object({
262
+ offeringSetup: z.boolean().default(false),
263
+ investorPortalSetup: z.boolean().default(false),
264
+ paymentMethodSetup: z.boolean().default(false),
265
+ accountContactsSetup: z.boolean().default(false),
266
+ });
267
+ export type IssuerOnboardingStepZod = z.infer<typeof IssuerOnboardingStepZod>;
268
+
269
+ export const OnboardingAccountSummaryZod = z.object({
270
+ accountId: accountIdSchema,
271
+ accountName: z.string(),
272
+ siteId: z.string().nullable(),
273
+ offeringId: z.string().nullable(),
274
+ investorPortalSetup: z.boolean(),
275
+ offeringSetup: z.boolean(),
276
+ paymentMethodSetup: z.boolean(),
277
+ accountContactsSetup: z.boolean(),
278
+ });
279
+ export type OnboardingAccountSummaryZod = z.infer<
280
+ typeof OnboardingAccountSummaryZod
281
+ >;
282
+
283
+ export const IPaginatedOnboardingAccountSummaryResponse = z.object({
284
+ items: z.array(OnboardingAccountSummaryZod),
285
+ meta: IPaginationMeta,
286
+ });
287
+ export type IPaginatedOnboardingAccountSummaryResponse = z.infer<
288
+ typeof IPaginatedOnboardingAccountSummaryResponse
289
+ >;
290
+
291
+ export const OnboardingAccountSummaryFilterZod = z.object({
292
+ status: z.nativeEnum(AccountStatus).optional(),
293
+ });
294
+ export type OnboardingAccountSummaryFilterZod = z.infer<
295
+ typeof OnboardingAccountSummaryFilterZod
296
+ >;
@@ -0,0 +1,274 @@
1
+ import { z } from 'zod';
2
+ import {
3
+ BaseAction,
4
+ BaseStatus,
5
+ IPaginationMeta,
6
+ PortalType,
7
+ TargetTableConfig,
8
+ TargetTableEnum,
9
+ } from './common.types';
10
+ import { TypeID } from 'typeid-js';
11
+ import { IBaseEntity } from './entity.types';
12
+
13
+ /**
14
+ * WARNING!!!
15
+ * ANY CHANGES TO:
16
+ * - ActivityTypeCategory
17
+ * - ActivityTypeResource
18
+ * - ActivityTypeAction
19
+ * Will require a migration to add the new combinations to the database. See activity-type.entity.ts
20
+ * Also, previous migrations will have to be updated to prevent the new combination from being seeded before the new migration introduces it.
21
+ * see: SeedActivityActionTable1733789494520
22
+ * This is required only for backwards compatibility when developing locally and e2e tests.
23
+ */
24
+ export enum ActivityTypeCategory {
25
+ CLIENT = PortalType.CLIENT,
26
+ INVESTOR = PortalType.INVESTOR,
27
+ COMPLIANCE = PortalType.COMPLIANCE,
28
+ ISSUER = PortalType.ISSUER,
29
+ }
30
+
31
+ export const CategoryMap: { [key: string]: ActivityTypeCategory } = {
32
+ compliance: ActivityTypeCategory.COMPLIANCE,
33
+ issuers: ActivityTypeCategory.ISSUER,
34
+ clients: ActivityTypeCategory.CLIENT,
35
+ investors: ActivityTypeCategory.INVESTOR,
36
+ };
37
+
38
+ export enum ActivityTypeResource {
39
+ KYCS = 'KYCS',
40
+ KYBS = 'KYBS',
41
+ INDIVIDUALS = 'INDIVIDUALS',
42
+ LEGAL_ENTITIES = 'LEGAL_ENTITIES',
43
+ INVESTOR_ACCOUNTS = 'INVESTOR_ACCOUNTS',
44
+ TRADES = 'TRADES',
45
+ OFFERINGS = 'OFFERINGS',
46
+ ISSUERS = 'ISSUERS',
47
+ COVERED_PERSONS = 'COVERED_PERSONS',
48
+ PAYMENT_METHODS = 'PAYMENT_METHODS',
49
+ NOTES = 'NOTES',
50
+ USERS = 'USERS',
51
+ ACCOUNTS = 'ACCOUNTS',
52
+ FILES = 'FILES',
53
+ PAGES = 'PAGES',
54
+ AMLS = 'AMLS',
55
+ DISBURSEMENTS = 'DISBURSEMENTS',
56
+ DISBURSEMENT_REVIEWS = 'DISBURSEMENT_REVIEWS',
57
+ TRADE_LINE_ITEMS = 'TRADE_LINE_ITEMS',
58
+ TRANSACTIONS = 'TRANSACTIONS',
59
+ AICS = 'AICS',
60
+ SITES = 'SITES',
61
+ THEMES = 'THEMES',
62
+ THEME_SETTINGS = 'THEME_SETTINGS',
63
+ }
64
+
65
+ export const ResourceMap: { [key: string]: ActivityTypeResource } = {
66
+ trades: ActivityTypeResource.TRADES,
67
+ 'trade-line-items': ActivityTypeResource.TRADE_LINE_ITEMS,
68
+ transactions: ActivityTypeResource.TRANSACTIONS,
69
+ users: ActivityTypeResource.USERS,
70
+ offerings: ActivityTypeResource.OFFERINGS,
71
+ 'investor-accounts': ActivityTypeResource.INVESTOR_ACCOUNTS,
72
+ individuals: ActivityTypeResource.INDIVIDUALS,
73
+ 'payment-methods': ActivityTypeResource.PAYMENT_METHODS,
74
+ notes: ActivityTypeResource.NOTES,
75
+ issuers: ActivityTypeResource.ISSUERS,
76
+ 'covered-persons': ActivityTypeResource.COVERED_PERSONS,
77
+ kyc: ActivityTypeResource.KYCS,
78
+ aml: ActivityTypeResource.AMLS,
79
+ aic: ActivityTypeResource.AICS,
80
+ kyb: ActivityTypeResource.KYBS,
81
+ 'legal-entities': ActivityTypeResource.LEGAL_ENTITIES,
82
+ accounts: ActivityTypeResource.ACCOUNTS,
83
+ files: ActivityTypeResource.FILES,
84
+ 'files-public': ActivityTypeResource.FILES,
85
+ pages: ActivityTypeResource.PAGES,
86
+ disbursements: ActivityTypeResource.DISBURSEMENTS,
87
+ 'disbursement-reviews': ActivityTypeResource.DISBURSEMENT_REVIEWS,
88
+ sites: ActivityTypeResource.SITES,
89
+ themes: ActivityTypeResource.THEMES,
90
+ 'theme-settings': ActivityTypeResource.THEME_SETTINGS,
91
+ };
92
+
93
+ /**
94
+ * WARNING!!!
95
+ * ANY CHANGES TO:
96
+ * - ActivityTypeAction
97
+ * Will require a migration to add the new combinations to the database. See activity-type.entity.ts
98
+ * Also, previous migrations will have to be updated to prevent the new combination from being seeded before the new migration introduces it.
99
+ * see:
100
+ * SeedActivityActionTable1733789494520
101
+ * SeedActivityResourceTableFiles1735884938590
102
+ * SeedAmlPagesInActivityTypes1740995815856
103
+ * SeedActivityResourceTypeDisbursement1742689286845
104
+ * SeedActivityResourceTradeLineItem1746449328700
105
+ * SeedActivityReset2faAction1746791323564
106
+ * SeedActivityResourceUserCombinations1747289941817
107
+ * AddedResubmitActivityType1747999619404
108
+ * AddedDeclinedAndSignedActivityAction1748011929459
109
+ * SeedActivityResourceTypeDisbursementReview1753945998383
110
+ * SeedActivityResourceTypeTransaction1754457409040
111
+ * AddedAicTargetTable1756265520122
112
+ * AddedReporcessActivityTypeAction1758023244400
113
+ * AddedActivityActionSave1761715000038
114
+ * AddedAcceptedActivityAction1762848949484
115
+ */
116
+ export enum ActivityTypeAction {
117
+ CREATE = BaseAction.CREATE,
118
+ UPDATE = BaseAction.UPDATE,
119
+ DELETE = BaseAction.DELETE,
120
+ IMPORT = BaseAction.IMPORT,
121
+ APPROVED = BaseStatus.APPROVED,
122
+ REJECTED = BaseStatus.REJECTED,
123
+ SUBMITTED = BaseStatus.SUBMITTED,
124
+ DECLINED = BaseStatus.DECLINED,
125
+ SIGNED = BaseStatus.SIGNED,
126
+ COMPLETED = BaseStatus.COMPLETED,
127
+ RE_SIGN = BaseStatus.RE_SIGN,
128
+ RESUBMIT = BaseStatus.RESUBMIT,
129
+ RESET_2FA = BaseStatus.RESET_2FA,
130
+ LOGIN = BaseStatus.LOGIN,
131
+ RESET_PASSWORD = BaseStatus.RESET_PASSWORD,
132
+ TWO_FACTOR_LOGIN = BaseStatus.TWO_FACTOR_LOGIN,
133
+ FORGOT_PASSWORD = BaseStatus.FORGOT_PASSWORD,
134
+ RE_PROCESS = BaseStatus.RE_PROCESS,
135
+ SAVE = BaseStatus.SAVE,
136
+ ACCEPTED = BaseStatus.ACCEPTED,
137
+ JOIN = BaseStatus.JOIN,
138
+ RESTORE = BaseStatus.RESTORE,
139
+ }
140
+
141
+ export const MethodMap: { [key: string]: ActivityTypeAction } = {
142
+ POST: ActivityTypeAction.CREATE,
143
+ PUT: ActivityTypeAction.UPDATE,
144
+ PATCH: ActivityTypeAction.UPDATE,
145
+ DELETE: ActivityTypeAction.DELETE,
146
+ };
147
+
148
+ export const activityIdSchema = z.string().refine(
149
+ (value) => {
150
+ try {
151
+ const tid = TypeID.fromString(value);
152
+ return tid.getType() === 'activity';
153
+ } catch {
154
+ return false;
155
+ }
156
+ },
157
+ {
158
+ message:
159
+ 'Invalid activity ID format. Must be a valid TypeID with "activity" prefix. Example: activity_01j5y5ghx8fvc83dmx3pznq7hv',
160
+ },
161
+ );
162
+
163
+ export const UserLoginForActivityZod = z.object({
164
+ id: z.string().openapi({
165
+ example: 'user_login_01jepymte1feb8a4j46gy6850k',
166
+ }),
167
+ firstName: z.string().openapi({
168
+ example: 'Daniel',
169
+ }),
170
+ lastName: z.string().openapi({
171
+ example: 'Ice',
172
+ }),
173
+ email: z.string().email().openapi({
174
+ example: 'dice@dalmoregroup.com',
175
+ }),
176
+ __entity: z.string().optional(),
177
+ });
178
+
179
+ const UserForActivityZod = z.object({
180
+ id: z.string(),
181
+ roleId: z.string().nullable(),
182
+ accountId: z.string().nullable(),
183
+ userLogin: UserLoginForActivityZod,
184
+ __entity: z.string().optional(),
185
+ });
186
+
187
+ const ActivityTypeZod = IBaseEntity.extend({
188
+ category: z.nativeEnum(ActivityTypeCategory),
189
+ resource: z.enum(TargetTableEnum),
190
+ action: z.nativeEnum(ActivityTypeAction),
191
+ __entity: z.string().optional(),
192
+ });
193
+
194
+ export const ActivityZod = IBaseEntity.extend({
195
+ id: activityIdSchema,
196
+ message: z.string(),
197
+ targetTable: z.enum(TargetTableEnum),
198
+ targetId: z.string(),
199
+ userId: z.string().nullable(),
200
+ activityTypeId: z.string(),
201
+ accountId: z.string().nullable(),
202
+ user: UserForActivityZod,
203
+ activityType: ActivityTypeZod,
204
+ targetObject: z.string().nullable().optional(),
205
+ __entity: z.string().optional(),
206
+ });
207
+ export type ActivityZod = z.infer<typeof ActivityZod>;
208
+
209
+ export const IPaginatedActivity = z.object({
210
+ items: z.array(ActivityZod),
211
+ meta: IPaginationMeta,
212
+ });
213
+ export type IPaginatedActivity = z.infer<typeof IPaginatedActivity>;
214
+
215
+ export const ActivitiesFilters = z.object({
216
+ targetTable: z.enum(TargetTableEnum).optional(),
217
+ targetId: z
218
+ .string()
219
+ .optional()
220
+ .openapi({
221
+ example: 'disbursement_01j6aqmtfyfwy9spjdcnh7yqk7',
222
+ })
223
+ .refine(
224
+ (value) => {
225
+ try {
226
+ if (!value) return true;
227
+ const tid = TypeID.fromString(value);
228
+ return Object.values(TargetTableConfig).some(
229
+ (config) => config.idPrefix === tid.getType(),
230
+ );
231
+ } catch {
232
+ return false;
233
+ }
234
+ },
235
+ {
236
+ message: `Invalid target ID format. Must match the corresponding table's ID prefix. Valid prefix: ${TargetTableEnum.toString().toLowerCase()}. Example: disbursement_01j6aqmtfyfwy9spjdcnh7yqk7`,
237
+ },
238
+ ),
239
+ search: z.string().max(50).optional(),
240
+ targetIds: z
241
+ .string()
242
+ .optional()
243
+ .openapi({
244
+ example:
245
+ 'disbursement_01j6aqmtfyfwy9spjdcnh7yqk7,disbursement_01j6aqmtfyfwy9spjdcnh7yqk8',
246
+ })
247
+ .transform((str) => {
248
+ if (!str) return [];
249
+ // Split by comma, trim whitespace, and remove duplicates using Set
250
+ const ids = str.split(',').map((id) => id.trim());
251
+ return Array.from(new Set(ids));
252
+ })
253
+ .refine(
254
+ (value) => {
255
+ if (!value || value.length === 0) return true;
256
+
257
+ // Validate each ID
258
+ return value.every((id) => {
259
+ try {
260
+ const tid = TypeID.fromString(id);
261
+ return Object.values(TargetTableConfig).some(
262
+ (config) => config.idPrefix === tid.getType(),
263
+ );
264
+ } catch {
265
+ return false;
266
+ }
267
+ });
268
+ },
269
+ {
270
+ message: `Invalid target IDs. All IDs must match the corresponding table's ID prefix. Valid prefix: ${TargetTableEnum.toString().toLowerCase()}. Example: disbursement_01j6aqmtfyfwy9spjdcnh7yqk7`,
271
+ },
272
+ ),
273
+ });
274
+ export type ActivitiesFilters = z.infer<typeof ActivitiesFilters>;