@sockethub/data-layer 1.0.0-alpha.13 → 1.0.0-alpha.14

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.
@@ -11,13 +11,43 @@ import type { RedisConfig } from "./types.js";
11
11
  * @returns Shared Redis connection instance
12
12
  */
13
13
  export declare function createCredentialsRedisConnection(config: RedisConfig): Redis;
14
+ /**
15
+ * Creates or returns a dedicated shared Redis connection for HTTP idempotency.
16
+ */
17
+ export declare function createIdempotencyRedisConnection(config: RedisConfig): Redis;
18
+ /**
19
+ * Creates or returns a dedicated shared Redis connection for rate limiting.
20
+ * A dedicated connection keeps rate-limit traffic off the credentials and
21
+ * idempotency connections and lets a Redis-backed limiter share request budgets
22
+ * across instances.
23
+ */
24
+ export declare function createRateLimitRedisConnection(config: RedisConfig): Redis;
14
25
  /**
15
26
  * Resets the shared credentials Redis connection. Used primarily for testing.
16
27
  */
17
28
  export declare function resetSharedCredentialsRedisConnection(): Promise<void>;
29
+ export declare function resetSharedIdempotencyRedisConnection(): Promise<void>;
30
+ export declare function resetSharedRateLimitRedisConnection(): Promise<void>;
18
31
  export interface CredentialsStoreInterface {
19
32
  get(actor: string, credentialsHash?: string, options?: CredentialsValidationOptions): Promise<CredentialsObject | undefined>;
20
33
  save(actor: string, creds: CredentialsObject): Promise<number>;
34
+ /**
35
+ * Delete this session's entire credential namespace from Redis. Used by
36
+ * single-use sessions (e.g. HTTP actions requests) whose credentials are
37
+ * never read again once the request completes. Optional: long-lived socket
38
+ * sessions do not implement it.
39
+ */
40
+ teardown?(): Promise<void>;
41
+ }
42
+ export interface CredentialsStoreOptions {
43
+ /**
44
+ * Sliding time-to-live in milliseconds applied to this session's
45
+ * credential key in Redis, refreshed on every save and read. A backstop
46
+ * against keys orphaned by crashes or ungraceful shutdowns where explicit
47
+ * teardown never runs — size it generously (idle sessions do not refresh
48
+ * it). Omit or 0 to disable expiry.
49
+ */
50
+ ttlMs?: number;
21
51
  }
22
52
  export interface CredentialsValidationOptions {
23
53
  /**
@@ -69,9 +99,9 @@ export declare class CredentialsStore implements CredentialsStoreInterface {
69
99
  * @param redisConfig - Redis connection configuration
70
100
  * @throws Error if secret is not exactly 32 characters
71
101
  */
72
- constructor(parentId: string, sessionId: string, secret: string, redisConfig: RedisConfig);
102
+ constructor(parentId: string, sessionId: string, secret: string, redisConfig: RedisConfig, options?: CredentialsStoreOptions);
73
103
  initCrypto(): void;
74
- initSecureStore(secret: string, redisConfig: RedisConfig): void;
104
+ initSecureStore(secret: string, redisConfig: RedisConfig, ttlMs?: number): void;
75
105
  /**
76
106
  * Gets the credentials for a given actor ID.
77
107
  * @param actor
@@ -85,4 +115,26 @@ export declare class CredentialsStore implements CredentialsStoreInterface {
85
115
  * @param creds
86
116
  */
87
117
  save(actor: string, creds: CredentialsObject): Promise<number>;
118
+ /**
119
+ * Delete this session's entire credential hash from Redis, promptly
120
+ * reclaiming the key instead of waiting for its TTL (if any) to lapse.
121
+ * Called when the session ends (socket disconnect, HTTP actions request
122
+ * cleanup). Best-effort and safe to call when nothing was stored — a
123
+ * missing key is a no-op.
124
+ */
125
+ teardown(): Promise<void>;
88
126
  }
127
+ /**
128
+ * Delete every credential-store key belonging to `parentId`. Called from
129
+ * server shutdown so an instance reclaims its own keys instead of stranding
130
+ * them under a parentId that no future boot will ever reference (each boot
131
+ * randomizes its parentId). Scoped strictly to the given parentId: Redis may
132
+ * be shared by multiple running instances, so keys under other parentIds are
133
+ * never touched. Returns the number of keys removed.
134
+ */
135
+ export declare function purgeCredentialsStoreKeys(client: Redis, parentId: string): Promise<number>;
136
+ /**
137
+ * Convenience wrapper over {@link purgeCredentialsStoreKeys} using the shared
138
+ * credentials Redis connection.
139
+ */
140
+ export declare function purgeCredentialsStores(parentId: string, config: RedisConfig): Promise<number>;
package/dist/index.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { CredentialsMismatchError, CredentialsNotShareableError, CredentialsStore, type CredentialsStoreInterface, type CredentialsValidationOptions, resetSharedCredentialsRedisConnection } from "./credentials-store.js";
1
+ import { CredentialsMismatchError, CredentialsNotShareableError, CredentialsStore, type CredentialsStoreInterface, type CredentialsStoreOptions, type CredentialsValidationOptions, createCredentialsRedisConnection, createIdempotencyRedisConnection, createRateLimitRedisConnection, purgeCredentialsStoreKeys, purgeCredentialsStores, resetSharedCredentialsRedisConnection, resetSharedIdempotencyRedisConnection, resetSharedRateLimitRedisConnection } from "./credentials-store.js";
2
2
  import { getRedisConnectionCount, resetSharedRedisConnection } from "./job-base.js";
3
3
  import { JobQueue } from "./job-queue.js";
4
4
  import { JobWorker, type JobWorkerOptions } from "./job-worker.js";
5
5
  export * from "./types.js";
6
6
  import type { RedisConfig } from "./types.js";
7
7
  declare function redisCheck(config: RedisConfig): Promise<void>;
8
- export { redisCheck, JobQueue, JobWorker, type JobWorkerOptions, CredentialsStore, CredentialsMismatchError, CredentialsNotShareableError, getRedisConnectionCount, resetSharedRedisConnection, resetSharedCredentialsRedisConnection, type CredentialsValidationOptions, type CredentialsStoreInterface, };
8
+ export { CredentialsMismatchError, CredentialsNotShareableError, CredentialsStore, type CredentialsStoreInterface, type CredentialsStoreOptions, type CredentialsValidationOptions, createCredentialsRedisConnection, createIdempotencyRedisConnection, createRateLimitRedisConnection, getRedisConnectionCount, JobQueue, purgeCredentialsStoreKeys, purgeCredentialsStores, JobWorker, type JobWorkerOptions, redisCheck, resetSharedCredentialsRedisConnection, resetSharedIdempotencyRedisConnection, resetSharedRateLimitRedisConnection, resetSharedRedisConnection, };