@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/fields.d.ts CHANGED
@@ -32,8 +32,10 @@ export declare const Field: z.ZodObject<{
32
32
  options: z.ZodArray<z.ZodString>;
33
33
  isVisible: z.ZodBoolean;
34
34
  order: z.ZodInt;
35
+ plugin: z.ZodNullable<z.ZodString>;
35
36
  archivedAt: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
36
37
  createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
38
+ pluginTitle: z.ZodNullable<z.ZodString>;
37
39
  }, {
38
40
  out: {};
39
41
  in: {};
@@ -66,6 +68,110 @@ export declare const FieldUsage: z.ZodObject<{
66
68
  }, z.core.$strip>;
67
69
  export type FieldUsage = z.infer<typeof FieldUsage>;
68
70
  export declare const fieldsContract: {
71
+ setPluginValues: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
72
+ contentType: z.ZodEnum<{
73
+ company: "company";
74
+ customer: "customer";
75
+ }>;
76
+ values: z.ZodArray<z.ZodObject<{
77
+ recordId: z.ZodString;
78
+ code: z.ZodString;
79
+ value: z.ZodNullable<z.ZodUnion<readonly [z.ZodNumber, z.ZodString, z.ZodArray<z.ZodString>]>>;
80
+ }, z.core.$strip>>;
81
+ }, z.core.$strip>, z.ZodObject<{
82
+ written: z.ZodInt;
83
+ skipped: z.ZodArray<z.ZodString>;
84
+ }, z.core.$strip>, import("@orpc/contract").MergedErrorMap<Record<never, never>, {
85
+ UNAUTHORIZED: {
86
+ status: number;
87
+ };
88
+ NOT_ALLOWED: {
89
+ status: number;
90
+ data: z.ZodOptional<z.ZodObject<{
91
+ permission: z.ZodString;
92
+ }, z.core.$strip>>;
93
+ };
94
+ PLUGIN_ONLY: {
95
+ status: number;
96
+ };
97
+ MEMBERS_ONLY: {
98
+ status: number;
99
+ };
100
+ ORG_REQUIRED: {
101
+ status: number;
102
+ };
103
+ SCOPE_REQUIRED: {
104
+ status: number;
105
+ };
106
+ SERVICE_TOKEN_REQUIRED: {
107
+ status: number;
108
+ };
109
+ ORGANIZATION_DISABLED: {
110
+ status: number;
111
+ data: z.ZodObject<{
112
+ manageUrl: z.ZodNullable<z.ZodString>;
113
+ }, z.core.$strip>;
114
+ };
115
+ NOT_IN_PLAN: {
116
+ status: number;
117
+ data: z.ZodOptional<z.ZodObject<{
118
+ manageUrl: z.ZodNullable<z.ZodString>;
119
+ }, z.core.$strip>>;
120
+ };
121
+ READ_ONLY: {
122
+ status: number;
123
+ };
124
+ TOO_MANY_REQUESTS: {
125
+ status: number;
126
+ };
127
+ INVALID_INPUT: {
128
+ status: number;
129
+ data: z.ZodObject<{
130
+ issues: z.ZodArray<z.ZodObject<{
131
+ path: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodInt]>>;
132
+ message: z.ZodString;
133
+ }, z.core.$strip>>;
134
+ }, z.core.$strip>;
135
+ };
136
+ NOT_FOUND: {
137
+ status: number;
138
+ };
139
+ TAKEN: {
140
+ status: number;
141
+ data: z.ZodObject<{
142
+ field: z.ZodString;
143
+ id: z.ZodOptional<z.ZodString>;
144
+ values: z.ZodOptional<z.ZodArray<z.ZodString>>;
145
+ }, z.core.$strip>;
146
+ };
147
+ INVALID_CURSOR: {
148
+ status: number;
149
+ };
150
+ INVALID_REFERENCE: {
151
+ status: number;
152
+ data: z.ZodObject<{
153
+ field: z.ZodString;
154
+ }, z.core.$strip>;
155
+ };
156
+ INVALID_FILTER: {
157
+ status: number;
158
+ };
159
+ FILTER_TOO_SLOW: {
160
+ status: number;
161
+ };
162
+ INVALID_FIELD: {
163
+ status: number;
164
+ data: z.ZodObject<{
165
+ fieldId: z.ZodString;
166
+ }, z.core.$strip>;
167
+ };
168
+ INVALID_FIELD_VALUE: {
169
+ status: number;
170
+ data: z.ZodObject<{
171
+ fieldId: z.ZodString;
172
+ }, z.core.$strip>;
173
+ };
174
+ }>, Record<never, never>>;
69
175
  list: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
