@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/payments.js CHANGED
@@ -1,34 +1,16 @@
1
- import { INVOICE_STATUSES, PAYMENT_GATEWAY_KINDS, paymentGateways, paymentInvoices, paymentPluginSettings, paymentRefunds } from "./db/src/schema/payments.js";
1
+ import { GATEWAY_REFUND_KINDS, PAYMENT_GATEWAY_STATUSES } from "./db/src/enums.js";
2
+ import { paymentGateways, paymentInvoices, paymentPluginSettings, paymentRefunds } from "./db/src/schema/payments.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 { InvoiceStatus, PaymentGatewayKind } from "./values.js";
6
+ import { CursorQuery, Id, cursorPageOf, isoDate, listOf } from "./common.js";
4
7
  import { Currency } from "./money.js";
5
8
  import { DedupeKey } from "./platform.js";
6
9
  import { PluginName } from "./plugins.js";
7
10
  import { oc } from "@orpc/contract";
8
- import { createSelectSchema } from "drizzle-zod";
9
11
  import { z } from "zod";
12
+ import { createSelectSchema } from "drizzle-zod";
10
13
  // src/payments.ts
11
- /**
12
- * The gateways core can connect, and where each works: the currencies it
13
- * takes and the countries it serves (empty: any). QPay is Mongolian; global
14
- * ones (Stripe …) join here as drivers in `@erxes/payment-gateways`.
15
- */
16
- const PAYMENT_GATEWAYS = {
17
- qpay: {
18
- currencies: ["MNT"],
19
- countries: ["MN"]
20
- },
21
- test: {
22
- currencies: [],
23
- countries: []
24
- }
25
- };
26
- const PaymentGatewayKind = z.enum(PAYMENT_GATEWAY_KINDS);
27
- /** Does this kind of gateway take this currency? */
28
- const gatewayTakes = (kind, currency) => {
29
- const { currencies } = PAYMENT_GATEWAYS[kind];
30
- return currencies.length === 0 || currencies.some((code) => code === currency);
31
- };
32
14
  /** What each gateway needs (secrets are write-only: never returned). */
