@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.
- package/dist/activities.d.ts +1387 -139
- package/dist/activities.js +90 -30
- package/dist/audit.d.ts +1081 -33
- package/dist/audit.js +28 -14
- package/dist/auth.d.ts +2834 -26
- package/dist/auth.js +47 -18
- package/dist/automationRuns.d.ts +7 -9
- package/dist/automationRuns.js +12 -13
- package/dist/automations.d.ts +2443 -61
- package/dist/automations.js +41 -21
- package/dist/client.d.ts +30704 -0
- package/dist/client.js +62 -0
- package/dist/common.d.ts +0 -13
- package/dist/common.js +1 -13
- package/dist/companies.d.ts +1120 -10
- package/dist/companies.js +27 -12
- package/dist/contract/routes.json.js +17 -1
- package/dist/customerAuth.d.ts +1456 -17
- package/dist/customerAuth.js +33 -16
- package/dist/customers.d.ts +1232 -11
- package/dist/customers.js +28 -13
- package/dist/{automationDefinition.d.ts → db/src/automationDefinition.d.ts} +2 -2
- package/dist/{automationDefinition.js → db/src/automationDefinition.js} +2 -2
- package/dist/db/src/enums.js +1 -3
- package/dist/db/src/schema/automations.d.ts +1 -0
- package/dist/db/src/schema/automations.js +3 -3
- package/dist/db/src/schema/index.d.ts +3 -0
- package/dist/db/src/schema/index.js +3 -2
- package/dist/db/src/schema/leads.js +2 -2
- package/dist/db/src/schema/notes.js +92 -0
- package/dist/db/src/schema/payments.js +2 -2
- package/dist/db/src/schema/platform.js +0 -5
- package/dist/db/src/schema/plugins.js +7 -2
- package/dist/db/src/schema/transfer.js +2 -2
- package/dist/errors.d.ts +516 -0
- package/dist/errors.js +218 -0
- package/dist/events.d.ts +570 -121
- package/dist/events.js +41 -24
- package/dist/fields.d.ts +1456 -16
- package/dist/fields.js +27 -19
- package/dist/files.d.ts +761 -62
- package/dist/files.js +32 -21
- package/dist/index.d.ts +25187 -618
- package/dist/index.js +8 -7
- package/dist/leads.d.ts +1105 -21
- package/dist/leads.js +31 -13
- package/dist/notifications.d.ts +689 -48
- package/dist/notifications.js +38 -18
- package/dist/organizations.d.ts +260 -2
- package/dist/organizations.js +21 -2
- package/dist/payments.d.ts +1766 -62
- package/dist/payments.js +48 -26
- package/dist/platform.d.ts +12 -21
- package/dist/platform.js +7 -17
- package/dist/plugins.d.ts +802 -71
- package/dist/plugins.js +48 -27
- package/dist/products.d.ts +1380 -17
- package/dist/products.js +32 -16
- package/dist/roles.d.ts +560 -5
- package/dist/roles.js +20 -6
- package/dist/saas.d.ts +164 -2
- package/dist/saas.js +9 -2
- package/dist/tags.d.ts +340 -4
- package/dist/tags.js +14 -6
- package/dist/transfer.d.ts +1299 -12
- package/dist/transfer.js +32 -13
- package/dist/trash.d.ts +278 -21
- package/dist/trash.js +23 -16
- package/dist/users.d.ts +1206 -18
- package/dist/users.js +35 -13
- package/dist/values.d.ts +0 -9
- package/dist/values.js +2 -7
- package/dist/views.d.ts +396 -5
- package/dist/views.js +10 -7
- package/dist/webhooks.d.ts +765 -9
- package/dist/webhooks.js +18 -10
- package/package.json +6 -2
package/dist/users.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { USER_STATUSES } from "./db/src/enums.js";
|
|
2
2
|
import { users } from "./db/src/schema/users.js";
|
|
3
3
|
import "./db/src/schema/index.js";
|
|
4
|
+
import { COMMON_ERRORS, ERRORS } from "./errors.js";
|
|
4
5
|
import { CursorQuery, DESCRIPTION_MAX, Id, IdList, ImageAddress, PhoneNumber, QueryBoolean, cursorPageOf, isoDate } from "./common.js";
|
|
5
6
|
import { InviteRole, NewPassword, RoleKey, UserLinkName } from "./values.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/users.ts
|
|
10
11
|
const UserStatus = z.enum(USER_STATUSES);
|
|
11
12
|
const UserLinks = z.record(z.string(), z.string());
|
|
@@ -16,6 +17,7 @@ const User = createSelectSchema(users, {
|
|
|
16
17
|
role: RoleKey,
|
|
17
18
|
links: UserLinks,
|
|
18
19
|
onboardedAt: isoDate,
|
|
20
|
+
totpEnabledAt: isoDate,
|
|
19
21
|
createdAt: isoDate,
|
|
20
22
|
updatedAt: isoDate
|
|
21
23
|
}).pick({
|
|
@@ -41,11 +43,11 @@ const User = createSelectSchema(users, {
|
|
|
41
43
|
links: true,
|
|
42
44
|
/** Finished the welcome steps; null shows them at the next sign-in. */
|
|
43
45
|
onboardedAt: true,
|
|
46
|
+
/** Signs in with a second step (an authenticator app's code) since then; null when off. */
|
|
47
|
+
totpEnabledAt: true,
|
|
44
48
|
createdAt: true,
|
|
45
49
|
updatedAt: true
|
|
46
|
-
})
|
|
47
|
-
/** Signs in with a second step (an authenticator app's code). */
|
|
48
|
-
twoFactorEnabled: z.boolean() });
|
|
50
|
+
});
|
|
49
51
|
/** A real calendar date, `YYYY-MM-DD` (2026-02-30 and 2026-99-99 are refused). */
|
|
50
52
|
const DateOnly = z.string().regex(/^\d{4}-\d{2}-\d{2}$/, "YYYY-MM-DD").refine((value) => {
|
|
51
53
|
const date = /* @__PURE__ */ new Date(`${value}T00:00:00Z`);
|
|
@@ -102,8 +104,28 @@ const InviteEntry = z.object({
|
|
|
102
104
|
});
|
|
103
105
|
/** Something to change: at least one field besides `id`. */
|
|
104
106
|
const changes = (value) => Object.keys(value).some((key) => key !== "id");
|
|
107
|
+
const { BEYOND_OWN_PERMISSIONS, BUILTIN_ROLE, FIXED_ROLE, INVALID_LINK, INVALID_RECIPIENT, LAST_OWNER, LIMIT_EXCEEDED, NOT_INVITED, OWNER_ONLY, OWNER_ONLY_PERMISSION, OWN_ACCOUNT, OWN_ROLE, ROLE_IN_USE, ROLE_NOT_FOUND, UNKNOWN_PERMISSION } = ERRORS;
|
|
108
|
+
/** What these procedures answer with besides the common errors. */
|
|
109
|
+
const base = oc.errors({
|
|
110
|
+
...COMMON_ERRORS,
|
|
111
|
+
BEYOND_OWN_PERMISSIONS,
|
|
112
|
+
BUILTIN_ROLE,
|
|
113
|
+
FIXED_ROLE,
|
|
114
|
+
INVALID_LINK,
|
|
115
|
+
INVALID_RECIPIENT,
|
|
116
|
+
LAST_OWNER,
|
|
117
|
+
LIMIT_EXCEEDED,
|
|
118
|
+
NOT_INVITED,
|
|
119
|
+
OWNER_ONLY,
|
|
120
|
+
OWNER_ONLY_PERMISSION,
|
|
121
|
+
OWN_ACCOUNT,
|
|
122
|
+
OWN_ROLE,
|
|
123
|
+
ROLE_IN_USE,
|
|
124
|
+
ROLE_NOT_FOUND,
|
|
125
|
+
UNKNOWN_PERMISSION
|
|
126
|
+
});
|
|
105
127
|
const usersContract = {
|
|
106
|
-
list:
|
|
128
|
+
list: base.route({
|
|
107
129
|
method: "GET",
|
|
108
130
|
path: "/users",
|
|
109
131
|
summary: "Team members of the organisation, newest first"
|
|
@@ -115,33 +137,33 @@ const usersContract = {
|
|
|
115
137
|
role: RoleKey.optional(),
|
|
116
138
|
ids: IdList.optional()
|
|
117
139
|
})).output(cursorPageOf(User)),
|
|
118
|
-
resendInvitation:
|
|
140
|
+
resendInvitation: base.route({
|
|
119
141
|
method: "POST",
|
|
120
142
|
path: "/users/{id}/invitation",
|
|
121
143
|
summary: "Email an invited member a new invitation link (earlier links stop working)"
|
|
122
144
|
}).input(z.object({ id: Id })).output(z.object({ ok: z.literal(true) })),
|
|
123
|
-
get:
|
|
145
|
+
get: base.route({
|
|
124
146
|
method: "GET",
|
|
125
147
|
path: "/users/{id}"
|
|
126
148
|
}).input(z.object({ id: Id })).output(User),
|
|
127
|
-
invite:
|
|
149
|
+
invite: base.route({
|
|
128
150
|
method: "POST",
|
|
129
151
|
path: "/users",
|
|
130
152
|
successStatus: 201,
|
|
131
153
|
summary: "Invite a team member (owners and admins)"
|
|
132
154
|
}).input(InviteEntry).output(User),
|
|
133
|
-
inviteMany:
|
|
155
|
+
inviteMany: base.route({
|
|
134
156
|
method: "POST",
|
|
135
157
|
path: "/users/invitations",
|
|
136
158
|
successStatus: 201,
|
|
137
159
|
summary: "Invite several team members at once, all or none (owners and admins)"
|
|
138
160
|
}).input(z.object({ entries: z.array(InviteEntry).min(1).max(50) })).output(z.object({ data: z.array(User).max(50) })),
|
|
139
|
-
update:
|
|
161
|
+
update: base.route({
|
|
140
162
|
method: "PATCH",
|
|
141
163
|
path: "/users/{id}",
|
|
142
164
|
summary: "Update a team member (self: own profile; owners/admins: anyone’s profile and role; only owners change an owner’s email)"
|
|
143
165
|
}).input(UserFields.extend({ id: Id }).refine(changes, "nothing to update")).output(User),
|
|
144
|
-
setPassword:
|
|
166
|
+
setPassword: base.route({
|
|
145
167
|
method: "POST",
|
|
146
168
|
path: "/users/{id}/password",
|
|
147
169
|
summary: "Set another member’s password (owners and admins; an invited member becomes active)"
|
|
@@ -149,11 +171,11 @@ const usersContract = {
|
|
|
149
171
|
id: Id,
|
|
150
172
|
password: NewPassword
|
|
151
173
|
})).output(User),
|
|
152
|
-
disable:
|
|
174
|
+
disable: base.route({
|
|
153
175
|
method: "POST",
|
|
154
176
|
path: "/users/{id}/disable"
|
|
155
177
|
}).input(z.object({ id: Id })).output(User),
|
|
156
|
-
enable:
|
|
178
|
+
enable: base.route({
|
|
157
179
|
method: "POST",
|
|
158
180
|
path: "/users/{id}/enable"
|
|
159
181
|
}).input(z.object({ id: Id })).output(User)
|
package/dist/values.d.ts
CHANGED
|
@@ -111,15 +111,6 @@ export declare const LiveMode: z.ZodEnum<{
|
|
|
111
111
|
live: "live";
|
|
112
112
|
polling: "polling";
|
|
113
113
|
}>;
|
|
114
|
-
/** The `data` of a 409 `CUSTOMER_EXISTS`: the customer that has the value, and which field it is. */
|
|
115
|
-
export declare const CustomerExists: z.ZodObject<{
|
|
116
|
-
id: z.ZodNullable<z.ZodString>;
|
|
117
|
-
field: z.ZodEnum<{
|
|
118
|
-
primaryEmail: "primaryEmail";
|
|
119
|
-
primaryPhone: "primaryPhone";
|
|
120
|
-
}>;
|
|
121
|
-
}, z.core.$strip>;
|
|
122
|
-
export type CustomerExists = z.infer<typeof CustomerExists>;
|
|
123
114
|
/**
|
|
124
115
|
* Core's notifications in groups a member chooses for at once (each plugin
|
|
125
116
|
* is a group of its own). `security` is always on.
|
package/dist/values.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AUDIT_STREAM_FORMATS, AUTOMATION_STATUSES, CUSTOMER_SEXES,
|
|
1
|
+
import { AUDIT_STREAM_FORMATS, AUTOMATION_STATUSES, CUSTOMER_SEXES, FIELD_TYPES, FIELD_VALIDATIONS, INVOICE_STATUSES, LIVE_MODES, NOTIFICATION_DELIVERIES, PAYMENT_GATEWAY_KINDS, PRODUCT_KINDS } from "./db/src/enums.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
// src/values.ts
|
|
4
4
|
const CORE_API_VERSION = "v1";
|
|
@@ -83,11 +83,6 @@ const UNMUTABLE_NOTIFICATION_KINDS = [
|
|
|
83
83
|
const NotificationDelivery = z.enum(NOTIFICATION_DELIVERIES);
|
|
84
84
|
/** How the live stream reaches this browser, in its `hello` event: pushing, or polling while it can't listen. */
|
|
85
85
|
const LiveMode = z.enum(LIVE_MODES);
|
|
86
|
-
/** The `data` of a 409 `CUSTOMER_EXISTS`: the customer that has the value, and which field it is. */
|
|
87
|
-
const CustomerExists = z.object({
|
|
88
|
-
id: z.string().nullable(),
|
|
89
|
-
field: z.enum(CUSTOMER_UNIQUE_FIELDS)
|
|
90
|
-
});
|
|
91
86
|
/**
|
|
92
87
|
* Core's notifications in groups a member chooses for at once (each plugin
|
|
93
88
|
* is a group of its own). `security` is always on.
|
|
@@ -141,4 +136,4 @@ const CORE_NOTIFICATION_GROUPS = [
|
|
|
141
136
|
];
|
|
142
137
|
/** The group a notification belongs to: a core group, or the plugin that sent it. */
|
|
143
138
|
const notificationGroupOf = (source, kind) => source === "core" ? CORE_NOTIFICATION_GROUPS.find((group) => group.kinds.includes(kind))?.key ?? "records" : source;
|
|
144
|
-
export { AuditStreamFormat, AutomationStatus, CORE_API_PREFIX, CORE_API_VERSION, CORE_NOTIFICATION_GROUPS,
|
|
139
|
+
export { AuditStreamFormat, AutomationStatus, CORE_API_PREFIX, CORE_API_VERSION, CORE_NOTIFICATION_GROUPS, CustomerSex, FIELD_TYPE_FAMILIES, FieldType, FieldValidation, InviteRole, InvoiceStatus, LiveMode, NewPassword, NotificationDelivery, OPTION_FIELD_TYPES, PAYMENT_GATEWAYS, PaymentGatewayKind, ProductKind, RoleKey, UNMUTABLE_NOTIFICATION_KINDS, USER_LINK_NAMES, UserLinkName, gatewayTakes, notificationGroupOf };
|
package/dist/views.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ConditionGroup } from "./db/src/schema/common.js";
|
|
2
|
+
import "./db/src/schema/index.js";
|
|
2
3
|
import { z } from "zod";
|
|
3
4
|
/** The list a view belongs to: customers, leads (people), companies, company leads, products. */
|
|
4
5
|
export declare const ViewRecordType: z.ZodEnum<{
|
|
@@ -116,7 +117,85 @@ export declare const viewsContract: {
|
|
|
116
117
|
out: {};
|
|
117
118
|
in: {};
|
|
118
119
|
}>>;
|
|
119
|
-
}, z.core.$strip>, Record<never, never>,
|
|
120
|
+
}, z.core.$strip>, import("@orpc/contract").MergedErrorMap<Record<never, never>, {
|
|
121
|
+
UNAUTHORIZED: {
|
|
122
|
+
status: number;
|
|
123
|
+
};
|
|
124
|
+
NOT_ALLOWED: {
|
|
125
|
+
status: number;
|
|
126
|
+
data: z.ZodOptional<z.ZodObject<{
|
|
127
|
+
permission: z.ZodString;
|
|
128
|
+
}, z.core.$strip>>;
|
|
129
|
+
};
|
|
130
|
+
PLUGIN_ONLY: {
|
|
131
|
+
status: number;
|
|
132
|
+
};
|
|
133
|
+
MEMBERS_ONLY: {
|
|
134
|
+
status: number;
|
|
135
|
+
};
|
|
136
|
+
ORG_REQUIRED: {
|
|
137
|
+
status: number;
|
|
138
|
+
};
|
|
139
|
+
SCOPE_REQUIRED: {
|
|
140
|
+
status: number;
|
|
141
|
+
};
|
|
142
|
+
SERVICE_TOKEN_REQUIRED: {
|
|
143
|
+
status: number;
|
|
144
|
+
};
|
|
145
|
+
ORGANIZATION_DISABLED: {
|
|
146
|
+
status: number;
|
|
147
|
+
data: z.ZodObject<{
|
|
148
|
+
manageUrl: z.ZodNullable<z.ZodString>;
|
|
149
|
+
}, z.core.$strip>;
|
|
150
|
+
};
|
|
151
|
+
NOT_IN_PLAN: {
|
|
152
|
+
status: number;
|
|
153
|
+
data: z.ZodOptional<z.ZodObject<{
|
|
154
|
+
manageUrl: z.ZodNullable<z.ZodString>;
|
|
155
|
+
}, z.core.$strip>>;
|
|
156
|
+
};
|
|
157
|
+
READ_ONLY: {
|
|
158
|
+
status: number;
|
|
159
|
+
};
|
|
160
|
+
TOO_MANY_REQUESTS: {
|
|
161
|
+
status: number;
|
|
162
|
+
};
|
|
163
|
+
INVALID_INPUT: {
|
|
164
|
+
status: number;
|
|
165
|
+
data: z.ZodObject<{
|
|
166
|
+
issues: z.ZodArray<z.ZodObject<{
|
|
167
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodInt]>>;
|
|
168
|
+
message: z.ZodString;
|
|
169
|
+
}, z.core.$strip>>;
|
|
170
|
+
}, z.core.$strip>;
|
|
171
|
+
};
|
|
172
|
+
NOT_FOUND: {
|
|
173
|
+
status: number;
|
|
174
|
+
};
|
|
175
|
+
TAKEN: {
|
|
176
|
+
status: number;
|
|
177
|
+
data: z.ZodObject<{
|
|
178
|
+
field: z.ZodString;
|
|
179
|
+
id: z.ZodOptional<z.ZodString>;
|
|
180
|
+
values: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
181
|
+
}, z.core.$strip>;
|
|
182
|
+
};
|
|
183
|
+
INVALID_CURSOR: {
|
|
184
|
+
status: number;
|
|
185
|
+
};
|
|
186
|
+
INVALID_REFERENCE: {
|
|
187
|
+
status: number;
|
|
188
|
+
data: z.ZodObject<{
|
|
189
|
+
field: z.ZodString;
|
|
190
|
+
}, z.core.$strip>;
|
|
191
|
+
};
|
|
192
|
+
INVALID_FILTER: {
|
|
193
|
+
status: number;
|
|
194
|
+
};
|
|
195
|
+
FILTER_TOO_SLOW: {
|
|
196
|
+
status: number;
|
|
197
|
+
};
|
|
198
|
+
}>, Record<never, never>>;
|
|
120
199
|
create: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
|
|
121
200
|
name: z.ZodNonOptional<z.ZodOptional<z.ZodString>>;
|
|
122
201
|
filter: z.ZodOptional<z.ZodNullable<z.ZodType<ConditionGroup, unknown, z.core.$ZodTypeInternals<ConditionGroup, unknown>>>>;
|
|
@@ -168,7 +247,85 @@ export declare const viewsContract: {
|
|
|
168
247
|
}, {
|
|
169
248
|
out: {};
|
|
170
249
|
in: {};
|
|
171
|
-
}>, Record<never, never>,
|
|
250
|
+
}>, import("@orpc/contract").MergedErrorMap<Record<never, never>, {
|
|
251
|
+
UNAUTHORIZED: {
|
|
252
|
+
status: number;
|
|
253
|
+
};
|
|
254
|
+
NOT_ALLOWED: {
|
|
255
|
+
status: number;
|
|
256
|
+
data: z.ZodOptional<z.ZodObject<{
|
|
257
|
+
permission: z.ZodString;
|
|
258
|
+
}, z.core.$strip>>;
|
|
259
|
+
};
|
|
260
|
+
PLUGIN_ONLY: {
|
|
261
|
+
status: number;
|
|
262
|
+
};
|
|
263
|
+
MEMBERS_ONLY: {
|
|
264
|
+
status: number;
|
|
265
|
+
};
|
|
266
|
+
ORG_REQUIRED: {
|
|
267
|
+
status: number;
|
|
268
|
+
};
|
|
269
|
+
SCOPE_REQUIRED: {
|
|
270
|
+
status: number;
|
|
271
|
+
};
|
|
272
|
+
SERVICE_TOKEN_REQUIRED: {
|
|
273
|
+
status: number;
|
|
274
|
+
};
|
|
275
|
+
ORGANIZATION_DISABLED: {
|
|
276
|
+
status: number;
|
|
277
|
+
data: z.ZodObject<{
|
|
278
|
+
manageUrl: z.ZodNullable<z.ZodString>;
|
|
279
|
+
}, z.core.$strip>;
|
|
280
|
+
};
|
|
281
|
+
NOT_IN_PLAN: {
|
|
282
|
+
status: number;
|
|
283
|
+
data: z.ZodOptional<z.ZodObject<{
|
|
284
|
+
manageUrl: z.ZodNullable<z.ZodString>;
|
|
285
|
+
}, z.core.$strip>>;
|
|
286
|
+
};
|
|
287
|
+
READ_ONLY: {
|
|
288
|
+
status: number;
|
|
289
|
+
};
|
|
290
|
+
TOO_MANY_REQUESTS: {
|
|
291
|
+
status: number;
|
|
292
|
+
};
|
|
293
|
+
INVALID_INPUT: {
|
|
294
|
+
status: number;
|
|
295
|
+
data: z.ZodObject<{
|
|
296
|
+
issues: z.ZodArray<z.ZodObject<{
|
|
297
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodInt]>>;
|
|
298
|
+
message: z.ZodString;
|
|
299
|
+
}, z.core.$strip>>;
|
|
300
|
+
}, z.core.$strip>;
|
|
301
|
+
};
|
|
302
|
+
NOT_FOUND: {
|
|
303
|
+
status: number;
|
|
304
|
+
};
|
|
305
|
+
TAKEN: {
|
|
306
|
+
status: number;
|
|
307
|
+
data: z.ZodObject<{
|
|
308
|
+
field: z.ZodString;
|
|
309
|
+
id: z.ZodOptional<z.ZodString>;
|
|
310
|
+
values: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
311
|
+
}, z.core.$strip>;
|
|
312
|
+
};
|
|
313
|
+
INVALID_CURSOR: {
|
|
314
|
+
status: number;
|
|
315
|
+
};
|
|
316
|
+
INVALID_REFERENCE: {
|
|
317
|
+
status: number;
|
|
318
|
+
data: z.ZodObject<{
|
|
319
|
+
field: z.ZodString;
|
|
320
|
+
}, z.core.$strip>;
|
|
321
|
+
};
|
|
322
|
+
INVALID_FILTER: {
|
|
323
|
+
status: number;
|
|
324
|
+
};
|
|
325
|
+
FILTER_TOO_SLOW: {
|
|
326
|
+
status: number;
|
|
327
|
+
};
|
|
328
|
+
}>, Record<never, never>>;
|
|
172
329
|
update: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
|
|
173
330
|
name: z.ZodOptional<z.ZodString>;
|
|
174
331
|
filter: z.ZodOptional<z.ZodNullable<z.ZodType<ConditionGroup, unknown, z.core.$ZodTypeInternals<ConditionGroup, unknown>>>>;
|
|
@@ -214,12 +371,168 @@ export declare const viewsContract: {
|
|
|
214
371
|
}, {
|
|
215
372
|
out: {};
|
|
216
373
|
in: {};
|
|
217
|
-
}>, Record<never, never>,
|
|
374
|
+
}>, import("@orpc/contract").MergedErrorMap<Record<never, never>, {
|
|
375
|
+
UNAUTHORIZED: {
|
|
376
|
+
status: number;
|
|
377
|
+
};
|
|
378
|
+
NOT_ALLOWED: {
|
|
379
|
+
status: number;
|
|
380
|
+
data: z.ZodOptional<z.ZodObject<{
|
|
381
|
+
permission: z.ZodString;
|
|
382
|
+
}, z.core.$strip>>;
|
|
383
|
+
};
|
|
384
|
+
PLUGIN_ONLY: {
|
|
385
|
+
status: number;
|
|
386
|
+
};
|
|
387
|
+
MEMBERS_ONLY: {
|
|
388
|
+
status: number;
|
|
389
|
+
};
|
|
390
|
+
ORG_REQUIRED: {
|
|
391
|
+
status: number;
|
|
392
|
+
};
|
|
393
|
+
SCOPE_REQUIRED: {
|
|
394
|
+
status: number;
|
|
395
|
+
};
|
|
396
|
+
SERVICE_TOKEN_REQUIRED: {
|
|
397
|
+
status: number;
|
|
398
|
+
};
|
|
399
|
+
ORGANIZATION_DISABLED: {
|
|
400
|
+
status: number;
|
|
401
|
+
data: z.ZodObject<{
|
|
402
|
+
manageUrl: z.ZodNullable<z.ZodString>;
|
|
403
|
+
}, z.core.$strip>;
|
|
404
|
+
};
|
|
405
|
+
NOT_IN_PLAN: {
|
|
406
|
+
status: number;
|
|
407
|
+
data: z.ZodOptional<z.ZodObject<{
|
|
408
|
+
manageUrl: z.ZodNullable<z.ZodString>;
|
|
409
|
+
}, z.core.$strip>>;
|
|
410
|
+
};
|
|
411
|
+
READ_ONLY: {
|
|
412
|
+
status: number;
|
|
413
|
+
};
|
|
414
|
+
TOO_MANY_REQUESTS: {
|
|
415
|
+
status: number;
|
|
416
|
+
};
|
|
417
|
+
INVALID_INPUT: {
|
|
418
|
+
status: number;
|
|
419
|
+
data: z.ZodObject<{
|
|
420
|
+
issues: z.ZodArray<z.ZodObject<{
|
|
421
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodInt]>>;
|
|
422
|
+
message: z.ZodString;
|
|
423
|
+
}, z.core.$strip>>;
|
|
424
|
+
}, z.core.$strip>;
|
|
425
|
+
};
|
|
426
|
+
NOT_FOUND: {
|
|
427
|
+
status: number;
|
|
428
|
+
};
|
|
429
|
+
TAKEN: {
|
|
430
|
+
status: number;
|
|
431
|
+
data: z.ZodObject<{
|
|
432
|
+
field: z.ZodString;
|
|
433
|
+
id: z.ZodOptional<z.ZodString>;
|
|
434
|
+
values: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
435
|
+
}, z.core.$strip>;
|
|
436
|
+
};
|
|
437
|
+
INVALID_CURSOR: {
|
|
438
|
+
status: number;
|
|
439
|
+
};
|
|
440
|
+
INVALID_REFERENCE: {
|
|
441
|
+
status: number;
|
|
442
|
+
data: z.ZodObject<{
|
|
443
|
+
field: z.ZodString;
|
|
444
|
+
}, z.core.$strip>;
|
|
445
|
+
};
|
|
446
|
+
INVALID_FILTER: {
|
|
447
|
+
status: number;
|
|
448
|
+
};
|
|
449
|
+
FILTER_TOO_SLOW: {
|
|
450
|
+
status: number;
|
|
451
|
+
};
|
|
452
|
+
}>, Record<never, never>>;
|
|
218
453
|
remove: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
|
|
219
454
|
id: z.ZodString;
|
|
220
455
|
}, z.core.$strip>, z.ZodObject<{
|
|
221
456
|
ok: z.ZodLiteral<true>;
|
|
222
|
-
}, z.core.$strip>, Record<never, never>,
|
|
457
|
+
}, z.core.$strip>, import("@orpc/contract").MergedErrorMap<Record<never, never>, {
|
|
458
|
+
UNAUTHORIZED: {
|
|
459
|
+
status: number;
|
|
460
|
+
};
|
|
461
|
+
NOT_ALLOWED: {
|
|
462
|
+
status: number;
|
|
463
|
+
data: z.ZodOptional<z.ZodObject<{
|
|
464
|
+
permission: z.ZodString;
|
|
465
|
+
}, z.core.$strip>>;
|
|
466
|
+
};
|
|
467
|
+
PLUGIN_ONLY: {
|
|
468
|
+
status: number;
|
|
469
|
+
};
|
|
470
|
+
MEMBERS_ONLY: {
|
|
471
|
+
status: number;
|
|
472
|
+
};
|
|
473
|
+
ORG_REQUIRED: {
|
|
474
|
+
status: number;
|
|
475
|
+
};
|
|
476
|
+
SCOPE_REQUIRED: {
|
|
477
|
+
status: number;
|
|
478
|
+
};
|
|
479
|
+
SERVICE_TOKEN_REQUIRED: {
|
|
480
|
+
status: number;
|
|
481
|
+
};
|
|
482
|
+
ORGANIZATION_DISABLED: {
|
|
483
|
+
status: number;
|
|
484
|
+
data: z.ZodObject<{
|
|
485
|
+
manageUrl: z.ZodNullable<z.ZodString>;
|
|
486
|
+
}, z.core.$strip>;
|
|
487
|
+
};
|
|
488
|
+
NOT_IN_PLAN: {
|
|
489
|
+
status: number;
|
|
490
|
+
data: z.ZodOptional<z.ZodObject<{
|
|
491
|
+
manageUrl: z.ZodNullable<z.ZodString>;
|
|
492
|
+
}, z.core.$strip>>;
|
|
493
|
+
};
|
|
494
|
+
READ_ONLY: {
|
|
495
|
+
status: number;
|
|
496
|
+
};
|
|
497
|
+
TOO_MANY_REQUESTS: {
|
|
498
|
+
status: number;
|
|
499
|
+
};
|
|
500
|
+
INVALID_INPUT: {
|
|
501
|
+
status: number;
|
|
502
|
+
data: z.ZodObject<{
|
|
503
|
+
issues: z.ZodArray<z.ZodObject<{
|
|
504
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodInt]>>;
|
|
505
|
+
message: z.ZodString;
|
|
506
|
+
}, z.core.$strip>>;
|
|
507
|
+
}, z.core.$strip>;
|
|
508
|
+
};
|
|
509
|
+
NOT_FOUND: {
|
|
510
|
+
status: number;
|
|
511
|
+
};
|
|
512
|
+
TAKEN: {
|
|
513
|
+
status: number;
|
|
514
|
+
data: z.ZodObject<{
|
|
515
|
+
field: z.ZodString;
|
|
516
|
+
id: z.ZodOptional<z.ZodString>;
|
|
517
|
+
values: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
518
|
+
}, z.core.$strip>;
|
|
519
|
+
};
|
|
520
|
+
INVALID_CURSOR: {
|
|
521
|
+
status: number;
|
|
522
|
+
};
|
|
523
|
+
INVALID_REFERENCE: {
|
|
524
|
+
status: number;
|
|
525
|
+
data: z.ZodObject<{
|
|
526
|
+
field: z.ZodString;
|
|
527
|
+
}, z.core.$strip>;
|
|
528
|
+
};
|
|
529
|
+
INVALID_FILTER: {
|
|
530
|
+
status: number;
|
|
531
|
+
};
|
|
532
|
+
FILTER_TOO_SLOW: {
|
|
533
|
+
status: number;
|
|
534
|
+
};
|
|
535
|
+
}>, Record<never, never>>;
|
|
223
536
|
fields: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
|
|
224
537
|
recordType: z.ZodEnum<{
|
|
225
538
|
company: "company";
|
|
@@ -250,5 +563,83 @@ export declare const viewsContract: {
|
|
|
250
563
|
lead: "lead";
|
|
251
564
|
}>;
|
|
252
565
|
}, z.core.$strip>>;
|
|
253
|
-
}, z.core.$strip>, Record<never, never>,
|
|
566
|
+
}, z.core.$strip>, import("@orpc/contract").MergedErrorMap<Record<never, never>, {
|
|
567
|
+
UNAUTHORIZED: {
|
|
568
|
+
status: number;
|
|
569
|
+
};
|
|
570
|
+
NOT_ALLOWED: {
|
|
571
|
+
status: number;
|
|
572
|
+
data: z.ZodOptional<z.ZodObject<{
|
|
573
|
+
permission: z.ZodString;
|
|
574
|
+
}, z.core.$strip>>;
|
|
575
|
+
};
|
|
576
|
+
PLUGIN_ONLY: {
|
|
577
|
+
status: number;
|
|
578
|
+
};
|
|
579
|
+
MEMBERS_ONLY: {
|
|
580
|
+
status: number;
|
|
581
|
+
};
|
|
582
|
+
ORG_REQUIRED: {
|
|
583
|
+
status: number;
|
|
584
|
+
};
|
|
585
|
+
SCOPE_REQUIRED: {
|
|
586
|
+
status: number;
|
|
587
|
+
};
|
|
588
|
+
SERVICE_TOKEN_REQUIRED: {
|
|
589
|
+
status: number;
|
|
590
|
+
};
|
|
591
|
+
ORGANIZATION_DISABLED: {
|
|
592
|
+
status: number;
|
|
593
|
+
data: z.ZodObject<{
|
|
594
|
+
manageUrl: z.ZodNullable<z.ZodString>;
|
|
595
|
+
}, z.core.$strip>;
|
|
596
|
+
};
|
|
597
|
+
NOT_IN_PLAN: {
|
|
598
|
+
status: number;
|
|
599
|
+
data: z.ZodOptional<z.ZodObject<{
|
|
600
|
+
manageUrl: z.ZodNullable<z.ZodString>;
|
|
601
|
+
}, z.core.$strip>>;
|
|
602
|
+
};
|
|
603
|
+
READ_ONLY: {
|
|
604
|
+
status: number;
|
|
605
|
+
};
|
|
606
|
+
TOO_MANY_REQUESTS: {
|
|
607
|
+
status: number;
|
|
608
|
+
};
|
|
609
|
+
INVALID_INPUT: {
|
|
610
|
+
status: number;
|
|
611
|
+
data: z.ZodObject<{
|
|
612
|
+
issues: z.ZodArray<z.ZodObject<{
|
|
613
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodInt]>>;
|
|
614
|
+
message: z.ZodString;
|
|
615
|
+
}, z.core.$strip>>;
|
|
616
|
+
}, z.core.$strip>;
|
|
617
|
+
};
|
|
618
|
+
NOT_FOUND: {
|
|
619
|
+
status: number;
|
|
620
|
+
};
|
|
621
|
+
TAKEN: {
|
|
622
|
+
status: number;
|
|
623
|
+
data: z.ZodObject<{
|
|
624
|
+
field: z.ZodString;
|
|
625
|
+
id: z.ZodOptional<z.ZodString>;
|
|
626
|
+
values: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
627
|
+
}, z.core.$strip>;
|
|
628
|
+
};
|
|
629
|
+
INVALID_CURSOR: {
|
|
630
|
+
status: number;
|
|
631
|
+
};
|
|
632
|
+
INVALID_REFERENCE: {
|
|
633
|
+
status: number;
|
|
634
|
+
data: z.ZodObject<{
|
|
635
|
+
field: z.ZodString;
|
|
636
|
+
}, z.core.$strip>;
|
|
637
|
+
};
|
|
638
|
+
INVALID_FILTER: {
|
|
639
|
+
status: number;
|
|
640
|
+
};
|
|
641
|
+
FILTER_TOO_SLOW: {
|
|
642
|
+
status: number;
|
|
643
|
+
};
|
|
644
|
+
}>, Record<never, never>>;
|
|
254
645
|
};
|
package/dist/views.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { FILTER_FIELD_GROUPS, FILTER_FIELD_TYPES, SORT_DIRECTIONS, VIEW_RECORD_TYPES } from "./db/src/enums.js";
|
|
2
2
|
import { views } from "./db/src/schema/views.js";
|
|
3
3
|
import "./db/src/schema/index.js";
|
|
4
|
-
import {
|
|
4
|
+
import { COMMON_ERRORS } from "./errors.js";
|
|
5
|
+
import { ConditionGroup } from "./db/src/automationDefinition.js";
|
|
5
6
|
import { Id, isoDate, listOf } from "./common.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/views.ts
|
|
10
11
|
/** The list a view belongs to: customers, leads (people), companies, company leads, products. */
|
|
11
12
|
const ViewRecordType = z.enum(VIEW_RECORD_TYPES);
|
|
@@ -67,29 +68,31 @@ const ViewFields = createUpdateSchema(views, {
|
|
|
67
68
|
sort: true,
|
|
68
69
|
shared: true
|
|
69
70
|
});
|
|
71
|
+
/** Views answer with the common errors only. */
|
|
72
|
+
const base = oc.errors(COMMON_ERRORS);
|
|
70
73
|
/** Saved lists (views) and what lists can be filtered by. */
|
|
71
74
|
const viewsContract = {
|
|
72
|
-
list:
|
|
75
|
+
list: base.route({
|
|
73
76
|
method: "GET",
|
|
74
77
|
path: "/views",
|
|
75
78
|
summary: "Views of a list: the member's own and the team's shared ones"
|
|
76
79
|
}).input(z.object({ recordType: ViewRecordType })).output(listOf(View)),
|
|
77
|
-
create:
|
|
80
|
+
create: base.route({
|
|
78
81
|
method: "POST",
|
|
79
82
|
path: "/views",
|
|
80
83
|
successStatus: 201,
|
|
81
84
|
summary: "Save a view (sharing it with the team needs contacts.edit; for products, products.manage)"
|
|
82
85
|
}).input(ViewFields.required({ name: true }).extend({ recordType: ViewRecordType })).output(View),
|
|
83
|
-
update:
|
|
86
|
+
update: base.route({
|
|
84
87
|
method: "PATCH",
|
|
85
88
|
path: "/views/{id}",
|
|
86
89
|
summary: "Change a view (its creator; a shared one also members who may share: contacts.edit, products.manage)"
|
|
87
90
|
}).input(ViewFields.extend({ id: Id })).output(View),
|
|
88
|
-
remove:
|
|
91
|
+
remove: base.route({
|
|
89
92
|
method: "DELETE",
|
|
90
93
|
path: "/views/{id}"
|
|
91
94
|
}).input(z.object({ id: Id })).output(z.object({ ok: z.literal(true) })),
|
|
92
|
-
fields:
|
|
95
|
+
fields: base.route({
|
|
93
96
|
method: "GET",
|
|
94
97
|
path: "/views/fields",
|
|
95
98
|
summary: "What a list can be filtered by: fields, custom fields, the company, activity"
|