@kontent-ai/delivery-sdk 16.4.2 → 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 +5770 -4807
- 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 +10038 -7042
- package/dist/bundles/stats.min.json +14400 -10652
- 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
package/lib/services/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './delivery-query.service';
|
|
2
|
-
export * from './mapping.service';
|
|
1
|
+
export * from './delivery-query.service';
|
|
2
|
+
export * from './mapping.service';
|
|
@@ -1,223 +1,223 @@
|
|
|
1
|
-
import { IDeliveryClientConfig } from '../config';
|
|
2
|
-
import { Contracts } from '../contracts';
|
|
3
|
-
import {
|
|
4
|
-
SyncMapper,
|
|
5
|
-
GenericElementMapper,
|
|
6
|
-
ItemMapper,
|
|
7
|
-
LanguageMapper,
|
|
8
|
-
TaxonomyMapper,
|
|
9
|
-
TypeMapper,
|
|
10
|
-
UsedInMapper
|
|
11
|
-
} from '../mappers';
|
|
12
|
-
import { Responses, IContentItem, IPagination, ClientTypes } from '../models';
|
|
13
|
-
|
|
14
|
-
export interface IMappingService<TClientTypes extends ClientTypes> {
|
|
15
|
-
listContentTypesResponse(
|
|
16
|
-
data: Contracts.IListContentTypeContract
|
|
17
|
-
): Responses.IListContentTypesResponse<TClientTypes['contentTypeCodenames']>;
|
|
18
|
-
|
|
19
|
-
itemsFeedResponse<TContentItem extends IContentItem = TClientTypes['contentItemType']>(
|
|
20
|
-
data: Contracts.IItemsFeedContract
|
|
21
|
-
): Responses.IListItemsFeedResponse<TContentItem, TClientTypes['contentItemType']>;
|
|
22
|
-
|
|
23
|
-
usedInResponse(data: Contracts.IUsedInItemsContract): Responses.IUsedInResponse<TClientTypes>;
|
|
24
|
-
|
|
25
|
-
viewContentTypeResponse(
|
|
26
|
-
data: Contracts.IViewContentTypeContract
|
|
27
|
-
): Responses.IViewContentTypeResponse<TClientTypes['contentTypeCodenames']>;
|
|
28
|
-
|
|
29
|
-
viewContentItemResponse<TContentItem extends IContentItem = TClientTypes['contentItemType']>(
|
|
30
|
-
data: Contracts.IViewContentItemContract
|
|
31
|
-
): Responses.IViewContentItemResponse<TContentItem, TClientTypes['contentItemType']>;
|
|
32
|
-
|
|
33
|
-
listContentItemsResponse<TContentItem extends IContentItem = TClientTypes['contentItemType']>(
|
|
34
|
-
data: Contracts.IListContentItemsContract
|
|
35
|
-
): Responses.IListContentItemsResponse<TContentItem, TClientTypes['contentItemType']>;
|
|
36
|
-
|
|
37
|
-
viewTaxonomyResponse(
|
|
38
|
-
data: Contracts.IViewTaxonomyGroupContract
|
|
39
|
-
): Responses.IViewTaxonomyResponse<TClientTypes['taxonomyCodenames']>;
|
|
40
|
-
|
|
41
|
-
listTaxonomiesResponse(
|
|
42
|
-
data: Contracts.IListTaxonomyGroupsContract
|
|
43
|
-
): Responses.IListTaxonomiesResponse<TClientTypes['taxonomyCodenames']>;
|
|
44
|
-
|
|
45
|
-
viewContentTypeElementResponse(
|
|
46
|
-
data: Contracts.IViewContentTypeElementContract
|
|
47
|
-
): Responses.IViewContentTypeElementResponse;
|
|
48
|
-
|
|
49
|
-
listLanguagesResponse(
|
|
50
|
-
data: Contracts.IListLanguagesContract
|
|
51
|
-
): Responses.IListLanguagesResponse<TClientTypes['languageCodenames']>;
|
|
52
|
-
initializeContentSync(data: Contracts.IInitializeSyncContract): Responses.IInitializeSyncResponse;
|
|
53
|
-
syncChanges(data: Contracts.ISyncChangesContract): Responses.ISyncChangesResponse;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export class MappingService<TClientTypes extends ClientTypes> implements IMappingService<TClientTypes> {
|
|
57
|
-
private readonly typeMapper: TypeMapper<TClientTypes['contentTypeCodenames']>;
|
|
58
|
-
private readonly languageMapper: LanguageMapper<TClientTypes['languageCodenames']>;
|
|
59
|
-
private readonly itemMapper: ItemMapper<TClientTypes['contentItemType']>;
|
|
60
|
-
private readonly taxonomyMapper: TaxonomyMapper<TClientTypes['taxonomyCodenames']>;
|
|
61
|
-
private readonly usedInMapper: UsedInMapper<TClientTypes>;
|
|
62
|
-
private readonly genericElementMapper: GenericElementMapper;
|
|
63
|
-
private readonly syncMapper: SyncMapper;
|
|
64
|
-
|
|
65
|
-
constructor(readonly config: IDeliveryClientConfig) {
|
|
66
|
-
this.typeMapper = new TypeMapper();
|
|
67
|
-
this.languageMapper = new LanguageMapper();
|
|
68
|
-
this.itemMapper = new ItemMapper(config);
|
|
69
|
-
this.taxonomyMapper = new TaxonomyMapper();
|
|
70
|
-
this.usedInMapper = new UsedInMapper<TClientTypes>();
|
|
71
|
-
this.genericElementMapper = new GenericElementMapper();
|
|
72
|
-
this.syncMapper = new SyncMapper();
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
usedInResponse(data: Contracts.IUsedInItemsContract): Responses.IUsedInResponse<TClientTypes> {
|
|
76
|
-
return {
|
|
77
|
-
items: data.items.map((m) => this.usedInMapper.mapUsedInItem(m))
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Gets response for list of languages
|
|
83
|
-
* @param data Response data
|
|
84
|
-
*/
|
|
85
|
-
listLanguagesResponse(
|
|
86
|
-
data: Contracts.IListLanguagesContract
|
|
87
|
-
): Responses.IListLanguagesResponse<TClientTypes['languageCodenames']> {
|
|
88
|
-
return {
|
|
89
|
-
items: this.languageMapper.mapMultipleLanguages(data),
|
|
90
|
-
pagination: this.mapPagination(data.pagination)
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Gets response for getting a multiple type
|
|
96
|
-
* @param data Response data
|
|
97
|
-
*/
|
|
98
|
-
listContentTypesResponse(
|
|
99
|
-
data: Contracts.IListContentTypeContract
|
|
100
|
-
): Responses.IListContentTypesResponse<TClientTypes['contentTypeCodenames']> {
|
|
101
|
-
return {
|
|
102
|
-
items: this.typeMapper.mapMultipleTypes(data),
|
|
103
|
-
pagination: this.mapPagination(data.pagination)
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Gets response for single type
|
|
109
|
-
* @param data Response data
|
|
110
|
-
* @param options Options
|
|
111
|
-
*/
|
|
112
|
-
viewContentTypeResponse(
|
|
113
|
-
data: Contracts.IViewContentTypeContract
|
|
114
|
-
): Responses.IViewContentTypeResponse<TClientTypes['contentTypeCodenames']> {
|
|
115
|
-
return {
|
|
116
|
-
type: this.typeMapper.mapSingleType(data)
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
itemsFeedResponse<TContentItem extends IContentItem = TClientTypes['contentItemType']>(
|
|
121
|
-
data: Contracts.IItemsFeedContract
|
|
122
|
-
): Responses.IListItemsFeedResponse<TContentItem, TClientTypes['contentItemType']> {
|
|
123
|
-
const itemsResult = this.itemMapper.mapItems<TContentItem>({
|
|
124
|
-
linkedItems: Object.values(data.modular_content),
|
|
125
|
-
mainItems: data.items
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
return {
|
|
129
|
-
items: itemsResult.items,
|
|
130
|
-
linkedItems: itemsResult.linkedItems
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Gets response for getting single item
|
|
136
|
-
* @param data Response data
|
|
137
|
-
* @param queryConfig Query configuration
|
|
138
|
-
*/
|
|
139
|
-
viewContentItemResponse<TContentItem extends IContentItem = TClientTypes['contentItemType']>(
|
|
140
|
-
data: Contracts.IViewContentItemContract
|
|
141
|
-
): Responses.IViewContentItemResponse<TContentItem, TClientTypes['contentItemType']> {
|
|
142
|
-
const itemResult = this.itemMapper.mapSingleItemFromResponse<TContentItem>(data);
|
|
143
|
-
|
|
144
|
-
return {
|
|
145
|
-
item: itemResult.item,
|
|
146
|
-
linkedItems: itemResult.linkedItems
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Gets response for getting multiple items
|
|
152
|
-
* @param data Response data
|
|
153
|
-
* @param queryConfig Query configuration
|
|
154
|
-
*/
|
|
155
|
-
listContentItemsResponse<TContentItem extends IContentItem = TClientTypes['contentItemType']>(
|
|
156
|
-
data: Contracts.IListContentItemsContract
|
|
157
|
-
): Responses.IListContentItemsResponse<TContentItem, TClientTypes['contentItemType']> {
|
|
158
|
-
const itemsResult = this.itemMapper.mapMultipleItemsFromResponse<TContentItem>(data);
|
|
159
|
-
|
|
160
|
-
return {
|
|
161
|
-
items: itemsResult.items,
|
|
162
|
-
pagination: this.mapPagination(data.pagination),
|
|
163
|
-
linkedItems: itemsResult.linkedItems
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Gets response for getting single taxonomy item
|
|
169
|
-
* @param data Response data
|
|
170
|
-
*/
|
|
171
|
-
viewTaxonomyResponse(
|
|
172
|
-
data: Contracts.IViewTaxonomyGroupContract
|
|
173
|
-
): Responses.IViewTaxonomyResponse<TClientTypes['taxonomyCodenames']> {
|
|
174
|
-
return {
|
|
175
|
-
taxonomy: this.taxonomyMapper.mapTaxonomy(data.system, data.terms)
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Gets response for getting multiples taxonomies
|
|
181
|
-
* @param data Response data
|
|
182
|
-
*/
|
|
183
|
-
listTaxonomiesResponse(
|
|
184
|
-
data: Contracts.IListTaxonomyGroupsContract
|
|
185
|
-
): Responses.IListTaxonomiesResponse<TClientTypes['taxonomyCodenames']> {
|
|
186
|
-
return {
|
|
187
|
-
items: this.taxonomyMapper.mapTaxonomies(data.taxonomies),
|
|
188
|
-
pagination: this.mapPagination(data.pagination)
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Gets response for getting single content type element
|
|
194
|
-
* @param data Response data
|
|
195
|
-
*/
|
|
196
|
-
viewContentTypeElementResponse(
|
|
197
|
-
data: Contracts.IViewContentTypeElementContract
|
|
198
|
-
): Responses.IViewContentTypeElementResponse {
|
|
199
|
-
return this.genericElementMapper.mapElement(data);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
initializeContentSync(data: Contracts.IInitializeSyncContract): Responses.IInitializeSyncResponse {
|
|
203
|
-
return {
|
|
204
|
-
items: data.items.map((m) => this.syncMapper.mapContentItemDelta(m))
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
syncChanges(data: Contracts.ISyncChangesContract): Responses.ISyncChangesResponse {
|
|
209
|
-
return {
|
|
210
|
-
items: data.items.map((m) => this.syncMapper.mapContentItemDelta(m))
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
private mapPagination(paginationContract: Contracts.IPaginationContract): IPagination {
|
|
215
|
-
return {
|
|
216
|
-
skip: paginationContract.skip,
|
|
217
|
-
count: paginationContract.count,
|
|
218
|
-
limit: paginationContract.limit,
|
|
219
|
-
nextPage: paginationContract.next_page,
|
|
220
|
-
totalCount: paginationContract.total_count ?? null
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
}
|
|
1
|
+
import { IDeliveryClientConfig } from '../config';
|
|
2
|
+
import { Contracts } from '../contracts';
|
|
3
|
+
import {
|
|
4
|
+
SyncMapper,
|
|
5
|
+
GenericElementMapper,
|
|
6
|
+
ItemMapper,
|
|
7
|
+
LanguageMapper,
|
|
8
|
+
TaxonomyMapper,
|
|
9
|
+
TypeMapper,
|
|
10
|
+
UsedInMapper
|
|
11
|
+
} from '../mappers';
|
|
12
|
+
import { Responses, IContentItem, IPagination, ClientTypes } from '../models';
|
|
13
|
+
|
|
14
|
+
export interface IMappingService<TClientTypes extends ClientTypes> {
|
|
15
|
+
listContentTypesResponse(
|
|
16
|
+
data: Contracts.IListContentTypeContract
|
|
17
|
+
): Responses.IListContentTypesResponse<TClientTypes['contentTypeCodenames']>;
|
|
18
|
+
|
|
19
|
+
itemsFeedResponse<TContentItem extends IContentItem = TClientTypes['contentItemType']>(
|
|
20
|
+
data: Contracts.IItemsFeedContract
|
|
21
|
+
): Responses.IListItemsFeedResponse<TContentItem, TClientTypes['contentItemType']>;
|
|
22
|
+
|
|
23
|
+
usedInResponse(data: Contracts.IUsedInItemsContract): Responses.IUsedInResponse<TClientTypes>;
|
|
24
|
+
|
|
25
|
+
viewContentTypeResponse(
|
|
26
|
+
data: Contracts.IViewContentTypeContract
|
|
27
|
+
): Responses.IViewContentTypeResponse<TClientTypes['contentTypeCodenames']>;
|
|
28
|
+
|
|
29
|
+
viewContentItemResponse<TContentItem extends IContentItem = TClientTypes['contentItemType']>(
|
|
30
|
+
data: Contracts.IViewContentItemContract
|
|
31
|
+
): Responses.IViewContentItemResponse<TContentItem, TClientTypes['contentItemType']>;
|
|
32
|
+
|
|
33
|
+
listContentItemsResponse<TContentItem extends IContentItem = TClientTypes['contentItemType']>(
|
|
34
|
+
data: Contracts.IListContentItemsContract
|
|
35
|
+
): Responses.IListContentItemsResponse<TContentItem, TClientTypes['contentItemType']>;
|
|
36
|
+
|
|
37
|
+
viewTaxonomyResponse(
|
|
38
|
+
data: Contracts.IViewTaxonomyGroupContract
|
|
39
|
+
): Responses.IViewTaxonomyResponse<TClientTypes['taxonomyCodenames']>;
|
|
40
|
+
|
|
41
|
+
listTaxonomiesResponse(
|
|
42
|
+
data: Contracts.IListTaxonomyGroupsContract
|
|
43
|
+
): Responses.IListTaxonomiesResponse<TClientTypes['taxonomyCodenames']>;
|
|
44
|
+
|
|
45
|
+
viewContentTypeElementResponse(
|
|
46
|
+
data: Contracts.IViewContentTypeElementContract
|
|
47
|
+
): Responses.IViewContentTypeElementResponse;
|
|
48
|
+
|
|
49
|
+
listLanguagesResponse(
|
|
50
|
+
data: Contracts.IListLanguagesContract
|
|
51
|
+
): Responses.IListLanguagesResponse<TClientTypes['languageCodenames']>;
|
|
52
|
+
initializeContentSync(data: Contracts.IInitializeSyncContract): Responses.IInitializeSyncResponse;
|
|
53
|
+
syncChanges(data: Contracts.ISyncChangesContract): Responses.ISyncChangesResponse;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export class MappingService<TClientTypes extends ClientTypes> implements IMappingService<TClientTypes> {
|
|
57
|
+
private readonly typeMapper: TypeMapper<TClientTypes['contentTypeCodenames']>;
|
|
58
|
+
private readonly languageMapper: LanguageMapper<TClientTypes['languageCodenames']>;
|
|
59
|
+
private readonly itemMapper: ItemMapper<TClientTypes['contentItemType']>;
|
|
60
|
+
private readonly taxonomyMapper: TaxonomyMapper<TClientTypes['taxonomyCodenames']>;
|
|
61
|
+
private readonly usedInMapper: UsedInMapper<TClientTypes>;
|
|
62
|
+
private readonly genericElementMapper: GenericElementMapper;
|
|
63
|
+
private readonly syncMapper: SyncMapper;
|
|
64
|
+
|
|
65
|
+
constructor(readonly config: IDeliveryClientConfig) {
|
|
66
|
+
this.typeMapper = new TypeMapper();
|
|
67
|
+
this.languageMapper = new LanguageMapper();
|
|
68
|
+
this.itemMapper = new ItemMapper(config);
|
|
69
|
+
this.taxonomyMapper = new TaxonomyMapper();
|
|
70
|
+
this.usedInMapper = new UsedInMapper<TClientTypes>();
|
|
71
|
+
this.genericElementMapper = new GenericElementMapper();
|
|
72
|
+
this.syncMapper = new SyncMapper();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
usedInResponse(data: Contracts.IUsedInItemsContract): Responses.IUsedInResponse<TClientTypes> {
|
|
76
|
+
return {
|
|
77
|
+
items: data.items.map((m) => this.usedInMapper.mapUsedInItem(m))
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Gets response for list of languages
|
|
83
|
+
* @param data Response data
|
|
84
|
+
*/
|
|
85
|
+
listLanguagesResponse(
|
|
86
|
+
data: Contracts.IListLanguagesContract
|
|
87
|
+
): Responses.IListLanguagesResponse<TClientTypes['languageCodenames']> {
|
|
88
|
+
return {
|
|
89
|
+
items: this.languageMapper.mapMultipleLanguages(data),
|
|
90
|
+
pagination: this.mapPagination(data.pagination)
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Gets response for getting a multiple type
|
|
96
|
+
* @param data Response data
|
|
97
|
+
*/
|
|
98
|
+
listContentTypesResponse(
|
|
99
|
+
data: Contracts.IListContentTypeContract
|
|
100
|
+
): Responses.IListContentTypesResponse<TClientTypes['contentTypeCodenames']> {
|
|
101
|
+
return {
|
|
102
|
+
items: this.typeMapper.mapMultipleTypes(data),
|
|
103
|
+
pagination: this.mapPagination(data.pagination)
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Gets response for single type
|
|
109
|
+
* @param data Response data
|
|
110
|
+
* @param options Options
|
|
111
|
+
*/
|
|
112
|
+
viewContentTypeResponse(
|
|
113
|
+
data: Contracts.IViewContentTypeContract
|
|
114
|
+
): Responses.IViewContentTypeResponse<TClientTypes['contentTypeCodenames']> {
|
|
115
|
+
return {
|
|
116
|
+
type: this.typeMapper.mapSingleType(data)
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
itemsFeedResponse<TContentItem extends IContentItem = TClientTypes['contentItemType']>(
|
|
121
|
+
data: Contracts.IItemsFeedContract
|
|
122
|
+
): Responses.IListItemsFeedResponse<TContentItem, TClientTypes['contentItemType']> {
|
|
123
|
+
const itemsResult = this.itemMapper.mapItems<TContentItem>({
|
|
124
|
+
linkedItems: Object.values(data.modular_content),
|
|
125
|
+
mainItems: data.items
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
return {
|
|
129
|
+
items: itemsResult.items,
|
|
130
|
+
linkedItems: itemsResult.linkedItems
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Gets response for getting single item
|
|
136
|
+
* @param data Response data
|
|
137
|
+
* @param queryConfig Query configuration
|
|
138
|
+
*/
|
|
139
|
+
viewContentItemResponse<TContentItem extends IContentItem = TClientTypes['contentItemType']>(
|
|
140
|
+
data: Contracts.IViewContentItemContract
|
|
141
|
+
): Responses.IViewContentItemResponse<TContentItem, TClientTypes['contentItemType']> {
|
|
142
|
+
const itemResult = this.itemMapper.mapSingleItemFromResponse<TContentItem>(data);
|
|
143
|
+
|
|
144
|
+
return {
|
|
145
|
+
item: itemResult.item,
|
|
146
|
+
linkedItems: itemResult.linkedItems
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Gets response for getting multiple items
|
|
152
|
+
* @param data Response data
|
|
153
|
+
* @param queryConfig Query configuration
|
|
154
|
+
*/
|
|
155
|
+
listContentItemsResponse<TContentItem extends IContentItem = TClientTypes['contentItemType']>(
|
|
156
|
+
data: Contracts.IListContentItemsContract
|
|
157
|
+
): Responses.IListContentItemsResponse<TContentItem, TClientTypes['contentItemType']> {
|
|
158
|
+
const itemsResult = this.itemMapper.mapMultipleItemsFromResponse<TContentItem>(data);
|
|
159
|
+
|
|
160
|
+
return {
|
|
161
|
+
items: itemsResult.items,
|
|
162
|
+
pagination: this.mapPagination(data.pagination),
|
|
163
|
+
linkedItems: itemsResult.linkedItems
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Gets response for getting single taxonomy item
|
|
169
|
+
* @param data Response data
|
|
170
|
+
*/
|
|
171
|
+
viewTaxonomyResponse(
|
|
172
|
+
data: Contracts.IViewTaxonomyGroupContract
|
|
173
|
+
): Responses.IViewTaxonomyResponse<TClientTypes['taxonomyCodenames']> {
|
|
174
|
+
return {
|
|
175
|
+
taxonomy: this.taxonomyMapper.mapTaxonomy(data.system, data.terms)
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Gets response for getting multiples taxonomies
|
|
181
|
+
* @param data Response data
|
|
182
|
+
*/
|
|
183
|
+
listTaxonomiesResponse(
|
|
184
|
+
data: Contracts.IListTaxonomyGroupsContract
|
|
185
|
+
): Responses.IListTaxonomiesResponse<TClientTypes['taxonomyCodenames']> {
|
|
186
|
+
return {
|
|
187
|
+
items: this.taxonomyMapper.mapTaxonomies(data.taxonomies),
|
|
188
|
+
pagination: this.mapPagination(data.pagination)
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Gets response for getting single content type element
|
|
194
|
+
* @param data Response data
|
|
195
|
+
*/
|
|
196
|
+
viewContentTypeElementResponse(
|
|
197
|
+
data: Contracts.IViewContentTypeElementContract
|
|
198
|
+
): Responses.IViewContentTypeElementResponse {
|
|
199
|
+
return this.genericElementMapper.mapElement(data);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
initializeContentSync(data: Contracts.IInitializeSyncContract): Responses.IInitializeSyncResponse {
|
|
203
|
+
return {
|
|
204
|
+
items: data.items.map((m) => this.syncMapper.mapContentItemDelta(m))
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
syncChanges(data: Contracts.ISyncChangesContract): Responses.ISyncChangesResponse {
|
|
209
|
+
return {
|
|
210
|
+
items: data.items.map((m) => this.syncMapper.mapContentItemDelta(m))
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
private mapPagination(paginationContract: Contracts.IPaginationContract): IPagination {
|
|
215
|
+
return {
|
|
216
|
+
skip: paginationContract.skip,
|
|
217
|
+
count: paginationContract.count,
|
|
218
|
+
limit: paginationContract.limit,
|
|
219
|
+
nextPage: paginationContract.next_page,
|
|
220
|
+
totalCount: paginationContract.total_count ?? null
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export class CodenameHelper {
|
|
2
|
-
/**
|
|
3
|
-
* This is used to prevent errors caused by reserved names in content item codename (e.g. 'constructor')
|
|
4
|
-
*/
|
|
5
|
-
escapeCodenameInCodenameIndexer(codename: string): string {
|
|
6
|
-
return `_${codename}`;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const codenameHelper = new CodenameHelper();
|
|
1
|
+
export class CodenameHelper {
|
|
2
|
+
/**
|
|
3
|
+
* This is used to prevent errors caused by reserved names in content item codename (e.g. 'constructor')
|
|
4
|
+
*/
|
|
5
|
+
escapeCodenameInCodenameIndexer(codename: string): string {
|
|
6
|
+
return `_${codename}`;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const codenameHelper = new CodenameHelper();
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export class DeliveryUrlHelper {
|
|
2
|
-
replaceAssetDomain(originalAssetUrl: string, customDomain: string): string {
|
|
3
|
-
return `${customDomain}${this.getPathname(originalAssetUrl)}`;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
getPathname(url: string): string {
|
|
7
|
-
return new URL(url).pathname;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export const deliveryUrlHelper = new DeliveryUrlHelper();
|
|
1
|
+
export class DeliveryUrlHelper {
|
|
2
|
+
replaceAssetDomain(originalAssetUrl: string, customDomain: string): string {
|
|
3
|
+
return `${customDomain}${this.getPathname(originalAssetUrl)}`;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
getPathname(url: string): string {
|
|
7
|
+
return new URL(url).pathname;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const deliveryUrlHelper = new DeliveryUrlHelper();
|
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
export class EnumHelper {
|
|
2
|
-
getAllValues(T: any): string[] {
|
|
3
|
-
const allEnumValues: string[] = Object.keys(T).map((key) => T[key]);
|
|
4
|
-
return allEnumValues;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
getEnumFromValue<T>(T: any, value: string | number): T | undefined {
|
|
8
|
-
try {
|
|
9
|
-
if (!value) {
|
|
10
|
-
return undefined;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// we can map back from index number directly
|
|
14
|
-
if (this.isNumeric(value)) {
|
|
15
|
-
return <T>T[value];
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// for strings, we need to compare each value separately
|
|
19
|
-
const allEnumValues = this.getAllValues(T);
|
|
20
|
-
|
|
21
|
-
const result = allEnumValues.find((m) => m.toLowerCase() === value.toString().toLowerCase());
|
|
22
|
-
|
|
23
|
-
if (!result) {
|
|
24
|
-
return undefined;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return result as T;
|
|
28
|
-
} catch (err) {
|
|
29
|
-
return undefined;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
private isNumeric(value: any): boolean {
|
|
34
|
-
return !isNaN(parseFloat(value)) && isFinite(value);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export const enumHelper = new EnumHelper();
|
|
1
|
+
export class EnumHelper {
|
|
2
|
+
getAllValues(T: any): string[] {
|
|
3
|
+
const allEnumValues: string[] = Object.keys(T).map((key) => T[key]);
|
|
4
|
+
return allEnumValues;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
getEnumFromValue<T>(T: any, value: string | number): T | undefined {
|
|
8
|
+
try {
|
|
9
|
+
if (!value) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// we can map back from index number directly
|
|
14
|
+
if (this.isNumeric(value)) {
|
|
15
|
+
return <T>T[value];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// for strings, we need to compare each value separately
|
|
19
|
+
const allEnumValues = this.getAllValues(T);
|
|
20
|
+
|
|
21
|
+
const result = allEnumValues.find((m) => m.toLowerCase() === value.toString().toLowerCase());
|
|
22
|
+
|
|
23
|
+
if (!result) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return result as T;
|
|
28
|
+
} catch (err) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
private isNumeric(value: any): boolean {
|
|
34
|
+
return !isNaN(parseFloat(value)) && isFinite(value);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const enumHelper = new EnumHelper();
|
package/lib/utilities/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './codename.helper';
|
|
2
|
-
export * from './delivery-url.helper';
|
|
3
|
-
export * from './enum.helper';
|
|
1
|
+
export * from './codename.helper';
|
|
2
|
+
export * from './delivery-url.helper';
|
|
3
|
+
export * from './enum.helper';
|