@erxes/core-contract 0.1.0-v2.0 → 0.1.0-v2.2

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 (102) hide show
  1. package/dist/activities.d.ts +1394 -139
  2. package/dist/activities.js +96 -40
  3. package/dist/audit.d.ts +1092 -48
  4. package/dist/audit.js +37 -23
  5. package/dist/auth.d.ts +2867 -61
  6. package/dist/auth.js +55 -25
  7. package/dist/automationRuns.d.ts +12 -13
  8. package/dist/automationRuns.js +15 -30
  9. package/dist/automations.d.ts +2474 -93
  10. package/dist/automations.js +56 -44
  11. package/dist/client.d.ts +30704 -0
  12. package/dist/client.js +62 -0
  13. package/dist/common.d.ts +28 -16
  14. package/dist/common.js +30 -22
  15. package/dist/companies.d.ts +1154 -44
  16. package/dist/companies.js +33 -17
  17. package/dist/contract/routes.json.js +1810 -0
  18. package/dist/customerAuth.d.ts +1661 -0
  19. package/dist/customerAuth.js +197 -0
  20. package/dist/customers.d.ts +1283 -65
  21. package/dist/customers.js +35 -25
  22. package/dist/{automationDefinition.d.ts → db/src/automationDefinition.d.ts} +4 -3
  23. package/dist/{automationDefinition.js → db/src/automationDefinition.js} +10 -32
  24. package/dist/db/src/enums.d.ts +8 -0
  25. package/dist/db/src/enums.js +334 -0
  26. package/dist/db/src/schema/auditStreams.js +6 -14
  27. package/dist/db/src/schema/authTokens.js +4 -6
  28. package/dist/db/src/schema/automations.d.ts +1 -0
  29. package/dist/db/src/schema/automations.js +15 -31
  30. package/dist/db/src/schema/common.d.ts +2 -6
  31. package/dist/db/src/schema/common.js +1 -24
  32. package/dist/db/src/schema/companies.js +6 -5
  33. package/dist/db/src/schema/customerAuth.js +101 -0
  34. package/dist/db/src/schema/customers.js +6 -6
  35. package/dist/db/src/schema/events.js +12 -60
  36. package/dist/db/src/schema/fieldValues.js +2 -2
  37. package/dist/db/src/schema/fields.js +10 -28
  38. package/dist/db/src/schema/index.d.ts +3 -0
  39. package/dist/db/src/schema/index.js +22 -20
  40. package/dist/db/src/schema/leadStages.js +5 -10
  41. package/dist/db/src/schema/leads.js +6 -11
  42. package/dist/db/src/schema/notes.js +92 -0
  43. package/dist/db/src/schema/oauth.js +3 -3
  44. package/dist/db/src/schema/payments.js +13 -23
  45. package/dist/db/src/schema/platform.js +11 -31
  46. package/dist/db/src/schema/plugins.js +10 -5
  47. package/dist/db/src/schema/products.js +7 -8
  48. package/dist/db/src/schema/rateLimits.js +7 -0
  49. package/dist/db/src/schema/saas.js +3 -9
  50. package/dist/db/src/schema/tags.js +6 -5
  51. package/dist/db/src/schema/transfer.js +13 -33
  52. package/dist/db/src/schema/trash.js +6 -7
  53. package/dist/db/src/schema/users.js +6 -10
  54. package/dist/db/src/schema/views.js +5 -13
  55. package/dist/db/src/schema/webhooks.js +7 -14
  56. package/dist/db/src/table.js +16 -2
  57. package/dist/errors.d.ts +516 -0
  58. package/dist/errors.js +218 -0
  59. package/dist/events.d.ts +585 -140
  60. package/dist/events.js +57 -42
  61. package/dist/fields.d.ts +1478 -66
  62. package/dist/fields.js +33 -47
  63. package/dist/files.d.ts +766 -62
  64. package/dist/files.js +34 -22
  65. package/dist/index.d.ts +25707 -902
  66. package/dist/index.js +22 -20
  67. package/dist/leads.d.ts +1108 -22
  68. package/dist/leads.js +39 -20
  69. package/dist/notifications.d.ts +691 -94
  70. package/dist/notifications.js +45 -91
  71. package/dist/organizations.d.ts +263 -5
  72. package/dist/organizations.js +21 -2
  73. package/dist/payments.d.ts +1794 -120
  74. package/dist/payments.js +58 -60
  75. package/dist/platform.d.ts +12 -20
  76. package/dist/platform.js +8 -21
  77. package/dist/plugins.d.ts +808 -71
  78. package/dist/plugins.js +66 -35
  79. package/dist/products.d.ts +1411 -53
  80. package/dist/products.js +40 -23
  81. package/dist/roles.d.ts +560 -8
  82. package/dist/roles.js +25 -11
  83. package/dist/routes.d.ts +8 -0
  84. package/dist/routes.js +13 -0
  85. package/dist/saas.d.ts +164 -8
  86. package/dist/saas.js +14 -29
  87. package/dist/tags.d.ts +344 -8
  88. package/dist/tags.js +16 -8
  89. package/dist/transfer.d.ts +1361 -36
  90. package/dist/transfer.js +47 -49
  91. package/dist/trash.d.ts +299 -23
  92. package/dist/trash.js +27 -20
  93. package/dist/users.d.ts +1233 -59
  94. package/dist/users.js +48 -39
  95. package/dist/values.d.ts +150 -0
  96. package/dist/values.js +139 -0
  97. package/dist/views.d.ts +404 -13
  98. package/dist/views.js +18 -28
  99. package/dist/webhooks.d.ts +791 -29
  100. package/dist/webhooks.js +36 -21
  101. package/package.json +9 -2
  102. package/dist/db/src/schema/jobs.js +0 -44
