@erxes/core-contract 0.1.0-v2.1 → 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 (77) hide show
  1. package/dist/activities.d.ts +1387 -139
  2. package/dist/activities.js +90 -30
  3. package/dist/audit.d.ts +1081 -33
  4. package/dist/audit.js +28 -14
  5. package/dist/auth.d.ts +2834 -26
  6. package/dist/auth.js +47 -18
  7. package/dist/automationRuns.d.ts +7 -9
  8. package/dist/automationRuns.js +12 -13
  9. package/dist/automations.d.ts +2443 -61
  10. package/dist/automations.js +41 -21
  11. package/dist/client.d.ts +30704 -0
  12. package/dist/client.js +62 -0
  13. package/dist/common.d.ts +0 -13
  14. package/dist/common.js +1 -13
  15. package/dist/companies.d.ts +1120 -10
  16. package/dist/companies.js +27 -12
  17. package/dist/contract/routes.json.js +17 -1
  18. package/dist/customerAuth.d.ts +1456 -17
  19. package/dist/customerAuth.js +33 -16
  20. package/dist/customers.d.ts +1232 -11
  21. package/dist/customers.js +28 -13
  22. package/dist/{automationDefinition.d.ts → db/src/automationDefinition.d.ts} +2 -2
  23. package/dist/{automationDefinition.js → db/src/automationDefinition.js} +2 -2
  24. package/dist/db/src/enums.js +1 -3
  25. package/dist/db/src/schema/automations.d.ts +1 -0
  26. package/dist/db/src/schema/automations.js +3 -3
  27. package/dist/db/src/schema/index.d.ts +3 -0
  28. package/dist/db/src/schema/index.js +3 -2
  29. package/dist/db/src/schema/leads.js +2 -2
  30. package/dist/db/src/schema/notes.js +92 -0
  31. package/dist/db/src/schema/payments.js +2 -2
  32. package/dist/db/src/schema/platform.js +0 -5
  33. package/dist/db/src/schema/plugins.js +7 -2
  34. package/dist/db/src/schema/transfer.js +2 -2
  35. package/dist/errors.d.ts +516 -0
  36. package/dist/errors.js +218 -0
  37. package/dist/events.d.ts +570 -121
  38. package/dist/events.js +41 -24
  39. package/dist/fields.d.ts +1456 -16
  40. package/dist/fields.js +27 -19
  41. package/dist/files.d.ts +761 -62
  42. package/dist/files.js +32 -21
  43. package/dist/index.d.ts +25187 -618
  44. package/dist/index.js +8 -7
  45. package/dist/leads.d.ts +1105 -21
  46. package/dist/leads.js +31 -13
  47. package/dist/notifications.d.ts +689 -48
  48. package/dist/notifications.js +38 -18
  49. package/dist/organizations.d.ts +260 -2
  50. package/dist/organizations.js +21 -2
  51. package/dist/payments.d.ts +1766 -62
  52. package/dist/payments.js +48 -26
  53. package/dist/platform.d.ts +12 -21
  54. package/dist/platform.js +7 -17
  55. package/dist/plugins.d.ts +802 -71
  56. package/dist/plugins.js +48 -27
  57. package/dist/products.d.ts +1380 -17
  58. package/dist/products.js +32 -16
  59. package/dist/roles.d.ts +560 -5
  60. package/dist/roles.js +20 -6
  61. package/dist/saas.d.ts +164 -2
  62. package/dist/saas.js +9 -2
  63. package/dist/tags.d.ts +340 -4
  64. package/dist/tags.js +14 -6
  65. package/dist/transfer.d.ts +1299 -12
  66. package/dist/transfer.js +32 -13
  67. package/dist/trash.d.ts +278 -21
  68. package/dist/trash.js +23 -16
  69. package/dist/users.d.ts +1206 -18
  70. package/dist/users.js +35 -13
  71. package/dist/values.d.ts +0 -9
  72. package/dist/values.js +2 -7
  73. package/dist/views.d.ts +396 -5
  74. package/dist/views.js +10 -7
  75. package/dist/webhooks.d.ts +765 -9
  76. package/dist/webhooks.js +18 -10
  77. package/package.json +6 -2
package/dist/payments.js CHANGED
@@ -1,14 +1,15 @@
1
1
  import { GATEWAY_REFUND_KINDS, PAYMENT_GATEWAY_STATUSES } from "./db/src/enums.js";
2
2
  import { paymentGateways, paymentInvoices, paymentPluginSettings, paymentRefunds } from "./db/src/schema/payments.js";
3
3
  import "./db/src/schema/index.js";
4
+ import { COMMON_ERRORS, ERRORS } from "./errors.js";
4
5
  import { InvoiceStatus, PaymentGatewayKind } from "./values.js";
5
6
  import { CursorQuery, Id, cursorPageOf, isoDate, listOf } from "./common.js";
6
7
  import { Currency } from "./money.js";
7
8
  import { DedupeKey } from "./platform.js";
8
9
  import { PluginName } from "./plugins.js";
