@kontent-ai/delivery-sdk 16.4.3 → 16.4.4
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/.npmignore +15 -15
- package/LICENSE.md +9 -9
- package/dist/bundles/kontent-delivery.umd.js +5077 -4620
- package/dist/bundles/kontent-delivery.umd.js.map +1 -1
- package/dist/bundles/kontent-delivery.umd.min.js +1 -1
- package/dist/bundles/kontent-delivery.umd.min.js.map +1 -1
- package/dist/bundles/report.json +1 -1
- package/dist/bundles/report.min.json +1 -1
- package/dist/bundles/stats.json +7195 -5946
- package/dist/bundles/stats.min.json +11923 -10797
- package/dist/cjs/sdk-info.generated.js +1 -1
- package/dist/es6/sdk-info.generated.js +1 -1
- package/dist/esnext/sdk-info.generated.js +1 -1
- package/lib/client/delivery-client.factory.ts +9 -9
- package/lib/client/delivery-client.ts +163 -163
- package/lib/client/idelivery-client.interface.ts +110 -110
- package/lib/client/index.ts +3 -3
- package/lib/config/delivery-configs.ts +98 -98
- package/lib/config/index.ts +1 -1
- package/lib/contracts/contracts.ts +265 -265
- package/lib/contracts/index.ts +1 -1
- package/lib/elements/element-models.ts +89 -89
- package/lib/elements/element-resolver.ts +3 -3
- package/lib/elements/element-type.ts +16 -16
- package/lib/elements/elements.ts +70 -70
- package/lib/elements/index.ts +4 -4
- package/lib/images/image-url-transformation-builder.factory.ts +5 -5
- package/lib/images/image-url-transformation-builder.ts +181 -181
- package/lib/images/image.models.ts +4 -4
- package/lib/images/index.ts +3 -3
- package/lib/index.ts +12 -12
- package/lib/mappers/element.mapper.ts +504 -504
- package/lib/mappers/generic-element.mapper.ts +20 -20
- package/lib/mappers/index.ts +8 -8
- package/lib/mappers/item.mapper.ts +181 -181
- package/lib/mappers/language.mapper.ts +24 -24
- package/lib/mappers/sync.mapper.ts +32 -32
- package/lib/mappers/taxonomy.mapper.ts +77 -77
- package/lib/mappers/type.mapper.ts +76 -76
- package/lib/mappers/used-in.mapper.ts +20 -20
- package/lib/models/common/base-responses.ts +13 -13
- package/lib/models/common/common-models.ts +118 -118
- package/lib/models/common/filters.ts +280 -280
- package/lib/models/common/headers.ts +5 -5
- package/lib/models/common/index.ts +7 -7
- package/lib/models/common/pagination.class.ts +7 -7
- package/lib/models/common/parameters.ts +189 -189
- package/lib/models/common/sort-order.ts +1 -1
- package/lib/models/content-type-models.ts +42 -42
- package/lib/models/element-models.ts +51 -51
- package/lib/models/index.ts +9 -9
- package/lib/models/item-models.ts +192 -192
- package/lib/models/language-models.ts +17 -17
- package/lib/models/responses.ts +137 -137
- package/lib/models/sync-models.ts +18 -18
- package/lib/models/taxonomy-models.ts +25 -25
- package/lib/query/common/base-item-listing-query.class.ts +274 -274
- package/lib/query/common/base-listing-query.class.ts +95 -95
- package/lib/query/common/base-query.class.ts +148 -148
- package/lib/query/element/element-query.class.ts +45 -45
- package/lib/query/index.ts +13 -13
- package/lib/query/item/multiple-items-query.class.ts +183 -183
- package/lib/query/item/single-item-query.class.ts +106 -106
- package/lib/query/items-feed/items-feed-query.class.ts +191 -191
- package/lib/query/language/languages-query.class.ts +91 -91
- package/lib/query/sync/initialize-sync-query.class.ts +83 -83
- package/lib/query/sync/sync-changes-query.class.ts +56 -56
- package/lib/query/taxonomy/taxonomies-query.class.ts +82 -82
- package/lib/query/taxonomy/taxonomy-query.class.ts +50 -50
- package/lib/query/type/multiple-type-query.class.ts +95 -95
- package/lib/query/type/single-type-query.class.ts +45 -45
- package/lib/query/used-in/used-in-query.class.ts +126 -126
- package/lib/sdk-info.generated.ts +1 -1
- package/lib/services/base-delivery-query.service.ts +375 -375
- package/lib/services/delivery-query.service.ts +336 -336
- package/lib/services/index.ts +2 -2
- package/lib/services/mapping.service.ts +223 -223
- package/lib/utilities/codename.helper.ts +10 -10
- package/lib/utilities/delivery-url.helper.ts +11 -11
- package/lib/utilities/enum.helper.ts +38 -38
- package/lib/utilities/index.ts +3 -3
- package/package.json +96 -96
- package/readme.md +531 -531
|
@@ -1,336 +1,336 @@
|
|
|
1
|
-
import { IHttpService } from '@kontent-ai/core-sdk';
|
|
2
|
-
import { IDeliveryClientConfig } from '../config';
|
|
3
|
-
import { Contracts } from '../contracts';
|
|
4
|
-
import {
|
|
5
|
-
Responses,
|
|
6
|
-
IContentItem,
|
|
7
|
-
IContentTypeQueryConfig,
|
|
8
|
-
IGroupedNetworkResponse,
|
|
9
|
-
IItemQueryConfig,
|
|
10
|
-
IDeliveryNetworkResponse,
|
|
11
|
-
ILanguagesQueryConfig,
|
|
12
|
-
ITaxonomyQueryConfig,
|
|
13
|
-
ISyncInitQueryConfig,
|
|
14
|
-
ClientTypes
|
|
15
|
-
} from '../models';
|
|
16
|
-
import {
|
|
17
|
-
IKontentListAllResponse,
|
|
18
|
-
IKontentListResponse,
|
|
19
|
-
IListAllQueryConfig,
|
|
20
|
-
ISDKInfo
|
|
21
|
-
} from '../models/common/common-models';
|
|
22
|
-
import { BaseDeliveryQueryService } from './base-delivery-query.service';
|
|
23
|
-
import { IMappingService } from './mapping.service';
|
|
24
|
-
|
|
25
|
-
export class QueryService<TClientTypes extends ClientTypes> extends BaseDeliveryQueryService<TClientTypes> {
|
|
26
|
-
constructor(
|
|
27
|
-
config: IDeliveryClientConfig,
|
|
28
|
-
httpService: IHttpService<any>,
|
|
29
|
-
sdkInfo: ISDKInfo,
|
|
30
|
-
mappingService: IMappingService<TClientTypes>
|
|
31
|
-
) {
|
|
32
|
-
super(config, httpService, sdkInfo, mappingService);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Gets single item from given url
|
|
37
|
-
* @param url Url used to get single item
|
|
38
|
-
* @param queryConfig Query configuration
|
|
39
|
-
*/
|
|
40
|
-
async getSingleItemAsync<TContentItem extends IContentItem = TClientTypes['contentItemType']>(
|
|
41
|
-
url: string,
|
|
42
|
-
queryConfig: IItemQueryConfig
|
|
43
|
-
): Promise<
|
|
44
|
-
IDeliveryNetworkResponse<
|
|
45
|
-
Responses.IViewContentItemResponse<TContentItem, TClientTypes['contentItemType']>,
|
|
46
|
-
Contracts.IViewContentItemContract
|
|
47
|
-
>
|
|
48
|
-
> {
|
|
49
|
-
const response = await this.getResponseAsync<Contracts.IViewContentItemContract>(url, queryConfig);
|
|
50
|
-
|
|
51
|
-
return this.mapNetworkResponse<
|
|
52
|
-
Responses.IViewContentItemResponse<TContentItem, TClientTypes['contentItemType']>,
|
|
53
|
-
Contracts.IViewContentItemContract
|
|
54
|
-
>(this.mappingService.viewContentItemResponse<TContentItem>(response.data), response);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Gets single feed response. Might not contain all items in your environment.
|
|
59
|
-
* @param url Url
|
|
60
|
-
* @param queryConfig Query configuration
|
|
61
|
-
*/
|
|
62
|
-
async getItemsFeed<TContentItem extends IContentItem = TClientTypes['contentItemType']>(
|
|
63
|
-
url: string,
|
|
64
|
-
queryConfig: IItemQueryConfig
|
|
65
|
-
): Promise<
|
|
66
|
-
IDeliveryNetworkResponse<
|
|
67
|
-
Responses.IListItemsFeedResponse<TContentItem, TClientTypes['contentItemType']>,
|
|
68
|
-
Contracts.IItemsFeedContract
|
|
69
|
-
>
|
|
70
|
-
> {
|
|
71
|
-
const response = await this.getResponseAsync<Contracts.IItemsFeedContract>(url, queryConfig);
|
|
72
|
-
|
|
73
|
-
return this.mapNetworkResponse(this.mappingService.itemsFeedResponse<TContentItem>(response.data), response);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Gets single used in response. Might not contain all used in references.
|
|
78
|
-
* @param url Url
|
|
79
|
-
* @param queryConfig Query configuration
|
|
80
|
-
*/
|
|
81
|
-
async getUsedIn(
|
|
82
|
-
url: string,
|
|
83
|
-
queryConfig: IItemQueryConfig
|
|
84
|
-
): Promise<IDeliveryNetworkResponse<Responses.IUsedInResponse<TClientTypes>, Contracts.IUsedInItemsContract>> {
|
|
85
|
-
const response = await this.getResponseAsync<Contracts.IUsedInItemsContract>(url, queryConfig);
|
|
86
|
-
|
|
87
|
-
return this.mapNetworkResponse(this.mappingService.usedInResponse(response.data), response);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Gets multiple items from given url
|
|
92
|
-
* @param url Url used to get multiple items
|
|
93
|
-
* @param queryConfig Query configuration
|
|
94
|
-
*/
|
|
95
|
-
async getMultipleItems<TContentItem extends IContentItem = TClientTypes['contentItemType']>(
|
|
96
|
-
url: string,
|
|
97
|
-
queryConfig: IItemQueryConfig
|
|
98
|
-
): Promise<
|
|
99
|
-
IDeliveryNetworkResponse<
|
|
100
|
-
Responses.IListContentItemsResponse<TContentItem, TClientTypes['contentItemType']>,
|
|
101
|
-
Contracts.IListContentItemsContract
|
|
102
|
-
>
|
|
103
|
-
> {
|
|
104
|
-
const response = await this.getResponseAsync<Contracts.IListContentItemsContract>(url, queryConfig);
|
|
105
|
-
|
|
106
|
-
return this.mapNetworkResponse(this.mappingService.listContentItemsResponse(response.data), response);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Gets single content type from given url
|
|
111
|
-
* @param url Url used to get single type
|
|
112
|
-
* @param queryConfig Query configuration
|
|
113
|
-
*/
|
|
114
|
-
async getSingleType(
|
|
115
|
-
url: string,
|
|
116
|
-
queryConfig: IContentTypeQueryConfig
|
|
117
|
-
): Promise<
|
|
118
|
-
IDeliveryNetworkResponse<
|
|
119
|
-
Responses.IViewContentTypeResponse<TClientTypes['contentTypeCodenames']>,
|
|
120
|
-
Contracts.IViewContentTypeContract
|
|
121
|
-
>
|
|
122
|
-
> {
|
|
123
|
-
const response = await this.getResponseAsync<Contracts.IViewContentTypeContract>(url, queryConfig);
|
|
124
|
-
|
|
125
|
-
return this.mapNetworkResponse(this.mappingService.viewContentTypeResponse(response.data), response);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Gets multiple content types from given url
|
|
130
|
-
* @param url Url used to get multiple types
|
|
131
|
-
* @param queryConfig Query configuration
|
|
132
|
-
*/
|
|
133
|
-
async getMultipleTypes(
|
|
134
|
-
url: string,
|
|
135
|
-
queryConfig: IContentTypeQueryConfig
|
|
136
|
-
): Promise<
|
|
137
|
-
IDeliveryNetworkResponse<
|
|
138
|
-
Responses.IListContentTypesResponse<TClientTypes['contentTypeCodenames']>,
|
|
139
|
-
Contracts.IListContentTypeContract
|
|
140
|
-
>
|
|
141
|
-
> {
|
|
142
|
-
const response = await this.getResponseAsync<Contracts.IListContentTypeContract>(url, queryConfig);
|
|
143
|
-
|
|
144
|
-
return this.mapNetworkResponse(this.mappingService.listContentTypesResponse(response.data), response);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Initializes synchronization of changes in content items based on the specified parameters. After the initialization,
|
|
149
|
-
* you'll get an X-Continuation token in the response.
|
|
150
|
-
* Use the token to synchronize changes in the content items matching the initialization criteria.
|
|
151
|
-
* @param url Url
|
|
152
|
-
* @param queryConfig Query configuration
|
|
153
|
-
*/
|
|
154
|
-
async initializeSync(
|
|
155
|
-
url: string,
|
|
156
|
-
queryConfig: ISyncInitQueryConfig
|
|
157
|
-
): Promise<IDeliveryNetworkResponse<Responses.IInitializeSyncResponse, Contracts.IInitializeSyncContract>> {
|
|
158
|
-
const response = await this.postResponseAsync<Contracts.IInitializeSyncContract>(url, {}, queryConfig);
|
|
159
|
-
|
|
160
|
-
return this.mapNetworkResponse(this.mappingService.initializeContentSync(response.data), response);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Retrieve a list of delta updates to recently changed content items in the specified environment.
|
|
165
|
-
* The types of items you get is determined by the X-Continuation token you use.
|
|
166
|
-
* @param url Url used to get multiple types
|
|
167
|
-
* @param queryConfig Query configuration
|
|
168
|
-
*/
|
|
169
|
-
async syncChanges(
|
|
170
|
-
url: string,
|
|
171
|
-
queryConfig: IContentTypeQueryConfig
|
|
172
|
-
): Promise<IDeliveryNetworkResponse<Responses.ISyncChangesResponse, Contracts.ISyncChangesContract>> {
|
|
173
|
-
const response = await this.getResponseAsync<Contracts.ISyncChangesContract>(url, queryConfig);
|
|
174
|
-
|
|
175
|
-
return this.mapNetworkResponse(this.mappingService.syncChanges(response.data), response);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Gets languages
|
|
180
|
-
* @param url Url
|
|
181
|
-
* @param queryConfig Query configuration
|
|
182
|
-
*/
|
|
183
|
-
async getLanguages(
|
|
184
|
-
url: string,
|
|
185
|
-
queryConfig: ILanguagesQueryConfig
|
|
186
|
-
): Promise<
|
|
187
|
-
IDeliveryNetworkResponse<
|
|
188
|
-
Responses.IListLanguagesResponse<TClientTypes['languageCodenames']>,
|
|
189
|
-
Contracts.IListLanguagesContract
|
|
190
|
-
>
|
|
191
|
-
> {
|
|
192
|
-
const response = await this.getResponseAsync<Contracts.IListLanguagesContract>(url, queryConfig);
|
|
193
|
-
|
|
194
|
-
return this.mapNetworkResponse(this.mappingService.listLanguagesResponse(response.data), response);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Gets single taxonomy from given url
|
|
199
|
-
* @param url Url used to get single taxonomy
|
|
200
|
-
* @param queryConfig Query configuration
|
|
201
|
-
*/
|
|
202
|
-
async getTaxonomy(
|
|
203
|
-
url: string,
|
|
204
|
-
queryConfig: ITaxonomyQueryConfig
|
|
205
|
-
): Promise<
|
|
206
|
-
IDeliveryNetworkResponse<
|
|
207
|
-
Responses.IViewTaxonomyResponse<TClientTypes['taxonomyCodenames']>,
|
|
208
|
-
Contracts.IViewTaxonomyGroupContract
|
|
209
|
-
>
|
|
210
|
-
> {
|
|
211
|
-
const response = await this.getResponseAsync<Contracts.IViewTaxonomyGroupContract>(url, queryConfig);
|
|
212
|
-
|
|
213
|
-
return this.mapNetworkResponse(this.mappingService.viewTaxonomyResponse(response.data), response);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* Gets multiple taxonomies from given url
|
|
218
|
-
* @param url Url used to get multiple taxonomies
|
|
219
|
-
* @param queryConfig Query configuration
|
|
220
|
-
*/
|
|
221
|
-
async getTaxonomies(
|
|
222
|
-
url: string,
|
|
223
|
-
queryConfig: ITaxonomyQueryConfig
|
|
224
|
-
): Promise<
|
|
225
|
-
IDeliveryNetworkResponse<
|
|
226
|
-
Responses.IListTaxonomiesResponse<TClientTypes['taxonomyCodenames']>,
|
|
227
|
-
Contracts.IListTaxonomyGroupsContract
|
|
228
|
-
>
|
|
229
|
-
> {
|
|
230
|
-
const response = await this.getResponseAsync<Contracts.IListTaxonomyGroupsContract>(url, queryConfig);
|
|
231
|
-
|
|
232
|
-
return this.mapNetworkResponse(this.mappingService.listTaxonomiesResponse(response.data), response);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* Gets single content type element from given url
|
|
237
|
-
* @param url Url used to get single content type element
|
|
238
|
-
* @param queryConfig Query configuration
|
|
239
|
-
*/
|
|
240
|
-
async getElementAsync(
|
|
241
|
-
url: string,
|
|
242
|
-
queryConfig: ITaxonomyQueryConfig
|
|
243
|
-
): Promise<
|
|
244
|
-
IDeliveryNetworkResponse<Responses.IViewContentTypeElementResponse, Contracts.IViewContentTypeElementContract>
|
|
245
|
-
> {
|
|
246
|
-
const response = await this.getResponseAsync<Contracts.IViewContentTypeElementContract>(url, queryConfig);
|
|
247
|
-
|
|
248
|
-
return this.mapNetworkResponse(this.mappingService.viewContentTypeElementResponse(response.data), response);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
async getListAllResponse<
|
|
252
|
-
TResponse extends IKontentListResponse,
|
|
253
|
-
TAllResponse extends IKontentListAllResponse,
|
|
254
|
-
TContract
|
|
255
|
-
>(data: {
|
|
256
|
-
page: number;
|
|
257
|
-
getResponse: (
|
|
258
|
-
nextPageUrl?: string,
|
|
259
|
-
continuationToken?: string
|
|
260
|
-
) => Promise<IDeliveryNetworkResponse<TResponse, TContract>>;
|
|
261
|
-
allResponseFactory: (
|
|
262
|
-
items: any[],
|
|
263
|
-
responses: IDeliveryNetworkResponse<TResponse, TContract>[]
|
|
264
|
-
) => IGroupedNetworkResponse<TAllResponse>;
|
|
265
|
-
listQueryConfig?: IListAllQueryConfig<TResponse, TContract>;
|
|
266
|
-
}): Promise<IGroupedNetworkResponse<TAllResponse>> {
|
|
267
|
-
const responses = await this.getListAllResponseInternalAsync({
|
|
268
|
-
page: data.page,
|
|
269
|
-
resolvedResponses: [],
|
|
270
|
-
getResponse: data.getResponse,
|
|
271
|
-
nextPageUrl: undefined,
|
|
272
|
-
continuationToken: undefined,
|
|
273
|
-
listQueryConfig: data.listQueryConfig
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
return data.allResponseFactory(
|
|
277
|
-
responses.reduce((prev: any[], current) => {
|
|
278
|
-
prev.push(...current.data.items);
|
|
279
|
-
return prev;
|
|
280
|
-
}, []),
|
|
281
|
-
responses
|
|
282
|
-
);
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
private async getListAllResponseInternalAsync<TResponse extends IKontentListResponse, TContract>(data: {
|
|
286
|
-
page: number;
|
|
287
|
-
nextPageUrl?: string;
|
|
288
|
-
continuationToken?: string;
|
|
289
|
-
getResponse: (
|
|
290
|
-
nextPageUrl?: string,
|
|
291
|
-
continuationToken?: string
|
|
292
|
-
) => Promise<IDeliveryNetworkResponse<TResponse, TContract>>;
|
|
293
|
-
resolvedResponses: IDeliveryNetworkResponse<TResponse, TContract>[];
|
|
294
|
-
listQueryConfig?: IListAllQueryConfig<TResponse, TContract>;
|
|
295
|
-
}): Promise<IDeliveryNetworkResponse<TResponse, TContract>[]> {
|
|
296
|
-
if (data.listQueryConfig?.pages) {
|
|
297
|
-
if (data.page > data.listQueryConfig.pages) {
|
|
298
|
-
// page limit reached, return result
|
|
299
|
-
return data.resolvedResponses;
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
const response = await data.getResponse(data.nextPageUrl, data.continuationToken);
|
|
304
|
-
|
|
305
|
-
if (data.listQueryConfig?.delayBetweenRequests) {
|
|
306
|
-
await this.sleep(data.listQueryConfig.delayBetweenRequests);
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
data.resolvedResponses.push(response);
|
|
310
|
-
|
|
311
|
-
if (data.listQueryConfig?.responseFetched) {
|
|
312
|
-
data.listQueryConfig.responseFetched(response, data.nextPageUrl, data.continuationToken);
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
const nextPage = response.data.pagination?.nextPage;
|
|
316
|
-
const continuationToken = response.xContinuationToken;
|
|
317
|
-
|
|
318
|
-
if (nextPage || continuationToken) {
|
|
319
|
-
// recursively fetch next page data
|
|
320
|
-
return await this.getListAllResponseInternalAsync({
|
|
321
|
-
page: data.page + 1,
|
|
322
|
-
nextPageUrl: nextPage,
|
|
323
|
-
continuationToken: continuationToken,
|
|
324
|
-
listQueryConfig: data.listQueryConfig,
|
|
325
|
-
getResponse: data.getResponse,
|
|
326
|
-
resolvedResponses: data.resolvedResponses
|
|
327
|
-
});
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
return data.resolvedResponses;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
private sleep(ms: number): Promise<void> {
|
|
334
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
335
|
-
}
|
|
336
|
-
}
|
|
1
|
+
import { IHttpService } from '@kontent-ai/core-sdk';
|
|
2
|
+
import { IDeliveryClientConfig } from '../config';
|
|
3
|
+
import { Contracts } from '../contracts';
|
|
4
|
+
import {
|
|
5
|
+
Responses,
|
|
6
|
+
IContentItem,
|
|
7
|
+
IContentTypeQueryConfig,
|
|
8
|
+
IGroupedNetworkResponse,
|
|
9
|
+
IItemQueryConfig,
|
|
10
|
+
IDeliveryNetworkResponse,
|
|
11
|
+
ILanguagesQueryConfig,
|
|
12
|
+
ITaxonomyQueryConfig,
|
|
13
|
+
ISyncInitQueryConfig,
|
|
14
|
+
ClientTypes
|
|
15
|
+
} from '../models';
|
|
16
|
+
import {
|
|
17
|
+
IKontentListAllResponse,
|
|
18
|
+
IKontentListResponse,
|
|
19
|
+
IListAllQueryConfig,
|
|
20
|
+
ISDKInfo
|
|
21
|
+
} from '../models/common/common-models';
|
|
22
|
+
import { BaseDeliveryQueryService } from './base-delivery-query.service';
|
|
23
|
+
import { IMappingService } from './mapping.service';
|
|
24
|
+
|
|
25
|
+
export class QueryService<TClientTypes extends ClientTypes> extends BaseDeliveryQueryService<TClientTypes> {
|
|
26
|
+
constructor(
|
|
27
|
+
config: IDeliveryClientConfig,
|
|
28
|
+
httpService: IHttpService<any>,
|
|
29
|
+
sdkInfo: ISDKInfo,
|
|
30
|
+
mappingService: IMappingService<TClientTypes>
|
|
31
|
+
) {
|
|
32
|
+
super(config, httpService, sdkInfo, mappingService);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Gets single item from given url
|
|
37
|
+
* @param url Url used to get single item
|
|
38
|
+
* @param queryConfig Query configuration
|
|
39
|
+
*/
|
|
40
|
+
async getSingleItemAsync<TContentItem extends IContentItem = TClientTypes['contentItemType']>(
|
|
41
|
+
url: string,
|
|
42
|
+
queryConfig: IItemQueryConfig
|
|
43
|
+
): Promise<
|
|
44
|
+
IDeliveryNetworkResponse<
|
|
45
|
+
Responses.IViewContentItemResponse<TContentItem, TClientTypes['contentItemType']>,
|
|
46
|
+
Contracts.IViewContentItemContract
|
|
47
|
+
>
|
|
48
|
+
> {
|
|
49
|
+
const response = await this.getResponseAsync<Contracts.IViewContentItemContract>(url, queryConfig);
|
|
50
|
+
|
|
51
|
+
return this.mapNetworkResponse<
|
|
52
|
+
Responses.IViewContentItemResponse<TContentItem, TClientTypes['contentItemType']>,
|
|
53
|
+
Contracts.IViewContentItemContract
|
|
54
|
+
>(this.mappingService.viewContentItemResponse<TContentItem>(response.data), response);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Gets single feed response. Might not contain all items in your environment.
|
|
59
|
+
* @param url Url
|
|
60
|
+
* @param queryConfig Query configuration
|
|
61
|
+
*/
|
|
62
|
+
async getItemsFeed<TContentItem extends IContentItem = TClientTypes['contentItemType']>(
|
|
63
|
+
url: string,
|
|
64
|
+
queryConfig: IItemQueryConfig
|
|
65
|
+
): Promise<
|
|
66
|
+
IDeliveryNetworkResponse<
|
|
67
|
+
Responses.IListItemsFeedResponse<TContentItem, TClientTypes['contentItemType']>,
|
|
68
|
+
Contracts.IItemsFeedContract
|
|
69
|
+
>
|
|
70
|
+
> {
|
|
71
|
+
const response = await this.getResponseAsync<Contracts.IItemsFeedContract>(url, queryConfig);
|
|
72
|
+
|
|
73
|
+
return this.mapNetworkResponse(this.mappingService.itemsFeedResponse<TContentItem>(response.data), response);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Gets single used in response. Might not contain all used in references.
|
|
78
|
+
* @param url Url
|
|
79
|
+
* @param queryConfig Query configuration
|
|
80
|
+
*/
|
|
81
|
+
async getUsedIn(
|
|
82
|
+
url: string,
|
|
83
|
+
queryConfig: IItemQueryConfig
|
|
84
|
+
): Promise<IDeliveryNetworkResponse<Responses.IUsedInResponse<TClientTypes>, Contracts.IUsedInItemsContract>> {
|
|
85
|
+
const response = await this.getResponseAsync<Contracts.IUsedInItemsContract>(url, queryConfig);
|
|
86
|
+
|
|
87
|
+
return this.mapNetworkResponse(this.mappingService.usedInResponse(response.data), response);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Gets multiple items from given url
|
|
92
|
+
* @param url Url used to get multiple items
|
|
93
|
+
* @param queryConfig Query configuration
|
|
94
|
+
*/
|
|
95
|
+
async getMultipleItems<TContentItem extends IContentItem = TClientTypes['contentItemType']>(
|
|
96
|
+
url: string,
|
|
97
|
+
queryConfig: IItemQueryConfig
|
|
98
|
+
): Promise<
|
|
99
|
+
IDeliveryNetworkResponse<
|
|
100
|
+
Responses.IListContentItemsResponse<TContentItem, TClientTypes['contentItemType']>,
|
|
101
|
+
Contracts.IListContentItemsContract
|
|
102
|
+
>
|
|
103
|
+
> {
|
|
104
|
+
const response = await this.getResponseAsync<Contracts.IListContentItemsContract>(url, queryConfig);
|
|
105
|
+
|
|
106
|
+
return this.mapNetworkResponse(this.mappingService.listContentItemsResponse(response.data), response);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Gets single content type from given url
|
|
111
|
+
* @param url Url used to get single type
|
|
112
|
+
* @param queryConfig Query configuration
|
|
113
|
+
*/
|
|
114
|
+
async getSingleType(
|
|
115
|
+
url: string,
|
|
116
|
+
queryConfig: IContentTypeQueryConfig
|
|
117
|
+
): Promise<
|
|
118
|
+
IDeliveryNetworkResponse<
|
|
119
|
+
Responses.IViewContentTypeResponse<TClientTypes['contentTypeCodenames']>,
|
|
120
|
+
Contracts.IViewContentTypeContract
|
|
121
|
+
>
|
|
122
|
+
> {
|
|
123
|
+
const response = await this.getResponseAsync<Contracts.IViewContentTypeContract>(url, queryConfig);
|
|
124
|
+
|
|
125
|
+
return this.mapNetworkResponse(this.mappingService.viewContentTypeResponse(response.data), response);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Gets multiple content types from given url
|
|
130
|
+
* @param url Url used to get multiple types
|
|
131
|
+
* @param queryConfig Query configuration
|
|
132
|
+
*/
|
|
133
|
+
async getMultipleTypes(
|
|
134
|
+
url: string,
|
|
135
|
+
queryConfig: IContentTypeQueryConfig
|
|
136
|
+
): Promise<
|
|
137
|
+
IDeliveryNetworkResponse<
|
|
138
|
+
Responses.IListContentTypesResponse<TClientTypes['contentTypeCodenames']>,
|
|
139
|
+
Contracts.IListContentTypeContract
|
|
140
|
+
>
|
|
141
|
+
> {
|
|
142
|
+
const response = await this.getResponseAsync<Contracts.IListContentTypeContract>(url, queryConfig);
|
|
143
|
+
|
|
144
|
+
return this.mapNetworkResponse(this.mappingService.listContentTypesResponse(response.data), response);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Initializes synchronization of changes in content items based on the specified parameters. After the initialization,
|
|
149
|
+
* you'll get an X-Continuation token in the response.
|
|
150
|
+
* Use the token to synchronize changes in the content items matching the initialization criteria.
|
|
151
|
+
* @param url Url
|
|
152
|
+
* @param queryConfig Query configuration
|
|
153
|
+
*/
|
|
154
|
+
async initializeSync(
|
|
155
|
+
url: string,
|
|
156
|
+
queryConfig: ISyncInitQueryConfig
|
|
157
|
+
): Promise<IDeliveryNetworkResponse<Responses.IInitializeSyncResponse, Contracts.IInitializeSyncContract>> {
|
|
158
|
+
const response = await this.postResponseAsync<Contracts.IInitializeSyncContract>(url, {}, queryConfig);
|
|
159
|
+
|
|
160
|
+
return this.mapNetworkResponse(this.mappingService.initializeContentSync(response.data), response);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Retrieve a list of delta updates to recently changed content items in the specified environment.
|
|
165
|
+
* The types of items you get is determined by the X-Continuation token you use.
|
|
166
|
+
* @param url Url used to get multiple types
|
|
167
|
+
* @param queryConfig Query configuration
|
|
168
|
+
*/
|
|
169
|
+
async syncChanges(
|
|
170
|
+
url: string,
|
|
171
|
+
queryConfig: IContentTypeQueryConfig
|
|
172
|
+
): Promise<IDeliveryNetworkResponse<Responses.ISyncChangesResponse, Contracts.ISyncChangesContract>> {
|
|
173
|
+
const response = await this.getResponseAsync<Contracts.ISyncChangesContract>(url, queryConfig);
|
|
174
|
+
|
|
175
|
+
return this.mapNetworkResponse(this.mappingService.syncChanges(response.data), response);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Gets languages
|
|
180
|
+
* @param url Url
|
|
181
|
+
* @param queryConfig Query configuration
|
|
182
|
+
*/
|
|
183
|
+
async getLanguages(
|
|
184
|
+
url: string,
|
|
185
|
+
queryConfig: ILanguagesQueryConfig
|
|
186
|
+
): Promise<
|
|
187
|
+
IDeliveryNetworkResponse<
|
|
188
|
+
Responses.IListLanguagesResponse<TClientTypes['languageCodenames']>,
|
|
189
|
+
Contracts.IListLanguagesContract
|
|
190
|
+
>
|
|
191
|
+
> {
|
|
192
|
+
const response = await this.getResponseAsync<Contracts.IListLanguagesContract>(url, queryConfig);
|
|
193
|
+
|
|
194
|
+
return this.mapNetworkResponse(this.mappingService.listLanguagesResponse(response.data), response);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Gets single taxonomy from given url
|
|
199
|
+
* @param url Url used to get single taxonomy
|
|
200
|
+
* @param queryConfig Query configuration
|
|
201
|
+
*/
|
|
202
|
+
async getTaxonomy(
|
|
203
|
+
url: string,
|
|
204
|
+
queryConfig: ITaxonomyQueryConfig
|
|
205
|
+
): Promise<
|
|
206
|
+
IDeliveryNetworkResponse<
|
|
207
|
+
Responses.IViewTaxonomyResponse<TClientTypes['taxonomyCodenames']>,
|
|
208
|
+
Contracts.IViewTaxonomyGroupContract
|
|
209
|
+
>
|
|
210
|
+
> {
|
|
211
|
+
const response = await this.getResponseAsync<Contracts.IViewTaxonomyGroupContract>(url, queryConfig);
|
|
212
|
+
|
|
213
|
+
return this.mapNetworkResponse(this.mappingService.viewTaxonomyResponse(response.data), response);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Gets multiple taxonomies from given url
|
|
218
|
+
* @param url Url used to get multiple taxonomies
|
|
219
|
+
* @param queryConfig Query configuration
|
|
220
|
+
*/
|
|
221
|
+
async getTaxonomies(
|
|
222
|
+
url: string,
|
|
223
|
+
queryConfig: ITaxonomyQueryConfig
|
|
224
|
+
): Promise<
|
|
225
|
+
IDeliveryNetworkResponse<
|
|
226
|
+
Responses.IListTaxonomiesResponse<TClientTypes['taxonomyCodenames']>,
|
|
227
|
+
Contracts.IListTaxonomyGroupsContract
|
|
228
|
+
>
|
|
229
|
+
> {
|
|
230
|
+
const response = await this.getResponseAsync<Contracts.IListTaxonomyGroupsContract>(url, queryConfig);
|
|
231
|
+
|
|
232
|
+
return this.mapNetworkResponse(this.mappingService.listTaxonomiesResponse(response.data), response);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Gets single content type element from given url
|
|
237
|
+
* @param url Url used to get single content type element
|
|
238
|
+
* @param queryConfig Query configuration
|
|
239
|
+
*/
|
|
240
|
+
async getElementAsync(
|
|
241
|
+
url: string,
|
|
242
|
+
queryConfig: ITaxonomyQueryConfig
|
|
243
|
+
): Promise<
|
|
244
|
+
IDeliveryNetworkResponse<Responses.IViewContentTypeElementResponse, Contracts.IViewContentTypeElementContract>
|
|
245
|
+
> {
|
|
246
|
+
const response = await this.getResponseAsync<Contracts.IViewContentTypeElementContract>(url, queryConfig);
|
|
247
|
+
|
|
248
|
+
return this.mapNetworkResponse(this.mappingService.viewContentTypeElementResponse(response.data), response);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
async getListAllResponse<
|
|
252
|
+
TResponse extends IKontentListResponse,
|
|
253
|
+
TAllResponse extends IKontentListAllResponse,
|
|
254
|
+
TContract
|
|
255
|
+
>(data: {
|
|
256
|
+
page: number;
|
|
257
|
+
getResponse: (
|
|
258
|
+
nextPageUrl?: string,
|
|
259
|
+
continuationToken?: string
|
|
260
|
+
) => Promise<IDeliveryNetworkResponse<TResponse, TContract>>;
|
|
261
|
+
allResponseFactory: (
|
|
262
|
+
items: any[],
|
|
263
|
+
responses: IDeliveryNetworkResponse<TResponse, TContract>[]
|
|
264
|
+
) => IGroupedNetworkResponse<TAllResponse>;
|
|
265
|
+
listQueryConfig?: IListAllQueryConfig<TResponse, TContract>;
|
|
266
|
+
}): Promise<IGroupedNetworkResponse<TAllResponse>> {
|
|
267
|
+
const responses = await this.getListAllResponseInternalAsync({
|
|
268
|
+
page: data.page,
|
|
269
|
+
resolvedResponses: [],
|
|
270
|
+
getResponse: data.getResponse,
|
|
271
|
+
nextPageUrl: undefined,
|
|
272
|
+
continuationToken: undefined,
|
|
273
|
+
listQueryConfig: data.listQueryConfig
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
return data.allResponseFactory(
|
|
277
|
+
responses.reduce((prev: any[], current) => {
|
|
278
|
+
prev.push(...current.data.items);
|
|
279
|
+
return prev;
|
|
280
|
+
}, []),
|
|
281
|
+
responses
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
private async getListAllResponseInternalAsync<TResponse extends IKontentListResponse, TContract>(data: {
|
|
286
|
+
page: number;
|
|
287
|
+
nextPageUrl?: string;
|
|
288
|
+
continuationToken?: string;
|
|
289
|
+
getResponse: (
|
|
290
|
+
nextPageUrl?: string,
|
|
291
|
+
continuationToken?: string
|
|
292
|
+
) => Promise<IDeliveryNetworkResponse<TResponse, TContract>>;
|
|
293
|
+
resolvedResponses: IDeliveryNetworkResponse<TResponse, TContract>[];
|
|
294
|
+
listQueryConfig?: IListAllQueryConfig<TResponse, TContract>;
|
|
295
|
+
}): Promise<IDeliveryNetworkResponse<TResponse, TContract>[]> {
|
|
296
|
+
if (data.listQueryConfig?.pages) {
|
|
297
|
+
if (data.page > data.listQueryConfig.pages) {
|
|
298
|
+
// page limit reached, return result
|
|
299
|
+
return data.resolvedResponses;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const response = await data.getResponse(data.nextPageUrl, data.continuationToken);
|
|
304
|
+
|
|
305
|
+
if (data.listQueryConfig?.delayBetweenRequests) {
|
|
306
|
+
await this.sleep(data.listQueryConfig.delayBetweenRequests);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
data.resolvedResponses.push(response);
|
|
310
|
+
|
|
311
|
+
if (data.listQueryConfig?.responseFetched) {
|
|
312
|
+
data.listQueryConfig.responseFetched(response, data.nextPageUrl, data.continuationToken);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const nextPage = response.data.pagination?.nextPage;
|
|
316
|
+
const continuationToken = response.xContinuationToken;
|
|
317
|
+
|
|
318
|
+
if (nextPage || continuationToken) {
|
|
319
|
+
// recursively fetch next page data
|
|
320
|
+
return await this.getListAllResponseInternalAsync({
|
|
321
|
+
page: data.page + 1,
|
|
322
|
+
nextPageUrl: nextPage,
|
|
323
|
+
continuationToken: continuationToken,
|
|
324
|
+
listQueryConfig: data.listQueryConfig,
|
|
325
|
+
getResponse: data.getResponse,
|
|
326
|
+
resolvedResponses: data.resolvedResponses
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
return data.resolvedResponses;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
private sleep(ms: number): Promise<void> {
|
|
334
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
335
|
+
}
|
|
336
|
+
}
|