package/dist/views.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { ConditionGroup } from "./db/src/schema/common.js";
2
+ import "./db/src/schema/index.js";
2
3
  import { z } from "zod";
3
4
  /** The list a view belongs to: customers, leads (people), companies, company leads, products. */
4
5
  export declare const ViewRecordType: z.ZodEnum<{
@@ -68,8 +69,8 @@ export declare const View: z.ZodObject<{
68
69
  }, z.core.$strip>>;
69
70
  shared: z.ZodBoolean;
70
71
  createdBy: z.ZodString;
71
- createdAt: z.ZodISODateTime;
72
- updatedAt: z.ZodISODateTime;
72
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
73
+ updatedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
73
74
  editable: z.ZodBoolean;
74
75
  }, {
75
76
  out: {};
@@ -109,14 +110,92 @@ export declare const viewsContract: {
109
110
  }, z.core.$strip>>;
110
111
  shared: z.ZodBoolean;
111
112
  createdBy: z.ZodString;
112
- createdAt: z.ZodISODateTime;
113
- updatedAt: z.ZodISODateTime;
113
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
114
+ updatedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
114
115
  editable: z.ZodBoolean;
115
116
  }, {
116
117
  out: {};
117
118
  in: {};
118
119
  }>>;
119
- }, z.core.$strip>, Record<never, never>, Record<never, never>>;
120
+ }, z.core.$strip>, import("@orpc/contract").MergedErrorMap<Record<never, never>, {
121
+ UNAUTHORIZED: {
122
+ status: number;
123
+ };
124
+ NOT_ALLOWED: {
125
+ status: number;
126
+ data: z.ZodOptional<z.ZodObject<{
127
+ permission: z.ZodString;
128
+ }, z.core.$strip>>;
129
+ };
130
+ PLUGIN_ONLY: {
131
+ status: number;
132
+ };
133
+ MEMBERS_ONLY: {
134
+ status: number;
135
+ };
136
+ ORG_REQUIRED: {
137
+ status: number;
138
+ };
139
+ SCOPE_REQUIRED: {
140
+ status: number;
141
+ };
142
+ SERVICE_TOKEN_REQUIRED: {
143
+ status: number;
144
+ };
145
+ ORGANIZATION_DISABLED: {
146
+ status: number;
147
+ data: z.ZodObject<{
148
+ manageUrl: z.ZodNullable<z.ZodString>;
149
+ }, z.core.$strip>;
150
+ };
151
+ NOT_IN_PLAN: {
152
+ status: number;
153
+ data: z.ZodOptional<z.ZodObject<{
154
+ manageUrl: z.ZodNullable<z.ZodString>;
155
+ }, z.core.$strip>>;
156
+ };
157
+ READ_ONLY: {
158
+ status: number;
159
+ };
160
+ TOO_MANY_REQUESTS: {
161
+ status: number;
162
+ };
163
+ INVALID_INPUT: {
164
+ status: number;
165
+ data: z.ZodObject<{
166
+ issues: z.ZodArray<z.ZodObject<{
167
+ path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodInt]>>;
168
+ message: z.ZodString;
169
+ }, z.core.$strip>>;
170
+ }, z.core.$strip>;
171
+ };
172
+ NOT_FOUND: {
173
+ status: number;
174
+ };
175
+ TAKEN: {
176
+ status: number;
177
+ data: z.ZodObject<{
178
+ field: z.ZodString;
179
+ id: z.ZodOptional<z.ZodString>;
180
+ values: z.ZodOptional<z.ZodArray<z.ZodString>>;
181
+ }, z.core.$strip>;
182
+ };
183
+ INVALID_CURSOR: {
184
+ status: number;
185
+ };
186
+ INVALID_REFERENCE: {
187
+ status: number;
188
+ data: z.ZodObject<{
189
+ field: z.ZodString;
190
+ }, z.core.$strip>;
191
+ };
192
+ INVALID_FILTER: {
193
+ status: number;
194
+ };
195
+ FILTER_TOO_SLOW: {
196
+ status: number;
197
+ };
198
+ }>, Record<never, never>>;
120
199
  create: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
