@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.
- package/dist/activities.d.ts +1394 -139
- package/dist/activities.js +96 -40
- package/dist/audit.d.ts +1092 -48
- package/dist/audit.js +37 -23
- package/dist/auth.d.ts +2867 -61
- package/dist/auth.js +55 -25
- package/dist/automationRuns.d.ts +12 -13
- package/dist/automationRuns.js +15 -30
- package/dist/automations.d.ts +2474 -93
- package/dist/automations.js +56 -44
- package/dist/client.d.ts +30704 -0
- package/dist/client.js +62 -0
- package/dist/common.d.ts +28 -16
- package/dist/common.js +30 -22
- package/dist/companies.d.ts +1154 -44
- package/dist/companies.js +33 -17
- package/dist/contract/routes.json.js +1810 -0
- package/dist/customerAuth.d.ts +1661 -0
- package/dist/customerAuth.js +197 -0
- package/dist/customers.d.ts +1283 -65
- package/dist/customers.js +35 -25
- package/dist/{automationDefinition.d.ts → db/src/automationDefinition.d.ts} +4 -3
- package/dist/{automationDefinition.js → db/src/automationDefinition.js} +10 -32
- package/dist/db/src/enums.d.ts +8 -0
- package/dist/db/src/enums.js +334 -0
- package/dist/db/src/schema/auditStreams.js +6 -14
- package/dist/db/src/schema/authTokens.js +4 -6
- package/dist/db/src/schema/automations.d.ts +1 -0
- package/dist/db/src/schema/automations.js +15 -31
- package/dist/db/src/schema/common.d.ts +2 -6
- package/dist/db/src/schema/common.js +1 -24
- package/dist/db/src/schema/companies.js +6 -5
- package/dist/db/src/schema/customerAuth.js +101 -0
- package/dist/db/src/schema/customers.js +6 -6
- package/dist/db/src/schema/events.js +12 -60
- package/dist/db/src/schema/fieldValues.js +2 -2
- package/dist/db/src/schema/fields.js +10 -28
- package/dist/db/src/schema/index.d.ts +3 -0
- package/dist/db/src/schema/index.js +22 -20
- package/dist/db/src/schema/leadStages.js +5 -10
- package/dist/db/src/schema/leads.js +6 -11
- package/dist/db/src/schema/notes.js +92 -0
- package/dist/db/src/schema/oauth.js +3 -3
- package/dist/db/src/schema/payments.js +13 -23
- package/dist/db/src/schema/platform.js +11 -31
- package/dist/db/src/schema/plugins.js +10 -5
- package/dist/db/src/schema/products.js +7 -8
- package/dist/db/src/schema/rateLimits.js +7 -0
- package/dist/db/src/schema/saas.js +3 -9
- package/dist/db/src/schema/tags.js +6 -5
- package/dist/db/src/schema/transfer.js +13 -33
- package/dist/db/src/schema/trash.js +6 -7
- package/dist/db/src/schema/users.js +6 -10
- package/dist/db/src/schema/views.js +5 -13
- package/dist/db/src/schema/webhooks.js +7 -14
- package/dist/db/src/table.js +16 -2
- package/dist/errors.d.ts +516 -0
- package/dist/errors.js +218 -0
- package/dist/events.d.ts +585 -140
- package/dist/events.js +57 -42
- package/dist/fields.d.ts +1478 -66
- package/dist/fields.js +33 -47
- package/dist/files.d.ts +766 -62
- package/dist/files.js +34 -22
- package/dist/index.d.ts +25707 -902
- package/dist/index.js +22 -20
- package/dist/leads.d.ts +1108 -22
- package/dist/leads.js +39 -20
- package/dist/notifications.d.ts +691 -94
- package/dist/notifications.js +45 -91
- package/dist/organizations.d.ts +263 -5
- package/dist/organizations.js +21 -2
- package/dist/payments.d.ts +1794 -120
- package/dist/payments.js +58 -60
- package/dist/platform.d.ts +12 -20
- package/dist/platform.js +8 -21
- package/dist/plugins.d.ts +808 -71
- package/dist/plugins.js +66 -35
- package/dist/products.d.ts +1411 -53
- package/dist/products.js +40 -23
- package/dist/roles.d.ts +560 -8
- package/dist/roles.js +25 -11
- package/dist/routes.d.ts +8 -0
- package/dist/routes.js +13 -0
- package/dist/saas.d.ts +164 -8
- package/dist/saas.js +14 -29
- package/dist/tags.d.ts +344 -8
- package/dist/tags.js +16 -8
- package/dist/transfer.d.ts +1361 -36
- package/dist/transfer.js +47 -49
- package/dist/trash.d.ts +299 -23
- package/dist/trash.js +27 -20
- package/dist/users.d.ts +1233 -59
- package/dist/users.js +48 -39
- package/dist/values.d.ts +150 -0
- package/dist/values.js +139 -0
- package/dist/views.d.ts +404 -13
- package/dist/views.js +18 -28
- package/dist/webhooks.d.ts +791 -29
- package/dist/webhooks.js +36 -21
- package/package.json +9 -2
- package/dist/db/src/schema/jobs.js +0 -44
package/dist/products.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import {
|
|
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 {
|
|
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:
|
|
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:
|
|
154
|
+
get: base.route({
|
|
138
155
|
method: "GET",
|
|
139
156
|
path: "/products/{id}"
|
|
140
157
|
}).input(z.object({ id: Id })).output(Product),
|
|
141
|
-
lookup:
|
|
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:
|
|
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
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
197
|
+
list: base.route({
|
|
181
198
|
method: "GET",
|
|
182
199
|
path: "/product-categories",
|
|
183
200
|
summary: "Every category, by name"
|
|
184
|
-
}).output(
|
|
185
|
-
create:
|
|
201
|
+
}).output(listOf(ProductCategory)),
|
|
202
|
+
create: base.route({
|
|
186
203
|
method: "POST",
|
|
187
204
|
path: "/product-categories",
|
|
188
205
|
successStatus: 201,
|
|
189
|
-
summary: "409
|
|
206
|
+
summary: "409 TAKEN (same name under the same parent); 400 INVALID_CATEGORY"
|
|
190
207
|
}).input(CategoryFields.required({ name: true })).output(ProductCategory),
|
|
191
|
-
update:
|
|
208
|
+
update: base.route({
|
|
192
209
|
method: "PATCH",
|
|
193
210
|
path: "/product-categories/{id}",
|
|
194
|
-
summary: "409
|
|
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:
|
|
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,
|
|
219
|
+
export { Product, ProductCategory, ProductStatus, productCategoriesContract, productsContract };
|