@ninetailed/experience.js-next-esr 2.2.8 → 3.0.1-beta.3
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/index.esm.js +14 -55
- package/index.umd.js +16 -68
- package/lib/fetchEdgeProfile.d.ts +2 -5
- package/lib/selector.d.ts +33 -2
- package/package.json +7 -9
package/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { v4 } from 'uuid';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { NinetailedApiClient, buildPageEvent } from '@ninetailed/experience.js-shared';
|
|
3
|
+
import { NINETAILED_ANONYMOUS_ID_COOKIE } from '@ninetailed/experience.js-plugin-ssr';
|
|
4
4
|
|
|
5
5
|
function absoluteUrl(req, localhostAddress = 'localhost:3000') {
|
|
6
6
|
const hostHeader = req.headers.get('host');
|
|
@@ -67,22 +67,6 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
const BASE_URL = 'https://api.ninetailed.co';
|
|
71
|
-
|
|
72
|
-
const getProfileCache = cookies => {
|
|
73
|
-
const cacheString = cookies[NINETAILED_PROFILE_CACHE_COOKIE];
|
|
74
|
-
|
|
75
|
-
if (cacheString) {
|
|
76
|
-
try {
|
|
77
|
-
return JSON.parse(decodeURIComponent(cacheString));
|
|
78
|
-
} catch (error) {
|
|
79
|
-
console.error(error);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return buildEmptyCache();
|
|
84
|
-
};
|
|
85
|
-
|
|
86
70
|
const fetchEdgeProfile = ({
|
|
87
71
|
ctx,
|
|
88
72
|
cookies,
|
|
@@ -92,49 +76,24 @@ const fetchEdgeProfile = ({
|
|
|
92
76
|
ip,
|
|
93
77
|
location
|
|
94
78
|
}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
95
|
-
const
|
|
96
|
-
const
|
|
79
|
+
const anonymousId = cookies[NINETAILED_ANONYMOUS_ID_COOKIE];
|
|
80
|
+
const apiClient = new NinetailedApiClient({
|
|
81
|
+
clientId,
|
|
82
|
+
environment,
|
|
83
|
+
url
|
|
84
|
+
});
|
|
97
85
|
const pageEvent = buildPageEvent({
|
|
98
86
|
ctx,
|
|
99
|
-
anonymousId,
|
|
100
87
|
messageId: v4(),
|
|
101
88
|
timestamp: Date.now(),
|
|
102
|
-
properties: {}
|
|
89
|
+
properties: {},
|
|
90
|
+
location
|
|
103
91
|
});
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
'Content-Type': 'application/json'
|
|
108
|
-
},
|
|
109
|
-
body: JSON.stringify(Object.assign(Object.assign(Object.assign({
|
|
110
|
-
events: [pageEvent]
|
|
111
|
-
}, cacheFromCookie), {
|
|
112
|
-
ip
|
|
113
|
-
}), {
|
|
114
|
-
location
|
|
115
|
-
}))
|
|
92
|
+
const profile = yield apiClient.upsertProfile([pageEvent], anonymousId, {
|
|
93
|
+
ip,
|
|
94
|
+
preflight: true
|
|
116
95
|
});
|
|
117
|
-
|
|
118
|
-
data: {
|
|
119
|
-
profile,
|
|
120
|
-
traitsUpdatedAt,
|
|
121
|
-
signals
|
|
122
|
-
}
|
|
123
|
-
} = yield request.json();
|
|
124
|
-
return {
|
|
125
|
-
profile,
|
|
126
|
-
cache: {
|
|
127
|
-
id: profile.id,
|
|
128
|
-
random: profile.random,
|
|
129
|
-
audiences: profile.audiences,
|
|
130
|
-
location: profile.location,
|
|
131
|
-
session: profile.session,
|
|
132
|
-
traitsUpdatedAt,
|
|
133
|
-
traits: profile.traits,
|
|
134
|
-
signals,
|
|
135
|
-
sessions: cacheFromCookie.sessions
|
|
136
|
-
}
|
|
137
|
-
};
|
|
96
|
+
return profile;
|
|
138
97
|
});
|
|
139
98
|
|
|
140
99
|
export { buildNinetailedEdgeRequestContext, fetchEdgeProfile };
|
package/index.umd.js
CHANGED
|
@@ -62,17 +62,6 @@
|
|
|
62
62
|
PERFORMANCE OF THIS SOFTWARE.
|
|
63
63
|
***************************************************************************** */
|
|
64
64
|
|
|
65
|
-
var __assign = function() {
|
|
66
|
-
__assign = Object.assign || function __assign(t) {
|
|
67
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
68
|
-
s = arguments[i];
|
|
69
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
70
|
-
}
|
|
71
|
-
return t;
|
|
72
|
-
};
|
|
73
|
-
return __assign.apply(this, arguments);
|
|
74
|
-
};
|
|
75
|
-
|
|
76
65
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
77
66
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
78
67
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -111,22 +100,6 @@
|
|
|
111
100
|
}
|
|
112
101
|
}
|
|
113
102
|
|
|
114
|
-
var BASE_URL = 'https://api.ninetailed.co';
|
|
115
|
-
|
|
116
|
-
var getProfileCache = function (cookies) {
|
|
117
|
-
var cacheString = cookies[experience_jsPluginSsr.NINETAILED_PROFILE_CACHE_COOKIE];
|
|
118
|
-
|
|
119
|
-
if (cacheString) {
|
|
120
|
-
try {
|
|
121
|
-
return JSON.parse(decodeURIComponent(cacheString));
|
|
122
|
-
} catch (error) {
|
|
123
|
-
console.error(error);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return experience_jsShared.buildEmptyCache();
|
|
128
|
-
};
|
|
129
|
-
|
|
130
103
|
var fetchEdgeProfile = function (_a) {
|
|
131
104
|
var ctx = _a.ctx,
|
|
132
105
|
cookies = _a.cookies,
|
|
@@ -136,60 +109,35 @@
|
|
|
136
109
|
ip = _a.ip,
|
|
137
110
|
location = _a.location;
|
|
138
111
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
139
|
-
var
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
switch (_c.label) {
|
|
112
|
+
var anonymousId, apiClient, pageEvent, profile;
|
|
113
|
+
return __generator(this, function (_b) {
|
|
114
|
+
switch (_b.label) {
|
|
143
115
|
case 0:
|
|
144
|
-
|
|
145
|
-
|
|
116
|
+
anonymousId = cookies[experience_jsPluginSsr.NINETAILED_ANONYMOUS_ID_COOKIE];
|
|
117
|
+
apiClient = new experience_jsShared.NinetailedApiClient({
|
|
118
|
+
clientId: clientId,
|
|
119
|
+
environment: environment,
|
|
120
|
+
url: url
|
|
121
|
+
});
|
|
146
122
|
pageEvent = experience_jsShared.buildPageEvent({
|
|
147
123
|
ctx: ctx,
|
|
148
|
-
anonymousId: anonymousId,
|
|
149
124
|
messageId: uuid.v4(),
|
|
150
125
|
timestamp: Date.now(),
|
|
151
|
-
properties: {}
|
|
126
|
+
properties: {},
|
|
127
|
+
location: location
|
|
152
128
|
});
|
|
153
129
|
return [4
|
|
154
130
|
/*yield*/
|
|
155
|
-
,
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
'Content-Type': 'application/json'
|
|
159
|
-
},
|
|
160
|
-
body: JSON.stringify(__assign(__assign(__assign({
|
|
161
|
-
events: [pageEvent]
|
|
162
|
-
}, cacheFromCookie), {
|
|
163
|
-
ip: ip
|
|
164
|
-
}), {
|
|
165
|
-
location: location
|
|
166
|
-
}))
|
|
131
|
+
, apiClient.upsertProfile([pageEvent], anonymousId, {
|
|
132
|
+
ip: ip,
|
|
133
|
+
preflight: true
|
|
167
134
|
})];
|
|
168
135
|
|
|
169
136
|
case 1:
|
|
170
|
-
|
|
171
|
-
return [4
|
|
172
|
-
/*yield*/
|
|
173
|
-
, request.json()];
|
|
174
|
-
|
|
175
|
-
case 2:
|
|
176
|
-
_b = _c.sent().data, profile = _b.profile, traitsUpdatedAt = _b.traitsUpdatedAt, signals = _b.signals;
|
|
137
|
+
profile = _b.sent();
|
|
177
138
|
return [2
|
|
178
139
|
/*return*/
|
|
179
|
-
,
|
|
180
|
-
profile: profile,
|
|
181
|
-
cache: {
|
|
182
|
-
id: profile.id,
|
|
183
|
-
random: profile.random,
|
|
184
|
-
audiences: profile.audiences,
|
|
185
|
-
location: profile.location,
|
|
186
|
-
session: profile.session,
|
|
187
|
-
traitsUpdatedAt: traitsUpdatedAt,
|
|
188
|
-
traits: profile.traits,
|
|
189
|
-
signals: signals,
|
|
190
|
-
sessions: cacheFromCookie.sessions
|
|
191
|
-
}
|
|
192
|
-
}];
|
|
140
|
+
, profile];
|
|
193
141
|
}
|
|
194
142
|
});
|
|
195
143
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Profile, GeoLocation, NinetailedRequestContext
|
|
1
|
+
import { Profile, GeoLocation, NinetailedRequestContext } from '@ninetailed/experience.js-shared';
|
|
2
2
|
declare type Cookies = {
|
|
3
3
|
[key: string]: string;
|
|
4
4
|
};
|
|
@@ -11,8 +11,5 @@ declare type GetServerSideProfileOptions = {
|
|
|
11
11
|
ip?: string;
|
|
12
12
|
location?: GeoLocation;
|
|
13
13
|
};
|
|
14
|
-
export declare const fetchEdgeProfile: ({ ctx, cookies, clientId, environment, url, ip, location, }: GetServerSideProfileOptions) => Promise<
|
|
15
|
-
profile: Profile;
|
|
16
|
-
cache: Cache;
|
|
17
|
-
}>;
|
|
14
|
+
export declare const fetchEdgeProfile: ({ ctx, cookies, clientId, environment, url, ip, location, }: GetServerSideProfileOptions) => Promise<Profile>;
|
|
18
15
|
export {};
|
package/lib/selector.d.ts
CHANGED
|
@@ -1,6 +1,37 @@
|
|
|
1
|
-
import { Profile } from '@ninetailed/experience.js-shared';
|
|
2
1
|
declare type SelectNinetailedProfileOptions = {
|
|
3
2
|
ninetailed: string;
|
|
4
3
|
};
|
|
5
|
-
export declare const selectNinetailedProfile: ({ ninetailed, }: SelectNinetailedProfileOptions) =>
|
|
4
|
+
export declare const selectNinetailedProfile: ({ ninetailed, }: SelectNinetailedProfileOptions) => {
|
|
5
|
+
id: string;
|
|
6
|
+
random: number;
|
|
7
|
+
audiences: string[];
|
|
8
|
+
traits: import("@ninetailed/experience.js-shared").Traits;
|
|
9
|
+
location: {
|
|
10
|
+
coordinates?: {
|
|
11
|
+
latitude: number;
|
|
12
|
+
longitude: number;
|
|
13
|
+
} | undefined;
|
|
14
|
+
city?: string | undefined;
|
|
15
|
+
postalCode?: string | undefined;
|
|
16
|
+
region?: string | undefined;
|
|
17
|
+
regionCode?: string | undefined;
|
|
18
|
+
country?: string | undefined;
|
|
19
|
+
countryCode?: string | undefined;
|
|
20
|
+
continent?: string | undefined;
|
|
21
|
+
timezone?: string | undefined;
|
|
22
|
+
};
|
|
23
|
+
session: {
|
|
24
|
+
isReturningVisitor: boolean;
|
|
25
|
+
ladingPage: {
|
|
26
|
+
path: string;
|
|
27
|
+
url: string;
|
|
28
|
+
query: Record<string, string>;
|
|
29
|
+
referrer: string;
|
|
30
|
+
search: string;
|
|
31
|
+
};
|
|
32
|
+
count: number;
|
|
33
|
+
activeSessionLength: number;
|
|
34
|
+
averageSessionLength: number;
|
|
35
|
+
};
|
|
36
|
+
} | null;
|
|
6
37
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ninetailed/experience.js-next-esr",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1-beta.3",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"next": "12.1.0"
|
|
6
6
|
},
|
|
@@ -8,18 +8,16 @@
|
|
|
8
8
|
"module": "./index.esm.js",
|
|
9
9
|
"typings": "./index.d.ts",
|
|
10
10
|
"peerDependencies": {
|
|
11
|
-
"@ninetailed/experience.js-shared": "
|
|
12
|
-
"uuid": "^8.3.2",
|
|
11
|
+
"@ninetailed/experience.js-shared": "3.0.1-beta.3",
|
|
13
12
|
"ts-toolbelt": "^9.6.0",
|
|
13
|
+
"diary": "^0.3.1",
|
|
14
|
+
"zod": "^3.18.0",
|
|
14
15
|
"locale-enum": "^1.1.1",
|
|
15
16
|
"i18n-iso-countries": "^7.3.0",
|
|
16
|
-
"
|
|
17
|
+
"uuid": "^8.3.2",
|
|
18
|
+
"@ninetailed/experience.js-plugin-ssr": "3.0.1-beta.3",
|
|
17
19
|
"node-fetch": "^3.2.3",
|
|
18
20
|
"analytics": "^0.8.0",
|
|
19
|
-
"js-cookie": "^3.0.1"
|
|
20
|
-
"@ninetailed/experience.js": "2.2.8",
|
|
21
|
-
"lodash": "^4.17.21",
|
|
22
|
-
"murmurhash-js": "^1.0.0",
|
|
23
|
-
"diary": "^0.3.1"
|
|
21
|
+
"js-cookie": "^3.0.1"
|
|
24
22
|
}
|
|
25
23
|
}
|