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

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 (94) hide show
  1. package/dist/activities.d.ts +21 -14
  2. package/dist/activities.js +6 -10
  3. package/dist/audit.d.ts +13 -17
  4. package/dist/audit.js +9 -9
  5. package/dist/auth.d.ts +33 -35
  6. package/dist/auth.js +8 -7
  7. package/dist/automationDefinition.d.ts +4 -3
  8. package/dist/automationDefinition.js +9 -31
  9. package/dist/automationRuns.d.ts +6 -5
  10. package/dist/automationRuns.js +8 -22
  11. package/dist/automations.d.ts +35 -36
  12. package/dist/automations.js +15 -23
  13. package/dist/common.d.ts +29 -4
  14. package/dist/common.js +30 -10
  15. package/dist/companies.d.ts +34 -34
  16. package/dist/companies.js +6 -5
  17. package/dist/contract/routes.json.js +1794 -0
  18. package/dist/customerAuth.d.ts +222 -0
  19. package/dist/customerAuth.js +180 -0
  20. package/dist/customers.d.ts +51 -54
  21. package/dist/customers.js +7 -12
  22. package/dist/db/src/enums.d.ts +8 -0
  23. package/dist/db/src/enums.js +336 -0
  24. package/dist/db/src/schema/auditStreams.js +6 -14
  25. package/dist/db/src/schema/authTokens.js +4 -6
  26. package/dist/db/src/schema/automations.js +12 -28
  27. package/dist/db/src/schema/common.d.ts +2 -6
  28. package/dist/db/src/schema/common.js +1 -24
  29. package/dist/db/src/schema/companies.js +6 -5
  30. package/dist/db/src/schema/customerAuth.js +101 -0
  31. package/dist/db/src/schema/customers.js +6 -6
  32. package/dist/db/src/schema/events.js +12 -60
  33. package/dist/db/src/schema/fieldValues.js +2 -2
  34. package/dist/db/src/schema/fields.js +10 -28
  35. package/dist/db/src/schema/index.js +21 -20
  36. package/dist/db/src/schema/leadStages.js +5 -10
  37. package/dist/db/src/schema/leads.js +5 -10
  38. package/dist/db/src/schema/oauth.js +3 -3
  39. package/dist/db/src/schema/payments.js +12 -22
  40. package/dist/db/src/schema/platform.js +11 -26
  41. package/dist/db/src/schema/plugins.js +4 -4
  42. package/dist/db/src/schema/products.js +7 -8
  43. package/dist/db/src/schema/rateLimits.js +7 -0
  44. package/dist/db/src/schema/saas.js +3 -9
  45. package/dist/db/src/schema/tags.js +6 -5
  46. package/dist/db/src/schema/transfer.js +12 -32
  47. package/dist/db/src/schema/trash.js +6 -7
  48. package/dist/db/src/schema/users.js +6 -10
  49. package/dist/db/src/schema/views.js +5 -13
  50. package/dist/db/src/schema/webhooks.js +7 -14
  51. package/dist/db/src/table.js +16 -2
  52. package/dist/events.d.ts +19 -23
  53. package/dist/events.js +16 -18
  54. package/dist/fields.d.ts +22 -50
  55. package/dist/fields.js +6 -28
  56. package/dist/files.d.ts +10 -5
  57. package/dist/files.js +4 -3
  58. package/dist/index.d.ts +557 -321
  59. package/dist/index.js +17 -16
  60. package/dist/leads.d.ts +5 -3
  61. package/dist/leads.js +8 -7
  62. package/dist/notifications.d.ts +4 -48
  63. package/dist/notifications.js +7 -73
  64. package/dist/organizations.d.ts +3 -3
  65. package/dist/payments.d.ts +28 -58
  66. package/dist/payments.js +10 -34
  67. package/dist/platform.d.ts +1 -0
  68. package/dist/platform.js +2 -5
  69. package/dist/plugins.d.ts +10 -4
  70. package/dist/plugins.js +19 -9
  71. package/dist/products.d.ts +31 -36
  72. package/dist/products.js +8 -7
  73. package/dist/roles.d.ts +0 -3
  74. package/dist/roles.js +5 -5
  75. package/dist/routes.d.ts +8 -0
  76. package/dist/routes.js +13 -0
  77. package/dist/saas.d.ts +0 -6
  78. package/dist/saas.js +5 -27
  79. package/dist/tags.d.ts +4 -4
  80. package/dist/tags.js +3 -3
  81. package/dist/transfer.d.ts +62 -24
  82. package/dist/transfer.js +15 -36
  83. package/dist/trash.d.ts +23 -4
  84. package/dist/trash.js +5 -5
  85. package/dist/users.d.ts +27 -41
  86. package/dist/users.js +13 -26
  87. package/dist/values.d.ts +159 -0
  88. package/dist/values.js +144 -0
  89. package/dist/views.d.ts +8 -8
  90. package/dist/views.js +8 -21
  91. package/dist/webhooks.d.ts +26 -20
  92. package/dist/webhooks.js +18 -11
  93. package/package.json +4 -1
  94. package/dist/db/src/schema/jobs.js +0 -44
