@sitecore-content-sdk/core 2.0.0-canary.10 → 2.0.0-canary.13

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 (35) hide show
  1. package/dist/cjs/constants.js +36 -1
  2. package/dist/cjs/debug.js +11 -0
  3. package/dist/cjs/index.js +6 -1
  4. package/dist/cjs/initialization/helpers.js +65 -0
  5. package/dist/cjs/initialization/index.js +6 -0
  6. package/dist/cjs/initialization/init-content-sdk.js +46 -0
  7. package/dist/cjs/initialization/types.js +2 -0
  8. package/dist/cjs/tools/auth/flow.js +1 -1
  9. package/dist/cjs/tools/timeout-promise.js +4 -1
  10. package/dist/esm/constants.js +35 -0
  11. package/dist/esm/debug.js +10 -0
  12. package/dist/esm/index.js +2 -1
  13. package/dist/esm/initialization/helpers.js +57 -0
  14. package/dist/esm/initialization/index.js +1 -0
  15. package/dist/esm/initialization/init-content-sdk.js +39 -0
  16. package/dist/esm/initialization/types.js +1 -0
  17. package/dist/esm/tools/auth/flow.js +2 -2
  18. package/dist/esm/tools/timeout-promise.js +4 -1
  19. package/package.json +4 -2
  20. package/types/constants.d.ts +34 -0
  21. package/types/constants.d.ts.map +1 -1
  22. package/types/debug.d.ts +8 -0
  23. package/types/debug.d.ts.map +1 -1
  24. package/types/index.d.ts +2 -1
  25. package/types/index.d.ts.map +1 -1
  26. package/types/initialization/helpers.d.ts +23 -0
  27. package/types/initialization/helpers.d.ts.map +1 -0
  28. package/types/initialization/index.d.ts +3 -0
  29. package/types/initialization/index.d.ts.map +1 -0
  30. package/types/initialization/init-content-sdk.d.ts +15 -0
  31. package/types/initialization/init-content-sdk.d.ts.map +1 -0
  32. package/types/initialization/types.d.ts +89 -0
  33. package/types/initialization/types.d.ts.map +1 -0
  34. package/types/tools/auth/flow.d.ts.map +1 -1
  35. package/types/tools/timeout-promise.d.ts.map +1 -1
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
+ /* eslint-disable jsdoc/require-param */
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DEFAULT_SITECORE_AUTH_BASE_URL = exports.DEFAULT_SITECORE_AUTH_AUDIENCE = exports.DEFAULT_SITECORE_AUTH_DOMAIN = exports.CLAIMS = exports.SITECORE_EXPERIENCE_EDGE_URL_DEFAULT = exports.SITECORE_EDGE_PLATFORM_URL_DEFAULT = void 0;
4
+ exports.ERROR_MESSAGES = exports.DEFAULT_SITECORE_AUTH_BASE_URL = exports.DEFAULT_SITECORE_AUTH_AUDIENCE = exports.DEFAULT_SITECORE_AUTH_DOMAIN = exports.CLAIMS = exports.SITECORE_EXPERIENCE_EDGE_URL_DEFAULT = exports.SITECORE_EDGE_PLATFORM_URL_DEFAULT = void 0;
4
5
  /**
5
6
  * Default Edge Platform URL (edge-platform.sitecorecloud.io). Used for service endpoints
6
7
  * (GraphQL, content API, forms, layout, static files) when no custom hostname is configured.
@@ -33,3 +34,37 @@ exports.DEFAULT_SITECORE_AUTH_AUDIENCE = 'https://api.sitecorecloud.io';
33
34
  * @internal
34
35
  */
35
36
  exports.DEFAULT_SITECORE_AUTH_BASE_URL = 'https://edge-platform.sitecorecloud.io/cs/api';
37
+ /**
38
+ * The error messages. Includes errors for all packages.
39
+ * @internal
40
+ */
41
+ exports.ERROR_MESSAGES = {
42
+ /** IV errors are related to incorrect values, wrongly formatted objects, etc. */
43
+ IV_001: '[IV-001] Incorrect value for "edgeUrl". Set the value to a valid URL.',
44
+ IV_002: '[IV-002] Incorrect value for "timeout". Set the value to an integer greater than or equal to 0.',
45
+ IV_003: '[IV-003] Incorrect value for "dob". Format the value according to ISO 8601.',
46
+ IV_004: '[IV-004] Incorrect value for "email". Set the value to a valid email address.',
47
+ IV_005: '[IV-005] Incorrect value for "expiryDate". Format the value according to ISO 8601.',
48
+ IV_006: (maxAttributes) => `[IV-006] "extensionData" supports maximum ${maxAttributes} attributes. Reduce the number of attributes.`,
49
+ IV_007: (siteName) => `[IV-007] Site "${siteName}" does not exist or site item tree is missing.`,
50
+ /** IE errors are related to incorrect execution */
51
+ IE_001: (pluginName, dependency) => `[IE-001] "${pluginName}" also requires "${dependency}". Add the missing dependency.`,
52
+ IE_002: '[IE-002] SDK not initialized. You must first initialize the SDK using "initContentSdk()".',
53
+ IE_003: '[IE-003] Timeout exceeded. The server did not respond within the allotted time.',
54
+ IE_004: (pluginName) => `[IE-004] Plugin not registered. You must first add "${pluginName}" to the "initContentSdk()" "plugins" array.`,
55
+ IE_005: '[IE-005] Unable to set the "sc_cid" cookie because the client ID could not be retrieved from the server. Make sure to set the correct values for "contextId" and "siteName". If the issue persists, try again later or use try-catch blocks to handle this error.',
56
+ IE_006: '[IE-006] Unable to set the "sc_cid_personalize" cookie because the visitor ID could not be retrieved from the server. Make sure to set the correct values for "contextId" and "siteName". If the issue persists, try again later or use try-catch blocks to handle this error.',
57
+ IE_007: (hostName) => `[IE-007] Could not resolve site for host "${hostName}".`,
58
+ /** MV errors are related to missing values */
59
+ MV_001: '[MV-001] "contextId" is required.',
60
+ MV_002: '[MV-002] "siteName" is required.',
61
+ MV_003: '[MV-003] "identifiers" is required.',
62
+ MV_004: '[MV-004] "friendlyId" is required.',
63
+ MV_005: (property) => `[MV-005] The "sitecore.cli.config" file is missing a "${property}". Please add it to use this command.`,
64
+ MV_006: '[MV-006] "clientContextId" is missing. Client-side functionalities may be limited.',
65
+ MV_007: '[MV-007] Provide either "contextId" or both "apiHost" and "apiKey".',
66
+ MV_008: '[MV-008] Verify that sitecore.config is properly imported and correctly referenced.',
67
+ MV_009: '[MV-009] "language" is required.',
68
+ /** Generic follow-up when the user should contact support */
69
+ CONTACT_SUPPORT: 'If the issue persists, please contact Sitecore Support.',
70
+ };
package/dist/cjs/debug.js CHANGED
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  var _a;
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.enableDebug = exports.debugNamespace = exports.debugModule = void 0;
8
+ exports.isNamespaceEnabled = isNamespaceEnabled;
8
9
  /* eslint-disable import/no-anonymous-default-export */
