@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/products.js CHANGED
@@ -1,13 +1,15 @@
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 { COMMON_ERRORS, ERRORS } from "./errors.js";
5
+ import { ProductKind } from "./values.js";
6
+ import { CursorQuery, CustomFields, CustomFieldsPatch, Id, IdList, QueryBoolean, cursorPageOf, isoDate, listOf } from "./common.js";
4
7
  import { Currency } from "./money.js";
5
8
  import { PluginName } from "./plugins.js";
6
9
  import { oc } from "@orpc/contract";
7
- import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
8
10
  import { z } from "zod";
11
+ import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
9
12
  // src/products.ts
10
- const ProductKind = z.enum(PRODUCT_KINDS);
11
13
  const ProductStatus = z.enum(PRODUCT_STATUSES);
12
14
  /**
13
15
  * One item of the organisation's shared catalog. Every plugin points at the
@@ -118,8 +120,23 @@ const CategoryFields = createUpdateSchema(productCategories, {
118
120
  * Products are archived, never deleted: orders and invoices keep pointing at
119
121
  * them. Plugins read with `products:read` and write with `products:write`.
120
122
  */
123
+ const { CATEGORY_HAS_CHILDREN, INVALID_CATEGORY, INVALID_FIELD, INVALID_FIELD_VALUE, INVALID_FILE, INVALID_PRODUCT, LIMIT_EXCEEDED, NOTHING_TO_RETRY, PLUGIN_NOT_INSTALLED, SUBJECT_REQUIRED } = ERRORS;
124
+ /** What these procedures answer with besides the common errors. */
125
+ const base = oc.errors({
126
+ ...COMMON_ERRORS,
127
+ CATEGORY_HAS_CHILDREN,
128
+ INVALID_CATEGORY,
129
+ INVALID_FIELD,
130
+ INVALID_FIELD_VALUE,
131
+ INVALID_FILE,
132
+ INVALID_PRODUCT,
133
+ LIMIT_EXCEEDED,
134
+ NOTHING_TO_RETRY,
135
+ PLUGIN_NOT_INSTALLED,
136
+ SUBJECT_REQUIRED
137
+ });
121
138
  const productsContract = {
122
- list: oc.route({
139
+ list: base.route({
123
140
  method: "GET",
124
141
  path: "/products",
125
142
  summary: "Products, newest first. A plugin gets the products it uses unless `all`; members filter by `plugin`"
@@ -134,69 +151,69 @@ const productsContract = {
134
151
  /** A filter on `views.fields({ recordType: 'product' })`: JSON of a condition group (`RecordFilter`), as views save it. */
135
152
  filter: z.string().max(2e4).optional()
136
153
  })).output(cursorPageOf(Product)),
137
- get: oc.route({
154
+ get: base.route({
138
155
  method: "GET",
139
156
  path: "/products/{id}"
140
157
  }).input(z.object({ id: Id })).output(Product),
141
- lookup: oc.route({
158
+ lookup: base.route({
142
159
  method: "GET",
143
160
  path: "/products/lookup",
144
161
  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
- create: oc.route({
162
+ }).input(z.object({ ids: IdList })).output(z.object({ data: z.array(Product).max(100) })),
163
+ create: base.route({
147
164
  method: "POST",
148
165
  path: "/products",
149
166
  successStatus: 201,
150
- summary: "Add a product. 409 PRODUCT_CODE_EXISTS / PRODUCT_BARCODE_EXISTS with the existing product's id in `data.productId` (a plugin can `use` it instead); 400 INVALID_CATEGORY, INVALID_FILE, PLUGIN_NOT_INSTALLED"
167
+ summary: "Add a product. 409 TAKEN for a code or barcode, with the existing product's id in `data.id` (a plugin can `use` it instead); 400 INVALID_CATEGORY, INVALID_FILE, PLUGIN_NOT_INSTALLED"
151
168
  }).input(ProductFields.required({
152
169
  kind: true,
153
170
  name: true
154
171
  })).output(Product),
155
- update: oc.route({
172
+ update: base.route({
156
173
  method: "PATCH",
157
174
  path: "/products/{id}",
158
175
  summary: "Change a product (`plugins`: members only). Errors as for create"
159
176
  }).input(ProductFields.extend({ id: Id }).refine((value) => Object.keys(value).some((key) => key !== "id"), "nothing to update")).output(Product),
160
- use: oc.route({
177
+ use: base.route({
161
178
  method: "POST",
162
179
  path: "/products/use",
163
180
  summary: "A plugin starts (`used`) or stops using products, so they appear in its lists (plugins only)"
164
181
  }).input(z.object({
165
182
  ids: z.array(Id).min(1).max(100),
166
183
  used: z.boolean()
167
- })).output(z.object({ data: z.array(Product) })),
168
- archive: oc.route({
184
+ })).output(z.object({ data: z.array(Product).max(100) })),
185
+ archive: base.route({
169
186
  method: "POST",
170
187
  path: "/products/{id}/archive",
171
188
  summary: "Take a product out of lists and pickers; orders and invoices keep it"
172
189
  }).input(z.object({ id: Id })).output(Product),
173
- restore: oc.route({
190
+ restore: base.route({
174
191
  method: "POST",
175
192
  path: "/products/{id}/restore"
176
193
  }).input(z.object({ id: Id })).output(Product)
177
194
  };
178
195
  /** Groups of products, nested by `parentId`. */
179
196
  const productCategoriesContract = {
180
- list: oc.route({
197
+ list: base.route({
181
198
  method: "GET",
182
199
  path: "/product-categories",
183
200
  summary: "Every category, by name"
184
- }).output(z.object({ data: z.array(ProductCategory) })),
185
- create: oc.route({
201
+ }).output(listOf(ProductCategory)),
202
+ create: base.route({
186
203
  method: "POST",
187
204
  path: "/product-categories",
188
205
  successStatus: 201,
189
- summary: "409 CATEGORY_EXISTS (same name under the same parent); 400 INVALID_CATEGORY"
206
+ summary: "409 TAKEN (same name under the same parent); 400 INVALID_CATEGORY"
190
207
  }).input(CategoryFields.required({ name: true })).output(ProductCategory),
191
- update: oc.route({
208
+ update: base.route({
192
209
  method: "PATCH",
193
210
  path: "/product-categories/{id}",
194
- summary: "409 CATEGORY_EXISTS; 400 INVALID_CATEGORY (unknown parent, or one of its own)"
211
+ summary: "409 TAKEN; 400 INVALID_CATEGORY (unknown parent, or one of its own)"
195
212
  }).input(CategoryFields.extend({ id: Id }).refine((value) => Object.keys(value).some((key) => key !== "id"), "nothing to update")).output(ProductCategory),
196
- remove: oc.route({
213
+ remove: base.route({
197
214
  method: "DELETE",
198
215
  path: "/product-categories/{id}",
199
216
  summary: "Delete an empty category; its products lose it. 409 CATEGORY_HAS_CHILDREN while it has subcategories"
200
217
  }).input(z.object({ id: Id })).output(z.object({ ok: z.literal(true) }))
201
218
  };
202
- export { Product, ProductCategory, ProductKind, ProductStatus, productCategoriesContract, productsContract };
219
+ export { Product, ProductCategory, ProductStatus, productCategoriesContract, productsContract };