@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/transfer.js CHANGED
@@ -1,21 +1,21 @@
1
- import { IMPORT_STATUSES, TRANSFER_RECORD_TYPES, exports, importRows, imports } from "./db/src/schema/transfer.js";
1
+ import { EXPORT_FORMATS, IMPORT_MATCH_KEYS, IMPORT_MODES, IMPORT_ROW_ACTIONS, IMPORT_STATUSES, TRANSFER_FIELD_GROUPS, TRANSFER_RECORD_TYPES } from "./db/src/enums.js";
2
+ import { exports, importRows, imports } from "./db/src/schema/transfer.js";
2
3
  import "./db/src/schema/index.js";
3
- import { ConditionGroup } from "./automationDefinition.js";
4
- import { Id, isoDate } from "./common.js";
4
+ import { COMMON_ERRORS, ERRORS } from "./errors.js";
5
+ import { ConditionGroup } from "./db/src/automationDefinition.js";
6
+ import { CursorQuery, Id, cursorPageOf, isoDate, listOf } from "./common.js";
5
7
  import { oc } from "@orpc/contract";
6
- import { createSelectSchema } from "drizzle-zod";
7
8
  import { z } from "zod";
9
+ import { createSelectSchema } from "drizzle-zod";
8
10
  // src/transfer.ts
9
11
  const TransferRecordType = z.enum(TRANSFER_RECORD_TYPES);
12
+ /** A page of imports or exports: 50, the most the lists showed before they paged. */
13
+ const TransferPage = CursorQuery.extend({ limit: z.coerce.number().int().min(1).max(100).default(50) }).prefault({});
10
14
  /** A column imports map to and exports write: built-in fields, properties (`customFields.<id>`), tags, owner, companies. */
