@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.
Files changed (102) hide show
  1. package/dist/activities.d.ts +1394 -139
  2. package/dist/activities.js +96 -40
  3. package/dist/audit.d.ts +1092 -48
  4. package/dist/audit.js +37 -23
  5. package/dist/auth.d.ts +2867 -61
  6. package/dist/auth.js +55 -25
  7. package/dist/automationRuns.d.ts +12 -13
  8. package/dist/automationRuns.js +15 -30
  9. package/dist/automations.d.ts +2474 -93
  10. package/dist/automations.js +56 -44
  11. package/dist/client.d.ts +30704 -0
  12. package/dist/client.js +62 -0
  13. package/dist/common.d.ts +28 -16
  14. package/dist/common.js +30 -22
  15. package/dist/companies.d.ts +1154 -44
  16. package/dist/companies.js +33 -17
  17. package/dist/contract/routes.json.js +1810 -0
  18. package/dist/customerAuth.d.ts +1661 -0
  19. package/dist/customerAuth.js +197 -0
  20. package/dist/customers.d.ts +1283 -65
  21. package/dist/customers.js +35 -25
  22. package/dist/{automationDefinition.d.ts → db/src/automationDefinition.d.ts} +4 -3
  23. package/dist/{automationDefinition.js → db/src/automationDefinition.js} +10 -32
  24. package/dist/db/src/enums.d.ts +8 -0
  25. package/dist/db/src/enums.js +334 -0
  26. package/dist/db/src/schema/auditStreams.js +6 -14
  27. package/dist/db/src/schema/authTokens.js +4 -6
  28. package/dist/db/src/schema/automations.d.ts +1 -0
  29. package/dist/db/src/schema/automations.js +15 -31
  30. package/dist/db/src/schema/common.d.ts +2 -6
  31. package/dist/db/src/schema/common.js +1 -24
  32. package/dist/db/src/schema/companies.js +6 -5
  33. package/dist/db/src/schema/customerAuth.js +101 -0
  34. package/dist/db/src/schema/customers.js +6 -6
  35. package/dist/db/src/schema/events.js +12 -60
  36. package/dist/db/src/schema/fieldValues.js +2 -2
  37. package/dist/db/src/schema/fields.js +10 -28
  38. package/dist/db/src/schema/index.d.ts +3 -0
  39. package/dist/db/src/schema/index.js +22 -20
  40. package/dist/db/src/schema/leadStages.js +5 -10
  41. package/dist/db/src/schema/leads.js +6 -11
  42. package/dist/db/src/schema/notes.js +92 -0
  43. package/dist/db/src/schema/oauth.js +3 -3
  44. package/dist/db/src/schema/payments.js +13 -23
  45. package/dist/db/src/schema/platform.js +11 -31
  46. package/dist/db/src/schema/plugins.js +10 -5
  47. package/dist/db/src/schema/products.js +7 -8
  48. package/dist/db/src/schema/rateLimits.js +7 -0
  49. package/dist/db/src/schema/saas.js +3 -9
  50. package/dist/db/src/schema/tags.js +6 -5
  51. package/dist/db/src/schema/transfer.js +13 -33
  52. package/dist/db/src/schema/trash.js +6 -7
  53. package/dist/db/src/schema/users.js +6 -10
  54. package/dist/db/src/schema/views.js +5 -13
  55. package/dist/db/src/schema/webhooks.js +7 -14
  56. package/dist/db/src/table.js +16 -2
  57. package/dist/errors.d.ts +516 -0
  58. package/dist/errors.js +218 -0
  59. package/dist/events.d.ts +585 -140
  60. package/dist/events.js +57 -42
  61. package/dist/fields.d.ts +1478 -66
  62. package/dist/fields.js +33 -47
  63. package/dist/files.d.ts +766 -62
  64. package/dist/files.js +34 -22
  65. package/dist/index.d.ts +25707 -902
  66. package/dist/index.js +22 -20
  67. package/dist/leads.d.ts +1108 -22
  68. package/dist/leads.js +39 -20
  69. package/dist/notifications.d.ts +691 -94
  70. package/dist/notifications.js +45 -91
  71. package/dist/organizations.d.ts +263 -5
  72. package/dist/organizations.js +21 -2
  73. package/dist/payments.d.ts +1794 -120
  74. package/dist/payments.js +58 -60
  75. package/dist/platform.d.ts +12 -20
  76. package/dist/platform.js +8 -21
  77. package/dist/plugins.d.ts +808 -71
  78. package/dist/plugins.js +66 -35
  79. package/dist/products.d.ts +1411 -53
  80. package/dist/products.js +40 -23
  81. package/dist/roles.d.ts +560 -8
  82. package/dist/roles.js +25 -11
  83. package/dist/routes.d.ts +8 -0
  84. package/dist/routes.js +13 -0
  85. package/dist/saas.d.ts +164 -8
  86. package/dist/saas.js +14 -29
  87. package/dist/tags.d.ts +344 -8
  88. package/dist/tags.js +16 -8
  89. package/dist/transfer.d.ts +1361 -36
  90. package/dist/transfer.js +47 -49
  91. package/dist/trash.d.ts +299 -23
  92. package/dist/trash.js +27 -20
  93. package/dist/users.d.ts +1233 -59
  94. package/dist/users.js +48 -39
  95. package/dist/values.d.ts +150 -0
  96. package/dist/values.js +139 -0
  97. package/dist/views.d.ts +404 -13
  98. package/dist/views.js +18 -28
  99. package/dist/webhooks.d.ts +791 -29
  100. package/dist/webhooks.js +36 -21
  101. package/package.json +9 -2
  102. 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 { CursorQuery, Id, cursorPageOf, isoDate } from "./common.js";
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(["customer", "company"]).nullable()
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: oc.route({
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(z.object({ data: z.array(EventTypeInfo) })),
232
- list: oc.route({
250
+ }).output(listOf(EventTypeInfo)),
251
+ list: base.route({
233
252
  method: "GET",
234
253
  path: "/webhooks"
235
- }).output(z.object({ data: z.array(Webhook) })),
236
- create: oc.route({
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: oc.route({
267
+ update: base.route({
249
268
  method: "PATCH",
250
269
  path: "/webhooks/{id}"
251
270
  }).input(WebhookFields.extend({ id: Id })).output(Webhook),
252
- remove: oc.route({
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: oc.route({
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: oc.route({
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: oc.route({
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: oc.route({
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.0",
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 };