@sitecore-jss/sitecore-jss-nextjs 21.6.0-canary.36 → 21.6.0-canary.39

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.
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Context = void 0;
4
+ const sitecore_jss_react_1 = require("@sitecore-jss/sitecore-jss-react");
4
5
  /**
5
6
  * Context instance that is used to initialize the application Context and associated Software Development Kits (SDKs).
6
7
  */
@@ -31,6 +32,7 @@ class Context {
31
32
  this.sitecoreEdgeUrl = props.sitecoreEdgeUrl;
32
33
  this.sitecoreEdgeContextId = props.sitecoreEdgeContextId;
33
34
  this.siteName = props.siteName;
35
+ this.pageState = sitecore_jss_react_1.LayoutServicePageState.Normal;
34
36
  }
35
37
  init(props = {}) {
36
38
  // Context and SDKs are initialized only once
@@ -40,6 +42,9 @@ class Context {
40
42
  if (props.siteName) {
41
43
  this.siteName = props.siteName;
42
44
  }
45
+ if (props.pageState) {
46
+ this.pageState = props.pageState;
47
+ }
43
48
  // iterate over the SDKs and initialize them
44
49
  for (const sdkName of Object.keys(this.props.sdks)) {
45
50
  this.initSDK(sdkName);
package/dist/cjs/index.js CHANGED
@@ -23,8 +23,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.FEaaSWrapper = exports.NextImage = exports.EditingComponentPlaceholder = exports.Placeholder = exports.RichText = exports.Link = exports.useComponentProps = exports.ComponentPropsContext = exports.ComponentPropsReactContext = exports.normalizeSiteRewrite = exports.getSiteRewriteData = exports.getSiteRewrite = exports.GraphQLSiteInfoService = exports.SiteResolver = exports.GraphQLRobotsService = exports.GraphQLErrorPagesService = exports.GraphQLSitemapXmlService = exports.MultisiteGraphQLSitemapService = exports.GraphQLSitemapService = exports.DisconnectedSitemapService = exports.ComponentPropsService = exports.CdpHelper = exports.normalizePersonalizedRewrite = exports.getPersonalizedRewriteData = exports.getPersonalizedRewrite = exports.personalizeLayout = exports.RestDictionaryService = exports.GraphQLDictionaryService = exports.trackingApi = exports.mediaApi = exports.EDITING_COMPONENT_ID = exports.EDITING_COMPONENT_PLACEHOLDER = exports.RenderingType = exports.getFieldValue = exports.getChildPlaceholder = exports.RestLayoutService = exports.GraphQLLayoutService = exports.LayoutServicePageState = exports.tryParseEnvValue = exports.resolveUrl = exports.resetEditorChromes = exports.isEditorActive = exports.getPublicUrl = exports.handleEditorFastRefresh = exports.GraphQLRequestClient = exports.debug = exports.enableDebug = exports.NativeDataFetcher = exports.AxiosDataFetcher = exports.constants = void 0;
27
- exports.withDatasourceCheck = exports.withPlaceholder = exports.withEditorChromes = exports.useSitecoreContext = exports.withSitecoreContext = exports.SitecoreContextReactContext = exports.SitecoreContext = exports.VisitorIdentification = exports.File = exports.getFEAASLibraryStylesheetLinks = exports.BYOCComponent = exports.fetchFEaaSComponentServerProps = exports.FEaaSComponent = exports.EditFrame = exports.DateField = exports.Text = exports.Image = exports.Context = exports.ComponentBuilder = exports.BYOCWrapper = void 0;
26
+ exports.NextImage = exports.EditingComponentPlaceholder = exports.Placeholder = exports.RichText = exports.Link = exports.useComponentProps = exports.ComponentPropsContext = exports.ComponentPropsReactContext = exports.normalizeSiteRewrite = exports.getSiteRewriteData = exports.getSiteRewrite = exports.GraphQLSiteInfoService = exports.SiteResolver = exports.GraphQLRobotsService = exports.GraphQLErrorPagesService = exports.GraphQLSitemapXmlService = exports.MultisiteGraphQLSitemapService = exports.GraphQLSitemapService = exports.DisconnectedSitemapService = exports.ComponentPropsService = exports.CdpHelper = exports.normalizePersonalizedRewrite = exports.getPersonalizedRewriteData = exports.getPersonalizedRewrite = exports.personalizeLayout = exports.RestDictionaryService = exports.GraphQLDictionaryService = exports.trackingApi = exports.mediaApi = exports.getContentStylesheetLink = exports.EDITING_COMPONENT_ID = exports.EDITING_COMPONENT_PLACEHOLDER = exports.RenderingType = exports.getFieldValue = exports.getChildPlaceholder = exports.RestLayoutService = exports.GraphQLLayoutService = exports.LayoutServicePageState = exports.tryParseEnvValue = exports.resolveUrl = exports.resetEditorChromes = exports.isEditorActive = exports.getPublicUrl = exports.handleEditorFastRefresh = exports.GraphQLRequestClient = exports.debug = exports.enableDebug = exports.NativeDataFetcher = exports.AxiosDataFetcher = exports.constants = void 0;
27
+ exports.withDatasourceCheck = exports.withPlaceholder = exports.withEditorChromes = exports.useSitecoreContext = exports.withSitecoreContext = exports.SitecoreContextReactContext = exports.SitecoreContext = exports.VisitorIdentification = exports.File = exports.getFEAASLibraryStylesheetLinks = exports.BYOCComponent = exports.fetchFEaaSComponentServerProps = exports.FEaaSComponent = exports.EditFrame = exports.DateField = exports.Text = exports.Image = exports.Context = exports.ComponentBuilder = exports.BYOCWrapper = exports.FEaaSWrapper = void 0;
28
28
  var sitecore_jss_1 = require("@sitecore-jss/sitecore-jss");
29
29
  Object.defineProperty(exports, "constants", { enumerable: true, get: function () { return sitecore_jss_1.constants; } });
30
30
  Object.defineProperty(exports, "AxiosDataFetcher", { enumerable: true, get: function () { return sitecore_jss_1.AxiosDataFetcher; } });
@@ -65,6 +65,7 @@ Object.defineProperty(exports, "getFieldValue", { enumerable: true, get: functio
65
65
  Object.defineProperty(exports, "RenderingType", { enumerable: true, get: function () { return layout_1.RenderingType; } });
66
66
  Object.defineProperty(exports, "EDITING_COMPONENT_PLACEHOLDER", { enumerable: true, get: function () { return layout_1.EDITING_COMPONENT_PLACEHOLDER; } });
67
67
  Object.defineProperty(exports, "EDITING_COMPONENT_ID", { enumerable: true, get: function () { return layout_1.EDITING_COMPONENT_ID; } });
68
+ Object.defineProperty(exports, "getContentStylesheetLink", { enumerable: true, get: function () { return layout_1.getContentStylesheetLink; } });
68
69
  var media_1 = require("@sitecore-jss/sitecore-jss/media");
69
70
  Object.defineProperty(exports, "mediaApi", { enumerable: true, get: function () { return media_1.mediaApi; } });
70
71
  var tracking_1 = require("@sitecore-jss/sitecore-jss/tracking");
@@ -136,13 +136,16 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
136
136
  const redirects = yield this.redirectsService.fetchRedirects(siteName);
137
137
  const tragetURL = req.nextUrl.pathname;
138
138
  const targetQS = req.nextUrl.search || '';
139
- return redirects.length
140
- ? redirects.find((redirect) => {
139
+ const language = this.getLanguage(req);
140
+ const modifyRedirects = JSON.parse(JSON.stringify(redirects));
141
+ return modifyRedirects.length
142
+ ? modifyRedirects.find((redirect) => {
143
+ redirect.pattern = redirect.pattern.replace(RegExp(`^[^]?/${language}/`, 'gi'), '');
141
144
  redirect.pattern = `/^\/${redirect.pattern
142
145
  .replace(/^\/|\/$/g, '')
143
146
  .replace(/^\^\/|\/\$$/g, '')
144
147
  .replace(/^\^|\$$/g, '')
145
- .replace(/\$\/gi$/g, '')}$/gi`;
148
+ .replace(/\$\/gi$/g, '')}[\/]?$/gi`;
146
149
  return (((0, regex_parser_1.default)(redirect.pattern).test(tragetURL) ||
147
150
  (0, regex_parser_1.default)(redirect.pattern).test(`${tragetURL}${targetQS}`) ||
148
151
  (0, regex_parser_1.default)(redirect.pattern).test(`/${req.nextUrl.locale}${tragetURL}`) ||
@@ -1,10 +1,6 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.getJssEditingSecret = exports.handleEditorFastRefresh = exports.getPublicUrl = void 0;
7
- const chalk_1 = __importDefault(require("chalk"));
8
4
  const utils_1 = require("@sitecore-jss/sitecore-jss/utils");
9
5
  /**
10
6
  * Get the publicUrl.
@@ -13,27 +9,19 @@ const utils_1 = require("@sitecore-jss/sitecore-jss/utils");
13
9
  * VERCEL_URL is provided by Vercel in case if we are in Preview deployment (deployment based on the custom branch),
14
10
  * preview deployment has unique url, we don't know exact url.
15
11
  * Similarly, DEPLOY_URL is provided by Netlify and would give us the deploy URL
12
+ * In production non-editing environments it is desirable to use relative urls, so in that case set PUBLIC_URL = ''
16
13
  */
17
14
  const getPublicUrl = () => {
18
- if (process.env.NETLIFY && process.env.DEPLOY_URL)
19
- return process.env.DEPLOY_URL;
20
- if (process.env.VERCEL_URL)
21
- return `https://${process.env.VERCEL_URL}`;
22
15
  let url = process.env.PUBLIC_URL;
23
16
  if (url === undefined) {
24
- console.warn(`${chalk_1.default.yellow.bold('Warning:')} An PUBLIC_URL environment variable is not defined. Falling back to http://localhost:3000.`);
17
+ if (process.env.NETLIFY && process.env.DEPLOY_URL)
18
+ return process.env.DEPLOY_URL;
19
+ if (process.env.VERCEL_URL)
20
+ return `https://${process.env.VERCEL_URL}`;
25
21
  url = 'http://localhost:3000';
26
22
  }
27
- else {
28
- try {
29
- new URL(url);
30
- }
31
- catch (error) {
32
- throw new Error(`The PUBLIC_URL environment variable '${url}' is not a valid URL.`);
33
- }
34
- }
35
23
  // Ensure no trailing slash
36
- return url.toString().replace(/\/$/, '');
24
+ return url.replace(/\/$/, '');
37
25
  };
38
26
  exports.getPublicUrl = getPublicUrl;
39
27
  /**
@@ -1,3 +1,4 @@
1
+ import { LayoutServicePageState } from '@sitecore-jss/sitecore-jss-react';
1
2
  /**
2
3
  * Context instance that is used to initialize the application Context and associated Software Development Kits (SDKs).
3
4
  */
@@ -28,6 +29,7 @@ export class Context {
28
29
  this.sitecoreEdgeUrl = props.sitecoreEdgeUrl;
29
30
  this.sitecoreEdgeContextId = props.sitecoreEdgeContextId;
30
31
  this.siteName = props.siteName;
32
+ this.pageState = LayoutServicePageState.Normal;
31
33
  }
32
34
  init(props = {}) {
33
35
  // Context and SDKs are initialized only once
@@ -37,6 +39,9 @@ export class Context {
37
39
  if (props.siteName) {
38
40
  this.siteName = props.siteName;
39
41
  }
42
+ if (props.pageState) {
43
+ this.pageState = props.pageState;
44
+ }
40
45
  // iterate over the SDKs and initialize them
41
46
  for (const sdkName of Object.keys(this.props.sdks)) {
42
47
  this.initSDK(sdkName);
package/dist/esm/index.js CHANGED
@@ -20,7 +20,7 @@ const { GraphQLRequestClientDep: GraphQLRequestClient } = {
20
20
  export { GraphQLRequestClient };
21
21
  export { handleEditorFastRefresh, getPublicUrl };
22
22
  export { isEditorActive, resetEditorChromes, resolveUrl, tryParseEnvValue };
23
- export { LayoutServicePageState, GraphQLLayoutService, RestLayoutService, getChildPlaceholder, getFieldValue, RenderingType, EDITING_COMPONENT_PLACEHOLDER, EDITING_COMPONENT_ID, } from '@sitecore-jss/sitecore-jss/layout';
23
+ export { LayoutServicePageState, GraphQLLayoutService, RestLayoutService, getChildPlaceholder, getFieldValue, RenderingType, EDITING_COMPONENT_PLACEHOLDER, EDITING_COMPONENT_ID, getContentStylesheetLink, } from '@sitecore-jss/sitecore-jss/layout';
24
24
  export { mediaApi } from '@sitecore-jss/sitecore-jss/media';
25
25
  export { trackingApi, } from '@sitecore-jss/sitecore-jss/tracking';
26
26
  export { GraphQLDictionaryService, RestDictionaryService, } from '@sitecore-jss/sitecore-jss/i18n';
@@ -130,13 +130,16 @@ export class RedirectsMiddleware extends MiddlewareBase {
130
130
  const redirects = yield this.redirectsService.fetchRedirects(siteName);
131
131
  const tragetURL = req.nextUrl.pathname;
132
132
  const targetQS = req.nextUrl.search || '';
133
- return redirects.length
134
- ? redirects.find((redirect) => {
133
+ const language = this.getLanguage(req);
134
+ const modifyRedirects = JSON.parse(JSON.stringify(redirects));
135
+ return modifyRedirects.length
136
+ ? modifyRedirects.find((redirect) => {
137
+ redirect.pattern = redirect.pattern.replace(RegExp(`^[^]?/${language}/`, 'gi'), '');
135
138
  redirect.pattern = `/^\/${redirect.pattern
136
139
  .replace(/^\/|\/$/g, '')
137
140
  .replace(/^\^\/|\/\$$/g, '')
138
141
  .replace(/^\^|\$$/g, '')
139
- .replace(/\$\/gi$/g, '')}$/gi`;
142
+ .replace(/\$\/gi$/g, '')}[\/]?$/gi`;
140
143
  return ((regexParser(redirect.pattern).test(tragetURL) ||
141
144
  regexParser(redirect.pattern).test(`${tragetURL}${targetQS}`) ||
142
145
  regexParser(redirect.pattern).test(`/${req.nextUrl.locale}${tragetURL}`) ||
@@ -1,4 +1,3 @@
1
- import chalk from 'chalk';
2
1
  import { isEditorActive, resetEditorChromes } from '@sitecore-jss/sitecore-jss/utils';
3
2
  /**
4
3
  * Get the publicUrl.
@@ -7,27 +6,19 @@ import { isEditorActive, resetEditorChromes } from '@sitecore-jss/sitecore-jss/u
7
6
  * VERCEL_URL is provided by Vercel in case if we are in Preview deployment (deployment based on the custom branch),
8
7
  * preview deployment has unique url, we don't know exact url.
9
8
  * Similarly, DEPLOY_URL is provided by Netlify and would give us the deploy URL
9
+ * In production non-editing environments it is desirable to use relative urls, so in that case set PUBLIC_URL = ''
10
10
  */
11
11
  export const getPublicUrl = () => {
12
- if (process.env.NETLIFY && process.env.DEPLOY_URL)
13
- return process.env.DEPLOY_URL;
14
- if (process.env.VERCEL_URL)
15
- return `https://${process.env.VERCEL_URL}`;
16
12
  let url = process.env.PUBLIC_URL;
17
13
  if (url === undefined) {
18
- console.warn(`${chalk.yellow.bold('Warning:')} An PUBLIC_URL environment variable is not defined. Falling back to http://localhost:3000.`);
14
+ if (process.env.NETLIFY && process.env.DEPLOY_URL)
15
+ return process.env.DEPLOY_URL;
16
+ if (process.env.VERCEL_URL)
17
+ return `https://${process.env.VERCEL_URL}`;
19
18
  url = 'http://localhost:3000';
20
19
  }
21
- else {
22
- try {
23
- new URL(url);
24
- }
25
- catch (error) {
26
- throw new Error(`The PUBLIC_URL environment variable '${url}' is not a valid URL.`);
27
- }
28
- }
29
20
  // Ensure no trailing slash
30
- return url.toString().replace(/\/$/, '');
21
+ return url.replace(/\/$/, '');
31
22
  };
32
23
  /**
33
24
  * Since Sitecore editors do not support Fast Refresh:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sitecore-jss/sitecore-jss-nextjs",
3
- "version": "21.6.0-canary.36",
3
+ "version": "21.6.0-canary.39",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "sideEffects": false,
@@ -14,8 +14,8 @@
14
14
  "generate-docs": "npx typedoc --plugin typedoc-plugin-markdown --readme none --out ../../ref-docs/sitecore-jss-nextjs --entryPoints src/index.ts --entryPoints src/monitoring/index.ts --entryPoints src/editing/index.ts --entryPoints src/middleware/index.ts --entryPoints src/context/index.ts --entryPoints src/utils/index.ts --entryPoints src/site/index.ts --entryPoints src/graphql/index.ts --githubPages false"
15
15
  },
16
16
  "engines": {
17
- "node": ">=12",
18
- "npm": ">=6"
17
+ "node": ">=18",
18
+ "npm": ">=10"
19
19
  },
20
20
  "author": {
21
21
  "name": "Sitecore Corporation",
@@ -73,9 +73,9 @@
73
73
  "react-dom": "^18.2.0"
74
74
  },
75
75
  "dependencies": {
76
- "@sitecore-jss/sitecore-jss": "^21.6.0-canary.36",
77
- "@sitecore-jss/sitecore-jss-dev-tools": "^21.6.0-canary.36",
78
- "@sitecore-jss/sitecore-jss-react": "^21.6.0-canary.36",
76
+ "@sitecore-jss/sitecore-jss": "^21.6.0-canary.39",
77
+ "@sitecore-jss/sitecore-jss-dev-tools": "^21.6.0-canary.39",
78
+ "@sitecore-jss/sitecore-jss-react": "^21.6.0-canary.39",
79
79
  "@vercel/kv": "^0.2.1",
80
80
  "node-html-parser": "^6.1.4",
81
81
  "prop-types": "^15.8.1",
@@ -84,7 +84,7 @@
84
84
  },
85
85
  "description": "",
86
86
  "types": "types/index.d.ts",
87
- "gitHead": "e46f93f3c108c8f4c2009644ca0b26fa23923d5d",
87
+ "gitHead": "7374ba0689c2121465c6fc68662ff02024920599",
88
88
  "files": [
89
89
  "dist",
90
90
  "types",
@@ -1,3 +1,4 @@
1
+ import { LayoutServicePageState } from '@sitecore-jss/sitecore-jss-react';
1
2
  /**
2
3
  * Software Development Kit (SDK) instance
3
4
  */
@@ -23,6 +24,10 @@ export interface ContextInitProps {
23
24
  * Your Sitecore site name
24
25
  */
25
26
  siteName?: string;
27
+ /**
28
+ * Sitecore page state (normal, preview, edit)
29
+ */
30
+ pageState?: LayoutServicePageState;
26
31
  }
27
32
  /**
28
33
  * Configuration that is passed to the Context.
@@ -72,6 +77,10 @@ export declare class Context<SDKModules extends SDKModulesType> {
72
77
  * The Sitecore site name
73
78
  */
74
79
  siteName: string;
80
+ /**
81
+ * Sitecore page state (normal, preview, edit)
82
+ */
83
+ pageState: LayoutServicePageState;
75
84
  /**
76
85
  * Software Development Kits (SDKs) to be initialized
77
86
  */
package/types/index.d.ts CHANGED
@@ -8,7 +8,7 @@ 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';
@@ -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
  /**