70
176
  contentType: z.ZodEnum<{
71
177
  company: "company";
@@ -111,8 +217,10 @@ export declare const fieldsContract: {
111
217
  options: z.ZodArray<z.ZodString>;
112
218
  isVisible: z.ZodBoolean;
113
219
  order: z.ZodInt;
220
+ plugin: z.ZodNullable<z.ZodString>;
114
221
  archivedAt: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
115
222
  createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
223
+ pluginTitle: z.ZodNullable<z.ZodString>;
116
224
  }, {
117
225
  out: {};
118
226
  in: {};
@@ -207,6 +315,13 @@ export declare const fieldsContract: {
207
315
  groupId: z.ZodString;
208
316
  }, z.core.$strip>>;
209
317
  };
318
+ PLUGIN_FIELD: {
319
+ status: number;
320
+ data: z.ZodObject<{
321
+ fieldId: z.ZodString;
322
+ plugin: z.ZodString;
323
+ }, z.core.$strip>;
324
+ };
210
325
  }>, Record<never, never>>;
211
326
  usage: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
212
327
  ids: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodTransform<string[], string>>>;
@@ -305,6 +420,13 @@ export declare const fieldsContract: {
305
420
  groupId: z.ZodString;
306
421
  }, z.core.$strip>>;
307
422
  };
423
+ PLUGIN_FIELD: {
424
+ status: number;
425
+ data: z.ZodObject<{
426
+ fieldId: z.ZodString;
427
+ plugin: z.ZodString;
428
+ }, z.core.$strip>;
429
+ };
308
430
  }>, Record<never, never>>;
309
431
  create: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
310
432
  contentType: z.ZodNonOptional<z.ZodOptional<z.ZodEnum<{
@@ -373,8 +495,10 @@ export declare const fieldsContract: {
373
495
  options: z.ZodArray<z.ZodString>;
374
496
  isVisible: z.ZodBoolean;
375
497
  order: z.ZodInt;
498
+ plugin: z.ZodNullable<z.ZodString>;
376
499
  archivedAt: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
377
500
  createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
501
+ pluginTitle: z.ZodNullable<z.ZodString>;
378
502
  }, {
379
503
  out: {};
380
504
  in: {};
@@ -468,6 +592,13 @@ export declare const fieldsContract: {
468
592
  groupId: z.ZodString;
469
593
  }, z.core.$strip>>;
470
594
  };
595
+ PLUGIN_FIELD: {
596
+ status: number;
597
+ data: z.ZodObject<{
598
+ fieldId: z.ZodString;
599
+ plugin: z.ZodString;
600
+ }, z.core.$strip>;
601
+ };
471
602
  }>, Record<never, never>>;
472
603
  update: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
473
604
  groupId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
@@ -533,8 +664,10 @@ export declare const fieldsContract: {
533
664
  options: z.ZodArray<z.ZodString>;
534
665
  isVisible: z.ZodBoolean;
535
666
  order: z.ZodInt;
667
+ plugin: z.ZodNullable<z.ZodString>;
536
668
  archivedAt: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
537
669
  createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
670
+ pluginTitle: z.ZodNullable<z.ZodString>;
538
671
  }, {
539
672
  out: {};
540
673
  in: {};
@@ -628,6 +761,13 @@ export declare const fieldsContract: {
628
761
  groupId: z.ZodString;
629
762
  }, z.core.$strip>>;
630
763
  };
764
+ PLUGIN_FIELD: {
765
+ status: number;
766
+ data: z.ZodObject<{
767
+ fieldId: z.ZodString;
768
+ plugin: z.ZodString;
769
+ }, z.core.$strip>;
770
+ };
631
771
  }>, Record<never, never>>;
632
772
  reorder: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
633
773
  orders: z.ZodArray<z.ZodObject<{
@@ -726,6 +866,13 @@ export declare const fieldsContract: {
726
866
  groupId: z.ZodString;
727
867
  }, z.core.$strip>>;
728
868
  };
