@cloudize/sdk-core 23.1.5 → 23.2.0

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.
@@ -1,322 +1,322 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.ResourceFilterType = void 0;
13
- const json_1 = require("@cloudize/json");
14
- const rest_client_1 = require("@cloudize/rest-client");
15
- const __1 = require("..");
16
- const resource_object_1 = require("./resource.object");
17
- const hash = require('object-hash');
18
- var ResourceFilterType;
19
- (function (ResourceFilterType) {
20
- ResourceFilterType["Equal"] = "equal";
21
- ResourceFilterType["NotEqual"] = "!equal";
22
- ResourceFilterType["From"] = "from";
23
- ResourceFilterType["To"] = "to";
24
- ResourceFilterType["AutoComplete"] = "autocomplete";
25
- ResourceFilterType["TextSearch"] = "text";
26
- ResourceFilterType["NearLocation"] = "near";
27
- ResourceFilterType["Exists"] = "exists";
28
- })(ResourceFilterType = exports.ResourceFilterType || (exports.ResourceFilterType = {}));
29
- class ResourceContainer {
30
- constructor(params) {
31
- this._data = undefined;
32
- this._includes = {};
33
- this._restClient = (0, json_1.isDefined)(params === null || params === void 0 ? void 0 : params.restClient) ? params === null || params === void 0 ? void 0 : params.restClient : new rest_client_1.RestClient();
34
- this._sdkConfig = (0, json_1.isDefined)(params === null || params === void 0 ? void 0 : params.sdkConfig) ? params === null || params === void 0 ? void 0 : params.sdkConfig : (0, __1.SDKConfig)();
35
- this.headerParams = {};
36
- this.pathParams = {};
37
- this._queryParams = {
38
- includes: {},
39
- filters: {},
40
- sort: undefined,
41
- pagination: {},
42
- };
43
- }
44
- get data() {
45
- throw new Error('Method or Property not implemented.');
46
- }
47
- get includes() {
48
- return this._includes;
49
- }
50
- get restClient() {
51
- return this._restClient;
52
- }
53
- get sdkConfig() {
54
- return this._sdkConfig;
55
- }
56
- get uri() {
57
- let uriPath = this.EndpointPath();
58
- for (const pathParam in this.pathParams) {
59
- if ((0, json_1.hasProperty)(this.pathParams, pathParam)) {
60
- uriPath = uriPath.replace(`{${pathParam}}`, this.pathParams[pathParam]);
61
- }
62
- }
63
- return uriPath;
64
- }
65
- isResourceObject(value) {
66
- return (0, json_1.isObject)(value);
67
- }
68
- isResourceList(value) {
69
- return (0, json_1.isArray)(value);
70
- }
71
- EndpointContentType() {
72
- throw new Error('Method or Property not implemented.');
73
- }
74
- EndpointPath() {
75
- throw new Error('Method or Property not implemented.');
76
- }
77
- ClearData() {
78
- this._data = undefined;
79
- this._includes = {};
80
- }
81
- AddResourceToMemoryStructure(obj) {
82
- if ((0, json_1.isDefined)(this.data)) {
83
- if (this.isResourceObject(this.data)) {
84
- const currentObj = this.data;
85
- this._data = [currentObj];
86
- }
87
- if (this.isResourceList(this.data)) {
88
- this.data.push(obj);
89
- }
90
- }
91
- else {
92
- this._data = obj;
93
- }
94
- this._countQueryHash = undefined;
95
- }
96
- RemoveResourceFromMemoryStructure(resource) {
97
- if (this.isResourceList(this.data)) {
98
- this.data.forEach((item, index) => {
99
- if (this.isResourceList(this.data) && (item.id === resource.id))
100
- this.data.splice(index, 1);
101
- });
102
- }
103
- else if (this.isResourceObject(this.data) && this.data.id === resource.id) {
104
- this._data = undefined;
105
- }
106
- this._countQueryHash = undefined;
107
- }
108
- LoadResourceData(resourceData) {
109
- if ((0, json_1.hasProperty)(resourceData, 'type') && (0, json_1.isString)(resourceData.type)) {
110
- if ((0, json_1.hasProperty)(resourceData, 'id') && (0, json_1.isString)(resourceData.id)) {
111
- const ResourceClass = this.sdkConfig.ResourceClass(resourceData.type);
112
- return new ResourceClass(this, resource_object_1.ResourceObjectMode.ExistingDocument).LoadData(resourceData);
113
- }
114
- throw new __1.SDKException('INVALID-RESOURCE-ID', 'The resource being loaded doesn\'t have the required resource id.');
115
- }
116
- throw new __1.SDKException('INVALID-RESOURCE-TYPE', 'The resource being loaded doesn\'t have the required resource type.');
117
- }
118
- LoadResponse(response) {
119
- this.ClearData();
120
- if ((0, json_1.hasProperty)(response.data, 'data')) {
121
- if ((0, json_1.isArray)(response.data.data)) {
122
- this._data = [];
123
- for (const resourceData of response.data.data) {
124
- this.AddResourceToMemoryStructure(this.LoadResourceData(resourceData));
125
- }
126
- }
127
- else if ((0, json_1.isObject)(response.data.data)) {
128
- this.AddResourceToMemoryStructure(this.LoadResourceData(response.data.data));
129
- }
130
- }
131
- if ((0, json_1.hasProperty)(response.data, 'included')) {
132
- if ((0, json_1.isArray)(response.data.included)) {
133
- for (const resourceData of response.data.included) {
134
- const resourceObject = this.LoadResourceData(resourceData);
135
- if ((0, json_1.isUndefined)(this._includes[resourceObject.type]))
136
- this._includes[resourceObject.type] = {};
137
- this._includes[resourceObject.type][resourceObject.id] = resourceObject;
138
- }
139
- }
140
- }
141
- }
142
- Add() {
143
- throw new Error('Method or Property not implemented.');
144
- }
145
- Delete(resource) {
146
- return __awaiter(this, void 0, void 0, function* () {
147
- if ((0, json_1.isDefined)(resource.id)) {
148
- const queryUri = `${this.uri}/${resource.id}`;
149
- const queryHeaders = this.GetHeaders('DELETE');
150
- const queryOptions = {
151
- queryParams: this.GetQueryParams(),
152
- };
153
- this.InitParams();
154
- (0, json_1.redactUndefinedValues)(queryOptions);
155
- yield this._restClient.Delete(queryUri, queryHeaders, queryOptions);
156
- this.RemoveResourceFromMemoryStructure(resource);
157
- }
158
- else {
159
- this.RemoveResourceFromMemoryStructure(resource);
160
- }
161
- });
162
- }
163
- Count() {
164
- return __awaiter(this, void 0, void 0, function* () {
165
- const queryUri = `${this.uri}`;
166
- const queryHeaders = this.GetHeaders('COUNT');
167
- const queryOptions = {
168
- queryParams: this.GetQueryParams(),
169
- };
170
- if ((0, json_1.isDefinedAndNotNull)(queryOptions.queryParams)) {
171
- (0, json_1.extractAndRedact)(queryOptions.queryParams, 'include');
172
- (0, json_1.extractAndRedact)(queryOptions.queryParams, 'page[number]');
173
- (0, json_1.extractAndRedact)(queryOptions.queryParams, 'page[offset]');
174
- (0, json_1.extractAndRedact)(queryOptions.queryParams, 'page[size]');
175
- (0, json_1.extractAndRedact)(queryOptions.queryParams, 'sort');
176
- }
177
- (0, json_1.redactUndefinedValues)(queryOptions);
178
- const queryParams = {
179
- uri: queryUri,
180
- headers: queryHeaders,
181
- queryOptions,
182
- };
183
- const queryHash = hash(queryParams);
184
- if ((0, json_1.isDefinedAndNotNull)(this._countQueryHash) && (this._countQueryHash === queryHash) && (0, json_1.isDefinedAndNotNull)(this._count)) {
185
- return this._count;
186
- }
187
- if ((0, json_1.isUndefinedOrNull)(queryOptions.queryParams))
188
- queryOptions.queryParams = {};
189
- queryOptions.queryParams['meta-action'] = 'count';
190
- const response = yield this._restClient.Get(queryUri, queryHeaders, queryOptions);
191
- if ((0, json_1.hasProperty)(response, 'data') && (0, json_1.hasProperty)(response.data, 'meta')
192
- && (0, json_1.hasProperty)(response.data.meta, 'count') && (0, json_1.isNumber)(response.data.meta.count)) {
193
- this._count = response.data.meta.count;
194
- this._countQueryHash = queryHash;
195
- return this._count;
196
- }
197
- throw new __1.SDKException('COUNT-FAILED', 'The request to count the number of resources related '
198
- + 'to this query was unsuccessful.');
199
- });
200
- }
201
- Find() {
202
- return __awaiter(this, void 0, void 0, function* () {
203
- this.ClearData();
204
- const queryUri = `${this.uri}`;
205
- const queryHeaders = this.GetHeaders('FIND');
206
- const queryOptions = {
207
- queryParams: this.GetQueryParams(),
208
- };
209
- this.InitParams();
210
- (0, json_1.redactUndefinedValues)(queryOptions);
211
- this.LoadResponse(yield this._restClient.Get(queryUri, queryHeaders, queryOptions));
212
- });
213
- }
214
- Get(id) {
215
- return __awaiter(this, void 0, void 0, function* () {
216
- this.ClearData();
217
- const queryUri = `${this.uri}/${id}`;
218
- const queryHeaders = this.GetHeaders('GET');
219
- const queryOptions = {
220
- queryParams: this.GetQueryParams(),
221
- };
222
- this.InitParams();
223
- (0, json_1.redactUndefinedValues)(queryOptions);
224
- this.LoadResponse(yield this._restClient.Get(queryUri, queryHeaders, queryOptions));
225
- });
226
- }
227
- InitParams() {
228
- this._queryParams = {
229
- includes: {},
230
- filters: {},
231
- sort: undefined,
232
- pagination: {},
233
- };
234
- }
235
- InitializeDefaultHeaderParams() {
236
- const headers = {};
237
- if ((0, json_1.isDefined)(this.headerParams)) {
238
- for (const headerParamName in this.headerParams) {
239
- if ((0, json_1.hasProperty)(this.headerParams, headerParamName)) {
240
- headers[headerParamName] = this.headerParams[headerParamName];
241
- }
242
- }
243
- }
244
- return headers;
245
- }
246
- GetHeaders(action) {
247
- const headers = this.InitializeDefaultHeaderParams();
248
- switch (action) {
249
- case 'GET':
250
- case 'COUNT':
251
- case 'FIND':
252
- headers.Accept = this.EndpointContentType();
253
- break;
254
- default:
255
- headers.Accept = this.EndpointContentType();
256
- headers['Content-Type'] = this.EndpointContentType();
257
- break;
258
- }
259
- if ((0, json_1.isDefined)(this.sdkConfig.apiKey)) {
260
- headers['x-api-key'] = this.sdkConfig.apiKey;
261
- }
262
- if ((0, json_1.isDefined)(this.sdkConfig.accessToken)) {
263
- headers.Authorization = `Bearer ${this.sdkConfig.accessToken}`;
264
- }
265
- return headers;
266
- }
267
- GetQueryParams() {
268
- const queryParams = {};
269
- for (const filterName in this._queryParams.filters) {
270
- if ((0, json_1.hasProperty)(this._queryParams.filters, filterName)) {
271
- queryParams[`filter[${filterName}]`] = this._queryParams.filters[filterName];
272
- }
273
- }
274
- const includeList = [];
275
- for (const includeName in this._queryParams.includes) {
276
- if ((0, json_1.hasProperty)(this._queryParams.includes, includeName)) {
277
- includeList.push(includeName);
278
- }
279
- }
280
- if (includeList.length > 0)
281
- queryParams.include = includeList.join(',');
282
- if ((0, json_1.hasProperty)(this._queryParams.pagination, 'offset'))
283
- queryParams['page[offset]'] = this._queryParams.pagination.offset;
284
- if ((0, json_1.hasProperty)(this._queryParams.pagination, 'page'))
285
- queryParams['page[number]'] = this._queryParams.pagination.page;
286
- if ((0, json_1.hasProperty)(this._queryParams.pagination, 'size'))
287
- queryParams['page[size]'] = this._queryParams.pagination.size;
288
- if ((0, json_1.isDefined)(this._queryParams.sort))
289
- queryParams.sort = this._queryParams.sort;
290
- if ((0, json_1.isEmpty)(queryParams))
291
- return undefined;
292
- return queryParams;
293
- }
294
- IncludedObject(type, id) {
295
- throw new Error('Method or Property not implemented.');
296
- }
297
- Filter(filter, selector, value) {
298
- this._queryParams.filters[`${selector}:${filter}`] = value;
299
- return this;
300
- }
301
- Sort(option) {
302
- this._queryParams.sort = option;
303
- return this;
304
- }
305
- Include(include) {
306
- this._queryParams.includes[include] = true;
307
- return this;
308
- }
309
- PageOffset(pageOffset, pageSize) {
310
- (0, json_1.extractAndRedact)(this._queryParams.pagination, 'page');
311
- this._queryParams.pagination.offset = pageOffset;
312
- this._queryParams.pagination.size = pageSize;
313
- return this;
314
- }
315
- PageNumber(pageNumber, pageSize) {
316
- (0, json_1.extractAndRedact)(this._queryParams.pagination, 'offset');
317
- this._queryParams.pagination.page = pageNumber;
318
- this._queryParams.pagination.size = pageSize;
319
- return this;
320
- }
321
- }
322
- exports.default = ResourceContainer;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ResourceFilterType = void 0;
13
+ const json_1 = require("@cloudize/json");
14
+ const rest_client_1 = require("@cloudize/rest-client");
15
+ const __1 = require("..");
16
+ const resource_object_1 = require("./resource.object");
17
+ const hash = require('object-hash');
18
+ var ResourceFilterType;
19
+ (function (ResourceFilterType) {
20
+ ResourceFilterType["Equal"] = "equal";
21
+ ResourceFilterType["NotEqual"] = "!equal";
22
+ ResourceFilterType["From"] = "from";
23
+ ResourceFilterType["To"] = "to";
24
+ ResourceFilterType["AutoComplete"] = "autocomplete";
25
+ ResourceFilterType["TextSearch"] = "text";
26
+ ResourceFilterType["NearLocation"] = "near";
27
+ ResourceFilterType["Exists"] = "exists";
28
+ })(ResourceFilterType = exports.ResourceFilterType || (exports.ResourceFilterType = {}));
29
+ class ResourceContainer {
30
+ constructor(params) {
31
+ this._data = undefined;
32
+ this._includes = {};
33
+ this._restClient = (0, json_1.isDefined)(params === null || params === void 0 ? void 0 : params.restClient) ? params === null || params === void 0 ? void 0 : params.restClient : new rest_client_1.RestClient();
34
+ this._sdkConfig = (0, json_1.isDefined)(params === null || params === void 0 ? void 0 : params.sdkConfig) ? params === null || params === void 0 ? void 0 : params.sdkConfig : (0, __1.SDKConfig)();
35
+ this.headerParams = {};
36
+ this.pathParams = {};
37
+ this._queryParams = {
38
+ includes: {},
39
+ filters: {},
40
+ sort: undefined,
41
+ pagination: {},
42
+ };
43
+ }
44
+ get data() {
45
+ throw new Error('Method or Property not implemented.');
46
+ }
47
+ get includes() {
48
+ return this._includes;
49
+ }
50
+ get restClient() {
51
+ return this._restClient;
52
+ }
53
+ get sdkConfig() {
54
+ return this._sdkConfig;
55
+ }
56
+ get uri() {
57
+ let uriPath = this.EndpointPath();
58
+ for (const pathParam in this.pathParams) {
59
+ if ((0, json_1.hasProperty)(this.pathParams, pathParam)) {
60
+ uriPath = uriPath.replace(`{${pathParam}}`, this.pathParams[pathParam]);
61
+ }
62
+ }
63
+ return uriPath;
64
+ }
65
+ isResourceObject(value) {
66
+ return (0, json_1.isObject)(value);
67
+ }
68
+ isResourceList(value) {
69
+ return (0, json_1.isArray)(value);
70
+ }
71
+ EndpointContentType() {
72
+ throw new Error('Method or Property not implemented.');
73
+ }
74
+ EndpointPath() {
75
+ throw new Error('Method or Property not implemented.');
76
+ }
77
+ ClearData() {
78
+ this._data = undefined;
79
+ this._includes = {};
80
+ }
81
+ AddResourceToMemoryStructure(obj) {
82
+ if ((0, json_1.isDefined)(this.data)) {
83
+ if (this.isResourceObject(this.data)) {
84
+ const currentObj = this.data;
85
+ this._data = [currentObj];
86
+ }
87
+ if (this.isResourceList(this.data)) {
88
+ this.data.push(obj);
89
+ }
90
+ }
91
+ else {
92
+ this._data = obj;
93
+ }
94
+ this._countQueryHash = undefined;
95
+ }
96
+ RemoveResourceFromMemoryStructure(resource) {
97
+ if (this.isResourceList(this.data)) {
98
+ this.data.forEach((item, index) => {
99
+ if (this.isResourceList(this.data) && (item.id === resource.id))
100
+ this.data.splice(index, 1);
101
+ });
102
+ }
103
+ else if (this.isResourceObject(this.data) && this.data.id === resource.id) {
104
+ this._data = undefined;
105
+ }
106
+ this._countQueryHash = undefined;
107
+ }
108
+ LoadResourceData(resourceData) {
109
+ if ((0, json_1.hasProperty)(resourceData, 'type') && (0, json_1.isString)(resourceData.type)) {
110
+ if ((0, json_1.hasProperty)(resourceData, 'id') && (0, json_1.isString)(resourceData.id)) {
111
+ const ResourceClass = this.sdkConfig.ResourceClass(resourceData.type);
112
+ return new ResourceClass(this, resource_object_1.ResourceObjectMode.ExistingDocument).LoadData(resourceData);
113
+ }
114
+ throw new __1.SDKException('INVALID-RESOURCE-ID', 'The resource being loaded doesn\'t have the required resource id.');
115
+ }
116
+ throw new __1.SDKException('INVALID-RESOURCE-TYPE', 'The resource being loaded doesn\'t have the required resource type.');
117
+ }
118
+ LoadResponse(response) {
119
+ this.ClearData();
120
+ if ((0, json_1.hasProperty)(response.data, 'data')) {
121
+ if ((0, json_1.isArray)(response.data.data)) {
122
+ this._data = [];
123
+ for (const resourceData of response.data.data) {
124
+ this.AddResourceToMemoryStructure(this.LoadResourceData(resourceData));
125
+ }
126
+ }
127
+ else if ((0, json_1.isObject)(response.data.data)) {
128
+ this.AddResourceToMemoryStructure(this.LoadResourceData(response.data.data));
129
+ }
130
+ }
131
+ if ((0, json_1.hasProperty)(response.data, 'included')) {
132
+ if ((0, json_1.isArray)(response.data.included)) {
133
+ for (const resourceData of response.data.included) {
134
+ const resourceObject = this.LoadResourceData(resourceData);
135
+ if ((0, json_1.isUndefined)(this._includes[resourceObject.type]))
136
+ this._includes[resourceObject.type] = {};
137
+ this._includes[resourceObject.type][resourceObject.id] = resourceObject;
138
+ }
139
+ }
140
+ }
141
+ }
142
+ Add() {
143
+ throw new Error('Method or Property not implemented.');
144
+ }
145
+ Delete(resource) {
146
+ return __awaiter(this, void 0, void 0, function* () {
147
+ if ((0, json_1.isDefined)(resource.id)) {
148
+ const queryUri = `${this.uri}/${resource.id}`;
149
+ const queryHeaders = this.GetHeaders('DELETE');
150
+ const queryOptions = {
151
+ queryParams: this.GetQueryParams(),
152
+ };
153
+ this.InitParams();
154
+ (0, json_1.redactUndefinedValues)(queryOptions);
155
+ yield this._restClient.Delete(queryUri, queryHeaders, queryOptions);
156
+ this.RemoveResourceFromMemoryStructure(resource);
157
+ }
158
+ else {
159
+ this.RemoveResourceFromMemoryStructure(resource);
160
+ }
161
+ });
162
+ }
163
+ Count() {
164
+ return __awaiter(this, void 0, void 0, function* () {
165
+ const queryUri = `${this.uri}`;
166
+ const queryHeaders = this.GetHeaders('COUNT');
167
+ const queryOptions = {
168
+ queryParams: this.GetQueryParams(),
169
+ };
170
+ if ((0, json_1.isDefinedAndNotNull)(queryOptions.queryParams)) {
171
+ (0, json_1.extractAndRedact)(queryOptions.queryParams, 'include');
172
+ (0, json_1.extractAndRedact)(queryOptions.queryParams, 'page[number]');
173
+ (0, json_1.extractAndRedact)(queryOptions.queryParams, 'page[offset]');
174
+ (0, json_1.extractAndRedact)(queryOptions.queryParams, 'page[size]');
175
+ (0, json_1.extractAndRedact)(queryOptions.queryParams, 'sort');
176
+ }
177
+ (0, json_1.redactUndefinedValues)(queryOptions);
178
+ const queryParams = {
179
+ uri: queryUri,
180
+ headers: queryHeaders,
181
+ queryOptions,
182
+ };
183
+ const queryHash = hash(queryParams);
184
+ if ((0, json_1.isDefinedAndNotNull)(this._countQueryHash) && (this._countQueryHash === queryHash) && (0, json_1.isDefinedAndNotNull)(this._count)) {
185
+ return this._count;
186
+ }
187
+ if ((0, json_1.isUndefinedOrNull)(queryOptions.queryParams))
188
+ queryOptions.queryParams = {};
189
+ queryOptions.queryParams['meta-action'] = 'count';
190
+ const response = yield this._restClient.Get(queryUri, queryHeaders, queryOptions);
191
+ if ((0, json_1.hasProperty)(response, 'data') && (0, json_1.hasProperty)(response.data, 'meta')
192
+ && (0, json_1.hasProperty)(response.data.meta, 'count') && (0, json_1.isNumber)(response.data.meta.count)) {
193
+ this._count = response.data.meta.count;
194
+ this._countQueryHash = queryHash;
195
+ return this._count;
196
+ }
197
+ throw new __1.SDKException('COUNT-FAILED', 'The request to count the number of resources related '
198
+ + 'to this query was unsuccessful.');
199
+ });
200
+ }
201
+ Find() {
202
+ return __awaiter(this, void 0, void 0, function* () {
203
+ this.ClearData();
204
+ const queryUri = `${this.uri}`;
205
+ const queryHeaders = this.GetHeaders('FIND');
206
+ const queryOptions = {
207
+ queryParams: this.GetQueryParams(),
208
+ };
209
+ this.InitParams();
210
+ (0, json_1.redactUndefinedValues)(queryOptions);
211
+ this.LoadResponse(yield this._restClient.Get(queryUri, queryHeaders, queryOptions));
212
+ });
213
+ }
214
+ Get(id) {
215
+ return __awaiter(this, void 0, void 0, function* () {
216
+ this.ClearData();
217
+ const queryUri = `${this.uri}/${id}`;
218
+ const queryHeaders = this.GetHeaders('GET');
219
+ const queryOptions = {
220
+ queryParams: this.GetQueryParams(),
221
+ };
222
+ this.InitParams();
223
+ (0, json_1.redactUndefinedValues)(queryOptions);
224
+ this.LoadResponse(yield this._restClient.Get(queryUri, queryHeaders, queryOptions));
225
+ });
226
+ }
227
+ InitParams() {
228
+ this._queryParams = {
229
+ includes: {},
230
+ filters: {},
231
+ sort: undefined,
232
+ pagination: {},
233
+ };
234
+ }
235
+ InitializeDefaultHeaderParams() {
236
+ const headers = {};
237
+ if ((0, json_1.isDefined)(this.headerParams)) {
238
+ for (const headerParamName in this.headerParams) {
239
+ if ((0, json_1.hasProperty)(this.headerParams, headerParamName)) {
240
+ headers[headerParamName] = this.headerParams[headerParamName];
241
+ }
242
+ }
243
+ }
244
+ return headers;
245
+ }
246
+ GetHeaders(action) {
247
+ const headers = this.InitializeDefaultHeaderParams();
248
+ switch (action) {
249
+ case 'GET':
250
+ case 'COUNT':
251
+ case 'FIND':
252
+ headers.Accept = this.EndpointContentType();
253
+ break;
254
+ default:
255
+ headers.Accept = this.EndpointContentType();
256
+ headers['Content-Type'] = this.EndpointContentType();
257
+ break;
258
+ }
259
+ if ((0, json_1.isDefined)(this.sdkConfig.apiKey)) {
260
+ headers['x-api-key'] = this.sdkConfig.apiKey;
261
+ }
262
+ if ((0, json_1.isDefined)(this.sdkConfig.accessToken)) {
263
+ headers.Authorization = `Bearer ${this.sdkConfig.accessToken}`;
264
+ }
265
+ return headers;
266
+ }
267
+ GetQueryParams() {
268
+ const queryParams = {};
269
+ for (const filterName in this._queryParams.filters) {
270
+ if ((0, json_1.hasProperty)(this._queryParams.filters, filterName)) {
271
+ queryParams[`filter[${filterName}]`] = this._queryParams.filters[filterName];
272
+ }
273
+ }
274
+ const includeList = [];
275
+ for (const includeName in this._queryParams.includes) {
276
+ if ((0, json_1.hasProperty)(this._queryParams.includes, includeName)) {
277
+ includeList.push(includeName);
278
+ }
279
+ }
280
+ if (includeList.length > 0)
281
+ queryParams.include = includeList.join(',');
282
+ if ((0, json_1.hasProperty)(this._queryParams.pagination, 'offset'))
283
+ queryParams['page[offset]'] = this._queryParams.pagination.offset;
284
+ if ((0, json_1.hasProperty)(this._queryParams.pagination, 'page'))
285
+ queryParams['page[number]'] = this._queryParams.pagination.page;
286
+ if ((0, json_1.hasProperty)(this._queryParams.pagination, 'size'))
287
+ queryParams['page[size]'] = this._queryParams.pagination.size;
288
+ if ((0, json_1.isDefined)(this._queryParams.sort))
289
+ queryParams.sort = this._queryParams.sort;
290
+ if ((0, json_1.isEmpty)(queryParams))
291
+ return undefined;
292
+ return queryParams;
293
+ }
294
+ IncludedObject(type, id) {
295
+ throw new Error('Method or Property not implemented.');
296
+ }
297
+ Filter(filter, selector, value) {
298
+ this._queryParams.filters[`${selector}:${filter}`] = value;
299
+ return this;
300
+ }
301
+ Sort(option) {
302
+ this._queryParams.sort = option;
303
+ return this;
304
+ }
305
+ Include(include) {
306
+ this._queryParams.includes[include] = true;
307
+ return this;
308
+ }
309
+ PageOffset(pageOffset, pageSize) {
310
+ (0, json_1.extractAndRedact)(this._queryParams.pagination, 'page');
311
+ this._queryParams.pagination.offset = pageOffset;
312
+ this._queryParams.pagination.size = pageSize;
313
+ return this;
314
+ }
315
+ PageNumber(pageNumber, pageSize) {
316
+ (0, json_1.extractAndRedact)(this._queryParams.pagination, 'offset');
317
+ this._queryParams.pagination.page = pageNumber;
318
+ this._queryParams.pagination.size = pageSize;
319
+ return this;
320
+ }
321
+ }
322
+ exports.default = ResourceContainer;
@@ -1,3 +1,3 @@
1
- export type ResourceHeaderParams = {
2
- [index: string]: string;
3
- };
1
+ export type ResourceHeaderParams = {
2
+ [index: string]: string;
3
+ };
@@ -1,2 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });