@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/client.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { coreRoutes } from "./routes.js";
|
|
2
|
+
import { CORE_API_PREFIX } from "./values.js";
|
|
3
|
+
import { ORPCError, createORPCClient } from "@orpc/client";
|
|
4
|
+
import { OpenAPILink } from "@orpc/openapi-client/fetch";
|
|
5
|
+
import { createTanstackQueryUtils } from "@orpc/tanstack-query";
|
|
6
|
+
// src/client.ts
|
|
7
|
+
/**
|
|
8
|
+
* The browser's typed client for /core/v1, from the contract the server implements. web and
|
|
9
|
+
* plugin UIs both import it. They are served from web's origin, so the HttpOnly session cookie
|
|
10
|
+
* goes with every request. Calls return the result or throw an `ORPCError` (`code`, `status`,
|
|
11
|
+
* `data`). It imports no table: the routes come from `routes.json` and the types stay types.
|
|
12
|
+
*/
|
|
13
|
+
const client = createORPCClient(new OpenAPILink(coreRoutes, {
|
|
14
|
+
url: () => `${window.location.origin}${CORE_API_PREFIX}`,
|
|
15
|
+
fetch: (request, init) => globalThis.fetch(request, {
|
|
16
|
+
...init,
|
|
17
|
+
credentials: "same-origin"
|
|
18
|
+
})
|
|
19
|
+
}));
|
|
20
|
+
/**
|
|
21
|
+
* Every core call: `orpc.users.list.queryOptions({ input })`,
|
|
22
|
+
* `orpc.users.update.mutationOptions()`, or `orpc.files.complete.call(input)`
|
|
23
|
+
* outside React Query. The key is the procedure and its input, so the same
|
|
24
|
+
* request is cached once wherever it's used, in web and in a plugin (they share
|
|
25
|
+
* web's QueryClient), and `invalidateQueries({ queryKey: orpc.users.key() })`
|
|
26
|
+
* reaches every users query. Never write a query key by hand.
|
|
27
|
+
*/
|
|
28
|
+
const orpc = createTanstackQueryUtils(client);
|
|
29
|
+
/**
|
|
30
|
+
* Where erxes-ui's member pickers and `useMembersById` read members:
|
|
31
|
+
* `<SelectMember.Field members={memberQueries} … />`. The active team is one
|
|
32
|
+
* request and cache entry for every picker and name in web and its plugins.
|
|
33
|
+
*/
|
|
34
|
+
const memberQueries = {
|
|
35
|
+
team: orpc.users.list.queryOptions({
|
|
36
|
+
input: {
|
|
37
|
+
limit: 100,
|
|
38
|
+
status: "active"
|
|
39
|
+
},
|
|
40
|
+
staleTime: 6e4
|
|
41
|
+
}),
|
|
42
|
+
byIds: (ids) => orpc.users.list.queryOptions({
|
|
43
|
+
input: {
|
|
44
|
+
ids: ids.join(","),
|
|
45
|
+
limit: 100
|
|
46
|
+
},
|
|
47
|
+
staleTime: 3e5
|
|
48
|
+
})
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Whether core answered with `code` (`TAKEN`, `NOT_FOUND`, …). It narrows
|
|
52
|
+
* `error.data` to what `ERRORS` declares for the code, so the field a
|
|
53
|
+
* `TAKEN` is about reads as `error.data.field`.
|
|
54
|
+
*/
|
|
55
|
+
const isApiError = (error, code) => error instanceof ORPCError && error.defined && error.code === code;
|
|
56
|
+
/** What to tell the member: the error's message, or the first field the contract refused. */
|
|
57
|
+
const messageOf = (error) => {
|
|
58
|
+
const issue = isApiError(error, "INVALID_INPUT") ? error.data.issues[0] : void 0;
|
|
59
|
+
if (issue) return `${issue.path.join(".")}: ${issue.message}`;
|
|
60
|
+
return error instanceof Error ? error.message : "Something went wrong. Try again.";
|
|
61
|
+
};
|
|
62
|
+
export { isApiError, memberQueries, messageOf, orpc };
|
package/dist/common.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
export declare const Id: z.ZodString;
|
|
3
3
|
/**
|
|
4
|
-
* A timestamp column
|
|
5
|
-
*
|
|
6
|
-
* nullable column stays nullable.
|
|
4
|
+
* A timestamp column in an output schema: the handler returns the row's `Date`,
|
|
5
|
+
* the client gets an ISO string. Give it to `createSelectSchema` as a
|
|
6
|
+
* refinement (`{ createdAt: isoDate }`), so a nullable column stays nullable.
|
|
7
|
+
* Inputs and JSON bodies read from the wire take `z.iso.datetime()`.
|
|
7
8
|
*/
|
|
8
|
-
export declare const isoDate: () => z.ZodISODateTime
|
|
9
|
+
export declare const isoDate: () => z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
|
|
9
10
|
/**
|
|
10
11
|
* Keyset ("cursor") paging, newest first. A cursor is the id of a record in
|
|
11
12
|
* the list: `forward` returns older records after it, `backward` newer ones
|
|
@@ -32,6 +33,11 @@ export declare const PageInfo: z.ZodObject<{
|
|
|
32
33
|
endCursor: z.ZodNullable<z.ZodString>;
|
|
33
34
|
}, z.core.$strip>;
|
|
34
35
|
export type PageInfo = z.infer<typeof PageInfo>;
|
|
36
|
+
/** `true`/`false` from a query string. */
|
|
37
|
+
export declare const QueryFlag: z.ZodPipe<z.ZodEnum<{
|
|
38
|
+
false: "false";
|
|
39
|
+
true: "true";
|
|
40
|
+
}>, z.ZodTransform<boolean, "false" | "true">>;
|
|
35
41
|
/** `true`/`false` from a query string, or a boolean from a typed client. */
|
|
36
42
|
export declare const QueryBoolean: z.ZodUnion<readonly [z.ZodBoolean, z.ZodPipe<z.ZodEnum<{
|
|
37
43
|
false: "false";
|
|
@@ -39,19 +45,15 @@ export declare const QueryBoolean: z.ZodUnion<readonly [z.ZodBoolean, z.ZodPipe<
|
|
|
39
45
|
}>, z.ZodTransform<boolean, "false" | "true">>]>;
|
|
40
46
|
/** Comma-separated ids in a query string (`?ids=a,b`), at most 100. */
|
|
41
47
|
export declare const IdList: z.ZodPipe<z.ZodString, z.ZodTransform<string[], string>>;
|
|
42
|
-
/**
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
defined: z.ZodBoolean;
|
|
49
|
-
code: z.ZodString;
|
|
50
|
-
status: z.ZodInt;
|
|
51
|
-
message: z.ZodString;
|
|
52
|
-
data: z.ZodOptional<z.ZodUnknown>;
|
|
48
|
+
/** `INVALID_INPUT`'s `data`: what failed the contract, field by field. */
|
|
49
|
+
export declare const InvalidInput: z.ZodObject<{
|
|
50
|
+
issues: z.ZodArray<z.ZodObject<{
|
|
51
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodInt]>>;
|
|
52
|
+
message: z.ZodString;
|
|
53
|
+
}, z.core.$strip>>;
|
|
53
54
|
}, z.core.$strip>;
|
|
54
|
-
|
|
55
|
+
/** Longest description a person, customer or company holds, as stored (editor JSON). */
|
|
56
|
+
export declare const DESCRIPTION_MAX = 5000;
|
|
55
57
|
export declare const cursorPageOf: <T extends z.ZodType>(item: T) => z.ZodObject<{
|
|
56
58
|
data: z.ZodArray<T>;
|
|
57
59
|
pageInfo: z.ZodObject<{
|
|
@@ -63,6 +65,16 @@ export declare const cursorPageOf: <T extends z.ZodType>(item: T) => z.ZodObject
|
|
|
63
65
|
totalCount: z.ZodInt;
|
|
64
66
|
totalCapped: z.ZodOptional<z.ZodBoolean>;
|
|
65
67
|
}, z.core.$strip>;
|
|
68
|
+
/**
|
|
69
|
+
* Most items a list read whole may hold. Whole lists are small config
|
|
70
|
+
* (roles, stages, fields, webhooks); past this the server fails instead of
|
|
71
|
+
* cutting the list. Lists that grow with use are `cursorPageOf`.
|
|
72
|
+
*/
|
|
73
|
+
export declare const LIST_MAX = 1000;
|
|
74
|
+
/** A small config list, read whole: at most `LIST_MAX` items. */
|
|
75
|
+
export declare const listOf: <T extends z.ZodType>(item: T) => z.ZodObject<{
|
|
76
|
+
data: z.ZodArray<T>;
|
|
77
|
+
}, z.core.$strip>;
|
|
66
78
|
/** Records that tags and custom fields attach to. */
|
|
67
79
|
export declare const ContentType: z.ZodEnum<{
|
|
68
80
|
company: "company";
|
package/dist/common.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import { CONTENT_TYPES, FIELD_CONTENT_TYPES } from "./db/src/
|
|
2
|
-
import "./db/src/schema/index.js";
|
|
1
|
+
import { BOOLEAN_STRINGS, CONTENT_TYPES, CURSOR_MODES, FIELD_CONTENT_TYPES, PAGE_DIRECTIONS } from "./db/src/enums.js";
|
|
3
2
|
import { z } from "zod";
|
|
4
3
|
// src/common.ts
|
|
5
4
|
const Id = z.string().min(1).max(64);
|
|
6
5
|
/**
|
|
7
|
-
* A timestamp column
|
|
8
|
-
*
|
|
9
|
-
* nullable column stays nullable.
|
|
6
|
+
* A timestamp column in an output schema: the handler returns the row's `Date`,
|
|
7
|
+
* the client gets an ISO string. Give it to `createSelectSchema` as a
|
|
8
|
+
* refinement (`{ createdAt: isoDate }`), so a nullable column stays nullable.
|
|
9
|
+
* Inputs and JSON bodies read from the wire take `z.iso.datetime()`.
|
|
10
10
|
*/
|
|
11
|
-
const isoDate = () => z.iso.datetime()
|
|
11
|
+
const isoDate = () => z.codec(z.date(), z.iso.datetime(), {
|
|
12
|
+
decode: (date) => date.toISOString(),
|
|
13
|
+
encode: (iso) => new Date(iso)
|
|
14
|
+
});
|
|
12
15
|
/**
|
|
13
16
|
* Keyset ("cursor") paging, newest first. A cursor is the id of a record in
|
|
14
17
|
* the list: `forward` returns older records after it, `backward` newer ones
|
|
@@ -18,8 +21,8 @@ const isoDate = () => z.iso.datetime();
|
|
|
18
21
|
const CursorQuery = z.object({
|
|
19
22
|
limit: z.coerce.number().int().min(1).max(100).default(30),
|
|
20
23
|
cursor: Id.optional(),
|
|
21
|
-
direction: z.enum(
|
|
22
|
-
cursorMode: z.enum(
|
|
24
|
+
direction: z.enum(PAGE_DIRECTIONS).default("forward"),
|
|
25
|
+
cursorMode: z.enum(CURSOR_MODES).default("exclusive")
|
|
23
26
|
});
|
|
24
27
|
const PageInfo = z.object({
|
|
25
28
|
hasNextPage: z.boolean(),
|
|
@@ -27,22 +30,19 @@ const PageInfo = z.object({
|
|
|
27
30
|
startCursor: z.string().nullable(),
|
|
28
31
|
endCursor: z.string().nullable()
|
|
29
32
|
});
|
|
33
|
+
/** `true`/`false` from a query string. */
|
|
34
|
+
const QueryFlag = z.enum(BOOLEAN_STRINGS).transform((value) => value === "true");
|
|
30
35
|
/** `true`/`false` from a query string, or a boolean from a typed client. */
|
|
31
|
-
const QueryBoolean = z.union([z.boolean(),
|
|
36
|
+
const QueryBoolean = z.union([z.boolean(), QueryFlag]);
|
|
32
37
|
/** Comma-separated ids in a query string (`?ids=a,b`), at most 100. */
|
|
33
38
|
const IdList = z.string().max(6500).transform((value) => value.split(",").map((id) => id.trim()).filter(Boolean).slice(0, 100));
|
|
34
|
-
/**
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
code: z.string(),
|
|
42
|
-
status: z.int(),
|
|
43
|
-
message: z.string(),
|
|
44
|
-
data: z.unknown().optional()
|
|
45
|
-
});
|
|
39
|
+
/** `INVALID_INPUT`'s `data`: what failed the contract, field by field. */
|
|
40
|
+
const InvalidInput = z.object({ issues: z.array(z.object({
|
|
41
|
+
path: z.array(z.union([z.string(), z.int()])),
|
|
42
|
+
message: z.string()
|
|
43
|
+
})) });
|
|
44
|
+
/** Longest description a person, customer or company holds, as stored (editor JSON). */
|
|
45
|
+
const DESCRIPTION_MAX = 5e3;
|
|
46
46
|
const cursorPageOf = (item) => z.object({
|
|
47
47
|
data: z.array(item),
|
|
48
48
|
pageInfo: PageInfo,
|
|
@@ -51,6 +51,14 @@ const cursorPageOf = (item) => z.object({
|
|
|
51
51
|
/** Big lists stop counting: `totalCount` is the cap and there are more ("10,000+"). */
|
|
52
52
|
totalCapped: z.boolean().optional()
|
|
53
53
|
});
|
|
54
|
+
/**
|
|
55
|
+
* Most items a list read whole may hold. Whole lists are small config
|
|
56
|
+
* (roles, stages, fields, webhooks); past this the server fails instead of
|
|
57
|
+
* cutting the list. Lists that grow with use are `cursorPageOf`.
|
|
58
|
+
*/
|
|
59
|
+
const LIST_MAX = 1e3;
|
|
60
|
+
/** A small config list, read whole: at most `LIST_MAX` items. */
|
|
61
|
+
const listOf = (item) => z.object({ data: z.array(item).max(LIST_MAX) });
|
|
54
62
|
/** Records that tags and custom fields attach to. */
|
|
55
63
|
const ContentType = z.enum(CONTENT_TYPES);
|
|
56
64
|
/** Records custom fields attach to: contacts, and the shared product catalog. */
|
|
@@ -73,4 +81,4 @@ const PhoneNumber = z.string().trim().min(3).max(32).regex(/^\+?[0-9 ()-]+$/, "d
|
|
|
73
81
|
* (`/core/v1/files/<id>/download`, as uploads return).
|
|
74
82
|
*/
|
|
75
83
|
const ImageAddress = z.string().trim().max(1e3).refine((value) => /^https?:\/\/\S+$/.test(value) || /^\/core\/v1\/files\/[A-Za-z0-9]+\/download$/.test(value), "a URL or an uploaded file");
|
|
76
|
-
export { ContentType, CursorQuery, CustomFields, CustomFieldsPatch, CustomValue,
|
|
84
|
+
export { ContentType, CursorQuery, CustomFields, CustomFieldsPatch, CustomValue, DESCRIPTION_MAX, EmailAddress, FieldContentType, Id, IdList, ImageAddress, InvalidInput, LIST_MAX, PageInfo, PhoneNumber, QueryBoolean, QueryFlag, cursorPageOf, isoDate, listOf };
|