@erxes/core-contract 0.1.0-v2.0 → 0.1.0-v2.1

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 (94) hide show
  1. package/dist/activities.d.ts +21 -14
  2. package/dist/activities.js +6 -10
  3. package/dist/audit.d.ts +13 -17
  4. package/dist/audit.js +9 -9
  5. package/dist/auth.d.ts +33 -35
  6. package/dist/auth.js +8 -7
  7. package/dist/automationDefinition.d.ts +4 -3
  8. package/dist/automationDefinition.js +9 -31
  9. package/dist/automationRuns.d.ts +6 -5
  10. package/dist/automationRuns.js +8 -22
  11. package/dist/automations.d.ts +35 -36
  12. package/dist/automations.js +15 -23
  13. package/dist/common.d.ts +29 -4
  14. package/dist/common.js +30 -10
  15. package/dist/companies.d.ts +34 -34
  16. package/dist/companies.js +6 -5
  17. package/dist/contract/routes.json.js +1794 -0
  18. package/dist/customerAuth.d.ts +222 -0
  19. package/dist/customerAuth.js +180 -0
  20. package/dist/customers.d.ts +51 -54
  21. package/dist/customers.js +7 -12
  22. package/dist/db/src/enums.d.ts +8 -0
  23. package/dist/db/src/enums.js +336 -0
  24. package/dist/db/src/schema/auditStreams.js +6 -14
  25. package/dist/db/src/schema/authTokens.js +4 -6
  26. package/dist/db/src/schema/automations.js +12 -28
  27. package/dist/db/src/schema/common.d.ts +2 -6
  28. package/dist/db/src/schema/common.js +1 -24
  29. package/dist/db/src/schema/companies.js +6 -5
  30. package/dist/db/src/schema/customerAuth.js +101 -0
  31. package/dist/db/src/schema/customers.js +6 -6
  32. package/dist/db/src/schema/events.js +12 -60
  33. package/dist/db/src/schema/fieldValues.js +2 -2
  34. package/dist/db/src/schema/fields.js +10 -28
  35. package/dist/db/src/schema/index.js +21 -20
  36. package/dist/db/src/schema/leadStages.js +5 -10
  37. package/dist/db/src/schema/leads.js +5 -10
  38. package/dist/db/src/schema/oauth.js +3 -3
  39. package/dist/db/src/schema/payments.js +12 -22
  40. package/dist/db/src/schema/platform.js +11 -26
  41. package/dist/db/src/schema/plugins.js +4 -4
  42. package/dist/db/src/schema/products.js +7 -8
  43. package/dist/db/src/schema/rateLimits.js +7 -0
  44. package/dist/db/src/schema/saas.js +3 -9
  45. package/dist/db/src/schema/tags.js +6 -5
  46. package/dist/db/src/schema/transfer.js +12 -32
  47. package/dist/db/src/schema/trash.js +6 -7
  48. package/dist/db/src/schema/users.js +6 -10
  49. package/dist/db/src/schema/views.js +5 -13
  50. package/dist/db/src/schema/webhooks.js +7 -14
  51. package/dist/db/src/table.js +16 -2
  52. package/dist/events.d.ts +19 -23
  53. package/dist/events.js +16 -18
  54. package/dist/fields.d.ts +22 -50
  55. package/dist/fields.js +6 -28
  56. package/dist/files.d.ts +10 -5
  57. package/dist/files.js +4 -3
  58. package/dist/index.d.ts +557 -321
  59. package/dist/index.js +17 -16
  60. package/dist/leads.d.ts +5 -3
  61. package/dist/leads.js +8 -7
  62. package/dist/notifications.d.ts +4 -48
  63. package/dist/notifications.js +7 -73
  64. package/dist/organizations.d.ts +3 -3
  65. package/dist/payments.d.ts +28 -58
  66. package/dist/payments.js +10 -34
  67. package/dist/platform.d.ts +1 -0
  68. package/dist/platform.js +2 -5
  69. package/dist/plugins.d.ts +10 -4
  70. package/dist/plugins.js +19 -9
  71. package/dist/products.d.ts +31 -36
  72. package/dist/products.js +8 -7
  73. package/dist/roles.d.ts +0 -3
  74. package/dist/roles.js +5 -5
  75. package/dist/routes.d.ts +8 -0
  76. package/dist/routes.js +13 -0
  77. package/dist/saas.d.ts +0 -6
  78. package/dist/saas.js +5 -27
  79. package/dist/tags.d.ts +4 -4
  80. package/dist/tags.js +3 -3
  81. package/dist/transfer.d.ts +62 -24
  82. package/dist/transfer.js +15 -36
  83. package/dist/trash.d.ts +23 -4
  84. package/dist/trash.js +5 -5
  85. package/dist/users.d.ts +27 -41
  86. package/dist/users.js +13 -26
  87. package/dist/values.d.ts +159 -0
  88. package/dist/values.js +144 -0
  89. package/dist/views.d.ts +8 -8
  90. package/dist/views.js +8 -21
  91. package/dist/webhooks.d.ts +26 -20
  92. package/dist/webhooks.js +18 -11
  93. package/package.json +4 -1
  94. package/dist/db/src/schema/jobs.js +0 -44
