@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.
Files changed (160) hide show
  1. package/LICENSE.txt +202 -0
  2. package/README.md +11 -0
  3. package/dist/cjs/cache-client.js +54 -0
  4. package/dist/cjs/constants.js +13 -0
  5. package/dist/cjs/data-fetcher.js +33 -0
  6. package/dist/cjs/debug.js +43 -0
  7. package/dist/cjs/editing/component-library.js +104 -0
  8. package/dist/cjs/editing/graphql-editing-service.js +186 -0
  9. package/dist/cjs/editing/index.js +23 -0
  10. package/dist/cjs/editing/models.js +23 -0
  11. package/dist/cjs/editing/rest-component-layout-service.js +76 -0
  12. package/dist/cjs/editing/utils.js +86 -0
  13. package/dist/cjs/graphql/app-root-query.js +73 -0
  14. package/dist/cjs/graphql/graphql-edge-proxy.js +21 -0
  15. package/dist/cjs/graphql/index.js +13 -0
  16. package/dist/cjs/graphql/search-service.js +61 -0
  17. package/dist/cjs/graphql-request-client.js +152 -0
  18. package/dist/cjs/i18n/dictionary-service.js +45 -0
  19. package/dist/cjs/i18n/graphql-dictionary-service.js +136 -0
  20. package/dist/cjs/i18n/index.js +7 -0
  21. package/dist/cjs/index.js +55 -0
  22. package/dist/cjs/layout/content-styles.js +70 -0
  23. package/dist/cjs/layout/graphql-layout-service.js +86 -0
  24. package/dist/cjs/layout/index.js +24 -0
  25. package/dist/cjs/layout/layout-service.js +9 -0
  26. package/dist/cjs/layout/models.js +35 -0
  27. package/dist/cjs/layout/themes.js +74 -0
  28. package/dist/cjs/layout/utils.js +110 -0
  29. package/dist/cjs/media/index.js +38 -0
  30. package/dist/cjs/media/media-api.js +96 -0
  31. package/dist/cjs/models.js +2 -0
  32. package/dist/cjs/native-fetcher.js +200 -0
  33. package/dist/cjs/personalize/graphql-personalize-service.js +114 -0
  34. package/dist/cjs/personalize/index.js +14 -0
  35. package/dist/cjs/personalize/layout-personalizer.js +97 -0
  36. package/dist/cjs/personalize/utils.js +136 -0
  37. package/dist/cjs/site/graphql-error-pages-service.js +89 -0
  38. package/dist/cjs/site/graphql-redirects-service.js +105 -0
  39. package/dist/cjs/site/graphql-robots-service.js +83 -0
  40. package/dist/cjs/site/graphql-siteinfo-service.js +107 -0
  41. package/dist/cjs/site/graphql-sitemap-service.js +93 -0
  42. package/dist/cjs/site/index.js +22 -0
  43. package/dist/cjs/site/site-resolver.js +79 -0
  44. package/dist/cjs/site/utils.js +43 -0
  45. package/dist/cjs/utils/env.js +26 -0
  46. package/dist/cjs/utils/index.js +20 -0
  47. package/dist/cjs/utils/is-server.js +10 -0
  48. package/dist/cjs/utils/timeout-promise.js +31 -0
  49. package/dist/cjs/utils/utils.js +222 -0
  50. package/dist/esm/cache-client.js +50 -0
  51. package/dist/esm/constants.js +10 -0
  52. package/dist/esm/data-fetcher.js +28 -0
  53. package/dist/esm/debug.js +36 -0
  54. package/dist/esm/editing/component-library.js +98 -0
  55. package/dist/esm/editing/graphql-editing-service.js +179 -0
  56. package/dist/esm/editing/index.js +5 -0
  57. package/dist/esm/editing/models.js +20 -0
  58. package/dist/esm/editing/rest-component-layout-service.js +72 -0
  59. package/dist/esm/editing/utils.js +76 -0
  60. package/dist/esm/graphql/app-root-query.js +69 -0
  61. package/dist/esm/graphql/graphql-edge-proxy.js +16 -0
  62. package/dist/esm/graphql/index.js +4 -0
  63. package/dist/esm/graphql/search-service.js +57 -0
  64. package/dist/esm/graphql-request-client.js +144 -0
  65. package/dist/esm/i18n/dictionary-service.js +41 -0
  66. package/dist/esm/i18n/graphql-dictionary-service.js +129 -0
  67. package/dist/esm/i18n/index.js +2 -0
  68. package/dist/esm/index.js +9 -0
  69. package/dist/esm/layout/content-styles.js +62 -0
  70. package/dist/esm/layout/graphql-layout-service.js +79 -0
  71. package/dist/esm/layout/index.js +6 -0
  72. package/dist/esm/layout/layout-service.js +5 -0
  73. package/dist/esm/layout/models.js +32 -0
  74. package/dist/esm/layout/themes.js +69 -0
  75. package/dist/esm/layout/utils.js +102 -0
  76. package/dist/esm/media/index.js +2 -0
  77. package/dist/esm/media/media-api.js +86 -0
  78. package/dist/esm/models.js +1 -0
  79. package/dist/esm/native-fetcher.js +193 -0
  80. package/dist/esm/personalize/graphql-personalize-service.js +107 -0
  81. package/dist/esm/personalize/index.js +3 -0
  82. package/dist/esm/personalize/layout-personalizer.js +92 -0
  83. package/dist/esm/personalize/utils.js +128 -0
  84. package/dist/esm/site/graphql-error-pages-service.js +82 -0
  85. package/dist/esm/site/graphql-redirects-service.js +98 -0
  86. package/dist/esm/site/graphql-robots-service.js +76 -0
  87. package/dist/esm/site/graphql-siteinfo-service.js +100 -0
  88. package/dist/esm/site/graphql-sitemap-service.js +86 -0
  89. package/dist/esm/site/index.js +7 -0
  90. package/dist/esm/site/site-resolver.js +75 -0
  91. package/dist/esm/site/utils.js +37 -0
  92. package/dist/esm/utils/env.js +22 -0
  93. package/dist/esm/utils/index.js +3 -0
  94. package/dist/esm/utils/is-server.js +8 -0
  95. package/dist/esm/utils/timeout-promise.js +28 -0
  96. package/dist/esm/utils/utils.js +207 -0
  97. package/editing.d.ts +1 -0
  98. package/editing.js +1 -0
  99. package/graphql.d.ts +1 -0
  100. package/graphql.js +1 -0
  101. package/i18n.d.ts +1 -0
  102. package/i18n.js +1 -0
  103. package/layout.d.ts +1 -0
  104. package/layout.js +1 -0
  105. package/media.d.ts +1 -0
  106. package/media.js +1 -0
  107. package/package.json +76 -0
  108. package/personalize.d.ts +1 -0
  109. package/personalize.js +1 -0
  110. package/site.d.ts +1 -0
  111. package/site.js +1 -0
  112. package/types/cache-client.d.ts +64 -0
  113. package/types/constants.d.ts +7 -0
  114. package/types/data-fetcher.d.ts +34 -0
  115. package/types/debug.d.ts +26 -0
  116. package/types/editing/component-library.d.ts +48 -0
  117. package/types/editing/graphql-editing-service.d.ts +90 -0
  118. package/types/editing/index.d.ts +6 -0
  119. package/types/editing/models.d.ts +52 -0
  120. package/types/editing/rest-component-layout-service.d.ts +100 -0
  121. package/types/editing/utils.d.ts +70 -0
  122. package/types/graphql/app-root-query.d.ts +32 -0
  123. package/types/graphql/graphql-edge-proxy.d.ts +15 -0
  124. package/types/graphql/index.d.ts +4 -0
  125. package/types/graphql/search-service.d.ts +95 -0
  126. package/types/graphql-request-client.d.ts +159 -0
  127. package/types/i18n/dictionary-service.d.ts +56 -0
  128. package/types/i18n/graphql-dictionary-service.d.ts +94 -0
  129. package/types/i18n/index.d.ts +2 -0
  130. package/types/index.d.ts +8 -0
  131. package/types/layout/content-styles.d.ts +18 -0
  132. package/types/layout/graphql-layout-service.d.ts +58 -0
  133. package/types/layout/index.d.ts +6 -0
  134. package/types/layout/layout-service.d.ts +19 -0
  135. package/types/layout/models.d.ts +145 -0
  136. package/types/layout/themes.d.ts +11 -0
  137. package/types/layout/utils.d.ts +40 -0
  138. package/types/media/index.d.ts +2 -0
  139. package/types/media/media-api.d.ts +55 -0
  140. package/types/models.d.ts +6 -0
  141. package/types/native-fetcher.d.ts +121 -0
  142. package/types/personalize/graphql-personalize-service.d.ts +80 -0
  143. package/types/personalize/index.d.ts +3 -0
  144. package/types/personalize/layout-personalizer.d.ts +27 -0
  145. package/types/personalize/utils.d.ts +69 -0
  146. package/types/site/graphql-error-pages-service.d.ts +57 -0
  147. package/types/site/graphql-redirects-service.d.ts +68 -0
  148. package/types/site/graphql-robots-service.d.ts +49 -0
  149. package/types/site/graphql-siteinfo-service.d.ts +70 -0
  150. package/types/site/graphql-sitemap-service.d.ts +55 -0
  151. package/types/site/index.d.ts +7 -0
  152. package/types/site/site-resolver.d.ts +27 -0
  153. package/types/site/utils.d.ts +24 -0
  154. package/types/utils/env.d.ts +7 -0
  155. package/types/utils/index.d.ts +3 -0
  156. package/types/utils/is-server.d.ts +6 -0
  157. package/types/utils/timeout-promise.d.ts +17 -0
  158. package/types/utils/utils.d.ts +71 -0
  159. package/utils.d.ts +1 -0
  160. package/utils.js +1 -0
