@erxes/core-contract 0.1.0-v2.1 → 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 +1387 -139
- package/dist/activities.js +90 -30
- package/dist/audit.d.ts +1081 -33
- package/dist/audit.js +28 -14
- package/dist/auth.d.ts +2834 -26
- package/dist/auth.js +47 -18
- package/dist/automationRuns.d.ts +7 -9
- package/dist/automationRuns.js +12 -13
- package/dist/automations.d.ts +2443 -61
- package/dist/automations.js +41 -21
- package/dist/client.d.ts +30704 -0
- package/dist/client.js +62 -0
- package/dist/common.d.ts +0 -13
- package/dist/common.js +1 -13
- package/dist/companies.d.ts +1120 -10
- package/dist/companies.js +27 -12
- package/dist/contract/routes.json.js +17 -1
- package/dist/customerAuth.d.ts +1456 -17
- package/dist/customerAuth.js +33 -16
- package/dist/customers.d.ts +1232 -11
- package/dist/customers.js +28 -13
- package/dist/{automationDefinition.d.ts → db/src/automationDefinition.d.ts} +2 -2
- package/dist/{automationDefinition.js → db/src/automationDefinition.js} +2 -2
- package/dist/db/src/enums.js +1 -3
- package/dist/db/src/schema/automations.d.ts +1 -0
- package/dist/db/src/schema/automations.js +3 -3
- package/dist/db/src/schema/index.d.ts +3 -0
- package/dist/db/src/schema/index.js +3 -2
- package/dist/db/src/schema/leads.js +2 -2
- package/dist/db/src/schema/notes.js +92 -0
- package/dist/db/src/schema/payments.js +2 -2
- package/dist/db/src/schema/platform.js +0 -5
- package/dist/db/src/schema/plugins.js +7 -2
- package/dist/db/src/schema/transfer.js +2 -2
- package/dist/errors.d.ts +516 -0
- package/dist/errors.js +218 -0
- package/dist/events.d.ts +570 -121
- package/dist/events.js +41 -24
- package/dist/fields.d.ts +1456 -16
- package/dist/fields.js +27 -19
- package/dist/files.d.ts +761 -62
- package/dist/files.js +32 -21
- package/dist/index.d.ts +25187 -618
- package/dist/index.js +8 -7
- package/dist/leads.d.ts +1105 -21
- package/dist/leads.js +31 -13
- package/dist/notifications.d.ts +689 -48
- package/dist/notifications.js +38 -18
- package/dist/organizations.d.ts +260 -2
- package/dist/organizations.js +21 -2
- package/dist/payments.d.ts +1766 -62
- package/dist/payments.js +48 -26
- package/dist/platform.d.ts +12 -21
- package/dist/platform.js +7 -17
- package/dist/plugins.d.ts +802 -71
- package/dist/plugins.js +48 -27
- package/dist/products.d.ts +1380 -17
- package/dist/products.js +32 -16
- package/dist/roles.d.ts +560 -5
- package/dist/roles.js +20 -6
- package/dist/saas.d.ts +164 -2
- package/dist/saas.js +9 -2
- package/dist/tags.d.ts +340 -4
- package/dist/tags.js +14 -6
- package/dist/transfer.d.ts +1299 -12
- package/dist/transfer.js +32 -13
- package/dist/trash.d.ts +278 -21
- package/dist/trash.js +23 -16
- package/dist/users.d.ts +1206 -18
- package/dist/users.js +35 -13
- package/dist/values.d.ts +0 -9
- package/dist/values.js +2 -7
- package/dist/views.d.ts +396 -5
- package/dist/views.js +10 -7
- package/dist/webhooks.d.ts +765 -9
- package/dist/webhooks.js +18 -10
- package/package.json +6 -2
package/dist/customers.js
CHANGED
|
@@ -2,12 +2,13 @@ import { CUSTOMER_STATES } from "./db/src/enums.js";
|
|
|
2
2
|
import { customers } from "./db/src/schema/customers.js";
|
|
3
3
|
import { companies, customerCompanies } from "./db/src/schema/companies.js";
|
|
4
4
|
import "./db/src/schema/index.js";
|
|
5
|
+
import { COMMON_ERRORS, ERRORS } from "./errors.js";
|
|
5
6
|
import { CustomerSex } from "./values.js";
|
|
6
7
|
import { CursorQuery, CustomFields, CustomFieldsPatch, DESCRIPTION_MAX, EmailAddress, Id, IdList, ImageAddress, PhoneNumber, cursorPageOf, isoDate, listOf } from "./common.js";
|
|
7
8
|
import { ContactState, LIFECYCLE_COLUMNS, LIFECYCLE_INPUT_COLUMNS, lifecycleInput, lifecycleRow } from "./leads.js";
|
|
8
9
|
import { oc } from "@orpc/contract";
|
|
9
|
-
import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
|
|
10
10
|
import { z } from "zod";
|
|
11
|
+
import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
|
|
11
12
|
// src/customers.ts
|
|
12
13
|
/** `lead`: not a customer yet (e.g. a form submission). */
|
|
13
14
|
const CustomerState = ContactState;
|
|
@@ -126,8 +127,22 @@ const TagChange = z.object({
|
|
|
126
127
|
add: z.array(Id).max(50).default([]),
|
|
127
128
|
remove: z.array(Id).max(50).default([])
|
|
128
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
|
+
});
|
|
129
144
|
const customersContract = {
|
|
130
|
-
list:
|
|
145
|
+
list: base.route({
|
|
131
146
|
method: "GET",
|
|
132
147
|
path: "/customers",
|
|
133
148
|
summary: "Customers of the organisation, newest first"
|
|
@@ -145,7 +160,7 @@ const customersContract = {
|
|
|
145
160
|
/** An advanced filter: JSON of a condition group (`RecordFilter`), as views save it. */
|
|
146
161
|
filter: z.string().max(2e4).optional()
|
|
147
162
|
})).output(cursorPageOf(Customer)),
|
|
148
|
-
findOrCreate:
|
|
163
|
+
findOrCreate: base.route({
|
|
149
164
|
method: "POST",
|
|
150
165
|
path: "/customers/find-or-create",
|
|
151
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"
|
|
@@ -162,42 +177,42 @@ const customersContract = {
|
|
|
162
177
|
customer: Customer,
|
|
163
178
|
created: z.boolean()
|
|
164
179
|
})),
|
|
165
|
-
get:
|
|
180
|
+
get: base.route({
|
|
166
181
|
method: "GET",
|
|
167
182
|
path: "/customers/{id}",
|
|
168
183
|
summary: "A customer; ids merged into another customer resolve to it"
|
|
169
184
|
}).input(ID).output(Customer),
|
|
170
|
-
create:
|
|
185
|
+
create: base.route({
|
|
171
186
|
method: "POST",
|
|
172
187
|
path: "/customers",
|
|
173
188
|
successStatus: 201,
|
|
174
|
-
summary: "Create a customer. 409
|
|
189
|
+
summary: "Create a customer. 409 TAKEN (data.field) when the primary email or phone is taken"
|
|
175
190
|
}).input(CustomerFields.refine(identifies, "a name, an email or a phone is required")).output(Customer),
|
|
176
|
-
update:
|
|
191
|
+
update: base.route({
|
|
177
192
|
method: "PATCH",
|
|
178
193
|
path: "/customers/{id}"
|
|
179
194
|
}).input(CustomerFields.extend({ id: Id }).refine(changes, "nothing to update")).output(Customer),
|
|
180
|
-
remove:
|
|
195
|
+
remove: base.route({
|
|
181
196
|
method: "POST",
|
|
182
197
|
path: "/customers/remove",
|
|
183
198
|
summary: "Delete customers (owners and admins)"
|
|
184
199
|
}).input(Ids).output(z.object({ removed: z.int() })),
|
|
185
|
-
merge:
|
|
200
|
+
merge: base.route({
|
|
186
201
|
method: "POST",
|
|
187
202
|
path: "/customers/merge",
|
|
188
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)"
|
|
189
204
|
}).input(MergeInput).output(Customer),
|
|
190
|
-
tag:
|
|
205
|
+
tag: base.route({
|
|
191
206
|
method: "POST",
|
|
192
207
|
path: "/customers/tag",
|
|
193
208
|
summary: "Add and remove tags on many customers"
|
|
194
209
|
}).input(TagChange).output(z.object({ updated: z.int() })),
|
|
195
|
-
companies:
|
|
210
|
+
companies: base.route({
|
|
196
211
|
method: "GET",
|
|
197
212
|
path: "/customers/{id}/companies",
|
|
198
213
|
summary: "The customer's companies"
|
|
199
214
|
}).input(ID).output(listOf(CompanyRef)),
|
|
200
|
-
linkCompany:
|
|
215
|
+
linkCompany: base.route({
|
|
201
216
|
method: "PUT",
|
|
202
217
|
path: "/customers/{id}/companies/{companyId}",
|
|
203
218
|
summary: "Link (or change the link: role, main contact, left)"
|
|
@@ -205,7 +220,7 @@ const customersContract = {
|
|
|
205
220
|
id: Id,
|
|
206
221
|
companyId: Id
|
|
207
222
|
})).output(z.object({ ok: z.literal(true) })),
|
|
208
|
-
unlinkCompany:
|
|
223
|
+
unlinkCompany: base.route({
|
|
209
224
|
method: "DELETE",
|
|
210
225
|
path: "/customers/{id}/companies/{companyId}"
|
|
211
226
|
}).input(z.object({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CONDITION_OPERATORS, DELAY_UNITS } from "./
|
|
2
|
-
import { ConditionGroup as ConditionGroup$1 } from "./
|
|
1
|
+
import { CONDITION_OPERATORS, DELAY_UNITS } from "./enums.js";
|
|
2
|
+
import { ConditionGroup as ConditionGroup$1 } from "./schema/common.js";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
/** Where a condition or template reads from: `event.payload.amount`, `subject.primaryEmail`, `steps.s2.output.id`. */
|
|
5
5
|
export declare const ContextPath: z.ZodString;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { CONDITION_MATCHES, CONDITION_OPERATORS, CONTENT_TYPES, DELAY_UNITS, REENTRY_RULES, RELATIVE_DATE_UNITS, SCHEDULE_INTERVALS } from "./
|
|
1
|
+
import { CONDITION_MATCHES, CONDITION_OPERATORS, CONTENT_TYPES, DELAY_UNITS, REENTRY_RULES, RELATIVE_DATE_UNITS, SCHEDULE_INTERVALS } from "./enums.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
// src/automationDefinition.ts
|
|
3
|
+
// ../db/src/automationDefinition.ts
|
|
4
4
|
/** Where a condition or template reads from: `event.payload.amount`, `subject.primaryEmail`, `steps.s2.output.id`. */
|
|
5
5
|
const ContextPath = z.string().trim().regex(/^(event|subject|steps|run)(\.[A-Za-z0-9_-]+)*$/, "a path like subject.primaryEmail");
|
|
6
6
|
const ConditionOperator = z.enum(CONDITION_OPERATORS);
|
package/dist/db/src/enums.js
CHANGED
|
@@ -19,8 +19,6 @@ const CUSTOMER_SEXES = [
|
|
|
19
19
|
2,
|
|
20
20
|
9
|
|
21
21
|
];
|
|
22
|
-
/** The fields no two customers share. A 409 `CUSTOMER_EXISTS` names the one that was taken. */
|
|
23
|
-
const CUSTOMER_UNIQUE_FIELDS = ["primaryEmail", "primaryPhone"];
|
|
24
22
|
/** `open`: still being worked; `qualified`: ready to become a customer; `disqualified`: not a fit (lost). */
|
|
25
23
|
const LEAD_STAGE_KINDS = [
|
|
26
24
|
"open",
|
|
@@ -333,4 +331,4 @@ const INVOICE_STATUSES = [
|
|
|
333
331
|
];
|
|
334
332
|
const REFUND_STATUSES = ["succeeded", "failed"];
|
|
335
333
|
const REFUND_METHODS = ["gateway", "manual"];
|
|
336
|
-
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,
|
|
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 };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../automationDefinition.js";
|
|
@@ -10,8 +10,8 @@ const timestamptz = () => timestamp({
|
|
|
10
10
|
mode: "date"
|
|
11
11
|
});
|
|
12
12
|
/**
|
|
13
|
-
* An automation: a trigger (event type + conditions) and steps,
|
|
14
|
-
* the contract
|
|
13
|
+
* An automation: a trigger (event type + conditions) and steps, in the shape of
|
|
14
|
+
* `AutomationDefinition` (`../automationDefinition`), which the contract checks on the way in. `definition` is the working copy;
|
|
15
15
|
* activating publishes it as a numbered version runs start from.
|
|
16
16
|
*/
|
|
17
17
|
const automations = pgTable("automations", {
|
|
@@ -25,7 +25,7 @@ const automations = pgTable("automations", {
|
|
|
25
25
|
triggerEvent: text().notNull(),
|
|
26
26
|
/** Scheduled and date triggers: when the next tick is due. */
|
|
27
27
|
nextRunAt: timestamptz(),
|
|
28
|
-
/** Working state: round-robin positions, runs skipped by the hourly limit. */
|
|
28
|
+
/** Working state: round-robin positions per step, runs skipped by the hourly limit. */
|
|
29
29
|
state: jsonb().$type().default({}).notNull(),
|
|
30
30
|
activeVersion: integer(),
|
|
31
31
|
/** The member it acts as: its actions need their permissions, checked at run time. */
|
|
@@ -6,8 +6,9 @@ import { organizations } from "./organizations.js";
|
|
|
6
6
|
import { tags } from "./tags.js";
|
|
7
7
|
import { roles, users } from "./users.js";
|
|
8
8
|
import { activities, auditLogs, files, notifications } from "./platform.js";
|
|
9
|
+
import { noteVersions, notes } from "./notes.js";
|
|
9
10
|
import { events } from "./events.js";
|
|
10
|
-
import { plugins } from "./plugins.js";
|
|
11
|
+
import { pluginInstallations, plugins } from "./plugins.js";
|
|
11
12
|
import { webhookDeliveries, webhooks } from "./webhooks.js";
|
|
12
13
|
import { automationRunSteps, automationRuns, automations } from "./automations.js";
|
|
13
14
|
import "./authTokens.js";
|
|
@@ -24,4 +25,4 @@ import { leadEvents } from "./leads.js";
|
|
|
24
25
|
import { productCategories, products } from "./products.js";
|
|
25
26
|
import { customerLogins, customerSessions } from "./customerAuth.js";
|
|
26
27
|
import "./rateLimits.js";
|
|
27
|
-
export { activities, auditLogs, auditStreams, automationRunSteps, automationRuns, automations, companies, createdAt, customerCompanies, customerLogins, customerSessions, customers, events, exports, fieldGroups, fields, files, importRows, imports, leadEvents, leadStages, notifications, organizations, paymentGateways, paymentInvoices, paymentPluginSettings, paymentRefunds, plugins, productCategories, products, roles, tags, trash, updatedAt, users, views, webhookDeliveries, webhooks };
|
|
28
|
+
export { activities, auditLogs, auditStreams, automationRunSteps, automationRuns, automations, companies, createdAt, customerCompanies, customerLogins, customerSessions, customers, events, exports, fieldGroups, fields, files, importRows, imports, leadEvents, leadStages, noteVersions, notes, notifications, organizations, paymentGateways, paymentInvoices, paymentPluginSettings, paymentRefunds, pluginInstallations, plugins, productCategories, products, roles, tags, trash, updatedAt, users, views, webhookDeliveries, webhooks };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LEAD_EVENTS } from "../enums.js";
|
|
1
|
+
import { ACTOR_TYPES, LEAD_EVENTS } from "../enums.js";
|
|
2
2
|
import { inList, orgIdColumn, pgTable } from "../table.js";
|
|
3
3
|
import { companies } from "./companies.js";
|
|
4
4
|
import { customers } from "./customers.js";
|
|
@@ -23,7 +23,7 @@ const leadEvents = pgTable("lead_events", {
|
|
|
23
23
|
toStageId: text(),
|
|
24
24
|
/** Why it was disqualified, or a note on the move. */
|
|
25
25
|
reason: text(),
|
|
26
|
-
actorType: text().notNull(),
|
|
26
|
+
actorType: text({ enum: ACTOR_TYPES }).notNull(),
|
|
27
27
|
actorId: text(),
|
|
28
28
|
createdAt: timestamp({
|
|
29
29
|
withTimezone: true,
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { orgIdColumn, pgTable } from "../table.js";
|
|
2
|
+
import { createdAt } from "./common.js";
|
|
3
|
+
import { organizations } from "./organizations.js";
|
|
4
|
+
import { activities } from "./platform.js";
|
|
5
|
+
import { users } from "./users.js";
|
|
6
|
+
import { foreignKey, index, primaryKey, text, timestamp } from "drizzle-orm/pg-core";
|
|
7
|
+
import { sql } from "drizzle-orm";
|
|
8
|
+
// ../db/src/schema/notes.ts
|
|
9
|
+
const timestamptz = () => timestamp({
|
|
10
|
+
withTimezone: true,
|
|
11
|
+
mode: "date"
|
|
12
|
+
});
|
|
13
|
+
/**
|
|
14
|
+
* A member's note on a timeline. The note is its timeline entry's own row
|
|
15
|
+
* (same id, `<target>.note`): the entry says where it is and who wrote it
|
|
16
|
+
* (`target_*`, `actor_id`), this row holds what only a note has. Deleting the
|
|
17
|
+
* entry deletes the note.
|
|
18
|
+
*/
|
|
19
|
+
const notes = pgTable("notes", {
|
|
20
|
+
id: text().primaryKey(),
|
|
21
|
+
orgId: orgIdColumn(),
|
|
22
|
+
body: text().notNull(),
|
|
23
|
+
/** Members mentioned with @: they are notified. */
|
|
24
|
+
mentions: text().array().notNull().default(sql`'{}'::text[]`),
|
|
25
|
+
/** Attached files (uploaded through `/files`). */
|
|
26
|
+
fileIds: text().array().notNull().default(sql`'{}'::text[]`),
|
|
27
|
+
/** Pinned to the top of the timeline. */
|
|
28
|
+
pinnedAt: timestamptz(),
|
|
29
|
+
/** Last reworded. */
|
|
30
|
+
editedAt: timestamptz()
|
|
31
|
+
}, (table) => [foreignKey({
|
|
32
|
+
columns: [table.id],
|
|
33
|
+
foreignColumns: [activities.id],
|
|
34
|
+
name: "core_notes_id_fkey"
|
|
35
|
+
}).onDelete("cascade"), foreignKey({
|
|
36
|
+
columns: [table.orgId],
|
|
37
|
+
foreignColumns: [organizations.id],
|
|
38
|
+
name: "core_notes_org_id_fkey"
|
|
39
|
+
}).onDelete("cascade")]);
|
|
40
|
+
/** Earlier wordings of a note: each edit keeps the text it replaced. */
|
|
41
|
+
const noteVersions = pgTable("note_versions", {
|
|
42
|
+
id: text().primaryKey(),
|
|
43
|
+
orgId: orgIdColumn(),
|
|
44
|
+
noteId: text().notNull(),
|
|
45
|
+
body: text().notNull(),
|
|
46
|
+
/** When this wording was written. */
|
|
47
|
+
editedAt: timestamptz().notNull()
|
|
48
|
+
}, (table) => [
|
|
49
|
+
index("core_note_versions_note_idx").on(table.orgId, table.noteId, table.editedAt),
|
|
50
|
+
foreignKey({
|
|
51
|
+
columns: [table.noteId],
|
|
52
|
+
foreignColumns: [notes.id],
|
|
53
|
+
name: "core_note_versions_note_id_fkey"
|
|
54
|
+
}).onDelete("cascade"),
|
|
55
|
+
foreignKey({
|
|
56
|
+
columns: [table.orgId],
|
|
57
|
+
foreignColumns: [organizations.id],
|
|
58
|
+
name: "core_note_versions_org_id_fkey"
|
|
59
|
+
}).onDelete("cascade")
|
|
60
|
+
]);
|
|
61
|
+
pgTable("reactions", {
|
|
62
|
+
orgId: orgIdColumn(),
|
|
63
|
+
activityId: text().notNull(),
|
|
64
|
+
userId: text().notNull(),
|
|
65
|
+
emoji: text().notNull(),
|
|
66
|
+
createdAt: createdAt()
|
|
67
|
+
}, (table) => [
|
|
68
|
+
primaryKey({
|
|
69
|
+
columns: [
|
|
70
|
+
table.activityId,
|
|
71
|
+
table.emoji,
|
|
72
|
+
table.userId
|
|
73
|
+
],
|
|
74
|
+
name: "core_reactions_pkey"
|
|
75
|
+
}),
|
|
76
|
+
foreignKey({
|
|
77
|
+
columns: [table.activityId],
|
|
78
|
+
foreignColumns: [activities.id],
|
|
79
|
+
name: "core_reactions_activity_id_fkey"
|
|
80
|
+
}).onDelete("cascade"),
|
|
81
|
+
foreignKey({
|
|
82
|
+
columns: [table.userId],
|
|
83
|
+
foreignColumns: [users.id],
|
|
84
|
+
name: "core_reactions_user_id_fkey"
|
|
85
|
+
}).onDelete("cascade"),
|
|
86
|
+
foreignKey({
|
|
87
|
+
columns: [table.orgId],
|
|
88
|
+
foreignColumns: [organizations.id],
|
|
89
|
+
name: "core_reactions_org_id_fkey"
|
|
90
|
+
}).onDelete("cascade")
|
|
91
|
+
]);
|
|
92
|
+
export { noteVersions, notes };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { INVOICE_STATUSES, PAYMENT_GATEWAY_KINDS, PAYMENT_GATEWAY_STATUSES, REFUND_METHODS, REFUND_STATUSES } from "../enums.js";
|
|
1
|
+
import { ACTOR_TYPES, INVOICE_STATUSES, PAYMENT_GATEWAY_KINDS, PAYMENT_GATEWAY_STATUSES, REFUND_METHODS, REFUND_STATUSES } from "../enums.js";
|
|
2
2
|
import { inList, orgIdColumn, pgTable } from "../table.js";
|
|
3
3
|
import { createdAt, updatedAt } from "./common.js";
|
|
4
4
|
import { organizations } from "./organizations.js";
|
|
@@ -101,7 +101,7 @@ const paymentRefunds = pgTable("payment_refunds", {
|
|
|
101
101
|
gatewayRefundId: text(),
|
|
102
102
|
error: text(),
|
|
103
103
|
/** `user` or `plugin`, and who. */
|
|
104
|
-
requestedByType: text().notNull(),
|
|
104
|
+
requestedByType: text({ enum: ACTOR_TYPES }).notNull(),
|
|
105
105
|
requestedBy: text(),
|
|
106
106
|
/** Retry-safe: one refund per invoice and key. */
|
|
107
107
|
dedupeKey: text(),
|
|
@@ -112,14 +112,9 @@ const activities = pgTable("activities", {
|
|
|
112
112
|
actorType: text({ enum: ACTOR_TYPES }).notNull(),
|
|
113
113
|
actorId: text(),
|
|
114
114
|
dedupeKey: text(),
|
|
115
|
-
/** Notes: pinned to the top of the timeline. */
|
|
116
|
-
pinnedAt: timestamptz(),
|
|
117
|
-
/** Notes: last edited. */
|
|
118
|
-
editedAt: timestamptz(),
|
|
119
115
|
occurredAt: timestamptz().defaultNow().notNull(),
|
|
120
116
|
createdAt: createdAt()
|
|
121
117
|
}, (table) => [
|
|
122
|
-
index("core_activities_pinned_idx").on(table.orgId, table.targetType, table.targetId).where(sql`${table.pinnedAt} IS NOT NULL`),
|
|
123
118
|
index("core_activities_target_idx").on(table.orgId, table.targetType, table.targetId, table.occurredAt.desc(), table.id.desc()),
|
|
124
119
|
uniqueIndex("core_activities_dedupe_key").on(table.orgId, table.source, table.dedupeKey).where(sql`${table.dedupeKey} IS NOT NULL`),
|
|
125
120
|
foreignKey({
|
|
@@ -28,7 +28,12 @@ const plugins = pgTable("plugins", {
|
|
|
28
28
|
createdAt: createdAt(),
|
|
29
29
|
updatedAt: updatedAt()
|
|
30
30
|
});
|
|
31
|
-
|
|
31
|
+
/**
|
|
32
|
+
* A plugin installed in an organisation, with the core scopes its owner
|
|
33
|
+
* granted. Tokens are issued only for installed, active plugins, and every
|
|
34
|
+
* request re-checks, so uninstalling cuts a plugin off at once.
|
|
35
|
+
*/
|
|
36
|
+
const pluginInstallations = pgTable("plugin_installations", {
|
|
32
37
|
orgId: orgIdColumn(),
|
|
33
38
|
plugin: text().notNull(),
|
|
34
39
|
status: text({ enum: PLUGIN_STATUSES }).default("active").notNull(),
|
|
@@ -56,4 +61,4 @@ pgTable("plugin_installations", {
|
|
|
56
61
|
name: "core_plugin_installations_plugin_fkey"
|
|
57
62
|
}).onDelete("cascade")
|
|
58
63
|
]);
|
|
59
|
-
export { plugins };
|
|
64
|
+
export { pluginInstallations, plugins };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EXPORT_FORMATS, EXPORT_STATUSES, IMPORT_STATUSES, TRANSFER_RECORD_TYPES } from "../enums.js";
|
|
1
|
+
import { EXPORT_FORMATS, EXPORT_STATUSES, IMPORT_ROW_ACTIONS, IMPORT_STATUSES, TRANSFER_RECORD_TYPES } from "../enums.js";
|
|
2
2
|
import { inList, orgIdColumn, pgTable } from "../table.js";
|
|
3
3
|
import { createdAt, updatedAt } from "./common.js";
|
|
4
4
|
import { organizations } from "./organizations.js";
|
|
@@ -57,7 +57,7 @@ const importRows = pgTable("import_rows", {
|
|
|
57
57
|
rowNumber: integer().notNull(),
|
|
58
58
|
cells: jsonb().$type().notNull(),
|
|
59
59
|
/** From the check, then the run: `create`, `update`, `skip` or `error`. */
|
|
60
|
-
action: text(),
|
|
60
|
+
action: text({ enum: IMPORT_ROW_ACTIONS }),
|
|
61
61
|
error: text(),
|
|
62
62
|
recordId: text()
|
|
63
63
|
}, (table) => [
|