@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/plugins.js CHANGED
@@ -1,4 +1,7 @@
1
1
  import { AUTOMATION_SUBJECTS, CONTENT_TYPES } from "./db/src/enums.js";
2
+ import { pluginInstallations, plugins } from "./db/src/schema/plugins.js";
3
+ import "./db/src/schema/index.js";
4
+ import { COMMON_ERRORS, ERRORS } from "./errors.js";
2
5
  import { EventPattern } from "./webhooks.js";
3
6
  import { Id, isoDate, listOf } from "./common.js";
4
7
  import { ActionField } from "./automationRuns.js";
@@ -6,6 +9,7 @@ import { Country } from "./money.js";
6
9
  import { EventType } from "./platform.js";
7
10
  import { oc } from "@orpc/contract";
8
11
  import { z } from "zod";
12
+ import { createSelectSchema } from "drizzle-zod";
9
13
  // src/plugins.ts
10
14
  /** A plugin's name: its namespace everywhere (`hr` → `hr.leave.requested`, `/hr/*`). */
11
15
  const PluginName = z.string().trim().regex(/^[a-z][a-z0-9_]{0,39}$/, "lower case letters, digits and _ (starting with a letter)").refine((name) => name !== "core", "reserved");
@@ -134,27 +138,33 @@ const PluginManifest = z.object({
134
138
  subject: z.enum(CONTENT_TYPES).optional()
135
139
  })).max(500).optional()
136
140
  });
137
- const Plugin = z.object({
138
- name: z.string(),
139
- title: z.string(),
140
- version: z.string().nullable(),
141
- description: z.string().nullable(),
142
- /** Made for these countries (empty: everywhere). */
143
- countries: z.array(z.string()),
144
- ui: z.object({
145
- remote: z.string(),
146
- entry: z.string()
147
- }).nullable(),
148
- api: z.object({ url: z.string() }).nullable(),
149
- /** In this organisation: installed and active. */
150
- installed: z.boolean(),
141
+ /** The plugin in this organisation; `status` `active` is installed. */
142
+ const PluginInstallation = createSelectSchema(pluginInstallations, { installedAt: isoDate }).pick({
143
+ status: true,
151
144
  /** Why it is off here (`Suspended: 600 deletions in a few minutes`). */
152
- statusReason: z.string().nullable(),
145
+ statusReason: true,
146
+ grantedScopes: true,
147
+ installedAt: true
148
+ });
149
+ const Plugin = createSelectSchema(plugins, {
150
+ /** What members see of the manifest (the column is nullable); the rest is for core. */
151
+ manifest: () => PluginManifest.pick({
152
+ title: true,
153
+ version: true,
154
+ description: true,
155
+ countries: true,
156
+ ui: true,
157
+ api: true
158
+ }) }).pick({
159
+ name: true,
160
+ manifest: true
161
+ }).extend({
162
+ /** Never installed here: null. */
163
+ installation: PluginInstallation.nullable(),
164
+ /** The manifest's scopes, or (before it sent one) what plugins could always do. */
153
165
  requestedScopes: z.array(z.string()),
154
- grantedScopes: z.array(z.string()),
155
- /** Asks for scopes the owner hasn't granted yet (a newer version). */
156
- needsApproval: z.boolean(),
157
- installedAt: isoDate().nullable()
166
+ /** Installed, and asks for scopes the owner hasn't granted yet (a newer version). */
167
+ needsApproval: z.boolean()
158
168
  });
159
169
  const TokenResponse = z.object({
160
170
  access_token: z.string(),
@@ -168,8 +178,19 @@ const TokenResponse = z.object({
168
178
  * plugin UIs (a member's short-lived session for one plugin's API), and live
169
179
  * signals to plugin UIs.
170
180
  */
181
+ const { CROSS_SITE, INVALID_CLIENT, LIMIT_EXCEEDED, NAMESPACE_REQUIRED, NOT_INSTALLED, PLUGIN_NOT_FOUND } = ERRORS;
182
+ /** What these procedures answer with besides the common errors. */
183
+ const base = oc.errors({
184
+ ...COMMON_ERRORS,
185
+ CROSS_SITE,
186
+ INVALID_CLIENT,
187
+ LIMIT_EXCEEDED,
188
+ NAMESPACE_REQUIRED,
189
+ NOT_INSTALLED,
190
+ PLUGIN_NOT_FOUND
191
+ });
171
192
  const pluginsContract = {
172
- token: oc.route({
193
+ token: base.route({
173
194
  method: "POST",
174
195
  path: "/plugins/token",
175
196
  summary: "Client credentials → a 15-minute token (ES256). With `org`: to act in an organisation that installed the plugin; without: to update the manifest"
@@ -179,27 +200,27 @@ const pluginsContract = {
179
200
  client_secret: z.string().min(32).max(200),
180
201
  org: Id.optional()
181
202
  })).output(TokenResponse),
182
- registerManifest: oc.route({
203
+ registerManifest: base.route({
183
204
  method: "PUT",
184
205
  path: "/plugins/manifest",
185
206
  summary: "The calling plugin declares its UI, API, scopes, permissions and events"
186
207
  }).input(PluginManifest).output(z.object({ ok: z.literal(true) })),
187
- list: oc.route({
208
+ list: base.route({
188
209
  method: "GET",
189
210
  path: "/plugins",
190
211
  summary: "Plugins of this deployment, and which are installed here"
191
212
  }).output(listOf(Plugin)),
192
- install: oc.route({
213
+ install: base.route({
193
214
  method: "POST",
194
215
  path: "/plugins/{name}/install",
195
216
  summary: "Install (or approve the new scopes of) a plugin (owners)"
196
217
  }).input(z.object({ name: PluginName })).output(Plugin),
197
- uninstall: oc.route({
218
+ uninstall: base.route({
198
219
  method: "POST",
199
220
  path: "/plugins/{name}/uninstall",
200
221
  summary: "Uninstall a plugin: its tokens stop working at once (owners)"
201
222
  }).input(z.object({ name: PluginName })).output(Plugin),
202
- session: oc.route({
223
+ session: base.route({
203
224
  method: "POST",
204
225
  path: "/plugins/{name}/session",
205
226
  summary: "A 5-minute token for one plugin's API, for the signed-in member (plugin UIs send it as Bearer)"
@@ -208,7 +229,7 @@ const pluginsContract = {
208
229
  expiresAt: z.iso.datetime(),
209
230
  apiUrl: z.string().nullable()
210
231
  })),
211
- signal: oc.route({
232
+ signal: base.route({
212
233
  method: "POST",
213
234
  path: "/plugins/live",
214
235
  summary: "Tell the plugin's open UIs something changed (plugins with live:write); no data, UIs refetch"
@@ -217,4 +238,4 @@ const pluginsContract = {
217
238
  userIds: z.array(Id).max(1e3).optional()
218
239
  })).output(z.object({ ok: z.literal(true) }))
219
240
  };
220
- export { LiveTopic, PLUGIN_SCOPES, Plugin, PluginManifest, PluginName, PluginScope, TokenResponse, pluginsContract };
241
+ export { LiveTopic, PLUGIN_SCOPES, Plugin, PluginInstallation, PluginManifest, PluginName, PluginScope, TokenResponse, pluginsContract };