869
+ PLUGIN_FIELD: {
870
+ status: number;
871
+ data: z.ZodObject<{
872
+ fieldId: z.ZodString;
873
+ plugin: z.ZodString;
874
+ }, z.core.$strip>;
875
+ };
729
876
  }>, Record<never, never>>;
730
877
  archive: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
731
878
  ids: z.ZodArray<z.ZodString>;
@@ -821,6 +968,13 @@ export declare const fieldsContract: {
821
968
  groupId: z.ZodString;
822
969
  }, z.core.$strip>>;
823
970
  };
971
+ PLUGIN_FIELD: {
972
+ status: number;
973
+ data: z.ZodObject<{
974
+ fieldId: z.ZodString;
975
+ plugin: z.ZodString;
976
+ }, z.core.$strip>;
977
+ };
824
978
  }>, Record<never, never>>;
825
979
  restore: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
826
980
  id: z.ZodString;
@@ -857,8 +1011,10 @@ export declare const fieldsContract: {
857
1011
  options: z.ZodArray<z.ZodString>;
858
1012
  isVisible: z.ZodBoolean;
859
1013
  order: z.ZodInt;
1014
+ plugin: z.ZodNullable<z.ZodString>;
860
1015
  archivedAt: z.ZodNullable<z.ZodCodec<z.ZodDate, z.ZodISODateTime>>;
861
1016
  createdAt: z.ZodCodec<z.ZodDate, z.ZodISODateTime>;
1017
+ pluginTitle: z.ZodNullable<z.ZodString>;
862
1018
  }, {
863
1019
  out: {};
864
1020
  in: {};
@@ -952,6 +1108,13 @@ export declare const fieldsContract: {
952
1108
  groupId: z.ZodString;
953
1109
  }, z.core.$strip>>;
954
1110
  };
1111
+ PLUGIN_FIELD: {
1112
+ status: number;
1113
+ data: z.ZodObject<{
1114
+ fieldId: z.ZodString;
1115
+ plugin: z.ZodString;
1116
+ }, z.core.$strip>;
1117
+ };
955
1118
  }>, Record<never, never>>;
956
1119
  removeUnused: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
957
1120
  ids: z.ZodArray<z.ZodString>;
@@ -1047,6 +1210,13 @@ export declare const fieldsContract: {
1047
1210
  groupId: z.ZodString;
1048
1211
  }, z.core.$strip>>;
1049
1212
  };
1213
+ PLUGIN_FIELD: {
1214
+ status: number;
1215
+ data: z.ZodObject<{
1216
+ fieldId: z.ZodString;
1217
+ plugin: z.ZodString;
1218
+ }, z.core.$strip>;
1219
+ };
1050
1220
  }>, Record<never, never>>;
1051
1221
  remove: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
1052
1222
  id: z.ZodString;
@@ -1142,6 +1312,13 @@ export declare const fieldsContract: {
1142
1312
  groupId: z.ZodString;
1143
1313
  }, z.core.$strip>>;
1144
1314
  };
1315
+ PLUGIN_FIELD: {
1316
+ status: number;
1317
+ data: z.ZodObject<{
1318
+ fieldId: z.ZodString;
1319
+ plugin: z.ZodString;
1320
+ }, z.core.$strip>;
1321
+ };
1145
1322
  }>, Record<never, never>>;
1146
1323
  };
1147
1324
  export declare const fieldGroupsContract: {
@@ -1263,6 +1440,13 @@ export declare const fieldGroupsContract: {
1263
1440
  groupId: z.ZodString;
1264
1441
  }, z.core.$strip>>;
1265
1442
  };
1443
+ PLUGIN_FIELD: {
1444
+ status: number;
1445
+ data: z.ZodObject<{
1446
+ fieldId: z.ZodString;
1447
+ plugin: z.ZodString;
1448
+ }, z.core.$strip>;
1449
+ };
1266
1450
  }>, Record<never, never>>;
1267
1451
  create: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
1268
1452
  contentType: z.ZodNonOptional<z.ZodOptional<z.ZodEnum<{
@@ -1382,6 +1566,13 @@ export declare const fieldGroupsContract: {
1382
1566
  groupId: z.ZodString;
1383
1567
  }, z.core.$strip>>;
1384
1568
  };
