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