@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/audit.js CHANGED
@@ -1,11 +1,13 @@
1
+ import { AUDIT_STREAM_STARTS } from "./db/src/enums.js";
1
2
  import { auditLogs } from "./db/src/schema/platform.js";
2
- import { AUDIT_STREAM_FORMATS, auditStreams } from "./db/src/schema/auditStreams.js";
3
+ import { auditStreams } from "./db/src/schema/auditStreams.js";
3
4
  import "./db/src/schema/index.js";
4
- import { CursorQuery, Id, cursorPageOf, isoDate } from "./common.js";
5
- import { ActorRef } from "./platform.js";
5
+ import { COMMON_ERRORS, ERRORS } from "./errors.js";
6
+ import { AuditStreamFormat } from "./values.js";
7
+ import { CursorQuery, Id, cursorPageOf, isoDate, listOf } from "./common.js";
6
8
  import { oc } from "@orpc/contract";
7
- import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
8
9
  import { z } from "zod";
10
+ import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
9
11
  // src/audit.ts
10
12
  const AuditEntry = createSelectSchema(auditLogs, {
11
13
  id: Id,
@@ -14,6 +16,9 @@ const AuditEntry = createSelectSchema(auditLogs, {
14
16
  createdAt: isoDate
15
17
  }).pick({
16
18
  id: true,
19
+ /** A team member (`actorId` = user id), a plugin (its name) or `system`. */
20
+ actorType: true,
21
+ actorId: true,
17
22
  /** `<record>.<verb>`: `customer.deleted`, `user.role_changed`, `auth.signed_in`. */
18
23
  action: true,
19
24
  targetType: true,
@@ -27,9 +32,7 @@ const AuditEntry = createSelectSchema(auditLogs, {
27
32
  /** `core` or the plugin that recorded it. */
28
33
  source: true,
29
34
  createdAt: true
30
- }).extend({ actor: ActorRef });
31
- /** Who changed what in core (owners and admins). */
32
- const AuditStreamFormat = z.enum(AUDIT_STREAM_FORMATS);
35
+ });
33
36
  const StreamUrl = z.string().trim().check(z.url()).max(2e3).refine((value) => /^https?:\/\//.test(value), "an http(s) address");
34
37
  /** A header the log service needs (`DD-API-KEY`, `Authorization: Splunk …`); its value is write-only. */
35
38
  const AuthHeader = z.object({
@@ -67,8 +70,19 @@ const StreamFields = createUpdateSchema(auditStreams, {
67
70
  format: true,
68
71
  status: true
69
72
  });
73
+ const { INVALID_ACTOR, INVALID_OWNER, INVALID_RECIPIENT, INVALID_TYPE, INVALID_URL, LIMIT_EXCEEDED } = ERRORS;
74
+ /** What these procedures answer with besides the common errors. */
75
+ const base = oc.errors({
76
+ ...COMMON_ERRORS,
77
+ INVALID_ACTOR,
78
+ INVALID_OWNER,
79
+ INVALID_RECIPIENT,
80
+ INVALID_TYPE,
81
+ INVALID_URL,
82
+ LIMIT_EXCEEDED
83
+ });
70
84
  const auditContract = {
71
- list: oc.route({
85
+ list: base.route({
72
86
  method: "GET",
73
87
  path: "/audit",
74
88
  summary: "Audit log, newest first (owners and admins)"
@@ -88,7 +102,7 @@ const auditContract = {
88
102
  })).output(cursorPageOf(AuditEntry).extend({
89
103
  /** `totalCount` stopped counting at this many. */
90
104
  totalCapped: z.boolean() })),
91
- record: oc.route({
105
+ record: base.route({
92
106
  method: "POST",
93
107
  path: "/audit",
94
108
  successStatus: 201,
@@ -105,7 +119,7 @@ totalCapped: z.boolean() })),
105
119
  ip: z.string().trim().max(64).optional(),
106
120
  userAgent: z.string().trim().max(500).optional()
107
121
  })).min(1).max(100) })).output(z.object({ recorded: z.int() })),
108
- verify: oc.route({
122
+ verify: base.route({
109
123
  method: "GET",
110
124
  path: "/audit/verify",
111
125
  summary: "Check the audit log’s hash chain: has any entry been changed or removed? (owners and admins)"
@@ -126,7 +140,7 @@ totalCapped: z.boolean() })),
126
140
  mismatchAt: z.int().nullable()
127
141
  })
128
142
  })),
