@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/users.js CHANGED
@@ -1,32 +1,23 @@
1
- import { USER_STATUSES, users } from "./db/src/schema/users.js";
1
+ import { USER_STATUSES } from "./db/src/enums.js";
2
+ import { users } from "./db/src/schema/users.js";
2
3
  import "./db/src/schema/index.js";
3
- import { CursorQuery, Id, IdList, ImageAddress, PhoneNumber, QueryBoolean, cursorPageOf, isoDate } from "./common.js";
4
- import { RoleKey } from "./roles.js";
4
+ import { COMMON_ERRORS, ERRORS } from "./errors.js";
5
+ import { CursorQuery, DESCRIPTION_MAX, Id, IdList, ImageAddress, PhoneNumber, QueryBoolean, cursorPageOf, isoDate } from "./common.js";
6
+ import { InviteRole, NewPassword, RoleKey, UserLinkName } from "./values.js";
5
7
  import { oc } from "@orpc/contract";
6
- import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
7
8
  import { z } from "zod";
9
+ import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
8
10
  // src/users.ts
9
- /** A role key: `owner`, `admin`, `member` or a custom role (`r_…`). See `./roles`. */
10
- const UserRole = RoleKey;
11
11
  const UserStatus = z.enum(USER_STATUSES);
12
- /** Social links a member can show (old erxes `users.links`). */
13
- const USER_LINK_NAMES = [
14
- "facebook",
15
- "twitter",
16
- "website",
17
- "discord",
18
- "github",
19
- "instagram"
20
- ];
21
- const UserLinkName = z.enum(USER_LINK_NAMES);
22
12
  const UserLinks = z.record(z.string(), z.string());
23
13
  /** A team member. Never carries credentials. */
24
14
  const User = createSelectSchema(users, {
25
15
  id: Id,
26
16
  email: z.email(),
27
- role: UserRole,
17
+ role: RoleKey,
28
18
  links: UserLinks,
29
19
  onboardedAt: isoDate,
20
+ totpEnabledAt: isoDate,
30
21
  createdAt: isoDate,
31
22
  updatedAt: isoDate
32
23
  }).pick({
@@ -52,11 +43,11 @@ const User = createSelectSchema(users, {
52
43
  links: true,
53
44
  /** Finished the welcome steps; null shows them at the next sign-in. */
54
45
  onboardedAt: true,
46
+ /** Signs in with a second step (an authenticator app's code) since then; null when off. */
47
+ totpEnabledAt: true,
55
48
  createdAt: true,
56
49
  updatedAt: true
57
- }).extend({
58
- /** Signs in with a second step (an authenticator app's code). */
59
- twoFactorEnabled: z.boolean() });
50
+ });
60
51
  /** A real calendar date, `YYYY-MM-DD` (2026-02-30 and 2026-99-99 are refused). */
