@erxes/core-contract 0.1.0-v2.0 → 0.1.0-v2.1

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 (94) hide show
  1. package/dist/activities.d.ts +21 -14
  2. package/dist/activities.js +6 -10
  3. package/dist/audit.d.ts +13 -17
  4. package/dist/audit.js +9 -9
  5. package/dist/auth.d.ts +33 -35
  6. package/dist/auth.js +8 -7
  7. package/dist/automationDefinition.d.ts +4 -3
  8. package/dist/automationDefinition.js +9 -31
  9. package/dist/automationRuns.d.ts +6 -5
  10. package/dist/automationRuns.js +8 -22
  11. package/dist/automations.d.ts +35 -36
  12. package/dist/automations.js +15 -23
  13. package/dist/common.d.ts +29 -4
  14. package/dist/common.js +30 -10
  15. package/dist/companies.d.ts +34 -34
  16. package/dist/companies.js +6 -5
  17. package/dist/contract/routes.json.js +1794 -0
  18. package/dist/customerAuth.d.ts +222 -0
  19. package/dist/customerAuth.js +180 -0
  20. package/dist/customers.d.ts +51 -54
  21. package/dist/customers.js +7 -12
  22. package/dist/db/src/enums.d.ts +8 -0
  23. package/dist/db/src/enums.js +336 -0
  24. package/dist/db/src/schema/auditStreams.js +6 -14
  25. package/dist/db/src/schema/authTokens.js +4 -6
  26. package/dist/db/src/schema/automations.js +12 -28
  27. package/dist/db/src/schema/common.d.ts +2 -6
  28. package/dist/db/src/schema/common.js +1 -24
  29. package/dist/db/src/schema/companies.js +6 -5
  30. package/dist/db/src/schema/customerAuth.js +101 -0
  31. package/dist/db/src/schema/customers.js +6 -6
  32. package/dist/db/src/schema/events.js +12 -60
  33. package/dist/db/src/schema/fieldValues.js +2 -2
  34. package/dist/db/src/schema/fields.js +10 -28
  35. package/dist/db/src/schema/index.js +21 -20
  36. package/dist/db/src/schema/leadStages.js +5 -10
  37. package/dist/db/src/schema/leads.js +5 -10
  38. package/dist/db/src/schema/oauth.js +3 -3
  39. package/dist/db/src/schema/payments.js +12 -22
  40. package/dist/db/src/schema/platform.js +11 -26
  41. package/dist/db/src/schema/plugins.js +4 -4
  42. package/dist/db/src/schema/products.js +7 -8
  43. package/dist/db/src/schema/rateLimits.js +7 -0
  44. package/dist/db/src/schema/saas.js +3 -9
  45. package/dist/db/src/schema/tags.js +6 -5
  46. package/dist/db/src/schema/transfer.js +12 -32
  47. package/dist/db/src/schema/trash.js +6 -7
  48. package/dist/db/src/schema/users.js +6 -10
  49. package/dist/db/src/schema/views.js +5 -13
  50. package/dist/db/src/schema/webhooks.js +7 -14
  51. package/dist/db/src/table.js +16 -2
  52. package/dist/events.d.ts +19 -23
  53. package/dist/events.js +16 -18
  54. package/dist/fields.d.ts +22 -50
  55. package/dist/fields.js +6 -28
  56. package/dist/files.d.ts +10 -5
  57. package/dist/files.js +4 -3
  58. package/dist/index.d.ts +557 -321
  59. package/dist/index.js +17 -16
  60. package/dist/leads.d.ts +5 -3
  61. package/dist/leads.js +8 -7
  62. package/dist/notifications.d.ts +4 -48
  63. package/dist/notifications.js +7 -73
  64. package/dist/organizations.d.ts +3 -3
  65. package/dist/payments.d.ts +28 -58
  66. package/dist/payments.js +10 -34
  67. package/dist/platform.d.ts +1 -0
  68. package/dist/platform.js +2 -5
  69. package/dist/plugins.d.ts +10 -4
  70. package/dist/plugins.js +19 -9
  71. package/dist/products.d.ts +31 -36
  72. package/dist/products.js +8 -7
  73. package/dist/roles.d.ts +0 -3
  74. package/dist/roles.js +5 -5
  75. package/dist/routes.d.ts +8 -0
  76. package/dist/routes.js +13 -0
  77. package/dist/saas.d.ts +0 -6
  78. package/dist/saas.js +5 -27
  79. package/dist/tags.d.ts +4 -4
  80. package/dist/tags.js +3 -3
  81. package/dist/transfer.d.ts +62 -24
  82. package/dist/transfer.js +15 -36
  83. package/dist/trash.d.ts +23 -4
  84. package/dist/trash.js +5 -5
  85. package/dist/users.d.ts +27 -41
  86. package/dist/users.js +13 -26
  87. package/dist/values.d.ts +159 -0
  88. package/dist/values.js +144 -0
  89. package/dist/views.d.ts +8 -8
  90. package/dist/views.js +8 -21
  91. package/dist/webhooks.d.ts +26 -20
  92. package/dist/webhooks.js +18 -11
  93. package/package.json +4 -1
  94. package/dist/db/src/schema/jobs.js +0 -44
