@sitecore-content-sdk/personalize 2.0.0-canary.12
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.MD +202 -0
- package/README.md +114 -0
- package/dist/cjs/package.json +75 -0
- package/dist/cjs/src/consts.js +14 -0
- package/dist/cjs/src/debug.js +12 -0
- package/dist/cjs/src/index.js +13 -0
- package/dist/cjs/src/initialization/browser-adapter.js +48 -0
- package/dist/cjs/src/initialization/const.js +8 -0
- package/dist/cjs/src/initialization/get-profile-id.js +17 -0
- package/dist/cjs/src/initialization/plugin-browser.js +82 -0
- package/dist/cjs/src/initialization/plugin-server.js +43 -0
- package/dist/cjs/src/initialization/server-adapter.js +89 -0
- package/dist/cjs/src/initialization/shared.js +17 -0
- package/dist/cjs/src/initialization/types.js +2 -0
- package/dist/cjs/src/internal.js +11 -0
- package/dist/cjs/src/personalization/personalize.js +29 -0
- package/dist/cjs/src/personalization/personalizer.js +120 -0
- package/dist/cjs/src/personalization/send-call-flows-request.js +47 -0
- package/dist/cjs/src/profile-id/fetch-profile-id-from-edge-proxy.js +35 -0
- package/dist/cjs/src/web-personalization/get-cdn-url.js +27 -0
- package/dist/esm/package.json +75 -0
- package/dist/esm/src/consts.js +8 -0
- package/dist/esm/src/debug.js +9 -0
- package/dist/esm/src/index.js +5 -0
- package/dist/esm/src/initialization/browser-adapter.js +45 -0
- package/dist/esm/src/initialization/const.js +5 -0
- package/dist/esm/src/initialization/get-profile-id.js +14 -0
- package/dist/esm/src/initialization/plugin-browser.js +79 -0
- package/dist/esm/src/initialization/plugin-server.js +40 -0
- package/dist/esm/src/initialization/server-adapter.js +86 -0
- package/dist/esm/src/initialization/shared.js +14 -0
- package/dist/esm/src/initialization/types.js +1 -0
- package/dist/esm/src/internal.js +4 -0
- package/dist/esm/src/personalization/personalize.js +26 -0
- package/dist/esm/src/personalization/personalizer.js +116 -0
- package/dist/esm/src/personalization/send-call-flows-request.js +44 -0
- package/dist/esm/src/profile-id/fetch-profile-id-from-edge-proxy.js +32 -0
- package/dist/esm/src/web-personalization/get-cdn-url.js +24 -0
- package/internal.d.ts +1 -0
- package/package.json +75 -0
- package/types/src/consts.d.ts +8 -0
- package/types/src/consts.d.ts.map +1 -0
- package/types/src/debug.d.ts +9 -0
- package/types/src/debug.d.ts.map +1 -0
- package/types/src/index.d.ts +15 -0
- package/types/src/index.d.ts.map +1 -0
- package/types/src/initialization/browser-adapter.d.ts +19 -0
- package/types/src/initialization/browser-adapter.d.ts.map +1 -0
- package/types/src/initialization/const.d.ts +6 -0
- package/types/src/initialization/const.d.ts.map +1 -0
- package/types/src/initialization/get-profile-id.d.ts +8 -0
- package/types/src/initialization/get-profile-id.d.ts.map +1 -0
- package/types/src/initialization/plugin-browser.d.ts +37 -0
- package/types/src/initialization/plugin-browser.d.ts.map +1 -0
- package/types/src/initialization/plugin-server.d.ts +23 -0
- package/types/src/initialization/plugin-server.d.ts.map +1 -0
- package/types/src/initialization/server-adapter.d.ts +29 -0
- package/types/src/initialization/server-adapter.d.ts.map +1 -0
- package/types/src/initialization/shared.d.ts +8 -0
- package/types/src/initialization/shared.d.ts.map +1 -0
- package/types/src/initialization/types.d.ts +168 -0
- package/types/src/initialization/types.d.ts.map +1 -0
- package/types/src/internal.d.ts +8 -0
- package/types/src/internal.d.ts.map +1 -0
- package/types/src/personalization/personalize.d.ts +21 -0
- package/types/src/personalization/personalize.d.ts.map +1 -0
- package/types/src/personalization/personalizer.d.ts +177 -0
- package/types/src/personalization/personalizer.d.ts.map +1 -0
- package/types/src/personalization/send-call-flows-request.d.ts +78 -0
- package/types/src/personalization/send-call-flows-request.d.ts.map +1 -0
- package/types/src/profile-id/fetch-profile-id-from-edge-proxy.d.ts +39 -0
- package/types/src/profile-id/fetch-profile-id-from-edge-proxy.d.ts.map +1 -0
- package/types/src/web-personalization/get-cdn-url.d.ts +9 -0
- package/types/src/web-personalization/get-cdn-url.d.ts.map +1 -0
package/LICENSE.MD
ADDED
|
@@ -0,0 +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 2025 Sitecore
|
|
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
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# personalize
|
|
2
|
+
|
|
3
|
+
This package provides browser- and server-side functions to run personalizations in your app. Personalization is for showing the most relevant content to your users.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @sitecore-content-sdk/personalize
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
1. Initialize the package using the `initContentSdk` function, available in the `core` package.
|
|
14
|
+
2. To run web personalization (browser-side only):
|
|
15
|
+
1. Initialize the `events` package.
|
|
16
|
+
2. Enable web personalization during initialization.
|
|
17
|
+
3. To run interactive personalization, use the `personalize` function.
|
|
18
|
+
|
|
19
|
+
## Code examples
|
|
20
|
+
|
|
21
|
+
Run personalizations from the browser side:
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
'use client';
|
|
25
|
+
|
|
26
|
+
import { useEffect } from 'react';
|
|
27
|
+
import { initContentSdk } from '@sitecore-content-sdk/core';
|
|
28
|
+
import { analyticsPlugin, analyticsBrowserAdapter } from '@sitecore-content-sdk/analytics-core';
|
|
29
|
+
import { eventsPlugin } from '@sitecore-content-sdk/events';
|
|
30
|
+
import { personalizeBrowserPlugin, personalizeBrowserAdapter, personalize } from '@sitecore-content-sdk/personalize';
|
|
31
|
+
|
|
32
|
+
export default function Home() {
|
|
33
|
+
const getPersonalizeData = async () => {
|
|
34
|
+
// Run interactive personalization:
|
|
35
|
+
const data = await personalize({
|
|
36
|
+
channel: 'WEB',
|
|
37
|
+
currency: 'EUR',
|
|
38
|
+
friendlyId: '<YOUR_EXPERIENCE_FRIENDLY_ID>'
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
console.log(data);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
initContentSdk({
|
|
46
|
+
config: {
|
|
47
|
+
contextId: '<YOUR_CONTEXT_ID>',
|
|
48
|
+
siteName: '<YOUR_SITE_NAME>',
|
|
49
|
+
},
|
|
50
|
+
plugins: [
|
|
51
|
+
analyticsPlugin({
|
|
52
|
+
options: { enableCookie: true },
|
|
53
|
+
adapter: analyticsBrowserAdapter(),
|
|
54
|
+
}),
|
|
55
|
+
eventsPlugin(),
|
|
56
|
+
personalizeBrowserPlugin({
|
|
57
|
+
options: { enablePersonalizeCookie: true, webPersonalization: true },
|
|
58
|
+
adapter: personalizeBrowserAdapter(),
|
|
59
|
+
}),
|
|
60
|
+
],
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
getPersonalizeData();
|
|
64
|
+
}, []);
|
|
65
|
+
|
|
66
|
+
return <></>;
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Run personalizations from the server side:
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
import type { NextRequest, NextResponse } from 'next/server';
|
|
74
|
+
import { initContentSdk } from '@sitecore-content-sdk/core';
|
|
75
|
+
import { analyticsPlugin } from '@sitecore-content-sdk/analytics-core';
|
|
76
|
+
import { personalizeServerPlugin, personalize } from '@sitecore-content-sdk/personalize';
|
|
77
|
+
import { analyticsProxyAdapter, personalizeProxyAdapter } from '@sitecore-content-sdk/nextjs';
|
|
78
|
+
|
|
79
|
+
export async function middleware(request: NextRequest) {
|
|
80
|
+
const response = NextResponse.next();
|
|
81
|
+
|
|
82
|
+
await initContentSdk({
|
|
83
|
+
config: {
|
|
84
|
+
contextId: '<YOUR_CONTEXT_ID>',
|
|
85
|
+
siteName: '<YOUR_SITE_NAME>',
|
|
86
|
+
},
|
|
87
|
+
plugins: [
|
|
88
|
+
analyticsPlugin({
|
|
89
|
+
options: { enableCookie: true },
|
|
90
|
+
adapter: analyticsProxyAdapter(request, response),
|
|
91
|
+
}),
|
|
92
|
+
personalizeServerPlugin({
|
|
93
|
+
options: { enablePersonalizeCookie: true },
|
|
94
|
+
adapter: personalizeProxyAdapter(request, response),
|
|
95
|
+
}),
|
|
96
|
+
],
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// Run interactive personalization:
|
|
100
|
+
const data = await personalize({
|
|
101
|
+
channel: 'WEB',
|
|
102
|
+
currency: 'EUR',
|
|
103
|
+
friendlyId: '<YOUR_EXPERIENCE_FRIENDLY_ID>'
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
console.log(data);
|
|
107
|
+
|
|
108
|
+
return response;
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Documentation
|
|
113
|
+
|
|
114
|
+
[Official Sitecore Content SDK documentation](https://doc.sitecore.com/sai/en/developers/content-sdk/sitecore-content-sdk-for-sitecoreai.html)
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
{
|
|
2
|
+
"author": {
|
|
3
|
+
"name": "Sitecore Corporation",
|
|
4
|
+
"url": "https://doc.sitecore.com/xmc/en/developers/content-sdk/index.html"
|
|
5
|
+
},
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/sitecore/content-sdk/issues"
|
|
8
|
+
},
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"@sitecore-content-sdk/analytics-core": "2.0.0-canary.12",
|
|
11
|
+
"@sitecore-content-sdk/core": "2.0.0-canary.12",
|
|
12
|
+
"@sitecore-content-sdk/events": "2.0.0-canary.12",
|
|
13
|
+
"debug": "^4.4.3"
|
|
14
|
+
},
|
|
15
|
+
"description": "Provides personalization capabilities to build tailored experiences for site visitors.",
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@jest/types": "^29.6.3",
|
|
18
|
+
"@stylistic/eslint-plugin": "^5.2.2",
|
|
19
|
+
"@types/debug": "^4.1.12",
|
|
20
|
+
"@types/jest": "^29.5.12",
|
|
21
|
+
"@typescript-eslint/eslint-plugin": "8.39.0",
|
|
22
|
+
"@typescript-eslint/parser": "8.39.0",
|
|
23
|
+
"del-cli": "^6.0.0",
|
|
24
|
+
"eslint": "^9.32.0",
|
|
25
|
+
"eslint-config-prettier": "^10.1.8",
|
|
26
|
+
"eslint-plugin-import": "2.32.0",
|
|
27
|
+
"eslint-plugin-jsdoc": "52.0.3",
|
|
28
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
29
|
+
"jest": "^29.7.0",
|
|
30
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
31
|
+
"jest-environment-node": "^29.7.0",
|
|
32
|
+
"ts-jest": "^29.1.0",
|
|
33
|
+
"ts-node": "^10.9.2"
|
|
34
|
+
},
|
|
35
|
+
"main": "dist/cjs/src/index.js",
|
|
36
|
+
"module": "dist/esm/src/index.js",
|
|
37
|
+
"types": "types/src/index.d.ts",
|
|
38
|
+
"exports": {
|
|
39
|
+
".": {
|
|
40
|
+
"import": "./dist/esm/src/index.js",
|
|
41
|
+
"require": "./dist/cjs/src/index.js",
|
|
42
|
+
"types": "./types/src/index.d.ts"
|
|
43
|
+
},
|
|
44
|
+
"./internal": {
|
|
45
|
+
"import": "./dist/esm/src/internal.js",
|
|
46
|
+
"require": "./dist/cjs/src/internal.js",
|
|
47
|
+
"types": "./types/src/internal.d.ts"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"files": [
|
|
51
|
+
"dist",
|
|
52
|
+
"types",
|
|
53
|
+
"/*.d.ts"
|
|
54
|
+
],
|
|
55
|
+
"homepage": "https://doc.sitecore.com/xmc/en/developers/content-sdk/index.html",
|
|
56
|
+
"license": "Apache-2.0",
|
|
57
|
+
"name": "@sitecore-content-sdk/personalize",
|
|
58
|
+
"publishConfig": {
|
|
59
|
+
"access": "public",
|
|
60
|
+
"registry": "https://registry.npmjs.org/"
|
|
61
|
+
},
|
|
62
|
+
"scripts": {
|
|
63
|
+
"build": "npm run clean && tsc -p tsconfig.json && tsc -p tsconfig-esm.json",
|
|
64
|
+
"clean": "del-cli dist types",
|
|
65
|
+
"coverage": "jest --config jest.config.ts --coverage",
|
|
66
|
+
"generate-docs": "npx typedoc --plugin typedoc-plugin-markdown --outputFileStrategy Members --parametersFormat table --readme none --out ../../ref-docs/personalize --entryPoints src/internal.ts --entryPoints src/index.ts --githubPages false",
|
|
67
|
+
"lint": "eslint \"./src/**/*.ts\"",
|
|
68
|
+
"prepublishOnly": "npm run build",
|
|
69
|
+
"test": "jest --config jest.config.ts",
|
|
70
|
+
"api-extractor": "npm run build && api-extractor run --local --verbose",
|
|
71
|
+
"api-extractor:verify": "api-extractor run"
|
|
72
|
+
},
|
|
73
|
+
"version": "2.0.0-canary.12",
|
|
74
|
+
"gitHead": "4a26005860f4931f25d8c63d765a030e04a5b1f4"
|
|
75
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.UTM_PREFIX = exports.PACKAGE_NAME = exports.PACKAGE_VERSION = void 0;
|
|
7
|
+
const package_json_1 = __importDefault(require("../package.json"));
|
|
8
|
+
/**
|
|
9
|
+
* The package version.
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
exports.PACKAGE_VERSION = package_json_1.default.version;
|
|
13
|
+
exports.PACKAGE_NAME = package_json_1.default.name;
|
|
14
|
+
exports.UTM_PREFIX = 'utm_';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.debug = exports.PERSONALIZE_NAMESPACE = void 0;
|
|
4
|
+
const core_1 = require("@sitecore-content-sdk/core");
|
|
5
|
+
exports.PERSONALIZE_NAMESPACE = 'personalize';
|
|
6
|
+
/**
|
|
7
|
+
* Debug module for personalize package
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
exports.debug = {
|
|
11
|
+
personalize: (0, core_1.debugModule)(`${core_1.debugNamespace}:${exports.PERSONALIZE_NAMESPACE}`),
|
|
12
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.personalizeBrowserAdapter = exports.personalizeBrowserPlugin = exports.personalizeServerAdapter = exports.personalizeServerPlugin = exports.personalize = void 0;
|
|
4
|
+
var personalize_1 = require("./personalization/personalize");
|
|
5
|
+
Object.defineProperty(exports, "personalize", { enumerable: true, get: function () { return personalize_1.personalize; } });
|
|
6
|
+
var plugin_server_1 = require("./initialization/plugin-server");
|
|
7
|
+
Object.defineProperty(exports, "personalizeServerPlugin", { enumerable: true, get: function () { return plugin_server_1.personalizeServerPlugin; } });
|
|
8
|
+
var server_adapter_1 = require("./initialization/server-adapter");
|
|
9
|
+
Object.defineProperty(exports, "personalizeServerAdapter", { enumerable: true, get: function () { return server_adapter_1.personalizeServerAdapter; } });
|
|
10
|
+
var plugin_browser_1 = require("./initialization/plugin-browser");
|
|
11
|
+
Object.defineProperty(exports, "personalizeBrowserPlugin", { enumerable: true, get: function () { return plugin_browser_1.personalizeBrowserPlugin; } });
|
|
12
|
+
var browser_adapter_1 = require("./initialization/browser-adapter");
|
|
13
|
+
Object.defineProperty(exports, "personalizeBrowserAdapter", { enumerable: true, get: function () { return browser_adapter_1.personalizeBrowserAdapter; } });
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.personalizeBrowserAdapter = personalizeBrowserAdapter;
|
|
4
|
+
const utils_1 = require("@sitecore-content-sdk/analytics-core/utils");
|
|
5
|
+
const core_1 = require("@sitecore-content-sdk/core");
|
|
6
|
+
const shared_1 = require("./shared");
|
|
7
|
+
const internal_1 = require("@sitecore-content-sdk/analytics-core/internal");
|
|
8
|
+
const internal_2 = require("@sitecore-content-sdk/analytics-core/internal");
|
|
9
|
+
const fetch_profile_id_from_edge_proxy_1 = require("../profile-id/fetch-profile-id-from-edge-proxy");
|
|
10
|
+
/**
|
|
11
|
+
* Creates a browser-based personalize adapter that reads and writes the profile ID
|
|
12
|
+
* using cookies and can resolve a new profile ID from the Edge proxy when needed.
|
|
13
|
+
* @returns {PersonalizeBrowserAdapter} An PersonalizeBrowserAdapter instance.
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
function personalizeBrowserAdapter() {
|
|
17
|
+
return {
|
|
18
|
+
type: 'browser',
|
|
19
|
+
getProfileId: () => {
|
|
20
|
+
return (0, utils_1.getCookieValueClientSide)((0, shared_1.getPersonalizePlugin)().options.cookies.name);
|
|
21
|
+
},
|
|
22
|
+
setProfileId: async () => {
|
|
23
|
+
const coreConfig = (0, core_1.getCoreContext)().config;
|
|
24
|
+
const analyticsOptions = (0, internal_2.getAnalyticsPlugin)().options;
|
|
25
|
+
const personalizePlugin = (0, shared_1.getPersonalizePlugin)();
|
|
26
|
+
const profileIdCookieName = personalizePlugin.options.cookies.name;
|
|
27
|
+
const legacyProfileIdCookieName = `${internal_1.COOKIE_NAME_PREFIX}${coreConfig.contextId}_personalize`;
|
|
28
|
+
const cookieAttributes = (0, internal_1.getDefaultCookieAttributes)(analyticsOptions.cookies.expiryDays, analyticsOptions.cookies.domain);
|
|
29
|
+
const legacyProfileIdCookie = (0, utils_1.getCookieValueClientSide)(legacyProfileIdCookieName);
|
|
30
|
+
if (legacyProfileIdCookie) {
|
|
31
|
+
document.cookie = (0, utils_1.createCookieString)(profileIdCookieName, legacyProfileIdCookie, cookieAttributes);
|
|
32
|
+
document.cookie = (0, utils_1.createCookieString)(legacyProfileIdCookieName, '', Object.assign(Object.assign({}, cookieAttributes), { maxAge: 0 }));
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const cookiesValuesFromEdgeBrowser = (0, internal_2.getAnalyticsPlugin)().options.visitorIds;
|
|
36
|
+
const profileIdCookieValue = (0, utils_1.getCookieValueClientSide)(profileIdCookieName);
|
|
37
|
+
const clientIdCookieValue = (0, utils_1.getCookieValueClientSide)(analyticsOptions.cookies.name);
|
|
38
|
+
if (profileIdCookieValue)
|
|
39
|
+
return;
|
|
40
|
+
else if (cookiesValuesFromEdgeBrowser === null || cookiesValuesFromEdgeBrowser === void 0 ? void 0 : cookiesValuesFromEdgeBrowser.profileId)
|
|
41
|
+
document.cookie = (0, utils_1.createCookieString)(profileIdCookieName, cookiesValuesFromEdgeBrowser.profileId, cookieAttributes);
|
|
42
|
+
else if (clientIdCookieValue) {
|
|
43
|
+
const profileIdCookieValue = await (0, fetch_profile_id_from_edge_proxy_1.fetchProfileIdFromEdgeProxy)(clientIdCookieValue, coreConfig.contextId, coreConfig.edgeUrl);
|
|
44
|
+
document.cookie = (0, utils_1.createCookieString)(profileIdCookieName, profileIdCookieValue, cookieAttributes);
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getProfileId = getProfileId;
|
|
4
|
+
const internal_1 = require("@sitecore-content-sdk/analytics-core/internal");
|
|
5
|
+
const fetch_profile_id_from_edge_proxy_1 = require("../profile-id/fetch-profile-id-from-edge-proxy");
|
|
6
|
+
const core_1 = require("@sitecore-content-sdk/core");
|
|
7
|
+
/**
|
|
8
|
+
* Returns the profile ID.
|
|
9
|
+
* @returns {Promise<string>} A promise that resolves with the profile ID.
|
|
10
|
+
* @throws If the Sitecore Edge context ID is incorrect.
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
async function getProfileId() {
|
|
14
|
+
const { config } = (0, core_1.getCoreContext)();
|
|
15
|
+
const clientId = (0, internal_1.getAnalyticsPlugin)().adapter.getClientId() || '';
|
|
16
|
+
return (0, fetch_profile_id_from_edge_proxy_1.fetchProfileIdFromEdgeProxy)(clientId, config.contextId, config.edgeUrl);
|
|
17
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.personalizeBrowserPlugin = personalizeBrowserPlugin;
|
|
4
|
+
const const_1 = require("./const");
|
|
5
|
+
const consts_1 = require("../consts");
|
|
6
|
+
const internal_1 = require("@sitecore-content-sdk/analytics-core/internal");
|
|
7
|
+
const internal_2 = require("@sitecore-content-sdk/events/internal");
|
|
8
|
+
const core_1 = require("@sitecore-content-sdk/core");
|
|
9
|
+
const get_cdn_url_1 = require("../web-personalization/get-cdn-url");
|
|
10
|
+
const utils_1 = require("@sitecore-content-sdk/analytics-core/utils");
|
|
11
|
+
const shared_1 = require("./shared");
|
|
12
|
+
const internal_3 = require("@sitecore-content-sdk/analytics-core/internal");
|
|
13
|
+
const get_profile_id_1 = require("./get-profile-id");
|
|
14
|
+
const personalize_1 = require("../personalization/personalize");
|
|
15
|
+
/**
|
|
16
|
+
* Initializes the personalize plugin with the provided options.
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
async function init() {
|
|
20
|
+
var _a;
|
|
21
|
+
const coreConfig = (0, core_1.getCoreContext)().config;
|
|
22
|
+
const personalizePlugin = (0, shared_1.getPersonalizePlugin)();
|
|
23
|
+
const personalizeOptions = personalizePlugin.options;
|
|
24
|
+
const analyticsPlugin = (0, internal_3.getAnalyticsPlugin)();
|
|
25
|
+
if (analyticsPlugin.options.cookies.enabled &&
|
|
26
|
+
personalizeOptions.cookies.enabled &&
|
|
27
|
+
(!personalizePlugin.adapter.getProfileId() || personalizePlugin.adapter.type !== 'browser'))
|
|
28
|
+
await personalizePlugin.adapter.setProfileId();
|
|
29
|
+
if (typeof window === 'undefined')
|
|
30
|
+
return;
|
|
31
|
+
window.scContentSDK = Object.assign(Object.assign({}, window.scContentSDK), { personalize: {
|
|
32
|
+
personalize: personalize_1.personalize,
|
|
33
|
+
version: consts_1.PACKAGE_VERSION,
|
|
34
|
+
options: personalizeOptions.webPersonalization ? personalizeOptions.webPersonalization : {},
|
|
35
|
+
}, analytics_core: Object.assign(Object.assign({}, (_a = window.scContentSDK) === null || _a === void 0 ? void 0 : _a.analytics_core), { getProfileId: get_profile_id_1.getProfileId }) });
|
|
36
|
+
if (!personalizeOptions.webPersonalization)
|
|
37
|
+
return;
|
|
38
|
+
window.scContentSDK.personalize.options = personalizeOptions.webPersonalization;
|
|
39
|
+
const cdnUrl = await (0, get_cdn_url_1.getCdnUrl)(coreConfig.contextId, coreConfig.edgeUrl);
|
|
40
|
+
if (!cdnUrl)
|
|
41
|
+
return;
|
|
42
|
+
(0, utils_1.appendScriptWithAttributes)({
|
|
43
|
+
async: personalizeOptions.webPersonalization.async,
|
|
44
|
+
src: cdnUrl,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Creates a personalize browser plugin with the provided adapter and options.
|
|
49
|
+
* @param {PersonalizeBrowserPluginParams} params - The personalize plugin parameters including adapter and options.
|
|
50
|
+
* @returns {PersonalizeBrowserPlugin} The configured personalize browser plugin.
|
|
51
|
+
* @public
|
|
52
|
+
*/
|
|
53
|
+
function personalizeBrowserPlugin(params) {
|
|
54
|
+
var _a, _b, _c, _d;
|
|
55
|
+
const { adapter, options } = params;
|
|
56
|
+
const cookies = {
|
|
57
|
+
enabled: (_a = options === null || options === void 0 ? void 0 : options.enablePersonalizeCookie) !== null && _a !== void 0 ? _a : false,
|
|
58
|
+
name: `${internal_1.COOKIE_NAME_PREFIX}${internal_1.CLIENT_ID_COOKIE_NAME}_personalize`,
|
|
59
|
+
};
|
|
60
|
+
const dependencies = [internal_3.ANALYTICS_PLUGIN_NAME];
|
|
61
|
+
let webPersonalization;
|
|
62
|
+
if (options === null || options === void 0 ? void 0 : options.webPersonalization) {
|
|
63
|
+
dependencies.push(internal_2.EVENTS_PLUGIN_NAME);
|
|
64
|
+
webPersonalization = {
|
|
65
|
+
async: (_b = options.webPersonalization.async) !== null && _b !== void 0 ? _b : true,
|
|
66
|
+
defer: (_c = options.webPersonalization.defer) !== null && _c !== void 0 ? _c : false,
|
|
67
|
+
language: (_d = options.webPersonalization.language) !== null && _d !== void 0 ? _d : undefined,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
webPersonalization !== null && webPersonalization !== void 0 ? webPersonalization : (webPersonalization = false);
|
|
71
|
+
const resolvedOptions = {
|
|
72
|
+
webPersonalization,
|
|
73
|
+
cookies,
|
|
74
|
+
};
|
|
75
|
+
return {
|
|
76
|
+
name: const_1.PERSONALIZE_PLUGIN_NAME,
|
|
77
|
+
init,
|
|
78
|
+
dependencies,
|
|
79
|
+
options: resolvedOptions,
|
|
80
|
+
adapter,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.personalizeServerPlugin = personalizeServerPlugin;
|
|
4
|
+
const const_1 = require("./const");
|
|
5
|
+
const internal_1 = require("@sitecore-content-sdk/analytics-core/internal");
|
|
6
|
+
const shared_1 = require("./shared");
|
|
7
|
+
const internal_2 = require("@sitecore-content-sdk/analytics-core/internal");
|
|
8
|
+
/**
|
|
9
|
+
* Initializes the personalize plugin with the provided options.
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
async function init() {
|
|
13
|
+
const personalizePlugin = (0, shared_1.getPersonalizePlugin)();
|
|
14
|
+
const personalizeOptions = personalizePlugin.options;
|
|
15
|
+
const analyticsPlugin = (0, internal_2.getAnalyticsPlugin)();
|
|
16
|
+
if (analyticsPlugin.options.cookies.enabled && personalizeOptions.cookies.enabled)
|
|
17
|
+
await personalizePlugin.adapter.setProfileId();
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Creates a personalize server plugin with the provided options.
|
|
21
|
+
* @param {PersonalizeServerPluginParams} params - The parameters for the personalize plugin.
|
|
22
|
+
* @returns {PersonalizeServerPlugin} The personalize plugin instance.
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
function personalizeServerPlugin(params) {
|
|
26
|
+
var _a;
|
|
27
|
+
const { adapter, options } = params;
|
|
28
|
+
const cookies = {
|
|
29
|
+
enabled: (_a = options === null || options === void 0 ? void 0 : options.enablePersonalizeCookie) !== null && _a !== void 0 ? _a : false,
|
|
30
|
+
name: `${internal_1.COOKIE_NAME_PREFIX}${internal_1.CLIENT_ID_COOKIE_NAME}_personalize`,
|
|
31
|
+
};
|
|
32
|
+
const dependencies = [internal_2.ANALYTICS_PLUGIN_NAME];
|
|
33
|
+
const resolvedOptions = {
|
|
34
|
+
cookies,
|
|
35
|
+
};
|
|
36
|
+
return {
|
|
37
|
+
name: const_1.PERSONALIZE_PLUGIN_NAME,
|
|
38
|
+
init,
|
|
39
|
+
dependencies,
|
|
40
|
+
options: resolvedOptions,
|
|
41
|
+
adapter,
|
|
42
|
+
};
|
|
43
|
+
}
|