@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.
- package/dist/activities.d.ts +1394 -139
- package/dist/activities.js +96 -40
- package/dist/audit.d.ts +1092 -48
- package/dist/audit.js +37 -23
- package/dist/auth.d.ts +2867 -61
- package/dist/auth.js +55 -25
- package/dist/automationRuns.d.ts +12 -13
- package/dist/automationRuns.js +15 -30
- package/dist/automations.d.ts +2474 -93
- package/dist/automations.js +56 -44
- package/dist/client.d.ts +30704 -0
- package/dist/client.js +62 -0
- package/dist/common.d.ts +28 -16
- package/dist/common.js +30 -22
- package/dist/companies.d.ts +1154 -44
- package/dist/companies.js +33 -17
- package/dist/contract/routes.json.js +1810 -0
- package/dist/customerAuth.d.ts +1661 -0
- package/dist/customerAuth.js +197 -0
- package/dist/customers.d.ts +1283 -65
- package/dist/customers.js +35 -25
- package/dist/{automationDefinition.d.ts → db/src/automationDefinition.d.ts} +4 -3
- package/dist/{automationDefinition.js → db/src/automationDefinition.js} +10 -32
- package/dist/db/src/enums.d.ts +8 -0
- package/dist/db/src/enums.js +334 -0
- package/dist/db/src/schema/auditStreams.js +6 -14
- package/dist/db/src/schema/authTokens.js +4 -6
- package/dist/db/src/schema/automations.d.ts +1 -0
- package/dist/db/src/schema/automations.js +15 -31
- package/dist/db/src/schema/common.d.ts +2 -6
- package/dist/db/src/schema/common.js +1 -24
- package/dist/db/src/schema/companies.js +6 -5
- package/dist/db/src/schema/customerAuth.js +101 -0
- package/dist/db/src/schema/customers.js +6 -6
- package/dist/db/src/schema/events.js +12 -60
- package/dist/db/src/schema/fieldValues.js +2 -2
- package/dist/db/src/schema/fields.js +10 -28
- package/dist/db/src/schema/index.d.ts +3 -0
- package/dist/db/src/schema/index.js +22 -20
- package/dist/db/src/schema/leadStages.js +5 -10
- package/dist/db/src/schema/leads.js +6 -11
- package/dist/db/src/schema/notes.js +92 -0
- package/dist/db/src/schema/oauth.js +3 -3
- package/dist/db/src/schema/payments.js +13 -23
- package/dist/db/src/schema/platform.js +11 -31
- package/dist/db/src/schema/plugins.js +10 -5
- package/dist/db/src/schema/products.js +7 -8
- package/dist/db/src/schema/rateLimits.js +7 -0
- package/dist/db/src/schema/saas.js +3 -9
- package/dist/db/src/schema/tags.js +6 -5
- package/dist/db/src/schema/transfer.js +13 -33
- package/dist/db/src/schema/trash.js +6 -7
- package/dist/db/src/schema/users.js +6 -10
- package/dist/db/src/schema/views.js +5 -13
- package/dist/db/src/schema/webhooks.js +7 -14
- package/dist/db/src/table.js +16 -2
- package/dist/errors.d.ts +516 -0
- package/dist/errors.js +218 -0
- package/dist/events.d.ts +585 -140
- package/dist/events.js +57 -42
- package/dist/fields.d.ts +1478 -66
- package/dist/fields.js +33 -47
- package/dist/files.d.ts +766 -62
- package/dist/files.js +34 -22
- package/dist/index.d.ts +25707 -902
- package/dist/index.js +22 -20
- package/dist/leads.d.ts +1108 -22
- package/dist/leads.js +39 -20
- package/dist/notifications.d.ts +691 -94
- package/dist/notifications.js +45 -91
- package/dist/organizations.d.ts +263 -5
- package/dist/organizations.js +21 -2
- package/dist/payments.d.ts +1794 -120
- package/dist/payments.js +58 -60
- package/dist/platform.d.ts +12 -20
- package/dist/platform.js +8 -21
- package/dist/plugins.d.ts +808 -71
- package/dist/plugins.js +66 -35
- package/dist/products.d.ts +1411 -53
- package/dist/products.js +40 -23
- package/dist/roles.d.ts +560 -8
- package/dist/roles.js +25 -11
- package/dist/routes.d.ts +8 -0
- package/dist/routes.js +13 -0
- package/dist/saas.d.ts +164 -8
- package/dist/saas.js +14 -29
- package/dist/tags.d.ts +344 -8
- package/dist/tags.js +16 -8
- package/dist/transfer.d.ts +1361 -36
- package/dist/transfer.js +47 -49
- package/dist/trash.d.ts +299 -23
- package/dist/trash.js +27 -20
- package/dist/users.d.ts +1233 -59
- package/dist/users.js +48 -39
- package/dist/values.d.ts +150 -0
- package/dist/values.js +139 -0
- package/dist/views.d.ts +404 -13
- package/dist/views.js +18 -28
- package/dist/webhooks.d.ts +791 -29
- package/dist/webhooks.js +36 -21
- package/package.json +9 -2
- package/dist/db/src/schema/jobs.js +0 -44
package/dist/automations.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import {
|
|
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 {
|
|
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:
|
|
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(
|
|
95
|
+
subject: z.enum(CONTENT_TYPES).nullable()
|
|
84
96
|
})),
|
|
85
97
|
actions: z.array(ActionInfo)
|
|
86
98
|
})),
|
|
87
|
-
list:
|
|
99
|
+
list: base.route({
|
|
88
100
|
method: "GET",
|
|
89
101
|
path: "/automations"
|
|
90
|
-
}).input(z.object({ status: AutomationStatus.optional() })).output(
|
|
91
|
-
get:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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(
|
|
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:
|
|
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:
|
|
182
|
+
versions: base.route({
|
|
171
183
|
method: "GET",
|
|
172
184
|
path: "/automations/{id}/versions",
|
|
173
|
-
summary: "
|
|
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:
|
|
189
|
+
createdAt: isoDate(),
|
|
178
190
|
definition: AutomationDefinition
|
|
179
|
-
})) })),
|
|
180
|
-
restoreVersion:
|
|
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:
|
|
200
|
+
templates: base.route({
|
|
189
201
|
method: "GET",
|
|
190
202
|
path: "/automations/templates",
|
|
191
203
|
summary: "Ready-made automations to start from"
|
|
192
|
-
}).output(
|
|
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:
|
|
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(
|
|
203
|
-
remove:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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,
|
|
244
|
+
export { Automation, AutomationFieldPath, DryRunStep, automationsContract };
|