@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.
Files changed (143) hide show
  1. package/LICENSE.txt +202 -0
  2. package/README.md +7 -0
  3. package/dist/cjs/cache-client.js +54 -0
  4. package/dist/cjs/constants.js +12 -0
  5. package/dist/cjs/debug.js +43 -0
  6. package/dist/cjs/graphql/app-root-query.js +73 -0
  7. package/dist/cjs/graphql/graphql-edge-proxy.js +12 -0
  8. package/dist/cjs/graphql/index.js +11 -0
  9. package/dist/cjs/graphql/search-service.js +60 -0
  10. package/dist/cjs/graphql-request-client.js +106 -0
  11. package/dist/cjs/i18n/dictionary-service.js +45 -0
  12. package/dist/cjs/i18n/graphql-dictionary-service.js +125 -0
  13. package/dist/cjs/i18n/index.js +7 -0
  14. package/dist/cjs/index.js +36 -0
  15. package/dist/cjs/layout/content-styles.js +73 -0
  16. package/dist/cjs/layout/graphql-layout-service.js +84 -0
  17. package/dist/cjs/layout/index.js +18 -0
  18. package/dist/cjs/layout/layout-service.js +9 -0
  19. package/dist/cjs/layout/models.js +27 -0
  20. package/dist/cjs/layout/themes.js +79 -0
  21. package/dist/cjs/layout/utils.js +44 -0
  22. package/dist/cjs/media/index.js +24 -0
  23. package/dist/cjs/media/media-api.js +128 -0
  24. package/dist/cjs/models.js +2 -0
  25. package/dist/cjs/native-fetcher.js +183 -0
  26. package/dist/cjs/personalize/graphql-personalize-service.js +114 -0
  27. package/dist/cjs/personalize/index.js +12 -0
  28. package/dist/cjs/personalize/layout-personalizer.js +75 -0
  29. package/dist/cjs/personalize/utils.js +92 -0
  30. package/dist/cjs/site/graphql-error-pages-service.js +86 -0
  31. package/dist/cjs/site/graphql-redirects-service.js +103 -0
  32. package/dist/cjs/site/graphql-robots-service.js +81 -0
  33. package/dist/cjs/site/graphql-siteinfo-service.js +128 -0
  34. package/dist/cjs/site/graphql-sitemap-service.js +91 -0
  35. package/dist/cjs/site/index.js +22 -0
  36. package/dist/cjs/site/site-resolver.js +79 -0
  37. package/dist/cjs/site/utils.js +43 -0
  38. package/dist/cjs/utils/edit-frame.js +138 -0
  39. package/dist/cjs/utils/editing.js +122 -0
  40. package/dist/cjs/utils/env.js +26 -0
  41. package/dist/cjs/utils/index.js +25 -0
  42. package/dist/cjs/utils/is-server.js +10 -0
  43. package/dist/cjs/utils/timeout-promise.js +31 -0
  44. package/dist/cjs/utils/utils.js +70 -0
  45. package/dist/esm/cache-client.js +50 -0
  46. package/dist/esm/constants.js +9 -0
  47. package/dist/esm/debug.js +36 -0
  48. package/dist/esm/graphql/app-root-query.js +69 -0
  49. package/dist/esm/graphql/graphql-edge-proxy.js +8 -0
  50. package/dist/esm/graphql/index.js +4 -0
  51. package/dist/esm/graphql/search-service.js +56 -0
  52. package/dist/esm/graphql-request-client.js +99 -0
  53. package/dist/esm/i18n/dictionary-service.js +41 -0
  54. package/dist/esm/i18n/graphql-dictionary-service.js +118 -0
  55. package/dist/esm/i18n/index.js +2 -0
  56. package/dist/esm/index.js +7 -0
  57. package/dist/esm/layout/content-styles.js +65 -0
  58. package/dist/esm/layout/graphql-layout-service.js +77 -0
  59. package/dist/esm/layout/index.js +6 -0
  60. package/dist/esm/layout/layout-service.js +5 -0
  61. package/dist/esm/layout/models.js +24 -0
  62. package/dist/esm/layout/themes.js +74 -0
  63. package/dist/esm/layout/utils.js +39 -0
  64. package/dist/esm/media/index.js +2 -0
  65. package/dist/esm/media/media-api.js +117 -0
  66. package/dist/esm/models.js +1 -0
  67. package/dist/esm/native-fetcher.js +176 -0
  68. package/dist/esm/personalize/graphql-personalize-service.js +107 -0
  69. package/dist/esm/personalize/index.js +3 -0
  70. package/dist/esm/personalize/layout-personalizer.js +69 -0
  71. package/dist/esm/personalize/utils.js +85 -0
  72. package/dist/esm/site/graphql-error-pages-service.js +79 -0
  73. package/dist/esm/site/graphql-redirects-service.js +96 -0
  74. package/dist/esm/site/graphql-robots-service.js +74 -0
  75. package/dist/esm/site/graphql-siteinfo-service.js +121 -0
  76. package/dist/esm/site/graphql-sitemap-service.js +84 -0
  77. package/dist/esm/site/index.js +7 -0
  78. package/dist/esm/site/site-resolver.js +75 -0
  79. package/dist/esm/site/utils.js +37 -0
  80. package/dist/esm/utils/edit-frame.js +133 -0
  81. package/dist/esm/utils/editing.js +111 -0
  82. package/dist/esm/utils/env.js +22 -0
  83. package/dist/esm/utils/index.js +5 -0
  84. package/dist/esm/utils/is-server.js +8 -0
  85. package/dist/esm/utils/timeout-promise.js +28 -0
  86. package/dist/esm/utils/utils.js +61 -0
  87. package/graphql.d.ts +1 -0
  88. package/graphql.js +1 -0
  89. package/i18n.d.ts +1 -0
  90. package/i18n.js +1 -0
  91. package/layout.d.ts +1 -0
  92. package/layout.js +1 -0
  93. package/media.d.ts +1 -0
  94. package/media.js +1 -0
  95. package/package.json +71 -0
  96. package/personalize.d.ts +1 -0
  97. package/personalize.js +1 -0
  98. package/site.d.ts +1 -0
  99. package/site.js +1 -0
  100. package/types/cache-client.d.ts +64 -0
  101. package/types/constants.d.ts +6 -0
  102. package/types/debug.d.ts +26 -0
  103. package/types/graphql/app-root-query.d.ts +32 -0
  104. package/types/graphql/graphql-edge-proxy.d.ts +7 -0
  105. package/types/graphql/index.d.ts +4 -0
  106. package/types/graphql/search-service.d.ts +92 -0
  107. package/types/graphql-request-client.d.ts +88 -0
  108. package/types/i18n/dictionary-service.d.ts +56 -0
  109. package/types/i18n/graphql-dictionary-service.d.ts +65 -0
  110. package/types/i18n/index.d.ts +2 -0
  111. package/types/index.d.ts +6 -0
  112. package/types/layout/content-styles.d.ts +18 -0
  113. package/types/layout/graphql-layout-service.d.ts +59 -0
  114. package/types/layout/index.d.ts +6 -0
  115. package/types/layout/layout-service.d.ts +20 -0
  116. package/types/layout/models.d.ts +140 -0
  117. package/types/layout/themes.d.ts +11 -0
  118. package/types/layout/utils.d.ts +17 -0
  119. package/types/media/index.d.ts +2 -0
  120. package/types/media/media-api.d.ts +69 -0
  121. package/types/models.d.ts +6 -0
  122. package/types/native-fetcher.d.ts +92 -0
  123. package/types/personalize/graphql-personalize-service.d.ts +77 -0
  124. package/types/personalize/index.d.ts +3 -0
  125. package/types/personalize/layout-personalizer.d.ts +25 -0
  126. package/types/personalize/utils.d.ts +53 -0
  127. package/types/site/graphql-error-pages-service.d.ts +55 -0
  128. package/types/site/graphql-redirects-service.d.ts +66 -0
  129. package/types/site/graphql-robots-service.d.ts +47 -0
  130. package/types/site/graphql-siteinfo-service.d.ts +69 -0
  131. package/types/site/graphql-sitemap-service.d.ts +53 -0
  132. package/types/site/index.d.ts +7 -0
  133. package/types/site/site-resolver.d.ts +27 -0
  134. package/types/site/utils.d.ts +24 -0
  135. package/types/utils/edit-frame.d.ts +76 -0
  136. package/types/utils/editing.d.ts +58 -0
  137. package/types/utils/env.d.ts +7 -0
  138. package/types/utils/index.d.ts +5 -0
  139. package/types/utils/is-server.d.ts +6 -0
  140. package/types/utils/timeout-promise.d.ts +18 -0
  141. package/types/utils/utils.d.ts +18 -0
  142. package/utils.d.ts +1 -0
  143. package/utils.js +1 -0