package/dist/payments.js CHANGED
@@ -1,6 +1,8 @@
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 { InvoiceStatus, PaymentGatewayKind } from "./values.js";
5
+ import { CursorQuery, Id, cursorPageOf, isoDate, listOf } from "./common.js";
4
6
  import { Currency } from "./money.js";
5
7
  import { DedupeKey } from "./platform.js";
6
8
  import { PluginName } from "./plugins.js";
@@ -8,27 +10,6 @@ import { oc } from "@orpc/contract";
8
10
  import { createSelectSchema } from "drizzle-zod";
9
11
  import { z } from "zod";
10
12
  // 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
13
  /** What each gateway needs (secrets are write-only: never returned). */
33
14
  const GatewayConfig = z.discriminatedUnion("kind", [z.object({
34
15
  kind: z.literal("qpay"),
@@ -50,7 +31,6 @@ const PaymentGateway = createSelectSchema(paymentGateways, {
50
31
  }).extend({
51
32
  /** Non-secret settings, for display (`invoiceCode`, `sandbox`). */
52
33
  settings: z.record(z.string(), z.unknown()) });
53
- const InvoiceStatus = z.enum(INVOICE_STATUSES);
54
34
  /** The caller's own data on an invoice (order lines, room number): at most 8 KB of JSON, returned in events. */
55
35
  const InvoiceMetadata = z.record(z.string(), z.unknown()).refine((value) => JSON.stringify(value).length <= 8192, "at most 8 KB of JSON");
56
36
  /**
@@ -128,11 +108,7 @@ const Invoice = createSelectSchema(paymentInvoices, {
128
108
  /** What can still be refunded, and how the gateway refunds (`full`: only the whole payment). */
129
109
  refundable: z.object({
130
110
  amount: z.int(),
131
- gateway: z.enum([
132
- "partial",
133
- "full",
134
- "none"
135
- ])
111
+ gateway: z.enum(GATEWAY_REFUND_KINDS)
136
112
  })
137
113
  });
138
114
  const Refund = createSelectSchema(paymentRefunds, {
@@ -172,7 +148,7 @@ const paymentsContract = {
172
148
  gateways: oc.route({
173
149
  method: "GET",
174
150
  path: "/payments/gateways"
175
- }).output(z.object({ data: z.array(PaymentGateway) })),
151
+ }).output(listOf(PaymentGateway)),
176
152
  addGateway: oc.route({
177
153
  method: "POST",
178
154
  path: "/payments/gateways",
@@ -189,7 +165,7 @@ const paymentsContract = {
189
165
  id: Id,
190
166
  name: z.string().trim().min(1).max(80).optional(),
191
167
  config: GatewayConfig.optional(),
192
- status: z.enum(["active", "disabled"]).optional()
168
+ status: z.enum(PAYMENT_GATEWAY_STATUSES).optional()
193
169
  })).output(PaymentGateway),
194
170
  removeGateway: oc.route({
195
171
  method: "DELETE",
@@ -243,12 +219,12 @@ const paymentsContract = {
243
219
  refunds: oc.route({
244
220
  method: "GET",
245
221
  path: "/payments/invoices/{id}/refunds"
246
- }).input(z.object({ id: Id })).output(z.object({ data: z.array(Refund) })),
222
+ }).input(z.object({ id: Id })).output(listOf(Refund)),
247
223
  pluginSettings: oc.route({
248
224
  method: "GET",
249
225
  path: "/payments/plugins",
250
226
  summary: "Installed plugins that take payments, with their gateway settings"
251
- }).output(z.object({ data: z.array(PluginPaymentSettings) })),
227
+ }).output(listOf(PluginPaymentSettings)),
252
228
  updatePluginSettings: oc.route({
253
229
  method: "PUT",
254
230
  path: "/payments/plugins/{plugin}"
@@ -272,4 +248,4 @@ const paymentsContract = {
272
248
  summary: "Pay an invoice of the test gateway (development)"
273
249
  }).input(z.object({ id: Id })).output(Invoice)
274
250
  };
275
- export { GatewayConfig, Invoice, InvoiceLine, InvoiceLineInput, InvoiceMetadata, InvoiceStatus, PAYMENT_GATEWAYS, PaymentGateway, PaymentGatewayKind, PluginPaymentSettings, Refund, gatewayTakes, paymentsContract };
251
+ export { GatewayConfig, Invoice, InvoiceLine, InvoiceLineInput, InvoiceMetadata, PaymentGateway, PluginPaymentSettings, Refund, paymentsContract };
@@ -6,6 +6,7 @@ import { z } from "zod";
6
6
  */
7
7
  export declare const ActorRef: z.ZodObject<{
8
8
  type: z.ZodEnum<{
9
+ customer: "customer";
9
10
  plugin: "plugin";
10
11
  system: "system";
11
12
  user: "user";
package/dist/platform.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { ACTOR_TYPES } from "./db/src/enums.js";
1
2
  import { Id } from "./common.js";
2
3
  import { z } from "zod";
3
4
  // src/platform.ts
@@ -7,11 +8,7 @@ import { z } from "zod";
7
8
  * unless the response carries them.
8
9
  */
9
10
  const ActorRef = z.object({
10
- type: z.enum([
11
- "user",
12
- "plugin",
13
- "system"
14
- ]),
11
+ type: z.enum(ACTOR_TYPES),
15
12
  id: z.string().nullable(),
16
13
  /** A team member's name and picture, where a list includes them (timelines), so it reads at once. */
17
14
  name: z.string().nullable().optional(),
package/dist/plugins.d.ts CHANGED
@@ -40,6 +40,9 @@ export declare const PluginManifest: z.ZodObject<{
40
40
  oauth: z.ZodOptional<z.ZodObject<{
41
41
  redirectUris: z.ZodArray<z.ZodString>;
42
42
  }, z.core.$strip>>;
43
+ customerApp: z.ZodOptional<z.ZodObject<{
44
+ origins: z.ZodArray<z.ZodString>;
45
+ }, z.core.$strip>>;
43
46
  scopes: z.ZodDefault<z.ZodArray<z.ZodEnum<{
44
47
  "activities:write": "activities:write";
45
48
  "audit:write": "audit:write";
@@ -144,7 +147,7 @@ export declare const Plugin: z.ZodObject<{
144
147
  requestedScopes: z.ZodArray<z.ZodString>;
145
148
  grantedScopes: z.ZodArray<z.ZodString>;
146
149
  needsApproval: z.ZodBoolean;
147
- installedAt: z.ZodNullable<z.ZodISODateTime>;
150
+ installedAt: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
148
151
  }, z.core.$strip>;
149
152
  export type Plugin = z.infer<typeof Plugin>;
150
153
  export declare const TokenResponse: z.ZodObject<{
@@ -186,6 +189,9 @@ export declare const pluginsContract: {
186
189
  oauth: z.ZodOptional<z.ZodObject<{
187
190
  redirectUris: z.ZodArray<z.ZodString>;
188
191
  }, z.core.$strip>>;
192
+ customerApp: z.ZodOptional<z.ZodObject<{
193
+ origins: z.ZodArray<z.ZodString>;
194
+ }, z.core.$strip>>;
189
195
  scopes: z.ZodDefault<z.ZodArray<z.ZodEnum<{
190
196
  "activities:write": "activities:write";
191
197
  "audit:write": "audit:write";
@@ -292,7 +298,7 @@ export declare const pluginsContract: {
292
298
  requestedScopes: z.ZodArray<z.ZodString>;
293
299
  grantedScopes: z.ZodArray<z.ZodString>;
294
300
  needsApproval: z.ZodBoolean;
295
- installedAt: z.ZodNullable<z.ZodISODateTime>;
301
+ installedAt: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
296
302
  }, z.core.$strip>>;
297
303
  }, z.core.$strip>, Record<never, never>, Record<never, never>>;
298
304
  install: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
@@ -315,7 +321,7 @@ export declare const pluginsContract: {
315
321
  requestedScopes: z.ZodArray<z.ZodString>;
316
322
  grantedScopes: z.ZodArray<z.ZodString>;
317
323
  needsApproval: z.ZodBoolean;
318
- installedAt: z.ZodNullable<z.ZodISODateTime>;
324
+ installedAt: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
319
325
  }, z.core.$strip>, Record<never, never>, Record<never, never>>;
320
326
  uninstall: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
321
327
  name: z.ZodString;
@@ -337,7 +343,7 @@ export declare const pluginsContract: {
337
343
  requestedScopes: z.ZodArray<z.ZodString>;
338
344
  grantedScopes: z.ZodArray<z.ZodString>;
339
345
  needsApproval: z.ZodBoolean;
340
- installedAt: z.ZodNullable<z.ZodISODateTime>;
346
+ installedAt: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
341
347
  }, z.core.$strip>, Record<never, never>, Record<never, never>>;
342
348
  session: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
343
349
  name: z.ZodString;
package/dist/plugins.js CHANGED
@@ -1,5 +1,6 @@
1
+ import { AUTOMATION_SUBJECTS, CONTENT_TYPES } from "./db/src/enums.js";
1
2
  import { EventPattern } from "./webhooks.js";
2
- import { Id } from "./common.js";
3
+ import { Id, isoDate, listOf } from "./common.js";
3
4
  import { ActionField } from "./automationRuns.js";
4
5
  import { Country } from "./money.js";
5
6
  import { EventType } from "./platform.js";
@@ -32,6 +33,12 @@ const PluginScope = z.enum(PLUGIN_SCOPES);
32
33
  /** Live update topic: `leave-requests`, `leave:abc123`. */
33
34
  const LiveTopic = z.string().trim().regex(/^[a-z0-9][a-z0-9._:-]{0,99}$/, "lower case letters, digits and . _ : -");
34
35
  const HttpsUrl = z.string().trim().check(z.url()).max(500).refine((value) => /^https?:\/\//.test(value), "an http(s) address");
36
+ /**
37
+ * A web origin a customer app runs at: `https://host[:port]`, where
38
+ * `{subdomain}` may stand for a whole label (the organisation's), or
39
+ * `http://localhost[:port]` while developing.
40
+ */
41
+ const AppOrigin = z.string().trim().max(200).regex(/^(https:\/\/(\{subdomain\}|[a-z0-9-]+)(\.(\{subdomain\}|[a-z0-9-]+))+|http:\/\/(localhost|127\.0\.0\.1))(:\d{1,5})?$/, "an origin: https://shop.example.com, https://{subdomain}.shop.example.com or http://localhost:3000");
35
42
  const PluginManifest = z.object({
36
43
  title: z.string().trim().min(1).max(80),
37
44
  version: z.string().trim().min(1).max(40),
@@ -55,6 +62,13 @@ const PluginManifest = z.object({
55
62
  * organisation's (`https://{subdomain}.hr.erxes.io/auth/callback`).
56
63
  */
57
64
  oauth: z.object({ redirectUris: z.array(z.string().trim().max(500).regex(/^https?:\/\/[^\s#]+$/, "an http(s) address without a fragment")).min(1).max(20) }).optional(),
65
+ /**
66
+ * The plugin's app for customers (a shop, tracking, booking). It signs
67
+ * customers in by calling `/customer-auth/*` itself (decision 42); browsers
68
+ * may call `/customer-auth/*` and `/customer/*` only from these origins.
69
+ * Apps without an origin (mobile) are limited by rate instead.
70
+ */
71
+ customerApp: z.object({ origins: z.array(AppOrigin).min(1).max(20) }).optional(),
58
72
  scopes: z.array(PluginScope).max(PLUGIN_SCOPES.length).default([]),
59
73
  /** Actions members can be granted (`hr.leave.approve`), shown in roles. */
60
74
  permissions: z.array(z.object({
@@ -77,11 +91,7 @@ const PluginManifest = z.object({
77
91
  type: EventType,
78
92
  label: z.string().trim().min(1).max(100),
79
93
  description: z.string().trim().max(300).optional(),
80
- subject: z.enum([
81
- "customer",
82
- "company",
83
- "any"
84
- ]).optional(),
94
+ subject: z.enum(AUTOMATION_SUBJECTS).optional(),
85
95
  fields: z.array(ActionField).max(50).default([])
86
96
  })).max(200).optional(),
87
97
  /** Its own record types that get a timeline in erxes (notes, mentions, entries), and who may see it. */
@@ -121,7 +131,7 @@ const PluginManifest = z.object({
121
131
  type: EventType,
122
132
  label: z.string().trim().min(1).max(100),
123
133
  description: z.string().trim().max(300).optional(),
124
- subject: z.enum(["customer", "company"]).optional()
134
+ subject: z.enum(CONTENT_TYPES).optional()
125
135
  })).max(500).optional()
126
136
  });
127
137
  const Plugin = z.object({
@@ -144,7 +154,7 @@ const Plugin = z.object({
144
154
  grantedScopes: z.array(z.string()),
145
155
  /** Asks for scopes the owner hasn't granted yet (a newer version). */
146
156
  needsApproval: z.boolean(),
147
- installedAt: z.iso.datetime().nullable()
157
+ installedAt: isoDate().nullable()
148
158
  });
149
159
  const TokenResponse = z.object({
150
160
  access_token: z.string(),
@@ -178,7 +188,7 @@ const pluginsContract = {
178
188
  method: "GET",
179
189
  path: "/plugins",
180
190
  summary: "Plugins of this deployment, and which are installed here"
181
- }).output(z.object({ data: z.array(Plugin) })),
191
+ }).output(listOf(Plugin)),
182
192
  install: oc.route({
183
193
  method: "POST",
184
194
  path: "/plugins/{name}/install",
@@ -1,9 +1,4 @@
1
1
  import { z } from "zod";
2
- export declare const ProductKind: z.ZodEnum<{
3
- goods: "goods";
4
- service: "service";
5
- }>;
6
- export type ProductKind = z.infer<typeof ProductKind>;
7
2
  export declare const ProductStatus: z.ZodEnum<{
8
3
  active: "active";
9
4
  archived: "archived";
@@ -33,9 +28,9 @@ export declare const Product: z.ZodObject<{
33
28
  widthMm: z.ZodNullable<z.ZodInt>;
34
29
  heightMm: z.ZodNullable<z.ZodInt>;
35
30
  plugins: z.ZodArray<z.ZodString>;
36
- createdAt: z.ZodISODateTime;
37
- updatedAt: z.ZodISODateTime;
38
- archivedAt: z.ZodNullable<z.ZodISODateTime>;
31
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
32
+ updatedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
33
+ archivedAt: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
39
34
  customFields: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString>]>>;
40
35
  }, {
41
36
  out: {};
@@ -46,7 +41,7 @@ export declare const ProductCategory: z.ZodObject<{
46
41
  id: z.ZodString;
47
42
  name: z.ZodString;
48
43
  parentId: z.ZodNullable<z.ZodString>;
49
- createdAt: z.ZodISODateTime;
44
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
50
45
  }, {
51
46
  out: {};
52
47
  in: {};
@@ -110,9 +105,9 @@ export declare const productsContract: {
110
105
  widthMm: z.ZodNullable<z.ZodInt>;
111
106
  heightMm: z.ZodNullable<z.ZodInt>;
112
107
  plugins: z.ZodArray<z.ZodString>;
113
- createdAt: z.ZodISODateTime;
114
- updatedAt: z.ZodISODateTime;
115
- archivedAt: z.ZodNullable<z.ZodISODateTime>;
108
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
109
+ updatedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
110
+ archivedAt: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
116
111
  customFields: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString>]>>;
117
112
  }, {
118
113
  out: {};
@@ -153,9 +148,9 @@ export declare const productsContract: {
153
148
  widthMm: z.ZodNullable<z.ZodInt>;
154
149
  heightMm: z.ZodNullable<z.ZodInt>;
155
150
  plugins: z.ZodArray<z.ZodString>;
156
- createdAt: z.ZodISODateTime;
157
- updatedAt: z.ZodISODateTime;
158
- archivedAt: z.ZodNullable<z.ZodISODateTime>;
151
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
152
+ updatedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
153
+ archivedAt: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
159
154
  customFields: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString>]>>;
160
155
  }, {
161
156
  out: {};
@@ -188,9 +183,9 @@ export declare const productsContract: {
188
183
  widthMm: z.ZodNullable<z.ZodInt>;
189
184
  heightMm: z.ZodNullable<z.ZodInt>;
190
185
  plugins: z.ZodArray<z.ZodString>;
191
- createdAt: z.ZodISODateTime;
192
- updatedAt: z.ZodISODateTime;
193
- archivedAt: z.ZodNullable<z.ZodISODateTime>;
186
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
187
+ updatedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
188
+ archivedAt: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
194
189
  customFields: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString>]>>;
195
190
  }, {
196
191
  out: {};
@@ -244,9 +239,9 @@ export declare const productsContract: {
244
239
  widthMm: z.ZodNullable<z.ZodInt>;
245
240
  heightMm: z.ZodNullable<z.ZodInt>;
246
241
  plugins: z.ZodArray<z.ZodString>;
247
- createdAt: z.ZodISODateTime;
248
- updatedAt: z.ZodISODateTime;
249
- archivedAt: z.ZodNullable<z.ZodISODateTime>;
242
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
243
+ updatedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
244
+ archivedAt: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
250
245
  customFields: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString>]>>;
251
246
  }, {
252
247
  out: {};
@@ -300,9 +295,9 @@ export declare const productsContract: {
300
295
  widthMm: z.ZodNullable<z.ZodInt>;
301
296
  heightMm: z.ZodNullable<z.ZodInt>;
302
297
  plugins: z.ZodArray<z.ZodString>;
303
- createdAt: z.ZodISODateTime;
304
- updatedAt: z.ZodISODateTime;
305
- archivedAt: z.ZodNullable<z.ZodISODateTime>;
298
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
299
+ updatedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
300
+ archivedAt: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
306
301
  customFields: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString>]>>;
307
302
  }, {
308
303
  out: {};
@@ -336,9 +331,9 @@ export declare const productsContract: {
336
331
  widthMm: z.ZodNullable<z.ZodInt>;
337
332
  heightMm: z.ZodNullable<z.ZodInt>;
338
333
  plugins: z.ZodArray<z.ZodString>;
339
- createdAt: z.ZodISODateTime;
340
- updatedAt: z.ZodISODateTime;
341
- archivedAt: z.ZodNullable<z.ZodISODateTime>;
334
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
335
+ updatedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
336
+ archivedAt: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
342
337
  customFields: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString>]>>;
343
338
  }, {
344
339
  out: {};
@@ -371,9 +366,9 @@ export declare const productsContract: {
371
366
  widthMm: z.ZodNullable<z.ZodInt>;
372
367
  heightMm: z.ZodNullable<z.ZodInt>;
373
368
  plugins: z.ZodArray<z.ZodString>;
374
- createdAt: z.ZodISODateTime;
375
- updatedAt: z.ZodISODateTime;
376
- archivedAt: z.ZodNullable<z.ZodISODateTime>;
369
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
370
+ updatedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
371
+ archivedAt: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
377
372
  customFields: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString>]>>;
378
373
  }, {
379
374
  out: {};
@@ -405,9 +400,9 @@ export declare const productsContract: {
405
400
  widthMm: z.ZodNullable<z.ZodInt>;
406
401
  heightMm: z.ZodNullable<z.ZodInt>;
407
402
  plugins: z.ZodArray<z.ZodString>;
408
- createdAt: z.ZodISODateTime;
409
- updatedAt: z.ZodISODateTime;
410
- archivedAt: z.ZodNullable<z.ZodISODateTime>;
403
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
404
+ updatedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
405
+ archivedAt: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
411
406
  customFields: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString>]>>;
412
407
  }, {
413
408
  out: {};
@@ -421,7 +416,7 @@ export declare const productCategoriesContract: {
421
416
  id: z.ZodString;
422
417
  name: z.ZodString;
423
418
  parentId: z.ZodNullable<z.ZodString>;
424
- createdAt: z.ZodISODateTime;
419
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
425
420
  }, {
426
421
  out: {};
427
422
  in: {};
@@ -437,7 +432,7 @@ export declare const productCategoriesContract: {
437
432
  id: z.ZodString;
438
433
  name: z.ZodString;
439
434
  parentId: z.ZodNullable<z.ZodString>;
440
- createdAt: z.ZodISODateTime;
435
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
441
436
  }, {
442
437
  out: {};
443
438
  in: {};
@@ -453,7 +448,7 @@ export declare const productCategoriesContract: {
453
448
  id: z.ZodString;
454
449
  name: z.ZodString;
455
450
  parentId: z.ZodNullable<z.ZodString>;
456
- createdAt: z.ZodISODateTime;
451
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
457
452
  }, {
458
453
  out: {};
459
454
  in: {};
package/dist/products.js CHANGED
@@ -1,13 +1,14 @@
1
- import { PRODUCT_KINDS, PRODUCT_STATUSES, productCategories, products } from "./db/src/schema/products.js";
1
+ import { PRODUCT_STATUSES } from "./db/src/enums.js";
2
+ import { productCategories, products } from "./db/src/schema/products.js";
2
3
  import "./db/src/schema/index.js";
3
- import { CursorQuery, CustomFields, CustomFieldsPatch, Id, IdList, QueryBoolean, cursorPageOf, isoDate } from "./common.js";
4
+ import { ProductKind } from "./values.js";
5
+ import { CursorQuery, CustomFields, CustomFieldsPatch, Id, IdList, QueryBoolean, cursorPageOf, isoDate, listOf } from "./common.js";
4
6
  import { Currency } from "./money.js";
5
7
  import { PluginName } from "./plugins.js";
6
8
  import { oc } from "@orpc/contract";
7
9
  import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
8
10
  import { z } from "zod";
9
11
  // src/products.ts
10
- const ProductKind = z.enum(PRODUCT_KINDS);
11
12
  const ProductStatus = z.enum(PRODUCT_STATUSES);
12
13
  /**
13
14
  * One item of the organisation's shared catalog. Every plugin points at the
@@ -142,7 +143,7 @@ const productsContract = {
142
143
  method: "GET",
143
144
  path: "/products/lookup",
144
145
  summary: "The given products (archived ones too), for order lines: `?ids=a,b`, at most 100"
145
- }).input(z.object({ ids: IdList })).output(z.object({ data: z.array(Product) })),
146
+ }).input(z.object({ ids: IdList })).output(z.object({ data: z.array(Product).max(100) })),
146
147
  create: oc.route({
147
148
  method: "POST",
148
149
  path: "/products",
@@ -164,7 +165,7 @@ const productsContract = {
164
165
  }).input(z.object({
165
166
  ids: z.array(Id).min(1).max(100),
166
167
  used: z.boolean()
167
- })).output(z.object({ data: z.array(Product) })),
168
+ })).output(z.object({ data: z.array(Product).max(100) })),
168
169
  archive: oc.route({
169
170
  method: "POST",
170
171
  path: "/products/{id}/archive",
@@ -181,7 +182,7 @@ const productCategoriesContract = {
181
182
  method: "GET",
182
183
  path: "/product-categories",
183
184
  summary: "Every category, by name"
184
- }).output(z.object({ data: z.array(ProductCategory) })),
185
+ }).output(listOf(ProductCategory)),
185
186
  create: oc.route({
186
187
  method: "POST",
187
188
  path: "/product-categories",
@@ -199,4 +200,4 @@ const productCategoriesContract = {
199
200
  summary: "Delete an empty category; its products lose it. 409 CATEGORY_HAS_CHILDREN while it has subcategories"
200
201
  }).input(z.object({ id: Id })).output(z.object({ ok: z.literal(true) }))
201
202
  };
202
- export { Product, ProductCategory, ProductKind, ProductStatus, productCategoriesContract, productsContract };
203
+ export { Product, ProductCategory, ProductStatus, productCategoriesContract, productsContract };
package/dist/roles.d.ts CHANGED
@@ -130,9 +130,6 @@ export type CorePermission = (typeof CORE_PERMISSIONS)[number]['action'];
130
130
  export declare const OWNER_ONLY_PERMISSIONS: readonly string[];
131
131
  /** `contacts.delete`, `hr.leave.approve`, or `*` (everything grantable). */
132
132
  export declare const PermissionAction: z.ZodString;
133
- /** `owner`, `admin`, `member`, or a custom role's `r_<id>`. */
134
- export declare const RoleKey: z.ZodString;
135
- export type RoleKey = z.infer<typeof RoleKey>;
136
133
  export declare const Role: z.ZodObject<{
137
134
  key: z.ZodString;
138
135
  name: z.ZodString;
package/dist/roles.js CHANGED
@@ -1,5 +1,7 @@
1
1
  import { roles } from "./db/src/schema/users.js";
2
2
  import "./db/src/schema/index.js";
3
+ import { listOf } from "./common.js";
4
+ import { RoleKey } from "./values.js";
3
5
  import { oc } from "@orpc/contract";
4
6
  import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
5
7
  import { z } from "zod";
@@ -164,8 +166,6 @@ const CORE_PERMISSIONS = [
164
166
  const OWNER_ONLY_PERMISSIONS = CORE_PERMISSIONS.filter((permission) => "ownerOnly" in permission && permission.ownerOnly).map((permission) => permission.action);
165
167
  /** `contacts.delete`, `hr.leave.approve`, or `*` (everything grantable). */
166
168
  const PermissionAction = z.string().trim().regex(/^(\*|[a-z][a-z0-9_]*(\.[a-z][a-z0-9_]*)+)$/, "an action like contacts.delete");
167
- /** `owner`, `admin`, `member`, or a custom role's `r_<id>`. */
168
- const RoleKey = z.string().trim().regex(/^(owner|admin|member|r_[A-Za-z0-9]{6,40})$/, "a role");
169
169
  const Role = createSelectSchema(roles).pick({
170
170
  key: true,
171
171
  name: true,
@@ -200,12 +200,12 @@ const rolesContract = {
200
200
  method: "GET",
201
201
  path: "/roles",
202
202
  summary: "Roles of the organisation, with member counts"
203
- }).output(z.object({ data: z.array(Role) })),
203
+ }).output(listOf(Role)),
204
204
  permissions: oc.route({
205
205
  method: "GET",
206
206
  path: "/permissions",
207
207
  summary: "Every action a role can include: core's and installed plugins'"
208
- }).output(z.object({ data: z.array(PermissionInfo) })),
208
+ }).output(listOf(PermissionInfo)),
209
209
  create: oc.route({
210
210
  method: "POST",
211
211
  path: "/roles",
@@ -226,4 +226,4 @@ const rolesContract = {
226
226
  summary: "Delete a custom role nobody has (roles.manage); 409 ROLE_IN_USE"
227
227
  }).input(z.object({ key: RoleKey })).output(z.object({ ok: z.literal(true) }))
228
228
  };
229
- export { CORE_PERMISSIONS, OWNER_ONLY_PERMISSIONS, PermissionAction, PermissionInfo, Role, RoleKey, rolesContract };
229
+ export { CORE_PERMISSIONS, OWNER_ONLY_PERMISSIONS, PermissionAction, PermissionInfo, Role, rolesContract };
@@ -0,0 +1,8 @@
1
+ import { AnyContractRouter } from "@orpc/contract";
2
+ /**
3
+ * Every procedure's method and path, without its schemas (`pnpm openapi` writes
4
+ * routes.json). Pass it to `OpenAPILink` and type the client with
5
+ * `ContractRouterClient<typeof coreContract>` from an `import type`: the client
6
+ * then loads no table and no drizzle.
7
+ */
8
+ export declare const coreRoutes: AnyContractRouter;
package/dist/routes.js ADDED
@@ -0,0 +1,13 @@
1
+ import routes_default from "./contract/routes.json.js";
2
+ import { isContractProcedure } from "@orpc/contract";
3
+ // src/routes.ts
4
+ const isRouter = (value) => isContractProcedure(value) || typeof value === "object" && value !== null && Object.values(value).every(isRouter);
5
+ if (!isRouter(routes_default)) throw new Error("routes.json is not a contract router: run pnpm openapi");
6
+ /**
7
+ * Every procedure's method and path, without its schemas (`pnpm openapi` writes
8
+ * routes.json). Pass it to `OpenAPILink` and type the client with
9
+ * `ContractRouterClient<typeof coreContract>` from an `import type`: the client
10
+ * then loads no table and no drizzle.
11
+ */
12
+ const coreRoutes = routes_default;
13
+ export { coreRoutes };
package/dist/saas.d.ts CHANGED
@@ -6,17 +6,11 @@ export declare const PluginTier: z.ZodEnum<{
6
6
  pro: "pro";
7
7
  }>;
8
8
  export type PluginTier = z.infer<typeof PluginTier>;
9
- /** A plugin's billing status on erxes.io: `past_due` while Stripe retries, `canceling` until the period ends. */
10
9
  export declare const EntitlementStatus: z.ZodEnum<{
11
10
  active: "active";
12
11
  canceling: "canceling";
13
12
  past_due: "past_due";
14
13
  }>;
15
- /**
16
- * What a plugin may do here: `full`; `warning` (payment retrying or ending
17
- * at period end — everything still works); `read_only` (it left the plan:
18
- * reads and exports for the grace period); `off` (not in the plan).
19
- */
20
14
  export declare const PluginAccess: z.ZodEnum<{
21
15
  full: "full";
22
16
  off: "off";
package/dist/saas.js CHANGED
@@ -1,35 +1,13 @@
1
+ import { ENTITLEMENT_STATUSES, ORGANIZATION_STATUSES, PLUGIN_ACCESS, PLUGIN_TIERS } from "./db/src/enums.js";
1
2
  import { OrganizationRegion } from "./organizations.js";
2
3
  import { oc } from "@orpc/contract";
3
4
  import { z } from "zod";
4
5
  // src/saas.ts
5
6
  /** erxes.io's plugin tiers: Free is never billed; Plus and Pro have their own monthly prices. */
6
- const PluginTier = z.enum([
7
- "free",
8
- "plus",
9
- "pro"
10
- ]);
11
- /** A plugin's billing status on erxes.io: `past_due` while Stripe retries, `canceling` until the period ends. */
12
- const EntitlementStatus = z.enum([
13
- "active",
14
- "past_due",
15
- "canceling"
16
- ]);
17
- /**
18
- * What a plugin may do here: `full`; `warning` (payment retrying or ending
19
- * at period end — everything still works); `read_only` (it left the plan:
20
- * reads and exports for the grace period); `off` (not in the plan).
21
- */
22
- const PluginAccess = z.enum([
23
- "full",
24
- "warning",
25
- "read_only",
26
- "off"
27
- ]);
28
- const OrganizationStatus = z.enum([
29
- "active",
30
- "suspended",
31
- "inactive"
32
- ]);
7
+ const PluginTier = z.enum(PLUGIN_TIERS);
8
+ const EntitlementStatus = z.enum(ENTITLEMENT_STATUSES);
9
+ const PluginAccess = z.enum(PLUGIN_ACCESS);
10
+ const OrganizationStatus = z.enum(ORGANIZATION_STATUSES);
33
11
  /**
34
12
  * erxes.io → core: create (or rename, or enable/disable) an organisation's
35
13
  * workspace. `PUT /core/v1/saas/organizations/{id}` with
package/dist/tags.d.ts CHANGED
@@ -7,7 +7,7 @@ export declare const Tag: z.ZodObject<{
7
7
  }>;
8
8
  name: z.ZodString;
9
9
  colorCode: z.ZodNullable<z.ZodString>;
10
- createdAt: z.ZodISODateTime;
10
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
11
11
  }, {
12
12
  out: {};
13
13
  in: {};
@@ -30,7 +30,7 @@ export declare const tagsContract: {
30
30
  }>;
31
31
  name: z.ZodString;
32
32
  colorCode: z.ZodNullable<z.ZodString>;
33
- createdAt: z.ZodISODateTime;
33
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
34
34
  }, {
35
35
  out: {};
36
36
  in: {};
@@ -54,7 +54,7 @@ export declare const tagsContract: {
54
54
  }>;
55
55
  name: z.ZodString;
56
56
  colorCode: z.ZodNullable<z.ZodString>;
57
- createdAt: z.ZodISODateTime;
57
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
58
58
  }, {
59
59
  out: {};
60
60
  in: {};
@@ -74,7 +74,7 @@ export declare const tagsContract: {
74
74
  }>;
75
75
  name: z.ZodString;
76
76
  colorCode: z.ZodNullable<z.ZodString>;
77
- createdAt: z.ZodISODateTime;
77
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
78
78
  }, {
79
79
  out: {};
80
80
  in: {};
package/dist/tags.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { tags } from "./db/src/schema/tags.js";
2
2
  import "./db/src/schema/index.js";
3
- import { ContentType, Id, isoDate } from "./common.js";
3
+ import { ContentType, Id, isoDate, listOf } from "./common.js";
4
4
  import { oc } from "@orpc/contract";
5
5
  import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
6
6
  import { z } from "zod";
@@ -33,12 +33,12 @@ const tagsContract = {
33
33
  }).input(z.object({
34
34
  type: ContentType,
35
35
  search: z.string().trim().max(100).optional()
36
- })).output(z.object({ data: z.array(Tag) })),
36
+ })).output(listOf(Tag)),
37
37
  create: oc.route({
38
38
  method: "POST",
39
39
  path: "/tags",
40
40
  successStatus: 201,
41
- summary: "Create a tag. 409 TAG_EXISTS when the name is taken for the type"
41
+ summary: "Create a tag. 409 TAG_EXISTS when the name is taken for the type, 409 TAG_LIMIT when the type already has LIST_MAX (1000) tags"
42
42
  }).input(TagFields.required({
43
43
  type: true,
44
44
  name: true