@erxes/core-contract 0.1.0-v2.7 → 0.1.0-v2.9
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 +154 -14
- package/dist/activities.js +20 -8
- package/dist/automationRuns.d.ts +38 -1
- package/dist/automationRuns.js +34 -3
- package/dist/automations.d.ts +3 -0
- package/dist/client.d.ts +1069 -42
- package/dist/client.js +23 -1
- package/dist/companies.d.ts +70 -0
- package/dist/companies.js +3 -1
- package/dist/contract/routes.json.js +24 -0
- package/dist/customers.d.ts +77 -0
- package/dist/customers.js +3 -2
- package/dist/db/src/enums.d.ts +5 -0
- package/dist/db/src/enums.js +43 -4
- package/dist/db/src/schema/fields.js +16 -2
- package/dist/db/src/schema/views.js +5 -3
- package/dist/errors.d.ts +10 -0
- package/dist/errors.js +8 -0
- package/dist/events.js +1 -1
- package/dist/fields.d.ts +226 -0
- package/dist/fields.js +16 -9
- package/dist/index.d.ts +722 -46
- package/dist/index.js +8 -6
- package/dist/pluginFields.d.ts +158 -0
- package/dist/pluginFields.js +65 -0
- package/dist/pluginJobs.d.ts +1 -0
- package/dist/pluginJobs.js +5 -0
- package/dist/plugins.d.ts +53 -6
- package/dist/plugins.js +11 -31
- package/dist/timelines.d.ts +36 -0
- package/dist/timelines.js +38 -0
- package/dist/views.d.ts +149 -12
- package/dist/views.js +37 -11
- package/package.json +3 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CONDITION_OPERATORS } from "./db/src/enums.js";
|
|
2
|
-
import { Activity, ActivityInput,
|
|
1
|
+
import { CONDITION_OPERATORS, PLUGIN_SCOPES } from "./db/src/enums.js";
|
|
2
|
+
import { Activity, ActivityInput, CORE_ACTIVITY_TYPES, Note, NoteInput, NoteVersion, TimelineKind, activitiesContract } from "./activities.js";
|
|
3
3
|
import { Automation, AutomationFieldPath, DryRunStep, automationsContract } from "./automations.js";
|
|
4
4
|
import { AuditEntry, AuditStream, auditContract } from "./audit.js";
|
|
5
5
|
import { Session, authContract } from "./auth.js";
|
|
@@ -13,7 +13,7 @@ import { FileInfo, FileSettings, UploadTarget, filesContract } from "./files.js"
|
|
|
13
13
|
import { CORE_NOTIFICATION_KINDS, Notification, NotificationGroupSetting, NotificationInput, NotificationSettings, notificationsContract } from "./notifications.js";
|
|
14
14
|
import { Organization, OrganizationRegion, organizationsContract } from "./organizations.js";
|
|
15
15
|
import { GatewayConfig, Invoice, InvoiceLine, InvoiceLineInput, InvoiceMetadata, PaymentGateway, PluginPaymentSettings, Refund, paymentsContract } from "./payments.js";
|
|
16
|
-
import { LiveTopic,
|
|
16
|
+
import { LiveTopic, Plugin, PluginInstallation, PluginManifest, PluginName, PluginScope, TokenResponse, pluginsContract } from "./plugins.js";
|
|
17
17
|
import { Product, ProductCategory, ProductStatus, productCategoriesContract, productsContract } from "./products.js";
|
|
18
18
|
import { CORE_PERMISSIONS, ManifestPermissionSet, OWNER_ONLY_PERMISSIONS, PermissionAction, PermissionInfo, PermissionSet, Role, rolesContract } from "./roles.js";
|
|
19
19
|
import { Tag, tagsContract } from "./tags.js";
|
|
@@ -21,16 +21,18 @@ import { TrashItem, trashContract } from "./trash.js";
|
|
|
21
21
|
import { DateOnly, User, UserLinks, UserStatus, usersContract } from "./users.js";
|
|
22
22
|
import { CORE_EVENT_TYPES, EventPattern, EventTypeInfo, Webhook, WebhookDelivery, webhooksContract } from "./webhooks.js";
|
|
23
23
|
import { EntitlementStatus, OrganizationStatus, PluginAccess, PluginPlan, PluginTier, SaasWorkspace, SubscriptionInfo, saasContract } from "./saas.js";
|
|
24
|
-
import { FilterField, RecordFilter, View, ViewRecordType, ViewSort, viewsContract } from "./views.js";
|
|
24
|
+
import { FilterField, PluginViewType, RecordFilter, VIEW_MATCHES_MAX, View, ViewListType, ViewRecordType, ViewSort, viewsContract } from "./views.js";
|
|
25
25
|
import { Export, ExportQuery, Import, ImportOptions, ImportRow, ImportStatus, TransferColumn, TransferRecordType, transferContract } from "./transfer.js";
|
|
26
26
|
import { LEAD_SOURCES, LIFECYCLE_COLUMNS, LIFECYCLE_INPUT_COLUMNS, LeadEvent, LeadRecordType, LeadReport, LeadSource, LeadStage, LeadStageKind, SourceDetails, leadsContract, lifecycleInput, lifecycleRow } from "./leads.js";
|
|
27
27
|
import { ActionInput, Audience, AutomationDefinition, AutomationStep, AutomationTrigger, ConditionGroup, ConditionOperator, ConditionRule, ContextPath, Reentry, RelativeAmount } from "./db/src/automationDefinition.js";
|
|
28
|
-
import { ActionField, ActionInfo, AutomationRun, RunStatus, RunStep } from "./automationRuns.js";
|
|
28
|
+
import { ActionField, ActionFields, ActionInfo, AutomationRun, RunStatus, RunStep } from "./automationRuns.js";
|
|
29
29
|
import { ContentType, CursorQuery, CustomFields, CustomFieldsPatch, CustomValue, DESCRIPTION_MAX, EmailAddress, FieldContentType, Id, IdList, ImageAddress, InvalidInput, LIST_MAX, PageInfo, PhoneNumber, QueryBoolean, QueryFlag, cursorPageOf, isoDate, listOf } from "./common.js";
|
|
30
30
|
import { COMMON_ERRORS, ERRORS } from "./errors.js";
|
|
31
31
|
import { COUNTRIES, Country, Currency, currencyDigits, currencyOfCountry } from "./money.js";
|
|
32
32
|
import { ActorType, AppLink, DedupeKey, EntityType, EventType } from "./platform.js";
|
|
33
33
|
import { JobName, PluginJobDelivery, PluginJobs } from "./pluginJobs.js";
|
|
34
|
+
import { PLUGIN_FIELDS_MAX, PLUGIN_VALUES_MAX, PluginField, PluginFields, pluginFieldsContract } from "./pluginFields.js";
|
|
35
|
+
import { ActivityTarget, PluginTimeline, RecordAccessAnswer, RecordAccessCheck, TimelineTarget } from "./timelines.js";
|
|
34
36
|
import { AuditStreamFormat, AutomationStatus, CORE_API_PREFIX, CORE_API_VERSION, CORE_NOTIFICATION_GROUPS, ContactState, 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 } from "./values.js";
|
|
35
37
|
// src/index.ts
|
|
36
38
|
/** The whole core API. Core implements it; plugins call it with a typed client. */
|
|
@@ -64,4 +66,4 @@ const coreContract = {
|
|
|
64
66
|
views: viewsContract,
|
|
65
67
|
webhooks: webhooksContract
|
|
66
68
|
};
|
|
67
|
-
export { ActionField, ActionInfo, ActionInput, Activity, ActivityInput, ActivityTarget, ActorType, AppLink, Audience, AuditEntry, AuditStream, AuditStreamFormat, Automation, AutomationDefinition, AutomationFieldPath, AutomationRun, AutomationStatus, AutomationStep, AutomationTrigger, COMMON_ERRORS, CONDITION_OPERATORS, CORE_ACTIVITY_TYPES, CORE_API_PREFIX, CORE_API_VERSION, CORE_EVENT_TYPES, CORE_NOTIFICATION_GROUPS, CORE_NOTIFICATION_KINDS, CORE_PERMISSIONS, COUNTRIES, Company, CompanyFields, CompanyRef, ConditionGroup, ConditionOperator, ConditionRule, ContactLink, ContactLinkInput, ContactState, ContentType, ContextPath, CoreEvent, Country, Currency, CursorQuery, CustomFields, CustomFieldsPatch, CustomValue, Customer, CustomerFields, CustomerLogin, CustomerProfile, CustomerSession, CustomerSex, CustomerState, CustomerTokens, DESCRIPTION_MAX, DateOnly, DedupeKey, DryRunStep, ERRORS, EmailAddress, EmailMessage, EntitlementStatus, EntityType, EventFailure, EventFailureStatus, EventInput, EventNotify, EventPattern, EventType, EventTypeInfo, Export, ExportQuery, FIELD_TYPE_FAMILIES, Field, FieldContentType, FieldGroup, FieldType, FieldUsage, FieldValidation, FileInfo, FileSettings, FilterField, GatewayConfig, Id, IdList, ImageAddress, Import, ImportOptions, ImportRow, ImportStatus, InvalidInput, InviteRole, Invoice, InvoiceLine, InvoiceLineInput, InvoiceMetadata, InvoiceStatus, JobName, LEAD_SOURCES, LIFECYCLE_COLUMNS, LIFECYCLE_INPUT_COLUMNS, LIST_MAX, LeadEvent, LeadRecordType, LeadReport, LeadSource, LeadStage, LeadStageKind, LiveMode, LiveTopic, ManifestPermissionSet, NewPassword, Note, NoteInput, NoteVersion, Notification, NotificationDelivery, NotificationGroupSetting, NotificationInput, NotificationSettings, OPTION_FIELD_TYPES, OWNER_ONLY_PERMISSIONS, Organization, OrganizationRegion, OrganizationStatus, PAYMENT_GATEWAYS, PLUGIN_SCOPES, PageInfo, PaymentGateway, PaymentGatewayKind, PermissionAction, PermissionInfo, PermissionSet, PersonRef, PhoneNumber, Plugin, PluginAccess, PluginInstallation, PluginJobDelivery, PluginJobs, PluginManifest, PluginName, PluginPaymentSettings, PluginPlan, PluginScope, PluginTier, Product, ProductCategory, ProductKind, ProductStatus, QueryBoolean, QueryFlag, RecordFilter, Reentry, Refund, RelativeAmount, Role, RoleKey, RunStatus, RunStep, SaasWorkspace, Session, SourceDetails, SubscriptionInfo, Tag, TimelineKind, TimelineTarget, TokenResponse, TransferColumn, TransferRecordType, TrashItem, UNMUTABLE_NOTIFICATION_KINDS, USER_LINK_NAMES, UploadTarget, User, UserLinkName, UserLinks, UserStatus, View, ViewRecordType, ViewSort, Webhook, WebhookDelivery, activitiesContract, auditContract, authContract, automationsContract, companiesContract, coreContract, currencyDigits, currencyOfCountry, cursorPageOf, customerAccountContract, customerAuthContract, customersContract, emailsContract, eventsContract, fieldGroupsContract, fieldsContract, filesContract, gatewayTakes, isoDate, leadsContract, lifecycleInput, lifecycleRow, listOf, notificationGroupOf, notificationsContract, organizationsContract, paymentsContract, pluginsContract, productCategoriesContract, productsContract, rolesContract, saasContract, tagsContract, transferContract, trashContract, usersContract, viewsContract, webhooksContract };
|
|
69
|
+
export { ActionField, ActionFields, ActionInfo, ActionInput, Activity, ActivityInput, ActivityTarget, ActorType, AppLink, Audience, AuditEntry, AuditStream, AuditStreamFormat, Automation, AutomationDefinition, AutomationFieldPath, AutomationRun, AutomationStatus, AutomationStep, AutomationTrigger, COMMON_ERRORS, CONDITION_OPERATORS, CORE_ACTIVITY_TYPES, CORE_API_PREFIX, CORE_API_VERSION, CORE_EVENT_TYPES, CORE_NOTIFICATION_GROUPS, CORE_NOTIFICATION_KINDS, CORE_PERMISSIONS, COUNTRIES, Company, CompanyFields, CompanyRef, ConditionGroup, ConditionOperator, ConditionRule, ContactLink, ContactLinkInput, ContactState, ContentType, ContextPath, CoreEvent, Country, Currency, CursorQuery, CustomFields, CustomFieldsPatch, CustomValue, Customer, CustomerFields, CustomerLogin, CustomerProfile, CustomerSession, CustomerSex, CustomerState, CustomerTokens, DESCRIPTION_MAX, DateOnly, DedupeKey, DryRunStep, ERRORS, EmailAddress, EmailMessage, EntitlementStatus, EntityType, EventFailure, EventFailureStatus, EventInput, EventNotify, EventPattern, EventType, EventTypeInfo, Export, ExportQuery, FIELD_TYPE_FAMILIES, Field, FieldContentType, FieldGroup, FieldType, FieldUsage, FieldValidation, FileInfo, FileSettings, FilterField, GatewayConfig, Id, IdList, ImageAddress, Import, ImportOptions, ImportRow, ImportStatus, InvalidInput, InviteRole, Invoice, InvoiceLine, InvoiceLineInput, InvoiceMetadata, InvoiceStatus, JobName, LEAD_SOURCES, LIFECYCLE_COLUMNS, LIFECYCLE_INPUT_COLUMNS, LIST_MAX, LeadEvent, LeadRecordType, LeadReport, LeadSource, LeadStage, LeadStageKind, LiveMode, LiveTopic, ManifestPermissionSet, NewPassword, Note, NoteInput, NoteVersion, Notification, NotificationDelivery, NotificationGroupSetting, NotificationInput, NotificationSettings, OPTION_FIELD_TYPES, OWNER_ONLY_PERMISSIONS, Organization, OrganizationRegion, OrganizationStatus, PAYMENT_GATEWAYS, PLUGIN_FIELDS_MAX, PLUGIN_SCOPES, PLUGIN_VALUES_MAX, PageInfo, PaymentGateway, PaymentGatewayKind, PermissionAction, PermissionInfo, PermissionSet, PersonRef, PhoneNumber, Plugin, PluginAccess, PluginField, PluginFields, PluginInstallation, PluginJobDelivery, PluginJobs, PluginManifest, PluginName, PluginPaymentSettings, PluginPlan, PluginScope, PluginTier, PluginTimeline, PluginViewType, Product, ProductCategory, ProductKind, ProductStatus, QueryBoolean, QueryFlag, RecordAccessAnswer, RecordAccessCheck, RecordFilter, Reentry, Refund, RelativeAmount, Role, RoleKey, RunStatus, RunStep, SaasWorkspace, Session, SourceDetails, SubscriptionInfo, Tag, TimelineKind, TimelineTarget, TokenResponse, TransferColumn, TransferRecordType, TrashItem, UNMUTABLE_NOTIFICATION_KINDS, USER_LINK_NAMES, UploadTarget, User, UserLinkName, UserLinks, UserStatus, VIEW_MATCHES_MAX, View, ViewListType, ViewRecordType, ViewSort, Webhook, WebhookDelivery, activitiesContract, auditContract, authContract, automationsContract, companiesContract, coreContract, currencyDigits, currencyOfCountry, cursorPageOf, customerAccountContract, customerAuthContract, customersContract, emailsContract, eventsContract, fieldGroupsContract, fieldsContract, filesContract, gatewayTakes, isoDate, leadsContract, lifecycleInput, lifecycleRow, listOf, notificationGroupOf, notificationsContract, organizationsContract, paymentsContract, pluginFieldsContract, pluginsContract, productCategoriesContract, productsContract, rolesContract, saasContract, tagsContract, transferContract, trashContract, usersContract, viewsContract, webhooksContract };
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** The most fields one plugin declares on core records. */
|
|
3
|
+
export declare const PLUGIN_FIELDS_MAX = 20;
|
|
4
|
+
/** The most values one `fields.setPluginValues` call writes. */
|
|
5
|
+
export declare const PLUGIN_VALUES_MAX = 500;
|
|
6
|
+
/**
|
|
7
|
+
* A field a plugin keeps on customers or companies (a rollup: `total_spent`, `last_order_at`).
|
|
8
|
+
* Core stores it as a custom field members filter, sort and save views by, and shows read-only;
|
|
9
|
+
* the plugin writes its values with `fields.setPluginValues`. Select types need `options`.
|
|
10
|
+
*/
|
|
11
|
+
export declare const PluginField: z.ZodObject<{
|
|
12
|
+
code: z.ZodString;
|
|
13
|
+
contentType: z.ZodEnum<{
|
|
14
|
+
company: "company";
|
|
15
|
+
customer: "customer";
|
|
16
|
+
}>;
|
|
17
|
+
label: z.ZodString;
|
|
18
|
+
type: z.ZodEnum<{
|
|
19
|
+
date: "date";
|
|
20
|
+
multiselect: "multiselect";
|
|
21
|
+
number: "number";
|
|
22
|
+
select: "select";
|
|
23
|
+
text: "text";
|
|
24
|
+
}>;
|
|
25
|
+
options: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
26
|
+
description: z.ZodOptional<z.ZodString>;
|
|
27
|
+
}, z.core.$strip>;
|
|
28
|
+
/**
|
|
29
|
+
* The manifest's `fields`, each code and label once per record type, at most 20. Each
|
|
30
|
+
* organisation that has the plugin gets them as read-only custom fields, listed under the
|
|
31
|
+
* plugin's title; a field left out is archived (values kept) until it comes back, and a changed
|
|
32
|
+
* `type` clears its values. The plugin writes values with `fields.setPluginValues` (scope
|
|
33
|
+
* `fields:write`).
|
|
34
|
+
*/
|
|
35
|
+
export declare const PluginFields: z.ZodArray<z.ZodObject<{
|
|
36
|
+
code: z.ZodString;
|
|
37
|
+
contentType: z.ZodEnum<{
|
|
38
|
+
company: "company";
|
|
39
|
+
customer: "customer";
|
|
40
|
+
}>;
|
|
41
|
+
label: z.ZodString;
|
|
42
|
+
type: z.ZodEnum<{
|
|
43
|
+
date: "date";
|
|
44
|
+
multiselect: "multiselect";
|
|
45
|
+
number: "number";
|
|
46
|
+
select: "select";
|
|
47
|
+
text: "text";
|
|
48
|
+
}>;
|
|
49
|
+
options: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
50
|
+
description: z.ZodOptional<z.ZodString>;
|
|
51
|
+
}, z.core.$strip>>;
|
|
52
|
+
/** The procedures of `fieldsContract` for plugins that keep fields on core's records. */
|
|
53
|
+
export declare const pluginFieldsContract: {
|
|
54
|
+
setPluginValues: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
|
|
55
|
+
contentType: z.ZodEnum<{
|
|
56
|
+
company: "company";
|
|
57
|
+
customer: "customer";
|
|
58
|
+
}>;
|
|
59
|
+
values: z.ZodArray<z.ZodObject<{
|
|
60
|
+
recordId: z.ZodString;
|
|
61
|
+
code: z.ZodString;
|
|
62
|
+
value: z.ZodNullable<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodArray<z.ZodString>]>>;
|
|
63
|
+
}, z.core.$strip>>;
|
|
64
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
65
|
+
written: z.ZodInt;
|
|
66
|
+
skipped: z.ZodArray<z.ZodString>;
|
|
67
|
+
}, z.core.$strip>, import("@orpc/contract").MergedErrorMap<Record<never, never>, {
|
|
68
|
+
UNAUTHORIZED: {
|
|
69
|
+
status: number;
|
|
70
|
+
};
|
|
71
|
+
NOT_ALLOWED: {
|
|
72
|
+
status: number;
|
|
73
|
+
data: z.ZodOptional<z.ZodObject<{
|
|
74
|
+
permission: z.ZodString;
|
|
75
|
+
}, z.core.$strip>>;
|
|
76
|
+
};
|
|
77
|
+
PLUGIN_ONLY: {
|
|
78
|
+
status: number;
|
|
79
|
+
};
|
|
80
|
+
MEMBERS_ONLY: {
|
|
81
|
+
status: number;
|
|
82
|
+
};
|
|
83
|
+
ORG_REQUIRED: {
|
|
84
|
+
status: number;
|
|
85
|
+
};
|
|
86
|
+
SCOPE_REQUIRED: {
|
|
87
|
+
status: number;
|
|
88
|
+
};
|
|
89
|
+
SERVICE_TOKEN_REQUIRED: {
|
|
90
|
+
status: number;
|
|
91
|
+
};
|
|
92
|
+
ORGANIZATION_DISABLED: {
|
|
93
|
+
status: number;
|
|
94
|
+
data: z.ZodObject<{
|
|
95
|
+
manageUrl: z.ZodNullable<z.ZodString>;
|
|
96
|
+
}, z.core.$strip>;
|
|
97
|
+
};
|
|
98
|
+
NOT_IN_PLAN: {
|
|
99
|
+
status: number;
|
|
100
|
+
data: z.ZodOptional<z.ZodObject<{
|
|
101
|
+
manageUrl: z.ZodNullable<z.ZodString>;
|
|
102
|
+
}, z.core.$strip>>;
|
|
103
|
+
};
|
|
104
|
+
READ_ONLY: {
|
|
105
|
+
status: number;
|
|
106
|
+
};
|
|
107
|
+
TOO_MANY_REQUESTS: {
|
|
108
|
+
status: number;
|
|
109
|
+
};
|
|
110
|
+
INVALID_INPUT: {
|
|
111
|
+
status: number;
|
|
112
|
+
data: z.ZodObject<{
|
|
113
|
+
issues: z.ZodArray<z.ZodObject<{
|
|
114
|
+
path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodInt]>>;
|
|
115
|
+
message: z.ZodString;
|
|
116
|
+
}, z.core.$strip>>;
|
|
117
|
+
}, z.core.$strip>;
|
|
118
|
+
};
|
|
119
|
+
NOT_FOUND: {
|
|
120
|
+
status: number;
|
|
121
|
+
};
|
|
122
|
+
TAKEN: {
|
|
123
|
+
status: number;
|
|
124
|
+
data: z.ZodObject<{
|
|
125
|
+
field: z.ZodString;
|
|
126
|
+
id: z.ZodOptional<z.ZodString>;
|
|
127
|
+
values: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
128
|
+
}, z.core.$strip>;
|
|
129
|
+
};
|
|
130
|
+
INVALID_CURSOR: {
|
|
131
|
+
status: number;
|
|
132
|
+
};
|
|
133
|
+
INVALID_REFERENCE: {
|
|
134
|
+
status: number;
|
|
135
|
+
data: z.ZodObject<{
|
|
136
|
+
field: z.ZodString;
|
|
137
|
+
}, z.core.$strip>;
|
|
138
|
+
};
|
|
139
|
+
INVALID_FILTER: {
|
|
140
|
+
status: number;
|
|
141
|
+
};
|
|
142
|
+
FILTER_TOO_SLOW: {
|
|
143
|
+
status: number;
|
|
144
|
+
};
|
|
145
|
+
INVALID_FIELD: {
|
|
146
|
+
status: number;
|
|
147
|
+
data: z.ZodObject<{
|
|
148
|
+
fieldId: z.ZodString;
|
|
149
|
+
}, z.core.$strip>;
|
|
150
|
+
};
|
|
151
|
+
INVALID_FIELD_VALUE: {
|
|
152
|
+
status: number;
|
|
153
|
+
data: z.ZodObject<{
|
|
154
|
+
fieldId: z.ZodString;
|
|
155
|
+
}, z.core.$strip>;
|
|
156
|
+
};
|
|
157
|
+
}>, Record<never, never>>;
|
|
158
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { CONTENT_TYPES, PLUGIN_FIELD_TYPES } from "./db/src/enums.js";
|
|
2
|
+
import { Id } from "./common.js";
|
|
3
|
+
import { COMMON_ERRORS, ERRORS } from "./errors.js";
|
|
4
|
+
import { oc } from "@orpc/contract";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
// src/pluginFields.ts
|
|
7
|
+
/** The most fields one plugin declares on core records. */
|
|
8
|
+
const PLUGIN_FIELDS_MAX = 20;
|
|
9
|
+
/** The most values one `fields.setPluginValues` call writes. */
|
|
10
|
+
const PLUGIN_VALUES_MAX = 500;
|
|
11
|
+
/**
|
|
12
|
+
* A field a plugin keeps on customers or companies (a rollup: `total_spent`, `last_order_at`).
|
|
13
|
+
* Core stores it as a custom field members filter, sort and save views by, and shows read-only;
|
|
14
|
+
* the plugin writes its values with `fields.setPluginValues`. Select types need `options`.
|
|
15
|
+
*/
|
|
16
|
+
const PluginField = z.object({
|
|
17
|
+
code: z.string().regex(/^[a-z][a-z0-9_]{0,49}$/, "lower case letters, digits and _ (starting with a letter)"),
|
|
18
|
+
contentType: z.enum(CONTENT_TYPES),
|
|
19
|
+
label: z.string().trim().min(1).max(100),
|
|
20
|
+
type: z.enum(PLUGIN_FIELD_TYPES),
|
|
21
|
+
options: z.array(z.string().trim().min(1).max(200)).max(100).optional(),
|
|
22
|
+
description: z.string().trim().max(1e3).optional()
|
|
23
|
+
}).refine((field) => field.type !== "select" && field.type !== "multiselect" || !!field.options?.length, {
|
|
24
|
+
path: ["options"],
|
|
25
|
+
error: "select fields need options"
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* The manifest's `fields`, each code and label once per record type, at most 20. Each
|
|
29
|
+
* organisation that has the plugin gets them as read-only custom fields, listed under the
|
|
30
|
+
* plugin's title; a field left out is archived (values kept) until it comes back, and a changed
|
|
31
|
+
* `type` clears its values. The plugin writes values with `fields.setPluginValues` (scope
|
|
32
|
+
* `fields:write`).
|
|
33
|
+
*/
|
|
34
|
+
const PluginFields = z.array(PluginField).max(20).refine((list) => new Set(list.map((field) => `${field.contentType}:${field.code}`)).size === list.length && new Set(list.map((field) => `${field.contentType}:${field.label.toLowerCase()}`)).size === list.length, "each code and label once per record type");
|
|
35
|
+
/** A value of a plugin's field on one record: a number, a date (`YYYY-MM-DD`), text, option(s); null clears it. */
|
|
36
|
+
const PluginValue = z.object({
|
|
37
|
+
recordId: Id,
|
|
38
|
+
/** The field's `code` in the plugin's manifest. */
|
|
39
|
+
code: z.string().min(1).max(50),
|
|
40
|
+
value: z.union([
|
|
41
|
+
z.number(),
|
|
42
|
+
z.string().max(1e4),
|
|
43
|
+
z.array(z.string().max(200)).max(100)
|
|
44
|
+
]).nullable()
|
|
45
|
+
});
|
|
46
|
+
const { INVALID_FIELD, INVALID_FIELD_VALUE } = ERRORS;
|
|
47
|
+
/** The procedures of `fieldsContract` for plugins that keep fields on core's records. */
|
|
48
|
+
const pluginFieldsContract = { setPluginValues: oc.errors({
|
|
49
|
+
...COMMON_ERRORS,
|
|
50
|
+
INVALID_FIELD,
|
|
51
|
+
INVALID_FIELD_VALUE
|
|
52
|
+
}).route({
|
|
53
|
+
method: "POST",
|
|
54
|
+
path: "/fields/plugin-values",
|
|
55
|
+
summary: "Write values of the calling plugin's own fields (by manifest `code`), up to 500; null clears one. Quiet: no timeline entry, event, audit row or notification. Records not found are skipped. 400 INVALID_FIELD for a code the manifest doesn't declare, INVALID_FIELD_VALUE for a value that doesn't fit"
|
|
56
|
+
}).input(z.object({
|
|
57
|
+
contentType: z.enum(CONTENT_TYPES),
|
|
58
|
+
values: z.array(PluginValue).min(1).max(500)
|
|
59
|
+
})).output(z.object({
|
|
60
|
+
/** Values written or cleared. */
|
|
61
|
+
written: z.int(),
|
|
62
|
+
/** Ids of records that don't exist here (deleted, or never this organisation's). */
|
|
63
|
+
skipped: z.array(Id)
|
|
64
|
+
})) };
|
|
65
|
+
export { PLUGIN_FIELDS_MAX, PLUGIN_VALUES_MAX, PluginField, PluginFields, pluginFieldsContract };
|
package/dist/pluginJobs.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export declare const JobName: z.ZodString;
|
|
|
11
11
|
export declare const PluginJobs: z.ZodArray<z.ZodObject<{
|
|
12
12
|
name: z.ZodString;
|
|
13
13
|
cron: z.ZodOptional<z.ZodString>;
|
|
14
|
+
onInstall: z.ZodOptional<z.ZodBoolean>;
|
|
14
15
|
retry: z.ZodOptional<z.ZodObject<{
|
|
15
16
|
attempts: z.ZodInt;
|
|
16
17
|
delay: z.ZodInt;
|
package/dist/pluginJobs.js
CHANGED
|
@@ -7,6 +7,11 @@ const PluginJob = z.object({
|
|
|
7
7
|
/** A cron schedule in UTC (`0 3 * * *`): one job per organisation each time it comes due. */
|
|
8
8
|
cron: z.string().trim().min(1).max(100).optional(),
|
|
9
9
|
/**
|
|
10
|
+
* Also runs once for an organisation when it installs the plugin or approves the scopes a newer
|
|
11
|
+
* version asks for: a backfill of what the plugin could not do before.
|
|
12
|
+
*/
|
|
13
|
+
onInstall: z.boolean().optional(),
|
|
14
|
+
/**
|
|
10
15
|
* Attempts in all; the first retry waits `delay` seconds, each next one
|
|
11
16
|
* about twice as long, up to `maxDelay`. Default: 8 attempts, 30 s, 6 hours.
|
|
12
17
|
*/
|
package/dist/plugins.d.ts
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
+
import { PLUGIN_SCOPES } from "./db/src/enums.js";
|
|
1
2
|
import { z } from "zod";
|
|
2
3
|
/** A plugin's name: its namespace everywhere (`hr` → `hr.leave.requested`, `/hr/*`). */
|
|
3
4
|
export declare const PluginName: z.ZodString;
|
|
4
|
-
/**
|
|
5
|
-
* What a plugin may do in core, granted per organisation when it is
|
|
6
|
-
* installed. A plugin only ever gets the scopes it asked for in its manifest.
|
|
7
|
-
*/
|
|
8
|
-
export declare const PLUGIN_SCOPES: readonly ['activities:write', 'customers:read', 'customers:write', 'audit:write', 'emails:write', 'events:read', 'events:write', 'files:read', 'files:write', 'live:write', 'notifications:write', 'payments:read', 'payments:write', 'products:read', 'products:write', 'users:read'];
|
|
9
5
|
export declare const PluginScope: z.ZodEnum<{
|
|
10
6
|
"activities:write": "activities:write";
|
|
11
7
|
"audit:write": "audit:write";
|
|
@@ -14,6 +10,7 @@ export declare const PluginScope: z.ZodEnum<{
|
|
|
14
10
|
"emails:write": "emails:write";
|
|
15
11
|
"events:read": "events:read";
|
|
16
12
|
"events:write": "events:write";
|
|
13
|
+
"fields:write": "fields:write";
|
|
17
14
|
"files:read": "files:read";
|
|
18
15
|
"files:write": "files:write";
|
|
19
16
|
"live:write": "live:write";
|
|
@@ -23,6 +20,7 @@ export declare const PluginScope: z.ZodEnum<{
|
|
|
23
20
|
"products:read": "products:read";
|
|
24
21
|
"products:write": "products:write";
|
|
25
22
|
"users:read": "users:read";
|
|
23
|
+
"views:read": "views:read";
|
|
26
24
|
}>;
|
|
27
25
|
export type PluginScope = z.infer<typeof PluginScope>;
|
|
28
26
|
/** Live update topic: `leave-requests`, `leave:abc123`. */
|
|
@@ -53,6 +51,7 @@ export declare const PluginManifest: z.ZodObject<{
|
|
|
53
51
|
"emails:write": "emails:write";
|
|
54
52
|
"events:read": "events:read";
|
|
55
53
|
"events:write": "events:write";
|
|
54
|
+
"fields:write": "fields:write";
|
|
56
55
|
"files:read": "files:read";
|
|
57
56
|
"files:write": "files:write";
|
|
58
57
|
"live:write": "live:write";
|
|
@@ -62,6 +61,7 @@ export declare const PluginManifest: z.ZodObject<{
|
|
|
62
61
|
"products:read": "products:read";
|
|
63
62
|
"products:write": "products:write";
|
|
64
63
|
"users:read": "users:read";
|
|
64
|
+
"views:read": "views:read";
|
|
65
65
|
}>>>;
|
|
66
66
|
permissions: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
67
67
|
action: z.ZodString;
|
|
@@ -101,6 +101,7 @@ export declare const PluginManifest: z.ZodObject<{
|
|
|
101
101
|
longtext: "longtext";
|
|
102
102
|
members: "members";
|
|
103
103
|
number: "number";
|
|
104
|
+
plugin_record: "plugin_record";
|
|
104
105
|
recipients: "recipients";
|
|
105
106
|
select: "select";
|
|
106
107
|
tags: "tags";
|
|
@@ -114,12 +115,15 @@ export declare const PluginManifest: z.ZodObject<{
|
|
|
114
115
|
description: z.ZodOptional<z.ZodString>;
|
|
115
116
|
placeholder: z.ZodOptional<z.ZodString>;
|
|
116
117
|
sameTypeAs: z.ZodOptional<z.ZodString>;
|
|
118
|
+
recordType: z.ZodOptional<z.ZodString>;
|
|
119
|
+
dependsOn: z.ZodOptional<z.ZodString>;
|
|
117
120
|
}, z.core.$strip>>>;
|
|
118
121
|
}, z.core.$strip>>>;
|
|
119
122
|
timelines: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
120
123
|
type: z.ZodString;
|
|
121
124
|
label: z.ZodString;
|
|
122
125
|
permission: z.ZodOptional<z.ZodString>;
|
|
126
|
+
recordAccess: z.ZodOptional<z.ZodBoolean>;
|
|
123
127
|
}, z.core.$strip>>>;
|
|
124
128
|
activityTypes: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
125
129
|
type: z.ZodString;
|
|
@@ -131,12 +135,30 @@ export declare const PluginManifest: z.ZodObject<{
|
|
|
131
135
|
jobs: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
132
136
|
name: z.ZodString;
|
|
133
137
|
cron: z.ZodOptional<z.ZodString>;
|
|
138
|
+
onInstall: z.ZodOptional<z.ZodBoolean>;
|
|
134
139
|
retry: z.ZodOptional<z.ZodObject<{
|
|
135
140
|
attempts: z.ZodInt;
|
|
136
141
|
delay: z.ZodInt;
|
|
137
142
|
maxDelay: z.ZodInt;
|
|
138
143
|
}, z.core.$strip>>;
|
|
139
144
|
}, z.core.$strip>>>;
|
|
145
|
+
fields: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
146
|
+
code: z.ZodString;
|
|
147
|
+
contentType: z.ZodEnum<{
|
|
148
|
+
company: "company";
|
|
149
|
+
customer: "customer";
|
|
150
|
+
}>;
|
|
151
|
+
label: z.ZodString;
|
|
152
|
+
type: z.ZodEnum<{
|
|
153
|
+
date: "date";
|
|
154
|
+
multiselect: "multiselect";
|
|
155
|
+
number: "number";
|
|
156
|
+
select: "select";
|
|
157
|
+
text: "text";
|
|
158
|
+
}>;
|
|
159
|
+
options: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
160
|
+
description: z.ZodOptional<z.ZodString>;
|
|
161
|
+
}, z.core.$strip>>>;
|
|
140
162
|
events: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
141
163
|
type: z.ZodString;
|
|
142
164
|
label: z.ZodString;
|
|
@@ -347,6 +369,7 @@ export declare const pluginsContract: {
|
|
|
347
369
|
"emails:write": "emails:write";
|
|
348
370
|
"events:read": "events:read";
|
|
349
371
|
"events:write": "events:write";
|
|
372
|
+
"fields:write": "fields:write";
|
|
350
373
|
"files:read": "files:read";
|
|
351
374
|
"files:write": "files:write";
|
|
352
375
|
"live:write": "live:write";
|
|
@@ -356,6 +379,7 @@ export declare const pluginsContract: {
|
|
|
356
379
|
"products:read": "products:read";
|
|
357
380
|
"products:write": "products:write";
|
|
358
381
|
"users:read": "users:read";
|
|
382
|
+
"views:read": "views:read";
|
|
359
383
|
}>>>;
|
|
360
384
|
permissions: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
361
385
|
action: z.ZodString;
|
|
@@ -395,6 +419,7 @@ export declare const pluginsContract: {
|
|
|
395
419
|
longtext: "longtext";
|
|
396
420
|
members: "members";
|
|
397
421
|
number: "number";
|
|
422
|
+
plugin_record: "plugin_record";
|
|
398
423
|
recipients: "recipients";
|
|
399
424
|
select: "select";
|
|
400
425
|
tags: "tags";
|
|
@@ -408,12 +433,15 @@ export declare const pluginsContract: {
|
|
|
408
433
|
description: z.ZodOptional<z.ZodString>;
|
|
409
434
|
placeholder: z.ZodOptional<z.ZodString>;
|
|
410
435
|
sameTypeAs: z.ZodOptional<z.ZodString>;
|
|
436
|
+
recordType: z.ZodOptional<z.ZodString>;
|
|
437
|
+
dependsOn: z.ZodOptional<z.ZodString>;
|
|
411
438
|
}, z.core.$strip>>>;
|
|
412
439
|
}, z.core.$strip>>>;
|
|
413
440
|
timelines: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
414
441
|
type: z.ZodString;
|
|
415
442
|
label: z.ZodString;
|
|
416
443
|
permission: z.ZodOptional<z.ZodString>;
|
|
444
|
+
recordAccess: z.ZodOptional<z.ZodBoolean>;
|
|
417
445
|
}, z.core.$strip>>>;
|
|
418
446
|
activityTypes: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
419
447
|
type: z.ZodString;
|
|
@@ -425,12 +453,30 @@ export declare const pluginsContract: {
|
|
|
425
453
|
jobs: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
426
454
|
name: z.ZodString;
|
|
427
455
|
cron: z.ZodOptional<z.ZodString>;
|
|
456
|
+
onInstall: z.ZodOptional<z.ZodBoolean>;
|
|
428
457
|
retry: z.ZodOptional<z.ZodObject<{
|
|
429
458
|
attempts: z.ZodInt;
|
|
430
459
|
delay: z.ZodInt;
|
|
431
460
|
maxDelay: z.ZodInt;
|
|
432
461
|
}, z.core.$strip>>;
|
|
433
462
|
}, z.core.$strip>>>;
|
|
463
|
+
fields: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
464
|
+
code: z.ZodString;
|
|
465
|
+
contentType: z.ZodEnum<{
|
|
466
|
+
company: "company";
|
|
467
|
+
customer: "customer";
|
|
468
|
+
}>;
|
|
469
|
+
label: z.ZodString;
|
|
470
|
+
type: z.ZodEnum<{
|
|
471
|
+
date: "date";
|
|
472
|
+
multiselect: "multiselect";
|
|
473
|
+
number: "number";
|
|
474
|
+
select: "select";
|
|
475
|
+
text: "text";
|
|
476
|
+
}>;
|
|
477
|
+
options: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
478
|
+
description: z.ZodOptional<z.ZodString>;
|
|
479
|
+
}, z.core.$strip>>>;
|
|
434
480
|
events: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
435
481
|
type: z.ZodString;
|
|
436
482
|
label: z.ZodString;
|
|
@@ -1209,4 +1255,5 @@ export declare const pluginsContract: {
|
|
|
1209
1255
|
}, z.core.$strip>;
|
|
1210
1256
|
};
|
|
1211
1257
|
}>, Record<never, never>>;
|
|
1212
|
-
};
|
|
1258
|
+
};
|
|
1259
|
+
export { PLUGIN_SCOPES };
|
package/dist/plugins.js
CHANGED
|
@@ -1,42 +1,22 @@
|
|
|
1
|
-
import { AUTOMATION_SUBJECTS, CONTENT_TYPES } from "./db/src/enums.js";
|
|
1
|
+
import { AUTOMATION_SUBJECTS, CONTENT_TYPES, PLUGIN_SCOPES } from "./db/src/enums.js";
|
|
2
2
|
import { pluginInstallations, plugins } from "./db/src/schema/plugins.js";
|
|
3
3
|
import "./db/src/schema/index.js";
|
|
4
4
|
import { COMMON_ERRORS, ERRORS } from "./errors.js";
|
|
5
5
|
import { EventPattern } from "./webhooks.js";
|
|
6
6
|
import { Id, isoDate, listOf } from "./common.js";
|
|
7
|
-
import {
|
|
7
|
+
import { ActionFields } from "./automationRuns.js";
|
|
8
8
|
import { Country } from "./money.js";
|
|
9
9
|
import { EventType } from "./platform.js";
|
|
10
|
+
import { PluginFields } from "./pluginFields.js";
|
|
10
11
|
import { PluginJobs } from "./pluginJobs.js";
|
|
11
12
|
import { ManifestPermissionSet } from "./roles.js";
|
|
13
|
+
import { PluginTimeline } from "./timelines.js";
|
|
12
14
|
import { oc } from "@orpc/contract";
|
|
13
15
|
import { z } from "zod";
|
|
14
16
|
import { createSelectSchema } from "drizzle-zod";
|
|
15
17
|
// src/plugins.ts
|
|
16
18
|
/** A plugin's name: its namespace everywhere (`hr` → `hr.leave.requested`, `/hr/*`). */
|
|
17
19
|
const PluginName = z.string().trim().regex(/^[a-z][a-z0-9_]{0,39}$/, "lower case letters, digits and _ (starting with a letter)").refine((name) => name !== "core", "reserved");
|
|
18
|
-
/**
|
|
19
|
-
* What a plugin may do in core, granted per organisation when it is
|
|
20
|
-
* installed. A plugin only ever gets the scopes it asked for in its manifest.
|
|
21
|
-
*/
|
|
22
|
-
const PLUGIN_SCOPES = [
|
|
23
|
-
"activities:write",
|
|
24
|
-
"customers:read",
|
|
25
|
-
"customers:write",
|
|
26
|
-
"audit:write",
|
|
27
|
-
"emails:write",
|
|
28
|
-
"events:read",
|
|
29
|
-
"events:write",
|
|
30
|
-
"files:read",
|
|
31
|
-
"files:write",
|
|
32
|
-
"live:write",
|
|
33
|
-
"notifications:write",
|
|
34
|
-
"payments:read",
|
|
35
|
-
"payments:write",
|
|
36
|
-
"products:read",
|
|
37
|
-
"products:write",
|
|
38
|
-
"users:read"
|
|
39
|
-
];
|
|
40
20
|
const PluginScope = z.enum(PLUGIN_SCOPES);
|
|
41
21
|
/** Live update topic: `leave-requests`, `leave:abc123`. */
|
|
42
22
|
const LiveTopic = z.string().trim().regex(/^[a-z0-9][a-z0-9._:-]{0,99}$/, "lower case letters, digits and . _ : -");
|
|
@@ -100,21 +80,19 @@ const PluginManifest = z.object({
|
|
|
100
80
|
* Actions automations can run (`hr.leave.create`): core POSTs
|
|
101
81
|
* `{ input, context }` to `<api.url>/automations/actions/<type>` with a
|
|
102
82
|
* core token and an `Idempotency-Key`; the JSON answer is the step's output.
|
|
83
|
+
* A `plugin_record` field's choices come from
|
|
84
|
+
* `GET <api.url>/automations/records/<recordType>?parent=<its dependsOn value>`,
|
|
85
|
+
* called with the member's session token, answering `[{ value, label }]`.
|
|
103
86
|
*/
|
|
104
87
|
actions: z.array(z.object({
|
|
105
88
|
type: EventType,
|
|
106
89
|
label: z.string().trim().min(1).max(100),
|
|
107
90
|
description: z.string().trim().max(300).optional(),
|
|
108
91
|
subject: z.enum(AUTOMATION_SUBJECTS).optional(),
|
|
109
|
-
fields:
|
|
92
|
+
fields: ActionFields.default([])
|
|
110
93
|
})).max(200).optional(),
|
|
111
94
|
/** Its own record types that get a timeline in erxes (notes, mentions, entries), and who may see it. */
|
|
112
|
-
timelines: z.array(
|
|
113
|
-
type: z.string().regex(/^[a-z][a-z0-9_]*\.[a-z][a-z0-9_]*$/),
|
|
114
|
-
label: z.string().trim().min(1).max(100),
|
|
115
|
-
/** A permission action of the plugin (`hr.employee.view`); none: every member. */
|
|
116
|
-
permission: z.string().optional()
|
|
117
|
-
})).max(50).optional(),
|
|
95
|
+
timelines: z.array(PluginTimeline).max(50).optional(),
|
|
118
96
|
/**
|
|
119
97
|
* How its timeline entries look: a label, a colour and an icon per type —
|
|
120
98
|
* one of IconBeach, IconBriefcase, IconCalendarEvent, IconCash,
|
|
@@ -138,6 +116,8 @@ const PluginManifest = z.object({
|
|
|
138
116
|
subscriptions: z.array(EventPattern).max(100).optional(),
|
|
139
117
|
/** Background work at its API (`PluginJobs`): core POSTs each job to `<api.url>/jobs/<name>`. */
|
|
140
118
|
jobs: PluginJobs.optional(),
|
|
119
|
+
/** Fields it keeps on customers and companies (`PluginFields`): read-only custom fields to members. */
|
|
120
|
+
fields: PluginFields.optional(),
|
|
141
121
|
/**
|
|
142
122
|
* Events it publishes: triggers for automations. `subject`: what its events
|
|
143
123
|
* are about (published with `subject`), so automations started by it can
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const ActivityTarget: z.ZodEnum<{
|
|
3
|
+
company: "company";
|
|
4
|
+
customer: "customer";
|
|
5
|
+
}>;
|
|
6
|
+
export type ActivityTarget = z.infer<typeof ActivityTarget>;
|
|
7
|
+
/**
|
|
8
|
+
* What a timeline is about: a customer or company, or a plugin's own record
|
|
9
|
+
* type declared in its manifest (`hr.employee`, `ecom.order`).
|
|
10
|
+
*/
|
|
11
|
+
export declare const TimelineTarget: z.ZodUnion<readonly [z.ZodEnum<{
|
|
12
|
+
company: "company";
|
|
13
|
+
customer: "customer";
|
|
14
|
+
}>, z.ZodString]>;
|
|
15
|
+
export type TimelineTarget = z.infer<typeof TimelineTarget>;
|
|
16
|
+
/** One of a manifest's `timelines`: a record type of the plugin's, and who may see its timeline. */
|
|
17
|
+
export declare const PluginTimeline: z.ZodObject<{
|
|
18
|
+
type: z.ZodString;
|
|
19
|
+
label: z.ZodString;
|
|
20
|
+
permission: z.ZodOptional<z.ZodString>;
|
|
21
|
+
recordAccess: z.ZodOptional<z.ZodBoolean>;
|
|
22
|
+
}, z.core.$strip>;
|
|
23
|
+
/**
|
|
24
|
+
* What core POSTs to `<api.url>/timelines/access` for a timeline with `recordAccess`: may this
|
|
25
|
+
* member read this record? The plugin answers `RecordAccessAnswer`.
|
|
26
|
+
*/
|
|
27
|
+
export declare const RecordAccessCheck: z.ZodObject<{
|
|
28
|
+
orgId: z.ZodString;
|
|
29
|
+
userId: z.ZodString;
|
|
30
|
+
type: z.ZodString;
|
|
31
|
+
id: z.ZodString;
|
|
32
|
+
}, z.core.$strip>;
|
|
33
|
+
export type RecordAccessCheck = z.infer<typeof RecordAccessCheck>;
|
|
34
|
+
export declare const RecordAccessAnswer: z.ZodObject<{
|
|
35
|
+
allowed: z.ZodBoolean;
|
|
36
|
+
}, z.core.$strip>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ACTIVITY_TARGETS } from "./db/src/enums.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
// src/timelines.ts
|
|
4
|
+
const ActivityTarget = z.enum(ACTIVITY_TARGETS);
|
|
5
|
+
/** A plugin's own record type with a timeline: `<plugin>.<type>`. */
|
|
6
|
+
const PLUGIN_TIMELINE_TYPE = /^[a-z][a-z0-9_]*\.[a-z][a-z0-9_]*$/;
|
|
7
|
+
/**
|
|
8
|
+
* What a timeline is about: a customer or company, or a plugin's own record
|
|
9
|
+
* type declared in its manifest (`hr.employee`, `ecom.order`).
|
|
10
|
+
*/
|
|
11
|
+
const TimelineTarget = z.union([ActivityTarget, z.string().regex(PLUGIN_TIMELINE_TYPE, "customer, company or <plugin>.<type>")]);
|
|
12
|
+
/** One of a manifest's `timelines`: a record type of the plugin's, and who may see its timeline. */
|
|
13
|
+
const PluginTimeline = z.object({
|
|
14
|
+
type: z.string().regex(PLUGIN_TIMELINE_TYPE),
|
|
15
|
+
label: z.string().trim().min(1).max(100),
|
|
16
|
+
/** A permission action of the plugin (`hr.employee.view`); none: every member. */
|
|
17
|
+
permission: z.string().optional(),
|
|
18
|
+
/**
|
|
19
|
+
* Some members may not read some records (a ticket only its channel's members read):
|
|
20
|
+
* before a member reads or notes on one's timeline, core POSTs a `RecordAccessCheck` to
|
|
21
|
+
* `<api.url>/timelines/access` and refuses unless the plugin answers `{ "allowed": true }`
|
|
22
|
+
* within 5 seconds.
|
|
23
|
+
*/
|
|
24
|
+
recordAccess: z.boolean().optional()
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* What core POSTs to `<api.url>/timelines/access` for a timeline with `recordAccess`: may this
|
|
28
|
+
* member read this record? The plugin answers `RecordAccessAnswer`.
|
|
29
|
+
*/
|
|
30
|
+
const RecordAccessCheck = z.object({
|
|
31
|
+
orgId: z.string(),
|
|
32
|
+
userId: z.string(),
|
|
33
|
+
/** The timeline type, `frontline.ticket`. */
|
|
34
|
+
type: z.string(),
|
|
35
|
+
id: z.string()
|
|
36
|
+
});
|
|
37
|
+
const RecordAccessAnswer = z.object({ allowed: z.boolean() });
|
|
38
|
+
export { ActivityTarget, PluginTimeline, RecordAccessAnswer, RecordAccessCheck, TimelineTarget };
|