beer-network 1.2.7 → 1.2.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.
@@ -0,0 +1,13 @@
1
+ type HeadersLike = {
2
+ get(name: string): string | null;
3
+ };
4
+ type CookiesLike = {
5
+ get(name: string): {
6
+ value: string;
7
+ } | undefined;
8
+ getAll?: () => Array<any>;
9
+ has?: (name: string) => boolean;
10
+ };
11
+ export declare function getNodeHeaders(): HeadersLike;
12
+ export declare function getNodeCookies(): CookiesLike;
13
+ export {};
@@ -0,0 +1,43 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ /* eslint-disable no-eval */
3
+ function loadNextHeadersModule() {
4
+ try {
5
+ const req = eval('require');
6
+ return req('next/headers');
7
+ }
8
+ catch {
9
+ return null;
10
+ }
11
+ }
12
+ function emptyHeaders() {
13
+ return {
14
+ get() {
15
+ return null;
16
+ }
17
+ };
18
+ }
19
+ function emptyCookies() {
20
+ return {
21
+ get() {
22
+ return undefined;
23
+ },
24
+ getAll() {
25
+ return [];
26
+ },
27
+ has() {
28
+ return false;
29
+ }
30
+ };
31
+ }
32
+ export function getNodeHeaders() {
33
+ const mod = loadNextHeadersModule();
34
+ if (mod?.headers)
35
+ return mod.headers();
36
+ return emptyHeaders();
37
+ }
38
+ export function getNodeCookies() {
39
+ const mod = loadNextHeadersModule();
40
+ if (mod?.cookies)
41
+ return mod.cookies();
42
+ return emptyCookies();
43
+ }
package/api.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Session } from './session';
2
+ import { getNodeHeaders } from './NextHeadersLazy';
2
3
  export default class Fetch {
3
4
  constructor(pathPrefix) {
4
5
  this.isNextJS = undefined;
@@ -293,8 +294,7 @@ export default class Fetch {
293
294
  return undefined;
294
295
  }
295
296
  if (this.isNextJS === true) {
296
- const nextModule = await import('next/headers');
297
- const nodeHeaders = await nextModule.headers();
297
+ const nodeHeaders = getNodeHeaders();
298
298
  return nodeHeaders.get('x-access-token')
299
299
  ?? nodeHeaders.get('access-token')
300
300
  ?? nodeHeaders.get('authorization')
@@ -304,7 +304,7 @@ export default class Fetch {
304
304
  }
305
305
  if (this.isNextJS === undefined) {
306
306
  try {
307
- await import('next/headers');
307
+ getNodeHeaders();
308
308
  this.isNextJS = true;
309
309
  }
310
310
  catch {
package/package.json CHANGED
@@ -1,13 +1,11 @@
1
1
  {
2
2
  "name": "beer-network",
3
3
  "private": false,
4
- "version": "1.2.7",
4
+ "version": "1.2.9",
5
5
  "scripts": {
6
6
  "pub-w": "tsc && copy package.json .\\dist\\package.json && npm publish ./dist",
7
7
  "pub-m": "tsc && cp package.json ./dist/package.json && npm publish ./dist"
8
8
  },
9
- "dependencies": {
10
- },
11
9
  "peerDependencies": {
12
10
  "next": "*"
13
11
  },
@@ -17,8 +15,8 @@
17
15
  }
18
16
  },
19
17
  "devDependencies": {
20
- "next": "^16.1.3",
21
18
  "@babel/eslint-parser": "^7.22.15",
19
+ "@types/node": "^25.0.10",
22
20
  "@typescript-eslint/eslint-plugin": "^6.0.0",
23
21
  "@typescript-eslint/parser": "^6.0.0",
24
22
  "eslint": "^8.45.0",
@@ -28,6 +26,7 @@
28
26
  "eslint-plugin-react": "^7.33.2",
29
27
  "eslint-plugin-react-hooks": "^4.6.0",
30
28
  "eslint-plugin-react-refresh": "^0.4.3",
29
+ "next": "^16.1.3",
31
30
  "typescript": "^5.0.2"
32
31
  }
33
32
  }