@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/leads.js CHANGED
@@ -1,11 +1,12 @@
1
- import { LEAD_STAGE_KINDS, leadStages } from "./db/src/schema/leadStages.js";
2
- import { CUSTOMER_STATES } from "./db/src/schema/customers.js";
1
+ import { CONTENT_TYPES, CUSTOMER_STATES, LEAD_STAGE_KINDS } from "./db/src/enums.js";
2
+ import { leadStages } from "./db/src/schema/leadStages.js";
3
3
  import { leadEvents } from "./db/src/schema/leads.js";
4
4
  import "./db/src/schema/index.js";
5
- import { Id, isoDate } from "./common.js";
5
+ import { COMMON_ERRORS, ERRORS } from "./errors.js";
6
+ import { Id, isoDate, listOf } from "./common.js";
6
7
  import { oc } from "@orpc/contract";
7
- import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
8
8
  import { z } from "zod";
9
+ import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
9
10
  // src/leads.ts
10
11
  /** `open`: still being worked; `qualified`: ready to become a customer; `disqualified`: lost. */
11
12
  const LeadStageKind = z.enum(LEAD_STAGE_KINDS);
@@ -24,6 +25,7 @@ const LEAD_SOURCES = [
24
25
  "event",
25
26
  "partner",
26
27
  "plugin",
28
+ "sign_in",
27
29
  "api",
28
30
  "other"
29
31
  ];
@@ -31,7 +33,7 @@ const LeadSource = z.string().trim().toLowerCase().regex(/^[a-z0-9][a-z0-9_.:-]{
31
33
  /** Campaign, medium, referrer, page, form …: up to 20 short values. */
32
34
  const SourceDetails = z.record(z.string().max(50), z.string().max(500)).refine((value) => Object.keys(value).length <= 20, "at most 20 details");
33
35
  /** Whom a lead action is about: people or companies (both go through the same stages). */
34
- const LeadRecordType = z.enum(["customer", "company"]);
36
+ const LeadRecordType = z.enum(CONTENT_TYPES);
35
37
  /** `lead`: not a customer yet. People and companies alike. */
36
38
  const ContactState = z.enum(CUSTOMER_STATES);
37
39
  /**
@@ -105,6 +107,9 @@ const LeadEvent = createSelectSchema(leadEvents, {
105
107
  createdAt: isoDate
106
108
  }).pick({
107
109
  id: true,
110
+ /** The person, or (`companyId`) the company. */
111
+ customerId: true,
112
+ companyId: true,
108
113
  event: true,
109
114
  fromStageId: true,
110
115
  toStageId: true,
@@ -112,9 +117,6 @@ const LeadEvent = createSelectSchema(leadEvents, {
112
117
  actorType: true,
113
118
  actorId: true,
114
119
  createdAt: true
115
- }).extend({
116
- recordType: LeadRecordType,
117
- recordId: Id
118
120
  });
119
121
  const Count = z.object({ count: z.int() });
120
122
  const LeadReport = z.object({
@@ -156,27 +158,44 @@ const LeadReport = z.object({
156
158
  });
157
159
  const Ids = z.array(Id).min(1).max(100);
158
160
  const RecordTypeInput = { recordType: LeadRecordType.default("customer") };
161
+ const { INVALID_ACTOR, INVALID_FILE, INVALID_LEAD_STAGE, INVALID_OWNER, INVALID_TYPE, LAST_OPEN_STAGE, LEAD_STAGE_IN_USE, LIMIT_EXCEEDED, NOTHING_TO_RETRY, NOT_AUTHOR, NOT_A_LEAD, SUBJECT_REQUIRED } = ERRORS;
162
+ /** What these procedures answer with besides the common errors. */
163
+ const base = oc.errors({
164
+ ...COMMON_ERRORS,
165
+ INVALID_ACTOR,
166
+ INVALID_FILE,
167
+ INVALID_LEAD_STAGE,
168
+ INVALID_OWNER,
169
+ INVALID_TYPE,
170
+ LAST_OPEN_STAGE,
171
+ LEAD_STAGE_IN_USE,
172
+ LIMIT_EXCEEDED,
173
+ NOTHING_TO_RETRY,
174
+ NOT_AUTHOR,
175
+ NOT_A_LEAD,
176
+ SUBJECT_REQUIRED
177
+ });
159
178
  const leadsContract = {
160
- stages: oc.route({
179
+ stages: base.route({
161
180
  method: "GET",
162
181
  path: "/lead-stages",
163
182
  summary: "The lead stages, in order, with how many leads each holds"
164
- }).output(z.object({ data: z.array(LeadStage) })),
165
- createStage: oc.route({
183
+ }).output(listOf(LeadStage)),
184
+ createStage: base.route({
166
185
  method: "POST",
167
186
  path: "/lead-stages",
168
187
  successStatus: 201
169
188
  }).input(StageFields.required({ name: true })).output(LeadStage),
170
- updateStage: oc.route({
189
+ updateStage: base.route({
171
190
  method: "PATCH",
172
191
  path: "/lead-stages/{id}"
173
192
  }).input(StageFields.extend({ id: Id })).output(LeadStage),
174
- reorderStages: oc.route({
193
+ reorderStages: base.route({
175
194
  method: "POST",
176
195
  path: "/lead-stages/reorder",
177
196
  summary: "Every stage id, in the new order"
178
197
  }).input(z.object({ ids: z.array(Id).min(1).max(50) })).output(z.object({ ok: z.literal(true) })),
179
- removeStage: oc.route({
198
+ removeStage: base.route({
180
199
  method: "POST",
181
200
  path: "/lead-stages/{id}/remove",
182
201
  summary: "Delete a stage; its leads move to `moveTo` (required when it has any). The last open stage stays"
@@ -184,7 +203,7 @@ const leadsContract = {
184
203
  id: Id,
185
204
  moveTo: Id.optional()
186
205
  })).output(z.object({ moved: z.int() })),
187
- move: oc.route({
206
+ move: base.route({
188
207
  method: "POST",
189
208
  path: "/leads/move",
190
209
  summary: "Move leads to a stage (a disqualified stage takes a reason)"
@@ -194,7 +213,7 @@ const leadsContract = {
194
213
  stageId: Id,
195
214
  reason: z.string().trim().max(500).optional()
196
215
  })).output(z.object({ moved: z.int() })),
197
- convert: oc.route({
216
+ convert: base.route({
198
217
  method: "POST",
199
218
  path: "/leads/convert",
200
219
  summary: "Leads become customers: optionally given an owner, and (people) linked to a company"
@@ -204,15 +223,15 @@ const leadsContract = {
204
223
  ownerId: Id.optional(),
205
224
  companyId: Id.optional()
206
225
  })).output(z.object({ converted: z.int() })),
207
- history: oc.route({
226
+ history: base.route({
208
227
  method: "GET",
209
228
  path: "/leads/{id}/history",
210
- summary: "A lead's journey: created, every stage, converted"
229
+ summary: "A lead's journey, its last 200 steps: created, every stage, converted"
211
230
  }).input(z.object({
212
231
  ...RecordTypeInput,
213
232
  id: Id
214
- })).output(z.object({ data: z.array(LeadEvent) })),
215
- report: oc.route({
233
+ })).output(z.object({ data: z.array(LeadEvent).max(200) })),
234
+ report: base.route({
216
235
  method: "GET",
217
236
  path: "/leads/report",
218
237
  summary: "Funnel, conversion, sources, owners and reasons for a period (default: last 30 days)"