@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
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { GraphQLClient } from '../graphql';
|
|
2
|
+
import { GraphQLRequestClientFactory } from '../graphql-request-client';
|
|
3
|
+
export type GraphQLSitemapXmlServiceConfig = {
|
|
4
|
+
/**
|
|
5
|
+
* The JSS application name
|
|
6
|
+
*/
|
|
7
|
+
siteName: string;
|
|
8
|
+
/**
|
|
9
|
+
* A GraphQL Request Client Factory is a function that accepts configuration and returns an instance of a GraphQLRequestClient.
|
|
10
|
+
* This factory function is used to create and configure GraphQL clients for making GraphQL API requests.
|
|
11
|
+
*/
|
|
12
|
+
clientFactory: GraphQLRequestClientFactory;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* The schema of data returned in response to sitemaps request
|
|
16
|
+
*/
|
|
17
|
+
export type SitemapQueryResult = {
|
|
18
|
+
site: {
|
|
19
|
+
siteInfo: {
|
|
20
|
+
sitemap: string[];
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Service that fetch the sitemaps data using Sitecore's GraphQL API.
|
|
26
|
+
*/
|
|
27
|
+
export declare class GraphQLSitemapXmlService {
|
|
28
|
+
options: GraphQLSitemapXmlServiceConfig;
|
|
29
|
+
private graphQLClient;
|
|
30
|
+
/**
|
|
31
|
+
* Creates an instance of graphQL sitemaps service with the provided options
|
|
32
|
+
* @param {GraphQLSitemapXmlServiceConfig} options instance
|
|
33
|
+
*/
|
|
34
|
+
constructor(options: GraphQLSitemapXmlServiceConfig);
|
|
35
|
+
protected get query(): string;
|
|
36
|
+
/**
|
|
37
|
+
* Fetch list of sitemaps for the site
|
|
38
|
+
* @returns {string[]} list of sitemap paths
|
|
39
|
+
* @throws {Error} if the siteName is empty.
|
|
40
|
+
*/
|
|
41
|
+
fetchSitemaps(): Promise<string[]>;
|
|
42
|
+
/**
|
|
43
|
+
* Get sitemap file path for sitemap id
|
|
44
|
+
* @param {string} id the sitemap id (can be empty for default 'sitemap.xml' file)
|
|
45
|
+
* @returns {string | undefined} the sitemap file path or undefined if one doesn't exist
|
|
46
|
+
*/
|
|
47
|
+
getSitemap(id: string): Promise<string | undefined>;
|
|
48
|
+
/**
|
|
49
|
+
* Gets a GraphQL client that can make requests to the API. Uses graphql-request as the default
|
|
50
|
+
* library for fetching graphql data (@see GraphQLRequestClient). Override this method if you
|
|
51
|
+
* want to use something else.
|
|
52
|
+
* @returns {GraphQLClient} implementation
|
|
53
|
+
*/
|
|
54
|
+
protected getGraphQLClient(): GraphQLClient;
|
|
55
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { RobotsQueryResult, GraphQLRobotsService, GraphQLRobotsServiceConfig, } from './graphql-robots-service';
|
|
2
|
+
export { RedirectInfo, RedirectsQueryResult, REDIRECT_TYPE_301, REDIRECT_TYPE_302, REDIRECT_TYPE_SERVER_TRANSFER, GraphQLRedirectsService, GraphQLRedirectsServiceConfig, } from './graphql-redirects-service';
|
|
3
|
+
export { SitemapQueryResult, GraphQLSitemapXmlService, GraphQLSitemapXmlServiceConfig, } from './graphql-sitemap-service';
|
|
4
|
+
export { ErrorPages, GraphQLErrorPagesService, GraphQLErrorPagesServiceConfig, } from './graphql-error-pages-service';
|
|
5
|
+
export { SiteInfo, GraphQLSiteInfoService, GraphQLSiteInfoServiceConfig, } from './graphql-siteinfo-service';
|
|
6
|
+
export { getSiteRewrite, getSiteRewriteData, normalizeSiteRewrite, SiteRewriteData } from './utils';
|
|
7
|
+
export { SiteResolver } from './site-resolver';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { SiteInfo } from './graphql-siteinfo-service';
|
|
2
|
+
/**
|
|
3
|
+
* Resolves site based on the provided host or site name
|
|
4
|
+
*/
|
|
5
|
+
export declare class SiteResolver {
|
|
6
|
+
readonly sites: SiteInfo[];
|
|
7
|
+
/**
|
|
8
|
+
* @param {SiteInfo[]} sites Array of sites to be used in resolution
|
|
9
|
+
*/
|
|
10
|
+
constructor(sites: SiteInfo[]);
|
|
11
|
+
/**
|
|
12
|
+
* Resolve site by host name
|
|
13
|
+
* @param {string} hostName the host name
|
|
14
|
+
* @returns {SiteInfo} the resolved site
|
|
15
|
+
* @throws {Error} if a matching site is not found
|
|
16
|
+
*/
|
|
17
|
+
getByHost: (hostName: string) => SiteInfo;
|
|
18
|
+
/**
|
|
19
|
+
* Resolve site by site name
|
|
20
|
+
* @param {string} siteName the site name
|
|
21
|
+
* @returns {SiteInfo} the resolved site
|
|
22
|
+
* @throws {Error} if a matching site is not found
|
|
23
|
+
*/
|
|
24
|
+
getByName: (siteName: string) => SiteInfo;
|
|
25
|
+
protected getHostMap: () => Map<string, SiteInfo>;
|
|
26
|
+
protected matchesPattern(hostname: string, pattern: string): boolean;
|
|
27
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare const SITE_PREFIX = "_site_";
|
|
2
|
+
export type SiteRewriteData = {
|
|
3
|
+
siteName: string;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Get a site rewrite path for given pathname
|
|
7
|
+
* @param {string} pathname the pathname
|
|
8
|
+
* @param {SiteRewriteData} data the site data to include in the rewrite
|
|
9
|
+
* @returns {string} the rewrite path
|
|
10
|
+
*/
|
|
11
|
+
export declare function getSiteRewrite(pathname: string, data: SiteRewriteData): string;
|
|
12
|
+
/**
|
|
13
|
+
* Get site data from the rewrite path
|
|
14
|
+
* @param {string} pathname the pathname
|
|
15
|
+
* @param {string} defaultSiteName the default site name
|
|
16
|
+
* @returns {SiteRewriteData} the site data from the rewrite
|
|
17
|
+
*/
|
|
18
|
+
export declare function getSiteRewriteData(pathname: string, defaultSiteName: string): SiteRewriteData;
|
|
19
|
+
/**
|
|
20
|
+
* Normalize a site rewrite path (remove site data)
|
|
21
|
+
* @param {string} pathname the pathname
|
|
22
|
+
* @returns {string} the pathname with site data removed
|
|
23
|
+
*/
|
|
24
|
+
export declare function normalizeSiteRewrite(pathname: string): string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Method to parse JSON-formatted environment variables
|
|
3
|
+
* @param {string} envValue - can be undefined when providing values via process.env
|
|
4
|
+
* @param {T} defaultValue - default value
|
|
5
|
+
* @returns {T | string} parsed value
|
|
6
|
+
*/
|
|
7
|
+
export declare const tryParseEnvValue: <T>(envValue: string | undefined, defaultValue: T) => T;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { default as isServer } from './is-server';
|
|
2
|
+
export { resolveUrl, isAbsoluteUrl, isTimeoutError, enforceCors, EnhancedOmit, getAllowedOriginsFromEnv, isRegexOrUrl, areURLSearchParamsEqual, escapeNonSpecialQuestionMarks, mergeURLSearchParams, } from './utils';
|
|
3
|
+
export { tryParseEnvValue } from './env';
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
private timeout;
|
|
7
|
+
timeoutId: NodeJS.Timeout | undefined;
|
|
8
|
+
constructor(timeout: number);
|
|
9
|
+
/**
|
|
10
|
+
* Creates a timeout promise
|
|
11
|
+
*/
|
|
12
|
+
get start(): Promise<unknown>;
|
|
13
|
+
/**
|
|
14
|
+
* Clears the timeout from timeout promise
|
|
15
|
+
*/
|
|
16
|
+
clear(): void;
|
|
17
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { IncomingMessage, OutgoingMessage } from 'http';
|
|
2
|
+
import { ParsedUrlQueryInput } from 'querystring';
|
|
3
|
+
/**
|
|
4
|
+
* Omit properties from T that are in K. This is a simplified version of TypeScript's built-in `Omit` utility type.
|
|
5
|
+
* Since default `Omit` doesn't support indexing types, we had to introduce this custom implementation.
|
|
6
|
+
*/
|
|
7
|
+
export type EnhancedOmit<T, K extends PropertyKey> = {
|
|
8
|
+
[P in keyof T as Exclude<P, K>]: T[P];
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Resolves a base URL that may contain query string parameters and an additional set of query
|
|
12
|
+
* string parameters into a unified string representation.
|
|
13
|
+
* @param {string} urlBase the base URL that may contain query string parameters
|
|
14
|
+
* @param {ParsedUrlQueryInput} params query string parameters
|
|
15
|
+
* @returns a URL string
|
|
16
|
+
* @throws {RangeError} if the provided url is an empty string
|
|
17
|
+
*/
|
|
18
|
+
export declare function resolveUrl(urlBase: string, params?: ParsedUrlQueryInput): string;
|
|
19
|
+
export declare const isAbsoluteUrl: (url: string) => boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Indicates whether the error is a timeout error
|
|
22
|
+
* @param {unknown} error error
|
|
23
|
+
* @returns {boolean} is timeout error
|
|
24
|
+
*/
|
|
25
|
+
export declare const isTimeoutError: (error: unknown) => boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Gets allowed origins from JSS_ALLOWED_ORIGINS env variable
|
|
28
|
+
* @returns {string[]} list of allowed origins from JSS_ALLOWED_ORIGINS env variable
|
|
29
|
+
*/
|
|
30
|
+
export declare const getAllowedOriginsFromEnv: () => string[];
|
|
31
|
+
/**
|
|
32
|
+
* Tests origin from incoming request against allowed origins list that can be
|
|
33
|
+
* set in JSS's JSS_ALLOWED_ORIGINS env variable, passed via allowedOrigins param and/or
|
|
34
|
+
* be already set in Access-Control-Allow-Origin by other logic.
|
|
35
|
+
* Applies Access-Control-Allow-Origin and Access-Control-Allow-Methods on match
|
|
36
|
+
* Also applies Access-Control-Allow-Headers for preflight requests
|
|
37
|
+
* @param {IncomingMessage} req incoming request
|
|
38
|
+
* @param {OutgoingMessage} res response to set CORS headers for
|
|
39
|
+
* @param {string[]} [allowedOrigins] additional list of origins to test against
|
|
40
|
+
* @returns true if incoming origin matches the allowed lists, false when it does not
|
|
41
|
+
*/
|
|
42
|
+
export declare const enforceCors: (req: IncomingMessage, res: OutgoingMessage, allowedOrigins?: string[]) => boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Determines whether the given input is a regular expression or resembles a URL.
|
|
45
|
+
* @param {string} input - The input string to evaluate.
|
|
46
|
+
* @returns {'regex' | 'url'} - Returns 'url' if the input looks like a URL, otherwise 'regex'.
|
|
47
|
+
*/
|
|
48
|
+
export declare const isRegexOrUrl: (input: string) => "regex" | "url";
|
|
49
|
+
/**
|
|
50
|
+
* Compares two URLSearchParams objects to determine if they are equal.
|
|
51
|
+
* @param {URLSearchParams} params1 - The first set of URL search parameters.
|
|
52
|
+
* @param {URLSearchParams} params2 - The second set of URL search parameters.
|
|
53
|
+
* @returns {boolean} - Returns true if the parameters are equal, otherwise false.
|
|
54
|
+
*/
|
|
55
|
+
export declare const areURLSearchParamsEqual: (params1: URLSearchParams, params2: URLSearchParams) => boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Escapes non-special "?" characters in a string or regex.
|
|
58
|
+
* - For regular strings, it escapes all unescaped "?" characters by adding a backslash (`\`).
|
|
59
|
+
* - For regex patterns (strings enclosed in `/.../`), it analyzes each "?" to determine if it has special meaning
|
|
60
|
+
* (e.g., `?` in `(abc)?`, `.*?`, `(?!...)`) or is just a literal character. Only literal "?" characters are escaped.
|
|
61
|
+
* @param {string} input - The input string or regex pattern.
|
|
62
|
+
* @returns {string} - The modified string or regex with non-special "?" characters escaped.
|
|
63
|
+
*/
|
|
64
|
+
export declare const escapeNonSpecialQuestionMarks: (input: string) => string;
|
|
65
|
+
/**
|
|
66
|
+
* Merges two URLSearchParams objects. If both objects contain the same key, the value from the second object overrides the first.
|
|
67
|
+
* @param {URLSearchParams} params1 - The first set of URL search parameters.
|
|
68
|
+
* @param {URLSearchParams} params2 - The second set of URL search parameters.
|
|
69
|
+
* @returns {string} - A string representation of the merged URL search parameters.
|
|
70
|
+
*/
|
|
71
|
+
export declare const mergeURLSearchParams: (params1: URLSearchParams, params2: URLSearchParams) => string;
|
package/utils.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './types/utils/index';
|
package/utils.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/cjs/utils/index');
|