@usermaven/nextjs 1.5.7 → 1.5.8-rc.103
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/lib/index.es.js +29 -4
- package/lib/middlewareEnv.d.ts +2 -2
- package/lib/middlewareEnv.js +28 -3
- package/package.json +7 -7
package/lib/index.es.js
CHANGED
|
@@ -1292,7 +1292,7 @@ function $e(n) {
|
|
|
1292
1292
|
};
|
|
1293
1293
|
e.privacyPolicy === "strict" && (e.cookiePolicy = "strict", e.ipPolicy = "strict"), e.cookiePolicy === "comply" && e.useBeaconApi && (e.cookiePolicy = "strict");
|
|
1294
1294
|
const t = C(e), i = e.namespace || "usermaven";
|
|
1295
|
-
return u() &&
|
|
1295
|
+
return u() && t.pageview(), Se(i, t), t;
|
|
1296
1296
|
}
|
|
1297
1297
|
function Se(n, e) {
|
|
1298
1298
|
let t = !1;
|
|
@@ -1659,29 +1659,54 @@ function isDate (val) {
|
|
|
1659
1659
|
val instanceof Date
|
|
1660
1660
|
}
|
|
1661
1661
|
|
|
1662
|
+
function hasGetMethod(cookies) {
|
|
1663
|
+
return cookies && typeof cookies.get === 'function';
|
|
1664
|
+
}
|
|
1665
|
+
function hasSetMethod(cookies) {
|
|
1666
|
+
return cookies && typeof cookies.set === 'function';
|
|
1667
|
+
}
|
|
1662
1668
|
function middlewareEnv(req, res, opts = {}) {
|
|
1663
1669
|
return {
|
|
1664
1670
|
getAnonymousId({ name, domain }) {
|
|
1665
1671
|
if (opts === null || opts === void 0 ? void 0 : opts.disableCookies) {
|
|
1666
1672
|
return "";
|
|
1667
1673
|
}
|
|
1668
|
-
|
|
1674
|
+
let cookie;
|
|
1675
|
+
if (hasGetMethod(req.cookies)) {
|
|
1676
|
+
const cookieObj = req.cookies.get(name);
|
|
1677
|
+
cookie = cookieObj === null || cookieObj === void 0 ? void 0 : cookieObj.value;
|
|
1678
|
+
}
|
|
1679
|
+
else if (req.cookies && typeof req.cookies === 'object') {
|
|
1680
|
+
cookie = req.cookies[name];
|
|
1681
|
+
}
|
|
1669
1682
|
if (cookie) {
|
|
1670
1683
|
return cookie;
|
|
1671
1684
|
}
|
|
1672
1685
|
const cookieOpts = {
|
|
1673
1686
|
maxAge: 31622400 * 10,
|
|
1674
1687
|
httpOnly: false,
|
|
1688
|
+
path: "/",
|
|
1675
1689
|
};
|
|
1676
1690
|
if (domain) {
|
|
1677
1691
|
cookieOpts.domain = domain;
|
|
1678
1692
|
}
|
|
1679
1693
|
let newId = Math.random().toString(36).substring(2, 12);
|
|
1680
|
-
res.
|
|
1694
|
+
if (res.cookies && hasSetMethod(res.cookies)) {
|
|
1695
|
+
res.cookies.set({
|
|
1696
|
+
name,
|
|
1697
|
+
value: newId,
|
|
1698
|
+
maxAge: cookieOpts.maxAge,
|
|
1699
|
+
domain: cookieOpts.domain,
|
|
1700
|
+
httpOnly: cookieOpts.httpOnly
|
|
1701
|
+
});
|
|
1702
|
+
}
|
|
1703
|
+
else {
|
|
1704
|
+
res.headers.set("Set-Cookie", serialize_1(name, newId, cookieOpts));
|
|
1705
|
+
}
|
|
1681
1706
|
return newId;
|
|
1682
1707
|
},
|
|
1683
1708
|
getSourceIp() {
|
|
1684
|
-
let ip = req.headers.get("x-forwarded-for") || req.headers.get("x-real-ip") ||
|
|
1709
|
+
let ip = req.headers.get("x-forwarded-for") || req.headers.get("x-real-ip") || '';
|
|
1685
1710
|
return ip && ip.split(",")[0].trim();
|
|
1686
1711
|
},
|
|
1687
1712
|
describeClient() {
|
package/lib/middlewareEnv.d.ts
CHANGED
|
@@ -4,8 +4,8 @@ declare function middlewareEnv(req: NextRequest, res: NextResponse, opts?: {
|
|
|
4
4
|
disableCookies?: boolean;
|
|
5
5
|
}): {
|
|
6
6
|
getAnonymousId({ name, domain }: {
|
|
7
|
-
name:
|
|
8
|
-
domain
|
|
7
|
+
name: string;
|
|
8
|
+
domain?: string;
|
|
9
9
|
}): string;
|
|
10
10
|
getSourceIp(): string;
|
|
11
11
|
describeClient(): ClientProperties;
|
package/lib/middlewareEnv.js
CHANGED
|
@@ -1,29 +1,54 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const cookie_1 = require("cookie");
|
|
4
|
+
function hasGetMethod(cookies) {
|
|
5
|
+
return cookies && typeof cookies.get === 'function';
|
|
6
|
+
}
|
|
7
|
+
function hasSetMethod(cookies) {
|
|
8
|
+
return cookies && typeof cookies.set === 'function';
|
|
9
|
+
}
|
|
4
10
|
function middlewareEnv(req, res, opts = {}) {
|
|
5
11
|
return {
|
|
6
12
|
getAnonymousId({ name, domain }) {
|
|
7
13
|
if (opts === null || opts === void 0 ? void 0 : opts.disableCookies) {
|
|
8
14
|
return "";
|
|
9
15
|
}
|
|
10
|
-
|
|
16
|
+
let cookie;
|
|
17
|
+
if (hasGetMethod(req.cookies)) {
|
|
18
|
+
const cookieObj = req.cookies.get(name);
|
|
19
|
+
cookie = cookieObj === null || cookieObj === void 0 ? void 0 : cookieObj.value;
|
|
20
|
+
}
|
|
21
|
+
else if (req.cookies && typeof req.cookies === 'object') {
|
|
22
|
+
cookie = req.cookies[name];
|
|
23
|
+
}
|
|
11
24
|
if (cookie) {
|
|
12
25
|
return cookie;
|
|
13
26
|
}
|
|
14
27
|
const cookieOpts = {
|
|
15
28
|
maxAge: 31622400 * 10,
|
|
16
29
|
httpOnly: false,
|
|
30
|
+
path: "/",
|
|
17
31
|
};
|
|
18
32
|
if (domain) {
|
|
19
33
|
cookieOpts.domain = domain;
|
|
20
34
|
}
|
|
21
35
|
let newId = Math.random().toString(36).substring(2, 12);
|
|
22
|
-
res.
|
|
36
|
+
if (res.cookies && hasSetMethod(res.cookies)) {
|
|
37
|
+
res.cookies.set({
|
|
38
|
+
name,
|
|
39
|
+
value: newId,
|
|
40
|
+
maxAge: cookieOpts.maxAge,
|
|
41
|
+
domain: cookieOpts.domain,
|
|
42
|
+
httpOnly: cookieOpts.httpOnly
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
res.headers.set("Set-Cookie", (0, cookie_1.serialize)(name, newId, cookieOpts));
|
|
47
|
+
}
|
|
23
48
|
return newId;
|
|
24
49
|
},
|
|
25
50
|
getSourceIp() {
|
|
26
|
-
let ip = req.headers.get("x-forwarded-for") || req.headers.get("x-real-ip") ||
|
|
51
|
+
let ip = req.headers.get("x-forwarded-for") || req.headers.get("x-real-ip") || '';
|
|
27
52
|
return ip && ip.split(",")[0].trim();
|
|
28
53
|
},
|
|
29
54
|
describeClient() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usermaven/nextjs",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.8-rc.103",
|
|
4
4
|
"description": "Usermaven JavaScript SDK for NextJS",
|
|
5
5
|
"author": "Usermaven <hello@usermaven.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,20 +18,20 @@
|
|
|
18
18
|
"access": "public"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@usermaven/sdk-js": "1.5.
|
|
21
|
+
"@usermaven/sdk-js": "1.5.8-rc.103",
|
|
22
22
|
"cookie": "^0.5.0"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"next": "^10.0.8 || ^11.0 || ^12.0 || ^13.0",
|
|
26
|
-
"react": "15.x || 16.x || 17.x || 18.x"
|
|
25
|
+
"next": "^10.0.8 || ^11.0 || ^12.0 || ^13.0 || ^14.0 || ^15.0",
|
|
26
|
+
"react": "15.x || 16.x || 17.x || 18.x || 19.x"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@rollup/plugin-commonjs": "^21.0.2",
|
|
30
30
|
"@rollup/plugin-node-resolve": "^13.1.4",
|
|
31
31
|
"@rollup/plugin-typescript": "^8.3.1",
|
|
32
|
-
"@types/react": "^
|
|
33
|
-
"next": "^
|
|
34
|
-
"react": "^
|
|
32
|
+
"@types/react": "^18.2.0",
|
|
33
|
+
"next": "^15.0.0",
|
|
34
|
+
"react": "^19.0.0",
|
|
35
35
|
"rollup": "^2.70.1",
|
|
36
36
|
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
37
37
|
"tslib": "^2.3.1"
|