@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/bun.js CHANGED
@@ -1695,6 +1695,81 @@ class InMemoryVectorStorage extends InMemoryTabularStorage {
1695
1695
  return topResults;
1696
1696
  }
1697
1697
  }
1698
+ // src/credentials/EncryptedKvCredentialStore.ts
1699
+ import { decrypt, encrypt } from "@workglow/util";
1700
+
1701
+ class EncryptedKvCredentialStore {
1702
+ kv;
1703
+ passphrase;
1704
+ keyCache = new Map;
1705
+ constructor(kv, passphrase) {
1706
+ this.kv = kv;
1707
+ this.passphrase = passphrase;
1708
+ if (!passphrase) {
1709
+ throw new Error("EncryptedKvCredentialStore requires a non-empty passphrase.");
1710
+ }
1711
+ }
1712
+ async get(key) {
1713
+ const raw = await this.kv.get(key);
1714
+ if (!raw)
1715
+ return;
1716
+ if (raw.expiresAt && new Date(raw.expiresAt) <= new Date) {
1717
+ await this.kv.delete(key);
1718
+ return;
1719
+ }
1720
+ return decrypt(raw.encrypted, raw.iv, this.passphrase, this.keyCache);
1721
+ }
1722
+ async put(key, value, options) {
1723
+ const now = new Date;
1724
+ const existing = await this.kv.get(key);
1725
+ const { encrypted, iv } = await encrypt(value, this.passphrase, this.keyCache);
1726
+ const stored = {
1727
+ encrypted,
1728
+ iv,
1729
+ label: options?.label ?? existing?.label,
1730
+ provider: options?.provider ?? existing?.provider,
1731
+ createdAt: existing?.createdAt ?? now.toISOString(),
1732
+ updatedAt: now.toISOString(),
1733
+ expiresAt: options?.expiresAt ? options.expiresAt.toISOString() : existing?.expiresAt
1734
+ };
1735
+ await this.kv.put(key, stored);
1736
+ }
1737
+ async delete(key) {
1738
+ const exists = await this.kv.get(key) !== undefined;
1739
+ if (exists) {
1740
+ await this.kv.delete(key);
1741
+ }
1742
+ return exists;
1743
+ }
1744
+ async has(key) {
1745
+ const raw = await this.kv.get(key);
1746
+ if (!raw)
1747
+ return false;
1748
+ if (raw.expiresAt && new Date(raw.expiresAt) <= new Date) {
1749
+ await this.kv.delete(key);
1750
+ return false;
1751
+ }
1752
+ return true;
1753
+ }
1754
+ async keys() {
1755
+ const all = await this.kv.getAll();
1756
+ if (!all)
1757
+ return [];
1758
+ const now = new Date;
1759
+ const result = [];
1760
+ for (const entry of all) {
1761
+ if (entry.value.expiresAt && new Date(entry.value.expiresAt) <= now) {
1762
+ await this.kv.delete(entry.key);
1763
+ continue;
1764
+ }
1765
+ result.push(entry.key);
1766
+ }
1767
+ return result;
1768
+ }
1769
+ async deleteAll() {
1770
+ await this.kv.deleteAll();
1771
+ }
1772
+ }
1698
1773
  // src/tabular/FsFolderTabularStorage.ts
1699
1774
  import {
1700
1775
  createServiceToken as createServiceToken12,
@@ -7279,6 +7354,7 @@ export {
7279
7354
  FS_FOLDER_TABULAR_REPOSITORY,
7280
7355
  FS_FOLDER_KV_REPOSITORY,
7281
7356
  FS_FOLDER_JSON_KV_REPOSITORY,
7357
+ EncryptedKvCredentialStore,
7282
7358
  DefaultKeyValueSchema,
7283
7359
  DefaultKeyValueKey,
7284
7360
  CachedTabularStorage,
@@ -7286,4 +7362,4 @@ export {
7286
7362
  BaseTabularStorage
7287
7363
  };
7288
7364
 
7289
- //# debugId=DB5310BD3588935D64756E2164756E21
7365
+ //# debugId=9D4931947389417A64756E2164756E21