@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/webhooks.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { CONTENT_TYPES, WEBHOOK_DELIVERY_STATUSES } from "./db/src/enums.js";
|
|
1
2
|
import { webhookDeliveries, webhooks } from "./db/src/schema/webhooks.js";
|
|
2
3
|
import "./db/src/schema/index.js";
|
|
3
|
-
import {
|
|
4
|
+
import { COMMON_ERRORS, ERRORS } from "./errors.js";
|
|
5
|
+
import { CursorQuery, Id, cursorPageOf, isoDate, listOf } from "./common.js";
|
|
4
6
|
import { oc } from "@orpc/contract";
|
|
5
|
-
import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
|
|
6
7
|
import { z } from "zod";
|
|
8
|
+
import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
|
|
7
9
|
// src/webhooks.ts
|
|
8
10
|
/**
|
|
9
11
|
* Events core publishes (plugins add theirs through their manifest). Webhooks
|
|
@@ -52,6 +54,18 @@ const CORE_EVENT_TYPES = [
|
|
|
52
54
|
subject: "customer",
|
|
53
55
|
description: "A person is unlinked from a company"
|
|
54
56
|
},
|
|
57
|
+
{
|
|
58
|
+
type: "core.customer.signed_up",
|
|
59
|
+
label: "Customer signed up",
|
|
60
|
+
subject: "customer",
|
|
61
|
+
description: "A person proves their first email address or phone and can sign in to apps"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
type: "core.customer.signed_in",
|
|
65
|
+
label: "Customer signed in",
|
|
66
|
+
subject: "customer",
|
|
67
|
+
description: "A person signs in with a code"
|
|
68
|
+
},
|
|
55
69
|
{
|
|
56
70
|
type: "core.lead.stage_changed",
|
|
57
71
|
label: "Lead moved to another stage",
|
|
@@ -162,7 +176,7 @@ const EventTypeInfo = z.object({
|
|
|
162
176
|
/** `core` or the plugin that publishes it. */
|
|
163
177
|
source: z.string(),
|
|
164
178
|
/** The record it is about, when it is about a customer or company. */
|
|
165
|
-
subject: z.enum(
|
|
179
|
+
subject: z.enum(CONTENT_TYPES).nullable()
|
|
166
180
|
});
|
|
167
181
|
/** `core.customer.created`, `core.customer.*`, `hr.*` or `*`. */
|
|
168
182
|
const EventPattern = z.string().trim().regex(/^(\*|[a-z][a-z0-9_]*(\.[a-z][a-z0-9_]*)*(\.\*)?)$/, "an event type, a prefix ending in .*, or *");
|
|
@@ -190,7 +204,6 @@ const WebhookDelivery = createSelectSchema(webhookDeliveries, {
|
|
|
190
204
|
attempts: int,
|
|
191
205
|
responseStatus: int,
|
|
192
206
|
durationMs: int,
|
|
193
|
-
nextAttemptAt: isoDate,
|
|
194
207
|
deliveredAt: isoDate,
|
|
195
208
|
createdAt: isoDate
|
|
196
209
|
}).pick({
|
|
@@ -204,7 +217,6 @@ const WebhookDelivery = createSelectSchema(webhookDeliveries, {
|
|
|
204
217
|
responseBody: true,
|
|
205
218
|
error: true,
|
|
206
219
|
durationMs: true,
|
|
207
|
-
nextAttemptAt: true,
|
|
208
220
|
deliveredAt: true,
|
|
209
221
|
createdAt: true
|
|
210
222
|
});
|
|
@@ -218,22 +230,29 @@ const WebhookFields = createUpdateSchema(webhooks, {
|
|
|
218
230
|
eventTypes: true,
|
|
219
231
|
status: true
|
|
220
232
|
});
|
|
233
|
+
const { INVALID_URL, LIMIT_EXCEEDED } = ERRORS;
|
|
234
|
+
/** What these procedures answer with besides the common errors. */
|
|
235
|
+
const base = oc.errors({
|
|
236
|
+
...COMMON_ERRORS,
|
|
237
|
+
INVALID_URL,
|
|
238
|
+
LIMIT_EXCEEDED
|
|
239
|
+
});
|
|
221
240
|
/**
|
|
222
241
|
* Webhooks: an organisation's endpoints get its events as signed POSTs
|
|
223
242
|
* (`Erxes-Signature: t=<unix>,v1=<hex HMAC-SHA256 of "<t>.<body>">`), retried
|
|
224
243
|
* with backoff for about a day; every attempt is in the delivery log.
|
|
225
244
|
*/
|
|
226
245
|
const webhooksContract = {
|
|
227
|
-
eventTypes:
|
|
246
|
+
eventTypes: base.route({
|
|
228
247
|
method: "GET",
|
|
229
248
|
path: "/events/types",
|
|
230
249
|
summary: "Event types to subscribe to or automate on: core's and installed plugins'"
|
|
231
|
-
}).output(
|
|
232
|
-
list:
|
|
250
|
+
}).output(listOf(EventTypeInfo)),
|
|
251
|
+
list: base.route({
|
|
233
252
|
method: "GET",
|
|
234
253
|
path: "/webhooks"
|
|
235
|
-
}).output(
|
|
236
|
-
create:
|
|
254
|
+
}).output(listOf(Webhook)),
|
|
255
|
+
create: base.route({
|
|
237
256
|
method: "POST",
|
|
238
257
|
path: "/webhooks",
|
|
239
258
|
successStatus: 201,
|
|
@@ -245,37 +264,33 @@ const webhooksContract = {
|
|
|
245
264
|
webhook: Webhook,
|
|
246
265
|
secret: z.string()
|
|
247
266
|
})),
|
|
248
|
-
update:
|
|
267
|
+
update: base.route({
|
|
249
268
|
method: "PATCH",
|
|
250
269
|
path: "/webhooks/{id}"
|
|
251
270
|
}).input(WebhookFields.extend({ id: Id })).output(Webhook),
|
|
252
|
-
remove:
|
|
271
|
+
remove: base.route({
|
|
253
272
|
method: "DELETE",
|
|
254
273
|
path: "/webhooks/{id}"
|
|
255
274
|
}).input(z.object({ id: Id })).output(z.object({ ok: z.literal(true) })),
|
|
256
|
-
rotateSecret:
|
|
275
|
+
rotateSecret: base.route({
|
|
257
276
|
method: "POST",
|
|
258
277
|
path: "/webhooks/{id}/secret",
|
|
259
278
|
summary: "A new signing secret (returned once); the old one stops at once"
|
|
260
279
|
}).input(z.object({ id: Id })).output(z.object({ secret: z.string() })),
|
|
261
|
-
test:
|
|
280
|
+
test: base.route({
|
|
262
281
|
method: "POST",
|
|
263
282
|
path: "/webhooks/{id}/test",
|
|
264
283
|
summary: "Send a `core.webhook.test` event to the endpoint now"
|
|
265
284
|
}).input(z.object({ id: Id })).output(WebhookDelivery),
|
|
266
|
-
deliveries:
|
|
285
|
+
deliveries: base.route({
|
|
267
286
|
method: "GET",
|
|
268
287
|
path: "/webhooks/{id}/deliveries",
|
|
269
288
|
summary: "Recent deliveries, newest first"
|
|
270
289
|
}).input(CursorQuery.extend({
|
|
271
290
|
id: Id,
|
|
272
|
-
status: z.enum(
|
|
273
|
-
"pending",
|
|
274
|
-
"succeeded",
|
|
275
|
-
"failed"
|
|
276
|
-
]).optional()
|
|
291
|
+
status: z.enum(WEBHOOK_DELIVERY_STATUSES).optional()
|
|
277
292
|
})).output(cursorPageOf(WebhookDelivery)),
|
|
278
|
-
redeliver:
|
|
293
|
+
redeliver: base.route({
|
|
279
294
|
method: "POST",
|
|
280
295
|
path: "/webhooks/deliveries/{deliveryId}/redeliver",
|
|
281
296
|
summary: "Send a delivery again"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@erxes/core-contract",
|
|
3
|
-
"version": "0.1.0-v2.
|
|
3
|
+
"version": "0.1.0-v2.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "erxes core API contract (/core/v1) and event schemas, shared by core and plugins",
|
|
6
6
|
"license": "AGPL-3.0-only",
|
|
@@ -19,12 +19,14 @@
|
|
|
19
19
|
"./activities": "./dist/activities.js",
|
|
20
20
|
"./audit": "./dist/audit.js",
|
|
21
21
|
"./auth": "./dist/auth.js",
|
|
22
|
-
"./automationDefinition": "./dist/automationDefinition.js",
|
|
23
22
|
"./automationRuns": "./dist/automationRuns.js",
|
|
24
23
|
"./automations": "./dist/automations.js",
|
|
24
|
+
"./client": "./dist/client.js",
|
|
25
25
|
"./common": "./dist/common.js",
|
|
26
26
|
"./companies": "./dist/companies.js",
|
|
27
|
+
"./customerAuth": "./dist/customerAuth.js",
|
|
27
28
|
"./customers": "./dist/customers.js",
|
|
29
|
+
"./errors": "./dist/errors.js",
|
|
28
30
|
"./events": "./dist/events.js",
|
|
29
31
|
"./fields": "./dist/fields.js",
|
|
30
32
|
"./files": "./dist/files.js",
|
|
@@ -37,11 +39,13 @@
|
|
|
37
39
|
"./plugins": "./dist/plugins.js",
|
|
38
40
|
"./products": "./dist/products.js",
|
|
39
41
|
"./roles": "./dist/roles.js",
|
|
42
|
+
"./routes": "./dist/routes.js",
|
|
40
43
|
"./saas": "./dist/saas.js",
|
|
41
44
|
"./tags": "./dist/tags.js",
|
|
42
45
|
"./transfer": "./dist/transfer.js",
|
|
43
46
|
"./trash": "./dist/trash.js",
|
|
44
47
|
"./users": "./dist/users.js",
|
|
48
|
+
"./values": "./dist/values.js",
|
|
45
49
|
"./views": "./dist/views.js",
|
|
46
50
|
"./webhooks": "./dist/webhooks.js",
|
|
47
51
|
"./package.json": "./package.json"
|
|
@@ -52,7 +56,10 @@
|
|
|
52
56
|
"tag": "v2-next"
|
|
53
57
|
},
|
|
54
58
|
"dependencies": {
|
|
59
|
+
"@orpc/client": "1.16.2",
|
|
55
60
|
"@orpc/contract": "1.16.2",
|
|
61
|
+
"@orpc/openapi-client": "1.16.2",
|
|
62
|
+
"@orpc/tanstack-query": "1.16.2",
|
|
56
63
|
"country-to-currency": "^3.0.2",
|
|
57
64
|
"drizzle-orm": "0.45.4",
|
|
58
65
|
"drizzle-zod": "0.8.3",
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { pgTable } from "../table.js";
|
|
2
|
-
import { createdAt, updatedAt } from "./common.js";
|
|
3
|
-
import { organizations } from "./organizations.js";
|
|
4
|
-
import { check, foreignKey, index, integer, jsonb, text, timestamp, uniqueIndex } from "drizzle-orm/pg-core";
|
|
5
|
-
import { sql } from "drizzle-orm";
|
|
6
|
-
// ../db/src/schema/jobs.ts
|
|
7
|
-
const timestamptz = () => timestamp({
|
|
8
|
-
withTimezone: true,
|
|
9
|
-
mode: "date"
|
|
10
|
-
});
|
|
11
|
-
const JOB_STATUSES = [
|
|
12
|
-
"queued",
|
|
13
|
-
"running",
|
|
14
|
-
"dead"
|
|
15
|
-
];
|
|
16
|
-
pgTable("jobs", {
|
|
17
|
-
id: text().primaryKey(),
|
|
18
|
-
orgId: text().notNull(),
|
|
19
|
-
/** What to do: `webhook.deliver`, `automation.step`, … */
|
|
20
|
-
queue: text().notNull(),
|
|
21
|
-
payload: jsonb().$type().default({}).notNull(),
|
|
22
|
-
status: text({ enum: JOB_STATUSES }).default("queued").notNull(),
|
|
23
|
-
runAt: timestamptz().defaultNow().notNull(),
|
|
24
|
-
attempts: integer().default(0).notNull(),
|
|
25
|
-
maxAttempts: integer().default(8).notNull(),
|
|
26
|
-
lockedUntil: timestamptz(),
|
|
27
|
-
lastError: text(),
|
|
28
|
-
/** One queued job per key (per organisation and queue). */
|
|
29
|
-
dedupeKey: text(),
|
|
30
|
-
createdAt: createdAt(),
|
|
31
|
-
updatedAt: updatedAt()
|
|
32
|
-
}, (table) => [
|
|
33
|
-
index("core_jobs_due_idx").on(table.runAt).where(sql`${table.status} = 'queued'`),
|
|
34
|
-
index("core_jobs_stuck_idx").on(table.lockedUntil).where(sql`${table.status} = 'running'`),
|
|
35
|
-
index("core_jobs_org_idx").on(table.orgId, table.queue, table.status),
|
|
36
|
-
uniqueIndex("core_jobs_dedupe_key").on(table.orgId, table.queue, table.dedupeKey).where(sql`${table.dedupeKey} IS NOT NULL`),
|
|
37
|
-
check("core_jobs_status_check", sql`${table.status} IN ('queued', 'running', 'dead')`),
|
|
38
|
-
foreignKey({
|
|
39
|
-
columns: [table.orgId],
|
|
40
|
-
foreignColumns: [organizations.id],
|
|
41
|
-
name: "core_jobs_org_id_fkey"
|
|
42
|
-
}).onDelete("cascade")
|
|
43
|
-
]);
|
|
44
|
-
export { JOB_STATUSES };
|