@erxes/core-contract 0.1.0-v2.7 → 0.1.0-v2.8

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/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { CONDITION_OPERATORS } from "./db/src/enums.js";
1
+ import { CONDITION_OPERATORS, PLUGIN_SCOPES } from "./db/src/enums.js";
2
2
  import { Activity, ActivityInput, ActivityTarget, CORE_ACTIVITY_TYPES, Note, NoteInput, NoteVersion, TimelineKind, TimelineTarget, activitiesContract } from "./activities.js";
3
3
  import { Automation, AutomationFieldPath, DryRunStep, automationsContract } from "./automations.js";
4
4
  import { AuditEntry, AuditStream, auditContract } from "./audit.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, PLUGIN_SCOPES, Plugin, PluginInstallation, PluginManifest, PluginName, PluginScope, TokenResponse, pluginsContract } from "./plugins.js";
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,7 +21,7 @@ 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";
@@ -31,6 +31,7 @@ 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";
34
35
  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
36
  // src/index.ts
36
37
  /** The whole core API. Core implements it; plugins call it with a typed client. */
@@ -64,4 +65,4 @@ const coreContract = {
64
65
  views: viewsContract,
65
66
  webhooks: webhooksContract
66
67
  };
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 };
68
+ 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_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, PluginViewType, 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_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/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;
@@ -137,6 +137,23 @@ export declare const PluginManifest: z.ZodObject<{
137
137
  maxDelay: z.ZodInt;
138
138
  }, z.core.$strip>>;
139
139
  }, z.core.$strip>>>;
140
+ fields: z.ZodOptional<z.ZodArray<z.ZodObject<{
141
+ code: z.ZodString;
142
+ contentType: z.ZodEnum<{
143
+ company: "company";
144
+ customer: "customer";
145
+ }>;
146
+ label: z.ZodString;
147
+ type: z.ZodEnum<{
148
+ date: "date";
149
+ multiselect: "multiselect";
150
+ number: "number";
151
+ select: "select";
152
+ text: "text";
153
+ }>;
154
+ options: z.ZodOptional<z.ZodArray<z.ZodString>>;
155
+ description: z.ZodOptional<z.ZodString>;
156
+ }, z.core.$strip>>>;
140
157
  events: z.ZodOptional<z.ZodArray<z.ZodObject<{
141
158
  type: z.ZodString;
142
159
  label: z.ZodString;
@@ -347,6 +364,7 @@ export declare const pluginsContract: {
347
364
  "emails:write": "emails:write";
348
365
  "events:read": "events:read";
349
366
  "events:write": "events:write";
367
+ "fields:write": "fields:write";
350
368
  "files:read": "files:read";
351
369
  "files:write": "files:write";
352
370
  "live:write": "live:write";
@@ -356,6 +374,7 @@ export declare const pluginsContract: {
356
374
  "products:read": "products:read";
357
375
  "products:write": "products:write";
358
376
  "users:read": "users:read";
377
+ "views:read": "views:read";
359
378
  }>>>;
360
379
  permissions: z.ZodOptional<z.ZodArray<z.ZodObject<{
361
380
  action: z.ZodString;
@@ -431,6 +450,23 @@ export declare const pluginsContract: {
431
450
  maxDelay: z.ZodInt;
432
451
  }, z.core.$strip>>;
433
452
  }, z.core.$strip>>>;
453
+ fields: z.ZodOptional<z.ZodArray<z.ZodObject<{
454
+ code: z.ZodString;
455
+ contentType: z.ZodEnum<{
456
+ company: "company";
457
+ customer: "customer";
458
+ }>;
459
+ label: z.ZodString;
460
+ type: z.ZodEnum<{
461
+ date: "date";
462
+ multiselect: "multiselect";
463
+ number: "number";
464
+ select: "select";
465
+ text: "text";
466
+ }>;
467
+ options: z.ZodOptional<z.ZodArray<z.ZodString>>;
468
+ description: z.ZodOptional<z.ZodString>;
469
+ }, z.core.$strip>>>;
434
470
  events: z.ZodOptional<z.ZodArray<z.ZodObject<{
435
471
  type: z.ZodString;
436
472
  label: z.ZodString;
@@ -1209,4 +1245,5 @@ export declare const pluginsContract: {
1209
1245
  }, z.core.$strip>;
1210
1246
  };
1211
1247
  }>, Record<never, never>>;
1212
- };
1248
+ };
1249
+ export { PLUGIN_SCOPES };
package/dist/plugins.js CHANGED
@@ -1,4 +1,4 @@
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";
@@ -7,6 +7,7 @@ import { Id, isoDate, listOf } from "./common.js";
7
7
  import { ActionField } 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";
12
13
  import { oc } from "@orpc/contract";
@@ -15,28 +16,6 @@ import { createSelectSchema } from "drizzle-zod";
15
16
  // src/plugins.ts
16
17
  /** A plugin's name: its namespace everywhere (`hr` → `hr.leave.requested`, `/hr/*`). */
17
18
  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
19
  const PluginScope = z.enum(PLUGIN_SCOPES);
41
20
  /** Live update topic: `leave-requests`, `leave:abc123`. */
42
21
  const LiveTopic = z.string().trim().regex(/^[a-z0-9][a-z0-9._:-]{0,99}$/, "lower case letters, digits and . _ : -");
@@ -138,6 +117,8 @@ const PluginManifest = z.object({
138
117
  subscriptions: z.array(EventPattern).max(100).optional(),
139
118
  /** Background work at its API (`PluginJobs`): core POSTs each job to `<api.url>/jobs/<name>`. */
140
119
  jobs: PluginJobs.optional(),
120
+ /** Fields it keeps on customers and companies (`PluginFields`): read-only custom fields to members. */
121
+ fields: PluginFields.optional(),
141
122
  /**
142
123
  * Events it publishes: triggers for automations. `subject`: what its events
143
124
  * are about (published with `subject`), so automations started by it can