@ninetailed/experience.js-next-esr 3.0.1-beta.4 → 3.0.2-beta.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/index.cjs +103 -0
- package/{index.esm.js → index.js} +5 -6
- package/lib/selector.d.ts +2 -2
- package/package.json +8 -15
- package/index.umd.js +0 -151
package/index.cjs
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var uuid = require('uuid');
|
|
6
|
+
var experience_jsShared = require('@ninetailed/experience.js-shared');
|
|
7
|
+
var experience_jsPluginSsr = require('@ninetailed/experience.js-plugin-ssr');
|
|
8
|
+
|
|
9
|
+
function absoluteUrl(req, localhostAddress = 'localhost:3000') {
|
|
10
|
+
const hostHeader = req.headers.get('host');
|
|
11
|
+
let host = hostHeader ? hostHeader : localhostAddress;
|
|
12
|
+
let protocol = /^localhost(:\d+)?$/.test(host) ? 'http:' : 'https:';
|
|
13
|
+
if (req && req.headers.get('x-forwarded-host') && typeof req.headers.get('x-forwarded-host') === 'string') {
|
|
14
|
+
host = req.headers.get('x-forwarded-host');
|
|
15
|
+
}
|
|
16
|
+
if (req && req.headers.get('x-forwarded-proto') && typeof req.headers.get('x-forwarded-proto') === 'string') {
|
|
17
|
+
protocol = `${req.headers.get('x-forwarded-proto')}:`;
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
protocol,
|
|
21
|
+
host,
|
|
22
|
+
origin: protocol + '//' + host
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const getLocale = req => {
|
|
27
|
+
try {
|
|
28
|
+
return req.nextUrl.locale;
|
|
29
|
+
} catch (error) {
|
|
30
|
+
return req.nextUrl.defaultLocale || '';
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const buildNinetailedEdgeRequestContext = ({
|
|
34
|
+
req
|
|
35
|
+
}) => {
|
|
36
|
+
const url = new URL(`${req.nextUrl.pathname}${req.nextUrl.search}`, absoluteUrl(req).origin);
|
|
37
|
+
return {
|
|
38
|
+
url: url.toString(),
|
|
39
|
+
locale: getLocale(req),
|
|
40
|
+
referrer: req.headers.get('referer') || '',
|
|
41
|
+
userAgent: req.headers.get('user-agent') || ''
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/******************************************************************************
|
|
46
|
+
Copyright (c) Microsoft Corporation.
|
|
47
|
+
|
|
48
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
49
|
+
purpose with or without fee is hereby granted.
|
|
50
|
+
|
|
51
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
52
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
53
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
54
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
55
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
56
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
57
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
58
|
+
***************************************************************************** */
|
|
59
|
+
|
|
60
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
61
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
62
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
63
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
64
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
65
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
66
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const fetchEdgeProfile = ({
|
|
71
|
+
ctx,
|
|
72
|
+
cookies,
|
|
73
|
+
clientId,
|
|
74
|
+
environment,
|
|
75
|
+
url,
|
|
76
|
+
ip,
|
|
77
|
+
location
|
|
78
|
+
}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
79
|
+
const anonymousId = cookies[experience_jsPluginSsr.NINETAILED_ANONYMOUS_ID_COOKIE];
|
|
80
|
+
const apiClient = new experience_jsShared.NinetailedApiClient({
|
|
81
|
+
clientId,
|
|
82
|
+
environment,
|
|
83
|
+
url
|
|
84
|
+
});
|
|
85
|
+
const pageEvent = experience_jsShared.buildPageEvent({
|
|
86
|
+
ctx,
|
|
87
|
+
messageId: uuid.v4(),
|
|
88
|
+
timestamp: Date.now(),
|
|
89
|
+
properties: {},
|
|
90
|
+
location
|
|
91
|
+
});
|
|
92
|
+
const profile = yield apiClient.upsertProfile({
|
|
93
|
+
events: [pageEvent],
|
|
94
|
+
profileId: anonymousId
|
|
95
|
+
}, {
|
|
96
|
+
ip,
|
|
97
|
+
preflight: true
|
|
98
|
+
});
|
|
99
|
+
return profile;
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
exports.buildNinetailedEdgeRequestContext = buildNinetailedEdgeRequestContext;
|
|
103
|
+
exports.fetchEdgeProfile = fetchEdgeProfile;
|
|
@@ -6,15 +6,12 @@ function absoluteUrl(req, localhostAddress = 'localhost:3000') {
|
|
|
6
6
|
const hostHeader = req.headers.get('host');
|
|
7
7
|
let host = hostHeader ? hostHeader : localhostAddress;
|
|
8
8
|
let protocol = /^localhost(:\d+)?$/.test(host) ? 'http:' : 'https:';
|
|
9
|
-
|
|
10
9
|
if (req && req.headers.get('x-forwarded-host') && typeof req.headers.get('x-forwarded-host') === 'string') {
|
|
11
10
|
host = req.headers.get('x-forwarded-host');
|
|
12
11
|
}
|
|
13
|
-
|
|
14
12
|
if (req && req.headers.get('x-forwarded-proto') && typeof req.headers.get('x-forwarded-proto') === 'string') {
|
|
15
13
|
protocol = `${req.headers.get('x-forwarded-proto')}:`;
|
|
16
14
|
}
|
|
17
|
-
|
|
18
15
|
return {
|
|
19
16
|
protocol,
|
|
20
17
|
host,
|
|
@@ -29,7 +26,6 @@ const getLocale = req => {
|
|
|
29
26
|
return req.nextUrl.defaultLocale || '';
|
|
30
27
|
}
|
|
31
28
|
};
|
|
32
|
-
|
|
33
29
|
const buildNinetailedEdgeRequestContext = ({
|
|
34
30
|
req
|
|
35
31
|
}) => {
|
|
@@ -42,7 +38,7 @@ const buildNinetailedEdgeRequestContext = ({
|
|
|
42
38
|
};
|
|
43
39
|
};
|
|
44
40
|
|
|
45
|
-
|
|
41
|
+
/******************************************************************************
|
|
46
42
|
Copyright (c) Microsoft Corporation.
|
|
47
43
|
|
|
48
44
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
@@ -89,7 +85,10 @@ const fetchEdgeProfile = ({
|
|
|
89
85
|
properties: {},
|
|
90
86
|
location
|
|
91
87
|
});
|
|
92
|
-
const profile = yield apiClient.upsertProfile(
|
|
88
|
+
const profile = yield apiClient.upsertProfile({
|
|
89
|
+
events: [pageEvent],
|
|
90
|
+
profileId: anonymousId
|
|
91
|
+
}, {
|
|
93
92
|
ip,
|
|
94
93
|
preflight: true
|
|
95
94
|
});
|
package/lib/selector.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare const selectNinetailedProfile: ({ ninetailed, }: SelectNinetailed
|
|
|
5
5
|
id: string;
|
|
6
6
|
random: number;
|
|
7
7
|
audiences: string[];
|
|
8
|
-
traits: import("@ninetailed/experience.js-shared").
|
|
8
|
+
traits: import("@ninetailed/experience.js-shared").Properties;
|
|
9
9
|
location: {
|
|
10
10
|
coordinates?: {
|
|
11
11
|
latitude: number;
|
|
@@ -22,7 +22,7 @@ export declare const selectNinetailedProfile: ({ ninetailed, }: SelectNinetailed
|
|
|
22
22
|
};
|
|
23
23
|
session: {
|
|
24
24
|
isReturningVisitor: boolean;
|
|
25
|
-
|
|
25
|
+
landingPage: {
|
|
26
26
|
path: string;
|
|
27
27
|
url: string;
|
|
28
28
|
query: Record<string, string>;
|
package/package.json
CHANGED
|
@@ -1,23 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ninetailed/experience.js-next-esr",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2-beta.0",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"next": "12.1.0"
|
|
6
6
|
},
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
7
|
+
"module": "./index.js",
|
|
8
|
+
"main": "./index.cjs",
|
|
9
|
+
"type": "module",
|
|
10
|
+
"types": "./index.d.ts",
|
|
10
11
|
"peerDependencies": {
|
|
11
|
-
"@ninetailed/experience.js-shared": "3.0.
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"zod": "^3.18.0",
|
|
15
|
-
"locale-enum": "^1.1.1",
|
|
16
|
-
"i18n-iso-countries": "^7.3.0",
|
|
17
|
-
"uuid": "^8.3.2",
|
|
18
|
-
"@ninetailed/experience.js-plugin-ssr": "3.0.1-beta.4",
|
|
19
|
-
"node-fetch": "^3.2.3",
|
|
20
|
-
"analytics": "^0.8.0",
|
|
21
|
-
"js-cookie": "^3.0.1"
|
|
12
|
+
"@ninetailed/experience.js-shared": "3.0.2-beta.0",
|
|
13
|
+
"uuid": "9.0.0",
|
|
14
|
+
"@ninetailed/experience.js-plugin-ssr": "3.0.2-beta.0"
|
|
22
15
|
}
|
|
23
16
|
}
|
package/index.umd.js
DELETED
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('uuid'), require('@ninetailed/experience.js-shared'), require('@ninetailed/experience.js-plugin-ssr')) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', 'uuid', '@ninetailed/experience.js-shared', '@ninetailed/experience.js-plugin-ssr'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.NextjsEsr = {}, global.uuid, global.experience_jsShared, global.experience_jsPluginSsr));
|
|
5
|
-
})(this, (function (exports, uuid, experience_jsShared, experience_jsPluginSsr) { 'use strict';
|
|
6
|
-
|
|
7
|
-
function absoluteUrl(req, localhostAddress) {
|
|
8
|
-
if (localhostAddress === void 0) {
|
|
9
|
-
localhostAddress = 'localhost:3000';
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
var hostHeader = req.headers.get('host');
|
|
13
|
-
var host = hostHeader ? hostHeader : localhostAddress;
|
|
14
|
-
var protocol = /^localhost(:\d+)?$/.test(host) ? 'http:' : 'https:';
|
|
15
|
-
|
|
16
|
-
if (req && req.headers.get('x-forwarded-host') && typeof req.headers.get('x-forwarded-host') === 'string') {
|
|
17
|
-
host = req.headers.get('x-forwarded-host');
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (req && req.headers.get('x-forwarded-proto') && typeof req.headers.get('x-forwarded-proto') === 'string') {
|
|
21
|
-
protocol = "".concat(req.headers.get('x-forwarded-proto'), ":");
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return {
|
|
25
|
-
protocol: protocol,
|
|
26
|
-
host: host,
|
|
27
|
-
origin: protocol + '//' + host
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
var getLocale = function (req) {
|
|
32
|
-
try {
|
|
33
|
-
return req.nextUrl.locale;
|
|
34
|
-
} catch (error) {
|
|
35
|
-
return req.nextUrl.defaultLocale || '';
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
var buildNinetailedEdgeRequestContext = function (_a) {
|
|
40
|
-
var req = _a.req;
|
|
41
|
-
var url = new URL("".concat(req.nextUrl.pathname).concat(req.nextUrl.search), absoluteUrl(req).origin);
|
|
42
|
-
return {
|
|
43
|
-
url: url.toString(),
|
|
44
|
-
locale: getLocale(req),
|
|
45
|
-
referrer: req.headers.get('referer') || '',
|
|
46
|
-
userAgent: req.headers.get('user-agent') || ''
|
|
47
|
-
};
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
/*! *****************************************************************************
|
|
51
|
-
Copyright (c) Microsoft Corporation.
|
|
52
|
-
|
|
53
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
54
|
-
purpose with or without fee is hereby granted.
|
|
55
|
-
|
|
56
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
57
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
58
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
59
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
60
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
61
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
62
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
63
|
-
***************************************************************************** */
|
|
64
|
-
|
|
65
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
66
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
67
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
68
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
69
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
70
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
71
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function __generator(thisArg, body) {
|
|
76
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
77
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
78
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
79
|
-
function step(op) {
|
|
80
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
81
|
-
while (_) try {
|
|
82
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
83
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
84
|
-
switch (op[0]) {
|
|
85
|
-
case 0: case 1: t = op; break;
|
|
86
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
87
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
88
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
89
|
-
default:
|
|
90
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
91
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
92
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
93
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
94
|
-
if (t[2]) _.ops.pop();
|
|
95
|
-
_.trys.pop(); continue;
|
|
96
|
-
}
|
|
97
|
-
op = body.call(thisArg, _);
|
|
98
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
99
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
var fetchEdgeProfile = function (_a) {
|
|
104
|
-
var ctx = _a.ctx,
|
|
105
|
-
cookies = _a.cookies,
|
|
106
|
-
clientId = _a.clientId,
|
|
107
|
-
environment = _a.environment,
|
|
108
|
-
url = _a.url,
|
|
109
|
-
ip = _a.ip,
|
|
110
|
-
location = _a.location;
|
|
111
|
-
return __awaiter(void 0, void 0, void 0, function () {
|
|
112
|
-
var anonymousId, apiClient, pageEvent, profile;
|
|
113
|
-
return __generator(this, function (_b) {
|
|
114
|
-
switch (_b.label) {
|
|
115
|
-
case 0:
|
|
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
|
-
});
|
|
122
|
-
pageEvent = experience_jsShared.buildPageEvent({
|
|
123
|
-
ctx: ctx,
|
|
124
|
-
messageId: uuid.v4(),
|
|
125
|
-
timestamp: Date.now(),
|
|
126
|
-
properties: {},
|
|
127
|
-
location: location
|
|
128
|
-
});
|
|
129
|
-
return [4
|
|
130
|
-
/*yield*/
|
|
131
|
-
, apiClient.upsertProfile([pageEvent], anonymousId, {
|
|
132
|
-
ip: ip,
|
|
133
|
-
preflight: true
|
|
134
|
-
})];
|
|
135
|
-
|
|
136
|
-
case 1:
|
|
137
|
-
profile = _b.sent();
|
|
138
|
-
return [2
|
|
139
|
-
/*return*/
|
|
140
|
-
, profile];
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
exports.buildNinetailedEdgeRequestContext = buildNinetailedEdgeRequestContext;
|
|
147
|
-
exports.fetchEdgeProfile = fetchEdgeProfile;
|
|
148
|
-
|
|
149
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
150
|
-
|
|
151
|
-
}));
|