121
200
  name: z.ZodNonOptional<z.ZodOptional<z.ZodString>>;
122
201
  filter: z.ZodOptional<z.ZodNullable<z.ZodType<ConditionGroup, unknown, z.core.$ZodTypeInternals<ConditionGroup, unknown>>>>;
@@ -162,13 +241,91 @@ export declare const viewsContract: {
162
241
  }, z.core.$strip>>;
163
242
  shared: z.ZodBoolean;
164
243
  createdBy: z.ZodString;
165
- createdAt: z.ZodISODateTime;
166
- updatedAt: z.ZodISODateTime;
244
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
245
+ updatedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
167
246
  editable: z.ZodBoolean;
168
247
  }, {
169
248
  out: {};
170
249
  in: {};
171
- }>, Record<never, never>, Record<never, never>>;
250
+ }>, import("@orpc/contract").MergedErrorMap<Record<never, never>, {
251
+ UNAUTHORIZED: {
252
+ status: number;
253
+ };
254
+ NOT_ALLOWED: {
255
+ status: number;
256
+ data: z.ZodOptional<z.ZodObject<{
257
+ permission: z.ZodString;
258
+ }, z.core.$strip>>;
259
+ };
260
+ PLUGIN_ONLY: {
261
+ status: number;
262
+ };
263
+ MEMBERS_ONLY: {
264
+ status: number;
265
+ };
266
+ ORG_REQUIRED: {
267
+ status: number;
268
+ };
269
+ SCOPE_REQUIRED: {
270
+ status: number;
271
+ };
272
+ SERVICE_TOKEN_REQUIRED: {
273
+ status: number;
274
+ };
275
+ ORGANIZATION_DISABLED: {
276
+ status: number;
277
+ data: z.ZodObject<{
278
+ manageUrl: z.ZodNullable<z.ZodString>;
279
+ }, z.core.$strip>;
280
+ };
281
+ NOT_IN_PLAN: {
282
+ status: number;
283
+ data: z.ZodOptional<z.ZodObject<{
284
+ manageUrl: z.ZodNullable<z.ZodString>;
285
+ }, z.core.$strip>>;
286
+ };
287
+ READ_ONLY: {
288
+ status: number;
289
+ };
290
+ TOO_MANY_REQUESTS: {
291
+ status: number;
292
+ };
293
+ INVALID_INPUT: {
294
+ status: number;
295
+ data: z.ZodObject<{
296
+ issues: z.ZodArray<z.ZodObject<{
297
+ path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodInt]>>;
298
+ message: z.ZodString;
299
+ }, z.core.$strip>>;
300
+ }, z.core.$strip>;
301
+ };
302
+ NOT_FOUND: {
303
+ status: number;
304
+ };
305
+ TAKEN: {
306
+ status: number;
307
+ data: z.ZodObject<{
308
+ field: z.ZodString;
309
+ id: z.ZodOptional<z.ZodString>;
310
+ values: z.ZodOptional<z.ZodArray<z.ZodString>>;
311
+ }, z.core.$strip>;
312
+ };
313
+ INVALID_CURSOR: {
314
+ status: number;
315
+ };
316
+ INVALID_REFERENCE: {
317
+ status: number;
318
+ data: z.ZodObject<{
319
+ field: z.ZodString;
320
+ }, z.core.$strip>;
321
+ };
322
+ INVALID_FILTER: {
323
+ status: number;
324
+ };
325
+ FILTER_TOO_SLOW: {
326
+ status: number;
327
+ };
328
+ }>, Record<never, never>>;
172
329
  update: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
