@koolbase/core 12.37.0 → 12.38.0

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.
@@ -1,6 +1,7 @@
1
1
  export * from './types.js';
2
2
  export * from './errors.js';
3
3
  export * from './network.js';
4
+ export * from './memory-auth-storage.js';
4
5
  export * from './aggregate.js';
5
6
  export * from './conflict.js';
6
7
  export * from './pending-write.js';
package/dist/cjs/index.js CHANGED
@@ -23,6 +23,7 @@ exports.memoryPlatform = exports.getPlatform = exports.setPlatform = exports.Res
23
23
  __exportStar(require("./types.js"), exports);
24
24
  __exportStar(require("./errors.js"), exports);
25
25
  __exportStar(require("./network.js"), exports);
26
+ __exportStar(require("./memory-auth-storage.js"), exports);
26
27
  __exportStar(require("./aggregate.js"), exports);
27
28
  __exportStar(require("./conflict.js"), exports);
28
29
  __exportStar(require("./pending-write.js"), exports);
@@ -0,0 +1,12 @@
1
+ import type { KoolbaseAuthStorage, KoolbaseSession } from './types.js';
2
+ /**
3
+ * A session kept in memory only (R49): nothing survives the process. For
4
+ * tests -- Koolbase.initializeForTesting uses it -- and for a host that must
5
+ * not persist a session. The twin of the Flutter SDK's InMemoryAuthStorage.
6
+ */
7
+ export declare class MemoryAuthStorage implements KoolbaseAuthStorage {
8
+ private session;
9
+ saveSession(session: KoolbaseSession): Promise<void>;
10
+ readSession(): Promise<KoolbaseSession | null>;
11
+ clear(): Promise<void>;
12
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MemoryAuthStorage = void 0;
4
+ /**
5
+ * A session kept in memory only (R49): nothing survives the process. For
6
+ * tests -- Koolbase.initializeForTesting uses it -- and for a host that must
7
+ * not persist a session. The twin of the Flutter SDK's InMemoryAuthStorage.
8
+ */
9
+ class MemoryAuthStorage {
10
+ constructor() {
11
+ this.session = null;
12
+ }
13
+ async saveSession(session) {
14
+ this.session = session;
15
+ }
16
+ async readSession() {
17
+ return this.session;
18
+ }
19
+ async clear() {
20
+ this.session = null;
21
+ }
22
+ }
23
+ exports.MemoryAuthStorage = MemoryAuthStorage;
@@ -1,3 +1,4 @@
1
+ import type { FetchLike } from './types.js';
1
2
  /**
2
3
  * Network failures, made actionable.
3
4
  *
@@ -17,6 +18,14 @@ export declare class KoolbaseNetworkError extends TypeError {
17
18
  readonly origin?: string;
18
19
  constructor(url: string, cause: unknown);
19
20
  }
21
+ /**
22
+ * Installed by Koolbase.initialize from KoolbaseConfig.fetch: the fetch every
23
+ * JSON request the SDK makes goes through -- a proxy, a logger, or a test's
24
+ * own server (initializeForTesting). Null is the global fetch, read at each
25
+ * call. File bytes sent to a storage URL are not JSON requests and use the
26
+ * global fetch.
27
+ */
28
+ export declare function setFetch(fn: FetchLike | null): void;
20
29
  /** fetch, with network failures turned into a KoolbaseNetworkError, and a
21
30
  * failed answer traced in a development build (#169). */
22
31
  export declare function koolbaseFetch(input: string, init?: RequestInit): Promise<Response>;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.KoolbaseNetworkError = void 0;
4
+ exports.setFetch = setFetch;
4
5
  exports.koolbaseFetch = koolbaseFetch;
5
6
  exports.setSessionRenewal = setSessionRenewal;
6
7
  exports.sessionFetch = sessionFetch;
@@ -42,11 +43,23 @@ class KoolbaseNetworkError extends TypeError {
42
43
  }
43
44
  }
44
45
  exports.KoolbaseNetworkError = KoolbaseNetworkError;
46
+ // ─── The fetch every JSON request goes through (R49) ───────────────────
47
+ let installedFetch = null;
48
+ /**
49
+ * Installed by Koolbase.initialize from KoolbaseConfig.fetch: the fetch every
50
+ * JSON request the SDK makes goes through -- a proxy, a logger, or a test's
51
+ * own server (initializeForTesting). Null is the global fetch, read at each
52
+ * call. File bytes sent to a storage URL are not JSON requests and use the
53
+ * global fetch.
54
+ */
55
+ function setFetch(fn) {
56
+ installedFetch = fn;
57
+ }
45
58
  /** fetch, with network failures turned into a KoolbaseNetworkError. Not
46
59
  * logged: sessionFetch's first attempt may yet be answered by renewal. */
