@bisondesk/commons-sdk 1.0.331 → 1.0.333

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.
@@ -0,0 +1,95 @@
1
+ import { MultiLangValue } from './types.js';
2
+
3
+ export type PicklistValueUpdateRequest = {
4
+ picklistId: string;
5
+ value: PicklistValue | NewPicklistValue;
6
+ tenantId?: string;
7
+ };
8
+
9
+ export type NewPicklistValue<T = Record<string, string>> = {
10
+ color?: string;
11
+ sortPriority?: number;
12
+ titles: MultiLangValue;
13
+ dependency?: PicklistValueDependency;
14
+ meta?: T;
15
+ };
16
+
17
+ export type PicklistValue<T = any> = NewPicklistValue<T> & {
18
+ id: string;
19
+ system?: boolean;
20
+ };
21
+
22
+ export type PicklistValueListRequest = {
23
+ picklistId: string;
24
+ limit: number;
25
+ offset: number;
26
+ dependencies?: PicklistValueDependency[];
27
+ };
28
+
29
+ export type PicklistValueRequest = {
30
+ picklistId: string;
31
+ valueId: string;
32
+ };
33
+
34
+ export type AdHocPicklistValues<T = any> = {
35
+ [picklistId: string]: {
36
+ [valueId: string]: PicklistValue<T>;
37
+ };
38
+ };
39
+
40
+ export type AdHocPicklistRequest = {
41
+ requests: PicklistValueRequest[];
42
+ preferredLang: string;
43
+ tenantLang: string;
44
+ };
45
+
46
+ export type AdHocPicklistValueDisplay = {
47
+ [picklistId: string]: {
48
+ [valueId: string]: {
49
+ color?: string;
50
+ title: string;
51
+ };
52
+ };
53
+ };
54
+
55
+ export type PicklistOptionsRequest = {
56
+ picklistId: string;
57
+ dependencies?: PicklistValueDependency[];
58
+ lang: string;
59
+ };
60
+
61
+ export type PicklistUpsertValueRequest = {
62
+ tenantId?: string;
63
+ picklistId: string;
64
+ value: PicklistValue | NewPicklistValue;
65
+ };
66
+
67
+ export type QuickAddPicklistValue = {
68
+ sortPriority?: number;
69
+ titles: MultiLangValue;
70
+ };
71
+
72
+ export type NewPicklist = {
73
+ id?: undefined;
74
+ titles: MultiLangValue;
75
+ values: QuickAddPicklistValue[];
76
+ customSort?: boolean;
77
+ };
78
+
79
+ export type BasePicklist = {
80
+ customSort?: boolean;
81
+ id: string;
82
+ system?: boolean;
83
+ titles: MultiLangValue;
84
+ };
85
+
86
+ export type PicklistInfo = BasePicklist & {
87
+ count: number;
88
+ modifiedAt: string;
89
+ };
90
+ export type PicklistValueDependency = {
91
+ picklistId: string;
92
+ values: string[];
93
+ };
94
+
95
+ export type PicklistCollection = (BasePicklist & { data: PicklistValue[] })[];
package/src/search.ts ADDED
@@ -0,0 +1,278 @@
1
+ import { BusinessEntityIds, SUPPORTED_LANGUAGES } from './constants.js';
2
+ import { FieldTypes, NumberMeta } from './fields.js';
3
+ import { MultiLangValue } from './types.js';
4
+
5
+ export enum ConditionType {
6
+ and = 'AND',
7
+ or = 'OR',
8
+ }
9
+
10
+ export enum ElasticsearchOperator {
11
+ // all properties
12
+ empty = 'EMPTY',
13
+ notEmpty = 'NOT_EMPTY',
14
+ is = 'IS',
15
+ isNot = 'IS_NOT',
16
+ // number, date properties
17
+ greaterThanOrEqual = 'GTE',
18
+ greaterThan = 'GT',
19
+ lessThanEqual = 'LTE',
20
+ lessThan = 'LT',
21
+ between = 'BETWEEN',
22
+ // string properties
23
+ contains = 'CONTAINS',
24
+ notContains = 'NOT_CONTAINS',
25
+ startsWith = 'STARTS_WITH',
26
+ endsWith = 'ENDS_WITH',
27
+ }
28
+
29
+ export type Filter<OP = ElasticsearchOperator> = {
30
+ data: string;
31
+ fieldId: string;
32
+ operator: OP;
33
+ };
34
+
35
+ export enum ElasticsearchGeoOperator {
36
+ boundingBox = 'geo_bounding_box',
37
+ distance = 'geo_distance',
38
+ polygon = 'geo_polygon',
39
+ }
40
+
41
+ type ElasticSearchCoordinates =
42
+ | {
43
+ lat: number;
44
+ lon: number;
45
+ }
46
+ | [lat: number, lon: number]
47
+ | string;
48
+
49
+ type BoundingBoxCoordinates = {
50
+ top_left: ElasticSearchCoordinates;
51
+ bottom_right: ElasticSearchCoordinates;
52
+ };
53
+
54
+ type BoundingBoxWKT = {
55
+ wkt: `BBOX (${number}, ${number}, ${number}, ${number})`;
56
+ };
57
+
58
+ type BoundingBoxVertices = {
59
+ top: number;
60
+ left: number;
61
+ bottom: number;
62
+ right: number;
63
+ };
64
+
65
+ type GeoDistanceUnit = 'mi' | 'yd' | 'ft' | 'in' | 'km' | 'm' | 'cm' | 'mm' | 'nmi';
66
+
67
+ type GeoBoundingBoxFilter = {
68
+ operator: ElasticsearchGeoOperator.boundingBox;
69
+ data: BoundingBoxCoordinates | BoundingBoxWKT | BoundingBoxVertices;
70
+ };
71
+
72
+ type GeoDistanceFilter = {
73
+ operator: ElasticsearchGeoOperator.distance;
74
+ data: {
75
+ distance: `${number}${GeoDistanceUnit}`;
76
+ coords: ElasticSearchCoordinates;
77
+ };
78
+ };
79
+
80
+ type GeoPolygonFilter = {
81
+ operator: ElasticsearchGeoOperator.polygon;
82
+ data: {
83
+ points: ElasticSearchCoordinates[];
84
+ };
85
+ };
86
+
87
+ export type GeoFilter = { fieldId: string } & (
88
+ | GeoBoundingBoxFilter
89
+ | GeoDistanceFilter
90
+ | GeoPolygonFilter
91
+ );
92
+
93
+ export type ComplexFilter<OP = ElasticsearchOperator> = {
94
+ condition: ConditionType;
95
+ filters: Array<Filter<OP> | ComplexFilter<OP>>;
96
+ };
97
+
98
+ export type SearchResponse<T = any> = {
99
+ took: number;
100
+ timed_out: boolean;
101
+ _scroll_id?: string;
102
+ _shards: unknown;
103
+ hits: {
104
+ total: {
105
+ value: number;
106
+ relation: 'eq' | 'gte';
107
+ };
108
+ max_score: number;
109
+ hits: Array<{
110
+ _index: string;
111
+ _type: string;
112
+ _id: string;
113
+ _score: number;
114
+ _source?: T;
115
+ _version?: number;
116
+ _explanation?: unknown;
117
+ fields?: any;
118
+ highlight?: any;
119
+ inner_hits?: any;
120
+ matched_queries?: string[];
121
+ sort?: Array<string | number>;
122
+ }>;
123
+ };
124
+ aggregations?: { [aggName: string]: object };
125
+ };
126
+
127
+ ///////////////////////////////////////////////////////
128
+ // Search
129
+ ///////////////////////////////////////////////////////
130
+
131
+ export const FILTER_RANGE_SEPARATOR = '__';
132
+
133
+ export enum SortOrder {
134
+ asc = 'asc',
135
+ desc = 'desc',
136
+ }
137
+
138
+ export type SortFilter = {
139
+ fieldId: string;
140
+ order: SortOrder;
141
+ };
142
+
143
+ export type BaseSearchRequest = {
144
+ fullText?: string;
145
+ limit: number;
146
+ query?: ComplexFilter<ElasticsearchOperator>;
147
+ sortBy?: SortFilter[];
148
+ };
149
+
150
+ type InfiniteSearchRequest = {
151
+ infinite: true;
152
+ nextToken?: string;
153
+ };
154
+
155
+ type PaginatedSearchRequest = {
156
+ infinite?: false;
157
+ offset?: number;
158
+ };
159
+
160
+ export type SearchRequest = {
161
+ fullText?: string;
162
+ limit: number;
163
+ query?: ComplexFilter<ElasticsearchOperator>;
164
+ geoFilters?: GeoFilter[];
165
+ sortBy?: SortFilter[];
166
+ } & (InfiniteSearchRequest | PaginatedSearchRequest);
167
+
168
+ export type GlobalSearchRequest = {
169
+ fullText: string;
170
+ limit: number;
171
+ } & {
172
+ entityIds: BusinessEntityIds[];
173
+ } & (InfiniteSearchRequest | PaginatedSearchRequest);
174
+
175
+ export type GlobalSearchResult = {
176
+ businessEntityId: BusinessEntityIds;
177
+ recordId: string;
178
+ title: string;
179
+ description: string;
180
+ tags?: string[];
181
+ };
182
+
183
+ export type GlobalSearchByIdRequest = {
184
+ ids: {
185
+ businessEntityId: BusinessEntityIds;
186
+ recordId: string;
187
+ }[];
188
+ };
189
+
190
+ export type PublicSearchRequest = {
191
+ limit: number;
192
+ offset?: number;
193
+ query?: ComplexFilter;
194
+ sortBy?: SortFilter[];
195
+ };
196
+
197
+ ///////////////////////////////////////////////////////
198
+ // Aggregations
199
+ ///////////////////////////////////////////////////////
200
+
201
+ export type AggFilterOperator =
202
+ | ElasticsearchOperator.is
203
+ | ElasticsearchOperator.greaterThan
204
+ | ElasticsearchOperator.lessThan
205
+ | ElasticsearchOperator.greaterThanOrEqual
206
+ | ElasticsearchOperator.lessThanEqual;
207
+
208
+ export enum AggregationType {
209
+ term = 'TERM',
210
+ range = 'RANGE',
211
+ }
212
+
213
+ export type TermAggregation = {
214
+ titles: MultiLangValue & { [local in (typeof SUPPORTED_LANGUAGES)[number]]: string };
215
+ fieldId: string;
216
+ type: AggregationType.term;
217
+
218
+ orderBy?: 'count' | 'field';
219
+ } & (
220
+ | {
221
+ fieldType: FieldTypes.picklist;
222
+ picklistId: string;
223
+ }
224
+ | {
225
+ fieldType: FieldTypes.number;
226
+ meta?: NumberMeta;
227
+ }
228
+ | {
229
+ fieldType: Exclude<FieldTypes, FieldTypes.picklist | FieldTypes.number>;
230
+ }
231
+ );
232
+
233
+ export type Range =
234
+ | {
235
+ start: number;
236
+ end?: number;
237
+ }
238
+ | {
239
+ start?: number;
240
+ end: number;
241
+ }
242
+ | {
243
+ start: number;
244
+ end: number;
245
+ };
246
+
247
+ export type RangeAggregation = {
248
+ titles: MultiLangValue & { [local in (typeof SUPPORTED_LANGUAGES)[number]]: string };
249
+ fieldId: string;
250
+ type: AggregationType.range;
251
+ step: number;
252
+ ranges: Range[];
253
+ format?: NumberMeta;
254
+ };
255
+
256
+ export type Aggregation = TermAggregation | RangeAggregation;
257
+
258
+ export type AggregationRequest = {
259
+ fullText?: string;
260
+ filters: ComplexFilter<AggFilterOperator>[];
261
+ geoFilters?: GeoFilter[];
262
+ };
263
+
264
+ export type AggregationResult = {
265
+ value: string;
266
+ count: number;
267
+ from?: number;
268
+ to?: number;
269
+ };
270
+
271
+ export type AggregationResultSet = {
272
+ [field: string]: AggregationResult[];
273
+ };
274
+
275
+ export type AggregationResponse<M = {}> = {
276
+ results: AggregationResultSet;
277
+ meta: M;
278
+ };
package/src/utils.ts ADDED
@@ -0,0 +1,52 @@
1
+ import { AdHocPicklistValueDisplay } from './picklists.js';
2
+ import { MultiLangValue } from './types.js';
3
+
4
+ export type CountryInfo = {
5
+ code: string; // code is ISO 3166-1 alpha-2
6
+ name: string;
7
+ labels: {
8
+ city: string;
9
+ state: string;
10
+ postalCode?: string;
11
+ };
12
+ required: {
13
+ city: boolean;
14
+ state: boolean;
15
+ postalCode: boolean;
16
+ };
17
+ dialCode: number;
18
+ currencyCode: string;
19
+ states?: {
20
+ [code: string]: string; // code is ISO 3166-2
21
+ };
22
+ postalCodeFormat?: string;
23
+ postalCodeEx?: string;
24
+ };
25
+
26
+ export type Country = {
27
+ code: string;
28
+ name: string;
29
+ dialCode: number;
30
+ };
31
+
32
+ export type ReferenceData = {
33
+ recordTitles: AdHocRecordTitles;
34
+ picklistTitles: AdHocPicklistValueDisplay;
35
+ };
36
+
37
+ export type AdHocRecordTitles = {
38
+ [businessEntityId: string]: {
39
+ [recordId: string]: string | MultiLangValue;
40
+ };
41
+ };
42
+
43
+ export type DataRecord<T, M = undefined> = {
44
+ record: T;
45
+ meta?: M; // typically ReferenceData
46
+ actions: string[];
47
+ };
48
+
49
+ export enum PricePercentageMode {
50
+ CURRENCY = 'currency',
51
+ PERCENTAGE = 'percentage',
52
+ }