9
10
  const debug_1 = __importDefault(require("debug"));
10
11
  const is_server_1 = __importDefault(require("./tools/is-server"));
@@ -34,6 +35,15 @@ if ((0, is_server_1.default)() &&
34
35
  */
35
36
  const enableDebug = (namespaces) => debug_1.default.enable(namespaces);
36
37
  exports.enableDebug = enableDebug;
38
+ /**
39
+ * Check if a debug namespace is enabled
40
+ * @param {string} namespace the namespace to check
41
+ * @returns {boolean} whether the namespace is enabled
42
+ * @public
43
+ */
44
+ function isNamespaceEnabled(namespace) {
45
+ return debug_1.default.enabled(namespace);
46
+ }
37
47
  /**
38
48
  * Default Sitecore Content SDK 'debug' module debuggers. Uses namespace prefix 'content-sdk:'.
39
49
  * See {@link https://www.npmjs.com/package/debug} for details.
@@ -41,4 +51,5 @@ exports.enableDebug = enableDebug;
41
51
  exports.default = {
42
52
  common: (0, debug_1.default)(`${exports.debugNamespace}:common`),
43
53
  http: (0, debug_1.default)(`${exports.debugNamespace}:http`),
54
+ init: (0, debug_1.default)(`${exports.debugNamespace}:init`),
44
55
  };
package/dist/cjs/index.js CHANGED
@@ -32,11 +32,14 @@ var __importStar = (this && this.__importStar) || (function () {
32
32
  return result;
33
33
  };
34
34
  })();
35
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
36
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
37
+ };
35
38
  var __importDefault = (this && this.__importDefault) || function (mod) {
36
39
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
40
  };
38
41
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.constants = exports.NativeDataFetcher = exports.ClientError = exports.MemoryCacheClient = exports.DefaultRetryStrategy = exports.GraphQLRequestClient = exports.debugModule = exports.debugNamespace = exports.enableDebug = exports.debug = void 0;
42
+ exports.constants = exports.NativeDataFetcher = exports.ClientError = exports.MemoryCacheClient = exports.DefaultRetryStrategy = exports.GraphQLRequestClient = exports.isNamespaceEnabled = exports.debugModule = exports.debugNamespace = exports.enableDebug = exports.debug = void 0;
40
43
  const constants = __importStar(require("./constants"));
41
44
  exports.constants = constants;
42
45
  var debug_1 = require("./debug");
@@ -44,6 +47,7 @@ Object.defineProperty(exports, "debug", { enumerable: true, get: function () { r
44
47
  Object.defineProperty(exports, "enableDebug", { enumerable: true, get: function () { return debug_1.enableDebug; } });
45
48
  Object.defineProperty(exports, "debugNamespace", { enumerable: true, get: function () { return debug_1.debugNamespace; } });
46
49
  Object.defineProperty(exports, "debugModule", { enumerable: true, get: function () { return debug_1.debugModule; } });
50
+ Object.defineProperty(exports, "isNamespaceEnabled", { enumerable: true, get: function () { return debug_1.isNamespaceEnabled; } });
47
51
  var graphql_request_client_1 = require("./graphql-request-client");
48
52
  Object.defineProperty(exports, "GraphQLRequestClient", { enumerable: true, get: function () { return graphql_request_client_1.GraphQLRequestClient; } });
49
53
  var retries_1 = require("./retries");
@@ -54,3 +58,4 @@ var graphql_request_1 = require("graphql-request");
54
58
  Object.defineProperty(exports, "ClientError", { enumerable: true, get: function () { return graphql_request_1.ClientError; } });
55
59
  var native_fetcher_1 = require("./native-fetcher");
56
60
  Object.defineProperty(exports, "NativeDataFetcher", { enumerable: true, get: function () { return native_fetcher_1.NativeDataFetcher; } });
61
+ __exportStar(require("./initialization"), exports);
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.checkPluginDependencies = checkPluginDependencies;
7
+ exports.initPlugins = initPlugins;
8
+ exports.resolveCoreContextConfig = resolveCoreContextConfig;
9
+ const debug_1 = __importDefault(require("../debug"));
10
+ const constants_1 = require("../constants");
11
+ const constants_2 = require("../constants");
12
+ const debugInit = debug_1.default.init;
13
+ /**
14
+ * Checks if the plugin's dependencies are present in the state.
15
+ * @param {Plugin} plugin - The plugin to check dependencies for.
16
+ * @param {Map<string, Plugin>} plugins - The map of available plugins.
17
+ * @internal
18
+ */
19
+ function checkPluginDependencies(plugin, plugins) {
20
+ if (!plugin.dependencies)
21
+ return;
22
+ for (const dependency of plugin.dependencies) {
23
+ if (!plugins.has(dependency))
24
+ throw new Error(constants_1.ERROR_MESSAGES.IE_001(plugin.name, dependency));
25
+ }
26
+ debugInit(`All required dependencies for "${plugin.name}" are present`);
27
+ }
28
+ /**
29
+ * Initializes all registered plugins by calling their `init` function.
30
+ * @param {Map<string, Plugin>} plugins - The array of plugins to initialize.
31
+ * @returns A promise that resolves when all plugins have been initialized.
32
+ * @internal
33
+ */
34
+ async function initPlugins(plugins) {
35
+ var _a;
36
+ debugInit(`Initializing ${plugins.size} plugins`);
37
+ for (const plugin of plugins.values()) {
38
+ checkPluginDependencies(plugin, plugins);
39
+ await ((_a = plugin.init) === null || _a === void 0 ? void 0 : _a.call(plugin));
40
+ debugInit(`Successfully initialized "${plugin.name}"`);
41
+ }
42
+ debugInit(`Successfully initialized ${plugins.size} plugins`);
43
+ }
44
+ /**
45
+ * Validates and constructs the core context settings.
46
+ * @param {InitContentSdkParams['config']} config - The core context settings object.
47
+ * @internal
48
+ */
49
+ function resolveCoreContextConfig(config) {
50
+ var _a;
51
+ const { contextId, siteName, edgeUrl } = config;
52
+ if (!contextId || contextId.trim().length === 0)
53
+ throw new Error(constants_1.ERROR_MESSAGES.MV_001);
54
+ if (!siteName || siteName.trim().length === 0)
55
+ throw new Error(constants_1.ERROR_MESSAGES.MV_002);
56
+ if (edgeUrl !== undefined)
57
+ try {
58
+ new URL(edgeUrl);
59
+ }
60
+ catch (_b) {
61
+ throw new Error(constants_1.ERROR_MESSAGES.IV_001);
62
+ }
63
+ debugInit('Configuration is valid');
64
+ return Object.assign(Object.assign({}, config), { edgeUrl: (_a = edgeUrl === null || edgeUrl === void 0 ? void 0 : edgeUrl.trim()) !== null && _a !== void 0 ? _a : constants_2.SITECORE_EDGE_PLATFORM_URL_DEFAULT });
65
+ }
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCoreContext = exports.initContentSdk = void 0;
4
+ var init_content_sdk_1 = require("./init-content-sdk");
5
+ Object.defineProperty(exports, "initContentSdk", { enumerable: true, get: function () { return init_content_sdk_1.initContentSdk; } });
6
+ Object.defineProperty(exports, "getCoreContext", { enumerable: true, get: function () { return init_content_sdk_1.getCoreContext; } });
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getCoreContext = getCoreContext;
7
+ exports.initContentSdk = initContentSdk;
8
+ const debug_1 = __importDefault(require("../debug"));
9
+ const helpers_1 = require("./helpers");
10
+ const constants_1 = require("../constants");
11
+ let coreContext;
12
+ /**
13
+ * Retrieves the current core context.
14
+ * @returns {CoreContext} The current core context object.
15
+ * @internal
16
+ */
17
+ function getCoreContext() {
18
+ if (!coreContext)
19
+ throw new Error(constants_1.ERROR_MESSAGES.IE_002);
20
+ return coreContext;
21
+ }
22
+ /**
23
+ * Initializes the Content SDK with the provided params.
24
+ * @param {InitContentSdkParams} params - The initialization params including config and plugins.
25
+ * @returns A promise that resolves when initialization is complete.
26
+ * @public
27
+ */
28
+ async function initContentSdk(params) {
29
+ debug_1.default.init('Initializing Content SDK with params:', params);
30
+ const { config, plugins } = params;
31
+ const resolvedConfig = (0, helpers_1.resolveCoreContextConfig)(config);
32
+ if (plugins.length === 0)
33
+ debug_1.default.init('No plugins provided to the plugins array');
34
+ coreContext = {
35
+ config: resolvedConfig,
36
+ plugins: new Map(),
37
+ readyPromise: null,
38
+ };
39
+ for (const plugin of plugins) {
40
+ coreContext.plugins.set(plugin.name, plugin);
41
+ }
42
+ debug_1.default.init(`Registered ${coreContext.plugins.size} plugins`);
43
+ coreContext.readyPromise = (0, helpers_1.initPlugins)(coreContext.plugins);
44
+ await coreContext.readyPromise;
45
+ debug_1.default.init('Content SDK initialization complete');
46
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -48,7 +48,7 @@ async function _clientCredentialsFlow({ clientId, clientSecret, organizationId,
48
48
  });
49
49
  const data = await response.json();
50
50
  if (!response.ok) {
51
- throw new Error(data.error_description || data.error || 'Error during client credentials flow');
51
+ throw new Error(data.error_description || data.error || `Error during client credentials flow. ${constants_1.ERROR_MESSAGES.CONTACT_SUPPORT}`);
52
52
  }
53
53
  const decodedPayload = (0, tenant_store_1.decodeJwtPayload)(data.access_token) || {};
54
54
  if (!(decodedPayload === null || decodedPayload === void 0 ? void 0 : decodedPayload.tokenTenantId) || !decodedPayload.tokenOrgId) {
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const constants_1 = require("../constants");
3
4
  /**
4
5
  * A helper to assign timeouts to fetch or other promises
5
6
  * Useful in nextjs middleware until fetch.signal is fully supported by Vercel edge functions
@@ -14,8 +15,10 @@ class TimeoutPromise {
14
15
  */
15
16
  get start() {
16
17
  return new Promise((_, reject) => {
18
+ if (!Number.isInteger(this.timeout) || this.timeout < 0)
19
+ throw new Error(constants_1.ERROR_MESSAGES.IV_002);
17
20
  this.timeoutId = setTimeout(() => {
18
- const abortError = new Error(`Request timed out, timeout of ${this.timeout}ms is exceeded`);
21
+ const abortError = new Error(constants_1.ERROR_MESSAGES.IE_003);
19
22
  abortError.name = 'AbortError';
20
23
  reject(abortError);
21
24
  }, this.timeout);
@@ -1,3 +1,4 @@
1
+ /* eslint-disable jsdoc/require-param */
1
2
  /**
2
3
  * Default Edge Platform URL (edge-platform.sitecorecloud.io). Used for service endpoints
3
4
  * (GraphQL, content API, forms, layout, static files) when no custom hostname is configured.
@@ -30,3 +31,37 @@ export const DEFAULT_SITECORE_AUTH_AUDIENCE = 'https://api.sitecorecloud.io';
30
31
  * @internal
31
32
  */
32
33
  export const DEFAULT_SITECORE_AUTH_BASE_URL = 'https://edge-platform.sitecorecloud.io/cs/api';
34
+ /**
35
+ * The error messages. Includes errors for all packages.
36
+ * @internal
37
+ */
38
+ export const ERROR_MESSAGES = {
39
+ /** IV errors are related to incorrect values, wrongly formatted objects, etc. */
40
+ IV_001: '[IV-001] Incorrect value for "edgeUrl". Set the value to a valid URL.',
41
+ IV_002: '[IV-002] Incorrect value for "timeout". Set the value to an integer greater than or equal to 0.',
42
+ IV_003: '[IV-003] Incorrect value for "dob". Format the value according to ISO 8601.',
43
+ IV_004: '[IV-004] Incorrect value for "email". Set the value to a valid email address.',
44
+ IV_005: '[IV-005] Incorrect value for "expiryDate". Format the value according to ISO 8601.',
45
+ IV_006: (maxAttributes) => `[IV-006] "extensionData" supports maximum ${maxAttributes} attributes. Reduce the number of attributes.`,
46
+ IV_007: (siteName) => `[IV-007] Site "${siteName}" does not exist or site item tree is missing.`,
47
+ /** IE errors are related to incorrect execution */
48
+ IE_001: (pluginName, dependency) => `[IE-001] "${pluginName}" also requires "${dependency}". Add the missing dependency.`,
49
+ IE_002: '[IE-002] SDK not initialized. You must first initialize the SDK using "initContentSdk()".',
50
+ IE_003: '[IE-003] Timeout exceeded. The server did not respond within the allotted time.',
51
+ IE_004: (pluginName) => `[IE-004] Plugin not registered. You must first add "${pluginName}" to the "initContentSdk()" "plugins" array.`,
52
+ IE_005: '[IE-005] Unable to set the "sc_cid" cookie because the client ID could not be retrieved from the server. Make sure to set the correct values for "contextId" and "siteName". If the issue persists, try again later or use try-catch blocks to handle this error.',
53
+ IE_006: '[IE-006] Unable to set the "sc_cid_personalize" cookie because the visitor ID could not be retrieved from the server. Make sure to set the correct values for "contextId" and "siteName". If the issue persists, try again later or use try-catch blocks to handle this error.',
54
+ IE_007: (hostName) => `[IE-007] Could not resolve site for host "${hostName}".`,
55
+ /** MV errors are related to missing values */
56
+ MV_001: '[MV-001] "contextId" is required.',
57
+ MV_002: '[MV-002] "siteName" is required.',
58
+ MV_003: '[MV-003] "identifiers" is required.',
59
+ MV_004: '[MV-004] "friendlyId" is required.',
60
+ MV_005: (property) => `[MV-005] The "sitecore.cli.config" file is missing a "${property}". Please add it to use this command.`,
61
+ MV_006: '[MV-006] "clientContextId" is missing. Client-side functionalities may be limited.',
62
+ MV_007: '[MV-007] Provide either "contextId" or both "apiHost" and "apiKey".',
63
+ MV_008: '[MV-008] Verify that sitecore.config is properly imported and correctly referenced.',
64
+ MV_009: '[MV-009] "language" is required.',
65
+ /** Generic follow-up when the user should contact support */
66
+ CONTACT_SUPPORT: 'If the issue persists, please contact Sitecore Support.',
67
+ };
package/dist/esm/debug.js CHANGED
@@ -27,6 +27,15 @@ if (isServer() &&
27
27
  * @public
28
28
  */
29
29
  export const enableDebug = (namespaces) => debug.enable(namespaces);
30
+ /**
31
+ * Check if a debug namespace is enabled
32
+ * @param {string} namespace the namespace to check
33
+ * @returns {boolean} whether the namespace is enabled
34
+ * @public
35
+ */
36
+ export function isNamespaceEnabled(namespace) {
37
+ return debug.enabled(namespace);
38
+ }
30
39
  /**
31
40
  * Default Sitecore Content SDK 'debug' module debuggers. Uses namespace prefix 'content-sdk:'.
32
41
  * See {@link https://www.npmjs.com/package/debug} for details.
@@ -34,4 +43,5 @@ export const enableDebug = (namespaces) => debug.enable(namespaces);
34
43
  export default {
35
44
  common: debug(`${debugNamespace}:common`),
36
45
  http: debug(`${debugNamespace}:http`),
46
+ init: debug(`${debugNamespace}:init`),
37
47
  };
package/dist/esm/index.js CHANGED
@@ -1,8 +1,9 @@
1
1
  import * as constants from './constants';
2
- export { default as debug, enableDebug, debugNamespace, debugModule } from './debug';
2
+ export { default as debug, enableDebug, debugNamespace, debugModule, isNamespaceEnabled, } from './debug';
3
3
  export { GraphQLRequestClient, } from './graphql-request-client';
4
4
  export { DefaultRetryStrategy } from './retries';
5
5
  export { MemoryCacheClient } from './cache-client';
6
6
  export { ClientError } from 'graphql-request';
7
7
  export { NativeDataFetcher, } from './native-fetcher';
8
8
  export { constants };
9
+ export * from './initialization';
@@ -0,0 +1,57 @@
1
+ import debug from '../debug';
2
+ import { ERROR_MESSAGES } from '../constants';
3
+ import { SITECORE_EDGE_PLATFORM_URL_DEFAULT } from '../constants';
4
+ const debugInit = debug.init;
5
+ /**
6
+ * Checks if the plugin's dependencies are present in the state.
7
+ * @param {Plugin} plugin - The plugin to check dependencies for.
8
+ * @param {Map<string, Plugin>} plugins - The map of available plugins.
9
+ * @internal
10
+ */
11
+ export function checkPluginDependencies(plugin, plugins) {
12
+ if (!plugin.dependencies)
13
+ return;
14
+ for (const dependency of plugin.dependencies) {
15
+ if (!plugins.has(dependency))
16
+ throw new Error(ERROR_MESSAGES.IE_001(plugin.name, dependency));
17
+ }
18
+ debugInit(`All required dependencies for "${plugin.name}" are present`);
19
+ }
20
+ /**
21
+ * Initializes all registered plugins by calling their `init` function.
22
+ * @param {Map<string, Plugin>} plugins - The array of plugins to initialize.
23
+ * @returns A promise that resolves when all plugins have been initialized.
24
+ * @internal
25
+ */
26
+ export async function initPlugins(plugins) {
27
+ var _a;
28
+ debugInit(`Initializing ${plugins.size} plugins`);
29
+ for (const plugin of plugins.values()) {
30
+ checkPluginDependencies(plugin, plugins);
31
+ await ((_a = plugin.init) === null || _a === void 0 ? void 0 : _a.call(plugin));
32
+ debugInit(`Successfully initialized "${plugin.name}"`);
33
+ }
34
+ debugInit(`Successfully initialized ${plugins.size} plugins`);
35
+ }
36
+ /**
37
+ * Validates and constructs the core context settings.
38
+ * @param {InitContentSdkParams['config']} config - The core context settings object.
39
+ * @internal
40
+ */
41
+ export function resolveCoreContextConfig(config) {
42
+ var _a;
43
+ const { contextId, siteName, edgeUrl } = config;
44
+ if (!contextId || contextId.trim().length === 0)
45
+ throw new Error(ERROR_MESSAGES.MV_001);
46
+ if (!siteName || siteName.trim().length === 0)
47
+ throw new Error(ERROR_MESSAGES.MV_002);
48
+ if (edgeUrl !== undefined)
49
+ try {
50
+ new URL(edgeUrl);
51
+ }
52
+ catch (_b) {
53
+ throw new Error(ERROR_MESSAGES.IV_001);
54
+ }
55
+ debugInit('Configuration is valid');
56
+ return Object.assign(Object.assign({}, config), { edgeUrl: (_a = edgeUrl === null || edgeUrl === void 0 ? void 0 : edgeUrl.trim()) !== null && _a !== void 0 ? _a : SITECORE_EDGE_PLATFORM_URL_DEFAULT });
57
+ }
@@ -0,0 +1 @@
1
+ export { initContentSdk, getCoreContext } from './init-content-sdk';
@@ -0,0 +1,39 @@
1
+ import debug from '../debug';
2
+ import { initPlugins, resolveCoreContextConfig } from './helpers';
3
+ import { ERROR_MESSAGES } from '../constants';
4
+ let coreContext;
5
+ /**
6
+ * Retrieves the current core context.
7
+ * @returns {CoreContext} The current core context object.
8
+ * @internal
9
+ */
10
+ export function getCoreContext() {
11
+ if (!coreContext)
12
+ throw new Error(ERROR_MESSAGES.IE_002);
13
+ return coreContext;
14
+ }
15
+ /**
16
+ * Initializes the Content SDK with the provided params.
17
+ * @param {InitContentSdkParams} params - The initialization params including config and plugins.
18
+ * @returns A promise that resolves when initialization is complete.
19
+ * @public
20
+ */
21
+ export async function initContentSdk(params) {
22
+ debug.init('Initializing Content SDK with params:', params);
23
+ const { config, plugins } = params;
24
+ const resolvedConfig = resolveCoreContextConfig(config);
25
+ if (plugins.length === 0)
26
+ debug.init('No plugins provided to the plugins array');
27
+ coreContext = {
28
+ config: resolvedConfig,
29
+ plugins: new Map(),
30
+ readyPromise: null,
31
+ };
32
+ for (const plugin of plugins) {
33
+ coreContext.plugins.set(plugin.name, plugin);
34
+ }
35
+ debug.init(`Registered ${coreContext.plugins.size} plugins`);
36
+ coreContext.readyPromise = initPlugins(coreContext.plugins);
37
+ await coreContext.readyPromise;
38
+ debug.init('Content SDK initialization complete');
39
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,5 +1,5 @@
1
1
  import { decodeJwtPayload } from './tenant-store';
2
- import { DEFAULT_SITECORE_AUTH_DOMAIN, DEFAULT_SITECORE_AUTH_AUDIENCE, DEFAULT_SITECORE_AUTH_BASE_URL, } from '../../constants';
2
+ import { DEFAULT_SITECORE_AUTH_DOMAIN, DEFAULT_SITECORE_AUTH_AUDIENCE, DEFAULT_SITECORE_AUTH_BASE_URL, ERROR_MESSAGES, } from '../../constants';
3
3
  const GRANT_TYPE = 'client_credentials';
4
4
  /**
5
5
  * Performs the OAuth 2.0 client credentials flow to obtain a JWT access token
@@ -45,7 +45,7 @@ async function _clientCredentialsFlow({ clientId, clientSecret, organizationId,
45
45
  });
46
46
  const data = await response.json();
47
47
  if (!response.ok) {
48
- throw new Error(data.error_description || data.error || 'Error during client credentials flow');
48
+ throw new Error(data.error_description || data.error || `Error during client credentials flow. ${ERROR_MESSAGES.CONTACT_SUPPORT}`);
49
49
  }
50
50
  const decodedPayload = decodeJwtPayload(data.access_token) || {};
51
51
  if (!(decodedPayload === null || decodedPayload === void 0 ? void 0 : decodedPayload.tokenTenantId) || !decodedPayload.tokenOrgId) {
@@ -1,3 +1,4 @@
1
+ import { ERROR_MESSAGES } from '../constants';
1
2
  /**
2
3
  * A helper to assign timeouts to fetch or other promises
3
4
  * Useful in nextjs middleware until fetch.signal is fully supported by Vercel edge functions
@@ -12,8 +13,10 @@ export default class TimeoutPromise {
12
13
  */
13
14
  get start() {
14
15
  return new Promise((_, reject) => {
16
+ if (!Number.isInteger(this.timeout) || this.timeout < 0)
17
+ throw new Error(ERROR_MESSAGES.IV_002);
15
18
  this.timeoutId = setTimeout(() => {
16
- const abortError = new Error(`Request timed out, timeout of ${this.timeout}ms is exceeded`);
19
+ const abortError = new Error(ERROR_MESSAGES.IE_003);
17
20
  abortError.name = 'AbortError';
18
21
  reject(abortError);
19
22
  }, this.timeout);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sitecore-content-sdk/core",
3
- "version": "2.0.0-canary.10",
3
+ "version": "2.0.0-canary.13",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "sideEffects": false,
@@ -43,6 +43,7 @@
43
43
  "@types/memory-cache": "^0.2.6",
44
44
  "@types/mocha": "^10.0.10",
45
45
  "@types/node": "^24.10.4",
46
+ "@types/proxyquire": "^1.3.31",
46
47
  "@types/sinon": "^17.0.4",
47
48
  "@types/url-parse": "1.4.11",
48
49
  "@typescript-eslint/eslint-plugin": "8.39.0",
@@ -59,6 +60,7 @@
59
60
  "nock": "14.0.0-beta.7",
60
61
  "nyc": "^17.1.0",
61
62
  "prettier": "^2.8.0",
63
+ "proxyquire": "^2.1.3",
62
64
  "sinon": "^20.0.0",
63
65
  "tsx": "^4.19.4",
64
66
  "typescript": "~5.8.3"
@@ -72,7 +74,7 @@
72
74
  },
73
75
  "description": "",
74
76
  "types": "types/index.d.ts",
75
- "gitHead": "6246e4787e22778e64c90bcd9292a9988b3552a8",
77
+ "gitHead": "414b181508e47177e1818381ad4f555c189b9e4a",
76
78
  "files": [
77
79
  "dist",
78
80
  "types",
@@ -30,4 +30,38 @@ export declare const DEFAULT_SITECORE_AUTH_AUDIENCE = "https://api.sitecorecloud
30
30
  * @internal
31
31
  */
32
32
  export declare const DEFAULT_SITECORE_AUTH_BASE_URL = "https://edge-platform.sitecorecloud.io/cs/api";
33
+ /**
34
+ * The error messages. Includes errors for all packages.
35
+ * @internal
36
+ */
37
+ export declare const ERROR_MESSAGES: {
38
+ /** IV errors are related to incorrect values, wrongly formatted objects, etc. */
39
+ readonly IV_001: "[IV-001] Incorrect value for \"edgeUrl\". Set the value to a valid URL.";
40
+ readonly IV_002: "[IV-002] Incorrect value for \"timeout\". Set the value to an integer greater than or equal to 0.";
41
+ readonly IV_003: "[IV-003] Incorrect value for \"dob\". Format the value according to ISO 8601.";
42
+ readonly IV_004: "[IV-004] Incorrect value for \"email\". Set the value to a valid email address.";
43
+ readonly IV_005: "[IV-005] Incorrect value for \"expiryDate\". Format the value according to ISO 8601.";
44
+ readonly IV_006: (maxAttributes: number) => string;
45
+ readonly IV_007: (siteName: string) => string;
46
+ /** IE errors are related to incorrect execution */
47
+ readonly IE_001: (pluginName: string, dependency: string) => string;
48
+ readonly IE_002: "[IE-002] SDK not initialized. You must first initialize the SDK using \"initContentSdk()\".";
49
+ readonly IE_003: "[IE-003] Timeout exceeded. The server did not respond within the allotted time.";
50
+ readonly IE_004: (pluginName: string) => string;
51
+ readonly IE_005: "[IE-005] Unable to set the \"sc_cid\" cookie because the client ID could not be retrieved from the server. Make sure to set the correct values for \"contextId\" and \"siteName\". If the issue persists, try again later or use try-catch blocks to handle this error.";
52
+ readonly IE_006: "[IE-006] Unable to set the \"sc_cid_personalize\" cookie because the visitor ID could not be retrieved from the server. Make sure to set the correct values for \"contextId\" and \"siteName\". If the issue persists, try again later or use try-catch blocks to handle this error.";
53
+ readonly IE_007: (hostName: string) => string;
54
+ /** MV errors are related to missing values */
55
+ readonly MV_001: "[MV-001] \"contextId\" is required.";
56
+ readonly MV_002: "[MV-002] \"siteName\" is required.";
57
+ readonly MV_003: "[MV-003] \"identifiers\" is required.";
58
+ readonly MV_004: "[MV-004] \"friendlyId\" is required.";
59
+ readonly MV_005: (property: string) => string;
60
+ readonly MV_006: "[MV-006] \"clientContextId\" is missing. Client-side functionalities may be limited.";
61
+ readonly MV_007: "[MV-007] Provide either \"contextId\" or both \"apiHost\" and \"apiKey\".";
62
+ readonly MV_008: "[MV-008] Verify that sitecore.config is properly imported and correctly referenced.";
63
+ readonly MV_009: "[MV-009] \"language\" is required.";
64
+ /** Generic follow-up when the user should contact support */
65
+ readonly CONTACT_SUPPORT: "If the issue persists, please contact Sitecore Support.";
66
+ };
33
67
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,kCAAkC,2CAA2C,CAAC;AAE3F;;;;GAIG;AACH,eAAO,MAAM,oCAAoC,kCAAkC,CAAC;AAEpF;;;GAGG;AACH,eAAO,MAAM,MAAM,yCAAyC,CAAC;AAC7D;;;GAGG;AACH,eAAO,MAAM,4BAA4B,kCAAkC,CAAC;AAC5E;;;GAGG;AACH,eAAO,MAAM,8BAA8B,iCAAiC,CAAC;AAC7E;;;GAGG;AACH,eAAO,MAAM,8BAA8B,kDAAkD,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,kCAAkC,2CAA2C,CAAC;AAE3F;;;;GAIG;AACH,eAAO,MAAM,oCAAoC,kCAAkC,CAAC;AAEpF;;;GAGG;AACH,eAAO,MAAM,MAAM,yCAAyC,CAAC;AAC7D;;;GAGG;AACH,eAAO,MAAM,4BAA4B,kCAAkC,CAAC;AAC5E;;;GAGG;AACH,eAAO,MAAM,8BAA8B,iCAAiC,CAAC;AAC7E;;;GAGG;AACH,eAAO,MAAM,8BAA8B,kDAAkD,CAAC;AAE9F;;;GAGG;AACH,eAAO,MAAM,cAAc;IACzB,iFAAiF;;;;;;qCAOzD,MAAM;gCAEX,MAAM;IAGzB,mDAAmD;kCAC9B,MAAM,cAAc,MAAM;;;kCAK1B,MAAM;;;gCAMR,MAAM;IAEzB,8CAA8C;;;;;gCAK3B,MAAM;;;;;IAOzB,6DAA6D;;CAErD,CAAC"}
package/types/debug.d.ts CHANGED
@@ -23,6 +23,13 @@ export type Debugger = debug.Debugger;
23
23
  * @public
24
24
  */
25
25
  export declare const enableDebug: (namespaces: string) => void;
26
+ /**
27
+ * Check if a debug namespace is enabled
28
+ * @param {string} namespace the namespace to check
29
+ * @returns {boolean} whether the namespace is enabled
30
+ * @public
31
+ */
32
+ export declare function isNamespaceEnabled(namespace: string): boolean;
26
33
  /**
27
34
  * Default Sitecore Content SDK 'debug' module debuggers. Uses namespace prefix 'content-sdk:'.
28
35
  * See {@link https://www.npmjs.com/package/debug} for details.
@@ -30,6 +37,7 @@ export declare const enableDebug: (namespaces: string) => void;
30
37
  declare const _default: {
31
38
  common: debug.Debugger;
32
39
  http: debug.Debugger;
40
+ init: debug.Debugger;
33
41
  };
34
42
  export default _default;
35
43
  //# sourceMappingURL=debug.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../src/debug.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B;;;GAGG;AACH,eAAO,MAAM,WAAW;;;CAAQ,CAAC;AAEjC;;;GAGG;AACH,eAAO,MAAM,cAAc,gBAAgB,CAAC;AAE5C;;;GAGG;AACH,MAAM,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;AActC;;;;GAIG;AACH,eAAO,MAAM,WAAW,GAAI,YAAY,MAAM,SAA6B,CAAC;AAE5E;;;GAGG;;;;;AACH,wBAGE"}
1
+ {"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../src/debug.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B;;;GAGG;AACH,eAAO,MAAM,WAAW;;;CAAQ,CAAC;AAEjC;;;GAGG;AACH,eAAO,MAAM,cAAc,gBAAgB,CAAC;AAE5C;;;GAGG;AACH,MAAM,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;AActC;;;;GAIG;AACH,eAAO,MAAM,WAAW,GAAI,YAAY,MAAM,SAA6B,CAAC;AAE5E;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAE7D;AAED;;;GAGG;;;;;;AACH,wBAIE"}
package/types/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as constants from './constants';
2
- export { default as debug, Debugger, enableDebug, debugNamespace, debugModule } from './debug';
2
+ export { default as debug, Debugger, enableDebug, debugNamespace, debugModule, isNamespaceEnabled, } from './debug';
3
3
  export { GraphQLClient, GraphQLRequestClient, GraphQLClientError, GraphQLRequestClientConfig, GraphQLRequestClientFactory, GraphQLRequestClientFactoryConfig, } from './graphql-request-client';
4
4
  export { DefaultRetryStrategy } from './retries';
5
5
  export { CacheClient, CacheOptions, MemoryCacheClient } from './cache-client';
@@ -7,4 +7,5 @@ export { ClientError } from 'graphql-request';
7
7
  export { NativeDataFetcher, NativeDataFetcherConfig, NativeDataFetcherError, NativeDataFetcherResponse, } from './native-fetcher';
8
8
  export { RetryStrategy, GenericGraphQLClientError, FetchOptions } from './models';
9
9
  export { constants };
10
+ export * from './initialization';
10
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC/F,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,kBAAkB,EAClB,0BAA0B,EAC1B,2BAA2B,EAC3B,iCAAiC,GAClC,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EACL,iBAAiB,EACjB,uBAAuB,EACvB,sBAAsB,EACtB,yBAAyB,GAC1B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAE,yBAAyB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAClF,OAAO,EAAE,SAAS,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,aAAa,CAAC;AAEzC,OAAO,EACL,OAAO,IAAI,KAAK,EAChB,QAAQ,EACR,WAAW,EACX,cAAc,EACd,WAAW,EACX,kBAAkB,GACnB,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,kBAAkB,EAClB,0BAA0B,EAC1B,2BAA2B,EAC3B,iCAAiC,GAClC,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EACL,iBAAiB,EACjB,uBAAuB,EACvB,sBAAsB,EACtB,yBAAyB,GAC1B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAE,yBAAyB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAClF,OAAO,EAAE,SAAS,EAAE,CAAC;AACrB,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { CoreContext, InitContentSdkParams } from './types';
2
+ import { Plugin } from './types';
3
+ /**
4
+ * Checks if the plugin's dependencies are present in the state.
5
+ * @param {Plugin} plugin - The plugin to check dependencies for.
6
+ * @param {Map<string, Plugin>} plugins - The map of available plugins.
7
+ * @internal
8
+ */
9
+ export declare function checkPluginDependencies(plugin: Plugin, plugins: Map<string, Plugin>): void;
10
+ /**
11
+ * Initializes all registered plugins by calling their `init` function.
12
+ * @param {Map<string, Plugin>} plugins - The array of plugins to initialize.
13
+ * @returns A promise that resolves when all plugins have been initialized.
14
+ * @internal
15
+ */
16
+ export declare function initPlugins(plugins: Map<string, Plugin>): Promise<void>;
17
+ /**
18
+ * Validates and constructs the core context settings.
19
+ * @param {InitContentSdkParams['config']} config - The core context settings object.
20
+ * @internal
21
+ */
22
+ export declare function resolveCoreContextConfig(config: InitContentSdkParams['config']): CoreContext['config'];
23
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/initialization/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAE5D,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAMjC;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAQ1F;AAED;;;;;GAKG;AACH,wBAAsB,WAAW,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAW7E;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,oBAAoB,CAAC,QAAQ,CAAC,GACrC,WAAW,CAAC,QAAQ,CAAC,CAmBvB"}
@@ -0,0 +1,3 @@
1
+ export { initContentSdk, getCoreContext } from './init-content-sdk';
2
+ export type { Plugin, PluginDependency, PluginAdapter, InitContentSdkParams, CoreContext, } from './types';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/initialization/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpE,YAAY,EACV,MAAM,EACN,gBAAgB,EAChB,aAAa,EACb,oBAAoB,EACpB,WAAW,GACZ,MAAM,SAAS,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { CoreContext, InitContentSdkParams } from './types';
2
+ /**
3
+ * Retrieves the current core context.
4
+ * @returns {CoreContext} The current core context object.
5
+ * @internal
6
+ */
7
+ export declare function getCoreContext(): CoreContext;
8
+ /**
9
+ * Initializes the Content SDK with the provided params.
10
+ * @param {InitContentSdkParams} params - The initialization params including config and plugins.
11
+ * @returns A promise that resolves when initialization is complete.
12
+ * @public
13
+ */
14
+ export declare function initContentSdk(params: InitContentSdkParams): Promise<void>;
15
+ //# sourceMappingURL=init-content-sdk.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init-content-sdk.d.ts","sourceRoot":"","sources":["../../src/initialization/init-content-sdk.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAOjE;;;;GAIG;AACH,wBAAgB,cAAc,IAAI,WAAW,CAI5C;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAwBhF"}
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Parameters for initContentSdk
3
+ * @public
4
+ */
5
+ export interface InitContentSdkParams {
6
+ /** Initialization config */
7
+ config: {
8
+ /**
9
+ * The context ID.
10
+ */
11
+ contextId: string;
12
+ /**
13
+ * Sitecore edge URL
14
+ */
15
+ edgeUrl?: string;
16
+ /**
17
+ * The site name.
18
+ */
19
+ siteName: string;
20
+ };
21
+ /** Array of plugins to initialize */
22
+ plugins: Plugin[];
23
+ }
24
+ /**
25
+ * Internal config of the SDK initialization
26
+ * @internal
27
+ */
28
+ export interface CoreContext {
29
+ /**
30
+ * The SDK initialization config
31
+ */
32
+ config: {
33
+ contextId: string;
34
+ edgeUrl: string;
35
+ siteName: string;
36
+ };
37
+ /**
38
+ * Map of enabled plugins by name
39
+ */
40
+ plugins: Map<string, Plugin>;
41
+ /**
42
+ * Promise that resolves when initialization is complete
43
+ */
44
+ readyPromise: Promise<void> | null;
45
+ }
46
+ /**
47
+ * Dependency definition for a plugin.
48
+ * Used to declare that a plugin requires another plugin to be present.
49
+ * @public
50
+ */
51
+ export type PluginDependency = string;
52
+ /**
53
+ * Plugin interface for extending SDK functionality.
54
+ * Plugins are the standard way to add capabilities to the SDK.
55
+ * @template Options - Plugin-specific options type
56
+ * @template Adapter - Plugin-specific adapter type
57
+ * @public
58
+ */
59
+ export interface Plugin<Options = unknown, Adapter = unknown> {
60
+ /**
61
+ * Unique identifier for the plugin (e.g., 'EventsPlugin')
62
+ */
63
+ name: string;
64
+ /**
65
+ * Optional plugin-specific options
66
+ */
67
+ options?: Options;
68
+ /**
69
+ * List of plugins this plugin depends on
70
+ */
71
+ dependencies?: PluginDependency[];
72
+ /**
73
+ * Initialization function run once when init is called for the first time.
74
+ * Can be async for plugins that need to perform async setup.
75
+ */
76
+ init?: () => void | Promise<void>;
77
+ /**
78
+ * Optional adapter requirements for the plugin.
79
+ */
80
+ adapter?: Adapter;
81
+ }
82
+ /**
83
+ * Adapter definition for plugins.
84
+ * @internal
85
+ */
86
+ export interface PluginAdapter {
87
+ type: 'browser' | (string & {});
88
+ }
89
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/initialization/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC,4BAA4B;IAC5B,MAAM,EAAE;QACN;;WAEG;QACH,SAAS,EAAE,MAAM,CAAC;QAClB;;WAEG;QACH,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB;;WAEG;QACH,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;IACF,qCAAqC;IACrC,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,MAAM,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IACjE;;OAEG;IACH,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B;;OAEG;IACH,YAAY,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CACpC;AAED;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAEtC;;;;;;GAMG;AACH,MAAM,WAAW,MAAM,CAAC,OAAO,GAAG,OAAO,EAAE,OAAO,GAAG,OAAO;IAC1D;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;OAEG;IACH,YAAY,CAAC,EAAE,gBAAgB,EAAE,CAAC;IAClC;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClC;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,SAAS,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;CACjC"}
@@ -1 +1 @@
1
- {"version":3,"file":"flow.d.ts","sourceRoot":"","sources":["../../../src/tools/auth/flow.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAUtC;;;;;;;;;;;;;;GAcG;AACH,eAAO,IAAI,qBAAqB,+BAAyB,CAAC;AAK1D,eAAO,MAAM,SAAS;;CAOrB,CAAC;AAEF,iBAAe,sBAAsB,CAAC,EACpC,QAAQ,EACR,YAAY,EACZ,cAAc,EACd,QAAQ,EACR,QAAyC,EACzC,SAAwC,EACxC,OAAwC,GACzC,EAAE,UAAU;;;;;;GAwCZ"}
1
+ {"version":3,"file":"flow.d.ts","sourceRoot":"","sources":["../../../src/tools/auth/flow.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAWtC;;;;;;;;;;;;;;GAcG;AACH,eAAO,IAAI,qBAAqB,+BAAyB,CAAC;AAK1D,eAAO,MAAM,SAAS;;CAOrB,CAAC;AAEF,iBAAe,sBAAsB,CAAC,EACpC,QAAQ,EACR,YAAY,EACZ,cAAc,EACd,QAAQ,EACR,QAAyC,EACzC,SAAwC,EACxC,OAAwC,GACzC,EAAE,UAAU;;;;;;GAwCZ"}
@@ -1 +1 @@
1
- {"version":3,"file":"timeout-promise.d.ts","sourceRoot":"","sources":["../../src/tools/timeout-promise.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,cAAc;IAGrB,OAAO,CAAC,OAAO;IAF3B,SAAS,EAAE,MAAM,CAAC,OAAO,GAAG,SAAS,CAAC;gBAElB,OAAO,EAAE,MAAM;IAInC;;OAEG;IACH,IAAI,KAAK,IAAI,OAAO,CAAC,OAAO,CAAC,CAQ5B;IAED;;OAEG;IACH,KAAK;CAGN"}
1
+ {"version":3,"file":"timeout-promise.d.ts","sourceRoot":"","sources":["../../src/tools/timeout-promise.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,cAAc;IAGrB,OAAO,CAAC,OAAO;IAF3B,SAAS,EAAE,MAAM,CAAC,OAAO,GAAG,SAAS,CAAC;gBAElB,OAAO,EAAE,MAAM;IAInC;;OAEG;IACH,IAAI,KAAK,IAAI,OAAO,CAAC,OAAO,CAAC,CAW5B;IAED;;OAEG;IACH,KAAK;CAGN"}