@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/saas.d.ts CHANGED
@@ -6,17 +6,11 @@ export declare const PluginTier: z.ZodEnum<{
6
6
  pro: "pro";
7
7
  }>;
8
8
  export type PluginTier = z.infer<typeof PluginTier>;
9
- /** A plugin's billing status on erxes.io: `past_due` while Stripe retries, `canceling` until the period ends. */
10
9
  export declare const EntitlementStatus: z.ZodEnum<{
11
10
  active: "active";
12
11
  canceling: "canceling";
13
12
  past_due: "past_due";
14
13
  }>;
15
- /**
16
- * What a plugin may do here: `full`; `warning` (payment retrying or ending
17
- * at period end — everything still works); `read_only` (it left the plan:
18
- * reads and exports for the grace period); `off` (not in the plan).
19
- */
20
14
  export declare const PluginAccess: z.ZodEnum<{
21
15
  full: "full";
22
16
  off: "off";
@@ -143,7 +137,88 @@ export declare const saasContract: {
143
137
  }, z.core.$strip>>;
144
138
  manageUrl: z.ZodNullable<z.ZodString>;
145
139
  checkedAt: z.ZodNullable<z.ZodISODateTime>;
146
- }, 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>>;
147
222
  pluginPlan: import("@orpc/contract").ContractProcedureBuilderWithOutput<import("@orpc/contract").Schema<unknown, unknown>, z.ZodObject<{
148
223
  saas: z.ZodBoolean;
149
224
  tier: z.ZodNullable<z.ZodEnum<{
@@ -163,5 +238,86 @@ export declare const saasContract: {
163
238
  warning: "warning";
164
239
  }>;
165
240
  readOnlyUntil: z.ZodNullable<z.ZodISODateTime>;
166
- }, 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>>;
167
323
  };
package/dist/saas.js CHANGED
@@ -1,35 +1,14 @@
1
+ import { ENTITLEMENT_STATUSES, ORGANIZATION_STATUSES, PLUGIN_ACCESS, PLUGIN_TIERS } from "./db/src/enums.js";
2
+ import { COMMON_ERRORS, ERRORS } from "./errors.js";
1
3
  import { OrganizationRegion } from "./organizations.js";
2
4
  import { oc } from "@orpc/contract";
3
5
  import { z } from "zod";
4
6
  // src/saas.ts
5
7
  /** erxes.io's plugin tiers: Free is never billed; Plus and Pro have their own monthly prices. */
6
- const PluginTier = z.enum([
7
- "free",
8
- "plus",
9
- "pro"
10
- ]);
11
- /** A plugin's billing status on erxes.io: `past_due` while Stripe retries, `canceling` until the period ends. */
12
- const EntitlementStatus = z.enum([
13
- "active",
14
- "past_due",
15
- "canceling"
16
- ]);
17
- /**
18
- * What a plugin may do here: `full`; `warning` (payment retrying or ending
19
- * at period end — everything still works); `read_only` (it left the plan:
20
- * reads and exports for the grace period); `off` (not in the plan).
21
- */
22
- const PluginAccess = z.enum([
23
- "full",
24
- "warning",
25
- "read_only",
26
- "off"
27
- ]);
28
- const OrganizationStatus = z.enum([
29
- "active",
30
- "suspended",
31
- "inactive"
32
- ]);
8
+ const PluginTier = z.enum(PLUGIN_TIERS);
9
+ const EntitlementStatus = z.enum(ENTITLEMENT_STATUSES);
10
+ const PluginAccess = z.enum(PLUGIN_ACCESS);
11
+ const OrganizationStatus = z.enum(ORGANIZATION_STATUSES);
33
12
  /**
34
13
  * erxes.io → core: create (or rename, or enable/disable) an organisation's
35
14
  * workspace. `PUT /core/v1/saas/organizations/{id}` with
@@ -75,13 +54,19 @@ const PluginPlan = z.object({
75
54
  access: PluginAccess,
76
55
  readOnlyUntil: z.iso.datetime().nullable()
77
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
+ });
78
63
  const saasContract = {
79
- plan: oc.route({
64
+ plan: base.route({
80
65
  method: "GET",
81
66
  path: "/plan",
82
67
  summary: "The organisation's subscription: each plugin's tier, status and access"
83
68
  }).output(SubscriptionInfo),
84
- pluginPlan: oc.route({
69
+ pluginPlan: base.route({
85
70
  method: "GET",
86
71
  path: "/plan/plugin",
87
72
  summary: "For the calling plugin: its tier and what it may do (read-only, off)"
package/dist/tags.d.ts CHANGED
@@ -7,7 +7,7 @@ export declare const Tag: z.ZodObject<{
7
7
  }>;
8
8
  name: z.ZodString;
9
9
  colorCode: z.ZodNullable<z.ZodString>;
10
- createdAt: z.ZodISODateTime;
10
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
11
11
  }, {
12
12
  out: {};
13
13
  in: {};
@@ -30,12 +30,96 @@ export declare const tagsContract: {
30
30
  }>;
31
31
  name: z.ZodString;
32
32
  colorCode: z.ZodNullable<z.ZodString>;
33
- createdAt: z.ZodISODateTime;
33
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
34
34
  }, {
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";
@@ -54,11 +138,95 @@ export declare const tagsContract: {
54
138
  }>;
55
139
  name: z.ZodString;
56
140
  colorCode: z.ZodNullable<z.ZodString>;
57
- createdAt: z.ZodISODateTime;
141
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
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>>;
@@ -74,14 +242,182 @@ export declare const tagsContract: {
74
242
  }>;
75
243
  name: z.ZodString;
76
244
  colorCode: z.ZodNullable<z.ZodString>;
77
- createdAt: z.ZodISODateTime;
245
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
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 { ContentType, Id, isoDate } from "./common.js";
3
+ import { COMMON_ERRORS, ERRORS } from "./errors.js";
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,30 +25,37 @@ 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"
33
41
  }).input(z.object({
34
42
  type: ContentType,
35
43
  search: z.string().trim().max(100).optional()
36
- })).output(z.object({ data: z.array(Tag) })),
37
- create: oc.route({
44
+ })).output(listOf(Tag)),
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"
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)"