@dalmore/api-contracts 0.0.0-dev.d8ef117 → 0.0.0-dev.dc7fdf8

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 (196) hide show
  1. package/README.md +23 -19
  2. package/common/types/account-contact.types.ts +2 -1
  3. package/common/types/account-manager.types.ts +3 -7
  4. package/common/types/account-setting.types.ts +65 -0
  5. package/common/types/account.types.ts +1 -0
  6. package/common/types/auth.types.ts +7 -18
  7. package/common/types/bonus-tier.types.ts +9 -0
  8. package/common/types/common.types.ts +38 -6
  9. package/common/types/comply-advantage-api.types.ts +3 -3
  10. package/common/types/contact-us.types.ts +6 -2
  11. package/common/types/covered-person.types.ts +2 -1
  12. package/common/types/dashboard.types.ts +2 -9
  13. package/common/types/escrow-account.types.ts +3 -3
  14. package/common/types/individuals.types.ts +3 -2
  15. package/common/types/investor-account.types.ts +2 -1
  16. package/common/types/invite.types.ts +27 -1
  17. package/common/types/issuer-offering.types.ts +11 -17
  18. package/common/types/legal-entity.types.ts +3 -2
  19. package/common/types/mail-template.types.ts +34 -0
  20. package/common/types/note.types.ts +1 -1
  21. package/common/types/notification.types.ts +525 -29
  22. package/common/types/offering.types.ts +2 -9
  23. package/common/types/site-settings.types.ts +2 -1
  24. package/common/types/site.types.ts +2 -9
  25. package/common/types/{trade-line-item.type.ts → trade-line-item.types.ts} +2 -9
  26. package/common/types/trade.types.ts +50 -2
  27. package/common/types/trusted-contact.types.ts +7 -7
  28. package/common/types/user.types.ts +11 -32
  29. package/common/types/webhook.types.ts +142 -0
  30. package/contracts/clients/trade-line-items/index.ts +1 -1
  31. package/contracts/clients/trades/index.ts +1 -1
  32. package/index.ts +10 -0
  33. package/package.json +23 -32
  34. package/contracts/compliance/account-contacts/index.ts +0 -82
  35. package/contracts/compliance/account-managers/index.ts +0 -142
  36. package/contracts/compliance/accounts/index.ts +0 -187
  37. package/contracts/compliance/activities/index.ts +0 -55
  38. package/contracts/compliance/aic/index.ts +0 -60
  39. package/contracts/compliance/api-keys/index.ts +0 -91
  40. package/contracts/compliance/assets/index.ts +0 -122
  41. package/contracts/compliance/auth/index.ts +0 -134
  42. package/contracts/compliance/batch-jobs/index.ts +0 -62
  43. package/contracts/compliance/bonus-tiers/index.ts +0 -74
  44. package/contracts/compliance/checklist/index.ts +0 -87
  45. package/contracts/compliance/checklist-items/index.ts +0 -86
  46. package/contracts/compliance/covered-persons/index.ts +0 -97
  47. package/contracts/compliance/dashboard/index.ts +0 -111
  48. package/contracts/compliance/data-records/index.ts +0 -116
  49. package/contracts/compliance/data-rooms/index.ts +0 -113
  50. package/contracts/compliance/default-theme-configs/index.ts +0 -95
  51. package/contracts/compliance/disbursement/index.ts +0 -165
  52. package/contracts/compliance/disbursement-approval-users/index.ts +0 -84
  53. package/contracts/compliance/disbursement-transactions/index.ts +0 -37
  54. package/contracts/compliance/domain-filters/index.ts +0 -117
  55. package/contracts/compliance/email-themes/index.ts +0 -284
  56. package/contracts/compliance/escrow-accounts/index.ts +0 -85
  57. package/contracts/compliance/exchange-api-keys/index.ts +0 -129
  58. package/contracts/compliance/exchange-imports/index.ts +0 -137
  59. package/contracts/compliance/files/index.ts +0 -267
  60. package/contracts/compliance/files-public/index.ts +0 -188
  61. package/contracts/compliance/health/index.ts +0 -26
  62. package/contracts/compliance/index.ts +0 -147
  63. package/contracts/compliance/individuals/index.ts +0 -57
  64. package/contracts/compliance/investor-accounts/index.ts +0 -141
  65. package/contracts/compliance/invites/index.ts +0 -137
  66. package/contracts/compliance/issuer-bank-accounts/index.ts +0 -81
  67. package/contracts/compliance/issuer-payment-methods/index.ts +0 -81
  68. package/contracts/compliance/issuers/index.ts +0 -97
  69. package/contracts/compliance/job-items/index.ts +0 -58
  70. package/contracts/compliance/jobs/index.ts +0 -59
  71. package/contracts/compliance/kyb/index.ts +0 -54
  72. package/contracts/compliance/kyc/index.ts +0 -77
  73. package/contracts/compliance/legal-entities/index.ts +0 -57
  74. package/contracts/compliance/login-histories/index.ts +0 -37
  75. package/contracts/compliance/notes/index.ts +0 -69
  76. package/contracts/compliance/notion-databases/index.ts +0 -107
  77. package/contracts/compliance/notion-pages/index.ts +0 -105
  78. package/contracts/compliance/offering-reports/index.ts +0 -149
  79. package/contracts/compliance/offerings/index.ts +0 -233
  80. package/contracts/compliance/pages/index.ts +0 -178
  81. package/contracts/compliance/payment-methods/index.ts +0 -57
  82. package/contracts/compliance/rejection-reasons/index.ts +0 -32
  83. package/contracts/compliance/review/index.ts +0 -169
  84. package/contracts/compliance/roles/index.ts +0 -34
  85. package/contracts/compliance/secondary-customers/index.ts +0 -77
  86. package/contracts/compliance/secondary-orders/index.ts +0 -60
  87. package/contracts/compliance/secondary-trades/index.ts +0 -100
  88. package/contracts/compliance/secure-requests/index.ts +0 -54
  89. package/contracts/compliance/signer/index.ts +0 -369
  90. package/contracts/compliance/site-links/index.ts +0 -128
  91. package/contracts/compliance/site-settings/index.ts +0 -669
  92. package/contracts/compliance/sites/index.ts +0 -56
  93. package/contracts/compliance/state-machine/index.ts +0 -94
  94. package/contracts/compliance/tasks/index.ts +0 -91
  95. package/contracts/compliance/third-parties/index.ts +0 -52
  96. package/contracts/compliance/trade-line-items/index.ts +0 -59
  97. package/contracts/compliance/trades/index.ts +0 -230
  98. package/contracts/compliance/transactions/index.ts +0 -161
  99. package/contracts/compliance/user-manuals/index.ts +0 -271
  100. package/contracts/compliance/user-settings/index.ts +0 -189
  101. package/contracts/compliance/users/index.ts +0 -221
  102. package/contracts/compliance/webhooks/index.ts +0 -41
  103. package/contracts/compliance-apikey/accounts/index.ts +0 -58
  104. package/contracts/compliance-apikey/index.ts +0 -14
  105. package/contracts/index.ts +0 -6
  106. package/contracts/investors/account-contacts/index.ts +0 -58
  107. package/contracts/investors/aic/index.ts +0 -59
  108. package/contracts/investors/assets/index.ts +0 -61
  109. package/contracts/investors/auth/index.ts +0 -116
  110. package/contracts/investors/bonus-tiers/index.ts +0 -55
  111. package/contracts/investors/cart/index.ts +0 -75
  112. package/contracts/investors/contact-us/index.ts +0 -48
  113. package/contracts/investors/data-records/index.ts +0 -113
  114. package/contracts/investors/data-rooms/index.ts +0 -96
  115. package/contracts/investors/files/index.ts +0 -167
  116. package/contracts/investors/files-public/index.ts +0 -185
  117. package/contracts/investors/index.ts +0 -72
  118. package/contracts/investors/individuals/index.ts +0 -121
  119. package/contracts/investors/investor-accounts/index.ts +0 -110
  120. package/contracts/investors/issuer-payment-methods/index.ts +0 -36
  121. package/contracts/investors/issuers/index.ts +0 -30
  122. package/contracts/investors/legal-entities/index.ts +0 -93
  123. package/contracts/investors/notes/index.ts +0 -69
  124. package/contracts/investors/offerings/index.ts +0 -93
  125. package/contracts/investors/pages/index.ts +0 -88
  126. package/contracts/investors/payment-methods/index.ts +0 -149
  127. package/contracts/investors/portfolios/index.ts +0 -53
  128. package/contracts/investors/sites/index.ts +0 -96
  129. package/contracts/investors/tasks/index.ts +0 -111
  130. package/contracts/investors/trade-line-items/index.ts +0 -75
  131. package/contracts/investors/trades/index.ts +0 -114
  132. package/contracts/investors/transactions/index.ts +0 -37
  133. package/contracts/investors/trusted-contacts/index.ts +0 -93
  134. package/contracts/investors/user-manuals/index.ts +0 -62
  135. package/contracts/investors/user-settings/index.ts +0 -170
  136. package/contracts/investors/users/index.ts +0 -45
  137. package/contracts/investors/webhooks/index.ts +0 -30
  138. package/contracts/issuers/account-contacts/index.ts +0 -76
  139. package/contracts/issuers/account-integrations/index.ts +0 -97
  140. package/contracts/issuers/accounts/index.ts +0 -97
  141. package/contracts/issuers/activities/index.ts +0 -54
  142. package/contracts/issuers/aic/index.ts +0 -39
  143. package/contracts/issuers/api-key-logs/index.ts +0 -53
  144. package/contracts/issuers/api-keys/index.ts +0 -93
  145. package/contracts/issuers/assets/index.ts +0 -122
  146. package/contracts/issuers/auth/index.ts +0 -152
  147. package/contracts/issuers/bonus-tiers/index.ts +0 -73
  148. package/contracts/issuers/contact-us/index.ts +0 -48
  149. package/contracts/issuers/covered-persons/index.ts +0 -136
  150. package/contracts/issuers/dashboard/index.ts +0 -72
  151. package/contracts/issuers/data-records/index.ts +0 -257
  152. package/contracts/issuers/data-rooms/index.ts +0 -134
  153. package/contracts/issuers/disbursement-approval-users/index.ts +0 -82
  154. package/contracts/issuers/disbursement-transactions/index.ts +0 -53
  155. package/contracts/issuers/disbursements/index.ts +0 -189
  156. package/contracts/issuers/email-themes/index.ts +0 -242
  157. package/contracts/issuers/escrow-accounts/index.ts +0 -81
  158. package/contracts/issuers/exchange-api-keys/index.ts +0 -144
  159. package/contracts/issuers/files/index.ts +0 -166
  160. package/contracts/issuers/files-public/index.ts +0 -166
  161. package/contracts/issuers/health/index.ts +0 -24
  162. package/contracts/issuers/index.ts +0 -112
  163. package/contracts/issuers/investor-accounts/index.ts +0 -148
  164. package/contracts/issuers/invites/index.ts +0 -129
  165. package/contracts/issuers/issuer/index.ts +0 -94
  166. package/contracts/issuers/issuer-bank-accounts/index.ts +0 -81
  167. package/contracts/issuers/issuer-payment-methods/index.ts +0 -136
  168. package/contracts/issuers/kyc/index.ts +0 -38
  169. package/contracts/issuers/login-histories/index.ts +0 -51
  170. package/contracts/issuers/notes/index.ts +0 -69
  171. package/contracts/issuers/offerings/index.ts +0 -206
  172. package/contracts/issuers/pages/index.ts +0 -138
  173. package/contracts/issuers/payment-methods/index.ts +0 -61
  174. package/contracts/issuers/portfolios/index.ts +0 -36
  175. package/contracts/issuers/rejection-reasons/index.ts +0 -32
  176. package/contracts/issuers/review/index.ts +0 -63
  177. package/contracts/issuers/secondary-customers/index.ts +0 -55
  178. package/contracts/issuers/secondary-orders/index.ts +0 -57
  179. package/contracts/issuers/secondary-trades/index.ts +0 -57
  180. package/contracts/issuers/secure-requests/index.ts +0 -34
  181. package/contracts/issuers/site-links/index.ts +0 -116
  182. package/contracts/issuers/site-settings/index.ts +0 -585
  183. package/contracts/issuers/sites/index.ts +0 -32
  184. package/contracts/issuers/tasks/index.ts +0 -111
  185. package/contracts/issuers/trades/index.ts +0 -132
  186. package/contracts/issuers/transactions/index.ts +0 -158
  187. package/contracts/issuers/user-manuals/index.ts +0 -62
  188. package/contracts/issuers/user-settings/index.ts +0 -170
  189. package/contracts/issuers/users/index.ts +0 -126
  190. package/contracts/secondaries/accounts/index.ts +0 -58
  191. package/contracts/secondaries/index.ts +0 -23
  192. package/contracts/secondaries/secondary-customers/index.ts +0 -55
  193. package/contracts/secondaries/secondary-issuers/index.ts +0 -94
  194. package/contracts/secondaries/secondary-orders/index.ts +0 -56
  195. package/contracts/secondaries/secondary-securities/index.ts +0 -95
  196. package/contracts/secondaries/secondary-trades/index.ts +0 -56
