@sitecore-content-sdk/core 0.3.0-canary.2 → 0.3.0-canary.20

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 (52) hide show
  1. package/config-cli.d.ts +1 -0
  2. package/config-cli.js +1 -0
  3. package/dist/cjs/client/sitecore-client.js +3 -7
  4. package/dist/cjs/client/utils.js +7 -0
  5. package/dist/cjs/config/define-config.js +57 -17
  6. package/dist/cjs/config/index.js +1 -3
  7. package/dist/cjs/config-cli/index.js +5 -0
  8. package/dist/cjs/editing/design-library.js +10 -0
  9. package/dist/cjs/editing/index.js +3 -1
  10. package/dist/cjs/editing/models.js +9 -1
  11. package/dist/cjs/editing/rest-component-layout-service.js +31 -45
  12. package/dist/cjs/site/graphql-robots-service.js +1 -0
  13. package/dist/cjs/tools/generate-map.js +2 -0
  14. package/dist/cjs/tools/templating/components.js +53 -12
  15. package/dist/cjs/tools/templating/index.js +3 -1
  16. package/dist/cjs/tools/templating/utils.js +25 -1
  17. package/dist/esm/client/sitecore-client.js +3 -7
  18. package/dist/esm/client/utils.js +7 -0
  19. package/dist/esm/config/define-config.js +56 -17
  20. package/dist/esm/config/index.js +0 -1
  21. package/dist/esm/config-cli/index.js +1 -0
  22. package/dist/esm/editing/design-library.js +9 -0
  23. package/dist/esm/editing/index.js +2 -2
  24. package/dist/esm/editing/models.js +8 -0
  25. package/dist/esm/editing/rest-component-layout-service.js +28 -45
  26. package/dist/esm/site/graphql-robots-service.js +1 -0
  27. package/dist/esm/tools/generate-map.js +1 -0
  28. package/dist/esm/tools/templating/components.js +20 -12
  29. package/dist/esm/tools/templating/index.js +1 -0
  30. package/dist/esm/tools/templating/utils.js +23 -1
  31. package/package.json +3 -2
  32. package/types/config/define-config.d.ts +7 -1
  33. package/types/config/index.d.ts +0 -1
  34. package/types/config/models.d.ts +16 -0
  35. package/types/{config → config-cli}/define-cli-config.d.ts +1 -1
  36. package/types/config-cli/index.d.ts +1 -0
  37. package/types/editing/design-library.d.ts +7 -0
  38. package/types/editing/index.d.ts +2 -2
  39. package/types/editing/models.d.ts +10 -3
  40. package/types/editing/rest-component-layout-service.d.ts +28 -58
  41. package/types/native-fetcher.d.ts +0 -7
  42. package/types/site/graphql-robots-service.d.ts +1 -0
  43. package/types/tools/generate-map.d.ts +18 -0
  44. package/types/tools/index.d.ts +1 -0
  45. package/types/tools/templating/components.d.ts +16 -9
  46. package/types/tools/templating/index.d.ts +2 -1
  47. package/types/tools/templating/utils.d.ts +8 -0
  48. package/dist/cjs/data-fetcher.js +0 -22
  49. package/dist/esm/data-fetcher.js +0 -17
  50. package/types/data-fetcher.d.ts +0 -34
  51. /package/dist/cjs/{config → config-cli}/define-cli-config.js +0 -0
  52. /package/dist/esm/{config → config-cli}/define-cli-config.js +0 -0
@@ -0,0 +1,18 @@
1
+ import { ComponentFile, ComponentImport } from './templating';
2
+ export type GenerateMapFunction = (args: GenerateMapArgs) => void;
3
+ /**
4
+ * Arguments for the generateMap function.
5
+ * @typedef GenerateMapArgs
6
+ * @property {string[]} paths - Array of component paths to include in component map.
7
+ * @property {string} [destination='src/.sitecore'] - Destination folder path for the generated map.
8
+ * @property {ComponentImport[]} [componentImports] - Optional array of package definitions for component imports to include in the map.
9
+ * @property {string[]} [exclude] - Optional array of glob paths to exclude from the map.
10
+ * @property {function} [mapTemplate] - Optional custom template function to generate the component map content.
11
+ */
12
+ export type GenerateMapArgs = {
13
+ paths: string[];
14
+ destination?: string;
15
+ componentImports?: ComponentImport[];
16
+ exclude?: string[];
17
+ mapTemplate?: (components: ComponentFile[], componentImports?: ComponentImport[]) => string;
18
+ };
@@ -1,4 +1,5 @@
1
1
  export { generateSites, GenerateSitesConfig } from './generateSites';
2
2
  export { generateMetadata } from './generateMetadata';
3
3
  export { scaffoldComponent } from './scaffold';
