@erxes/core-contract 0.1.0-v2.1 → 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 +1387 -139
- package/dist/activities.js +90 -30
- package/dist/audit.d.ts +1081 -33
- package/dist/audit.js +28 -14
- package/dist/auth.d.ts +2834 -26
- package/dist/auth.js +47 -18
- package/dist/automationRuns.d.ts +7 -9
- package/dist/automationRuns.js +12 -13
- package/dist/automations.d.ts +2443 -61
- package/dist/automations.js +41 -21
- package/dist/client.d.ts +30704 -0
- package/dist/client.js +62 -0
- package/dist/common.d.ts +0 -13
- package/dist/common.js +1 -13
- package/dist/companies.d.ts +1120 -10
- package/dist/companies.js +27 -12
- package/dist/contract/routes.json.js +17 -1
- package/dist/customerAuth.d.ts +1456 -17
- package/dist/customerAuth.js +33 -16
- package/dist/customers.d.ts +1232 -11
- package/dist/customers.js +28 -13
- package/dist/{automationDefinition.d.ts → db/src/automationDefinition.d.ts} +2 -2
- package/dist/{automationDefinition.js → db/src/automationDefinition.js} +2 -2
- package/dist/db/src/enums.js +1 -3
- package/dist/db/src/schema/automations.d.ts +1 -0
- package/dist/db/src/schema/automations.js +3 -3
- package/dist/db/src/schema/index.d.ts +3 -0
- package/dist/db/src/schema/index.js +3 -2
- package/dist/db/src/schema/leads.js +2 -2
- package/dist/db/src/schema/notes.js +92 -0
- package/dist/db/src/schema/payments.js +2 -2
- package/dist/db/src/schema/platform.js +0 -5
- package/dist/db/src/schema/plugins.js +7 -2
- package/dist/db/src/schema/transfer.js +2 -2
- package/dist/errors.d.ts +516 -0
- package/dist/errors.js +218 -0
- package/dist/events.d.ts +570 -121
- package/dist/events.js +41 -24
- package/dist/fields.d.ts +1456 -16
- package/dist/fields.js +27 -19
- package/dist/files.d.ts +761 -62
- package/dist/files.js +32 -21
- package/dist/index.d.ts +25187 -618
- package/dist/index.js +8 -7
- package/dist/leads.d.ts +1105 -21
- package/dist/leads.js +31 -13
- package/dist/notifications.d.ts +689 -48
- package/dist/notifications.js +38 -18
- package/dist/organizations.d.ts +260 -2
- package/dist/organizations.js +21 -2
- package/dist/payments.d.ts +1766 -62
- package/dist/payments.js +48 -26
- package/dist/platform.d.ts +12 -21
- package/dist/platform.js +7 -17
- package/dist/plugins.d.ts +802 -71
- package/dist/plugins.js +48 -27
- package/dist/products.d.ts +1380 -17
- package/dist/products.js +32 -16
- package/dist/roles.d.ts +560 -5
- package/dist/roles.js +20 -6
- package/dist/saas.d.ts +164 -2
- package/dist/saas.js +9 -2
- package/dist/tags.d.ts +340 -4
- package/dist/tags.js +14 -6
- package/dist/transfer.d.ts +1299 -12
- package/dist/transfer.js +32 -13
- package/dist/trash.d.ts +278 -21
- package/dist/trash.js +23 -16
- package/dist/users.d.ts +1206 -18
- package/dist/users.js +35 -13
- package/dist/values.d.ts +0 -9
- package/dist/values.js +2 -7
- package/dist/views.d.ts +396 -5
- package/dist/views.js +10 -7
- package/dist/webhooks.d.ts +765 -9
- package/dist/webhooks.js +18 -10
- package/package.json +6 -2
package/dist/activities.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { ACTIVITY_TARGETS, TIMELINE_KINDS } from "./db/src/enums.js";
|
|
2
2
|
import { activities } from "./db/src/schema/platform.js";
|
|
3
|
+
import { noteVersions, notes } from "./db/src/schema/notes.js";
|
|
3
4
|
import "./db/src/schema/index.js";
|
|
5
|
+
import { COMMON_ERRORS, ERRORS } from "./errors.js";
|
|
4
6
|
import { CursorQuery, Id, QueryFlag, cursorPageOf, isoDate } from "./common.js";
|
|
5
|
-
import {
|
|
7
|
+
import { AppLink, DedupeKey, EntityType, EventType } from "./platform.js";
|
|
6
8
|
import { oc } from "@orpc/contract";
|
|
7
|
-
import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
|
|
8
9
|
import { z } from "zod";
|
|
10
|
+
import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
|
|
9
11
|
// src/activities.ts
|
|
10
12
|
const ActivityTarget = z.enum(ACTIVITY_TARGETS);
|
|
11
13
|
/**
|
|
@@ -31,11 +33,34 @@ const CORE_ACTIVITY_TYPES = [
|
|
|
31
33
|
"company.customer_linked",
|
|
32
34
|
"company.customer_unlinked"
|
|
33
35
|
];
|
|
36
|
+
/** What only a note has; its entry says where it is and who wrote it. */
|
|
37
|
+
const Note = createSelectSchema(notes, {
|
|
38
|
+
pinnedAt: isoDate,
|
|
39
|
+
editedAt: isoDate
|
|
40
|
+
}).pick({
|
|
41
|
+
body: true,
|
|
42
|
+
/** Members mentioned with @. */
|
|
43
|
+
mentions: true,
|
|
44
|
+
fileIds: true,
|
|
45
|
+
/** Pinned to the top of the timeline. */
|
|
46
|
+
pinnedAt: true,
|
|
47
|
+
/** Last reworded; earlier wordings are in `noteVersions`. */
|
|
48
|
+
editedAt: true
|
|
49
|
+
});
|
|
50
|
+
const NoteVersion = createSelectSchema(noteVersions, {
|
|
51
|
+
id: Id,
|
|
52
|
+
editedAt: isoDate
|
|
53
|
+
}).pick({
|
|
54
|
+
id: true,
|
|
55
|
+
/** The wording an edit replaced. */
|
|
56
|
+
body: true,
|
|
57
|
+
/** When this wording was written. */
|
|
58
|
+
editedAt: true
|
|
59
|
+
});
|
|
34
60
|
const Activity = createSelectSchema(activities, {
|
|
35
61
|
id: Id,
|
|
36
62
|
targetId: Id,
|
|
37
63
|
data: z.record(z.string(), z.unknown()),
|
|
38
|
-
editedAt: isoDate,
|
|
39
64
|
occurredAt: isoDate
|
|
40
65
|
}).pick({
|
|
41
66
|
id: true,
|
|
@@ -52,17 +77,23 @@ const Activity = createSelectSchema(activities, {
|
|
|
52
77
|
*/
|
|
53
78
|
data: true,
|
|
54
79
|
link: true,
|
|
55
|
-
|
|
80
|
+
/** The plugin's own record it is about. */
|
|
81
|
+
entityType: true,
|
|
82
|
+
entityId: true,
|
|
83
|
+
/** Who did it: a team member (`actorId` = user id), a plugin (its name) or `system`. */
|
|
84
|
+
actorType: true,
|
|
85
|
+
actorId: true,
|
|
56
86
|
occurredAt: true
|
|
57
87
|
}).extend({
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
88
|
+
/** A team member's name and picture, selected with the entry so the timeline reads at once. */
|
|
89
|
+
actorName: z.string().nullable(),
|
|
90
|
+
actorAvatarUrl: z.string().nullable(),
|
|
91
|
+
/** Notes (`<target>.note`) only. */
|
|
92
|
+
note: Note.nullable(),
|
|
93
|
+
/** Emoji → the members who reacted, first reaction first. */
|
|
63
94
|
reactions: z.record(z.string(), z.array(z.string()))
|
|
64
95
|
});
|
|
65
|
-
/** Notes are timeline entries of type `customer.note` / `company.note
|
|
96
|
+
/** Notes are timeline entries of type `customer.note` / `company.note`, with `note` set. */
|
|
66
97
|
const NoteInput = z.object({
|
|
67
98
|
body: z.string().trim().min(1).max(1e4),
|
|
68
99
|
/** Team members mentioned with @: they are notified. */
|
|
@@ -80,7 +111,9 @@ const ActivityInput = createUpdateSchema(activities, {
|
|
|
80
111
|
data: () => z.record(z.string(), z.unknown()),
|
|
81
112
|
link: AppLink.optional(),
|
|
82
113
|
occurredAt: () => z.iso.datetime(),
|
|
83
|
-
dedupeKey: DedupeKey.optional()
|
|
114
|
+
dedupeKey: DedupeKey.optional(),
|
|
115
|
+
entityType: EntityType.optional(),
|
|
116
|
+
entityId: Id.optional()
|
|
84
117
|
}).pick({
|
|
85
118
|
targetType: true,
|
|
86
119
|
targetId: true,
|
|
@@ -90,6 +123,9 @@ const ActivityInput = createUpdateSchema(activities, {
|
|
|
90
123
|
summary: true,
|
|
91
124
|
data: true,
|
|
92
125
|
link: true,
|
|
126
|
+
/** The plugin's own record it is about. */
|
|
127
|
+
entityType: true,
|
|
128
|
+
entityId: true,
|
|
93
129
|
/** When it happened (defaults to now). */
|
|
94
130
|
occurredAt: true,
|
|
95
131
|
/** Retry-safe: one entry per plugin and key. */
|
|
@@ -98,14 +134,26 @@ const ActivityInput = createUpdateSchema(activities, {
|
|
|
98
134
|
targetType: true,
|
|
99
135
|
targetId: true,
|
|
100
136
|
type: true
|
|
101
|
-
}).extend({
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
actorUserId: Id.optional()
|
|
105
|
-
});
|
|
137
|
+
}).extend({
|
|
138
|
+
/** The team member who did it, if any. */
|
|
139
|
+
actorUserId: Id.optional() }).refine((value) => value.entityType === void 0 === (value.entityId === void 0), "entityType and entityId go together");
|
|
106
140
|
/** The customer and company timeline, across core and plugins. */
|
|
141
|
+
const { INVALID_ACTOR, INVALID_FILE, INVALID_OWNER, INVALID_RECIPIENT, INVALID_TYPE, MASS_DELETE_STOPPED, NOT_AUTHOR, NO_TIMELINE, TOO_MANY_REACTIONS } = ERRORS;
|
|
142
|
+
/** What these procedures answer with besides the common errors. */
|
|
143
|
+
const base = oc.errors({
|
|
144
|
+
...COMMON_ERRORS,
|
|
145
|
+
INVALID_ACTOR,
|
|
146
|
+
INVALID_FILE,
|
|
147
|
+
INVALID_OWNER,
|
|
148
|
+
INVALID_RECIPIENT,
|
|
149
|
+
INVALID_TYPE,
|
|
150
|
+
MASS_DELETE_STOPPED,
|
|
151
|
+
NOT_AUTHOR,
|
|
152
|
+
NO_TIMELINE,
|
|
153
|
+
TOO_MANY_REACTIONS
|
|
154
|
+
});
|
|
107
155
|
const activitiesContract = {
|
|
108
|
-
list:
|
|
156
|
+
list: base.route({
|
|
109
157
|
method: "GET",
|
|
110
158
|
path: "/activities",
|
|
111
159
|
summary: "A customer’s or company’s timeline, newest first"
|
|
@@ -125,7 +173,7 @@ const activitiesContract = {
|
|
|
125
173
|
/** A company's timeline with its customers' entries too. */
|
|
126
174
|
includeRelated: QueryFlag.optional()
|
|
127
175
|
})).output(cursorPageOf(Activity)),
|
|
128
|
-
addNote:
|
|
176
|
+
addNote: base.route({
|
|
129
177
|
method: "POST",
|
|
130
178
|
path: "/activities/notes",
|
|
131
179
|
successStatus: 201,
|
|
@@ -134,7 +182,7 @@ const activitiesContract = {
|
|
|
134
182
|
targetType: TimelineTarget,
|
|
135
183
|
targetId: Id
|
|
136
184
|
})).output(Activity),
|
|
137
|
-
react:
|
|
185
|
+
react: base.route({
|
|
138
186
|
method: "POST",
|
|
139
187
|
path: "/activities/{id}/reactions",
|
|
140
188
|
summary: "Add or take back a reaction (an emoji) on an entry"
|
|
@@ -142,7 +190,7 @@ const activitiesContract = {
|
|
|
142
190
|
id: Id,
|
|
143
191
|
emoji: z.string().trim().min(1).max(16)
|
|
144
192
|
})).output(Activity),
|
|
145
|
-
types:
|
|
193
|
+
types: base.route({
|
|
146
194
|
method: "GET",
|
|
147
195
|
path: "/activities/types",
|
|
148
196
|
summary: "Timeline entry types and plugin record timelines: core's and installed plugins'"
|
|
@@ -161,23 +209,35 @@ const activitiesContract = {
|
|
|
161
209
|
permission: z.string().nullable()
|
|
162
210
|
}))
|
|
163
211
|
})),
|
|
164
|
-
|
|
212
|
+
editNote: base.route({
|
|
165
213
|
method: "PATCH",
|
|
166
214
|
path: "/activities/notes/{id}",
|
|
167
|
-
summary: "Edit a note (its author)
|
|
215
|
+
summary: "Edit a note (its author only). A new wording keeps the old one in `noteVersions`; newly mentioned members are notified"
|
|
168
216
|
}).input(z.object({
|
|
169
217
|
id: Id,
|
|
170
218
|
body: NoteInput.shape.body.optional(),
|
|
171
219
|
mentions: z.array(Id).max(50).optional(),
|
|
172
|
-
fileIds: z.array(Id).max(20).optional()
|
|
173
|
-
|
|
220
|
+
fileIds: z.array(Id).max(20).optional()
|
|
221
|
+
}).refine((value) => value.body !== void 0 || value.mentions !== void 0 || value.fileIds !== void 0, "Change the body, the mentions or the files")).output(Activity),
|
|
222
|
+
pinNote: base.route({
|
|
223
|
+
method: "PUT",
|
|
224
|
+
path: "/activities/notes/{id}/pinned",
|
|
225
|
+
summary: "Pin a note to the top of its timeline, or unpin it (any member)"
|
|
226
|
+
}).input(z.object({
|
|
227
|
+
id: Id,
|
|
228
|
+
pinned: z.boolean()
|
|
174
229
|
})).output(Activity),
|
|
175
|
-
|
|
230
|
+
noteVersions: base.route({
|
|
231
|
+
method: "GET",
|
|
232
|
+
path: "/activities/notes/{id}/versions",
|
|
233
|
+
summary: "A note's earlier wordings, newest first (the latest 100)"
|
|
234
|
+
}).input(z.object({ id: Id })).output(z.object({ data: z.array(NoteVersion).max(100) })),
|
|
235
|
+
removeNote: base.route({
|
|
176
236
|
method: "DELETE",
|
|
177
237
|
path: "/activities/notes/{id}",
|
|
178
238
|
summary: "Delete a note (its author, owners and admins)"
|
|
179
239
|
}).input(z.object({ id: Id })).output(z.object({ ok: z.literal(true) })),
|
|
180
|
-
create:
|
|
240
|
+
create: base.route({
|
|
181
241
|
method: "POST",
|
|
182
242
|
path: "/activities",
|
|
183
243
|
successStatus: 201,
|
|
@@ -186,7 +246,7 @@ const activitiesContract = {
|
|
|
186
246
|
activity: Activity,
|
|
187
247
|
created: z.boolean()
|
|
188
248
|
})),
|
|
189
|
-
update:
|
|
249
|
+
update: base.route({
|
|
190
250
|
method: "PATCH",
|
|
191
251
|
path: "/activities/{id}",
|
|
192
252
|
summary: "Change a plugin's own entry (by id, or by its dedupe key with id `key:<dedupeKey>`) — the order was refunded, the line changes"
|
|
@@ -195,11 +255,11 @@ const activitiesContract = {
|
|
|
195
255
|
summary: z.string().trim().min(1).max(500).optional(),
|
|
196
256
|
data: z.record(z.string(), z.unknown()).optional(),
|
|
197
257
|
link: AppLink.nullable().optional()
|
|
198
|
-
})).output(Activity),
|
|
199
|
-
remove:
|
|
258
|
+
}).refine((value) => value.summary !== void 0 || value.data !== void 0 || value.link !== void 0, "Change the summary, the data or the link")).output(Activity),
|
|
259
|
+
remove: base.route({
|
|
200
260
|
method: "DELETE",
|
|
201
261
|
path: "/activities/{id}",
|
|
202
262
|
summary: "Remove a plugin's own entry (by id or `key:<dedupeKey>`)"
|
|
203
263
|
}).input(z.object({ id: z.string().min(1).max(260) })).output(z.object({ ok: z.literal(true) }))
|
|
204
264
|
};
|
|
205
|
-
export { Activity, ActivityInput, ActivityTarget, CORE_ACTIVITY_TYPES, NoteInput, TimelineKind, TimelineTarget, activitiesContract };
|
|
265
|
+
export { Activity, ActivityInput, ActivityTarget, CORE_ACTIVITY_TYPES, Note, NoteInput, NoteVersion, TimelineKind, TimelineTarget, activitiesContract };
|