61
52
  const DateOnly = z.string().regex(/^\d{4}-\d{2}-\d{2}$/, "YYYY-MM-DD").refine((value) => {
62
53
  const date = /* @__PURE__ */ new Date(`${value}T00:00:00Z`);
@@ -78,12 +69,12 @@ const UserFields = createUpdateSchema(users, {
78
69
  phone: () => PhoneNumber,
79
70
  birthDate: () => DateOnly,
80
71
  workStartedDate: () => DateOnly,
81
- description: (value) => value.trim().max(5e3),
72
+ description: (value) => value.trim().max(DESCRIPTION_MAX),
82
73
  /** Sets the given links; an empty string or `null` removes one. Others stay. */
83
74
  links: z.partialRecord(UserLinkName, z.string().trim().max(500).nullable()).optional(),
84
75
  email: (email) => email.trim().check(z.email()).max(254),
85
76
  avatarUrl: () => ImageAddress,
86
- role: () => UserRole
77
+ role: () => RoleKey
87
78
  }).pick({
88
79
  fullName: true,
89
80
  username: true,
@@ -101,13 +92,11 @@ const UserFields = createUpdateSchema(users, {
101
92
  avatarUrl: true,
102
93
  role: true
103
94
  });
104
- /** As sign-up (`NewPassword` in auth.ts, which imports this file). */
105
- const MemberPassword = 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");
106
95
  const InviteEntry = z.object({
107
96
  email: z.string().trim().check(z.email()).max(254),
108
- role: UserRole.refine((role) => role !== "owner", "invite as admin or member, then make them owner").default("member"),
97
+ role: InviteRole.default("member"),
109
98
  /** Given: the member can sign in at once (active). Otherwise they stay invited. */
110
- password: MemberPassword.optional(),
99
+ password: NewPassword.optional(),
111
100
  ...UserFields.pick({
112
101
  fullName: true,
113
102
  username: true
@@ -115,8 +104,28 @@ const InviteEntry = z.object({
115
104
  });
116
105
  /** Something to change: at least one field besides `id`. */
117
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
+ });
118
127
  const usersContract = {
119
- list: oc.route({
128
+ list: base.route({
120
129
  method: "GET",
121
130
  path: "/users",
122
131
  summary: "Team members of the organisation, newest first"
@@ -125,50 +134,50 @@ const usersContract = {
125
134
  status: UserStatus.optional(),
126
135
  /** `true`: invited and active members; `false`: disabled ones. */
127
136
  isActive: QueryBoolean.optional(),
128
- role: UserRole.optional(),
137
+ role: RoleKey.optional(),
129
138
  ids: IdList.optional()
130
139
  })).output(cursorPageOf(User)),
131
- resendInvitation: oc.route({
140
+ resendInvitation: base.route({
132
141
  method: "POST",
133
142
  path: "/users/{id}/invitation",
134
143
  summary: "Email an invited member a new invitation link (earlier links stop working)"
135
144
  }).input(z.object({ id: Id })).output(z.object({ ok: z.literal(true) })),
136
- get: oc.route({
145
+ get: base.route({
137
146
  method: "GET",
138
147
  path: "/users/{id}"
139
148
  }).input(z.object({ id: Id })).output(User),
140
- invite: oc.route({
149
+ invite: base.route({
141
150
  method: "POST",
142
151
  path: "/users",
143
152
  successStatus: 201,
144
153
  summary: "Invite a team member (owners and admins)"
145
154
  }).input(InviteEntry).output(User),
146
- inviteMany: oc.route({
155
+ inviteMany: base.route({
147
156
  method: "POST",
148
157
  path: "/users/invitations",
149
158
  successStatus: 201,
150
159
  summary: "Invite several team members at once, all or none (owners and admins)"
151
- }).input(z.object({ entries: z.array(InviteEntry).min(1).max(50) })).output(z.object({ data: z.array(User) })),
152
- update: oc.route({
160
+ }).input(z.object({ entries: z.array(InviteEntry).min(1).max(50) })).output(z.object({ data: z.array(User).max(50) })),
161
+ update: base.route({
153
162
  method: "PATCH",
154
163
  path: "/users/{id}",
155
164
  summary: "Update a team member (self: own profile; owners/admins: anyone’s profile and role; only owners change an owner’s email)"
156
165
  }).input(UserFields.extend({ id: Id }).refine(changes, "nothing to update")).output(User),
157
- setPassword: oc.route({
166
+ setPassword: base.route({
158
167
  method: "POST",
159
168
  path: "/users/{id}/password",
160
169
  summary: "Set another member’s password (owners and admins; an invited member becomes active)"
161
170
  }).input(z.object({
162
171
  id: Id,
163
- password: MemberPassword
172
+ password: NewPassword
164
173
  })).output(User),
165
- disable: oc.route({
174
+ disable: base.route({
166
175
  method: "POST",
167
176
  path: "/users/{id}/disable"
168
177
  }).input(z.object({ id: Id })).output(User),
169
- enable: oc.route({
178
+ enable: base.route({
170
179
  method: "POST",
171
180
  path: "/users/{id}/enable"
172
181
  }).input(z.object({ id: Id })).output(User)
173
182
  };
174
- export { DateOnly, USER_LINK_NAMES, User, UserLinkName, UserLinks, UserRole, UserStatus, usersContract };
183
+ export { DateOnly, User, UserLinks, UserStatus, usersContract };
@@ -0,0 +1,150 @@
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
+ /**
115
+ * Core's notifications in groups a member chooses for at once (each plugin
116
+ * is a group of its own). `security` is always on.
117
+ */
118
+ export declare const CORE_NOTIFICATION_GROUPS: readonly [{
119
+ readonly key: 'assigned';
120
+ readonly label: 'Assigned to me';
121
+ readonly kinds: readonly ["core.customer.assigned", "core.company.assigned"];
122
+ readonly default: 'email';
123
+ }, {
124
+ readonly key: 'records';
125
+ readonly label: 'Changes to records I own';
126
+ 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"];
127
+ readonly default: 'inbox';
128
+ }, {
129
+ readonly key: 'mentions';
130
+ readonly label: 'Mentions';
131
+ readonly kinds: readonly ["core.note.mentioned"];
132
+ readonly default: 'email';
133
+ }, {
134
+ readonly key: 'automations';
135
+ readonly label: 'Automations';
136
+ readonly kinds: readonly ["core.automation.message", "core.automation.failed"];
137
+ readonly default: 'inbox';
138
+ }, {
139
+ readonly key: 'transfer';
140
+ readonly label: 'Imports and exports';
141
+ readonly kinds: readonly ["core.import.done", "core.export.ready"];
142
+ readonly default: 'inbox';
143
+ }, {
144
+ readonly key: 'security';
145
+ readonly label: 'Security';
146
+ readonly kinds: readonly string[];
147
+ readonly default: 'inbox';
148
+ }];
149
+ /** The group a notification belongs to: a core group, or the plugin that sent it. */
150
+ export declare const notificationGroupOf: (source: string, kind: string) => string;
package/dist/values.js ADDED
@@ -0,0 +1,139 @@
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
+ 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
+ /**
87
+ * Core's notifications in groups a member chooses for at once (each plugin
88
+ * is a group of its own). `security` is always on.
89
+ */
90
+ const CORE_NOTIFICATION_GROUPS = [
91
+ {
92
+ key: "assigned",
93
+ label: "Assigned to me",
94
+ kinds: ["core.customer.assigned", "core.company.assigned"],
95
+ default: "email"
96
+ },
97
+ {
98
+ key: "records",
99
+ label: "Changes to records I own",
100
+ kinds: [
101
+ "core.customer.updated",
102
+ "core.customer.merged",
103
+ "core.customer.deleted",
104
+ "core.company.updated",
105
+ "core.company.merged",
106
+ "core.company.deleted",
107
+ "core.customer.activity",
108
+ "core.company.activity"
109
+ ],
110
+ default: "inbox"
111
+ },
112
+ {
113
+ key: "mentions",
114
+ label: "Mentions",
115
+ kinds: ["core.note.mentioned"],
116
+ default: "email"
117
+ },
118
+ {
119
+ key: "automations",
120
+ label: "Automations",
121
+ kinds: ["core.automation.message", "core.automation.failed"],
122
+ default: "inbox"
123
+ },
124
+ {
125
+ key: "transfer",
126
+ label: "Imports and exports",
127
+ kinds: ["core.import.done", "core.export.ready"],
128
+ default: "inbox"
129
+ },
130
+ {
131
+ key: "security",
132
+ label: "Security",
133
+ kinds: UNMUTABLE_NOTIFICATION_KINDS,
134
+ default: "inbox"
135
+ }
136
+ ];
137
+ /** The group a notification belongs to: a core group, or the plugin that sent it. */
138
+ const notificationGroupOf = (source, kind) => source === "core" ? CORE_NOTIFICATION_GROUPS.find((group) => group.kinds.includes(kind))?.key ?? "records" : source;
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 };