package/dist/index.js CHANGED
@@ -1,22 +1,23 @@
1
- import { CONDITION_OPERATORS } from "./db/src/schema/common.js";
1
+ import { CONDITION_OPERATORS } from "./db/src/enums.js";
2
2
  import { Activity, ActivityInput, ActivityTarget, CORE_ACTIVITY_TYPES, NoteInput, TimelineKind, TimelineTarget, activitiesContract } from "./activities.js";
3
- import { Automation, AutomationFieldPath, AutomationStatus, DryRunStep, automationsContract } from "./automations.js";
4
- import { AuditEntry, AuditStream, AuditStreamFormat, auditContract } from "./audit.js";
5
- import { NewPassword, Session, authContract } from "./auth.js";
3
+ import { Automation, AutomationFieldPath, DryRunStep, automationsContract } from "./automations.js";
4
+ import { AuditEntry, AuditStream, auditContract } from "./audit.js";
5
+ import { Session, authContract } from "./auth.js";
6
6
  import { Company, CompanyFields, PersonRef, companiesContract } from "./companies.js";
7
7
  import { CoreEvent, EventFailure, EventFailureStatus, EventInput, EventNotify, eventsContract } from "./events.js";
8
- import { CompanyRef, ContactLink, ContactLinkInput, Customer, CustomerFields, CustomerSex, CustomerState, customersContract } from "./customers.js";
9
- import { FIELD_TYPE_FAMILIES, Field, FieldGroup, FieldType, FieldUsage, FieldValidation, OPTION_FIELD_TYPES, fieldGroupsContract, fieldsContract } from "./fields.js";
8
+ import { CompanyRef, ContactLink, ContactLinkInput, Customer, CustomerFields, CustomerState, customersContract } from "./customers.js";
9
+ import { CustomerLogin, CustomerProfile, CustomerSession, CustomerTokens, customerAccountContract, customerAuthContract } from "./customerAuth.js";
10
+ import { Field, FieldGroup, FieldUsage, fieldGroupsContract, fieldsContract } from "./fields.js";
10
11
  import { FileInfo, FileSettings, UploadTarget, filesContract } from "./files.js";
11
- import { CORE_NOTIFICATION_GROUPS, CORE_NOTIFICATION_KINDS, Notification, NotificationDelivery, NotificationGroupSetting, NotificationInput, NotificationSettings, UNMUTABLE_NOTIFICATION_KINDS, notificationGroupOf, notificationsContract } from "./notifications.js";
12
+ import { CORE_NOTIFICATION_KINDS, Notification, NotificationGroupSetting, NotificationInput, NotificationSettings, notificationsContract } from "./notifications.js";
12
13
  import { Organization, OrganizationRegion, organizationsContract } from "./organizations.js";
13
- import { GatewayConfig, Invoice, InvoiceLine, InvoiceLineInput, InvoiceMetadata, InvoiceStatus, PAYMENT_GATEWAYS, PaymentGateway, PaymentGatewayKind, PluginPaymentSettings, Refund, gatewayTakes, paymentsContract } from "./payments.js";
14
+ import { GatewayConfig, Invoice, InvoiceLine, InvoiceLineInput, InvoiceMetadata, PaymentGateway, PluginPaymentSettings, Refund, paymentsContract } from "./payments.js";
14
15
  import { LiveTopic, PLUGIN_SCOPES, Plugin, PluginManifest, PluginName, PluginScope, TokenResponse, pluginsContract } from "./plugins.js";
15
- import { Product, ProductCategory, ProductKind, ProductStatus, productCategoriesContract, productsContract } from "./products.js";
16
- import { CORE_PERMISSIONS, OWNER_ONLY_PERMISSIONS, PermissionAction, PermissionInfo, Role, RoleKey, rolesContract } from "./roles.js";
16
+ import { Product, ProductCategory, ProductStatus, productCategoriesContract, productsContract } from "./products.js";
17
+ import { CORE_PERMISSIONS, OWNER_ONLY_PERMISSIONS, PermissionAction, PermissionInfo, Role, rolesContract } from "./roles.js";
17
18
  import { Tag, tagsContract } from "./tags.js";
18
19
  import { TrashItem, trashContract } from "./trash.js";
19
- import { DateOnly, USER_LINK_NAMES, User, UserLinkName, UserLinks, UserRole, UserStatus, usersContract } from "./users.js";
20
+ import { DateOnly, User, UserLinks, UserStatus, usersContract } from "./users.js";
20
21
  import { CORE_EVENT_TYPES, EventPattern, EventTypeInfo, Webhook, WebhookDelivery, webhooksContract } from "./webhooks.js";
21
22
  import { EntitlementStatus, OrganizationStatus, PluginAccess, PluginPlan, PluginTier, SaasWorkspace, SubscriptionInfo, saasContract } from "./saas.js";
22
23
  import { FilterField, RecordFilter, View, ViewRecordType, ViewSort, viewsContract } from "./views.js";
