@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/customers.js CHANGED
@@ -1,21 +1,17 @@
1
+ import { CUSTOMER_STATES } from "./db/src/enums.js";
1
2
  import { customers } from "./db/src/schema/customers.js";
2
3
  import { companies, customerCompanies } from "./db/src/schema/companies.js";
3
4
  import "./db/src/schema/index.js";
4
- import { CursorQuery, CustomFields, CustomFieldsPatch, EmailAddress, Id, IdList, ImageAddress, PhoneNumber, cursorPageOf, isoDate } from "./common.js";
5
+ import { COMMON_ERRORS, ERRORS } from "./errors.js";
6
+ import { CustomerSex } from "./values.js";
7
+ import { CursorQuery, CustomFields, CustomFieldsPatch, DESCRIPTION_MAX, EmailAddress, Id, IdList, ImageAddress, PhoneNumber, cursorPageOf, isoDate, listOf } from "./common.js";
5
8
  import { ContactState, LIFECYCLE_COLUMNS, LIFECYCLE_INPUT_COLUMNS, lifecycleInput, lifecycleRow } from "./leads.js";
6
9
  import { oc } from "@orpc/contract";
7
- import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
8
10
  import { z } from "zod";
11
+ import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
9
12
  // src/customers.ts
10
13
  /** `lead`: not a customer yet (e.g. a form submission). */
11
14
  const CustomerState = ContactState;
12
- /** ISO/IEC 5218, as in erxes until now: 0 not known, 1 male, 2 female, 9 not applicable. */
13
- const CustomerSex = z.union([
14
- z.literal(0),
15
- z.literal(1),
16
- z.literal(2),
17
- z.literal(9)
18
- ]);
19
15
  /** A person the organisation works with; shared by every plugin. */