173
330
  name: z.ZodOptional<z.ZodString>;
174
331
  filter: z.ZodOptional<z.ZodNullable<z.ZodType<ConditionGroup, unknown, z.core.$ZodTypeInternals<ConditionGroup, unknown>>>>;
@@ -208,18 +365,174 @@ export declare const viewsContract: {
208
365
  }, z.core.$strip>>;
209
366
  shared: z.ZodBoolean;
210
367
  createdBy: z.ZodString;
211
- createdAt: z.ZodISODateTime;
212
- updatedAt: z.ZodISODateTime;
368
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
369
+ updatedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
213
370
  editable: z.ZodBoolean;
214
371
  }, {
215
372
  out: {};
216
373
  in: {};
217
- }>, Record<never, never>, Record<never, never>>;
374
+ }>, import("@orpc/contract").MergedErrorMap<Record<never, never>, {
375
+ UNAUTHORIZED: {
376
+ status: number;
377
+ };
378
+ NOT_ALLOWED: {
379
+ status: number;
380
+ data: z.ZodOptional<z.ZodObject<{
381
+ permission: z.ZodString;
382
+ }, z.core.$strip>>;
383
+ };
384
+ PLUGIN_ONLY: {
385
+ status: number;
386
+ };
387
+ MEMBERS_ONLY: {
388
+ status: number;
389
+ };
390
+ ORG_REQUIRED: {
391
+ status: number;
392
+ };
393
+ SCOPE_REQUIRED: {
394
+ status: number;
395
+ };
396
+ SERVICE_TOKEN_REQUIRED: {
397
+ status: number;
398
+ };
399
+ ORGANIZATION_DISABLED: {
400
+ status: number;
401
+ data: z.ZodObject<{
402
+ manageUrl: z.ZodNullable<z.ZodString>;
403
+ }, z.core.$strip>;
404
+ };
405
+ NOT_IN_PLAN: {
406
+ status: number;
407
+ data: z.ZodOptional<z.ZodObject<{
408
+ manageUrl: z.ZodNullable<z.ZodString>;
409
+ }, z.core.$strip>>;
410
+ };
411
+ READ_ONLY: {
412
+ status: number;
413
+ };
414
+ TOO_MANY_REQUESTS: {
415
+ status: number;
416
+ };
417
+ INVALID_INPUT: {
418
+ status: number;
419
+ data: z.ZodObject<{
420
+ issues: z.ZodArray<z.ZodObject<{
421
+ path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodInt]>>;
422
+ message: z.ZodString;
423
+ }, z.core.$strip>>;
424
+ }, z.core.$strip>;
425
+ };
426
+ NOT_FOUND: {
427
+ status: number;
428
+ };
429
+ TAKEN: {
430
+ status: number;
431
+ data: z.ZodObject<{
432
+ field: z.ZodString;
433
+ id: z.ZodOptional<z.ZodString>;
434
+ values: z.ZodOptional<z.ZodArray<z.ZodString>>;
435
+ }, z.core.$strip>;
436
+ };
437
+ INVALID_CURSOR: {
438
+ status: number;
439
+ };
440
+ INVALID_REFERENCE: {
441
+ status: number;
442
+ data: z.ZodObject<{
443
+ field: z.ZodString;
444
+ }, z.core.$strip>;
445
+ };
446
+ INVALID_FILTER: {
447
+ status: number;
448
+ };
449
+ FILTER_TOO_SLOW: {
450
+ status: number;
451
+ };
452
+ }>, Record<never, never>>;
218
453
  remove: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
