@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/fields.js
CHANGED
|
@@ -1,33 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { fieldGroups, fields } from "./db/src/schema/fields.js";
|
|
2
2
|
import "./db/src/schema/index.js";
|
|
3
|
-
import {
|
|
3
|
+
import { COMMON_ERRORS, ERRORS } from "./errors.js";
|
|
4
|
+
import { OPTION_FIELD_TYPES } from "./values.js";
|
|
5
|
+
import { FieldContentType, Id, IdList, QueryBoolean, isoDate, listOf } from "./common.js";
|
|
4
6
|
import { oc } from "@orpc/contract";
|
|
5
|
-
import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
|
|
6
7
|
import { z } from "zod";
|
|
8
|
+
import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
|
|
7
9
|
// src/fields.ts
|
|
8
|
-
const FieldType = z.enum(FIELD_TYPES);
|
|
9
|
-
/** Field types whose values are chosen from `options`. */
|
|
10
|
-
const OPTION_FIELD_TYPES = [
|
|
11
|
-
"select",
|
|
12
|
-
"multiselect",
|
|
13
|
-
"radio",
|
|
14
|
-
"check"
|
|
15
|
-
];
|
|
16
|
-
/**
|
|
17
|
-
* Types sharing a stored value: a field holding values may only change within
|
|
18
|
-
* its family; an unused field may become any type.
|
|
19
|
-
*/
|
|
20
|
-
const FIELD_TYPE_FAMILIES = [
|
|
21
|
-
["select", "radio"],
|
|
22
|
-
["multiselect", "check"],
|
|
23
|
-
[
|
|
24
|
-
"text",
|
|
25
|
-
"textarea",
|
|
26
|
-
"phone"
|
|
27
|
-
]
|
|
28
|
-
];
|
|
29
|
-
/** Format a text field's values must have. */
|
|
30
|
-
const FieldValidation = z.enum(FIELD_VALIDATIONS);
|
|
31
10
|
/** A custom field ("property") on customers or companies. */
|
|
32
11
|
const int = () => z.int();
|
|
33
12
|
const Field = createSelectSchema(fields, {
|
|
@@ -131,8 +110,15 @@ const Orders = z.object({ orders: z.array(z.object({
|
|
|
131
110
|
const Ok = z.object({ ok: z.literal(true) });
|
|
132
111
|
const changes = (value) => Object.keys(value).some((key) => key !== "id");
|
|
133
112
|
const needsOptions = (value) => !value.type || !OPTION_FIELD_TYPES.includes(value.type) || (value.options?.length ?? 0) > 0;
|
|
113
|
+
const { FIELD_IN_USE, INVALID_FIELD_GROUP } = ERRORS;
|
|
114
|
+
/** What these procedures answer with besides the common errors. */
|
|
115
|
+
const base = oc.errors({
|
|
116
|
+
...COMMON_ERRORS,
|
|
117
|
+
FIELD_IN_USE,
|
|
118
|
+
INVALID_FIELD_GROUP
|
|
119
|
+
});
|
|
134
120
|
const fieldsContract = {
|
|
135
|
-
list:
|
|
121
|
+
list: base.route({
|
|
136
122
|
method: "GET",
|
|
137
123
|
path: "/fields",
|
|
138
124
|
summary: "Custom fields of a record type, in order. Archived ones (or those of an archived group) only with `archived=true`"
|
|
@@ -140,8 +126,8 @@ const fieldsContract = {
|
|
|
140
126
|
contentType: FieldContentType,
|
|
141
127
|
groupId: Id.optional(),
|
|
142
128
|
archived: QueryBoolean.optional()
|
|
143
|
-
})).output(
|
|
144
|
-
usage:
|
|
129
|
+
})).output(listOf(Field)),
|
|
130
|
+
usage: base.route({
|
|
145
131
|
method: "GET",
|
|
146
132
|
path: "/fields/usage",
|
|
147
133
|
summary: "How many records hold values of the given fields (or of a group’s fields)"
|
|
@@ -149,11 +135,11 @@ const fieldsContract = {
|
|
|
149
135
|
ids: IdList.optional(),
|
|
150
136
|
groupId: Id.optional()
|
|
151
137
|
}).refine((value) => (value.ids?.length ?? 0) > 0 || !!value.groupId, "ids or groupId is required")).output(FieldUsage),
|
|
152
|
-
create:
|
|
138
|
+
create: base.route({
|
|
153
139
|
method: "POST",
|
|
154
140
|
path: "/fields",
|
|
155
141
|
successStatus: 201,
|
|
156
|
-
summary: "Add a custom field (owners and admins). 409
|
|
142
|
+
summary: "Add a custom field (owners and admins). 409 TAKEN for a taken label or code"
|
|
157
143
|
}).input(FieldFields.omit({ order: true }).required({
|
|
158
144
|
contentType: true,
|
|
159
145
|
label: true,
|
|
@@ -162,79 +148,79 @@ const fieldsContract = {
|
|
|
162
148
|
path: ["options"],
|
|
163
149
|
error: "select fields need options"
|
|
164
150
|
})).output(Field),
|
|
165
|
-
update:
|
|
151
|
+
update: base.route({
|
|
166
152
|
method: "PATCH",
|
|
167
153
|
path: "/fields/{id}",
|
|
168
154
|
summary: "Change a field. The type changes only within types sharing a stored value while records hold values (409 FIELD_IN_USE)"
|
|
169
155
|
}).input(FieldFields.omit({ contentType: true }).extend({ id: Id }).refine(changes, "nothing to update")).output(Field),
|
|
170
|
-
reorder:
|
|
156
|
+
reorder: base.route({
|
|
171
157
|
method: "POST",
|
|
172
158
|
path: "/fields/order",
|
|
173
159
|
summary: "Set the order of fields (owners and admins)"
|
|
174
160
|
}).input(Orders).output(Ok),
|
|
175
|
-
archive:
|
|
161
|
+
archive: base.route({
|
|
176
162
|
method: "POST",
|
|
177
163
|
path: "/fields/archive",
|
|
178
164
|
summary: "Archive fields: hidden everywhere, values kept (owners and admins)"
|
|
179
165
|
}).input(z.object({ ids: z.array(Id).min(1).max(100) })).output(Ok),
|
|
180
|
-
restore:
|
|
166
|
+
restore: base.route({
|
|
181
167
|
method: "POST",
|
|
182
168
|
path: "/fields/{id}/restore",
|
|
183
169
|
summary: "Restore an archived field (owners and admins)"
|
|
184
170
|
}).input(z.object({ id: Id })).output(Field),
|
|
185
|
-
removeUnused:
|
|
171
|
+
removeUnused: base.route({
|
|
186
172
|
method: "POST",
|
|
187
173
|
path: "/fields/remove",
|
|
188
174
|
summary: "Delete fields no record holds a value of (owners and admins). 409 FIELD_IN_USE otherwise"
|
|
189
175
|
}).input(z.object({ ids: z.array(Id).min(1).max(100) })).output(Ok),
|
|
190
|
-
remove:
|
|
176
|
+
remove: base.route({
|
|
191
177
|
method: "DELETE",
|
|
192
178
|
path: "/fields/{id}",
|
|
193
179
|
summary: "Delete a custom field and its values (owners and admins)"
|
|
194
180
|
}).input(z.object({ id: Id })).output(Ok)
|
|
195
181
|
};
|
|
196
182
|
const fieldGroupsContract = {
|
|
197
|
-
list:
|
|
183
|
+
list: base.route({
|
|
198
184
|
method: "GET",
|
|
199
185
|
path: "/field-groups",
|
|
200
186
|
summary: "Field groups of a record type, in order. Archived ones only with `archived=true`"
|
|
201
187
|
}).input(z.object({
|
|
202
188
|
contentType: FieldContentType,
|
|
203
189
|
archived: QueryBoolean.optional()
|
|
204
|
-
})).output(
|
|
205
|
-
create:
|
|
190
|
+
})).output(listOf(FieldGroup)),
|
|
191
|
+
create: base.route({
|
|
206
192
|
method: "POST",
|
|
207
193
|
path: "/field-groups",
|
|
208
194
|
successStatus: 201,
|
|
209
|
-
summary: "Add a field group (owners and admins). The code defaults to the name; 409
|
|
195
|
+
summary: "Add a field group (owners and admins). The code defaults to the name; 409 TAKEN for a taken code"
|
|
210
196
|
}).input(GroupFields.omit({ order: true }).required({
|
|
211
197
|
contentType: true,
|
|
212
198
|
name: true
|
|
213
199
|
})).output(FieldGroup),
|
|
214
|
-
update:
|
|
200
|
+
update: base.route({
|
|
215
201
|
method: "PATCH",
|
|
216
202
|
path: "/field-groups/{id}",
|
|
217
203
|
summary: "Rename a field group (owners and admins)"
|
|
218
204
|
}).input(GroupFields.omit({ contentType: true }).extend({ id: Id }).refine(changes, "nothing to update")).output(FieldGroup),
|
|
219
|
-
reorder:
|
|
205
|
+
reorder: base.route({
|
|
220
206
|
method: "POST",
|
|
221
207
|
path: "/field-groups/order",
|
|
222
208
|
summary: "Set the order of field groups (owners and admins)"
|
|
223
209
|
}).input(Orders).output(Ok),
|
|
224
|
-
archive:
|
|
210
|
+
archive: base.route({
|
|
225
211
|
method: "POST",
|
|
226
212
|
path: "/field-groups/{id}/archive",
|
|
227
213
|
summary: "Archive a group: it and its fields are hidden, values kept (owners and admins)"
|
|
228
214
|
}).input(z.object({ id: Id })).output(FieldGroup),
|
|
229
|
-
restore:
|
|
215
|
+
restore: base.route({
|
|
230
216
|
method: "POST",
|
|
231
217
|
path: "/field-groups/{id}/restore",
|
|
232
218
|
summary: "Restore an archived group (owners and admins)"
|
|
233
219
|
}).input(z.object({ id: Id })).output(FieldGroup),
|
|
234
|
-
remove:
|
|
220
|
+
remove: base.route({
|
|
235
221
|
method: "DELETE",
|
|
236
222
|
path: "/field-groups/{id}",
|
|
237
223
|
summary: "Delete a group and its fields when no record holds their values (owners and admins). 409 FIELD_IN_USE otherwise"
|
|
238
224
|
}).input(z.object({ id: Id })).output(Ok)
|
|
239
225
|
};
|
|
240
|
-
export {
|
|
226
|
+
export { Field, FieldGroup, FieldUsage, fieldGroupsContract, fieldsContract };
|