@usermaven/nextjs 1.5.8 → 1.5.9

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.
@@ -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: any;
8
- domain: any;
7
+ name: string;
8
+ domain?: string;
9
9
  }): string;
10
10
  getSourceIp(): string;
11
11
  describeClient(): ClientProperties;
@@ -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
- const cookie = req.cookies[name];
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.headers.set("Set-Cookie", (0, cookie_1.serialize)(name, newId, cookieOpts));
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") || req.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.8",
3
+ "version": "1.5.9",
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.8",
21
+ "@usermaven/sdk-js": "1.5.9",
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": "^17.0.43",
33
- "next": "^12.1.5",
34
- "react": "^17.0.2",
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"