@sitecore-jss/sitecore-jss-nextjs 21.7.0-canary.3 → 21.7.0-canary.30

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 (36) hide show
  1. package/context.d.ts +1 -0
  2. package/context.js +1 -0
  3. package/dist/cjs/context/context.js +63 -0
  4. package/dist/cjs/context/index.js +5 -0
  5. package/dist/cjs/editing/editing-render-middleware.js +1 -1
  6. package/dist/cjs/index.js +5 -3
  7. package/dist/cjs/middleware/middleware.js +17 -0
  8. package/dist/cjs/middleware/multisite-middleware.js +1 -6
  9. package/dist/cjs/middleware/personalize-middleware.js +34 -47
  10. package/dist/cjs/middleware/redirects-middleware.js +14 -9
  11. package/dist/cjs/revalidate/index.js +5 -0
  12. package/dist/cjs/revalidate/revalidate-middleware.js +216 -0
  13. package/dist/cjs/utils/utils.js +6 -18
  14. package/dist/esm/context/context.js +59 -0
  15. package/dist/esm/context/index.js +1 -0
  16. package/dist/esm/editing/editing-render-middleware.js +1 -1
  17. package/dist/esm/index.js +3 -2
  18. package/dist/esm/middleware/middleware.js +17 -0
  19. package/dist/esm/middleware/multisite-middleware.js +1 -6
  20. package/dist/esm/middleware/personalize-middleware.js +35 -48
  21. package/dist/esm/middleware/redirects-middleware.js +14 -9
  22. package/dist/esm/revalidate/index.js +1 -0
  23. package/dist/esm/revalidate/revalidate-middleware.js +212 -0
  24. package/dist/esm/utils/utils.js +6 -15
  25. package/package.json +10 -9
  26. package/revalidate.d.ts +1 -0
  27. package/revalidate.js +1 -0
  28. package/types/context/context.d.ts +104 -0
  29. package/types/context/index.d.ts +1 -0
  30. package/types/editing/editing-render-middleware.d.ts +1 -1
  31. package/types/index.d.ts +3 -2
  32. package/types/middleware/middleware.d.ts +8 -0
  33. package/types/middleware/personalize-middleware.d.ts +20 -15
  34. package/types/revalidate/index.d.ts +1 -0
  35. package/types/revalidate/revalidate-middleware.d.ts +115 -0
  36. package/types/utils/utils.d.ts +1 -0
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Software Development Kit (SDK) instance
3
+ */
4
+ export type SDK<SDKType = unknown> = {
5
+ /**
6
+ * The Software Development Kit (SDK) library instance
7
+ */
8
+ sdk: SDKType;
9
+ /**
10
+ * Initializes the Software Development Kit (SDK)
11
+ */
12
+ init: (props: InitSDKProps) => Promise<void>;
13
+ };
14
+ /**
15
+ * Software Development Kits (SDKs) to be initialized
16
+ */
17
+ type SDKModulesType = Record<string, SDK>;
18
+ /**
19
+ * Properties that are passed to the Context.
20
+ */
21
+ export interface ContextInitProps {
22
+ /**
23
+ * Your Sitecore site name
24
+ */
25
+ siteName?: string;
26
+ }
27
+ /**
28
+ * Configuration that is passed to the Context.
29
+ */
30
+ export interface ContextConfig<SDKModules extends SDKModulesType> {
31
+ /**
32
+ * Your Sitecore Edge URL
33
+ */
34
+ sitecoreEdgeUrl: string;
35
+ /**
36
+ * Your Sitecore Edge Context ID
37
+ */
38
+ sitecoreEdgeContextId: string;
39
+ /**
40
+ * Your Sitecore site name
41
+ */
42
+ siteName: string;
43
+ /**
44
+ * Software Development Kits (SDKs) to be initialized
45
+ */
46
+ sdks: {
47
+ [module in keyof SDKModules]: SDKModules[module];
48
+ };
49
+ }
50
+ /**
51
+ * Properties that are passed to the Software Development Kit (SDK) initialization function.
52
+ */
53
+ type InitSDKProps = Omit<ContextConfig<SDKModulesType>, 'sdks'>;
54
+ /**
55
+ * Context instance that is used to initialize the application Context and associated Software Development Kits (SDKs).
56
+ */
57
+ export declare class Context<SDKModules extends SDKModulesType> {
58
+ protected props: ContextConfig<SDKModules>;
59
+ /**
60
+ * Indicates whether the Context and SDK(s) have been initialized
61
+ */
62
+ isInitialized: boolean;
63
+ /**
64
+ * The Sitecore Edge URL
65
+ */
66
+ readonly sitecoreEdgeUrl: string;
67
+ /**
68
+ * The Sitecore Edge Context ID
69
+ */
70
+ readonly sitecoreEdgeContextId: string;
71
+ /**
72
+ * The Sitecore site name
73
+ */
74
+ siteName: string;
75
+ /**
76
+ * Software Development Kits (SDKs) to be initialized
77
+ */
78
+ readonly sdks: {
79
+ [module in keyof SDKModules]?: SDKModules[module]['sdk'];
80
+ };
81
+ /**
82
+ * Promises for the SDKs
83
+ */
84
+ protected sdkPromises: {
85
+ [module in keyof SDKModules]?: Promise<SDKModules[module]['sdk']>;
86
+ };
87
+ constructor(props: ContextConfig<SDKModules>);
88
+ init(props?: ContextInitProps): void;
89
+ /**
90
+ * Retrieves the Software Development Kit (SDK) instance, ensuring it is initialized before returning
91
+ *
92
+ * @param {string} name SDK name
93
+ * @returns initialized SDK
94
+ */
95
+ getSDK: <T extends keyof SDKModules>(name: T) => Promise<SDKModules[T]["sdk"]>;
96
+ /**
97
+ * Initializes the Software Development Kit (SDK)
98
+ *
99
+ * @param {T} name SDK name
100
+ * @returns {void}
101
+ */
102
+ protected initSDK<T extends keyof SDKModules>(name: T): void;
103
+ }
104
+ export {};
@@ -0,0 +1 @@
1
+ export { Context, ContextConfig, SDK } from './context';
@@ -57,7 +57,7 @@ export declare class EditingRenderMiddleware {
57
57
  getHandler(): (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
58
58
  /**
59
59
  * Gets query parameters that should be passed along to subsequent requests
60
- * @param query Object of query parameters from incoming URL
60
+ * @param {Object} query Object of query parameters from incoming URL
61
61
  * @returns Object of approved query parameters
62
62
  */
63
63
  protected getQueryParamsForPropagation: (query: Partial<{
package/types/index.d.ts CHANGED
@@ -8,11 +8,11 @@ declare const GraphQLRequestClient: typeof GraphQLRequestClientDep;
8
8
  export { GraphQLRequestClient };
9
9
  export { handleEditorFastRefresh, getPublicUrl };
10
10
  export { isEditorActive, resetEditorChromes, resolveUrl, tryParseEnvValue };
11
- export { LayoutService, LayoutServiceData, LayoutServicePageState, LayoutServiceContext, LayoutServiceContextData, GraphQLLayoutService, GraphQLLayoutServiceConfig, RestLayoutService, RestLayoutServiceConfig, PlaceholderData, PlaceholdersData, RouteData, Field, Item, HtmlElementRendering, getChildPlaceholder, getFieldValue, ComponentRendering, ComponentFields, ComponentParams, RenderingType, EDITING_COMPONENT_PLACEHOLDER, EDITING_COMPONENT_ID, } from '@sitecore-jss/sitecore-jss/layout';
11
+ export { LayoutService, LayoutServiceData, LayoutServicePageState, LayoutServiceContext, LayoutServiceContextData, GraphQLLayoutService, GraphQLLayoutServiceConfig, RestLayoutService, RestLayoutServiceConfig, PlaceholderData, PlaceholdersData, RouteData, Field, Item, HtmlElementRendering, getChildPlaceholder, getFieldValue, ComponentRendering, ComponentFields, ComponentParams, RenderingType, EDITING_COMPONENT_PLACEHOLDER, EDITING_COMPONENT_ID, getContentStylesheetLink, } from '@sitecore-jss/sitecore-jss/layout';
12
12
  export { mediaApi } from '@sitecore-jss/sitecore-jss/media';
13
13
  export { trackingApi, TrackingRequestOptions, CampaignInstance, GoalInstance, OutcomeInstance, EventInstance, PageViewInstance, } from '@sitecore-jss/sitecore-jss/tracking';
14
14
  export { DictionaryPhrases, DictionaryService, GraphQLDictionaryService, GraphQLDictionaryServiceConfig, RestDictionaryService, RestDictionaryServiceConfig, } from '@sitecore-jss/sitecore-jss/i18n';
15
- export { personalizeLayout, getPersonalizedRewrite, getPersonalizedRewriteData, normalizePersonalizedRewrite, CdpHelper, PosResolver, } from '@sitecore-jss/sitecore-jss/personalize';
15
+ export { personalizeLayout, getPersonalizedRewrite, getPersonalizedRewriteData, normalizePersonalizedRewrite, CdpHelper, } from '@sitecore-jss/sitecore-jss/personalize';
16
16
  export { ComponentPropsCollection, ComponentPropsError, GetStaticComponentProps, GetServerSideComponentProps, } from './sharedTypes/component-props';
17
17
  export { ModuleFactory, Module } from './sharedTypes/module-factory';
18
18
  export { ComponentPropsService } from './services/component-props-service';
@@ -32,4 +32,5 @@ import * as BYOCWrapper from './components/BYOCWrapper';
32
32
  export { FEaaSWrapper };
33
33
  export { BYOCWrapper };
34
34
  export { ComponentBuilder, ComponentBuilderConfig } from './ComponentBuilder';
35
+ export { Context, ContextConfig, SDK } from './context';
35
36
  export { ComponentFactory, Image, ImageField, ImageFieldValue, ImageProps, LinkField, LinkFieldValue, Text, TextField, DateField, EditFrame, FEaaSComponent, FEaaSComponentProps, FEaaSComponentParams, fetchFEaaSComponentServerProps, BYOCComponentParams, BYOCComponent, BYOCComponentProps, getFEAASLibraryStylesheetLinks, File, FileField, RichTextField, VisitorIdentification, PlaceholderComponentProps, SitecoreContext, SitecoreContextState, SitecoreContextValue, SitecoreContextReactContext, withSitecoreContext, useSitecoreContext, withEditorChromes, withPlaceholder, withDatasourceCheck, ImageSizeParameters, ComponentConsumerProps, WithSitecoreContextOptions, WithSitecoreContextProps, } from '@sitecore-jss/sitecore-jss-react';
@@ -28,6 +28,7 @@ export type MiddlewareBaseConfig = {
28
28
  export declare abstract class MiddlewareBase {
29
29
  protected config: MiddlewareBaseConfig;
30
30
  protected SITE_SYMBOL: string;
31
+ protected REWRITE_HEADER_NAME: string;
31
32
  protected defaultHostname: string;
32
33
  constructor(config: MiddlewareBaseConfig);
33
34
  /**
@@ -65,4 +66,11 @@ export declare abstract class MiddlewareBase {
65
66
  * @returns {SiteInfo} site information
66
67
  */
67
68
  protected getSite(req: NextRequest, res?: NextResponse): SiteInfo;
69
+ /**
70
+ * Create a rewrite response
71
+ * @param {string} rewritePath the destionation path
72
+ * @param {NextRequest} req the current request
73
+ * @param {NextResponse} res the current response
74
+ */
75
+ protected rewrite(rewritePath: string, req: NextRequest, res: NextResponse): NextResponse;
68
76
  }
@@ -1,17 +1,16 @@
1
1
  import { NextResponse, NextRequest } from 'next/server';
2
- import { GraphQLPersonalizeServiceConfig } from '@sitecore-jss/sitecore-jss/personalize';
3
- import { SiteInfo } from '@sitecore-jss/sitecore-jss/site';
2
+ import { GraphQLPersonalizeServiceConfig, PersonalizeInfo } from '@sitecore-jss/sitecore-jss/personalize';
4
3
  import { MiddlewareBase, MiddlewareBaseConfig } from './middleware';
5
- import { EngageServer } from '@sitecore/engage';
6
4
  export type CdpServiceConfig = {
7
5
  /**
8
- * Your Sitecore CDP API endpoint
6
+ * Your Sitecore Edge Platform endpoint
7
+ * Default is https://edge-platform.sitecorecloud.io
9
8
  */
10
- endpoint: string;
9
+ sitecoreEdgeUrl?: string;
11
10
  /**
12
- * The client key to use for authentication
11
+ * Your unified Sitecore Edge Context Id
13
12
  */
14
- clientKey: string;
13
+ sitecoreEdgeContextId: string;
15
14
  /**
16
15
  * The Sitecore CDP channel to use for events. Uses 'WEB' by default.
17
16
  */
@@ -34,13 +33,6 @@ export type PersonalizeMiddlewareConfig = MiddlewareBaseConfig & {
34
33
  * Configuration for your Sitecore CDP endpoint
35
34
  */
36
35
  cdpConfig: CdpServiceConfig;
37
- /**
38
- * function to resolve point of sale for a site
39
- * @param {Siteinfo} site to get info from
40
- * @param {string} language to get info for
41
- * @returns point of sale value for site/language combination
42
- */
43
- getPointOfSale?: (site: SiteInfo, language: string) => string;
44
36
  };
45
37
  /**
46
38
  * Object model of Experience Context data
@@ -70,7 +62,20 @@ export declare class PersonalizeMiddleware extends MiddlewareBase {
70
62
  * @returns middleware handler
71
63
  */
72
64
  getHandler(): (req: NextRequest, res?: NextResponse) => Promise<NextResponse>;
73
- protected initializeEngageServer(hostName: string, site: SiteInfo, language: string): EngageServer;
65
+ protected initPersonalizeServer({ hostname, siteName, request, response, }: {
66
+ hostname: string;
67
+ siteName: string;
68
+ request: NextRequest;
69
+ response: NextResponse;
70
+ }): Promise<void>;
71
+ protected personalize({ params, personalizeInfo, language, timeout, }: {
72
+ personalizeInfo: PersonalizeInfo;
73
+ params: ExperienceParams;
74
+ language: string;
75
+ timeout?: number;
76
+ }, request: NextRequest): Promise<{
77
+ variantId: string;
78
+ }>;
74
79
  protected getExperienceParams(req: NextRequest): ExperienceParams;
75
80
  protected excludeRoute(pathname: string): boolean | undefined;
76
81
  private handler;
@@ -0,0 +1 @@
1
+ export { RevalidateMiddleware } from './revalidate-middleware';
@@ -0,0 +1,115 @@
1
+ import { NextApiResponse, NextApiRequest } from 'next';
2
+ import { GraphQLRequestClientFactory } from '@sitecore-jss/sitecore-jss/graphql';
3
+ declare enum EntityDefinition {
4
+ LayoutData = "LayoutData",
5
+ Item = "Item"
6
+ }
7
+ /**
8
+ * Object model of each updated entity returned from the webhook payload
9
+ */
10
+ export type Entity = {
11
+ identifier: string;
12
+ entity_definition: EntityDefinition;
13
+ operation: string;
14
+ entity_culture: string;
15
+ };
16
+ /**
17
+ * Object model for updated paths returned from the webhook payload
18
+ */
19
+ export type UpdatedPaths = {
20
+ path: string;
21
+ language: string;
22
+ };
23
+ /**
24
+ * Object model for personalized results from GraphqlPersonalizeService
25
+ */
26
+ export type PersonalizedResult = {
27
+ path: string;
28
+ variantId: string;
29
+ };
30
+ export type RevalidateConfig = {
31
+ /**
32
+ * A GraphQL Request Client Factory is a function that accepts configuration and returns an instance of a GraphQLRequestClient.
33
+ * This factory function is used to create and configure GraphQL clients for making GraphQL API requests.
34
+ */
35
+ clientFactory: GraphQLRequestClientFactory;
36
+ /**
37
+ * Indicates whether multisite functionality is enabled.
38
+ * Default is false
39
+ */
40
+ multiSite?: boolean;
41
+ /**
42
+ * Indicates whether personalization is enabled.
43
+ * Default is false
44
+ */
45
+ personalize?: boolean;
46
+ /**
47
+ * Function to handle language prefixes for different locales.
48
+ * @param language - The language to generate the prefix for.
49
+ * @returns The language prefix or null.
50
+ */
51
+ localePrefix?: (language: string) => string | null;
52
+ };
53
+ /**
54
+ * Middleware / handler for on-demand ISR (e.g. '/api/revalidate').
55
+ */
56
+ export declare class RevalidateMiddleware {
57
+ protected config: RevalidateConfig;
58
+ private personalizeService;
59
+ constructor(config: RevalidateConfig);
60
+ /**
61
+ * Generates a Next.js API route handler that executes a revalidation process.
62
+ * @returns The route handler function for handling Next.js API requests.
63
+ */
64
+ getHandler(): (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
65
+ /**
66
+ * Gets personalized results for the updated paths
67
+ * @param {UpdatedPaths[]} filteredUpdates Updated paths
68
+ */
69
+ getPersonalizedResults(filteredUpdates: UpdatedPaths[]): Promise<{
70
+ personalized: PersonalizedResult[];
71
+ nonPersonalized: {
72
+ path: string;
73
+ }[];
74
+ }>;
75
+ protected isEmpty(data: UpdatedPaths[]): boolean;
76
+ /**
77
+ * Extracts the paths from the updated paths
78
+ * @param {UpdatedPaths[]} filteredUpdates Updated paths
79
+ * @returns {string[]} paths
80
+ */
81
+ protected extractPaths(filteredUpdates: UpdatedPaths[]): string[];
82
+ /**
83
+ * Gets the site name from the path name
84
+ * @param {string} pathname Path name
85
+ * @returns {string} site name
86
+ */
87
+ protected getSiteName(pathname: string): string;
88
+ /**
89
+ * Gets the path name from the full path
90
+ * @param {string} fullPath Full path
91
+ * @returns {string} path name
92
+ */
93
+ protected getPathName(fullPath: string): string;
94
+ protected extractSiteName(path: string): string;
95
+ /**
96
+ * Filters out the updated paths and language from the request body
97
+ * @param {NextApiRequest} req Next.js API request
98
+ * @returns {UpdatedPaths[]} updated paths
99
+ */
100
+ protected getFilteredUpdates(req: NextApiRequest): UpdatedPaths[];
101
+ protected handleMultiSitePersonalization(personalizeInfo: {
102
+ personalized: PersonalizedResult[];
103
+ nonPersonalized: {
104
+ path: string;
105
+ }[];
106
+ }, pathsToRevalidate: string[], getPathName: (x: string) => string, getSiteName: (x: string) => string): void;
107
+ protected handleNonMultiSitePersonalization(personalizeInfo: {
108
+ personalized: PersonalizedResult[];
109
+ nonPersonalized: {
110
+ path: string;
111
+ }[];
112
+ }, pathsToRevalidate: string[], getPathName: (x: string) => string): void;
113
+ private handler;
114
+ }
115
+ export {};
@@ -5,6 +5,7 @@
5
5
  * VERCEL_URL is provided by Vercel in case if we are in Preview deployment (deployment based on the custom branch),
6
6
  * preview deployment has unique url, we don't know exact url.
7
7
  * Similarly, DEPLOY_URL is provided by Netlify and would give us the deploy URL
8
+ * In production non-editing environments it is desirable to use relative urls, so in that case set PUBLIC_URL = ''
8
9
  */
9
10
  export declare const getPublicUrl: () => string;
10
11
  /**