4
+ export { GenerateMapFunction, GenerateMapArgs } from './generate-map';
4
5
  export * from './templating';
@@ -7,14 +7,20 @@ export interface ComponentFile {
7
7
  componentName: string;
8
8
  }
9
9
  /**
10
- * Describes a package and components to be imported
10
+ * Definition for custom components to be included in component map.
11
+ * Use this to define components imported from modules/dependencies/packages
12
+ * @typedef ComponentImport
13
+ * @property {string} importName - Name of the import.
14
+ * @property {object} importInfo - Information about how to import the package.
15
+ * @property {string} importInfo.importFrom - The path from which to import the component(s).
16
+ * @property {string[]} [importInfo.namedImports] - The specific named components to import from the package. Leave empty to have whole package be imported as wildcard and allow SXA variants support for component.
11
17
  */
12
- export interface PackageDefinition {
13
- name: string;
14
- components: {
15
- moduleName: string;
16
- componentName: string;
17
- }[];
18
+ export interface ComponentImport {
19
+ importName: string;
20
+ importInfo: {
21
+ importFrom: string;
22
+ namedImports?: string[];
23
+ };
18
24
  }
19
25
  /**
20
26
  * Get list of components from @var path
@@ -24,6 +30,7 @@ export interface PackageDefinition {
24
30
  * componentName: 'ComponentName',
25
31
  * moduleName: 'ComponentName'
26
32
  * }
27
- * @param {string} path path to search
33
+ * @param {string[]} paths paths to search
34
+ * @param {string[]} [exclude] paths and glob patterns to exclude from final result
28
35
  */
29
- export declare function getComponentList(path: string): ComponentFile[];
36
+ export declare function getComponentList(paths: string[], exclude?: string[]): ComponentFile[];
@@ -1,2 +1,3 @@
1
- export { ComponentFile, PackageDefinition, getComponentList } from './components';
1
+ export { ComponentFile, ComponentImport, getComponentList } from './components';
2
2
  export { PluginDefinition, generatePlugins, ModuleType } from './plugins';
3
+ export { matchPath } from './utils';
@@ -14,6 +14,7 @@ export type GetItemsSettings<Item> = {
14
14
  * Will be called when new file is found
15
15
  */
16
16
  cb?: (name: string) => void;
17
+ exclude?: string[];
17
18
  /**
18
19
  * Matches specific files format
19
20
  */
@@ -23,6 +24,13 @@ export type GetItemsSettings<Item> = {
23
24
  */
24
25
  recursive?: boolean;
25
26
  };
27
+ /**
28
+ * Compares two paths to determine if they match.
29
+ * @param {string} itemPath base path to compare against, can be absolute or relative
30
+ * @param {string} compare comparer, can be relate, absolute or regex string
31
+ * @returns true if paths match, false otherwise
32
+ */
33
+ export declare const matchPath: (itemPath: string, compare: string) => boolean;
26
34
  /**
27
35
  * Using @var path find all files and generate output using @var resolveItem function for each file
28
36
  * Can be used to generate list of components, templates, etc.
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ResponseError = void 0;
4
- exports.fetchData = fetchData;
5
- const utils_1 = require("./utils/utils");
6
- class ResponseError extends Error {
7
- constructor(message, response) {
8
- super(message);
9
- Object.setPrototypeOf(this, ResponseError.prototype);
10
- this.response = response;
11
- }
12
- }
13
- exports.ResponseError = ResponseError;
14
- /**
15
- * @param {string} url the URL to request; may include query string
16
- * @param {HttpDataFetcher<T> | NativeDataFetcherFunction<T>} fetcher the fetcher to use to perform the request
17
- * @param {ParsedUrlQueryInput} params the query string parameters to send with the request
18
- */
19
- async function fetchData(url, fetcher, params = {}) {
20
- const response = await fetcher((0, utils_1.resolveUrl)(url, params));
21
- return response.data;
22
- }
@@ -1,17 +0,0 @@
1
- import { resolveUrl } from './utils/utils';
2
- export class ResponseError extends Error {
3
- constructor(message, response) {
4
- super(message);
5
- Object.setPrototypeOf(this, ResponseError.prototype);
6
- this.response = response;
7
- }
8
- }
9
- /**
10
- * @param {string} url the URL to request; may include query string
11
- * @param {HttpDataFetcher<T> | NativeDataFetcherFunction<T>} fetcher the fetcher to use to perform the request
12
- * @param {ParsedUrlQueryInput} params the query string parameters to send with the request
13
- */
14
- export async function fetchData(url, fetcher, params = {}) {
15
- const response = await fetcher(resolveUrl(url, params));
16
- return response.data;
17
- }
@@ -1,34 +0,0 @@
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>;