@sitecore-jss/sitecore-jss-nextjs 22.1.3 → 22.1.4-canary.2
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 -202
- package/README.md +11 -11
- package/dist/cjs/middleware/index.js +3 -1
- package/dist/cjs/middleware/redirects-middleware.js +81 -26
- package/dist/esm/middleware/index.js +1 -0
- package/dist/esm/middleware/redirects-middleware.js +81 -26
- package/package.json +5 -5
- package/types/middleware/index.d.ts +1 -0
- package/types/middleware/redirects-middleware.d.ts +13 -2
package/LICENSE.txt
CHANGED
|
@@ -1,202 +1,202 @@
|
|
|
1
|
-
|
|
2
|
-
Apache License
|
|
3
|
-
Version 2.0, January 2004
|
|
4
|
-
http://www.apache.org/licenses/
|
|
5
|
-
|
|
6
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
-
|
|
8
|
-
1. Definitions.
|
|
9
|
-
|
|
10
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
-
|
|
13
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
-
the copyright owner that is granting the License.
|
|
15
|
-
|
|
16
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
-
other entities that control, are controlled by, or are under common
|
|
18
|
-
control with that entity. For the purposes of this definition,
|
|
19
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
-
direction or management of such entity, whether by contract or
|
|
21
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
-
|
|
24
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
-
exercising permissions granted by this License.
|
|
26
|
-
|
|
27
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
-
including but not limited to software source code, documentation
|
|
29
|
-
source, and configuration files.
|
|
30
|
-
|
|
31
|
-
"Object" form shall mean any form resulting from mechanical
|
|
32
|
-
transformation or translation of a Source form, including but
|
|
33
|
-
not limited to compiled object code, generated documentation,
|
|
34
|
-
and conversions to other media types.
|
|
35
|
-
|
|
36
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
-
Object form, made available under the License, as indicated by a
|
|
38
|
-
copyright notice that is included in or attached to the work
|
|
39
|
-
(an example is provided in the Appendix below).
|
|
40
|
-
|
|
41
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
-
form, that is based on (or derived from) the Work and for which the
|
|
43
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
-
of this License, Derivative Works shall not include works that remain
|
|
46
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
-
the Work and Derivative Works thereof.
|
|
48
|
-
|
|
49
|
-
"Contribution" shall mean any work of authorship, including
|
|
50
|
-
the original version of the Work and any modifications or additions
|
|
51
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
-
means any form of electronic, verbal, or written communication sent
|
|
56
|
-
to the Licensor or its representatives, including but not limited to
|
|
57
|
-
communication on electronic mailing lists, source code control systems,
|
|
58
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
-
excluding communication that is conspicuously marked or otherwise
|
|
61
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
-
|
|
63
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
-
subsequently incorporated within the Work.
|
|
66
|
-
|
|
67
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
-
Work and such Derivative Works in Source or Object form.
|
|
73
|
-
|
|
74
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
-
(except as stated in this section) patent license to make, have made,
|
|
78
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
-
where such license applies only to those patent claims licensable
|
|
80
|
-
by such Contributor that are necessarily infringed by their
|
|
81
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
-
institute patent litigation against any entity (including a
|
|
84
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
-
or contributory patent infringement, then any patent licenses
|
|
87
|
-
granted to You under this License for that Work shall terminate
|
|
88
|
-
as of the date such litigation is filed.
|
|
89
|
-
|
|
90
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
-
modifications, and in Source or Object form, provided that You
|
|
93
|
-
meet the following conditions:
|
|
94
|
-
|
|
95
|
-
(a) You must give any other recipients of the Work or
|
|
96
|
-
Derivative Works a copy of this License; and
|
|
97
|
-
|
|
98
|
-
(b) You must cause any modified files to carry prominent notices
|
|
99
|
-
stating that You changed the files; and
|
|
100
|
-
|
|
101
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
-
that You distribute, all copyright, patent, trademark, and
|
|
103
|
-
attribution notices from the Source form of the Work,
|
|
104
|
-
excluding those notices that do not pertain to any part of
|
|
105
|
-
the Derivative Works; and
|
|
106
|
-
|
|
107
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
-
distribution, then any Derivative Works that You distribute must
|
|
109
|
-
include a readable copy of the attribution notices contained
|
|
110
|
-
within such NOTICE file, excluding those notices that do not
|
|
111
|
-
pertain to any part of the Derivative Works, in at least one
|
|
112
|
-
of the following places: within a NOTICE text file distributed
|
|
113
|
-
as part of the Derivative Works; within the Source form or
|
|
114
|
-
documentation, if provided along with the Derivative Works; or,
|
|
115
|
-
within a display generated by the Derivative Works, if and
|
|
116
|
-
wherever such third-party notices normally appear. The contents
|
|
117
|
-
of the NOTICE file are for informational purposes only and
|
|
118
|
-
do not modify the License. You may add Your own attribution
|
|
119
|
-
notices within Derivative Works that You distribute, alongside
|
|
120
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
-
that such additional attribution notices cannot be construed
|
|
122
|
-
as modifying the License.
|
|
123
|
-
|
|
124
|
-
You may add Your own copyright statement to Your modifications and
|
|
125
|
-
may provide additional or different license terms and conditions
|
|
126
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
-
the conditions stated in this License.
|
|
130
|
-
|
|
131
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
-
this License, without any additional terms or conditions.
|
|
135
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
-
the terms of any separate license agreement you may have executed
|
|
137
|
-
with Licensor regarding such Contributions.
|
|
138
|
-
|
|
139
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
-
except as required for reasonable and customary use in describing the
|
|
142
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
-
|
|
144
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
-
implied, including, without limitation, any warranties or conditions
|
|
149
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
-
appropriateness of using or redistributing the Work and assume any
|
|
152
|
-
risks associated with Your exercise of permissions under this License.
|
|
153
|
-
|
|
154
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
-
unless required by applicable law (such as deliberate and grossly
|
|
157
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
-
liable to You for damages, including any direct, indirect, special,
|
|
159
|
-
incidental, or consequential damages of any character arising as a
|
|
160
|
-
result of this License or out of the use or inability to use the
|
|
161
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
-
other commercial damages or losses), even if such Contributor
|
|
164
|
-
has been advised of the possibility of such damages.
|
|
165
|
-
|
|
166
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
-
or other liability obligations and/or rights consistent with this
|
|
170
|
-
License. However, in accepting such obligations, You may act only
|
|
171
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
-
defend, and hold each Contributor harmless for any liability
|
|
174
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
-
of your accepting any such warranty or additional liability.
|
|
176
|
-
|
|
177
|
-
END OF TERMS AND CONDITIONS
|
|
178
|
-
|
|
179
|
-
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
-
|
|
181
|
-
To apply the Apache License to your work, attach the following
|
|
182
|
-
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
-
replaced with your own identifying information. (Don't include
|
|
184
|
-
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
-
comment syntax for the file format. We also recommend that a
|
|
186
|
-
file or class name and description of purpose be included on the
|
|
187
|
-
same "printed page" as the copyright notice for easier
|
|
188
|
-
identification within third-party archives.
|
|
189
|
-
|
|
190
|
-
Copyright [yyyy] [name of copyright owner]
|
|
191
|
-
|
|
192
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
-
you may not use this file except in compliance with the License.
|
|
194
|
-
You may obtain a copy of the License at
|
|
195
|
-
|
|
196
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
-
|
|
198
|
-
Unless required by applicable law or agreed to in writing, software
|
|
199
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
-
See the License for the specific language governing permissions and
|
|
202
|
-
limitations under the License.
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
# Sitecore JavaScript Rendering SDK for Next.js
|
|
2
|
-
|
|
3
|
-
This module is provided as a part of Sitecore JavaScript Rendering SDK. It contains Next.js components and integration for JSS.
|
|
4
|
-
|
|
5
|
-
<!---
|
|
6
|
-
@TODO: Update to next version docs before release
|
|
7
|
-
-->
|
|
8
|
-
[Documentation (Experience Platform)](https://doc.sitecore.com/xp/en/developers/hd/22/sitecore-headless-development/sitecore-javascript-rendering-sdk--jss--for-next-js.html)
|
|
9
|
-
|
|
10
|
-
[Documentation (XM Cloud)](https://doc.sitecore.com/xmc/en/developers/xm-cloud/sitecore-javascript-rendering-sdk--jss--for-next-js.html)
|
|
11
|
-
|
|
1
|
+
# Sitecore JavaScript Rendering SDK for Next.js
|
|
2
|
+
|
|
3
|
+
This module is provided as a part of Sitecore JavaScript Rendering SDK. It contains Next.js components and integration for JSS.
|
|
4
|
+
|
|
5
|
+
<!---
|
|
6
|
+
@TODO: Update to next version docs before release
|
|
7
|
+
-->
|
|
8
|
+
[Documentation (Experience Platform)](https://doc.sitecore.com/xp/en/developers/hd/22/sitecore-headless-development/sitecore-javascript-rendering-sdk--jss--for-next-js.html)
|
|
9
|
+
|
|
10
|
+
[Documentation (XM Cloud)](https://doc.sitecore.com/xmc/en/developers/xm-cloud/sitecore-javascript-rendering-sdk--jss--for-next-js.html)
|
|
11
|
+
|
|
12
12
|
[API reference documentation](/ref-docs/sitecore-jss-nextjs/)
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MultisiteMiddleware = exports.PersonalizeMiddleware = exports.RedirectsMiddleware = exports.debug = void 0;
|
|
3
|
+
exports.MultisiteMiddleware = exports.PersonalizeMiddleware = exports.RedirectsMiddleware = exports.MiddlewareBase = exports.debug = void 0;
|
|
4
4
|
var sitecore_jss_1 = require("@sitecore-jss/sitecore-jss");
|
|
5
5
|
Object.defineProperty(exports, "debug", { enumerable: true, get: function () { return sitecore_jss_1.debug; } });
|
|
6
|
+
var middleware_1 = require("./middleware");
|
|
7
|
+
Object.defineProperty(exports, "MiddlewareBase", { enumerable: true, get: function () { return middleware_1.MiddlewareBase; } });
|
|
6
8
|
var redirects_middleware_1 = require("./redirects-middleware");
|
|
7
9
|
Object.defineProperty(exports, "RedirectsMiddleware", { enumerable: true, get: function () { return redirects_middleware_1.RedirectsMiddleware; } });
|
|
8
10
|
var personalize_middleware_1 = require("./personalize-middleware");
|
|
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.RedirectsMiddleware = void 0;
|
|
16
16
|
const sitecore_jss_1 = require("@sitecore-jss/sitecore-jss");
|
|
17
17
|
const site_1 = require("@sitecore-jss/sitecore-jss/site");
|
|
18
|
+
const utils_1 = require("@sitecore-jss/sitecore-jss/utils");
|
|
18
19
|
const server_1 = require("next/server");
|
|
19
20
|
const regex_parser_1 = __importDefault(require("regex-parser"));
|
|
20
21
|
const middleware_1 = require("./middleware");
|
|
@@ -64,13 +65,14 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
|
|
|
64
65
|
!(REGEXP_ABSOLUTE_URL.test(existsRedirect.target) &&
|
|
65
66
|
existsRedirect.target.includes(hostname))) {
|
|
66
67
|
existsRedirect.target = existsRedirect.target.replace(REGEXP_CONTEXT_SITE_LANG, site.language);
|
|
68
|
+
req.nextUrl.locale = site.language;
|
|
67
69
|
}
|
|
68
70
|
const url = this.normalizeUrl(req.nextUrl.clone());
|
|
69
71
|
if (REGEXP_ABSOLUTE_URL.test(existsRedirect.target)) {
|
|
70
72
|
url.href = existsRedirect.target;
|
|
71
73
|
}
|
|
72
74
|
else {
|
|
73
|
-
const source = `${url.pathname.replace(/\/*$/gi, '')}${
|
|
75
|
+
const source = `${url.pathname.replace(/\/*$/gi, '')}${existsRedirect.matchedQueryString}`;
|
|
74
76
|
const urlFirstPart = existsRedirect.target.split('/')[1];
|
|
75
77
|
if (this.locales.includes(urlFirstPart)) {
|
|
76
78
|
req.nextUrl.locale = urlFirstPart;
|
|
@@ -92,18 +94,20 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
|
|
|
92
94
|
}
|
|
93
95
|
const prepareNewURL = new URL(`${target[0]}${url.search}`, url.origin);
|
|
94
96
|
url.href = prepareNewURL.href;
|
|
97
|
+
url.pathname = prepareNewURL.pathname;
|
|
98
|
+
url.search = prepareNewURL.search;
|
|
99
|
+
url.locale = req.nextUrl.locale;
|
|
95
100
|
}
|
|
96
|
-
const redirectUrl = decodeURIComponent(url.href);
|
|
97
101
|
/** return Response redirect with http code of redirect type **/
|
|
98
102
|
switch (existsRedirect.redirectType) {
|
|
99
103
|
case site_1.REDIRECT_TYPE_301: {
|
|
100
|
-
return this.createRedirectResponse(
|
|
104
|
+
return this.createRedirectResponse(url, res, 301, 'Moved Permanently');
|
|
101
105
|
}
|
|
102
106
|
case site_1.REDIRECT_TYPE_302: {
|
|
103
|
-
return this.createRedirectResponse(
|
|
107
|
+
return this.createRedirectResponse(url, res, 302, 'Found');
|
|
104
108
|
}
|
|
105
109
|
case site_1.REDIRECT_TYPE_SERVER_TRANSFER: {
|
|
106
|
-
return this.rewrite(
|
|
110
|
+
return this.rewrite(url.href, req, res || server_1.NextResponse.next());
|
|
107
111
|
}
|
|
108
112
|
default:
|
|
109
113
|
return res || server_1.NextResponse.next();
|
|
@@ -149,27 +153,58 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
|
|
|
149
153
|
getExistsRedirect(req, siteName) {
|
|
150
154
|
return __awaiter(this, void 0, void 0, function* () {
|
|
151
155
|
const redirects = yield this.redirectsService.fetchRedirects(siteName);
|
|
152
|
-
const
|
|
153
|
-
const tragetURL = normalizedUrl.pathname;
|
|
154
|
-
const targetQS = normalizedUrl.search || '';
|
|
156
|
+
const { pathname: targetURL, search: targetQS = '', locale } = this.normalizeUrl(req.nextUrl.clone());
|
|
155
157
|
const language = this.getLanguage(req);
|
|
156
158
|
const modifyRedirects = structuredClone(redirects);
|
|
157
159
|
return modifyRedirects.length
|
|
158
160
|
? modifyRedirects.find((redirect) => {
|
|
161
|
+
// Modify the redirect pattern to ignore the language prefix in the path
|
|
159
162
|
redirect.pattern = redirect.pattern.replace(RegExp(`^[^]?/${language}/`, 'gi'), '');
|
|
163
|
+
// Prepare the redirect pattern as a regular expression, making it more flexible for matching URLs
|
|
160
164
|
redirect.pattern = `/^\/${redirect.pattern
|
|
161
|
-
.replace(/^\/|\/$/g, '')
|
|
162
|
-
.replace(/^\^\/|\/\$$/g, '')
|
|
163
|
-
.replace(/^\^|\$$/g, '')
|
|
164
|
-
.replace(/(?<!\\)\?/g, '\\?')
|
|
165
|
-
.replace(/\$\/gi$/g, '')}[\/]?$/
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
165
|
+
.replace(/^\/|\/$/g, '') // Removes leading and trailing slashes
|
|
166
|
+
.replace(/^\^\/|\/\$$/g, '') // Removes unnecessary start (^) and end ($) anchors
|
|
167
|
+
.replace(/^\^|\$$/g, '') // Further cleans up anchors
|
|
168
|
+
.replace(/(?<!\\)\?/g, '\\?') // Escapes question marks in the pattern
|
|
169
|
+
.replace(/\$\/gi$/g, '')}[\/]?$/i`; // Ensures the pattern allows an optional trailing slash
|
|
170
|
+
/**
|
|
171
|
+
* This line checks whether the current URL query string (and all its possible permutations)
|
|
172
|
+
* matches the redirect pattern.
|
|
173
|
+
*
|
|
174
|
+
* Query parameters in URLs can come in different orders, but logically they represent the
|
|
175
|
+
* same information (e.g., "key1=value1&key2=value2" is the same as "key2=value2&key1=value1").
|
|
176
|
+
* To account for this, the method `isPermutedQueryMatch` generates all possible permutations
|
|
177
|
+
* of the query parameters and checks if any of those permutations match the regex pattern for the redirect.
|
|
178
|
+
*
|
|
179
|
+
* NOTE: This fix is specifically implemented for Netlify, where query parameters are sometimes
|
|
180
|
+
* automatically sorted, which can cause issues with matching redirects if the order of query
|
|
181
|
+
* parameters is important. By checking every possible permutation, we ensure that redirects
|
|
182
|
+
* work correctly on Netlify despite this behavior.
|
|
183
|
+
*
|
|
184
|
+
* It passes several pieces of information to the function:
|
|
185
|
+
* 1. `pathname`: The normalized URL path without query parameters (e.g., '/about').
|
|
186
|
+
* 2. `queryString`: The current query string from the URL, which will be permuted and matched (e.g., '?key1=value1&key2=value2').
|
|
187
|
+
* 3. `pattern`: The regex pattern for the redirect that we are trying to match against the URL (e.g., '/about?key1=value1').
|
|
188
|
+
* 4. `locale`: The locale part of the URL (if any), which helps support multilingual URLs.
|
|
189
|
+
*
|
|
190
|
+
* If one of the permutations of the query string matches the redirect pattern, the function
|
|
191
|
+
* returns the matched query string, which is stored in `matchedQueryString`. If no match is found,
|
|
192
|
+
* it returns `undefined`. The `matchedQueryString` is later used to indicate whether the query
|
|
193
|
+
* string contributed to a successful redirect match.
|
|
194
|
+
*/
|
|
195
|
+
const matchedQueryString = this.isPermutedQueryMatch({
|
|
196
|
+
pathname: targetURL,
|
|
197
|
+
queryString: targetQS,
|
|
198
|
+
pattern: redirect.pattern,
|
|
199
|
+
locale,
|
|
200
|
+
});
|
|
201
|
+
// Save the matched query string (if found) into the redirect object
|
|
202
|
+
redirect.matchedQueryString = matchedQueryString || '';
|
|
203
|
+
// Return the redirect if the URL path or any query string permutation matches the pattern
|
|
204
|
+
return (((0, regex_parser_1.default)(redirect.pattern).test(targetURL) ||
|
|
205
|
+
(0, regex_parser_1.default)(redirect.pattern).test(`/${req.nextUrl.locale}${targetURL}`) ||
|
|
206
|
+
matchedQueryString) &&
|
|
207
|
+
(redirect.locale ? redirect.locale.toLowerCase() === locale.toLowerCase() : true));
|
|
173
208
|
})
|
|
174
209
|
: undefined;
|
|
175
210
|
});
|
|
@@ -178,7 +213,7 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
|
|
|
178
213
|
* When a user clicks on a link generated by the Link component from next/link,
|
|
179
214
|
* Next.js adds special parameters in the route called path.
|
|
180
215
|
* This method removes these special parameters.
|
|
181
|
-
* @param {
|
|
216
|
+
* @param {NextURL} url
|
|
182
217
|
* @returns {string} normalize url
|
|
183
218
|
*/
|
|
184
219
|
normalizeUrl(url) {
|
|
@@ -208,14 +243,15 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
|
|
|
208
243
|
return false;
|
|
209
244
|
})
|
|
210
245
|
.join('&');
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
246
|
+
const newUrl = new URL(`${url.pathname}?${newQueryString}`, url.origin);
|
|
247
|
+
url.search = newUrl.search;
|
|
248
|
+
url.pathname = newUrl.pathname;
|
|
249
|
+
url.href = newUrl.href;
|
|
250
|
+
return url;
|
|
215
251
|
}
|
|
216
252
|
/**
|
|
217
253
|
* Helper function to create a redirect response and remove the x-middleware-next header.
|
|
218
|
-
* @param {
|
|
254
|
+
* @param {NextURL} url The URL to redirect to.
|
|
219
255
|
* @param {Response} res The response object.
|
|
220
256
|
* @param {number} status The HTTP status code of the redirect.
|
|
221
257
|
* @param {string} statusText The status text of the redirect.
|
|
@@ -233,5 +269,24 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
|
|
|
233
269
|
}
|
|
234
270
|
return redirect;
|
|
235
271
|
}
|
|
272
|
+
/**
|
|
273
|
+
* Checks if the current URL query matches the provided pattern, considering all permutations of query parameters.
|
|
274
|
+
* It constructs all possible query parameter permutations and tests them against the pattern.
|
|
275
|
+
* @param {Object} params - The parameters for the URL match.
|
|
276
|
+
* @param {string} params.pathname - The current URL pathname.
|
|
277
|
+
* @param {string} params.queryString - The current URL query string.
|
|
278
|
+
* @param {string} params.pattern - The regex pattern to test the constructed URLs against.
|
|
279
|
+
* @param {string} [params.locale] - The locale prefix to include in the URL if present.
|
|
280
|
+
* @returns {string | undefined} - return query string if any of the query permutations match the provided pattern, undefined otherwise.
|
|
281
|
+
*/
|
|
282
|
+
isPermutedQueryMatch({ pathname, queryString, pattern, locale, }) {
|
|
283
|
+
const paramsArray = Array.from(new URLSearchParams(queryString).entries());
|
|
284
|
+
const listOfPermuted = (0, utils_1.getPermutations)(paramsArray).map((permutation) => '?' + permutation.map(([key, value]) => `${key}=${value}`).join('&'));
|
|
285
|
+
const normalizedPath = pathname.replace(/\/*$/gi, '');
|
|
286
|
+
return listOfPermuted.find((query) => [
|
|
287
|
+
(0, regex_parser_1.default)(pattern).test(`${normalizedPath}${query}`),
|
|
288
|
+
(0, regex_parser_1.default)(pattern).test(`/${locale}${normalizedPath}${query}`),
|
|
289
|
+
].some(Boolean));
|
|
290
|
+
}
|
|
236
291
|
}
|
|
237
292
|
exports.RedirectsMiddleware = RedirectsMiddleware;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { debug } from '@sitecore-jss/sitecore-jss';
|
|
2
|
+
export { MiddlewareBase } from './middleware';
|
|
2
3
|
export { RedirectsMiddleware } from './redirects-middleware';
|
|
3
4
|
export { PersonalizeMiddleware } from './personalize-middleware';
|
|
4
5
|
export { MultisiteMiddleware } from './multisite-middleware';
|
|
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { debug } from '@sitecore-jss/sitecore-jss';
|
|
11
11
|
import { GraphQLRedirectsService, REDIRECT_TYPE_301, REDIRECT_TYPE_302, REDIRECT_TYPE_SERVER_TRANSFER, } from '@sitecore-jss/sitecore-jss/site';
|
|
12
|
+
import { getPermutations } from '@sitecore-jss/sitecore-jss/utils';
|
|
12
13
|
import { NextResponse } from 'next/server';
|
|
13
14
|
import regexParser from 'regex-parser';
|
|
14
15
|
import { MiddlewareBase } from './middleware';
|
|
@@ -58,13 +59,14 @@ export class RedirectsMiddleware extends MiddlewareBase {
|
|
|
58
59
|
!(REGEXP_ABSOLUTE_URL.test(existsRedirect.target) &&
|
|
59
60
|
existsRedirect.target.includes(hostname))) {
|
|
60
61
|
existsRedirect.target = existsRedirect.target.replace(REGEXP_CONTEXT_SITE_LANG, site.language);
|
|
62
|
+
req.nextUrl.locale = site.language;
|
|
61
63
|
}
|
|
62
64
|
const url = this.normalizeUrl(req.nextUrl.clone());
|
|
63
65
|
if (REGEXP_ABSOLUTE_URL.test(existsRedirect.target)) {
|
|
64
66
|
url.href = existsRedirect.target;
|
|
65
67
|
}
|
|
66
68
|
else {
|
|
67
|
-
const source = `${url.pathname.replace(/\/*$/gi, '')}${
|
|
69
|
+
const source = `${url.pathname.replace(/\/*$/gi, '')}${existsRedirect.matchedQueryString}`;
|
|
68
70
|
const urlFirstPart = existsRedirect.target.split('/')[1];
|
|
69
71
|
if (this.locales.includes(urlFirstPart)) {
|
|
70
72
|
req.nextUrl.locale = urlFirstPart;
|
|
@@ -86,18 +88,20 @@ export class RedirectsMiddleware extends MiddlewareBase {
|
|
|
86
88
|
}
|
|
87
89
|
const prepareNewURL = new URL(`${target[0]}${url.search}`, url.origin);
|
|
88
90
|
url.href = prepareNewURL.href;
|
|
91
|
+
url.pathname = prepareNewURL.pathname;
|
|
92
|
+
url.search = prepareNewURL.search;
|
|
93
|
+
url.locale = req.nextUrl.locale;
|
|
89
94
|
}
|
|
90
|
-
const redirectUrl = decodeURIComponent(url.href);
|
|
91
95
|
/** return Response redirect with http code of redirect type **/
|
|
92
96
|
switch (existsRedirect.redirectType) {
|
|
93
97
|
case REDIRECT_TYPE_301: {
|
|
94
|
-
return this.createRedirectResponse(
|
|
98
|
+
return this.createRedirectResponse(url, res, 301, 'Moved Permanently');
|
|
95
99
|
}
|
|
96
100
|
case REDIRECT_TYPE_302: {
|
|
97
|
-
return this.createRedirectResponse(
|
|
101
|
+
return this.createRedirectResponse(url, res, 302, 'Found');
|
|
98
102
|
}
|
|
99
103
|
case REDIRECT_TYPE_SERVER_TRANSFER: {
|
|
100
|
-
return this.rewrite(
|
|
104
|
+
return this.rewrite(url.href, req, res || NextResponse.next());
|
|
101
105
|
}
|
|
102
106
|
default:
|
|
103
107
|
return res || NextResponse.next();
|
|
@@ -143,27 +147,58 @@ export class RedirectsMiddleware extends MiddlewareBase {
|
|
|
143
147
|
getExistsRedirect(req, siteName) {
|
|
144
148
|
return __awaiter(this, void 0, void 0, function* () {
|
|
145
149
|
const redirects = yield this.redirectsService.fetchRedirects(siteName);
|
|
146
|
-
const
|
|
147
|
-
const tragetURL = normalizedUrl.pathname;
|
|
148
|
-
const targetQS = normalizedUrl.search || '';
|
|
150
|
+
const { pathname: targetURL, search: targetQS = '', locale } = this.normalizeUrl(req.nextUrl.clone());
|
|
149
151
|
const language = this.getLanguage(req);
|
|
150
152
|
const modifyRedirects = structuredClone(redirects);
|
|
151
153
|
return modifyRedirects.length
|
|
152
154
|
? modifyRedirects.find((redirect) => {
|
|
155
|
+
// Modify the redirect pattern to ignore the language prefix in the path
|
|
153
156
|
redirect.pattern = redirect.pattern.replace(RegExp(`^[^]?/${language}/`, 'gi'), '');
|
|
157
|
+
// Prepare the redirect pattern as a regular expression, making it more flexible for matching URLs
|
|
154
158
|
redirect.pattern = `/^\/${redirect.pattern
|
|
155
|
-
.replace(/^\/|\/$/g, '')
|
|
156
|
-
.replace(/^\^\/|\/\$$/g, '')
|
|
157
|
-
.replace(/^\^|\$$/g, '')
|
|
158
|
-
.replace(/(?<!\\)\?/g, '\\?')
|
|
159
|
-
.replace(/\$\/gi$/g, '')}[\/]?$/
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
159
|
+
.replace(/^\/|\/$/g, '') // Removes leading and trailing slashes
|
|
160
|
+
.replace(/^\^\/|\/\$$/g, '') // Removes unnecessary start (^) and end ($) anchors
|
|
161
|
+
.replace(/^\^|\$$/g, '') // Further cleans up anchors
|
|
162
|
+
.replace(/(?<!\\)\?/g, '\\?') // Escapes question marks in the pattern
|
|
163
|
+
.replace(/\$\/gi$/g, '')}[\/]?$/i`; // Ensures the pattern allows an optional trailing slash
|
|
164
|
+
/**
|
|
165
|
+
* This line checks whether the current URL query string (and all its possible permutations)
|
|
166
|
+
* matches the redirect pattern.
|
|
167
|
+
*
|
|
168
|
+
* Query parameters in URLs can come in different orders, but logically they represent the
|
|
169
|
+
* same information (e.g., "key1=value1&key2=value2" is the same as "key2=value2&key1=value1").
|
|
170
|
+
* To account for this, the method `isPermutedQueryMatch` generates all possible permutations
|
|
171
|
+
* of the query parameters and checks if any of those permutations match the regex pattern for the redirect.
|
|
172
|
+
*
|
|
173
|
+
* NOTE: This fix is specifically implemented for Netlify, where query parameters are sometimes
|
|
174
|
+
* automatically sorted, which can cause issues with matching redirects if the order of query
|
|
175
|
+
* parameters is important. By checking every possible permutation, we ensure that redirects
|
|
176
|
+
* work correctly on Netlify despite this behavior.
|
|
177
|
+
*
|
|
178
|
+
* It passes several pieces of information to the function:
|
|
179
|
+
* 1. `pathname`: The normalized URL path without query parameters (e.g., '/about').
|
|
180
|
+
* 2. `queryString`: The current query string from the URL, which will be permuted and matched (e.g., '?key1=value1&key2=value2').
|
|
181
|
+
* 3. `pattern`: The regex pattern for the redirect that we are trying to match against the URL (e.g., '/about?key1=value1').
|
|
182
|
+
* 4. `locale`: The locale part of the URL (if any), which helps support multilingual URLs.
|
|
183
|
+
*
|
|
184
|
+
* If one of the permutations of the query string matches the redirect pattern, the function
|
|
185
|
+
* returns the matched query string, which is stored in `matchedQueryString`. If no match is found,
|
|
186
|
+
* it returns `undefined`. The `matchedQueryString` is later used to indicate whether the query
|
|
187
|
+
* string contributed to a successful redirect match.
|
|
188
|
+
*/
|
|
189
|
+
const matchedQueryString = this.isPermutedQueryMatch({
|
|
190
|
+
pathname: targetURL,
|
|
191
|
+
queryString: targetQS,
|
|
192
|
+
pattern: redirect.pattern,
|
|
193
|
+
locale,
|
|
194
|
+
});
|
|
195
|
+
// Save the matched query string (if found) into the redirect object
|
|
196
|
+
redirect.matchedQueryString = matchedQueryString || '';
|
|
197
|
+
// Return the redirect if the URL path or any query string permutation matches the pattern
|
|
198
|
+
return ((regexParser(redirect.pattern).test(targetURL) ||
|
|
199
|
+
regexParser(redirect.pattern).test(`/${req.nextUrl.locale}${targetURL}`) ||
|
|
200
|
+
matchedQueryString) &&
|
|
201
|
+
(redirect.locale ? redirect.locale.toLowerCase() === locale.toLowerCase() : true));
|
|
167
202
|
})
|
|
168
203
|
: undefined;
|
|
169
204
|
});
|
|
@@ -172,7 +207,7 @@ export class RedirectsMiddleware extends MiddlewareBase {
|
|
|
172
207
|
* When a user clicks on a link generated by the Link component from next/link,
|
|
173
208
|
* Next.js adds special parameters in the route called path.
|
|
174
209
|
* This method removes these special parameters.
|
|
175
|
-
* @param {
|
|
210
|
+
* @param {NextURL} url
|
|
176
211
|
* @returns {string} normalize url
|
|
177
212
|
*/
|
|
178
213
|
normalizeUrl(url) {
|
|
@@ -202,14 +237,15 @@ export class RedirectsMiddleware extends MiddlewareBase {
|
|
|
202
237
|
return false;
|
|
203
238
|
})
|
|
204
239
|
.join('&');
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
240
|
+
const newUrl = new URL(`${url.pathname}?${newQueryString}`, url.origin);
|
|
241
|
+
url.search = newUrl.search;
|
|
242
|
+
url.pathname = newUrl.pathname;
|
|
243
|
+
url.href = newUrl.href;
|
|
244
|
+
return url;
|
|
209
245
|
}
|
|
210
246
|
/**
|
|
211
247
|
* Helper function to create a redirect response and remove the x-middleware-next header.
|
|
212
|
-
* @param {
|
|
248
|
+
* @param {NextURL} url The URL to redirect to.
|
|
213
249
|
* @param {Response} res The response object.
|
|
214
250
|
* @param {number} status The HTTP status code of the redirect.
|
|
215
251
|
* @param {string} statusText The status text of the redirect.
|
|
@@ -227,4 +263,23 @@ export class RedirectsMiddleware extends MiddlewareBase {
|
|
|
227
263
|
}
|
|
228
264
|
return redirect;
|
|
229
265
|
}
|
|
266
|
+
/**
|
|
267
|
+
* Checks if the current URL query matches the provided pattern, considering all permutations of query parameters.
|
|
268
|
+
* It constructs all possible query parameter permutations and tests them against the pattern.
|
|
269
|
+
* @param {Object} params - The parameters for the URL match.
|
|
270
|
+
* @param {string} params.pathname - The current URL pathname.
|
|
271
|
+
* @param {string} params.queryString - The current URL query string.
|
|
272
|
+
* @param {string} params.pattern - The regex pattern to test the constructed URLs against.
|
|
273
|
+
* @param {string} [params.locale] - The locale prefix to include in the URL if present.
|
|
274
|
+
* @returns {string | undefined} - return query string if any of the query permutations match the provided pattern, undefined otherwise.
|
|
275
|
+
*/
|
|
276
|
+
isPermutedQueryMatch({ pathname, queryString, pattern, locale, }) {
|
|
277
|
+
const paramsArray = Array.from(new URLSearchParams(queryString).entries());
|
|
278
|
+
const listOfPermuted = getPermutations(paramsArray).map((permutation) => '?' + permutation.map(([key, value]) => `${key}=${value}`).join('&'));
|
|
279
|
+
const normalizedPath = pathname.replace(/\/*$/gi, '');
|
|
280
|
+
return listOfPermuted.find((query) => [
|
|
281
|
+
regexParser(pattern).test(`${normalizedPath}${query}`),
|
|
282
|
+
regexParser(pattern).test(`/${locale}${normalizedPath}${query}`),
|
|
283
|
+
].some(Boolean));
|
|
284
|
+
}
|
|
230
285
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sitecore-jss/sitecore-jss-nextjs",
|
|
3
|
-
"version": "22.1.
|
|
3
|
+
"version": "22.1.4-canary.2",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -72,9 +72,9 @@
|
|
|
72
72
|
"react-dom": "^18.2.0"
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"@sitecore-jss/sitecore-jss": "22.1.
|
|
76
|
-
"@sitecore-jss/sitecore-jss-dev-tools": "22.1.
|
|
77
|
-
"@sitecore-jss/sitecore-jss-react": "22.1.
|
|
75
|
+
"@sitecore-jss/sitecore-jss": "^22.1.4-canary.2",
|
|
76
|
+
"@sitecore-jss/sitecore-jss-dev-tools": "^22.1.4-canary.2",
|
|
77
|
+
"@sitecore-jss/sitecore-jss-react": "^22.1.4-canary.2",
|
|
78
78
|
"@vercel/kv": "^0.2.1",
|
|
79
79
|
"prop-types": "^15.8.1",
|
|
80
80
|
"regex-parser": "^2.2.11",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
},
|
|
83
83
|
"description": "",
|
|
84
84
|
"types": "types/index.d.ts",
|
|
85
|
-
"gitHead": "
|
|
85
|
+
"gitHead": "9c234dbfd9a89e86bc4d2c2371b2e848e2df2291",
|
|
86
86
|
"files": [
|
|
87
87
|
"dist",
|
|
88
88
|
"types",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { debug } from '@sitecore-jss/sitecore-jss';
|
|
2
|
+
export { MiddlewareBase, MiddlewareBaseConfig } from './middleware';
|
|
2
3
|
export { RedirectsMiddleware, RedirectsMiddlewareConfig } from './redirects-middleware';
|
|
3
4
|
export { PersonalizeMiddleware, PersonalizeMiddlewareConfig } from './personalize-middleware';
|
|
4
5
|
export { MultisiteMiddleware, MultisiteMiddlewareConfig } from './multisite-middleware';
|
|
@@ -41,17 +41,28 @@ export declare class RedirectsMiddleware extends MiddlewareBase {
|
|
|
41
41
|
* When a user clicks on a link generated by the Link component from next/link,
|
|
42
42
|
* Next.js adds special parameters in the route called path.
|
|
43
43
|
* This method removes these special parameters.
|
|
44
|
-
* @param {
|
|
44
|
+
* @param {NextURL} url
|
|
45
45
|
* @returns {string} normalize url
|
|
46
46
|
*/
|
|
47
47
|
private normalizeUrl;
|
|
48
48
|
/**
|
|
49
49
|
* Helper function to create a redirect response and remove the x-middleware-next header.
|
|
50
|
-
* @param {
|
|
50
|
+
* @param {NextURL} url The URL to redirect to.
|
|
51
51
|
* @param {Response} res The response object.
|
|
52
52
|
* @param {number} status The HTTP status code of the redirect.
|
|
53
53
|
* @param {string} statusText The status text of the redirect.
|
|
54
54
|
* @returns {NextResponse<unknown>} The redirect response.
|
|
55
55
|
*/
|
|
56
56
|
private createRedirectResponse;
|
|
57
|
+
/**
|
|
58
|
+
* Checks if the current URL query matches the provided pattern, considering all permutations of query parameters.
|
|
59
|
+
* It constructs all possible query parameter permutations and tests them against the pattern.
|
|
60
|
+
* @param {Object} params - The parameters for the URL match.
|
|
61
|
+
* @param {string} params.pathname - The current URL pathname.
|
|
62
|
+
* @param {string} params.queryString - The current URL query string.
|
|
63
|
+
* @param {string} params.pattern - The regex pattern to test the constructed URLs against.
|
|
64
|
+
* @param {string} [params.locale] - The locale prefix to include in the URL if present.
|
|
65
|
+
* @returns {string | undefined} - return query string if any of the query permutations match the provided pattern, undefined otherwise.
|
|
66
|
+
*/
|
|
67
|
+
private isPermutedQueryMatch;
|
|
57
68
|
}
|