@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/views.d.ts CHANGED
@@ -10,6 +10,17 @@ export declare const ViewRecordType: z.ZodEnum<{
10
10
  product: "product";
11
11
  }>;
12
12
  export type ViewRecordType = z.infer<typeof ViewRecordType>;
13
+ /** A plugin's list: its record type, `<plugin>:<record>` (`sales:deal`). Its API applies the filter. */
14
+ export declare const PluginViewType: z.ZodTemplateLiteral<`${string}:${string}`>;
15
+ /** Any list views can belong to: one of core's, or a plugin's. */
16
+ export declare const ViewListType: z.ZodUnion<readonly [z.ZodEnum<{
17
+ company: "company";
18
+ company_lead: "company_lead";
19
+ customer: "customer";
20
+ lead: "lead";
21
+ product: "product";
22
+ }>, z.ZodTemplateLiteral<`${string}:${string}`>]>;
23
+ export type ViewListType = z.infer<typeof ViewListType>;
13
24
  /**
14
25
  * A filter on a list: the condition language automations use, on the
15
26
  * record's fields (`subject.state`, `subject.customFields.<id>`,
@@ -37,7 +48,9 @@ export declare const FilterField: z.ZodObject<{
37
48
  custom: "custom";
38
49
  fields: "fields";
39
50
  lead: "lead";
51
+ plugin: "plugin";
40
52
  }>;
53
+ groupLabel: z.ZodOptional<z.ZodString>;
41
54
  }, z.core.$strip>;
42
55
  export type FilterField = z.infer<typeof FilterField>;
43
56
  export declare const ViewSort: z.ZodObject<{
@@ -49,13 +62,13 @@ export declare const ViewSort: z.ZodObject<{
49
62
  }, z.core.$strip>;
50
63
  export declare const View: z.ZodObject<{
51
64
  id: z.ZodString;
52
- recordType: z.ZodEnum<{
65
+ recordType: z.ZodUnion<readonly [z.ZodEnum<{
53
66
  company: "company";
54
67
  company_lead: "company_lead";
55
68
  customer: "customer";
56
69
  lead: "lead";
57
70
  product: "product";
58
- }>;
71
+ }>, z.ZodTemplateLiteral<`${string}:${string}`>]>;
59
72
  name: z.ZodString;
60
73
  filter: z.ZodNullable<z.ZodType<ConditionGroup, unknown, z.core.$ZodTypeInternals<ConditionGroup, unknown>>>;
61
74
  search: z.ZodNullable<z.ZodString>;
@@ -77,26 +90,28 @@ export declare const View: z.ZodObject<{
77
90
  in: {};
78
91
  }>;
79
92
  export type View = z.infer<typeof View>;
93
+ /** The most record ids one `views.matches` call checks. */
94
+ export declare const VIEW_MATCHES_MAX = 500;
80
95
  /** Saved lists (views) and what lists can be filtered by. */
