@erxes/core-contract 0.1.0-v2.0 → 0.1.0-v2.1
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 +21 -14
- package/dist/activities.js +6 -10
- package/dist/audit.d.ts +13 -17
- package/dist/audit.js +9 -9
- package/dist/auth.d.ts +33 -35
- package/dist/auth.js +8 -7
- package/dist/automationDefinition.d.ts +4 -3
- package/dist/automationDefinition.js +9 -31
- package/dist/automationRuns.d.ts +6 -5
- package/dist/automationRuns.js +8 -22
- package/dist/automations.d.ts +35 -36
- package/dist/automations.js +15 -23
- package/dist/common.d.ts +29 -4
- package/dist/common.js +30 -10
- package/dist/companies.d.ts +34 -34
- package/dist/companies.js +6 -5
- package/dist/contract/routes.json.js +1794 -0
- package/dist/customerAuth.d.ts +222 -0
- package/dist/customerAuth.js +180 -0
- package/dist/customers.d.ts +51 -54
- package/dist/customers.js +7 -12
- package/dist/db/src/enums.d.ts +8 -0
- package/dist/db/src/enums.js +336 -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.js +12 -28
- 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.js +21 -20
- package/dist/db/src/schema/leadStages.js +5 -10
- package/dist/db/src/schema/leads.js +5 -10
- package/dist/db/src/schema/oauth.js +3 -3
- package/dist/db/src/schema/payments.js +12 -22
- package/dist/db/src/schema/platform.js +11 -26
- package/dist/db/src/schema/plugins.js +4 -4
- 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 +12 -32
- 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/events.d.ts +19 -23
- package/dist/events.js +16 -18
- package/dist/fields.d.ts +22 -50
- package/dist/fields.js +6 -28
- package/dist/files.d.ts +10 -5
- package/dist/files.js +4 -3
- package/dist/index.d.ts +557 -321
- package/dist/index.js +17 -16
- package/dist/leads.d.ts +5 -3
- package/dist/leads.js +8 -7
- package/dist/notifications.d.ts +4 -48
- package/dist/notifications.js +7 -73
- package/dist/organizations.d.ts +3 -3
- package/dist/payments.d.ts +28 -58
- package/dist/payments.js +10 -34
- package/dist/platform.d.ts +1 -0
- package/dist/platform.js +2 -5
- package/dist/plugins.d.ts +10 -4
- package/dist/plugins.js +19 -9
- package/dist/products.d.ts +31 -36
- package/dist/products.js +8 -7
- package/dist/roles.d.ts +0 -3
- package/dist/roles.js +5 -5
- package/dist/routes.d.ts +8 -0
- package/dist/routes.js +13 -0
- package/dist/saas.d.ts +0 -6
- package/dist/saas.js +5 -27
- package/dist/tags.d.ts +4 -4
- package/dist/tags.js +3 -3
- package/dist/transfer.d.ts +62 -24
- package/dist/transfer.js +15 -36
- package/dist/trash.d.ts +23 -4
- package/dist/trash.js +5 -5
- package/dist/users.d.ts +27 -41
- package/dist/users.js +13 -26
- package/dist/values.d.ts +159 -0
- package/dist/values.js +144 -0
- package/dist/views.d.ts +8 -8
- package/dist/views.js +8 -21
- package/dist/webhooks.d.ts +26 -20
- package/dist/webhooks.js +18 -11
- package/package.json +4 -1
- package/dist/db/src/schema/jobs.js +0 -44
package/dist/values.d.ts
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const CORE_API_VERSION = "v1";
|
|
3
|
+
/** Every path in the contract is under this prefix (`/core/v1/customers`, …). */
|
|
4
|
+
export declare const CORE_API_PREFIX = "/core/v1";
|
|
5
|
+
/** `owner`, `admin`, `member`, or a custom role's `r_<id>`. */
|
|
6
|
+
export declare const RoleKey: z.ZodString;
|
|
7
|
+
export type RoleKey = z.infer<typeof RoleKey>;
|
|
8
|
+
/** A role an invitation can give: any but owner, which goes to a member who has joined. */
|
|
9
|
+
export declare const InviteRole: z.ZodString;
|
|
10
|
+
/** At least 8 characters with a lower-case letter, an upper-case letter and a digit (as old erxes). */
|
|
11
|
+
export declare const NewPassword: z.ZodString;
|
|
12
|
+
/** Social links a member can show (old erxes `users.links`). */
|
|
13
|
+
export declare const USER_LINK_NAMES: readonly ['facebook', 'twitter', 'website', 'discord', 'github', 'instagram'];
|
|
14
|
+
export declare const UserLinkName: z.ZodEnum<{
|
|
15
|
+
discord: "discord";
|
|
16
|
+
facebook: "facebook";
|
|
17
|
+
github: "github";
|
|
18
|
+
instagram: "instagram";
|
|
19
|
+
twitter: "twitter";
|
|
20
|
+
website: "website";
|
|
21
|
+
}>;
|
|
22
|
+
export type UserLinkName = z.infer<typeof UserLinkName>;
|
|
23
|
+
/** ISO/IEC 5218, as in erxes until now: 0 not known, 1 male, 2 female, 9 not applicable. */
|
|
24
|
+
export declare const CustomerSex: z.ZodUnion<z.ZodLiteral<0 | 1 | 2 | 9>[]>;
|
|
25
|
+
export type CustomerSex = z.infer<typeof CustomerSex>;
|
|
26
|
+
export declare const ProductKind: z.ZodEnum<{
|
|
27
|
+
goods: "goods";
|
|
28
|
+
service: "service";
|
|
29
|
+
}>;
|
|
30
|
+
export type ProductKind = z.infer<typeof ProductKind>;
|
|
31
|
+
export declare const FieldType: z.ZodEnum<{
|
|
32
|
+
boolean: "boolean";
|
|
33
|
+
check: "check";
|
|
34
|
+
date: "date";
|
|
35
|
+
list: "list";
|
|
36
|
+
multiselect: "multiselect";
|
|
37
|
+
number: "number";
|
|
38
|
+
phone: "phone";
|
|
39
|
+
radio: "radio";
|
|
40
|
+
select: "select";
|
|
41
|
+
text: "text";
|
|
42
|
+
textarea: "textarea";
|
|
43
|
+
}>;
|
|
44
|
+
export type FieldType = z.infer<typeof FieldType>;
|
|
45
|
+
/** Field types whose values are chosen from `options`. */
|
|
46
|
+
export declare const OPTION_FIELD_TYPES: readonly FieldType[];
|
|
47
|
+
/**
|
|
48
|
+
* Types sharing a stored value: a field holding values may only change within
|
|
49
|
+
* its family; an unused field may become any type.
|
|
50
|
+
*/
|
|
51
|
+
export declare const FIELD_TYPE_FAMILIES: readonly (readonly FieldType[])[];
|
|
52
|
+
/** Format a text field's values must have. */
|
|
53
|
+
export declare const FieldValidation: z.ZodEnum<{
|
|
54
|
+
date: "date";
|
|
55
|
+
email: "email";
|
|
56
|
+
number: "number";
|
|
57
|
+
}>;
|
|
58
|
+
export type FieldValidation = z.infer<typeof FieldValidation>;
|
|
59
|
+
export declare const AutomationStatus: z.ZodEnum<{
|
|
60
|
+
active: "active";
|
|
61
|
+
draft: "draft";
|
|
62
|
+
paused: "paused";
|
|
63
|
+
}>;
|
|
64
|
+
/** Who changed what in core (owners and admins). */
|
|
65
|
+
export declare const AuditStreamFormat: z.ZodEnum<{
|
|
66
|
+
datadog: "datadog";
|
|
67
|
+
erxes: "erxes";
|
|
68
|
+
splunk: "splunk";
|
|
69
|
+
}>;
|
|
70
|
+
/**
|
|
71
|
+
* The gateways core can connect, and where each works: the currencies it
|
|
72
|
+
* takes and the countries it serves (empty: any). QPay is Mongolian; global
|
|
73
|
+
* ones (Stripe …) join here as drivers in `@erxes/payment-gateways`.
|
|
74
|
+
*/
|
|
75
|
+
export declare const PAYMENT_GATEWAYS: {
|
|
76
|
+
readonly qpay: {
|
|
77
|
+
readonly currencies: ["MNT"];
|
|
78
|
+
readonly countries: ["MN"];
|
|
79
|
+
};
|
|
80
|
+
readonly test: {
|
|
81
|
+
readonly currencies: [];
|
|
82
|
+
readonly countries: [];
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
export declare const PaymentGatewayKind: z.ZodEnum<{
|
|
86
|
+
qpay: "qpay";
|
|
87
|
+
test: "test";
|
|
88
|
+
}>;
|
|
89
|
+
export type PaymentGatewayKind = z.infer<typeof PaymentGatewayKind>;
|
|
90
|
+
/** Does this kind of gateway take this currency? */
|
|
91
|
+
export declare const gatewayTakes: (kind: PaymentGatewayKind, currency: string) => boolean;
|
|
92
|
+
export declare const InvoiceStatus: z.ZodEnum<{
|
|
93
|
+
cancelled: "cancelled";
|
|
94
|
+
expired: "expired";
|
|
95
|
+
failed: "failed";
|
|
96
|
+
paid: "paid";
|
|
97
|
+
pending: "pending";
|
|
98
|
+
refunded: "refunded";
|
|
99
|
+
}>;
|
|
100
|
+
/** Security notices a member can't mute. */
|
|
101
|
+
export declare const UNMUTABLE_NOTIFICATION_KINDS: readonly string[];
|
|
102
|
+
/** Where a group of notifications goes: the inbox and email, the inbox only, or nowhere. */
|
|
103
|
+
export declare const NotificationDelivery: z.ZodEnum<{
|
|
104
|
+
email: "email";
|
|
105
|
+
inbox: "inbox";
|
|
106
|
+
off: "off";
|
|
107
|
+
}>;
|
|
108
|
+
export type NotificationDelivery = z.infer<typeof NotificationDelivery>;
|
|
109
|
+
/** How the live stream reaches this browser, in its `hello` event: pushing, or polling while it can't listen. */
|
|
110
|
+
export declare const LiveMode: z.ZodEnum<{
|
|
111
|
+
live: "live";
|
|
112
|
+
polling: "polling";
|
|
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
|
+
/**
|
|
124
|
+
* Core's notifications in groups a member chooses for at once (each plugin
|
|
125
|
+
* is a group of its own). `security` is always on.
|
|
126
|
+
*/
|
|
127
|
+
export declare const CORE_NOTIFICATION_GROUPS: readonly [{
|
|
128
|
+
readonly key: 'assigned';
|
|
129
|
+
readonly label: 'Assigned to me';
|
|
130
|
+
readonly kinds: readonly ["core.customer.assigned", "core.company.assigned"];
|
|
131
|
+
readonly default: 'email';
|
|
132
|
+
}, {
|
|
133
|
+
readonly key: 'records';
|
|
134
|
+
readonly label: 'Changes to records I own';
|
|
135
|
+
readonly kinds: readonly ["core.customer.updated", "core.customer.merged", "core.customer.deleted", "core.company.updated", "core.company.merged", "core.company.deleted", "core.customer.activity", "core.company.activity"];
|
|
136
|
+
readonly default: 'inbox';
|
|
137
|
+
}, {
|
|
138
|
+
readonly key: 'mentions';
|
|
139
|
+
readonly label: 'Mentions';
|
|
140
|
+
readonly kinds: readonly ["core.note.mentioned"];
|
|
141
|
+
readonly default: 'email';
|
|
142
|
+
}, {
|
|
143
|
+
readonly key: 'automations';
|
|
144
|
+
readonly label: 'Automations';
|
|
145
|
+
readonly kinds: readonly ["core.automation.message", "core.automation.failed"];
|
|
146
|
+
readonly default: 'inbox';
|
|
147
|
+
}, {
|
|
148
|
+
readonly key: 'transfer';
|
|
149
|
+
readonly label: 'Imports and exports';
|
|
150
|
+
readonly kinds: readonly ["core.import.done", "core.export.ready"];
|
|
151
|
+
readonly default: 'inbox';
|
|
152
|
+
}, {
|
|
153
|
+
readonly key: 'security';
|
|
154
|
+
readonly label: 'Security';
|
|
155
|
+
readonly kinds: readonly string[];
|
|
156
|
+
readonly default: 'inbox';
|
|
157
|
+
}];
|
|
158
|
+
/** The group a notification belongs to: a core group, or the plugin that sent it. */
|
|
159
|
+
export declare const notificationGroupOf: (source: string, kind: string) => string;
|
package/dist/values.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { AUDIT_STREAM_FORMATS, AUTOMATION_STATUSES, CUSTOMER_SEXES, CUSTOMER_UNIQUE_FIELDS, FIELD_TYPES, FIELD_VALIDATIONS, INVOICE_STATUSES, LIVE_MODES, NOTIFICATION_DELIVERIES, PAYMENT_GATEWAY_KINDS, PRODUCT_KINDS } from "./db/src/enums.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
// src/values.ts
|
|
4
|
+
const CORE_API_VERSION = "v1";
|
|
5
|
+
/** Every path in the contract is under this prefix (`/core/v1/customers`, …). */
|
|
6
|
+
const CORE_API_PREFIX = "/core/v1";
|
|
7
|
+
/** `owner`, `admin`, `member`, or a custom role's `r_<id>`. */
|
|
8
|
+
const RoleKey = z.string().trim().regex(/^(owner|admin|member|r_[A-Za-z0-9]{6,40})$/, "a role");
|
|
9
|
+
/** A role an invitation can give: any but owner, which goes to a member who has joined. */
|
|
10
|
+
const InviteRole = RoleKey.refine((role) => role !== "owner", "invite as admin or member, then make them owner");
|
|
11
|
+
/** At least 8 characters with a lower-case letter, an upper-case letter and a digit (as old erxes). */
|
|
12
|
+
const NewPassword = z.string().min(8, "At least 8 characters").max(200).regex(/[a-z]/, "Add a lower-case letter").regex(/[A-Z]/, "Add an upper-case letter").regex(/\d/, "Add a digit");
|
|
13
|
+
/** Social links a member can show (old erxes `users.links`). */
|
|
14
|
+
const USER_LINK_NAMES = [
|
|
15
|
+
"facebook",
|
|
16
|
+
"twitter",
|
|
17
|
+
"website",
|
|
18
|
+
"discord",
|
|
19
|
+
"github",
|
|
20
|
+
"instagram"
|
|
21
|
+
];
|
|
22
|
+
const UserLinkName = z.enum(USER_LINK_NAMES);
|
|
23
|
+
/** ISO/IEC 5218, as in erxes until now: 0 not known, 1 male, 2 female, 9 not applicable. */
|
|
24
|
+
const CustomerSex = z.union(CUSTOMER_SEXES.map((code) => z.literal(code)));
|
|
25
|
+
const ProductKind = z.enum(PRODUCT_KINDS);
|
|
26
|
+
const FieldType = z.enum(FIELD_TYPES);
|
|
27
|
+
/** Field types whose values are chosen from `options`. */
|
|
28
|
+
const OPTION_FIELD_TYPES = [
|
|
29
|
+
"select",
|
|
30
|
+
"multiselect",
|
|
31
|
+
"radio",
|
|
32
|
+
"check"
|
|
33
|
+
];
|
|
34
|
+
/**
|
|
35
|
+
* Types sharing a stored value: a field holding values may only change within
|
|
36
|
+
* its family; an unused field may become any type.
|
|
37
|
+
*/
|
|
38
|
+
const FIELD_TYPE_FAMILIES = [
|
|
39
|
+
["select", "radio"],
|
|
40
|
+
["multiselect", "check"],
|
|
41
|
+
[
|
|
42
|
+
"text",
|
|
43
|
+
"textarea",
|
|
44
|
+
"phone"
|
|
45
|
+
]
|
|
46
|
+
];
|
|
47
|
+
/** Format a text field's values must have. */
|
|
48
|
+
const FieldValidation = z.enum(FIELD_VALIDATIONS);
|
|
49
|
+
const AutomationStatus = z.enum(AUTOMATION_STATUSES);
|
|
50
|
+
/** Who changed what in core (owners and admins). */
|
|
51
|
+
const AuditStreamFormat = z.enum(AUDIT_STREAM_FORMATS);
|
|
52
|
+
/**
|
|
53
|
+
* The gateways core can connect, and where each works: the currencies it
|
|
54
|
+
* takes and the countries it serves (empty: any). QPay is Mongolian; global
|
|
55
|
+
* ones (Stripe …) join here as drivers in `@erxes/payment-gateways`.
|
|
56
|
+
*/
|
|
57
|
+
const PAYMENT_GATEWAYS = {
|
|
58
|
+
qpay: {
|
|
59
|
+
currencies: ["MNT"],
|
|
60
|
+
countries: ["MN"]
|
|
61
|
+
},
|
|
62
|
+
test: {
|
|
63
|
+
currencies: [],
|
|
64
|
+
countries: []
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const PaymentGatewayKind = z.enum(PAYMENT_GATEWAY_KINDS);
|
|
68
|
+
/** Does this kind of gateway take this currency? */
|
|
69
|
+
const gatewayTakes = (kind, currency) => {
|
|
70
|
+
const { currencies } = PAYMENT_GATEWAYS[kind];
|
|
71
|
+
return currencies.length === 0 || currencies.some((code) => code === currency);
|
|
72
|
+
};
|
|
73
|
+
const InvoiceStatus = z.enum(INVOICE_STATUSES);
|
|
74
|
+
/** Security notices a member can't mute. */
|
|
75
|
+
const UNMUTABLE_NOTIFICATION_KINDS = [
|
|
76
|
+
"core.user.role_changed",
|
|
77
|
+
"core.user.password_set",
|
|
78
|
+
"core.security.mass_deletion",
|
|
79
|
+
"core.security.alert",
|
|
80
|
+
"core.security.new_sign_in"
|
|
81
|
+
];
|
|
82
|
+
/** Where a group of notifications goes: the inbox and email, the inbox only, or nowhere. */
|
|
83
|
+
const NotificationDelivery = z.enum(NOTIFICATION_DELIVERIES);
|
|
84
|
+
/** How the live stream reaches this browser, in its `hello` event: pushing, or polling while it can't listen. */
|
|
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
|
+
/**
|
|
92
|
+
* Core's notifications in groups a member chooses for at once (each plugin
|
|
93
|
+
* is a group of its own). `security` is always on.
|
|
94
|
+
*/
|
|
95
|
+
const CORE_NOTIFICATION_GROUPS = [
|
|
96
|
+
{
|
|
97
|
+
key: "assigned",
|
|
98
|
+
label: "Assigned to me",
|
|
99
|
+
kinds: ["core.customer.assigned", "core.company.assigned"],
|
|
100
|
+
default: "email"
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
key: "records",
|
|
104
|
+
label: "Changes to records I own",
|
|
105
|
+
kinds: [
|
|
106
|
+
"core.customer.updated",
|
|
107
|
+
"core.customer.merged",
|
|
108
|
+
"core.customer.deleted",
|
|
109
|
+
"core.company.updated",
|
|
110
|
+
"core.company.merged",
|
|
111
|
+
"core.company.deleted",
|
|
112
|
+
"core.customer.activity",
|
|
113
|
+
"core.company.activity"
|
|
114
|
+
],
|
|
115
|
+
default: "inbox"
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
key: "mentions",
|
|
119
|
+
label: "Mentions",
|
|
120
|
+
kinds: ["core.note.mentioned"],
|
|
121
|
+
default: "email"
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
key: "automations",
|
|
125
|
+
label: "Automations",
|
|
126
|
+
kinds: ["core.automation.message", "core.automation.failed"],
|
|
127
|
+
default: "inbox"
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
key: "transfer",
|
|
131
|
+
label: "Imports and exports",
|
|
132
|
+
kinds: ["core.import.done", "core.export.ready"],
|
|
133
|
+
default: "inbox"
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
key: "security",
|
|
137
|
+
label: "Security",
|
|
138
|
+
kinds: UNMUTABLE_NOTIFICATION_KINDS,
|
|
139
|
+
default: "inbox"
|
|
140
|
+
}
|
|
141
|
+
];
|
|
142
|
+
/** The group a notification belongs to: a core group, or the plugin that sent it. */
|
|
143
|
+
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, CustomerExists, 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
|
@@ -68,8 +68,8 @@ export declare const View: z.ZodObject<{
|
|
|
68
68
|
}, z.core.$strip>>;
|
|
69
69
|
shared: z.ZodBoolean;
|
|
70
70
|
createdBy: z.ZodString;
|
|
71
|
-
createdAt: z.ZodISODateTime
|
|
72
|
-
updatedAt: z.ZodISODateTime
|
|
71
|
+
createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
|
|
72
|
+
updatedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
|
|
73
73
|
editable: z.ZodBoolean;
|
|
74
74
|
}, {
|
|
75
75
|
out: {};
|
|
@@ -109,8 +109,8 @@ export declare const viewsContract: {
|
|
|
109
109
|
}, z.core.$strip>>;
|
|
110
110
|
shared: z.ZodBoolean;
|
|
111
111
|
createdBy: z.ZodString;
|
|
112
|
-
createdAt: z.ZodISODateTime
|
|
113
|
-
updatedAt: z.ZodISODateTime
|
|
112
|
+
createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
|
|
113
|
+
updatedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
|
|
114
114
|
editable: z.ZodBoolean;
|
|
115
115
|
}, {
|
|
116
116
|
out: {};
|
|
@@ -162,8 +162,8 @@ export declare const viewsContract: {
|
|
|
162
162
|
}, z.core.$strip>>;
|
|
163
163
|
shared: z.ZodBoolean;
|
|
164
164
|
createdBy: z.ZodString;
|
|
165
|
-
createdAt: z.ZodISODateTime
|
|
166
|
-
updatedAt: z.ZodISODateTime
|
|
165
|
+
createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
|
|
166
|
+
updatedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
|
|
167
167
|
editable: z.ZodBoolean;
|
|
168
168
|
}, {
|
|
169
169
|
out: {};
|
|
@@ -208,8 +208,8 @@ export declare const viewsContract: {
|
|
|
208
208
|
}, z.core.$strip>>;
|
|
209
209
|
shared: z.ZodBoolean;
|
|
210
210
|
createdBy: z.ZodString;
|
|
211
|
-
createdAt: z.ZodISODateTime
|
|
212
|
-
updatedAt: z.ZodISODateTime
|
|
211
|
+
createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
|
|
212
|
+
updatedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
|
|
213
213
|
editable: z.ZodBoolean;
|
|
214
214
|
}, {
|
|
215
215
|
out: {};
|
package/dist/views.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FILTER_FIELD_GROUPS, FILTER_FIELD_TYPES, SORT_DIRECTIONS, VIEW_RECORD_TYPES } from "./db/src/enums.js";
|
|
2
|
+
import { views } from "./db/src/schema/views.js";
|
|
2
3
|
import "./db/src/schema/index.js";
|
|
3
4
|
import { ConditionGroup } from "./automationDefinition.js";
|
|
4
|
-
import { Id, isoDate } from "./common.js";
|
|
5
|
+
import { Id, isoDate, listOf } from "./common.js";
|
|
5
6
|
import { oc } from "@orpc/contract";
|
|
6
7
|
import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
|
|
7
8
|
import { z } from "zod";
|
|
@@ -19,28 +20,14 @@ const RecordFilter = ConditionGroup;
|
|
|
19
20
|
const FilterField = z.object({
|
|
20
21
|
path: z.string(),
|
|
21
22
|
label: z.string(),
|
|
22
|
-
type: z.enum(
|
|
23
|
-
"text",
|
|
24
|
-
"number",
|
|
25
|
-
"date",
|
|
26
|
-
"boolean",
|
|
27
|
-
"select",
|
|
28
|
-
"member",
|
|
29
|
-
"tags"
|
|
30
|
-
]),
|
|
23
|
+
type: z.enum(FILTER_FIELD_TYPES),
|
|
31
24
|
options: z.array(z.string()).optional(),
|
|
32
25
|
/** Where it comes from, for grouping in the picker. */
|
|
33
|
-
group: z.enum(
|
|
34
|
-
"fields",
|
|
35
|
-
"lead",
|
|
36
|
-
"custom",
|
|
37
|
-
"company",
|
|
38
|
-
"activity"
|
|
39
|
-
])
|
|
26
|
+
group: z.enum(FILTER_FIELD_GROUPS)
|
|
40
27
|
});
|
|
41
28
|
const ViewSort = z.object({
|
|
42
29
|
field: z.string().max(100),
|
|
43
|
-
direction: z.enum(
|
|
30
|
+
direction: z.enum(SORT_DIRECTIONS)
|
|
44
31
|
});
|
|
45
32
|
const View = createSelectSchema(views, {
|
|
46
33
|
id: Id,
|
|
@@ -86,7 +73,7 @@ const viewsContract = {
|
|
|
86
73
|
method: "GET",
|
|
87
74
|
path: "/views",
|
|
88
75
|
summary: "Views of a list: the member's own and the team's shared ones"
|
|
89
|
-
}).input(z.object({ recordType: ViewRecordType })).output(
|
|
76
|
+
}).input(z.object({ recordType: ViewRecordType })).output(listOf(View)),
|
|
90
77
|
create: oc.route({
|
|
91
78
|
method: "POST",
|
|
92
79
|
path: "/views",
|
|
@@ -106,6 +93,6 @@ const viewsContract = {
|
|
|
106
93
|
method: "GET",
|
|
107
94
|
path: "/views/fields",
|
|
108
95
|
summary: "What a list can be filtered by: fields, custom fields, the company, activity"
|
|
109
|
-
}).input(z.object({ recordType: ViewRecordType })).output(
|
|
96
|
+
}).input(z.object({ recordType: ViewRecordType })).output(listOf(FilterField))
|
|
110
97
|
};
|
|
111
98
|
export { FilterField, RecordFilter, View, ViewRecordType, ViewSort, viewsContract };
|
package/dist/webhooks.d.ts
CHANGED
|
@@ -38,6 +38,16 @@ export declare const CORE_EVENT_TYPES: readonly [{
|
|
|
38
38
|
readonly label: 'Customer unlinked from a company';
|
|
39
39
|
readonly subject: 'customer';
|
|
40
40
|
readonly description: 'A person is unlinked from a company';
|
|
41
|
+
}, {
|
|
42
|
+
readonly type: 'core.customer.signed_up';
|
|
43
|
+
readonly label: 'Customer signed up';
|
|
44
|
+
readonly subject: 'customer';
|
|
45
|
+
readonly description: 'A person proves their first email address or phone and can sign in to apps';
|
|
46
|
+
}, {
|
|
47
|
+
readonly type: 'core.customer.signed_in';
|
|
48
|
+
readonly label: 'Customer signed in';
|
|
49
|
+
readonly subject: 'customer';
|
|
50
|
+
readonly description: 'A person signs in with a code';
|
|
41
51
|
}, {
|
|
42
52
|
readonly type: 'core.lead.stage_changed';
|
|
43
53
|
readonly label: 'Lead moved to another stage';
|
|
@@ -148,8 +158,8 @@ export declare const Webhook: z.ZodObject<{
|
|
|
148
158
|
}>;
|
|
149
159
|
disabledReason: z.ZodNullable<z.ZodString>;
|
|
150
160
|
consecutiveFailures: z.ZodInt;
|
|
151
|
-
createdAt: z.ZodISODateTime
|
|
152
|
-
updatedAt: z.ZodISODateTime
|
|
161
|
+
createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
|
|
162
|
+
updatedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
|
|
153
163
|
}, {
|
|
154
164
|
out: {};
|
|
155
165
|
in: {};
|
|
@@ -170,9 +180,8 @@ export declare const WebhookDelivery: z.ZodObject<{
|
|
|
170
180
|
responseBody: z.ZodNullable<z.ZodString>;
|
|
171
181
|
error: z.ZodNullable<z.ZodString>;
|
|
172
182
|
durationMs: z.ZodNullable<z.ZodInt>;
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
createdAt: z.ZodISODateTime;
|
|
183
|
+
deliveredAt: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
|
|
184
|
+
createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
|
|
176
185
|
}, {
|
|
177
186
|
out: {};
|
|
178
187
|
in: {};
|
|
@@ -208,8 +217,8 @@ export declare const webhooksContract: {
|
|
|
208
217
|
}>;
|
|
209
218
|
disabledReason: z.ZodNullable<z.ZodString>;
|
|
210
219
|
consecutiveFailures: z.ZodInt;
|
|
211
|
-
createdAt: z.ZodISODateTime
|
|
212
|
-
updatedAt: z.ZodISODateTime
|
|
220
|
+
createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
|
|
221
|
+
updatedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
|
|
213
222
|
}, {
|
|
214
223
|
out: {};
|
|
215
224
|
in: {};
|
|
@@ -234,8 +243,8 @@ export declare const webhooksContract: {
|
|
|
234
243
|
}>;
|
|
235
244
|
disabledReason: z.ZodNullable<z.ZodString>;
|
|
236
245
|
consecutiveFailures: z.ZodInt;
|
|
237
|
-
createdAt: z.ZodISODateTime
|
|
238
|
-
updatedAt: z.ZodISODateTime
|
|
246
|
+
createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
|
|
247
|
+
updatedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
|
|
239
248
|
}, {
|
|
240
249
|
out: {};
|
|
241
250
|
in: {};
|
|
@@ -265,8 +274,8 @@ export declare const webhooksContract: {
|
|
|
265
274
|
}>;
|
|
266
275
|
disabledReason: z.ZodNullable<z.ZodString>;
|
|
267
276
|
consecutiveFailures: z.ZodInt;
|
|
268
|
-
createdAt: z.ZodISODateTime
|
|
269
|
-
updatedAt: z.ZodISODateTime
|
|
277
|
+
createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
|
|
278
|
+
updatedAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
|
|
270
279
|
}, {
|
|
271
280
|
out: {};
|
|
272
281
|
in: {};
|
|
@@ -298,9 +307,8 @@ export declare const webhooksContract: {
|
|
|
298
307
|
responseBody: z.ZodNullable<z.ZodString>;
|
|
299
308
|
error: z.ZodNullable<z.ZodString>;
|
|
300
309
|
durationMs: z.ZodNullable<z.ZodInt>;
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
createdAt: z.ZodISODateTime;
|
|
310
|
+
deliveredAt: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
|
|
311
|
+
createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
|
|
304
312
|
}, {
|
|
305
313
|
out: {};
|
|
306
314
|
in: {};
|
|
@@ -338,9 +346,8 @@ export declare const webhooksContract: {
|
|
|
338
346
|
responseBody: z.ZodNullable<z.ZodString>;
|
|
339
347
|
error: z.ZodNullable<z.ZodString>;
|
|
340
348
|
durationMs: z.ZodNullable<z.ZodInt>;
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
createdAt: z.ZodISODateTime;
|
|
349
|
+
deliveredAt: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
|
|
350
|
+
createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
|
|
344
351
|
}, {
|
|
345
352
|
out: {};
|
|
346
353
|
in: {};
|
|
@@ -371,9 +378,8 @@ export declare const webhooksContract: {
|
|
|
371
378
|
responseBody: z.ZodNullable<z.ZodString>;
|
|
372
379
|
error: z.ZodNullable<z.ZodString>;
|
|
373
380
|
durationMs: z.ZodNullable<z.ZodInt>;
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
createdAt: z.ZodISODateTime;
|
|
381
|
+
deliveredAt: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
|
|
382
|
+
createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
|
|
377
383
|
}, {
|
|
378
384
|
out: {};
|
|
379
385
|
in: {};
|
package/dist/webhooks.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { CONTENT_TYPES, WEBHOOK_DELIVERY_STATUSES } from "./db/src/enums.js";
|
|
1
2
|
import { webhookDeliveries, webhooks } from "./db/src/schema/webhooks.js";
|
|
2
3
|
import "./db/src/schema/index.js";
|
|
3
|
-
import { CursorQuery, Id, cursorPageOf, isoDate } from "./common.js";
|
|
4
|
+
import { CursorQuery, Id, cursorPageOf, isoDate, listOf } from "./common.js";
|
|
4
5
|
import { oc } from "@orpc/contract";
|
|
5
6
|
import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
|
|
6
7
|
import { z } from "zod";
|
|
@@ -52,6 +53,18 @@ const CORE_EVENT_TYPES = [
|
|
|
52
53
|
subject: "customer",
|
|
53
54
|
description: "A person is unlinked from a company"
|
|
54
55
|
},
|
|
56
|
+
{
|
|
57
|
+
type: "core.customer.signed_up",
|
|
58
|
+
label: "Customer signed up",
|
|
59
|
+
subject: "customer",
|
|
60
|
+
description: "A person proves their first email address or phone and can sign in to apps"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
type: "core.customer.signed_in",
|
|
64
|
+
label: "Customer signed in",
|
|
65
|
+
subject: "customer",
|
|
66
|
+
description: "A person signs in with a code"
|
|
67
|
+
},
|
|
55
68
|
{
|
|
56
69
|
type: "core.lead.stage_changed",
|
|
57
70
|
label: "Lead moved to another stage",
|
|
@@ -162,7 +175,7 @@ const EventTypeInfo = z.object({
|
|
|
162
175
|
/** `core` or the plugin that publishes it. */
|
|
163
176
|
source: z.string(),
|
|
164
177
|
/** The record it is about, when it is about a customer or company. */
|
|
165
|
-
subject: z.enum(
|
|
178
|
+
subject: z.enum(CONTENT_TYPES).nullable()
|
|
166
179
|
});
|
|
167
180
|
/** `core.customer.created`, `core.customer.*`, `hr.*` or `*`. */
|
|
168
181
|
const EventPattern = z.string().trim().regex(/^(\*|[a-z][a-z0-9_]*(\.[a-z][a-z0-9_]*)*(\.\*)?)$/, "an event type, a prefix ending in .*, or *");
|
|
@@ -190,7 +203,6 @@ const WebhookDelivery = createSelectSchema(webhookDeliveries, {
|
|
|
190
203
|
attempts: int,
|
|
191
204
|
responseStatus: int,
|
|
192
205
|
durationMs: int,
|
|
193
|
-
nextAttemptAt: isoDate,
|
|
194
206
|
deliveredAt: isoDate,
|
|
195
207
|
createdAt: isoDate
|
|
196
208
|
}).pick({
|
|
@@ -204,7 +216,6 @@ const WebhookDelivery = createSelectSchema(webhookDeliveries, {
|
|
|
204
216
|
responseBody: true,
|
|
205
217
|
error: true,
|
|
206
218
|
durationMs: true,
|
|
207
|
-
nextAttemptAt: true,
|
|
208
219
|
deliveredAt: true,
|
|
209
220
|
createdAt: true
|
|
210
221
|
});
|
|
@@ -228,11 +239,11 @@ const webhooksContract = {
|
|
|
228
239
|
method: "GET",
|
|
229
240
|
path: "/events/types",
|
|
230
241
|
summary: "Event types to subscribe to or automate on: core's and installed plugins'"
|
|
231
|
-
}).output(
|
|
242
|
+
}).output(listOf(EventTypeInfo)),
|
|
232
243
|
list: oc.route({
|
|
233
244
|
method: "GET",
|
|
234
245
|
path: "/webhooks"
|
|
235
|
-
}).output(
|
|
246
|
+
}).output(listOf(Webhook)),
|
|
236
247
|
create: oc.route({
|
|
237
248
|
method: "POST",
|
|
238
249
|
path: "/webhooks",
|
|
@@ -269,11 +280,7 @@ const webhooksContract = {
|
|
|
269
280
|
summary: "Recent deliveries, newest first"
|
|
270
281
|
}).input(CursorQuery.extend({
|
|
271
282
|
id: Id,
|
|
272
|
-
status: z.enum(
|
|
273
|
-
"pending",
|
|
274
|
-
"succeeded",
|
|
275
|
-
"failed"
|
|
276
|
-
]).optional()
|
|
283
|
+
status: z.enum(WEBHOOK_DELIVERY_STATUSES).optional()
|
|
277
284
|
})).output(cursorPageOf(WebhookDelivery)),
|
|
278
285
|
redeliver: oc.route({
|
|
279
286
|
method: "POST",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@erxes/core-contract",
|
|
3
|
-
"version": "0.1.0-v2.
|
|
3
|
+
"version": "0.1.0-v2.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "erxes core API contract (/core/v1) and event schemas, shared by core and plugins",
|
|
6
6
|
"license": "AGPL-3.0-only",
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"./automations": "./dist/automations.js",
|
|
25
25
|
"./common": "./dist/common.js",
|
|
26
26
|
"./companies": "./dist/companies.js",
|
|
27
|
+
"./customerAuth": "./dist/customerAuth.js",
|
|
27
28
|
"./customers": "./dist/customers.js",
|
|
28
29
|
"./events": "./dist/events.js",
|
|
29
30
|
"./fields": "./dist/fields.js",
|
|
@@ -37,11 +38,13 @@
|
|
|
37
38
|
"./plugins": "./dist/plugins.js",
|
|
38
39
|
"./products": "./dist/products.js",
|
|
39
40
|
"./roles": "./dist/roles.js",
|
|
41
|
+
"./routes": "./dist/routes.js",
|
|
40
42
|
"./saas": "./dist/saas.js",
|
|
41
43
|
"./tags": "./dist/tags.js",
|
|
42
44
|
"./transfer": "./dist/transfer.js",
|
|
43
45
|
"./trash": "./dist/trash.js",
|
|
44
46
|
"./users": "./dist/users.js",
|
|
47
|
+
"./values": "./dist/values.js",
|
|
45
48
|
"./views": "./dist/views.js",
|
|
46
49
|
"./webhooks": "./dist/webhooks.js",
|
|
47
50
|
"./package.json": "./package.json"
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { pgTable } from "../table.js";
|
|
2
|
-
import { createdAt, updatedAt } from "./common.js";
|
|
3
|
-
import { organizations } from "./organizations.js";
|
|
4
|
-
import { check, foreignKey, index, integer, jsonb, text, timestamp, uniqueIndex } from "drizzle-orm/pg-core";
|
|
5
|
-
import { sql } from "drizzle-orm";
|
|
6
|
-
// ../db/src/schema/jobs.ts
|
|
7
|
-
const timestamptz = () => timestamp({
|
|
8
|
-
withTimezone: true,
|
|
9
|
-
mode: "date"
|
|
10
|
-
});
|
|
11
|
-
const JOB_STATUSES = [
|
|
12
|
-
"queued",
|
|
13
|
-
"running",
|
|
14
|
-
"dead"
|
|
15
|
-
];
|
|
16
|
-
pgTable("jobs", {
|
|
17
|
-
id: text().primaryKey(),
|
|
18
|
-
orgId: text().notNull(),
|
|
19
|
-
/** What to do: `webhook.deliver`, `automation.step`, … */
|
|
20
|
-
queue: text().notNull(),
|
|
21
|
-
payload: jsonb().$type().default({}).notNull(),
|
|
22
|
-
status: text({ enum: JOB_STATUSES }).default("queued").notNull(),
|
|
23
|
-
runAt: timestamptz().defaultNow().notNull(),
|
|
24
|
-
attempts: integer().default(0).notNull(),
|
|
25
|
-
maxAttempts: integer().default(8).notNull(),
|
|
26
|
-
lockedUntil: timestamptz(),
|
|
27
|
-
lastError: text(),
|
|
28
|
-
/** One queued job per key (per organisation and queue). */
|
|
29
|
-
dedupeKey: text(),
|
|
30
|
-
createdAt: createdAt(),
|
|
31
|
-
updatedAt: updatedAt()
|
|
32
|
-
}, (table) => [
|
|
33
|
-
index("core_jobs_due_idx").on(table.runAt).where(sql`${table.status} = 'queued'`),
|
|
34
|
-
index("core_jobs_stuck_idx").on(table.lockedUntil).where(sql`${table.status} = 'running'`),
|
|
35
|
-
index("core_jobs_org_idx").on(table.orgId, table.queue, table.status),
|
|
36
|
-
uniqueIndex("core_jobs_dedupe_key").on(table.orgId, table.queue, table.dedupeKey).where(sql`${table.dedupeKey} IS NOT NULL`),
|
|
37
|
-
check("core_jobs_status_check", sql`${table.status} IN ('queued', 'running', 'dead')`),
|
|
38
|
-
foreignKey({
|
|
39
|
-
columns: [table.orgId],
|
|
40
|
-
foreignColumns: [organizations.id],
|
|
41
|
-
name: "core_jobs_org_id_fkey"
|
|
42
|
-
}).onDelete("cascade")
|
|
43
|
-
]);
|
|
44
|
-
export { JOB_STATUSES };
|