@@ -434,3 +434,37 @@ export type EmailThemeSetting = z.infer<typeof EmailThemeSettingZod>;
434
434
 
435
435
  export const EmailThemeSettingsZod = z.array(EmailThemeSettingZod);
436
436
  export type EmailThemeSettingsZod = z.infer<typeof EmailThemeSettingsZod>;
437
+
438
+ /**
439
+ * Response from a successful email send operation.
440
+ * Based on SendGrid SDK's ClientResponse structure.
441
+ */
442
+ export const EmailSendResponseSchema = z.object({
443
+ /** HTTP status code from SendGrid (e.g., 202 for accepted) */
444
+ statusCode: z.number(),
445
+ /** SendGrid's x-message-id header for tracking emails in their dashboard */
446
+ messageId: z.string().optional(),
447
+ /** Full response headers, available for debugging if needed */
448
+ headers: z.record(z.string(), z.unknown()).optional(),
449
+ });
450
+ export type EmailSendResponse = z.infer<typeof EmailSendResponseSchema>;
451
+
452
+ /**
453
+ * Error from a failed email send operation.
454
+ * Fields are optional because error shapes vary depending on failure type
455
+ * (network errors vs SendGrid API errors).
456
+ */
457
+ export const EmailSendErrorSchema = z.object({
458
+ /** Human-readable error message */
459
+ message: z.string(),
460
+ /** Network-level error code (e.g., 'ECONNREFUSED', 'ETIMEDOUT') */
461
+ code: z.string().optional(),
462
+ /** HTTP status code if request reached SendGrid (e.g., 400, 401, 403, 413, 500) */
463
+ statusCode: z.number().optional(),
464
+ /**
465
+ * SendGrid's error response body. Structure: { errors: [{ message, field, help, id }] }
466
+ * @see https://www.twilio.com/docs/sendgrid/api-reference/mail-send/mail-send#responses
467
+ */
468
+ response: z.unknown().optional(),
469
+ });
470
+ export type EmailSendError = z.infer<typeof EmailSendErrorSchema>;
@@ -79,7 +79,7 @@ export const PostNoteBody = z.object({
79
79
  export type PostNoteBody = z.infer<typeof PostNoteBody>;
80
80
 
81
81
  export const CompliancePostNoteBody = PostNoteBody.extend({
82
- accountId: accountIdSchema,
82
+ accountId: accountIdSchema.nullable().default(null),
83
83
  });
84
84
 
85
85
  export type CompliancePostNoteBody = z.infer<typeof CompliancePostNoteBody>;
@@ -1,58 +1,554 @@
1
1
  import { extendZodWithOpenApi } from '@anatine/zod-openapi';
2
2
  import { z } from 'zod';
3
3
  import { TypeID } from 'typeid-js';
4
- import { accountIdSchema } from './account.types';
4
+ import { IBaseEntity } from './entity.types';
5
+ import { IPaginationMeta, StringToBooleanSchema } from './common.types';
6
+ import {
7
+ ActivityTypeAction,
8
+ ActivityTypeCategory,
9
+ ActivityTypeResource,
10
+ } from './activity.types';
5
11
 
6
12
  extendZodWithOpenApi(z);
7
- export enum NotificationChannel {
13
+
14
+ export enum NotificationChannelType {
8
15
  EMAIL = 'EMAIL',
9
16
  SLACK = 'SLACK',
17
+ WEBHOOK = 'WEBHOOK',
10
18
  }
11
- export enum NotificationType {
12
- COMPLIANCE_TRADE_ALERT = 'COMPLIANCE_TRADE_ALERT',
13
- TRADE_ALERT = 'TRADE_ALERT',
19
+
20
+ export enum NotificationRecordStatus {
21
+ PENDING = 'PENDING',
22
+ SENT = 'SENT',
23
+ FAILED = 'FAILED',
14
24
  }
15
25
 
16
- export const notificationIdSchema = z.string().refine(
26
+ export type TriggerExclusion = {
27
+ category?: ActivityTypeCategory;
28
+ resource?: ActivityTypeResource;
29
+ action?: ActivityTypeAction;
30
+ };
31
+
32
+ // Excluded notifications
33
+ export const EXCLUDED_NOTIFICATION_TRIGGERS: TriggerExclusion[] = [
34
+ // { action: ActivityTypeAction.RE_SIGN },
35
+ // { action: ActivityTypeAction.RESET_2FA },
36
+ // { action: ActivityTypeAction.LOGIN },
37
+ // { action: ActivityTypeAction.RESET_PASSWORD },
38
+ // { action: ActivityTypeAction.TWO_FACTOR_LOGIN },
39
+ // { action: ActivityTypeAction.FORGOT_PASSWORD },
40
+ // { resource: ActivityTypeResource.USERS },
41
+ // { resource: ActivityTypeResource.THEME_SETTINGS },
42
+ ];
43
+
44
+ export const ISSUER_ALLOWED_CATEGORIES: ActivityTypeCategory[] = [
45
+ ActivityTypeCategory.ISSUER,
46
+ ];
47
+
48
+ /**
49
+ * Checks if an activity type should be excluded from notifications.
50
+ *
51
+ * Each exclusion pattern can specify any combination of category, resource, and action.
52
+ * Omitted fields act as wildcards (match any value).
53
+ *
54
+ * @example
55
+ * // Excludes ALL activities with action RE_SIGN (any category, any resource)
56
+ * { action: ActivityTypeAction.RE_SIGN }
57
+ *
58
+ * @example
59
+ * // Excludes ALL USERS activities (any category, any action)
60
+ * { resource: ActivityTypeResource.USERS }
61
+ *
62
+ * @example
63
+ * // Excludes only COMPLIANCE + TRADES + CREATE (all three must match)
64
+ * { category: ActivityTypeCategory.COMPLIANCE, resource: ActivityTypeResource.TRADES, action: ActivityTypeAction.CREATE }
65
+ *
66
+ * @param category - The activity type category to check
67
+ * @param resource - The activity type resource to check
68
+ * @param action - The activity type action to check
69
+ * @param exclusions - Array of exclusion patterns (defaults to EXCLUDED_NOTIFICATION_TRIGGERS)
70
+ * @returns true if the activity type matches any exclusion pattern
71
+ */
72
+ export function isTriggerExcluded(
73
+ category: string,
74
+ resource: string,
75
+ action: string,
76
+ exclusions: TriggerExclusion[] = EXCLUDED_NOTIFICATION_TRIGGERS,
77
+ ): boolean {
78
+ return exclusions.some((exclusion) => {
79
+ const categoryMatch =
80
+ !exclusion.category || exclusion.category === category;
81
+ const resourceMatch =
82
+ !exclusion.resource || exclusion.resource === resource;
83
+ const actionMatch = !exclusion.action || exclusion.action === action;
84
+ return categoryMatch && resourceMatch && actionMatch;
85
+ });
86
+ }
87
+
88
+ /**
89
+ * Checks if a category is allowed for notification triggers.
90
+ *
91
+ * Used to restrict which activity type categories a user can subscribe to.
92
+ * For example, issuers can only subscribe to ISSUER category triggers.
93
+ *
94
+ * @param category - The activity type category to check
95
+ * @param allowedCategories - Optional array of allowed categories. If empty or undefined, all categories are allowed.
96
+ * @returns true if the category is allowed (or if no restrictions are set)
97
+ */
98
+ export function isCategoryAllowed(
99
+ category: string,
100
+ allowedCategories?: ActivityTypeCategory[],
101
+ ): boolean {
102
+ if (!allowedCategories || allowedCategories.length === 0) {
103
+ return true;
104
+ }
105
+ return allowedCategories.includes(category as ActivityTypeCategory);
106
+ }
107
+
108
+ export const notificationChannelIdSchema = z.string().refine(
17
109
  (value) => {
18
110
  try {
19
111
  const tid = TypeID.fromString(value);
20
- return tid.getType() === 'notification';
112
+ return tid.getType() === 'notification_channel';
21
113
  } catch {
22
114
  return false;
23
115
  }
24
116
  },
25
117
  {
26
118
  message:
27
- 'Invalid notification ID format. Must be a valid TypeID with "notification" prefix.',
119
+ 'Invalid notification channel ID format. Must be a valid TypeID with "notification_channel" prefix.',
28
120
  },
29
121
  );
30
122
 
31
- export const SendNotificationZod = z.object({
32
- message: z.string(),
123
+ export const notificationChannelTriggerIdSchema = z.string().refine(
124
+ (value) => {
125
+ try {
126
+ const tid = TypeID.fromString(value);
127
+ return tid.getType() === 'notification_channel_trigger';
128
+ } catch {
129
+ return false;
130
+ }
131
+ },
132
+ {
133
+ message:
134
+ 'Invalid notification channel trigger ID format. Must be a valid TypeID with "notification_channel_trigger" prefix.',
135
+ },
136
+ );
137
+
138
+ export const notificationRecordIdSchema = z.string().refine(
139
+ (value) => {
140
+ try {
141
+ const tid = TypeID.fromString(value);
142
+ return tid.getType() === 'notification_record';
143
+ } catch {
144
+ return false;
145
+ }
146
+ },
147
+ {
148
+ message:
149
+ 'Invalid notification record ID format. Must be a valid TypeID with "notification_record" prefix.',
150
+ },
151
+ );
152
+
153
+ export const EmailChannelSettingsSchema = z.object({
154
+ recipients: z
155
+ .array(z.string().email())
156
+ .min(1)
157
+ .max(100, 'At most 100 recipients are allowed'),
158
+ subjectTemplate: z.string().optional(),
159
+ });
160
+ export type EmailChannelSettings = z.infer<typeof EmailChannelSettingsSchema>;
161
+
162
+ export const SlackChannelSettingsSchema = z
163
+ .object({
164
+ webhookUrl: z.string().url().optional(),
165
+ channelEmail: z.string().email().optional(),
166
+ })
167
+ .refine((data) => data.webhookUrl || data.channelEmail, {
168
+ message: 'Either webhookUrl or channelEmail is required',
169
+ });
170
+ export type SlackChannelSettings = z.infer<typeof SlackChannelSettingsSchema>;
171
+
172
+ export const WebhookChannelSettingsSchema = z.object({
173
+ url: z.string().url(),
174
+ method: z.enum(['POST', 'PUT']),
175
+ headers: z.record(z.string()).optional(),
176
+ authType: z.enum(['none', 'bearer', 'basic', 'api_key']).default('none'),
177
+ authValue: z.string().optional(),
178
+ });
179
+ export type WebhookChannelSettings = z.infer<
180
+ typeof WebhookChannelSettingsSchema
181
+ >;
182
+
183
+ export const NotificationChannelSettingsSchema = z.discriminatedUnion('type', [
184
+ z.object({
185
+ type: z.literal(NotificationChannelType.EMAIL),
186
+ config: EmailChannelSettingsSchema,
187
+ }),
188
+ z.object({
189
+ type: z.literal(NotificationChannelType.SLACK),
190
+ config: SlackChannelSettingsSchema,
191
+ }),
192
+ z.object({
193
+ type: z.literal(NotificationChannelType.WEBHOOK),
194
+ config: WebhookChannelSettingsSchema,
195
+ }),
196
+ ]);
197
+ export type NotificationChannelSettings = z.infer<
198
+ typeof NotificationChannelSettingsSchema
199
+ >;
200
+
201
+ export const EmailNotificationPayloadSchema = z.object({
202
+ to: z.array(z.string().email()),
33
203
  subject: z.string(),
34
- buttonText: z.string(),
35
- link: z.string(),
36
- debug: z.boolean().default(false),
37
- notificationChannel: z.nativeEnum(NotificationChannel),
38
- channelName: z.string(),
39
- channelEmail: z.string().email(),
40
- notificationType: z.nativeEnum(NotificationType),
204
+ body: z.string(),
205
+ html: z.string().optional(),
206
+ });
207
+ export type EmailNotificationPayload = z.infer<
208
+ typeof EmailNotificationPayloadSchema
209
+ >;
210
+
211
+ /**
212
+ * Payload for Slack notifications sent via Incoming Webhooks.
213
+ *
214
+ * @property webhookUrl - Slack Incoming Webhook URL
215
+ * @property channelEmail - Slack channel email integration (alternative delivery method)
216
+ * @property message - Plain text message (also serves as fallback for notifications)
217
+ * @property blocks - Optional Slack Block Kit elements for rich message formatting.
218
+ * Blocks allow structured layouts with headers, sections, images, buttons, etc.
219
+ * @see https://docs.slack.dev/messaging/creating-interactive-messages
220
+ */
221
+ export const SlackNotificationPayloadSchema = z.object({
222
+ webhookUrl: z.string().url().optional(),
223
+ channelEmail: z.string().email().optional(),
224
+ message: z.string(),
225
+ blocks: z.array(z.record(z.unknown())).optional(),
226
+ });
227
+ export type SlackNotificationPayload = z.infer<
228
+ typeof SlackNotificationPayloadSchema
229
+ >;
230
+
231
+ export const WebhookNotificationPayloadSchema = z.object({
232
+ url: z.string().url(),
233
+ method: z.enum(['POST', 'PUT']),
234
+ headers: z.record(z.string()),
235
+ body: z.record(z.unknown()),
41
236
  });
42
- export type SendNotificationZod = z.infer<typeof SendNotificationZod>;
237
+ export type WebhookNotificationPayload = z.infer<
238
+ typeof WebhookNotificationPayloadSchema
239
+ >;
240
+
241
+ export const NotificationPayloadSchema = z.discriminatedUnion('type', [
242
+ z.object({
243
+ type: z.literal(NotificationChannelType.EMAIL),
244
+ data: EmailNotificationPayloadSchema,
245
+ }),
246
+ z.object({
247
+ type: z.literal(NotificationChannelType.SLACK),
248
+ data: SlackNotificationPayloadSchema,
249
+ }),
250
+ z.object({
251
+ type: z.literal(NotificationChannelType.WEBHOOK),
252
+ data: WebhookNotificationPayloadSchema,
253
+ }),
254
+ ]);
255
+ export type NotificationPayload = z.infer<typeof NotificationPayloadSchema>;
43
256
 
44
- const SlackSettingsSchema = z.object({
45
- channelName: z.string().min(1).max(50),
46
- channelEmail: z.string().email(),
257
+ export const EmailNotificationResponseSchema = z.object({
258
+ messageId: z.string().optional(),
259
+ accepted: z.array(z.string()).optional(),
260
+ rejected: z.array(z.string()).optional(),
47
261
  });
262
+ export type EmailNotificationResponse = z.infer<
263
+ typeof EmailNotificationResponseSchema
264
+ >;
48
265
 
49
- export const PostNotificationZod = z.object({
50
- accountId: accountIdSchema,
51
- notificationChannel: z.literal(NotificationChannel.SLACK), // Only Slack for now
52
- notificationType: z.nativeEnum(NotificationType),
53
- enabled: z.boolean().default(true),
54
- debug: z.boolean().default(false),
55
- settings: SlackSettingsSchema,
266
+ export const SlackNotificationResponseSchema = z.object({
267
+ ok: z.boolean().optional(),
268
+ error: z.string().optional(),
269
+ responseBody: z.string().optional(),
56
270
  });
271
+ export type SlackNotificationResponse = z.infer<
272
+ typeof SlackNotificationResponseSchema
273
+ >;
57
274
 
58
- export type PostNotificationZod = z.infer<typeof PostNotificationZod>;
275
+ export const WebhookNotificationResponseSchema = z.object({
276
+ statusCode: z.number(),
277
+ headers: z.record(z.string()).optional(),
278
+ body: z.unknown().optional(),
279
+ });
280
+ export type WebhookNotificationResponse = z.infer<
281
+ typeof WebhookNotificationResponseSchema
282
+ >;
283
+
284
+ export const NotificationResponseSchema = z.discriminatedUnion('type', [
285
+ z.object({
286
+ type: z.literal(NotificationChannelType.EMAIL),
287
+ data: EmailNotificationResponseSchema,
288
+ }),
289
+ z.object({
290
+ type: z.literal(NotificationChannelType.SLACK),
291
+ data: SlackNotificationResponseSchema,
292
+ }),
293
+ z.object({
294
+ type: z.literal(NotificationChannelType.WEBHOOK),
295
+ data: WebhookNotificationResponseSchema,
296
+ }),
297
+ ]);
298
+ export type NotificationResponse = z.infer<typeof NotificationResponseSchema>;
299
+
300
+ export const INotificationChannelZod = IBaseEntity.extend({
301
+ id: notificationChannelIdSchema.openapi({
302
+ example: 'notification_channel_01j5y5ghx8fvc83dmx3pznq7hv',
303
+ }),
304
+ accountSettingsId: z.string().openapi({
305
+ example: 'account_setting_01j5y5ghx8fvc83dmx3pznq7hv',
306
+ }),
307
+ channelType: z.nativeEnum(NotificationChannelType).openapi({
308
+ example: NotificationChannelType.SLACK,
309
+ }),
310
+ name: z.string().openapi({
311
+ example: 'Compliance Alerts',
312
+ }),
313
+ enabled: z.boolean().openapi({
314
+ example: true,
315
+ }),
316
+ settings: NotificationChannelSettingsSchema.openapi({
317
+ example: {
318
+ type: NotificationChannelType.SLACK,
319
+ config: {
320
+ webhookUrl: 'https://hooks.slack.com/test',
321
+ },
322
+ },
323
+ }),
324
+ });
325
+ export type INotificationChannelZod = z.infer<typeof INotificationChannelZod>;
326
+
327
+ export const INotificationChannelTriggerZod = IBaseEntity.extend({
328
+ id: notificationChannelTriggerIdSchema.openapi({
329
+ example: 'notification_channel_trigger_01j5y5ghx8fvc83dmx3pznq7hv',
330
+ }),
331
+ notificationChannelId: notificationChannelIdSchema.openapi({
332
+ example: 'notification_channel_01j5y5ghx8fvc83dmx3pznq7hv',
333
+ }),
334
+ activityTypeId: z.string().openapi({
335
+ example: 'activity_type_01j5y5ghx8fvc83dmx3pznq7hv',
336
+ }),
337
+ enabled: z.boolean().openapi({
338
+ example: true,
339
+ }),
340
+ });
341
+ export type INotificationChannelTriggerZod = z.infer<
342
+ typeof INotificationChannelTriggerZod
343
+ >;
344
+
345
+ export const IAvailableTriggerZod = z.object({
346
+ activityTypeId: z.string().openapi({
347
+ example: 'activity_type_01j5y5ghx8fvc83dmx3pznq7hv',
348
+ }),
349
+ category: z.string().openapi({
350
+ example: 'COMPLIANCE',
351
+ }),
352
+ resource: z.string().openapi({
353
+ example: 'TRADES',
354
+ }),
355
+ action: z.string().openapi({
356
+ example: 'CREATE',
357
+ }),
358
+ enabled: z.boolean().openapi({
359
+ description: 'Whether the trigger is enabled for this activity type',
360
+ example: false,
361
+ }),
362
+ trigger: INotificationChannelTriggerZod.nullable().openapi({
363
+ description: 'The configured trigger, or null if not configured',
364
+ }),
365
+ });
366
+ export type IAvailableTriggerZod = z.infer<typeof IAvailableTriggerZod>;
367
+
368
+ export const IAvailableTriggersResponse = z.object({
369
+ items: z.array(IAvailableTriggerZod),
370
+ });
371
+ export type IAvailableTriggersResponse = z.infer<
372
+ typeof IAvailableTriggersResponse
373
+ >;
374
+
375
+ export const INotificationRecordZod = IBaseEntity.extend({
376
+ id: notificationRecordIdSchema.openapi({
377
+ example: 'notification_record_01j5y5ghx8fvc83dmx3pznq7hv',
378
+ }),
379
+ notificationChannelId: notificationChannelIdSchema.openapi({
380
+ example: 'notification_channel_01j5y5ghx8fvc83dmx3pznq7hv',
381
+ }),
382
+ activityId: z.string().nullable().openapi({
383
+ example: 'activity_01j5y5ghx8fvc83dmx3pznq7hv',
384
+ }),
385
+ targetTable: z.string().openapi({
386
+ example: 'trades',
387
+ }),
388
+ targetId: z.string().openapi({
389
+ example: 'trade_01j5y5ghx8fvc83dmx3pznq7hv',
390
+ }),
391
+ status: z.nativeEnum(NotificationRecordStatus).openapi({
392
+ example: NotificationRecordStatus.SENT,
393
+ }),
394
+ payload: NotificationPayloadSchema,
395
+ response: NotificationResponseSchema.nullable(),
396
+ errorMessage: z.string().nullable().openapi({
397
+ example: null,
398
+ }),
399
+ retryCount: z.number().openapi({
400
+ example: 0,
401
+ }),
402
+ sentAt: z.date().nullable().openapi({
403
+ example: new Date(),
404
+ }),
405
+ });
406
+ export type INotificationRecordZod = z.infer<typeof INotificationRecordZod>;
407
+
408
+ export const CreateChannelInputSchema = z
409
+ .object({
410
+ accountSettingsId: z.string(),
411
+ channelType: z.nativeEnum(NotificationChannelType),
412
+ name: z
413
+ .string()
414
+ .min(1, 'Name is required')
415
+ .max(255, 'Name must be less than 255 characters'),
416
+ enabled: z.boolean().optional(),
417
+ settings: NotificationChannelSettingsSchema,
418
+ })
419
+ .refine((data) => data.channelType === data.settings.type, {
420
+ message: 'Channel type must match settings type',
421
+ path: ['settings', 'type'],
422
+ });
423
+ export type CreateChannelInput = z.infer<typeof CreateChannelInputSchema>;
424
+
425
+ export const IssuerCreateChannelInputSchema = z
426
+ .object({
427
+ channelType: z.nativeEnum(NotificationChannelType),
428
+ name: z
429
+ .string()
430
+ .min(1, 'Name is required')
431
+ .max(255, 'Name must be less than 255 characters'),
432
+ enabled: z.boolean().optional(),
433
+ settings: NotificationChannelSettingsSchema,
434
+ })
435
+ .refine((data) => data.channelType === data.settings.type, {
436
+ message: 'Channel type must match settings type',
437
+ path: ['settings', 'type'],
438
+ });
439
+ export type IssuerCreateChannelInput = z.infer<
440
+ typeof IssuerCreateChannelInputSchema
441
+ >;
442
+
443
+ export const UpdateChannelInputSchema = z.object({
444
+ name: z.string().optional(),
445
+ enabled: z.boolean().optional(),
446
+ settings: NotificationChannelSettingsSchema.optional(),
447
+ });
448
+ export type UpdateChannelInput = z.infer<typeof UpdateChannelInputSchema>;
449
+
450
+ export const CreateTriggerInputSchema = z.object({
451
+ notificationChannelId: notificationChannelIdSchema,
452
+ activityTypeId: z.string(),
453
+ enabled: z.boolean().optional(),
454
+ });
455
+ export type CreateTriggerInput = z.infer<typeof CreateTriggerInputSchema>;
456
+
457
+ export const IPaginatedNotificationChannel = z.object({
458
+ items: z.array(INotificationChannelZod),
459
+ meta: IPaginationMeta,
460
+ });
461
+ export type IPaginatedNotificationChannel = z.infer<
462
+ typeof IPaginatedNotificationChannel
463
+ >;
464
+
465
+ export const IPaginatedNotificationChannelTrigger = z.object({
466
+ items: z.array(INotificationChannelTriggerZod),
467
+ meta: IPaginationMeta,
468
+ });
469
+ export type IPaginatedNotificationChannelTrigger = z.infer<
470
+ typeof IPaginatedNotificationChannelTrigger
471
+ >;
472
+
473
+ export const IPaginatedNotificationRecord = z.object({
474
+ items: z.array(INotificationRecordZod),
475
+ meta: IPaginationMeta,
476
+ });
477
+ export type IPaginatedNotificationRecord = z.infer<
478
+ typeof IPaginatedNotificationRecord
479
+ >;
480
+
481
+ export const NotificationChannelFilters = z.object({
482
+ accountSettingsId: z.string().optional(),
483
+ channelType: z.nativeEnum(NotificationChannelType).optional(),
484
+ enabled: StringToBooleanSchema.optional(),
485
+ });
486
+ export type NotificationChannelFilters = z.infer<
487
+ typeof NotificationChannelFilters
488
+ >;
489
+
490
+ export const NotificationChannelTriggerFilters = z.object({
491
+ notificationChannelId: notificationChannelIdSchema.optional(),
492
+ activityTypeId: z.string().optional(),
493
+ enabled: StringToBooleanSchema.optional(),
494
+ });
495
+ export type NotificationChannelTriggerFilters = z.infer<
496
+ typeof NotificationChannelTriggerFilters
497
+ >;
498
+
499
+ export const NotificationRecordFilters = z.object({
500
+ notificationChannelId: notificationChannelIdSchema.optional(),
501
+ status: z.nativeEnum(NotificationRecordStatus).optional(),
502
+ });
503
+ export type NotificationRecordFilters = z.infer<
504
+ typeof NotificationRecordFilters
505
+ >;
506
+
507
+ export const notificationChannelsInclude = z.enum([
508
+ 'triggers',
509
+ 'accountSettings',
510
+ 'notificationRecords',
511
+ ]);
512
+
513
+ export const NotificationChannelsIncludeQuery = z.object({
514
+ include: z
515
+ .string()
516
+ .optional()
517
+ .transform((str) => (str ? str.split(',') : []))
518
+ .refine(
519
+ (includes) =>
520
+ includes.every((include) =>
521
+ notificationChannelsInclude.options.includes(include as any),
522
+ ),
523
+ {
524
+ message: `Invalid include value. Valid values are: ${notificationChannelsInclude.options.join(', ')}`,
525
+ },
526
+ ),
527
+ });
528
+ export type NotificationChannelsIncludeQuery = z.infer<
529
+ typeof NotificationChannelsIncludeQuery
530
+ >;
531
+
532
+ export const notificationRecordsInclude = z.enum([
533
+ 'notificationChannel',
534
+ 'activity',
535
+ ]);
536
+
537
+ export const NotificationRecordsIncludeQuery = z.object({
538
+ include: z
539
+ .string()
540
+ .optional()
541
+ .transform((str) => (str ? str.split(',') : []))
542
+ .refine(
543
+ (includes) =>
544
+ includes.every((include) =>
545
+ notificationRecordsInclude.options.includes(include as any),
546
+ ),
547
+ {
548
+ message: `Invalid include value. Valid values are: ${notificationRecordsInclude.options.join(', ')}`,
549
+ },
550
+ ),
551
+ });
552
+ export type NotificationRecordsIncludeQuery = z.infer<
553
+ typeof NotificationRecordsIncludeQuery
554
+ >;
@@ -17,6 +17,7 @@ import {
17
17
  OfferingOnboardingStatus,
18
18
  AssetType,
19
19
  DurationType,
20
+ StringToBooleanSchema,
20
21
  } from './common.types';
21
22
  import { IBaseEntity } from './entity.types';
22
23
  import { fileIdSchema, FileZod } from './file.types';
@@ -346,15 +347,7 @@ export const OfferingFiltersZod = z.object({
346
347
  issuerId: z.lazy(() => issuerIdSchema).optional(),
347
348
  type: z.nativeEnum(OfferingType).optional(),
348
349
  status: z.nativeEnum(ComplianceReview).optional(),
349
- enabled: z.preprocess(
350
- (val) =>
351
- val === 'true' || val === '1'
352
- ? true
353
- : val === 'false' || val === '0'
354
- ? false
355
- : val,
356
- z.boolean().optional(),
357
- ),
350
+ enabled: StringToBooleanSchema.optional(),
358
351
  managedBy: z.nativeEnum(ManagedByType).optional(),
359
352
  versioningType: z.nativeEnum(OfferingVersioningType).optional(),
360
353
  combinedStatus: z.nativeEnum(OfferingStatus).optional(),
@@ -3,6 +3,7 @@ import { z } from 'zod';
3
3
  import { fileIdSchema } from './file.types';
4
4
  import {
5
5
  AccountZod,
6
+ EmailSchema,
6
7
  HexCodeColorSchema,
7
8
  IPaginationMeta,
8
9
  SubdomainSchema,
@@ -462,7 +463,7 @@ export const GetSenderEmailZod = z.object({
462
463
  export type GetSenderEmailZod = z.infer<typeof GetSenderEmailZod>;
463
464
 
464
465
  export const PatchSenderEmailZod = z.object({
465
- senderEmail: z.string().email().openapi({ example: 'example@example.com' }),
466
+ senderEmail: EmailSchema,
466
467
  });
467
468
  export type PatchSenderEmailZod = z.infer<typeof PatchSenderEmailZod>;
468
469
 
@@ -5,6 +5,7 @@ import {
5
5
  AccountStatus,
6
6
  AccountZod,
7
7
  IPaginationMeta,
8
+ StringToBooleanSchema,
8
9
  UrlSchema,
9
10
  } from './common.types';
10
11
  import { accountIdSchema } from './account.types';
@@ -73,15 +74,7 @@ export const SitesParamSchema = z.object({
73
74
  export const SitesFiltersZod = z.object({
74
75
  url: z.string().optional(),
75
76
  accountId: accountIdSchema.optional(),
76
- enabled: z.preprocess(
77
- (val) =>
78
- val === 'true' || val === '1'
79
- ? true
80
- : val === 'false' || val === '0'
81
- ? false
82
- : val,
83
- z.boolean().optional(),
84
- ),
77
+ enabled: StringToBooleanSchema.optional(),
85
78
  });
86
79
 
87
80
  const sitesInclude = z.enum(['account']);