20
16
  const Customer = createSelectSchema(customers, {
21
17
  id: Id,
@@ -66,7 +62,7 @@ const CustomerFields = createUpdateSchema(customers, {
66
62
  position: (value) => value.trim().max(200),
67
63
  department: (value) => value.trim().max(200),
68
64
  code: (code) => code.trim().max(100),
69
- description: (value) => value.trim().max(5e3),
65
+ description: (value) => value.trim().max(DESCRIPTION_MAX),
70
66
  ownerId: () => Id,
71
67
  ...lifecycleInput
72
68
  }).pick({
@@ -131,8 +127,22 @@ const TagChange = z.object({
131
127
  add: z.array(Id).max(50).default([]),
132
128
  remove: z.array(Id).max(50).default([])
133
129
  });
130
+ const { INVALID_ACTOR, INVALID_FIELD, INVALID_FIELD_VALUE, INVALID_OWNER, INVALID_TAG, INVALID_TYPE, MASS_DELETE_STOPPED, NOT_A_LEAD, TAG_LIMIT } = ERRORS;
131
+ /** What these procedures answer with besides the common errors. */
132
+ const base = oc.errors({
133
+ ...COMMON_ERRORS,
134
+ INVALID_ACTOR,
135
+ INVALID_FIELD,
136
+ INVALID_FIELD_VALUE,
137
+ INVALID_OWNER,
138
+ INVALID_TAG,
139
+ INVALID_TYPE,
140
+ MASS_DELETE_STOPPED,
141
+ NOT_A_LEAD,
142
+ TAG_LIMIT
143
+ });
134
144
  const customersContract = {
135
- list: oc.route({
145
+ list: base.route({
136
146
  method: "GET",
137
147
  path: "/customers",
138
148
  summary: "Customers of the organisation, newest first"
@@ -150,7 +160,7 @@ const customersContract = {
150
160
  /** An advanced filter: JSON of a condition group (`RecordFilter`), as views save it. */
151
161
  filter: z.string().max(2e4).optional()
152
162
  })).output(cursorPageOf(Customer)),
153
- findOrCreate: oc.route({
163
+ findOrCreate: base.route({
154
164
  method: "POST",
155
165
  path: "/customers/find-or-create",
156
166
  summary: "The customer with this email or phone, or a new one (members with contacts.create; plugins with customers:write). Safe to call twice at once"
@@ -159,7 +169,7 @@ const customersContract = {
159
169
  primaryPhone: z.string().trim().min(3).max(40).optional(),
160
170
  firstName: z.string().trim().max(100).optional(),
161
171
  lastName: z.string().trim().max(100).optional(),
162
- state: z.enum(["lead", "customer"]).optional(),
172
+ state: z.enum(CUSTOMER_STATES).optional(),
163
173
  /** For a new one: where they came from (default: the plugin, or `manual`). */
164
174
  source: CustomerFields.shape.source,
165
175
  sourceDetails: CustomerFields.shape.sourceDetails
@@ -167,42 +177,42 @@ const customersContract = {
167
177
  customer: Customer,
168
178
  created: z.boolean()
169
179
  })),
170
- get: oc.route({
180
+ get: base.route({
171
181
  method: "GET",
172
182
  path: "/customers/{id}",
173
183
  summary: "A customer; ids merged into another customer resolve to it"
174
184
  }).input(ID).output(Customer),
175
- create: oc.route({
185
+ create: base.route({
176
186
  method: "POST",
177
187
  path: "/customers",
178
188
  successStatus: 201,
179
- summary: "Create a customer. 409 CUSTOMER_EXISTS (data: { id, field }) when the primary email or phone is taken"
189
+ summary: "Create a customer. 409 TAKEN (data.field) when the primary email or phone is taken"
180
190
  }).input(CustomerFields.refine(identifies, "a name, an email or a phone is required")).output(Customer),
181
- update: oc.route({
191
+ update: base.route({
182
192
  method: "PATCH",
183
193
  path: "/customers/{id}"
184
194
  }).input(CustomerFields.extend({ id: Id }).refine(changes, "nothing to update")).output(Customer),
185
- remove: oc.route({
195
+ remove: base.route({
186
196
  method: "POST",
187
197
  path: "/customers/remove",
188
198
  summary: "Delete customers (owners and admins)"
189
199
  }).input(Ids).output(z.object({ removed: z.int() })),
190
- merge: oc.route({
200
+ merge: base.route({
191
201
  method: "POST",
192
202
  path: "/customers/merge",
193
203
  summary: "Merge customers into `keepId`: empty fields are filled from the others, emails, phones, tags and companies are combined, the others are deleted (owners and admins)"
194
204
  }).input(MergeInput).output(Customer),
195
- tag: oc.route({
205
+ tag: base.route({
196
206
  method: "POST",
197
207
  path: "/customers/tag",
198
208
  summary: "Add and remove tags on many customers"
199
209
  }).input(TagChange).output(z.object({ updated: z.int() })),
200
- companies: oc.route({
210
+ companies: base.route({
201
211
  method: "GET",
202
212
  path: "/customers/{id}/companies",
203
213
  summary: "The customer's companies"
204
- }).input(ID).output(z.object({ data: z.array(CompanyRef) })),
205
- linkCompany: oc.route({
214
+ }).input(ID).output(listOf(CompanyRef)),
215
+ linkCompany: base.route({
206
216
  method: "PUT",
207
217
  path: "/customers/{id}/companies/{companyId}",
208
218
  summary: "Link (or change the link: role, main contact, left)"
@@ -210,7 +220,7 @@ const customersContract = {
210
220
  id: Id,
211
221
  companyId: Id
212
222
  })).output(z.object({ ok: z.literal(true) })),
213
- unlinkCompany: oc.route({
223
+ unlinkCompany: base.route({
214
224
  method: "DELETE",
215
225
  path: "/customers/{id}/companies/{companyId}"
216
226
  }).input(z.object({
@@ -218,4 +228,4 @@ const customersContract = {
218
228
  companyId: Id
219
229
  })).output(z.object({ ok: z.literal(true) }))
220
230
  };
221
- export { CompanyRef, ContactLink, ContactLinkInput, Customer, CustomerFields, CustomerSex, CustomerState, customersContract };
231
+ export { CompanyRef, ContactLink, ContactLinkInput, Customer, CustomerFields, CustomerState, customersContract };
@@ -1,4 +1,5 @@
1
- import { CONDITION_OPERATORS, ConditionGroup as ConditionGroup$1 } from "./db/src/schema/common.js";
1
+ import { CONDITION_OPERATORS, DELAY_UNITS } from "./enums.js";
2
+ import { ConditionGroup as ConditionGroup$1 } from "./schema/common.js";
2
3
  import { z } from "zod";
3
4
  /** Where a condition or template reads from: `event.payload.amount`, `subject.primaryEmail`, `steps.s2.output.id`. */
4
5
  export declare const ContextPath: z.ZodString;
@@ -74,7 +75,7 @@ export type AutomationStep = {
74
75
  id: string;
75
76
  type: 'delay';
76
77
  amount?: number;
77
- unit?: 'minutes' | 'hours' | 'days';
78
+ unit?: (typeof DELAY_UNITS)[number];
78
79
  until?: string;
79
80
  label?: string;
80
81
  } | {
@@ -85,7 +86,7 @@ export type AutomationStep = {
85
86
  conditions?: ConditionGroup;
86
87
  /** Give up after this long (the step's output says `matched: false`). */
87
88
  amount: number;
88
- unit: 'minutes' | 'hours' | 'days';
89
+ unit: (typeof DELAY_UNITS)[number];
89
90
  label?: string;
90
91
  } | {
91
92
  id: string;
@@ -1,18 +1,13 @@
1
- import { CONDITION_OPERATORS } from "./db/src/schema/common.js";
2
- import "./db/src/schema/index.js";
1
+ import { CONDITION_MATCHES, CONDITION_OPERATORS, CONTENT_TYPES, DELAY_UNITS, REENTRY_RULES, RELATIVE_DATE_UNITS, SCHEDULE_INTERVALS } from "./enums.js";
3
2
  import { z } from "zod";
4
- // src/automationDefinition.ts
3
+ // ../db/src/automationDefinition.ts
5
4
  /** Where a condition or template reads from: `event.payload.amount`, `subject.primaryEmail`, `steps.s2.output.id`. */
6
5
  const ContextPath = z.string().trim().regex(/^(event|subject|steps|run)(\.[A-Za-z0-9_-]+)*$/, "a path like subject.primaryEmail");
7
6
  const ConditionOperator = z.enum(CONDITION_OPERATORS);
8
7
  /** The value of a relative-date rule: "within the last 30 days". */
9
8
  const RelativeAmount = z.object({
10
9
  amount: z.int().min(0).max(3650),
11
- unit: z.enum([
12
- "days",
13
- "weeks",
14
- "months"
15
- ]).default("days")
10
+ unit: z.enum(RELATIVE_DATE_UNITS).default("days")
16
11
  });
17
12
  const ConditionRule = z.object({
18
13
  path: ContextPath,
@@ -21,18 +16,14 @@ const ConditionRule = z.object({
21
16
  });
22
17
  /** Rules (or nested groups) that must all, or any, hold. */
23
18
  const ConditionGroup = z.lazy(() => z.object({
24
- match: z.enum(["all", "any"]),
19
+ match: z.enum(CONDITION_MATCHES),
25
20
  rules: z.array(z.union([ConditionRule, ConditionGroup])).max(50)
26
21
  }));
27
22
  const StepId = z.string().regex(/^[a-z0-9]{1,24}$/i, "letters and digits");
28
23
  const Label = z.string().trim().max(100).optional();
29
24
  const Duration = {
30
25
  amount: z.int().min(1).max(1e4),
31
- unit: z.enum([
32
- "minutes",
33
- "hours",
34
- "days"
35
- ])
26
+ unit: z.enum(DELAY_UNITS)
36
27
  };
37
28
  /**
38
29
  * Action input: values, or text with `{{subject.firstName}}`-style
@@ -52,11 +43,7 @@ const AutomationStep = z.lazy(() => z.discriminatedUnion("type", [
52
43
  id: StepId,
53
44
  type: z.literal("delay"),
54
45
  amount: z.int().min(1).max(1e4).optional(),
55
- unit: z.enum([
56
- "minutes",
57
- "hours",
58
- "days"
59
- ]).optional(),
46
+ unit: z.enum(DELAY_UNITS).optional(),
60
47
  /** A date to wait until (template allowed), instead of an amount. */
61
48
  until: z.string().max(200).optional(),
62
49
  label: Label
@@ -116,7 +103,7 @@ const TimeZone = z.string().max(60).refine((zone) => {
116
103
  }, "a time zone like Asia/Ulaanbaatar");
117
104
  /** Which records a scheduled or manual run goes through: none (one run), or each matching customer/company. */
118
105
  const Audience = z.object({
119
- type: z.enum(["customer", "company"]),
106
+ type: z.enum(CONTENT_TYPES),
120
107
  /** Conditions on `subject.*`; empty: every record. */
121
108
  conditions: ConditionGroup.optional()
122
109
  });
@@ -128,12 +115,7 @@ const AutomationTrigger = z.discriminatedUnion("kind", [
128
115
  }),
129
116
  z.object({
130
117
  kind: z.literal("schedule"),
131
- every: z.enum([
132
- "hour",
133
- "day",
134
- "week",
135
- "month"
136
- ]),
118
+ every: z.enum(SCHEDULE_INTERVALS),
137
119
  at: TimeOfDay.default("09:00"),
138
120
  /** 1 = Monday … 7 = Sunday (week). */
139
121
  weekdays: z.array(z.int().min(1).max(7)).max(7).optional(),
@@ -143,7 +125,7 @@ const AutomationTrigger = z.discriminatedUnion("kind", [
143
125
  }),
144
126
  z.object({
145
127
  kind: z.literal("date"),
146
- subject: z.enum(["customer", "company"]),
128
+ subject: z.enum(CONTENT_TYPES),
147
129
  /** `birthDate` or a date custom field's id. */
148
130
  field: z.string().min(1).max(64),
149
131
  /** Days after (positive) or before (negative) the date. */
@@ -163,11 +145,7 @@ const AutomationTrigger = z.discriminatedUnion("kind", [
163
145
  * When the same customer or company may run through again:
164
146
  * every time, only once ever, or once a day.
165
147
  */
166
- const Reentry = z.enum([
167
- "always",
168
- "once",
169
- "daily"
170
- ]);
148
+ const Reentry = z.enum(REENTRY_RULES);
171
149
  const AutomationDefinition = z.object({
172
150
  trigger: AutomationTrigger,
173
151
  steps: z.array(AutomationStep).min(1).max(100),
@@ -0,0 +1,8 @@
1
+ /** `all`: every condition holds; `any`: one does. */
2
+ export declare const CONDITION_MATCHES: readonly ['all', 'any'];
3
+ export declare const CONDITION_OPERATORS: readonly ['eq', 'neq', 'gt', 'gte', 'lt', 'lte', 'contains', 'not_contains', 'starts_with', 'in', 'not_in', 'exists', 'not_exists',
4
+ /** Dates relative to now; the value is `{ amount, unit }` (days, weeks, months). */
5
+ 'within_last', 'more_than_ago', 'within_next',
6
+ /** The day and month fall within the next `amount` days (birthdays, anniversaries), whatever the year. */
7
+ 'anniversary_within'];
8
+ export declare const DELAY_UNITS: readonly ['minutes', 'hours', 'days'];
@@ -0,0 +1,334 @@
1
+ // ../db/src/enums.ts
2
+ /**
3
+ * Every value list core stores, accepts or reads from its settings, one `as const` array
4
+ * each. The tables (`text({ enum })`, `inList` checks), the contract (`z.enum`) and the
5
+ * config all read them from here; `erxes/no-inline-enum` fails a list spelled out anywhere
6
+ * else. This file imports nothing, so a browser can load an enum without the tables or drizzle.
7
+ */
8
+ /** The contact records: what tags, trash, webhooks and automation subjects refer to. */
9
+ const CONTENT_TYPES = ["customer", "company"];
10
+ /** An automation or plugin action's subject: a contact record, or either. */
11
+ const AUTOMATION_SUBJECTS = [...CONTENT_TYPES, "any"];
12
+ /** Records custom fields attach to: contacts, and the shared product catalog. */
13
+ const FIELD_CONTENT_TYPES = [...CONTENT_TYPES, "product"];
14
+ const CUSTOMER_STATES = ["lead", "customer"];
15
+ /** ISO/IEC 5218: not known, male, female, not applicable. */
16
+ const CUSTOMER_SEXES = [
17
+ 0,
18
+ 1,
19
+ 2,
20
+ 9
21
+ ];
22
+ /** `open`: still being worked; `qualified`: ready to become a customer; `disqualified`: not a fit (lost). */
23
+ const LEAD_STAGE_KINDS = [
24
+ "open",
25
+ "qualified",
26
+ "disqualified"
27
+ ];
28
+ const LEAD_EVENTS = [
29
+ "created",
30
+ "stage",
31
+ "converted",
32
+ "reopened"
33
+ ];
34
+ const PRODUCT_KINDS = ["goods", "service"];
35
+ const PRODUCT_STATUSES = ["active", "archived"];
36
+ /** Lists views belong to: customers, leads (people), companies, company leads, products. */
37
+ const VIEW_RECORD_TYPES = [
38
+ "customer",
39
+ "lead",
40
+ "company",
41
+ "company_lead",
42
+ "product"
43
+ ];
44
+ const ACTIVITY_TARGETS = ["customer", "company"];
45
+ /** Which activities a record's timeline shows. */
46
+ const TIMELINE_KINDS = [
47
+ "all",
48
+ "notes",
49
+ "changes",
50
+ "plugins"
51
+ ];
52
+ const SORT_DIRECTIONS = ["asc", "desc"];
53
+ const PAGE_DIRECTIONS = ["forward", "backward"];
54
+ /** Whether a page starts at the cursor's record or after it. */
55
+ const CURSOR_MODES = ["inclusive", "exclusive"];
56
+ /** A yes/no query parameter or setting, as text. */
57
+ const BOOLEAN_STRINGS = ["true", "false"];
58
+ /** How a list filter's values compare. */
59
+ const FILTER_FIELD_TYPES = [
60
+ "text",
61
+ "number",
62
+ "date",
63
+ "boolean",
64
+ "select",
65
+ "member",
66
+ "tags"
67
+ ];
68
+ /** Where a list filter comes from, for grouping in the picker. */
69
+ const FILTER_FIELD_GROUPS = [
70
+ "fields",
71
+ "lead",
72
+ "custom",
73
+ "company",
74
+ "activity"
75
+ ];
76
+ const FIELD_TYPES = [
77
+ "text",
78
+ "textarea",
79
+ "number",
80
+ "date",
81
+ "boolean",
82
+ "select",
83
+ "multiselect",
84
+ "radio",
85
+ "check",
86
+ "phone",
87
+ "list"
88
+ ];
89
+ /** `all`: every condition holds; `any`: one does. */
90
+ const CONDITION_MATCHES = ["all", "any"];
91
+ /** The units of a relative date condition's `{ amount, unit }`. */
92
+ const RELATIVE_DATE_UNITS = [
93
+ "days",
94
+ "weeks",
95
+ "months"
96
+ ];
97
+ /** Formats a text field's values must have. */
98
+ const FIELD_VALIDATIONS = [
99
+ "number",
100
+ "email",
101
+ "date"
102
+ ];
103
+ const CONDITION_OPERATORS = [
104
+ "eq",
105
+ "neq",
106
+ "gt",
107
+ "gte",
108
+ "lt",
109
+ "lte",
110
+ "contains",
111
+ "not_contains",
112
+ "starts_with",
113
+ "in",
114
+ "not_in",
115
+ "exists",
116
+ "not_exists",
117
+ "within_last",
118
+ "more_than_ago",
119
+ "within_next",
120
+ "anniversary_within"
121
+ ];
122
+ const USER_STATUSES = [
123
+ "invited",
124
+ "active",
125
+ "disabled"
126
+ ];
127
+ const AUTH_TOKEN_PURPOSES = ["invite", "password_reset"];
128
+ /** The languages core's emails and example data come in. */
129
+ const LANGUAGES = ["en", "mn"];
130
+ /** How a member gets one kind of notification. */
131
+ const NOTIFICATION_DELIVERIES = [
132
+ "email",
133
+ "inbox",
134
+ "off"
135
+ ];
136
+ /** How a customer signs in: a code sent to an email address or a phone. */
137
+ const CUSTOMER_LOGIN_KINDS = ["email", "phone"];
138
+ /** What a sign-in code is for: signing in (or up), or adding a login to a signed-in customer. */
139
+ const CUSTOMER_CODE_PURPOSES = ["sign_in", "add_login"];
140
+ const ORGANIZATION_STATUSES = [
141
+ "active",
142
+ "suspended",
143
+ "inactive"
144
+ ];
145
+ const PLUGIN_TIERS = [
146
+ "free",
147
+ "plus",
148
+ "pro"
149
+ ];
150
+ const PLUGIN_STATUSES = ["active", "disabled"];
151
+ /** A plugin's billing status on erxes.io: `past_due` while Stripe retries, `canceling` until the period ends. */
152
+ const ENTITLEMENT_STATUSES = [
153
+ "active",
154
+ "past_due",
155
+ "canceling"
156
+ ];
157
+ /**
158
+ * What a plugin may do here: `full`; `warning` (payment retrying or ending
159
+ * at period end: everything still works); `read_only` (it left the plan:
160
+ * reads and exports for the grace period); `off` (not in the plan).
161
+ */
162
+ const PLUGIN_ACCESS = [
163
+ "full",
164
+ "warning",
165
+ "read_only",
166
+ "off"
167
+ ];
168
+ /**
169
+ * Who did something: a team member, a plugin (by name, e.g. `hr`), a signed-in
170
+ * customer, or core itself (`system`: cleanups, imports). Ids only: names are
171
+ * resolved when shown.
172
+ */
173
+ const ACTOR_TYPES = [
174
+ "user",
175
+ "plugin",
176
+ "customer",
177
+ "system"
178
+ ];
179
+ /** `deleting`: removed, waiting for storage to confirm the bytes are gone (retried until it does). */
180
+ const FILE_STATUSES = [
181
+ "pending",
182
+ "ready",
183
+ "deleting"
184
+ ];
185
+ /** Where files are kept. */
186
+ const FILE_STORAGES = ["local", "s3"];
187
+ /** How a browser gets live updates: a stream, or polling when streams are off. */
188
+ const LIVE_MODES = ["live", "polling"];
189
+ const NOTIFICATION_PRIORITIES = ["normal", "high"];
190
+ const AUDIT_STREAM_FORMATS = [
191
+ "erxes",
192
+ "datadog",
193
+ "splunk"
194
+ ];
195
+ const AUDIT_STREAM_STATUSES = ["active", "paused"];
196
+ /** Where a new audit stream starts: new entries only, or the whole log. */
197
+ const AUDIT_STREAM_STARTS = ["now", "beginning"];
198
+ const EVENT_FAILURE_STATUSES = ["retrying", "dead"];
199
+ const WEBHOOK_STATUSES = ["active", "disabled"];
200
+ const WEBHOOK_DELIVERY_STATUSES = [
201
+ "pending",
202
+ "succeeded",
203
+ "failed"
204
+ ];
205
+ const TRANSFER_RECORD_TYPES = [
206
+ "customer",
207
+ "lead",
208
+ "company"
209
+ ];
210
+ const IMPORT_STATUSES = [
211
+ "parsing",
212
+ "mapping",
213
+ "checking",
214
+ "checked",
215
+ "running",
216
+ "done",
217
+ "failed",
218
+ "undone"
219
+ ];
220
+ const EXPORT_STATUSES = [
221
+ "running",
222
+ "done",
223
+ "failed"
224
+ ];
225
+ const EXPORT_FORMATS = ["csv", "xlsx"];
226
+ /** The columns an import maps to: the record's fields, custom fields, links to other records. */
227
+ const TRANSFER_FIELD_GROUPS = [
228
+ "fields",
229
+ "custom",
230
+ "relations"
231
+ ];
232
+ const IMPORT_MODES = [
233
+ "create",
234
+ "update",
235
+ "upsert"
236
+ ];
237
+ /** The column an import finds an existing record by. */
238
+ const IMPORT_MATCH_KEYS = [
239
+ "email",
240
+ "phone",
241
+ "code",
242
+ "id",
243
+ "name"
244
+ ];
245
+ /** What an import does with one row. */
246
+ const IMPORT_ROW_ACTIONS = [
247
+ "create",
248
+ "update",
249
+ "skip",
250
+ "error"
251
+ ];
252
+ const AUTOMATION_STATUSES = [
253
+ "draft",
254
+ "active",
255
+ "paused"
256
+ ];
257
+ const FINISHED_RUN_STATUSES = [
258
+ "succeeded",
259
+ "failed",
260
+ "cancelled"
261
+ ];
262
+ const RUN_STATUSES = [
263
+ "running",
264
+ "waiting",
265
+ ...FINISHED_RUN_STATUSES
266
+ ];
267
+ const RUN_STEP_STATUSES = [
268
+ "succeeded",
269
+ "failed",
270
+ "skipped"
271
+ ];
272
+ /** Whether a record may enter an automation again: every time, once, or once a day. */
273
+ const REENTRY_RULES = [
274
+ "always",
275
+ "once",
276
+ "daily"
277
+ ];
278
+ const DELAY_UNITS = [
279
+ "minutes",
280
+ "hours",
281
+ "days"
282
+ ];
283
+ /** How often a scheduled trigger fires. */
284
+ const SCHEDULE_INTERVALS = [
285
+ "hour",
286
+ "day",
287
+ "week",
288
+ "month"
289
+ ];
290
+ /** How the values of a path conditions and placeholders read compare. */
291
+ const AUTOMATION_FIELD_TYPES = [
292
+ "text",
293
+ "number",
294
+ "date",
295
+ "boolean",
296
+ "list",
297
+ "member",
298
+ "tags",
299
+ "select"
300
+ ];
301
+ /** The inputs an action's form shows. */
302
+ const ACTION_FIELD_TYPES = [
303
+ "text",
304
+ "longtext",
305
+ "number",
306
+ "boolean",
307
+ "date",
308
+ "select",
309
+ "members",
310
+ "tags",
311
+ "json",
312
+ "custom_field",
313
+ "lead_stage",
314
+ "recipients"
315
+ ];
316
+ const PAYMENT_GATEWAY_KINDS = ["qpay", "test"];
317
+ const PAYMENT_GATEWAY_STATUSES = ["active", "disabled"];
318
+ /** How a gateway refunds: any part, only the whole payment, or not at all. */
319
+ const GATEWAY_REFUND_KINDS = [
320
+ "partial",
321
+ "full",
322
+ "none"
323
+ ];
324
+ const INVOICE_STATUSES = [
325
+ "pending",
326
+ "paid",
327
+ "refunded",
328
+ "cancelled",
329
+ "expired",
330
+ "failed"
331
+ ];
332
+ const REFUND_STATUSES = ["succeeded", "failed"];
333
+ const REFUND_METHODS = ["gateway", "manual"];
334
+ export { ACTION_FIELD_TYPES, ACTIVITY_TARGETS, ACTOR_TYPES, AUDIT_STREAM_FORMATS, AUDIT_STREAM_STARTS, AUDIT_STREAM_STATUSES, AUTH_TOKEN_PURPOSES, AUTOMATION_FIELD_TYPES, AUTOMATION_STATUSES, AUTOMATION_SUBJECTS, BOOLEAN_STRINGS, CONDITION_MATCHES, CONDITION_OPERATORS, CONTENT_TYPES, CURSOR_MODES, CUSTOMER_CODE_PURPOSES, CUSTOMER_LOGIN_KINDS, CUSTOMER_SEXES, CUSTOMER_STATES, DELAY_UNITS, ENTITLEMENT_STATUSES, EVENT_FAILURE_STATUSES, EXPORT_FORMATS, EXPORT_STATUSES, FIELD_CONTENT_TYPES, FIELD_TYPES, FIELD_VALIDATIONS, FILE_STATUSES, FILE_STORAGES, FILTER_FIELD_GROUPS, FILTER_FIELD_TYPES, FINISHED_RUN_STATUSES, GATEWAY_REFUND_KINDS, IMPORT_MATCH_KEYS, IMPORT_MODES, IMPORT_ROW_ACTIONS, IMPORT_STATUSES, INVOICE_STATUSES, LANGUAGES, LEAD_EVENTS, LEAD_STAGE_KINDS, LIVE_MODES, NOTIFICATION_DELIVERIES, NOTIFICATION_PRIORITIES, ORGANIZATION_STATUSES, PAGE_DIRECTIONS, PAYMENT_GATEWAY_KINDS, PAYMENT_GATEWAY_STATUSES, PLUGIN_ACCESS, PLUGIN_STATUSES, PLUGIN_TIERS, PRODUCT_KINDS, PRODUCT_STATUSES, REENTRY_RULES, REFUND_METHODS, REFUND_STATUSES, RELATIVE_DATE_UNITS, RUN_STATUSES, RUN_STEP_STATUSES, SCHEDULE_INTERVALS, SORT_DIRECTIONS, TIMELINE_KINDS, TRANSFER_FIELD_GROUPS, TRANSFER_RECORD_TYPES, USER_STATUSES, VIEW_RECORD_TYPES, WEBHOOK_DELIVERY_STATUSES, WEBHOOK_STATUSES };
@@ -1,19 +1,13 @@
1
- import { pgTable } from "../table.js";
1
+ import { AUDIT_STREAM_FORMATS, AUDIT_STREAM_STATUSES } from "../enums.js";
2
+ import { inList, orgIdColumn, pgTable } from "../table.js";
2
3
  import { createdAt, updatedAt } from "./common.js";
3
4
  import { organizations } from "./organizations.js";
4
5
  import { bigint, check, foreignKey, index, integer, text, timestamp } from "drizzle-orm/pg-core";
5
- import { sql } from "drizzle-orm";
6
6
  // ../db/src/schema/auditStreams.ts
7
7
  const timestamptz = () => timestamp({
8
8
  withTimezone: true,
9
9
  mode: "date"
10
10
  });
11
- const AUDIT_STREAM_FORMATS = [
12
- "erxes",
13
- "datadog",
14
- "splunk"
15
- ];
16
- const AUDIT_STREAM_STATUSES = ["active", "paused"];
17
11
  /**
18
12
  * Sends an organisation's audit log, in chain order, to a log service as it
19
13
  * is written (SIEM, Datadog, Splunk, any HTTPS endpoint). `cursor_seq` is
@@ -22,7 +16,7 @@ const AUDIT_STREAM_STATUSES = ["active", "paused"];
22
16
  */
23
17
  const auditStreams = pgTable("audit_streams", {
24
18
  id: text().primaryKey(),
25
- orgId: text().notNull(),
19
+ orgId: orgIdColumn(),
26
20
  name: text().notNull(),
27
21
  url: text().notNull(),
28
22
  format: text({ enum: AUDIT_STREAM_FORMATS }).default("erxes").notNull(),
@@ -32,8 +26,6 @@ const auditStreams = pgTable("audit_streams", {
32
26
  authHeaderValueSealed: text(),
33
27
  status: text({ enum: AUDIT_STREAM_STATUSES }).default("active").notNull(),
34
28
  cursorSeq: bigint({ mode: "number" }).default(0).notNull(),
35
- /** The delivery loop that owns the stream: resuming starts a new one and the old one stops. */
36
- chainId: text(),
37
29
  lastDeliveredAt: timestamptz(),
38
30
  lastError: text(),
39
31
  consecutiveFailures: integer().default(0).notNull(),
@@ -42,12 +34,12 @@ const auditStreams = pgTable("audit_streams", {
42
34
  updatedAt: updatedAt()
43
35
  }, (table) => [
44
36
  index("core_audit_streams_org_idx").on(table.orgId),
45
- check("core_audit_streams_format_check", sql`${table.format} IN ('erxes', 'datadog', 'splunk')`),
46
- check("core_audit_streams_status_check", sql`${table.status} IN ('active', 'paused')`),
37
+ check("core_audit_streams_format_check", inList(table.format, AUDIT_STREAM_FORMATS)),
38
+ check("core_audit_streams_status_check", inList(table.status, AUDIT_STREAM_STATUSES)),
47
39
  foreignKey({
48
40
  columns: [table.orgId],
49
41
  foreignColumns: [organizations.id],
50
42
  name: "core_audit_streams_org_id_fkey"
51
43
  }).onDelete("cascade")
52
44
  ]);
53
- export { AUDIT_STREAM_FORMATS, AUDIT_STREAM_STATUSES, auditStreams };
45
+ export { auditStreams };