@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,12 +1,15 @@
1
+ import { ACTIVITY_TARGETS, TIMELINE_KINDS } from "./db/src/enums.js";
1
2
  import { activities } from "./db/src/schema/platform.js";
3
+ import { noteVersions, notes } from "./db/src/schema/notes.js";
2
4
  import "./db/src/schema/index.js";
3
- import { CursorQuery, Id, cursorPageOf, isoDate } from "./common.js";
4
- import { ActorRef, AppLink, DedupeKey, EntityRef, EventType } from "./platform.js";
5
+ import { COMMON_ERRORS, ERRORS } from "./errors.js";
6
+ import { CursorQuery, Id, QueryFlag, cursorPageOf, isoDate } from "./common.js";
7
+ import { AppLink, DedupeKey, EntityType, EventType } from "./platform.js";
5
8
  import { oc } from "@orpc/contract";
6
- import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
7
9
  import { z } from "zod";
10
+ import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
8
11
  // src/activities.ts
9
- const ActivityTarget = z.enum(["customer", "company"]);
12
+ const ActivityTarget = z.enum(ACTIVITY_TARGETS);
10
13
  /**
11
14
  * What a timeline is about: a customer or company, or a plugin's own record
12
15
  * type declared in its manifest (`hr.employee`, `ecom.order`).
@@ -30,11 +33,34 @@ const CORE_ACTIVITY_TYPES = [
30
33
  "company.customer_linked",
31
34
  "company.customer_unlinked"
32
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
+ });
33
60
  const Activity = createSelectSchema(activities, {
34
61
  id: Id,
35
62
  targetId: Id,
36
63
  data: z.record(z.string(), z.unknown()),
37
- editedAt: isoDate,
38
64
  occurredAt: isoDate
39
65
  }).pick({
40
66
  id: true,
@@ -51,17 +77,23 @@ const Activity = createSelectSchema(activities, {
51
77
  */
52
78
  data: true,
53
79
  link: true,
54
- 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,
55
86
  occurredAt: true
56
87
  }).extend({
57
- entity: EntityRef.nullable(),
58
- actor: ActorRef,
59
- /** Notes only. */
60
- pinned: z.boolean(),
61
- /** 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. */
62
94
  reactions: z.record(z.string(), z.array(z.string()))
63
95
  });