81
96
  export declare const viewsContract: {
82
97
  list: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
83
- recordType: z.ZodEnum<{
98
+ recordType: z.ZodUnion<readonly [z.ZodEnum<{
84
99
  company: "company";
85
100
  company_lead: "company_lead";
86
101
  customer: "customer";
87
102
  lead: "lead";
88
103
  product: "product";
89
- }>;
104
+ }>, z.ZodTemplateLiteral<`${string}:${string}`>]>;
90
105
  }, z.core.$strip>, z.ZodObject<{
91
106
  data: z.ZodArray<z.ZodObject<{
92
107
  id: z.ZodString;
93
- recordType: z.ZodEnum<{
108
+ recordType: z.ZodUnion<readonly [z.ZodEnum<{
94
109
  company: "company";
95
110
  company_lead: "company_lead";
96
111
  customer: "customer";
97
112
  lead: "lead";
98
113
  product: "product";
99
- }>;
114
+ }>, z.ZodTemplateLiteral<`${string}:${string}`>]>;
100
115
  name: z.ZodString;
101
116
  filter: z.ZodNullable<z.ZodType<ConditionGroup, unknown, z.core.$ZodTypeInternals<ConditionGroup, unknown>>>;
102
117
  search: z.ZodNullable<z.ZodString>;
@@ -195,6 +210,12 @@ export declare const viewsContract: {
195
210
  FILTER_TOO_SLOW: {
196
211
  status: number;
197
212
  };
213
+ INVALID_TYPE: {
214
+ status: number;
215
+ };
216
+ VIEW_NOT_SHARED: {
217
+ status: number;
218
+ };
198
219
  }>, Record<never, never>>;
199
220
  create: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
200
221
  name: z.ZodNonOptional<z.ZodOptional<z.ZodString>>;
@@ -209,25 +230,25 @@ export declare const viewsContract: {
209
230
  }>;
210
231
  }, z.core.$strip>>>;
211
232
  shared: z.ZodOptional<z.ZodBoolean>;
212
- recordType: z.ZodEnum<{
233
+ recordType: z.ZodUnion<readonly [z.ZodEnum<{
213
234
  company: "company";
214
235
  company_lead: "company_lead";
215
236
  customer: "customer";
216
237
  lead: "lead";
217
238
  product: "product";
218
- }>;
239
+ }>, z.ZodTemplateLiteral<`${string}:${string}`>]>;
219
240
  }, {
220
241
  out: {};
221
242
  in: {};
222
243
  }>, z.ZodObject<{
223
244
  id: z.ZodString;
224
- recordType: z.ZodEnum<{
245
+ recordType: z.ZodUnion<readonly [z.ZodEnum<{
225
246
  company: "company";
226
247
  company_lead: "company_lead";
227
248
  customer: "customer";
228
249
  lead: "lead";
229
250
  product: "product";
230
- }>;
251
+ }>, z.ZodTemplateLiteral<`${string}:${string}`>]>;
231
252
  name: z.ZodString;
232
253
  filter: z.ZodNullable<z.ZodType<ConditionGroup, unknown, z.core.$ZodTypeInternals<ConditionGroup, unknown>>>;
233
254
  search: z.ZodNullable<z.ZodString>;
@@ -325,6 +346,12 @@ export declare const viewsContract: {
325
346
  FILTER_TOO_SLOW: {
326
347
  status: number;
327
348
  };
349
+ INVALID_TYPE: {
350
+ status: number;
351
+ };
352
+ VIEW_NOT_SHARED: {
353
+ status: number;
354
+ };
328
355
  }>, Record<never, never>>;
329
356
  update: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
330
357
  name: z.ZodOptional<z.ZodString>;
@@ -345,13 +372,13 @@ export declare const viewsContract: {
345
372
  in: {};
346
373
  }>, z.ZodObject<{
347
374
  id: z.ZodString;
348
- recordType: z.ZodEnum<{
375
+ recordType: z.ZodUnion<readonly [z.ZodEnum<{
349
376
  company: "company";
350
377
  company_lead: "company_lead";
351
378
  customer: "customer";
352
379
  lead: "lead";
353
380
  product: "product";
354
- }>;
381
+ }>, z.ZodTemplateLiteral<`${string}:${string}`>]>;
355
382
  name: z.ZodString;
356
383
  filter: z.ZodNullable<z.ZodType<ConditionGroup, unknown, z.core.$ZodTypeInternals<ConditionGroup, unknown>>>;
357
384
  search: z.ZodNullable<z.ZodString>;
@@ -449,6 +476,12 @@ export declare const viewsContract: {
449
476
  FILTER_TOO_SLOW: {
450
477
  status: number;
451
478
  };
479
+ INVALID_TYPE: {
480
+ status: number;
481
+ };
482
+ VIEW_NOT_SHARED: {
483
+ status: number;
484
+ };
452
485
  }>, Record<never, never>>;
453
486
  remove: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
454
487
  id: z.ZodString;
@@ -532,6 +565,12 @@ export declare const viewsContract: {
532
565
  FILTER_TOO_SLOW: {
533
566
  status: number;
534
567
  };
568
+ INVALID_TYPE: {
569
+ status: number;
570
+ };
571
+ VIEW_NOT_SHARED: {
572
+ status: number;
573
+ };
535
574
  }>, Record<never, never>>;
536
575
  fields: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
537
576
  recordType: z.ZodEnum<{
@@ -561,7 +600,9 @@ export declare const viewsContract: {
561
600
  custom: "custom";
562
601
  fields: "fields";
563
602
  lead: "lead";
603
+ plugin: "plugin";
564
604
  }>;
605
+ groupLabel: z.ZodOptional<z.ZodString>;
565
606
  }, z.core.$strip>>;
566
607
  }, z.core.$strip>, import("@orpc/contract").MergedErrorMap<Record<never, never>, {
567
608
  UNAUTHORIZED: {
@@ -641,5 +682,101 @@ export declare const viewsContract: {
641
682
  FILTER_TOO_SLOW: {
642
683
  status: number;
643
684
  };
685
+ INVALID_TYPE: {
686
+ status: number;
687
+ };
688
+ VIEW_NOT_SHARED: {
689
+ status: number;
690
+ };
691
+ }>, Record<never, never>>;
692
+ matches: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
693
+ viewId: z.ZodString;
694
+ recordIds: z.ZodArray<z.ZodString>;
695
+ }, z.core.$strip>, z.ZodObject<{
696
+ recordIds: z.ZodArray<z.ZodString>;
697
+ }, z.core.$strip>, import("@orpc/contract").MergedErrorMap<Record<never, never>, {
698
+ UNAUTHORIZED: {
699
+ status: number;
700
+ };
701
+ NOT_ALLOWED: {
702
+ status: number;
703
+ data: z.ZodOptional<z.ZodObject<{
704
+ permission: z.ZodString;
705
+ }, z.core.$strip>>;
706
+ };
707
+ PLUGIN_ONLY: {
708
+ status: number;
709
+ };
710
+ MEMBERS_ONLY: {
711
+ status: number;
712
+ };
713
+ ORG_REQUIRED: {
714
+ status: number;
715
+ };
716
+ SCOPE_REQUIRED: {
717
+ status: number;
718
+ };
719
+ SERVICE_TOKEN_REQUIRED: {
720
+ status: number;
721
+ };
722
+ ORGANIZATION_DISABLED: {
723
+ status: number;
724
+ data: z.ZodObject<{
725
+ manageUrl: z.ZodNullable<z.ZodString>;
726
+ }, z.core.$strip>;
727
+ };
728
+ NOT_IN_PLAN: {
729
+ status: number;
730
+ data: z.ZodOptional<z.ZodObject<{
731
+ manageUrl: z.ZodNullable<z.ZodString>;
732
+ }, z.core.$strip>>;
733
+ };
734
+ READ_ONLY: {
735
+ status: number;
736
+ };
737
+ TOO_MANY_REQUESTS: {
738
+ status: number;
739
+ };
740
+ INVALID_INPUT: {
741
+ status: number;
742
+ data: z.ZodObject<{
743
+ issues: z.ZodArray<z.ZodObject<{
744
+ path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodInt]>>;
745
+ message: z.ZodString;
746
+ }, z.core.$strip>>;
747
+ }, z.core.$strip>;
748
+ };
749
+ NOT_FOUND: {
750
+ status: number;
751
+ };
752
+ TAKEN: {
753
+ status: number;
754
+ data: z.ZodObject<{
755
+ field: z.ZodString;
756
+ id: z.ZodOptional<z.ZodString>;
757
+ values: z.ZodOptional<z.ZodArray<z.ZodString>>;
758
+ }, z.core.$strip>;
759
+ };
760
+ INVALID_CURSOR: {
761
+ status: number;
762
+ };
763
+ INVALID_REFERENCE: {
764
+ status: number;
765
+ data: z.ZodObject<{
766
+ field: z.ZodString;
767
+ }, z.core.$strip>;
768
+ };
769
+ INVALID_FILTER: {
770
+ status: number;
771
+ };
772
+ FILTER_TOO_SLOW: {
773
+ status: number;
774
+ };
775
+ INVALID_TYPE: {
776
+ status: number;
777
+ };
778
+ VIEW_NOT_SHARED: {
779
+ status: number;
780
+ };
644
781
  }>, Record<never, never>>;
645
782
  };
