@erxes/core-contract 0.1.0-v2.8 → 0.1.0-v2.9
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 +154 -14
- package/dist/activities.js +20 -8
- package/dist/automationRuns.d.ts +38 -1
- package/dist/automationRuns.js +34 -3
- package/dist/automations.d.ts +3 -0
- package/dist/client.d.ts +501 -3
- package/dist/client.js +23 -1
- package/dist/contract/routes.json.js +8 -0
- package/dist/db/src/enums.js +2 -1
- package/dist/events.js +1 -1
- package/dist/index.d.ts +166 -3
- package/dist/index.js +4 -3
- package/dist/pluginJobs.d.ts +1 -0
- package/dist/pluginJobs.js +5 -0
- package/dist/plugins.d.ts +10 -0
- package/dist/plugins.js +7 -8
- package/dist/timelines.d.ts +36 -0
- package/dist/timelines.js +38 -0
- package/package.json +2 -1
package/dist/activities.d.ts
CHANGED
|
@@ -1,18 +1,4 @@
|
|
|
1
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
2
|
/**
|
|
17
3
|
* Activity types core records itself; `data` has a known shape for each.
|
|
18
4
|
* Plugin types (`ecom.order.paid`) carry a `summary` instead.
|
|
@@ -445,6 +431,160 @@ export declare const activitiesContract: {
|
|
|
445
431
|
status: number;
|
|
446
432
|
};
|
|
447
433
|
}>, Record<never, never>>;
|
|
434
|
+
importNote: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
|
|
435
|
+
targetType: z.ZodUnion<readonly [z.ZodEnum<{
|
|
436
|
+
company: "company";
|
|
437
|
+
customer: "customer";
|
|
438
|
+
}>, z.ZodString]>;
|
|
439
|
+
targetId: z.ZodString;
|
|
440
|
+
body: z.ZodString;
|
|
441
|
+
authorId: z.ZodString;
|
|
442
|
+
createdAt: z.ZodISODateTime;
|
|
443
|
+
dedupeKey: z.ZodString;
|
|
444
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
445
|
+
activity: z.ZodObject<{
|
|
446
|
+
id: z.ZodString;
|
|
447
|
+
targetType: z.ZodString;
|
|
448
|
+
targetId: z.ZodString;
|
|
449
|
+
source: z.ZodString;
|
|
450
|
+
type: z.ZodString;
|
|
451
|
+
summary: z.ZodNullable<z.ZodString>;
|
|
452
|
+
data: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
453
|
+
entityType: z.ZodNullable<z.ZodString>;
|
|
454
|
+
entityId: z.ZodNullable<z.ZodString>;
|
|
455
|
+
link: z.ZodNullable<z.ZodString>;
|
|
456
|
+
actorType: z.ZodEnum<{
|
|
457
|
+
customer: "customer";
|
|
458
|
+
plugin: "plugin";
|
|
459
|
+
system: "system";
|
|
460
|
+
user: "user";
|
|
461
|
+
}>;
|
|
462
|
+
actorId: z.ZodNullable<z.ZodString>;
|
|
463
|
+
occurredAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
|
|
464
|
+
actorName: z.ZodNullable<z.ZodString>;
|
|
465
|
+
actorAvatarUrl: z.ZodNullable<z.ZodString>;
|
|
466
|
+
note: z.ZodNullable<z.ZodObject<{
|
|
467
|
+
body: z.ZodString;
|
|
468
|
+
mentions: z.ZodArray<z.ZodString>;
|
|
469
|
+
fileIds: z.ZodArray<z.ZodString>;
|
|
470
|
+
pinnedAt: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
|
|
471
|
+
editedAt: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
|
|
472
|
+
}, {
|
|
473
|
+
out: {};
|
|
474
|
+
in: {};
|
|
475
|
+
}>>;
|
|
476
|
+
reactions: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>;
|
|
477
|
+
}, {
|
|
478
|
+
out: {};
|
|
479
|
+
in: {};
|
|
480
|
+
}>;
|
|
481
|
+
created: z.ZodBoolean;
|
|
482
|
+
}, z.core.$strip>, import("@orpc/contract").MergedErrorMap<Record<never, never>, {
|
|
483
|
+
UNAUTHORIZED: {
|
|
484
|
+
status: number;
|
|
485
|
+
};
|
|
486
|
+
NOT_ALLOWED: {
|
|
487
|
+
status: number;
|
|
488
|
+
data: z.ZodOptional<z.ZodObject<{
|
|
489
|
+
permission: z.ZodString;
|
|
490
|
+
}, z.core.$strip>>;
|
|
491
|
+
};
|
|
492
|
+
PLUGIN_ONLY: {
|
|
493
|
+
status: number;
|
|
494
|
+
};
|
|
495
|
+
MEMBERS_ONLY: {
|
|
496
|
+
status: number;
|
|
497
|
+
};
|
|
498
|
+
ORG_REQUIRED: {
|
|
499
|
+
status: number;
|
|
500
|
+
};
|
|
501
|
+
SCOPE_REQUIRED: {
|
|
502
|
+
status: number;
|
|
503
|
+
};
|
|
504
|
+
SERVICE_TOKEN_REQUIRED: {
|
|
505
|
+
status: number;
|
|
506
|
+
};
|
|
507
|
+
ORGANIZATION_DISABLED: {
|
|
508
|
+
status: number;
|
|
509
|
+
data: z.ZodObject<{
|
|
510
|
+
manageUrl: z.ZodNullable<z.ZodString>;
|
|
511
|
+
}, z.core.$strip>;
|
|
512
|
+
};
|
|
513
|
+
NOT_IN_PLAN: {
|
|
514
|
+
status: number;
|
|
515
|
+
data: z.ZodOptional<z.ZodObject<{
|
|
516
|
+
manageUrl: z.ZodNullable<z.ZodString>;
|
|
517
|
+
}, z.core.$strip>>;
|
|
518
|
+
};
|
|
519
|
+
READ_ONLY: {
|
|
520
|
+
status: number;
|
|
521
|
+
};
|
|
522
|
+
TOO_MANY_REQUESTS: {
|
|
523
|
+
status: number;
|
|
524
|
+
};
|
|
525
|
+
INVALID_INPUT: {
|
|
526
|
+
status: number;
|
|
527
|
+
data: z.ZodObject<{
|
|
528
|
+
issues: z.ZodArray<z.ZodObject<{
|
|
529
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodInt]>>;
|
|
530
|
+
message: z.ZodString;
|
|
531
|
+
}, z.core.$strip>>;
|
|
532
|
+
}, z.core.$strip>;
|
|
533
|
+
};
|
|
534
|
+
NOT_FOUND: {
|
|
535
|
+
status: number;
|
|
536
|
+
};
|
|
537
|
+
TAKEN: {
|
|
538
|
+
status: number;
|
|
539
|
+
data: z.ZodObject<{
|
|
540
|
+
field: z.ZodString;
|
|
541
|
+
id: z.ZodOptional<z.ZodString>;
|
|
542
|
+
values: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
543
|
+
}, z.core.$strip>;
|
|
544
|
+
};
|
|
545
|
+
INVALID_CURSOR: {
|
|
546
|
+
status: number;
|
|
547
|
+
};
|
|
548
|
+
INVALID_REFERENCE: {
|
|
549
|
+
status: number;
|
|
550
|
+
data: z.ZodObject<{
|
|
551
|
+
field: z.ZodString;
|
|
552
|
+
}, z.core.$strip>;
|
|
553
|
+
};
|
|
554
|
+
INVALID_FILTER: {
|
|
555
|
+
status: number;
|
|
556
|
+
};
|
|
557
|
+
FILTER_TOO_SLOW: {
|
|
558
|
+
status: number;
|
|
559
|
+
};
|
|
560
|
+
INVALID_ACTOR: {
|
|
561
|
+
status: number;
|
|
562
|
+
};
|
|
563
|
+
INVALID_FILE: {
|
|
564
|
+
status: number;
|
|
565
|
+
};
|
|
566
|
+
INVALID_OWNER: {
|
|
567
|
+
status: number;
|
|
568
|
+
};
|
|
569
|
+
INVALID_RECIPIENT: {
|
|
570
|
+
status: number;
|
|
571
|
+
};
|
|
572
|
+
INVALID_TYPE: {
|
|
573
|
+
status: number;
|
|
574
|
+
};
|
|
575
|
+
MASS_DELETE_STOPPED: {
|
|
576
|
+
status: number;
|
|
577
|
+
};
|
|
578
|
+
NOT_AUTHOR: {
|
|
579
|
+
status: number;
|
|
580
|
+
};
|
|
581
|
+
NO_TIMELINE: {
|
|
582
|
+
status: number;
|
|
583
|
+
};
|
|
584
|
+
TOO_MANY_REACTIONS: {
|
|
585
|
+
status: number;
|
|
586
|
+
};
|
|
587
|
+
}>, Record<never, never>>;
|
|
448
588
|
react: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
|
|
449
589
|
id: z.ZodString;
|
|
450
590
|
emoji: z.ZodString;
|
package/dist/activities.js
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TIMELINE_KINDS } from "./db/src/enums.js";
|
|
2
2
|
import { activities } from "./db/src/schema/platform.js";
|
|
3
3
|
import { noteVersions, notes } from "./db/src/schema/notes.js";
|
|
4
4
|
import "./db/src/schema/index.js";
|
|
5
5
|
import { COMMON_ERRORS, ERRORS } from "./errors.js";
|
|
6
6
|
import { CursorQuery, Id, QueryFlag, cursorPageOf, isoDate } from "./common.js";
|
|
7
7
|
import { AppLink, DedupeKey, EntityType, EventType } from "./platform.js";
|
|
8
|
+
import { TimelineTarget } from "./timelines.js";
|
|
8
9
|
import { oc } from "@orpc/contract";
|
|
9
10
|
import { z } from "zod";
|
|
10
11
|
import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
|
|
11
12
|
// src/activities.ts
|
|
12
|
-
const ActivityTarget = z.enum(ACTIVITY_TARGETS);
|
|
13
|
-
/**
|
|
14
|
-
* What a timeline is about: a customer or company, or a plugin's own record
|
|
15
|
-
* type declared in its manifest (`hr.employee`, `ecom.order`).
|
|
16
|
-
*/
|
|
17
|
-
const TimelineTarget = z.union([ActivityTarget, z.string().regex(/^[a-z][a-z0-9_]*\.[a-z][a-z0-9_]*$/, "customer, company or <plugin>.<type>")]);
|
|
18
13
|
/**
|
|
19
14
|
* Activity types core records itself; `data` has a known shape for each.
|
|
20
15
|
* Plugin types (`ecom.order.paid`) carry a `summary` instead.
|
|
@@ -182,6 +177,23 @@ const activitiesContract = {
|
|
|
182
177
|
targetType: TimelineTarget,
|
|
183
178
|
targetId: Id
|
|
184
179
|
})).output(Activity),
|
|
180
|
+
importNote: base.route({
|
|
181
|
+
method: "POST",
|
|
182
|
+
path: "/activities/notes/import",
|
|
183
|
+
successStatus: 201,
|
|
184
|
+
summary: "Bring a note over from old erxes, with its author and time (plugins only). Nobody is notified; a retried `dedupeKey` returns the note made the first time"
|
|
185
|
+
}).input(z.object({
|
|
186
|
+
targetType: TimelineTarget,
|
|
187
|
+
targetId: Id,
|
|
188
|
+
body: NoteInput.shape.body,
|
|
189
|
+
/** The team member who wrote it. */
|
|
190
|
+
authorId: Id,
|
|
191
|
+
createdAt: z.iso.datetime(),
|
|
192
|
+
dedupeKey: DedupeKey
|
|
193
|
+
})).output(z.object({
|
|
194
|
+
activity: Activity,
|
|
195
|
+
created: z.boolean()
|
|
196
|
+
})),
|
|
185
197
|
react: base.route({
|
|
186
198
|
method: "POST",
|
|
187
199
|
path: "/activities/{id}/reactions",
|
|
@@ -262,4 +274,4 @@ const activitiesContract = {
|
|
|
262
274
|
summary: "Remove a plugin's own entry (by id or `key:<dedupeKey>`)"
|
|
263
275
|
}).input(z.object({ id: z.string().min(1).max(260) })).output(z.object({ ok: z.literal(true) }))
|
|
264
276
|
};
|
|
265
|
-
export { Activity, ActivityInput,
|
|
277
|
+
export { Activity, ActivityInput, CORE_ACTIVITY_TYPES, Note, NoteInput, NoteVersion, TimelineKind, activitiesContract };
|
package/dist/automationRuns.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ import { z } from "zod";
|
|
|
2
2
|
/**
|
|
3
3
|
* One input of an action. Besides plain values: `custom_field` (one of the
|
|
4
4
|
* subject's custom fields, by id), `lead_stage` (a lead stage, by id),
|
|
5
|
-
* `recipients` (`subject` = the record's own email, or addresses)
|
|
5
|
+
* `recipients` (`subject` = the record's own email, or addresses),
|
|
6
|
+
* `plugin_record` (one of the plugin's own records of `recordType`, by id).
|
|
6
7
|
*/
|
|
7
8
|
export declare const ActionField: z.ZodObject<{
|
|
8
9
|
key: z.ZodString;
|
|
@@ -16,6 +17,7 @@ export declare const ActionField: z.ZodObject<{
|
|
|
16
17
|
longtext: "longtext";
|
|
17
18
|
members: "members";
|
|
18
19
|
number: "number";
|
|
20
|
+
plugin_record: "plugin_record";
|
|
19
21
|
recipients: "recipients";
|
|
20
22
|
select: "select";
|
|
21
23
|
tags: "tags";
|
|
@@ -29,8 +31,40 @@ export declare const ActionField: z.ZodObject<{
|
|
|
29
31
|
description: z.ZodOptional<z.ZodString>;
|
|
30
32
|
placeholder: z.ZodOptional<z.ZodString>;
|
|
31
33
|
sameTypeAs: z.ZodOptional<z.ZodString>;
|
|
34
|
+
recordType: z.ZodOptional<z.ZodString>;
|
|
35
|
+
dependsOn: z.ZodOptional<z.ZodString>;
|
|
32
36
|
}, z.core.$strip>;
|
|
33
37
|
export type ActionField = z.infer<typeof ActionField>;
|
|
38
|
+
/** A plugin action's inputs: each `dependsOn` names another of them, with no circle. */
|
|
39
|
+
export declare const ActionFields: z.ZodArray<z.ZodObject<{
|
|
40
|
+
key: z.ZodString;
|
|
41
|
+
label: z.ZodString;
|
|
42
|
+
type: z.ZodEnum<{
|
|
43
|
+
boolean: "boolean";
|
|
44
|
+
custom_field: "custom_field";
|
|
45
|
+
date: "date";
|
|
46
|
+
json: "json";
|
|
47
|
+
lead_stage: "lead_stage";
|
|
48
|
+
longtext: "longtext";
|
|
49
|
+
members: "members";
|
|
50
|
+
number: "number";
|
|
51
|
+
plugin_record: "plugin_record";
|
|
52
|
+
recipients: "recipients";
|
|
53
|
+
select: "select";
|
|
54
|
+
tags: "tags";
|
|
55
|
+
text: "text";
|
|
56
|
+
}>;
|
|
57
|
+
required: z.ZodDefault<z.ZodBoolean>;
|
|
58
|
+
options: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
59
|
+
value: z.ZodString;
|
|
60
|
+
label: z.ZodString;
|
|
61
|
+
}, z.core.$strip>>>;
|
|
62
|
+
description: z.ZodOptional<z.ZodString>;
|
|
63
|
+
placeholder: z.ZodOptional<z.ZodString>;
|
|
64
|
+
sameTypeAs: z.ZodOptional<z.ZodString>;
|
|
65
|
+
recordType: z.ZodOptional<z.ZodString>;
|
|
66
|
+
dependsOn: z.ZodOptional<z.ZodString>;
|
|
67
|
+
}, z.core.$strip>>;
|
|
34
68
|
export declare const ActionInfo: z.ZodObject<{
|
|
35
69
|
type: z.ZodString;
|
|
36
70
|
label: z.ZodString;
|
|
@@ -53,6 +87,7 @@ export declare const ActionInfo: z.ZodObject<{
|
|
|
53
87
|
longtext: "longtext";
|
|
54
88
|
members: "members";
|
|
55
89
|
number: "number";
|
|
90
|
+
plugin_record: "plugin_record";
|
|
56
91
|
recipients: "recipients";
|
|
57
92
|
select: "select";
|
|
58
93
|
tags: "tags";
|
|
@@ -66,6 +101,8 @@ export declare const ActionInfo: z.ZodObject<{
|
|
|
66
101
|
description: z.ZodOptional<z.ZodString>;
|
|
67
102
|
placeholder: z.ZodOptional<z.ZodString>;
|
|
68
103
|
sameTypeAs: z.ZodOptional<z.ZodString>;
|
|
104
|
+
recordType: z.ZodOptional<z.ZodString>;
|
|
105
|
+
dependsOn: z.ZodOptional<z.ZodString>;
|
|
69
106
|
}, z.core.$strip>>;
|
|
70
107
|
}, z.core.$strip>;
|
|
71
108
|
export type ActionInfo = z.infer<typeof ActionInfo>;
|
package/dist/automationRuns.js
CHANGED
|
@@ -8,7 +8,8 @@ import { createSelectSchema } from "drizzle-zod";
|
|
|
8
8
|
/**
|
|
9
9
|
* One input of an action. Besides plain values: `custom_field` (one of the
|
|
10
10
|
* subject's custom fields, by id), `lead_stage` (a lead stage, by id),
|
|
11
|
-
* `recipients` (`subject` = the record's own email, or addresses)
|
|
11
|
+
* `recipients` (`subject` = the record's own email, or addresses),
|
|
12
|
+
* `plugin_record` (one of the plugin's own records of `recordType`, by id).
|
|
12
13
|
*/
|
|
13
14
|
const ActionField = z.object({
|
|
14
15
|
key: z.string(),
|
|
@@ -22,8 +23,38 @@ const ActionField = z.object({
|
|
|
22
23
|
description: z.string().optional(),
|
|
23
24
|
placeholder: z.string().optional(),
|
|
24
25
|
/** The key of a `custom_field` input: this value takes that field's type (a date, a choice …). */
|
|
25
|
-
sameTypeAs: z.string().optional()
|
|
26
|
+
sameTypeAs: z.string().optional(),
|
|
27
|
+
/**
|
|
28
|
+
* A `plugin_record` input's records (`pipeline`): web lists them from
|
|
29
|
+
* `GET <api.url>/automations/records/<recordType>`, which answers `[{ value, label }]`.
|
|
30
|
+
*/
|
|
31
|
+
recordType: z.string().regex(/^[a-z][a-z0-9_-]{0,59}$/, "lower case letters, digits, _ and -").optional(),
|
|
32
|
+
/**
|
|
33
|
+
* The key of another input of the action: the records follow its value
|
|
34
|
+
* (`?parent=<value>`), and changing it clears this one.
|
|
35
|
+
*/
|
|
36
|
+
dependsOn: z.string().optional()
|
|
37
|
+
}).refine((field) => field.type === "plugin_record" === (field.recordType !== void 0), {
|
|
38
|
+
message: "a plugin_record input names its recordType, and no other input does",
|
|
39
|
+
path: ["recordType"]
|
|
40
|
+
}).refine((field) => field.dependsOn === void 0 || field.type === "plugin_record", {
|
|
41
|
+
message: "only a plugin_record input depends on another",
|
|
42
|
+
path: ["dependsOn"]
|
|
26
43
|
});
|
|
44
|
+
/** Whether following `dependsOn` from some input comes back to a key it passed. */
|
|
45
|
+
const dependsInCircle = (fields) => {
|
|
46
|
+
const parentOf = new Map(fields.map((field) => [field.key, field.dependsOn]));
|
|
47
|
+
return fields.some((field) => {
|
|
48
|
+
const seen = /* @__PURE__ */ new Set([field.key]);
|
|
49
|
+
for (let key = field.dependsOn; key !== void 0; key = parentOf.get(key)) {
|
|
50
|
+
if (seen.has(key)) return true;
|
|
51
|
+
seen.add(key);
|
|
52
|
+
}
|
|
53
|
+
return false;
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
/** A plugin action's inputs: each `dependsOn` names another of them, with no circle. */
|
|
57
|
+
const ActionFields = z.array(ActionField).max(50).refine((fields) => fields.every((field) => field.dependsOn === void 0 || field.dependsOn !== field.key && fields.some((other) => other.key === field.dependsOn)), "dependsOn names another input of the same action").refine((fields) => !dependsInCircle(fields), "dependsOn inputs depend on each other in a circle");
|
|
27
58
|
const ActionInfo = z.object({
|
|
28
59
|
type: z.string(),
|
|
29
60
|
label: z.string(),
|
|
@@ -81,4 +112,4 @@ const RunStep = createSelectSchema(automationRunSteps, {
|
|
|
81
112
|
startedAt: true,
|
|
82
113
|
finishedAt: true
|
|
83
114
|
});
|
|
84
|
-
export { ActionField, ActionInfo, AutomationRun, RunStatus, RunStep };
|
|
115
|
+
export { ActionField, ActionFields, ActionInfo, AutomationRun, RunStatus, RunStep };
|
package/dist/automations.d.ts
CHANGED
|
@@ -140,6 +140,7 @@ export declare const automationsContract: {
|
|
|
140
140
|
longtext: "longtext";
|
|
141
141
|
members: "members";
|
|
142
142
|
number: "number";
|
|
143
|
+
plugin_record: "plugin_record";
|
|
143
144
|
recipients: "recipients";
|
|
144
145
|
select: "select";
|
|
145
146
|
tags: "tags";
|
|
@@ -153,6 +154,8 @@ export declare const automationsContract: {
|
|
|
153
154
|
description: z.ZodOptional<z.ZodString>;
|
|
154
155
|
placeholder: z.ZodOptional<z.ZodString>;
|
|
155
156
|
sameTypeAs: z.ZodOptional<z.ZodString>;
|
|
157
|
+
recordType: z.ZodOptional<z.ZodString>;
|
|
158
|
+
dependsOn: z.ZodOptional<z.ZodString>;
|
|
156
159
|
}, z.core.$strip>>;
|
|
157
160
|
}, z.core.$strip>>;
|
|
158
161
|
}, z.core.$strip>, import("@orpc/contract").MergedErrorMap<Record<never, never>, {
|