1569
+ PLUGIN_FIELD: {
1570
+ status: number;
1571
+ data: z.ZodObject<{
1572
+ fieldId: z.ZodString;
1573
+ plugin: z.ZodString;
1574
+ }, z.core.$strip>;
1575
+ };
1385
1576
  }>, Record<never, never>>;
1386
1577
  update: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
1387
1578
  name: z.ZodOptional<z.ZodString>;
@@ -1498,6 +1689,13 @@ export declare const fieldGroupsContract: {
1498
1689
  groupId: z.ZodString;
1499
1690
  }, z.core.$strip>>;
1500
1691
  };
1692
+ PLUGIN_FIELD: {
1693
+ status: number;
1694
+ data: z.ZodObject<{
1695
+ fieldId: z.ZodString;
1696
+ plugin: z.ZodString;
1697
+ }, z.core.$strip>;
1698
+ };
1501
1699
  }>, Record<never, never>>;
1502
1700
  reorder: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
1503
1701
  orders: z.ZodArray<z.ZodObject<{
@@ -1596,6 +1794,13 @@ export declare const fieldGroupsContract: {
1596
1794
  groupId: z.ZodString;
1597
1795
  }, z.core.$strip>>;
1598
1796
  };
1797
+ PLUGIN_FIELD: {
1798
+ status: number;
1799
+ data: z.ZodObject<{
1800
+ fieldId: z.ZodString;
1801
+ plugin: z.ZodString;
1802
+ }, z.core.$strip>;
1803
+ };
1599
1804
  }>, Record<never, never>>;
1600
1805
  archive: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
1601
1806
  id: z.ZodString;
@@ -1705,6 +1910,13 @@ export declare const fieldGroupsContract: {
1705
1910
  groupId: z.ZodString;
1706
1911
  }, z.core.$strip>>;
1707
1912
  };
1913
+ PLUGIN_FIELD: {
1914
+ status: number;
1915
+ data: z.ZodObject<{
1916
+ fieldId: z.ZodString;
1917
+ plugin: z.ZodString;
1918
+ }, z.core.$strip>;
1919
+ };
1708
1920
  }>, Record<never, never>>;
1709
1921
  restore: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
1710
1922
  id: z.ZodString;
@@ -1814,6 +2026,13 @@ export declare const fieldGroupsContract: {
1814
2026
  groupId: z.ZodString;
1815
2027
  }, z.core.$strip>>;
1816
2028
  };
2029
+ PLUGIN_FIELD: {
2030
+ status: number;
2031
+ data: z.ZodObject<{
2032
+ fieldId: z.ZodString;
2033
+ plugin: z.ZodString;
2034
+ }, z.core.$strip>;
2035
+ };
1817
2036
  }>, Record<never, never>>;
1818
2037
  remove: import("@orpc/contract").ContractProcedureBuilderWithInputOutput<z.ZodObject<{
1819
2038
  id: z.ZodString;
@@ -1909,5 +2128,12 @@ export declare const fieldGroupsContract: {
1909
2128
  groupId: z.ZodString;
1910
2129
  }, z.core.$strip>>;
1911
2130
  };
2131
+ PLUGIN_FIELD: {
2132
+ status: number;
2133
+ data: z.ZodObject<{
2134
+ fieldId: z.ZodString;
2135
+ plugin: z.ZodString;
2136
+ }, z.core.$strip>;
2137
+ };
1912
2138
  }>, Record<never, never>>;
1913
2139
  };
package/dist/fields.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { fieldGroups, fields } from "./db/src/schema/fields.js";
2
2
  import "./db/src/schema/index.js";
3
3
  import { COMMON_ERRORS, ERRORS } from "./errors.js";
4
+ import { pluginFieldsContract } from "./pluginFields.js";
4
5
  import { OPTION_FIELD_TYPES } from "./values.js";
5
6
  import { FieldContentType, Id, IdList, QueryBoolean, isoDate, listOf } from "./common.js";
6
7
  import { oc } from "@orpc/contract";