9
10
  import { oc } from "@orpc/contract";
10
- import { createSelectSchema } from "drizzle-zod";
11
11
  import { z } from "zod";
12
+ import { createSelectSchema } from "drizzle-zod";
12
13
  // src/payments.ts
13
14
  /** What each gateway needs (secrets are write-only: never returned). */
14
15
  const GatewayConfig = z.discriminatedUnion("kind", [z.object({
@@ -88,6 +89,9 @@ const Invoice = createSelectSchema(paymentInvoices, {
88
89
  /** ISO 4217. */
89
90
  currency: true,
90
91
  description: true,
92
+ /** The caller's record it is for (`order` and its id). */
93
+ referenceType: true,
94
+ referenceId: true,
91
95
  status: true,
92
96
  metadata: true,
93
97
  lines: true,
@@ -100,11 +104,8 @@ const Invoice = createSelectSchema(paymentInvoices, {
100
104
  paidAt: true,
101
105
  createdAt: true
102
106
  }).extend({
107
+ /** The gateway's kind, joined in the query. */
103
108
  gatewayKind: PaymentGatewayKind,
104
- reference: z.object({
105
- type: z.string(),
106
- id: z.string()
107
- }),
108
109
  /** What can still be refunded, and how the gateway refunds (`full`: only the whole payment). */
109
110
  refundable: z.object({
110
111
  amount: z.int(),
@@ -125,11 +126,11 @@ const Refund = createSelectSchema(paymentRefunds, {
125
126
  method: true,
126
127
  status: true,
127
128
  error: true,
129
+ /** Who asked: a team member (`requestedBy` = user id), a plugin (its name) or `system`. */
130
+ requestedByType: true,
131
+ requestedBy: true,
128
132
  createdAt: true
129
- }).extend({ requestedBy: z.object({
130
- type: z.string(),
131
- id: z.string().nullable()
132
- }) });
133
+ });
133
134
  /** How a plugin takes payments here: its default gateway, and the only ones it may use (none: any). */
134
135
  const PluginPaymentSettings = createSelectSchema(paymentPluginSettings, {
135
136
  defaultGatewayId: () => Id,
@@ -144,12 +145,34 @@ const PluginPaymentSettings = createSelectSchema(paymentPluginSettings, {
144
145
  * made through them for plugins' records. Paid invoices publish
145
146
  * `core.payment.paid` (webhooks, automations, the plugin's own consumer).
146
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
+ });
147
170
  const paymentsContract = {
148
- gateways: oc.route({
171
+ gateways: base.route({
149
172
  method: "GET",
150
173
  path: "/payments/gateways"
151
174
  }).output(listOf(PaymentGateway)),
152
- addGateway: oc.route({
175
+ addGateway: base.route({
153
176
  method: "POST",
154
177
  path: "/payments/gateways",
155
178
  successStatus: 201,
@@ -158,7 +181,7 @@ const paymentsContract = {
158
181
  name: z.string().trim().min(1).max(80),
159
182
  config: GatewayConfig
160
183
  })).output(PaymentGateway),
161
- updateGateway: oc.route({
184
+ updateGateway: base.route({
162
185
  method: "PATCH",
163
186
  path: "/payments/gateways/{id}"
164
187
  }).input(z.object({
@@ -167,12 +190,12 @@ const paymentsContract = {
167
190
  config: GatewayConfig.optional(),
168
191
  status: z.enum(PAYMENT_GATEWAY_STATUSES).optional()
169
192
  })).output(PaymentGateway),
170
- removeGateway: oc.route({
193
+ removeGateway: base.route({
171
194
  method: "DELETE",
172
195
  path: "/payments/gateways/{id}",
173
196
  summary: "Remove a gateway without invoices (turn it off otherwise)"
174
197
  }).input(z.object({ id: Id })).output(z.object({ ok: z.literal(true) })),
175
- createInvoice: oc.route({
198
+ createInvoice: base.route({
176
199
  method: "POST",
177
200
  path: "/payments/invoices",
178
201
  successStatus: 201,
@@ -182,26 +205,25 @@ const paymentsContract = {
182
205
  amount: z.int().min(1).max(1e11),
183
206
  currency: Currency.optional(),
184
207
  description: z.string().trim().min(1).max(255),
185
- reference: z.object({
186
- type: z.string().trim().min(1).max(60),
187
- id: z.string().trim().min(1).max(100)
188
- }),
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),
189
211
  /** Minutes the invoice can be paid in (default 30). */
190
212
  expiresInMinutes: z.int().min(1).max(10080).default(30),
191
213
  dedupeKey: DedupeKey.optional(),
192
214
  metadata: InvoiceMetadata.optional(),
193
215
  lines: z.array(InvoiceLineInput).max(100).optional()
194
216
  })).output(Invoice),
195
- getInvoice: oc.route({
217
+ getInvoice: base.route({
196
218
  method: "GET",
197
219
  path: "/payments/invoices/{id}",
198
220
  summary: "An invoice; a pending one is checked with the gateway"
199
221
  }).input(z.object({ id: Id })).output(Invoice),
200
- cancelInvoice: oc.route({
222
+ cancelInvoice: base.route({
201
223
  method: "POST",
202
224
  path: "/payments/invoices/{id}/cancel"
203
225
  }).input(z.object({ id: Id })).output(Invoice),
204
- refund: oc.route({
226
+ refund: base.route({
205
227
  method: "POST",
206
228
  path: "/payments/invoices/{id}/refunds",
207
229
  successStatus: 201,
@@ -216,16 +238,16 @@ const paymentsContract = {
216
238
  refund: Refund,
217
239
  invoice: Invoice
218
240
  })),
219
- refunds: oc.route({
241
+ refunds: base.route({
220
242
  method: "GET",
221
243
  path: "/payments/invoices/{id}/refunds"
222
244
  }).input(z.object({ id: Id })).output(listOf(Refund)),
223
- pluginSettings: oc.route({
245
+ pluginSettings: base.route({
224
246
  method: "GET",
225
247
  path: "/payments/plugins",
226
248
  summary: "Installed plugins that take payments, with their gateway settings"
227
249
  }).output(listOf(PluginPaymentSettings)),
228
- updatePluginSettings: oc.route({
250
+ updatePluginSettings: base.route({
229
251
  method: "PUT",
230
252
  path: "/payments/plugins/{plugin}"
231
253
  }).input(z.object({
@@ -233,7 +255,7 @@ const paymentsContract = {
233
255
  defaultGatewayId: Id.nullable(),
234
256
  allowedGatewayIds: z.array(Id).max(50)
235
257
  })).output(PluginPaymentSettings),
236
- invoices: oc.route({
258
+ invoices: base.route({
237
259
  method: "GET",
238
260
  path: "/payments/invoices",
239
261
  summary: "Invoices, newest first"
@@ -242,7 +264,7 @@ const paymentsContract = {
242
264
  source: z.string().max(40).optional(),
243
265
  referenceId: z.string().max(100).optional()
244
266
  })).output(cursorPageOf(Invoice)),
245
- payTestInvoice: oc.route({
267
+ payTestInvoice: base.route({
246
268
  method: "POST",
247
269
  path: "/payments/invoices/{id}/test-pay",
248
270
  summary: "Pay an invoice of the test gateway (development)"
@@ -1,27 +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
- customer: "customer";
10
- plugin: "plugin";
11
- system: "system";
12
- user: "user";
13
- }>;
14
- id: z.ZodNullable<z.ZodString>;
15
- name: z.ZodOptional<z.ZodNullable<z.ZodString>>;
16
- avatarUrl: z.ZodOptional<z.ZodNullable<z.ZodString>>;
17
- }, z.core.$strip>;
18
- export type ActorRef = z.infer<typeof ActorRef>;
19
- /** A record in a plugin that an entry points at. */
20
- export declare const EntityRef: z.ZodObject<{
21
- type: z.ZodString;
22
- id: z.ZodString;
23
- }, z.core.$strip>;
24
- 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;
25
16
  /** An app path inside erxes (`/hr/leaves/abc`), never another site. */
26
17
  export declare const AppLink: z.ZodString;
27
18
  /**
package/dist/platform.js CHANGED
@@ -1,24 +1,14 @@
1
1
  import { ACTOR_TYPES } from "./db/src/enums.js";
2
- import { Id } from "./common.js";
3
2
  import { z } from "zod";
4
3
  // src/platform.ts
5
4
  /**
6
- * Who did something: a team member (`id` = user id), a plugin (`id` = plugin
7
- * name, e.g. `hr`) or core itself (`system`). Names are resolved when shown,
8
- * 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).
9
8
  */
10
- const ActorRef = z.object({
11
- type: z.enum(ACTOR_TYPES),
12
- id: z.string().nullable(),
13
- /** A team member's name and picture, where a list includes them (timelines), so it reads at once. */
14
- name: z.string().nullable().optional(),
15
- avatarUrl: z.string().nullable().optional()
16
- });
17
- /** A record in a plugin that an entry points at. */
18
- const EntityRef = z.object({
19
- type: z.string().trim().min(1).max(64),
20
- id: Id
21
- });
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);
22
12
  /** An app path inside erxes (`/hr/leaves/abc`), never another site. */
23
13
  const AppLink = z.string().trim().max(500).regex(/^\/(?!\/)[^\s]*$/, "an app path starting with /");
24
14
  /**
@@ -28,4 +18,4 @@ const AppLink = z.string().trim().max(500).regex(/^\/(?!\/)[^\s]*$/, "an app pat
28
18
  const DedupeKey = z.string().trim().min(1).max(200);
29
19
  /** `<source>.<what>`, lower case: `hr.leave.requested`. */
30
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");
31
- export { ActorRef, AppLink, DedupeKey, EntityRef, EventType };
21
+ export { ActorType, AppLink, DedupeKey, EntityType, EventType };