@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
@@ -1,13 +1,15 @@
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";
3
- import { AutomationDefinition } from "./automationDefinition.js";
4
+ import { COMMON_ERRORS, ERRORS } from "./errors.js";
5
+ import { AutomationStatus } from "./values.js";
6
+ import { AutomationDefinition } from "./db/src/automationDefinition.js";
4
7
  import { ActionInfo, AutomationRun, RunStatus, RunStep } from "./automationRuns.js";
5
- import { CursorQuery, Id, cursorPageOf, isoDate } from "./common.js";
8
+ import { CursorQuery, Id, cursorPageOf, isoDate, listOf } from "./common.js";
6
9
  import { oc } from "@orpc/contract";
7
- import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
8
10
  import { z } from "zod";
11
+ import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
9
12
  // src/automations.ts
10
- const AutomationStatus = z.enum(AUTOMATION_STATUSES);
11
13
  const Automation = createSelectSchema(automations, {
12
14
  id: Id,
13
15
  definition: AutomationDefinition,
@@ -34,16 +36,7 @@ const Automation = createSelectSchema(automations, {
34
36
  const AutomationFieldPath = z.object({
35
37
  path: z.string(),
36
38
  label: z.string(),
37
- type: z.enum([
38
- "text",
39
- "number",
40
- "date",
41
- "boolean",
42
- "list",
43
- "member",
44
- "tags",
45
- "select"
46
- ]),
39
+ type: z.enum(AUTOMATION_FIELD_TYPES),
47
40
  options: z.array(z.string()).optional()
48
41
  });
49
42
  /** One step of a dry run: what it would do, and what would stop it. */
@@ -68,8 +61,27 @@ const Fields = createUpdateSchema(automations, {
68
61
  * actions from core and plugins, delays and branches — for its customer or
69
62
  * company. Every run and step is logged.
70
63
  */
64
+ const { CROSS_SITE, INVALID_AUTOMATION, INVALID_FILE, INVALID_LEAD_STAGE, INVALID_RECIPIENT, INVALID_STEP_INPUT, INVALID_URL, LIMIT_EXCEEDED, NOT_ACTIVE, NOT_AUTHOR, NOT_FAILED, NOT_RUNNING, NO_MEMBERS, NO_SUBJECT } = ERRORS;
65
+ /** What these procedures answer with besides the common errors. */
66
+ const base = oc.errors({
67
+ ...COMMON_ERRORS,
68
+ CROSS_SITE,
69
+ INVALID_AUTOMATION,
70
+ INVALID_FILE,
71
+ INVALID_LEAD_STAGE,
72
+ INVALID_RECIPIENT,
73
+ INVALID_STEP_INPUT,
74
+ INVALID_URL,
75
+ LIMIT_EXCEEDED,
76
+ NOT_ACTIVE,
77
+ NOT_AUTHOR,
78
+ NOT_FAILED,
79
+ NOT_RUNNING,
80
+ NO_MEMBERS,
81
+ NO_SUBJECT
82
+ });
71
83
  const automationsContract = {
72
- catalog: oc.route({
84
+ catalog: base.route({
73
85
  method: "GET",
74
86
  path: "/automations/catalog",
75
87
  summary: "Triggers (event types) and actions: core's and installed plugins'"
@@ -80,19 +92,19 @@ const automationsContract = {
80
92
  /** A line on what it is, for pickers. */
81
93
  description: z.string().nullable().optional(),
82
94
  source: z.string(),
83
- subject: z.enum(["customer", "company"]).nullable()
95
+ subject: z.enum(CONTENT_TYPES).nullable()
84
96
  })),
85
97
  actions: z.array(ActionInfo)
86
98
  })),
87
- list: oc.route({
99
+ list: base.route({
88
100
  method: "GET",
89
101
  path: "/automations"
90
- }).input(z.object({ status: AutomationStatus.optional() })).output(z.object({ data: z.array(Automation) })),
91
- get: oc.route({
102
+ }).input(z.object({ status: AutomationStatus.optional() })).output(listOf(Automation)),
103
+ get: base.route({
92
104
  method: "GET",
93
105
  path: "/automations/{id}"
94
106
  }).input(z.object({ id: Id })).output(Automation),
95
- create: oc.route({
107
+ create: base.route({
96
108
  method: "POST",
97
109
  path: "/automations",
98
110
  successStatus: 201
@@ -100,21 +112,21 @@ const automationsContract = {
100
112
  name: true,
101
113
  definition: true
102
114
  })).output(Automation),
103
- update: oc.route({
115
+ update: base.route({
104
116
  method: "PATCH",
105
117
  path: "/automations/{id}",
106
118
  summary: "Change an automation; an active one publishes a new version (runs in progress keep theirs)"
107
119
  }).input(Fields.extend({ id: Id })).output(Automation),
108
- activate: oc.route({
120
+ activate: base.route({
109
121
  method: "POST",
110
122
  path: "/automations/{id}/activate",
111
123
  summary: "Check and turn on (as the member, whose permissions its actions use)"
112
124
  }).input(z.object({ id: Id })).output(Automation),
113
- pause: oc.route({
125
+ pause: base.route({
114
126
  method: "POST",
115
127
  path: "/automations/{id}/pause"
116
128
  }).input(z.object({ id: Id })).output(Automation),
117
- start: oc.route({
129
+ start: base.route({
118
130
  method: "POST",
119
131
  path: "/automations/{id}/start",
120
132
  summary: "Run a manual (or any) automation now: on the given records, or on its audience"
@@ -127,14 +139,14 @@ const automationsContract = {
127
139
  /** The audience is larger than one page: the rest starts in the background. */
128
140
  continuing: z.boolean()
129
141
  })),
130
- test: oc.route({
142
+ test: base.route({
131
143
  method: "POST",
132
144
  path: "/automations/{id}/test",
133
145
  summary: "Dry run of the working copy: what each step would do for a record (nothing is changed)"
134
146
  }).input(z.object({
135
147
  id: Id,
136
148
  subject: z.object({
137
- type: z.enum(["customer", "company"]),
149
+ type: z.enum(CONTENT_TYPES),
138
150
  id: Id
139
151
  }).optional(),
140
152
  /** Event fields for the trigger (type, payload); defaults to the trigger's event. */
@@ -146,7 +158,7 @@ const automationsContract = {
146
158
  goalMetAtStart: z.boolean(),
147
159
  trace: z.array(DryRunStep)
148
160
  })),
149
- stats: oc.route({
161
+ stats: base.route({
150
162
  method: "GET",
151
163
  path: "/automations/{id}/stats",
152
164
  summary: "How runs went, overall and step by step (last 30 days)"
@@ -167,17 +179,17 @@ const automationsContract = {
167
179
  })),
168
180
  skippedByLimit: z.int()
169
181
  })),
170
- versions: oc.route({
182
+ versions: base.route({
171
183
  method: "GET",
172
184
  path: "/automations/{id}/versions",
173
- summary: "Published versions, newest first"
185
+ summary: "The 100 latest published versions, newest first"
174
186
  }).input(z.object({ id: Id })).output(z.object({ data: z.array(z.object({
175
187
  version: z.int(),
176
188
  publishedBy: z.string().nullable(),
177
- createdAt: z.iso.datetime(),
189
+ createdAt: isoDate(),
178
190
  definition: AutomationDefinition
179
- })) })),
180
- restoreVersion: oc.route({
191
+ })).max(100) })),
192
+ restoreVersion: base.route({
181
193
  method: "POST",
182
194
  path: "/automations/{id}/versions/{version}/restore",
183
195
  summary: "Make an older version the working copy (and publish it if the automation is on)"
@@ -185,48 +197,48 @@ const automationsContract = {
185
197
  id: Id,
186
198
  version: z.coerce.number().int().min(1)
187
199
  })).output(Automation),
188
- templates: oc.route({
200
+ templates: base.route({
189
201
  method: "GET",
190
202
  path: "/automations/templates",
191
203
  summary: "Ready-made automations to start from"
192
- }).output(z.object({ data: z.array(z.object({
204
+ }).output(listOf(z.object({
193
205
  id: z.string(),
194
206
  name: z.string(),
195
207
  description: z.string(),
196
208
  definition: AutomationDefinition
197
- })) })),
198
- fields: oc.route({
209
+ }))),
210
+ fields: base.route({
199
211
  method: "GET",
200
212
  path: "/automations/fields",
201
213
  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) })),
203
- remove: oc.route({
214
+ }).input(z.object({ subject: z.enum(CONTENT_TYPES).optional() })).output(listOf(AutomationFieldPath)),
215
+ remove: base.route({
204
216
  method: "DELETE",
205
217
  path: "/automations/{id}"
206
218
  }).input(z.object({ id: Id })).output(z.object({ ok: z.literal(true) })),
207
- runs: oc.route({
219
+ runs: base.route({
208
220
  method: "GET",
209
221
  path: "/automations/{id}/runs"
210
222
  }).input(CursorQuery.extend({
211
223
  id: Id,
212
224
  status: RunStatus.optional()
213
225
  })).output(cursorPageOf(AutomationRun)),
214
- run: oc.route({
226
+ run: base.route({
215
227
  method: "GET",
216
228
  path: "/automations/runs/{runId}"
217
229
  }).input(z.object({ runId: Id })).output(z.object({
218
230
  run: AutomationRun,
219
231
  steps: z.array(RunStep)
220
232
  })),
221
- retryRun: oc.route({
233
+ retryRun: base.route({
222
234
  method: "POST",
223
235
  path: "/automations/runs/{runId}/retry",
224
236
  summary: "Continue a failed run from the step that failed"
225
237
  }).input(z.object({ runId: Id })).output(AutomationRun),
226
- cancelRun: oc.route({
238
+ cancelRun: base.route({
227
239
  method: "POST",
228
240
  path: "/automations/runs/{runId}/cancel",
229
241
  summary: "Stop a running or waiting run"
230
242
  }).input(z.object({ runId: Id })).output(AutomationRun)
231
243
  };
232
- export { Automation, AutomationFieldPath, AutomationStatus, DryRunStep, automationsContract };
244
+ export { Automation, AutomationFieldPath, DryRunStep, automationsContract };