@sitecore-jss/sitecore-jss 0.1.0-beta.2
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 +7 -0
- package/dist/cjs/cache-client.js +54 -0
- package/dist/cjs/constants.js +12 -0
- package/dist/cjs/debug.js +43 -0
- package/dist/cjs/graphql/app-root-query.js +73 -0
- package/dist/cjs/graphql/graphql-edge-proxy.js +12 -0
- package/dist/cjs/graphql/index.js +11 -0
- package/dist/cjs/graphql/search-service.js +60 -0
- package/dist/cjs/graphql-request-client.js +106 -0
- package/dist/cjs/i18n/dictionary-service.js +45 -0
- package/dist/cjs/i18n/graphql-dictionary-service.js +125 -0
- package/dist/cjs/i18n/index.js +7 -0
- package/dist/cjs/index.js +36 -0
- package/dist/cjs/layout/content-styles.js +73 -0
- package/dist/cjs/layout/graphql-layout-service.js +84 -0
- package/dist/cjs/layout/index.js +18 -0
- package/dist/cjs/layout/layout-service.js +9 -0
- package/dist/cjs/layout/models.js +27 -0
- package/dist/cjs/layout/themes.js +79 -0
- package/dist/cjs/layout/utils.js +44 -0
- package/dist/cjs/media/index.js +24 -0
- package/dist/cjs/media/media-api.js +128 -0
- package/dist/cjs/models.js +2 -0
- package/dist/cjs/native-fetcher.js +183 -0
- package/dist/cjs/personalize/graphql-personalize-service.js +114 -0
- package/dist/cjs/personalize/index.js +12 -0
- package/dist/cjs/personalize/layout-personalizer.js +75 -0
- package/dist/cjs/personalize/utils.js +92 -0
- package/dist/cjs/site/graphql-error-pages-service.js +86 -0
- package/dist/cjs/site/graphql-redirects-service.js +103 -0
- package/dist/cjs/site/graphql-robots-service.js +81 -0
- package/dist/cjs/site/graphql-siteinfo-service.js +128 -0
- package/dist/cjs/site/graphql-sitemap-service.js +91 -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/edit-frame.js +138 -0
- package/dist/cjs/utils/editing.js +122 -0
- package/dist/cjs/utils/env.js +26 -0
- package/dist/cjs/utils/index.js +25 -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 +70 -0
- package/dist/esm/cache-client.js +50 -0
- package/dist/esm/constants.js +9 -0
- package/dist/esm/debug.js +36 -0
- package/dist/esm/graphql/app-root-query.js +69 -0
- package/dist/esm/graphql/graphql-edge-proxy.js +8 -0
- package/dist/esm/graphql/index.js +4 -0
- package/dist/esm/graphql/search-service.js +56 -0
- package/dist/esm/graphql-request-client.js +99 -0
- package/dist/esm/i18n/dictionary-service.js +41 -0
- package/dist/esm/i18n/graphql-dictionary-service.js +118 -0
- package/dist/esm/i18n/index.js +2 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/layout/content-styles.js +65 -0
- package/dist/esm/layout/graphql-layout-service.js +77 -0
- package/dist/esm/layout/index.js +6 -0
- package/dist/esm/layout/layout-service.js +5 -0
- package/dist/esm/layout/models.js +24 -0
- package/dist/esm/layout/themes.js +74 -0
- package/dist/esm/layout/utils.js +39 -0
- package/dist/esm/media/index.js +2 -0
- package/dist/esm/media/media-api.js +117 -0
- package/dist/esm/models.js +1 -0
- package/dist/esm/native-fetcher.js +176 -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 +69 -0
- package/dist/esm/personalize/utils.js +85 -0
- package/dist/esm/site/graphql-error-pages-service.js +79 -0
- package/dist/esm/site/graphql-redirects-service.js +96 -0
- package/dist/esm/site/graphql-robots-service.js +74 -0
- package/dist/esm/site/graphql-siteinfo-service.js +121 -0
- package/dist/esm/site/graphql-sitemap-service.js +84 -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/edit-frame.js +133 -0
- package/dist/esm/utils/editing.js +111 -0
- package/dist/esm/utils/env.js +22 -0
- package/dist/esm/utils/index.js +5 -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 +61 -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 +71 -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 +6 -0
- package/types/debug.d.ts +26 -0
- package/types/graphql/app-root-query.d.ts +32 -0
- package/types/graphql/graphql-edge-proxy.d.ts +7 -0
- package/types/graphql/index.d.ts +4 -0
- package/types/graphql/search-service.d.ts +92 -0
- package/types/graphql-request-client.d.ts +88 -0
- package/types/i18n/dictionary-service.d.ts +56 -0
- package/types/i18n/graphql-dictionary-service.d.ts +65 -0
- package/types/i18n/index.d.ts +2 -0
- package/types/index.d.ts +6 -0
- package/types/layout/content-styles.d.ts +18 -0
- package/types/layout/graphql-layout-service.d.ts +59 -0
- package/types/layout/index.d.ts +6 -0
- package/types/layout/layout-service.d.ts +20 -0
- package/types/layout/models.d.ts +140 -0
- package/types/layout/themes.d.ts +11 -0
- package/types/layout/utils.d.ts +17 -0
- package/types/media/index.d.ts +2 -0
- package/types/media/media-api.d.ts +69 -0
- package/types/models.d.ts +6 -0
- package/types/native-fetcher.d.ts +92 -0
- package/types/personalize/graphql-personalize-service.d.ts +77 -0
- package/types/personalize/index.d.ts +3 -0
- package/types/personalize/layout-personalizer.d.ts +25 -0
- package/types/personalize/utils.d.ts +53 -0
- package/types/site/graphql-error-pages-service.d.ts +55 -0
- package/types/site/graphql-redirects-service.d.ts +66 -0
- package/types/site/graphql-robots-service.d.ts +47 -0
- package/types/site/graphql-siteinfo-service.d.ts +69 -0
- package/types/site/graphql-sitemap-service.d.ts +53 -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/edit-frame.d.ts +76 -0
- package/types/utils/editing.d.ts +58 -0
- package/types/utils/env.d.ts +7 -0
- package/types/utils/index.d.ts +5 -0
- package/types/utils/is-server.d.ts +6 -0
- package/types/utils/timeout-promise.d.ts +18 -0
- package/types/utils/utils.d.ts +18 -0
- package/utils.d.ts +1 -0
- package/utils.js +1 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ComponentRendering, Field, HtmlElementRendering, Item, LayoutServiceData, RouteData } from './index';
|
|
2
|
+
import { HTMLLink } from '../models';
|
|
3
|
+
declare 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 | HtmlElementRendering>, config: Config) => void;
|
|
16
|
+
export declare const traverseField: (field: Field | Item | Item[] | undefined, config: Config) => void;
|
|
17
|
+
export declare const traverseComponent: (component: RouteData | ComponentRendering | HtmlElementRendering, config: Config) => void;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { LayoutServiceBase } from './layout-service';
|
|
2
|
+
import { LayoutServiceData } from './models';
|
|
3
|
+
import { GraphQLClient, GraphQLRequestClientFactory, GraphQLRequestClientConfig } from '../graphql-request-client';
|
|
4
|
+
export interface GraphQLLayoutServiceConfig extends Pick<GraphQLRequestClientConfig, 'retries'> {
|
|
5
|
+
/**
|
|
6
|
+
* The JSS application name
|
|
7
|
+
*/
|
|
8
|
+
siteName: string;
|
|
9
|
+
/**
|
|
10
|
+
* A GraphQL Request Client Factory is a function that accepts configuration and returns an instance of a GraphQLRequestClient.
|
|
11
|
+
* This factory function is used to create and configure GraphQL clients for making GraphQL API requests.
|
|
12
|
+
*/
|
|
13
|
+
clientFactory: GraphQLRequestClientFactory;
|
|
14
|
+
/**
|
|
15
|
+
* Override default layout query
|
|
16
|
+
* @param {string} siteName
|
|
17
|
+
* @param {string} itemPath
|
|
18
|
+
* @param {string} [locale]
|
|
19
|
+
* @returns {string} custom layout query
|
|
20
|
+
*
|
|
21
|
+
* @default
|
|
22
|
+
* Layout query
|
|
23
|
+
* layout(site:"${siteName}", routePath:"${itemPath}", language:"${language}")
|
|
24
|
+
*/
|
|
25
|
+
formatLayoutQuery?: (siteName: string, itemPath: string, locale?: string) => string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Service that fetch layout data using Sitecore's GraphQL API.
|
|
29
|
+
* @augments LayoutServiceBase
|
|
30
|
+
* @mixes GraphQLRequestClient
|
|
31
|
+
*/
|
|
32
|
+
export declare class GraphQLLayoutService extends LayoutServiceBase {
|
|
33
|
+
serviceConfig: GraphQLLayoutServiceConfig;
|
|
34
|
+
private graphQLClient;
|
|
35
|
+
/**
|
|
36
|
+
* Fetch layout data using the Sitecore GraphQL endpoint.
|
|
37
|
+
* @param {GraphQLLayoutServiceConfig} serviceConfig configuration
|
|
38
|
+
*/
|
|
39
|
+
constructor(serviceConfig: GraphQLLayoutServiceConfig);
|
|
40
|
+
/**
|
|
41
|
+
* Fetch layout data for an item.
|
|
42
|
+
* @param {string} itemPath item path to fetch layout data for.
|
|
43
|
+
* @param {string} [language] the language to fetch layout data for.
|
|
44
|
+
* @returns {Promise<LayoutServiceData>} layout service data
|
|
45
|
+
*/
|
|
46
|
+
fetchLayoutData(itemPath: string, language?: string): Promise<LayoutServiceData>;
|
|
47
|
+
/**
|
|
48
|
+
* Gets a GraphQL client that can make requests to the API.
|
|
49
|
+
* @returns {GraphQLClient} implementation
|
|
50
|
+
*/
|
|
51
|
+
protected getGraphQLClient(): GraphQLClient;
|
|
52
|
+
/**
|
|
53
|
+
* Returns GraphQL Layout query
|
|
54
|
+
* @param {string} itemPath page route
|
|
55
|
+
* @param {string} [language] language
|
|
56
|
+
* @returns {string} GraphQL query
|
|
57
|
+
*/
|
|
58
|
+
protected getLayoutQuery(itemPath: string, language?: string): string;
|
|
59
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { LayoutServiceData, LayoutServicePageState, LayoutServiceContext, LayoutServiceContextData, RouteData, PlaceholderData, ComponentRendering, HtmlElementRendering, Field, Item, PlaceholdersData, ComponentFields, ComponentParams, RenderingType, EDITING_COMPONENT_PLACEHOLDER, EDITING_COMPONENT_ID, } from './models';
|
|
2
|
+
export { getFieldValue, getChildPlaceholder } from './utils';
|
|
3
|
+
export { getContentStylesheetLink } from './content-styles';
|
|
4
|
+
export { LayoutService } from './layout-service';
|
|
5
|
+
export { GraphQLLayoutService, GraphQLLayoutServiceConfig } from './graphql-layout-service';
|
|
6
|
+
export { getComponentLibraryStylesheetLinks } from './themes';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import * as models from './models';
|
|
3
|
+
import { IncomingMessage, ServerResponse } from 'http';
|
|
4
|
+
export interface LayoutService {
|
|
5
|
+
/**
|
|
6
|
+
* Fetch layout data for an item.
|
|
7
|
+
* @param {string} itemPath
|
|
8
|
+
* @param {string} [language]
|
|
9
|
+
* @param {IncomingMessage} [req] Request instance
|
|
10
|
+
* @param {ServerResponse} [res] Response instance
|
|
11
|
+
* @returns {Promise<LayoutServiceData>} layout data
|
|
12
|
+
*/
|
|
13
|
+
fetchLayoutData(itemPath: string, language?: string, req?: IncomingMessage, res?: ServerResponse): Promise<models.LayoutServiceData>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Base abstraction to implement custom layout service
|
|
17
|
+
*/
|
|
18
|
+
export declare abstract class LayoutServiceBase implements LayoutService {
|
|
19
|
+
abstract fetchLayoutData(itemPath: string, language?: string, req?: IncomingMessage, res?: ServerResponse): Promise<models.LayoutServiceData>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Static placeholder name used for component rendering
|
|
3
|
+
*/
|
|
4
|
+
export declare const EDITING_COMPONENT_PLACEHOLDER = "editing-componentmode-placeholder";
|
|
5
|
+
/**
|
|
6
|
+
* Id of wrapper for component rendering
|
|
7
|
+
*/
|
|
8
|
+
export declare const EDITING_COMPONENT_ID = "editing-component";
|
|
9
|
+
/**
|
|
10
|
+
* A reply from the Sitecore Layout Service
|
|
11
|
+
*/
|
|
12
|
+
export interface LayoutServiceData {
|
|
13
|
+
sitecore: LayoutServiceContextData & {
|
|
14
|
+
route: RouteData | null;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Layout Service page state enum
|
|
19
|
+
*/
|
|
20
|
+
export declare enum LayoutServicePageState {
|
|
21
|
+
Preview = "preview",
|
|
22
|
+
Edit = "edit",
|
|
23
|
+
Normal = "normal"
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Editing rendering type
|
|
27
|
+
*/
|
|
28
|
+
export declare enum RenderingType {
|
|
29
|
+
Component = "component"
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Shape of context data from the Sitecore Layout Service
|
|
33
|
+
*/
|
|
34
|
+
export interface LayoutServiceContext {
|
|
35
|
+
[key: string]: unknown;
|
|
36
|
+
renderingType?: RenderingType;
|
|
37
|
+
pageEditing?: boolean;
|
|
38
|
+
language?: string;
|
|
39
|
+
pageState?: LayoutServicePageState;
|
|
40
|
+
visitorIdentificationTimestamp?: number;
|
|
41
|
+
site?: {
|
|
42
|
+
name?: string;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Context information from the Sitecore Layout Service
|
|
47
|
+
*/
|
|
48
|
+
export interface LayoutServiceContextData {
|
|
49
|
+
context: LayoutServiceContext;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Shape of route data returned from Sitecore Layout Service
|
|
53
|
+
*/
|
|
54
|
+
export interface RouteData<Fields = Record<string, Field | Item | Item[]>> {
|
|
55
|
+
name: string;
|
|
56
|
+
displayName?: string;
|
|
57
|
+
fields?: Fields;
|
|
58
|
+
databaseName?: string;
|
|
59
|
+
deviceId?: string;
|
|
60
|
+
itemLanguage?: string;
|
|
61
|
+
itemVersion?: number;
|
|
62
|
+
layoutId?: string;
|
|
63
|
+
templateId?: string;
|
|
64
|
+
templateName?: string;
|
|
65
|
+
placeholders: PlaceholdersData;
|
|
66
|
+
itemId?: string;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Placeholder contents data (name: placeholder name, then array of components within that placeholder name)
|
|
70
|
+
* Note: HtmlElementRendering is used by Sitecore Experience Editor
|
|
71
|
+
*/
|
|
72
|
+
export declare type PlaceholdersData<TYPEDNAME extends string = string> = {
|
|
73
|
+
[P in TYPEDNAME]: Array<ComponentRendering | HtmlElementRendering>;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Content field data passed to a component
|
|
77
|
+
*/
|
|
78
|
+
export interface ComponentFields {
|
|
79
|
+
[name: string]: Field | Item | Item[];
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Component params
|
|
83
|
+
*/
|
|
84
|
+
export interface ComponentParams {
|
|
85
|
+
[name: string]: string;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Definition of a component instance within a placeholder on a route
|
|
89
|
+
*/
|
|
90
|
+
export interface ComponentRendering {
|
|
91
|
+
componentName: string;
|
|
92
|
+
dataSource?: string;
|
|
93
|
+
uid?: string;
|
|
94
|
+
placeholders?: PlaceholdersData;
|
|
95
|
+
fields?: ComponentFields;
|
|
96
|
+
params?: ComponentParams;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* HTML content used to support Sitecore Experience Editor
|
|
100
|
+
*/
|
|
101
|
+
export interface HtmlElementRendering {
|
|
102
|
+
name: string;
|
|
103
|
+
type?: string;
|
|
104
|
+
contents: string | null;
|
|
105
|
+
attributes: {
|
|
106
|
+
[name: string]: string | undefined;
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Field value data on a component
|
|
111
|
+
*/
|
|
112
|
+
export declare type GenericFieldValue = string | boolean | number | {
|
|
113
|
+
[key: string]: unknown;
|
|
114
|
+
} | Array<{
|
|
115
|
+
[key: string]: unknown;
|
|
116
|
+
}>;
|
|
117
|
+
export interface Field<T = GenericFieldValue> {
|
|
118
|
+
value: T;
|
|
119
|
+
editable?: string;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Content data returned from Content Service
|
|
123
|
+
*/
|
|
124
|
+
export interface Item {
|
|
125
|
+
name: string;
|
|
126
|
+
displayName?: string;
|
|
127
|
+
id?: string;
|
|
128
|
+
url?: string;
|
|
129
|
+
fields: {
|
|
130
|
+
[name: string]: Field | Item | Item[] | undefined;
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Contents of a single placeholder returned from placeholder service
|
|
135
|
+
*/
|
|
136
|
+
export interface PlaceholderData {
|
|
137
|
+
name: string;
|
|
138
|
+
path: string;
|
|
139
|
+
elements: Array<HtmlElementRendering | ComponentRendering>;
|
|
140
|
+
}
|
|
@@ -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;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ComponentRendering, ComponentFields, HtmlElementRendering } 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 {Array<ComponentRendering | HtmlElementRendering>} child placeholder
|
|
16
|
+
*/
|
|
17
|
+
export declare function getChildPlaceholder(rendering: ComponentRendering, placeholderName: string): Array<ComponentRendering | HtmlElementRendering>;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Makes a request to Sitecore Content Service for the specified item path.
|
|
3
|
+
* @param {string} editorMarkup the markup to parse
|
|
4
|
+
* @returns {Object | null} found image tag; null in case if not found
|
|
5
|
+
*/
|
|
6
|
+
export declare const findEditorImageTag: (editorMarkup: string) => {
|
|
7
|
+
imgTag: string;
|
|
8
|
+
attrs: {
|
|
9
|
+
[key: string]: string;
|
|
10
|
+
};
|
|
11
|
+
} | null;
|
|
12
|
+
/**
|
|
13
|
+
* Get required query string params which should be merged with user params
|
|
14
|
+
* @param {object} qs layout service parsed query string
|
|
15
|
+
* @returns {object} requiredParams
|
|
16
|
+
*/
|
|
17
|
+
export declare const getRequiredParams: (qs: {
|
|
18
|
+
[key: string]: string | undefined;
|
|
19
|
+
}) => {
|
|
20
|
+
rev: string | undefined;
|
|
21
|
+
db: string | undefined;
|
|
22
|
+
la: string | undefined;
|
|
23
|
+
vs: string | undefined;
|
|
24
|
+
ts: string | undefined;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Replace `/~/media` or `/-/media` with `/~/jssmedia` or `/-/jssmedia`, respectively.
|
|
28
|
+
* Can use `mediaUrlPrefix` in order to use a custom prefix.
|
|
29
|
+
* @param {string} url The URL to replace the media URL prefix in
|
|
30
|
+
* @param {RegExp} [mediaUrlPrefix=mediaUrlPrefixRegex] The regex to match the media URL prefix
|
|
31
|
+
* @returns {string} The URL with the media URL prefix replaced
|
|
32
|
+
*/
|
|
33
|
+
export declare const replaceMediaUrlPrefix: (url: string, mediaUrlPrefix?: RegExp) => string;
|
|
34
|
+
/**
|
|
35
|
+
* Prepares a Sitecore media URL with `params` for use by the JSS media handler.
|
|
36
|
+
* This is done by replacing `/~/media` or `/-/media` with `/~/jssmedia` or `/-/jssmedia`, respectively.
|
|
37
|
+
* Provided `params` are used as the querystring parameters for the media URL.
|
|
38
|
+
* Can use `mediaUrlPrefix` in order to use a custom prefix.
|
|
39
|
+
* If no `params` are sent, the original media URL is returned.
|
|
40
|
+
* @param {string} url The URL to prepare
|
|
41
|
+
* @param {Object} [params] The querystring parameters to use
|
|
42
|
+
* @param {RegExp} [mediaUrlPrefix=mediaUrlPrefixRegex] The regex to match the media URL prefix
|
|
43
|
+
* @returns {string} The prepared URL
|
|
44
|
+
*/
|
|
45
|
+
export declare const updateImageUrl: (url: string, params?: {
|
|
46
|
+
[key: string]: string | number | undefined;
|
|
47
|
+
} | null | undefined, mediaUrlPrefix?: RegExp) => string;
|
|
48
|
+
/**
|
|
49
|
+
* Receives an array of `srcSet` parameters that are iterated and used as parameters to generate
|
|
50
|
+
* a corresponding set of updated Sitecore media URLs via @see updateImageUrl. The result is a comma-delimited
|
|
51
|
+
* list of media URLs with respective dimension parameters.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* // returns '/ipsum.jpg?h=1000&w=1000 1000w, /ipsum.jpg?mh=250&mw=250 250w'
|
|
55
|
+
* getSrcSet('/ipsum.jpg', [{ h: 1000, w: 1000 }, { mh: 250, mw: 250 } ])
|
|
56
|
+
*
|
|
57
|
+
* More information about `srcSet`: {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img}
|
|
58
|
+
*
|
|
59
|
+
* @param {string} url The URL to prepare
|
|
60
|
+
* @param {Array} srcSet The array of parameters to use
|
|
61
|
+
* @param {Object} [imageParams] The querystring parameters to use
|
|
62
|
+
* @param {RegExp} [mediaUrlPrefix] The regex to match the media URL prefix
|
|
63
|
+
* @returns {string} The prepared URL
|
|
64
|
+
*/
|
|
65
|
+
export declare const getSrcSet: (url: string, srcSet: {
|
|
66
|
+
[key: string]: string | number | undefined;
|
|
67
|
+
}[], imageParams?: {
|
|
68
|
+
[key: string]: string | number | undefined;
|
|
69
|
+
} | undefined, mediaUrlPrefix?: RegExp | undefined) => string;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { Debugger } from './debug';
|
|
2
|
+
declare type NativeDataFetcherOptions = {
|
|
3
|
+
/**
|
|
4
|
+
* Override debugger for logging. Uses 'sitecore-jss: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
|
+
}
|
|
28
|
+
export declare type NativeDataFetcherConfig = NativeDataFetcherOptions & RequestInit;
|
|
29
|
+
export declare class NativeDataFetcher {
|
|
30
|
+
protected config: NativeDataFetcherConfig;
|
|
31
|
+
private abortTimeout?;
|
|
32
|
+
constructor(config?: NativeDataFetcherConfig);
|
|
33
|
+
/**
|
|
34
|
+
* Implements a data fetcher.
|
|
35
|
+
* @param {string} url The URL to request (may include query string)
|
|
36
|
+
* @param {RequestInit} [options] Optional fetch options
|
|
37
|
+
* @returns {Promise<NativeDataFetcherResponse<T>>} response
|
|
38
|
+
*/
|
|
39
|
+
fetch<T>(url: string, options?: RequestInit): Promise<NativeDataFetcherResponse<T>>;
|
|
40
|
+
/**
|
|
41
|
+
* Perform a GET request
|
|
42
|
+
* @param {string} url The URL to request (may include query string)
|
|
43
|
+
* @param {RequestInit} [options] Fetch options
|
|
44
|
+
* @returns {Promise<NativeDataFetcherResponse<T>>} response
|
|
45
|
+
*/
|
|
46
|
+
get<T>(url: string, options?: RequestInit): Promise<NativeDataFetcherResponse<T>>;
|
|
47
|
+
/**
|
|
48
|
+
* Perform a POST request
|
|
49
|
+
* @param {string} url The URL to request (may include query string)
|
|
50
|
+
* @param {unknown} body The data to send with the request
|
|
51
|
+
* @param {RequestInit} [options] Fetch options
|
|
52
|
+
* @returns {Promise<NativeDataFetcherResponse<T>>} response
|
|
53
|
+
*/
|
|
54
|
+
post<T>(url: string, body: unknown, options?: RequestInit): Promise<NativeDataFetcherResponse<T>>;
|
|
55
|
+
/**
|
|
56
|
+
* Perform a DELETE 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
|
+
delete<T>(url: string, options?: RequestInit): Promise<NativeDataFetcherResponse<T>>;
|
|
62
|
+
/**
|
|
63
|
+
* Perform a PUT 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
|
+
put<T>(url: string, body: unknown, options?: RequestInit): Promise<NativeDataFetcherResponse<T>>;
|
|
70
|
+
/**
|
|
71
|
+
* Perform a HEAD 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
|
+
head<T>(url: string, options?: RequestInit): Promise<NativeDataFetcherResponse<T>>;
|
|
77
|
+
/**
|
|
78
|
+
* Determines settings for the request
|
|
79
|
+
* @param {RequestInit} init Custom settings for request
|
|
80
|
+
* @returns {RequestInit} The final request settings
|
|
81
|
+
*/
|
|
82
|
+
protected getRequestInit(init?: RequestInit): RequestInit;
|
|
83
|
+
/**
|
|
84
|
+
* Safely extract all headers for debug logging
|
|
85
|
+
* @param {HeadersInit} incomingHeaders Incoming headers
|
|
86
|
+
* @returns Object with headers as key/value pairs
|
|
87
|
+
*/
|
|
88
|
+
protected extractDebugHeaders(incomingHeaders?: HeadersInit): {
|
|
89
|
+
[key: string]: string | string[];
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { GraphQLClient, GraphQLRequestClientFactory } from '../graphql-request-client';
|
|
2
|
+
import { CacheClient, CacheOptions } from '../cache-client';
|
|
3
|
+
export declare 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
|
+
*/
|
|
11
|
+
scope?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Override fetch method. Uses 'GraphQLRequestClient' default otherwise.
|
|
14
|
+
*/
|
|
15
|
+
fetch?: typeof fetch;
|
|
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
|
+
/**
|
|
23
|
+
* Object model of personlize info
|
|
24
|
+
*/
|
|
25
|
+
export declare type PersonalizeInfo = {
|
|
26
|
+
/**
|
|
27
|
+
* The (CDP-friendly) content id
|
|
28
|
+
*/
|
|
29
|
+
contentId: string;
|
|
30
|
+
/**
|
|
31
|
+
* The configured variant ids
|
|
32
|
+
*/
|
|
33
|
+
variantIds: string[];
|
|
34
|
+
};
|
|
35
|
+
declare type PersonalizeQueryResult = {
|
|
36
|
+
layout: {
|
|
37
|
+
item: {
|
|
38
|
+
id: string;
|
|
39
|
+
version: string;
|
|
40
|
+
personalization: {
|
|
41
|
+
variantIds: string[];
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
export declare class GraphQLPersonalizeService {
|
|
47
|
+
protected config: GraphQLPersonalizeServiceConfig;
|
|
48
|
+
private graphQLClient;
|
|
49
|
+
private cache;
|
|
50
|
+
protected get query(): string;
|
|
51
|
+
/**
|
|
52
|
+
* Fetch personalize data using the Sitecore GraphQL endpoint.
|
|
53
|
+
* @param {GraphQLPersonalizeServiceConfig} config
|
|
54
|
+
*/
|
|
55
|
+
constructor(config: GraphQLPersonalizeServiceConfig);
|
|
56
|
+
/**
|
|
57
|
+
* Get personalize information for a route
|
|
58
|
+
* @param {string} itemPath page route
|
|
59
|
+
* @param {string} language language
|
|
60
|
+
* @param {string} siteName site name
|
|
61
|
+
* @returns {Promise<PersonalizeInfo | undefined>} the personalize information or undefined (if itemPath / language not found)
|
|
62
|
+
*/
|
|
63
|
+
getPersonalizeInfo(itemPath: string, language: string, siteName: string): Promise<PersonalizeInfo | undefined>;
|
|
64
|
+
/**
|
|
65
|
+
* Gets cache client implementation
|
|
66
|
+
* Override this method if custom cache needs to be used
|
|
67
|
+
* @returns CacheClient instance
|
|
68
|
+
*/
|
|
69
|
+
protected getCacheClient(): CacheClient<PersonalizeQueryResult>;
|
|
70
|
+
protected getCacheKey(itemPath: string, language: string, siteName: string): string;
|
|
71
|
+
/**
|
|
72
|
+
* Gets a GraphQL client that can make requests to the API.
|
|
73
|
+
* @returns {GraphQLClient} implementation
|
|
74
|
+
*/
|
|
75
|
+
protected getGraphQLClient(): GraphQLClient;
|
|
76
|
+
}
|
|
77
|
+
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { personalizeLayout } from './layout-personalizer';
|
|
2
|
+
export { PersonalizeInfo, GraphQLPersonalizeService, GraphQLPersonalizeServiceConfig, } from './graphql-personalize-service';
|
|
3
|
+
export { getPersonalizedRewrite, getPersonalizedRewriteData, normalizePersonalizedRewrite, PersonalizedRewriteData, CdpHelper, } from './utils';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { LayoutServiceData, ComponentRendering, HtmlElementRendering } from './../layout/models';
|
|
2
|
+
export declare 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
|
+
*/
|
|
12
|
+
export declare function personalizeLayout(layout: LayoutServiceData, variantId: string): void;
|
|
13
|
+
/**
|
|
14
|
+
|
|
15
|
+
* @param {Array} components components within placeholder
|
|
16
|
+
* @param {string} variantId variant id
|
|
17
|
+
* @returns {Array<ComponentRendering | HtmlElementRendering>} components with personalization applied
|
|
18
|
+
*/
|
|
19
|
+
export declare function personalizePlaceholder(components: Array<ComponentRendering | HtmlElementRendering>, variantId: string): Array<ComponentRendering | HtmlElementRendering>;
|
|
20
|
+
/**
|
|
21
|
+
* @param {ComponentRenderingWithExperiences} component component with experiences
|
|
22
|
+
* @param {string} variantId variant id
|
|
23
|
+
* @returns {ComponentRendering | null} component with personalization applied or null if hidden
|
|
24
|
+
*/
|
|
25
|
+
export declare function personalizeComponent(component: ComponentRenderingWithExperiences, variantId: string): ComponentRendering | null;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export declare const DEFAULT_VARIANT = "_default";
|
|
2
|
+
export declare const VARIANT_PREFIX = "_variantId_";
|
|
3
|
+
export declare type PersonalizedRewriteData = {
|
|
4
|
+
variantId: string;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Get a personalized rewrite path for given pathname
|
|
8
|
+
* @param {string} pathname the pathname
|
|
9
|
+
* @param {PersonalizedRewriteData} data the personalize data to include in the rewrite
|
|
10
|
+
* @returns {string} the rewrite path
|
|
11
|
+
*/
|
|
12
|
+
export declare function getPersonalizedRewrite(pathname: string, data: PersonalizedRewriteData): string;
|
|
13
|
+
/**
|
|
14
|
+
* Get personalize data from the rewrite path
|
|
15
|
+
* @param {string} pathname the pathname
|
|
16
|
+
* @returns {PersonalizedRewriteData} the personalize data from the rewrite
|
|
17
|
+
*/
|
|
18
|
+
export declare function getPersonalizedRewriteData(pathname: string): PersonalizedRewriteData;
|
|
19
|
+
/**
|
|
20
|
+
* Normalize a personalized rewrite path (remove personalize data)
|
|
21
|
+
* @param {string} pathname the pathname
|
|
22
|
+
* @returns {string} the pathname with personalize data removed
|
|
23
|
+
*/
|
|
24
|
+
export declare function normalizePersonalizedRewrite(pathname: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Static utility class for Sitecore CDP
|
|
27
|
+
*/
|
|
28
|
+
export declare class CdpHelper {
|
|
29
|
+
/**
|
|
30
|
+
* Gets the page variant id for CDP in the required format
|
|
31
|
+
* @param {string} pageId the page id
|
|
32
|
+
* @param {string} language the language
|
|
33
|
+
* @param {string} variantId the variant id
|
|
34
|
+
* @param {string} [scope] the scope value
|
|
35
|
+
* @returns {string} the formatted page variant id
|
|
36
|
+
*/
|
|
37
|
+
static getPageVariantId(pageId: string, language: string, variantId: string, scope?: string): string;
|
|
38
|
+
/**
|
|
39
|
+
* Gets the content id for CDP in the required format `embedded_[<scope>_]<id>_<lang>`
|
|
40
|
+
* @param {string} pageId the page id
|
|
41
|
+
* @param {string} language the language
|
|
42
|
+
* @param {string} [scope] the scope value
|
|
43
|
+
* @returns {string} the content id
|
|
44
|
+
*/
|
|
45
|
+
static getContentId(pageId: string, language: string, scope?: string): string;
|
|
46
|
+
/**
|
|
47
|
+
* Normalizes the scope from the given string value
|
|
48
|
+
* Removes all non-alphanumeric characters
|
|
49
|
+
* @param {string} [scope] the scope value
|
|
50
|
+
* @returns {string} normalized scope value
|
|
51
|
+
*/
|
|
52
|
+
static normalizeScope(scope?: string): string;
|
|
53
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
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'> {
|
|
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 declare 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
|
+
protected get query(): string;
|
|
39
|
+
/**
|
|
40
|
+
* Creates an instance of graphQL error pages service with the provided options
|
|
41
|
+
* @param {GraphQLErrorPagesServiceConfig} options instance
|
|
42
|
+
*/
|
|
43
|
+
constructor(options: GraphQLErrorPagesServiceConfig);
|
|
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.
|
|
52
|
+
* @returns {GraphQLClient} implementation
|
|
53
|
+
*/
|
|
54
|
+
protected getGraphQLClient(): GraphQLClient;
|
|
55
|
+
}
|