@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/plugins.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
+
import { AUTOMATION_SUBJECTS, CONTENT_TYPES } from "./db/src/enums.js";
|
|
2
|
+
import { pluginInstallations, plugins } from "./db/src/schema/plugins.js";
|
|
3
|
+
import "./db/src/schema/index.js";
|
|
4
|
+
import { COMMON_ERRORS, ERRORS } from "./errors.js";
|
|
1
5
|
import { EventPattern } from "./webhooks.js";
|
|
2
|
-
import { Id } from "./common.js";
|
|
6
|
+
import { Id, isoDate, listOf } from "./common.js";
|
|
3
7
|
import { ActionField } from "./automationRuns.js";
|
|
4
8
|
import { Country } from "./money.js";
|
|
5
9
|
import { EventType } from "./platform.js";
|
|
6
10
|
import { oc } from "@orpc/contract";
|
|
7
11
|
import { z } from "zod";
|
|
12
|
+
import { createSelectSchema } from "drizzle-zod";
|
|
8
13
|
// src/plugins.ts
|
|
9
14
|
/** A plugin's name: its namespace everywhere (`hr` → `hr.leave.requested`, `/hr/*`). */
|
|
10
15
|
const PluginName = z.string().trim().regex(/^[a-z][a-z0-9_]{0,39}$/, "lower case letters, digits and _ (starting with a letter)").refine((name) => name !== "core", "reserved");
|
|
@@ -32,6 +37,12 @@ const PluginScope = z.enum(PLUGIN_SCOPES);
|
|
|
32
37
|
/** Live update topic: `leave-requests`, `leave:abc123`. */
|
|
33
38
|
const LiveTopic = z.string().trim().regex(/^[a-z0-9][a-z0-9._:-]{0,99}$/, "lower case letters, digits and . _ : -");
|
|
34
39
|
const HttpsUrl = z.string().trim().check(z.url()).max(500).refine((value) => /^https?:\/\//.test(value), "an http(s) address");
|
|
40
|
+
/**
|
|
41
|
+
* A web origin a customer app runs at: `https://host[:port]`, where
|
|
42
|
+
* `{subdomain}` may stand for a whole label (the organisation's), or
|
|
43
|
+
* `http://localhost[:port]` while developing.
|
|
44
|
+
*/
|
|
45
|
+
const AppOrigin = z.string().trim().max(200).regex(/^(https:\/\/(\{subdomain\}|[a-z0-9-]+)(\.(\{subdomain\}|[a-z0-9-]+))+|http:\/\/(localhost|127\.0\.0\.1))(:\d{1,5})?$/, "an origin: https://shop.example.com, https://{subdomain}.shop.example.com or http://localhost:3000");
|
|
35
46
|
const PluginManifest = z.object({
|
|
36
47
|
title: z.string().trim().min(1).max(80),
|
|
37
48
|
version: z.string().trim().min(1).max(40),
|
|
@@ -55,6 +66,13 @@ const PluginManifest = z.object({
|
|
|
55
66
|
* organisation's (`https://{subdomain}.hr.erxes.io/auth/callback`).
|
|
56
67
|
*/
|
|
57
68
|
oauth: z.object({ redirectUris: z.array(z.string().trim().max(500).regex(/^https?:\/\/[^\s#]+$/, "an http(s) address without a fragment")).min(1).max(20) }).optional(),
|
|
69
|
+
/**
|
|
70
|
+
* The plugin's app for customers (a shop, tracking, booking). It signs
|
|
71
|
+
* customers in by calling `/customer-auth/*` itself (decision 42); browsers
|
|
72
|
+
* may call `/customer-auth/*` and `/customer/*` only from these origins.
|
|
73
|
+
* Apps without an origin (mobile) are limited by rate instead.
|
|
74
|
+
*/
|
|
75
|
+
customerApp: z.object({ origins: z.array(AppOrigin).min(1).max(20) }).optional(),
|
|
58
76
|
scopes: z.array(PluginScope).max(PLUGIN_SCOPES.length).default([]),
|
|
59
77
|
/** Actions members can be granted (`hr.leave.approve`), shown in roles. */
|
|
60
78
|
permissions: z.array(z.object({
|
|
@@ -77,11 +95,7 @@ const PluginManifest = z.object({
|
|
|
77
95
|
type: EventType,
|
|
78
96
|
label: z.string().trim().min(1).max(100),
|
|
79
97
|
description: z.string().trim().max(300).optional(),
|
|
80
|
-
subject: z.enum(
|
|
81
|
-
"customer",
|
|
82
|
-
"company",
|
|
83
|
-
"any"
|
|
84
|
-
]).optional(),
|
|
98
|
+
subject: z.enum(AUTOMATION_SUBJECTS).optional(),
|
|
85
99
|
fields: z.array(ActionField).max(50).default([])
|
|
86
100
|
})).max(200).optional(),
|
|
87
101
|
/** Its own record types that get a timeline in erxes (notes, mentions, entries), and who may see it. */
|
|
@@ -121,30 +135,36 @@ const PluginManifest = z.object({
|
|
|
121
135
|
type: EventType,
|
|
122
136
|
label: z.string().trim().min(1).max(100),
|
|
123
137
|
description: z.string().trim().max(300).optional(),
|
|
124
|
-
subject: z.enum(
|
|
138
|
+
subject: z.enum(CONTENT_TYPES).optional()
|
|
125
139
|
})).max(500).optional()
|
|
126
140
|
});
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
version: z.string().nullable(),
|
|
131
|
-
description: z.string().nullable(),
|
|
132
|
-
/** Made for these countries (empty: everywhere). */
|
|
133
|
-
countries: z.array(z.string()),
|
|
134
|
-
ui: z.object({
|
|
135
|
-
remote: z.string(),
|
|
136
|
-
entry: z.string()
|
|
137
|
-
}).nullable(),
|
|
138
|
-
api: z.object({ url: z.string() }).nullable(),
|
|
139
|
-
/** In this organisation: installed and active. */
|
|
140
|
-
installed: z.boolean(),
|
|
141
|
+
/** The plugin in this organisation; `status` `active` is installed. */
|
|
142
|
+
const PluginInstallation = createSelectSchema(pluginInstallations, { installedAt: isoDate }).pick({
|
|
143
|
+
status: true,
|
|
141
144
|
/** Why it is off here (`Suspended: 600 deletions in a few minutes`). */
|
|
142
|
-
statusReason:
|
|
145
|
+
statusReason: true,
|
|
146
|
+
grantedScopes: true,
|
|
147
|
+
installedAt: true
|
|
148
|
+
});
|
|
149
|
+
const Plugin = createSelectSchema(plugins, {
|
|
150
|
+
/** What members see of the manifest (the column is nullable); the rest is for core. */
|
|
151
|
+
manifest: () => PluginManifest.pick({
|
|
152
|
+
title: true,
|
|
153
|
+
version: true,
|
|
154
|
+
description: true,
|
|
155
|
+
countries: true,
|
|
156
|
+
ui: true,
|
|
157
|
+
api: true
|
|
158
|
+
}) }).pick({
|
|
159
|
+
name: true,
|
|
160
|
+
manifest: true
|
|
161
|
+
}).extend({
|
|
162
|
+
/** Never installed here: null. */
|
|
163
|
+
installation: PluginInstallation.nullable(),
|
|
164
|
+
/** The manifest's scopes, or (before it sent one) what plugins could always do. */
|
|
143
165
|
requestedScopes: z.array(z.string()),
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
needsApproval: z.boolean(),
|
|
147
|
-
installedAt: z.iso.datetime().nullable()
|
|
166
|
+
/** Installed, and asks for scopes the owner hasn't granted yet (a newer version). */
|
|
167
|
+
needsApproval: z.boolean()
|
|
148
168
|
});
|
|
149
169
|
const TokenResponse = z.object({
|
|
150
170
|
access_token: z.string(),
|
|
@@ -158,8 +178,19 @@ const TokenResponse = z.object({
|
|
|
158
178
|
* plugin UIs (a member's short-lived session for one plugin's API), and live
|
|
159
179
|
* signals to plugin UIs.
|
|
160
180
|
*/
|
|
181
|
+
const { CROSS_SITE, INVALID_CLIENT, LIMIT_EXCEEDED, NAMESPACE_REQUIRED, NOT_INSTALLED, PLUGIN_NOT_FOUND } = ERRORS;
|
|
182
|
+
/** What these procedures answer with besides the common errors. */
|
|
183
|
+
const base = oc.errors({
|
|
184
|
+
...COMMON_ERRORS,
|
|
185
|
+
CROSS_SITE,
|
|
186
|
+
INVALID_CLIENT,
|
|
187
|
+
LIMIT_EXCEEDED,
|
|
188
|
+
NAMESPACE_REQUIRED,
|
|
189
|
+
NOT_INSTALLED,
|
|
190
|
+
PLUGIN_NOT_FOUND
|
|
191
|
+
});
|
|
161
192
|
const pluginsContract = {
|
|
162
|
-
token:
|
|
193
|
+
token: base.route({
|
|
163
194
|
method: "POST",
|
|
164
195
|
path: "/plugins/token",
|
|
165
196
|
summary: "Client credentials → a 15-minute token (ES256). With `org`: to act in an organisation that installed the plugin; without: to update the manifest"
|
|
@@ -169,27 +200,27 @@ const pluginsContract = {
|
|
|
169
200
|
client_secret: z.string().min(32).max(200),
|
|
170
201
|
org: Id.optional()
|
|
171
202
|
})).output(TokenResponse),
|
|
172
|
-
registerManifest:
|
|
203
|
+
registerManifest: base.route({
|
|
173
204
|
method: "PUT",
|
|
174
205
|
path: "/plugins/manifest",
|
|
175
206
|
summary: "The calling plugin declares its UI, API, scopes, permissions and events"
|
|
176
207
|
}).input(PluginManifest).output(z.object({ ok: z.literal(true) })),
|
|
177
|
-
list:
|
|
208
|
+
list: base.route({
|
|
178
209
|
method: "GET",
|
|
179
210
|
path: "/plugins",
|
|
180
211
|
summary: "Plugins of this deployment, and which are installed here"
|
|
181
|
-
}).output(
|
|
182
|
-
install:
|
|
212
|
+
}).output(listOf(Plugin)),
|
|
213
|
+
install: base.route({
|
|
183
214
|
method: "POST",
|
|
184
215
|
path: "/plugins/{name}/install",
|
|
185
216
|
summary: "Install (or approve the new scopes of) a plugin (owners)"
|
|
186
217
|
}).input(z.object({ name: PluginName })).output(Plugin),
|
|
187
|
-
uninstall:
|
|
218
|
+
uninstall: base.route({
|
|
188
219
|
method: "POST",
|
|
189
220
|
path: "/plugins/{name}/uninstall",
|
|
190
221
|
summary: "Uninstall a plugin: its tokens stop working at once (owners)"
|
|
191
222
|
}).input(z.object({ name: PluginName })).output(Plugin),
|
|
192
|
-
session:
|
|
223
|
+
session: base.route({
|
|
193
224
|
method: "POST",
|
|
194
225
|
path: "/plugins/{name}/session",
|
|
195
226
|
summary: "A 5-minute token for one plugin's API, for the signed-in member (plugin UIs send it as Bearer)"
|
|
@@ -198,7 +229,7 @@ const pluginsContract = {
|
|
|
198
229
|
expiresAt: z.iso.datetime(),
|
|
199
230
|
apiUrl: z.string().nullable()
|
|
200
231
|
})),
|
|
201
|
-
signal:
|
|
232
|
+
signal: base.route({
|
|
202
233
|
method: "POST",
|
|
203
234
|
path: "/plugins/live",
|
|
204
235
|
summary: "Tell the plugin's open UIs something changed (plugins with live:write); no data, UIs refetch"
|
|
@@ -207,4 +238,4 @@ const pluginsContract = {
|
|
|
207
238
|
userIds: z.array(Id).max(1e3).optional()
|
|
208
239
|
})).output(z.object({ ok: z.literal(true) }))
|
|
209
240
|
};
|
|
210
|
-
export { LiveTopic, PLUGIN_SCOPES, Plugin, PluginManifest, PluginName, PluginScope, TokenResponse, pluginsContract };
|
|
241
|
+
export { LiveTopic, PLUGIN_SCOPES, Plugin, PluginInstallation, PluginManifest, PluginName, PluginScope, TokenResponse, pluginsContract };
|