@logto/node 2.5.5 → 2.5.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.
@@ -12,7 +12,7 @@ class CookieStorage {
12
12
  httpOnly: true,
13
13
  path: '/',
14
14
  sameSite: 'lax',
15
- secure: this.#isSecure,
15
+ secure: this.config.isSecure ?? false,
16
16
  maxAge: 14 * 24 * 3600, // 14 days
17
17
  });
18
18
  }
@@ -22,16 +22,13 @@ class CookieStorage {
22
22
  get data() {
23
23
  return this.sessionData;
24
24
  }
25
- #isSecure;
26
- constructor(config, request) {
25
+ constructor(config) {
27
26
  this.config = config;
28
27
  this.sessionData = {};
29
28
  this.saveQueue = new promiseQueue.PromiseQueue();
30
29
  if (!config.encryptionKey) {
31
30
  throw new TypeError('The `encryptionKey` string is required for `CookieStorage`');
32
31
  }
33
- this.#isSecure =
34
- request.headers.get('x-forwarded-proto') === 'https' || request.url.startsWith('https');
35
32
  }
36
33
  async init() {
37
34
  const { encryptionKey } = this.config;
@@ -49,12 +46,17 @@ class CookieStorage {
49
46
  delete this.sessionData[key];
50
47
  await this.save();
51
48
  }
49
+ async destroy() {
50
+ this.sessionData = {};
51
+ await this.save();
52
+ }
52
53
  async save() {
53
54
  return this.saveQueue.enqueue(async () => this.write());
54
55
  }
55
56
  async write(data = this.sessionData) {
56
57
  const { encryptionKey } = this.config;
57
- this.config.setCookie(this.cookieKey, await session.wrapSession(data, encryptionKey), this.cookieOptions);
58
+ const value = await session.wrapSession(data, encryptionKey);
59
+ this.config.setCookie(this.cookieKey, value, this.cookieOptions);
58
60
  }
59
61
  }
60
62
 
@@ -1,5 +1,5 @@
1
1
  import { type PersistKey, type Storage } from '@logto/client';
2
- import type { CookieSerializeOptions } from 'cookie';
2
+ import { type CookieSerializeOptions } from 'cookie';
3
3
  import { PromiseQueue } from './promise-queue.js';
4
4
  import { type SessionData } from './session.js';
5
5
  type Nullable<T> = T | null;
@@ -8,20 +8,17 @@ export type CookieConfig = {
8
8
  encryptionKey: string;
9
9
  /** The name of the cookie key. Default to `logtoCookies`. */
10
10
  cookieKey?: string;
11
+ /** Set to true in https */
12
+ isSecure?: boolean;
11
13
  getCookie: (name: string) => string | undefined;
12
14
  setCookie: (name: string, value: string, options: CookieSerializeOptions & {
13
15
  path: string;
14
16
  }) => void;
15
17
  };
16
- export type PartialRequest = {
17
- headers: Headers;
18
- url: string;
19
- };
20
18
  /**
21
19
  * A storage that persists data in cookies with encryption.
22
20
  */
23
21
  export declare class CookieStorage implements Storage<PersistKey> {
24
- #private;
25
22
  config: CookieConfig;
26
23
  protected get cookieOptions(): Readonly<{
27
24
  httpOnly: true;
@@ -34,11 +31,12 @@ export declare class CookieStorage implements Storage<PersistKey> {
34
31
  get data(): SessionData;
35
32
  protected sessionData: SessionData;
36
33
  protected saveQueue: PromiseQueue;
37
- constructor(config: CookieConfig, request: PartialRequest);
34
+ constructor(config: CookieConfig);
38
35
  init(): Promise<void>;
39
36
  getItem(key: PersistKey): Promise<Nullable<string>>;
40
37
  setItem(key: PersistKey, value: string): Promise<void>;
41
38
  removeItem(key: PersistKey): Promise<void>;
39
+ destroy(): Promise<void>;
42
40
  protected save(): Promise<void>;
43
41
  protected write(data?: SessionData): Promise<void>;
44
42
  }
@@ -10,7 +10,7 @@ class CookieStorage {
10
10
  httpOnly: true,
11
11
  path: '/',
12
12
  sameSite: 'lax',
13
- secure: this.#isSecure,
13
+ secure: this.config.isSecure ?? false,
14
14
  maxAge: 14 * 24 * 3600, // 14 days
15
15
  });
16
16
  }
@@ -20,16 +20,13 @@ class CookieStorage {
20
20
  get data() {
21
21
  return this.sessionData;
22
22
  }
23
- #isSecure;
24
- constructor(config, request) {
23
+ constructor(config) {
25
24
  this.config = config;
26
25
  this.sessionData = {};
27
26
  this.saveQueue = new PromiseQueue();
28
27
  if (!config.encryptionKey) {
29
28
  throw new TypeError('The `encryptionKey` string is required for `CookieStorage`');
30
29
  }
31
- this.#isSecure =
32
- request.headers.get('x-forwarded-proto') === 'https' || request.url.startsWith('https');
33
30
  }
34
31
  async init() {
35
32
  const { encryptionKey } = this.config;
@@ -47,12 +44,17 @@ class CookieStorage {
47
44
  delete this.sessionData[key];
48
45
  await this.save();
49
46
  }
47
+ async destroy() {
48
+ this.sessionData = {};
49
+ await this.save();
50
+ }
50
51
  async save() {
51
52
  return this.saveQueue.enqueue(async () => this.write());
52
53
  }
53
54
  async write(data = this.sessionData) {
54
55
  const { encryptionKey } = this.config;
55
- this.config.setCookie(this.cookieKey, await wrapSession(data, encryptionKey), this.cookieOptions);
56
+ const value = await wrapSession(data, encryptionKey);
57
+ this.config.setCookie(this.cookieKey, value, this.cookieOptions);
56
58
  }
57
59
  }
58
60
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logto/node",
3
- "version": "2.5.5",
3
+ "version": "2.5.7",
4
4
  "type": "module",
5
5
  "main": "./lib/src/index.cjs",
6
6
  "module": "./lib/src/index.js",
@@ -34,7 +34,7 @@
34
34
  "dependencies": {
35
35
  "@silverhand/essentials": "^2.8.7",
36
36
  "js-base64": "^3.7.4",
37
- "@logto/client": "^2.7.3"
37
+ "@logto/client": "^2.8.1"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@silverhand/eslint-config": "^6.0.1",