@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/plugins.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
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";
|
|
2
5
|
import { EventPattern } from "./webhooks.js";
|
|
3
6
|
import { Id, isoDate, listOf } from "./common.js";
|
|
4
7
|
import { ActionField } from "./automationRuns.js";
|
|
@@ -6,6 +9,7 @@ import { Country } from "./money.js";
|
|
|
6
9
|
import { EventType } from "./platform.js";
|
|
7
10
|
import { oc } from "@orpc/contract";
|
|
8
11
|
import { z } from "zod";
|
|
12
|
+
import { createSelectSchema } from "drizzle-zod";
|
|
9
13
|
// src/plugins.ts
|
|
10
14
|
/** A plugin's name: its namespace everywhere (`hr` → `hr.leave.requested`, `/hr/*`). */
|
|
11
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");
|
|
@@ -134,27 +138,33 @@ const PluginManifest = z.object({
|
|
|
134
138
|
subject: z.enum(CONTENT_TYPES).optional()
|
|
135
139
|
})).max(500).optional()
|
|
136
140
|
});
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
version: z.string().nullable(),
|
|
141
|
-
description: z.string().nullable(),
|
|
142
|
-
/** Made for these countries (empty: everywhere). */
|
|
143
|
-
countries: z.array(z.string()),
|
|
144
|
-
ui: z.object({
|
|
145
|
-
remote: z.string(),
|
|
146
|
-
entry: z.string()
|
|
147
|
-
}).nullable(),
|
|
148
|
-
api: z.object({ url: z.string() }).nullable(),
|
|
149
|
-
/** In this organisation: installed and active. */
|
|
150
|
-
installed: z.boolean(),
|
|
141
|
+
/** The plugin in this organisation; `status` `active` is installed. */
|
|
142
|
+
const PluginInstallation = createSelectSchema(pluginInstallations, { installedAt: isoDate }).pick({
|
|
143
|
+
status: true,
|
|
151
144
|
/** Why it is off here (`Suspended: 600 deletions in a few minutes`). */
|
|
152
|
-
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. */
|
|
153
165
|
requestedScopes: z.array(z.string()),
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
needsApproval: z.boolean(),
|
|
157
|
-
installedAt: isoDate().nullable()
|
|
166
|
+
/** Installed, and asks for scopes the owner hasn't granted yet (a newer version). */
|
|
167
|
+
needsApproval: z.boolean()
|
|
158
168
|
});
|
|
159
169
|
const TokenResponse = z.object({
|
|
160
170
|
access_token: z.string(),
|
|
@@ -168,8 +178,19 @@ const TokenResponse = z.object({
|
|
|
168
178
|
* plugin UIs (a member's short-lived session for one plugin's API), and live
|
|
169
179
|
* signals to plugin UIs.
|
|
170
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
|
+
});
|
|
171
192
|
const pluginsContract = {
|
|
172
|
-
token:
|
|
193
|
+
token: base.route({
|
|
173
194
|
method: "POST",
|
|
174
195
|
path: "/plugins/token",
|
|
175
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"
|
|
@@ -179,27 +200,27 @@ const pluginsContract = {
|
|
|
179
200
|
client_secret: z.string().min(32).max(200),
|
|
180
201
|
org: Id.optional()
|
|
181
202
|
})).output(TokenResponse),
|
|
182
|
-
registerManifest:
|
|
203
|
+
registerManifest: base.route({
|
|
183
204
|
method: "PUT",
|
|
184
205
|
path: "/plugins/manifest",
|
|
185
206
|
summary: "The calling plugin declares its UI, API, scopes, permissions and events"
|
|
186
207
|
}).input(PluginManifest).output(z.object({ ok: z.literal(true) })),
|
|
187
|
-
list:
|
|
208
|
+
list: base.route({
|
|
188
209
|
method: "GET",
|
|
189
210
|
path: "/plugins",
|
|
190
211
|
summary: "Plugins of this deployment, and which are installed here"
|
|
191
212
|
}).output(listOf(Plugin)),
|
|
192
|
-
install:
|
|
213
|
+
install: base.route({
|
|
193
214
|
method: "POST",
|
|
194
215
|
path: "/plugins/{name}/install",
|
|
195
216
|
summary: "Install (or approve the new scopes of) a plugin (owners)"
|
|
196
217
|
}).input(z.object({ name: PluginName })).output(Plugin),
|
|
197
|
-
uninstall:
|
|
218
|
+
uninstall: base.route({
|
|
198
219
|
method: "POST",
|
|
199
220
|
path: "/plugins/{name}/uninstall",
|
|
200
221
|
summary: "Uninstall a plugin: its tokens stop working at once (owners)"
|
|
201
222
|
}).input(z.object({ name: PluginName })).output(Plugin),
|
|
202
|
-
session:
|
|
223
|
+
session: base.route({
|
|
203
224
|
method: "POST",
|
|
204
225
|
path: "/plugins/{name}/session",
|
|
205
226
|
summary: "A 5-minute token for one plugin's API, for the signed-in member (plugin UIs send it as Bearer)"
|
|
@@ -208,7 +229,7 @@ const pluginsContract = {
|
|
|
208
229
|
expiresAt: z.iso.datetime(),
|
|
209
230
|
apiUrl: z.string().nullable()
|
|
210
231
|
})),
|
|
211
|
-
signal:
|
|
232
|
+
signal: base.route({
|
|
212
233
|
method: "POST",
|
|
213
234
|
path: "/plugins/live",
|
|
214
235
|
summary: "Tell the plugin's open UIs something changed (plugins with live:write); no data, UIs refetch"
|
|
@@ -217,4 +238,4 @@ const pluginsContract = {
|
|
|
217
238
|
userIds: z.array(Id).max(1e3).optional()
|
|
218
239
|
})).output(z.object({ ok: z.literal(true) }))
|
|
219
240
|
};
|
|
220
|
-
export { LiveTopic, PLUGIN_SCOPES, Plugin, PluginManifest, PluginName, PluginScope, TokenResponse, pluginsContract };
|
|
241
|
+
export { LiveTopic, PLUGIN_SCOPES, Plugin, PluginInstallation, PluginManifest, PluginName, PluginScope, TokenResponse, pluginsContract };
|