@erxes/core-contract 0.0.0-stage → 0.1.0-v2.0

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 (88) hide show
  1. package/dist/activities.d.ts +392 -0
  2. package/dist/activities.js +209 -0
  3. package/dist/audit.d.ts +295 -0
  4. package/dist/audit.js +204 -0
  5. package/dist/auth.d.ts +451 -0
  6. package/dist/auth.js +159 -0
  7. package/dist/automationDefinition.d.ts +244 -0
  8. package/dist/automationDefinition.js +180 -0
  9. package/dist/automationRuns.d.ts +128 -0
  10. package/dist/automationRuns.js +99 -0
  11. package/dist/automations.d.ts +1221 -0
  12. package/dist/automations.js +232 -0
  13. package/dist/common.d.ts +92 -0
  14. package/dist/common.js +76 -0
  15. package/dist/companies.d.ts +423 -0
  16. package/dist/companies.js +171 -0
  17. package/dist/customers.d.ts +499 -0
  18. package/dist/customers.js +221 -0
  19. package/dist/db/src/schema/auditStreams.js +53 -0
  20. package/dist/db/src/schema/authTokens.js +30 -0
  21. package/dist/db/src/schema/automations.js +141 -0
  22. package/dist/db/src/schema/common.d.ts +18 -0
  23. package/dist/db/src/schema/common.js +34 -0
  24. package/dist/db/src/schema/companies.js +128 -0
  25. package/dist/db/src/schema/customers.js +107 -0
  26. package/dist/db/src/schema/events.js +105 -0
  27. package/dist/db/src/schema/fieldValues.js +72 -0
  28. package/dist/db/src/schema/fields.js +103 -0
  29. package/dist/db/src/schema/index.js +26 -0
  30. package/dist/db/src/schema/jobs.js +44 -0
  31. package/dist/db/src/schema/leadStages.js +37 -0
  32. package/dist/db/src/schema/leads.js +59 -0
  33. package/dist/db/src/schema/oauth.js +49 -0
  34. package/dist/db/src/schema/organizations.js +24 -0
  35. package/dist/db/src/schema/payments.js +151 -0
  36. package/dist/db/src/schema/platform.js +209 -0
  37. package/dist/db/src/schema/plugins.js +59 -0
  38. package/dist/db/src/schema/products.js +94 -0
  39. package/dist/db/src/schema/saas.js +35 -0
  40. package/dist/db/src/schema/tags.js +65 -0
  41. package/dist/db/src/schema/transfer.js +122 -0
  42. package/dist/db/src/schema/trash.js +64 -0
  43. package/dist/db/src/schema/users.js +120 -0
  44. package/dist/db/src/schema/views.js +43 -0
  45. package/dist/db/src/schema/webhooks.js +81 -0
  46. package/dist/db/src/table.js +9 -0
  47. package/dist/events.d.ts +327 -0
  48. package/dist/events.js +143 -0
  49. package/dist/fields.d.ts +501 -0
  50. package/dist/fields.js +240 -0
  51. package/dist/files.d.ts +200 -0
  52. package/dist/files.js +103 -0
  53. package/dist/index.d.ts +6577 -0
  54. package/dist/index.js +62 -0
  55. package/dist/leads.d.ts +342 -0
  56. package/dist/leads.js +225 -0
  57. package/dist/money.d.ts +15 -0
  58. package/dist/money.js +21 -0
  59. package/dist/notifications.d.ts +281 -0
  60. package/dist/notifications.js +228 -0
  61. package/dist/organizations.d.ts +52 -0
  62. package/dist/organizations.js +48 -0
  63. package/dist/payments.d.ts +763 -0
  64. package/dist/payments.js +275 -0
  65. package/dist/platform.d.ts +32 -0
  66. package/dist/platform.js +34 -0
  67. package/dist/plugins.d.ts +355 -0
  68. package/dist/plugins.js +210 -0
  69. package/dist/products.d.ts +466 -0
  70. package/dist/products.js +202 -0
  71. package/dist/roles.d.ts +227 -0
  72. package/dist/roles.js +229 -0
  73. package/dist/saas.d.ts +167 -0
  74. package/dist/saas.js +90 -0
  75. package/dist/tags.d.ts +87 -0
  76. package/dist/tags.js +56 -0
  77. package/dist/transfer.d.ts +715 -0
  78. package/dist/transfer.js +211 -0
  79. package/dist/trash.d.ts +84 -0
  80. package/dist/trash.js +64 -0
  81. package/dist/users.d.ts +389 -0
  82. package/dist/users.js +174 -0
  83. package/dist/views.d.ts +254 -0
  84. package/dist/views.js +111 -0
  85. package/dist/webhooks.d.ts +381 -0
  86. package/dist/webhooks.js +284 -0
  87. package/package.json +64 -3
  88. package/README.md +0 -3
