@sitecore-content-sdk/core 0.1.0-beta.1
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/LICENSE.txt +202 -0
- package/README.md +11 -0
- package/dist/cjs/cache-client.js +54 -0
- package/dist/cjs/constants.js +13 -0
- package/dist/cjs/data-fetcher.js +33 -0
- package/dist/cjs/debug.js +43 -0
- package/dist/cjs/editing/component-library.js +104 -0
- package/dist/cjs/editing/graphql-editing-service.js +186 -0
- package/dist/cjs/editing/index.js +23 -0
- package/dist/cjs/editing/models.js +23 -0
- package/dist/cjs/editing/rest-component-layout-service.js +76 -0
- package/dist/cjs/editing/utils.js +86 -0
- package/dist/cjs/graphql/app-root-query.js +73 -0
- package/dist/cjs/graphql/graphql-edge-proxy.js +21 -0
- package/dist/cjs/graphql/index.js +13 -0
- package/dist/cjs/graphql/search-service.js +61 -0
- package/dist/cjs/graphql-request-client.js +152 -0
- package/dist/cjs/i18n/dictionary-service.js +45 -0
- package/dist/cjs/i18n/graphql-dictionary-service.js +136 -0
- package/dist/cjs/i18n/index.js +7 -0
- package/dist/cjs/index.js +55 -0
- package/dist/cjs/layout/content-styles.js +70 -0
- package/dist/cjs/layout/graphql-layout-service.js +86 -0
- package/dist/cjs/layout/index.js +24 -0
- package/dist/cjs/layout/layout-service.js +9 -0
- package/dist/cjs/layout/models.js +35 -0
- package/dist/cjs/layout/themes.js +74 -0
- package/dist/cjs/layout/utils.js +110 -0
- package/dist/cjs/media/index.js +38 -0
- package/dist/cjs/media/media-api.js +96 -0
- package/dist/cjs/models.js +2 -0
- package/dist/cjs/native-fetcher.js +200 -0
- package/dist/cjs/personalize/graphql-personalize-service.js +114 -0
- package/dist/cjs/personalize/index.js +14 -0
- package/dist/cjs/personalize/layout-personalizer.js +97 -0
- package/dist/cjs/personalize/utils.js +136 -0
- package/dist/cjs/site/graphql-error-pages-service.js +89 -0
- package/dist/cjs/site/graphql-redirects-service.js +105 -0
- package/dist/cjs/site/graphql-robots-service.js +83 -0
- package/dist/cjs/site/graphql-siteinfo-service.js +107 -0
- package/dist/cjs/site/graphql-sitemap-service.js +93 -0
- package/dist/cjs/site/index.js +22 -0
- package/dist/cjs/site/site-resolver.js +79 -0
- package/dist/cjs/site/utils.js +43 -0
- package/dist/cjs/utils/env.js +26 -0
- package/dist/cjs/utils/index.js +20 -0
- package/dist/cjs/utils/is-server.js +10 -0
- package/dist/cjs/utils/timeout-promise.js +31 -0
- package/dist/cjs/utils/utils.js +222 -0
- package/dist/esm/cache-client.js +50 -0
- package/dist/esm/constants.js +10 -0
- package/dist/esm/data-fetcher.js +28 -0
- package/dist/esm/debug.js +36 -0
- package/dist/esm/editing/component-library.js +98 -0
- package/dist/esm/editing/graphql-editing-service.js +179 -0
- package/dist/esm/editing/index.js +5 -0
- package/dist/esm/editing/models.js +20 -0
- package/dist/esm/editing/rest-component-layout-service.js +72 -0
- package/dist/esm/editing/utils.js +76 -0
- package/dist/esm/graphql/app-root-query.js +69 -0
- package/dist/esm/graphql/graphql-edge-proxy.js +16 -0
- package/dist/esm/graphql/index.js +4 -0
- package/dist/esm/graphql/search-service.js +57 -0
- package/dist/esm/graphql-request-client.js +144 -0
- package/dist/esm/i18n/dictionary-service.js +41 -0
- package/dist/esm/i18n/graphql-dictionary-service.js +129 -0
- package/dist/esm/i18n/index.js +2 -0
- package/dist/esm/index.js +9 -0
- package/dist/esm/layout/content-styles.js +62 -0
- package/dist/esm/layout/graphql-layout-service.js +79 -0
- package/dist/esm/layout/index.js +6 -0
- package/dist/esm/layout/layout-service.js +5 -0
- package/dist/esm/layout/models.js +32 -0
- package/dist/esm/layout/themes.js +69 -0
- package/dist/esm/layout/utils.js +102 -0
- package/dist/esm/media/index.js +2 -0
- package/dist/esm/media/media-api.js +86 -0
- package/dist/esm/models.js +1 -0
- package/dist/esm/native-fetcher.js +193 -0
- package/dist/esm/personalize/graphql-personalize-service.js +107 -0
- package/dist/esm/personalize/index.js +3 -0
- package/dist/esm/personalize/layout-personalizer.js +92 -0
- package/dist/esm/personalize/utils.js +128 -0
- package/dist/esm/site/graphql-error-pages-service.js +82 -0
- package/dist/esm/site/graphql-redirects-service.js +98 -0
- package/dist/esm/site/graphql-robots-service.js +76 -0
- package/dist/esm/site/graphql-siteinfo-service.js +100 -0
- package/dist/esm/site/graphql-sitemap-service.js +86 -0
- package/dist/esm/site/index.js +7 -0
- package/dist/esm/site/site-resolver.js +75 -0
- package/dist/esm/site/utils.js +37 -0
- package/dist/esm/utils/env.js +22 -0
- package/dist/esm/utils/index.js +3 -0
- package/dist/esm/utils/is-server.js +8 -0
- package/dist/esm/utils/timeout-promise.js +28 -0
- package/dist/esm/utils/utils.js +207 -0
- package/editing.d.ts +1 -0
- package/editing.js +1 -0
- package/graphql.d.ts +1 -0
- package/graphql.js +1 -0
- package/i18n.d.ts +1 -0
- package/i18n.js +1 -0
- package/layout.d.ts +1 -0
- package/layout.js +1 -0
- package/media.d.ts +1 -0
- package/media.js +1 -0
- package/package.json +76 -0
- package/personalize.d.ts +1 -0
- package/personalize.js +1 -0
- package/site.d.ts +1 -0
- package/site.js +1 -0
- package/types/cache-client.d.ts +64 -0
- package/types/constants.d.ts +7 -0
- package/types/data-fetcher.d.ts +34 -0
- package/types/debug.d.ts +26 -0
- package/types/editing/component-library.d.ts +48 -0
- package/types/editing/graphql-editing-service.d.ts +90 -0
- package/types/editing/index.d.ts +6 -0
- package/types/editing/models.d.ts +52 -0
- package/types/editing/rest-component-layout-service.d.ts +100 -0
- package/types/editing/utils.d.ts +70 -0
- package/types/graphql/app-root-query.d.ts +32 -0
- package/types/graphql/graphql-edge-proxy.d.ts +15 -0
- package/types/graphql/index.d.ts +4 -0
- package/types/graphql/search-service.d.ts +95 -0
- package/types/graphql-request-client.d.ts +159 -0
- package/types/i18n/dictionary-service.d.ts +56 -0
- package/types/i18n/graphql-dictionary-service.d.ts +94 -0
- package/types/i18n/index.d.ts +2 -0
- package/types/index.d.ts +8 -0
- package/types/layout/content-styles.d.ts +18 -0
- package/types/layout/graphql-layout-service.d.ts +58 -0
- package/types/layout/index.d.ts +6 -0
- package/types/layout/layout-service.d.ts +19 -0
- package/types/layout/models.d.ts +145 -0
- package/types/layout/themes.d.ts +11 -0
- package/types/layout/utils.d.ts +40 -0
- package/types/media/index.d.ts +2 -0
- package/types/media/media-api.d.ts +55 -0
- package/types/models.d.ts +6 -0
- package/types/native-fetcher.d.ts +121 -0
- package/types/personalize/graphql-personalize-service.d.ts +80 -0
- package/types/personalize/index.d.ts +3 -0
- package/types/personalize/layout-personalizer.d.ts +27 -0
- package/types/personalize/utils.d.ts +69 -0
- package/types/site/graphql-error-pages-service.d.ts +57 -0
- package/types/site/graphql-redirects-service.d.ts +68 -0
- package/types/site/graphql-robots-service.d.ts +49 -0
- package/types/site/graphql-siteinfo-service.d.ts +70 -0
- package/types/site/graphql-sitemap-service.d.ts +55 -0
- package/types/site/index.d.ts +7 -0
- package/types/site/site-resolver.d.ts +27 -0
- package/types/site/utils.d.ts +24 -0
- package/types/utils/env.d.ts +7 -0
- package/types/utils/index.d.ts +3 -0
- package/types/utils/is-server.d.ts +6 -0
- package/types/utils/timeout-promise.d.ts +17 -0
- package/types/utils/utils.d.ts +71 -0
- package/utils.d.ts +1 -0
- package/utils.js +1 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { DocumentNode } from 'graphql';
|
|
2
|
+
import { GraphQLClient } from '../graphql-request-client';
|
|
3
|
+
/**
|
|
4
|
+
* Data needed to paginate results
|
|
5
|
+
*/
|
|
6
|
+
export interface PageInfo {
|
|
7
|
+
/**
|
|
8
|
+
* string token that can be used to fetch the next page of results
|
|
9
|
+
*/
|
|
10
|
+
endCursor: string;
|
|
11
|
+
/**
|
|
12
|
+
* a value that indicates whether more pages of results are available
|
|
13
|
+
*/
|
|
14
|
+
hasNext: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Schema of data returned in response to a "search" query request
|
|
18
|
+
* @template T The type of objects being requested.
|
|
19
|
+
*/
|
|
20
|
+
export type SearchQueryResult<T> = {
|
|
21
|
+
search: {
|
|
22
|
+
/**
|
|
23
|
+
* Data needed to paginate the search results
|
|
24
|
+
*/
|
|
25
|
+
pageInfo: PageInfo;
|
|
26
|
+
results: T[];
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Describes the variables used by the 'search' query. Language should always be specified.
|
|
31
|
+
* The other predicates are optional.
|
|
32
|
+
*/
|
|
33
|
+
export interface SearchQueryVariables {
|
|
34
|
+
/**
|
|
35
|
+
* Required. The language versions to search for. Fetch pages that have versions in this language.
|
|
36
|
+
*/
|
|
37
|
+
language: string;
|
|
38
|
+
/**
|
|
39
|
+
* Optional. The ID of the search root item. Fetch items that have this item as an ancestor.
|
|
40
|
+
*/
|
|
41
|
+
rootItemId?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Optional. Sitecore template ID(s). Fetch items that inherit from this template(s).
|
|
44
|
+
*/
|
|
45
|
+
templates?: string;
|
|
46
|
+
/**
|
|
47
|
+
* common variable for all GraphQL queries
|
|
48
|
+
* it will be used for every type of query to regulate result batch size
|
|
49
|
+
* Optional. How many result items to fetch in each GraphQL call. This is needed for pagination.
|
|
50
|
+
* @default 10
|
|
51
|
+
*/
|
|
52
|
+
pageSize?: number;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* @deprecated will be removed with SearchQueryService. Use GraphQLClient and supporting types
|
|
56
|
+
* Configuration options for service classes that extend @see SearchQueryService.
|
|
57
|
+
* This extends @see SearchQueryVariables because properties that can be passed to the search query
|
|
58
|
+
* as predicates should be configurable. 'language' is excluded because, normally, all properties
|
|
59
|
+
* except 'language' are consistent across languages so they are passed to constructors, and
|
|
60
|
+
* 'language' can vary so it is passed to methods.
|
|
61
|
+
*/
|
|
62
|
+
export interface SearchServiceConfig extends Omit<SearchQueryVariables, 'language'> {
|
|
63
|
+
/**
|
|
64
|
+
* The name of the current Sitecore site. This is used to to determine the search query root
|
|
65
|
+
* in cases where one is not specified by the caller.
|
|
66
|
+
*/
|
|
67
|
+
siteName: string;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* @deprecated use GraphQLClient instead
|
|
71
|
+
* Provides functionality for performing GraphQL 'search' operations, including handling pagination.
|
|
72
|
+
* This class is meant to be extended or used as a mixin; it's not meant to be used directly.
|
|
73
|
+
* @template T The type of objects being requested.
|
|
74
|
+
* @mixin
|
|
75
|
+
*/
|
|
76
|
+
export declare class SearchQueryService<T> {
|
|
77
|
+
protected client: GraphQLClient;
|
|
78
|
+
/**
|
|
79
|
+
* Creates an instance of search query service.
|
|
80
|
+
* @param {GraphQLClient} client that fetches data from a GraphQL endpoint.
|
|
81
|
+
*/
|
|
82
|
+
constructor(client: GraphQLClient);
|
|
83
|
+
/**
|
|
84
|
+
* 1. Validates mandatory search query arguments
|
|
85
|
+
* 2. Executes search query with pagination
|
|
86
|
+
* 3. Aggregates pagination results into a single result-set.
|
|
87
|
+
* @template T The type of objects being requested.
|
|
88
|
+
* @param {string | DocumentNode} query the search query.
|
|
89
|
+
* @param {SearchQueryVariables} args search query arguments.
|
|
90
|
+
* @returns {T[]} array of result objects.
|
|
91
|
+
* @throws {RangeError} if a valid root item ID is not provided.
|
|
92
|
+
* @throws {RangeError} if the provided language(s) is(are) not valid.
|
|
93
|
+
*/
|
|
94
|
+
fetch(query: string | DocumentNode, args: SearchQueryVariables): Promise<T[]>;
|
|
95
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { ClientError } from 'graphql-request';
|
|
2
|
+
import { DocumentNode } from 'graphql';
|
|
3
|
+
import { Debugger } from './debug';
|
|
4
|
+
/**
|
|
5
|
+
* Options for configuring a GraphQL request.
|
|
6
|
+
*/
|
|
7
|
+
interface RequestOptions {
|
|
8
|
+
headers?: Record<string, string>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* An interface for GraphQL clients for Sitecore APIs
|
|
12
|
+
*/
|
|
13
|
+
export interface GraphQLClient {
|
|
14
|
+
/**
|
|
15
|
+
* Execute graphql request
|
|
16
|
+
* @param {string | DocumentNode} query graphql query
|
|
17
|
+
* @param {object} [variables] graphql variables
|
|
18
|
+
* @param {RequestOptions} [options] options for configuring a GraphQL request.
|
|
19
|
+
*/
|
|
20
|
+
request<T>(query: string | DocumentNode, variables?: {
|
|
21
|
+
[key: string]: unknown;
|
|
22
|
+
}, options?: RequestOptions): Promise<T>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* This type represents errors that can occur in a GraphQL client.
|
|
26
|
+
* In cases where an error status was sent back from the server (`!response.ok`), the `response` will be populated with details. In cases where a response was never received, the `code` can be populated with the error code (e.g. Node's 'ECONNRESET', 'ETIMEDOUT', etc).
|
|
27
|
+
*/
|
|
28
|
+
export type GraphQLClientError = Partial<ClientError> & {
|
|
29
|
+
headers?: HeadersInit;
|
|
30
|
+
code?: string;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Defines the strategy for retrying GraphQL requests based on errors and attempts.
|
|
34
|
+
*/
|
|
35
|
+
export interface RetryStrategy {
|
|
36
|
+
/**
|
|
37
|
+
* Determines whether a request should be retried based on the given error and attempt count.
|
|
38
|
+
* @param error - The error received from the GraphQL request.
|
|
39
|
+
* @param attempt - The current attempt number.
|
|
40
|
+
* @param retries - The number of retries configured.
|
|
41
|
+
* @returns A boolean indicating whether to retry the request.
|
|
42
|
+
*/
|
|
43
|
+
shouldRetry(error: GraphQLClientError, attempt: number, retries: number): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Calculates the delay (in milliseconds) before the next retry based on the given error and attempt count.
|
|
46
|
+
* @param error - The error received from the GraphQL request.
|
|
47
|
+
* @param attempt - The current attempt number.
|
|
48
|
+
* @returns The delay in milliseconds before the next retry.
|
|
49
|
+
*/
|
|
50
|
+
getDelay(error: GraphQLClientError, attempt: number): number;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Minimum configuration options for classes that implement @see GraphQLClient
|
|
54
|
+
*/
|
|
55
|
+
export type GraphQLRequestClientConfig = {
|
|
56
|
+
/**
|
|
57
|
+
* The API key to use for authentication. This will be added as an 'sc_apikey' header.
|
|
58
|
+
*/
|
|
59
|
+
apiKey?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Override debugger for logging. Uses 'core:http' by default.
|
|
62
|
+
*/
|
|
63
|
+
debugger?: Debugger;
|
|
64
|
+
/**
|
|
65
|
+
* Override fetch method. Uses 'graphql-request' library default otherwise ('cross-fetch').
|
|
66
|
+
*/
|
|
67
|
+
fetch?: typeof fetch;
|
|
68
|
+
/**
|
|
69
|
+
* GraphQLClient request timeout (in milliseconds).
|
|
70
|
+
*/
|
|
71
|
+
timeout?: number;
|
|
72
|
+
/**
|
|
73
|
+
* Number of retries for client. Will use the specified `retryStrategy`.
|
|
74
|
+
*/
|
|
75
|
+
retries?: number;
|
|
76
|
+
/**
|
|
77
|
+
* Retry strategy for the client. Uses `DefaultRetryStrategy` by default with exponential
|
|
78
|
+
* back-off factor of 2 for codes 429, 502, 503, 504, 520, 521, 522, 523, 524.
|
|
79
|
+
*/
|
|
80
|
+
retryStrategy?: RetryStrategy;
|
|
81
|
+
/**
|
|
82
|
+
* Custom headers to be sent with each request.
|
|
83
|
+
*/
|
|
84
|
+
headers?: Record<string, string>;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* A GraphQL Client Factory is a function that accepts configuration and returns an instance of a GraphQLRequestClient.
|
|
88
|
+
* This factory function is used to create and configure GraphQL clients for making GraphQL API requests.
|
|
89
|
+
* @param config - The configuration object that specifies how the GraphQL client should be set up.
|
|
90
|
+
* @returns An instance of a GraphQL Request Client ready to send GraphQL requests.
|
|
91
|
+
*/
|
|
92
|
+
export type GraphQLRequestClientFactory = (config?: Omit<GraphQLRequestClientConfig, 'apiKey'>) => GraphQLRequestClient;
|
|
93
|
+
/**
|
|
94
|
+
* Configuration type for @type GraphQLRequestClientFactory
|
|
95
|
+
*/
|
|
96
|
+
export type GraphQLRequestClientFactoryConfig = {
|
|
97
|
+
endpoint: string;
|
|
98
|
+
apiKey?: string;
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Represents a default retry strategy for handling retry attempts in case of specific HTTP status codes.
|
|
102
|
+
* This class implements the RetryStrategy interface and provides methods to determine whether a request
|
|
103
|
+
* should be retried and calculates the delay before the next retry attempt.
|
|
104
|
+
*/
|
|
105
|
+
export declare class DefaultRetryStrategy implements RetryStrategy {
|
|
106
|
+
private statusCodes;
|
|
107
|
+
private errorCodes;
|
|
108
|
+
private factor;
|
|
109
|
+
/**
|
|
110
|
+
* @param {object} options Configurable options for retry mechanism.
|
|
111
|
+
* @param {number[]} [options.statusCodes] HTTP status codes to trigger retries on. Default is [429].
|
|
112
|
+
* @param {string[]} [options.errorCodes] Node error codes to trigger retries. Default is ['ECONNRESET', 'ETIMEDOUT', 'EPROTO'].
|
|
113
|
+
* @param {number} [options.factor] Factor by which the delay increases with each retry attempt. Default is 2.
|
|
114
|
+
*/
|
|
115
|
+
constructor(options?: {
|
|
116
|
+
statusCodes?: number[];
|
|
117
|
+
errorCodes?: string[];
|
|
118
|
+
factor?: number;
|
|
119
|
+
});
|
|
120
|
+
shouldRetry(error: GraphQLClientError, attempt: number, retries: number): boolean;
|
|
121
|
+
getDelay(error: GraphQLClientError, attempt: number): number;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* A GraphQL client for Sitecore APIs that uses the 'graphql-request' library.
|
|
125
|
+
* https://github.com/prisma-labs/graphql-request
|
|
126
|
+
*/
|
|
127
|
+
export declare class GraphQLRequestClient implements GraphQLClient {
|
|
128
|
+
private endpoint;
|
|
129
|
+
private client;
|
|
130
|
+
private headers;
|
|
131
|
+
private debug;
|
|
132
|
+
private abortTimeout?;
|
|
133
|
+
private timeout?;
|
|
134
|
+
private retries;
|
|
135
|
+
private retryStrategy;
|
|
136
|
+
/**
|
|
137
|
+
* Provides ability to execute graphql query using given `endpoint`
|
|
138
|
+
* @param {string} endpoint The Graphql endpoint
|
|
139
|
+
* @param {GraphQLRequestClientConfig} [clientConfig] GraphQL request client configuration.
|
|
140
|
+
*/
|
|
141
|
+
constructor(endpoint: string, clientConfig?: GraphQLRequestClientConfig);
|
|
142
|
+
/**
|
|
143
|
+
* Factory method for creating a GraphQLRequestClientFactory.
|
|
144
|
+
* @param {object} config - client configuration options.
|
|
145
|
+
* @param {string} config.endpoint - endpoint
|
|
146
|
+
* @param {string} [config.apiKey] - apikey
|
|
147
|
+
*/
|
|
148
|
+
static createClientFactory({ endpoint, apiKey, }: GraphQLRequestClientFactoryConfig): GraphQLRequestClientFactory;
|
|
149
|
+
/**
|
|
150
|
+
* Execute graphql request
|
|
151
|
+
* @param {string | DocumentNode} query graphql query
|
|
152
|
+
* @param {object} [variables] graphql variables
|
|
153
|
+
* @param {RequestOptions} [options] Options for configuring a GraphQL request.
|
|
154
|
+
*/
|
|
155
|
+
request<T>(query: string | DocumentNode, variables?: {
|
|
156
|
+
[key: string]: unknown;
|
|
157
|
+
}, options?: RequestOptions): Promise<T>;
|
|
158
|
+
}
|
|
159
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { CacheClient, CacheOptions } from '../cache-client';
|
|
2
|
+
/**
|
|
3
|
+
* Object model for Sitecore dictionary phrases
|
|
4
|
+
*/
|
|
5
|
+
export interface DictionaryPhrases {
|
|
6
|
+
[k: string]: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Service that fetches dictionary data using Sitecore's GraphQL API.
|
|
10
|
+
*/
|
|
11
|
+
export interface DictionaryService {
|
|
12
|
+
/**
|
|
13
|
+
* Fetch dictionary data for a language.
|
|
14
|
+
* @param {string} language the language to be used to fetch the dictionary
|
|
15
|
+
*/
|
|
16
|
+
fetchDictionaryData(language: string): Promise<DictionaryPhrases>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Base implementation of @see DictionaryService that handles caching dictionary values
|
|
20
|
+
*/
|
|
21
|
+
export declare abstract class DictionaryServiceBase implements DictionaryService, CacheClient<DictionaryPhrases> {
|
|
22
|
+
options: CacheOptions;
|
|
23
|
+
private cache;
|
|
24
|
+
/**
|
|
25
|
+
* Initializes a new instance of @see DictionaryService using the provided @see CacheOptions
|
|
26
|
+
* @param {CacheOptions} options Configuration options
|
|
27
|
+
*/
|
|
28
|
+
constructor(options: CacheOptions);
|
|
29
|
+
/**
|
|
30
|
+
* Caches a @see DictionaryPhrases value for the specified cache key.
|
|
31
|
+
* @param {string} key The cache key.
|
|
32
|
+
* @param {DictionaryPhrases} value The value to cache.
|
|
33
|
+
* @returns The value added to the cache.
|
|
34
|
+
* @mixes CacheClient<DictionaryPhrases>
|
|
35
|
+
*/
|
|
36
|
+
setCacheValue(key: string, value: DictionaryPhrases): DictionaryPhrases;
|
|
37
|
+
/**
|
|
38
|
+
* Retrieves a @see DictionaryPhrases value from the cache.
|
|
39
|
+
* @param {string} key The cache key.
|
|
40
|
+
* @returns The @see DictionaryPhrases value, or null if the specified key is not found in the cache.
|
|
41
|
+
*/
|
|
42
|
+
getCacheValue(key: string): DictionaryPhrases | null;
|
|
43
|
+
/**
|
|
44
|
+
* Gets a cache client that can cache data. Uses memory-cache as the default
|
|
45
|
+
* library for caching (@see MemoryCacheClient). Override this method if you
|
|
46
|
+
* want to use something else.
|
|
47
|
+
* @returns {CacheClient} implementation
|
|
48
|
+
*/
|
|
49
|
+
protected getCacheClient(): CacheClient<DictionaryPhrases>;
|
|
50
|
+
/**
|
|
51
|
+
* Fetch dictionary data for a language.
|
|
52
|
+
* @param {string} language the language to be used to fetch the dictionary
|
|
53
|
+
* @returns {Promise<DictionaryPhrases>}
|
|
54
|
+
*/
|
|
55
|
+
abstract fetchDictionaryData(language: string): Promise<DictionaryPhrases>;
|
|
56
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { GraphQLClient, GraphQLRequestClientConfig, GraphQLRequestClientFactory } from '../graphql-request-client';
|
|
2
|
+
import { DictionaryPhrases, DictionaryServiceBase } from './dictionary-service';
|
|
3
|
+
import { CacheOptions } from '../cache-client';
|
|
4
|
+
import { PageInfo, SearchQueryVariables } from '../graphql';
|
|
5
|
+
/** @private */
|
|
6
|
+
export declare const queryError = "Valid value for rootItemId not provided and failed to auto-resolve app root item.";
|
|
7
|
+
/**
|
|
8
|
+
* Configuration options for @see GraphQLDictionaryService instances
|
|
9
|
+
*/
|
|
10
|
+
export interface GraphQLDictionaryServiceConfig extends Omit<SearchQueryVariables, 'language'>, CacheOptions, Pick<GraphQLRequestClientConfig, 'retries' | 'retryStrategy'> {
|
|
11
|
+
/**
|
|
12
|
+
* The name of the current Sitecore site. This is used to to determine the search query root
|
|
13
|
+
* in cases where one is not specified by the caller.
|
|
14
|
+
*/
|
|
15
|
+
siteName: string;
|
|
16
|
+
/**
|
|
17
|
+
* A GraphQL Request Client Factory is a function that accepts configuration and returns an instance of a GraphQLRequestClient.
|
|
18
|
+
* This factory function is used to create and configure GraphQL clients for making GraphQL API requests.
|
|
19
|
+
*/
|
|
20
|
+
clientFactory: GraphQLRequestClientFactory;
|
|
21
|
+
/**
|
|
22
|
+
* Optional. The template ID to use when searching for dictionary entries.
|
|
23
|
+
* @default '6d1cd89719364a3aa511289a94c2a7b1' (/sitecore/templates/System/Dictionary/Dictionary entry)
|
|
24
|
+
*/
|
|
25
|
+
dictionaryEntryTemplateId?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Optional. The template ID of a JSS App to use when searching for the appRootId.
|
|
28
|
+
* @default '061cba1554744b918a0617903b102b82' (/sitecore/templates/Foundation/JavaScript Services/App)
|
|
29
|
+
*/
|
|
30
|
+
jssAppTemplateId?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Optional. Use site query for dictionary fetch instead of search query (XM Cloud only)
|
|
33
|
+
*/
|
|
34
|
+
useSiteQuery?: boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The schema of data returned in response to a dictionary query request.
|
|
38
|
+
*/
|
|
39
|
+
export type DictionaryQueryResult = {
|
|
40
|
+
key: {
|
|
41
|
+
value: string;
|
|
42
|
+
};
|
|
43
|
+
phrase: {
|
|
44
|
+
value: string;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
export type DictionarySiteQueryResponse = {
|
|
48
|
+
site: {
|
|
49
|
+
siteInfo: {
|
|
50
|
+
dictionary: {
|
|
51
|
+
results: {
|
|
52
|
+
key: string;
|
|
53
|
+
value: string;
|
|
54
|
+
}[];
|
|
55
|
+
pageInfo: PageInfo;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Service that fetch dictionary data using Sitecore's GraphQL API.
|
|
62
|
+
* @augments DictionaryServiceBase
|
|
63
|
+
* @mixes SearchQueryService<DictionaryQueryResult>
|
|
64
|
+
*/
|
|
65
|
+
export declare class GraphQLDictionaryService extends DictionaryServiceBase {
|
|
66
|
+
options: GraphQLDictionaryServiceConfig;
|
|
67
|
+
private graphQLClient;
|
|
68
|
+
/**
|
|
69
|
+
* Creates an instance of graphQL dictionary service with the provided options
|
|
70
|
+
* @param {GraphQLDictionaryService} options instance
|
|
71
|
+
*/
|
|
72
|
+
constructor(options: GraphQLDictionaryServiceConfig);
|
|
73
|
+
/**
|
|
74
|
+
* Fetches dictionary data for internalization. Uses search query by default
|
|
75
|
+
* @param {string} language the language to fetch
|
|
76
|
+
* @returns {Promise<DictionaryPhrases>} dictionary phrases
|
|
77
|
+
* @throws {Error} if the app root was not found for the specified site and language.
|
|
78
|
+
*/
|
|
79
|
+
fetchDictionaryData(language: string): Promise<DictionaryPhrases>;
|
|
80
|
+
/**
|
|
81
|
+
* Fetches dictionary data with site query
|
|
82
|
+
* This is the default behavior for XMCloud deployments. Uses `siteQuery` to retrieve data.
|
|
83
|
+
* @param {string} language the language to fetch
|
|
84
|
+
* @returns {Promise<DictionaryPhrases>} dictionary phrases
|
|
85
|
+
*/
|
|
86
|
+
fetchWithSiteQuery(language: string): Promise<DictionaryPhrases>;
|
|
87
|
+
/**
|
|
88
|
+
* Gets a GraphQL client that can make requests to the API. Uses graphql-request as the default
|
|
89
|
+
* library for fetching graphql data (@see GraphQLRequestClient). Override this method if you
|
|
90
|
+
* want to use something else.
|
|
91
|
+
* @returns {GraphQLClient} implementation
|
|
92
|
+
*/
|
|
93
|
+
protected getGraphQLClient(): GraphQLClient;
|
|
94
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as constants from './constants';
|
|
2
|
+
export { default as debug, Debugger, enableDebug } from './debug';
|
|
3
|
+
export { RetryStrategy, DefaultRetryStrategy, GraphQLClient, GraphQLRequestClient, GraphQLRequestClientConfig, GraphQLRequestClientFactory, GraphQLRequestClientFactoryConfig, } from './graphql-request-client';
|
|
4
|
+
export { CacheClient, CacheOptions, MemoryCacheClient } from './cache-client';
|
|
5
|
+
export { ClientError } from 'graphql-request';
|
|
6
|
+
export { NativeDataFetcher, NativeDataFetcherConfig, NativeDataFetcherError, NativeDataFetcherResponse, } from './native-fetcher';
|
|
7
|
+
export { HTMLLink } from './models';
|
|
8
|
+
export { constants };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ComponentRendering, Field, Item, LayoutServiceData, RouteData } from './index';
|
|
2
|
+
import { HTMLLink } from '../models';
|
|
3
|
+
type Config = {
|
|
4
|
+
loadStyles: boolean;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Get the content styles link to be loaded from the Sitecore Edge Platform
|
|
8
|
+
* @param {LayoutServiceData} layoutData Layout service data
|
|
9
|
+
* @param {string} sitecoreEdgeContextId Sitecore Edge Context ID
|
|
10
|
+
* @param {string} [sitecoreEdgeUrl] Sitecore Edge Platform URL. Default is https://edge-platform.sitecorecloud.io
|
|
11
|
+
* @returns {HTMLLink | null} content styles link, null if no styles are used in layout
|
|
12
|
+
*/
|
|
13
|
+
export declare const getContentStylesheetLink: (layoutData: LayoutServiceData, sitecoreEdgeContextId: string, sitecoreEdgeUrl?: string) => HTMLLink | null;
|
|
14
|
+
export declare const getContentStylesheetUrl: (sitecoreEdgeContextId: string, sitecoreEdgeUrl?: string) => string;
|
|
15
|
+
export declare const traversePlaceholder: (components: Array<ComponentRendering>, config: Config) => void;
|
|
16
|
+
export declare const traverseField: (field: Field | Item | Item[] | undefined, config: Config) => void;
|
|
17
|
+
export declare const traverseComponent: (component: RouteData | ComponentRendering, config: Config) => void;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { LayoutServiceBase } from './layout-service';
|
|
2
|
+
import { LayoutServiceData } from './models';
|
|
3
|
+
import { GraphQLClient, GraphQLRequestClientFactory, GraphQLRequestClientConfig } from '../graphql-request-client';
|
|
4
|
+
export declare const GRAPHQL_LAYOUT_QUERY_NAME = "JssLayoutQuery";
|
|
5
|
+
export interface GraphQLLayoutServiceConfig extends Pick<GraphQLRequestClientConfig, 'retries' | 'retryStrategy'> {
|
|
6
|
+
/**
|
|
7
|
+
* The JSS application name
|
|
8
|
+
*/
|
|
9
|
+
siteName: string;
|
|
10
|
+
/**
|
|
11
|
+
* A GraphQL Request Client Factory is a function that accepts configuration and returns an instance of a GraphQLRequestClient.
|
|
12
|
+
* This factory function is used to create and configure GraphQL clients for making GraphQL API requests.
|
|
13
|
+
*/
|
|
14
|
+
clientFactory: GraphQLRequestClientFactory;
|
|
15
|
+
/**
|
|
16
|
+
* Override default layout query
|
|
17
|
+
* @param {string} siteName
|
|
18
|
+
* @param {string} itemPath
|
|
19
|
+
* @param {string} [locale]
|
|
20
|
+
* @returns {string} custom layout query
|
|
21
|
+
* Layout query
|
|
22
|
+
* layout(site:"${siteName}", routePath:"${itemPath}", language:"${language}")
|
|
23
|
+
*/
|
|
24
|
+
formatLayoutQuery?: (siteName: string, itemPath: string, locale?: string) => string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Service that fetch layout data using Sitecore's GraphQL API.
|
|
28
|
+
* @augments LayoutServiceBase
|
|
29
|
+
* @mixes GraphQLRequestClient
|
|
30
|
+
*/
|
|
31
|
+
export declare class GraphQLLayoutService extends LayoutServiceBase {
|
|
32
|
+
serviceConfig: GraphQLLayoutServiceConfig;
|
|
33
|
+
private graphQLClient;
|
|
34
|
+
/**
|
|
35
|
+
* Fetch layout data using the Sitecore GraphQL endpoint.
|
|
36
|
+
* @param {GraphQLLayoutServiceConfig} serviceConfig configuration
|
|
37
|
+
*/
|
|
38
|
+
constructor(serviceConfig: GraphQLLayoutServiceConfig);
|
|
39
|
+
/**
|
|
40
|
+
* Fetch layout data for an item.
|
|
41
|
+
* @param {string} itemPath item path to fetch layout data for.
|
|
42
|
+
* @param {string} [language] the language to fetch layout data for.
|
|
43
|
+
* @returns {Promise<LayoutServiceData>} layout service data
|
|
44
|
+
*/
|
|
45
|
+
fetchLayoutData(itemPath: string, language?: string): Promise<LayoutServiceData>;
|
|
46
|
+
/**
|
|
47
|
+
* Gets a GraphQL client that can make requests to the API.
|
|
48
|
+
* @returns {GraphQLClient} implementation
|
|
49
|
+
*/
|
|
50
|
+
protected getGraphQLClient(): GraphQLClient;
|
|
51
|
+
/**
|
|
52
|
+
* Returns GraphQL Layout query
|
|
53
|
+
* @param {string} itemPath page route
|
|
54
|
+
* @param {string} [language] language
|
|
55
|
+
* @returns {string} GraphQL query
|
|
56
|
+
*/
|
|
57
|
+
protected getLayoutQuery(itemPath: string, language?: string): string;
|
|
58
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { LayoutServiceData, LayoutServicePageState, LayoutServiceContext, LayoutServiceContextData, RouteData, PlaceholderData, ComponentRendering, Field, GenericFieldValue, Item, PlaceholdersData, ComponentFields, ComponentParams, EditMode, FieldMetadata, RenderingType, EDITING_COMPONENT_PLACEHOLDER, EDITING_COMPONENT_ID, } from './models';
|
|
2
|
+
export { getFieldValue, getChildPlaceholder, isFieldValueEmpty, isDynamicPlaceholder, getDynamicPlaceholderPattern, EMPTY_DATE_FIELD_VALUE, } from './utils';
|
|
3
|
+
export { getContentStylesheetLink } from './content-styles';
|
|
4
|
+
export { LayoutService } from './layout-service';
|
|
5
|
+
export { GraphQLLayoutService, GraphQLLayoutServiceConfig, GRAPHQL_LAYOUT_QUERY_NAME, } from './graphql-layout-service';
|
|
6
|
+
export { getComponentLibraryStylesheetLinks } from './themes';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as models from './models';
|
|
2
|
+
import { IncomingMessage, ServerResponse } from 'http';
|
|
3
|
+
export interface LayoutService {
|
|
4
|
+
/**
|
|
5
|
+
* Fetch layout data for an item.
|
|
6
|
+
* @param {string} itemPath
|
|
7
|
+
* @param {string} [language]
|
|
8
|
+
* @param {IncomingMessage} [req] Request instance
|
|
9
|
+
* @param {ServerResponse} [res] Response instance
|
|
10
|
+
* @returns {Promise<LayoutServiceData>} layout data
|
|
11
|
+
*/
|
|
12
|
+
fetchLayoutData(itemPath: string, language?: string, req?: IncomingMessage, res?: ServerResponse): Promise<models.LayoutServiceData>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Base abstraction to implement custom layout service
|
|
16
|
+
*/
|
|
17
|
+
export declare abstract class LayoutServiceBase implements LayoutService {
|
|
18
|
+
abstract fetchLayoutData(itemPath: string, language?: string, req?: IncomingMessage, res?: ServerResponse): Promise<models.LayoutServiceData>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A reply from the Sitecore Layout Service
|
|
3
|
+
*/
|
|
4
|
+
export interface LayoutServiceData {
|
|
5
|
+
sitecore: LayoutServiceContextData & {
|
|
6
|
+
route: RouteData | null;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Layout Service page state enum
|
|
11
|
+
* library mode would render a single component
|
|
12
|
+
*/
|
|
13
|
+
export declare enum LayoutServicePageState {
|
|
14
|
+
Preview = "preview",
|
|
15
|
+
Edit = "edit",
|
|
16
|
+
Normal = "normal"
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Represents the edit mode for rendering content in Sitecore Editors
|
|
20
|
+
*/
|
|
21
|
+
export declare enum EditMode {
|
|
22
|
+
Metadata = "metadata"
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Shape of context data from the Sitecore Layout Service
|
|
26
|
+
*/
|
|
27
|
+
export interface LayoutServiceContext {
|
|
28
|
+
[key: string]: unknown;
|
|
29
|
+
pageEditing?: boolean;
|
|
30
|
+
language?: string;
|
|
31
|
+
itemPath?: string;
|
|
32
|
+
pageState?: LayoutServicePageState;
|
|
33
|
+
visitorIdentificationTimestamp?: number;
|
|
34
|
+
site?: {
|
|
35
|
+
name?: string;
|
|
36
|
+
};
|
|
37
|
+
renderingType?: RenderingType;
|
|
38
|
+
clientScripts?: string[];
|
|
39
|
+
clientData?: Record<string, Record<string, unknown>>;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Context information from the Sitecore Layout Service
|
|
43
|
+
*/
|
|
44
|
+
export interface LayoutServiceContextData {
|
|
45
|
+
context: LayoutServiceContext;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Shape of route data returned from Sitecore Layout Service
|
|
49
|
+
*/
|
|
50
|
+
export interface RouteData<Fields = Record<string, Field | Item | Item[]>> {
|
|
51
|
+
name: string;
|
|
52
|
+
displayName?: string;
|
|
53
|
+
fields?: Fields;
|
|
54
|
+
databaseName?: string;
|
|
55
|
+
deviceId?: string;
|
|
56
|
+
itemLanguage?: string;
|
|
57
|
+
itemVersion?: number;
|
|
58
|
+
layoutId?: string;
|
|
59
|
+
templateId?: string;
|
|
60
|
+
templateName?: string;
|
|
61
|
+
placeholders: PlaceholdersData;
|
|
62
|
+
itemId?: string;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Placeholder contents data (name: placeholder name, then array of components within that placeholder name)
|
|
66
|
+
*/
|
|
67
|
+
export type PlaceholdersData<TYPEDNAME extends string = string> = {
|
|
68
|
+
[P in TYPEDNAME]: Array<ComponentRendering>;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Content field data passed to a component
|
|
72
|
+
*/
|
|
73
|
+
export interface ComponentFields {
|
|
74
|
+
[name: string]: Field | Item | Item[];
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Component params
|
|
78
|
+
*/
|
|
79
|
+
export interface ComponentParams {
|
|
80
|
+
[name: string]: string;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Definition of a component instance within a placeholder on a route
|
|
84
|
+
*/
|
|
85
|
+
export interface ComponentRendering<T = ComponentFields> {
|
|
86
|
+
componentName: string;
|
|
87
|
+
dataSource?: string;
|
|
88
|
+
uid?: string;
|
|
89
|
+
placeholders?: PlaceholdersData;
|
|
90
|
+
fields?: T;
|
|
91
|
+
params?: ComponentParams;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Field value data on a component
|
|
95
|
+
*/
|
|
96
|
+
export type GenericFieldValue = string | boolean | number | Date | {
|
|
97
|
+
[key: string]: unknown;
|
|
98
|
+
} | Array<{
|
|
99
|
+
[key: string]: unknown;
|
|
100
|
+
}>;
|
|
101
|
+
export interface Field<T = GenericFieldValue> extends FieldMetadata {
|
|
102
|
+
value: T;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Field metadata in editing mode
|
|
106
|
+
*/
|
|
107
|
+
export interface FieldMetadata {
|
|
108
|
+
metadata?: {
|
|
109
|
+
[key: string]: unknown;
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Content data returned from Layout Service
|
|
114
|
+
*/
|
|
115
|
+
export interface Item {
|
|
116
|
+
name: string;
|
|
117
|
+
displayName?: string;
|
|
118
|
+
id?: string;
|
|
119
|
+
url?: string;
|
|
120
|
+
fields: {
|
|
121
|
+
[name: string]: Field | Item | Item[] | undefined;
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Contents of a single placeholder returned from placeholder service
|
|
126
|
+
*/
|
|
127
|
+
export interface PlaceholderData {
|
|
128
|
+
name: string;
|
|
129
|
+
path: string;
|
|
130
|
+
elements: ComponentRendering[];
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Editing rendering type
|
|
134
|
+
*/
|
|
135
|
+
export declare enum RenderingType {
|
|
136
|
+
Component = "component"
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Static placeholder name used for component rendering
|
|
140
|
+
*/
|
|
141
|
+
export declare const EDITING_COMPONENT_PLACEHOLDER = "editing-componentmode-placeholder";
|
|
142
|
+
/**
|
|
143
|
+
* Id of wrapper for component rendering
|
|
144
|
+
*/
|
|
145
|
+
export declare const EDITING_COMPONENT_ID = "editing-component";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { LayoutServiceData } from '.';
|
|
2
|
+
import { HTMLLink } from '../models';
|
|
3
|
+
/**
|
|
4
|
+
* Walks through rendering tree and returns list of links of all FEAAS, BYOC or SXA Component Library Stylesheets that are used
|
|
5
|
+
* @param {LayoutServiceData} layoutData Layout service data
|
|
6
|
+
* @param {string} sitecoreEdgeContextId Sitecore Edge Context ID
|
|
7
|
+
* @param {string} [sitecoreEdgeUrl] Sitecore Edge Platform URL. Default is https://edge-platform.sitecorecloud.io
|
|
8
|
+
* @returns {HTMLLink[]} library stylesheet links
|
|
9
|
+
*/
|
|
10
|
+
export declare function getComponentLibraryStylesheetLinks(layoutData: LayoutServiceData, sitecoreEdgeContextId: string, sitecoreEdgeUrl?: string): HTMLLink[];
|
|
11
|
+
export declare const getStylesheetUrl: (id: string, sitecoreEdgeContextId: string, sitecoreEdgeUrl?: string) => string;
|