@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,95 +1,95 @@
|
|
|
1
|
-
import { IDeliveryClientConfig } from '../../config';
|
|
2
|
-
import {
|
|
3
|
-
continuationTokenHeaderName,
|
|
4
|
-
IGroupedNetworkResponse,
|
|
5
|
-
IKontentListAllResponse,
|
|
6
|
-
IKontentListResponse,
|
|
7
|
-
IDeliveryNetworkResponse,
|
|
8
|
-
IListAllQueryConfig,
|
|
9
|
-
IQueryConfig,
|
|
10
|
-
IContentItem,
|
|
11
|
-
ClientTypes,
|
|
12
|
-
IUsedInItemRecord,
|
|
13
|
-
IContentType,
|
|
14
|
-
ITaxonomyGroup,
|
|
15
|
-
IContentItemDelta,
|
|
16
|
-
ILanguage
|
|
17
|
-
} from '../../models';
|
|
18
|
-
import { QueryService } from '../../services';
|
|
19
|
-
import { BaseQuery } from './base-query.class';
|
|
20
|
-
|
|
21
|
-
type ListingRecord<TClientTypes extends ClientTypes> =
|
|
22
|
-
| IContentItem
|
|
23
|
-
| IContentItemDelta
|
|
24
|
-
| IUsedInItemRecord<TClientTypes>
|
|
25
|
-
| IContentType<TClientTypes['contentTypeCodenames']>
|
|
26
|
-
| ILanguage<TClientTypes['languageCodenames']>
|
|
27
|
-
| ITaxonomyGroup<TClientTypes['taxonomyCodenames']>;
|
|
28
|
-
|
|
29
|
-
export abstract class BaseListingQuery<
|
|
30
|
-
TClientTypes extends ClientTypes,
|
|
31
|
-
TRecord extends ListingRecord<TClientTypes>,
|
|
32
|
-
TResponse extends IKontentListResponse,
|
|
33
|
-
TAllResponse extends IKontentListAllResponse,
|
|
34
|
-
TQueryConfig extends IQueryConfig,
|
|
35
|
-
TContract
|
|
36
|
-
> extends BaseQuery<TClientTypes, TResponse, TQueryConfig, TContract> {
|
|
37
|
-
constructor(protected config: IDeliveryClientConfig, protected queryService: QueryService<TClientTypes>) {
|
|
38
|
-
super(config, queryService);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Sets continuation token header
|
|
43
|
-
*/
|
|
44
|
-
withContinuationToken(token: string): this {
|
|
45
|
-
// remove previous continuation token if there is any
|
|
46
|
-
let queryHeaders = this._queryConfig.customHeaders ?? [];
|
|
47
|
-
queryHeaders = queryHeaders.filter((m) => m.header !== continuationTokenHeaderName);
|
|
48
|
-
|
|
49
|
-
this._queryConfig.customHeaders = queryHeaders;
|
|
50
|
-
|
|
51
|
-
this.withHeaders([
|
|
52
|
-
{
|
|
53
|
-
header: continuationTokenHeaderName,
|
|
54
|
-
value: token
|
|
55
|
-
}
|
|
56
|
-
]);
|
|
57
|
-
|
|
58
|
-
return this;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Query to get all items. Uses paging data and may execute multiple HTTP requests depending on number of items
|
|
63
|
-
*/
|
|
64
|
-
toAllPromise(
|
|
65
|
-
queryAllConfig?: IListAllQueryConfig<TResponse, TContract>
|
|
66
|
-
): Promise<IGroupedNetworkResponse<TAllResponse>> {
|
|
67
|
-
return this.queryService.getListAllResponse<TResponse, TAllResponse, TContract>({
|
|
68
|
-
page: 1,
|
|
69
|
-
listQueryConfig: queryAllConfig,
|
|
70
|
-
allResponseFactory: (items, responses) => {
|
|
71
|
-
const response = this.allResponseFactory(items, responses);
|
|
72
|
-
|
|
73
|
-
return {
|
|
74
|
-
data: response,
|
|
75
|
-
responses: responses
|
|
76
|
-
};
|
|
77
|
-
},
|
|
78
|
-
getResponse: (nextPageUrl, continuationToken) => {
|
|
79
|
-
if (nextPageUrl) {
|
|
80
|
-
this.withCustomUrl(nextPageUrl);
|
|
81
|
-
}
|
|
82
|
-
if (continuationToken) {
|
|
83
|
-
this.withContinuationToken(continuationToken);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return this.toPromise();
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
protected abstract allResponseFactory(
|
|
92
|
-
items: TRecord[],
|
|
93
|
-
responses: IDeliveryNetworkResponse<TResponse, TContract>[]
|
|
94
|
-
): TAllResponse;
|
|
95
|
-
}
|
|
1
|
+
import { IDeliveryClientConfig } from '../../config';
|
|
2
|
+
import {
|
|
3
|
+
continuationTokenHeaderName,
|
|
4
|
+
IGroupedNetworkResponse,
|
|
5
|
+
IKontentListAllResponse,
|
|
6
|
+
IKontentListResponse,
|
|
7
|
+
IDeliveryNetworkResponse,
|
|
8
|
+
IListAllQueryConfig,
|
|
9
|
+
IQueryConfig,
|
|
10
|
+
IContentItem,
|
|
11
|
+
ClientTypes,
|
|
12
|
+
IUsedInItemRecord,
|
|
13
|
+
IContentType,
|
|
14
|
+
ITaxonomyGroup,
|
|
15
|
+
IContentItemDelta,
|
|
16
|
+
ILanguage
|
|
17
|
+
} from '../../models';
|
|
18
|
+
import { QueryService } from '../../services';
|
|
19
|
+
import { BaseQuery } from './base-query.class';
|
|
20
|
+
|
|
21
|
+
type ListingRecord<TClientTypes extends ClientTypes> =
|
|
22
|
+
| IContentItem
|
|
23
|
+
| IContentItemDelta
|
|
24
|
+
| IUsedInItemRecord<TClientTypes>
|
|
25
|
+
| IContentType<TClientTypes['contentTypeCodenames']>
|
|
26
|
+
| ILanguage<TClientTypes['languageCodenames']>
|
|
27
|
+
| ITaxonomyGroup<TClientTypes['taxonomyCodenames']>;
|
|
28
|
+
|
|
29
|
+
export abstract class BaseListingQuery<
|
|
30
|
+
TClientTypes extends ClientTypes,
|
|
31
|
+
TRecord extends ListingRecord<TClientTypes>,
|
|
32
|
+
TResponse extends IKontentListResponse,
|
|
33
|
+
TAllResponse extends IKontentListAllResponse,
|
|
34
|
+
TQueryConfig extends IQueryConfig,
|
|
35
|
+
TContract
|
|
36
|
+
> extends BaseQuery<TClientTypes, TResponse, TQueryConfig, TContract> {
|
|
37
|
+
constructor(protected config: IDeliveryClientConfig, protected queryService: QueryService<TClientTypes>) {
|
|
38
|
+
super(config, queryService);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Sets continuation token header
|
|
43
|
+
*/
|
|
44
|
+
withContinuationToken(token: string): this {
|
|
45
|
+
// remove previous continuation token if there is any
|
|
46
|
+
let queryHeaders = this._queryConfig.customHeaders ?? [];
|
|
47
|
+
queryHeaders = queryHeaders.filter((m) => m.header !== continuationTokenHeaderName);
|
|
48
|
+
|
|
49
|
+
this._queryConfig.customHeaders = queryHeaders;
|
|
50
|
+
|
|
51
|
+
this.withHeaders([
|
|
52
|
+
{
|
|
53
|
+
header: continuationTokenHeaderName,
|
|
54
|
+
value: token
|
|
55
|
+
}
|
|
56
|
+
]);
|
|
57
|
+
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Query to get all items. Uses paging data and may execute multiple HTTP requests depending on number of items
|
|
63
|
+
*/
|
|
64
|
+
toAllPromise(
|
|
65
|
+
queryAllConfig?: IListAllQueryConfig<TResponse, TContract>
|
|
66
|
+
): Promise<IGroupedNetworkResponse<TAllResponse>> {
|
|
67
|
+
return this.queryService.getListAllResponse<TResponse, TAllResponse, TContract>({
|
|
68
|
+
page: 1,
|
|
69
|
+
listQueryConfig: queryAllConfig,
|
|
70
|
+
allResponseFactory: (items, responses) => {
|
|
71
|
+
const response = this.allResponseFactory(items, responses);
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
data: response,
|
|
75
|
+
responses: responses
|
|
76
|
+
};
|
|
77
|
+
},
|
|
78
|
+
getResponse: (nextPageUrl, continuationToken) => {
|
|
79
|
+
if (nextPageUrl) {
|
|
80
|
+
this.withCustomUrl(nextPageUrl);
|
|
81
|
+
}
|
|
82
|
+
if (continuationToken) {
|
|
83
|
+
this.withContinuationToken(continuationToken);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return this.toPromise();
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
protected abstract allResponseFactory(
|
|
92
|
+
items: TRecord[],
|
|
93
|
+
responses: IDeliveryNetworkResponse<TResponse, TContract>[]
|
|
94
|
+
): TAllResponse;
|
|
95
|
+
}
|
|
@@ -1,148 +1,148 @@
|
|
|
1
|
-
import { IHeader, IQueryParameter } from '@kontent-ai/core-sdk';
|
|
2
|
-
|
|
3
|
-
import { IDeliveryClientConfig } from '../../config';
|
|
4
|
-
import {
|
|
5
|
-
ClientTypes,
|
|
6
|
-
Filters,
|
|
7
|
-
IDeliveryNetworkResponse,
|
|
8
|
-
IKontentResponse,
|
|
9
|
-
IQueryConfig,
|
|
10
|
-
Parameters
|
|
11
|
-
} from '../../models';
|
|
12
|
-
import { QueryService } from '../../services';
|
|
13
|
-
|
|
14
|
-
export abstract class BaseQuery<
|
|
15
|
-
TClientTypes extends ClientTypes,
|
|
16
|
-
TResponse extends IKontentResponse,
|
|
17
|
-
TQueryConfig extends IQueryConfig,
|
|
18
|
-
TContract
|
|
19
|
-
> {
|
|
20
|
-
protected parameters: IQueryParameter[] = [];
|
|
21
|
-
protected customUrl?: string;
|
|
22
|
-
protected abstract _queryConfig: TQueryConfig;
|
|
23
|
-
constructor(protected config: IDeliveryClientConfig, protected queryService: QueryService<TClientTypes>) {}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Gets URL of the query
|
|
27
|
-
*/
|
|
28
|
-
abstract getUrl(): string;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Gets promise for query execution
|
|
32
|
-
*/
|
|
33
|
-
abstract toPromise(): Promise<IDeliveryNetworkResponse<TResponse, TContract>>;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Maps json data to response
|
|
37
|
-
*/
|
|
38
|
-
abstract map(json: any): TResponse;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Adds custom parameter to query
|
|
42
|
-
* @param name Name of parameter
|
|
43
|
-
* @param value Value of parameter
|
|
44
|
-
*/
|
|
45
|
-
withCustomParameter(name: string, value: string): this {
|
|
46
|
-
this.parameters.push(new Parameters.QueryParameter(name, value));
|
|
47
|
-
return this;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Adds parameter to query
|
|
52
|
-
* @param name Name of parameter
|
|
53
|
-
* @param value Value of parameter
|
|
54
|
-
*/
|
|
55
|
-
withParameter(parameter: IQueryParameter): this {
|
|
56
|
-
this.parameters.push(parameter);
|
|
57
|
-
return this;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Adds parameters to query
|
|
62
|
-
* @param parameters Array of parameters
|
|
63
|
-
*/
|
|
64
|
-
withParameters(parameters: IQueryParameter[]): this {
|
|
65
|
-
this.parameters.push(...parameters);
|
|
66
|
-
return this;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Gets headers used by this query
|
|
71
|
-
*/
|
|
72
|
-
getHeaders(): IHeader[] {
|
|
73
|
-
return this.queryService.getHeaders(this._queryConfig, []);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Sets request headers
|
|
78
|
-
*/
|
|
79
|
-
withHeaders(headers: IHeader[]): this {
|
|
80
|
-
const queryHeaders = this._queryConfig.customHeaders ?? [];
|
|
81
|
-
queryHeaders.push(...headers);
|
|
82
|
-
this._queryConfig.customHeaders = queryHeaders;
|
|
83
|
-
return this;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Sets request header
|
|
88
|
-
*/
|
|
89
|
-
withHeader(header: IHeader): this {
|
|
90
|
-
const queryHeaders = this._queryConfig.customHeaders ?? [];
|
|
91
|
-
queryHeaders.push(header);
|
|
92
|
-
this._queryConfig.customHeaders = queryHeaders;
|
|
93
|
-
return this;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Sets custom URL of request (overrides default URL of the query)
|
|
98
|
-
*/
|
|
99
|
-
withCustomUrl(url: string): this {
|
|
100
|
-
this.customUrl = url;
|
|
101
|
-
return this;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Gets all query parameter currently applied to query
|
|
106
|
-
*/
|
|
107
|
-
getParameters(): IQueryParameter[] {
|
|
108
|
-
return this.parameters;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Used to configure query
|
|
113
|
-
* @param queryConfig Query configuration
|
|
114
|
-
*/
|
|
115
|
-
queryConfig(queryConfig: TQueryConfig): this {
|
|
116
|
-
this._queryConfig = queryConfig;
|
|
117
|
-
return this;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
protected resolveUrlInternal(action: string): string {
|
|
121
|
-
// use custom URL if user specified it
|
|
122
|
-
if (this.customUrl) {
|
|
123
|
-
return this.customUrl;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// use original url
|
|
127
|
-
return this.queryService.getUrl(action, this._queryConfig ?? {}, this.getParameters());
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
protected processDefaultLanguageParameter(): void {
|
|
131
|
-
// add default language if none is specified && default language is specified globally
|
|
132
|
-
if (this.config.defaultLanguage) {
|
|
133
|
-
const languageParameter = this.getParameters().find((m) =>
|
|
134
|
-
m.getParam()?.toLowerCase().includes('language='.toLowerCase())
|
|
135
|
-
);
|
|
136
|
-
if (!languageParameter) {
|
|
137
|
-
// language parameter was not specified in query, use globally defined language
|
|
138
|
-
this.parameters.push(new Parameters.LanguageParameter(this.config.defaultLanguage));
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
protected processExcludeArchivedItemsParameter(): void {
|
|
144
|
-
if (this.config.excludeArchivedItems) {
|
|
145
|
-
this.parameters.push(new Filters.NotEqualsFilter('system.workflow_step', 'archived'));
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
1
|
+
import { IHeader, IQueryParameter } from '@kontent-ai/core-sdk';
|
|
2
|
+
|
|
3
|
+
import { IDeliveryClientConfig } from '../../config';
|
|
4
|
+
import {
|
|
5
|
+
ClientTypes,
|
|
6
|
+
Filters,
|
|
7
|
+
IDeliveryNetworkResponse,
|
|
8
|
+
IKontentResponse,
|
|
9
|
+
IQueryConfig,
|
|
10
|
+
Parameters
|
|
11
|
+
} from '../../models';
|
|
12
|
+
import { QueryService } from '../../services';
|
|
13
|
+
|
|
14
|
+
export abstract class BaseQuery<
|
|
15
|
+
TClientTypes extends ClientTypes,
|
|
16
|
+
TResponse extends IKontentResponse,
|
|
17
|
+
TQueryConfig extends IQueryConfig,
|
|
18
|
+
TContract
|
|
19
|
+
> {
|
|
20
|
+
protected parameters: IQueryParameter[] = [];
|
|
21
|
+
protected customUrl?: string;
|
|
22
|
+
protected abstract _queryConfig: TQueryConfig;
|
|
23
|
+
constructor(protected config: IDeliveryClientConfig, protected queryService: QueryService<TClientTypes>) {}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Gets URL of the query
|
|
27
|
+
*/
|
|
28
|
+
abstract getUrl(): string;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Gets promise for query execution
|
|
32
|
+
*/
|
|
33
|
+
abstract toPromise(): Promise<IDeliveryNetworkResponse<TResponse, TContract>>;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Maps json data to response
|
|
37
|
+
*/
|
|
38
|
+
abstract map(json: any): TResponse;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Adds custom parameter to query
|
|
42
|
+
* @param name Name of parameter
|
|
43
|
+
* @param value Value of parameter
|
|
44
|
+
*/
|
|
45
|
+
withCustomParameter(name: string, value: string): this {
|
|
46
|
+
this.parameters.push(new Parameters.QueryParameter(name, value));
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Adds parameter to query
|
|
52
|
+
* @param name Name of parameter
|
|
53
|
+
* @param value Value of parameter
|
|
54
|
+
*/
|
|
55
|
+
withParameter(parameter: IQueryParameter): this {
|
|
56
|
+
this.parameters.push(parameter);
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Adds parameters to query
|
|
62
|
+
* @param parameters Array of parameters
|
|
63
|
+
*/
|
|
64
|
+
withParameters(parameters: IQueryParameter[]): this {
|
|
65
|
+
this.parameters.push(...parameters);
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Gets headers used by this query
|
|
71
|
+
*/
|
|
72
|
+
getHeaders(): IHeader[] {
|
|
73
|
+
return this.queryService.getHeaders(this._queryConfig, []);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Sets request headers
|
|
78
|
+
*/
|
|
79
|
+
withHeaders(headers: IHeader[]): this {
|
|
80
|
+
const queryHeaders = this._queryConfig.customHeaders ?? [];
|
|
81
|
+
queryHeaders.push(...headers);
|
|
82
|
+
this._queryConfig.customHeaders = queryHeaders;
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Sets request header
|
|
88
|
+
*/
|
|
89
|
+
withHeader(header: IHeader): this {
|
|
90
|
+
const queryHeaders = this._queryConfig.customHeaders ?? [];
|
|
91
|
+
queryHeaders.push(header);
|
|
92
|
+
this._queryConfig.customHeaders = queryHeaders;
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Sets custom URL of request (overrides default URL of the query)
|
|
98
|
+
*/
|
|
99
|
+
withCustomUrl(url: string): this {
|
|
100
|
+
this.customUrl = url;
|
|
101
|
+
return this;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Gets all query parameter currently applied to query
|
|
106
|
+
*/
|
|
107
|
+
getParameters(): IQueryParameter[] {
|
|
108
|
+
return this.parameters;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Used to configure query
|
|
113
|
+
* @param queryConfig Query configuration
|
|
114
|
+
*/
|
|
115
|
+
queryConfig(queryConfig: TQueryConfig): this {
|
|
116
|
+
this._queryConfig = queryConfig;
|
|
117
|
+
return this;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
protected resolveUrlInternal(action: string): string {
|
|
121
|
+
// use custom URL if user specified it
|
|
122
|
+
if (this.customUrl) {
|
|
123
|
+
return this.customUrl;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// use original url
|
|
127
|
+
return this.queryService.getUrl(action, this._queryConfig ?? {}, this.getParameters());
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
protected processDefaultLanguageParameter(): void {
|
|
131
|
+
// add default language if none is specified && default language is specified globally
|
|
132
|
+
if (this.config.defaultLanguage) {
|
|
133
|
+
const languageParameter = this.getParameters().find((m) =>
|
|
134
|
+
m.getParam()?.toLowerCase().includes('language='.toLowerCase())
|
|
135
|
+
);
|
|
136
|
+
if (!languageParameter) {
|
|
137
|
+
// language parameter was not specified in query, use globally defined language
|
|
138
|
+
this.parameters.push(new Parameters.LanguageParameter(this.config.defaultLanguage));
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
protected processExcludeArchivedItemsParameter(): void {
|
|
144
|
+
if (this.config.excludeArchivedItems) {
|
|
145
|
+
this.parameters.push(new Filters.NotEqualsFilter('system.workflow_step', 'archived'));
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import { Contracts } from '../../contracts';
|
|
2
|
-
import { IDeliveryClientConfig } from '../../config';
|
|
3
|
-
import { Responses, IElementQueryConfig, IDeliveryNetworkResponse, ClientTypes } from '../../models';
|
|
4
|
-
import { QueryService } from '../../services';
|
|
5
|
-
import { BaseQuery } from '../common/base-query.class';
|
|
6
|
-
|
|
7
|
-
export class ElementQuery<TClientTypes extends ClientTypes> extends BaseQuery<
|
|
8
|
-
TClientTypes,
|
|
9
|
-
Responses.IViewContentTypeElementResponse,
|
|
10
|
-
IElementQueryConfig,
|
|
11
|
-
Contracts.IViewContentTypeElementContract
|
|
12
|
-
> {
|
|
13
|
-
protected _queryConfig: IElementQueryConfig = {};
|
|
14
|
-
|
|
15
|
-
constructor(
|
|
16
|
-
protected config: IDeliveryClientConfig,
|
|
17
|
-
protected queryService: QueryService<TClientTypes>,
|
|
18
|
-
private typeCodename: string,
|
|
19
|
-
private elementCodename: string
|
|
20
|
-
) {
|
|
21
|
-
super(config, queryService);
|
|
22
|
-
|
|
23
|
-
if (!typeCodename) {
|
|
24
|
-
throw Error(`Codename of the type has to be provided`);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (!elementCodename) {
|
|
28
|
-
throw Error(`Codename of the element has to be provided`);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
toPromise(): Promise<
|
|
33
|
-
IDeliveryNetworkResponse<Responses.IViewContentTypeElementResponse, Contracts.IViewContentTypeElementContract>
|
|
34
|
-
> {
|
|
35
|
-
return this.queryService.getElementAsync(this.getUrl(), this._queryConfig ?? {});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
getUrl(): string {
|
|
39
|
-
return super.resolveUrlInternal(`/types/${this.typeCodename}/elements/${this.elementCodename}`);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
map(json: any): Responses.IViewContentTypeElementResponse {
|
|
43
|
-
return this.queryService.mappingService.viewContentTypeElementResponse(json);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
1
|
+
import { Contracts } from '../../contracts';
|
|
2
|
+
import { IDeliveryClientConfig } from '../../config';
|
|
3
|
+
import { Responses, IElementQueryConfig, IDeliveryNetworkResponse, ClientTypes } from '../../models';
|
|
4
|
+
import { QueryService } from '../../services';
|
|
5
|
+
import { BaseQuery } from '../common/base-query.class';
|
|
6
|
+
|
|
7
|
+
export class ElementQuery<TClientTypes extends ClientTypes> extends BaseQuery<
|
|
8
|
+
TClientTypes,
|
|
9
|
+
Responses.IViewContentTypeElementResponse,
|
|
10
|
+
IElementQueryConfig,
|
|
11
|
+
Contracts.IViewContentTypeElementContract
|
|
12
|
+
> {
|
|
13
|
+
protected _queryConfig: IElementQueryConfig = {};
|
|
14
|
+
|
|
15
|
+
constructor(
|
|
16
|
+
protected config: IDeliveryClientConfig,
|
|
17
|
+
protected queryService: QueryService<TClientTypes>,
|
|
18
|
+
private typeCodename: string,
|
|
19
|
+
private elementCodename: string
|
|
20
|
+
) {
|
|
21
|
+
super(config, queryService);
|
|
22
|
+
|
|
23
|
+
if (!typeCodename) {
|
|
24
|
+
throw Error(`Codename of the type has to be provided`);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (!elementCodename) {
|
|
28
|
+
throw Error(`Codename of the element has to be provided`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
toPromise(): Promise<
|
|
33
|
+
IDeliveryNetworkResponse<Responses.IViewContentTypeElementResponse, Contracts.IViewContentTypeElementContract>
|
|
34
|
+
> {
|
|
35
|
+
return this.queryService.getElementAsync(this.getUrl(), this._queryConfig ?? {});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
getUrl(): string {
|
|
39
|
+
return super.resolveUrlInternal(`/types/${this.typeCodename}/elements/${this.elementCodename}`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
map(json: any): Responses.IViewContentTypeElementResponse {
|
|
43
|
+
return this.queryService.mappingService.viewContentTypeElementResponse(json);
|
|
44
|
+
}
|
|
45
|
+
}
|
package/lib/query/index.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
export * from './common/base-query.class';
|
|
2
|
-
export * from './element/element-query.class';
|
|
3
|
-
export * from './item/multiple-items-query.class';
|
|
4
|
-
export * from './item/single-item-query.class';
|
|
5
|
-
export * from './taxonomy/taxonomies-query.class';
|
|
6
|
-
export * from './taxonomy/taxonomy-query.class';
|
|
7
|
-
export * from './type/multiple-type-query.class';
|
|
8
|
-
export * from './type/single-type-query.class';
|
|
9
|
-
export * from './items-feed/items-feed-query.class';
|
|
10
|
-
export * from './language/languages-query.class';
|
|
11
|
-
export * from './sync/initialize-sync-query.class';
|
|
12
|
-
export * from './sync/sync-changes-query.class';
|
|
13
|
-
export * from './used-in/used-in-query.class';
|
|
1
|
+
export * from './common/base-query.class';
|
|
2
|
+
export * from './element/element-query.class';
|
|
3
|
+
export * from './item/multiple-items-query.class';
|
|
4
|
+
export * from './item/single-item-query.class';
|
|
5
|
+
export * from './taxonomy/taxonomies-query.class';
|
|
6
|
+
export * from './taxonomy/taxonomy-query.class';
|
|
7
|
+
export * from './type/multiple-type-query.class';
|
|
8
|
+
export * from './type/single-type-query.class';
|
|
9
|
+
export * from './items-feed/items-feed-query.class';
|
|
10
|
+
export * from './language/languages-query.class';
|
|
11
|
+
export * from './sync/initialize-sync-query.class';
|
|
12
|
+
export * from './sync/sync-changes-query.class';
|
|
13
|
+
export * from './used-in/used-in-query.class';
|