@@ -0,0 +1,28 @@
1
+ /**
2
+ * A helper to assign timeouts to fetch or other promises
3
+ * Useful in nextjs middleware until fetch.signal is fully supported by Vercel edge functions
4
+ */
5
+ export default class TimeoutPromise {
6
+ constructor(timeout) {
7
+ this.timeout = timeout;
8
+ this.timeoutId = undefined;
9
+ }
10
+ /**
11
+ * Creates a timeout promise
12
+ */
13
+ get start() {
14
+ return new Promise((_, reject) => {
15
+ this.timeoutId = setTimeout(() => {
16
+ const abortError = new Error(`Request timed out, timeout of ${this.timeout}ms is exceeded`);
17
+ abortError.name = 'AbortError';
18
+ reject(abortError);
19
+ }, this.timeout);
20
+ });
21
+ }
22
+ /**
23
+ * Clears the timeout from timeout promise
24
+ */
25
+ clear() {
26
+ this.timeoutId && clearTimeout(this.timeoutId);
27
+ }
28
+ }
@@ -0,0 +1,61 @@
1
+ import isServer from './is-server';
2
+ /**
3
+ * note: encodeURIComponent is available via browser (window) or natively in node.js
4
+ * if you use another js engine for server-side rendering you may not have native encodeURIComponent
5
+ * and would then need to install a package for that functionality
6
+ * @param {ParsedUrlQueryInput} params query string parameters
7
+ * @returns {string} query string
8
+ */
9
+ function getQueryString(params) {
10
+ return Object.keys(params)
11
+ .map((k) => `${encodeURIComponent(k)}=${encodeURIComponent(String(params[k]))}`)
12
+ .join('&');
13
+ }
14
+ /**
15
+ * Resolves a base URL that may contain query string parameters and an additional set of query
16
+ * string parameters into a unified string representation.
17
+ * @param {string} urlBase the base URL that may contain query string parameters
18
+ * @param {ParsedUrlQueryInput} params query string parameters
19
+ * @returns a URL string
20
+ * @throws {RangeError} if the provided url is an empty string
21
+ */
22
+ export function resolveUrl(urlBase, params = {}) {
23
+ if (!urlBase) {
24
+ throw new RangeError('url must be a non-empty string');
25
+ }
26
+ // This is a better way to work with URLs since it handles different user input
27
+ // edge cases. This works in Node and all browser except IE11.
28
+ // https://developer.mozilla.org/en-US/docs/Web/API/URL
29
+ // TODO: Verify our browser support requirements.
30
+ if (isServer()) {
31
+ const url = new URL(urlBase);
32
+ for (const key in params) {
33
+ if ({}.hasOwnProperty.call(params, key)) {
34
+ url.searchParams.append(key, String(params[key]));
35
+ }
36
+ }
37
+ const result = url.toString();
38
+ return result;
39
+ }
40
+ const qs = getQueryString(params);
41
+ const result = urlBase.indexOf('?') !== -1 ? `${urlBase}&${qs}` : `${urlBase}?${qs}`;
42
+ return result;
43
+ }
44
+ export const isAbsoluteUrl = (url) => {
45
+ if (!url) {
46
+ return false;
47
+ }
48
+ if (typeof url !== 'string') {
49
+ throw new TypeError('Expected a string');
50
+ }
51
+ return /^[a-z][a-z0-9+.-]*:/.test(url);
52
+ };
53
+ /**
54
+ * Indicates whether the error is a timeout error
55
+ * @param {unknown} error error
56
+ * @returns {boolean} is timeout error
57
+ */
58
+ export const isTimeoutError = (error) => {
59
+ var _a;
60
+ return ((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 408 || error.name === 'AbortError';
61
+ };
package/graphql.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './types/graphql/index';
package/graphql.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/cjs/graphql/index');
package/i18n.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './types/i18n/index';
package/i18n.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/cjs/i18n/index');
package/layout.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './types/layout/index';
package/layout.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/cjs/layout/index');
package/media.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './types/media/index';
package/media.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/cjs/media/index');
package/package.json ADDED
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "@sitecore-jss/sitecore-jss",
3
+ "version": "0.1.0-beta.2",
4
+ "main": "dist/cjs/index.js",
5
+ "module": "dist/esm/index.js",
6
+ "sideEffects": false,
7
+ "scripts": {
8
+ "build": "npm run clean && tsc -p tsconfig.json && tsc -p tsconfig-esm.json",
9
+ "clean": "del-cli dist types",
10
+ "lint": "eslint \"./src/**/*.ts\"",
11
+ "test": "mocha --require ts-node/register \"./src/**/*.test.ts\"",
12
+ "prepublishOnly": "npm run build",
13
+ "coverage": "nyc npm test",
14
+ "generate-docs": "npx typedoc --plugin typedoc-plugin-markdown --readme none --out ../../ref-docs/sitecore-jss --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/utils/index.ts --githubPages false"
15
+ },
16
+ "engines": {
17
+ "node": ">=18"
18
+ },
19
+ "author": {
20
+ "name": "Sitecore Corporation",
21
+ "url": "https://jss.sitecore.com"
22
+ },
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "https://github.com/Sitecore/jss"
26
+ },
27
+ "license": "Apache-2.0",
28
+ "homepage": "https://jss.sitecore.com",
29
+ "bugs": {
30
+ "url": "https://github.com/sitecore/jss/issues"
31
+ },
32
+ "devDependencies": {
33
+ "@types/chai": "^4.2.3",
34
+ "@types/chai-spies": "^1.0.3",
35
+ "@types/chai-string": "^1.4.2",
36
+ "@types/debug": "^4.1.5",
37
+ "@types/lodash.unescape": "^4.0.6",
38
+ "@types/memory-cache": "^0.2.1",
39
+ "@types/mocha": "^9.0.0",
40
+ "@types/node": "^16.11.6",
41
+ "@types/url-parse": "1.4.8",
42
+ "chai": "^4.2.0",
43
+ "chai-spies": "^1.0.0",
44
+ "chai-string": "^1.5.0",
45
+ "del-cli": "^5.0.0",
46
+ "eslint": "^7.15.0",
47
+ "mocha": "^10.2.0",
48
+ "nock": "^13.0.5",
49
+ "nyc": "^15.1.0",
50
+ "ts-node": "^8.4.1",
51
+ "tslib": "^1.10.0",
52
+ "typescript": "~4.3.5"
53
+ },
54
+ "dependencies": {
55
+ "debug": "^4.3.1",
56
+ "graphql": "^16.5.0",
57
+ "graphql-request": "^4.2.0",
58
+ "lodash.unescape": "^4.0.1",
59
+ "memory-cache": "^0.2.0",
60
+ "url-parse": "^1.5.9"
61
+ },
62
+ "description": "",
63
+ "types": "types/index.d.ts",
64
+ "gitHead": "db3098b97fd0fe5616636da848ab9aefb664a3f3",
65
+ "files": [
66
+ "dist",
67
+ "types",
68
+ "/*.js",
69
+ "/*.d.ts"
70
+ ]
71
+ }
@@ -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,6 @@
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";
@@ -0,0 +1,26 @@
1
+ import debug from 'debug';
2
+ export declare 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
+ declare const _default: {
9
+ common: debug.Debugger;
10
+ http: debug.Debugger;
11
+ layout: debug.Debugger;
12
+ dictionary: debug.Debugger;
13
+ editing: debug.Debugger;
14
+ sitemap: debug.Debugger;
15
+ multisite: debug.Debugger;
16
+ robots: debug.Debugger;
17
+ redirects: debug.Debugger;
18
+ personalize: debug.Debugger;
19
+ errorpages: debug.Debugger;
20
+ revalidate: debug.Debugger;
21
+ };
22
+ /**
23
+ * Default Sitecore JSS 'debug' module debuggers. Uses namespace prefix 'sitecore-jss:'.
24
+ * See {@link https://www.npmjs.com/package/debug} for details.
25
+ */
26
+ export default _default;
@@ -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 declare 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,7 @@
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;
@@ -0,0 +1,4 @@
1
+ export { getAppRootId, AppRootQueryResult } from './app-root-query';
2
+ export { GraphQLClient, GraphQLRequestClient, GraphQLRequestClientConfig, GraphQLRequestClientFactory, GraphQLRequestClientFactoryConfig, } from './../graphql-request-client';
3
+ export { SearchQueryResult, SearchQueryVariables, SearchServiceConfig, SearchQueryService, PageInfo, } from './search-service';
4
+ export { getEdgeProxyContentUrl } from './graphql-edge-proxy';
@@ -0,0 +1,92 @@
1
+ import { DocumentNode } from 'graphql';
2
+ import { GraphQLClient } from '../graphql-request-client';
3
+ /**
4
+ * Data needed to paginate results
5
+ */
6
+ export interface PageInfo {
7
+ /**
8
+ * string token that can be used to fetch the next page of results
9
+ */
10
+ endCursor: string;
11
+ /**
12
+ * a value that indicates whether more pages of results are available
13
+ */
14
+ hasNext: boolean;
15
+ }
16
+ /**
17
+ * Schema of data returned in response to a "search" query request
18
+ * @template T The type of objects being requested.
19
+ */
20
+ export declare type SearchQueryResult<T> = {
21
+ search: {
22
+ /**
23
+ * Data needed to paginate the search results
24
+ */
25
+ pageInfo: PageInfo;
26
+ results: T[];
27
+ };
28
+ };
29
+ /**
30
+ * Describes the variables used by the 'search' query. Language should always be specified.
31
+ * The other predicates are optional.
32
+ */
33
+ export interface SearchQueryVariables {
34
+ /**
35
+ * Required. The language versions to search for. Fetch pages that have versions in this language.
36
+ */
37
+ language: string;
38
+ /**
39
+ * Optional. The ID of the search root item. Fetch items that have this item as an ancestor.
40
+ */
41
+ rootItemId?: string;
42
+ /**
43
+ * Optional. Sitecore template ID(s). Fetch items that inherit from this template(s).
44
+ */
45
+ templates?: string;
46
+ /** common variable for all GraphQL queries
47
+ * it will be used for every type of query to regulate result batch size
48
+ * Optional. How many result items to fetch in each GraphQL call. This is needed for pagination.
49
+ * @default 10
50
+ */
51
+ pageSize?: number;
52
+ }
53
+ /**
54
+ * Configuration options for service classes that extend @see SearchQueryService.
55
+ * This extends @see SearchQueryVariables because properties that can be passed to the search query
56
+ * as predicates should be configurable. 'language' is excluded because, normally, all properties
57
+ * except 'language' are consistent across languages so they are passed to constructors, and
58
+ * 'language' can vary so it is passed to methods.
59
+ */
60
+ export interface SearchServiceConfig extends Omit<SearchQueryVariables, 'language'> {
61
+ /**
62
+ * The name of the current Sitecore site. This is used to to determine the search query root
63
+ * in cases where one is not specified by the caller.
64
+ */
65
+ siteName: string;
66
+ }
67
+ /**
68
+ * Provides functionality for performing GraphQL 'search' operations, including handling pagination.
69
+ * This class is meant to be extended or used as a mixin; it's not meant to be used directly.
70
+ * @template T The type of objects being requested.
71
+ * @mixin
72
+ */
73
+ export declare class SearchQueryService<T> {
74
+ protected client: GraphQLClient;
75
+ /**
76
+ * Creates an instance of search query service.
77
+ * @param {GraphQLClient} client that fetches data from a GraphQL endpoint.
78
+ */
79
+ constructor(client: GraphQLClient);
80
+ /**
81
+ * 1. Validates mandatory search query arguments
82
+ * 2. Executes search query with pagination
83
+ * 3. Aggregates pagination results into a single result-set.
84
+ * @template T The type of objects being requested.
85
+ * @param {string | DocumentNode} query the search query.
86
+ * @param {SearchQueryVariables} args search query arguments.
87
+ * @returns {T[]} array of result objects.
88
+ * @throws {RangeError} if a valid root item ID is not provided.
89
+ * @throws {RangeError} if the provided language(s) is(are) not valid.
90
+ */
91
+ fetch(query: string | DocumentNode, args: SearchQueryVariables): Promise<T[]>;
92
+ }
@@ -0,0 +1,88 @@
1
+ import { DocumentNode } from 'graphql';
2
+ import { Debugger } from './debug';
3
+ /**
4
+ * An interface for GraphQL clients for Sitecore APIs
5
+ */
6
+ export interface GraphQLClient {
7
+ /**
8
+ * Execute graphql request
9
+ * @param {string | DocumentNode} query graphql query
10
+ * @param {Object} variables graphql variables
11
+ */
12
+ request<T>(query: string | DocumentNode, variables?: {
13
+ [key: string]: unknown;
14
+ }): Promise<T>;
15
+ }
16
+ /**
17
+ * Minimum configuration options for classes that implement @see GraphQLClient
18
+ */
19
+ export declare type GraphQLRequestClientConfig = {
20
+ /**
21
+ * The API key to use for authentication. This will be added as an 'sc_apikey' header.
22
+ */
23
+ apiKey?: string;
24
+ /**
25
+ * Override debugger for logging. Uses 'sitecore-jss:http' by default.
26
+ */
27
+ debugger?: Debugger;
28
+ /**
29
+ * Override fetch method. Uses 'graphql-request' library default otherwise ('cross-fetch').
30
+ */
31
+ fetch?: typeof fetch;
32
+ /**
33
+ * GraphQLClient request timeout
34
+ */
35
+ timeout?: number;
36
+ /**
37
+ * Number of retries for client. Will be used if endpoint responds with 429 (rate limit reached) error
38
+ */
39
+ retries?: number;
40
+ };
41
+ /**
42
+ * A GraphQL Client Factory is a function that accepts configuration and returns an instance of a GraphQLRequestClient.
43
+ * This factory function is used to create and configure GraphQL clients for making GraphQL API requests.
44
+ * @param config - The configuration object that specifies how the GraphQL client should be set up.
45
+ * @returns An instance of a GraphQL Request Client ready to send GraphQL requests.
46
+ */
47
+ export declare type GraphQLRequestClientFactory = (config: Omit<GraphQLRequestClientConfig, 'apiKey'>) => GraphQLRequestClient;
48
+ /**
49
+ * Configuration type for @type GraphQLRequestClientFactory
50
+ */
51
+ export declare type GraphQLRequestClientFactoryConfig = {
52
+ endpoint: string;
53
+ apiKey?: string;
54
+ };
55
+ /**
56
+ * A GraphQL client for Sitecore APIs that uses the 'graphql-request' library.
57
+ * https://github.com/prisma-labs/graphql-request
58
+ */
59
+ export declare class GraphQLRequestClient implements GraphQLClient {
60
+ private endpoint;
61
+ private client;
62
+ private headers;
63
+ private debug;
64
+ private retries;
65
+ private abortTimeout?;
66
+ private timeout?;
67
+ /**
68
+ * Provides ability to execute graphql query using given `endpoint`
69
+ * @param {string} endpoint The Graphql endpoint
70
+ * @param {GraphQLRequestClientConfig} [clientConfig] GraphQL request client configuration.
71
+ */
72
+ constructor(endpoint: string, clientConfig?: GraphQLRequestClientConfig);
73
+ /**
74
+ * Factory method for creating a GraphQLRequestClientFactory.
75
+ * @param {Object} config - client configuration options.
76
+ * @param {string} config.endpoint - endpoint
77
+ * @param {string} [config.apiKey] - apikey
78
+ */
79
+ static createClientFactory({ endpoint, apiKey, }: GraphQLRequestClientFactoryConfig): GraphQLRequestClientFactory;
80
+ /**
81
+ * Execute graphql request
82
+ * @param {string | DocumentNode} query graphql query
83
+ * @param {Object} variables graphql variables
84
+ */
85
+ request<T>(query: string | DocumentNode, variables?: {
86
+ [key: string]: unknown;
87
+ }): Promise<T>;
88
+ }
@@ -0,0 +1,56 @@
1
+ import { CacheClient, CacheOptions } from '../cache-client';
2
+ /**
3
+ * Object model for Sitecore dictionary phrases
4
+ */
5
+ export interface DictionaryPhrases {
6
+ [k: string]: string;
7
+ }
8
+ /**
9
+ * Service that fetches dictionary data using Sitecore's GraphQL API.
10
+ */
11
+ export interface DictionaryService {
12
+ /**
13
+ * Fetch dictionary data for a language.
14
+ * @param {string} language the language to be used to fetch the dictionary
15
+ */
16
+ fetchDictionaryData(language: string): Promise<DictionaryPhrases>;
17
+ }
18
+ /**
19
+ * Base implementation of @see DictionaryService that handles caching dictionary values
20
+ */
21
+ export declare abstract class DictionaryServiceBase implements DictionaryService, CacheClient<DictionaryPhrases> {
22
+ options: CacheOptions;
23
+ private cache;
24
+ /**
25
+ * Initializes a new instance of @see DictionaryService using the provided @see CacheOptions
26
+ * @param {CacheOptions} options Configuration options
27
+ */
28
+ constructor(options: CacheOptions);
29
+ /**
30
+ * Caches a @see DictionaryPhrases value for the specified cache key.
31
+ * @param {string} key The cache key.
32
+ * @param {DictionaryPhrases} value The value to cache.
33
+ * @returns The value added to the cache.
34
+ * @mixes CacheClient<DictionaryPhrases>
35
+ */
36
+ setCacheValue(key: string, value: DictionaryPhrases): DictionaryPhrases;
37
+ /**
38
+ * Retrieves a @see DictionaryPhrases value from the cache.
39
+ * @param {string} key The cache key.
40
+ * @returns The @see DictionaryPhrases value, or null if the specified key is not found in the cache.
41
+ */
42
+ getCacheValue(key: string): DictionaryPhrases | null;
43
+ /**
44
+ * Gets a cache client that can cache data. Uses memory-cache as the default
45
+ * library for caching (@see MemoryCacheClient). Override this method if you
46
+ * want to use something else.
47
+ * @returns {CacheClient} implementation
48
+ */
49
+ protected getCacheClient(): CacheClient<DictionaryPhrases>;
50
+ /**
51
+ * Fetch dictionary data for a language.
52
+ * @param {string} language the language to be used to fetch the dictionary
53
+ * @returns {Promise<DictionaryPhrases>}
54
+ */
55
+ abstract fetchDictionaryData(language: string): Promise<DictionaryPhrases>;
56
+ }
@@ -0,0 +1,65 @@
1
+ import { GraphQLClient, GraphQLRequestClientConfig, GraphQLRequestClientFactory } from '../graphql-request-client';
2
+ import { DictionaryPhrases, DictionaryServiceBase } from './dictionary-service';
3
+ import { CacheOptions } from '../cache-client';
4
+ import { SearchServiceConfig } from '../graphql';
5
+ /** @private */
6
+ export declare const queryError = "Valid value for rootItemId not provided and failed to auto-resolve app root item.";
7
+ /**
8
+ * Configuration options for @see GraphQLDictionaryService instances
9
+ */
10
+ export interface GraphQLDictionaryServiceConfig extends SearchServiceConfig, CacheOptions, Pick<GraphQLRequestClientConfig, 'retries'> {
11
+ /**
12
+ * A GraphQL Request Client Factory is a function that accepts configuration and returns an instance of a GraphQLRequestClient.
13
+ * This factory function is used to create and configure GraphQL clients for making GraphQL API requests.
14
+ */
15
+ clientFactory: GraphQLRequestClientFactory;
16
+ /**
17
+ * Optional. The template ID to use when searching for dictionary entries.
18
+ * @default '6d1cd89719364a3aa511289a94c2a7b1' (/sitecore/templates/System/Dictionary/Dictionary entry)
19
+ */
20
+ dictionaryEntryTemplateId?: string;
21
+ /**
22
+ * Optional. The template ID of a JSS App to use when searching for the appRootId.
23
+ * @default '061cba1554744b918a0617903b102b82' (/sitecore/templates/Foundation/JavaScript Services/App)
24
+ */
25
+ jssAppTemplateId?: string;
26
+ }
27
+ /**
28
+ * The schema of data returned in response to a dictionary query request.
29
+ */
30
+ export declare type DictionaryQueryResult = {
31
+ key: {
32
+ value: string;
33
+ };
34
+ phrase: {
35
+ value: string;
36
+ };
37
+ };
38
+ /**
39
+ * Service that fetch dictionary data using Sitecore's GraphQL API.
40
+ * @augments DictionaryServiceBase
41
+ * @mixes SearchQueryService<DictionaryQueryResult>
42
+ */
43
+ export declare class GraphQLDictionaryService extends DictionaryServiceBase {
44
+ options: GraphQLDictionaryServiceConfig;
45
+ private graphQLClient;
46
+ private searchService;
47
+ /**
48
+ * Creates an instance of graphQL dictionary service with the provided options
49
+ * @param {GraphQLDictionaryService} options instance
50
+ */
51
+ constructor(options: GraphQLDictionaryServiceConfig);
52
+ /**
53
+ * Fetches dictionary data for internalization.
54
+ * @param {string} language the language to fetch
55
+ * @default query (@see query)
56
+ * @returns {Promise<DictionaryPhrases>} dictionary phrases
57
+ * @throws {Error} if the app root was not found for the specified site and language.
58
+ */
59
+ fetchDictionaryData(language: string): Promise<DictionaryPhrases>;
60
+ /**
61
+ * Gets a GraphQL client that can make requests to the API.
62
+ * @returns {GraphQLClient} implementation
63
+ */
64
+ protected getGraphQLClient(): GraphQLClient;
65
+ }
@@ -0,0 +1,2 @@
1
+ export { DictionaryPhrases, DictionaryService, DictionaryServiceBase } from './dictionary-service';
2
+ export { GraphQLDictionaryServiceConfig, GraphQLDictionaryService, } from './graphql-dictionary-service';
@@ -0,0 +1,6 @@
1
+ import * as constants from './constants';
2
+ export { default as debug, Debugger, enableDebug } from './debug';
3
+ export { GraphQLClient, GraphQLRequestClient, GraphQLRequestClientConfig, GraphQLRequestClientFactory, GraphQLRequestClientFactoryConfig, } from './graphql-request-client';
4
+ export { NativeDataFetcher, NativeDataFetcherConfig, NativeDataFetcherResponse, } from './native-fetcher';
5
+ export { HTMLLink } from './models';
6
+ export { constants };