11
15
  const TransferColumn = z.object({
12
16
  key: z.string(),
13
17
  label: z.string(),
14
- group: z.enum([
15
- "fields",
16
- "custom",
17
- "relations"
18
- ]),
18
+ group: z.enum(TRANSFER_FIELD_GROUPS),
19
19
  importable: z.boolean(),
20
20
  exportable: z.boolean(),
21
21
  /** Exported unless the member unticks it. */
@@ -26,18 +26,8 @@ const TransferColumn = z.object({
26
26
  * takes `.partial()` of this, where a default would overwrite the stored option.
27
27
  */
28
28
  const ImportOptions = z.object({
29
- mode: z.enum([
30
- "create",
31
- "update",
32
- "upsert"
33
- ]),
34
- matchBy: z.enum([
35
- "email",
36
- "phone",
37
- "code",
38
- "id",
39
- "name"
40
- ]),
29
+ mode: z.enum(IMPORT_MODES),
30
+ matchBy: z.enum(IMPORT_MATCH_KEYS),
41
31
  tagIds: z.array(Id).max(50).optional(),
42
32
  ownerId: Id.nullable().optional(),
43
33
  createMissing: z.boolean(),
@@ -86,12 +76,7 @@ const Import = createSelectSchema(imports, {
86
76
  const ImportRow = createSelectSchema(importRows, {
87
77
  rowNumber: () => z.int(),
88
78
  cells: strings,
89
- action: () => z.enum([
90
- "create",
91
- "update",
92
- "skip",
93
- "error"
94
- ])
79
+ action: () => z.enum(IMPORT_ROW_ACTIONS)
95
80
  }).pick({
96
81
  rowNumber: true,
97
82
  cells: true,
@@ -129,22 +114,40 @@ const Export = createSelectSchema(exports, {
129
114
  finishedAt: true
130
115
  });
131
116
  /** Imports from CSV or Excel (mapped, checked, run in the background, undoable) and exports of lists. */
117
+ const { CROSS_SITE, IMPORT_LOCKED, INVALID_COLUMNS, INVALID_MAPPING, INVALID_OPTIONS, INVALID_RECIPIENT, INVALID_TAG, LIMIT_EXCEEDED, NOT_UNDOABLE, TAG_LIMIT, UNSUPPORTED_FILE, UPLOAD_CHANGED, UPLOAD_INCOMPLETE } = ERRORS;
118
+ /** What these procedures answer with besides the common errors. */
119
+ const base = oc.errors({
120
+ ...COMMON_ERRORS,
121
+ CROSS_SITE,
122
+ IMPORT_LOCKED,
123
+ INVALID_COLUMNS,
124
+ INVALID_MAPPING,
125
+ INVALID_OPTIONS,
126
+ INVALID_RECIPIENT,
127
+ INVALID_TAG,
128
+ LIMIT_EXCEEDED,
129
+ NOT_UNDOABLE,
130
+ TAG_LIMIT,
131
+ UNSUPPORTED_FILE,
132
+ UPLOAD_CHANGED,
133
+ UPLOAD_INCOMPLETE
134
+ });
132
135
  const transferContract = {
133
- columns: oc.route({
136
+ columns: base.route({
134
137
  method: "GET",
135
138
  path: "/transfer/columns",
136
139
  summary: "What imports can fill and exports can write, for a record type"
137
- }).input(z.object({ recordType: TransferRecordType })).output(z.object({ data: z.array(TransferColumn) })),
138
- imports: oc.route({
140
+ }).input(z.object({ recordType: TransferRecordType })).output(listOf(TransferColumn)),
141
+ imports: base.route({
139
142
  method: "GET",
140
143
  path: "/imports",
141
144
  summary: "Imports, newest first"
142
- }).output(z.object({ data: z.array(Import) })),
143
- import: oc.route({
145
+ }).input(TransferPage).output(cursorPageOf(Import)),
146
+ import: base.route({
144
147
  method: "GET",
145
148
  path: "/imports/{id}"
146
149
  }).input(z.object({ id: Id })).output(Import),
147
- createImport: oc.route({
150
+ createImport: base.route({
148
151
  method: "POST",
149
152
  path: "/imports",
150
153
  successStatus: 201,
@@ -153,7 +156,7 @@ const transferContract = {
153
156
  recordType: TransferRecordType,
154
157
  fileId: Id
155
158
  })).output(Import),
156
- updateImport: oc.route({
159
+ updateImport: base.route({
157
160
  method: "PATCH",
158
161
  path: "/imports/{id}",
159
162
  summary: "Set the column mapping and options (before it runs); the check result is cleared"
@@ -162,48 +165,43 @@ const transferContract = {
162
165
  mapping: z.record(z.string(), z.string()).optional(),
163
166
  options: ImportOptions.partial().optional()
164
167
  })).output(Import),
165
- checkImport: oc.route({
168
+ checkImport: base.route({
166
169
  method: "POST",
167
170
  path: "/imports/{id}/check",
168
171
  summary: "A dry run: what each row would do (create, update, skip, error), changing nothing"
169
172
  }).input(z.object({ id: Id })).output(Import),
170
- startImport: oc.route({
173
+ startImport: base.route({
171
174
  method: "POST",
172
175
  path: "/imports/{id}/start",
173
176
  summary: "Run it, in the background, in batches"
174
177
  }).input(z.object({ id: Id })).output(Import),
175
- undoImport: oc.route({
178
+ undoImport: base.route({
176
179
  method: "POST",
177
180
  path: "/imports/{id}/undo",
178
181
  summary: "Remove the records it created (to the recycle bin), within 30 days; updates stay"
179
182
  }).input(z.object({ id: Id })).output(Import),
180
- importRows: oc.route({
183
+ importRows: base.route({
181
184
  method: "GET",
182
185
  path: "/imports/{id}/rows",
183
186
  summary: "Rows of an import, by what they did (errors first for the report)"
184
187
  }).input(z.object({
185
188
  id: Id,
186
- action: z.enum([
187
- "create",
188
- "update",
189
- "skip",
190
- "error"
191
- ]).optional(),
189
+ action: z.enum(IMPORT_ROW_ACTIONS).optional(),
192
190
  limit: z.coerce.number().int().min(1).max(1e3).default(200)
193
- })).output(z.object({ data: z.array(ImportRow) })),
194
- exports: oc.route({
191
+ })).output(z.object({ data: z.array(ImportRow).max(1e3) })),
192
+ exports: base.route({
195
193
  method: "GET",
196
194
  path: "/exports",
197
195
  summary: "Exports, newest first"
198
- }).output(z.object({ data: z.array(Export) })),
199
- createExport: oc.route({
196
+ }).input(TransferPage).output(cursorPageOf(Export)),
197
+ createExport: base.route({
200
198
  method: "POST",
201
199
  path: "/exports",
202
200
  successStatus: 202,
203
201
  summary: "Export a list (its filters) to CSV or Excel in the background; a notification says when it is ready"
204
202
  }).input(z.object({
205
203
  recordType: TransferRecordType,
206
- format: z.enum(["csv", "xlsx"]).default("csv"),
204
+ format: z.enum(EXPORT_FORMATS).default("csv"),
207
205
  columns: z.array(z.string().max(100)).min(1).max(200),
208
206
  query: ExportQuery.default({})
209
207
  })).output(Export)
package/dist/trash.d.ts CHANGED
@@ -7,16 +7,15 @@ export declare const TrashItem: z.ZodObject<{
7
7
  }>;
8
8
  recordId: z.ZodString;
9
9
  label: z.ZodNullable<z.ZodString>;
10
- deletedAt: z.ZodISODateTime;
11
- purgeAt: z.ZodISODateTime;
12
- deletedBy: z.ZodObject<{
13
- type: z.ZodEnum<{
14
- plugin: "plugin";
15
- system: "system";
16
- user: "user";
17
- }>;
18
- id: z.ZodNullable<z.ZodString>;
19
- }, z.core.$strip>;
10
+ deletedByType: z.ZodEnum<{
11
+ customer: "customer";
12
+ plugin: "plugin";
13
+ system: "system";
14
+ user: "user";
15
+ }>;
16
+ deletedBy: z.ZodNullable<z.ZodString>;
17
+ deletedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
18
+ purgeAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
20
19
  counts: z.ZodObject<{
21
20
  tags: z.ZodInt;
22
21
  links: z.ZodInt;
@@ -33,6 +32,15 @@ export type TrashItem = z.infer<typeof TrashItem>;
33
32
  */
34
33
  export declare const trashContract: {
35
34
  list: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
35
+ cursor: z.ZodOptional<z.ZodString>;
36
+ direction: z.ZodDefault<z.ZodEnum<{
37
+ backward: "backward";
38
+ forward: "forward";
39
+ }>>;
40
+ cursorMode: z.ZodDefault<z.ZodEnum<{
41
+ exclusive: "exclusive";
42
+ inclusive: "inclusive";
43
+ }>>;
36
44
  type: z.ZodOptional<z.ZodEnum<{
37
45
  company: "company";
38
46
  customer: "customer";
@@ -47,16 +55,15 @@ export declare const trashContract: {
47
55
  }>;
48
56
  recordId: z.ZodString;
49
57
  label: z.ZodNullable<z.ZodString>;
50
- deletedAt: z.ZodISODateTime;
51
- purgeAt: z.ZodISODateTime;
52
- deletedBy: z.ZodObject<{
53
- type: z.ZodEnum<{
54
- plugin: "plugin";
55
- system: "system";
56
- user: "user";
57
- }>;
58
- id: z.ZodNullable<z.ZodString>;
59
- }, z.core.$strip>;
58
+ deletedByType: z.ZodEnum<{
59
+ customer: "customer";
60
+ plugin: "plugin";
61
+ system: "system";
62
+ user: "user";
63
+ }>;
64
+ deletedBy: z.ZodNullable<z.ZodString>;
65
+ deletedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
66
+ purgeAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
60
67
  counts: z.ZodObject<{
61
68
  tags: z.ZodInt;
62
69
  links: z.ZodInt;
@@ -66,7 +73,102 @@ export declare const trashContract: {
66
73
  out: {};
67
74
  in: {};
68
75
  }>>;
69
- }, z.core.$strip>, Record<never, never>, Record<never, never>>;
76
+ pageInfo: z.ZodObject<{
77
+ hasNextPage: z.ZodBoolean;
78
+ hasPreviousPage: z.ZodBoolean;
79
+ startCursor: z.ZodNullable<z.ZodString>;
80
+ endCursor: z.ZodNullable<z.ZodString>;
81
+ }, z.core.$strip>;
82
+ totalCount: z.ZodInt;
83
+ totalCapped: z.ZodOptional<z.ZodBoolean>;
84
+ }, z.core.$strip>, import("@orpc/contract").MergedErrorMap<Record<never, never>, {
85
+ UNAUTHORIZED: {
86
+ status: number;
87
+ };
88
+ NOT_ALLOWED: {
89
+ status: number;
90
+ data: z.ZodOptional<z.ZodObject<{
91
+ permission: z.ZodString;
92
+ }, z.core.$strip>>;
93
+ };
94
+ PLUGIN_ONLY: {
95
+ status: number;
96
+ };
97
+ MEMBERS_ONLY: {
98
+ status: number;
99
+ };
100
+ ORG_REQUIRED: {
101
+ status: number;
102
+ };
103
+ SCOPE_REQUIRED: {
104
+ status: number;
105
+ };
106
+ SERVICE_TOKEN_REQUIRED: {
107
+ status: number;
108
+ };
109
+ ORGANIZATION_DISABLED: {
110
+ status: number;
111
+ data: z.ZodObject<{
112
+ manageUrl: z.ZodNullable<z.ZodString>;
113
+ }, z.core.$strip>;
114
+ };
115
+ NOT_IN_PLAN: {
116
+ status: number;
117
+ data: z.ZodOptional<z.ZodObject<{
118
+ manageUrl: z.ZodNullable<z.ZodString>;
119
+ }, z.core.$strip>>;
120
+ };
121
+ READ_ONLY: {
122
+ status: number;
123
+ };
124
+ TOO_MANY_REQUESTS: {
125
+ status: number;
126
+ };
127
+ INVALID_INPUT: {
128
+ status: number;
129
+ data: z.ZodObject<{
130
+ issues: z.ZodArray<z.ZodObject<{
131
+ path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodInt]>>;
132
+ message: z.ZodString;
133
+ }, z.core.$strip>>;
134
+ }, z.core.$strip>;
135
+ };
136
+ NOT_FOUND: {
137
+ status: number;
138
+ };
139
+ TAKEN: {
140
+ status: number;
141
+ data: z.ZodObject<{
142
+ field: z.ZodString;
143
+ id: z.ZodOptional<z.ZodString>;
144
+ values: z.ZodOptional<z.ZodArray<z.ZodString>>;
145
+ }, z.core.$strip>;
146
+ };
147
+ INVALID_CURSOR: {
148
+ status: number;
149
+ };
150
+ INVALID_REFERENCE: {
151
+ status: number;
152
+ data: z.ZodObject<{
153
+ field: z.ZodString;
154
+ }, z.core.$strip>;
155
+ };
156
+ INVALID_FILTER: {
157
+ status: number;
158
+ };
159
+ FILTER_TOO_SLOW: {
160
+ status: number;
161
+ };
162
+ LIMIT_EXCEEDED: {
163
+ status: number;
164
+ };
165
+ NOTHING_TO_RETRY: {
166
+ status: number;
167
+ };
168
+ SUBJECT_REQUIRED: {
169
+ status: number;
170
+ };
171
+ }>, Record<never, never>>;
70
172
  restore: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
71
173
  ids: z.ZodArray<z.ZodString>;
72
174
  }, z.core.$strip>, z.ZodObject<{
@@ -75,10 +177,184 @@ export declare const trashContract: {
75
177
  id: z.ZodString;
76
178
  reason: z.ZodString;
77
179
  }, z.core.$strip>>;
78
- }, z.core.$strip>, Record<never, never>, Record<never, never>>;
180
+ }, z.core.$strip>, import("@orpc/contract").MergedErrorMap<Record<never, never>, {
181
+ UNAUTHORIZED: {
182
+ status: number;
183
+ };
184
+ NOT_ALLOWED: {
185
+ status: number;
186
+ data: z.ZodOptional<z.ZodObject<{
187
+ permission: z.ZodString;
188
+ }, z.core.$strip>>;
189
+ };
190
+ PLUGIN_ONLY: {
191
+ status: number;
192
+ };
193
+ MEMBERS_ONLY: {
194
+ status: number;
195
+ };
196
+ ORG_REQUIRED: {
197
+ status: number;
198
+ };
199
+ SCOPE_REQUIRED: {
200
+ status: number;
201
+ };
202
+ SERVICE_TOKEN_REQUIRED: {
203
+ status: number;
204
+ };
205
+ ORGANIZATION_DISABLED: {
206
+ status: number;
207
+ data: z.ZodObject<{
208
+ manageUrl: z.ZodNullable<z.ZodString>;
209
+ }, z.core.$strip>;
210
+ };
211
+ NOT_IN_PLAN: {
212
+ status: number;
213
+ data: z.ZodOptional<z.ZodObject<{
214
+ manageUrl: z.ZodNullable<z.ZodString>;
215
+ }, z.core.$strip>>;
216
+ };
217
+ READ_ONLY: {
218
+ status: number;
219
+ };
220
+ TOO_MANY_REQUESTS: {
221
+ status: number;
222
+ };
223
+ INVALID_INPUT: {
224
+ status: number;
225
+ data: z.ZodObject<{
226
+ issues: z.ZodArray<z.ZodObject<{
227
+ path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodInt]>>;
228
+ message: z.ZodString;
229
+ }, z.core.$strip>>;
230
+ }, z.core.$strip>;
231
+ };
232
+ NOT_FOUND: {
233
+ status: number;
234
+ };
235
+ TAKEN: {
236
+ status: number;
237
+ data: z.ZodObject<{
238
+ field: z.ZodString;
239
+ id: z.ZodOptional<z.ZodString>;
240
+ values: z.ZodOptional<z.ZodArray<z.ZodString>>;
241
+ }, z.core.$strip>;
242
+ };
243
+ INVALID_CURSOR: {
244
+ status: number;
245
+ };
246
+ INVALID_REFERENCE: {
247
+ status: number;
248
+ data: z.ZodObject<{
249
+ field: z.ZodString;
250
+ }, z.core.$strip>;
251
+ };
252
+ INVALID_FILTER: {
253
+ status: number;
254
+ };
255
+ FILTER_TOO_SLOW: {
256
+ status: number;
257
+ };
258
+ LIMIT_EXCEEDED: {
259
+ status: number;
260
+ };
261
+ NOTHING_TO_RETRY: {
262
+ status: number;
263
+ };
264
+ SUBJECT_REQUIRED: {
265
+ status: number;
266
+ };
267
+ }>, Record<never, never>>;
79
268
  purge: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
80
269
  ids: z.ZodArray<z.ZodString>;
81
270
  }, z.core.$strip>, z.ZodObject<{
82
271
  purged: z.ZodInt;
83
- }, z.core.$strip>, Record<never, never>, Record<never, never>>;
272
+ }, z.core.$strip>, import("@orpc/contract").MergedErrorMap<Record<never, never>, {
273
+ UNAUTHORIZED: {
274
+ status: number;
275
+ };
276
+ NOT_ALLOWED: {
277
+ status: number;
278
+ data: z.ZodOptional<z.ZodObject<{
279
+ permission: z.ZodString;
280
+ }, z.core.$strip>>;
281
+ };
282
+ PLUGIN_ONLY: {
283
+ status: number;
284
+ };
285
+ MEMBERS_ONLY: {
286
+ status: number;
287
+ };
288
+ ORG_REQUIRED: {
289
+ status: number;
290
+ };
291
+ SCOPE_REQUIRED: {
292
+ status: number;
293
+ };
294
+ SERVICE_TOKEN_REQUIRED: {
295
+ status: number;
296
+ };
297
+ ORGANIZATION_DISABLED: {
298
+ status: number;
299
+ data: z.ZodObject<{
300
+ manageUrl: z.ZodNullable<z.ZodString>;
301
+ }, z.core.$strip>;
302
+ };
303
+ NOT_IN_PLAN: {
304
+ status: number;
305
+ data: z.ZodOptional<z.ZodObject<{
306
+ manageUrl: z.ZodNullable<z.ZodString>;
307
+ }, z.core.$strip>>;
308
+ };
309
+ READ_ONLY: {
310
+ status: number;
311
+ };
312
+ TOO_MANY_REQUESTS: {
313
+ status: number;
314
+ };
315
+ INVALID_INPUT: {
316
+ status: number;
317
+ data: z.ZodObject<{
318
+ issues: z.ZodArray<z.ZodObject<{
319
+ path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodInt]>>;
320
+ message: z.ZodString;
321
+ }, z.core.$strip>>;
322
+ }, z.core.$strip>;
323
+ };
324
+ NOT_FOUND: {
325
+ status: number;
326
+ };
327
+ TAKEN: {
328
+ status: number;
329
+ data: z.ZodObject<{
330
+ field: z.ZodString;
331
+ id: z.ZodOptional<z.ZodString>;
332
+ values: z.ZodOptional<z.ZodArray<z.ZodString>>;
333
+ }, z.core.$strip>;
334
+ };
335
+ INVALID_CURSOR: {
336
+ status: number;
337
+ };
338
+ INVALID_REFERENCE: {
339
+ status: number;
340
+ data: z.ZodObject<{
341
+ field: z.ZodString;
342
+ }, z.core.$strip>;
343
+ };
344
+ INVALID_FILTER: {
345
+ status: number;
346
+ };
347
+ FILTER_TOO_SLOW: {
348
+ status: number;
349
+ };
350
+ LIMIT_EXCEEDED: {
351
+ status: number;
352
+ };
353
+ NOTHING_TO_RETRY: {
354
+ status: number;
355
+ };
356
+ SUBJECT_REQUIRED: {
357
+ status: number;
358
+ };
359
+ }>, Record<never, never>>;
84
360
  };
package/dist/trash.js CHANGED
@@ -1,10 +1,11 @@
1
- import { ACTOR_TYPES } from "./db/src/schema/platform.js";
1
+ import { CONTENT_TYPES } from "./db/src/enums.js";
2
2
  import { trash } from "./db/src/schema/trash.js";
3
3
  import "./db/src/schema/index.js";
4
- import { Id, isoDate } from "./common.js";
4
+ import { COMMON_ERRORS, ERRORS } from "./errors.js";
5
+ import { CursorQuery, Id, cursorPageOf, isoDate } from "./common.js";
5
6
  import { oc } from "@orpc/contract";
6
- import { createSelectSchema } from "drizzle-zod";
7
7
  import { z } from "zod";
8
+ import { createSelectSchema } from "drizzle-zod";
8
9
  // src/trash.ts
9
10
  const TrashItem = createSelectSchema(trash, {
10
11
  id: Id,
@@ -16,35 +17,41 @@ const TrashItem = createSelectSchema(trash, {
16
17
  recordType: true,
17
18
  recordId: true,
18
19
  label: true,
20
+ /** Who deleted it: a team member (`deletedBy` = user id), a plugin (its name) or `system`. */
21
+ deletedByType: true,
22
+ deletedBy: true,
19
23
  deletedAt: true,
20
24
  /** When it is gone for good. */
21
25
  purgeAt: true
22
- }).extend({
23
- deletedBy: z.object({
24
- type: z.enum(ACTOR_TYPES),
25
- id: z.string().nullable()
26
- }),
27
- /** What comes back with it. */
28
- counts: z.object({
29
- tags: z.int(),
30
- links: z.int(),
31
- activities: z.int()
32
- })
26
+ }).extend({
27
+ /** What comes back with it, counted in the query. */
28
+ counts: z.object({
29
+ tags: z.int(),
30
+ links: z.int(),
31
+ activities: z.int()
32
+ }) });
33
+ const { LIMIT_EXCEEDED, NOTHING_TO_RETRY, SUBJECT_REQUIRED } = ERRORS;
34
+ /** What these procedures answer with besides the common errors. */
35
+ const base = oc.errors({
36
+ ...COMMON_ERRORS,
37
+ LIMIT_EXCEEDED,
38
+ NOTHING_TO_RETRY,
39
+ SUBJECT_REQUIRED
33
40
  });
34
41
  /**
35
42
  * The recycle bin: deleted customers and companies stay restorable for 30
36
43
  * days — with their tags, links and timeline — then are purged for good.
37
44
  */
38
45
  const trashContract = {
39
- list: oc.route({
46
+ list: base.route({
40
47
  method: "GET",
41
48
  path: "/trash",
42
49
  summary: "Deleted customers and companies, newest first (contacts.delete)"
43
- }).input(z.object({
44
- type: z.enum(["customer", "company"]).optional(),
50
+ }).input(CursorQuery.extend({
51
+ type: z.enum(CONTENT_TYPES).optional(),
45
52
  limit: z.coerce.number().int().min(1).max(500).default(100)
46
- })).output(z.object({ data: z.array(TrashItem) })),
47
- restore: oc.route({
53
+ })).output(cursorPageOf(TrashItem)),
54
+ restore: base.route({
48
55
  method: "POST",
49
56
  path: "/trash/restore",
50
57
  summary: "Bring records back with their tags, links and timeline (409 when an email or phone is taken now)"
@@ -55,7 +62,7 @@ const trashContract = {
55
62
  reason: z.string()
56
63
  }))
57
64
  })),
58
- purge: oc.route({
65
+ purge: base.route({
59
66
  method: "POST",
60
67
  path: "/trash/purge",
61
68
  summary: "Delete for good now (privacy requests; owners)"