219
454
  id: z.ZodString;
220
455
  }, z.core.$strip>, z.ZodObject<{
221
456
  ok: z.ZodLiteral<true>;
222
- }, z.core.$strip>, Record<never, never>, Record<never, never>>;
457
+ }, z.core.$strip>, import("@orpc/contract").MergedErrorMap<Record<never, never>, {
458
+ UNAUTHORIZED: {
459
+ status: number;
460
+ };
461
+ NOT_ALLOWED: {
462
+ status: number;
463
+ data: z.ZodOptional<z.ZodObject<{
464
+ permission: z.ZodString;
465
+ }, z.core.$strip>>;
466
+ };
467
+ PLUGIN_ONLY: {
468
+ status: number;
469
+ };
470
+ MEMBERS_ONLY: {
471
+ status: number;
472
+ };
473
+ ORG_REQUIRED: {
474
+ status: number;
475
+ };
476
+ SCOPE_REQUIRED: {
477
+ status: number;
478
+ };
479
+ SERVICE_TOKEN_REQUIRED: {
480
+ status: number;
481
+ };
482
+ ORGANIZATION_DISABLED: {
483
+ status: number;
484
+ data: z.ZodObject<{
485
+ manageUrl: z.ZodNullable<z.ZodString>;
486
+ }, z.core.$strip>;
487
+ };
488
+ NOT_IN_PLAN: {
489
+ status: number;
490
+ data: z.ZodOptional<z.ZodObject<{
491
+ manageUrl: z.ZodNullable<z.ZodString>;
492
+ }, z.core.$strip>>;
493
+ };
494
+ READ_ONLY: {
495
+ status: number;
496
+ };
497
+ TOO_MANY_REQUESTS: {
498
+ status: number;
499
+ };
500
+ INVALID_INPUT: {
501
+ status: number;
502
+ data: z.ZodObject<{
503
+ issues: z.ZodArray<z.ZodObject<{
504
+ path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodInt]>>;
505
+ message: z.ZodString;
506
+ }, z.core.$strip>>;
507
+ }, z.core.$strip>;
508
+ };
509
+ NOT_FOUND: {
510
+ status: number;
511
+ };
512
+ TAKEN: {
513
+ status: number;
514
+ data: z.ZodObject<{
515
+ field: z.ZodString;
516
+ id: z.ZodOptional<z.ZodString>;
517
+ values: z.ZodOptional<z.ZodArray<z.ZodString>>;
518
+ }, z.core.$strip>;
519
+ };
520
+ INVALID_CURSOR: {
521
+ status: number;
522
+ };
523
+ INVALID_REFERENCE: {
524
+ status: number;
525
+ data: z.ZodObject<{
526
+ field: z.ZodString;
527
+ }, z.core.$strip>;
528
+ };
529
+ INVALID_FILTER: {
530
+ status: number;
531
+ };
532
+ FILTER_TOO_SLOW: {
533
+ status: number;
534
+ };
535
+ }>, Record<never, never>>;
223
536
  fields: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
