@sitecore-jss/sitecore-jss-nextjs 22.8.0-canary.3 → 22.8.0-canary.5

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.
@@ -26,7 +26,7 @@ class PersonalizeMiddleware extends middleware_1.MiddlewareBase {
26
26
  constructor(config) {
27
27
  super(config);
28
28
  this.config = config;
29
- this.handler = (req, res, options) => __awaiter(this, void 0, void 0, function* () {
29
+ this.processPersonalizationRequest = (req, res, options) => __awaiter(this, void 0, void 0, function* () {
30
30
  const pathname = req.nextUrl.pathname;
31
31
  const language = this.getLanguage(req);
32
32
  const hostname = this.getHostHeader(req) || this.defaultHostname;
@@ -52,7 +52,7 @@ class PersonalizeMiddleware extends middleware_1.MiddlewareBase {
52
52
  }
53
53
  const site = this.getSite(req, response);
54
54
  // Get personalization info from Experience Edge
55
- const personalizeInfo = yield this.personalizeService.getPersonalizeInfo(pathname, language, site.name);
55
+ const personalizeInfo = yield this.getPersonalizeInfo(pathname, language, site.name);
56
56
  if (!personalizeInfo) {
57
57
  // Likely an invalid route / language
58
58
  sitecore_jss_1.debug.personalize('skipped (personalize info not found)');
@@ -127,7 +127,7 @@ class PersonalizeMiddleware extends middleware_1.MiddlewareBase {
127
127
  getHandler() {
128
128
  return (req, res, options) => __awaiter(this, void 0, void 0, function* () {
129
129
  try {
130
- return yield this.handler(req, res, options);
130
+ return yield this.processPersonalizationRequest(req, res, options);
131
131
  }
132
132
  catch (error) {
133
133
  console.log('Personalize middleware failed:');
@@ -229,5 +229,10 @@ class PersonalizeMiddleware extends middleware_1.MiddlewareBase {
229
229
  return results;
230
230
  }, results);
231
231
  }
232
+ getPersonalizeInfo(pathname, language, siteName) {
233
+ return __awaiter(this, void 0, void 0, function* () {
234
+ return this.personalizeService.getPersonalizeInfo(pathname, language, siteName);
235
+ });
236
+ }
232
237
  }
233
238
  exports.PersonalizeMiddleware = PersonalizeMiddleware;
@@ -65,7 +65,7 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
65
65
  const { pathname: incomingURL, search: incomingQS = '' } = this.normalizeUrl(req.nextUrl.clone());
66
66
  const locale = this.getLanguage(req);
67
67
  const normalizedPath = incomingURL.replace(/\/*$/gi, '');
68
- const redirects = yield this.redirectsService.fetchRedirects(siteName);
68
+ const redirects = yield this.getRedirects(siteName);
69
69
  const language = this.getLanguage(req);
70
70
  const modifyRedirects = structuredClone(redirects);
71
71
  let matchedQueryString;
@@ -221,6 +221,17 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
221
221
  return response;
222
222
  });
223
223
  }
224
+ /**
225
+ * Fetches all redirects for a given site from the Sitecore instance
226
+ * @param {string} siteName - The name of the site to fetch redirects for
227
+ * @returns {Promise<RedirectInfo[]>} A promise that resolves to an array of redirect information
228
+ * @protected
229
+ */
230
+ getRedirects(siteName) {
231
+ return __awaiter(this, void 0, void 0, function* () {
232
+ return yield this.redirectsService.fetchRedirects(siteName);
233
+ });
234
+ }
224
235
  /**
225
236
  * When a user clicks on a link generated by the Link component from next/link,
226
237
  * Next.js adds special parameters in the route called path.
@@ -23,7 +23,7 @@ export class PersonalizeMiddleware extends MiddlewareBase {
23
23
  constructor(config) {
24
24
  super(config);
25
25
  this.config = config;
26
- this.handler = (req, res, options) => __awaiter(this, void 0, void 0, function* () {
26
+ this.processPersonalizationRequest = (req, res, options) => __awaiter(this, void 0, void 0, function* () {
27
27
  const pathname = req.nextUrl.pathname;
28
28
  const language = this.getLanguage(req);
29
29
  const hostname = this.getHostHeader(req) || this.defaultHostname;
@@ -49,7 +49,7 @@ export class PersonalizeMiddleware extends MiddlewareBase {
49
49
  }
50
50
  const site = this.getSite(req, response);
51
51
  // Get personalization info from Experience Edge
52
- const personalizeInfo = yield this.personalizeService.getPersonalizeInfo(pathname, language, site.name);
52
+ const personalizeInfo = yield this.getPersonalizeInfo(pathname, language, site.name);
53
53
  if (!personalizeInfo) {
54
54
  // Likely an invalid route / language
55
55
  debug.personalize('skipped (personalize info not found)');
@@ -124,7 +124,7 @@ export class PersonalizeMiddleware extends MiddlewareBase {
124
124
  getHandler() {
125
125
  return (req, res, options) => __awaiter(this, void 0, void 0, function* () {
126
126
  try {
127
- return yield this.handler(req, res, options);
127
+ return yield this.processPersonalizationRequest(req, res, options);
128
128
  }
129
129
  catch (error) {
130
130
  console.log('Personalize middleware failed:');
@@ -226,4 +226,9 @@ export class PersonalizeMiddleware extends MiddlewareBase {
226
226
  return results;
227
227
  }, results);
228
228
  }
229
+ getPersonalizeInfo(pathname, language, siteName) {
230
+ return __awaiter(this, void 0, void 0, function* () {
231
+ return this.personalizeService.getPersonalizeInfo(pathname, language, siteName);
232
+ });
233
+ }
229
234
  }
@@ -59,7 +59,7 @@ export class RedirectsMiddleware extends MiddlewareBase {
59
59
  const { pathname: incomingURL, search: incomingQS = '' } = this.normalizeUrl(req.nextUrl.clone());
60
60
  const locale = this.getLanguage(req);
61
61
  const normalizedPath = incomingURL.replace(/\/*$/gi, '');
62
- const redirects = yield this.redirectsService.fetchRedirects(siteName);
62
+ const redirects = yield this.getRedirects(siteName);
63
63
  const language = this.getLanguage(req);
64
64
  const modifyRedirects = structuredClone(redirects);
65
65
  let matchedQueryString;
@@ -215,6 +215,17 @@ export class RedirectsMiddleware extends MiddlewareBase {
215
215
  return response;
216
216
  });
217
217
  }
218
+ /**
219
+ * Fetches all redirects for a given site from the Sitecore instance
220
+ * @param {string} siteName - The name of the site to fetch redirects for
221
+ * @returns {Promise<RedirectInfo[]>} A promise that resolves to an array of redirect information
222
+ * @protected
223
+ */
224
+ getRedirects(siteName) {
225
+ return __awaiter(this, void 0, void 0, function* () {
226
+ return yield this.redirectsService.fetchRedirects(siteName);
227
+ });
228
+ }
218
229
  /**
219
230
  * When a user clicks on a link generated by the Link component from next/link,
220
231
  * Next.js adds special parameters in the route called path.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sitecore-jss/sitecore-jss-nextjs",
3
- "version": "22.8.0-canary.3",
3
+ "version": "22.8.0-canary.5",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "sideEffects": false,
@@ -72,16 +72,16 @@
72
72
  "react-dom": "^19.1.0"
73
73
  },
74
74
  "dependencies": {
75
- "@sitecore-jss/sitecore-jss": "22.8.0-canary.3",
76
- "@sitecore-jss/sitecore-jss-dev-tools": "22.8.0-canary.3",
77
- "@sitecore-jss/sitecore-jss-react": "22.8.0-canary.3",
75
+ "@sitecore-jss/sitecore-jss": "22.8.0-canary.5",
76
+ "@sitecore-jss/sitecore-jss-dev-tools": "22.8.0-canary.5",
77
+ "@sitecore-jss/sitecore-jss-react": "22.8.0-canary.5",
78
78
  "@vercel/kv": "^0.2.1",
79
79
  "regex-parser": "^2.2.11",
80
80
  "sync-disk-cache": "^2.1.0"
81
81
  },
82
82
  "description": "",
83
83
  "types": "types/index.d.ts",
84
- "gitHead": "79696336a6cfd4ee3fd533cc28ebd87dd748ad41",
84
+ "gitHead": "d4f014efefea9724e16de66084691fab2a91d2e6",
85
85
  "files": [
86
86
  "dist",
87
87
  "types",
@@ -115,6 +115,7 @@ export declare class PersonalizeMiddleware extends MiddlewareBase {
115
115
  * @returns An array of personalize executions
116
116
  */
117
117
  protected getPersonalizeExecutions(personalizeInfo: PersonalizeInfo, language: string): PersonalizeExecution[];
118
- private handler;
118
+ protected processPersonalizationRequest: (req: NextRequest, res?: NextResponse, options?: PersonalizeOptions) => Promise<NextResponse>;
119
+ protected getPersonalizeInfo(pathname: string, language: string, siteName: string): Promise<PersonalizeInfo | undefined>;
119
120
  }
120
121
  export {};
@@ -45,6 +45,13 @@ export declare class RedirectsMiddleware extends MiddlewareBase {
45
45
  * @returns {Promise<NextResponse>} The redirect response.
46
46
  */
47
47
  protected processRedirectRequest(req: NextRequest, res?: NextResponse): Promise<NextResponse>;
48
+ /**
49
+ * Fetches all redirects for a given site from the Sitecore instance
50
+ * @param {string} siteName - The name of the site to fetch redirects for
51
+ * @returns {Promise<RedirectInfo[]>} A promise that resolves to an array of redirect information
52
+ * @protected
53
+ */
54
+ protected getRedirects(siteName: string): Promise<RedirectInfo[]>;
48
55
  /**
49
56
  * When a user clicks on a link generated by the Link component from next/link,
50
57
  * Next.js adds special parameters in the route called path.