@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/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
@@ -45,19 +45,6 @@ export declare const QueryBoolean: z.ZodUnion<readonly [z.ZodBoolean, z.ZodPipe<
45
45
  }>, z.ZodTransform<boolean, "false" | "true">>]>;
46
46
  /** Comma-separated ids in a query string (`?ids=a,b`), at most 100. */
47
47
  export declare const IdList: z.ZodPipe<z.ZodString, z.ZodTransform<string[], string>>;
48
- /**
49
- * Every error (oRPC's error body): a stable `code` to branch on, the HTTP
50
- * `status`, a readable `message` and, for some codes, `data` (e.g. the id of
51
- * an existing record for `CUSTOMER_EXISTS`, validation `issues` for `INVALID_INPUT`).
52
- */
53
- export declare const ErrorBody: z.ZodObject<{
54
- defined: z.ZodBoolean;
55
- code: z.ZodString;
56
- status: z.ZodInt;
57
- message: z.ZodString;
58
- data: z.ZodOptional<z.ZodUnknown>;
59
- }, z.core.$strip>;
60
- export type ErrorBody = z.infer<typeof ErrorBody>;
61
48
  /** `INVALID_INPUT`'s `data`: what failed the contract, field by field. */
62
49
  export declare const InvalidInput: z.ZodObject<{
63
50
  issues: z.ZodArray<z.ZodObject<{
package/dist/common.js CHANGED
@@ -36,18 +36,6 @@ const QueryFlag = z.enum(BOOLEAN_STRINGS).transform((value) => value === "true")
36
36
  const QueryBoolean = z.union([z.boolean(), QueryFlag]);
37
37
  /** Comma-separated ids in a query string (`?ids=a,b`), at most 100. */
38
38
  const IdList = z.string().max(6500).transform((value) => value.split(",").map((id) => id.trim()).filter(Boolean).slice(0, 100));
39
- /**
40
- * Every error (oRPC's error body): a stable `code` to branch on, the HTTP
41
- * `status`, a readable `message` and, for some codes, `data` (e.g. the id of
42
- * an existing record for `CUSTOMER_EXISTS`, validation `issues` for `INVALID_INPUT`).
43
- */
44
- const ErrorBody = z.object({
45
- defined: z.boolean(),
46
- code: z.string(),
47
- status: z.int(),
48
- message: z.string(),
49
- data: z.unknown().optional()
50
- });
51
39
  /** `INVALID_INPUT`'s `data`: what failed the contract, field by field. */
52
40
  const InvalidInput = z.object({ issues: z.array(z.object({
53
41
  path: z.array(z.union([z.string(), z.int()])),
@@ -93,4 +81,4 @@ const PhoneNumber = z.string().trim().min(3).max(32).regex(/^\+?[0-9 ()-]+$/, "d
93
81
  * (`/core/v1/files/<id>/download`, as uploads return).
94
82
  */
95
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");
96
- export { ContentType, CursorQuery, CustomFields, CustomFieldsPatch, CustomValue, DESCRIPTION_MAX, EmailAddress, ErrorBody, FieldContentType, Id, IdList, ImageAddress, InvalidInput, LIST_MAX, PageInfo, PhoneNumber, QueryBoolean, QueryFlag, cursorPageOf, isoDate, listOf };
84
+ export { ContentType, CursorQuery, CustomFields, CustomFieldsPatch, CustomValue, DESCRIPTION_MAX, EmailAddress, FieldContentType, Id, IdList, ImageAddress, InvalidInput, LIST_MAX, PageInfo, PhoneNumber, QueryBoolean, QueryFlag, cursorPageOf, isoDate, listOf };