package/dist/views.js CHANGED
@@ -1,7 +1,7 @@
1
- import { FILTER_FIELD_GROUPS, FILTER_FIELD_TYPES, SORT_DIRECTIONS, VIEW_RECORD_TYPES } from "./db/src/enums.js";
1
+ import { FILTER_FIELD_GROUPS, FILTER_FIELD_TYPES, PLUGIN_VIEW_TYPE, SORT_DIRECTIONS, VIEW_RECORD_TYPES } from "./db/src/enums.js";
2
2
  import { views } from "./db/src/schema/views.js";
3
3
  import "./db/src/schema/index.js";
4
- import { COMMON_ERRORS } from "./errors.js";
4
+ import { COMMON_ERRORS, ERRORS } from "./errors.js";
5
5
  import { ConditionGroup } from "./db/src/automationDefinition.js";
6
6
  import { Id, isoDate, listOf } from "./common.js";
7
7
  import { oc } from "@orpc/contract";
@@ -10,6 +10,14 @@ import { createSelectSchema, createUpdateSchema } from "drizzle-zod";
10
10
  // src/views.ts
11
11
  /** The list a view belongs to: customers, leads (people), companies, company leads, products. */
12
12
  const ViewRecordType = z.enum(VIEW_RECORD_TYPES);
