@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.
- package/dist/activities.d.ts +1394 -139
- package/dist/activities.js +96 -40
- package/dist/audit.d.ts +1092 -48
- package/dist/audit.js +37 -23
- package/dist/auth.d.ts +2867 -61
- package/dist/auth.js +55 -25
- package/dist/automationRuns.d.ts +12 -13
- package/dist/automationRuns.js +15 -30
- package/dist/automations.d.ts +2474 -93
- package/dist/automations.js +56 -44
- package/dist/client.d.ts +30704 -0
- package/dist/client.js +62 -0
- package/dist/common.d.ts +28 -16
- package/dist/common.js +30 -22
- package/dist/companies.d.ts +1154 -44
- package/dist/companies.js +33 -17
- package/dist/contract/routes.json.js +1810 -0
- package/dist/customerAuth.d.ts +1661 -0
- package/dist/customerAuth.js +197 -0
- package/dist/customers.d.ts +1283 -65
- package/dist/customers.js +35 -25
- package/dist/{automationDefinition.d.ts → db/src/automationDefinition.d.ts} +4 -3
- package/dist/{automationDefinition.js → db/src/automationDefinition.js} +10 -32
- package/dist/db/src/enums.d.ts +8 -0
- package/dist/db/src/enums.js +334 -0
- package/dist/db/src/schema/auditStreams.js +6 -14
- package/dist/db/src/schema/authTokens.js +4 -6
- package/dist/db/src/schema/automations.d.ts +1 -0
- package/dist/db/src/schema/automations.js +15 -31
- package/dist/db/src/schema/common.d.ts +2 -6
- package/dist/db/src/schema/common.js +1 -24
- package/dist/db/src/schema/companies.js +6 -5
- package/dist/db/src/schema/customerAuth.js +101 -0
- package/dist/db/src/schema/customers.js +6 -6
- package/dist/db/src/schema/events.js +12 -60
- package/dist/db/src/schema/fieldValues.js +2 -2
- package/dist/db/src/schema/fields.js +10 -28
- package/dist/db/src/schema/index.d.ts +3 -0
- package/dist/db/src/schema/index.js +22 -20
- package/dist/db/src/schema/leadStages.js +5 -10
- package/dist/db/src/schema/leads.js +6 -11
- package/dist/db/src/schema/notes.js +92 -0
- package/dist/db/src/schema/oauth.js +3 -3
- package/dist/db/src/schema/payments.js +13 -23
- package/dist/db/src/schema/platform.js +11 -31
- package/dist/db/src/schema/plugins.js +10 -5
- package/dist/db/src/schema/products.js +7 -8
- package/dist/db/src/schema/rateLimits.js +7 -0
- package/dist/db/src/schema/saas.js +3 -9
- package/dist/db/src/schema/tags.js +6 -5
- package/dist/db/src/schema/transfer.js +13 -33
- package/dist/db/src/schema/trash.js +6 -7
- package/dist/db/src/schema/users.js +6 -10
- package/dist/db/src/schema/views.js +5 -13
- package/dist/db/src/schema/webhooks.js +7 -14
- package/dist/db/src/table.js +16 -2
- package/dist/errors.d.ts +516 -0
- package/dist/errors.js +218 -0
- package/dist/events.d.ts +585 -140
- package/dist/events.js +57 -42
- package/dist/fields.d.ts +1478 -66
- package/dist/fields.js +33 -47
- package/dist/files.d.ts +766 -62
- package/dist/files.js +34 -22
- package/dist/index.d.ts +25707 -902
- package/dist/index.js +22 -20
- package/dist/leads.d.ts +1108 -22
- package/dist/leads.js +39 -20
- package/dist/notifications.d.ts +691 -94
- package/dist/notifications.js +45 -91
- package/dist/organizations.d.ts +263 -5
- package/dist/organizations.js +21 -2
- package/dist/payments.d.ts +1794 -120
- package/dist/payments.js +58 -60
- package/dist/platform.d.ts +12 -20
- package/dist/platform.js +8 -21
- package/dist/plugins.d.ts +808 -71
- package/dist/plugins.js +66 -35
- package/dist/products.d.ts +1411 -53
- package/dist/products.js +40 -23
- package/dist/roles.d.ts +560 -8
- package/dist/roles.js +25 -11
- package/dist/routes.d.ts +8 -0
- package/dist/routes.js +13 -0
- package/dist/saas.d.ts +164 -8
- package/dist/saas.js +14 -29
- package/dist/tags.d.ts +344 -8
- package/dist/tags.js +16 -8
- package/dist/transfer.d.ts +1361 -36
- package/dist/transfer.js +47 -49
- package/dist/trash.d.ts +299 -23
- package/dist/trash.js +27 -20
- package/dist/users.d.ts +1233 -59
- package/dist/users.js +48 -39
- package/dist/values.d.ts +150 -0
- package/dist/values.js +139 -0
- package/dist/views.d.ts +404 -13
- package/dist/views.js +18 -28
- package/dist/webhooks.d.ts +791 -29
- package/dist/webhooks.js +36 -21
- package/package.json +9 -2
- package/dist/db/src/schema/jobs.js +0 -44
package/dist/auth.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { LANGUAGES } from "./db/src/enums.js";
|
|
2
|
+
import { COMMON_ERRORS, ERRORS } from "./errors.js";
|
|
3
|
+
import { isoDate } from "./common.js";
|
|
4
|
+
import { NewPassword } from "./values.js";
|
|
1
5
|
import { Organization, OrganizationRegion } from "./organizations.js";
|
|
2
6
|
import { User } from "./users.js";
|
|
3
7
|
import { oc } from "@orpc/contract";
|
|
@@ -9,15 +13,41 @@ const Session = z.object({
|
|
|
9
13
|
/** What the member may do (actions); owners have every one. */
|
|
10
14
|
permissions: z.array(z.string())
|
|
11
15
|
});
|
|
12
|
-
|
|
13
|
-
|
|
16
|
+
const { ALREADY_ENABLED, BEYOND_OWN_PERMISSIONS, BUILTIN_ROLE, CHALLENGE_EXPIRED, CROSS_SITE, FIXED_ROLE, INVALID_CREDENTIALS, INVALID_LINK, LIMIT_EXCEEDED, NOT_ENABLED, NOT_INVITED, NOT_SET_UP, ORGANIZATION_REQUIRED, OWNER_ONLY_PERMISSION, ROLE_IN_USE, ROLE_NOT_FOUND, SAME_PASSWORD, SETUP_DISABLED, SETUP_DONE, TOO_MANY_ATTEMPTS, UNKNOWN_PERMISSION, WRONG_CODE, WRONG_PASSWORD } = ERRORS;
|
|
17
|
+
/** What these procedures answer with besides the common errors. */
|
|
18
|
+
const base = oc.errors({
|
|
19
|
+
...COMMON_ERRORS,
|
|
20
|
+
ALREADY_ENABLED,
|
|
21
|
+
BEYOND_OWN_PERMISSIONS,
|
|
22
|
+
BUILTIN_ROLE,
|
|
23
|
+
CHALLENGE_EXPIRED,
|
|
24
|
+
CROSS_SITE,
|
|
25
|
+
FIXED_ROLE,
|
|
26
|
+
INVALID_CREDENTIALS,
|
|
27
|
+
INVALID_LINK,
|
|
28
|
+
LIMIT_EXCEEDED,
|
|
29
|
+
NOT_ENABLED,
|
|
30
|
+
NOT_INVITED,
|
|
31
|
+
NOT_SET_UP,
|
|
32
|
+
ORGANIZATION_REQUIRED,
|
|
33
|
+
OWNER_ONLY_PERMISSION,
|
|
34
|
+
ROLE_IN_USE,
|
|
35
|
+
ROLE_NOT_FOUND,
|
|
36
|
+
SAME_PASSWORD,
|
|
37
|
+
SETUP_DISABLED,
|
|
38
|
+
SETUP_DONE,
|
|
39
|
+
TOO_MANY_ATTEMPTS,
|
|
40
|
+
UNKNOWN_PERMISSION,
|
|
41
|
+
WRONG_CODE,
|
|
42
|
+
WRONG_PASSWORD
|
|
43
|
+
});
|
|
14
44
|
const authContract = {
|
|
15
|
-
setupStatus:
|
|
45
|
+
setupStatus: base.route({
|
|
16
46
|
method: "GET",
|
|
17
47
|
path: "/setup",
|
|
18
48
|
summary: "Whether this installation still needs its first organisation and owner"
|
|
19
49
|
}).output(z.object({ required: z.boolean() })),
|
|
20
|
-
setup:
|
|
50
|
+
setup: base.route({
|
|
21
51
|
method: "POST",
|
|
22
52
|
path: "/setup",
|
|
23
53
|
successStatus: 201,
|
|
@@ -31,7 +61,7 @@ const authContract = {
|
|
|
31
61
|
email: z.string().trim().check(z.email()).max(254),
|
|
32
62
|
password: NewPassword
|
|
33
63
|
})).output(Session),
|
|
34
|
-
signIn:
|
|
64
|
+
signIn: base.route({
|
|
35
65
|
method: "POST",
|
|
36
66
|
path: "/auth/sign-in",
|
|
37
67
|
summary: "Sign in with email and password; sets the session cookie"
|
|
@@ -44,7 +74,7 @@ const authContract = {
|
|
|
44
74
|
twoFactorRequired: z.literal(true),
|
|
45
75
|
challenge: z.string()
|
|
46
76
|
})])),
|
|
47
|
-
requestPasswordReset:
|
|
77
|
+
requestPasswordReset: base.route({
|
|
48
78
|
method: "POST",
|
|
49
79
|
path: "/auth/password-reset",
|
|
50
80
|
summary: "Email a password reset link. Always answers ok: it never tells whether an email has an account"
|
|
@@ -52,7 +82,7 @@ const authContract = {
|
|
|
52
82
|
email: z.string().trim().check(z.email()).max(254),
|
|
53
83
|
subdomain: z.string().trim().max(63).optional()
|
|
54
84
|
})).output(z.object({ ok: z.literal(true) })),
|
|
55
|
-
resetPassword:
|
|
85
|
+
resetPassword: base.route({
|
|
56
86
|
method: "POST",
|
|
57
87
|
path: "/auth/password-reset/confirm",
|
|
58
88
|
summary: "Set a new password with the emailed link's token; signs in"
|
|
@@ -60,7 +90,7 @@ const authContract = {
|
|
|
60
90
|
token: z.string().min(10).max(300),
|
|
61
91
|
password: NewPassword
|
|
62
92
|
})).output(Session),
|
|
63
|
-
invitation:
|
|
93
|
+
invitation: base.route({
|
|
64
94
|
method: "GET",
|
|
65
95
|
path: "/auth/invitation",
|
|
66
96
|
summary: "What an invitation link is for (organisation, email), to show before accepting"
|
|
@@ -69,7 +99,7 @@ const authContract = {
|
|
|
69
99
|
email: z.string(),
|
|
70
100
|
inviter: z.string().nullable()
|
|
71
101
|
})),
|
|
72
|
-
acceptInvitation:
|
|
102
|
+
acceptInvitation: base.route({
|
|
73
103
|
method: "POST",
|
|
74
104
|
path: "/auth/invitation/accept",
|
|
75
105
|
summary: "Accept an invitation: choose a password; signs in"
|
|
@@ -79,7 +109,7 @@ const authContract = {
|
|
|
79
109
|
firstName: z.string().trim().max(100).optional(),
|
|
80
110
|
lastName: z.string().trim().max(100).optional()
|
|
81
111
|
})).output(Session),
|
|
82
|
-
signInTwoFactor:
|
|
112
|
+
signInTwoFactor: base.route({
|
|
83
113
|
method: "POST",
|
|
84
114
|
path: "/auth/sign-in/2fa",
|
|
85
115
|
summary: "The sign-in's second step: an authenticator code, or a recovery code"
|
|
@@ -88,7 +118,7 @@ const authContract = {
|
|
|
88
118
|
code: z.string().trim().regex(/^\d{6}$/).optional(),
|
|
89
119
|
recoveryCode: z.string().trim().min(8).max(40).optional()
|
|
90
120
|
}).refine((value) => Boolean(value.code || value.recoveryCode), "a code or a recovery code")).output(Session),
|
|
91
|
-
twoFactorSetup:
|
|
121
|
+
twoFactorSetup: base.route({
|
|
92
122
|
method: "POST",
|
|
93
123
|
path: "/auth/2fa/setup",
|
|
94
124
|
summary: "Start turning on two-factor sign-in: a new secret for an authenticator app"
|
|
@@ -96,37 +126,37 @@ const authContract = {
|
|
|
96
126
|
secret: z.string(),
|
|
97
127
|
uri: z.string()
|
|
98
128
|
})),
|
|
99
|
-
twoFactorEnable:
|
|
129
|
+
twoFactorEnable: base.route({
|
|
100
130
|
method: "POST",
|
|
101
131
|
path: "/auth/2fa/enable",
|
|
102
132
|
summary: "Confirm with a code from the app; returns recovery codes (shown once)"
|
|
103
133
|
}).input(z.object({ code: z.string().trim().regex(/^\d{6}$/) })).output(z.object({ recoveryCodes: z.array(z.string()) })),
|
|
104
|
-
twoFactorDisable:
|
|
134
|
+
twoFactorDisable: base.route({
|
|
105
135
|
method: "POST",
|
|
106
136
|
path: "/auth/2fa/disable",
|
|
107
137
|
summary: "Turn two-factor sign-in off (needs the password)"
|
|
108
138
|
}).input(z.object({ password: z.string().min(1).max(200) })).output(z.object({ ok: z.literal(true) })),
|
|
109
|
-
twoFactorRecoveryCodes:
|
|
139
|
+
twoFactorRecoveryCodes: base.route({
|
|
110
140
|
method: "POST",
|
|
111
141
|
path: "/auth/2fa/recovery-codes",
|
|
112
142
|
summary: "New recovery codes (the old ones stop working; needs the password)"
|
|
113
143
|
}).input(z.object({ password: z.string().min(1).max(200) })).output(z.object({ recoveryCodes: z.array(z.string()) })),
|
|
114
|
-
signOutEverywhere:
|
|
144
|
+
signOutEverywhere: base.route({
|
|
115
145
|
method: "POST",
|
|
116
146
|
path: "/auth/sign-out-everywhere",
|
|
117
147
|
summary: "End every session of the signed-in member, on every device"
|
|
118
148
|
}).output(z.object({ ok: z.literal(true) })),
|
|
119
|
-
signOut:
|
|
149
|
+
signOut: base.route({
|
|
120
150
|
method: "POST",
|
|
121
151
|
path: "/auth/sign-out",
|
|
122
152
|
summary: "Sign out; clears the session cookie"
|
|
123
153
|
}).output(z.object({ ok: z.literal(true) })),
|
|
124
|
-
me:
|
|
154
|
+
me: base.route({
|
|
125
155
|
method: "GET",
|
|
126
156
|
path: "/auth/me",
|
|
127
157
|
summary: "The signed-in team member and their organisation"
|
|
128
158
|
}).output(Session),
|
|
129
|
-
onboarded:
|
|
159
|
+
onboarded: base.route({
|
|
130
160
|
method: "POST",
|
|
131
161
|
path: "/auth/onboarded",
|
|
132
162
|
summary: "The signed-in member finished the welcome steps (on every browser)"
|
|
@@ -134,9 +164,9 @@ const authContract = {
|
|
|
134
164
|
/** Fill a fresh organisation with example contacts, notes and an automation (owners; once, while it has no contacts). */
|
|
135
165
|
exampleData: z.boolean().optional(),
|
|
136
166
|
/** The language of the example data: the member's UI language. */
|
|
137
|
-
language: z.enum(
|
|
167
|
+
language: z.enum(LANGUAGES).optional()
|
|
138
168
|
}).optional()).output(Session),
|
|
139
|
-
changePassword:
|
|
169
|
+
changePassword: base.route({
|
|
140
170
|
method: "POST",
|
|
141
171
|
path: "/auth/password",
|
|
142
172
|
summary: "Change my own password. 400 WRONG_PASSWORD when the current one is wrong; SAME_PASSWORD when unchanged"
|
|
@@ -144,16 +174,16 @@ const authContract = {
|
|
|
144
174
|
currentPassword: z.string().min(1).max(200),
|
|
145
175
|
newPassword: NewPassword
|
|
146
176
|
})).output(z.object({ ok: z.literal(true) })),
|
|
147
|
-
signIns:
|
|
177
|
+
signIns: base.route({
|
|
148
178
|
method: "GET",
|
|
149
179
|
path: "/auth/sign-ins",
|
|
150
|
-
summary: "My recent sign-ins and failed attempts, newest first"
|
|
180
|
+
summary: "My 15 most recent sign-ins and failed attempts, newest first"
|
|
151
181
|
}).output(z.object({ data: z.array(z.object({
|
|
152
182
|
id: z.string(),
|
|
153
183
|
success: z.boolean(),
|
|
154
184
|
ip: z.string().nullable(),
|
|
155
185
|
userAgent: z.string().nullable(),
|
|
156
|
-
createdAt:
|
|
157
|
-
})) }))
|
|
186
|
+
createdAt: isoDate()
|
|
187
|
+
})).max(15) }))
|
|
158
188
|
};
|
|
159
|
-
export {
|
|
189
|
+
export { Session, authContract };
|
package/dist/automationRuns.d.ts
CHANGED
|
@@ -82,6 +82,11 @@ export declare const AutomationRun: z.ZodObject<{
|
|
|
82
82
|
version: z.ZodInt;
|
|
83
83
|
eventId: z.ZodString;
|
|
84
84
|
eventType: z.ZodString;
|
|
85
|
+
subjectType: z.ZodNullable<z.ZodEnum<{
|
|
86
|
+
company: "company";
|
|
87
|
+
customer: "customer";
|
|
88
|
+
}>>;
|
|
89
|
+
subjectId: z.ZodNullable<z.ZodString>;
|
|
85
90
|
status: z.ZodEnum<{
|
|
86
91
|
cancelled: "cancelled";
|
|
87
92
|
failed: "failed";
|
|
@@ -90,17 +95,11 @@ export declare const AutomationRun: z.ZodObject<{
|
|
|
90
95
|
waiting: "waiting";
|
|
91
96
|
}>;
|
|
92
97
|
error: z.ZodNullable<z.ZodString>;
|
|
93
|
-
waitingUntil: z.ZodNullable<z.ZodISODateTime
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
company: "company";
|
|
99
|
-
customer: "customer";
|
|
100
|
-
}>;
|
|
101
|
-
id: z.ZodString;
|
|
102
|
-
}, z.core.$strip>>;
|
|
103
|
-
goalReached: z.ZodBoolean;
|
|
98
|
+
waitingUntil: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
|
|
99
|
+
goalReachedAt: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
|
|
100
|
+
startedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
|
|
101
|
+
finishedAt: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
|
|
102
|
+
subjectName: z.ZodNullable<z.ZodString>;
|
|
104
103
|
}, {
|
|
105
104
|
out: {};
|
|
106
105
|
in: {};
|
|
@@ -119,8 +118,8 @@ export declare const RunStep: z.ZodObject<{
|
|
|
119
118
|
output: z.ZodNullable<z.ZodUnknown>;
|
|
120
119
|
error: z.ZodNullable<z.ZodString>;
|
|
121
120
|
attempt: z.ZodInt;
|
|
122
|
-
startedAt: z.ZodISODateTime
|
|
123
|
-
finishedAt: z.ZodISODateTime
|
|
121
|
+
startedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
|
|
122
|
+
finishedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
|
|
124
123
|
}, {
|
|
125
124
|
out: {};
|
|
126
125
|
in: {};
|
package/dist/automationRuns.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ACTION_FIELD_TYPES, AUTOMATION_SUBJECTS, RUN_STATUSES } from "./db/src/enums.js";
|
|
2
|
+
import { automationRunSteps, automationRuns } from "./db/src/schema/automations.js";
|
|
2
3
|
import "./db/src/schema/index.js";
|
|
3
4
|
import { Id, isoDate } from "./common.js";
|
|
4
|
-
import { createSelectSchema } from "drizzle-zod";
|
|
5
5
|
import { z } from "zod";
|
|
6
|
+
import { createSelectSchema } from "drizzle-zod";
|
|
6
7
|
// src/automationRuns.ts
|
|
7
8
|
/**
|
|
8
9
|
* One input of an action. Besides plain values: `custom_field` (one of the
|
|
@@ -12,20 +13,7 @@ import { z } from "zod";
|
|
|
12
13
|
const ActionField = z.object({
|
|
13
14
|
key: z.string(),
|
|
14
15
|
label: z.string(),
|
|
15
|
-
type: z.enum(
|
|
16
|
-
"text",
|
|
17
|
-
"longtext",
|
|
18
|
-
"number",
|
|
19
|
-
"boolean",
|
|
20
|
-
"date",
|
|
21
|
-
"select",
|
|
22
|
-
"members",
|
|
23
|
-
"tags",
|
|
24
|
-
"json",
|
|
25
|
-
"custom_field",
|
|
26
|
-
"lead_stage",
|
|
27
|
-
"recipients"
|
|
28
|
-
]),
|
|
16
|
+
type: z.enum(ACTION_FIELD_TYPES),
|
|
29
17
|
required: z.boolean().default(false),
|
|
30
18
|
options: z.array(z.object({
|
|
31
19
|
value: z.string(),
|
|
@@ -42,11 +30,7 @@ const ActionInfo = z.object({
|
|
|
42
30
|
description: z.string().nullable(),
|
|
43
31
|
source: z.string(),
|
|
44
32
|
/** Needs a customer or company as the run's subject. */
|
|
45
|
-
subject: z.enum(
|
|
46
|
-
"customer",
|
|
47
|
-
"company",
|
|
48
|
-
"any"
|
|
49
|
-
]).nullable(),
|
|
33
|
+
subject: z.enum(AUTOMATION_SUBJECTS).nullable(),
|
|
50
34
|
fields: z.array(ActionField)
|
|
51
35
|
});
|
|
52
36
|
const RunStatus = z.enum(RUN_STATUSES);
|
|
@@ -57,26 +41,27 @@ const AutomationRun = createSelectSchema(automationRuns, {
|
|
|
57
41
|
version: int,
|
|
58
42
|
waitingUntil: isoDate,
|
|
59
43
|
startedAt: isoDate,
|
|
60
|
-
finishedAt: isoDate
|
|
44
|
+
finishedAt: isoDate,
|
|
45
|
+
goalReachedAt: isoDate
|
|
61
46
|
}).pick({
|
|
62
47
|
id: true,
|
|
63
48
|
automationId: true,
|
|
64
49
|
version: true,
|
|
65
50
|
eventId: true,
|
|
66
51
|
eventType: true,
|
|
52
|
+
/** The customer or company the run is about. */
|
|
53
|
+
subjectType: true,
|
|
54
|
+
subjectId: true,
|
|
67
55
|
status: true,
|
|
68
56
|
error: true,
|
|
69
57
|
waitingUntil: true,
|
|
70
58
|
startedAt: true,
|
|
71
|
-
finishedAt: true
|
|
72
|
-
}).extend({
|
|
73
|
-
subject: z.object({
|
|
74
|
-
type: z.enum(["customer", "company"]),
|
|
75
|
-
id: Id
|
|
76
|
-
}).nullable(),
|
|
59
|
+
finishedAt: true,
|
|
77
60
|
/** Left early because the automation's goal was met. */
|
|
78
|
-
|
|
79
|
-
})
|
|
61
|
+
goalReachedAt: true
|
|
62
|
+
}).extend({
|
|
63
|
+
/** The customer's or company's name now; null once it is deleted. */
|
|
64
|
+
subjectName: z.string().nullable() });
|
|
80
65
|
const RunStep = createSelectSchema(automationRunSteps, {
|
|
81
66
|
id: Id,
|
|
82
67
|
input: () => z.unknown(),
|