129
- checkpoints: oc.route({
143
+ checkpoints: base.route({
130
144
  method: "GET",
131
145
  path: "/audit/checkpoints",
132
146
  summary: "Signed checkpoints of the audit chain (JWS, ES256; keys at /core/v1/.well-known/jwks.json), to keep outside erxes (owners and admins)"
@@ -138,9 +152,9 @@ totalCapped: z.boolean() })),
138
152
  hash: z.string(),
139
153
  keyId: z.string(),
140
154
  signature: z.string(),
141
- createdAt: z.iso.datetime()
142
- })) })),
143
- settings: oc.route({
155
+ createdAt: isoDate()
156
+ })).max(1e3) })),
157
+ settings: base.route({
144
158
  method: "GET",
145
159
  path: "/settings/audit",
146
160
  summary: "How long the audit log keeps entries"
@@ -148,7 +162,7 @@ totalCapped: z.boolean() })),
148
162
  retentionDays: z.int(),
149
163
  maxRetentionDays: z.int()
150
164
  })),
151
- updateSettings: oc.route({
165
+ updateSettings: base.route({
152
166
  method: "PUT",
153
167
  path: "/settings/audit",
154
168
  summary: "Change audit retention (owners)"
@@ -156,12 +170,12 @@ totalCapped: z.boolean() })),
156
170
  retentionDays: z.int(),
157
171
  maxRetentionDays: z.int()
158
172
  })),
159
- streams: oc.route({
173
+ streams: base.route({
160
174
  method: "GET",
161
175
  path: "/audit/streams",
162
176
  summary: "Where the audit log is streamed (owners)"
163
- }).output(z.object({ data: z.array(AuditStream) })),
164
- createStream: oc.route({
177
+ }).output(listOf(AuditStream)),
178
+ createStream: base.route({
165
179
  method: "POST",
166
180
  path: "/audit/streams",
167
181
  successStatus: 201,
@@ -173,23 +187,23 @@ totalCapped: z.boolean() })),
173
187
  format: AuditStreamFormat.default("erxes"),
174
188
  authHeader: AuthHeader.optional(),
175
189
  /** `now`: entries from here on; `beginning`: everything still kept, then new ones. */
176
- from: z.enum(["now", "beginning"]).default("now")
190
+ from: z.enum(AUDIT_STREAM_STARTS).default("now")
177
191
  })).output(z.object({
178
192
  stream: AuditStream,
179
193
  secret: z.string()
180
194
  })),
181
- updateStream: oc.route({
195
+ updateStream: base.route({
182
196
  method: "PATCH",
183
197
  path: "/audit/streams/{id}"
184
198
  }).input(StreamFields.extend({
185
199
  id: Id,
186
200
  authHeader: AuthHeader.nullable().optional()
187
201
  })).output(AuditStream),
188
- removeStream: oc.route({
202
+ removeStream: base.route({
189
203
  method: "DELETE",
190
204
  path: "/audit/streams/{id}"
191
205
  }).input(z.object({ id: Id })).output(z.object({ ok: z.literal(true) })),
192
- testStream: oc.route({
206
+ testStream: base.route({
193
207
  method: "POST",
194
208
  path: "/audit/streams/{id}/test",
195
209
  summary: "Send one test entry now and report the answer"
@@ -201,4 +215,4 @@ totalCapped: z.boolean() })),
201
215
  ms: z.number().nullable()
202
216
  }))
203
217
  };
204
- export { AuditEntry, AuditStream, AuditStreamFormat, auditContract };
218
+ export { AuditEntry, AuditStream, auditContract };