@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/events.js CHANGED
@@ -1,12 +1,13 @@
1
1
  import { EVENT_FAILURE_STATUSES, NOTIFICATION_PRIORITIES } from "./db/src/enums.js";
2
2
  import { events } from "./db/src/schema/events.js";
3
3
  import "./db/src/schema/index.js";
4
+ import { COMMON_ERRORS, ERRORS } from "./errors.js";
4
5
  import { CursorQuery, Id, cursorPageOf, isoDate } from "./common.js";
5
6
  import { ActivityTarget } from "./activities.js";
6
- import { ActorRef, AppLink, DedupeKey, EntityRef, EventType } from "./platform.js";
7
+ import { AppLink, DedupeKey, EntityType, EventType } from "./platform.js";
7
8
  import { oc } from "@orpc/contract";
8
- import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
9
9
  import { z } from "zod";
10
+ import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
10
11
  // src/events.ts
11
12
  /** What a published event asks core to notify (as `POST /notifications`). */
12
13
  const EventNotify = z.object({
@@ -24,7 +25,11 @@ const EventInput = createUpdateSchema(events, {
24
25
  link: AppLink.optional(),
25
26
  notify: EventNotify.optional(),
26
27
  occurredAt: () => z.iso.datetime(),
27
- dedupeKey: DedupeKey.optional()
28
+ dedupeKey: DedupeKey.optional(),
29
+ subjectType: ActivityTarget.optional(),
30
+ subjectId: Id.optional(),
31
+ entityType: EntityType.optional(),
32
+ entityId: Id.optional()
28
33
  }).pick({
29
34
  /** Namespaced by the plugin: `hr.leave.approved`. */
30
35
  type: true,
@@ -35,16 +40,14 @@ const EventInput = createUpdateSchema(events, {
35
40
  notify: true,
36
41
  occurredAt: true,
37
42
  /** Retry-safe: one event per plugin and key. */
38
- dedupeKey: true
39
- }).required({ type: true }).extend({
43
+ dedupeKey: true,
40
44
  /** The customer or company it concerns: with `summary`, it goes on their timeline. */
41
- subject: z.object({
42
- type: ActivityTarget,
43
- id: Id
44
- }).optional(),
45
- entity: EntityRef.optional(),
46
- actorUserId: Id.optional()
47
- });
45
+ subjectType: true,
46
+ subjectId: true,
47
+ /** The plugin's own record it is about. */
48
+ entityType: true,
49
+ entityId: true
50
+ }).required({ type: true }).extend({ actorUserId: Id.optional() }).refine((value) => value.subjectType === void 0 === (value.subjectId === void 0), "subjectType and subjectId go together").refine((value) => value.entityType === void 0 === (value.entityId === void 0), "entityType and entityId go together");
48
51
  const CoreEvent = createSelectSchema(events, {
49
52
  id: Id,
50
53
  version: () => z.int(),
@@ -56,18 +59,20 @@ const CoreEvent = createSelectSchema(events, {
56
59
  source: true,
57
60
  type: true,
58
61
  version: true,
62
+ /** The customer or company it concerns. */
63
+ subjectType: true,
64
+ subjectId: true,
65
+ /** The plugin's own record it is about. */
66
+ entityType: true,
67
+ entityId: true,
68
+ /** A team member (`actorId` = user id), a plugin (its name) or `system`. */
69
+ actorType: true,
70
+ actorId: true,
59
71
  payload: true,
60
72
  summary: true,
61
73
  link: true,
62
74
  occurredAt: true,
63
75
  createdAt: true
64
- }).extend({
65
- subject: z.object({
66
- type: ActivityTarget,
67
- id: Id
68
- }).nullable(),
69
- entity: EntityRef.nullable(),
70
- actor: ActorRef
71
76
  });
72
77
  const EventFailureStatus = z.enum(EVENT_FAILURE_STATUSES);
73
78
  /** An event a consumer (timeline, notifications, …) could not handle: its job in the consumer's queue. */
@@ -92,8 +97,20 @@ const FailureRef = z.object({
92
97
  * `POST /events`. Core turns events into timeline entries and notifications;
93
98
  * automations and webhooks will read the same stream.
94
99
  */
100
+ const { INVALID_ACTOR, INVALID_OWNER, INVALID_TYPE, LIMIT_EXCEEDED, NOTHING_TO_RETRY, NO_TIMELINE, SUBJECT_REQUIRED } = ERRORS;
101
+ /** What these procedures answer with besides the common errors. */
102
+ const base = oc.errors({
103
+ ...COMMON_ERRORS,
104
+ INVALID_ACTOR,
105
+ INVALID_OWNER,
106
+ INVALID_TYPE,
107
+ LIMIT_EXCEEDED,
108
+ NOTHING_TO_RETRY,
109
+ NO_TIMELINE,
110
+ SUBJECT_REQUIRED
111
+ });
95
112
  const eventsContract = {
96
- publish: oc.route({
113
+ publish: base.route({
97
114
  method: "POST",
98
115
  path: "/events",
99
116
  successStatus: 201,
@@ -102,7 +119,7 @@ const eventsContract = {
102
119
  published: z.int(),
103
120
  duplicates: z.int()
104
121
  })),
105
- list: oc.route({
122
+ list: base.route({
106
123
  method: "GET",
107
124
  path: "/events",
108
125
  summary: "Recent events of the organisation (owners and admins)"
@@ -113,7 +130,7 @@ const eventsContract = {
113
130
  subjectType: ActivityTarget.optional(),
114
131
  subjectId: Id.optional()
115
132
  })).output(cursorPageOf(CoreEvent)),
116
- failures: oc.route({
133
+ failures: base.route({
117
134
  method: "GET",
118
135
  path: "/events/failures",
119
136
  summary: "Events that could not be handled: retrying with backoff, or dead after the last attempt (owners and admins)"
@@ -124,7 +141,7 @@ const eventsContract = {
124
141
  dead: z.int()
125
142
  })
126
143
  })),
127
- retryFailures: oc.route({
144
+ retryFailures: base.route({
128
145
  method: "POST",
129
146
  path: "/events/failures/retry",
130
147
  summary: "Try failed events again now (owners and admins)"
@@ -132,7 +149,7 @@ const eventsContract = {
132
149
  failures: z.array(FailureRef).min(1).max(200).optional(),
133
150
  allDead: z.boolean().optional()
134
151
  })).output(z.object({ retried: z.int() })),
135
- dismissFailures: oc.route({
152
+ dismissFailures: base.route({
136
153
  method: "POST",
137
154
  path: "/events/failures/dismiss",
138
155
  summary: "Give up on failed events (owners and admins)"