pecunia-core 0.0.0

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.
@@ -0,0 +1,3677 @@
1
+ import { C as ScheduleStatus, D as TransactionStatus, E as SubscriptionStatus, M as WebHookEventStatus, O as TransactionType, S as ProrationBehavior, T as ScheduledTaskType, _ as PaymentIntentStatus, b as PricingModel, c as BillingInterval, d as CollectionMethod, f as Currency, h as InvoiceStatus, j as WebHookDeliveryTrigger, k as UsageAction, l as CheckoutSessionMode, n as PecuniaError, o as Actor, s as AuditAction, u as CheckoutSessionStatus, v as PaymentProviders, w as ScheduledTaskStatus, y as PriceType } from "./errors-vpD21Iku.mjs";
2
+ import { t as generateId } from "./generate-id-D3ZvbbXn.mjs";
3
+ import { z } from "zod";
4
+
5
+ //#region src/db/attributes/get-default-model-name.ts
6
+ const initGetDefaultModelName = ({ usePlural, schema }) => {
7
+ /**
8
+ * This function helps us get the default model name from the schema defined by devs.
9
+ * Often times, the user will be using the `modelName` which could had been customized by the users.
10
+ * This function helps us get the actual model name useful to match against the schema. (eg: schema[model])
11
+ *
12
+ * If it's still unclear what this does:
13
+ *
14
+ * 1. User can define a custom modelName.
15
+ * 2. When using a custom modelName, doing something like `schema[model]` will not work.
16
+ * 3. Using this function helps us get the actual model name based on the user's defined custom modelName.
17
+ */
18
+ const getDefaultModelName = (model) => {
19
+ if (usePlural && model.charAt(model.length - 1) === "s") {
20
+ let pluralessModel = model.slice(0, -1);
21
+ let m$1 = schema[pluralessModel] ? pluralessModel : void 0;
22
+ if (!m$1) m$1 = Object.entries(schema).find(([_, f]) => f.modelName === pluralessModel)?.[0];
23
+ if (m$1) return m$1;
24
+ }
25
+ let m = schema[model] ? model : void 0;
26
+ if (!m) m = Object.entries(schema).find(([_, f]) => f.modelName === model)?.[0];
27
+ if (!m) throw new PecuniaError(`Model "${model}" not found in schema`);
28
+ return m;
29
+ };
30
+ return getDefaultModelName;
31
+ };
32
+
33
+ //#endregion
34
+ //#region src/db/attributes/get-default-field-name.ts
35
+ const initGetDefaultFieldName = ({ schema, usePlural }) => {
36
+ const getDefaultModelName = initGetDefaultModelName({
37
+ schema,
38
+ usePlural
39
+ });
40
+ /**
41
+ * This function helps us get the default field name from the schema defined by devs.
42
+ * Often times, the user will be using the `fieldName` which could had been customized by the users.
43
+ * This function helps us get the actual field name useful to match against the schema. (eg: schema[model].fields[field])
44
+ *
45
+ * If it's still unclear what this does:
46
+ *
47
+ * 1. User can define a custom fieldName.
48
+ * 2. When using a custom fieldName, doing something like `schema[model].fields[field]` will not work.
49
+ */
50
+ const getDefaultFieldName = ({ field, model: unsafeModel }) => {
51
+ if (field === "id" || field === "_id") return "id";
52
+ const model = getDefaultModelName(unsafeModel);
53
+ let f = schema[model]?.fields[field];
54
+ if (!f) {
55
+ const result = Object.entries(schema[model].fields).find(([_, f$1]) => f$1.fieldName === field);
56
+ if (result) {
57
+ f = result[1];
58
+ field = result[0];
59
+ }
60
+ }
61
+ if (!f) throw new PecuniaError(`Field ${field} not found in model ${model}`);
62
+ return field;
63
+ };
64
+ return getDefaultFieldName;
65
+ };
66
+
67
+ //#endregion
68
+ //#region src/db/attributes/get-id-field.ts
69
+ const initGetIdField = () => {
70
+ const idField = () => {
71
+ return {
72
+ type: "string",
73
+ required: true,
74
+ defaultValue: () => generateId(),
75
+ transform: {
76
+ input: (value) => {
77
+ if (!value) return void 0;
78
+ return value;
79
+ },
80
+ output: (value) => {
81
+ if (!value) return void 0;
82
+ return String(value);
83
+ }
84
+ }
85
+ };
86
+ };
87
+ return idField;
88
+ };
89
+
90
+ //#endregion
91
+ //#region src/db/attributes/get-field-attributes.ts
92
+ const initGetFieldAttributes = ({ usePlural, schema }) => {
93
+ const getDefaultModelName = initGetDefaultModelName({
94
+ usePlural,
95
+ schema
96
+ });
97
+ const getDefaultFieldName = initGetDefaultFieldName({
98
+ usePlural,
99
+ schema
100
+ });
101
+ const idField = initGetIdField();
102
+ const getFieldAttributes = ({ model, field }) => {
103
+ const defaultModelName = getDefaultModelName(model);
104
+ const defaultFieldName = getDefaultFieldName({
105
+ field,
106
+ model: defaultModelName
107
+ });
108
+ const fields = schema[defaultModelName].fields;
109
+ fields.id = idField();
110
+ const fieldAttributes = fields[defaultFieldName];
111
+ if (!fieldAttributes) throw new PecuniaError(`Field ${field} not found in model ${model}`);
112
+ return fieldAttributes;
113
+ };
114
+ return getFieldAttributes;
115
+ };
116
+
117
+ //#endregion
118
+ //#region src/db/attributes/get-model-name.ts
119
+ const initGetModelName = ({ usePlural, schema }) => {
120
+ const getDefaultModelName = initGetDefaultModelName({
121
+ schema,
122
+ usePlural
123
+ });
124
+ /**
125
+ * Users can overwrite the default model of some tables. This function helps find the correct model name.
126
+ * Furthermore, if the user passes `usePlural` as true in their adapter config,
127
+ * then we should return the model name ending with an `s`.
128
+ */
129
+ const getModelName = (model) => {
130
+ const defaultModelKey = getDefaultModelName(model);
131
+ if (schema && schema[defaultModelKey] && schema[defaultModelKey].modelName !== model) return usePlural ? `${schema[defaultModelKey].modelName}s` : schema[defaultModelKey].modelName;
132
+ return usePlural ? `${model}s` : model;
133
+ };
134
+ return getModelName;
135
+ };
136
+
137
+ //#endregion
138
+ //#region src/db/utils/with-apply-default.ts
139
+ function withApplyDefault(value, field, action) {
140
+ if (action === "update") {
141
+ if (value === void 0 && field.onUpdate !== void 0) {
142
+ if (typeof field.onUpdate === "function") return field.onUpdate();
143
+ return field.onUpdate;
144
+ }
145
+ return value;
146
+ }
147
+ if (action === "create") {
148
+ if (value === void 0 || field.required === true && value === null) {
149
+ if (field.defaultValue !== void 0) {
150
+ if (typeof field.defaultValue === "function") return field.defaultValue();
151
+ return field.defaultValue;
152
+ }
153
+ }
154
+ }
155
+ return value;
156
+ }
157
+ function isObject(item) {
158
+ return item !== null && typeof item === "object" && !Array.isArray(item);
159
+ }
160
+ function deepmerge(target, source) {
161
+ if (Array.isArray(target) && Array.isArray(source)) return [...target, ...source];
162
+ else if (isObject(target) && isObject(source)) {
163
+ const result = { ...target };
164
+ for (const [key, value] of Object.entries(source)) {
165
+ if (value === void 0) continue;
166
+ if (key in target) result[key] = deepmerge(target[key], value);
167
+ else result[key] = value;
168
+ }
169
+ return result;
170
+ }
171
+ return source;
172
+ }
173
+
174
+ //#endregion
175
+ //#region src/db/get-payment-tables.ts
176
+ const getPaymentTables = (options) => {
177
+ const { customer, idempotency_key, payment_method, product, price, usageRecord, subscription, subscriptionItem, subscriptionSchedule, invoice, invoiceItem, webHookEndpoint, webHookDelivery, event, sessionEvent, checkoutSession, paymentIntent, transaction, scheduledTask, auditLog, ...pluginTables } = (options.plugins ?? []).reduce((acc, plugin) => {
178
+ const schema = plugin.schema;
179
+ if (!schema) return acc;
180
+ for (const [key, value] of Object.entries(schema)) acc[key] = {
181
+ fields: {
182
+ ...acc[key]?.fields,
183
+ ...value.fields
184
+ },
185
+ modelName: value.modelName || key
186
+ };
187
+ return acc;
188
+ }, {});
189
+ return {
190
+ customer: {
191
+ modelName: "customer",
192
+ fields: {
193
+ id: {
194
+ type: "string",
195
+ required: true,
196
+ fieldName: "id",
197
+ unique: true,
198
+ sortable: true
199
+ },
200
+ phoneNumber: {
201
+ type: "string",
202
+ required: true,
203
+ fieldName: "phoneNumber",
204
+ sortable: true
205
+ },
206
+ firstName: {
207
+ type: "string",
208
+ required: true,
209
+ fieldName: "firstName",
210
+ sortable: true
211
+ },
212
+ lastName: {
213
+ type: "string",
214
+ required: true,
215
+ fieldName: "lastName",
216
+ sortable: true
217
+ },
218
+ email: {
219
+ type: "string",
220
+ required: true,
221
+ fieldName: "email",
222
+ sortable: true,
223
+ unique: true
224
+ },
225
+ paymentMethodId: {
226
+ type: "uuid",
227
+ required: false,
228
+ fieldName: "paymentMethodId",
229
+ references: {
230
+ model: "payment_methods",
231
+ field: "id",
232
+ onDelete: "set null"
233
+ },
234
+ validator: {
235
+ input: z.uuid().optional(),
236
+ output: z.uuid().optional()
237
+ },
238
+ index: true
239
+ },
240
+ createdAt: {
241
+ type: "date",
242
+ required: true,
243
+ fieldName: "createdAt",
244
+ defaultValue: () => /* @__PURE__ */ new Date(),
245
+ sortable: true,
246
+ input: false,
247
+ returned: true,
248
+ validator: { output: z.date() }
249
+ },
250
+ updatedAt: {
251
+ type: "date",
252
+ required: true,
253
+ fieldName: "updatedAt",
254
+ defaultValue: () => /* @__PURE__ */ new Date(),
255
+ onUpdate: () => /* @__PURE__ */ new Date(),
256
+ sortable: true,
257
+ input: false,
258
+ returned: true,
259
+ validator: { output: z.date() }
260
+ },
261
+ ...customer?.fields
262
+ },
263
+ relations: {
264
+ paymentMethods: {
265
+ kind: "many",
266
+ model: "payment_methods",
267
+ foreignKey: "customerId"
268
+ },
269
+ paymentIntents: {
270
+ kind: "many",
271
+ model: "payment_intent",
272
+ foreignKey: "customerId"
273
+ },
274
+ subscriptions: {
275
+ kind: "many",
276
+ model: "subscription",
277
+ foreignKey: "customerId"
278
+ },
279
+ invoices: {
280
+ kind: "many",
281
+ model: "invoice",
282
+ foreignKey: "customerId"
283
+ },
284
+ transactions: {
285
+ kind: "many",
286
+ model: "transactions",
287
+ foreignKey: "customerId"
288
+ },
289
+ defaultPaymentMethod: {
290
+ kind: "one",
291
+ model: "payment_methods",
292
+ foreignKey: "paymentMethodId"
293
+ }
294
+ },
295
+ order: 1
296
+ },
297
+ idempotency_key: {
298
+ modelName: "idempotency_key",
299
+ order: 10,
300
+ fields: {
301
+ id: {
302
+ type: "string",
303
+ fieldName: "id",
304
+ required: true,
305
+ input: false,
306
+ returned: true,
307
+ unique: true,
308
+ validator: { output: z.uuid() }
309
+ },
310
+ key: {
311
+ type: "string",
312
+ fieldName: "key",
313
+ required: false,
314
+ unique: true,
315
+ sortable: true,
316
+ validator: { input: z.string().max(255).optional() }
317
+ },
318
+ requestPath: {
319
+ fieldName: "request_path",
320
+ type: "string",
321
+ required: false,
322
+ sortable: true,
323
+ validator: { input: z.string().max(150).optional() }
324
+ },
325
+ requestMethod: {
326
+ type: "string",
327
+ fieldName: "request_method",
328
+ required: false,
329
+ sortable: true,
330
+ validator: { input: z.string().max(10).optional() }
331
+ },
332
+ requestBody: {
333
+ type: "string",
334
+ fieldName: "request_body",
335
+ required: false,
336
+ validator: { input: z.unknown().optional() }
337
+ },
338
+ responseStatus: {
339
+ type: "string",
340
+ fieldName: "response_status",
341
+ required: false,
342
+ validator: { output: z.number().int().optional() }
343
+ },
344
+ responseBody: {
345
+ type: "string",
346
+ fieldName: "response_body",
347
+ required: false,
348
+ validator: { input: z.unknown().optional() }
349
+ },
350
+ objectType: {
351
+ type: "string",
352
+ fieldName: "object_type",
353
+ required: false,
354
+ sortable: true,
355
+ validator: { input: z.string().max(50).optional() }
356
+ },
357
+ objectId: {
358
+ type: "string",
359
+ fieldName: "object_id",
360
+ required: false,
361
+ sortable: true,
362
+ validator: { input: z.string().max(255).optional() }
363
+ },
364
+ expiresAt: {
365
+ type: "string",
366
+ fieldName: "expires_at",
367
+ required: false,
368
+ validator: { input: z.date().optional() }
369
+ },
370
+ createdAt: {
371
+ type: "string",
372
+ fieldName: "created_at",
373
+ required: true,
374
+ input: false,
375
+ returned: true,
376
+ defaultValue: () => /* @__PURE__ */ new Date(),
377
+ validator: { output: z.date() }
378
+ }
379
+ },
380
+ constraints: {
381
+ unique: [{
382
+ name: "idempotency_key_object_unique",
383
+ fields: ["objectType", "objectId"]
384
+ }],
385
+ indexes: [{
386
+ name: "idempotency_key_idx",
387
+ unique: true,
388
+ fields: ["key"]
389
+ }, {
390
+ name: "expires_at_idx",
391
+ fields: ["expiresAt"]
392
+ }]
393
+ }
394
+ },
395
+ payment_method: {
396
+ modelName: "payment_methods",
397
+ order: 2,
398
+ fields: {
399
+ id: {
400
+ type: "uuid",
401
+ fieldName: "id",
402
+ required: true,
403
+ input: false,
404
+ returned: true,
405
+ unique: true,
406
+ validator: { output: z.uuid() }
407
+ },
408
+ phone: {
409
+ type: "string",
410
+ fieldName: "phone_number",
411
+ required: true,
412
+ sortable: true,
413
+ validator: {
414
+ input: z.string().max(15),
415
+ output: z.string()
416
+ }
417
+ },
418
+ provider: {
419
+ type: "string",
420
+ fieldName: "payment_providers",
421
+ required: true,
422
+ sortable: true,
423
+ defaultValue: PaymentProviders.MPESA,
424
+ validator: {
425
+ input: z.enum(PaymentProviders),
426
+ output: z.enum(PaymentProviders)
427
+ }
428
+ },
429
+ isActive: {
430
+ type: "boolean",
431
+ fieldName: "is_active",
432
+ required: false,
433
+ defaultValue: true,
434
+ validator: {
435
+ input: z.boolean().optional(),
436
+ output: z.boolean()
437
+ }
438
+ },
439
+ customerId: {
440
+ type: "uuid",
441
+ fieldName: "customer_id",
442
+ required: true,
443
+ index: true,
444
+ validator: {
445
+ input: z.uuid(),
446
+ output: z.uuid()
447
+ },
448
+ references: {
449
+ model: "customer",
450
+ field: "id",
451
+ onDelete: "cascade"
452
+ }
453
+ },
454
+ metadata: {
455
+ type: "json",
456
+ fieldName: "metadata",
457
+ required: false,
458
+ validator: {
459
+ input: z.unknown().optional(),
460
+ output: z.unknown()
461
+ }
462
+ },
463
+ createdAt: {
464
+ type: "date",
465
+ fieldName: "created_at",
466
+ required: true,
467
+ input: false,
468
+ returned: true,
469
+ defaultValue: () => /* @__PURE__ */ new Date(),
470
+ validator: { output: z.date() }
471
+ },
472
+ updatedAt: {
473
+ type: "date",
474
+ fieldName: "updated_at",
475
+ required: true,
476
+ input: false,
477
+ returned: true,
478
+ defaultValue: () => /* @__PURE__ */ new Date(),
479
+ onUpdate: () => /* @__PURE__ */ new Date(),
480
+ validator: { output: z.date() }
481
+ }
482
+ },
483
+ constraints: {
484
+ unique: [{
485
+ name: "payment_methods_customer_phone_provider_unique",
486
+ fields: [
487
+ "customerId",
488
+ "phone",
489
+ "provider"
490
+ ]
491
+ }],
492
+ indexes: [{
493
+ name: "payment_methods_customer_active_idx",
494
+ fields: ["customerId", "isActive"]
495
+ }]
496
+ },
497
+ relations: {
498
+ customer: {
499
+ kind: "one",
500
+ model: "customer",
501
+ foreignKey: "customerId"
502
+ },
503
+ subscriptions: {
504
+ kind: "many",
505
+ model: "subscription",
506
+ foreignKey: "paymentMethodId"
507
+ }
508
+ }
509
+ },
510
+ product: {
511
+ modelName: "products",
512
+ order: 1,
513
+ fields: {
514
+ id: {
515
+ type: "uuid",
516
+ fieldName: "id",
517
+ required: true,
518
+ input: false,
519
+ returned: true,
520
+ unique: true,
521
+ validator: { output: z.uuid() }
522
+ },
523
+ type: {
524
+ type: "string",
525
+ fieldName: "product_type",
526
+ required: false
527
+ },
528
+ name: {
529
+ type: "string",
530
+ fieldName: "product_name",
531
+ required: true,
532
+ sortable: true,
533
+ validator: {
534
+ input: z.string().max(255),
535
+ output: z.string()
536
+ },
537
+ index: true
538
+ },
539
+ description: {
540
+ type: "string",
541
+ fieldName: "product_description",
542
+ required: false
543
+ },
544
+ images: {
545
+ type: "string[]",
546
+ fieldName: "product_images",
547
+ required: true,
548
+ defaultValue: () => [],
549
+ validator: {
550
+ input: z.array(z.string()).default([]),
551
+ output: z.array(z.string())
552
+ }
553
+ },
554
+ defaultPriceId: {
555
+ type: "uuid",
556
+ fieldName: "default_price_id",
557
+ required: false,
558
+ references: {
559
+ model: "prices",
560
+ field: "id",
561
+ onDelete: "set null"
562
+ },
563
+ validator: {
564
+ input: z.uuid().optional(),
565
+ output: z.uuid().optional()
566
+ },
567
+ index: true
568
+ },
569
+ marketingFeatures: {
570
+ type: "json",
571
+ fieldName: "marketing_features",
572
+ required: false,
573
+ validator: {
574
+ input: z.array(z.object({ name: z.string() })).optional(),
575
+ output: z.array(z.object({ name: z.string() })).optional()
576
+ }
577
+ },
578
+ packageDimensions: {
579
+ type: "json",
580
+ fieldName: "package_dimensions",
581
+ required: false,
582
+ validator: {
583
+ input: z.object({
584
+ height: z.number(),
585
+ length: z.number(),
586
+ weight: z.number(),
587
+ width: z.number()
588
+ }).optional(),
589
+ output: z.object({
590
+ height: z.number(),
591
+ length: z.number(),
592
+ weight: z.number(),
593
+ width: z.number()
594
+ }).optional()
595
+ }
596
+ },
597
+ shippable: {
598
+ type: "boolean",
599
+ fieldName: "shippable",
600
+ required: false
601
+ },
602
+ url: {
603
+ type: "string",
604
+ fieldName: "url",
605
+ required: false
606
+ },
607
+ active: {
608
+ type: "boolean",
609
+ fieldName: "active",
610
+ required: false,
611
+ defaultValue: true
612
+ },
613
+ metadata: {
614
+ type: "json",
615
+ fieldName: "metadata",
616
+ required: false
617
+ },
618
+ deleted: {
619
+ type: "boolean",
620
+ fieldName: "deleted",
621
+ required: true,
622
+ defaultValue: false,
623
+ input: false,
624
+ returned: true
625
+ },
626
+ deletedAt: {
627
+ type: "date",
628
+ fieldName: "deleted_at",
629
+ required: false,
630
+ input: false,
631
+ returned: true
632
+ },
633
+ createdAt: {
634
+ type: "date",
635
+ fieldName: "created_at",
636
+ required: true,
637
+ input: false,
638
+ returned: true,
639
+ defaultValue: () => /* @__PURE__ */ new Date()
640
+ },
641
+ updatedAt: {
642
+ type: "date",
643
+ fieldName: "updated_at",
644
+ required: true,
645
+ input: false,
646
+ returned: true,
647
+ defaultValue: () => /* @__PURE__ */ new Date(),
648
+ onUpdate: () => /* @__PURE__ */ new Date()
649
+ }
650
+ },
651
+ constraints: { indexes: [{
652
+ name: "product_name_idx",
653
+ fields: ["name"]
654
+ }] },
655
+ relations: {
656
+ prices: {
657
+ kind: "many",
658
+ model: "prices",
659
+ foreignKey: "productId"
660
+ },
661
+ defaultPrice: {
662
+ kind: "one",
663
+ model: "prices",
664
+ foreignKey: "defaultPriceId"
665
+ }
666
+ }
667
+ },
668
+ price: {
669
+ modelName: "prices",
670
+ order: 1,
671
+ fields: {
672
+ id: {
673
+ type: "uuid",
674
+ fieldName: "id",
675
+ required: true,
676
+ input: false,
677
+ returned: true,
678
+ unique: true,
679
+ validator: { output: z.uuid() }
680
+ },
681
+ productId: {
682
+ type: "uuid",
683
+ fieldName: "product_id",
684
+ required: false,
685
+ references: {
686
+ model: "products",
687
+ field: "id",
688
+ onDelete: "cascade"
689
+ },
690
+ validator: {
691
+ input: z.uuid().optional(),
692
+ output: z.uuid().optional()
693
+ },
694
+ index: true
695
+ },
696
+ unitAmount: {
697
+ type: "number",
698
+ fieldName: "unit_amount",
699
+ required: false,
700
+ defaultValue: 0,
701
+ validator: {
702
+ input: z.number().int().min(0).optional(),
703
+ output: z.number().int()
704
+ }
705
+ },
706
+ currency: {
707
+ type: "string",
708
+ fieldName: "currency",
709
+ required: false,
710
+ defaultValue: Currency.KES,
711
+ validator: {
712
+ input: z.enum(Currency).optional(),
713
+ output: z.enum(Currency)
714
+ },
715
+ sortable: true
716
+ },
717
+ type: {
718
+ type: "string",
719
+ fieldName: "price_type",
720
+ required: false,
721
+ defaultValue: PriceType.ONE_TIME,
722
+ validator: {
723
+ input: z.enum(PriceType).optional(),
724
+ output: z.enum(PriceType)
725
+ },
726
+ sortable: true
727
+ },
728
+ pricingModel: {
729
+ type: "string",
730
+ fieldName: "pricing_model",
731
+ required: false,
732
+ defaultValue: PricingModel.FLAT,
733
+ validator: {
734
+ input: z.enum(PricingModel).optional(),
735
+ output: z.enum(PricingModel)
736
+ },
737
+ sortable: true
738
+ },
739
+ billingInterval: {
740
+ type: "string",
741
+ fieldName: "billing_interval",
742
+ required: false,
743
+ defaultValue: BillingInterval.MONTH,
744
+ validator: {
745
+ input: z.enum(BillingInterval).optional(),
746
+ output: z.enum(BillingInterval)
747
+ },
748
+ sortable: true
749
+ },
750
+ billingIntervalCount: {
751
+ type: "number",
752
+ fieldName: "billing_interval_count",
753
+ required: false,
754
+ defaultValue: 1,
755
+ validator: {
756
+ input: z.number().int().min(1).optional(),
757
+ output: z.number().int()
758
+ }
759
+ },
760
+ trialPeriodDays: {
761
+ type: "number",
762
+ fieldName: "trial_period_days",
763
+ required: false,
764
+ defaultValue: 0,
765
+ validator: {
766
+ input: z.number().int().min(0).optional(),
767
+ output: z.number().int()
768
+ }
769
+ },
770
+ usageAggregation: {
771
+ type: "string",
772
+ fieldName: "usage_aggregation",
773
+ required: false,
774
+ validator: {
775
+ input: z.string().optional(),
776
+ output: z.string().optional()
777
+ },
778
+ sortable: true
779
+ },
780
+ active: {
781
+ type: "boolean",
782
+ fieldName: "active",
783
+ required: false,
784
+ defaultValue: true,
785
+ validator: {
786
+ input: z.boolean().optional(),
787
+ output: z.boolean()
788
+ }
789
+ },
790
+ metadata: {
791
+ type: "json",
792
+ fieldName: "metadata",
793
+ required: false,
794
+ validator: {
795
+ input: z.unknown().optional(),
796
+ output: z.unknown().optional()
797
+ }
798
+ },
799
+ deleted: {
800
+ type: "boolean",
801
+ fieldName: "deleted",
802
+ required: true,
803
+ defaultValue: false,
804
+ input: false,
805
+ returned: true,
806
+ validator: { output: z.boolean() },
807
+ index: true
808
+ },
809
+ deletedAt: {
810
+ type: "date",
811
+ fieldName: "deleted_at",
812
+ required: false,
813
+ input: false,
814
+ returned: true,
815
+ validator: { output: z.date().optional() }
816
+ },
817
+ createdAt: {
818
+ type: "date",
819
+ fieldName: "created_at",
820
+ required: true,
821
+ input: false,
822
+ returned: true,
823
+ defaultValue: () => /* @__PURE__ */ new Date(),
824
+ validator: { output: z.date() }
825
+ },
826
+ updatedAt: {
827
+ type: "date",
828
+ fieldName: "updated_at",
829
+ required: true,
830
+ input: false,
831
+ returned: true,
832
+ defaultValue: () => /* @__PURE__ */ new Date(),
833
+ onUpdate: () => /* @__PURE__ */ new Date(),
834
+ validator: { output: z.date() }
835
+ }
836
+ },
837
+ constraints: { indexes: [
838
+ {
839
+ name: "price_product_active_idx",
840
+ fields: ["productId", "active"]
841
+ },
842
+ {
843
+ name: "price_type_active_idx",
844
+ fields: ["type", "active"]
845
+ },
846
+ {
847
+ name: "price_deleted_idx",
848
+ fields: ["deleted"]
849
+ }
850
+ ] },
851
+ checks: [{
852
+ name: "billing_interval_countx",
853
+ kind: "gt",
854
+ field: "billingIntervalCount",
855
+ value: 0
856
+ }],
857
+ relations: {
858
+ product: {
859
+ kind: "one",
860
+ model: "products",
861
+ foreignKey: "productId"
862
+ },
863
+ subscriptionItems: {
864
+ kind: "many",
865
+ model: "subscription_item",
866
+ foreignKey: "priceId"
867
+ },
868
+ invoiceItems: {
869
+ kind: "many",
870
+ model: "invoice_item",
871
+ foreignKey: "priceId"
872
+ }
873
+ }
874
+ },
875
+ usageRecord: {
876
+ modelName: "usage_record",
877
+ order: 1,
878
+ fields: {
879
+ id: {
880
+ type: "uuid",
881
+ fieldName: "id",
882
+ required: true,
883
+ input: false,
884
+ returned: true,
885
+ unique: true,
886
+ validator: { output: z.uuid() }
887
+ },
888
+ subscriptionItemId: {
889
+ type: "uuid",
890
+ fieldName: "subscription_item_id",
891
+ required: false,
892
+ references: {
893
+ model: "subscription_item",
894
+ field: "id",
895
+ onDelete: "cascade"
896
+ },
897
+ validator: {
898
+ input: z.uuid().optional(),
899
+ output: z.uuid().optional()
900
+ },
901
+ index: true
902
+ },
903
+ quantity: {
904
+ type: "number",
905
+ fieldName: "quantity",
906
+ required: true,
907
+ validator: {
908
+ input: z.number().int(),
909
+ output: z.number().int()
910
+ }
911
+ },
912
+ timestamp: {
913
+ type: "date",
914
+ fieldName: "timestamp",
915
+ required: false,
916
+ defaultValue: () => /* @__PURE__ */ new Date(),
917
+ validator: { output: z.date() },
918
+ index: true
919
+ },
920
+ action: {
921
+ type: "string",
922
+ fieldName: "usage_action",
923
+ required: false,
924
+ defaultValue: UsageAction.INCREMENT,
925
+ sortable: true,
926
+ validator: {
927
+ input: z.enum(UsageAction).optional(),
928
+ output: z.enum(UsageAction)
929
+ }
930
+ },
931
+ idempotencyKey: {
932
+ type: "string",
933
+ fieldName: "idempotency_key",
934
+ required: false,
935
+ unique: true,
936
+ sortable: true,
937
+ validator: {
938
+ input: z.string().max(255).optional(),
939
+ output: z.string().max(255).optional()
940
+ },
941
+ index: true
942
+ },
943
+ metadata: {
944
+ type: "json",
945
+ fieldName: "metadata",
946
+ required: false,
947
+ validator: {
948
+ input: z.unknown().optional(),
949
+ output: z.unknown().optional()
950
+ }
951
+ },
952
+ createdAt: {
953
+ type: "date",
954
+ fieldName: "created_at",
955
+ required: true,
956
+ input: false,
957
+ returned: true,
958
+ defaultValue: () => /* @__PURE__ */ new Date(),
959
+ validator: { output: z.date() }
960
+ }
961
+ },
962
+ constraints: { indexes: [{
963
+ name: "usage_record_subscription_item_id_timestamp_idx",
964
+ fields: ["subscriptionItemId", "timestamp"]
965
+ }, {
966
+ name: "usage_record_timestamp_idx",
967
+ fields: ["timestamp"]
968
+ }] },
969
+ relations: { subscriptionItem: {
970
+ kind: "one",
971
+ model: "subscription_item",
972
+ foreignKey: "subscriptionItemId"
973
+ } }
974
+ },
975
+ subscription: {
976
+ modelName: "subscription",
977
+ order: 1,
978
+ fields: {
979
+ id: {
980
+ type: "uuid",
981
+ fieldName: "id",
982
+ required: true,
983
+ input: false,
984
+ returned: true,
985
+ unique: true,
986
+ validator: { output: z.uuid() }
987
+ },
988
+ customerId: {
989
+ type: "uuid",
990
+ fieldName: "customer_id",
991
+ required: true,
992
+ references: {
993
+ model: "customer",
994
+ field: "id",
995
+ onDelete: "cascade"
996
+ },
997
+ validator: {
998
+ input: z.uuid(),
999
+ output: z.uuid()
1000
+ },
1001
+ index: true
1002
+ },
1003
+ paymentMethodId: {
1004
+ type: "uuid",
1005
+ fieldName: "payment_method_id",
1006
+ required: false,
1007
+ references: {
1008
+ model: "payment_methods",
1009
+ field: "id",
1010
+ onDelete: "set null"
1011
+ },
1012
+ validator: {
1013
+ input: z.uuid().optional(),
1014
+ output: z.uuid().optional()
1015
+ },
1016
+ index: true
1017
+ },
1018
+ status: {
1019
+ type: "string",
1020
+ fieldName: "subscription_status",
1021
+ required: false,
1022
+ defaultValue: SubscriptionStatus.INCOMPLETE,
1023
+ sortable: true,
1024
+ validator: {
1025
+ input: z.enum(SubscriptionStatus).optional(),
1026
+ output: z.enum(SubscriptionStatus)
1027
+ },
1028
+ index: true
1029
+ },
1030
+ currentBillingPeriodStart: {
1031
+ type: "date",
1032
+ fieldName: "current_billing_period_start",
1033
+ required: true,
1034
+ validator: {
1035
+ input: z.date(),
1036
+ output: z.date()
1037
+ }
1038
+ },
1039
+ currentBillingPeriodEnd: {
1040
+ type: "date",
1041
+ fieldName: "current_billing_period_end",
1042
+ required: true,
1043
+ validator: {
1044
+ input: z.date(),
1045
+ output: z.date()
1046
+ },
1047
+ index: true
1048
+ },
1049
+ currentTrialStart: {
1050
+ type: "date",
1051
+ fieldName: "current_trial_start",
1052
+ required: false,
1053
+ validator: {
1054
+ input: z.date().optional(),
1055
+ output: z.date().optional()
1056
+ }
1057
+ },
1058
+ currentTrialEnd: {
1059
+ type: "date",
1060
+ fieldName: "current_trial_end",
1061
+ required: false,
1062
+ validator: {
1063
+ input: z.date().optional(),
1064
+ output: z.date().optional()
1065
+ },
1066
+ index: true
1067
+ },
1068
+ cancelAtPeriodEnd: {
1069
+ type: "boolean",
1070
+ fieldName: "cancel_at_period_end",
1071
+ required: true,
1072
+ defaultValue: false,
1073
+ validator: {
1074
+ input: z.boolean().optional(),
1075
+ output: z.boolean()
1076
+ }
1077
+ },
1078
+ canceledAt: {
1079
+ type: "date",
1080
+ fieldName: "canceled_at",
1081
+ required: false,
1082
+ validator: {
1083
+ input: z.date().optional(),
1084
+ output: z.date().optional()
1085
+ }
1086
+ },
1087
+ cancelAt: {
1088
+ type: "date",
1089
+ fieldName: "cancel_at",
1090
+ required: false,
1091
+ validator: {
1092
+ input: z.date().optional(),
1093
+ output: z.date().optional()
1094
+ }
1095
+ },
1096
+ daysUntilDue: {
1097
+ type: "number",
1098
+ fieldName: "days_until_due",
1099
+ required: true,
1100
+ defaultValue: 0,
1101
+ validator: {
1102
+ input: z.number().int().min(0).optional(),
1103
+ output: z.number().int()
1104
+ }
1105
+ },
1106
+ proration: {
1107
+ type: "string",
1108
+ fieldName: "proration",
1109
+ required: true,
1110
+ defaultValue: ProrationBehavior.CREATE_PRORATIONS,
1111
+ sortable: true,
1112
+ validator: {
1113
+ input: z.enum(ProrationBehavior).optional(),
1114
+ output: z.enum(ProrationBehavior)
1115
+ }
1116
+ },
1117
+ collectionMethod: {
1118
+ type: "string",
1119
+ fieldName: "collection_method",
1120
+ required: true,
1121
+ defaultValue: CollectionMethod.SEND_INVOICE,
1122
+ sortable: true,
1123
+ validator: {
1124
+ input: z.enum(CollectionMethod).optional(),
1125
+ output: z.enum(CollectionMethod)
1126
+ }
1127
+ },
1128
+ metadata: {
1129
+ type: "json",
1130
+ fieldName: "metadata",
1131
+ required: false,
1132
+ validator: {
1133
+ input: z.unknown().optional(),
1134
+ output: z.unknown().optional()
1135
+ }
1136
+ },
1137
+ deleted: {
1138
+ type: "boolean",
1139
+ fieldName: "deleted",
1140
+ required: true,
1141
+ defaultValue: false,
1142
+ input: false,
1143
+ returned: true,
1144
+ validator: { output: z.boolean() },
1145
+ index: true
1146
+ },
1147
+ deletedAt: {
1148
+ type: "date",
1149
+ fieldName: "deleted_at",
1150
+ required: false,
1151
+ input: false,
1152
+ returned: true,
1153
+ validator: { output: z.date().optional() }
1154
+ },
1155
+ createdAt: {
1156
+ type: "date",
1157
+ fieldName: "created_at",
1158
+ required: true,
1159
+ input: false,
1160
+ returned: true,
1161
+ defaultValue: () => /* @__PURE__ */ new Date(),
1162
+ validator: { output: z.date() }
1163
+ },
1164
+ updatedAt: {
1165
+ type: "date",
1166
+ fieldName: "updated_at",
1167
+ required: true,
1168
+ input: false,
1169
+ returned: true,
1170
+ defaultValue: () => /* @__PURE__ */ new Date(),
1171
+ onUpdate: () => /* @__PURE__ */ new Date(),
1172
+ validator: { output: z.date() }
1173
+ },
1174
+ subscriptionStartedAt: {
1175
+ type: "date",
1176
+ fieldName: "subscription_started_at",
1177
+ required: true,
1178
+ validator: {
1179
+ input: z.date(),
1180
+ output: z.date()
1181
+ }
1182
+ },
1183
+ subscriptionEndedAt: {
1184
+ type: "date",
1185
+ fieldName: "subscription_ended_at",
1186
+ required: false,
1187
+ validator: {
1188
+ input: z.date().optional(),
1189
+ output: z.date().optional()
1190
+ }
1191
+ }
1192
+ },
1193
+ constraints: { indexes: [
1194
+ {
1195
+ name: "subscription_customer_id_status_idx",
1196
+ fields: ["customerId", "status"]
1197
+ },
1198
+ {
1199
+ name: "subscription_current_billing_period_end_status_idx",
1200
+ fields: ["currentBillingPeriodEnd", "status"]
1201
+ },
1202
+ {
1203
+ name: "subscription_current_trial_end_status_idx",
1204
+ fields: ["currentTrialEnd", "status"]
1205
+ },
1206
+ {
1207
+ name: "subscription_payment_method_id_idx",
1208
+ fields: ["paymentMethodId"]
1209
+ },
1210
+ {
1211
+ name: "subscription_deleted_idx",
1212
+ fields: ["deleted"]
1213
+ }
1214
+ ] },
1215
+ checks: [{
1216
+ name: "days_until_due_gte_0",
1217
+ kind: "gte",
1218
+ field: "daysUntilDue",
1219
+ value: 0
1220
+ }],
1221
+ relations: {
1222
+ items: {
1223
+ kind: "many",
1224
+ model: "subscription_item",
1225
+ foreignKey: "subscriptionId"
1226
+ },
1227
+ invoices: {
1228
+ kind: "many",
1229
+ model: "invoice",
1230
+ foreignKey: "subscriptionId"
1231
+ },
1232
+ paymentIntents: {
1233
+ kind: "many",
1234
+ model: "payment_intent",
1235
+ foreignKey: "subscriptionId"
1236
+ },
1237
+ schedules: {
1238
+ kind: "many",
1239
+ model: "subscription_schedule",
1240
+ foreignKey: "subscriptionId"
1241
+ },
1242
+ checkoutSession: {
1243
+ kind: "one",
1244
+ model: "checkout_sessions",
1245
+ foreignKey: "id"
1246
+ },
1247
+ customer: {
1248
+ kind: "one",
1249
+ model: "customer",
1250
+ foreignKey: "customerId"
1251
+ },
1252
+ paymentMethod: {
1253
+ kind: "one",
1254
+ model: "payment_methods",
1255
+ foreignKey: "paymentMethodId"
1256
+ }
1257
+ }
1258
+ },
1259
+ subscriptionItem: {
1260
+ modelName: "subscription_item",
1261
+ order: 1,
1262
+ fields: {
1263
+ id: {
1264
+ type: "uuid",
1265
+ fieldName: "id",
1266
+ required: true,
1267
+ input: false,
1268
+ returned: true,
1269
+ unique: true,
1270
+ validator: { output: z.uuid() }
1271
+ },
1272
+ subscriptionId: {
1273
+ type: "uuid",
1274
+ fieldName: "subscription_id",
1275
+ required: false,
1276
+ references: {
1277
+ model: "subscription",
1278
+ field: "id",
1279
+ onDelete: "cascade"
1280
+ },
1281
+ validator: {
1282
+ input: z.uuid().optional(),
1283
+ output: z.uuid().optional()
1284
+ },
1285
+ index: true
1286
+ },
1287
+ priceId: {
1288
+ type: "uuid",
1289
+ fieldName: "price_id",
1290
+ required: true,
1291
+ references: {
1292
+ model: "prices",
1293
+ field: "id",
1294
+ onDelete: "cascade"
1295
+ },
1296
+ validator: {
1297
+ input: z.uuid(),
1298
+ output: z.uuid()
1299
+ },
1300
+ index: true
1301
+ },
1302
+ quantity: {
1303
+ type: "number",
1304
+ fieldName: "quantity",
1305
+ required: false,
1306
+ defaultValue: 1,
1307
+ validator: {
1308
+ input: z.number().int().min(0).optional(),
1309
+ output: z.number().int()
1310
+ }
1311
+ },
1312
+ metadata: {
1313
+ type: "json",
1314
+ fieldName: "metadata",
1315
+ required: false,
1316
+ validator: {
1317
+ input: z.unknown().optional(),
1318
+ output: z.unknown().optional()
1319
+ }
1320
+ },
1321
+ deleted: {
1322
+ type: "boolean",
1323
+ fieldName: "deleted",
1324
+ required: true,
1325
+ defaultValue: false,
1326
+ input: false,
1327
+ returned: true,
1328
+ validator: { output: z.boolean() },
1329
+ index: true
1330
+ },
1331
+ deletedAt: {
1332
+ type: "date",
1333
+ fieldName: "deleted_at",
1334
+ required: false,
1335
+ input: false,
1336
+ returned: true,
1337
+ validator: { output: z.date().optional() }
1338
+ },
1339
+ createdAt: {
1340
+ type: "date",
1341
+ fieldName: "created_at",
1342
+ required: true,
1343
+ input: false,
1344
+ returned: true,
1345
+ defaultValue: () => /* @__PURE__ */ new Date(),
1346
+ validator: { output: z.date() }
1347
+ },
1348
+ updatedAt: {
1349
+ type: "date",
1350
+ fieldName: "updated_at",
1351
+ required: true,
1352
+ input: false,
1353
+ returned: true,
1354
+ defaultValue: () => /* @__PURE__ */ new Date(),
1355
+ onUpdate: () => /* @__PURE__ */ new Date(),
1356
+ validator: { output: z.date() }
1357
+ }
1358
+ },
1359
+ constraints: {
1360
+ unique: [{
1361
+ name: "subscription_item_subscription_price_deleted_unique",
1362
+ fields: [
1363
+ "subscriptionId",
1364
+ "priceId",
1365
+ "deleted"
1366
+ ]
1367
+ }],
1368
+ indexes: [
1369
+ {
1370
+ name: "subscription_item_subscription_id_idx",
1371
+ fields: ["subscriptionId"]
1372
+ },
1373
+ {
1374
+ name: "subscription_item_price_id_idx",
1375
+ fields: ["priceId"]
1376
+ },
1377
+ {
1378
+ name: "subscription_item_deleted_idx",
1379
+ fields: ["deleted"]
1380
+ }
1381
+ ]
1382
+ },
1383
+ relations: {
1384
+ usageRecords: {
1385
+ kind: "many",
1386
+ model: "usage_record",
1387
+ foreignKey: "subscriptionItemId"
1388
+ },
1389
+ subscription: {
1390
+ kind: "one",
1391
+ model: "subscription",
1392
+ foreignKey: "subscriptionId"
1393
+ },
1394
+ price: {
1395
+ kind: "one",
1396
+ model: "prices",
1397
+ foreignKey: "priceId"
1398
+ }
1399
+ }
1400
+ },
1401
+ subscriptionSchedule: {
1402
+ modelName: "subscription_schedule",
1403
+ order: 1,
1404
+ fields: {
1405
+ id: {
1406
+ type: "uuid",
1407
+ fieldName: "id",
1408
+ required: true,
1409
+ input: false,
1410
+ returned: true,
1411
+ unique: true,
1412
+ validator: { output: z.uuid() }
1413
+ },
1414
+ subscriptionId: {
1415
+ type: "uuid",
1416
+ fieldName: "subscription_id",
1417
+ required: true,
1418
+ references: {
1419
+ model: "subscription",
1420
+ field: "id",
1421
+ onDelete: "cascade"
1422
+ },
1423
+ validator: {
1424
+ input: z.uuid(),
1425
+ output: z.uuid()
1426
+ },
1427
+ index: true
1428
+ },
1429
+ phases: {
1430
+ type: "json",
1431
+ fieldName: "phases",
1432
+ required: false,
1433
+ validator: {
1434
+ input: z.unknown().optional(),
1435
+ output: z.unknown().optional()
1436
+ }
1437
+ },
1438
+ status: {
1439
+ type: "string",
1440
+ fieldName: "schedule_status",
1441
+ required: true,
1442
+ defaultValue: ScheduleStatus.ACTIVE,
1443
+ sortable: true,
1444
+ validator: {
1445
+ input: z.enum(ScheduleStatus).optional(),
1446
+ output: z.enum(ScheduleStatus)
1447
+ },
1448
+ index: true
1449
+ },
1450
+ startDate: {
1451
+ type: "date",
1452
+ fieldName: "start_date",
1453
+ required: false,
1454
+ validator: {
1455
+ input: z.date().optional(),
1456
+ output: z.date().optional()
1457
+ },
1458
+ index: true
1459
+ },
1460
+ endDate: {
1461
+ type: "date",
1462
+ fieldName: "end_date",
1463
+ required: false,
1464
+ validator: {
1465
+ input: z.date().optional(),
1466
+ output: z.date().optional()
1467
+ }
1468
+ },
1469
+ completedAt: {
1470
+ type: "date",
1471
+ fieldName: "completed_at",
1472
+ required: false,
1473
+ validator: {
1474
+ input: z.date().optional(),
1475
+ output: z.date().optional()
1476
+ }
1477
+ },
1478
+ releasedAt: {
1479
+ type: "date",
1480
+ fieldName: "released_at",
1481
+ required: false,
1482
+ validator: {
1483
+ input: z.date().optional(),
1484
+ output: z.date().optional()
1485
+ }
1486
+ },
1487
+ metadata: {
1488
+ type: "json",
1489
+ fieldName: "metadata",
1490
+ required: false,
1491
+ validator: {
1492
+ input: z.unknown().optional(),
1493
+ output: z.unknown().optional()
1494
+ }
1495
+ },
1496
+ createdAt: {
1497
+ type: "date",
1498
+ fieldName: "created_at",
1499
+ required: true,
1500
+ input: false,
1501
+ returned: true,
1502
+ defaultValue: () => /* @__PURE__ */ new Date(),
1503
+ validator: { output: z.date() }
1504
+ },
1505
+ updatedAt: {
1506
+ type: "date",
1507
+ fieldName: "updated_at",
1508
+ required: true,
1509
+ input: false,
1510
+ returned: true,
1511
+ defaultValue: () => /* @__PURE__ */ new Date(),
1512
+ onUpdate: () => /* @__PURE__ */ new Date(),
1513
+ validator: { output: z.date() }
1514
+ }
1515
+ },
1516
+ constraints: { indexes: [
1517
+ {
1518
+ name: "subscription_schedule_subscription_id_status_idx",
1519
+ fields: ["subscriptionId", "status"]
1520
+ },
1521
+ {
1522
+ name: "subscription_schedule_start_date_idx",
1523
+ fields: ["startDate"]
1524
+ },
1525
+ {
1526
+ name: "subscription_schedule_status_idx",
1527
+ fields: ["status"]
1528
+ }
1529
+ ] },
1530
+ relations: { subscription: {
1531
+ kind: "one",
1532
+ model: "subscription",
1533
+ foreignKey: "subscriptionId"
1534
+ } }
1535
+ },
1536
+ invoice: {
1537
+ modelName: "invoice",
1538
+ order: 1,
1539
+ fields: {
1540
+ id: {
1541
+ type: "uuid",
1542
+ fieldName: "id",
1543
+ required: true,
1544
+ input: false,
1545
+ returned: true,
1546
+ unique: true,
1547
+ validator: { output: z.uuid() }
1548
+ },
1549
+ customerId: {
1550
+ type: "uuid",
1551
+ fieldName: "customer_id",
1552
+ required: false,
1553
+ references: {
1554
+ model: "customer",
1555
+ field: "id",
1556
+ onDelete: "cascade"
1557
+ },
1558
+ validator: {
1559
+ input: z.uuid().optional(),
1560
+ output: z.uuid().optional()
1561
+ },
1562
+ index: true
1563
+ },
1564
+ subscriptionId: {
1565
+ type: "uuid",
1566
+ fieldName: "subscription_id",
1567
+ required: false,
1568
+ references: {
1569
+ model: "subscription",
1570
+ field: "id",
1571
+ onDelete: "cascade"
1572
+ },
1573
+ validator: {
1574
+ input: z.uuid().optional(),
1575
+ output: z.uuid().optional()
1576
+ },
1577
+ index: true
1578
+ },
1579
+ status: {
1580
+ type: "string",
1581
+ fieldName: "invoice_status",
1582
+ required: true,
1583
+ defaultValue: InvoiceStatus.DRAFT,
1584
+ sortable: true,
1585
+ validator: {
1586
+ input: z.enum(InvoiceStatus).optional(),
1587
+ output: z.enum(InvoiceStatus)
1588
+ },
1589
+ index: true
1590
+ },
1591
+ subtotal: {
1592
+ type: "number",
1593
+ fieldName: "sub_total",
1594
+ required: true,
1595
+ defaultValue: 0,
1596
+ validator: {
1597
+ input: z.number().int().min(0).optional(),
1598
+ output: z.number().int()
1599
+ }
1600
+ },
1601
+ total: {
1602
+ type: "number",
1603
+ fieldName: "total",
1604
+ required: true,
1605
+ defaultValue: 0,
1606
+ validator: {
1607
+ input: z.number().int().min(0).optional(),
1608
+ output: z.number().int()
1609
+ }
1610
+ },
1611
+ amountPaid: {
1612
+ type: "number",
1613
+ fieldName: "amount_paid",
1614
+ required: true,
1615
+ defaultValue: 0,
1616
+ validator: {
1617
+ input: z.number().int().min(0).optional(),
1618
+ output: z.number().int()
1619
+ }
1620
+ },
1621
+ amountDue: {
1622
+ type: "number",
1623
+ fieldName: "amount_due",
1624
+ required: true,
1625
+ defaultValue: 0,
1626
+ validator: {
1627
+ input: z.number().int().min(0).optional(),
1628
+ output: z.number().int()
1629
+ }
1630
+ },
1631
+ amountRemaining: {
1632
+ type: "number",
1633
+ fieldName: "amount_remaining",
1634
+ required: false,
1635
+ defaultValue: 0,
1636
+ validator: {
1637
+ input: z.number().int().min(0).optional(),
1638
+ output: z.number().int().optional()
1639
+ }
1640
+ },
1641
+ currency: {
1642
+ type: "string",
1643
+ fieldName: "currency",
1644
+ required: true,
1645
+ defaultValue: Currency.KES,
1646
+ sortable: true,
1647
+ validator: {
1648
+ input: z.nativeEnum(Currency).optional(),
1649
+ output: z.nativeEnum(Currency)
1650
+ }
1651
+ },
1652
+ invoiceBillingPeriodStart: {
1653
+ type: "date",
1654
+ fieldName: "invoice_billing_period_start",
1655
+ required: false,
1656
+ validator: {
1657
+ input: z.date().optional(),
1658
+ output: z.date().optional()
1659
+ }
1660
+ },
1661
+ invoiceBillingPeriodEnd: {
1662
+ type: "date",
1663
+ fieldName: "invoice_billing_period_end",
1664
+ required: false,
1665
+ validator: {
1666
+ input: z.date().optional(),
1667
+ output: z.date().optional()
1668
+ }
1669
+ },
1670
+ invoiceDueDate: {
1671
+ type: "date",
1672
+ fieldName: "invoice_due_date",
1673
+ required: false,
1674
+ validator: {
1675
+ input: z.date().optional(),
1676
+ output: z.date().optional()
1677
+ },
1678
+ index: true
1679
+ },
1680
+ collectionMethod: {
1681
+ type: "string",
1682
+ fieldName: "invoice_collection_method",
1683
+ required: true,
1684
+ defaultValue: CollectionMethod.SEND_INVOICE,
1685
+ sortable: true,
1686
+ validator: {
1687
+ input: z.enum(CollectionMethod).optional(),
1688
+ output: z.enum(CollectionMethod)
1689
+ }
1690
+ },
1691
+ invoiceNumber: {
1692
+ type: "string",
1693
+ fieldName: "invoice_number",
1694
+ required: true,
1695
+ unique: true,
1696
+ sortable: true,
1697
+ validator: {
1698
+ input: z.string(),
1699
+ output: z.string()
1700
+ },
1701
+ index: true
1702
+ },
1703
+ customerName: {
1704
+ type: "string",
1705
+ fieldName: "customer_name",
1706
+ required: true,
1707
+ sortable: true,
1708
+ validator: {
1709
+ input: z.string().max(255),
1710
+ output: z.string()
1711
+ }
1712
+ },
1713
+ customerEmail: {
1714
+ type: "string",
1715
+ fieldName: "customer_email",
1716
+ required: true,
1717
+ sortable: true,
1718
+ validator: {
1719
+ input: z.string().email().max(255),
1720
+ output: z.string()
1721
+ },
1722
+ index: true
1723
+ },
1724
+ customerPhoneNumber: {
1725
+ type: "string",
1726
+ fieldName: "customer_phone_number",
1727
+ required: true,
1728
+ sortable: true,
1729
+ validator: {
1730
+ input: z.string().max(15),
1731
+ output: z.string()
1732
+ },
1733
+ index: true
1734
+ },
1735
+ autoAdvance: {
1736
+ type: "boolean",
1737
+ fieldName: "invoice_auto_advance",
1738
+ required: false,
1739
+ defaultValue: true,
1740
+ validator: {
1741
+ input: z.boolean().optional(),
1742
+ output: z.boolean()
1743
+ }
1744
+ },
1745
+ attemptCount: {
1746
+ type: "number",
1747
+ fieldName: "invoice_attempt_count",
1748
+ required: false,
1749
+ defaultValue: 0,
1750
+ validator: {
1751
+ input: z.number().int().min(0).optional(),
1752
+ output: z.number().int().optional()
1753
+ }
1754
+ },
1755
+ nextPaymentAttempt: {
1756
+ type: "date",
1757
+ fieldName: "next_payment_attempt",
1758
+ required: false,
1759
+ validator: {
1760
+ input: z.date().optional(),
1761
+ output: z.date().optional()
1762
+ },
1763
+ index: true
1764
+ },
1765
+ description: {
1766
+ type: "string",
1767
+ fieldName: "invoice_description",
1768
+ required: false
1769
+ },
1770
+ metadata: {
1771
+ type: "json",
1772
+ fieldName: "metadata",
1773
+ required: false,
1774
+ validator: {
1775
+ input: z.unknown().optional(),
1776
+ output: z.unknown().optional()
1777
+ }
1778
+ },
1779
+ deleted: {
1780
+ type: "boolean",
1781
+ fieldName: "deleted",
1782
+ required: true,
1783
+ defaultValue: false,
1784
+ input: false,
1785
+ returned: true,
1786
+ validator: { output: z.boolean() },
1787
+ index: true
1788
+ },
1789
+ deletedAt: {
1790
+ type: "date",
1791
+ fieldName: "deleted_at",
1792
+ required: false,
1793
+ input: false,
1794
+ returned: true,
1795
+ validator: { output: z.date().optional() }
1796
+ },
1797
+ createdAt: {
1798
+ type: "date",
1799
+ fieldName: "created_at",
1800
+ required: true,
1801
+ input: false,
1802
+ returned: true,
1803
+ defaultValue: () => /* @__PURE__ */ new Date(),
1804
+ validator: { output: z.date() }
1805
+ },
1806
+ updatedAt: {
1807
+ type: "date",
1808
+ fieldName: "updated_at",
1809
+ required: true,
1810
+ input: false,
1811
+ returned: true,
1812
+ defaultValue: () => /* @__PURE__ */ new Date(),
1813
+ onUpdate: () => /* @__PURE__ */ new Date(),
1814
+ validator: { output: z.date() }
1815
+ },
1816
+ finalizedAt: {
1817
+ type: "date",
1818
+ fieldName: "finalized_at",
1819
+ required: false,
1820
+ input: false,
1821
+ returned: true,
1822
+ validator: { output: z.date().optional() }
1823
+ },
1824
+ paidAt: {
1825
+ type: "date",
1826
+ fieldName: "paid_at",
1827
+ required: false,
1828
+ input: false,
1829
+ returned: true,
1830
+ validator: { output: z.date().optional() }
1831
+ },
1832
+ voidedAt: {
1833
+ type: "date",
1834
+ fieldName: "voided_at",
1835
+ required: false,
1836
+ input: false,
1837
+ returned: true,
1838
+ validator: { output: z.date().optional() }
1839
+ },
1840
+ markedUncollectibleAt: {
1841
+ type: "date",
1842
+ fieldName: "marked_uncollectible_at",
1843
+ required: false,
1844
+ input: false,
1845
+ returned: true,
1846
+ validator: { output: z.date().optional() }
1847
+ }
1848
+ },
1849
+ constraints: { indexes: [
1850
+ {
1851
+ name: "invoice_customer_id_status_idx",
1852
+ fields: ["customerId", "status"]
1853
+ },
1854
+ {
1855
+ name: "invoice_subscription_id_idx",
1856
+ fields: ["subscriptionId"]
1857
+ },
1858
+ {
1859
+ name: "invoice_status_due_date_idx",
1860
+ fields: ["status", "invoiceDueDate"]
1861
+ },
1862
+ {
1863
+ name: "invoice_status_next_payment_attempt_idx",
1864
+ fields: ["status", "nextPaymentAttempt"]
1865
+ },
1866
+ {
1867
+ name: "invoice_customer_phone_number_idx",
1868
+ fields: ["customerPhoneNumber"]
1869
+ },
1870
+ {
1871
+ name: "invoice_deleted_idx",
1872
+ fields: ["deleted"]
1873
+ }
1874
+ ] },
1875
+ checks: [
1876
+ {
1877
+ name: "invoice_subtotal_gte_0",
1878
+ kind: "gte",
1879
+ field: "subtotal",
1880
+ value: 0
1881
+ },
1882
+ {
1883
+ name: "invoice_total_gte_0",
1884
+ kind: "gte",
1885
+ field: "total",
1886
+ value: 0
1887
+ },
1888
+ {
1889
+ name: "invoice_amount_paid_gte_0",
1890
+ kind: "gte",
1891
+ field: "amountPaid",
1892
+ value: 0
1893
+ },
1894
+ {
1895
+ name: "invoice_amount_due_gte_0",
1896
+ kind: "gte",
1897
+ field: "amountDue",
1898
+ value: 0
1899
+ },
1900
+ {
1901
+ name: "invoice_attempt_count_gte_0",
1902
+ kind: "gte",
1903
+ field: "attemptCount",
1904
+ value: 0
1905
+ }
1906
+ ],
1907
+ relations: {
1908
+ invoiceItems: {
1909
+ kind: "many",
1910
+ model: "invoice_item",
1911
+ foreignKey: "invoiceId"
1912
+ },
1913
+ paymentIntents: {
1914
+ kind: "many",
1915
+ model: "payment_intent",
1916
+ foreignKey: "invoiceId"
1917
+ },
1918
+ customer: {
1919
+ kind: "one",
1920
+ model: "customer",
1921
+ foreignKey: "customerId"
1922
+ },
1923
+ subscription: {
1924
+ kind: "one",
1925
+ model: "subscription",
1926
+ foreignKey: "subscriptionId"
1927
+ }
1928
+ }
1929
+ },
1930
+ invoiceItem: {
1931
+ modelName: "invoice_item",
1932
+ order: 1,
1933
+ fields: {
1934
+ id: {
1935
+ type: "uuid",
1936
+ fieldName: "id",
1937
+ required: true,
1938
+ input: false,
1939
+ returned: true,
1940
+ unique: true,
1941
+ validator: { output: z.uuid() }
1942
+ },
1943
+ invoiceId: {
1944
+ type: "uuid",
1945
+ fieldName: "invoice_id",
1946
+ required: true,
1947
+ references: {
1948
+ model: "invoice",
1949
+ field: "id",
1950
+ onDelete: "cascade"
1951
+ },
1952
+ validator: {
1953
+ input: z.uuid(),
1954
+ output: z.uuid()
1955
+ },
1956
+ index: true
1957
+ },
1958
+ priceId: {
1959
+ type: "uuid",
1960
+ fieldName: "price_id",
1961
+ required: false,
1962
+ references: {
1963
+ model: "prices",
1964
+ field: "id",
1965
+ onDelete: "cascade"
1966
+ },
1967
+ validator: {
1968
+ input: z.uuid().optional(),
1969
+ output: z.uuid().optional()
1970
+ },
1971
+ index: true
1972
+ },
1973
+ description: {
1974
+ type: "string",
1975
+ fieldName: "invoice_item_description",
1976
+ required: false
1977
+ },
1978
+ quantity: {
1979
+ type: "number",
1980
+ fieldName: "invoice_item_quantity",
1981
+ required: false,
1982
+ defaultValue: 1,
1983
+ validator: {
1984
+ input: z.number().int().min(0).optional(),
1985
+ output: z.number().int().optional()
1986
+ }
1987
+ },
1988
+ unitAmount: {
1989
+ type: "number",
1990
+ fieldName: "invoice_item_unit_amount",
1991
+ required: true,
1992
+ defaultValue: 1,
1993
+ validator: {
1994
+ input: z.number().int().min(0).optional(),
1995
+ output: z.number().int()
1996
+ }
1997
+ },
1998
+ amount: {
1999
+ type: "number",
2000
+ fieldName: "invoice_item_amount",
2001
+ required: true,
2002
+ defaultValue: 0,
2003
+ validator: {
2004
+ input: z.number().int().min(0).optional(),
2005
+ output: z.number().int()
2006
+ }
2007
+ },
2008
+ currency: {
2009
+ type: "string",
2010
+ fieldName: "invoice_item_currency",
2011
+ required: false,
2012
+ defaultValue: Currency.KES,
2013
+ sortable: true,
2014
+ validator: {
2015
+ input: z.enum(Currency).optional(),
2016
+ output: z.enum(Currency).optional()
2017
+ }
2018
+ },
2019
+ invoicePeriodStart: {
2020
+ type: "date",
2021
+ fieldName: "invoice_period_start",
2022
+ required: false,
2023
+ validator: {
2024
+ input: z.date().optional(),
2025
+ output: z.date().optional()
2026
+ }
2027
+ },
2028
+ invoicePeriodEnd: {
2029
+ type: "date",
2030
+ fieldName: "invoice_period_end",
2031
+ required: false,
2032
+ validator: {
2033
+ input: z.date().optional(),
2034
+ output: z.date().optional()
2035
+ }
2036
+ },
2037
+ invoiceProration: {
2038
+ type: "boolean",
2039
+ fieldName: "invoice_proration",
2040
+ required: false,
2041
+ defaultValue: false,
2042
+ validator: {
2043
+ input: z.boolean().optional(),
2044
+ output: z.boolean().optional()
2045
+ }
2046
+ },
2047
+ metadata: {
2048
+ type: "json",
2049
+ fieldName: "metadata",
2050
+ required: false,
2051
+ validator: {
2052
+ input: z.unknown().optional(),
2053
+ output: z.unknown().optional()
2054
+ }
2055
+ },
2056
+ createdAt: {
2057
+ type: "date",
2058
+ fieldName: "created_at",
2059
+ required: true,
2060
+ input: false,
2061
+ returned: true,
2062
+ defaultValue: () => /* @__PURE__ */ new Date(),
2063
+ validator: { output: z.date() }
2064
+ }
2065
+ },
2066
+ constraints: { indexes: [{
2067
+ name: "invoice_item_invoice_id_idx",
2068
+ fields: ["invoiceId"]
2069
+ }, {
2070
+ name: "invoice_item_price_id_idx",
2071
+ fields: ["priceId"]
2072
+ }] },
2073
+ checks: [
2074
+ {
2075
+ name: "invoice_item_unit_amount_gte_0",
2076
+ kind: "gte",
2077
+ field: "unitAmount",
2078
+ value: 0
2079
+ },
2080
+ {
2081
+ name: "invoice_item_amount_gte_0",
2082
+ kind: "gte",
2083
+ field: "amount",
2084
+ value: 0
2085
+ },
2086
+ {
2087
+ name: "invoice_item_quantity_gte_0",
2088
+ kind: "gte",
2089
+ field: "quantity",
2090
+ value: 0
2091
+ }
2092
+ ],
2093
+ relations: {
2094
+ invoice: {
2095
+ kind: "one",
2096
+ model: "invoice",
2097
+ foreignKey: "invoiceId"
2098
+ },
2099
+ price: {
2100
+ kind: "one",
2101
+ model: "prices",
2102
+ foreignKey: "priceId"
2103
+ }
2104
+ }
2105
+ },
2106
+ webHookEndpoint: {
2107
+ modelName: "webhook_endpoints",
2108
+ order: 1,
2109
+ fields: {
2110
+ id: {
2111
+ type: "uuid",
2112
+ fieldName: "id",
2113
+ required: true,
2114
+ input: false,
2115
+ returned: true,
2116
+ unique: true,
2117
+ validator: { output: z.uuid() }
2118
+ },
2119
+ url: {
2120
+ type: "string",
2121
+ fieldName: "endpoint_url",
2122
+ required: true,
2123
+ unique: true,
2124
+ sortable: false,
2125
+ validator: {
2126
+ input: z.string().url(),
2127
+ output: z.string()
2128
+ },
2129
+ index: true
2130
+ },
2131
+ description: {
2132
+ type: "string",
2133
+ fieldName: "description",
2134
+ required: false
2135
+ },
2136
+ enabledEvents: {
2137
+ type: "string[]",
2138
+ fieldName: "enabled_webhook_events",
2139
+ required: false,
2140
+ defaultValue: () => [],
2141
+ validator: {
2142
+ input: z.array(z.string()).default([]),
2143
+ output: z.array(z.string())
2144
+ }
2145
+ },
2146
+ active: {
2147
+ type: "boolean",
2148
+ fieldName: "is_webhook_active",
2149
+ required: false,
2150
+ defaultValue: true,
2151
+ validator: {
2152
+ input: z.boolean().optional(),
2153
+ output: z.boolean()
2154
+ }
2155
+ },
2156
+ secret: {
2157
+ type: "string",
2158
+ fieldName: "webhook_secret_signature",
2159
+ required: true,
2160
+ sortable: true,
2161
+ validator: {
2162
+ input: z.string().max(255),
2163
+ output: z.string()
2164
+ },
2165
+ returned: false
2166
+ },
2167
+ apiVersion: {
2168
+ type: "string",
2169
+ fieldName: "webhook_api_version",
2170
+ required: false,
2171
+ sortable: true,
2172
+ validator: {
2173
+ input: z.string().max(10).optional(),
2174
+ output: z.string().max(10).optional()
2175
+ }
2176
+ },
2177
+ deleted: {
2178
+ type: "boolean",
2179
+ fieldName: "deleted",
2180
+ required: true,
2181
+ defaultValue: false,
2182
+ input: false,
2183
+ returned: true,
2184
+ validator: { output: z.boolean() },
2185
+ index: true
2186
+ },
2187
+ deletedAt: {
2188
+ type: "date",
2189
+ fieldName: "deleted_at",
2190
+ required: false,
2191
+ input: false,
2192
+ returned: true,
2193
+ validator: { output: z.date().optional() }
2194
+ },
2195
+ createdAt: {
2196
+ type: "date",
2197
+ fieldName: "created_at",
2198
+ required: true,
2199
+ input: false,
2200
+ returned: true,
2201
+ defaultValue: () => /* @__PURE__ */ new Date(),
2202
+ validator: { output: z.date() }
2203
+ },
2204
+ updatedAt: {
2205
+ type: "date",
2206
+ fieldName: "updated_at",
2207
+ required: true,
2208
+ input: false,
2209
+ returned: true,
2210
+ defaultValue: () => /* @__PURE__ */ new Date(),
2211
+ onUpdate: () => /* @__PURE__ */ new Date(),
2212
+ validator: { output: z.date() }
2213
+ }
2214
+ },
2215
+ constraints: { indexes: [{
2216
+ name: "webhook_endpoints_active_deleted_idx",
2217
+ fields: ["active", "deleted"]
2218
+ }, {
2219
+ name: "webhook_endpoint_unique_url",
2220
+ unique: true,
2221
+ fields: ["url"]
2222
+ }] },
2223
+ relations: { webhookDeliveries: {
2224
+ kind: "many",
2225
+ model: "webhook_delivery",
2226
+ foreignKey: "endpointId"
2227
+ } }
2228
+ },
2229
+ webHookDelivery: {
2230
+ modelName: "webhook_delivery",
2231
+ order: 1,
2232
+ fields: {
2233
+ id: {
2234
+ type: "uuid",
2235
+ fieldName: "id",
2236
+ required: true,
2237
+ input: false,
2238
+ returned: true,
2239
+ unique: true,
2240
+ validator: { output: z.uuid() }
2241
+ },
2242
+ endpointId: {
2243
+ type: "uuid",
2244
+ fieldName: "endpoint_id",
2245
+ required: true,
2246
+ references: {
2247
+ model: "webhook_endpoints",
2248
+ field: "id",
2249
+ onDelete: "cascade"
2250
+ },
2251
+ validator: {
2252
+ input: z.uuid(),
2253
+ output: z.uuid()
2254
+ },
2255
+ index: true
2256
+ },
2257
+ eventId: {
2258
+ type: "uuid",
2259
+ fieldName: "event_id",
2260
+ required: true,
2261
+ references: {
2262
+ model: "events",
2263
+ field: "id",
2264
+ onDelete: "cascade"
2265
+ },
2266
+ validator: {
2267
+ input: z.uuid(),
2268
+ output: z.uuid()
2269
+ },
2270
+ index: true
2271
+ },
2272
+ url: {
2273
+ type: "string",
2274
+ fieldName: "webhook_delivery_url",
2275
+ required: true,
2276
+ validator: {
2277
+ input: z.string().url(),
2278
+ output: z.string()
2279
+ }
2280
+ },
2281
+ payload: {
2282
+ type: "json",
2283
+ fieldName: "payload",
2284
+ required: false,
2285
+ validator: {
2286
+ input: z.unknown().optional(),
2287
+ output: z.unknown().optional()
2288
+ }
2289
+ },
2290
+ headers: {
2291
+ type: "json",
2292
+ fieldName: "headers",
2293
+ required: false,
2294
+ validator: {
2295
+ input: z.unknown().optional(),
2296
+ output: z.unknown().optional()
2297
+ }
2298
+ },
2299
+ statusCode: {
2300
+ type: "number",
2301
+ fieldName: "status_code",
2302
+ required: false,
2303
+ validator: {
2304
+ input: z.number().int().optional(),
2305
+ output: z.number().int().optional()
2306
+ }
2307
+ },
2308
+ responseBody: {
2309
+ type: "string",
2310
+ fieldName: "response_body",
2311
+ required: false
2312
+ },
2313
+ responseTime: {
2314
+ type: "number",
2315
+ fieldName: "response_time",
2316
+ required: false,
2317
+ validator: {
2318
+ input: z.number().int().min(0).optional(),
2319
+ output: z.number().int().optional()
2320
+ }
2321
+ },
2322
+ error: {
2323
+ type: "string",
2324
+ fieldName: "error",
2325
+ required: false
2326
+ },
2327
+ status: {
2328
+ type: "string",
2329
+ fieldName: "webhook_event_status",
2330
+ required: true,
2331
+ defaultValue: WebHookEventStatus.PENDING,
2332
+ sortable: true,
2333
+ validator: {
2334
+ input: z.enum(WebHookEventStatus).optional(),
2335
+ output: z.enum(WebHookEventStatus)
2336
+ },
2337
+ index: true
2338
+ },
2339
+ attemptNumber: {
2340
+ type: "number",
2341
+ fieldName: "webhook_attempts",
2342
+ required: false,
2343
+ defaultValue: 1,
2344
+ validator: {
2345
+ input: z.number().int().min(1).optional(),
2346
+ output: z.number().int().optional()
2347
+ }
2348
+ },
2349
+ nextWebhookRetryAt: {
2350
+ type: "date",
2351
+ fieldName: "next_webhook_retry_at",
2352
+ required: false,
2353
+ validator: {
2354
+ input: z.date().optional(),
2355
+ output: z.date().optional()
2356
+ },
2357
+ index: true
2358
+ },
2359
+ createdAt: {
2360
+ type: "date",
2361
+ fieldName: "created_at",
2362
+ required: true,
2363
+ input: false,
2364
+ returned: true,
2365
+ defaultValue: () => /* @__PURE__ */ new Date(),
2366
+ validator: { output: z.date() }
2367
+ },
2368
+ updatedAt: {
2369
+ type: "date",
2370
+ fieldName: "updated_at",
2371
+ required: true,
2372
+ input: false,
2373
+ returned: true,
2374
+ defaultValue: () => /* @__PURE__ */ new Date(),
2375
+ onUpdate: () => /* @__PURE__ */ new Date(),
2376
+ validator: { output: z.date() }
2377
+ },
2378
+ deliveredAt: {
2379
+ type: "date",
2380
+ fieldName: "delivered_at",
2381
+ required: false,
2382
+ input: false,
2383
+ returned: true,
2384
+ validator: { output: z.date().optional() }
2385
+ },
2386
+ triggeredBy: {
2387
+ type: "string",
2388
+ fieldName: "webhook_delivery_trigger",
2389
+ required: true,
2390
+ defaultValue: WebHookDeliveryTrigger.SYSTEM,
2391
+ sortable: true,
2392
+ validator: {
2393
+ input: z.enum(WebHookDeliveryTrigger).optional(),
2394
+ output: z.enum(WebHookDeliveryTrigger)
2395
+ }
2396
+ }
2397
+ },
2398
+ constraints: { indexes: [
2399
+ {
2400
+ name: "webhook_delivery_endpoint_id_status_idx",
2401
+ fields: ["endpointId", "status"]
2402
+ },
2403
+ {
2404
+ name: "webhook_delivery_event_id_idx",
2405
+ fields: ["eventId"]
2406
+ },
2407
+ {
2408
+ name: "webhook_delivery_next_retry_at_status_idx",
2409
+ fields: ["nextWebhookRetryAt", "status"]
2410
+ }
2411
+ ] },
2412
+ checks: [{
2413
+ name: "webhook_delivery_attempt_number_gte_1",
2414
+ kind: "gte",
2415
+ field: "attemptNumber",
2416
+ value: 1
2417
+ }, {
2418
+ name: "webhook_delivery_response_time_gte_0",
2419
+ kind: "gte",
2420
+ field: "responseTime",
2421
+ value: 0
2422
+ }],
2423
+ relations: {
2424
+ endpoint: {
2425
+ kind: "one",
2426
+ model: "webhook_endpoints",
2427
+ foreignKey: "endpointId"
2428
+ },
2429
+ event: {
2430
+ kind: "one",
2431
+ model: "event",
2432
+ foreignKey: "eventId"
2433
+ }
2434
+ }
2435
+ },
2436
+ event: {
2437
+ modelName: "event",
2438
+ order: 1,
2439
+ fields: {
2440
+ id: {
2441
+ type: "uuid",
2442
+ fieldName: "id",
2443
+ required: true,
2444
+ input: false,
2445
+ returned: true,
2446
+ unique: true,
2447
+ validator: { output: z.uuid() }
2448
+ },
2449
+ type: {
2450
+ type: "string",
2451
+ fieldName: "event_type",
2452
+ required: true,
2453
+ sortable: true,
2454
+ validator: {
2455
+ input: z.string().max(100),
2456
+ output: z.string()
2457
+ },
2458
+ index: true
2459
+ },
2460
+ data: {
2461
+ type: "json",
2462
+ fieldName: "event_data",
2463
+ required: false,
2464
+ validator: {
2465
+ input: z.unknown().optional(),
2466
+ output: z.unknown().optional()
2467
+ }
2468
+ },
2469
+ objectType: {
2470
+ type: "string",
2471
+ fieldName: "event_object_type",
2472
+ required: false,
2473
+ sortable: true,
2474
+ validator: {
2475
+ input: z.string().max(100).optional(),
2476
+ output: z.string().max(100).optional()
2477
+ },
2478
+ index: true
2479
+ },
2480
+ objectId: {
2481
+ type: "string",
2482
+ fieldName: "event_object_id",
2483
+ required: false,
2484
+ sortable: true,
2485
+ validator: {
2486
+ input: z.string().max(255).optional(),
2487
+ output: z.string().max(255).optional()
2488
+ },
2489
+ index: true
2490
+ },
2491
+ apiVersion: {
2492
+ type: "string",
2493
+ fieldName: "event_api_version",
2494
+ required: true,
2495
+ sortable: true,
2496
+ validator: {
2497
+ input: z.string().max(10),
2498
+ output: z.string().max(10)
2499
+ }
2500
+ },
2501
+ idempotencyKey: {
2502
+ type: "string",
2503
+ fieldName: "event_idempotency_key",
2504
+ required: true,
2505
+ unique: true,
2506
+ sortable: true,
2507
+ validator: {
2508
+ input: z.string().max(255),
2509
+ output: z.string().max(255)
2510
+ },
2511
+ index: true
2512
+ },
2513
+ deliveryCount: {
2514
+ type: "number",
2515
+ fieldName: "delivery_count",
2516
+ required: true,
2517
+ defaultValue: 0,
2518
+ validator: {
2519
+ input: z.number().int().min(0).optional(),
2520
+ output: z.number().int()
2521
+ }
2522
+ },
2523
+ lastDeliveredAt: {
2524
+ type: "date",
2525
+ fieldName: "last_delivered_at",
2526
+ required: false,
2527
+ input: false,
2528
+ returned: true,
2529
+ validator: { output: z.date().optional() }
2530
+ },
2531
+ lastDeliveryStatus: {
2532
+ type: "string",
2533
+ fieldName: "last_delivery_status",
2534
+ required: false,
2535
+ sortable: true,
2536
+ validator: {
2537
+ input: z.string().max(50).optional(),
2538
+ output: z.string().max(50).optional()
2539
+ }
2540
+ },
2541
+ successfulDeliveries: {
2542
+ type: "number",
2543
+ fieldName: "successful_deliveries",
2544
+ required: false,
2545
+ defaultValue: 0,
2546
+ validator: {
2547
+ input: z.number().int().min(0).optional(),
2548
+ output: z.number().int().optional()
2549
+ }
2550
+ },
2551
+ failedDeliveries: {
2552
+ type: "number",
2553
+ fieldName: "failed_deliveries",
2554
+ required: false,
2555
+ defaultValue: 0,
2556
+ validator: {
2557
+ input: z.number().int().min(0).optional(),
2558
+ output: z.number().int().optional()
2559
+ }
2560
+ },
2561
+ requestId: {
2562
+ type: "string",
2563
+ fieldName: "event_request_id",
2564
+ required: false,
2565
+ sortable: true,
2566
+ validator: {
2567
+ input: z.string().max(255).optional(),
2568
+ output: z.string().max(255).optional()
2569
+ }
2570
+ },
2571
+ createdAt: {
2572
+ type: "date",
2573
+ fieldName: "created_at",
2574
+ required: true,
2575
+ input: false,
2576
+ returned: true,
2577
+ defaultValue: () => /* @__PURE__ */ new Date(),
2578
+ validator: { output: z.date() },
2579
+ index: true
2580
+ },
2581
+ payloadHash: {
2582
+ type: "string",
2583
+ fieldName: "payload_hash",
2584
+ required: false,
2585
+ sortable: true,
2586
+ validator: {
2587
+ input: z.string().max(64).optional(),
2588
+ output: z.string().max(64).optional()
2589
+ }
2590
+ }
2591
+ },
2592
+ constraints: { indexes: [{
2593
+ name: "event_created_at_type_idx",
2594
+ fields: ["createdAt", "type"]
2595
+ }, {
2596
+ name: "event_object_id_object_type_idx",
2597
+ fields: ["objectId", "objectType"]
2598
+ }] },
2599
+ checks: [
2600
+ {
2601
+ name: "event_delivery_count_gte_0",
2602
+ kind: "gte",
2603
+ field: "deliveryCount",
2604
+ value: 0
2605
+ },
2606
+ {
2607
+ name: "event_successful_deliveries_gte_0",
2608
+ kind: "gte",
2609
+ field: "successfulDeliveries",
2610
+ value: 0
2611
+ },
2612
+ {
2613
+ name: "event_failed_deliveries_gte_0",
2614
+ kind: "gte",
2615
+ field: "failedDeliveries",
2616
+ value: 0
2617
+ }
2618
+ ],
2619
+ relations: {
2620
+ webHookDeliveries: {
2621
+ kind: "many",
2622
+ model: "webhook_delivery",
2623
+ foreignKey: "eventId"
2624
+ },
2625
+ sessionEvents: {
2626
+ kind: "many",
2627
+ model: "sessions",
2628
+ foreignKey: "eventId"
2629
+ }
2630
+ }
2631
+ },
2632
+ sessionEvent: {
2633
+ modelName: "sessions",
2634
+ order: 1,
2635
+ fields: {
2636
+ id: {
2637
+ type: "uuid",
2638
+ fieldName: "id",
2639
+ required: true,
2640
+ input: false,
2641
+ returned: true,
2642
+ unique: true,
2643
+ validator: { output: z.uuid() }
2644
+ },
2645
+ sessionId: {
2646
+ type: "uuid",
2647
+ fieldName: "session_id",
2648
+ required: true,
2649
+ references: {
2650
+ model: "checkout_sessions",
2651
+ field: "id",
2652
+ onDelete: "cascade"
2653
+ },
2654
+ validator: {
2655
+ input: z.uuid(),
2656
+ output: z.uuid()
2657
+ },
2658
+ index: true
2659
+ },
2660
+ eventId: {
2661
+ type: "uuid",
2662
+ fieldName: "event_id",
2663
+ required: true,
2664
+ references: {
2665
+ model: "event",
2666
+ field: "id",
2667
+ onDelete: "cascade"
2668
+ },
2669
+ validator: {
2670
+ input: z.uuid(),
2671
+ output: z.uuid()
2672
+ },
2673
+ index: true
2674
+ },
2675
+ createdAt: {
2676
+ type: "date",
2677
+ fieldName: "created_at",
2678
+ required: true,
2679
+ input: false,
2680
+ returned: true,
2681
+ defaultValue: () => /* @__PURE__ */ new Date(),
2682
+ validator: { output: z.date() },
2683
+ index: true
2684
+ }
2685
+ },
2686
+ constraints: { indexes: [{
2687
+ name: "sessions_session_id_created_at_idx",
2688
+ fields: ["sessionId", "createdAt"]
2689
+ }, {
2690
+ name: "sessions_event_id_idx",
2691
+ fields: ["eventId"]
2692
+ }] },
2693
+ relations: {
2694
+ session: {
2695
+ kind: "one",
2696
+ model: "checkout_sessions",
2697
+ foreignKey: "sessionId"
2698
+ },
2699
+ event: {
2700
+ kind: "one",
2701
+ model: "event",
2702
+ foreignKey: "eventId"
2703
+ }
2704
+ }
2705
+ },
2706
+ checkoutSession: {
2707
+ modelName: "checkout_sessions",
2708
+ order: 1,
2709
+ fields: {
2710
+ id: {
2711
+ type: "uuid",
2712
+ fieldName: "id",
2713
+ required: true,
2714
+ input: false,
2715
+ returned: true,
2716
+ unique: true,
2717
+ validator: { output: z.uuid() }
2718
+ },
2719
+ expiresAt: {
2720
+ type: "date",
2721
+ fieldName: "checkout_session_expires_at",
2722
+ required: true,
2723
+ validator: {
2724
+ input: z.date(),
2725
+ output: z.date()
2726
+ },
2727
+ index: true
2728
+ },
2729
+ successUrl: {
2730
+ type: "string",
2731
+ fieldName: "success_url",
2732
+ required: false,
2733
+ validator: {
2734
+ input: z.url().optional(),
2735
+ output: z.url().optional()
2736
+ }
2737
+ },
2738
+ cancelUrl: {
2739
+ type: "string",
2740
+ fieldName: "cancel_url",
2741
+ required: false,
2742
+ validator: {
2743
+ input: z.url().optional(),
2744
+ output: z.url().optional()
2745
+ }
2746
+ },
2747
+ mode: {
2748
+ type: "string",
2749
+ fieldName: "checkout_session_mode",
2750
+ required: true,
2751
+ defaultValue: CheckoutSessionMode.PAYMENT,
2752
+ sortable: true,
2753
+ validator: {
2754
+ input: z.enum(CheckoutSessionMode).optional(),
2755
+ output: z.enum(CheckoutSessionMode)
2756
+ }
2757
+ },
2758
+ customerId: {
2759
+ type: "uuid",
2760
+ fieldName: "customer_id",
2761
+ required: true,
2762
+ references: {
2763
+ model: "customer",
2764
+ field: "id",
2765
+ onDelete: "cascade"
2766
+ },
2767
+ validator: {
2768
+ input: z.uuid(),
2769
+ output: z.uuid()
2770
+ },
2771
+ index: true
2772
+ },
2773
+ customerEmail: {
2774
+ type: "string",
2775
+ fieldName: "customer_email_address",
2776
+ required: true,
2777
+ sortable: true,
2778
+ validator: {
2779
+ input: z.string().email().max(255),
2780
+ output: z.string()
2781
+ }
2782
+ },
2783
+ paymentIntentId: {
2784
+ type: "uuid",
2785
+ fieldName: "payment_intent_id",
2786
+ required: true,
2787
+ references: {
2788
+ model: "payment_intents",
2789
+ field: "id",
2790
+ onDelete: "cascade"
2791
+ },
2792
+ validator: {
2793
+ input: z.uuid(),
2794
+ output: z.uuid()
2795
+ },
2796
+ index: true
2797
+ },
2798
+ subscriptionId: {
2799
+ type: "uuid",
2800
+ fieldName: "subscription_id",
2801
+ required: true,
2802
+ references: {
2803
+ model: "subscription",
2804
+ field: "id",
2805
+ onDelete: "cascade"
2806
+ },
2807
+ validator: {
2808
+ input: z.uuid(),
2809
+ output: z.uuid()
2810
+ },
2811
+ index: true
2812
+ },
2813
+ metadata: {
2814
+ type: "json",
2815
+ fieldName: "metadata",
2816
+ required: false,
2817
+ validator: {
2818
+ input: z.unknown().optional(),
2819
+ output: z.unknown().optional()
2820
+ }
2821
+ },
2822
+ status: {
2823
+ type: "string",
2824
+ fieldName: "checkout_session_status",
2825
+ required: true,
2826
+ defaultValue: CheckoutSessionStatus.OPEN,
2827
+ sortable: true,
2828
+ validator: {
2829
+ input: z.enum(CheckoutSessionStatus).optional(),
2830
+ output: z.enum(CheckoutSessionStatus)
2831
+ },
2832
+ index: true
2833
+ },
2834
+ createdAt: {
2835
+ type: "date",
2836
+ fieldName: "created_at",
2837
+ required: true,
2838
+ input: false,
2839
+ returned: true,
2840
+ defaultValue: () => /* @__PURE__ */ new Date(),
2841
+ validator: { output: z.date() },
2842
+ index: true
2843
+ },
2844
+ updatedAt: {
2845
+ type: "date",
2846
+ fieldName: "updated_at",
2847
+ required: true,
2848
+ input: false,
2849
+ returned: true,
2850
+ defaultValue: () => /* @__PURE__ */ new Date(),
2851
+ onUpdate: () => /* @__PURE__ */ new Date(),
2852
+ validator: { output: z.date() }
2853
+ },
2854
+ completedAt: {
2855
+ type: "date",
2856
+ fieldName: "completed_at",
2857
+ required: false,
2858
+ input: false,
2859
+ returned: true,
2860
+ validator: { output: z.date().optional() }
2861
+ }
2862
+ },
2863
+ constraints: { indexes: [{
2864
+ name: "checkout_sessions_expires_at_idx",
2865
+ fields: ["expiresAt"]
2866
+ }, {
2867
+ name: "checkout_sessions_status_created_at_idx",
2868
+ fields: ["status", "createdAt"]
2869
+ }] },
2870
+ relations: {
2871
+ events: {
2872
+ kind: "many",
2873
+ model: "sessions",
2874
+ foreignKey: "sessionId"
2875
+ },
2876
+ customer: {
2877
+ kind: "one",
2878
+ model: "customer",
2879
+ foreignKey: "customerId"
2880
+ },
2881
+ paymentIntent: {
2882
+ kind: "one",
2883
+ model: "payment_intent",
2884
+ foreignKey: "paymentIntentId"
2885
+ },
2886
+ subscription: {
2887
+ kind: "one",
2888
+ model: "subscription",
2889
+ foreignKey: "subscriptionId"
2890
+ }
2891
+ }
2892
+ },
2893
+ paymentIntent: {
2894
+ modelName: "payment_intent",
2895
+ order: 1,
2896
+ fields: {
2897
+ id: {
2898
+ type: "uuid",
2899
+ fieldName: "id",
2900
+ required: true,
2901
+ input: false,
2902
+ returned: true,
2903
+ unique: true,
2904
+ validator: { output: z.uuid() }
2905
+ },
2906
+ amount: {
2907
+ type: "number",
2908
+ fieldName: "amount",
2909
+ required: true,
2910
+ defaultValue: 0,
2911
+ validator: {
2912
+ input: z.number().int().min(0).optional(),
2913
+ output: z.number().int()
2914
+ }
2915
+ },
2916
+ currency: {
2917
+ type: "string",
2918
+ fieldName: "currency",
2919
+ required: true,
2920
+ defaultValue: Currency.KES,
2921
+ sortable: true,
2922
+ validator: {
2923
+ input: z.enum(Currency).optional(),
2924
+ output: z.enum(Currency)
2925
+ }
2926
+ },
2927
+ phoneNumber: {
2928
+ type: "string",
2929
+ fieldName: "phone_number",
2930
+ required: true,
2931
+ sortable: true,
2932
+ validator: {
2933
+ input: z.string().max(15),
2934
+ output: z.string()
2935
+ }
2936
+ },
2937
+ provider: {
2938
+ type: "string",
2939
+ fieldName: "payment_provider",
2940
+ required: true,
2941
+ defaultValue: PaymentProviders.MPESA,
2942
+ sortable: true,
2943
+ validator: {
2944
+ input: z.enum(PaymentProviders).optional(),
2945
+ output: z.enum(PaymentProviders)
2946
+ }
2947
+ },
2948
+ status: {
2949
+ type: "string",
2950
+ fieldName: "payment_intent_status",
2951
+ required: true,
2952
+ defaultValue: PaymentIntentStatus.REQUIRES_CONFIRMATION,
2953
+ sortable: true,
2954
+ validator: {
2955
+ input: z.enum(PaymentIntentStatus).optional(),
2956
+ output: z.enum(PaymentIntentStatus)
2957
+ },
2958
+ index: true
2959
+ },
2960
+ idempotencyKey: {
2961
+ type: "uuid",
2962
+ fieldName: "idempotency_key",
2963
+ required: true,
2964
+ unique: true,
2965
+ validator: {
2966
+ input: z.uuid(),
2967
+ output: z.uuid()
2968
+ },
2969
+ index: true
2970
+ },
2971
+ providerTransactionId: {
2972
+ type: "string",
2973
+ fieldName: "provider_transaction_id",
2974
+ required: true,
2975
+ unique: true,
2976
+ sortable: true,
2977
+ validator: {
2978
+ input: z.string().max(255),
2979
+ output: z.string()
2980
+ },
2981
+ index: true
2982
+ },
2983
+ providerMetadata: {
2984
+ type: "json",
2985
+ fieldName: "provider_metadata",
2986
+ required: false,
2987
+ validator: {
2988
+ input: z.unknown().optional(),
2989
+ output: z.unknown().optional()
2990
+ }
2991
+ },
2992
+ customerId: {
2993
+ type: "uuid",
2994
+ fieldName: "customer_id",
2995
+ required: true,
2996
+ references: {
2997
+ model: "customer",
2998
+ field: "id",
2999
+ onDelete: "cascade"
3000
+ },
3001
+ validator: {
3002
+ input: z.uuid(),
3003
+ output: z.uuid()
3004
+ },
3005
+ index: true
3006
+ },
3007
+ subscriptionId: {
3008
+ type: "uuid",
3009
+ fieldName: "subscription_id",
3010
+ required: true,
3011
+ references: {
3012
+ model: "subscription",
3013
+ field: "id",
3014
+ onDelete: "cascade"
3015
+ },
3016
+ validator: {
3017
+ input: z.uuid(),
3018
+ output: z.uuid()
3019
+ },
3020
+ index: true
3021
+ },
3022
+ invoiceId: {
3023
+ type: "uuid",
3024
+ fieldName: "invoice_id",
3025
+ required: true,
3026
+ references: {
3027
+ model: "invoice",
3028
+ field: "id",
3029
+ onDelete: "cascade"
3030
+ },
3031
+ validator: {
3032
+ input: z.uuid(),
3033
+ output: z.uuid()
3034
+ },
3035
+ index: true
3036
+ },
3037
+ description: {
3038
+ type: "string",
3039
+ fieldName: "payment_intent_description",
3040
+ required: false
3041
+ },
3042
+ lastPaymentError: {
3043
+ type: "json",
3044
+ fieldName: "last_payment_error",
3045
+ required: false,
3046
+ returned: false,
3047
+ validator: {
3048
+ input: z.unknown().optional(),
3049
+ output: z.unknown().optional()
3050
+ }
3051
+ },
3052
+ metadata: {
3053
+ type: "json",
3054
+ fieldName: "metadata",
3055
+ required: false,
3056
+ validator: {
3057
+ input: z.unknown().optional(),
3058
+ output: z.unknown().optional()
3059
+ }
3060
+ },
3061
+ createdAt: {
3062
+ type: "date",
3063
+ fieldName: "created_at",
3064
+ required: true,
3065
+ input: false,
3066
+ returned: true,
3067
+ defaultValue: () => /* @__PURE__ */ new Date(),
3068
+ validator: { output: z.date() },
3069
+ index: true
3070
+ },
3071
+ updatedAt: {
3072
+ type: "date",
3073
+ fieldName: "updated_at",
3074
+ required: true,
3075
+ input: false,
3076
+ returned: true,
3077
+ defaultValue: () => /* @__PURE__ */ new Date(),
3078
+ onUpdate: () => /* @__PURE__ */ new Date(),
3079
+ validator: { output: z.date() }
3080
+ },
3081
+ completedAt: {
3082
+ type: "date",
3083
+ fieldName: "completed_at",
3084
+ required: false,
3085
+ input: false,
3086
+ returned: true,
3087
+ validator: { output: z.date().optional() }
3088
+ },
3089
+ canceledAt: {
3090
+ type: "date",
3091
+ fieldName: "canceled_at",
3092
+ required: false,
3093
+ input: false,
3094
+ returned: true,
3095
+ validator: { output: z.date().optional() }
3096
+ }
3097
+ },
3098
+ constraints: { indexes: [
3099
+ {
3100
+ name: "payment_intent_status_created_at_idx",
3101
+ fields: ["status", "createdAt"]
3102
+ },
3103
+ {
3104
+ name: "payment_intent_provider_transaction_id_idx",
3105
+ fields: ["providerTransactionId"]
3106
+ },
3107
+ {
3108
+ name: "payment_intent_customer_id_created_at_idx",
3109
+ fields: ["customerId", "createdAt"]
3110
+ },
3111
+ {
3112
+ name: "payment_intent_subscription_id_idx",
3113
+ fields: ["subscriptionId"]
3114
+ },
3115
+ {
3116
+ name: "payment_intent_invoice_id_idx",
3117
+ fields: ["invoiceId"]
3118
+ }
3119
+ ] },
3120
+ checks: [{
3121
+ name: "payment_intent_amount_gte_0",
3122
+ kind: "gte",
3123
+ field: "amount",
3124
+ value: 0
3125
+ }],
3126
+ relations: {
3127
+ customer: {
3128
+ kind: "one",
3129
+ model: "customer",
3130
+ foreignKey: "customerId"
3131
+ },
3132
+ subscription: {
3133
+ kind: "one",
3134
+ model: "subscription",
3135
+ foreignKey: "subscriptionId"
3136
+ },
3137
+ invoice: {
3138
+ kind: "one",
3139
+ model: "invoice",
3140
+ foreignKey: "invoiceId"
3141
+ },
3142
+ checkoutSession: {
3143
+ kind: "one",
3144
+ model: "checkout_sessions",
3145
+ foreignKey: "id"
3146
+ },
3147
+ transaction: {
3148
+ kind: "one",
3149
+ model: "transactions",
3150
+ foreignKey: "id"
3151
+ }
3152
+ }
3153
+ },
3154
+ transaction: {
3155
+ modelName: "transactions",
3156
+ order: 1,
3157
+ fields: {
3158
+ id: {
3159
+ type: "uuid",
3160
+ fieldName: "id",
3161
+ required: true,
3162
+ input: false,
3163
+ returned: true,
3164
+ unique: true,
3165
+ validator: { output: z.uuid() }
3166
+ },
3167
+ amount: {
3168
+ type: "number",
3169
+ fieldName: "amount",
3170
+ required: true,
3171
+ defaultValue: 0,
3172
+ validator: {
3173
+ input: z.number().int().min(0).optional(),
3174
+ output: z.number().int()
3175
+ }
3176
+ },
3177
+ currency: {
3178
+ type: "string",
3179
+ fieldName: "currency",
3180
+ required: true,
3181
+ defaultValue: Currency.KES,
3182
+ sortable: true,
3183
+ validator: {
3184
+ input: z.enum(Currency).optional(),
3185
+ output: z.enum(Currency)
3186
+ }
3187
+ },
3188
+ type: {
3189
+ type: "string",
3190
+ fieldName: "transaction_type",
3191
+ required: true,
3192
+ defaultValue: TransactionType.PAYMENT,
3193
+ sortable: true,
3194
+ validator: {
3195
+ input: z.enum(TransactionType).optional(),
3196
+ output: z.enum(TransactionType)
3197
+ },
3198
+ index: true
3199
+ },
3200
+ status: {
3201
+ type: "string",
3202
+ fieldName: "transaction_status",
3203
+ required: true,
3204
+ defaultValue: TransactionStatus.PENDING,
3205
+ sortable: true,
3206
+ validator: {
3207
+ input: z.enum(TransactionStatus).optional(),
3208
+ output: z.enum(TransactionStatus)
3209
+ },
3210
+ index: true
3211
+ },
3212
+ paymentIntentId: {
3213
+ type: "uuid",
3214
+ fieldName: "payment_intent_id",
3215
+ required: true,
3216
+ references: {
3217
+ model: "payment_intent",
3218
+ field: "id",
3219
+ onDelete: "cascade"
3220
+ },
3221
+ validator: {
3222
+ input: z.uuid(),
3223
+ output: z.uuid()
3224
+ },
3225
+ index: true
3226
+ },
3227
+ customerId: {
3228
+ type: "uuid",
3229
+ fieldName: "customer_id",
3230
+ required: true,
3231
+ references: {
3232
+ model: "customer",
3233
+ field: "id",
3234
+ onDelete: "cascade"
3235
+ },
3236
+ validator: {
3237
+ input: z.uuid(),
3238
+ output: z.uuid()
3239
+ },
3240
+ index: true
3241
+ },
3242
+ provider: {
3243
+ type: "string",
3244
+ fieldName: "payment_provider",
3245
+ required: true,
3246
+ defaultValue: PaymentProviders.MPESA,
3247
+ sortable: true,
3248
+ validator: {
3249
+ input: z.enum(PaymentProviders).optional(),
3250
+ output: z.enum(PaymentProviders)
3251
+ }
3252
+ },
3253
+ providerReference: {
3254
+ type: "string",
3255
+ fieldName: "payment_provider_reference",
3256
+ required: true,
3257
+ sortable: true,
3258
+ validator: {
3259
+ input: z.string().max(255),
3260
+ output: z.string()
3261
+ },
3262
+ index: true
3263
+ },
3264
+ providerMetadata: {
3265
+ type: "json",
3266
+ fieldName: "provider_metadata",
3267
+ required: false,
3268
+ validator: {
3269
+ input: z.unknown().optional(),
3270
+ output: z.unknown().optional()
3271
+ }
3272
+ },
3273
+ reversedById: {
3274
+ type: "uuid",
3275
+ fieldName: "reversed_by_id",
3276
+ required: false,
3277
+ validator: {
3278
+ input: z.uuid().optional(),
3279
+ output: z.uuid().optional()
3280
+ },
3281
+ index: true
3282
+ },
3283
+ description: {
3284
+ type: "string",
3285
+ fieldName: "transaction_description",
3286
+ required: false
3287
+ },
3288
+ metadata: {
3289
+ type: "json",
3290
+ fieldName: "metadata",
3291
+ required: false,
3292
+ validator: {
3293
+ input: z.unknown().optional(),
3294
+ output: z.unknown().optional()
3295
+ }
3296
+ },
3297
+ createdAt: {
3298
+ type: "date",
3299
+ fieldName: "created_at",
3300
+ required: true,
3301
+ input: false,
3302
+ returned: true,
3303
+ defaultValue: () => /* @__PURE__ */ new Date(),
3304
+ validator: { output: z.date() },
3305
+ index: true
3306
+ },
3307
+ updatedAt: {
3308
+ type: "date",
3309
+ fieldName: "updated_at",
3310
+ required: true,
3311
+ input: false,
3312
+ returned: true,
3313
+ defaultValue: () => /* @__PURE__ */ new Date(),
3314
+ onUpdate: () => /* @__PURE__ */ new Date(),
3315
+ validator: { output: z.date() }
3316
+ }
3317
+ },
3318
+ constraints: { indexes: [
3319
+ {
3320
+ name: "transactions_customer_id_created_at_idx",
3321
+ fields: ["customerId", "createdAt"]
3322
+ },
3323
+ {
3324
+ name: "transactions_status_type_created_at_idx",
3325
+ fields: [
3326
+ "status",
3327
+ "type",
3328
+ "createdAt"
3329
+ ]
3330
+ },
3331
+ {
3332
+ name: "transactions_provider_reference_idx",
3333
+ fields: ["providerReference"]
3334
+ },
3335
+ {
3336
+ name: "transactions_reversed_by_id_idx",
3337
+ fields: ["reversedById"]
3338
+ }
3339
+ ] },
3340
+ checks: [{
3341
+ name: "transactions_amount_gte_0",
3342
+ kind: "gte",
3343
+ field: "amount",
3344
+ value: 0
3345
+ }],
3346
+ relations: {
3347
+ customer: {
3348
+ kind: "one",
3349
+ model: "customer",
3350
+ foreignKey: "customerId"
3351
+ },
3352
+ paymentIntent: {
3353
+ kind: "one",
3354
+ model: "payment_intent",
3355
+ foreignKey: "paymentIntentId"
3356
+ },
3357
+ reversedBy: {
3358
+ kind: "one",
3359
+ model: "transactions",
3360
+ foreignKey: "reversedById"
3361
+ },
3362
+ reverses: {
3363
+ kind: "many",
3364
+ model: "transactions",
3365
+ foreignKey: "reversedById"
3366
+ }
3367
+ }
3368
+ },
3369
+ scheduledTask: {
3370
+ modelName: "scheduled_tasks",
3371
+ order: 1,
3372
+ fields: {
3373
+ id: {
3374
+ type: "uuid",
3375
+ fieldName: "id",
3376
+ required: true,
3377
+ input: false,
3378
+ returned: true,
3379
+ unique: true,
3380
+ validator: { output: z.uuid() }
3381
+ },
3382
+ taskType: {
3383
+ type: "string",
3384
+ fieldName: "scheduled_task_type",
3385
+ required: false,
3386
+ sortable: true,
3387
+ validator: {
3388
+ input: z.enum(ScheduledTaskType).optional(),
3389
+ output: z.enum(ScheduledTaskType).optional()
3390
+ },
3391
+ index: true
3392
+ },
3393
+ relatedObjectType: {
3394
+ type: "string",
3395
+ fieldName: "related_object_type",
3396
+ required: false,
3397
+ sortable: true,
3398
+ validator: {
3399
+ input: z.string().max(50).optional(),
3400
+ output: z.string().max(50).optional()
3401
+ },
3402
+ index: true
3403
+ },
3404
+ relatedObjectId: {
3405
+ type: "string",
3406
+ fieldName: "related_object_id",
3407
+ required: false,
3408
+ sortable: true,
3409
+ validator: {
3410
+ input: z.string().max(255).optional(),
3411
+ output: z.string().max(255).optional()
3412
+ },
3413
+ index: true
3414
+ },
3415
+ scheduledFor: {
3416
+ type: "date",
3417
+ fieldName: "scheduled_for",
3418
+ required: false,
3419
+ validator: {
3420
+ input: z.date().optional(),
3421
+ output: z.date().optional()
3422
+ },
3423
+ index: true
3424
+ },
3425
+ status: {
3426
+ type: "string",
3427
+ fieldName: "status",
3428
+ required: false,
3429
+ defaultValue: ScheduledTaskStatus.PENDING,
3430
+ sortable: true,
3431
+ validator: {
3432
+ input: z.enum(ScheduledTaskStatus).optional(),
3433
+ output: z.enum(ScheduledTaskStatus).optional()
3434
+ },
3435
+ index: true
3436
+ },
3437
+ attemptCount: {
3438
+ type: "number",
3439
+ fieldName: "attempt_count",
3440
+ required: false,
3441
+ defaultValue: 0,
3442
+ validator: {
3443
+ input: z.number().int().min(0).optional(),
3444
+ output: z.number().int().optional()
3445
+ }
3446
+ },
3447
+ maxAttemptCount: {
3448
+ type: "number",
3449
+ fieldName: "max_attempt_count",
3450
+ required: false,
3451
+ defaultValue: 3,
3452
+ validator: {
3453
+ input: z.number().int().min(0).optional(),
3454
+ output: z.number().int().optional()
3455
+ }
3456
+ },
3457
+ lastAttemptAt: {
3458
+ type: "date",
3459
+ fieldName: "last_attempt_at",
3460
+ required: false,
3461
+ input: false,
3462
+ returned: true,
3463
+ validator: { output: z.date().optional() }
3464
+ },
3465
+ completedAt: {
3466
+ type: "date",
3467
+ fieldName: "completed_at",
3468
+ required: false,
3469
+ input: false,
3470
+ returned: true,
3471
+ validator: { output: z.date().optional() }
3472
+ },
3473
+ scheduledTaskResult: {
3474
+ type: "json",
3475
+ fieldName: "scheduled_task_result",
3476
+ required: false,
3477
+ validator: {
3478
+ input: z.unknown().optional(),
3479
+ output: z.unknown().optional()
3480
+ }
3481
+ },
3482
+ error: {
3483
+ type: "string",
3484
+ fieldName: "error",
3485
+ required: false
3486
+ },
3487
+ payload: {
3488
+ type: "json",
3489
+ fieldName: "payload",
3490
+ required: false,
3491
+ validator: {
3492
+ input: z.unknown().optional(),
3493
+ output: z.unknown().optional()
3494
+ }
3495
+ },
3496
+ createdAt: {
3497
+ type: "date",
3498
+ fieldName: "created_at",
3499
+ required: true,
3500
+ input: false,
3501
+ returned: true,
3502
+ defaultValue: () => /* @__PURE__ */ new Date(),
3503
+ validator: { output: z.date() },
3504
+ index: true
3505
+ },
3506
+ updatedAt: {
3507
+ type: "date",
3508
+ fieldName: "updated_at",
3509
+ required: true,
3510
+ input: false,
3511
+ returned: true,
3512
+ defaultValue: () => /* @__PURE__ */ new Date(),
3513
+ onUpdate: () => /* @__PURE__ */ new Date(),
3514
+ validator: { output: z.date() }
3515
+ }
3516
+ },
3517
+ constraints: { indexes: [
3518
+ {
3519
+ name: "scheduled_tasks_scheduled_for_status_idx",
3520
+ fields: ["scheduledFor", "status"]
3521
+ },
3522
+ {
3523
+ name: "scheduled_tasks_scheduled_for_status_task_type_idx",
3524
+ fields: [
3525
+ "scheduledFor",
3526
+ "status",
3527
+ "taskType"
3528
+ ]
3529
+ },
3530
+ {
3531
+ name: "scheduled_tasks_related_object_type_related_object_id_idx",
3532
+ fields: ["relatedObjectType", "relatedObjectId"]
3533
+ }
3534
+ ] },
3535
+ checks: [{
3536
+ name: "scheduled_tasks_attempt_count_gte_0",
3537
+ kind: "gte",
3538
+ field: "attemptCount",
3539
+ value: 0
3540
+ }, {
3541
+ name: "scheduled_tasks_max_attempt_count_gte_0",
3542
+ kind: "gte",
3543
+ field: "maxAttemptCount",
3544
+ value: 0
3545
+ }]
3546
+ },
3547
+ auditLog: {
3548
+ modelName: "audit_logs",
3549
+ order: 1,
3550
+ fields: {
3551
+ id: {
3552
+ type: "uuid",
3553
+ fieldName: "id",
3554
+ required: true,
3555
+ input: false,
3556
+ returned: true,
3557
+ unique: true,
3558
+ validator: { output: z.uuid() }
3559
+ },
3560
+ action: {
3561
+ type: "string",
3562
+ fieldName: "audit_action",
3563
+ required: false,
3564
+ sortable: true,
3565
+ validator: {
3566
+ input: z.enum(AuditAction).optional(),
3567
+ output: z.enum(AuditAction).optional()
3568
+ },
3569
+ index: true
3570
+ },
3571
+ actor: {
3572
+ type: "string",
3573
+ fieldName: "actor",
3574
+ required: false,
3575
+ sortable: true,
3576
+ validator: {
3577
+ input: z.enum(Actor).optional(),
3578
+ output: z.enum(Actor).optional()
3579
+ },
3580
+ index: true
3581
+ },
3582
+ objectType: {
3583
+ type: "string",
3584
+ fieldName: "object_type",
3585
+ required: false,
3586
+ sortable: true,
3587
+ validator: {
3588
+ input: z.string().max(50).optional(),
3589
+ output: z.string().max(50).optional()
3590
+ },
3591
+ index: true
3592
+ },
3593
+ objectId: {
3594
+ type: "string",
3595
+ fieldName: "object_id",
3596
+ required: false,
3597
+ sortable: true,
3598
+ validator: {
3599
+ input: z.string().max(255).optional(),
3600
+ output: z.string().max(255).optional()
3601
+ },
3602
+ index: true
3603
+ },
3604
+ changes: {
3605
+ type: "json",
3606
+ fieldName: "changes",
3607
+ required: false,
3608
+ validator: {
3609
+ input: z.unknown().optional(),
3610
+ output: z.unknown().optional()
3611
+ }
3612
+ },
3613
+ ipAddress: {
3614
+ type: "string",
3615
+ fieldName: "ip_address",
3616
+ required: false,
3617
+ sortable: true,
3618
+ validator: {
3619
+ input: z.string().max(45).optional(),
3620
+ output: z.string().max(45).optional()
3621
+ }
3622
+ },
3623
+ userAgent: {
3624
+ type: "string",
3625
+ fieldName: "user_agent",
3626
+ required: false,
3627
+ validator: {
3628
+ input: z.string().optional(),
3629
+ output: z.string().optional()
3630
+ }
3631
+ },
3632
+ apiVersion: {
3633
+ type: "string",
3634
+ fieldName: "api_version",
3635
+ required: false,
3636
+ sortable: true,
3637
+ validator: {
3638
+ input: z.string().max(20).optional(),
3639
+ output: z.string().max(20).optional()
3640
+ }
3641
+ },
3642
+ createdAt: {
3643
+ type: "date",
3644
+ fieldName: "created_at",
3645
+ required: true,
3646
+ input: false,
3647
+ returned: true,
3648
+ defaultValue: () => /* @__PURE__ */ new Date(),
3649
+ validator: { output: z.date() },
3650
+ index: true
3651
+ }
3652
+ },
3653
+ constraints: { indexes: [
3654
+ {
3655
+ name: "audit_logs_object_type_object_id_created_at_idx",
3656
+ fields: [
3657
+ "objectType",
3658
+ "objectId",
3659
+ "createdAt"
3660
+ ]
3661
+ },
3662
+ {
3663
+ name: "audit_logs_created_at_action_idx",
3664
+ fields: ["createdAt", "action"]
3665
+ },
3666
+ {
3667
+ name: "audit_logs_actor_created_at_idx",
3668
+ fields: ["actor", "createdAt"]
3669
+ }
3670
+ ] }
3671
+ },
3672
+ ...pluginTables
3673
+ };
3674
+ };
3675
+
3676
+ //#endregion
3677
+ export { initGetFieldAttributes as a, initGetDefaultModelName as c, initGetModelName as i, deepmerge as n, initGetIdField as o, withApplyDefault as r, initGetDefaultFieldName as s, getPaymentTables as t };