@sitecore-jss/sitecore-jss-nextjs 21.5.0-canary.9 → 21.5.0
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 +9 -9
- package/dist/cjs/middleware/personalize-middleware.js +60 -49
- package/dist/cjs/middleware/redirects-middleware.js +2 -1
- package/dist/esm/middleware/personalize-middleware.js +63 -52
- package/dist/esm/middleware/redirects-middleware.js +2 -1
- package/package.json +7 -5
- package/types/middleware/personalize-middleware.d.ts +40 -7
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,9 +1,9 @@
|
|
|
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
|
-
[Documentation (Experience Platform)](https://doc.sitecore.com/xp/en/developers/hd/21/sitecore-headless-development/sitecore-javascript-rendering-sdk--jss--for-next-js.html)
|
|
6
|
-
|
|
7
|
-
[Documentation (XM Cloud)](https://doc.sitecore.com/xmc/en/developers/xm-cloud/sitecore-javascript-rendering-sdk--jss--for-next-js.html)
|
|
8
|
-
|
|
9
|
-
[API reference documentation](/ref-docs/sitecore-jss-nextjs/)
|
|
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
|
+
[Documentation (Experience Platform)](https://doc.sitecore.com/xp/en/developers/hd/21/sitecore-headless-development/sitecore-javascript-rendering-sdk--jss--for-next-js.html)
|
|
6
|
+
|
|
7
|
+
[Documentation (XM Cloud)](https://doc.sitecore.com/xmc/en/developers/xm-cloud/sitecore-javascript-rendering-sdk--jss--for-next-js.html)
|
|
8
|
+
|
|
9
|
+
[API reference documentation](/ref-docs/sitecore-jss-nextjs/)
|
|
@@ -14,6 +14,7 @@ const server_1 = require("next/server");
|
|
|
14
14
|
const personalize_1 = require("@sitecore-jss/sitecore-jss/personalize");
|
|
15
15
|
const sitecore_jss_1 = require("@sitecore-jss/sitecore-jss");
|
|
16
16
|
const middleware_1 = require("./middleware");
|
|
17
|
+
const engage_1 = require("@sitecore/engage");
|
|
17
18
|
/**
|
|
18
19
|
* Middleware / handler to support Sitecore Personalize
|
|
19
20
|
*/
|
|
@@ -25,19 +26,20 @@ class PersonalizeMiddleware extends middleware_1.MiddlewareBase {
|
|
|
25
26
|
super(config);
|
|
26
27
|
this.config = config;
|
|
27
28
|
this.handler = (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
var _a;
|
|
28
30
|
const pathname = req.nextUrl.pathname;
|
|
29
31
|
const language = this.getLanguage(req);
|
|
30
32
|
const hostname = this.getHostHeader(req) || this.defaultHostname;
|
|
31
33
|
const startTimestamp = Date.now();
|
|
32
|
-
|
|
34
|
+
const timeout = this.config.cdpConfig.timeout;
|
|
35
|
+
// Response will be provided if other middleware is run before us (e.g. redirects)
|
|
36
|
+
let response = res || server_1.NextResponse.next();
|
|
33
37
|
sitecore_jss_1.debug.personalize('personalize middleware start: %o', {
|
|
34
38
|
pathname,
|
|
35
39
|
language,
|
|
36
40
|
hostname,
|
|
37
|
-
|
|
41
|
+
headers: this.extractDebugHeaders(req.headers),
|
|
38
42
|
});
|
|
39
|
-
// Response will be provided if other middleware is run before us (e.g. redirects)
|
|
40
|
-
let response = res || server_1.NextResponse.next();
|
|
41
43
|
if (this.config.disabled && this.config.disabled(req, response)) {
|
|
42
44
|
sitecore_jss_1.debug.personalize('skipped (personalize middleware is disabled)');
|
|
43
45
|
return response;
|
|
@@ -48,7 +50,7 @@ class PersonalizeMiddleware extends middleware_1.MiddlewareBase {
|
|
|
48
50
|
sitecore_jss_1.debug.personalize('skipped (%s)', response.redirected ? 'redirected' : this.isPreview(req) ? 'preview' : 'route excluded');
|
|
49
51
|
return response;
|
|
50
52
|
}
|
|
51
|
-
const site = this.getSite(req,
|
|
53
|
+
const site = this.getSite(req, response);
|
|
52
54
|
// Get personalization info from Experience Edge
|
|
53
55
|
const personalizeInfo = yield this.personalizeService.getPersonalizeInfo(pathname, language, site.name);
|
|
54
56
|
if (!personalizeInfo) {
|
|
@@ -60,20 +62,34 @@ class PersonalizeMiddleware extends middleware_1.MiddlewareBase {
|
|
|
60
62
|
sitecore_jss_1.debug.personalize('skipped (no personalization configured)');
|
|
61
63
|
return response;
|
|
62
64
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
const engageServer = this.initializeEngageServer(hostname, site, language);
|
|
66
|
+
// creates the browser ID cookie on the server side
|
|
67
|
+
// and includes the cookie in the response header
|
|
68
|
+
try {
|
|
69
|
+
yield engageServer.handleCookie(req, response, timeout);
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
sitecore_jss_1.debug.personalize('skipped (browser id generation failed)');
|
|
73
|
+
throw error;
|
|
69
74
|
}
|
|
70
|
-
// Execute targeted experience in CDP
|
|
71
|
-
const { ua } = (0, server_1.userAgent)(req);
|
|
72
75
|
const params = this.getExperienceParams(req);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
:
|
|
76
|
-
|
|
76
|
+
sitecore_jss_1.debug.personalize('executing experience for %s %s %o', personalizeInfo.contentId, params);
|
|
77
|
+
const personalizationData = {
|
|
78
|
+
channel: this.config.cdpConfig.channel || 'WEB',
|
|
79
|
+
currency: (_a = this.config.cdpConfig.currency) !== null && _a !== void 0 ? _a : 'USA',
|
|
80
|
+
friendlyId: personalizeInfo.contentId,
|
|
81
|
+
params,
|
|
82
|
+
language,
|
|
83
|
+
};
|
|
84
|
+
let variantId;
|
|
85
|
+
// Execute targeted experience in CDP
|
|
86
|
+
// eslint-disable-next-line no-useless-catch
|
|
87
|
+
try {
|
|
88
|
+
variantId = (yield engageServer.personalize(personalizationData, req, timeout)).variantId;
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
77
93
|
if (!variantId) {
|
|
78
94
|
sitecore_jss_1.debug.personalize('skipped (no variant identified)');
|
|
79
95
|
return response;
|
|
@@ -88,20 +104,24 @@ class PersonalizeMiddleware extends middleware_1.MiddlewareBase {
|
|
|
88
104
|
const rewritePath = (0, personalize_1.getPersonalizedRewrite)(basePath, { variantId });
|
|
89
105
|
// Note an absolute URL is required: https://nextjs.org/docs/messages/middleware-relative-urls
|
|
90
106
|
const rewriteUrl = req.nextUrl.clone();
|
|
107
|
+
// Preserve cookies from previous response
|
|
108
|
+
const cookies = response.cookies.getAll();
|
|
91
109
|
rewriteUrl.pathname = rewritePath;
|
|
92
|
-
response = server_1.NextResponse.rewrite(rewriteUrl);
|
|
110
|
+
response = server_1.NextResponse.rewrite(rewriteUrl, response);
|
|
93
111
|
// Disable preflight caching to force revalidation on client-side navigation (personalization may be influenced)
|
|
94
112
|
// See https://github.com/vercel/next.js/issues/32727
|
|
95
113
|
response.headers.set('x-middleware-cache', 'no-cache');
|
|
96
|
-
// Share rewrite path with following executed
|
|
114
|
+
// Share rewrite path with following executed middleware
|
|
97
115
|
response.headers.set('x-sc-rewrite', rewritePath);
|
|
98
|
-
// Set browserId cookie on the response
|
|
99
|
-
this.setBrowserId(response, browserId);
|
|
100
116
|
// Share site name with the following executed middlewares
|
|
101
117
|
response.cookies.set(this.SITE_SYMBOL, site.name);
|
|
118
|
+
// Restore cookies from previous response since
|
|
119
|
+
// browserId cookie gets omitted after rewrite
|
|
120
|
+
cookies.forEach((cookie) => {
|
|
121
|
+
response.cookies.set(cookie);
|
|
122
|
+
});
|
|
102
123
|
sitecore_jss_1.debug.personalize('personalize middleware end in %dms: %o', Date.now() - startTimestamp, {
|
|
103
124
|
rewritePath,
|
|
104
|
-
browserId,
|
|
105
125
|
headers: this.extractDebugHeaders(response.headers),
|
|
106
126
|
});
|
|
107
127
|
return response;
|
|
@@ -109,15 +129,6 @@ class PersonalizeMiddleware extends middleware_1.MiddlewareBase {
|
|
|
109
129
|
// NOTE: we provide native fetch for compatibility on Next.js Edge Runtime
|
|
110
130
|
// (underlying default 'cross-fetch' is not currently compatible: https://github.com/lquixada/cross-fetch/issues/78)
|
|
111
131
|
this.personalizeService = new personalize_1.GraphQLPersonalizeService(Object.assign(Object.assign({}, config.edgeConfig), { fetch: fetch }));
|
|
112
|
-
// NOTE: same here, we provide NativeDataFetcher for compatibility on Next.js Edge Runtime
|
|
113
|
-
this.cdpService = new personalize_1.CdpService(Object.assign(Object.assign({}, config.cdpConfig), { dataFetcherResolver: ({ timeout, headers, }) => {
|
|
114
|
-
const fetcher = new sitecore_jss_1.NativeDataFetcher({
|
|
115
|
-
debugger: sitecore_jss_1.debug.personalize,
|
|
116
|
-
timeout,
|
|
117
|
-
headers,
|
|
118
|
-
});
|
|
119
|
-
return (url, data) => fetcher.fetch(url, data);
|
|
120
|
-
} }));
|
|
121
132
|
}
|
|
122
133
|
/**
|
|
123
134
|
* Gets the Next.js middleware handler with error handling
|
|
@@ -135,31 +146,31 @@ class PersonalizeMiddleware extends middleware_1.MiddlewareBase {
|
|
|
135
146
|
}
|
|
136
147
|
});
|
|
137
148
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
res.cookies.set(this.browserIdCookieName, browserId, options);
|
|
149
|
+
initializeEngageServer(hostName, site, language) {
|
|
150
|
+
const engageServer = (0, engage_1.initServer)({
|
|
151
|
+
clientKey: this.config.cdpConfig.clientKey,
|
|
152
|
+
targetURL: this.config.cdpConfig.endpoint,
|
|
153
|
+
pointOfSale: this.config.getPointOfSale
|
|
154
|
+
? this.config.getPointOfSale(site, language)
|
|
155
|
+
: personalize_1.PosResolver.resolve(site, language),
|
|
156
|
+
cookieDomain: hostName,
|
|
157
|
+
forceServerCookieMode: true,
|
|
158
|
+
});
|
|
159
|
+
return engageServer;
|
|
150
160
|
}
|
|
151
161
|
getExperienceParams(req) {
|
|
162
|
+
const utm = {
|
|
163
|
+
campaign: req.nextUrl.searchParams.get('utm_campaign') || undefined,
|
|
164
|
+
content: req.nextUrl.searchParams.get('utm_content') || undefined,
|
|
165
|
+
medium: req.nextUrl.searchParams.get('utm_medium') || undefined,
|
|
166
|
+
source: req.nextUrl.searchParams.get('utm_source') || undefined,
|
|
167
|
+
};
|
|
152
168
|
return {
|
|
153
169
|
// It's expected that the header name "referer" is actually a misspelling of the word "referrer"
|
|
154
170
|
// req.referrer is used during fetching to determine the value of the Referer header of the request being made,
|
|
155
171
|
// used as a fallback
|
|
156
172
|
referrer: req.headers.get('referer') || req.referrer,
|
|
157
|
-
utm:
|
|
158
|
-
campaign: req.nextUrl.searchParams.get('utm_campaign'),
|
|
159
|
-
content: req.nextUrl.searchParams.get('utm_content'),
|
|
160
|
-
medium: req.nextUrl.searchParams.get('utm_medium'),
|
|
161
|
-
source: req.nextUrl.searchParams.get('utm_source'),
|
|
162
|
-
},
|
|
173
|
+
utm: utm,
|
|
163
174
|
};
|
|
164
175
|
}
|
|
165
176
|
excludeRoute(pathname) {
|
|
@@ -141,7 +141,8 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
|
|
|
141
141
|
redirect.pattern = `/^\/${redirect.pattern
|
|
142
142
|
.replace(/^\/|\/$/g, '')
|
|
143
143
|
.replace(/^\^\/|\/\$$/g, '')
|
|
144
|
-
.replace(/^\^|\$$/g, '')
|
|
144
|
+
.replace(/^\^|\$$/g, '')
|
|
145
|
+
.replace(/\$\/gi$/g, '')}$/gi`;
|
|
145
146
|
return (((0, regex_parser_1.default)(redirect.pattern).test(tragetURL) ||
|
|
146
147
|
(0, regex_parser_1.default)(redirect.pattern).test(`${tragetURL}${targetQS}`) ||
|
|
147
148
|
(0, regex_parser_1.default)(redirect.pattern).test(`/${req.nextUrl.locale}${tragetURL}`) ||
|
|
@@ -7,10 +7,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { NextResponse
|
|
11
|
-
import { GraphQLPersonalizeService,
|
|
12
|
-
import { debug
|
|
10
|
+
import { NextResponse } from 'next/server';
|
|
11
|
+
import { GraphQLPersonalizeService, getPersonalizedRewrite, PosResolver, } from '@sitecore-jss/sitecore-jss/personalize';
|
|
12
|
+
import { debug } from '@sitecore-jss/sitecore-jss';
|
|
13
13
|
import { MiddlewareBase } from './middleware';
|
|
14
|
+
import { initServer } from '@sitecore/engage';
|
|
14
15
|
/**
|
|
15
16
|
* Middleware / handler to support Sitecore Personalize
|
|
16
17
|
*/
|
|
@@ -22,19 +23,20 @@ export class PersonalizeMiddleware extends MiddlewareBase {
|
|
|
22
23
|
super(config);
|
|
23
24
|
this.config = config;
|
|
24
25
|
this.handler = (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
var _a;
|
|
25
27
|
const pathname = req.nextUrl.pathname;
|
|
26
28
|
const language = this.getLanguage(req);
|
|
27
29
|
const hostname = this.getHostHeader(req) || this.defaultHostname;
|
|
28
30
|
const startTimestamp = Date.now();
|
|
29
|
-
|
|
31
|
+
const timeout = this.config.cdpConfig.timeout;
|
|
32
|
+
// Response will be provided if other middleware is run before us (e.g. redirects)
|
|
33
|
+
let response = res || NextResponse.next();
|
|
30
34
|
debug.personalize('personalize middleware start: %o', {
|
|
31
35
|
pathname,
|
|
32
36
|
language,
|
|
33
37
|
hostname,
|
|
34
|
-
|
|
38
|
+
headers: this.extractDebugHeaders(req.headers),
|
|
35
39
|
});
|
|
36
|
-
// Response will be provided if other middleware is run before us (e.g. redirects)
|
|
37
|
-
let response = res || NextResponse.next();
|
|
38
40
|
if (this.config.disabled && this.config.disabled(req, response)) {
|
|
39
41
|
debug.personalize('skipped (personalize middleware is disabled)');
|
|
40
42
|
return response;
|
|
@@ -45,7 +47,7 @@ export class PersonalizeMiddleware extends MiddlewareBase {
|
|
|
45
47
|
debug.personalize('skipped (%s)', response.redirected ? 'redirected' : this.isPreview(req) ? 'preview' : 'route excluded');
|
|
46
48
|
return response;
|
|
47
49
|
}
|
|
48
|
-
const site = this.getSite(req,
|
|
50
|
+
const site = this.getSite(req, response);
|
|
49
51
|
// Get personalization info from Experience Edge
|
|
50
52
|
const personalizeInfo = yield this.personalizeService.getPersonalizeInfo(pathname, language, site.name);
|
|
51
53
|
if (!personalizeInfo) {
|
|
@@ -57,20 +59,34 @@ export class PersonalizeMiddleware extends MiddlewareBase {
|
|
|
57
59
|
debug.personalize('skipped (no personalization configured)');
|
|
58
60
|
return response;
|
|
59
61
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
const engageServer = this.initializeEngageServer(hostname, site, language);
|
|
63
|
+
// creates the browser ID cookie on the server side
|
|
64
|
+
// and includes the cookie in the response header
|
|
65
|
+
try {
|
|
66
|
+
yield engageServer.handleCookie(req, response, timeout);
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
debug.personalize('skipped (browser id generation failed)');
|
|
70
|
+
throw error;
|
|
66
71
|
}
|
|
67
|
-
// Execute targeted experience in CDP
|
|
68
|
-
const { ua } = userAgent(req);
|
|
69
72
|
const params = this.getExperienceParams(req);
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
:
|
|
73
|
-
|
|
73
|
+
debug.personalize('executing experience for %s %s %o', personalizeInfo.contentId, params);
|
|
74
|
+
const personalizationData = {
|
|
75
|
+
channel: this.config.cdpConfig.channel || 'WEB',
|
|
76
|
+
currency: (_a = this.config.cdpConfig.currency) !== null && _a !== void 0 ? _a : 'USA',
|
|
77
|
+
friendlyId: personalizeInfo.contentId,
|
|
78
|
+
params,
|
|
79
|
+
language,
|
|
80
|
+
};
|
|
81
|
+
let variantId;
|
|
82
|
+
// Execute targeted experience in CDP
|
|
83
|
+
// eslint-disable-next-line no-useless-catch
|
|
84
|
+
try {
|
|
85
|
+
variantId = (yield engageServer.personalize(personalizationData, req, timeout)).variantId;
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
74
90
|
if (!variantId) {
|
|
75
91
|
debug.personalize('skipped (no variant identified)');
|
|
76
92
|
return response;
|
|
@@ -85,20 +101,24 @@ export class PersonalizeMiddleware extends MiddlewareBase {
|
|
|
85
101
|
const rewritePath = getPersonalizedRewrite(basePath, { variantId });
|
|
86
102
|
// Note an absolute URL is required: https://nextjs.org/docs/messages/middleware-relative-urls
|
|
87
103
|
const rewriteUrl = req.nextUrl.clone();
|
|
104
|
+
// Preserve cookies from previous response
|
|
105
|
+
const cookies = response.cookies.getAll();
|
|
88
106
|
rewriteUrl.pathname = rewritePath;
|
|
89
|
-
response = NextResponse.rewrite(rewriteUrl);
|
|
107
|
+
response = NextResponse.rewrite(rewriteUrl, response);
|
|
90
108
|
// Disable preflight caching to force revalidation on client-side navigation (personalization may be influenced)
|
|
91
109
|
// See https://github.com/vercel/next.js/issues/32727
|
|
92
110
|
response.headers.set('x-middleware-cache', 'no-cache');
|
|
93
|
-
// Share rewrite path with following executed
|
|
111
|
+
// Share rewrite path with following executed middleware
|
|
94
112
|
response.headers.set('x-sc-rewrite', rewritePath);
|
|
95
|
-
// Set browserId cookie on the response
|
|
96
|
-
this.setBrowserId(response, browserId);
|
|
97
113
|
// Share site name with the following executed middlewares
|
|
98
114
|
response.cookies.set(this.SITE_SYMBOL, site.name);
|
|
115
|
+
// Restore cookies from previous response since
|
|
116
|
+
// browserId cookie gets omitted after rewrite
|
|
117
|
+
cookies.forEach((cookie) => {
|
|
118
|
+
response.cookies.set(cookie);
|
|
119
|
+
});
|
|
99
120
|
debug.personalize('personalize middleware end in %dms: %o', Date.now() - startTimestamp, {
|
|
100
121
|
rewritePath,
|
|
101
|
-
browserId,
|
|
102
122
|
headers: this.extractDebugHeaders(response.headers),
|
|
103
123
|
});
|
|
104
124
|
return response;
|
|
@@ -106,15 +126,6 @@ export class PersonalizeMiddleware extends MiddlewareBase {
|
|
|
106
126
|
// NOTE: we provide native fetch for compatibility on Next.js Edge Runtime
|
|
107
127
|
// (underlying default 'cross-fetch' is not currently compatible: https://github.com/lquixada/cross-fetch/issues/78)
|
|
108
128
|
this.personalizeService = new GraphQLPersonalizeService(Object.assign(Object.assign({}, config.edgeConfig), { fetch: fetch }));
|
|
109
|
-
// NOTE: same here, we provide NativeDataFetcher for compatibility on Next.js Edge Runtime
|
|
110
|
-
this.cdpService = new CdpService(Object.assign(Object.assign({}, config.cdpConfig), { dataFetcherResolver: ({ timeout, headers, }) => {
|
|
111
|
-
const fetcher = new NativeDataFetcher({
|
|
112
|
-
debugger: debug.personalize,
|
|
113
|
-
timeout,
|
|
114
|
-
headers,
|
|
115
|
-
});
|
|
116
|
-
return (url, data) => fetcher.fetch(url, data);
|
|
117
|
-
} }));
|
|
118
129
|
}
|
|
119
130
|
/**
|
|
120
131
|
* Gets the Next.js middleware handler with error handling
|
|
@@ -132,31 +143,31 @@ export class PersonalizeMiddleware extends MiddlewareBase {
|
|
|
132
143
|
}
|
|
133
144
|
});
|
|
134
145
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
res.cookies.set(this.browserIdCookieName, browserId, options);
|
|
146
|
+
initializeEngageServer(hostName, site, language) {
|
|
147
|
+
const engageServer = initServer({
|
|
148
|
+
clientKey: this.config.cdpConfig.clientKey,
|
|
149
|
+
targetURL: this.config.cdpConfig.endpoint,
|
|
150
|
+
pointOfSale: this.config.getPointOfSale
|
|
151
|
+
? this.config.getPointOfSale(site, language)
|
|
152
|
+
: PosResolver.resolve(site, language),
|
|
153
|
+
cookieDomain: hostName,
|
|
154
|
+
forceServerCookieMode: true,
|
|
155
|
+
});
|
|
156
|
+
return engageServer;
|
|
147
157
|
}
|
|
148
158
|
getExperienceParams(req) {
|
|
159
|
+
const utm = {
|
|
160
|
+
campaign: req.nextUrl.searchParams.get('utm_campaign') || undefined,
|
|
161
|
+
content: req.nextUrl.searchParams.get('utm_content') || undefined,
|
|
162
|
+
medium: req.nextUrl.searchParams.get('utm_medium') || undefined,
|
|
163
|
+
source: req.nextUrl.searchParams.get('utm_source') || undefined,
|
|
164
|
+
};
|
|
149
165
|
return {
|
|
150
166
|
// It's expected that the header name "referer" is actually a misspelling of the word "referrer"
|
|
151
167
|
// req.referrer is used during fetching to determine the value of the Referer header of the request being made,
|
|
152
168
|
// used as a fallback
|
|
153
169
|
referrer: req.headers.get('referer') || req.referrer,
|
|
154
|
-
utm:
|
|
155
|
-
campaign: req.nextUrl.searchParams.get('utm_campaign'),
|
|
156
|
-
content: req.nextUrl.searchParams.get('utm_content'),
|
|
157
|
-
medium: req.nextUrl.searchParams.get('utm_medium'),
|
|
158
|
-
source: req.nextUrl.searchParams.get('utm_source'),
|
|
159
|
-
},
|
|
170
|
+
utm: utm,
|
|
160
171
|
};
|
|
161
172
|
}
|
|
162
173
|
excludeRoute(pathname) {
|
|
@@ -135,7 +135,8 @@ export class RedirectsMiddleware extends MiddlewareBase {
|
|
|
135
135
|
redirect.pattern = `/^\/${redirect.pattern
|
|
136
136
|
.replace(/^\/|\/$/g, '')
|
|
137
137
|
.replace(/^\^\/|\/\$$/g, '')
|
|
138
|
-
.replace(/^\^|\$$/g, '')
|
|
138
|
+
.replace(/^\^|\$$/g, '')
|
|
139
|
+
.replace(/\$\/gi$/g, '')}$/gi`;
|
|
139
140
|
return ((regexParser(redirect.pattern).test(tragetURL) ||
|
|
140
141
|
regexParser(redirect.pattern).test(`${tragetURL}${targetQS}`) ||
|
|
141
142
|
regexParser(redirect.pattern).test(`/${req.nextUrl.locale}${tragetURL}`) ||
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sitecore-jss/sitecore-jss-nextjs",
|
|
3
|
-
"version": "21.5.0
|
|
3
|
+
"version": "21.5.0",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"url": "https://github.com/sitecore/jss/issues"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
+
"@sitecore/engage": "^1.4.1",
|
|
33
34
|
"@types/chai": "^4.3.4",
|
|
34
35
|
"@types/chai-as-promised": "^7.1.5",
|
|
35
36
|
"@types/chai-string": "^1.4.2",
|
|
@@ -65,14 +66,15 @@
|
|
|
65
66
|
"typescript": "~4.9.4"
|
|
66
67
|
},
|
|
67
68
|
"peerDependencies": {
|
|
69
|
+
"@sitecore/engage": "^1.4.1",
|
|
68
70
|
"next": "^13.4.16",
|
|
69
71
|
"react": "^18.2.0",
|
|
70
72
|
"react-dom": "^18.2.0"
|
|
71
73
|
},
|
|
72
74
|
"dependencies": {
|
|
73
|
-
"@sitecore-jss/sitecore-jss": "
|
|
74
|
-
"@sitecore-jss/sitecore-jss-dev-tools": "
|
|
75
|
-
"@sitecore-jss/sitecore-jss-react": "
|
|
75
|
+
"@sitecore-jss/sitecore-jss": "21.5.0",
|
|
76
|
+
"@sitecore-jss/sitecore-jss-dev-tools": "21.5.0",
|
|
77
|
+
"@sitecore-jss/sitecore-jss-react": "21.5.0",
|
|
76
78
|
"@vercel/kv": "^0.2.1",
|
|
77
79
|
"node-html-parser": "^6.1.4",
|
|
78
80
|
"prop-types": "^15.8.1",
|
|
@@ -81,7 +83,7 @@
|
|
|
81
83
|
},
|
|
82
84
|
"description": "",
|
|
83
85
|
"types": "types/index.d.ts",
|
|
84
|
-
"gitHead": "
|
|
86
|
+
"gitHead": "cefc81cad1a627e705406a2fb6a663571bd41e56",
|
|
85
87
|
"files": [
|
|
86
88
|
"dist",
|
|
87
89
|
"types",
|
|
@@ -1,7 +1,30 @@
|
|
|
1
1
|
import { NextResponse, NextRequest } from 'next/server';
|
|
2
|
-
import { GraphQLPersonalizeServiceConfig
|
|
3
|
-
import { MiddlewareBase, MiddlewareBaseConfig } from './middleware';
|
|
2
|
+
import { GraphQLPersonalizeServiceConfig } from '@sitecore-jss/sitecore-jss/personalize';
|
|
4
3
|
import { SiteInfo } from '@sitecore-jss/sitecore-jss/site';
|
|
4
|
+
import { MiddlewareBase, MiddlewareBaseConfig } from './middleware';
|
|
5
|
+
import { EngageServer } from '@sitecore/engage';
|
|
6
|
+
export type CdpServiceConfig = {
|
|
7
|
+
/**
|
|
8
|
+
* Your Sitecore CDP API endpoint
|
|
9
|
+
*/
|
|
10
|
+
endpoint: string;
|
|
11
|
+
/**
|
|
12
|
+
* The client key to use for authentication
|
|
13
|
+
*/
|
|
14
|
+
clientKey: string;
|
|
15
|
+
/**
|
|
16
|
+
* The Sitecore CDP channel to use for events. Uses 'WEB' by default.
|
|
17
|
+
*/
|
|
18
|
+
channel?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Currency for CDP request. Uses 'USA' as default.
|
|
21
|
+
*/
|
|
22
|
+
currency?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Timeout (ms) for CDP request. Default is 400.
|
|
25
|
+
*/
|
|
26
|
+
timeout?: number;
|
|
27
|
+
};
|
|
5
28
|
export type PersonalizeMiddlewareConfig = MiddlewareBaseConfig & {
|
|
6
29
|
/**
|
|
7
30
|
* Configuration for your Sitecore Experience Edge endpoint
|
|
@@ -10,7 +33,7 @@ export type PersonalizeMiddlewareConfig = MiddlewareBaseConfig & {
|
|
|
10
33
|
/**
|
|
11
34
|
* Configuration for your Sitecore CDP endpoint
|
|
12
35
|
*/
|
|
13
|
-
cdpConfig:
|
|
36
|
+
cdpConfig: CdpServiceConfig;
|
|
14
37
|
/**
|
|
15
38
|
* function to resolve point of sale for a site
|
|
16
39
|
* @param {Siteinfo} site to get info from
|
|
@@ -19,13 +42,25 @@ export type PersonalizeMiddlewareConfig = MiddlewareBaseConfig & {
|
|
|
19
42
|
*/
|
|
20
43
|
getPointOfSale?: (site: SiteInfo, language: string) => string;
|
|
21
44
|
};
|
|
45
|
+
/**
|
|
46
|
+
* Object model of Experience Context data
|
|
47
|
+
*/
|
|
48
|
+
export type ExperienceParams = {
|
|
49
|
+
referrer: string;
|
|
50
|
+
utm: {
|
|
51
|
+
[key: string]: string | undefined;
|
|
52
|
+
campaign: string | undefined;
|
|
53
|
+
source: string | undefined;
|
|
54
|
+
medium: string | undefined;
|
|
55
|
+
content: string | undefined;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
22
58
|
/**
|
|
23
59
|
* Middleware / handler to support Sitecore Personalize
|
|
24
60
|
*/
|
|
25
61
|
export declare class PersonalizeMiddleware extends MiddlewareBase {
|
|
26
62
|
protected config: PersonalizeMiddlewareConfig;
|
|
27
63
|
private personalizeService;
|
|
28
|
-
private cdpService;
|
|
29
64
|
/**
|
|
30
65
|
* @param {PersonalizeMiddlewareConfig} [config] Personalize middleware config
|
|
31
66
|
*/
|
|
@@ -35,9 +70,7 @@ export declare class PersonalizeMiddleware extends MiddlewareBase {
|
|
|
35
70
|
* @returns middleware handler
|
|
36
71
|
*/
|
|
37
72
|
getHandler(): (req: NextRequest, res?: NextResponse) => Promise<NextResponse>;
|
|
38
|
-
protected
|
|
39
|
-
protected getBrowserId(req: NextRequest): string | undefined;
|
|
40
|
-
protected setBrowserId(res: NextResponse, browserId: string): void;
|
|
73
|
+
protected initializeEngageServer(hostName: string, site: SiteInfo, language: string): EngageServer;
|
|
41
74
|
protected getExperienceParams(req: NextRequest): ExperienceParams;
|
|
42
75
|
protected excludeRoute(pathname: string): boolean | undefined;
|
|
43
76
|
private handler;
|