13
+ /** A plugin's list: its record type, `<plugin>:<record>` (`sales:deal`). Its API applies the filter. */
14
+ const PluginViewType = z.templateLiteral([
15
+ z.string(),
16
+ ":",
17
+ z.string()
18
+ ]).refine((type) => new RegExp(PLUGIN_VIEW_TYPE).test(type), "Expected <plugin>:<record>");
19
+ /** Any list views can belong to: one of core's, or a plugin's. */
20
+ const ViewListType = z.union([ViewRecordType, PluginViewType]);
13
21
  /**
14
22
  * A filter on a list: the condition language automations use, on the
15
23
  * record's fields (`subject.state`, `subject.customFields.<id>`,
@@ -24,7 +32,9 @@ const FilterField = z.object({
24
32
  type: z.enum(FILTER_FIELD_TYPES),
25
33
  options: z.array(z.string()).optional(),
26
34
  /** Where it comes from, for grouping in the picker. */
27
- group: z.enum(FILTER_FIELD_GROUPS)
35
+ group: z.enum(FILTER_FIELD_GROUPS),
36
+ /** The heading to list it under instead of the group's own: a plugin's title (`plugin`). */
37
+ groupLabel: z.string().optional()
28
38
  });
29
39
  const ViewSort = z.object({
30
40
  field: z.string().max(100),
@@ -32,6 +42,7 @@ const ViewSort = z.object({
32
42
  });
33
43
  const View = createSelectSchema(views, {
34
44
  id: Id,
45
+ recordType: () => ViewListType,
35
46
  filter: () => ConditionGroup,
36
47
  columns: () => z.array(z.string()),
37
48
  sort: () => ViewSort,
@@ -68,21 +79,28 @@ const ViewFields = createUpdateSchema(views, {
68
79
  sort: true,
69
80
  shared: true
70
81
  });
71
- /** Views answer with the common errors only. */
72
- const base = oc.errors(COMMON_ERRORS);
82
+ /** The most record ids one `views.matches` call checks. */
83
+ const VIEW_MATCHES_MAX = 500;
84
+ const { INVALID_TYPE, VIEW_NOT_SHARED } = ERRORS;
85
+ /** What these procedures answer with besides the common errors. */
86
+ const base = oc.errors({
87
+ ...COMMON_ERRORS,
88
+ INVALID_TYPE,
89
+ VIEW_NOT_SHARED
90
+ });
73
91
  /** Saved lists (views) and what lists can be filtered by. */
74
92
  const viewsContract = {
75
93
  list: base.route({
76
94
  method: "GET",
77
95
  path: "/views",
78
- summary: "Views of a list: the member's own and the team's shared ones"
79
- }).input(z.object({ recordType: ViewRecordType })).output(listOf(View)),
96
+ summary: "Views of a list (core's, or a plugin's `<plugin>:<record>`): the member's own and the team's shared ones. A plugin (`views:read`) gets the shared ones"
97
+ }).input(z.object({ recordType: ViewListType })).output(listOf(View)),
80
98
  create: base.route({
81
99
  method: "POST",
82
100
  path: "/views",
83
101
  successStatus: 201,
84
- summary: "Save a view (sharing it with the team needs contacts.edit; for products, products.manage)"
85
- }).input(ViewFields.required({ name: true }).extend({ recordType: ViewRecordType })).output(View),
102
+ summary: "Save a view (sharing it with the team needs contacts.edit; for products, products.manage; a plugin's list, none)"
103
+ }).input(ViewFields.required({ name: true }).extend({ recordType: ViewListType })).output(View),
86
104
  update: base.route({
87
105
  method: "PATCH",
88
106
  path: "/views/{id}",
@@ -96,6 +114,14 @@ const viewsContract = {
96
114
  method: "GET",
97
115
  path: "/views/fields",
98
116
  summary: "What a list can be filtered by: fields, custom fields, the company, activity"
99
- }).input(z.object({ recordType: ViewRecordType })).output(listOf(FilterField))
117
+ }).input(z.object({ recordType: ViewRecordType })).output(listOf(FilterField)),
118
+ matches: base.route({
119
+ method: "POST",
120
+ path: "/views/{viewId}/matches",
121
+ summary: "Which of the given records a shared view's filter and search match now (plugins with `views:read`; a segment for prices, audiences). Customer, lead, company and company lead views; up to 500 ids, others' and unknown ones never match. 403 VIEW_NOT_SHARED for a member's own view, 400 INVALID_TYPE for another list's"
122
+ }).input(z.object({
123
+ viewId: Id,
124
+ recordIds: z.array(Id).min(1).max(500)
125
+ })).output(z.object({ recordIds: z.array(Id) }))
100
126
  };
