@erxes/core-contract 0.1.0-v2.1 → 0.1.0-v2.3

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/roles.js CHANGED
@@ -1,10 +1,11 @@
1
1
  import { roles } from "./db/src/schema/users.js";
2
2
  import "./db/src/schema/index.js";
3
+ import { COMMON_ERRORS, ERRORS } from "./errors.js";
3
4
  import { listOf } from "./common.js";
4
5
  import { RoleKey } from "./values.js";
5
6
  import { oc } from "@orpc/contract";
6
- import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
7
7
  import { z } from "zod";
8
+ import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
8
9
  // src/roles.ts
9
10
  /**
10
11
  * What a member may do, as actions (`contacts.delete`). Roles are named sets
@@ -195,18 +196,31 @@ const RoleFields = createUpdateSchema(roles, {
195
196
  description: true,
196
197
  permissions: true
197
198
  });
199
+ const { BEYOND_OWN_PERMISSIONS, BUILTIN_ROLE, FIXED_ROLE, LIMIT_EXCEEDED, OWNER_ONLY_PERMISSION, ROLE_IN_USE, ROLE_NOT_FOUND, UNKNOWN_PERMISSION } = ERRORS;
200
+ /** What these procedures answer with besides the common errors. */
201
+ const base = oc.errors({
202
+ ...COMMON_ERRORS,
203
+ BEYOND_OWN_PERMISSIONS,
204
+ BUILTIN_ROLE,
205
+ FIXED_ROLE,
206
+ LIMIT_EXCEEDED,
207
+ OWNER_ONLY_PERMISSION,
208
+ ROLE_IN_USE,
209
+ ROLE_NOT_FOUND,
210
+ UNKNOWN_PERMISSION
211
+ });
198
212
  const rolesContract = {
199
- list: oc.route({
213
+ list: base.route({
200
214
  method: "GET",
201
215
  path: "/roles",
202
216
  summary: "Roles of the organisation, with member counts"
203
217
  }).output(listOf(Role)),
204
- permissions: oc.route({
218
+ permissions: base.route({
205
219
  method: "GET",
206
220
  path: "/permissions",
207
221
  summary: "Every action a role can include: core's and installed plugins'"
208
222
  }).output(listOf(PermissionInfo)),
209
- create: oc.route({
223
+ create: base.route({
210
224
  method: "POST",
211
225
  path: "/roles",
212
226
  successStatus: 201,
@@ -215,12 +229,12 @@ const rolesContract = {
215
229
  name: true,
216
230
  permissions: true
217
231
  })).output(Role),
218
- update: oc.route({
232
+ update: base.route({
219
233
  method: "PATCH",
220
234
  path: "/roles/{key}",
221
235
  summary: "Rename a role or change its permissions (roles.manage; not Owner or Admin)"
222
236
  }).input(RoleFields.extend({ key: RoleKey })).output(Role),
223
- remove: oc.route({
237
+ remove: base.route({
224
238
  method: "DELETE",
225
239
  path: "/roles/{key}",
226
240
  summary: "Delete a custom role nobody has (roles.manage); 409 ROLE_IN_USE"
package/dist/saas.d.ts CHANGED
@@ -137,7 +137,88 @@ export declare const saasContract: {
137
137
  }, z.core.$strip>>;
138
138
  manageUrl: z.ZodNullable<z.ZodString>;
139
139
  checkedAt: z.ZodNullable<z.ZodISODateTime>;
140
- }, z.core.$strip>, Record<never, never>, Record<never, never>>;
140
+ }, z.core.$strip>, import("@orpc/contract").MergedErrorMap<Record<never, never>, {
141
+ UNAUTHORIZED: {
142
+ status: number;
143
+ };
144
+ NOT_ALLOWED: {
145
+ status: number;
146
+ data: z.ZodOptional<z.ZodObject<{
147
+ permission: z.ZodString;
148
+ }, z.core.$strip>>;
149
+ };
150
+ PLUGIN_ONLY: {
151
+ status: number;
152
+ };
153
+ MEMBERS_ONLY: {
154
+ status: number;
155
+ };
156
+ ORG_REQUIRED: {
157
+ status: number;
158
+ };
159
+ SCOPE_REQUIRED: {
160
+ status: number;
161
+ };
162
+ SERVICE_TOKEN_REQUIRED: {
163
+ status: number;
164
+ };
165
+ ORGANIZATION_DISABLED: {
166
+ status: number;
167
+ data: z.ZodObject<{
168
+ manageUrl: z.ZodNullable<z.ZodString>;
169
+ }, z.core.$strip>;
170
+ };
171
+ NOT_IN_PLAN: {
172
+ status: number;
173
+ data: z.ZodOptional<z.ZodObject<{
174
+ manageUrl: z.ZodNullable<z.ZodString>;
175
+ }, z.core.$strip>>;
176
+ };
177
+ READ_ONLY: {
178
+ status: number;
179
+ };
180
+ TOO_MANY_REQUESTS: {
181
+ status: number;
182
+ };
183
+ INVALID_INPUT: {
184
+ status: number;
185
+ data: z.ZodObject<{
186
+ issues: z.ZodArray<z.ZodObject<{
187
+ path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodInt]>>;
188
+ message: z.ZodString;
189
+ }, z.core.$strip>>;
190
+ }, z.core.$strip>;
191
+ };
192
+ NOT_FOUND: {
193
+ status: number;
194
+ };
195
+ TAKEN: {
196
+ status: number;
197
+ data: z.ZodObject<{
198
+ field: z.ZodString;
199
+ id: z.ZodOptional<z.ZodString>;
200
+ values: z.ZodOptional<z.ZodArray<z.ZodString>>;
201
+ }, z.core.$strip>;
202
+ };
203
+ INVALID_CURSOR: {
204
+ status: number;
205
+ };
206
+ INVALID_REFERENCE: {
207
+ status: number;
208
+ data: z.ZodObject<{
209
+ field: z.ZodString;
210
+ }, z.core.$strip>;
211
+ };
212
+ INVALID_FILTER: {
213
+ status: number;
214
+ };
215
+ FILTER_TOO_SLOW: {
216
+ status: number;
217
+ };
218
+ LIMIT_EXCEEDED: {
219
+ status: number;
220
+ };
221
+ }>, Record<never, never>>;
141
222
  pluginPlan: import("@orpc/contract").ContractProcedureBuilderWithOutput<import("@orpc/contract").Schema<unknown, unknown>, z.ZodObject<{
142
223
  saas: z.ZodBoolean;
143
224
  tier: z.ZodNullable<z.ZodEnum<{
@@ -157,5 +238,86 @@ export declare const saasContract: {
157
238
  warning: "warning";
158
239
  }>;
159
240
  readOnlyUntil: z.ZodNullable<z.ZodISODateTime>;
160
- }, z.core.$strip>, Record<never, never>, Record<never, never>>;
241
+ }, z.core.$strip>, import("@orpc/contract").MergedErrorMap<Record<never, never>, {
242
+ UNAUTHORIZED: {
243
+ status: number;
244
+ };
245
+ NOT_ALLOWED: {
246
+ status: number;
247
+ data: z.ZodOptional<z.ZodObject<{
248
+ permission: z.ZodString;
249
+ }, z.core.$strip>>;
250
+ };
251
+ PLUGIN_ONLY: {
252
+ status: number;
253
+ };
254
+ MEMBERS_ONLY: {
255
+ status: number;
256
+ };
257
+ ORG_REQUIRED: {
258
+ status: number;
259
+ };
260
+ SCOPE_REQUIRED: {
261
+ status: number;
262
+ };
263
+ SERVICE_TOKEN_REQUIRED: {
264
+ status: number;
265
+ };
266
+ ORGANIZATION_DISABLED: {
267
+ status: number;
268
+ data: z.ZodObject<{
269
+ manageUrl: z.ZodNullable<z.ZodString>;
270
+ }, z.core.$strip>;
271
+ };
272
+ NOT_IN_PLAN: {
273
+ status: number;
274
+ data: z.ZodOptional<z.ZodObject<{
275
+ manageUrl: z.ZodNullable<z.ZodString>;
276
+ }, z.core.$strip>>;
277
+ };
278
+ READ_ONLY: {
279
+ status: number;
280
+ };
281
+ TOO_MANY_REQUESTS: {
282
+ status: number;
283
+ };
284
+ INVALID_INPUT: {
285
+ status: number;
286
+ data: z.ZodObject<{
287
+ issues: z.ZodArray<z.ZodObject<{
288
+ path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodInt]>>;
289
+ message: z.ZodString;
290
+ }, z.core.$strip>>;
291
+ }, z.core.$strip>;
292
+ };
293
+ NOT_FOUND: {
294
+ status: number;
295
+ };
296
+ TAKEN: {
297
+ status: number;
298
+ data: z.ZodObject<{
299
+ field: z.ZodString;
300
+ id: z.ZodOptional<z.ZodString>;
301
+ values: z.ZodOptional<z.ZodArray<z.ZodString>>;
302
+ }, z.core.$strip>;
303
+ };
304
+ INVALID_CURSOR: {
305
+ status: number;
306
+ };
307
+ INVALID_REFERENCE: {
308
+ status: number;
309
+ data: z.ZodObject<{
310
+ field: z.ZodString;
311
+ }, z.core.$strip>;
312
+ };
313
+ INVALID_FILTER: {
314
+ status: number;
315
+ };
316
+ FILTER_TOO_SLOW: {
317
+ status: number;
318
+ };
319
+ LIMIT_EXCEEDED: {
320
+ status: number;
321
+ };
322
+ }>, Record<never, never>>;
161
323
  };
package/dist/saas.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { ENTITLEMENT_STATUSES, ORGANIZATION_STATUSES, PLUGIN_ACCESS, PLUGIN_TIERS } from "./db/src/enums.js";
2
+ import { COMMON_ERRORS, ERRORS } from "./errors.js";
2
3
  import { OrganizationRegion } from "./organizations.js";
3
4
  import { oc } from "@orpc/contract";
4
5
  import { z } from "zod";
@@ -53,13 +54,19 @@ const PluginPlan = z.object({
53
54
  access: PluginAccess,
54
55
  readOnlyUntil: z.iso.datetime().nullable()
55
56
  });
57
+ const { LIMIT_EXCEEDED } = ERRORS;
58
+ /** What these procedures answer with besides the common errors. */
59
+ const base = oc.errors({
60
+ ...COMMON_ERRORS,
61
+ LIMIT_EXCEEDED
62
+ });
56
63
  const saasContract = {
57
- plan: oc.route({
64
+ plan: base.route({
58
65
  method: "GET",
59
66
  path: "/plan",
60
67
  summary: "The organisation's subscription: each plugin's tier, status and access"
61
68
  }).output(SubscriptionInfo),
62
- pluginPlan: oc.route({
69
+ pluginPlan: base.route({
63
70
  method: "GET",
64
71
  path: "/plan/plugin",
65
72
  summary: "For the calling plugin: its tier and what it may do (read-only, off)"
package/dist/tags.d.ts CHANGED
@@ -35,7 +35,91 @@ export declare const tagsContract: {
35
35
  out: {};
36
36
  in: {};
37
37
  }>>;
38
- }, z.core.$strip>, Record<never, never>, Record<never, never>>;
38
+ }, z.core.$strip>, import("@orpc/contract").MergedErrorMap<Record<never, never>, {
39
+ UNAUTHORIZED: {
40
+ status: number;
41
+ };
42
+ NOT_ALLOWED: {
43
+ status: number;
44
+ data: z.ZodOptional<z.ZodObject<{
45
+ permission: z.ZodString;
46
+ }, z.core.$strip>>;
47
+ };
48
+ PLUGIN_ONLY: {
49
+ status: number;
50
+ };
51
+ MEMBERS_ONLY: {
52
+ status: number;
53
+ };
54
+ ORG_REQUIRED: {
55
+ status: number;
56
+ };
57
+ SCOPE_REQUIRED: {
58
+ status: number;
59
+ };
60
+ SERVICE_TOKEN_REQUIRED: {
61
+ status: number;
62
+ };
63
+ ORGANIZATION_DISABLED: {
64
+ status: number;
65
+ data: z.ZodObject<{
66
+ manageUrl: z.ZodNullable<z.ZodString>;
67
+ }, z.core.$strip>;
68
+ };
69
+ NOT_IN_PLAN: {
70
+ status: number;
71
+ data: z.ZodOptional<z.ZodObject<{
72
+ manageUrl: z.ZodNullable<z.ZodString>;
73
+ }, z.core.$strip>>;
74
+ };
75
+ READ_ONLY: {
76
+ status: number;
77
+ };
78
+ TOO_MANY_REQUESTS: {
79
+ status: number;
80
+ };
81
+ INVALID_INPUT: {
82
+ status: number;
83
+ data: z.ZodObject<{
84
+ issues: z.ZodArray<z.ZodObject<{
85
+ path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodInt]>>;
86
+ message: z.ZodString;
87
+ }, z.core.$strip>>;
88
+ }, z.core.$strip>;
89
+ };
90
+ NOT_FOUND: {
91
+ status: number;
92
+ };
93
+ TAKEN: {
94
+ status: number;
95
+ data: z.ZodObject<{
96
+ field: z.ZodString;
97
+ id: z.ZodOptional<z.ZodString>;
98
+ values: z.ZodOptional<z.ZodArray<z.ZodString>>;
99
+ }, z.core.$strip>;
100
+ };
101
+ INVALID_CURSOR: {
102
+ status: number;
103
+ };
104
+ INVALID_REFERENCE: {
105
+ status: number;
106
+ data: z.ZodObject<{
107
+ field: z.ZodString;
108
+ }, z.core.$strip>;
109
+ };
110
+ INVALID_FILTER: {
111
+ status: number;
112
+ };
113
+ FILTER_TOO_SLOW: {
114
+ status: number;
115
+ };
116
+ INVALID_TAG: {
117
+ status: number;
118
+ };
119
+ TAG_LIMIT: {
120
+ status: number;
121
+ };
122
+ }>, Record<never, never>>;
39
123
  create: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
40
124
  type: z.ZodNonOptional<z.ZodOptional<z.ZodEnum<{
41
125
  company: "company";
@@ -58,7 +142,91 @@ export declare const tagsContract: {
58
142
  }, {
59
143
  out: {};
60
144
  in: {};
61
- }>, Record<never, never>, Record<never, never>>;
145
+ }>, import("@orpc/contract").MergedErrorMap<Record<never, never>, {
146
+ UNAUTHORIZED: {
147
+ status: number;
148
+ };
149
+ NOT_ALLOWED: {
150
+ status: number;
151
+ data: z.ZodOptional<z.ZodObject<{
152
+ permission: z.ZodString;
153
+ }, z.core.$strip>>;
154
+ };
155
+ PLUGIN_ONLY: {
156
+ status: number;
157
+ };
158
+ MEMBERS_ONLY: {
159
+ status: number;
160
+ };
161
+ ORG_REQUIRED: {
162
+ status: number;
163
+ };
164
+ SCOPE_REQUIRED: {
165
+ status: number;
166
+ };
167
+ SERVICE_TOKEN_REQUIRED: {
168
+ status: number;
169
+ };
170
+ ORGANIZATION_DISABLED: {
171
+ status: number;
172
+ data: z.ZodObject<{
173
+ manageUrl: z.ZodNullable<z.ZodString>;
174
+ }, z.core.$strip>;
175
+ };
176
+ NOT_IN_PLAN: {
177
+ status: number;
178
+ data: z.ZodOptional<z.ZodObject<{
179
+ manageUrl: z.ZodNullable<z.ZodString>;
180
+ }, z.core.$strip>>;
181
+ };
182
+ READ_ONLY: {
183
+ status: number;
184
+ };
185
+ TOO_MANY_REQUESTS: {
186
+ status: number;
187
+ };
188
+ INVALID_INPUT: {
189
+ status: number;
190
+ data: z.ZodObject<{
191
+ issues: z.ZodArray<z.ZodObject<{
192
+ path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodInt]>>;
193
+ message: z.ZodString;
194
+ }, z.core.$strip>>;
195
+ }, z.core.$strip>;
196
+ };
197
+ NOT_FOUND: {
198
+ status: number;
199
+ };
200
+ TAKEN: {
201
+ status: number;
202
+ data: z.ZodObject<{
203
+ field: z.ZodString;
204
+ id: z.ZodOptional<z.ZodString>;
205
+ values: z.ZodOptional<z.ZodArray<z.ZodString>>;
206
+ }, z.core.$strip>;
207
+ };
208
+ INVALID_CURSOR: {
209
+ status: number;
210
+ };
211
+ INVALID_REFERENCE: {
212
+ status: number;
213
+ data: z.ZodObject<{
214
+ field: z.ZodString;
215
+ }, z.core.$strip>;
216
+ };
217
+ INVALID_FILTER: {
218
+ status: number;
219
+ };
220
+ FILTER_TOO_SLOW: {
221
+ status: number;
222
+ };
223
+ INVALID_TAG: {
224
+ status: number;
225
+ };
226
+ TAG_LIMIT: {
227
+ status: number;
228
+ };
229
+ }>, Record<never, never>>;
62
230
  update: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
63
231
  name: z.ZodOptional<z.ZodString>;
64
232
  colorCode: z.ZodOptional<z.ZodNullable<z.ZodString>>;
@@ -78,10 +246,178 @@ export declare const tagsContract: {
78
246
  }, {
79
247
  out: {};
80
248
  in: {};
81
- }>, Record<never, never>, Record<never, never>>;
249
+ }>, import("@orpc/contract").MergedErrorMap<Record<never, never>, {
250
+ UNAUTHORIZED: {
251
+ status: number;
252
+ };
253
+ NOT_ALLOWED: {
254
+ status: number;
255
+ data: z.ZodOptional<z.ZodObject<{
256
+ permission: z.ZodString;
257
+ }, z.core.$strip>>;
258
+ };
259
+ PLUGIN_ONLY: {
260
+ status: number;
261
+ };
262
+ MEMBERS_ONLY: {
263
+ status: number;
264
+ };
265
+ ORG_REQUIRED: {
266
+ status: number;
267
+ };
268
+ SCOPE_REQUIRED: {
269
+ status: number;
270
+ };
271
+ SERVICE_TOKEN_REQUIRED: {
272
+ status: number;
273
+ };
274
+ ORGANIZATION_DISABLED: {
275
+ status: number;
276
+ data: z.ZodObject<{
277
+ manageUrl: z.ZodNullable<z.ZodString>;
278
+ }, z.core.$strip>;
279
+ };
280
+ NOT_IN_PLAN: {
281
+ status: number;
282
+ data: z.ZodOptional<z.ZodObject<{
283
+ manageUrl: z.ZodNullable<z.ZodString>;
284
+ }, z.core.$strip>>;
285
+ };
286
+ READ_ONLY: {
287
+ status: number;
288
+ };
289
+ TOO_MANY_REQUESTS: {
290
+ status: number;
291
+ };
292
+ INVALID_INPUT: {
293
+ status: number;
294
+ data: z.ZodObject<{
295
+ issues: z.ZodArray<z.ZodObject<{
296
+ path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodInt]>>;
297
+ message: z.ZodString;
298
+ }, z.core.$strip>>;
299
+ }, z.core.$strip>;
300
+ };
301
+ NOT_FOUND: {
302
+ status: number;
303
+ };
304
+ TAKEN: {
305
+ status: number;
306
+ data: z.ZodObject<{
307
+ field: z.ZodString;
308
+ id: z.ZodOptional<z.ZodString>;
309
+ values: z.ZodOptional<z.ZodArray<z.ZodString>>;
310
+ }, z.core.$strip>;
311
+ };
312
+ INVALID_CURSOR: {
313
+ status: number;
314
+ };
315
+ INVALID_REFERENCE: {
316
+ status: number;
317
+ data: z.ZodObject<{
318
+ field: z.ZodString;
319
+ }, z.core.$strip>;
320
+ };
321
+ INVALID_FILTER: {
322
+ status: number;
323
+ };
324
+ FILTER_TOO_SLOW: {
325
+ status: number;
326
+ };
327
+ INVALID_TAG: {
328
+ status: number;
329
+ };
330
+ TAG_LIMIT: {
331
+ status: number;
332
+ };
333
+ }>, Record<never, never>>;
82
334
  remove: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
83
335
  id: z.ZodString;
84
336
  }, z.core.$strip>, z.ZodObject<{
85
337
  ok: z.ZodLiteral<true>;
86
- }, z.core.$strip>, Record<never, never>, Record<never, never>>;
338
+ }, z.core.$strip>, import("@orpc/contract").MergedErrorMap<Record<never, never>, {
339
+ UNAUTHORIZED: {
340
+ status: number;
341
+ };
342
+ NOT_ALLOWED: {
343
+ status: number;
344
+ data: z.ZodOptional<z.ZodObject<{
345
+ permission: z.ZodString;
346
+ }, z.core.$strip>>;
347
+ };
348
+ PLUGIN_ONLY: {
349
+ status: number;
350
+ };
351
+ MEMBERS_ONLY: {
352
+ status: number;
353
+ };
354
+ ORG_REQUIRED: {
355
+ status: number;
356
+ };
357
+ SCOPE_REQUIRED: {
358
+ status: number;
359
+ };
360
+ SERVICE_TOKEN_REQUIRED: {
361
+ status: number;
362
+ };
363
+ ORGANIZATION_DISABLED: {
364
+ status: number;
365
+ data: z.ZodObject<{
366
+ manageUrl: z.ZodNullable<z.ZodString>;
367
+ }, z.core.$strip>;
368
+ };
369
+ NOT_IN_PLAN: {
370
+ status: number;
371
+ data: z.ZodOptional<z.ZodObject<{
372
+ manageUrl: z.ZodNullable<z.ZodString>;
373
+ }, z.core.$strip>>;
374
+ };
375
+ READ_ONLY: {
376
+ status: number;
377
+ };
378
+ TOO_MANY_REQUESTS: {
379
+ status: number;
380
+ };
381
+ INVALID_INPUT: {
382
+ status: number;
383
+ data: z.ZodObject<{
384
+ issues: z.ZodArray<z.ZodObject<{
385
+ path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodInt]>>;
386
+ message: z.ZodString;
387
+ }, z.core.$strip>>;
388
+ }, z.core.$strip>;
389
+ };
390
+ NOT_FOUND: {
391
+ status: number;
392
+ };
393
+ TAKEN: {
394
+ status: number;
395
+ data: z.ZodObject<{
396
+ field: z.ZodString;
397
+ id: z.ZodOptional<z.ZodString>;
398
+ values: z.ZodOptional<z.ZodArray<z.ZodString>>;
399
+ }, z.core.$strip>;
400
+ };
401
+ INVALID_CURSOR: {
402
+ status: number;
403
+ };
404
+ INVALID_REFERENCE: {
405
+ status: number;
406
+ data: z.ZodObject<{
407
+ field: z.ZodString;
408
+ }, z.core.$strip>;
409
+ };
410
+ INVALID_FILTER: {
411
+ status: number;
412
+ };
413
+ FILTER_TOO_SLOW: {
414
+ status: number;
415
+ };
416
+ INVALID_TAG: {
417
+ status: number;
418
+ };
419
+ TAG_LIMIT: {
420
+ status: number;
421
+ };
422
+ }>, Record<never, never>>;
87
423
  };
package/dist/tags.js CHANGED
@@ -1,9 +1,10 @@
1
1
  import { tags } from "./db/src/schema/tags.js";
2
2
  import "./db/src/schema/index.js";
3
+ import { COMMON_ERRORS, ERRORS } from "./errors.js";
3
4
  import { ContentType, Id, isoDate, listOf } from "./common.js";
4
5
  import { oc } from "@orpc/contract";
5
- import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
6
6
  import { z } from "zod";
7
+ import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
7
8
  // src/tags.ts
8
9
  const Tag = createSelectSchema(tags, {
9
10
  id: Id,
@@ -24,9 +25,16 @@ const TagFields = createUpdateSchema(tags, {
24
25
  name: true,
25
26
  colorCode: true
26
27
  });
28
+ const { INVALID_TAG, TAG_LIMIT } = ERRORS;
29
+ /** What these procedures answer with besides the common errors. */
30
+ const base = oc.errors({
31
+ ...COMMON_ERRORS,
32
+ INVALID_TAG,
33
+ TAG_LIMIT
34
+ });
27
35
  /** Labels for customers and companies. Plugins keep their own tags. */
28
36
  const tagsContract = {
29
- list: oc.route({
37
+ list: base.route({
30
38
  method: "GET",
31
39
  path: "/tags",
32
40
  summary: "Tags of a record type, by name"
@@ -34,20 +42,20 @@ const tagsContract = {
34
42
  type: ContentType,
35
43
  search: z.string().trim().max(100).optional()
36
44
  })).output(listOf(Tag)),
37
- create: oc.route({
45
+ create: base.route({
38
46
  method: "POST",
39
47
  path: "/tags",
40
48
  successStatus: 201,
41
- summary: "Create a tag. 409 TAG_EXISTS when the name is taken for the type, 409 TAG_LIMIT when the type already has LIST_MAX (1000) tags"
49
+ summary: "Create a tag. 409 TAKEN when the name is taken for the type, 409 TAG_LIMIT when the type already has LIST_MAX (1000) tags"
42
50
  }).input(TagFields.required({
43
51
  type: true,
44
52
  name: true
45
53
  })).output(Tag),
46
- update: oc.route({
54
+ update: base.route({
47
55
  method: "PATCH",
48
56
  path: "/tags/{id}"
49
57
  }).input(TagFields.omit({ type: true }).extend({ id: Id }).refine((value) => Object.keys(value).some((key) => key !== "id"), "nothing to update")).output(Tag),
50
- remove: oc.route({
58
+ remove: base.route({
51
59
  method: "DELETE",
52
60
  path: "/tags/{id}",
53
61
  summary: "Delete a tag; it comes off every record (owners and admins)"