@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.
- package/dist/activities.d.ts +1394 -139
- package/dist/activities.js +96 -40
- package/dist/audit.d.ts +1092 -48
- package/dist/audit.js +37 -23
- package/dist/auth.d.ts +2867 -61
- package/dist/auth.js +55 -25
- package/dist/automationRuns.d.ts +12 -13
- package/dist/automationRuns.js +15 -30
- package/dist/automations.d.ts +2474 -93
- package/dist/automations.js +56 -44
- package/dist/client.d.ts +30704 -0
- package/dist/client.js +62 -0
- package/dist/common.d.ts +28 -16
- package/dist/common.js +30 -22
- package/dist/companies.d.ts +1154 -44
- package/dist/companies.js +33 -17
- package/dist/contract/routes.json.js +1810 -0
- package/dist/customerAuth.d.ts +1661 -0
- package/dist/customerAuth.js +197 -0
- package/dist/customers.d.ts +1283 -65
- package/dist/customers.js +35 -25
- package/dist/{automationDefinition.d.ts → db/src/automationDefinition.d.ts} +4 -3
- package/dist/{automationDefinition.js → db/src/automationDefinition.js} +10 -32
- package/dist/db/src/enums.d.ts +8 -0
- package/dist/db/src/enums.js +334 -0
- package/dist/db/src/schema/auditStreams.js +6 -14
- package/dist/db/src/schema/authTokens.js +4 -6
- package/dist/db/src/schema/automations.d.ts +1 -0
- package/dist/db/src/schema/automations.js +15 -31
- package/dist/db/src/schema/common.d.ts +2 -6
- package/dist/db/src/schema/common.js +1 -24
- package/dist/db/src/schema/companies.js +6 -5
- package/dist/db/src/schema/customerAuth.js +101 -0
- package/dist/db/src/schema/customers.js +6 -6
- package/dist/db/src/schema/events.js +12 -60
- package/dist/db/src/schema/fieldValues.js +2 -2
- package/dist/db/src/schema/fields.js +10 -28
- package/dist/db/src/schema/index.d.ts +3 -0
- package/dist/db/src/schema/index.js +22 -20
- package/dist/db/src/schema/leadStages.js +5 -10
- package/dist/db/src/schema/leads.js +6 -11
- package/dist/db/src/schema/notes.js +92 -0
- package/dist/db/src/schema/oauth.js +3 -3
- package/dist/db/src/schema/payments.js +13 -23
- package/dist/db/src/schema/platform.js +11 -31
- package/dist/db/src/schema/plugins.js +10 -5
- package/dist/db/src/schema/products.js +7 -8
- package/dist/db/src/schema/rateLimits.js +7 -0
- package/dist/db/src/schema/saas.js +3 -9
- package/dist/db/src/schema/tags.js +6 -5
- package/dist/db/src/schema/transfer.js +13 -33
- package/dist/db/src/schema/trash.js +6 -7
- package/dist/db/src/schema/users.js +6 -10
- package/dist/db/src/schema/views.js +5 -13
- package/dist/db/src/schema/webhooks.js +7 -14
- package/dist/db/src/table.js +16 -2
- package/dist/errors.d.ts +516 -0
- package/dist/errors.js +218 -0
- package/dist/events.d.ts +585 -140
- package/dist/events.js +57 -42
- package/dist/fields.d.ts +1478 -66
- package/dist/fields.js +33 -47
- package/dist/files.d.ts +766 -62
- package/dist/files.js +34 -22
- package/dist/index.d.ts +25707 -902
- package/dist/index.js +22 -20
- package/dist/leads.d.ts +1108 -22
- package/dist/leads.js +39 -20
- package/dist/notifications.d.ts +691 -94
- package/dist/notifications.js +45 -91
- package/dist/organizations.d.ts +263 -5
- package/dist/organizations.js +21 -2
- package/dist/payments.d.ts +1794 -120
- package/dist/payments.js +58 -60
- package/dist/platform.d.ts +12 -20
- package/dist/platform.js +8 -21
- package/dist/plugins.d.ts +808 -71
- package/dist/plugins.js +66 -35
- package/dist/products.d.ts +1411 -53
- package/dist/products.js +40 -23
- package/dist/roles.d.ts +560 -8
- package/dist/roles.js +25 -11
- package/dist/routes.d.ts +8 -0
- package/dist/routes.js +13 -0
- package/dist/saas.d.ts +164 -8
- package/dist/saas.js +14 -29
- package/dist/tags.d.ts +344 -8
- package/dist/tags.js +16 -8
- package/dist/transfer.d.ts +1361 -36
- package/dist/transfer.js +47 -49
- package/dist/trash.d.ts +299 -23
- package/dist/trash.js +27 -20
- package/dist/users.d.ts +1233 -59
- package/dist/users.js +48 -39
- package/dist/values.d.ts +150 -0
- package/dist/values.js +139 -0
- package/dist/views.d.ts +404 -13
- package/dist/views.js +18 -28
- package/dist/webhooks.d.ts +791 -29
- package/dist/webhooks.js +36 -21
- package/package.json +9 -2
- package/dist/db/src/schema/jobs.js +0 -44
package/dist/events.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { EVENT_FAILURE_STATUSES,
|
|
1
|
+
import { EVENT_FAILURE_STATUSES, NOTIFICATION_PRIORITIES } from "./db/src/enums.js";
|
|
2
|
+
import { events } from "./db/src/schema/events.js";
|
|
2
3
|
import "./db/src/schema/index.js";
|
|
4
|
+
import { COMMON_ERRORS, ERRORS } from "./errors.js";
|
|
3
5
|
import { CursorQuery, Id, cursorPageOf, isoDate } from "./common.js";
|
|
4
6
|
import { ActivityTarget } from "./activities.js";
|
|
5
|
-
import {
|
|
7
|
+
import { AppLink, DedupeKey, EntityType, EventType } from "./platform.js";
|
|
6
8
|
import { oc } from "@orpc/contract";
|
|
7
|
-
import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
|
|
8
9
|
import { z } from "zod";
|
|
10
|
+
import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
|
|
9
11
|
// src/events.ts
|
|
10
12
|
/** What a published event asks core to notify (as `POST /notifications`). */
|
|
11
13
|
const EventNotify = z.object({
|
|
@@ -13,7 +15,7 @@ const EventNotify = z.object({
|
|
|
13
15
|
title: z.string().trim().min(1).max(200),
|
|
14
16
|
body: z.string().trim().max(2e3).optional(),
|
|
15
17
|
link: AppLink.optional(),
|
|
16
|
-
priority: z.enum(
|
|
18
|
+
priority: z.enum(NOTIFICATION_PRIORITIES).optional()
|
|
17
19
|
});
|
|
18
20
|
const EventInput = createUpdateSchema(events, {
|
|
19
21
|
type: () => EventType,
|
|
@@ -23,7 +25,11 @@ const EventInput = createUpdateSchema(events, {
|
|
|
23
25
|
link: AppLink.optional(),
|
|
24
26
|
notify: EventNotify.optional(),
|
|
25
27
|
occurredAt: () => z.iso.datetime(),
|
|
26
|
-
dedupeKey: DedupeKey.optional()
|
|
28
|
+
dedupeKey: DedupeKey.optional(),
|
|
29
|
+
subjectType: ActivityTarget.optional(),
|
|
30
|
+
subjectId: Id.optional(),
|
|
31
|
+
entityType: EntityType.optional(),
|
|
32
|
+
entityId: Id.optional()
|
|
27
33
|
}).pick({
|
|
28
34
|
/** Namespaced by the plugin: `hr.leave.approved`. */
|
|
29
35
|
type: true,
|
|
@@ -34,16 +40,14 @@ const EventInput = createUpdateSchema(events, {
|
|
|
34
40
|
notify: true,
|
|
35
41
|
occurredAt: true,
|
|
36
42
|
/** Retry-safe: one event per plugin and key. */
|
|
37
|
-
dedupeKey: true
|
|
38
|
-
}).required({ type: true }).extend({
|
|
43
|
+
dedupeKey: true,
|
|
39
44
|
/** The customer or company it concerns: with `summary`, it goes on their timeline. */
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
});
|
|
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");
|
|
47
51
|
const CoreEvent = createSelectSchema(events, {
|
|
48
52
|
id: Id,
|
|
49
53
|
version: () => z.int(),
|
|
@@ -55,35 +59,34 @@ const CoreEvent = createSelectSchema(events, {
|
|
|
55
59
|
source: true,
|
|
56
60
|
type: true,
|
|
57
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,
|
|
58
71
|
payload: true,
|
|
59
72
|
summary: true,
|
|
60
73
|
link: true,
|
|
61
74
|
occurredAt: true,
|
|
62
75
|
createdAt: true
|
|
63
|
-
}).extend({
|
|
64
|
-
subject: z.object({
|
|
65
|
-
type: ActivityTarget,
|
|
66
|
-
id: Id
|
|
67
|
-
}).nullable(),
|
|
68
|
-
entity: EntityRef.nullable(),
|
|
69
|
-
actor: ActorRef
|
|
70
76
|
});
|
|
71
77
|
const EventFailureStatus = z.enum(EVENT_FAILURE_STATUSES);
|
|
72
|
-
/** An event a consumer (timeline, notifications, …) could not handle. */
|
|
73
|
-
const EventFailure =
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
firstFailedAt: true,
|
|
85
|
-
updatedAt: true
|
|
86
|
-
}).extend({ event: CoreEvent });
|
|
78
|
+
/** An event a consumer (timeline, notifications, …) could not handle: its job in the consumer's queue. */
|
|
79
|
+
const EventFailure = z.object({
|
|
80
|
+
consumer: z.string(),
|
|
81
|
+
status: EventFailureStatus,
|
|
82
|
+
attempts: z.int(),
|
|
83
|
+
lastError: z.string(),
|
|
84
|
+
/** When the last attempt failed. */
|
|
85
|
+
failedAt: isoDate(),
|
|
86
|
+
/** When it is tried again; null once dead. */
|
|
87
|
+
nextAttemptAt: isoDate().nullable(),
|
|
88
|
+
event: CoreEvent
|
|
89
|
+
});
|
|
87
90
|
const FailureRef = z.object({
|
|
88
91
|
consumer: z.string().trim().min(1).max(100),
|
|
89
92
|
eventId: Id
|
|
@@ -94,8 +97,20 @@ const FailureRef = z.object({
|
|
|
94
97
|
* `POST /events`. Core turns events into timeline entries and notifications;
|
|
95
98
|
* automations and webhooks will read the same stream.
|
|
96
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
|
+
});
|
|
97
112
|
const eventsContract = {
|
|
98
|
-
publish:
|
|
113
|
+
publish: base.route({
|
|
99
114
|
method: "POST",
|
|
100
115
|
path: "/events",
|
|
101
116
|
successStatus: 201,
|
|
@@ -104,7 +119,7 @@ const eventsContract = {
|
|
|
104
119
|
published: z.int(),
|
|
105
120
|
duplicates: z.int()
|
|
106
121
|
})),
|
|
107
|
-
list:
|
|
122
|
+
list: base.route({
|
|
108
123
|
method: "GET",
|
|
109
124
|
path: "/events",
|
|
110
125
|
summary: "Recent events of the organisation (owners and admins)"
|
|
@@ -115,18 +130,18 @@ const eventsContract = {
|
|
|
115
130
|
subjectType: ActivityTarget.optional(),
|
|
116
131
|
subjectId: Id.optional()
|
|
117
132
|
})).output(cursorPageOf(CoreEvent)),
|
|
118
|
-
failures:
|
|
133
|
+
failures: base.route({
|
|
119
134
|
method: "GET",
|
|
120
135
|
path: "/events/failures",
|
|
121
136
|
summary: "Events that could not be handled: retrying with backoff, or dead after the last attempt (owners and admins)"
|
|
122
137
|
}).input(z.object({ status: EventFailureStatus.optional() })).output(z.object({
|
|
123
|
-
data: z.array(EventFailure),
|
|
138
|
+
data: z.array(EventFailure).max(200),
|
|
124
139
|
counts: z.object({
|
|
125
140
|
retrying: z.int(),
|
|
126
141
|
dead: z.int()
|
|
127
142
|
})
|
|
128
143
|
})),
|
|
129
|
-
retryFailures:
|
|
144
|
+
retryFailures: base.route({
|
|
130
145
|
method: "POST",
|
|
131
146
|
path: "/events/failures/retry",
|
|
132
147
|
summary: "Try failed events again now (owners and admins)"
|
|
@@ -134,7 +149,7 @@ const eventsContract = {
|
|
|
134
149
|
failures: z.array(FailureRef).min(1).max(200).optional(),
|
|
135
150
|
allDead: z.boolean().optional()
|
|
136
151
|
})).output(z.object({ retried: z.int() })),
|
|
137
|
-
dismissFailures:
|
|
152
|
+
dismissFailures: base.route({
|
|
138
153
|
method: "POST",
|
|
139
154
|
path: "/events/failures/dismiss",
|
|
140
155
|
summary: "Give up on failed events (owners and admins)"
|