@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
package/package.json
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sitecore-content-sdk/core",
|
|
3
|
+
"version": "0.1.0-beta.1",
|
|
4
|
+
"main": "dist/cjs/index.js",
|
|
5
|
+
"module": "dist/esm/index.js",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public",
|
|
9
|
+
"registry": "https://registry.npmjs.org/"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "npm run clean && tsc -p tsconfig.json && tsc -p tsconfig-esm.json",
|
|
13
|
+
"clean": "del-cli dist types",
|
|
14
|
+
"lint": "eslint \"./src/**/*.ts\"",
|
|
15
|
+
"test": "mocha \"./src/**/*.test.ts\"",
|
|
16
|
+
"prepublishOnly": "npm run build",
|
|
17
|
+
"coverage": "nyc npm test",
|
|
18
|
+
"generate-docs": "npx typedoc --plugin typedoc-plugin-markdown --outputFileStrategy Members --parametersFormat table --readme none --out ../../ref-docs/core --entryPoints src/index.ts --entryPoints src/graphql/index.ts --entryPoints src/i18n/index.ts --entryPoints src/layout/index.ts --entryPoints src/media/index.ts --entryPoints src/personalize/index.ts --entryPoints src/site/index.ts --entryPoints src/tracking/index.ts --entryPoints src/utils/index.ts --entryPoints src/editing/index.ts --githubPages false"
|
|
19
|
+
},
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=22"
|
|
22
|
+
},
|
|
23
|
+
"author": {
|
|
24
|
+
"name": "Sitecore Corporation",
|
|
25
|
+
"url": "https://jss.sitecore.com"
|
|
26
|
+
},
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "https://github.com/Sitecore/jss"
|
|
30
|
+
},
|
|
31
|
+
"license": "Apache-2.0",
|
|
32
|
+
"homepage": "https://jss.sitecore.com",
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/sitecore/jss/issues"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/chai": "^5.0.1",
|
|
38
|
+
"@types/chai-spies": "^1.0.6",
|
|
39
|
+
"@types/chai-string": "^1.4.5",
|
|
40
|
+
"@types/debug": "^4.1.12",
|
|
41
|
+
"@types/memory-cache": "^0.2.6",
|
|
42
|
+
"@types/mocha": "^10.0.1",
|
|
43
|
+
"@types/node": "^22.12.0",
|
|
44
|
+
"@types/sinon": "^17.0.3",
|
|
45
|
+
"@types/url-parse": "1.4.11",
|
|
46
|
+
"chai": "^4.2.0",
|
|
47
|
+
"chai-spies": "^1.1.0",
|
|
48
|
+
"chai-string": "^1.5.0",
|
|
49
|
+
"del-cli": "^6.0.0",
|
|
50
|
+
"eslint": "^8.56.0",
|
|
51
|
+
"eslint-plugin-jsdoc": "48.7.0",
|
|
52
|
+
"mocha": "^11.1.0",
|
|
53
|
+
"nock": "14.0.0-beta.7",
|
|
54
|
+
"nyc": "^17.1.0",
|
|
55
|
+
"sinon": "^19.0.2",
|
|
56
|
+
"tslib": "^2.8.1",
|
|
57
|
+
"tsx": "^4.19.2",
|
|
58
|
+
"typescript": "~5.7.3"
|
|
59
|
+
},
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"debug": "^4.4.0",
|
|
62
|
+
"graphql": "^16.10.0",
|
|
63
|
+
"graphql-request": "^6.1.0",
|
|
64
|
+
"memory-cache": "^0.2.0",
|
|
65
|
+
"url-parse": "^1.5.10"
|
|
66
|
+
},
|
|
67
|
+
"description": "",
|
|
68
|
+
"types": "types/index.d.ts",
|
|
69
|
+
"gitHead": "11e6c0ce4b6bcaf8a5ddffa39a921c8dd145e603",
|
|
70
|
+
"files": [
|
|
71
|
+
"dist",
|
|
72
|
+
"types",
|
|
73
|
+
"/*.js",
|
|
74
|
+
"/*.d.ts"
|
|
75
|
+
]
|
|
76
|
+
}
|
package/personalize.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './types/personalize/index';
|
package/personalize.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/cjs/personalize/index');
|
package/site.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './types/site/index';
|
package/site.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/cjs/site/index');
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An interface for cache clients.
|
|
3
|
+
* @template T The type of data being cached.
|
|
4
|
+
*/
|
|
5
|
+
export interface CacheClient<T> {
|
|
6
|
+
/**
|
|
7
|
+
* Adds a value to the cache for the specified cache key.
|
|
8
|
+
* @param {string} key The cache key.
|
|
9
|
+
* @param {T} value The value to cache.
|
|
10
|
+
* @returns The value added to the cache.
|
|
11
|
+
*/
|
|
12
|
+
setCacheValue(key: string, value: T): T;
|
|
13
|
+
/**
|
|
14
|
+
* Retrieves a value from the cache.
|
|
15
|
+
* @param {string} key The cache key.
|
|
16
|
+
* @returns The cache value as {T}, or null if the specified key was not found in the cache.
|
|
17
|
+
*/
|
|
18
|
+
getCacheValue(key: string): T | null;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Minimum configuration options for classes that implement @see CacheClient
|
|
22
|
+
*/
|
|
23
|
+
export interface CacheOptions {
|
|
24
|
+
/**
|
|
25
|
+
* Enable/disable caching mechanism
|
|
26
|
+
* @default true
|
|
27
|
+
*/
|
|
28
|
+
cacheEnabled?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Cache timeout (sec)
|
|
31
|
+
* @default 60
|
|
32
|
+
*/
|
|
33
|
+
cacheTimeout?: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A cache client that uses the 'memory-cache' library (https://github.com/ptarjan/node-cache).
|
|
37
|
+
* This class is meant to be extended or used as a mixin; it's not meant to be used directly.
|
|
38
|
+
* @template T The type of data being cached.
|
|
39
|
+
* @mixin
|
|
40
|
+
*/
|
|
41
|
+
export declare class MemoryCacheClient<T> implements CacheClient<T> {
|
|
42
|
+
options: CacheOptions;
|
|
43
|
+
private cache;
|
|
44
|
+
/**
|
|
45
|
+
* Initializes a new instance of @see MemoryCacheClient using the provided @see CacheOptions
|
|
46
|
+
* @param {CacheOptions} options Configuration options
|
|
47
|
+
*/
|
|
48
|
+
constructor(options: CacheOptions);
|
|
49
|
+
/**
|
|
50
|
+
* Retrieves a value from the cache.
|
|
51
|
+
* @template T The type of data being cached.
|
|
52
|
+
* @param {string} key The cache key.
|
|
53
|
+
* @returns The cache value as {T}, or null if the specified key is not found in the cache.
|
|
54
|
+
*/
|
|
55
|
+
getCacheValue(key: string): T | null;
|
|
56
|
+
/**
|
|
57
|
+
* Adds a value to the cache for the specified cache key.
|
|
58
|
+
* @template T The type of data being cached.
|
|
59
|
+
* @param {string} key The cache key.
|
|
60
|
+
* @param {T} value The value to cache.
|
|
61
|
+
* @returns The value added to the cache.
|
|
62
|
+
*/
|
|
63
|
+
setCacheValue(key: string, value: T): T;
|
|
64
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare enum SitecoreTemplateId {
|
|
2
|
+
JssApp = "061cba1554744b918a0617903b102b82",
|
|
3
|
+
DictionaryEntry = "6d1cd89719364a3aa511289a94c2a7b1"
|
|
4
|
+
}
|
|
5
|
+
export declare const siteNameError = "The siteName cannot be empty";
|
|
6
|
+
export declare const SITECORE_EDGE_URL_DEFAULT = "https://edge-platform.sitecorecloud.io";
|
|
7
|
+
export declare const HIDDEN_RENDERING_NAME = "Hidden Rendering";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { NativeDataFetcherFunction } from './native-fetcher';
|
|
2
|
+
import { ParsedUrlQueryInput } from 'querystring';
|
|
3
|
+
/**
|
|
4
|
+
* Response data for an HTTP request sent to an API
|
|
5
|
+
* @template T the type of data model requested
|
|
6
|
+
*/
|
|
7
|
+
export interface HttpResponse<T> {
|
|
8
|
+
/** HTTP status code of the response (i.e. 200, 404) */
|
|
9
|
+
status: number;
|
|
10
|
+
/** HTTP status text of the response (i.e. 'OK', 'Bad Request') */
|
|
11
|
+
statusText: string;
|
|
12
|
+
/** Response content */
|
|
13
|
+
data: T;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Describes functions that fetch data asynchronously (i.e. from an API endpoint).
|
|
17
|
+
* This interface conforms to 'fetch' public API, but is adaptable to other HTTP libraries and
|
|
18
|
+
* fetch polyfills.
|
|
19
|
+
* The interface implementation must:
|
|
20
|
+
* - Support SSR
|
|
21
|
+
* - Comply with the rules of REST by returning appropriate response status codes when there is an error instead of throwing exceptions.
|
|
22
|
+
* - Send HTTP POST requests if `data` param is specified; GET is suggested but not required for data-less requests
|
|
23
|
+
*/
|
|
24
|
+
export type HttpDataFetcher<T> = (url: string, data?: unknown) => Promise<HttpResponse<T>>;
|
|
25
|
+
export declare class ResponseError extends Error {
|
|
26
|
+
response: HttpResponse<unknown>;
|
|
27
|
+
constructor(message: string, response: HttpResponse<unknown>);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* @param {string} url the URL to request; may include query string
|
|
31
|
+
* @param {HttpDataFetcher<T> | NativeDataFetcherFunction<T>} fetcher the fetcher to use to perform the request
|
|
32
|
+
* @param {ParsedUrlQueryInput} params the query string parameters to send with the request
|
|
33
|
+
*/
|
|
34
|
+
export declare function fetchData<T>(url: string, fetcher: HttpDataFetcher<T> | NativeDataFetcherFunction<T>, params?: ParsedUrlQueryInput): Promise<T>;
|
package/types/debug.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import debug from 'debug';
|
|
2
|
+
export type Debugger = debug.Debugger;
|
|
3
|
+
/**
|
|
4
|
+
* Enable debug logging dynamically
|
|
5
|
+
* @param {string} namespaces space-separated list of namespaces to enable
|
|
6
|
+
*/
|
|
7
|
+
export declare const enableDebug: (namespaces: string) => void;
|
|
8
|
+
/**
|
|
9
|
+
* Default Sitecore JSS 'debug' module debuggers. Uses namespace prefix 'core:'.
|
|
10
|
+
* See {@link https://www.npmjs.com/package/debug} for details.
|
|
11
|
+
*/
|
|
12
|
+
declare const _default: {
|
|
13
|
+
common: debug.Debugger;
|
|
14
|
+
http: debug.Debugger;
|
|
15
|
+
layout: debug.Debugger;
|
|
16
|
+
dictionary: debug.Debugger;
|
|
17
|
+
editing: debug.Debugger;
|
|
18
|
+
sitemap: debug.Debugger;
|
|
19
|
+
multisite: debug.Debugger;
|
|
20
|
+
robots: debug.Debugger;
|
|
21
|
+
redirects: debug.Debugger;
|
|
22
|
+
personalize: debug.Debugger;
|
|
23
|
+
errorpages: debug.Debugger;
|
|
24
|
+
proxy: debug.Debugger;
|
|
25
|
+
};
|
|
26
|
+
export default _default;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { ComponentRendering, Field, GenericFieldValue } from '../layout/models';
|
|
2
|
+
/**
|
|
3
|
+
* Event to be sent when report status to component library
|
|
4
|
+
*/
|
|
5
|
+
export declare const COMPONENT_LIBRARY_STATUS_EVENT_NAME = "component:status";
|
|
6
|
+
/**
|
|
7
|
+
* Represents an event indicating the status of a component in the library.
|
|
8
|
+
*/
|
|
9
|
+
export interface ComponentLibraryStatusEvent {
|
|
10
|
+
name: typeof COMPONENT_LIBRARY_STATUS_EVENT_NAME;
|
|
11
|
+
message: {
|
|
12
|
+
status: 'ready' | 'rendered';
|
|
13
|
+
uid: string;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Enumeration of statuses for the component library.
|
|
18
|
+
*/
|
|
19
|
+
export declare enum ComponentLibraryStatus {
|
|
20
|
+
READY = "ready",
|
|
21
|
+
RENDERED = "rendered"
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Event args for Component Library `update` event
|
|
25
|
+
*/
|
|
26
|
+
export interface ComponentUpdateEventArgs {
|
|
27
|
+
name: string;
|
|
28
|
+
details?: {
|
|
29
|
+
uid: string;
|
|
30
|
+
params?: Record<string, string>;
|
|
31
|
+
fields?: Record<string, Field<GenericFieldValue>>;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Adds the browser-side event handler for 'component:update' message used in Component Library
|
|
36
|
+
* The event should update a component on page by uid, with fields and params from event args
|
|
37
|
+
* @param {ComponentRendering} rootComponent root component displayed for Component Library page
|
|
38
|
+
* @param {Function} successCallback callback to be called after successful component update
|
|
39
|
+
*/
|
|
40
|
+
export declare const addComponentUpdateHandler: (rootComponent: ComponentRendering, successCallback?: (updatedRootComponent: ComponentRendering) => void) => (() => void) | undefined;
|
|
41
|
+
export declare const updateComponentHandler: (e: MessageEvent, rootComponent: ComponentRendering, successCallback?: (updatedRootComponent: ComponentRendering) => void) => ComponentRendering<import("../layout/models").ComponentFields> | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Generates a ComponentLibraryStatusEvent with the given status and uid.
|
|
44
|
+
* @param {ComponentLibraryStatus} status - The status of rendering.
|
|
45
|
+
* @param {string} uid - The unique identifier for the event.
|
|
46
|
+
* @returns An object representing the ComponentLibraryStatusEvent.
|
|
47
|
+
*/
|
|
48
|
+
export declare function getComponentLibraryStatusEvent(status: ComponentLibraryStatus, uid: string): ComponentLibraryStatusEvent;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { PageInfo } from '../graphql';
|
|
2
|
+
import { GraphQLClient, GraphQLRequestClientFactory } from '../graphql-request-client';
|
|
3
|
+
import { DictionaryPhrases } from '../i18n';
|
|
4
|
+
import { LayoutServiceData } from '../layout';
|
|
5
|
+
import { LayoutKind } from './models';
|
|
6
|
+
/**
|
|
7
|
+
* GraphQL query for fetching editing data.
|
|
8
|
+
*/
|
|
9
|
+
export declare const query = "\n query EditingQuery(\n $siteName: String!\n $itemId: String!\n $language: String!\n $version: String\n $after: String\n $pageSize: Int = 1000\n) {\n item(path: $itemId, language: $language, version: $version) {\n rendered\n }\n site {\n siteInfo(site: $siteName) {\n dictionary(language: $language, first: $pageSize, after: $after) {\n results {\n key\n value\n }\n pageInfo {\n endCursor\n hasNext\n }\n }\n }\n }\n }\n";
|
|
10
|
+
/**
|
|
11
|
+
* GraphQL query for fetching dictionary data.
|
|
12
|
+
* This query is used when the dictionary data is paginated.
|
|
13
|
+
*/
|
|
14
|
+
export declare const dictionaryQuery = "\n query EditingDictionaryQuery(\n $siteName: String!\n $language: String!\n $after: String\n $pageSize: Int = 1000\n ) {\n site {\n siteInfo(site: $siteName) {\n dictionary(language: $language, first: $pageSize, after: $after) {\n results {\n key\n value\n }\n pageInfo {\n endCursor\n hasNext\n }\n }\n }\n }\n }\n";
|
|
15
|
+
/**
|
|
16
|
+
* Response from the GraphQL Dictionary query.
|
|
17
|
+
*/
|
|
18
|
+
export type GraphQLDictionaryQueryResponse = {
|
|
19
|
+
site: {
|
|
20
|
+
siteInfo: {
|
|
21
|
+
dictionary: {
|
|
22
|
+
results: {
|
|
23
|
+
key: string;
|
|
24
|
+
value: string;
|
|
25
|
+
}[];
|
|
26
|
+
pageInfo: PageInfo;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Response from the GraphQL Editing query.
|
|
33
|
+
*/
|
|
34
|
+
export type GraphQLEditingQueryResponse = GraphQLDictionaryQueryResponse & {
|
|
35
|
+
item: {
|
|
36
|
+
rendered: LayoutServiceData;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
export interface GraphQLEditingServiceConfig {
|
|
40
|
+
/**
|
|
41
|
+
* A GraphQL Request Client Factory is a function that accepts configuration and returns an instance of a GraphQLRequestClient.
|
|
42
|
+
* This factory function is used to create and configure GraphQL clients for making GraphQL API requests.
|
|
43
|
+
*/
|
|
44
|
+
clientFactory: GraphQLRequestClientFactory;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Service for fetching editing data from Sitecore using the Sitecore's GraphQL API.
|
|
48
|
+
* Expected to be used in XMCloud Pages preview (editing) Metadata Edit Mode.
|
|
49
|
+
*/
|
|
50
|
+
export declare class GraphQLEditingService {
|
|
51
|
+
serviceConfig: GraphQLEditingServiceConfig;
|
|
52
|
+
private graphQLClient;
|
|
53
|
+
/**
|
|
54
|
+
* Fetch layout data using the Sitecore GraphQL endpoint.
|
|
55
|
+
* @param {GraphQLLayoutServiceConfig} serviceConfig configuration
|
|
56
|
+
*/
|
|
57
|
+
constructor(serviceConfig: GraphQLEditingServiceConfig);
|
|
58
|
+
/**
|
|
59
|
+
* Fetches editing data. Provides the layout data and dictionary phrases
|
|
60
|
+
* @param {object} variables - The parameters for fetching editing data.
|
|
61
|
+
* @param {string} variables.siteName - The site name.
|
|
62
|
+
* @param {string} variables.itemId - The item id (path) to fetch layout data for.
|
|
63
|
+
* @param {string} variables.language - The language to fetch layout data for.
|
|
64
|
+
* @param {string} [variables.version] - The version of the item (optional).
|
|
65
|
+
* @param {LayoutKind} [variables.layoutKind] - The final or shared layout variant.
|
|
66
|
+
* @returns {Promise} The layout data and dictionary phrases.
|
|
67
|
+
*/
|
|
68
|
+
fetchEditingData({ siteName, itemId, language, version, layoutKind, }: {
|
|
69
|
+
siteName: string;
|
|
70
|
+
itemId: string;
|
|
71
|
+
language: string;
|
|
72
|
+
version?: string;
|
|
73
|
+
layoutKind?: LayoutKind;
|
|
74
|
+
}): Promise<{
|
|
75
|
+
layoutData: LayoutServiceData;
|
|
76
|
+
dictionary: DictionaryPhrases;
|
|
77
|
+
}>;
|
|
78
|
+
fetchDictionaryData({ siteName, language, }: {
|
|
79
|
+
siteName: string;
|
|
80
|
+
language: string;
|
|
81
|
+
}, initDictionary?: {
|
|
82
|
+
key: string;
|
|
83
|
+
value: string;
|
|
84
|
+
}[], hasNext?: boolean, after?: string): Promise<DictionaryPhrases>;
|
|
85
|
+
/**
|
|
86
|
+
* Gets a GraphQL client that can make requests to the API.
|
|
87
|
+
* @returns {GraphQLClient} implementation
|
|
88
|
+
*/
|
|
89
|
+
protected getGraphQLClient(): GraphQLClient;
|
|
90
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { GraphQLEditingService } from './graphql-editing-service';
|
|
2
|
+
export { DEFAULT_PLACEHOLDER_UID, PagesEditor, isEditorActive, resetEditorChromes, Metadata, getJssPagesClientData, EDITING_ALLOWED_ORIGINS, QUERY_PARAM_EDITING_SECRET, PAGES_EDITING_MARKER, ComponentUpdateEventArgs, } from './utils';
|
|
3
|
+
export { RestComponentLayoutService, ComponentLayoutRequestParams, } from './rest-component-layout-service';
|
|
4
|
+
export { EditingRenderQueryParams, RenderComponentQueryParams } from './models';
|
|
5
|
+
export { LayoutKind, MetadataKind } from './models';
|
|
6
|
+
export { addComponentUpdateHandler, ComponentLibraryStatus, ComponentLibraryStatusEvent, getComponentLibraryStatusEvent, } from './component-library';
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { LayoutServicePageState } from '../layout';
|
|
2
|
+
/**
|
|
3
|
+
* Query parameters appended to the page route URL
|
|
4
|
+
* Appended when XMCloud Pages preview (editing) mode is used
|
|
5
|
+
* `mode` is a special case as it serves editing and component library both
|
|
6
|
+
*/
|
|
7
|
+
export interface EditingRenderQueryParams {
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
secret: string;
|
|
10
|
+
sc_lang: string;
|
|
11
|
+
sc_itemid: string;
|
|
12
|
+
sc_site: string;
|
|
13
|
+
route: string;
|
|
14
|
+
mode: Exclude<LayoutServicePageState, 'normal'> | 'library';
|
|
15
|
+
sc_layoutKind?: LayoutKind;
|
|
16
|
+
sc_variant?: string;
|
|
17
|
+
sc_version?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Query parameters appended for Component Library functionaity.
|
|
21
|
+
* Used when a single component is rendered in Pages.
|
|
22
|
+
*/
|
|
23
|
+
export interface RenderComponentQueryParams {
|
|
24
|
+
[key: string]: unknown;
|
|
25
|
+
secret: string;
|
|
26
|
+
sc_lang: string;
|
|
27
|
+
sc_itemid: string;
|
|
28
|
+
sc_renderingId: string;
|
|
29
|
+
sc_uid: string;
|
|
30
|
+
sc_site: string;
|
|
31
|
+
mode: 'library';
|
|
32
|
+
sc_variant?: string;
|
|
33
|
+
sc_version?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Represents the Editing Layout variant.
|
|
37
|
+
* - shared - shared layout
|
|
38
|
+
* - final - final layout
|
|
39
|
+
*/
|
|
40
|
+
export declare enum LayoutKind {
|
|
41
|
+
Final = "final",
|
|
42
|
+
Shared = "shared"
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Represents the kind of metadata element.
|
|
46
|
+
* - open - starting chrome element
|
|
47
|
+
* - close - closing chrome element
|
|
48
|
+
*/
|
|
49
|
+
export declare enum MetadataKind {
|
|
50
|
+
Open = "open",
|
|
51
|
+
Close = "close"
|
|
52
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { LayoutServiceData, EditMode } from '../layout/models';
|
|
2
|
+
import { IncomingMessage, ServerResponse } from 'http';
|
|
3
|
+
import { HttpDataFetcher } from '../data-fetcher';
|
|
4
|
+
/**
|
|
5
|
+
* Data fetcher resolver in order to provide custom data fetcher
|
|
6
|
+
* @param {IncomingMessage} [req] Request instance
|
|
7
|
+
* @param {ServerResponse} [res] Response instance
|
|
8
|
+
*/
|
|
9
|
+
export type DataFetcherResolver = <T>(req?: IncomingMessage, res?: ServerResponse) => HttpDataFetcher<T>;
|
|
10
|
+
export type RestLayoutServiceConfig = {
|
|
11
|
+
/**
|
|
12
|
+
* Your Sitecore instance hostname that is the backend for JSS
|
|
13
|
+
*/
|
|
14
|
+
apiHost: string;
|
|
15
|
+
/**
|
|
16
|
+
* The Sitecore SSC API key your app uses
|
|
17
|
+
*/
|
|
18
|
+
apiKey: string;
|
|
19
|
+
/**
|
|
20
|
+
* The JSS application name
|
|
21
|
+
*/
|
|
22
|
+
siteName: string;
|
|
23
|
+
/**
|
|
24
|
+
* Enables/disables analytics tracking for the Layout Service invocation (default is true).
|
|
25
|
+
* More than likely, this would be set to false for SSG/hybrid implementations, and the
|
|
26
|
+
* JSS tracker would instead be used on the client-side: {@link https://jss.sitecore.com/docs/fundamentals/services/tracking}
|
|
27
|
+
* @default true
|
|
28
|
+
*/
|
|
29
|
+
tracking?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Function that handles fetching API data
|
|
32
|
+
*/
|
|
33
|
+
dataFetcherResolver?: DataFetcherResolver;
|
|
34
|
+
/**
|
|
35
|
+
* Layout Service "named" configuration
|
|
36
|
+
*/
|
|
37
|
+
configurationName?: string;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Params for requesting component data from service in Component Library mode
|
|
41
|
+
*/
|
|
42
|
+
export interface ComponentLayoutRequestParams {
|
|
43
|
+
/**
|
|
44
|
+
* Item id to be used as context for rendering the component
|
|
45
|
+
*/
|
|
46
|
+
itemId: string;
|
|
47
|
+
/**
|
|
48
|
+
* Component identifier. Can be either taken from item's layout details or
|
|
49
|
+
* an arbitrary one (component renderingId and datasource would be used for identification then)
|
|
50
|
+
*/
|
|
51
|
+
componentUid: string;
|
|
52
|
+
/**
|
|
53
|
+
* language to render component in
|
|
54
|
+
*/
|
|
55
|
+
language?: string;
|
|
56
|
+
/**
|
|
57
|
+
* optional component datasource
|
|
58
|
+
*/
|
|
59
|
+
dataSourceId?: string;
|
|
60
|
+
/**
|
|
61
|
+
* ID of the component definition rendering item in Sitecore
|
|
62
|
+
*/
|
|
63
|
+
renderingId?: string;
|
|
64
|
+
/**
|
|
65
|
+
* version of the context item (latest by default)
|
|
66
|
+
*/
|
|
67
|
+
version?: string;
|
|
68
|
+
/**
|
|
69
|
+
* edit mode to be rendered component in. Component is rendered in normal mode by default
|
|
70
|
+
*/
|
|
71
|
+
editMode?: EditMode;
|
|
72
|
+
/**
|
|
73
|
+
* site name to be used as context for rendering the component
|
|
74
|
+
*/
|
|
75
|
+
siteName?: string;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* REST service that enables Component Library functioality
|
|
79
|
+
* Makes a request to /sitecore/api/layout/component in 'library' mode in Pages.
|
|
80
|
+
* Returns layoutData for one single rendered component
|
|
81
|
+
*/
|
|
82
|
+
export declare class RestComponentLayoutService {
|
|
83
|
+
private config;
|
|
84
|
+
constructor(config: RestLayoutServiceConfig);
|
|
85
|
+
fetchComponentData(params: ComponentLayoutRequestParams, req?: IncomingMessage, res?: ServerResponse): Promise<LayoutServiceData>;
|
|
86
|
+
protected getFetcher: (req?: IncomingMessage, res?: ServerResponse) => HttpDataFetcher<LayoutServiceData> | ((url: string, data?: RequestInit) => Promise<import("..").NativeDataFetcherResponse<LayoutServiceData>>);
|
|
87
|
+
/**
|
|
88
|
+
* Resolves layout service url
|
|
89
|
+
* @param {string} apiType which layout service API to call ('render' or 'placeholder')
|
|
90
|
+
* @returns the layout service url
|
|
91
|
+
*/
|
|
92
|
+
protected resolveLayoutServiceUrl(apiType: string): string;
|
|
93
|
+
/**
|
|
94
|
+
* Provides default @see NativeDataFetcher data fetcher
|
|
95
|
+
* @param {IncomingMessage} [req] Request instance
|
|
96
|
+
* @returns default fetcher
|
|
97
|
+
*/
|
|
98
|
+
protected getDefaultFetcher: <T>(req?: IncomingMessage) => (url: string, data?: RequestInit) => Promise<import("..").NativeDataFetcherResponse<T>>;
|
|
99
|
+
protected getComponentFetchParams(params: ComponentLayoutRequestParams): any;
|
|
100
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Field, GenericFieldValue } from '../layout/models';
|
|
2
|
+
/**
|
|
3
|
+
* Default value of uid for root placeholder when uid is not present.
|
|
4
|
+
*/
|
|
5
|
+
export declare const DEFAULT_PLACEHOLDER_UID = "00000000-0000-0000-0000-000000000000";
|
|
6
|
+
/**
|
|
7
|
+
* Query parameter for editing secret
|
|
8
|
+
*/
|
|
9
|
+
export declare const QUERY_PARAM_EDITING_SECRET = "secret";
|
|
10
|
+
/**
|
|
11
|
+
* ID to be used as a marker for a script rendered in XMC Pages
|
|
12
|
+
* Should identify app is in XM Cloud Pages editing mode
|
|
13
|
+
*/
|
|
14
|
+
export declare const PAGES_EDITING_MARKER = "jss-hrz-editing";
|
|
15
|
+
/**
|
|
16
|
+
* Default allowed origins for editing requests. This is used to enforce CORS, CSP headers.
|
|
17
|
+
*/
|
|
18
|
+
export declare const EDITING_ALLOWED_ORIGINS: string[];
|
|
19
|
+
/**
|
|
20
|
+
* Event args for Component Library `update` event
|
|
21
|
+
*/
|
|
22
|
+
export interface ComponentUpdateEventArgs {
|
|
23
|
+
name: string;
|
|
24
|
+
details?: {
|
|
25
|
+
uid: string;
|
|
26
|
+
params?: Record<string, string>;
|
|
27
|
+
fields?: Record<string, Field<GenericFieldValue>>;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Application metadata
|
|
32
|
+
*/
|
|
33
|
+
export interface Metadata {
|
|
34
|
+
packages: {
|
|
35
|
+
[key: string]: string;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Copy of chrome rediscovery contract from Horizon (chrome-rediscovery.contract.ts)
|
|
40
|
+
*/
|
|
41
|
+
export declare const ChromeRediscoveryGlobalFunctionName: {
|
|
42
|
+
name: string;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Static utility class for Sitecore Pages Editor
|
|
46
|
+
*/
|
|
47
|
+
export declare class PagesEditor {
|
|
48
|
+
/**
|
|
49
|
+
* Determines whether the current execution context is within a Pages Editor.
|
|
50
|
+
* Pages Editor environment can be identified only in the browser
|
|
51
|
+
* @returns true if executing within a Pages Editor
|
|
52
|
+
*/
|
|
53
|
+
static isActive(): boolean;
|
|
54
|
+
static resetChromes(): void;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Determines whether the current execution context is within a Sitecore editor.
|
|
58
|
+
* Sitecore Editor environment can be identified only in the browser
|
|
59
|
+
* @returns true if executing within a Sitecore editor
|
|
60
|
+
*/
|
|
61
|
+
export declare const isEditorActive: () => boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Resets Sitecore editor "chromes"
|
|
64
|
+
*/
|
|
65
|
+
export declare const resetEditorChromes: () => void;
|
|
66
|
+
/**
|
|
67
|
+
* Gets extra JSS clientData scripts to render in XMC Pages in addition to clientData from Pages itself
|
|
68
|
+
* @returns {Record} collection of clientData
|
|
69
|
+
*/
|
|
70
|
+
export declare const getJssPagesClientData: () => Record<string, Record<string, unknown>>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { GraphQLClient } from '../graphql-request-client';
|
|
2
|
+
/** @private */
|
|
3
|
+
export declare const siteNameError = "The site name must be a non-empty string";
|
|
4
|
+
/** @private */
|
|
5
|
+
export declare const languageError = "The language must be a non-empty string";
|
|
6
|
+
/**
|
|
7
|
+
* The schema of data returned in response to an app root query request
|
|
8
|
+
*/
|
|
9
|
+
export type AppRootQueryResult = {
|
|
10
|
+
layout: {
|
|
11
|
+
homePage: {
|
|
12
|
+
rootItem: {
|
|
13
|
+
id: string;
|
|
14
|
+
}[];
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Gets the ID of the JSS App root item for the specified site and language.
|
|
20
|
+
* @param {GraphQLClient} client that fetches data from a GraphQL endpoint.
|
|
21
|
+
* @param {string} siteName the name of the Sitecore site.
|
|
22
|
+
* @param {string} language the item language version.
|
|
23
|
+
* @param {string} [jssAppTemplateId] optional template ID of the app root item. If not
|
|
24
|
+
* specified, the ID of the "/sitecore/templates/Foundation/JavaScript Services/App"
|
|
25
|
+
* item is used.
|
|
26
|
+
* @returns the root item ID of the JSS App in Sitecore. Returns null if the app root item is not found.
|
|
27
|
+
* @throws {RangeError} if a valid site name value is not provided.
|
|
28
|
+
* @throws {RangeError} if a valid language value is not provided.
|
|
29
|
+
* @summary This function intentionally avoids throwing an error if a root item is not found,
|
|
30
|
+
* leaving that decision up to implementations.
|
|
31
|
+
*/
|
|
32
|
+
export declare function getAppRootId(client: GraphQLClient, siteName: string, language: string, jssAppTemplateId?: string): Promise<string | null>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a URL for accessing Sitecore Edge Platform Content using the provided endpoint and context ID.
|
|
3
|
+
* @param {string} sitecoreEdgeContextId - The unique context id.
|
|
4
|
+
* @param {string} [sitecoreEdgeUrl] - The base endpoint URL for the Edge Platform. Default is https://edge-platform.sitecorecloud.io
|
|
5
|
+
* @returns {string} The complete URL for accessing content through the Edge Platform.
|
|
6
|
+
*/
|
|
7
|
+
export declare const getEdgeProxyContentUrl: (sitecoreEdgeContextId: string, sitecoreEdgeUrl?: string) => string;
|
|
8
|
+
/**
|
|
9
|
+
* Generates a URL for accessing Sitecore Edge Platform Forms using the provided form ID and context ID.
|
|
10
|
+
* @param {string} sitecoreEdgeContextId - The unique context id.
|
|
11
|
+
* @param {string} formId - The unique form id.
|
|
12
|
+
* @param {string} [sitecoreEdgeUrl] - The base endpoint URL for the Edge Platform. Default is https://edge-platform.sitecorecloud.io
|
|
13
|
+
* @returns {string} The complete URL for accessing forms through the Edge Platform.
|
|
14
|
+
*/
|
|
15
|
+
export declare const getEdgeProxyFormsUrl: (sitecoreEdgeContextId: string, formId: string, sitecoreEdgeUrl?: string) => string;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { getAppRootId, AppRootQueryResult } from './app-root-query';
|
|
2
|
+
export { RetryStrategy, DefaultRetryStrategy, GraphQLClientError, GraphQLClient, GraphQLRequestClient, GraphQLRequestClientConfig, GraphQLRequestClientFactory, GraphQLRequestClientFactoryConfig, } from '../graphql-request-client';
|
|
3
|
+
export { SearchQueryResult, SearchQueryVariables, SearchServiceConfig, SearchQueryService, PageInfo, } from './search-service';
|
|
4
|
+
export { getEdgeProxyContentUrl, getEdgeProxyFormsUrl } from './graphql-edge-proxy';
|