@@ -0,0 +1,40 @@
1
+ import { ComponentRendering, ComponentFields, Field, GenericFieldValue } from './models';
2
+ /**
3
+ * Safely extracts a field value from a rendering or fields object.
4
+ * Null will be returned if the field is not defined.
5
+ * @param {ComponentRendering | Fields} renderingOrFields the rendering or fields object to extract the field from
6
+ * @param {string} fieldName the name of the field to extract
7
+ * @returns {T | undefined} the field value or null if the field is not defined
8
+ */
9
+ export declare function getFieldValue<T>(renderingOrFields: ComponentRendering | ComponentFields, fieldName: string): T | undefined;
10
+ export declare function getFieldValue<T>(renderingOrFields: ComponentRendering | ComponentFields, fieldName: string, defaultValue: T): T;
11
+ /**
12
+ * Gets rendering definitions in a given child placeholder under a current rendering.
13
+ * @param {ComponentRendering} rendering
14
+ * @param {string} placeholderName
15
+ * @returns {ComponentRendering[]} child placeholder
16
+ */
17
+ export declare function getChildPlaceholder(rendering: ComponentRendering, placeholderName: string): ComponentRendering[];
18
+ /**
19
+ * Returns a regular expression pattern for a dynamic placeholder name.
20
+ * @param {string} placeholder Placeholder name with a dynamic segment (e.g. 'main-{*}')
21
+ * @returns Regular expression pattern for the dynamic segment
22
+ */
23
+ export declare const getDynamicPlaceholderPattern: (placeholder: string) => RegExp;
24
+ /**
25
+ * Checks if the placeholder name is dynamic.
26
+ * @param {string} placeholder Placeholder name
27
+ * @returns True if the placeholder name is dynamic
28
+ */
29
+ export declare const isDynamicPlaceholder: (placeholder: string) => boolean;
30
+ /**
31
+ * The default value for an empty Date field.
32
+ * This value is defined as a default one by .NET
33
+ */
34
+ export declare const EMPTY_DATE_FIELD_VALUE = "0001-01-01T00:00:00Z";
35
+ /**
36
+ * Determines if the passed in field object's value is empty.
37
+ * @param {GenericFieldValue | Partial<Field>} field the field object.
38
+ * Partial<T> type is used here because _field.value_ could be required or optional for the different field types
39
+ */
40
+ export declare function isFieldValueEmpty(field: GenericFieldValue | Partial<Field>): boolean;
@@ -0,0 +1,2 @@
1
+ import * as mediaApi from './media-api';
2
+ export { mediaApi };
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Get required query string params which should be merged with user params
3
+ * @param {object} qs layout service parsed query string
4
+ * @returns {object} requiredParams
5
+ */
6
+ export declare const getRequiredParams: (qs: {
7
+ [key: string]: string | undefined;
8
+ }) => {
9
+ rev: string | undefined;
10
+ db: string | undefined;
11
+ la: string | undefined;
12
+ vs: string | undefined;
13
+ ts: string | undefined;
14
+ };
15
+ /**
16
+ * Replace `/~/media` or `/-/media` with `/~/jssmedia` or `/-/jssmedia`, respectively.
17
+ * Can use `mediaUrlPrefix` in order to use a custom prefix.
18
+ * @param {string} url The URL to replace the media URL prefix in
19
+ * @param {RegExp} [mediaUrlPrefix] The regex to match the media URL prefix
20
+ * @returns {string} The URL with the media URL prefix replaced
21
+ */
22
+ export declare const replaceMediaUrlPrefix: (url: string, mediaUrlPrefix?: RegExp) => string;
23
+ /**
24
+ * Prepares a Sitecore media URL with `params` for use by the JSS media handler.
25
+ * This is done by replacing `/~/media` or `/-/media` with `/~/jssmedia` or `/-/jssmedia`, respectively.
26
+ * Provided `params` are used as the querystring parameters for the media URL.
27
+ * Can use `mediaUrlPrefix` in order to use a custom prefix.
28
+ * If no `params` are sent, the original media URL is returned.
29
+ * @param {string} url The URL to prepare
30
+ * @param {object} [params] The querystring parameters to use
31
+ * @param {RegExp} [mediaUrlPrefix] The regex to match the media URL prefix
32
+ * @returns {string} The prepared URL
33
+ */
34
+ export declare const updateImageUrl: (url: string, params?: {
35
+ [key: string]: string | number | undefined;
36
+ } | null, mediaUrlPrefix?: RegExp) => string;
37
+ /**
38
+ * Receives an array of `srcSet` parameters that are iterated and used as parameters to generate
39
+ * a corresponding set of updated Sitecore media URLs via @see updateImageUrl. The result is a comma-delimited
40
+ * list of media URLs with respective dimension parameters.
41
+ * @example
42
+ * // returns '/ipsum.jpg?h=1000&w=1000 1000w, /ipsum.jpg?mh=250&mw=250 250w'
43
+ * getSrcSet('/ipsum.jpg', [{ h: 1000, w: 1000 }, { mh: 250, mw: 250 } ])
44
+ * More information about `srcSet`: {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img}
45
+ * @param {string} url The URL to prepare
46
+ * @param {Array} srcSet The array of parameters to use
47
+ * @param {object} [imageParams] The querystring parameters to use
48
+ * @param {RegExp} [mediaUrlPrefix] The regex to match the media URL prefix
49
+ * @returns {string} The prepared URL
50
+ */
51
+ export declare const getSrcSet: (url: string, srcSet: Array<{
52
+ [key: string]: string | number | undefined;
53
+ }>, imageParams?: {
54
+ [key: string]: string | number | undefined;
55
+ }, mediaUrlPrefix?: RegExp) => string;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Html <link> tag data model
3
+ */
4
+ export type HTMLLink = {
5
+ [key: string]: unknown;
6
+ } & Pick<HTMLLinkElement, 'rel' | 'href'>;
@@ -0,0 +1,121 @@
1
+ import { Debugger } from './debug';
2
+ type NativeDataFetcherOptions = {
3
+ /**
4
+ * Override debugger for logging. Uses 'core:http' by default.
5
+ */
6
+ debugger?: Debugger;
7
+ /**
8
+ * Override fetch method. Uses native (or polyfilled) fetch by default.
9
+ */
10
+ fetch?: typeof fetch;
11
+ /**
12
+ * Optional request timeout.
13
+ */
14
+ timeout?: number;
15
+ };
16
+ /**
17
+ * Response data for an HTTP request sent to an API
18
+ * @template T the type of data model requested
19
+ */
20
+ export interface NativeDataFetcherResponse<T> {
21
+ /** HTTP status code of the response (i.e. 200, 404) */
22
+ status: number;
23
+ /** HTTP status text of the response (i.e. 'OK', 'Bad Request') */
24
+ statusText: string;
25
+ /** Response content */
26
+ data: T;
27
+ /** Response headers */
28
+ headers?: HeadersInit;
29
+ }
30
+ /**
31
+ * Native fetcher error type to include response text and status
32
+ */
33
+ export type NativeDataFetcherError = Error & {
34
+ response: NativeDataFetcherResponse<unknown>;
35
+ };
36
+ /**
37
+ * A function that fetches data from a given URL and returns a `NativeDataFetcherResponse`.
38
+ * @param {string} url The URL to request (can include query string parameters).
39
+ * @param {unknown} [data] Optional data to send with the request (e.g., for POST or PUT requests).
40
+ * @returns {Promise<NativeDataFetcherResponse<T>>} A promise that resolves to a `NativeDataFetcherResponse<T>`,
41
+ */
42
+ export type NativeDataFetcherFunction<T> = (url: string, data?: RequestInit) => Promise<NativeDataFetcherResponse<T>>;
43
+ export type NativeDataFetcherConfig = NativeDataFetcherOptions & RequestInit;
44
+ export declare class NativeDataFetcher {
45
+ protected config: NativeDataFetcherConfig;
46
+ private abortTimeout?;
47
+ constructor(config?: NativeDataFetcherConfig);
48
+ /**
49
+ * Implements a data fetcher.
50
+ * @param {string} url The URL to request (may include query string)
51
+ * @param {RequestInit} [options] Optional fetch options
52
+ * @returns {Promise<NativeDataFetcherResponse<T>>} response
53
+ */
54
+ fetch<T>(url: string, options?: RequestInit): Promise<NativeDataFetcherResponse<T>>;
55
+ /**
56
+ * Perform a GET request
57
+ * @param {string} url The URL to request (may include query string)
58
+ * @param {RequestInit} [options] Fetch options
59
+ * @returns {Promise<NativeDataFetcherResponse<T>>} response
60
+ */
61
+ get<T>(url: string, options?: RequestInit): Promise<NativeDataFetcherResponse<T>>;
62
+ /**
63
+ * Perform a POST request
64
+ * @param {string} url The URL to request (may include query string)
65
+ * @param {unknown} body The data to send with the request
66
+ * @param {RequestInit} [options] Fetch options
67
+ * @returns {Promise<NativeDataFetcherResponse<T>>} response
68
+ */
69
+ post<T>(url: string, body: unknown, options?: RequestInit): Promise<NativeDataFetcherResponse<T>>;
70
+ /**
71
+ * Perform a DELETE request
72
+ * @param {string} url The URL to request (may include query string)
73
+ * @param {RequestInit} [options] Fetch options
74
+ * @returns {Promise<NativeDataFetcherResponse<T>>} response
75
+ */
76
+ delete<T>(url: string, options?: RequestInit): Promise<NativeDataFetcherResponse<T>>;
77
+ /**
78
+ * Perform a PUT request
79
+ * @param {string} url The URL to request (may include query string)
80
+ * @param {unknown} body The data to send with the request
81
+ * @param {RequestInit} [options] Fetch options
82
+ * @returns {Promise<NativeDataFetcherResponse<T>>} response
83
+ */
84
+ put<T>(url: string, body: unknown, options?: RequestInit): Promise<NativeDataFetcherResponse<T>>;
85
+ /**
86
+ * Perform a HEAD request
87
+ * @param {string} url The URL to request (may include query string)
88
+ * @param {RequestInit} [options] Fetch options
89
+ * @returns {Promise<NativeDataFetcherResponse<T>>} response
90
+ */
91
+ head<T>(url: string, options?: RequestInit): Promise<NativeDataFetcherResponse<T>>;
92
+ /**
93
+ * Determines settings for the request
94
+ * @param {RequestInit} init Custom settings for request
95
+ * @returns {RequestInit} The final request settings
96
+ */
97
+ protected getRequestInit(init?: RequestInit): RequestInit;
98
+ /**
99
+ * Safely extract all headers for debug logging
100
+ * @param {HeadersInit} incomingHeaders Incoming headers
101
+ * @returns Object with headers as key/value pairs
102
+ */
103
+ protected extractDebugHeaders(incomingHeaders?: HeadersInit): {
104
+ [key: string]: string | string[];
105
+ };
106
+ /**
107
+ * Parses the response data.
108
+ * @param {Response} response - The fetch response object.
109
+ * @param {Function} debug - The debug logger function.
110
+ * @returns {Promise<unknown>} - The parsed response data.
111
+ */
112
+ private parseResponse;
113
+ /**
114
+ * Creates a custom error for fetch failures.
115
+ * @param {Response} response - The fetch response object.
116
+ * @param {unknown} data - The parsed response data.
117
+ * @returns {NativeDataFetcherError} - The constructed error object.
118
+ */
119
+ private createError;
120
+ }
121
+ export {};
@@ -0,0 +1,80 @@
1
+ import { GraphQLClient, GraphQLRequestClientFactory } from '../graphql-request-client';
2
+ import { CacheClient, CacheOptions } from '../cache-client';
3
+ export type GraphQLPersonalizeServiceConfig = CacheOptions & {
4
+ /**
5
+ * Timeout (ms) for the Personalize request. Default is 400.
6
+ */
7
+ timeout?: number;
8
+ /**
9
+ * Optional Sitecore Personalize scope identifier allowing you to isolate your personalization data between XM Cloud environments
10
+ * @deprecated Will be removed in a future release.
11
+ */
12
+ scope?: string;
13
+ /**
14
+ * Override fetch method. Uses 'GraphQLRequestClient' default otherwise.
15
+ */
16
+ fetch?: typeof fetch;
17
+ /**
18
+ * A GraphQL Request Client Factory is a function that accepts configuration and returns an instance of a GraphQLRequestClient.
19
+ * This factory function is used to create and configure GraphQL clients for making GraphQL API requests.
20
+ */
21
+ clientFactory: GraphQLRequestClientFactory;
22
+ };
23
+ /**
24
+ * Object model of personlize info
25
+ */
26
+ export type PersonalizeInfo = {
27
+ /**
28
+ * The page id
29
+ */
30
+ pageId: string;
31
+ /**
32
+ * The configured variant ids
33
+ */
34
+ variantIds: string[];
35
+ };
36
+ type PersonalizeQueryResult = {
37
+ layout: {
38
+ item: {
39
+ id: string;
40
+ version: string;
41
+ personalization: {
42
+ variantIds: string[];
43
+ };
44
+ };
45
+ };
46
+ };
47
+ export declare class GraphQLPersonalizeService {
48
+ protected config: GraphQLPersonalizeServiceConfig;
49
+ private graphQLClient;
50
+ private cache;
51
+ /**
52
+ * Fetch personalize data using the Sitecore GraphQL endpoint.
53
+ * @param {GraphQLPersonalizeServiceConfig} config
54
+ */
55
+ constructor(config: GraphQLPersonalizeServiceConfig);
56
+ protected get query(): string;
57
+ /**
58
+ * Get personalize information for a route
59
+ * @param {string} itemPath page route
60
+ * @param {string} language language
61
+ * @param {string} siteName site name
62
+ * @returns {Promise<PersonalizeInfo | undefined>} the personalize information or undefined (if itemPath / language not found)
63
+ */
64
+ getPersonalizeInfo(itemPath: string, language: string, siteName: string): Promise<PersonalizeInfo | undefined>;
65
+ /**
66
+ * Gets cache client implementation
67
+ * Override this method if custom cache needs to be used
68
+ * @returns CacheClient instance
69
+ */
70
+ protected getCacheClient(): CacheClient<PersonalizeQueryResult>;
71
+ protected getCacheKey(itemPath: string, language: string, siteName: string): string;
72
+ /**
73
+ * Gets a GraphQL client that can make requests to the API. Uses graphql-request as the default
74
+ * library for fetching graphql data (@see GraphQLRequestClient). Override this method if you
75
+ * want to use something else.
76
+ * @returns {GraphQLClient} implementation
77
+ */
78
+ protected getGraphQLClient(): GraphQLClient;
79
+ }
80
+ export {};
@@ -0,0 +1,3 @@
1
+ export { personalizeLayout } from './layout-personalizer';
2
+ export { PersonalizeInfo, GraphQLPersonalizeService, GraphQLPersonalizeServiceConfig, } from './graphql-personalize-service';
3
+ export { getPersonalizedRewrite, getPersonalizedRewriteData, getGroomedVariantIds, normalizePersonalizedRewrite, PersonalizedRewriteData, CdpHelper, DEFAULT_VARIANT, } from './utils';
@@ -0,0 +1,27 @@
1
+ import { LayoutServiceData, ComponentRendering, PlaceholdersData } from '../layout/models';
2
+ export type ComponentRenderingWithExperiences = ComponentRendering & {
3
+ experiences: {
4
+ [name: string]: ComponentRenderingWithExperiences;
5
+ };
6
+ };
7
+ /**
8
+ * Apply personalization to layout data. This will recursively go through all placeholders/components, check experiences nodes and replace default with object from specific experience.
9
+ * @param {LayoutServiceData} layout Layout data
10
+ * @param {string} variantId variant id
11
+ * @param {string[]} [componentVariantIds] component variant ids
12
+ */
13
+ export declare function personalizeLayout(layout: LayoutServiceData, variantId: string, componentVariantIds?: string[]): PlaceholdersData<string> | undefined;
14
+ /**
15
+ * @param {Array} components components within placeholder
16
+ * @param {string[]} variantIds variant ids
17
+ * @param {boolean} isEditing indicates if page is rendered in metadata edit mode
18
+ * @returns {ComponentRendering[]} components with personalization applied
19
+ */
20
+ export declare function personalizePlaceholder(components: ComponentRendering[], variantIds: string[], isEditing?: boolean): ComponentRendering[];
21
+ /**
22
+ * @param {ComponentRenderingWithExperiences} component component with experiences
23
+ * @param {string[]} variantIds variant ids
24
+ * @param {boolean} isEditing indicates if page is rendered in metadata edit mode
25
+ * @returns {ComponentRendering | null} component with personalization applied or null if hidden
26
+ */
27
+ export declare function personalizeComponent(component: ComponentRenderingWithExperiences, variantIds: string[], isEditing?: boolean): ComponentRendering | null;
@@ -0,0 +1,69 @@
1
+ export declare const DEFAULT_VARIANT = "_default";
2
+ export declare const VARIANT_PREFIX = "_variantId_";
3
+ export type PersonalizedRewriteData = {
4
+ variantId: string;
5
+ componentVariantIds?: string[];
6
+ };
7
+ /**
8
+ * Get a personalized rewrite path for given pathname
9
+ * @param {string} pathname the pathname
10
+ * @param {string[]} variantIds the variantIds to include in the rewrite
11
+ * @returns {string} the rewrite path
12
+ */
13
+ export declare function getPersonalizedRewrite(pathname: string, variantIds: string[]): string;
14
+ /**
15
+ * Get personalize data from the rewrite path
16
+ * @param {string} pathname the pathname
17
+ * @returns {PersonalizedRewriteData} the personalize data from the rewrite
18
+ */
19
+ export declare function getPersonalizedRewriteData(pathname: string): PersonalizedRewriteData;
20
+ /**
21
+ * Parses a list of variantIds and divides into layout and component variants
22
+ * @param {string[]} variantIds the list of variant IDs for a page
23
+ * @returns {PersonalizedRewriteData} object with variant IDs sorted
24
+ */
25
+ export declare function getGroomedVariantIds(variantIds: string[]): PersonalizedRewriteData;
26
+ /**
27
+ * Normalize a personalized rewrite path (remove personalize data)
28
+ * @param {string} pathname the pathname
29
+ * @returns {string} the pathname with personalize data removed
30
+ */
31
+ export declare function normalizePersonalizedRewrite(pathname: string): string;
32
+ /**
33
+ * Static utility class for Sitecore CDP
34
+ */
35
+ export declare class CdpHelper {
36
+ /**
37
+ * Gets the page variant id for CDP in the required format
38
+ * @param {string} pageId the page id
39
+ * @param {string} language the language
40
+ * @param {string} variantId the variant id
41
+ * @param {string} [scope] the scope value
42
+ * @returns {string} the formatted page variant id
43
+ */
44
+ static getPageVariantId(pageId: string, language: string, variantId: string, scope?: string): string;
45
+ /**
46
+ * Gets the friendly id for (page-level) Embedded Personalization in the required format `embedded_[<scope>_]<id>_<lang>`
47
+ * @param {string} pageId the page id
48
+ * @param {string} language the language
49
+ * @param {string} [scope] the scope value
50
+ * @returns {string} the friendly id
51
+ */
52
+ static getPageFriendlyId(pageId: string, language: string, scope?: string): string;
53
+ /**
54
+ * Gets the friendly id for Component A/B Testing in the required format `component_[<scope>_]<pageId>_<componentId>_<language>*`
55
+ * @param {string} pageId the page id
56
+ * @param {string} componentId the component id
57
+ * @param {string} language the language
58
+ * @param {string} [scope] the scope value
59
+ * @returns {string} the friendly id
60
+ */
61
+ static getComponentFriendlyId(pageId: string, componentId: string, language: string, scope?: string): string;
62
+ /**
63
+ * Normalizes the scope from the given string value
64
+ * Removes all non-alphanumeric characters
65
+ * @param {string} [scope] the scope value
66
+ * @returns {string} normalized scope value
67
+ */
68
+ static normalizeScope(scope?: string): string;
69
+ }
@@ -0,0 +1,57 @@
1
+ import { GraphQLClient, GraphQLRequestClientConfig } from '../graphql';
2
+ import { LayoutServiceData } from '../layout';
3
+ import { GraphQLRequestClientFactory } from '../graphql-request-client';
4
+ export interface GraphQLErrorPagesServiceConfig extends Pick<GraphQLRequestClientConfig, 'retries' | 'retryStrategy'> {
5
+ /**
6
+ * The JSS application name
7
+ */
8
+ siteName: string;
9
+ /**
10
+ * The language
11
+ */
12
+ language: string;
13
+ /**
14
+ * A GraphQL Request Client Factory is a function that accepts configuration and returns an instance of a GraphQLRequestClient.
15
+ * This factory function is used to create and configure GraphQL clients for making GraphQL API requests.
16
+ */
17
+ clientFactory: GraphQLRequestClientFactory;
18
+ }
19
+ /**
20
+ * Object model of Error Pages result
21
+ */
22
+ export type ErrorPages = {
23
+ notFoundPage: {
24
+ rendered: LayoutServiceData;
25
+ };
26
+ notFoundPagePath: string;
27
+ serverErrorPage: {
28
+ rendered: LayoutServiceData;
29
+ };
30
+ serverErrorPagePath: string;
31
+ };
32
+ /**
33
+ * Service that fetch the error pages data using Sitecore's GraphQL API.
34
+ */
35
+ export declare class GraphQLErrorPagesService {
36
+ options: GraphQLErrorPagesServiceConfig;
37
+ private graphQLClient;
38
+ /**
39
+ * Creates an instance of graphQL error pages service with the provided options
40
+ * @param {GraphQLErrorPagesServiceConfig} options instance
41
+ */
42
+ constructor(options: GraphQLErrorPagesServiceConfig);
43
+ protected get query(): string;
44
+ /**
45
+ * Fetch list of error pages for the site
46
+ * @returns {ErrorPages} list of url's error pages
47
+ * @throws {Error} if the siteName is empty.
48
+ */
49
+ fetchErrorPages(): Promise<ErrorPages | null>;
50
+ /**
51
+ * Gets a GraphQL client that can make requests to the API. Uses graphql-request as the default
52
+ * library for fetching graphql data (@see GraphQLRequestClient). Override this method if you
53
+ * want to use something else.
54
+ * @returns {GraphQLClient} implementation
55
+ */
56
+ protected getGraphQLClient(): GraphQLClient;
57
+ }
@@ -0,0 +1,68 @@
1
+ import { GraphQLClient } from '../graphql';
2
+ import { CacheOptions, CacheClient } from '../cache-client';
3
+ import { GraphQLRequestClientFactory } from '../graphql-request-client';
4
+ export declare const REDIRECT_TYPE_301 = "REDIRECT_301";
5
+ export declare const REDIRECT_TYPE_302 = "REDIRECT_302";
6
+ export declare const REDIRECT_TYPE_SERVER_TRANSFER = "SERVER_TRANSFER";
7
+ export type RedirectInfo = {
8
+ pattern: string;
9
+ target: string;
10
+ redirectType: string;
11
+ isQueryStringPreserved: boolean;
12
+ locale: string;
13
+ };
14
+ export type GraphQLRedirectsServiceConfig = CacheOptions & {
15
+ /**
16
+ * Override fetch method. Uses 'GraphQLRequestClient' default otherwise.
17
+ */
18
+ fetch?: typeof fetch;
19
+ /**
20
+ * A GraphQL Request Client Factory is a function that accepts configuration and returns an instance of a GraphQLRequestClient.
21
+ * This factory function is used to create and configure GraphQL clients for making GraphQL API requests.
22
+ */
23
+ clientFactory: GraphQLRequestClientFactory;
24
+ };
25
+ /**
26
+ * The schema of data returned in response to redirects array request
27
+ */
28
+ export type RedirectsQueryResult = {
29
+ site: {
30
+ siteInfo: {
31
+ redirects: RedirectInfo[];
32
+ } | null;
33
+ };
34
+ };
35
+ /**
36
+ * The GraphQLRedirectsService class is used to query the JSS redirects using Graphql endpoint
37
+ */
38
+ export declare class GraphQLRedirectsService {
39
+ private options;
40
+ private graphQLClient;
41
+ private cache;
42
+ /**
43
+ * Creates an instance of graphQL redirects service with the provided options
44
+ * @param {GraphQLRedirectsServiceConfig} options instance
45
+ */
46
+ constructor(options: GraphQLRedirectsServiceConfig);
47
+ protected get query(): string;
48
+ /**
49
+ * Fetch an array of redirects from API
50
+ * @param {string} siteName site name
51
+ * @returns Promise<RedirectInfo[]>
52
+ * @throws {Error} if the siteName is empty.
53
+ */
54
+ fetchRedirects(siteName: string): Promise<RedirectInfo[]>;
55
+ /**
56
+ * Gets a GraphQL client that can make requests to the API. Uses graphql-request as the default
57
+ * library for fetching graphql data (@see GraphQLRequestClient). Override this method if you
58
+ * want to use something else.
59
+ * @returns {GraphQLClient} implementation
60
+ */
61
+ protected getGraphQLClient(): GraphQLClient;
62
+ /**
63
+ * Gets cache client implementation
64
+ * Override this method if custom cache needs to be used
65
+ * @returns CacheClient instance
66
+ */
67
+ protected getCacheClient(): CacheClient<RedirectsQueryResult>;
68
+ }
@@ -0,0 +1,49 @@
1
+ import { GraphQLClient } from '../graphql';
2
+ import { GraphQLRequestClientFactory } from '../graphql-request-client';
3
+ export type GraphQLRobotsServiceConfig = {
4
+ /**
5
+ * The JSS application name
6
+ */
7
+ siteName: string;
8
+ /**
9
+ * A GraphQL Request Client Factory is a function that accepts configuration and returns an instance of a GraphQLRequestClient.
10
+ * This factory function is used to create and configure GraphQL clients for making GraphQL API requests.
11
+ */
12
+ clientFactory: GraphQLRequestClientFactory;
13
+ };
14
+ /**
15
+ * The schema of data returned in response to robots.txt request
16
+ */
17
+ export type RobotsQueryResult = {
18
+ site: {
19
+ siteInfo: {
20
+ robots: string;
21
+ };
22
+ };
23
+ };
24
+ /**
25
+ * Service that fetch the robots.txt data using Sitecore's GraphQL API.
26
+ */
27
+ export declare class GraphQLRobotsService {
28
+ options: GraphQLRobotsServiceConfig;
29
+ private graphQLClient;
30
+ /**
31
+ * Creates an instance of graphQL robots.txt service with the provided options
32
+ * @param {GraphQLRobotsServiceConfig} options instance
33
+ */
34
+ constructor(options: GraphQLRobotsServiceConfig);
35
+ protected get query(): string;
36
+ /**
37
+ * Fetch a data of robots.txt from API
38
+ * @returns text of robots.txt
39
+ * @throws {Error} if the siteName is empty.
40
+ */
41
+ fetchRobots(): Promise<string>;
42
+ /**
43
+ * Gets a GraphQL client that can make requests to the API. Uses graphql-request as the default
44
+ * library for fetching graphql data (@see GraphQLRequestClient). Override this method if you
45
+ * want to use something else.
46
+ * @returns {GraphQLClient} implementation
47
+ */
48
+ protected getGraphQLClient(): GraphQLClient;
49
+ }
@@ -0,0 +1,70 @@
1
+ import { GraphQLClient } from '../graphql';
2
+ import { CacheClient, CacheOptions } from '../cache-client';
3
+ import { GraphQLRequestClientFactory } from '../graphql-request-client';
4
+ export type SiteInfo = {
5
+ /**
6
+ * Additional user-defined properties
7
+ */
8
+ [key: string]: unknown;
9
+ /**
10
+ * Site name
11
+ */
12
+ name: string;
13
+ /**
14
+ * Site host name. May include multiple values (separated by '|') and wildcards ('*')
15
+ */
16
+ hostName: string;
17
+ /**
18
+ * Site default language
19
+ */
20
+ language: string;
21
+ };
22
+ export type GraphQLSiteInfoServiceConfig = CacheOptions & {
23
+ /**
24
+ * common variable for all GraphQL queries
25
+ * it will be used for every type of query to regulate result batch size
26
+ * Optional. How many result items to fetch in each GraphQL call. This is needed for pagination.
27
+ * @default 10
28
+ */
29
+ pageSize?: number;
30
+ /**
31
+ * A GraphQL Request Client Factory is a function that accepts configuration and returns an instance of a GraphQLRequestClient.
32
+ * This factory function is used to create and configure GraphQL clients for making GraphQL API requests.
33
+ */
34
+ clientFactory: GraphQLRequestClientFactory;
35
+ };
36
+ export type GraphQLSiteInfoResult = {
37
+ name: string;
38
+ hostName: string;
39
+ language: string;
40
+ };
41
+ export declare class GraphQLSiteInfoService {
42
+ private config;
43
+ private graphQLClient;
44
+ private cache;
45
+ /**
46
+ * Creates an instance of graphQL service to retrieve site configuration list from Sitecore
47
+ * @param {GraphQLSiteInfoServiceConfig} config instance
48
+ */
49
+ constructor(config: GraphQLSiteInfoServiceConfig);
50
+ /**
51
+ * site query is available on XM Cloud and XP 10.4+
52
+ */
53
+ protected get siteQuery(): string;
54
+ fetchSiteInfo(): Promise<SiteInfo[]>;
55
+ protected fetchWithSiteQuery(): Promise<SiteInfo[]>;
56
+ /**
57
+ * Gets cache client implementation
58
+ * Override this method if custom cache needs to be used
59
+ * @returns CacheClient instance
60
+ */
61
+ protected getCacheClient(): CacheClient<SiteInfo[]>;
62
+ /**
63
+ * Gets a GraphQL client that can make requests to the API. Uses graphql-request as the default
64
+ * library for fetching graphql data (@see GraphQLRequestClient). Override this method if you
65
+ * want to use something else.
66
+ * @returns {GraphQLClient} implementation
67
+ */
68
+ protected getGraphQLClient(): GraphQLClient;
69
+ private getCacheKey;
70
+ }