101
- export { FilterField, RecordFilter, View, ViewRecordType, ViewSort, viewsContract };
127
+ export { FilterField, PluginViewType, RecordFilter, VIEW_MATCHES_MAX, View, ViewListType, ViewRecordType, ViewSort, viewsContract };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@erxes/core-contract",
3
- "version": "0.1.0-v2.7",
3
+ "version": "0.1.0-v2.9",
4
4
  "private": false,
5
5
  "description": "erxes core API contract (/core/v1) and event schemas, shared by core and plugins",
6
6
  "license": "AGPL-3.0-only",
@@ -37,6 +37,7 @@
37
37
  "./organizations": "./dist/organizations.js",
38
38
  "./payments": "./dist/payments.js",
39
39
  "./platform": "./dist/platform.js",
40
+ "./pluginFields": "./dist/pluginFields.js",
40
41
  "./pluginJobs": "./dist/pluginJobs.js",
41
42
  "./plugins": "./dist/plugins.js",
42
43
  "./products": "./dist/products.js",
@@ -44,6 +45,7 @@
44
45
  "./routes": "./dist/routes.js",
45
46
  "./saas": "./dist/saas.js",
46
47
  "./tags": "./dist/tags.js",
48
+ "./timelines": "./dist/timelines.js",
47
49
  "./transfer": "./dist/transfer.js",
48
50
  "./trash": "./dist/trash.js",
49
51
  "./users": "./dist/users.js",