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

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 (77) hide show
  1. package/dist/activities.d.ts +1387 -139
  2. package/dist/activities.js +90 -30
  3. package/dist/audit.d.ts +1081 -33
  4. package/dist/audit.js +28 -14
  5. package/dist/auth.d.ts +2834 -26
  6. package/dist/auth.js +47 -18
  7. package/dist/automationRuns.d.ts +7 -9
  8. package/dist/automationRuns.js +12 -13
  9. package/dist/automations.d.ts +2443 -61
  10. package/dist/automations.js +41 -21
  11. package/dist/client.d.ts +30704 -0
  12. package/dist/client.js +62 -0
  13. package/dist/common.d.ts +0 -13
  14. package/dist/common.js +1 -13
  15. package/dist/companies.d.ts +1120 -10
  16. package/dist/companies.js +27 -12
  17. package/dist/contract/routes.json.js +17 -1
  18. package/dist/customerAuth.d.ts +1456 -17
  19. package/dist/customerAuth.js +33 -16
  20. package/dist/customers.d.ts +1232 -11
  21. package/dist/customers.js +28 -13
  22. package/dist/{automationDefinition.d.ts → db/src/automationDefinition.d.ts} +2 -2
  23. package/dist/{automationDefinition.js → db/src/automationDefinition.js} +2 -2
  24. package/dist/db/src/enums.js +1 -3
  25. package/dist/db/src/schema/automations.d.ts +1 -0
  26. package/dist/db/src/schema/automations.js +3 -3
  27. package/dist/db/src/schema/index.d.ts +3 -0
  28. package/dist/db/src/schema/index.js +3 -2
  29. package/dist/db/src/schema/leads.js +2 -2
  30. package/dist/db/src/schema/notes.js +92 -0
  31. package/dist/db/src/schema/payments.js +2 -2
  32. package/dist/db/src/schema/platform.js +0 -5
  33. package/dist/db/src/schema/plugins.js +7 -2
  34. package/dist/db/src/schema/transfer.js +2 -2
  35. package/dist/errors.d.ts +516 -0
  36. package/dist/errors.js +218 -0
  37. package/dist/events.d.ts +570 -121
  38. package/dist/events.js +41 -24
  39. package/dist/fields.d.ts +1456 -16
  40. package/dist/fields.js +27 -19
  41. package/dist/files.d.ts +761 -62
  42. package/dist/files.js +32 -21
  43. package/dist/index.d.ts +25187 -618
  44. package/dist/index.js +8 -7
  45. package/dist/leads.d.ts +1105 -21
  46. package/dist/leads.js +31 -13
  47. package/dist/notifications.d.ts +689 -48
  48. package/dist/notifications.js +38 -18
  49. package/dist/organizations.d.ts +260 -2
  50. package/dist/organizations.js +21 -2
  51. package/dist/payments.d.ts +1766 -62
  52. package/dist/payments.js +48 -26
  53. package/dist/platform.d.ts +12 -21
  54. package/dist/platform.js +7 -17
  55. package/dist/plugins.d.ts +802 -71
  56. package/dist/plugins.js +48 -27
  57. package/dist/products.d.ts +1380 -17
  58. package/dist/products.js +32 -16
  59. package/dist/roles.d.ts +560 -5
  60. package/dist/roles.js +20 -6
  61. package/dist/saas.d.ts +164 -2
  62. package/dist/saas.js +9 -2
  63. package/dist/tags.d.ts +340 -4
  64. package/dist/tags.js +14 -6
  65. package/dist/transfer.d.ts +1299 -12
  66. package/dist/transfer.js +32 -13
  67. package/dist/trash.d.ts +278 -21
  68. package/dist/trash.js +23 -16
  69. package/dist/users.d.ts +1206 -18
  70. package/dist/users.js +35 -13
  71. package/dist/values.d.ts +0 -9
  72. package/dist/values.js +2 -7
  73. package/dist/views.d.ts +396 -5
  74. package/dist/views.js +10 -7
  75. package/dist/webhooks.d.ts +765 -9
  76. package/dist/webhooks.js +18 -10
  77. package/package.json +6 -2
@@ -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 { ActorRef, AppLink, DedupeKey, EntityRef, EventType } from "./platform.js";
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
- editedAt: true,
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
- entity: EntityRef.nullable(),
59
- actor: ActorRef,
60
- /** Notes only. */
61
- pinned: z.boolean(),
62
- /** Emoji → the members who reacted. */
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`; `data` = `{ body, mentions, fileIds }`. */
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
- entity: EntityRef.optional(),
103
- /** The team member who did it, if any. */
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: oc.route({
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: oc.route({
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: oc.route({
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: oc.route({
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
- updateNote: oc.route({
212
+ editNote: base.route({
165
213
  method: "PATCH",
166
214
  path: "/activities/notes/{id}",
167
- summary: "Edit a note (its author) or pin / unpin it (any member)"
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
- pinned: z.boolean().optional()
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
- removeNote: oc.route({
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: oc.route({
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: oc.route({
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: oc.route({
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 };