@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.
- package/dist/activities.d.ts +1387 -139
- package/dist/activities.js +90 -30
- package/dist/audit.d.ts +1081 -33
- package/dist/audit.js +28 -14
- package/dist/auth.d.ts +2834 -26
- package/dist/auth.js +47 -18
- package/dist/automationRuns.d.ts +7 -9
- package/dist/automationRuns.js +12 -13
- package/dist/automations.d.ts +2443 -61
- package/dist/automations.js +41 -21
- package/dist/client.d.ts +30704 -0
- package/dist/client.js +62 -0
- package/dist/common.d.ts +0 -13
- package/dist/common.js +1 -13
- package/dist/companies.d.ts +1120 -10
- package/dist/companies.js +27 -12
- package/dist/contract/routes.json.js +17 -1
- package/dist/customerAuth.d.ts +1456 -17
- package/dist/customerAuth.js +33 -16
- package/dist/customers.d.ts +1232 -11
- package/dist/customers.js +28 -13
- package/dist/{automationDefinition.d.ts → db/src/automationDefinition.d.ts} +2 -2
- package/dist/{automationDefinition.js → db/src/automationDefinition.js} +2 -2
- package/dist/db/src/enums.js +1 -3
- package/dist/db/src/schema/automations.d.ts +1 -0
- package/dist/db/src/schema/automations.js +3 -3
- package/dist/db/src/schema/index.d.ts +3 -0
- package/dist/db/src/schema/index.js +3 -2
- package/dist/db/src/schema/leads.js +2 -2
- package/dist/db/src/schema/notes.js +92 -0
- package/dist/db/src/schema/payments.js +2 -2
- package/dist/db/src/schema/platform.js +0 -5
- package/dist/db/src/schema/plugins.js +7 -2
- package/dist/db/src/schema/transfer.js +2 -2
- package/dist/errors.d.ts +516 -0
- package/dist/errors.js +218 -0
- package/dist/events.d.ts +570 -121
- package/dist/events.js +41 -24
- package/dist/fields.d.ts +1456 -16
- package/dist/fields.js +27 -19
- package/dist/files.d.ts +761 -62
- package/dist/files.js +32 -21
- package/dist/index.d.ts +25187 -618
- package/dist/index.js +8 -7
- package/dist/leads.d.ts +1105 -21
- package/dist/leads.js +31 -13
- package/dist/notifications.d.ts +689 -48
- package/dist/notifications.js +38 -18
- package/dist/organizations.d.ts +260 -2
- package/dist/organizations.js +21 -2
- package/dist/payments.d.ts +1766 -62
- package/dist/payments.js +48 -26
- package/dist/platform.d.ts +12 -21
- package/dist/platform.js +7 -17
- package/dist/plugins.d.ts +802 -71
- package/dist/plugins.js +48 -27
- package/dist/products.d.ts +1380 -17
- package/dist/products.js +32 -16
- package/dist/roles.d.ts +560 -5
- package/dist/roles.js +20 -6
- package/dist/saas.d.ts +164 -2
- package/dist/saas.js +9 -2
- package/dist/tags.d.ts +340 -4
- package/dist/tags.js +14 -6
- package/dist/transfer.d.ts +1299 -12
- package/dist/transfer.js +32 -13
- package/dist/trash.d.ts +278 -21
- package/dist/trash.js +23 -16
- package/dist/users.d.ts +1206 -18
- package/dist/users.js +35 -13
- package/dist/values.d.ts +0 -9
- package/dist/values.js +2 -7
- package/dist/views.d.ts +396 -5
- package/dist/views.js +10 -7
- package/dist/webhooks.d.ts +765 -9
- package/dist/webhooks.js +18 -10
- package/package.json +6 -2
package/dist/events.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { EVENT_FAILURE_STATUSES, NOTIFICATION_PRIORITIES } from "./db/src/enums.js";
|
|
2
2
|
import { events } from "./db/src/schema/events.js";
|
|
3
3
|
import "./db/src/schema/index.js";
|
|
4
|
+
import { COMMON_ERRORS, ERRORS } from "./errors.js";
|
|
4
5
|
import { CursorQuery, Id, cursorPageOf, isoDate } from "./common.js";
|
|
5
6
|
import { ActivityTarget } from "./activities.js";
|
|
6
|
-
import {
|
|
7
|
+
import { AppLink, DedupeKey, EntityType, EventType } from "./platform.js";
|
|
7
8
|
import { oc } from "@orpc/contract";
|
|
8
|
-
import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
|
|
9
9
|
import { z } from "zod";
|
|
10
|
+
import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
|
|
10
11
|
// src/events.ts
|
|
11
12
|
/** What a published event asks core to notify (as `POST /notifications`). */
|
|
12
13
|
const EventNotify = z.object({
|
|
@@ -24,7 +25,11 @@ const EventInput = createUpdateSchema(events, {
|
|
|
24
25
|
link: AppLink.optional(),
|
|
25
26
|
notify: EventNotify.optional(),
|
|
26
27
|
occurredAt: () => z.iso.datetime(),
|
|
27
|
-
dedupeKey: DedupeKey.optional()
|
|
28
|
+
dedupeKey: DedupeKey.optional(),
|
|
29
|
+
subjectType: ActivityTarget.optional(),
|
|
30
|
+
subjectId: Id.optional(),
|
|
31
|
+
entityType: EntityType.optional(),
|
|
32
|
+
entityId: Id.optional()
|
|
28
33
|
}).pick({
|
|
29
34
|
/** Namespaced by the plugin: `hr.leave.approved`. */
|
|
30
35
|
type: true,
|
|
@@ -35,16 +40,14 @@ const EventInput = createUpdateSchema(events, {
|
|
|
35
40
|
notify: true,
|
|
36
41
|
occurredAt: true,
|
|
37
42
|
/** Retry-safe: one event per plugin and key. */
|
|
38
|
-
dedupeKey: true
|
|
39
|
-
}).required({ type: true }).extend({
|
|
43
|
+
dedupeKey: true,
|
|
40
44
|
/** The customer or company it concerns: with `summary`, it goes on their timeline. */
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
});
|
|
45
|
+
subjectType: true,
|
|
46
|
+
subjectId: true,
|
|
47
|
+
/** The plugin's own record it is about. */
|
|
48
|
+
entityType: true,
|
|
49
|
+
entityId: true
|
|
50
|
+
}).required({ type: true }).extend({ actorUserId: Id.optional() }).refine((value) => value.subjectType === void 0 === (value.subjectId === void 0), "subjectType and subjectId go together").refine((value) => value.entityType === void 0 === (value.entityId === void 0), "entityType and entityId go together");
|
|
48
51
|
const CoreEvent = createSelectSchema(events, {
|
|
49
52
|
id: Id,
|
|
50
53
|
version: () => z.int(),
|
|
@@ -56,18 +59,20 @@ const CoreEvent = createSelectSchema(events, {
|
|
|
56
59
|
source: true,
|
|
57
60
|
type: true,
|
|
58
61
|
version: true,
|
|
62
|
+
/** The customer or company it concerns. */
|
|
63
|
+
subjectType: true,
|
|
64
|
+
subjectId: true,
|
|
65
|
+
/** The plugin's own record it is about. */
|
|
66
|
+
entityType: true,
|
|
67
|
+
entityId: true,
|
|
68
|
+
/** A team member (`actorId` = user id), a plugin (its name) or `system`. */
|
|
69
|
+
actorType: true,
|
|
70
|
+
actorId: true,
|
|
59
71
|
payload: true,
|
|
60
72
|
summary: true,
|
|
61
73
|
link: true,
|
|
62
74
|
occurredAt: true,
|
|
63
75
|
createdAt: true
|
|
64
|
-
}).extend({
|
|
65
|
-
subject: z.object({
|
|
66
|
-
type: ActivityTarget,
|
|
67
|
-
id: Id
|
|
68
|
-
}).nullable(),
|
|
69
|
-
entity: EntityRef.nullable(),
|
|
70
|
-
actor: ActorRef
|
|
71
76
|
});
|
|
72
77
|
const EventFailureStatus = z.enum(EVENT_FAILURE_STATUSES);
|
|
73
78
|
/** An event a consumer (timeline, notifications, …) could not handle: its job in the consumer's queue. */
|
|
@@ -92,8 +97,20 @@ const FailureRef = z.object({
|
|
|
92
97
|
* `POST /events`. Core turns events into timeline entries and notifications;
|
|
93
98
|
* automations and webhooks will read the same stream.
|
|
94
99
|
*/
|
|
100
|
+
const { INVALID_ACTOR, INVALID_OWNER, INVALID_TYPE, LIMIT_EXCEEDED, NOTHING_TO_RETRY, NO_TIMELINE, SUBJECT_REQUIRED } = ERRORS;
|
|
101
|
+
/** What these procedures answer with besides the common errors. */
|
|
102
|
+
const base = oc.errors({
|
|
103
|
+
...COMMON_ERRORS,
|
|
104
|
+
INVALID_ACTOR,
|
|
105
|
+
INVALID_OWNER,
|
|
106
|
+
INVALID_TYPE,
|
|
107
|
+
LIMIT_EXCEEDED,
|
|
108
|
+
NOTHING_TO_RETRY,
|
|
109
|
+
NO_TIMELINE,
|
|
110
|
+
SUBJECT_REQUIRED
|
|
111
|
+
});
|
|
95
112
|
const eventsContract = {
|
|
96
|
-
publish:
|
|
113
|
+
publish: base.route({
|
|
97
114
|
method: "POST",
|
|
98
115
|
path: "/events",
|
|
99
116
|
successStatus: 201,
|
|
@@ -102,7 +119,7 @@ const eventsContract = {
|
|
|
102
119
|
published: z.int(),
|
|
103
120
|
duplicates: z.int()
|
|
104
121
|
})),
|
|
105
|
-
list:
|
|
122
|
+
list: base.route({
|
|
106
123
|
method: "GET",
|
|
107
124
|
path: "/events",
|
|
108
125
|
summary: "Recent events of the organisation (owners and admins)"
|
|
@@ -113,7 +130,7 @@ const eventsContract = {
|
|
|
113
130
|
subjectType: ActivityTarget.optional(),
|
|
114
131
|
subjectId: Id.optional()
|
|
115
132
|
})).output(cursorPageOf(CoreEvent)),
|
|
116
|
-
failures:
|
|
133
|
+
failures: base.route({
|
|
117
134
|
method: "GET",
|
|
118
135
|
path: "/events/failures",
|
|
119
136
|
summary: "Events that could not be handled: retrying with backoff, or dead after the last attempt (owners and admins)"
|
|
@@ -124,7 +141,7 @@ const eventsContract = {
|
|
|
124
141
|
dead: z.int()
|
|
125
142
|
})
|
|
126
143
|
})),
|
|
127
|
-
retryFailures:
|
|
144
|
+
retryFailures: base.route({
|
|
128
145
|
method: "POST",
|
|
129
146
|
path: "/events/failures/retry",
|
|
130
147
|
summary: "Try failed events again now (owners and admins)"
|
|
@@ -132,7 +149,7 @@ const eventsContract = {
|
|
|
132
149
|
failures: z.array(FailureRef).min(1).max(200).optional(),
|
|
133
150
|
allDead: z.boolean().optional()
|
|
134
151
|
})).output(z.object({ retried: z.int() })),
|
|
135
|
-
dismissFailures:
|
|
152
|
+
dismissFailures: base.route({
|
|
136
153
|
method: "POST",
|
|
137
154
|
path: "/events/failures/dismiss",
|
|
138
155
|
summary: "Give up on failed events (owners and admins)"
|