@workglow/storage 0.0.103 → 0.0.104

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.
package/dist/common.d.ts CHANGED
@@ -21,4 +21,5 @@ export * from "./util/HybridSubscriptionManager";
21
21
  export * from "./util/PollingSubscriptionManager";
22
22
  export * from "./vector/InMemoryVectorStorage";
23
23
  export * from "./vector/IVectorStorage";
24
+ export * from "./credentials/EncryptedKvCredentialStore";
24
25
  //# sourceMappingURL=common.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qCAAqC,CAAC;AACpD,cAAc,kCAAkC,CAAC;AACjD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kCAAkC,CAAC;AAEjD,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,0BAA0B,CAAC;AAEzC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uBAAuB,CAAC;AAEtC,cAAc,4CAA4C,CAAC;AAC3D,cAAc,qCAAqC,CAAC;AAEpD,cAAc,kCAAkC,CAAC;AACjD,cAAc,mCAAmC,CAAC;AAElD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,yBAAyB,CAAC"}
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qCAAqC,CAAC;AACpD,cAAc,kCAAkC,CAAC;AACjD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kCAAkC,CAAC;AAEjD,cAAc,iBAAiB,CAAC;AAChC,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,0BAA0B,CAAC;AAEzC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uBAAuB,CAAC;AAEtC,cAAc,4CAA4C,CAAC;AAC3D,cAAc,qCAAqC,CAAC;AAEpD,cAAc,kCAAkC,CAAC;AACjD,cAAc,mCAAmC,CAAC;AAElD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,yBAAyB,CAAC;AAExC,cAAc,0CAA0C,CAAC"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Steven Roussey <sroussey@gmail.com>
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+ import type { CredentialPutOptions, ICredentialStore } from "@workglow/util";
7
+ import type { IKvStorage } from "../kv/IKvStorage";
8
+ /**
9
+ * Serialized form of a credential stored in the KV backend
10
+ */
11
+ interface StoredCredential {
12
+ readonly encrypted: string;
13
+ readonly iv: string;
14
+ readonly label: string | undefined;
15
+ readonly provider: string | undefined;
16
+ readonly createdAt: string;
17
+ readonly updatedAt: string;
18
+ readonly expiresAt: string | undefined;
19
+ }
20
+ /**
21
+ * Credential store that encrypts values with AES-256-GCM before persisting
22
+ * them to an {@link IKvStorage} backend.
23
+ *
24
+ * Works with any KV backend (SQLite, PostgreSQL, IndexedDB, in-memory, etc.).
25
+ * Uses the Web Crypto API (available in Node 20+, Bun, and browsers).
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * import { SqliteKvStorage } from "@workglow/storage";
30
+ *
31
+ * const kv = new SqliteKvStorage(":memory:");
32
+ * const store = new EncryptedKvCredentialStore(kv, "my-encryption-key");
33
+ *
34
+ * await store.put("openai-api-key", "sk-...", { provider: "openai" });
35
+ * const key = await store.get("openai-api-key"); // "sk-..."
36
+ * ```
37
+ */
38
+ export declare class EncryptedKvCredentialStore implements ICredentialStore {
39
+ private readonly kv;
40
+ private readonly passphrase;
41
+ /** Per-instance cache of derived CryptoKey instances keyed by base64(salt). */
42
+ private readonly keyCache;
43
+ constructor(kv: IKvStorage<string, StoredCredential>, passphrase: string);
44
+ get(key: string): Promise<string | undefined>;
45
+ put(key: string, value: string, options?: CredentialPutOptions): Promise<void>;
46
+ delete(key: string): Promise<boolean>;
47
+ has(key: string): Promise<boolean>;
48
+ keys(): Promise<readonly string[]>;
49
+ deleteAll(): Promise<void>;
50
+ }
51
+ export {};
52
+ //# sourceMappingURL=EncryptedKvCredentialStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EncryptedKvCredentialStore.d.ts","sourceRoot":"","sources":["../../src/credentials/EncryptedKvCredentialStore.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,oBAAoB,EACpB,gBAAgB,EACjB,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD;;GAEG;AACH,UAAU,gBAAgB;IACxB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IACtC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;CACxC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,0BAA2B,YAAW,gBAAgB;IAK/D,OAAO,CAAC,QAAQ,CAAC,EAAE;IACnB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAL7B,+EAA+E;IAC/E,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAgC;gBAGtC,EAAE,EAAE,UAAU,CAAC,MAAM,EAAE,gBAAgB,CAAC,EACxC,UAAU,EAAE,MAAM;IAO/B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAY7C,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;IAmB9E,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAQrC,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAWlC,IAAI,IAAI,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC;IAgBlC,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;CAGjC"}
package/dist/node.js CHANGED
@@ -1694,6 +1694,81 @@ class InMemoryVectorStorage extends InMemoryTabularStorage {
1694
1694
  return topResults;
1695
1695
  }
