@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,588 @@
1
+ import { z } from 'zod';
2
+ import { PersonaStatus } from './common.types';
3
+
4
+ export const WebhookReceived = z.object({
5
+ received: z.boolean(),
6
+ });
7
+ export type WebhookReceived = z.infer<typeof WebhookReceived>;
8
+
9
+ // https://docs.stripe.com/api/events/object
10
+ export const StripeWebhookEvent = z.object({
11
+ id: z.string().nullable().optional(),
12
+ object: z.string().nullable().optional(),
13
+ account: z.string().nullable().optional(),
14
+ api_version: z.string().nullable().optional(),
15
+ created: z.number().nullable().optional(),
16
+ data: z
17
+ .object({
18
+ object: z
19
+ .object({
20
+ id: z.string().nullable().optional(),
21
+ object: z.string().nullable().optional(),
22
+ application: z.string().nullable().optional(),
23
+ automatic_payment_methods: z
24
+ .object({
25
+ allow_redirects: z.string().nullable().optional(),
26
+ enabled: z.boolean().nullable().optional(),
27
+ })
28
+ .nullable()
29
+ .optional(),
30
+ cancellation_reason: z.string().nullable().optional(),
31
+ client_secret: z.string().nullable().optional(),
32
+ created: z.number().nullable().optional(),
33
+ customer: z.string().nullable().optional(),
34
+ description: z.string().nullable().optional(),
35
+ flow_directions: z.string().nullable().optional(),
36
+ last_setup_error: z.object({}).nullable().optional(),
37
+ latest_attempt: z.string().nullable().optional(),
38
+ livemode: z.boolean().nullable().optional(),
39
+ mandate: z.string().nullable().optional(),
40
+ metadata: z.record(z.any()).nullable().optional(),
41
+ next_action: z.string().nullable().optional(),
42
+ on_behalf_of: z.string().nullable().optional(),
43
+ payment_method: z.string().nullable().optional(),
44
+ payment_method_options: z
45
+ .object({
46
+ acss_debit: z
47
+ .object({
48
+ currency: z.string().nullable().optional(),
49
+ mandate_options: z
50
+ .object({
51
+ interval_description: z.string().nullable().optional(),
52
+ payment_schedule: z.string().nullable().optional(),
53
+ transaction_type: z.string().nullable().optional(),
54
+ })
55
+ .nullable()
56
+ .optional(),
57
+ verification_method: z.string().nullable().optional(),
58
+ })
59
+ .nullable()
60
+ .optional(),
61
+ card: z
62
+ .object({
63
+ installments: z.any().nullable().optional(),
64
+ mandate_options: z.any().nullable().optional(),
65
+ network: z.string().nullable().optional(),
66
+ request_three_d_secure: z.string().nullable().optional(),
67
+ })
68
+ .nullable()
69
+ .optional(),
70
+ link: z
71
+ .object({
72
+ persistent_token: z.string().nullable().optional(),
73
+ })
74
+ .nullable()
75
+ .optional(),
76
+ us_bank_account: z
77
+ .object({
78
+ financial_connections: z
79
+ .object({
80
+ permissions: z.array(z.string()).nullable().optional(),
81
+ prefetch: z.array(z.string()).nullable().optional(),
82
+ })
83
+ .nullable()
84
+ .optional(),
85
+ mandate_options: z.record(z.any()).nullable().optional(),
86
+ verification_method: z.string().nullable().optional(),
87
+ })
88
+ .nullable()
89
+ .optional(),
90
+ })
91
+ .nullable()
92
+ .optional(),
93
+ payment_method_types: z.array(z.string()).nullable().optional(),
94
+ single_use_mandate: z.string().nullable().optional(),
95
+ status: z.string().nullable().optional(),
96
+ usage: z.string().nullable().optional(),
97
+ amount: z.number().nullable().optional(),
98
+ amount_capturable: z.number().nullable().optional(),
99
+ amount_details: z.record(z.any()).nullable().optional(),
100
+ amount_received: z.number().nullable().optional(),
101
+ application_fee_amount: z.number().nullable().optional(),
102
+ canceled_at: z.number().nullable().optional(),
103
+ capture_method: z.string().nullable().optional(),
104
+ confirmation_method: z.string().nullable().optional(),
105
+ currency: z.string().nullable().optional(),
106
+ invoice: z.string().nullable().optional(),
107
+ last_payment_error: z.record(z.any()).nullable().optional(),
108
+ latest_charge: z.string().nullable().optional(),
109
+ payment_method_configuration_details: z
110
+ .object({
111
+ id: z.string().nullable().optional(),
112
+ parent: z.string().nullable().optional(),
113
+ })
114
+ .nullable()
115
+ .optional(),
116
+ processing: z.record(z.any()).nullable().optional(),
117
+ receipt_email: z.string().nullable().optional(),
118
+ review: z.string().nullable().optional(),
119
+ setup_future_usage: z.string().nullable().optional(),
120
+ shipping: z.record(z.any()).nullable().optional(),
121
+ source: z.string().nullable().optional(),
122
+ statement_descriptor: z.string().nullable().optional(),
123
+ statement_descriptor_suffix: z.string().nullable().optional(),
124
+ transfer_data: z.record(z.any()).nullable().optional(),
125
+ transfer_group: z.string().nullable().optional(),
126
+ })
127
+ .nullable()
128
+ .optional(),
129
+ })
130
+ .nullable()
131
+ .optional(),
132
+ livemode: z.boolean().nullable().optional(),
133
+ pending_webhooks: z.number().nullable().optional(),
134
+ request: z
135
+ .object({
136
+ id: z.string().nullable().optional(),
137
+ idempotency_key: z.string().nullable().optional(),
138
+ })
139
+ .nullable()
140
+ .optional(),
141
+ type: z.string().nullable().optional(),
142
+ context: z.string().nullable().optional(),
143
+ });
144
+ export type StripeWebhookEvent = z.infer<typeof StripeWebhookEvent>;
145
+
146
+ /**
147
+ * BoldSign webhook event structure
148
+ * @see https://developers.boldsign.com/webhooks/sample-event-data/?region=us
149
+ *
150
+ * Event types include:
151
+ * - Signed: When a signer completes signing
152
+ * - Declined: When a signer declines to sign
153
+ * - SenderIdentityVerified: When a sender identity is verified
154
+ * - SenderIdentityDenied: When a sender identity is denied
155
+ * - SenderIdentityRevoked: When a sender identity is revoked
156
+ * - SenderIdentityDeleted: When a sender identity is deleted
157
+ */
158
+ export const BoldsignWebhookEvent = z.object({
159
+ event: z.object({
160
+ id: z.string().optional(),
161
+ eventType: z.string(),
162
+ created: z.number().optional(),
163
+ clientId: z.string().optional(),
164
+ environment: z.string().optional(),
165
+ }),
166
+ data: z.object({
167
+ object: z.string().optional(),
168
+ documentId: z.string().optional(),
169
+ messageTitle: z.string().optional(),
170
+ documentDescription: z.string().optional(),
171
+ status: z.string().optional(),
172
+ email: z.string().optional(), // For SenderIdentity events
173
+ senderDetail: z
174
+ .object({
175
+ name: z.string().optional(),
176
+ emailAddress: z.string().optional(),
177
+ })
178
+ .optional(),
179
+ signerDetails: z
180
+ .array(
181
+ z.object({
182
+ signerName: z.string().optional(),
183
+ signerRole: z.string().optional(),
184
+ signerEmail: z.string().optional(),
185
+ status: z.string().optional(),
186
+ signerOrder: z.number().optional(),
187
+ formFields: z
188
+ .array(
189
+ z.object({
190
+ id: z.string().optional(),
191
+ name: z.string().optional(),
192
+ fieldType: z.string().optional(),
193
+ value: z.any().optional(),
194
+ isRequired: z.boolean().optional(),
195
+ }),
196
+ )
197
+ .optional(),
198
+ }),
199
+ )
200
+ .optional(),
201
+ metaData: z.record(z.string(), z.any()).optional(),
202
+ }),
203
+ });
204
+ export type BoldsignWebhookEvent = z.infer<typeof BoldsignWebhookEvent>;
205
+
206
+ /**
207
+ * Sample event data:
208
+ * https://docs.withpersona.com/docs/webhooks
209
+ * We are only interested in the inquiry and inquiry session events
210
+ * because we subscribe only to inquiry events
211
+ * https://docs.withpersona.com/docs/events
212
+ */
213
+ const fieldValueSchema = z.object({
214
+ type: z.string(),
215
+ value: z.any().optional(),
216
+ });
217
+
218
+ const behaviorsSchema = z.object({
219
+ 'autofill-cancels': z.number().nullable().optional(),
220
+ 'autofill-starts': z.number().nullable().optional(),
221
+ 'completion-time': z.number().nullable().optional(),
222
+ 'devtools-open': z.boolean().nullable().optional(),
223
+ 'distraction-events': z.number().nullable().optional(),
224
+ 'hesitation-baseline': z.number().nullable().optional(),
225
+ 'hesitation-count': z.number().nullable().optional(),
226
+ 'hesitation-percentage': z.number().nullable().optional(),
227
+ 'hesitation-time': z.number().nullable().optional(),
228
+ 'request-spoof-attempts': z.number().nullable().optional(),
229
+ 'shortcut-copies': z.number().nullable().optional(),
230
+ 'shortcut-pastes': z.number().nullable().optional(),
231
+ 'user-agent-spoof-attempts': z.number().nullable().optional(),
232
+ 'behavior-threat-level': z.string().nullable().optional(),
233
+ });
234
+
235
+ const relationshipDataSchema = z.object({
236
+ type: z.string(),
237
+ id: z.string(),
238
+ });
239
+
240
+ const relationshipSchema = z.object({
241
+ data: z.union([relationshipDataSchema, z.null()]),
242
+ });
243
+
244
+ const inquiryAttributesSchema = z
245
+ .object({
246
+ behaviors: behaviorsSchema.optional(),
247
+ fields: z.record(fieldValueSchema).optional(),
248
+ status: z.nativeEnum(PersonaStatus),
249
+ 'reference-id': z.string().nullable().optional(),
250
+ note: z.string().nullable().optional(),
251
+ creator: z.string().nullable().optional(),
252
+ 'reviewer-comment': z.string().nullable().optional(),
253
+ 'created-at': z.string().datetime().nullable().optional(),
254
+ 'started-at': z.string().datetime().nullable().optional(),
255
+ 'expires-at': z.string().datetime().nullable().optional(),
256
+ 'completed-at': z.string().datetime().nullable().optional(),
257
+ 'failed-at': z.string().datetime().nullable().optional(),
258
+ 'marked-for-review-at': z.string().datetime().nullable().optional(),
259
+ 'decisioned-at': z.string().datetime().nullable().optional(),
260
+ 'expired-at': z.string().datetime().nullable().optional(),
261
+ 'redacted-at': z.string().datetime().nullable().optional(),
262
+ 'updated-at': z.string().datetime().nullable().optional(),
263
+ 'previous-step-name': z.string().nullable().optional(),
264
+ 'next-step-name': z.string().nullable().optional(),
265
+ 'name-first': z.string().nullable().optional(),
266
+ 'name-middle': z.string().nullable().optional(),
267
+ 'name-last': z.string().nullable().optional(),
268
+ birthdate: z.string().nullable().optional(),
269
+ 'address-street-1': z.string().nullable().optional(),
270
+ 'address-street-2': z.string().nullable().optional(),
271
+ 'address-city': z.string().nullable().optional(),
272
+ 'address-subdivision': z.string().nullable().optional(),
273
+ 'address-subdivision-abbr': z.string().nullable().optional(),
274
+ 'address-postal-code': z.string().nullable().optional(),
275
+ 'address-postal-code-abbr': z.string().nullable().optional(),
276
+ 'social-security-number': z.string().nullable().optional(),
277
+ 'identification-number': z.string().nullable().optional(),
278
+ 'email-address': z.string().nullable().optional(),
279
+ 'phone-number': z.string().nullable().optional(),
280
+ tags: z.array(z.string()).nullable().optional(),
281
+ })
282
+ .passthrough();
283
+
284
+ const accountFieldsSchema = z.object({
285
+ name: z.object({
286
+ type: z.string(),
287
+ value: z.object({
288
+ first: fieldValueSchema,
289
+ middle: fieldValueSchema,
290
+ last: fieldValueSchema,
291
+ }),
292
+ }),
293
+ address: z.object({
294
+ type: z.string(),
295
+ value: z.object({
296
+ street_1: fieldValueSchema,
297
+ street_2: fieldValueSchema,
298
+ city: fieldValueSchema,
299
+ subdivision: fieldValueSchema,
300
+ postal_code: fieldValueSchema,
301
+ country_code: fieldValueSchema,
302
+ }),
303
+ }),
304
+ identification_numbers: z.object({
305
+ type: z.string(),
306
+ value: z.array(z.any()),
307
+ }),
308
+ birthdate: fieldValueSchema,
309
+ phone_number: fieldValueSchema,
310
+ email_address: fieldValueSchema,
311
+ selfie_photo: fieldValueSchema,
312
+ });
313
+
314
+ const accountSchema = z.object({
315
+ type: z.string(),
316
+ id: z.string(),
317
+ attributes: z.object({
318
+ 'reference-id': z.string().optional(),
319
+ 'created-at': z.string().datetime().optional(),
320
+ 'updated-at': z.string().datetime().optional(),
321
+ 'redacted-at': z.string().datetime().optional(),
322
+ 'account-type-name': z.string().optional(),
323
+ fields: accountFieldsSchema,
324
+ 'name-first': z.string().optional(),
325
+ 'name-middle': z.string().optional(),
326
+ 'name-last': z.string().optional(),
327
+ 'social-security-number': z.string().optional(),
328
+ 'address-street-1': z.string().optional(),
329
+ 'address-street-2': z.string().optional(),
330
+ 'address-city': z.string().optional(),
331
+ 'address-subdivision': z.string().optional(),
332
+ 'address-postal-code': z.string().optional(),
333
+ 'country-code': z.string().optional(),
334
+ birthdate: z.string().optional(),
335
+ 'phone-number': z.string().optional(),
336
+ 'email-address': z.string().optional(),
337
+ tags: z.array(z.string()).optional(),
338
+ 'identification-numbers': z.record(z.any()).optional(),
339
+ }),
340
+ relationships: z.object({
341
+ 'account-type': relationshipSchema.optional(),
342
+ }),
343
+ });
344
+
345
+ const inquiryRelationshipsSchema = z.object({
346
+ account: relationshipSchema.optional(),
347
+ template: relationshipSchema.optional(),
348
+ 'inquiry-template': relationshipSchema.optional(),
349
+ 'inquiry-template-version': relationshipSchema.optional(),
350
+ transaction: relationshipSchema.optional(),
351
+ reviewer: relationshipSchema.optional(),
352
+ reports: z.object({ data: z.array(z.any()) }).optional(),
353
+ verifications: z.object({ data: z.array(z.any()) }).optional(),
354
+ sessions: z.object({ data: z.array(z.any()) }).optional(),
355
+ documents: z.object({ data: z.array(z.any()) }).optional(),
356
+ selfies: z.object({ data: z.array(z.any()) }).optional(),
357
+ });
358
+
359
+ const inquirySchema = z.object({
360
+ type: z.string(),
361
+ id: z.string(),
362
+ attributes: inquiryAttributesSchema.optional(),
363
+ relationships: inquiryRelationshipsSchema.partial().optional(),
364
+ });
365
+
366
+ const inquiryTemplateSchema = z.object({
367
+ type: z.literal('inquiry-template'),
368
+ id: z.string(),
369
+ attributes: z.object({
370
+ status: z.string(),
371
+ name: z.string(),
372
+ }),
373
+ relationships: z.object({
374
+ 'latest-published-version': relationshipSchema.optional(),
375
+ }),
376
+ });
377
+
378
+ const genericIncludedItemSchema = z.object({
379
+ type: z.string(),
380
+ id: z.string(),
381
+ attributes: z.record(z.any()).optional(),
382
+ relationships: z.record(z.any()).optional(),
383
+ });
384
+
385
+ const userSchema = z.object({
386
+ type: z.string(),
387
+ id: z.string(),
388
+ attributes: z.record(z.any()).optional(),
389
+ relationships: z.record(z.any()).optional(),
390
+ });
391
+
392
+ const inquiryTemplateVersionSchema = z.object({
393
+ type: z.literal('inquiry-template-version'),
394
+ id: z.string(),
395
+ attributes: z.object({
396
+ 'name-display': z.string().optional(),
397
+ status: z.string().optional(),
398
+ 'enabled-locales': z.array(z.string()).optional(),
399
+ 'created-at': z.string().datetime().optional(),
400
+ 'updated-at': z.string().datetime().optional(),
401
+ 'published-at': z.string().datetime().optional(),
402
+ theme: z.record(z.any()).optional(),
403
+ }),
404
+ relationships: z.object({
405
+ 'inquiry-template': relationshipSchema,
406
+ }),
407
+ });
408
+
409
+ // Schemas for Government ID Verification for Persona
410
+ //https://docs.withpersona.com/reference/retrieve-a-government-id-verification
411
+ const photoUrlSchema = z
412
+ .object({
413
+ page: z.string().optional(),
414
+ url: z.string().url().optional(),
415
+ 'normalized-url': z.string().url().optional(),
416
+ 'original-urls': z.array(z.string().url()).optional(),
417
+ 'byte-size': z.number().optional(),
418
+ })
419
+ .optional();
420
+ export type PhotoUrlSchema = z.infer<typeof photoUrlSchema>;
421
+
422
+ const NormalizedPhotoUrlSchema = z
423
+ .object({
424
+ page: z.string().optional(),
425
+ url: z.string().url().optional(),
426
+ normalizedUrl: z.string().url().optional(),
427
+ originalUrls: z.array(z.string().url()).optional(),
428
+ byteSize: z.number().optional(),
429
+ })
430
+ .optional();
431
+ export type NormalizedPhotoUrlSchema = z.infer<typeof NormalizedPhotoUrlSchema>;
432
+
433
+ // Selfie photo schema
434
+ const selfiePhotoSchema = z
435
+ .object({
436
+ url: z.string().url().optional(),
437
+ 'byte-size': z.number().optional(),
438
+ })
439
+ .optional();
440
+
441
+ // Attributes schema
442
+ export const attributesSchema = z
443
+ .object({
444
+ status: z.string().optional(),
445
+ 'created-at': z.string().datetime().optional(),
446
+ 'created-at-ts': z.number().int().optional(),
447
+ 'submitted-at': z.string().datetime().optional(),
448
+ 'submitted-at-ts': z.number().int().optional(),
449
+ 'completed-at': z.string().datetime().optional(),
450
+ 'completed-at-ts': z.number().int().optional(),
451
+ 'country-code': z.string().optional(),
452
+ checks: z.array(z.unknown()).optional(),
453
+ 'entity-confidence-score': z.number().optional(),
454
+ 'entity-confidence-reasons': z.array(z.string()).optional(),
455
+ 'front-photo-url': z.string().url().optional(),
456
+ 'back-photo-url': z.null().optional(),
457
+ 'photo-urls': z.array(photoUrlSchema).optional(),
458
+ 'selfie-photo': selfiePhotoSchema.optional(),
459
+ 'selfie-photo-url': z.string().url().optional(),
460
+ 'video-url': z.null().optional(),
461
+ 'id-class': z.string().optional(),
462
+ 'capture-method': z.string().optional(),
463
+ 'name-first': z.string().optional(),
464
+ 'name-middle': z.string().optional(),
465
+ 'name-last': z.string().optional(),
466
+ 'name-suffix': z.null().optional(),
467
+ birthdate: z.string().optional(),
468
+ 'address-street-1': z.string().optional(),
469
+ 'address-street-2': z.null().optional(),
470
+ 'address-city': z.string().optional(),
471
+ 'address-subdivision': z.string().optional(),
472
+ 'address-postal-code': z.string().optional(),
473
+ 'issuing-authority': z.null().optional(),
474
+ 'issuing-subdivision': z.string().optional(),
475
+ nationality: z.null().optional(),
476
+ 'document-number': z.null().optional(),
477
+ 'visa-status': z.null().optional(),
478
+ 'issue-date': z.string().optional(),
479
+ 'expiration-date': z.string().optional(),
480
+ designations: z.array(z.unknown()).optional(),
481
+ birthplace: z.null().optional(),
482
+ endorsements: z.null().optional(),
483
+ height: z.null().optional(),
484
+ sex: z.null().optional(),
485
+ restrictions: z.null().optional(),
486
+ 'vehicle-class': z.null().optional(),
487
+ 'identification-number': z.string().optional(),
488
+ 'from-reusable-persona': z.boolean().optional(),
489
+ })
490
+ .optional();
491
+
492
+ export type AttributesSchema = z.infer<typeof attributesSchema>;
493
+
494
+ // Relationship with data schema
495
+ const relationshipWithDataSchema = z
496
+ .object({
497
+ data: relationshipDataSchema.optional(),
498
+ })
499
+ .optional();
500
+
501
+ // Relationship with null data schema
502
+ const relationshipWithNullDataSchema = z
503
+ .object({
504
+ data: z.null().optional(),
505
+ })
506
+ .optional();
507
+
508
+ // Relationships schema
509
+ const relationshipsSchema = z
510
+ .object({
511
+ inquiry: relationshipWithDataSchema.optional(),
512
+ template: relationshipWithNullDataSchema.optional(),
513
+ 'inquiry-template-version': relationshipWithDataSchema.optional(),
514
+ 'inquiry-template': relationshipWithDataSchema.optional(),
515
+ transaction: relationshipWithNullDataSchema.optional(),
516
+ 'verification-template': relationshipWithDataSchema.optional(),
517
+ 'verification-template-version': relationshipWithDataSchema.optional(),
518
+ document: relationshipWithDataSchema.optional(),
519
+ })
520
+ .optional();
521
+
522
+ // Verification Data schema
523
+ const verificationDataSchema = z
524
+ .object({
525
+ type: z.string().optional(),
526
+ id: z.string().optional(),
527
+ attributes: attributesSchema.optional(),
528
+ relationships: relationshipsSchema.optional(),
529
+ })
530
+ .optional();
531
+ export type VerificationDataSchema = z.infer<typeof verificationDataSchema>;
532
+
533
+ export const PersonaWebhookEvent = z.object({
534
+ data: z.object({
535
+ type: z.string(),
536
+ id: z.string(),
537
+ attributes: z.object({
538
+ name: z.enum([
539
+ 'inquiry.created',
540
+ 'inquiry.started',
541
+ 'inquiry.expired',
542
+ 'inquiry.completed',
543
+ 'inquiry.failed',
544
+ 'inquiry.marked-for-review',
545
+ 'inquiry.approved',
546
+ 'inquiry.declined',
547
+ 'inquiry.redacted',
548
+ 'inquiry.transitioned',
549
+ 'inquiry-session.started',
550
+ 'inquiry-session.expired',
551
+ 'inquiry-session.canceled',
552
+ 'inquiry.reusable-persona-created',
553
+ 'inquiry.reusable-persona-updated',
554
+ 'inquiry.reusable-persona-deleted',
555
+ 'inquiry-template-version.created',
556
+ 'inquiry-template-version.updated',
557
+ 'inquiry-template-version.deleted',
558
+ 'inquiry-template-version.published',
559
+ ]),
560
+ payload: z.object({
561
+ data: inquirySchema,
562
+ included: z.array(
563
+ z.union([
564
+ inquirySchema,
565
+ accountSchema,
566
+ inquiryTemplateSchema,
567
+ inquiryTemplateVersionSchema,
568
+ verificationDataSchema,
569
+ genericIncludedItemSchema,
570
+ userSchema,
571
+ ]),
572
+ ),
573
+ }),
574
+ 'created-at': z.string().datetime(),
575
+ }),
576
+ }),
577
+ });
578
+
579
+ export type PersonaWebhookEvent = z.infer<typeof PersonaWebhookEvent>;
580
+
581
+ // Root schema
582
+ const PersonsGovernmentIdVerification = z.object({
583
+ data: verificationDataSchema.optional(),
584
+ });
585
+
586
+ export type PersonsGovernmentIdVerification = z.infer<
587
+ typeof PersonsGovernmentIdVerification
588
+ >;
@@ -0,0 +1,36 @@
1
+ import { z } from 'zod';
2
+ import { validateCanadaZipCode, validateUSZipCode } from './contract-helpers';
3
+ import { CountryCode, CountryEnumSchema } from './countries.types';
4
+
5
+ export function refineAddressZip(
6
+ country: string | undefined | null,
7
+ zip: string | undefined | null,
8
+ ) {
9
+ return country === CountryCode['US']
10
+ ? !zip || validateUSZipCode(zip)
11
+ : country === CountryCode['CA']
12
+ ? !zip || validateCanadaZipCode(zip) // it's optional, so if nullish, it's valid
13
+ : z.string().min(2).max(10).nullable().optional().safeParse(zip).success;
14
+ }
15
+
16
+ export const ZipSchema = z.string();
17
+
18
+ export const CountryZipSchema = z
19
+ .object({
20
+ country: CountryEnumSchema.nullable().optional(),
21
+ zip: ZipSchema.nullable().optional(),
22
+ })
23
+ .refine(({ zip, country }) => refineAddressZip(country, zip), {
24
+ message:
25
+ 'zip value is not valid, it shall follow the US(12345 or 12345-6789), CANADA(A1A 1A1) format! it shall be a string for other states',
26
+ });
27
+
28
+ export const RequiredCountryZipSchema = z
29
+ .object({
30
+ country: CountryEnumSchema,
31
+ zip: ZipSchema,
32
+ })
33
+ .refine(({ zip, country }) => refineAddressZip(country, zip), {
34
+ message:
35
+ 'zip value is not valid, it shall follow the US(12345 or 12345-6789), CANADA(A1A 1A1) format! it shall be a string for other states',
36
+ });
@@ -0,0 +1,61 @@
1
+ import { initContract } from '@ts-rest/core';
2
+ import {
3
+ ForbiddenError,
4
+ IPaginatedAccount,
5
+ NotFoundError,
6
+ PaginationOptionsZod,
7
+ UnauthorizedError,
8
+ AccountFiltersZod,
9
+ AccountsIncludeQuery,
10
+ AccountZod,
11
+ accountIdSchema,
12
+ InternalError,
13
+ } from '../../../common/types';
14
+ import { z } from 'zod';
15
+
16
+ const c = initContract();
17
+
18
+ export const accountsContract = c.router(
19
+ {
20
+ getAccount: {
21
+ summary: 'Get account by id',
22
+ method: 'GET',
23
+ path: '/:id',
24
+ metadata: {
25
+ auth: true,
26
+ },
27
+ query: z.object({}).merge(AccountsIncludeQuery),
28
+ pathParams: z.object({
29
+ id: accountIdSchema,
30
+ }),
31
+ responses: {
32
+ 200: AccountZod,
33
+ 401: UnauthorizedError,
34
+ 403: ForbiddenError,
35
+ 404: NotFoundError,
36
+ 500: InternalError,
37
+ },
38
+ },
39
+ getAccounts: {
40
+ summary: 'Get accounts',
41
+ method: 'GET',
42
+ path: '',
43
+ metadata: {
44
+ auth: true,
45
+ },
46
+ query:
47
+ PaginationOptionsZod.merge(AccountFiltersZod).merge(
48
+ AccountsIncludeQuery,
49
+ ),
50
+ responses: {
51
+ 200: IPaginatedAccount,
52
+ 401: UnauthorizedError,
53
+ 403: ForbiddenError,
54
+ 500: InternalError,
55
+ },
56
+ },
57
+ },
58
+ {
59
+ pathPrefix: 'accounts',
60
+ },
61
+ );