@@ -90,15 +90,16 @@ export declare const AutomationRun: z.ZodObject<{
90
90
  waiting: "waiting";
91
91
  }>;
92
92
  error: z.ZodNullable<z.ZodString>;
93
- waitingUntil: z.ZodNullable<z.ZodISODateTime>;
94
- startedAt: z.ZodISODateTime;
95
- finishedAt: z.ZodNullable<z.ZodISODateTime>;
93
+ waitingUntil: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
94
+ startedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
95
+ finishedAt: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
96
96
  subject: z.ZodNullable<z.ZodObject<{
97
97
  type: z.ZodEnum<{
98
98
  company: "company";
99
99
  customer: "customer";
100
100
  }>;
101
101
  id: z.ZodString;
102
+ name: z.ZodNullable<z.ZodString>;
102
103
  }, z.core.$strip>>;
103
104
  goalReached: z.ZodBoolean;
104
105
  }, {
@@ -119,8 +120,8 @@ export declare const RunStep: z.ZodObject<{
119
120
  output: z.ZodNullable<z.ZodUnknown>;
120
121
  error: z.ZodNullable<z.ZodString>;
121
122
  attempt: z.ZodInt;
122
- startedAt: z.ZodISODateTime;
123
- finishedAt: z.ZodISODateTime;
123
+ startedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
124
+ finishedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
124
125
  }, {
125
126
  out: {};
126
127
  in: {};
@@ -1,4 +1,5 @@
1
- import { RUN_STATUSES, automationRunSteps, automationRuns } from "./db/src/schema/automations.js";
1
+ import { ACTION_FIELD_TYPES, AUTOMATION_SUBJECTS, CONTENT_TYPES, RUN_STATUSES } from "./db/src/enums.js";
2
+ import { automationRunSteps, automationRuns } from "./db/src/schema/automations.js";
2
3
  import "./db/src/schema/index.js";
3
4
  import { Id, isoDate } from "./common.js";
4
5
  import { createSelectSchema } from "drizzle-zod";
@@ -12,20 +13,7 @@ import { z } from "zod";
12
13
  const ActionField = z.object({
13
14
  key: z.string(),
14
15
  label: z.string(),
15
- type: z.enum([
16
- "text",
17
- "longtext",
18
- "number",
19
- "boolean",
20
- "date",
21
- "select",
22
- "members",
23
- "tags",
24
- "json",
25
- "custom_field",
26
- "lead_stage",
27
- "recipients"
28
- ]),
16
+ type: z.enum(ACTION_FIELD_TYPES),
29
17
  required: z.boolean().default(false),
30
18
  options: z.array(z.object({
31
19
  value: z.string(),
@@ -42,11 +30,7 @@ const ActionInfo = z.object({
42
30
  description: z.string().nullable(),
43
31
  source: z.string(),
44
32
  /** Needs a customer or company as the run's subject. */
45
- subject: z.enum([
46
- "customer",
47
- "company",
48
- "any"
49
- ]).nullable(),
33
+ subject: z.enum(AUTOMATION_SUBJECTS).nullable(),
50
34
  fields: z.array(ActionField)
51
35
  });
52
36
  const RunStatus = z.enum(RUN_STATUSES);
@@ -71,8 +55,10 @@ const AutomationRun = createSelectSchema(automationRuns, {
71
55
  finishedAt: true
72
56
  }).extend({
73
57
  subject: z.object({
74
- type: z.enum(["customer", "company"]),
75
- id: Id
58
+ type: z.enum(CONTENT_TYPES),
59
+ id: Id,
60
+ /** The customer's or company's name now; null once it is deleted. */
61
+ name: z.string().nullable()
76
62
  }).nullable(),
77
63
  /** Left early because the automation's goal was met. */
78
64
  goalReached: z.boolean()
@@ -1,11 +1,6 @@
1
1
  import { ConditionGroup } from "./db/src/schema/common.js";
2
2
  import { AutomationStep } from "./automationDefinition.js";
3
3
  import { z } from "zod";
4
- export declare const AutomationStatus: z.ZodEnum<{
5
- active: "active";
6
- draft: "draft";
7
- paused: "paused";
8
- }>;
9
4
  export declare const Automation: z.ZodObject<{
10
5
  id: z.ZodString;
11
6
  name: z.ZodString;
@@ -72,8 +67,8 @@ export declare const Automation: z.ZodObject<{
72
67
  }, z.core.$strip>;
73
68
  activeVersion: z.ZodNullable<z.ZodInt>;
74
69
  activatedBy: z.ZodNullable<z.ZodString>;
75
- createdAt: z.ZodISODateTime;
76
- updatedAt: z.ZodISODateTime;
70
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
71
+ updatedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
77
72
  stats: z.ZodObject<{
78
73
  running: z.ZodInt;
79
74
  succeeded: z.ZodInt;
@@ -238,8 +233,8 @@ export declare const automationsContract: {
238
233
  }, z.core.$strip>;
239
234
  activeVersion: z.ZodNullable<z.ZodInt>;
240
235
  activatedBy: z.ZodNullable<z.ZodString>;
241
- createdAt: z.ZodISODateTime;
242
- updatedAt: z.ZodISODateTime;
236
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
237
+ updatedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
243
238
  stats: z.ZodObject<{
244
239
  running: z.ZodInt;
245
240
  succeeded: z.ZodInt;
@@ -318,8 +313,8 @@ export declare const automationsContract: {
318
313
  }, z.core.$strip>;
319
314
  activeVersion: z.ZodNullable<z.ZodInt>;
320
315
  activatedBy: z.ZodNullable<z.ZodString>;
321
- createdAt: z.ZodISODateTime;
322
- updatedAt: z.ZodISODateTime;
316
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
317
+ updatedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
323
318
  stats: z.ZodObject<{
324
319
  running: z.ZodInt;
325
320
  succeeded: z.ZodInt;
@@ -456,8 +451,8 @@ export declare const automationsContract: {
456
451
  }, z.core.$strip>;
457
452
  activeVersion: z.ZodNullable<z.ZodInt>;
458
453
  activatedBy: z.ZodNullable<z.ZodString>;
459
- createdAt: z.ZodISODateTime;
460
- updatedAt: z.ZodISODateTime;
454
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
455
+ updatedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
461
456
  stats: z.ZodObject<{
462
457
  running: z.ZodInt;
463
458
  succeeded: z.ZodInt;
@@ -595,8 +590,8 @@ export declare const automationsContract: {
595
590
  }, z.core.$strip>;
596
591
  activeVersion: z.ZodNullable<z.ZodInt>;
597
592
  activatedBy: z.ZodNullable<z.ZodString>;
598
- createdAt: z.ZodISODateTime;
599
- updatedAt: z.ZodISODateTime;
593
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
594
+ updatedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
600
595
  stats: z.ZodObject<{
601
596
  running: z.ZodInt;
602
597
  succeeded: z.ZodInt;
@@ -674,8 +669,8 @@ export declare const automationsContract: {
674
669
  }, z.core.$strip>;
675
670
  activeVersion: z.ZodNullable<z.ZodInt>;
676
671
  activatedBy: z.ZodNullable<z.ZodString>;
677
- createdAt: z.ZodISODateTime;
678
- updatedAt: z.ZodISODateTime;
672
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
673
+ updatedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
679
674
  stats: z.ZodObject<{
680
675
  running: z.ZodInt;
681
676
  succeeded: z.ZodInt;
@@ -753,8 +748,8 @@ export declare const automationsContract: {
753
748
  }, z.core.$strip>;
754
749
  activeVersion: z.ZodNullable<z.ZodInt>;
755
750
  activatedBy: z.ZodNullable<z.ZodString>;
756
- createdAt: z.ZodISODateTime;
757
- updatedAt: z.ZodISODateTime;
751
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
752
+ updatedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
758
753
  stats: z.ZodObject<{
759
754
  running: z.ZodInt;
760
755
  succeeded: z.ZodInt;
@@ -819,7 +814,7 @@ export declare const automationsContract: {
819
814
  data: z.ZodArray<z.ZodObject<{
820
815
  version: z.ZodInt;
821
816
  publishedBy: z.ZodNullable<z.ZodString>;
822
- createdAt: z.ZodISODateTime;
817
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
823
818
  definition: z.ZodObject<{
824
819
  trigger: z.ZodDiscriminatedUnion<[z.ZodObject<{
825
820
  kind: z.ZodLiteral<"event">;
@@ -946,8 +941,8 @@ export declare const automationsContract: {
946
941
  }, z.core.$strip>;
947
942
  activeVersion: z.ZodNullable<z.ZodInt>;
948
943
  activatedBy: z.ZodNullable<z.ZodString>;
949
- createdAt: z.ZodISODateTime;
950
- updatedAt: z.ZodISODateTime;
944
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
945
+ updatedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
951
946
  stats: z.ZodObject<{
952
947
  running: z.ZodInt;
953
948
  succeeded: z.ZodInt;
@@ -1080,15 +1075,16 @@ export declare const automationsContract: {
1080
1075
  waiting: "waiting";
1081
1076
  }>;
1082
1077
  error: z.ZodNullable<z.ZodString>;
1083
- waitingUntil: z.ZodNullable<z.ZodISODateTime>;
1084
- startedAt: z.ZodISODateTime;
1085
- finishedAt: z.ZodNullable<z.ZodISODateTime>;
1078
+ waitingUntil: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
1079
+ startedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
1080
+ finishedAt: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
1086
1081
  subject: z.ZodNullable<z.ZodObject<{
1087
1082
  type: z.ZodEnum<{
1088
1083
  company: "company";
1089
1084
  customer: "customer";
1090
1085
  }>;
1091
1086
  id: z.ZodString;
1087
+ name: z.ZodNullable<z.ZodString>;
1092
1088
  }, z.core.$strip>>;
1093
1089
  goalReached: z.ZodBoolean;
1094
1090
  }, {
@@ -1121,15 +1117,16 @@ export declare const automationsContract: {
1121
1117
  waiting: "waiting";
1122
1118
  }>;
1123
1119
  error: z.ZodNullable<z.ZodString>;
1124
- waitingUntil: z.ZodNullable<z.ZodISODateTime>;
1125
- startedAt: z.ZodISODateTime;
1126
- finishedAt: z.ZodNullable<z.ZodISODateTime>;
1120
+ waitingUntil: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
1121
+ startedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
1122
+ finishedAt: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
1127
1123
  subject: z.ZodNullable<z.ZodObject<{
1128
1124
  type: z.ZodEnum<{
1129
1125
  company: "company";
1130
1126
  customer: "customer";
1131
1127
  }>;
1132
1128
  id: z.ZodString;
1129
+ name: z.ZodNullable<z.ZodString>;
1133
1130
  }, z.core.$strip>>;
1134
1131
  goalReached: z.ZodBoolean;
1135
1132
  }, {
@@ -1149,8 +1146,8 @@ export declare const automationsContract: {
1149
1146
  output: z.ZodNullable<z.ZodUnknown>;
1150
1147
  error: z.ZodNullable<z.ZodString>;
1151
1148
  attempt: z.ZodInt;
1152
- startedAt: z.ZodISODateTime;
1153
- finishedAt: z.ZodISODateTime;
1149
+ startedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
1150
+ finishedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
1154
1151
  }, {
1155
1152
  out: {};
1156
1153
  in: {};
@@ -1172,15 +1169,16 @@ export declare const automationsContract: {
1172
1169
  waiting: "waiting";
1173
1170
  }>;
1174
1171
  error: z.ZodNullable<z.ZodString>;
1175
- waitingUntil: z.ZodNullable<z.ZodISODateTime>;
1176
- startedAt: z.ZodISODateTime;
1177
- finishedAt: z.ZodNullable<z.ZodISODateTime>;
1172
+ waitingUntil: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
1173
+ startedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
1174
+ finishedAt: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
1178
1175
  subject: z.ZodNullable<z.ZodObject<{
1179
1176
  type: z.ZodEnum<{
1180
1177
  company: "company";
1181
1178
  customer: "customer";
1182
1179
  }>;
1183
1180
  id: z.ZodString;
1181
+ name: z.ZodNullable<z.ZodString>;
1184
1182
  }, z.core.$strip>>;
1185
1183
  goalReached: z.ZodBoolean;
1186
1184
  }, {
@@ -1203,15 +1201,16 @@ export declare const automationsContract: {
1203
1201
  waiting: "waiting";
1204
1202
  }>;
1205
1203
  error: z.ZodNullable<z.ZodString>;
1206
- waitingUntil: z.ZodNullable<z.ZodISODateTime>;
1207
- startedAt: z.ZodISODateTime;
1208
- finishedAt: z.ZodNullable<z.ZodISODateTime>;
1204
+ waitingUntil: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
1205
+ startedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
1206
+ finishedAt: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
1209
1207
  subject: z.ZodNullable<z.ZodObject<{
1210
1208
  type: z.ZodEnum<{
1211
1209
  company: "company";
1212
1210
  customer: "customer";
1213
1211
  }>;
1214
1212
  id: z.ZodString;
1213
+ name: z.ZodNullable<z.ZodString>;
1215
1214
  }, z.core.$strip>>;
1216
1215
  goalReached: z.ZodBoolean;
1217
1216
  }, {
@@ -1,13 +1,14 @@
1
- import { AUTOMATION_STATUSES, automations } from "./db/src/schema/automations.js";
1
+ import { AUTOMATION_FIELD_TYPES, CONTENT_TYPES } from "./db/src/enums.js";
2
+ import { automations } from "./db/src/schema/automations.js";
2
3
  import "./db/src/schema/index.js";
4
+ import { AutomationStatus } from "./values.js";
3
5
  import { AutomationDefinition } from "./automationDefinition.js";
4
6
  import { ActionInfo, AutomationRun, RunStatus, RunStep } from "./automationRuns.js";
5
- import { CursorQuery, Id, cursorPageOf, isoDate } from "./common.js";
7
+ import { CursorQuery, Id, cursorPageOf, isoDate, listOf } from "./common.js";
6
8
  import { oc } from "@orpc/contract";
7
9
  import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
8
10
  import { z } from "zod";
9
11
  // src/automations.ts
10
- const AutomationStatus = z.enum(AUTOMATION_STATUSES);
11
12
  const Automation = createSelectSchema(automations, {
12
13
  id: Id,
13
14
  definition: AutomationDefinition,
@@ -34,16 +35,7 @@ const Automation = createSelectSchema(automations, {
34
35
  const AutomationFieldPath = z.object({
35
36
  path: z.string(),
36
37
  label: z.string(),
37
- type: z.enum([
38
- "text",
39
- "number",
40
- "date",
41
- "boolean",
42
- "list",
43
- "member",
44
- "tags",
45
- "select"
46
- ]),
38
+ type: z.enum(AUTOMATION_FIELD_TYPES),
47
39
  options: z.array(z.string()).optional()
48
40
  });
49
41
  /** One step of a dry run: what it would do, and what would stop it. */
@@ -80,14 +72,14 @@ const automationsContract = {
80
72
  /** A line on what it is, for pickers. */
81
73
  description: z.string().nullable().optional(),
82
74
  source: z.string(),
83
- subject: z.enum(["customer", "company"]).nullable()
75
+ subject: z.enum(CONTENT_TYPES).nullable()
84
76
  })),
85
77
  actions: z.array(ActionInfo)
86
78
  })),
87
79
  list: oc.route({
88
80
  method: "GET",
89
81
  path: "/automations"
90
- }).input(z.object({ status: AutomationStatus.optional() })).output(z.object({ data: z.array(Automation) })),
82
+ }).input(z.object({ status: AutomationStatus.optional() })).output(listOf(Automation)),
91
83
  get: oc.route({
92
84
  method: "GET",
93
85
  path: "/automations/{id}"
@@ -134,7 +126,7 @@ const automationsContract = {
134
126
  }).input(z.object({
135
127
  id: Id,
136
128
  subject: z.object({
137
- type: z.enum(["customer", "company"]),
129
+ type: z.enum(CONTENT_TYPES),
138
130
  id: Id
139
131
  }).optional(),
140
132
  /** Event fields for the trigger (type, payload); defaults to the trigger's event. */
@@ -170,13 +162,13 @@ const automationsContract = {
170
162
  versions: oc.route({
171
163
  method: "GET",
172
164
  path: "/automations/{id}/versions",
173
- summary: "Published versions, newest first"
165
+ summary: "The 100 latest published versions, newest first"
174
166
  }).input(z.object({ id: Id })).output(z.object({ data: z.array(z.object({
175
167
  version: z.int(),
176
168
  publishedBy: z.string().nullable(),
177
- createdAt: z.iso.datetime(),
169
+ createdAt: isoDate(),
178
170
  definition: AutomationDefinition
179
- })) })),
171
+ })).max(100) })),
180
172
  restoreVersion: oc.route({
181
173
  method: "POST",
182
174
  path: "/automations/{id}/versions/{version}/restore",
@@ -189,17 +181,17 @@ const automationsContract = {
189
181
  method: "GET",
190
182
  path: "/automations/templates",
191
183
  summary: "Ready-made automations to start from"
192
- }).output(z.object({ data: z.array(z.object({
184
+ }).output(listOf(z.object({
193
185
  id: z.string(),
194
186
  name: z.string(),
195
187
  description: z.string(),
196
188
  definition: AutomationDefinition
197
- })) })),
189
+ }))),
198
190
  fields: oc.route({
199
191
  method: "GET",
200
192
  path: "/automations/fields",
201
193
  summary: "Paths conditions and placeholders can use, with their types (custom fields included)"
202
- }).input(z.object({ subject: z.enum(["customer", "company"]).optional() })).output(z.object({ data: z.array(AutomationFieldPath) })),
194
+ }).input(z.object({ subject: z.enum(CONTENT_TYPES).optional() })).output(listOf(AutomationFieldPath)),
203
195
  remove: oc.route({
204
196
  method: "DELETE",
205
197
  path: "/automations/{id}"
@@ -229,4 +221,4 @@ const automationsContract = {
229
221
  summary: "Stop a running or waiting run"
230
222
  }).input(z.object({ runId: Id })).output(AutomationRun)
231
223
  };
232
- export { Automation, AutomationFieldPath, AutomationStatus, DryRunStep, automationsContract };
224
+ export { Automation, AutomationFieldPath, DryRunStep, automationsContract };
package/dist/common.d.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  import { z } from "zod";
2
2
  export declare const Id: z.ZodString;
3
3
  /**
4
- * A timestamp column as the API sends it, an ISO string. Give it to
5
- * `createSelectSchema` as a refinement (`{ createdAt: isoDate }`), so a
6
- * nullable column stays nullable.
4
+ * A timestamp column in an output schema: the handler returns the row's `Date`,
5
+ * the client gets an ISO string. Give it to `createSelectSchema` as a
6
+ * refinement (`{ createdAt: isoDate }`), so a nullable column stays nullable.
7
+ * Inputs and JSON bodies read from the wire take `z.iso.datetime()`.
7
8
  */
8
- export declare const isoDate: () => z.ZodISODateTime;
9
+ export declare const isoDate: () => z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
9
10
  /**
10
11
  * Keyset ("cursor") paging, newest first. A cursor is the id of a record in
11
12
  * the list: `forward` returns older records after it, `backward` newer ones
@@ -32,6 +33,11 @@ export declare const PageInfo: z.ZodObject<{
32
33
  endCursor: z.ZodNullable<z.ZodString>;
33
34
  }, z.core.$strip>;
34
35
  export type PageInfo = z.infer<typeof PageInfo>;
36
+ /** `true`/`false` from a query string. */
37
+ export declare const QueryFlag: z.ZodPipe<z.ZodEnum<{
38
+ false: "false";
39
+ true: "true";
40
+ }>, z.ZodTransform<boolean, "false" | "true">>;
35
41
  /** `true`/`false` from a query string, or a boolean from a typed client. */
36
42
  export declare const QueryBoolean: z.ZodUnion<readonly [z.ZodBoolean, z.ZodPipe<z.ZodEnum<{
37
43
  false: "false";
@@ -52,6 +58,15 @@ export declare const ErrorBody: z.ZodObject<{
52
58
  data: z.ZodOptional<z.ZodUnknown>;
53
59
  }, z.core.$strip>;
54
60
  export type ErrorBody = z.infer<typeof ErrorBody>;
61
+ /** `INVALID_INPUT`'s `data`: what failed the contract, field by field. */
62
+ export declare const InvalidInput: z.ZodObject<{
63
+ issues: z.ZodArray<z.ZodObject<{
64
+ path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodInt]>>;
65
+ message: z.ZodString;
66
+ }, z.core.$strip>>;
67
+ }, z.core.$strip>;
68
+ /** Longest description a person, customer or company holds, as stored (editor JSON). */
69
+ export declare const DESCRIPTION_MAX = 5000;
55
70
  export declare const cursorPageOf: <T extends z.ZodType>(item: T) => z.ZodObject<{
56
71
  data: z.ZodArray<T>;
57
72
  pageInfo: z.ZodObject<{
@@ -63,6 +78,16 @@ export declare const cursorPageOf: <T extends z.ZodType>(item: T) => z.ZodObject
63
78
  totalCount: z.ZodInt;
64
79
  totalCapped: z.ZodOptional<z.ZodBoolean>;
65
80
  }, z.core.$strip>;
81
+ /**
82
+ * Most items a list read whole may hold. Whole lists are small config
83
+ * (roles, stages, fields, webhooks); past this the server fails instead of
84
+ * cutting the list. Lists that grow with use are `cursorPageOf`.
85
+ */
86
+ export declare const LIST_MAX = 1000;
87
+ /** A small config list, read whole: at most `LIST_MAX` items. */
88
+ export declare const listOf: <T extends z.ZodType>(item: T) => z.ZodObject<{
89
+ data: z.ZodArray<T>;
90
+ }, z.core.$strip>;
66
91
  /** Records that tags and custom fields attach to. */
67
92
  export declare const ContentType: z.ZodEnum<{
68
93
  company: "company";
package/dist/common.js CHANGED
@@ -1,14 +1,17 @@
1
- import { CONTENT_TYPES, FIELD_CONTENT_TYPES } from "./db/src/schema/common.js";
2
- import "./db/src/schema/index.js";
1
+ import { BOOLEAN_STRINGS, CONTENT_TYPES, CURSOR_MODES, FIELD_CONTENT_TYPES, PAGE_DIRECTIONS } from "./db/src/enums.js";
3
2
  import { z } from "zod";
4
3
  // src/common.ts
5
4
  const Id = z.string().min(1).max(64);
6
5
  /**
7
- * A timestamp column as the API sends it, an ISO string. Give it to
8
- * `createSelectSchema` as a refinement (`{ createdAt: isoDate }`), so a
9
- * nullable column stays nullable.
6
+ * A timestamp column in an output schema: the handler returns the row's `Date`,
7
+ * the client gets an ISO string. Give it to `createSelectSchema` as a
8
+ * refinement (`{ createdAt: isoDate }`), so a nullable column stays nullable.
9
+ * Inputs and JSON bodies read from the wire take `z.iso.datetime()`.
10
10
  */
11
- const isoDate = () => z.iso.datetime();
11
+ const isoDate = () => z.codec(z.date(), z.iso.datetime(), {
12
+ decode: (date) => date.toISOString(),
13
+ encode: (iso) => new Date(iso)
14
+ });
12
15
  /**
13
16
  * Keyset ("cursor") paging, newest first. A cursor is the id of a record in
14
17
  * the list: `forward` returns older records after it, `backward` newer ones
@@ -18,8 +21,8 @@ const isoDate = () => z.iso.datetime();
18
21
  const CursorQuery = z.object({
19
22
  limit: z.coerce.number().int().min(1).max(100).default(30),
20
23
  cursor: Id.optional(),
21
- direction: z.enum(["forward", "backward"]).default("forward"),
22
- cursorMode: z.enum(["inclusive", "exclusive"]).default("exclusive")
24
+ direction: z.enum(PAGE_DIRECTIONS).default("forward"),
25
+ cursorMode: z.enum(CURSOR_MODES).default("exclusive")
23
26
  });
24
27
  const PageInfo = z.object({
25
28
  hasNextPage: z.boolean(),
@@ -27,8 +30,10 @@ const PageInfo = z.object({
27
30
  startCursor: z.string().nullable(),
28
31
  endCursor: z.string().nullable()
29
32
  });
33
+ /** `true`/`false` from a query string. */
34
+ const QueryFlag = z.enum(BOOLEAN_STRINGS).transform((value) => value === "true");
30
35
  /** `true`/`false` from a query string, or a boolean from a typed client. */
31
- const QueryBoolean = z.union([z.boolean(), z.enum(["true", "false"]).transform((value) => value === "true")]);
36
+ const QueryBoolean = z.union([z.boolean(), QueryFlag]);
32
37
  /** Comma-separated ids in a query string (`?ids=a,b`), at most 100. */
33
38
  const IdList = z.string().max(6500).transform((value) => value.split(",").map((id) => id.trim()).filter(Boolean).slice(0, 100));
34
39
  /**
@@ -43,6 +48,13 @@ const ErrorBody = z.object({
43
48
  message: z.string(),
44
49
  data: z.unknown().optional()
45
50
  });
51
+ /** `INVALID_INPUT`'s `data`: what failed the contract, field by field. */
52
+ const InvalidInput = z.object({ issues: z.array(z.object({
53
+ path: z.array(z.union([z.string(), z.int()])),
54
+ message: z.string()
55
+ })) });
56
+ /** Longest description a person, customer or company holds, as stored (editor JSON). */
57
+ const DESCRIPTION_MAX = 5e3;
46
58
  const cursorPageOf = (item) => z.object({
47
59
  data: z.array(item),
48
60
  pageInfo: PageInfo,
@@ -51,6 +63,14 @@ const cursorPageOf = (item) => z.object({
51
63
  /** Big lists stop counting: `totalCount` is the cap and there are more ("10,000+"). */
52
64
  totalCapped: z.boolean().optional()
53
65
  });
66
+ /**
67
+ * Most items a list read whole may hold. Whole lists are small config
68
+ * (roles, stages, fields, webhooks); past this the server fails instead of
69
+ * cutting the list. Lists that grow with use are `cursorPageOf`.
70
+ */
71
+ const LIST_MAX = 1e3;
72
+ /** A small config list, read whole: at most `LIST_MAX` items. */
73
+ const listOf = (item) => z.object({ data: z.array(item).max(LIST_MAX) });
54
74
  /** Records that tags and custom fields attach to. */
55
75
  const ContentType = z.enum(CONTENT_TYPES);
56
76
  /** Records custom fields attach to: contacts, and the shared product catalog. */
@@ -73,4 +93,4 @@ const PhoneNumber = z.string().trim().min(3).max(32).regex(/^\+?[0-9 ()-]+$/, "d
73
93
  * (`/core/v1/files/<id>/download`, as uploads return).
74
94
  */
75
95
  const ImageAddress = z.string().trim().max(1e3).refine((value) => /^https?:\/\/\S+$/.test(value) || /^\/core\/v1\/files\/[A-Za-z0-9]+\/download$/.test(value), "a URL or an uploaded file");
76
- export { ContentType, CursorQuery, CustomFields, CustomFieldsPatch, CustomValue, EmailAddress, ErrorBody, FieldContentType, Id, IdList, ImageAddress, PageInfo, PhoneNumber, QueryBoolean, cursorPageOf, isoDate };
96
+ export { ContentType, CursorQuery, CustomFields, CustomFieldsPatch, CustomValue, DESCRIPTION_MAX, EmailAddress, ErrorBody, FieldContentType, Id, IdList, ImageAddress, InvalidInput, LIST_MAX, PageInfo, PhoneNumber, QueryBoolean, QueryFlag, cursorPageOf, isoDate, listOf };