64
- /** 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. */
65
97
  const NoteInput = z.object({
66
98
  body: z.string().trim().min(1).max(1e4),
67
99
  /** Team members mentioned with @: they are notified. */
@@ -70,12 +102,7 @@ const NoteInput = z.object({
70
102
  fileIds: z.array(Id).max(20).default([])
71
103
  });
72
104
  /** Which entries a timeline shows. */
73
- const TimelineKind = z.enum([
74
- "all",
75
- "notes",
76
- "changes",
77
- "plugins"
78
- ]);
105
+ const TimelineKind = z.enum(TIMELINE_KINDS);
79
106
  const ActivityInput = createUpdateSchema(activities, {
80
107
  targetType: () => TimelineTarget,
81
108
  targetId: () => Id,
@@ -84,7 +111,9 @@ const ActivityInput = createUpdateSchema(activities, {
84
111
  data: () => z.record(z.string(), z.unknown()),
85
112
  link: AppLink.optional(),
86
113
  occurredAt: () => z.iso.datetime(),
87
- dedupeKey: DedupeKey.optional()
114
+ dedupeKey: DedupeKey.optional(),
115
+ entityType: EntityType.optional(),
116
+ entityId: Id.optional()
88
117
  }).pick({
89
118
  targetType: true,
90
119
  targetId: true,
@@ -94,6 +123,9 @@ const ActivityInput = createUpdateSchema(activities, {
94
123
  summary: true,
95
124
  data: true,
96
125
  link: true,
126
+ /** The plugin's own record it is about. */
127
+ entityType: true,
128
+ entityId: true,
97
129
  /** When it happened (defaults to now). */
98
130
  occurredAt: true,
99
131
  /** Retry-safe: one entry per plugin and key. */
@@ -102,14 +134,26 @@ const ActivityInput = createUpdateSchema(activities, {
102
134
  targetType: true,
103
135
  targetId: true,
104
136
  type: true
105
- }).extend({
106
- entity: EntityRef.optional(),
107
- /** The team member who did it, if any. */
108
- actorUserId: Id.optional()
109
- });
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");
110
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
+ });
111
155
  const activitiesContract = {
112
- list: oc.route({
156
+ list: base.route({
113
157
  method: "GET",
114
158
  path: "/activities",
115
159
  summary: "A customer’s or company’s timeline, newest first"
@@ -125,11 +169,11 @@ const activitiesContract = {
125
169
  to: z.iso.datetime().optional(),
126
170
  kind: TimelineKind.default("all"),
127
171
  /** Pinned notes only. */
128
- pinned: z.enum(["true", "false"]).transform((value) => value === "true").optional(),
172
+ pinned: QueryFlag.optional(),
129
173
  /** A company's timeline with its customers' entries too. */
130
- includeRelated: z.enum(["true", "false"]).transform((value) => value === "true").optional()
174
+ includeRelated: QueryFlag.optional()
131
175
  })).output(cursorPageOf(Activity)),
132
- addNote: oc.route({
176
+ addNote: base.route({
133
177
  method: "POST",
134
178
  path: "/activities/notes",
135
179
  successStatus: 201,
@@ -138,7 +182,7 @@ const activitiesContract = {
138
182
  targetType: TimelineTarget,
139
183
  targetId: Id
140
184
  })).output(Activity),
141
- react: oc.route({
185
+ react: base.route({
142
186
  method: "POST",
143
187
  path: "/activities/{id}/reactions",
144
188
  summary: "Add or take back a reaction (an emoji) on an entry"
@@ -146,7 +190,7 @@ const activitiesContract = {
146
190
  id: Id,
147
191
  emoji: z.string().trim().min(1).max(16)
148
192
  })).output(Activity),
149
- types: oc.route({
193
+ types: base.route({
150
194
  method: "GET",
151
195
  path: "/activities/types",
152
196
  summary: "Timeline entry types and plugin record timelines: core's and installed plugins'"
@@ -165,23 +209,35 @@ const activitiesContract = {
165
209
  permission: z.string().nullable()
166
210
  }))
167
211
  })),
168
- updateNote: oc.route({
212
+ editNote: base.route({
169
213
  method: "PATCH",
170
214
  path: "/activities/notes/{id}",
171
- 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"
172
216
  }).input(z.object({
173
217
  id: Id,
174
218
  body: NoteInput.shape.body.optional(),
175
219
  mentions: z.array(Id).max(50).optional(),
176
- fileIds: z.array(Id).max(20).optional(),
177
- 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()
178
229
  })).output(Activity),
179
- 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({
180
236
  method: "DELETE",
181
237
  path: "/activities/notes/{id}",
182
238
  summary: "Delete a note (its author, owners and admins)"
183
239
  }).input(z.object({ id: Id })).output(z.object({ ok: z.literal(true) })),
184
- create: oc.route({
240
+ create: base.route({
185
241
  method: "POST",
186
242
  path: "/activities",
187
243
  successStatus: 201,
@@ -190,7 +246,7 @@ const activitiesContract = {
190
246
  activity: Activity,
191
247
  created: z.boolean()
192
248
  })),
193
- update: oc.route({
249
+ update: base.route({
194
250
  method: "PATCH",
195
251
  path: "/activities/{id}",
196
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"
@@ -199,11 +255,11 @@ const activitiesContract = {
199
255
  summary: z.string().trim().min(1).max(500).optional(),
200
256
  data: z.record(z.string(), z.unknown()).optional(),
201
257
  link: AppLink.nullable().optional()
202
- })).output(Activity),
203
- 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({
204
260
  method: "DELETE",
205
261
  path: "/activities/{id}",
206
262
  summary: "Remove a plugin's own entry (by id or `key:<dedupeKey>`)"
207
263
  }).input(z.object({ id: z.string().min(1).max(260) })).output(z.object({ ok: z.literal(true) }))
208
264
  };
209
- 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 };