beer-network 1.2.6 → 1.2.7

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.
Files changed (3) hide show
  1. package/api.d.ts +0 -1
  2. package/api.js +16 -14
  3. package/package.json +1 -1
package/api.d.ts CHANGED
@@ -38,7 +38,6 @@ export default class Fetch {
38
38
  private readonly pathPrefix;
39
39
  private readonly isNode;
40
40
  private isNextJS;
41
- private nodeHeaders;
42
41
  constructor(pathPrefix?: string);
43
42
  private sendBody;
44
43
  private sendForm;
package/api.js CHANGED
@@ -2,7 +2,6 @@ import { Session } from './session';
2
2
  export default class Fetch {
3
3
  constructor(pathPrefix) {
4
4
  this.isNextJS = undefined;
5
- this.nodeHeaders = undefined;
6
5
  this.pathPrefix = pathPrefix || '';
7
6
  this.isNode = typeof process !== 'undefined' && !!process.versions?.node;
8
7
  }
@@ -293,21 +292,24 @@ export default class Fetch {
293
292
  if (index > 2) {
294
293
  return undefined;
295
294
  }
296
- if (this.isNextJS && this.nodeHeaders !== undefined) {
297
- return this.nodeHeaders.get('x-access-token')
298
- ?? this.nodeHeaders.get('access-token')
299
- ?? this.nodeHeaders.get('authorization')
300
- ?? this.nodeHeaders.get('AccessToken')
301
- ?? this.nodeHeaders.get('Authorization')
302
- ?? '';
303
- }
304
- try {
295
+ if (this.isNextJS === true) {
305
296
  const nextModule = await import('next/headers');
306
- this.isNextJS = true;
307
- this.nodeHeaders = await nextModule.headers();
297
+ const nodeHeaders = await nextModule.headers();
298
+ return nodeHeaders.get('x-access-token')
299
+ ?? nodeHeaders.get('access-token')
300
+ ?? nodeHeaders.get('authorization')
301
+ ?? nodeHeaders.get('AccessToken')
302
+ ?? nodeHeaders.get('Authorization')
303
+ ?? '';
308
304
  }
309
- catch {
310
- this.isNextJS = false;
305
+ if (this.isNextJS === undefined) {
306
+ try {
307
+ await import('next/headers');
308
+ this.isNextJS = true;
309
+ }
310
+ catch {
311
+ this.isNextJS = false;
312
+ }
311
313
  }
312
314
  return this.tryAuthorization(index + 1);
313
315
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "beer-network",
3
3
  "private": false,
4
- "version": "1.2.6",
4
+ "version": "1.2.7",
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"