@@ -24,13 +25,11 @@ import { Export, ExportQuery, Import, ImportOptions, ImportRow, ImportStatus, Tr
24
25
  import { ContactState, LEAD_SOURCES, LIFECYCLE_COLUMNS, LIFECYCLE_INPUT_COLUMNS, LeadEvent, LeadRecordType, LeadReport, LeadSource, LeadStage, LeadStageKind, SourceDetails, leadsContract, lifecycleInput, lifecycleRow } from "./leads.js";
25
26
  import { ActionInput, Audience, AutomationDefinition, AutomationStep, AutomationTrigger, ConditionGroup, ConditionOperator, ConditionRule, ContextPath, Reentry, RelativeAmount } from "./automationDefinition.js";
26
27
  import { ActionField, ActionInfo, AutomationRun, RunStatus, RunStep } from "./automationRuns.js";
27
- import { ContentType, CursorQuery, CustomFields, CustomFieldsPatch, CustomValue, EmailAddress, ErrorBody, FieldContentType, Id, IdList, ImageAddress, PageInfo, PhoneNumber, QueryBoolean, cursorPageOf, isoDate } from "./common.js";
28
+ import { ContentType, CursorQuery, CustomFields, CustomFieldsPatch, CustomValue, DESCRIPTION_MAX, EmailAddress, ErrorBody, FieldContentType, Id, IdList, ImageAddress, InvalidInput, LIST_MAX, PageInfo, PhoneNumber, QueryBoolean, QueryFlag, cursorPageOf, isoDate, listOf } from "./common.js";
28
29
  import { COUNTRIES, Country, Currency, currencyDigits, currencyOfCountry } from "./money.js";
29
30
  import { ActorRef, AppLink, DedupeKey, EntityRef, EventType } from "./platform.js";
31
+ import { AuditStreamFormat, AutomationStatus, CORE_API_PREFIX, CORE_API_VERSION, CORE_NOTIFICATION_GROUPS, CustomerExists, 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";
30
32
  // src/index.ts
31
- const CORE_API_VERSION = "v1";
32
- /** Every path in the contract is under this prefix (`/core/v1/customers`, …). */
33
- const CORE_API_PREFIX = "/core/v1";
34
33
  /** The whole core API. Core implements it; plugins call it with a typed client. */
35
34
  const coreContract = {
36
35
  activities: activitiesContract,
@@ -39,6 +38,8 @@ const coreContract = {
39
38
  auth: authContract,
40
39
  companies: companiesContract,
41
40
  customers: customersContract,
41
+ customerAccount: customerAccountContract,
42
+ customerAuth: customerAuthContract,
42
43
  events: eventsContract,
43
44
  fieldGroups: fieldGroupsContract,
44
45
  fields: fieldsContract,
@@ -59,4 +60,4 @@ const coreContract = {
59
60
  views: viewsContract,
60
61
  webhooks: webhooksContract
61
62
  };
62
- export { ActionField, ActionInfo, ActionInput, Activity, ActivityInput, ActivityTarget, ActorRef, AppLink, Audience, AuditEntry, AuditStream, AuditStreamFormat, Automation, AutomationDefinition, AutomationFieldPath, AutomationRun, AutomationStatus, AutomationStep, AutomationTrigger, 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, CustomerSex, CustomerState, DateOnly, DedupeKey, DryRunStep, EmailAddress, EntitlementStatus, EntityRef, ErrorBody, 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, Invoice, InvoiceLine, InvoiceLineInput, InvoiceMetadata, InvoiceStatus, LEAD_SOURCES, LIFECYCLE_COLUMNS, LIFECYCLE_INPUT_COLUMNS, LeadEvent, LeadRecordType, LeadReport, LeadSource, LeadStage, LeadStageKind, LiveTopic, NewPassword, NoteInput, Notification, NotificationDelivery, NotificationGroupSetting, NotificationInput, NotificationSettings, OPTION_FIELD_TYPES, OWNER_ONLY_PERMISSIONS, Organization, OrganizationRegion, OrganizationStatus, PAYMENT_GATEWAYS, PLUGIN_SCOPES, PageInfo, PaymentGateway, PaymentGatewayKind, PermissionAction, PermissionInfo, PersonRef, PhoneNumber, Plugin, PluginAccess, PluginManifest, PluginName, PluginPaymentSettings, PluginPlan, PluginScope, PluginTier, Product, ProductCategory, ProductKind, ProductStatus, QueryBoolean, 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, UserRole, UserStatus, View, ViewRecordType, ViewSort, Webhook, WebhookDelivery, activitiesContract, auditContract, authContract, automationsContract, companiesContract, coreContract, currencyDigits, currencyOfCountry, cursorPageOf, customersContract, eventsContract, fieldGroupsContract, fieldsContract, filesContract, gatewayTakes, isoDate, leadsContract, lifecycleInput, lifecycleRow, notificationGroupOf, notificationsContract, organizationsContract, paymentsContract, pluginsContract, productCategoriesContract, productsContract, rolesContract, saasContract, tagsContract, transferContract, trashContract, usersContract, viewsContract, webhooksContract };
63
+ export { ActionField, ActionInfo, ActionInput, Activity, ActivityInput, ActivityTarget, ActorRef, AppLink, Audience, AuditEntry, AuditStream, AuditStreamFormat, Automation, AutomationDefinition, AutomationFieldPath, AutomationRun, AutomationStatus, AutomationStep, AutomationTrigger, 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, CustomerExists, CustomerFields, CustomerLogin, CustomerProfile, CustomerSession, CustomerSex, CustomerState, CustomerTokens, DESCRIPTION_MAX, DateOnly, DedupeKey, DryRunStep, EmailAddress, EntitlementStatus, EntityRef, ErrorBody, 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, LEAD_SOURCES, LIFECYCLE_COLUMNS, LIFECYCLE_INPUT_COLUMNS, LIST_MAX, LeadEvent, LeadRecordType, LeadReport, LeadSource, LeadStage, LeadStageKind, LiveMode, LiveTopic, NewPassword, NoteInput, Notification, NotificationDelivery, NotificationGroupSetting, NotificationInput, NotificationSettings, OPTION_FIELD_TYPES, OWNER_ONLY_PERMISSIONS, Organization, OrganizationRegion, OrganizationStatus, PAYMENT_GATEWAYS, PLUGIN_SCOPES, PageInfo, PaymentGateway, PaymentGatewayKind, PermissionAction, PermissionInfo, PersonRef, PhoneNumber, Plugin, PluginAccess, 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, 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 };
package/dist/leads.d.ts CHANGED
@@ -8,7 +8,9 @@ export declare const LeadStageKind: z.ZodEnum<{
8
8
  }>;
9
9
  export type LeadStageKind = z.infer<typeof LeadStageKind>;
10
10
  /** Where people come from. Plugins and integrations may send others. */
11
- export declare const LEAD_SOURCES: readonly ['manual', 'import', 'form', 'website', 'email', 'phone', 'chat', 'social', 'ads', 'referral', 'event', 'partner', 'plugin', 'api', 'other'];
11
+ export declare const LEAD_SOURCES: readonly ['manual', 'import', 'form', 'website', 'email', 'phone', 'chat', 'social', 'ads', 'referral', 'event', 'partner', 'plugin',
12
+ /** Signed up with a code on core's customer sign-in page. */
13
+ 'sign_in', 'api', 'other'];
12
14
  export declare const LeadSource: z.ZodString;
13
15
  /** Campaign, medium, referrer, page, form …: up to 20 short values. */
14
16
  export declare const SourceDetails: z.ZodRecord<z.ZodString, z.ZodString>;
@@ -96,7 +98,7 @@ export declare const LeadEvent: z.ZodObject<{
96
98
  reason: z.ZodNullable<z.ZodString>;
97
99
  actorType: z.ZodString;
98
100
  actorId: z.ZodNullable<z.ZodString>;
99
- createdAt: z.ZodISODateTime;
101
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
100
102
  recordType: z.ZodEnum<{
101
103
  company: "company";
102
104
  customer: "customer";
@@ -278,7 +280,7 @@ export declare const leadsContract: {
278
280
  reason: z.ZodNullable<z.ZodString>;
279
281
  actorType: z.ZodString;
280
282
  actorId: z.ZodNullable<z.ZodString>;
281
- createdAt: z.ZodISODateTime;
283
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
282
284
  recordType: z.ZodEnum<{
283
285
  company: "company";
284
286
  customer: "customer";
package/dist/leads.js CHANGED
@@ -1,8 +1,8 @@
1
- import { LEAD_STAGE_KINDS, leadStages } from "./db/src/schema/leadStages.js";
2
- import { CUSTOMER_STATES } from "./db/src/schema/customers.js";
1
+ import { CONTENT_TYPES, CUSTOMER_STATES, LEAD_STAGE_KINDS } from "./db/src/enums.js";
2
+ import { leadStages } from "./db/src/schema/leadStages.js";
3
3
  import { leadEvents } from "./db/src/schema/leads.js";
4
4
  import "./db/src/schema/index.js";
5
- import { Id, isoDate } from "./common.js";
5
+ import { Id, isoDate, listOf } from "./common.js";
6
6
  import { oc } from "@orpc/contract";
7
7
  import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
8
8
  import { z } from "zod";
@@ -24,6 +24,7 @@ const LEAD_SOURCES = [
24
24
  "event",
25
25
  "partner",
26
26
  "plugin",
27
+ "sign_in",
27
28
  "api",
28
29
  "other"
29
30
  ];
@@ -31,7 +32,7 @@ const LeadSource = z.string().trim().toLowerCase().regex(/^[a-z0-9][a-z0-9_.:-]{
31
32
  /** Campaign, medium, referrer, page, form …: up to 20 short values. */
32
33
  const SourceDetails = z.record(z.string().max(50), z.string().max(500)).refine((value) => Object.keys(value).length <= 20, "at most 20 details");
33
34
  /** Whom a lead action is about: people or companies (both go through the same stages). */
34
- const LeadRecordType = z.enum(["customer", "company"]);
35
+ const LeadRecordType = z.enum(CONTENT_TYPES);
35
36
  /** `lead`: not a customer yet. People and companies alike. */
36
37
  const ContactState = z.enum(CUSTOMER_STATES);
37
38
  /**
@@ -161,7 +162,7 @@ const leadsContract = {
161
162
  method: "GET",
162
163
  path: "/lead-stages",
163
164
  summary: "The lead stages, in order, with how many leads each holds"
164
- }).output(z.object({ data: z.array(LeadStage) })),
165
+ }).output(listOf(LeadStage)),
165
166
  createStage: oc.route({
166
167
  method: "POST",
167
168
  path: "/lead-stages",
@@ -207,11 +208,11 @@ const leadsContract = {
207
208
  history: oc.route({
208
209
  method: "GET",
209
210
  path: "/leads/{id}/history",
210
- summary: "A lead's journey: created, every stage, converted"
211
+ summary: "A lead's journey, its last 200 steps: created, every stage, converted"
211
212
  }).input(z.object({
212
213
  ...RecordTypeInput,
213
214
  id: Id
214
- })).output(z.object({ data: z.array(LeadEvent) })),
215
+ })).output(z.object({ data: z.array(LeadEvent).max(200) })),
215
216
  report: oc.route({
216
217
  method: "GET",
217
218
  path: "/leads/report",
@@ -11,13 +11,14 @@ export declare const Notification: z.ZodObject<{
11
11
  high: "high";
12
12
  normal: "normal";
13
13
  }>;
14
- createdAt: z.ZodISODateTime;
14
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
15
15
  entity: z.ZodNullable<z.ZodObject<{
16
16
  type: z.ZodString;
17
17
  id: z.ZodString;
18
18
  }, z.core.$strip>>;
19
19
  actor: z.ZodObject<{
20
20
  type: z.ZodEnum<{
21
+ customer: "customer";
21
22
  plugin: "plugin";
22
23
  system: "system";
23
24
  user: "user";
@@ -60,52 +61,6 @@ export type NotificationInput = z.infer<typeof NotificationInput>;
60
61
  */
61
62
  export declare const CORE_NOTIFICATION_KINDS: readonly ['core.customer.assigned', 'core.customer.updated', 'core.customer.merged', 'core.customer.deleted', 'core.customer.activity', 'core.company.assigned', 'core.company.updated', 'core.company.merged', 'core.company.deleted', 'core.company.activity', 'core.user.role_changed', 'core.user.password_set', 'core.note.mentioned', 'core.automation.message', 'core.automation.failed', 'core.security.mass_deletion', 'core.security.alert', 'core.import.done', 'core.export.ready', 'core.security.new_sign_in'];
62
63
  export type CoreNotificationKind = (typeof CORE_NOTIFICATION_KINDS)[number];
63
- /** Security notices a member can't mute. */
64
- export declare const UNMUTABLE_NOTIFICATION_KINDS: readonly string[];
65
- /** Where a group of notifications goes: the inbox and email, the inbox only, or nowhere. */
66
- export declare const NotificationDelivery: z.ZodEnum<{
67
- email: "email";
68
- inbox: "inbox";
69
- off: "off";
70
- }>;
71
- export type NotificationDelivery = z.infer<typeof NotificationDelivery>;
72
- /**
73
- * Core's notifications in groups a member chooses for at once (each plugin
74
- * is a group of its own). `security` is always on.
75
- */
76
- export declare const CORE_NOTIFICATION_GROUPS: readonly [{
77
- readonly key: 'assigned';
78
- readonly label: 'Assigned to me';
79
- readonly kinds: readonly ["core.customer.assigned", "core.company.assigned"];
80
- readonly default: 'email';
81
- }, {
82
- readonly key: 'records';
83
- readonly label: 'Changes to records I own';
84
- readonly kinds: readonly ["core.customer.updated", "core.customer.merged", "core.customer.deleted", "core.company.updated", "core.company.merged", "core.company.deleted", "core.customer.activity", "core.company.activity"];
85
- readonly default: 'inbox';
86
- }, {
87
- readonly key: 'mentions';
88
- readonly label: 'Mentions';
89
- readonly kinds: readonly ["core.note.mentioned"];
90
- readonly default: 'email';
91
- }, {
92
- readonly key: 'automations';
93
- readonly label: 'Automations';
94
- readonly kinds: readonly ["core.automation.message", "core.automation.failed"];
95
- readonly default: 'inbox';
96
- }, {
97
- readonly key: 'transfer';
98
- readonly label: 'Imports and exports';
99
- readonly kinds: readonly ["core.import.done", "core.export.ready"];
100
- readonly default: 'inbox';
101
- }, {
102
- readonly key: 'security';
103
- readonly label: 'Security';
104
- readonly kinds: readonly string[];
105
- readonly default: 'inbox';
106
- }];
107
- /** The group a notification belongs to: a core group, or the plugin that sent it. */
108
- export declare const notificationGroupOf: (source: string, kind: string) => string;
109
64
  export declare const NotificationGroupSetting: z.ZodObject<{
110
65
  key: z.ZodString;
111
66
  label: z.ZodString;
@@ -169,13 +124,14 @@ export declare const notificationsContract: {
169
124
  high: "high";
170
125
  normal: "normal";
171
126
  }>;
172
- createdAt: z.ZodISODateTime;
127
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
173
128
  entity: z.ZodNullable<z.ZodObject<{
174
129
  type: z.ZodString;
175
130
  id: z.ZodString;
176
131
  }, z.core.$strip>>;
177
132
  actor: z.ZodObject<{
178
133
  type: z.ZodEnum<{
134
+ customer: "customer";
179
135
  plugin: "plugin";
180
136
  system: "system";
181
137
  user: "user";
@@ -1,6 +1,8 @@
1
- import { NOTIFICATION_PRIORITIES, notifications } from "./db/src/schema/platform.js";
1
+ import { NOTIFICATION_PRIORITIES } from "./db/src/enums.js";
2
+ import { notifications } from "./db/src/schema/platform.js";
2
3
  import "./db/src/schema/index.js";
3
- import { CursorQuery, Id, cursorPageOf, isoDate } from "./common.js";
4
+ import { NotificationDelivery } from "./values.js";
5
+ import { CursorQuery, Id, QueryFlag, cursorPageOf, isoDate } from "./common.js";
4
6
  import { ActorRef, AppLink, DedupeKey, EntityRef, EventType } from "./platform.js";
5
7
  import { oc } from "@orpc/contract";
6
8
  import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
@@ -82,73 +84,6 @@ const CORE_NOTIFICATION_KINDS = [
82
84
  "core.export.ready",
83
85
  "core.security.new_sign_in"
84
86
  ];
85
- /** Security notices a member can't mute. */
86
- const UNMUTABLE_NOTIFICATION_KINDS = [
87
- "core.user.role_changed",
88
- "core.user.password_set",
89
- "core.security.mass_deletion",
90
- "core.security.alert",
91
- "core.security.new_sign_in"
92
- ];
93
- /** Where a group of notifications goes: the inbox and email, the inbox only, or nowhere. */
94
- const NotificationDelivery = z.enum([
95
- "email",
96
- "inbox",
97
- "off"
98
- ]);
99
- /**
100
- * Core's notifications in groups a member chooses for at once (each plugin
101
- * is a group of its own). `security` is always on.
102
- */
103
- const CORE_NOTIFICATION_GROUPS = [
104
- {
105
- key: "assigned",
106
- label: "Assigned to me",
107
- kinds: ["core.customer.assigned", "core.company.assigned"],
108
- default: "email"
109
- },
110
- {
111
- key: "records",
112
- label: "Changes to records I own",
113
- kinds: [
114
- "core.customer.updated",
115
- "core.customer.merged",
116
- "core.customer.deleted",
117
- "core.company.updated",
118
- "core.company.merged",
119
- "core.company.deleted",
120
- "core.customer.activity",
121
- "core.company.activity"
122
- ],
123
- default: "inbox"
124
- },
125
- {
126
- key: "mentions",
127
- label: "Mentions",
128
- kinds: ["core.note.mentioned"],
129
- default: "email"
130
- },
131
- {
132
- key: "automations",
133
- label: "Automations",
134
- kinds: ["core.automation.message", "core.automation.failed"],
135
- default: "inbox"
136
- },
137
- {
138
- key: "transfer",
139
- label: "Imports and exports",
140
- kinds: ["core.import.done", "core.export.ready"],
141
- default: "inbox"
142
- },
143
- {
144
- key: "security",
145
- label: "Security",
146
- kinds: UNMUTABLE_NOTIFICATION_KINDS,
147
- default: "inbox"
148
- }
149
- ];
150
- /** The group a notification belongs to: a core group, or the plugin that sent it. */
151
- const notificationGroupOf = (source, kind) => source === "core" ? CORE_NOTIFICATION_GROUPS.find((group) => group.kinds.includes(kind))?.key ?? "records" : source;
152
87
  const NotificationGroupSetting = z.object({
153
88
  key: z.string(),
154
89
  label: z.string(),
@@ -165,7 +100,6 @@ const NotificationSettings = z.object({
165
100
  /** Desktop notifications in this member's browsers (each browser also asks permission). */
166
101
  browser: z.boolean()
167
102
  });
168
- const boolQuery = z.enum(["true", "false"]).transform((value) => value === "true").optional();
169
103
  /** The signed-in member's inbox. Plugins create notifications with `create`. */
170
104
  const notificationsContract = {
171
105
  list: oc.route({
@@ -173,9 +107,9 @@ const notificationsContract = {
173
107
  path: "/notifications",
174
108
  summary: "My notifications, newest first"
175
109
  }).input(CursorQuery.extend({
176
- unread: boolQuery,
110
+ unread: QueryFlag.optional(),
177
111
  source: z.string().trim().max(40).optional(),
178
- priority: z.enum(["normal", "high"]).optional(),
112
+ priority: z.enum(NOTIFICATION_PRIORITIES).optional(),
179
113
  /** A kind, or a prefix ending in `.` or `*` (`core.customer.`). */
180
114
  kind: z.string().trim().max(100).optional()
181
115
  })).output(cursorPageOf(Notification)),
@@ -225,4 +159,4 @@ const notificationsContract = {
225
159
  skipped: z.int()
226
160
  }))
227
161
  };
228
- export { CORE_NOTIFICATION_GROUPS, CORE_NOTIFICATION_KINDS, Notification, NotificationDelivery, NotificationGroupSetting, NotificationInput, NotificationSettings, UNMUTABLE_NOTIFICATION_KINDS, notificationGroupOf, notificationsContract };
162
+ export { CORE_NOTIFICATION_KINDS, Notification, NotificationGroupSetting, NotificationInput, NotificationSettings, notificationsContract };
@@ -5,7 +5,7 @@ export declare const Organization: z.ZodObject<{
5
5
  name: z.ZodString;
6
6
  country: z.ZodNullable<z.ZodString>;
7
7
  currency: z.ZodString;
8
- createdAt: z.ZodISODateTime;
8
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
9
9
  }, {
10
10
  out: {};
11
11
  in: {};
@@ -26,7 +26,7 @@ export declare const organizationsContract: {
26
26
  name: z.ZodString;
27
27
  country: z.ZodNullable<z.ZodString>;
28
28
  currency: z.ZodString;
29
- createdAt: z.ZodISODateTime;
29
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
30
30
  }, {
31
31
  out: {};
32
32
  in: {};
@@ -44,7 +44,7 @@ export declare const organizationsContract: {
44
44
  name: z.ZodString;
45
45
  country: z.ZodNullable<z.ZodString>;
46
46
  currency: z.ZodString;
47
- createdAt: z.ZodISODateTime;
47
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
48
48
  }, {
49
49
  out: {};
50
50
  in: {};
@@ -1,26 +1,4 @@
1
1
  import { z } from "zod";
2
- /**
3
- * The gateways core can connect, and where each works: the currencies it
4
- * takes and the countries it serves (empty: any). QPay is Mongolian; global
5
- * ones (Stripe …) join here as drivers in `@erxes/payment-gateways`.
6
- */
7
- export declare const PAYMENT_GATEWAYS: {
8
- readonly qpay: {
9
- readonly currencies: ["MNT"];
10
- readonly countries: ["MN"];
11
- };
12
- readonly test: {
13
- readonly currencies: [];
14
- readonly countries: [];
15
- };
16
- };
17
- export declare const PaymentGatewayKind: z.ZodEnum<{
18
- qpay: "qpay";
19
- test: "test";
20
- }>;
21
- export type PaymentGatewayKind = z.infer<typeof PaymentGatewayKind>;
22
- /** Does this kind of gateway take this currency? */
23
- export declare const gatewayTakes: (kind: PaymentGatewayKind, currency: string) => boolean;
24
2
  /** What each gateway needs (secrets are write-only: never returned). */
25
3
  export declare const GatewayConfig: z.ZodDiscriminatedUnion<[z.ZodObject<{
26
4
  kind: z.ZodLiteral<"qpay">;
@@ -43,21 +21,13 @@ export declare const PaymentGateway: z.ZodObject<{
43
21
  active: "active";
44
22
  disabled: "disabled";
45
23
  }>;
46
- createdAt: z.ZodISODateTime;
24
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
47
25
  settings: z.ZodRecord<z.ZodString, z.ZodUnknown>;
48
26
  }, {
49
27
  out: {};
50
28
  in: {};
51
29
  }>;
52
30
  export type PaymentGateway = z.infer<typeof PaymentGateway>;
53
- export declare const InvoiceStatus: z.ZodEnum<{
54
- cancelled: "cancelled";
55
- expired: "expired";
56
- failed: "failed";
57
- paid: "paid";
58
- pending: "pending";
59
- refunded: "refunded";
60
- }>;
61
31
  /** The caller's own data on an invoice (order lines, room number): at most 8 KB of JSON, returned in events. */
62
32
  export declare const InvoiceMetadata: z.ZodRecord<z.ZodString, z.ZodUnknown>;
63
33
  /**
@@ -118,9 +88,9 @@ export declare const Invoice: z.ZodObject<{
118
88
  }, z.core.$strip>>;
119
89
  paidAmount: z.ZodNullable<z.ZodInt>;
120
90
  refundedAmount: z.ZodInt;
121
- expiresAt: z.ZodISODateTime;
122
- paidAt: z.ZodNullable<z.ZodISODateTime>;
123
- createdAt: z.ZodISODateTime;
91
+ expiresAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
92
+ paidAt: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
93
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
124
94
  gatewayKind: z.ZodEnum<{
125
95
  qpay: "qpay";
126
96
  test: "test";
@@ -156,7 +126,7 @@ export declare const Refund: z.ZodObject<{
156
126
  succeeded: "succeeded";
157
127
  }>;
158
128
  error: z.ZodNullable<z.ZodString>;
159
- createdAt: z.ZodISODateTime;
129
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
160
130
  requestedBy: z.ZodObject<{
161
131
  type: z.ZodString;
162
132
  id: z.ZodNullable<z.ZodString>;
@@ -195,7 +165,7 @@ export declare const paymentsContract: {
195
165
  active: "active";
196
166
  disabled: "disabled";
197
167
  }>;
198
- createdAt: z.ZodISODateTime;
168
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
199
169
  settings: z.ZodRecord<z.ZodString, z.ZodUnknown>;
200
170
  }, {
201
171
  out: {};
@@ -224,7 +194,7 @@ export declare const paymentsContract: {
224
194
  active: "active";
225
195
  disabled: "disabled";
226
196
  }>;
227
- createdAt: z.ZodISODateTime;
197
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
228
198
  settings: z.ZodRecord<z.ZodString, z.ZodUnknown>;
229
199
  }, {
230
200
  out: {};
@@ -257,7 +227,7 @@ export declare const paymentsContract: {
257
227
  active: "active";
258
228
  disabled: "disabled";
259
229
  }>;
260
- createdAt: z.ZodISODateTime;
230
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
261
231
  settings: z.ZodRecord<z.ZodString, z.ZodUnknown>;
262
232
  }, {
263
233
  out: {};
@@ -323,9 +293,9 @@ export declare const paymentsContract: {
323
293
  }, z.core.$strip>>;
324
294
  paidAmount: z.ZodNullable<z.ZodInt>;
325
295
  refundedAmount: z.ZodInt;
326
- expiresAt: z.ZodISODateTime;
327
- paidAt: z.ZodNullable<z.ZodISODateTime>;
328
- createdAt: z.ZodISODateTime;
296
+ expiresAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
297
+ paidAt: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
298
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
329
299
  gatewayKind: z.ZodEnum<{
330
300
  qpay: "qpay";
331
301
  test: "test";
@@ -384,9 +354,9 @@ export declare const paymentsContract: {
384
354
  }, z.core.$strip>>;
385
355
  paidAmount: z.ZodNullable<z.ZodInt>;
386
356
  refundedAmount: z.ZodInt;
387
- expiresAt: z.ZodISODateTime;
388
- paidAt: z.ZodNullable<z.ZodISODateTime>;
389
- createdAt: z.ZodISODateTime;
357
+ expiresAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
358
+ paidAt: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
359
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
390
360
  gatewayKind: z.ZodEnum<{
391
361
  qpay: "qpay";
392
362
  test: "test";
@@ -445,9 +415,9 @@ export declare const paymentsContract: {
445
415
  }, z.core.$strip>>;
446
416
  paidAmount: z.ZodNullable<z.ZodInt>;
447
417
  refundedAmount: z.ZodInt;
448
- expiresAt: z.ZodISODateTime;
449
- paidAt: z.ZodNullable<z.ZodISODateTime>;
450
- createdAt: z.ZodISODateTime;
418
+ expiresAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
419
+ paidAt: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
420
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
451
421
  gatewayKind: z.ZodEnum<{
452
422
  qpay: "qpay";
453
423
  test: "test";
@@ -489,7 +459,7 @@ export declare const paymentsContract: {
489
459
  succeeded: "succeeded";
490
460
  }>;
491
461
  error: z.ZodNullable<z.ZodString>;
492
- createdAt: z.ZodISODateTime;
462
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
493
463
  requestedBy: z.ZodObject<{
494
464
  type: z.ZodString;
495
465
  id: z.ZodNullable<z.ZodString>;
@@ -534,9 +504,9 @@ export declare const paymentsContract: {
534
504
  }, z.core.$strip>>;
535
505
  paidAmount: z.ZodNullable<z.ZodInt>;
536
506
  refundedAmount: z.ZodInt;
537
- expiresAt: z.ZodISODateTime;
538
- paidAt: z.ZodNullable<z.ZodISODateTime>;
539
- createdAt: z.ZodISODateTime;
507
+ expiresAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
508
+ paidAt: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
509
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
540
510
  gatewayKind: z.ZodEnum<{
541
511
  qpay: "qpay";
542
512
  test: "test";
@@ -575,7 +545,7 @@ export declare const paymentsContract: {
575
545
  succeeded: "succeeded";
576
546
  }>;
577
547
  error: z.ZodNullable<z.ZodString>;
578
- createdAt: z.ZodISODateTime;
548
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
579
549
  requestedBy: z.ZodObject<{
580
550
  type: z.ZodString;
581
551
  id: z.ZodNullable<z.ZodString>;
@@ -667,9 +637,9 @@ export declare const paymentsContract: {
667
637
  }, z.core.$strip>>;
668
638
  paidAmount: z.ZodNullable<z.ZodInt>;
669
639
  refundedAmount: z.ZodInt;
670
- expiresAt: z.ZodISODateTime;
671
- paidAt: z.ZodNullable<z.ZodISODateTime>;
672
- createdAt: z.ZodISODateTime;
640
+ expiresAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
641
+ paidAt: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
642
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
673
643
  gatewayKind: z.ZodEnum<{
674
644
  qpay: "qpay";
675
645
  test: "test";
@@ -737,9 +707,9 @@ export declare const paymentsContract: {
737
707
  }, z.core.$strip>>;
738
708
  paidAmount: z.ZodNullable<z.ZodInt>;
739
709
  refundedAmount: z.ZodInt;
740
- expiresAt: z.ZodISODateTime;
741
- paidAt: z.ZodNullable<z.ZodISODateTime>;
742
- createdAt: z.ZodISODateTime;
710
+ expiresAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
711
+ paidAt: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
712
+ createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
743
713
  gatewayKind: z.ZodEnum<{
744
714
  qpay: "qpay";
745
715
  test: "test";