1696
1696
  }
1697
+ // src/credentials/EncryptedKvCredentialStore.ts
1698
+ import { decrypt, encrypt } from "@workglow/util";
1699
+
1700
+ class EncryptedKvCredentialStore {
1701
+ kv;
1702
+ passphrase;
1703
+ keyCache = new Map;
1704
+ constructor(kv, passphrase) {
1705
+ this.kv = kv;
1706
+ this.passphrase = passphrase;
1707
+ if (!passphrase) {
1708
+ throw new Error("EncryptedKvCredentialStore requires a non-empty passphrase.");
1709
+ }
1710
+ }
1711
+ async get(key) {
1712
+ const raw = await this.kv.get(key);
1713
+ if (!raw)
1714
+ return;
1715
+ if (raw.expiresAt && new Date(raw.expiresAt) <= new Date) {
1716
+ await this.kv.delete(key);
1717
+ return;
1718
+ }
1719
+ return decrypt(raw.encrypted, raw.iv, this.passphrase, this.keyCache);
1720
+ }
1721
+ async put(key, value, options) {
1722
+ const now = new Date;
1723
+ const existing = await this.kv.get(key);
1724
+ const { encrypted, iv } = await encrypt(value, this.passphrase, this.keyCache);
1725
+ const stored = {
1726
+ encrypted,
1727
+ iv,
1728
+ label: options?.label ?? existing?.label,
1729
+ provider: options?.provider ?? existing?.provider,
1730
+ createdAt: existing?.createdAt ?? now.toISOString(),
1731
+ updatedAt: now.toISOString(),
1732
+ expiresAt: options?.expiresAt ? options.expiresAt.toISOString() : existing?.expiresAt
1733
+ };
1734
+ await this.kv.put(key, stored);
1735
+ }
1736
+ async delete(key) {
1737
+ const exists = await this.kv.get(key) !== undefined;
1738
+ if (exists) {
1739
+ await this.kv.delete(key);
1740
+ }
1741
+ return exists;
1742
+ }
1743
+ async has(key) {
1744
+ const raw = await this.kv.get(key);
1745
+ if (!raw)
1746
+ return false;
1747
+ if (raw.expiresAt && new Date(raw.expiresAt) <= new Date) {
1748
+ await this.kv.delete(key);
1749
+ return false;
1750
+ }
1751
+ return true;
1752
+ }
1753
+ async keys() {
1754
+ const all = await this.kv.getAll();
1755
+ if (!all)
1756
+ return [];
1757
+ const now = new Date;
1758
+ const result = [];
1759
+ for (const entry of all) {
1760
+ if (entry.value.expiresAt && new Date(entry.value.expiresAt) <= now) {
1761
+ await this.kv.delete(entry.key);
1762
+ continue;
1763
+ }
1764
+ result.push(entry.key);
1765
+ }
1766
+ return result;
1767
+ }
1768
+ async deleteAll() {
1769
+ await this.kv.deleteAll();
1770
+ }
1771
+ }
1697
1772
  // src/tabular/FsFolderTabularStorage.ts
1698
1773
  import {
1699
1774
  createServiceToken as createServiceToken12,
@@ -7278,6 +7353,7 @@ export {
7278
7353
  FS_FOLDER_TABULAR_REPOSITORY,
7279
7354
  FS_FOLDER_KV_REPOSITORY,
7280
7355
  FS_FOLDER_JSON_KV_REPOSITORY,
7356
+ EncryptedKvCredentialStore,
7281
7357
  DefaultKeyValueSchema,
7282
7358
  DefaultKeyValueKey,
7283
7359
  CachedTabularStorage,
@@ -7285,4 +7361,4 @@ export {
7285
7361
  BaseTabularStorage
7286
7362
  };
7287
7363
 
7288
- //# debugId=24D8B8B9BAD9862964756E2164756E21
7364
+ //# debugId=2D59BEA4EF2DA70564756E2164756E21