33
15
  const GatewayConfig = z.discriminatedUnion("kind", [z.object({
34
16
  kind: z.literal("qpay"),
@@ -50,7 +32,6 @@ const PaymentGateway = createSelectSchema(paymentGateways, {
50
32
  }).extend({
51
33
  /** Non-secret settings, for display (`invoiceCode`, `sandbox`). */
52
34
  settings: z.record(z.string(), z.unknown()) });
53
- const InvoiceStatus = z.enum(INVOICE_STATUSES);
54
35
  /** The caller's own data on an invoice (order lines, room number): at most 8 KB of JSON, returned in events. */
55
36
  const InvoiceMetadata = z.record(z.string(), z.unknown()).refine((value) => JSON.stringify(value).length <= 8192, "at most 8 KB of JSON");
56
37
  /**
@@ -108,6 +89,9 @@ const Invoice = createSelectSchema(paymentInvoices, {
108
89
  /** ISO 4217. */
109
90
  currency: true,
110
91
  description: true,
92
+ /** The caller's record it is for (`order` and its id). */
93
+ referenceType: true,
94
+ referenceId: true,
111
95
  status: true,
112
96
  metadata: true,
113
97
  lines: true,
@@ -120,19 +104,12 @@ const Invoice = createSelectSchema(paymentInvoices, {
120
104
  paidAt: true,
121
105
  createdAt: true
122
106
  }).extend({
107
+ /** The gateway's kind, joined in the query. */
123
108
  gatewayKind: PaymentGatewayKind,
124
- reference: z.object({
125
- type: z.string(),
126
- id: z.string()
127
- }),
128
109
  /** What can still be refunded, and how the gateway refunds (`full`: only the whole payment). */
129
110
  refundable: z.object({
130
111
  amount: z.int(),
131
- gateway: z.enum([
132
- "partial",
133
- "full",
134
- "none"
135
- ])
112
+ gateway: z.enum(GATEWAY_REFUND_KINDS)
136
113
  })
137
114
  });
138
115
  const Refund = createSelectSchema(paymentRefunds, {
@@ -149,11 +126,11 @@ const Refund = createSelectSchema(paymentRefunds, {
149
126
  method: true,
150
127
  status: true,
151
128
  error: true,
129
+ /** Who asked: a team member (`requestedBy` = user id), a plugin (its name) or `system`. */
130
+ requestedByType: true,
131
+ requestedBy: true,
152
132
  createdAt: true
153
- }).extend({ requestedBy: z.object({
154
- type: z.string(),
155
- id: z.string().nullable()
156
- }) });
133
+ });
157
134
  /** How a plugin takes payments here: its default gateway, and the only ones it may use (none: any). */
158
135
  const PluginPaymentSettings = createSelectSchema(paymentPluginSettings, {
159
136
  defaultGatewayId: () => Id,
@@ -168,12 +145,34 @@ const PluginPaymentSettings = createSelectSchema(paymentPluginSettings, {
168
145
  * made through them for plugins' records. Paid invoices publish
169
146
  * `core.payment.paid` (webhooks, automations, the plugin's own consumer).
170
147
  */
148
+ const { CURRENCY_NOT_SUPPORTED, DEFAULT_NOT_ALLOWED, GATEWAY_IN_USE, GATEWAY_NOT_ALLOWED, GATEWAY_REFUSED, INVALID_PRODUCT, INVALID_SUBDOMAIN, KIND_CHANGED, LIMIT_EXCEEDED, LINES_MISMATCH, NOTHING_TO_RETRY, NOT_PENDING, NOT_REFUNDABLE, NOT_TEST, NO_GATEWAY, PARTIAL_NOT_SUPPORTED, SUBJECT_REQUIRED } = ERRORS;
149
+ /** What these procedures answer with besides the common errors. */
150
+ const base = oc.errors({
151
+ ...COMMON_ERRORS,
152
+ CURRENCY_NOT_SUPPORTED,
153
+ DEFAULT_NOT_ALLOWED,
154
+ GATEWAY_IN_USE,
155
+ GATEWAY_NOT_ALLOWED,
156
+ GATEWAY_REFUSED,
157
+ INVALID_PRODUCT,
158
+ INVALID_SUBDOMAIN,
159
+ KIND_CHANGED,
160
+ LIMIT_EXCEEDED,
161
+ LINES_MISMATCH,
162
+ NOTHING_TO_RETRY,
163
+ NOT_PENDING,
164
+ NOT_REFUNDABLE,
165
+ NOT_TEST,
166
+ NO_GATEWAY,
167
+ PARTIAL_NOT_SUPPORTED,
168
+ SUBJECT_REQUIRED
169
+ });
171
170
  const paymentsContract = {
172
- gateways: oc.route({
171
+ gateways: base.route({
173
172
  method: "GET",
174
173
  path: "/payments/gateways"
175
- }).output(z.object({ data: z.array(PaymentGateway) })),
176
- addGateway: oc.route({
174
+ }).output(listOf(PaymentGateway)),
175
+ addGateway: base.route({
177
176
  method: "POST",
178
177
  path: "/payments/gateways",
179
178
  successStatus: 201,
@@ -182,21 +181,21 @@ const paymentsContract = {
182
181
  name: z.string().trim().min(1).max(80),
183
182
  config: GatewayConfig
184
183
  })).output(PaymentGateway),
185
- updateGateway: oc.route({
184
+ updateGateway: base.route({
186
185
  method: "PATCH",
187
186
  path: "/payments/gateways/{id}"
188
187
  }).input(z.object({
189
188
  id: Id,
190
189
  name: z.string().trim().min(1).max(80).optional(),
191
190
  config: GatewayConfig.optional(),
192
- status: z.enum(["active", "disabled"]).optional()
191
+ status: z.enum(PAYMENT_GATEWAY_STATUSES).optional()
193
192
  })).output(PaymentGateway),
194
- removeGateway: oc.route({
193
+ removeGateway: base.route({
195
194
  method: "DELETE",
196
195
  path: "/payments/gateways/{id}",
197
196
  summary: "Remove a gateway without invoices (turn it off otherwise)"
198
197
  }).input(z.object({ id: Id })).output(z.object({ ok: z.literal(true) })),
199
- createInvoice: oc.route({
198
+ createInvoice: base.route({
200
199
  method: "POST",
201
200
  path: "/payments/invoices",
202
201
  successStatus: 201,
@@ -206,26 +205,25 @@ const paymentsContract = {
206
205
  amount: z.int().min(1).max(1e11),
207
206
  currency: Currency.optional(),
208
207
  description: z.string().trim().min(1).max(255),
209
- reference: z.object({
210
- type: z.string().trim().min(1).max(60),
211
- id: z.string().trim().min(1).max(100)
212
- }),
208
+ /** The caller's record it is for: `order` and its id. */
209
+ referenceType: z.string().trim().min(1).max(60),
210
+ referenceId: z.string().trim().min(1).max(100),
213
211
  /** Minutes the invoice can be paid in (default 30). */
214
212
  expiresInMinutes: z.int().min(1).max(10080).default(30),
215
213
  dedupeKey: DedupeKey.optional(),
216
214
  metadata: InvoiceMetadata.optional(),
217
215
  lines: z.array(InvoiceLineInput).max(100).optional()
218
216
  })).output(Invoice),
219
- getInvoice: oc.route({
217
+ getInvoice: base.route({
220
218
  method: "GET",
221
219
  path: "/payments/invoices/{id}",
222
220
  summary: "An invoice; a pending one is checked with the gateway"
223
221
  }).input(z.object({ id: Id })).output(Invoice),
224
- cancelInvoice: oc.route({
222
+ cancelInvoice: base.route({
225
223
  method: "POST",
226
224
  path: "/payments/invoices/{id}/cancel"
227
225
  }).input(z.object({ id: Id })).output(Invoice),
228
- refund: oc.route({
226
+ refund: base.route({
229
227
  method: "POST",
230
228
  path: "/payments/invoices/{id}/refunds",
231
229
  successStatus: 201,
@@ -240,16 +238,16 @@ const paymentsContract = {
240
238
  refund: Refund,
241
239
  invoice: Invoice
242
240
  })),
243
- refunds: oc.route({
241
+ refunds: base.route({
244
242
  method: "GET",
245
243
  path: "/payments/invoices/{id}/refunds"
246
- }).input(z.object({ id: Id })).output(z.object({ data: z.array(Refund) })),
247
- pluginSettings: oc.route({
244
+ }).input(z.object({ id: Id })).output(listOf(Refund)),
245
+ pluginSettings: base.route({
248
246
  method: "GET",
249
247
  path: "/payments/plugins",
250
248
  summary: "Installed plugins that take payments, with their gateway settings"
251
- }).output(z.object({ data: z.array(PluginPaymentSettings) })),
252
- updatePluginSettings: oc.route({
249
+ }).output(listOf(PluginPaymentSettings)),
250
+ updatePluginSettings: base.route({
253
251
  method: "PUT",
254
252
  path: "/payments/plugins/{plugin}"
255
253
  }).input(z.object({
@@ -257,7 +255,7 @@ const paymentsContract = {
257
255
  defaultGatewayId: Id.nullable(),
258
256
  allowedGatewayIds: z.array(Id).max(50)
259
257
  })).output(PluginPaymentSettings),
260
- invoices: oc.route({
258
+ invoices: base.route({
261
259
  method: "GET",
262
260
  path: "/payments/invoices",
263
261
  summary: "Invoices, newest first"
@@ -266,10 +264,10 @@ const paymentsContract = {
266
264
  source: z.string().max(40).optional(),
267
265
  referenceId: z.string().max(100).optional()
268
266
  })).output(cursorPageOf(Invoice)),
269
- payTestInvoice: oc.route({
267
+ payTestInvoice: base.route({
270
268
  method: "POST",
271
269
  path: "/payments/invoices/{id}/test-pay",
272
270
  summary: "Pay an invoice of the test gateway (development)"
273
271
  }).input(z.object({ id: Id })).output(Invoice)
274
272
  };
275
- export { GatewayConfig, Invoice, InvoiceLine, InvoiceLineInput, InvoiceMetadata, InvoiceStatus, PAYMENT_GATEWAYS, PaymentGateway, PaymentGatewayKind, PluginPaymentSettings, Refund, gatewayTakes, paymentsContract };
273
+ export { GatewayConfig, Invoice, InvoiceLine, InvoiceLineInput, InvoiceMetadata, PaymentGateway, PluginPaymentSettings, Refund, paymentsContract };
@@ -1,26 +1,18 @@
1
1
  import { z } from "zod";
2
2
  /**
3
- * Who did something: a team member (`id` = user id), a plugin (`id` = plugin
4
- * name, e.g. `hr`) or core itself (`system`). Names are resolved when shown,
5
- * unless the response carries them.
3
+ * Who did something, stored as `actorType` with `actorId`: a team member (the
4
+ * user id), a plugin (its name, e.g. `hr`), a customer (the customer id) or
5
+ * core itself (`system`, no id).
6
6
  */
7
- export declare const ActorRef: z.ZodObject<{
8
- type: z.ZodEnum<{
9
- plugin: "plugin";
10
- system: "system";
11
- user: "user";
12
- }>;
13
- id: z.ZodNullable<z.ZodString>;
14
- name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
15
- avatarUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
16
- }, z.core.$strip>;
17
- export type ActorRef = z.infer<typeof ActorRef>;
18
- /** A record in a plugin that an entry points at. */
19
- export declare const EntityRef: z.ZodObject<{
20
- type: z.ZodString;
21
- id: z.ZodString;
22
- }, z.core.$strip>;
23
- export type EntityRef = z.infer<typeof EntityRef>;
7
+ export declare const ActorType: z.ZodEnum<{
8
+ customer: "customer";
9
+ plugin: "plugin";
10
+ system: "system";
11
+ user: "user";
12
+ }>;
13
+ export type ActorType = z.infer<typeof ActorType>;
14
+ /** The type of a plugin's record an entry points at (`entityType`, with `entityId`). */
15
+ export declare const EntityType: z.ZodString;
24
16
  /** An app path inside erxes (`/hr/leaves/abc`), never another site. */
25
17
  export declare const AppLink: z.ZodString;
26
18
  /**
package/dist/platform.js CHANGED
@@ -1,27 +1,14 @@
1
- import { Id } from "./common.js";
1
+ import { ACTOR_TYPES } from "./db/src/enums.js";
2
2
  import { z } from "zod";
3
3
  // src/platform.ts
4
4
  /**
5
- * Who did something: a team member (`id` = user id), a plugin (`id` = plugin
6
- * name, e.g. `hr`) or core itself (`system`). Names are resolved when shown,
7
- * unless the response carries them.
5
+ * Who did something, stored as `actorType` with `actorId`: a team member (the
6
+ * user id), a plugin (its name, e.g. `hr`), a customer (the customer id) or
7
+ * core itself (`system`, no id).
8
8
  */
9
- const ActorRef = z.object({
10
- type: z.enum([
11
- "user",
12
- "plugin",
13
- "system"
14
- ]),
15
- id: z.string().nullable(),
16
- /** A team member's name and picture, where a list includes them (timelines), so it reads at once. */
17
- name: z.string().nullable().optional(),
18
- avatarUrl: z.string().nullable().optional()
19
- });
20
- /** A record in a plugin that an entry points at. */
21
- const EntityRef = z.object({
22
- type: z.string().trim().min(1).max(64),
23
- id: Id
24
- });
9
+ const ActorType = z.enum(ACTOR_TYPES);
10
+ /** The type of a plugin's record an entry points at (`entityType`, with `entityId`). */
11
+ const EntityType = z.string().trim().min(1).max(64);
25
12
  /** An app path inside erxes (`/hr/leaves/abc`), never another site. */
26
13
  const AppLink = z.string().trim().max(500).regex(/^\/(?!\/)[^\s]*$/, "an app path starting with /");
27
14
  /**
@@ -31,4 +18,4 @@ const AppLink = z.string().trim().max(500).regex(/^\/(?!\/)[^\s]*$/, "an app pat
31
18
  const DedupeKey = z.string().trim().min(1).max(200);
32
19
  /** `<source>.<what>`, lower case: `hr.leave.requested`. */
33
20
  const EventType = z.string().trim().max(100).regex(/^[a-z][a-z0-9_]*(\.[a-z][a-z0-9_]*)+$/, "dotted lower-case name, e.g. hr.leave.requested");
34
- export { ActorRef, AppLink, DedupeKey, EntityRef, EventType };
21
+ export { ActorType, AppLink, DedupeKey, EntityType, EventType };