224
537
  recordType: z.ZodEnum<{
225
538
  company: "company";
@@ -250,5 +563,83 @@ export declare const viewsContract: {
250
563
  lead: "lead";
251
564
  }>;
252
565
  }, z.core.$strip>>;
253
- }, z.core.$strip>, Record<never, never>, Record<never, never>>;
566
+ }, z.core.$strip>, import("@orpc/contract").MergedErrorMap<Record<never, never>, {
567
+ UNAUTHORIZED: {
568
+ status: number;
569
+ };
570
+ NOT_ALLOWED: {
571
+ status: number;
572
+ data: z.ZodOptional<z.ZodObject<{
573
+ permission: z.ZodString;
574
+ }, z.core.$strip>>;
575
+ };
576
+ PLUGIN_ONLY: {
577
+ status: number;
578
+ };
579
+ MEMBERS_ONLY: {
580
+ status: number;
581
+ };
582
+ ORG_REQUIRED: {
583
+ status: number;
584
+ };
585
+ SCOPE_REQUIRED: {
586
+ status: number;
587
+ };
588
+ SERVICE_TOKEN_REQUIRED: {
589
+ status: number;
590
+ };
591
+ ORGANIZATION_DISABLED: {
592
+ status: number;
593
+ data: z.ZodObject<{
594
+ manageUrl: z.ZodNullable<z.ZodString>;
595
+ }, z.core.$strip>;
596
+ };
597
+ NOT_IN_PLAN: {
598
+ status: number;
599
+ data: z.ZodOptional<z.ZodObject<{
600
+ manageUrl: z.ZodNullable<z.ZodString>;
601
+ }, z.core.$strip>>;
602
+ };
603
+ READ_ONLY: {
604
+ status: number;
605
+ };
606
+ TOO_MANY_REQUESTS: {
607
+ status: number;
608
+ };
609
+ INVALID_INPUT: {
610
+ status: number;
611
+ data: z.ZodObject<{
612
+ issues: z.ZodArray<z.ZodObject<{
613
+ path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodInt]>>;
614
+ message: z.ZodString;
615
+ }, z.core.$strip>>;
616
+ }, z.core.$strip>;
617
+ };
618
+ NOT_FOUND: {
619
+ status: number;
620
+ };
621
+ TAKEN: {
622
+ status: number;
623
+ data: z.ZodObject<{
624
+ field: z.ZodString;
625
+ id: z.ZodOptional<z.ZodString>;
626
+ values: z.ZodOptional<z.ZodArray<z.ZodString>>;
627
+ }, z.core.$strip>;
628
+ };
629
+ INVALID_CURSOR: {
630
+ status: number;
631
+ };
632
+ INVALID_REFERENCE: {
633
+ status: number;
634
+ data: z.ZodObject<{
635
+ field: z.ZodString;
636
+ }, z.core.$strip>;
637
+ };
638
+ INVALID_FILTER: {
639
+ status: number;
640
+ };
641
+ FILTER_TOO_SLOW: {
642
+ status: number;
643
+ };
644
+ }>, Record<never, never>>;
254
645
  };
package/dist/views.js CHANGED
@@ -1,10 +1,12 @@
1
- import { VIEW_RECORD_TYPES, views } from "./db/src/schema/views.js";
1
+ import { FILTER_FIELD_GROUPS, FILTER_FIELD_TYPES, SORT_DIRECTIONS, VIEW_RECORD_TYPES } from "./db/src/enums.js";
2
+ import { views } from "./db/src/schema/views.js";
2
3
  import "./db/src/schema/index.js";