@@ -0,0 +1,392 @@
1
+ import { z } from "zod";
2
+ export declare const ActivityTarget: z.ZodEnum<{
3
+ company: "company";
4
+ customer: "customer";
5
+ }>;
6
+ export type ActivityTarget = z.infer<typeof ActivityTarget>;
7
+ /**
8
+ * What a timeline is about: a customer or company, or a plugin's own record
9
+ * type declared in its manifest (`hr.employee`, `ecom.order`).
10
+ */
11
+ export declare const TimelineTarget: z.ZodUnion<readonly [z.ZodEnum<{
12
+ company: "company";
13
+ customer: "customer";
14
+ }>, z.ZodString]>;
15
+ export type TimelineTarget = z.infer<typeof TimelineTarget>;
16
+ /**
17
+ * Activity types core records itself; `data` has a known shape for each.
18
+ * Plugin types (`ecom.order.paid`) carry a `summary` instead.
19
+ */
20
+ export declare const CORE_ACTIVITY_TYPES: readonly ['customer.created', 'customer.updated', 'customer.tagged', 'customer.merged', 'customer.company_linked', 'customer.company_unlinked', 'company.created', 'company.updated', 'company.tagged', 'company.merged', 'company.customer_linked', 'company.customer_unlinked'];
21
+ export declare const Activity: z.ZodObject<{
22
+ id: z.ZodString;
23
+ targetType: z.ZodString;
24
+ targetId: z.ZodString;
25
+ source: z.ZodString;
26
+ type: z.ZodString;
27
+ summary: z.ZodNullable<z.ZodString>;
28
+ data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
29
+ link: z.ZodNullable<z.ZodString>;
30
+ editedAt: z.ZodNullable<z.ZodISODateTime>;
31
+ occurredAt: z.ZodISODateTime;
32
+ entity: z.ZodNullable<z.ZodObject<{
33
+ type: z.ZodString;
34
+ id: z.ZodString;
35
+ }, z.core.$strip>>;
36
+ actor: z.ZodObject<{
37
+ type: z.ZodEnum<{
38
+ plugin: "plugin";
39
+ system: "system";
40
+ user: "user";
41
+ }>;
42
+ id: z.ZodNullable<z.ZodString>;
43
+ name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
44
+ avatarUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
45
+ }, z.core.$strip>;
46
+ pinned: z.ZodBoolean;
47
+ reactions: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>;
48
+ }, {
49
+ out: {};
50
+ in: {};
51
+ }>;
52
+ export type Activity = z.infer<typeof Activity>;
53
+ /** Notes are timeline entries of type `customer.note` / `company.note`; `data` = `{ body, mentions, fileIds }`. */
54
+ export declare const NoteInput: z.ZodObject<{
55
+ body: z.ZodString;
56
+ mentions: z.ZodDefault<z.ZodArray<z.ZodString>>;
57
+ fileIds: z.ZodDefault<z.ZodArray<z.ZodString>>;
58
+ }, z.core.$strip>;
59
+ /** Which entries a timeline shows. */
60
+ export declare const TimelineKind: z.ZodEnum<{
61
+ all: "all";
62
+ changes: "changes";
63
+ notes: "notes";
64
+ plugins: "plugins";
65
+ }>;
66
+ export declare const ActivityInput: z.ZodObject<{
67
+ targetType: z.ZodNonOptional<z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
68
+ company: "company";
69
+ customer: "customer";
70
+ }>, z.ZodString]>>>;
71
+ targetId: z.ZodNonOptional<z.ZodOptional<z.ZodString>>;
72
+ type: z.ZodNonOptional<z.ZodOptional<z.ZodString>>;
73
+ summary: z.ZodString;
74
+ data: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
75
+ link: z.ZodOptional<z.ZodString>;
76
+ dedupeKey: z.ZodOptional<z.ZodString>;
77
+ occurredAt: z.ZodOptional<z.ZodISODateTime>;
78
+ entity: z.ZodOptional<z.ZodObject<{
79
+ type: z.ZodString;
80
+ id: z.ZodString;
81
+ }, z.core.$strip>>;
82
+ actorUserId: z.ZodOptional<z.ZodString>;
83
+ }, {
84
+ out: {};
85
+ in: {};
86
+ }>;
87
+ export type ActivityInput = z.infer<typeof ActivityInput>;
88
+ /** The customer and company timeline, across core and plugins. */
89
+ export declare const activitiesContract: {
90
+ list: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
91
+ limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
92
+ cursor: z.ZodOptional<z.ZodString>;
93
+ direction: z.ZodDefault<z.ZodEnum<{
94
+ backward: "backward";
95
+ forward: "forward";
96
+ }>>;
97
+ cursorMode: z.ZodDefault<z.ZodEnum<{
98
+ exclusive: "exclusive";
99
+ inclusive: "inclusive";
100
+ }>>;
101
+ targetType: z.ZodUnion<readonly [z.ZodEnum<{
102
+ company: "company";
103
+ customer: "customer";
104
+ }>, z.ZodString]>;
105
+ targetId: z.ZodString;
106
+ source: z.ZodOptional<z.ZodString>;
107
+ q: z.ZodOptional<z.ZodString>;
108
+ actorId: z.ZodOptional<z.ZodString>;
109
+ from: z.ZodOptional<z.ZodISODateTime>;
110
+ to: z.ZodOptional<z.ZodISODateTime>;
111
+ kind: z.ZodDefault<z.ZodEnum<{
112
+ all: "all";
113
+ changes: "changes";
114
+ notes: "notes";
115
+ plugins: "plugins";
116
+ }>>;
117
+ pinned: z.ZodOptional<z.ZodPipe<z.ZodEnum<{
118
+ false: "false";
119
+ true: "true";
120
+ }>, z.ZodTransform<boolean, "false" | "true">>>;
121
+ includeRelated: z.ZodOptional<z.ZodPipe<z.ZodEnum<{
122
+ false: "false";
123
+ true: "true";
124
+ }>, z.ZodTransform<boolean, "false" | "true">>>;
125
+ }, z.core.$strip>, z.ZodObject<{
126
+ data: z.ZodArray<z.ZodObject<{
127
+ id: z.ZodString;
128
+ targetType: z.ZodString;
129
+ targetId: z.ZodString;
130
+ source: z.ZodString;
131
+ type: z.ZodString;
132
+ summary: z.ZodNullable<z.ZodString>;
133
+ data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
134
+ link: z.ZodNullable<z.ZodString>;
135
+ editedAt: z.ZodNullable<z.ZodISODateTime>;
136
+ occurredAt: z.ZodISODateTime;
137
+ entity: z.ZodNullable<z.ZodObject<{
138
+ type: z.ZodString;
139
+ id: z.ZodString;
140
+ }, z.core.$strip>>;
141
+ actor: z.ZodObject<{
142
+ type: z.ZodEnum<{
143
+ plugin: "plugin";
144
+ system: "system";
145
+ user: "user";
146
+ }>;
147
+ id: z.ZodNullable<z.ZodString>;
148
+ name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
149
+ avatarUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
150
+ }, z.core.$strip>;
151
+ pinned: z.ZodBoolean;
152
+ reactions: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>;
153
+ }, {
154
+ out: {};
155
+ in: {};
156
+ }>>;
157
+ pageInfo: z.ZodObject<{
158
+ hasNextPage: z.ZodBoolean;
159
+ hasPreviousPage: z.ZodBoolean;
160
+ startCursor: z.ZodNullable<z.ZodString>;
161
+ endCursor: z.ZodNullable<z.ZodString>;
162
+ }, z.core.$strip>;
163
+ totalCount: z.ZodInt;
164
+ totalCapped: z.ZodOptional<z.ZodBoolean>;
165
+ }, z.core.$strip>, Record<never, never>, Record<never, never>>;
166
+ addNote: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
167
+ body: z.ZodString;
168
+ mentions: z.ZodDefault<z.ZodArray<z.ZodString>>;
169
+ fileIds: z.ZodDefault<z.ZodArray<z.ZodString>>;
170
+ targetType: z.ZodUnion<readonly [z.ZodEnum<{
171
+ company: "company";
172
+ customer: "customer";
173
+ }>, z.ZodString]>;
174
+ targetId: z.ZodString;
175
+ }, z.core.$strip>, z.ZodObject<{
176
+ id: z.ZodString;
177
+ targetType: z.ZodString;
178
+ targetId: z.ZodString;
179
+ source: z.ZodString;
180
+ type: z.ZodString;
181
+ summary: z.ZodNullable<z.ZodString>;
182
+ data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
183
+ link: z.ZodNullable<z.ZodString>;
184
+ editedAt: z.ZodNullable<z.ZodISODateTime>;
185
+ occurredAt: z.ZodISODateTime;
186
+ entity: z.ZodNullable<z.ZodObject<{
187
+ type: z.ZodString;
188
+ id: z.ZodString;
189
+ }, z.core.$strip>>;
190
+ actor: z.ZodObject<{
191
+ type: z.ZodEnum<{
192
+ plugin: "plugin";
193
+ system: "system";
194
+ user: "user";
195
+ }>;
196
+ id: z.ZodNullable<z.ZodString>;
197
+ name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
198
+ avatarUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
199
+ }, z.core.$strip>;
200
+ pinned: z.ZodBoolean;
201
+ reactions: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>;
202
+ }, {
203
+ out: {};
204
+ in: {};
205
+ }>, Record<never, never>, Record<never, never>>;
206
+ react: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
207
+ id: z.ZodString;
208
+ emoji: z.ZodString;
209
+ }, z.core.$strip>, z.ZodObject<{
210
+ id: z.ZodString;
211
+ targetType: z.ZodString;
212
+ targetId: z.ZodString;
213
+ source: z.ZodString;
214
+ type: z.ZodString;
215
+ summary: z.ZodNullable<z.ZodString>;
216
+ data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
217
+ link: z.ZodNullable<z.ZodString>;
218
+ editedAt: z.ZodNullable<z.ZodISODateTime>;
219
+ occurredAt: z.ZodISODateTime;
220
+ entity: z.ZodNullable<z.ZodObject<{
221
+ type: z.ZodString;
222
+ id: z.ZodString;
223
+ }, z.core.$strip>>;
224
+ actor: z.ZodObject<{
225
+ type: z.ZodEnum<{
226
+ plugin: "plugin";
227
+ system: "system";
228
+ user: "user";
229
+ }>;
230
+ id: z.ZodNullable<z.ZodString>;
231
+ name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
232
+ avatarUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
233
+ }, z.core.$strip>;
234
+ pinned: z.ZodBoolean;
235
+ reactions: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>;
236
+ }, {
237
+ out: {};
238
+ in: {};
239
+ }>, Record<never, never>, Record<never, never>>;
240
+ types: import("@orpc/contract").ContractProcedureBuilderWithOutput<import("@orpc/contract").Schema<unknown, unknown>, z.ZodObject<{
241
+ types: z.ZodArray<z.ZodObject<{
242
+ type: z.ZodString;
243
+ label: z.ZodString;
244
+ source: z.ZodString;
245
+ icon: z.ZodNullable<z.ZodString>;
246
+ color: z.ZodNullable<z.ZodString>;
247
+ }, z.core.$strip>>;
248
+ timelines: z.ZodArray<z.ZodObject<{
249
+ type: z.ZodString;
250
+ label: z.ZodString;
251
+ source: z.ZodString;
252
+ permission: z.ZodNullable<z.ZodString>;
253
+ }, z.core.$strip>>;
254
+ }, z.core.$strip>, Record<never, never>, Record<never, never>>;
255
+ updateNote: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
256
+ id: z.ZodString;
257
+ body: z.ZodOptional<z.ZodString>;
258
+ mentions: z.ZodOptional<z.ZodArray<z.ZodString>>;
259
+ fileIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
260
+ pinned: z.ZodOptional<z.ZodBoolean>;
261
+ }, z.core.$strip>, z.ZodObject<{
262
+ id: z.ZodString;
263
+ targetType: z.ZodString;
264
+ targetId: z.ZodString;
265
+ source: z.ZodString;
266
+ type: z.ZodString;
267
+ summary: z.ZodNullable<z.ZodString>;
268
+ data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
269
+ link: z.ZodNullable<z.ZodString>;
270
+ editedAt: z.ZodNullable<z.ZodISODateTime>;
271
+ occurredAt: z.ZodISODateTime;
272
+ entity: z.ZodNullable<z.ZodObject<{
273
+ type: z.ZodString;
274
+ id: z.ZodString;
275
+ }, z.core.$strip>>;
276
+ actor: z.ZodObject<{
277
+ type: z.ZodEnum<{
278
+ plugin: "plugin";
279
+ system: "system";
280
+ user: "user";
281
+ }>;
282
+ id: z.ZodNullable<z.ZodString>;
283
+ name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
284
+ avatarUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
285
+ }, z.core.$strip>;
286
+ pinned: z.ZodBoolean;
287
+ reactions: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>;
288
+ }, {
289
+ out: {};
290
+ in: {};
291
+ }>, Record<never, never>, Record<never, never>>;
292
+ removeNote: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
293
+ id: z.ZodString;
294
+ }, z.core.$strip>, z.ZodObject<{
295
+ ok: z.ZodLiteral<true>;
296
+ }, z.core.$strip>, Record<never, never>, Record<never, never>>;
297
+ create: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
298
+ targetType: z.ZodNonOptional<z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
299
+ company: "company";
300
+ customer: "customer";
301
+ }>, z.ZodString]>>>;
302
+ targetId: z.ZodNonOptional<z.ZodOptional<z.ZodString>>;
303
+ type: z.ZodNonOptional<z.ZodOptional<z.ZodString>>;
304
+ summary: z.ZodString;
305
+ data: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
306
+ link: z.ZodOptional<z.ZodString>;
307
+ dedupeKey: z.ZodOptional<z.ZodString>;
308
+ occurredAt: z.ZodOptional<z.ZodISODateTime>;
309
+ entity: z.ZodOptional<z.ZodObject<{
310
+ type: z.ZodString;
311
+ id: z.ZodString;
312
+ }, z.core.$strip>>;
313
+ actorUserId: z.ZodOptional<z.ZodString>;
314
+ }, {
315
+ out: {};
316
+ in: {};
317
+ }>, z.ZodObject<{
318
+ activity: z.ZodObject<{
319
+ id: z.ZodString;
320
+ targetType: z.ZodString;
321
+ targetId: z.ZodString;
322
+ source: z.ZodString;
323
+ type: z.ZodString;
324
+ summary: z.ZodNullable<z.ZodString>;
325
+ data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
326
+ link: z.ZodNullable<z.ZodString>;
327
+ editedAt: z.ZodNullable<z.ZodISODateTime>;
328
+ occurredAt: z.ZodISODateTime;
329
+ entity: z.ZodNullable<z.ZodObject<{
330
+ type: z.ZodString;
331
+ id: z.ZodString;
332
+ }, z.core.$strip>>;
333
+ actor: z.ZodObject<{
334
+ type: z.ZodEnum<{
335
+ plugin: "plugin";
336
+ system: "system";
337
+ user: "user";
338
+ }>;
339
+ id: z.ZodNullable<z.ZodString>;
340
+ name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
341
+ avatarUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
342
+ }, z.core.$strip>;
343
+ pinned: z.ZodBoolean;
344
+ reactions: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>;
345
+ }, {
346
+ out: {};
347
+ in: {};
348
+ }>;
349
+ created: z.ZodBoolean;
350
+ }, z.core.$strip>, Record<never, never>, Record<never, never>>;
351
+ update: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
352
+ id: z.ZodString;
353
+ summary: z.ZodOptional<z.ZodString>;
354
+ data: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
355
+ link: z.ZodOptional<z.ZodNullable<z.ZodString>>;
356
+ }, z.core.$strip>, z.ZodObject<{
357
+ id: z.ZodString;
358
+ targetType: z.ZodString;
359
+ targetId: z.ZodString;
360
+ source: z.ZodString;
361
+ type: z.ZodString;
362
+ summary: z.ZodNullable<z.ZodString>;
363
+ data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
364
+ link: z.ZodNullable<z.ZodString>;
365
+ editedAt: z.ZodNullable<z.ZodISODateTime>;
366
+ occurredAt: z.ZodISODateTime;
367
+ entity: z.ZodNullable<z.ZodObject<{
368
+ type: z.ZodString;
369
+ id: z.ZodString;
370
+ }, z.core.$strip>>;
371
+ actor: z.ZodObject<{
372
+ type: z.ZodEnum<{
373
+ plugin: "plugin";
374
+ system: "system";
375
+ user: "user";
376
+ }>;
377
+ id: z.ZodNullable<z.ZodString>;
378
+ name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
379
+ avatarUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
380
+ }, z.core.$strip>;
381
+ pinned: z.ZodBoolean;
382
+ reactions: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>;
383
+ }, {
384
+ out: {};
385
+ in: {};
386
+ }>, Record<never, never>, Record<never, never>>;
387
+ remove: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
388
+ id: z.ZodString;
389
+ }, z.core.$strip>, z.ZodObject<{
390
+ ok: z.ZodLiteral<true>;
391
+ }, z.core.$strip>, Record<never, never>, Record<never, never>>;
392
+ };
@@ -0,0 +1,209 @@
1
+ import { activities } from "./db/src/schema/platform.js";
2
+ 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 { oc } from "@orpc/contract";
6
+ import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
7
+ import { z } from "zod";
8
+ // src/activities.ts
9
+ const ActivityTarget = z.enum(["customer", "company"]);
10
+ /**
11
+ * What a timeline is about: a customer or company, or a plugin's own record
12
+ * type declared in its manifest (`hr.employee`, `ecom.order`).
13
+ */
14
+ const TimelineTarget = z.union([ActivityTarget, z.string().regex(/^[a-z][a-z0-9_]*\.[a-z][a-z0-9_]*$/, "customer, company or <plugin>.<type>")]);
15
+ /**
16
+ * Activity types core records itself; `data` has a known shape for each.
17
+ * Plugin types (`ecom.order.paid`) carry a `summary` instead.
18
+ */
19
+ const CORE_ACTIVITY_TYPES = [
20
+ "customer.created",
21
+ "customer.updated",
22
+ "customer.tagged",
23
+ "customer.merged",
24
+ "customer.company_linked",
25
+ "customer.company_unlinked",
26
+ "company.created",
27
+ "company.updated",
28
+ "company.tagged",
29
+ "company.merged",
30
+ "company.customer_linked",
31
+ "company.customer_unlinked"
32
+ ];
33
+ const Activity = createSelectSchema(activities, {
34
+ id: Id,
35
+ targetId: Id,
36
+ data: z.record(z.string(), z.unknown()),
37
+ editedAt: isoDate,
38
+ occurredAt: isoDate
39
+ }).pick({
40
+ id: true,
41
+ targetType: true,
42
+ targetId: true,
43
+ /** `core` or the plugin that recorded it. */
44
+ source: true,
45
+ type: true,
46
+ summary: true,
47
+ /**
48
+ * Core types: `updated` → `{ changes: { field: [before, after] } }`;
49
+ * `tagged` → `{ added: ids, removed: ids }`; `merged` → `{ mergedIds }`;
50
+ * `*_linked` → `{ customerId | companyId }`.
51
+ */
52
+ data: true,
53
+ link: true,
54
+ editedAt: true,
55
+ occurredAt: true
56
+ }).extend({
57
+ entity: EntityRef.nullable(),
58
+ actor: ActorRef,
59
+ /** Notes only. */
60
+ pinned: z.boolean(),
61
+ /** Emoji → the members who reacted. */
62
+ reactions: z.record(z.string(), z.array(z.string()))
63
+ });
64
+ /** Notes are timeline entries of type `customer.note` / `company.note`; `data` = `{ body, mentions, fileIds }`. */
65
+ const NoteInput = z.object({
66
+ body: z.string().trim().min(1).max(1e4),
67
+ /** Team members mentioned with @: they are notified. */
68
+ mentions: z.array(Id).max(50).default([]),
69
+ /** Attached files (uploaded through `/files`). */
70
+ fileIds: z.array(Id).max(20).default([])
71
+ });
72
+ /** Which entries a timeline shows. */
73
+ const TimelineKind = z.enum([
74
+ "all",
75
+ "notes",
76
+ "changes",
77
+ "plugins"
78
+ ]);
79
+ const ActivityInput = createUpdateSchema(activities, {
80
+ targetType: () => TimelineTarget,
81
+ targetId: () => Id,
82
+ type: () => EventType,
83
+ summary: z.string().trim().min(1).max(500),
84
+ data: () => z.record(z.string(), z.unknown()),
85
+ link: AppLink.optional(),
86
+ occurredAt: () => z.iso.datetime(),
87
+ dedupeKey: DedupeKey.optional()
88
+ }).pick({
89
+ targetType: true,
90
+ targetId: true,
91
+ /** Must start with the plugin's name: `ecom.order.paid`. */
92
+ type: true,
93
+ /** The line shown on the timeline. */
94
+ summary: true,
95
+ data: true,
96
+ link: true,
97
+ /** When it happened (defaults to now). */
98
+ occurredAt: true,
99
+ /** Retry-safe: one entry per plugin and key. */
100
+ dedupeKey: true
101
+ }).required({
102
+ targetType: true,
103
+ targetId: true,
104
+ type: true
105
+ }).extend({
106
+ entity: EntityRef.optional(),
107
+ /** The team member who did it, if any. */
108
+ actorUserId: Id.optional()
109
+ });
110
+ /** The customer and company timeline, across core and plugins. */
111
+ const activitiesContract = {
112
+ list: oc.route({
113
+ method: "GET",
114
+ path: "/activities",
115
+ summary: "A customer’s or company’s timeline, newest first"
116
+ }).input(CursorQuery.extend({
117
+ targetType: TimelineTarget,
118
+ targetId: Id,
119
+ source: z.string().trim().max(40).optional(),
120
+ /** Text in notes and plugin lines. */
121
+ q: z.string().trim().max(100).optional(),
122
+ /** Done by this member. */
123
+ actorId: Id.optional(),
124
+ from: z.iso.datetime().optional(),
125
+ to: z.iso.datetime().optional(),
126
+ kind: TimelineKind.default("all"),
127
+ /** Pinned notes only. */
128
+ pinned: z.enum(["true", "false"]).transform((value) => value === "true").optional(),
129
+ /** A company's timeline with its customers' entries too. */
130
+ includeRelated: z.enum(["true", "false"]).transform((value) => value === "true").optional()
131
+ })).output(cursorPageOf(Activity)),
132
+ addNote: oc.route({
133
+ method: "POST",
134
+ path: "/activities/notes",
135
+ successStatus: 201,
136
+ summary: "Add a note to a timeline"
137
+ }).input(NoteInput.extend({
138
+ targetType: TimelineTarget,
139
+ targetId: Id
140
+ })).output(Activity),
141
+ react: oc.route({
142
+ method: "POST",
143
+ path: "/activities/{id}/reactions",
144
+ summary: "Add or take back a reaction (an emoji) on an entry"
145
+ }).input(z.object({
146
+ id: Id,
147
+ emoji: z.string().trim().min(1).max(16)
148
+ })).output(Activity),
149
+ types: oc.route({
150
+ method: "GET",
151
+ path: "/activities/types",
152
+ summary: "Timeline entry types and plugin record timelines: core's and installed plugins'"
153
+ }).output(z.object({
154
+ types: z.array(z.object({
155
+ type: z.string(),
156
+ label: z.string(),
157
+ source: z.string(),
158
+ icon: z.string().nullable(),
159
+ color: z.string().nullable()
160
+ })),
161
+ timelines: z.array(z.object({
162
+ type: z.string(),
163
+ label: z.string(),
164
+ source: z.string(),
165
+ permission: z.string().nullable()
166
+ }))
167
+ })),
168
+ updateNote: oc.route({
169
+ method: "PATCH",
170
+ path: "/activities/notes/{id}",
171
+ summary: "Edit a note (its author) or pin / unpin it (any member)"
172
+ }).input(z.object({
173
+ id: Id,
174
+ body: NoteInput.shape.body.optional(),
175
+ mentions: z.array(Id).max(50).optional(),
176
+ fileIds: z.array(Id).max(20).optional(),
177
+ pinned: z.boolean().optional()
178
+ })).output(Activity),
179
+ removeNote: oc.route({
180
+ method: "DELETE",
181
+ path: "/activities/notes/{id}",
182
+ summary: "Delete a note (its author, owners and admins)"
183
+ }).input(z.object({ id: Id })).output(z.object({ ok: z.literal(true) })),
184
+ create: oc.route({
185
+ method: "POST",
186
+ path: "/activities",
187
+ successStatus: 201,
188
+ summary: "Add to a customer’s or company’s timeline (plugins only). 404 when the record does not exist"
189
+ }).input(ActivityInput).output(z.object({
190
+ activity: Activity,
191
+ created: z.boolean()
192
+ })),
193
+ update: oc.route({
194
+ method: "PATCH",
195
+ path: "/activities/{id}",
196
+ 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"
197
+ }).input(z.object({
198
+ id: z.string().min(1).max(260),
199
+ summary: z.string().trim().min(1).max(500).optional(),
200
+ data: z.record(z.string(), z.unknown()).optional(),
201
+ link: AppLink.nullable().optional()
202
+ })).output(Activity),
203
+ remove: oc.route({
204
+ method: "DELETE",
205
+ path: "/activities/{id}",
206
+ summary: "Remove a plugin's own entry (by id or `key:<dedupeKey>`)"
207
+ }).input(z.object({ id: z.string().min(1).max(260) })).output(z.object({ ok: z.literal(true) }))
208
+ };
209
+ export { Activity, ActivityInput, ActivityTarget, CORE_ACTIVITY_TYPES, NoteInput, TimelineKind, TimelineTarget, activitiesContract };