@@ -34,10 +35,14 @@ const Field = createSelectSchema(fields, {
34
35
  /** Shown in record tables and the record panel. */
35
36
  isVisible: true,
36
37
  order: true,
38
+ /** The plugin that declared it and writes its values (members only read it); null: a member's. */
39
+ plugin: true,
37
40
  /** Set while it (or its group) is archived: hidden, values kept. */
38
41
  archivedAt: true,
39
42
  createdAt: true
40
- });
43
+ }).extend({
44
+ /** The plugin's title from its manifest, to list its fields under; null for members' fields. */
45
+ pluginTitle: z.string().nullable() });
41
46
  /** A group of custom fields of a record type. */
42
47
  const FieldGroup = createSelectSchema(fieldGroups, {
43
48
  id: Id,
@@ -110,12 +115,13 @@ const Orders = z.object({ orders: z.array(z.object({
110
115
  const Ok = z.object({ ok: z.literal(true) });
111
116
  const changes = (value) => Object.keys(value).some((key) => key !== "id");
112
117
  const needsOptions = (value) => !value.type || !OPTION_FIELD_TYPES.includes(value.type) || (value.options?.length ?? 0) > 0;
113
- const { FIELD_IN_USE, INVALID_FIELD_GROUP } = ERRORS;
118
+ const { FIELD_IN_USE, INVALID_FIELD_GROUP, PLUGIN_FIELD } = ERRORS;
114
119
  /** What these procedures answer with besides the common errors. */
115
120
  const base = oc.errors({
116
121
  ...COMMON_ERRORS,
117
122
  FIELD_IN_USE,
118
- INVALID_FIELD_GROUP
123
+ INVALID_FIELD_GROUP,
124
+ PLUGIN_FIELD
119
125
  });
120
126
  const fieldsContract = {
121
127
  list: base.route({
@@ -151,7 +157,7 @@ const fieldsContract = {
151
157
  update: base.route({
152
158
  method: "PATCH",
153
159
  path: "/fields/{id}",
154
- summary: "Change a field. The type changes only within types sharing a stored value while records hold values (409 FIELD_IN_USE)"
160
+ summary: "Change a field. The type changes only within types sharing a stored value while records hold values (409 FIELD_IN_USE). A plugin's field takes only `isVisible` (403 PLUGIN_FIELD)"
155
161
  }).input(FieldFields.omit({ contentType: true }).extend({ id: Id }).refine(changes, "nothing to update")).output(Field),
156
162
  reorder: base.route({
157
163
  method: "POST",
@@ -161,23 +167,24 @@ const fieldsContract = {
161
167
  archive: base.route({
162
168
  method: "POST",
163
169
  path: "/fields/archive",
164
- summary: "Archive fields: hidden everywhere, values kept (owners and admins)"
170
+ summary: "Archive fields: hidden everywhere, values kept (owners and admins). 403 PLUGIN_FIELD for a plugin's field"
165
171
  }).input(z.object({ ids: z.array(Id).min(1).max(100) })).output(Ok),
166
172
  restore: base.route({
167
173
  method: "POST",
168
174
  path: "/fields/{id}/restore",
169
- summary: "Restore an archived field (owners and admins)"
175
+ summary: "Restore an archived field (owners and admins). 403 PLUGIN_FIELD for a plugin's field"
170
176
  }).input(z.object({ id: Id })).output(Field),
171
177
  removeUnused: base.route({
172
178
  method: "POST",
173
179
  path: "/fields/remove",
174
- summary: "Delete fields no record holds a value of (owners and admins). 409 FIELD_IN_USE otherwise"
180
+ summary: "Delete fields no record holds a value of (owners and admins). 409 FIELD_IN_USE otherwise, 403 PLUGIN_FIELD for a plugin's field"
175
181
  }).input(z.object({ ids: z.array(Id).min(1).max(100) })).output(Ok),
176
182
  remove: base.route({
177
183
  method: "DELETE",
178
184
  path: "/fields/{id}",
179
- summary: "Delete a custom field and its values (owners and admins)"
180
- }).input(z.object({ id: Id })).output(Ok)
185
+ summary: "Delete a custom field and its values (owners and admins). 403 PLUGIN_FIELD for a plugin's field"
186
+ }).input(z.object({ id: Id })).output(Ok),
187
+ ...pluginFieldsContract
181
188
  };
182
189
  const fieldGroupsContract = {
183
190
  list: base.route({