47
60
  async function sendOnce(input, init) {
48
61
  try {
49
- return await fetch(input, init);
62
+ return await (installedFetch ?? fetch)(input, init);
50
63
  }
51
64
  catch (e) {
52
65
  // A request the caller cancelled keeps its meaning.
@@ -1,6 +1,7 @@
1
1
  export * from './types.js';
2
2
  export * from './errors.js';
3
3
  export * from './network.js';
4
+ export * from './memory-auth-storage.js';
4
5
  export * from './aggregate.js';
5
6
  export * from './conflict.js';
6
7
  export * from './pending-write.js';
package/dist/esm/index.js CHANGED
@@ -6,6 +6,7 @@
6
6
  export * from './types.js';
7
7
  export * from './errors.js';
8
8
  export * from './network.js';
9
+ export * from './memory-auth-storage.js';
9
10
  export * from './aggregate.js';
10
11
  export * from './conflict.js';
11
12
  export * from './pending-write.js';
@@ -0,0 +1,12 @@
1
+ import type { KoolbaseAuthStorage, KoolbaseSession } from './types.js';
2
+ /**
3
+ * A session kept in memory only (R49): nothing survives the process. For
4
+ * tests -- Koolbase.initializeForTesting uses it -- and for a host that must
5
+ * not persist a session. The twin of the Flutter SDK's InMemoryAuthStorage.
6
+ */
7
+ export declare class MemoryAuthStorage implements KoolbaseAuthStorage {
8
+ private session;
9
+ saveSession(session: KoolbaseSession): Promise<void>;
10
+ readSession(): Promise<KoolbaseSession | null>;
11
+ clear(): Promise<void>;
12
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * A session kept in memory only (R49): nothing survives the process. For
3
+ * tests -- Koolbase.initializeForTesting uses it -- and for a host that must
4
+ * not persist a session. The twin of the Flutter SDK's InMemoryAuthStorage.
5
+ */
6
+ export class MemoryAuthStorage {
7
+ constructor() {
8
+ this.session = null;
9
+ }
10
+ async saveSession(session) {
11
+ this.session = session;
12
+ }
13
+ async readSession() {
14
+ return this.session;
15
+ }
16
+ async clear() {
17
+ this.session = null;
18
+ }
19
+ }
@@ -1,3 +1,4 @@
1
+ import type { FetchLike } from './types.js';
1
2
  /**
2
3
  * Network failures, made actionable.
3
4
  *
@@ -17,6 +18,14 @@ export declare class KoolbaseNetworkError extends TypeError {
17
18
  readonly origin?: string;
18
19
  constructor(url: string, cause: unknown);
19
20
  }
21
+ /**
22
+ * Installed by Koolbase.initialize from KoolbaseConfig.fetch: the fetch every
23
+ * JSON request the SDK makes goes through -- a proxy, a logger, or a test's
24
+ * own server (initializeForTesting). Null is the global fetch, read at each
25
+ * call. File bytes sent to a storage URL are not JSON requests and use the
26
+ * global fetch.
27
+ */
28
+ export declare function setFetch(fn: FetchLike | null): void;
20
29
  /** fetch, with network failures turned into a KoolbaseNetworkError, and a
21
30
  * failed answer traced in a development build (#169). */
22
31
  export declare function koolbaseFetch(input: string, init?: RequestInit): Promise<Response>;
@@ -35,11 +35,23 @@ export class KoolbaseNetworkError extends TypeError {
35
35
  Object.setPrototypeOf(this, new.target.prototype);
36
36
  }
37
37
  }
38
+ // ─── The fetch every JSON request goes through (R49) ───────────────────
39
+ let installedFetch = null;
40
+ /**
41
+ * Installed by Koolbase.initialize from KoolbaseConfig.fetch: the fetch every
42
+ * JSON request the SDK makes goes through -- a proxy, a logger, or a test's
43
+ * own server (initializeForTesting). Null is the global fetch, read at each
44
+ * call. File bytes sent to a storage URL are not JSON requests and use the
45
+ * global fetch.
46
+ */
47
+ export function setFetch(fn) {
48
+ installedFetch = fn;
49
+ }
38
50
  /** fetch, with network failures turned into a KoolbaseNetworkError. Not
39
51
  * logged: sessionFetch's first attempt may yet be answered by renewal. */
40
52
  async function sendOnce(input, init) {
41
53
  try {
42
- return await fetch(input, init);
54
+ return await (installedFetch ?? fetch)(input, init);
43
55
  }
44
56
  catch (e) {
45
57
  // A request the caller cancelled keeps its meaning.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koolbase/core",
3
- "version": "12.37.0",
3
+ "version": "12.38.0",
4
4
  "description": "Koolbase SDK core \u2014 shared behaviour behind @koolbase/react-native and @koolbase/js. Install one of those, not this.",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "types": "./dist/esm/index.d.ts",