@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/browser.js +77 -1
- package/dist/browser.js.map +4 -3
- package/dist/bun.js +77 -1
- package/dist/bun.js.map +4 -3
- package/dist/common.d.ts +1 -0
- package/dist/common.d.ts.map +1 -1
- package/dist/credentials/EncryptedKvCredentialStore.d.ts +52 -0
- package/dist/credentials/EncryptedKvCredentialStore.d.ts.map +1 -0
- package/dist/node.js +77 -1
- package/dist/node.js.map +4 -3
- package/package.json +7 -7
package/dist/browser.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/IndexedDbTabularStorage.ts
|
|
1698
1773
|
import {
|
|
1699
1774
|
createServiceToken as createServiceToken12,
|
|
@@ -4908,6 +4983,7 @@ export {
|
|
|
4908
4983
|
HybridSubscriptionManager,
|
|
4909
4984
|
HuggingFaceTabularStorage,
|
|
4910
4985
|
HF_TABULAR_REPOSITORY,
|
|
4986
|
+
EncryptedKvCredentialStore,
|
|
4911
4987
|
DefaultKeyValueSchema,
|
|
4912
4988
|
DefaultKeyValueKey,
|
|
4913
4989
|
CachedTabularStorage,
|
|
@@ -4915,4 +4991,4 @@ export {
|
|
|
4915
4991
|
BaseTabularStorage
|
|
4916
4992
|
};
|
|
4917
4993
|
|
|
4918
|
-
//# debugId=
|
|
4994
|
+
//# debugId=6C77B36216FE8BAE64756E2164756E21
|