@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
@@ -1,11 +1,12 @@
1
1
  import { customers } from "./db/src/schema/customers.js";
2
2
  import { customerLogins, customerSessions } from "./db/src/schema/customerAuth.js";
3
3
  import "./db/src/schema/index.js";
4
+ import { COMMON_ERRORS, ERRORS } from "./errors.js";
4
5
  import { EmailAddress, Id, ImageAddress, PhoneNumber, isoDate, listOf } from "./common.js";
5
6
  import { PluginName } from "./plugins.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/customerAuth.ts
10
11
  /** An email address or phone, with more fields. */
11
12
  const addressWith = (fields) => z.discriminatedUnion("kind", [z.object({
@@ -91,8 +92,24 @@ const CustomerTokens = z.object({
91
92
  * Customers sign in to a plugin's app with a one-time code (decision 42): the
92
93
  * app's own form calls these. Public; browsers only from the app's origins.
93
94
  */
95
+ const { INVALID_CODE, INVALID_CREDENTIALS, INVALID_TOKEN, LAST_LOGIN, NOTHING_TO_RETRY, ORGANIZATION_REQUIRED, ORIGIN_NOT_ALLOWED, SUBJECT_REQUIRED, TOO_MANY_ATTEMPTS, TOO_MANY_CODES, UNKNOWN_APP } = ERRORS;
96
+ /** What these procedures answer with besides the common errors. */
97
+ const base = oc.errors({
98
+ ...COMMON_ERRORS,
99
+ INVALID_CODE,
100
+ INVALID_CREDENTIALS,
101
+ INVALID_TOKEN,
102
+ LAST_LOGIN,
103
+ NOTHING_TO_RETRY,
104
+ ORGANIZATION_REQUIRED,
105
+ ORIGIN_NOT_ALLOWED,
106
+ SUBJECT_REQUIRED,
107
+ TOO_MANY_ATTEMPTS,
108
+ TOO_MANY_CODES,
109
+ UNKNOWN_APP
110
+ });
94
111
  const customerAuthContract = {
95
- sendCode: oc.route({
112
+ sendCode: base.route({
96
113
  method: "POST",
97
114
  path: "/customer-auth/code",
98
115
  successStatus: 202,
@@ -101,7 +118,7 @@ const customerAuthContract = {
101
118
  clientId,
102
119
  organization
103
120
  })).output(CodeSent),
104
- signIn: oc.route({
121
+ signIn: base.route({
105
122
  method: "POST",
106
123
  path: "/customer-auth/sign-in",
107
124
  summary: "Sign in (or up) with the code and get the app's tokens. 400 INVALID_CODE (wrong, used, expired or 5 tries), 400 UNKNOWN_APP, 403 ORIGIN_NOT_ALLOWED"
@@ -113,7 +130,7 @@ const customerAuthContract = {
113
130
  customer: CustomerProfile,
114
131
  created: z.boolean()
115
132
  })),
116
- refresh: oc.route({
133
+ refresh: base.route({
117
134
  method: "POST",
118
135
  path: "/customer-auth/refresh",
119
136
  summary: "New tokens for a refresh token; the old one stops working, and using it again ends the session. 401 INVALID_TOKEN, 403 ORIGIN_NOT_ALLOWED"
@@ -121,7 +138,7 @@ const customerAuthContract = {
121
138
  clientId,
122
139
  refreshToken: RefreshToken
123
140
  })).output(CustomerTokens),
124
- signOut: oc.route({
141
+ signOut: base.route({
125
142
  method: "POST",
126
143
  path: "/customer-auth/sign-out",
127
144
  summary: "End the refresh token's session; the answer is ok either way"
@@ -129,49 +146,49 @@ const customerAuthContract = {
129
146
  };
130
147
  /** The signed-in customer (`Authorization: Bearer` with a customer access token). */
131
148
  const customerAccountContract = {
132
- me: oc.route({
149
+ me: base.route({
133
150
  method: "GET",
134
151
  path: "/customer/me",
135
152
  summary: "The signed-in customer's profile"
136
153
  }).output(CustomerProfile),
137
- update: oc.route({
154
+ update: base.route({
138
155
  method: "PATCH",
139
156
  path: "/customer/me",
140
157
  summary: "Change name, picture or birth date"
141
158
  }).input(CustomerProfileFields).output(CustomerProfile),
142
- logins: oc.route({
159
+ logins: base.route({
143
160
  method: "GET",
144
161
  path: "/customer/me/logins",
145
162
  summary: "Addresses I sign in with"
146
163
  }).output(listOf(CustomerLogin)),
147
- addLogin: oc.route({
164
+ addLogin: base.route({
148
165
  method: "POST",
149
166
  path: "/customer/me/logins",
150
167
  successStatus: 202,
151
- summary: "Send a code to a new address to sign in with. 409 LOGIN_TAKEN when it is already a login, 429 TOO_MANY_CODES"
168
+ summary: "Send a code to a new address to sign in with. 409 TAKEN when it is already a login, 429 TOO_MANY_CODES"
152
169
  }).input(addressWith({})).output(CodeSent),
153
- confirmLogin: oc.route({
170
+ confirmLogin: base.route({
154
171
  method: "POST",
155
172
  path: "/customer/me/logins/confirm",
156
173
  successStatus: 201,
157
- summary: "Add the address with its code. 400 INVALID_CODE, 409 LOGIN_TAKEN"
174
+ summary: "Add the address with its code. 400 INVALID_CODE, 409 TAKEN"
158
175
  }).input(addressWith({ code: Code })).output(CustomerLogin),
159
- removeLogin: oc.route({
176
+ removeLogin: base.route({
160
177
  method: "DELETE",
161
178
  path: "/customer/me/logins/{id}",
162
179
  summary: "Stop signing in with an address. 409 LAST_LOGIN"
163
180
  }).input(z.object({ id: Id })).output(z.object({ ok: z.literal(true) })),
164
- sessions: oc.route({
181
+ sessions: base.route({
165
182
  method: "GET",
166
183
  path: "/customer/me/sessions",
167
184
  summary: "Where I am signed in"
168
185
  }).output(listOf(CustomerSession)),
169
- revokeSession: oc.route({
186
+ revokeSession: base.route({
170
187
  method: "DELETE",
171
188
  path: "/customer/me/sessions/{id}",
172
189
  summary: "Sign out one app"
173
190
  }).input(z.object({ id: Id })).output(z.object({ ok: z.literal(true) })),
174
- signOutEverywhere: oc.route({
191
+ signOutEverywhere: base.route({
175
192
  method: "POST",
176
193
  path: "/customer/me/sign-out-everywhere",
177
194
  summary: "Sign out of every app (access tokens end within 15 minutes)"