3
- import { ConditionGroup } from "./automationDefinition.js";
4
- import { Id, isoDate } from "./common.js";
4
+ import { COMMON_ERRORS } from "./errors.js";
5
+ import { ConditionGroup } from "./db/src/automationDefinition.js";
6
+ import { Id, isoDate, listOf } from "./common.js";
5
7
  import { oc } from "@orpc/contract";
6
- import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
7
8
  import { z } from "zod";
9
+ import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
8
10
  // src/views.ts
9
11
  /** The list a view belongs to: customers, leads (people), companies, company leads, products. */
10
12
  const ViewRecordType = z.enum(VIEW_RECORD_TYPES);
@@ -19,28 +21,14 @@ const RecordFilter = ConditionGroup;
19
21
  const FilterField = z.object({
20
22
  path: z.string(),
21
23
  label: z.string(),
22
- type: z.enum([
23
- "text",
24
- "number",
25
- "date",
26
- "boolean",
27
- "select",
28
- "member",
29
- "tags"
30
- ]),
24
+ type: z.enum(FILTER_FIELD_TYPES),
31
25
  options: z.array(z.string()).optional(),
32
26
  /** Where it comes from, for grouping in the picker. */
33
- group: z.enum([
34
- "fields",
35
- "lead",
36
- "custom",
37
- "company",
38
- "activity"
39
- ])
27
+ group: z.enum(FILTER_FIELD_GROUPS)
40
28
  });
41
29
  const ViewSort = z.object({
42
30
  field: z.string().max(100),
43
- direction: z.enum(["asc", "desc"])
31
+ direction: z.enum(SORT_DIRECTIONS)
44
32
  });
45
33
  const View = createSelectSchema(views, {
46
34
  id: Id,
@@ -80,32 +68,34 @@ const ViewFields = createUpdateSchema(views, {
80
68
  sort: true,
81
69
  shared: true
82
70
  });
71
+ /** Views answer with the common errors only. */
72
+ const base = oc.errors(COMMON_ERRORS);
83
73
  /** Saved lists (views) and what lists can be filtered by. */
84
74
  const viewsContract = {
85
- list: oc.route({
75
+ list: base.route({
86
76
  method: "GET",
87
77
  path: "/views",
88
78
  summary: "Views of a list: the member's own and the team's shared ones"
89
- }).input(z.object({ recordType: ViewRecordType })).output(z.object({ data: z.array(View) })),
90
- create: oc.route({
79
+ }).input(z.object({ recordType: ViewRecordType })).output(listOf(View)),
80
+ create: base.route({
91
81
  method: "POST",
92
82
  path: "/views",
93
83
  successStatus: 201,
94
84
  summary: "Save a view (sharing it with the team needs contacts.edit; for products, products.manage)"
95
85
  }).input(ViewFields.required({ name: true }).extend({ recordType: ViewRecordType })).output(View),
96
- update: oc.route({
86
+ update: base.route({
97
87
  method: "PATCH",
98
88
  path: "/views/{id}",
99
89
  summary: "Change a view (its creator; a shared one also members who may share: contacts.edit, products.manage)"
100
90
  }).input(ViewFields.extend({ id: Id })).output(View),
101
- remove: oc.route({
91
+ remove: base.route({
102
92
  method: "DELETE",
103
93
  path: "/views/{id}"
104
94
  }).input(z.object({ id: Id })).output(z.object({ ok: z.literal(true) })),
105
- fields: oc.route({
95
+ fields: base.route({
106
96
  method: "GET",
107
97
  path: "/views/fields",
108
98
  summary: "What a list can be filtered by: fields, custom fields, the company, activity"
109
- }).input(z.object({ recordType: ViewRecordType })).output(z.object({ data: z.array(FilterField) }))
99
+ }).input(z.object({ recordType: ViewRecordType })).output(listOf(FilterField))
110
100
  };
111
101
  export { FilterField, RecordFilter, View, ViewRecordType, ViewSort, viewsContract };