@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/companies.js CHANGED
@@ -1,12 +1,14 @@
1
+ import { CUSTOMER_STATES } from "./db/src/enums.js";
1
2
  import { customers } from "./db/src/schema/customers.js";
2
3
  import { companies } from "./db/src/schema/companies.js";
3
4
  import "./db/src/schema/index.js";
4
- import { CursorQuery, CustomFields, CustomFieldsPatch, EmailAddress, Id, IdList, ImageAddress, PhoneNumber, cursorPageOf, isoDate } from "./common.js";
5
+ import { COMMON_ERRORS, ERRORS } from "./errors.js";
6
+ import { CursorQuery, CustomFields, CustomFieldsPatch, DESCRIPTION_MAX, EmailAddress, Id, IdList, ImageAddress, PhoneNumber, cursorPageOf, isoDate } from "./common.js";
5
7
  import { ContactLink, ContactLinkInput } from "./customers.js";
6
8
  import { LIFECYCLE_COLUMNS, LIFECYCLE_INPUT_COLUMNS, lifecycleInput, lifecycleRow } from "./leads.js";
7
9
  import { oc } from "@orpc/contract";
8
- import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
9
10
  import { z } from "zod";
11
+ import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
10
12
  // src/companies.ts
11
13
  /** An organisation the organisation works with; shared by every plugin. */
12
14
  const Company = createSelectSchema(companies, {
@@ -64,7 +66,7 @@ const CompanyFields = createUpdateSchema(companies, {
64
66
  size: () => z.int().min(0).max(1e7),
65
67
  businessType: (value) => value.trim().max(200),
66
68
  code: (code) => code.trim().max(100),
67
- description: (value) => value.trim().max(5e3),
69
+ description: (value) => value.trim().max(DESCRIPTION_MAX),
68
70
  ownerId: () => Id,
69
71
  ...lifecycleInput
70
72
  }).pick({
@@ -99,14 +101,28 @@ const TagChange = z.object({
99
101
  add: z.array(Id).max(50).default([]),
100
102
  remove: z.array(Id).max(50).default([])
101
103
  });
104
+ const { INVALID_ACTOR, INVALID_FIELD, INVALID_FIELD_VALUE, INVALID_OWNER, INVALID_TAG, INVALID_TYPE, MASS_DELETE_STOPPED, NOT_A_LEAD, TAG_LIMIT } = ERRORS;
105
+ /** What these procedures answer with besides the common errors. */
106
+ const base = oc.errors({
107
+ ...COMMON_ERRORS,
108
+ INVALID_ACTOR,
109
+ INVALID_FIELD,
110
+ INVALID_FIELD_VALUE,
111
+ INVALID_OWNER,
112
+ INVALID_TAG,
113
+ INVALID_TYPE,
114
+ MASS_DELETE_STOPPED,
115
+ NOT_A_LEAD,
116
+ TAG_LIMIT
117
+ });
102
118
  const companiesContract = {
103
- list: oc.route({
119
+ list: base.route({
104
120
  method: "GET",
105
121
  path: "/companies",
106
122
  summary: "Companies of the organisation, newest first"
107
123
  }).input(CursorQuery.extend({
108
124
  search: z.string().trim().max(100).optional(),
109
- state: z.enum(["lead", "customer"]).optional(),
125
+ state: z.enum(CUSTOMER_STATES).optional(),
110
126
  /** Leads in this stage. */
111
127
  leadStageId: Id.optional(),
112
128
  ownerId: Id.optional(),
@@ -117,42 +133,42 @@ const companiesContract = {
117
133
  /** An advanced filter: JSON of a condition group (`RecordFilter`), as views save it. */
118
134
  filter: z.string().max(2e4).optional()
119
135
  })).output(cursorPageOf(Company)),
120
- get: oc.route({
136
+ get: base.route({
121
137
  method: "GET",
122
138
  path: "/companies/{id}",
123
139
  summary: "A company; ids merged into another company resolve to it"
124
140
  }).input(ID).output(Company),
125
- create: oc.route({
141
+ create: base.route({
126
142
  method: "POST",
127
143
  path: "/companies",
128
144
  successStatus: 201,
129
- summary: "Create a company. 409 COMPANY_EXISTS (data: { id }) when the name is taken"
145
+ summary: "Create a company. 409 TAKEN when the name is taken"
130
146
  }).input(CompanyFields.extend({ primaryName: z.string().trim().min(1).max(200) })).output(Company),
131
- update: oc.route({
147
+ update: base.route({
132
148
  method: "PATCH",
133
149
  path: "/companies/{id}"
134
150
  }).input(CompanyFields.extend({ id: Id }).refine(changes, "nothing to update")).output(Company),
135
- remove: oc.route({
151
+ remove: base.route({
136
152
  method: "POST",
137
153
  path: "/companies/remove",
138
154
  summary: "Delete companies (owners and admins)"
139
155
  }).input(Ids).output(z.object({ removed: z.int() })),
140
- merge: oc.route({
156
+ merge: base.route({
141
157
  method: "POST",
142
158
  path: "/companies/merge",
143
159
  summary: "Merge companies into `keepId` (owners and admins), as for customers"
144
160
  }).input(MergeInput).output(Company),
145
- tag: oc.route({
161
+ tag: base.route({
146
162
  method: "POST",
147
163
  path: "/companies/tag",
148
164
  summary: "Add and remove tags on many companies"
149
165
  }).input(TagChange).output(z.object({ updated: z.int() })),
150
- people: oc.route({
166
+ people: base.route({
151
167
  method: "GET",
152
168
  path: "/companies/{id}/people",
153
- summary: "The company's people: main contact first, then current, then former"
154
- }).input(ID).output(z.object({ data: z.array(PersonRef) })),
155
- linkPerson: oc.route({
169
+ summary: "The company's first 500 people: main contact first, then current, then former"
170
+ }).input(ID).output(z.object({ data: z.array(PersonRef).max(500) })),
171
+ linkPerson: base.route({
156
172
  method: "PUT",
157
173
  path: "/companies/{id}/people/{customerId}",
158
174
  summary: "Link a person (or change the link), as from the person"
@@ -160,7 +176,7 @@ const companiesContract = {
160
176
  id: Id,
161
177
  customerId: Id
162
178
  })).output(z.object({ ok: z.literal(true) })),
163
- unlinkPerson: oc.route({
179
+ unlinkPerson: base.route({
164
180
  method: "DELETE",
165
181
  path: "/companies/{id}/people/{customerId}"
166
182
  }).input(z.object({