@inkeep/agents-core 0.0.0-dev-20250910233133
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/LICENSE.md +56 -0
- package/README.md +464 -0
- package/dist/__tests__/integration/helpers.d.ts +5 -0
- package/dist/__tests__/integration/helpers.d.ts.map +1 -0
- package/dist/__tests__/integration/helpers.js +37 -0
- package/dist/__tests__/integration/helpers.js.map +1 -0
- package/dist/__tests__/setup.d.ts +3 -0
- package/dist/__tests__/setup.d.ts.map +1 -0
- package/dist/__tests__/setup.js +29 -0
- package/dist/__tests__/setup.js.map +1 -0
- package/dist/client-exports.d.ts +299 -0
- package/dist/client-exports.d.ts.map +1 -0
- package/dist/client-exports.js +252 -0
- package/dist/client-exports.js.map +1 -0
- package/dist/context/ContextConfig.d.ts +54 -0
- package/dist/context/ContextConfig.d.ts.map +1 -0
- package/dist/context/ContextConfig.js +302 -0
- package/dist/context/ContextConfig.js.map +1 -0
- package/dist/context/ContextFetcher.d.ts +64 -0
- package/dist/context/ContextFetcher.d.ts.map +1 -0
- package/dist/context/ContextFetcher.js +325 -0
- package/dist/context/ContextFetcher.js.map +1 -0
- package/dist/context/ContextResolver.d.ts +52 -0
- package/dist/context/ContextResolver.d.ts.map +1 -0
- package/dist/context/ContextResolver.js +298 -0
- package/dist/context/ContextResolver.js.map +1 -0
- package/dist/context/TemplateEngine.d.ts +46 -0
- package/dist/context/TemplateEngine.d.ts.map +1 -0
- package/dist/context/TemplateEngine.js +175 -0
- package/dist/context/TemplateEngine.js.map +1 -0
- package/dist/context/context.d.ts +8 -0
- package/dist/context/context.d.ts.map +1 -0
- package/dist/context/context.js +157 -0
- package/dist/context/context.js.map +1 -0
- package/dist/context/contextCache.d.ts +50 -0
- package/dist/context/contextCache.d.ts.map +1 -0
- package/dist/context/contextCache.js +175 -0
- package/dist/context/contextCache.js.map +1 -0
- package/dist/context/index.d.ts +11 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/index.js +8 -0
- package/dist/context/index.js.map +1 -0
- package/dist/credential-stores/CredentialStoreRegistry.d.ts +39 -0
- package/dist/credential-stores/CredentialStoreRegistry.d.ts.map +1 -0
- package/dist/credential-stores/CredentialStoreRegistry.js +65 -0
- package/dist/credential-stores/CredentialStoreRegistry.js.map +1 -0
- package/dist/credential-stores/defaults.d.ts +6 -0
- package/dist/credential-stores/defaults.d.ts.map +1 -0
- package/dist/credential-stores/defaults.js +22 -0
- package/dist/credential-stores/defaults.js.map +1 -0
- package/dist/credential-stores/index.d.ts +6 -0
- package/dist/credential-stores/index.d.ts.map +1 -0
- package/dist/credential-stores/index.js +6 -0
- package/dist/credential-stores/index.js.map +1 -0
- package/dist/credential-stores/keychain-store.d.ts +100 -0
- package/dist/credential-stores/keychain-store.d.ts.map +1 -0
- package/dist/credential-stores/keychain-store.js +225 -0
- package/dist/credential-stores/keychain-store.js.map +1 -0
- package/dist/credential-stores/memory-store.d.ts +39 -0
- package/dist/credential-stores/memory-store.d.ts.map +1 -0
- package/dist/credential-stores/memory-store.js +58 -0
- package/dist/credential-stores/memory-store.js.map +1 -0
- package/dist/credential-stores/nango-store.d.ts +59 -0
- package/dist/credential-stores/nango-store.d.ts.map +1 -0
- package/dist/credential-stores/nango-store.js +264 -0
- package/dist/credential-stores/nango-store.js.map +1 -0
- package/dist/credential-stuffer/CredentialStuffer.d.ts +80 -0
- package/dist/credential-stuffer/CredentialStuffer.d.ts.map +1 -0
- package/dist/credential-stuffer/CredentialStuffer.js +186 -0
- package/dist/credential-stuffer/CredentialStuffer.js.map +1 -0
- package/dist/credential-stuffer/index.d.ts +2 -0
- package/dist/credential-stuffer/index.d.ts.map +1 -0
- package/dist/credential-stuffer/index.js +2 -0
- package/dist/credential-stuffer/index.js.map +1 -0
- package/dist/data-access/agentDataComponents.d.ts +1 -0
- package/dist/data-access/agentDataComponents.d.ts.map +1 -0
- package/dist/data-access/agentDataComponents.js +2 -0
- package/dist/data-access/agentDataComponents.js.map +1 -0
- package/dist/data-access/agentGraphs.d.ts +399 -0
- package/dist/data-access/agentGraphs.d.ts.map +1 -0
- package/dist/data-access/agentGraphs.js +551 -0
- package/dist/data-access/agentGraphs.js.map +1 -0
- package/dist/data-access/agentRelations.d.ts +456 -0
- package/dist/data-access/agentRelations.d.ts.map +1 -0
- package/dist/data-access/agentRelations.js +471 -0
- package/dist/data-access/agentRelations.js.map +1 -0
- package/dist/data-access/agents.d.ts +218 -0
- package/dist/data-access/agents.d.ts.map +1 -0
- package/dist/data-access/agents.js +130 -0
- package/dist/data-access/agents.js.map +1 -0
- package/dist/data-access/apiKeys.d.ts +114 -0
- package/dist/data-access/apiKeys.d.ts.map +1 -0
- package/dist/data-access/apiKeys.js +185 -0
- package/dist/data-access/apiKeys.js.map +1 -0
- package/dist/data-access/artifactComponents.d.ts +152 -0
- package/dist/data-access/artifactComponents.d.ts.map +1 -0
- package/dist/data-access/artifactComponents.js +214 -0
- package/dist/data-access/artifactComponents.js.map +1 -0
- package/dist/data-access/contextCache.d.ts +68 -0
- package/dist/data-access/contextCache.d.ts.map +1 -0
- package/dist/data-access/contextCache.js +135 -0
- package/dist/data-access/contextCache.js.map +1 -0
- package/dist/data-access/contextConfigs.d.ts +110 -0
- package/dist/data-access/contextConfigs.d.ts.map +1 -0
- package/dist/data-access/contextConfigs.js +156 -0
- package/dist/data-access/contextConfigs.js.map +1 -0
- package/dist/data-access/conversations.d.ts +125 -0
- package/dist/data-access/conversations.d.ts.map +1 -0
- package/dist/data-access/conversations.js +244 -0
- package/dist/data-access/conversations.js.map +1 -0
- package/dist/data-access/credentialReferences.d.ts +86 -0
- package/dist/data-access/credentialReferences.d.ts.map +1 -0
- package/dist/data-access/credentialReferences.js +175 -0
- package/dist/data-access/credentialReferences.js.map +1 -0
- package/dist/data-access/dataComponents.d.ts +129 -0
- package/dist/data-access/dataComponents.d.ts.map +1 -0
- package/dist/data-access/dataComponents.js +213 -0
- package/dist/data-access/dataComponents.js.map +1 -0
- package/dist/data-access/externalAgents.d.ts +83 -0
- package/dist/data-access/externalAgents.d.ts.map +1 -0
- package/dist/data-access/externalAgents.js +163 -0
- package/dist/data-access/externalAgents.js.map +1 -0
- package/dist/data-access/graphFull.d.ts +32 -0
- package/dist/data-access/graphFull.d.ts.map +1 -0
- package/dist/data-access/graphFull.js +996 -0
- package/dist/data-access/graphFull.js.map +1 -0
- package/dist/data-access/index.d.ts +21 -0
- package/dist/data-access/index.d.ts.map +1 -0
- package/dist/data-access/index.js +22 -0
- package/dist/data-access/index.js.map +1 -0
- package/dist/data-access/ledgerArtifacts.d.ts +49 -0
- package/dist/data-access/ledgerArtifacts.d.ts.map +1 -0
- package/dist/data-access/ledgerArtifacts.js +112 -0
- package/dist/data-access/ledgerArtifacts.js.map +1 -0
- package/dist/data-access/messages.d.ts +209 -0
- package/dist/data-access/messages.d.ts.map +1 -0
- package/dist/data-access/messages.js +100 -0
- package/dist/data-access/messages.js.map +1 -0
- package/dist/data-access/projects.d.ts +67 -0
- package/dist/data-access/projects.d.ts.map +1 -0
- package/dist/data-access/projects.js +337 -0
- package/dist/data-access/projects.js.map +1 -0
- package/dist/data-access/tasks.d.ts +37 -0
- package/dist/data-access/tasks.d.ts.map +1 -0
- package/dist/data-access/tasks.js +40 -0
- package/dist/data-access/tasks.js.map +1 -0
- package/dist/data-access/tools.d.ts +277 -0
- package/dist/data-access/tools.d.ts.map +1 -0
- package/dist/data-access/tools.js +183 -0
- package/dist/data-access/tools.js.map +1 -0
- package/dist/data-access/validation.d.ts +17 -0
- package/dist/data-access/validation.d.ts.map +1 -0
- package/dist/data-access/validation.js +52 -0
- package/dist/data-access/validation.js.map +1 -0
- package/dist/db/clean.d.ts +6 -0
- package/dist/db/clean.d.ts.map +1 -0
- package/dist/db/clean.js +81 -0
- package/dist/db/clean.js.map +1 -0
- package/dist/db/client.d.ts +19 -0
- package/dist/db/client.d.ts.map +1 -0
- package/dist/db/client.js +24 -0
- package/dist/db/client.js.map +1 -0
- package/dist/db/schema.d.ts +4335 -0
- package/dist/db/schema.d.ts.map +1 -0
- package/dist/db/schema.js +696 -0
- package/dist/db/schema.js.map +1 -0
- package/dist/db/test-client.d.ts +25 -0
- package/dist/db/test-client.d.ts.map +1 -0
- package/dist/db/test-client.js +136 -0
- package/dist/db/test-client.js.map +1 -0
- package/dist/env.d.ts +19 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +49 -0
- package/dist/env.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware/contextValidation.d.ts +49 -0
- package/dist/middleware/contextValidation.d.ts.map +1 -0
- package/dist/middleware/contextValidation.js +473 -0
- package/dist/middleware/contextValidation.js.map +1 -0
- package/dist/middleware/index.d.ts +2 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/index.js +2 -0
- package/dist/middleware/index.js.map +1 -0
- package/dist/types/a2a.d.ts +373 -0
- package/dist/types/a2a.d.ts.map +1 -0
- package/dist/types/a2a.js +14 -0
- package/dist/types/a2a.js.map +1 -0
- package/dist/types/entities.d.ts +147 -0
- package/dist/types/entities.d.ts.map +1 -0
- package/dist/types/entities.js +2 -0
- package/dist/types/entities.js.map +1 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +6 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/server.d.ts +116 -0
- package/dist/types/server.d.ts.map +1 -0
- package/dist/types/server.js +2 -0
- package/dist/types/server.js.map +1 -0
- package/dist/types/utility.d.ts +213 -0
- package/dist/types/utility.d.ts.map +1 -0
- package/dist/types/utility.js +9 -0
- package/dist/types/utility.js.map +1 -0
- package/dist/utils/apiKeys.d.ts +32 -0
- package/dist/utils/apiKeys.d.ts.map +1 -0
- package/dist/utils/apiKeys.js +117 -0
- package/dist/utils/apiKeys.js.map +1 -0
- package/dist/utils/auth-detection.d.ts +23 -0
- package/dist/utils/auth-detection.d.ts.map +1 -0
- package/dist/utils/auth-detection.js +148 -0
- package/dist/utils/auth-detection.js.map +1 -0
- package/dist/utils/credential-store-utils.d.ts +11 -0
- package/dist/utils/credential-store-utils.d.ts.map +1 -0
- package/dist/utils/credential-store-utils.js +19 -0
- package/dist/utils/credential-store-utils.js.map +1 -0
- package/dist/utils/error.d.ts +526 -0
- package/dist/utils/error.d.ts.map +1 -0
- package/dist/utils/error.js +282 -0
- package/dist/utils/error.js.map +1 -0
- package/dist/utils/execution.d.ts +18 -0
- package/dist/utils/execution.d.ts.map +1 -0
- package/dist/utils/execution.js +25 -0
- package/dist/utils/execution.js.map +1 -0
- package/dist/utils/index.d.ts +9 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +9 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/logger.d.ts +79 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +102 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/logging.d.ts +11 -0
- package/dist/utils/logging.d.ts.map +1 -0
- package/dist/utils/logging.js +6 -0
- package/dist/utils/logging.js.map +1 -0
- package/dist/utils/mcp-client.d.ts +48 -0
- package/dist/utils/mcp-client.d.ts.map +1 -0
- package/dist/utils/mcp-client.js +174 -0
- package/dist/utils/mcp-client.js.map +1 -0
- package/dist/utils/tracer.d.ts +24 -0
- package/dist/utils/tracer.d.ts.map +1 -0
- package/dist/utils/tracer.js +110 -0
- package/dist/utils/tracer.js.map +1 -0
- package/dist/validation/graphFull.d.ts +36 -0
- package/dist/validation/graphFull.d.ts.map +1 -0
- package/dist/validation/graphFull.js +128 -0
- package/dist/validation/graphFull.js.map +1 -0
- package/dist/validation/id-validation.d.ts +38 -0
- package/dist/validation/id-validation.d.ts.map +1 -0
- package/dist/validation/id-validation.js +60 -0
- package/dist/validation/id-validation.js.map +1 -0
- package/dist/validation/index.d.ts +4 -0
- package/dist/validation/index.d.ts.map +1 -0
- package/dist/validation/index.js +5 -0
- package/dist/validation/index.js.map +1 -0
- package/dist/validation/schemas.d.ts +7213 -0
- package/dist/validation/schemas.d.ts.map +1 -0
- package/dist/validation/schemas.js +576 -0
- package/dist/validation/schemas.js.map +1 -0
- package/package.json +95 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { CredentialStore } from '../types/server';
|
|
2
|
+
/**
|
|
3
|
+
* KeyChainStore - Cross-platform system keychain credential storage
|
|
4
|
+
*
|
|
5
|
+
* Uses the native OS credential storage:
|
|
6
|
+
* - macOS: Keychain
|
|
7
|
+
* - Windows: Credential Vault
|
|
8
|
+
* - Linux: Secret Service API/libsecret
|
|
9
|
+
*
|
|
10
|
+
* Requires the 'keytar' npm package to be installed.
|
|
11
|
+
* Falls back gracefully if keytar is not available.
|
|
12
|
+
*
|
|
13
|
+
* ## macOS Permission Handling
|
|
14
|
+
*
|
|
15
|
+
* On macOS, when your Node.js app first calls keytar operations:
|
|
16
|
+
* - `setPassword()` creates a new Keychain item (no prompt required)
|
|
17
|
+
* - `getPassword()` may prompt the user for permission on first access
|
|
18
|
+
* - Users can click "Allow", "Always Allow", or "Deny"
|
|
19
|
+
* - If denied, keytar returns `null` which this implementation handles gracefully
|
|
20
|
+
* - The calling binary (usually `node`) will be shown in the permission prompt
|
|
21
|
+
* - For better UX in packaged apps, consider code signing and app bundling
|
|
22
|
+
*
|
|
23
|
+
* This implementation handles all permission scenarios gracefully:
|
|
24
|
+
* - Returns `null` when access is denied or credentials don't exist
|
|
25
|
+
* - Logs errors for debugging permission issues
|
|
26
|
+
* - Never throws on permission denial, only on system-level errors
|
|
27
|
+
*/
|
|
28
|
+
export declare class KeyChainStore implements CredentialStore {
|
|
29
|
+
readonly id: string;
|
|
30
|
+
readonly type = "keychain";
|
|
31
|
+
private readonly service;
|
|
32
|
+
private readonly logger;
|
|
33
|
+
private keytarAvailable;
|
|
34
|
+
private keytar;
|
|
35
|
+
private initializationPromise;
|
|
36
|
+
constructor(id: string, servicePrefix?: string);
|
|
37
|
+
/**
|
|
38
|
+
* Initialize keytar dynamically to handle optional availability
|
|
39
|
+
*/
|
|
40
|
+
private initializeKeytar;
|
|
41
|
+
/**
|
|
42
|
+
* Get a credential from the keychain
|
|
43
|
+
*/
|
|
44
|
+
get(key: string): Promise<string | null>;
|
|
45
|
+
/**
|
|
46
|
+
* Set a credential in the keychain
|
|
47
|
+
*/
|
|
48
|
+
set(key: string, value: string): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Check if a credential exists in the keychain
|
|
51
|
+
*/
|
|
52
|
+
has(key: string): Promise<boolean>;
|
|
53
|
+
/**
|
|
54
|
+
* Delete a credential from the keychain
|
|
55
|
+
*/
|
|
56
|
+
delete(key: string): Promise<boolean>;
|
|
57
|
+
/**
|
|
58
|
+
* Find all credentials for this service
|
|
59
|
+
* Useful for debugging and listing stored credentials
|
|
60
|
+
*/
|
|
61
|
+
findAllCredentials(): Promise<Array<{
|
|
62
|
+
account: string;
|
|
63
|
+
password: string;
|
|
64
|
+
}>>;
|
|
65
|
+
/**
|
|
66
|
+
* Clear all credentials for this service
|
|
67
|
+
* WARNING: This will delete all credentials stored under this service
|
|
68
|
+
*/
|
|
69
|
+
clearAll(): Promise<number>;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Factory function to create KeyChainStore
|
|
73
|
+
* Provides consistent initialization and optional configuration
|
|
74
|
+
*
|
|
75
|
+
* ## Usage Recommendations for macOS Permission Handling
|
|
76
|
+
*
|
|
77
|
+
* 1. **First-time setup**: Inform users that they may see permission prompts
|
|
78
|
+
* 2. **Error handling**: Check for `null` returns from `get()` operations
|
|
79
|
+
* 3. **User guidance**: If credentials can't be retrieved, guide users to:
|
|
80
|
+
* - Check Keychain Access app for denied permissions
|
|
81
|
+
* - Re-run the application if they accidentally clicked "Deny"
|
|
82
|
+
* 4. **Development**: Use a consistent `servicePrefix` to avoid permission prompt spam
|
|
83
|
+
* 5. **Production**: Consider code-signing your distributed app for better permission prompts
|
|
84
|
+
*
|
|
85
|
+
* Example usage with permission handling:
|
|
86
|
+
* ```typescript
|
|
87
|
+
* const store = createKeyChainStore('my-app');
|
|
88
|
+
*
|
|
89
|
+
* // Always check for null when retrieving
|
|
90
|
+
* const apiKey = await store.get('api-key');
|
|
91
|
+
* if (!apiKey) {
|
|
92
|
+
* console.log('API key not found or access denied');
|
|
93
|
+
* // Guide user to check permissions or re-enter credentials
|
|
94
|
+
* }
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export declare function createKeyChainStore(id: string, options?: {
|
|
98
|
+
servicePrefix?: string;
|
|
99
|
+
}): KeyChainStore;
|
|
100
|
+
//# sourceMappingURL=keychain-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keychain-store.d.ts","sourceRoot":"","sources":["../../src/credential-stores/keychain-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGvD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBAAa,aAAc,YAAW,eAAe;IACnD,SAAgB,EAAE,EAAE,MAAM,CAAC;IAC3B,SAAgB,IAAI,cAAc;IAClC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA8B;IACrD,OAAO,CAAC,eAAe,CAAS;IAChC,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,qBAAqB,CAAgB;gBAEjC,EAAE,EAAE,MAAM,EAAE,aAAa,SAA2B;IAOhE;;OAEG;YACW,gBAAgB;IA4B9B;;OAEG;IACG,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAiC9C;;OAEG;IACG,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA+BpD;;OAEG;IACG,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAKxC;;OAEG;IACG,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAsC3C;;;OAGG;IACG,kBAAkB,IAAI,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAuBjF;;;OAGG;IACG,QAAQ,IAAI,OAAO,CAAC,MAAM,CAAC;CAwBlC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,mBAAmB,CACjC,EAAE,EAAE,MAAM,EACV,OAAO,CAAC,EAAE;IACR,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,GACA,aAAa,CAEf"}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { getLogger } from '../utils/logger';
|
|
2
|
+
/**
|
|
3
|
+
* KeyChainStore - Cross-platform system keychain credential storage
|
|
4
|
+
*
|
|
5
|
+
* Uses the native OS credential storage:
|
|
6
|
+
* - macOS: Keychain
|
|
7
|
+
* - Windows: Credential Vault
|
|
8
|
+
* - Linux: Secret Service API/libsecret
|
|
9
|
+
*
|
|
10
|
+
* Requires the 'keytar' npm package to be installed.
|
|
11
|
+
* Falls back gracefully if keytar is not available.
|
|
12
|
+
*
|
|
13
|
+
* ## macOS Permission Handling
|
|
14
|
+
*
|
|
15
|
+
* On macOS, when your Node.js app first calls keytar operations:
|
|
16
|
+
* - `setPassword()` creates a new Keychain item (no prompt required)
|
|
17
|
+
* - `getPassword()` may prompt the user for permission on first access
|
|
18
|
+
* - Users can click "Allow", "Always Allow", or "Deny"
|
|
19
|
+
* - If denied, keytar returns `null` which this implementation handles gracefully
|
|
20
|
+
* - The calling binary (usually `node`) will be shown in the permission prompt
|
|
21
|
+
* - For better UX in packaged apps, consider code signing and app bundling
|
|
22
|
+
*
|
|
23
|
+
* This implementation handles all permission scenarios gracefully:
|
|
24
|
+
* - Returns `null` when access is denied or credentials don't exist
|
|
25
|
+
* - Logs errors for debugging permission issues
|
|
26
|
+
* - Never throws on permission denial, only on system-level errors
|
|
27
|
+
*/
|
|
28
|
+
export class KeyChainStore {
|
|
29
|
+
id;
|
|
30
|
+
type = 'keychain';
|
|
31
|
+
service;
|
|
32
|
+
logger = getLogger('KeyChainStore');
|
|
33
|
+
keytarAvailable = false;
|
|
34
|
+
keytar = null;
|
|
35
|
+
initializationPromise;
|
|
36
|
+
constructor(id, servicePrefix = 'inkeep-agent-framework') {
|
|
37
|
+
this.id = id;
|
|
38
|
+
// Use service prefix to isolate credentials by store ID
|
|
39
|
+
this.service = `${servicePrefix}-${id}`;
|
|
40
|
+
this.initializationPromise = this.initializeKeytar();
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Initialize keytar dynamically to handle optional availability
|
|
44
|
+
*/
|
|
45
|
+
async initializeKeytar() {
|
|
46
|
+
if (this.keytar) {
|
|
47
|
+
this.keytarAvailable = true;
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
this.keytar = (await import('keytar')).default;
|
|
52
|
+
this.keytarAvailable = true;
|
|
53
|
+
this.logger.info({
|
|
54
|
+
storeId: this.id,
|
|
55
|
+
service: this.service,
|
|
56
|
+
}, 'Keytar initialized successfully');
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
this.logger.warn({
|
|
60
|
+
storeId: this.id,
|
|
61
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
62
|
+
}, 'Keytar not available - KeyChainStore will return null for all operations');
|
|
63
|
+
this.keytarAvailable = false;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Get a credential from the keychain
|
|
68
|
+
*/
|
|
69
|
+
async get(key) {
|
|
70
|
+
await this.initializationPromise;
|
|
71
|
+
if (!this.keytarAvailable || !this.keytar) {
|
|
72
|
+
this.logger.debug({ storeId: this.id, key }, 'Keytar not available, returning null');
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
const password = await this.keytar.getPassword(this.service, key);
|
|
77
|
+
if (password === null) {
|
|
78
|
+
this.logger.debug({ storeId: this.id, service: this.service, account: key }, 'No credential found in keychain');
|
|
79
|
+
}
|
|
80
|
+
return password;
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
this.logger.error({
|
|
84
|
+
storeId: this.id,
|
|
85
|
+
service: this.service,
|
|
86
|
+
account: key,
|
|
87
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
88
|
+
}, 'Error getting credential from keychain');
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Set a credential in the keychain
|
|
94
|
+
*/
|
|
95
|
+
async set(key, value) {
|
|
96
|
+
await this.initializationPromise;
|
|
97
|
+
if (!this.keytarAvailable || !this.keytar) {
|
|
98
|
+
this.logger.warn({ storeId: this.id, key }, 'Keytar not available, cannot set credential');
|
|
99
|
+
throw new Error('Keytar not available - cannot store credentials in system keychain');
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
await this.keytar.setPassword(this.service, key, value);
|
|
103
|
+
this.logger.debug({ storeId: this.id, service: this.service, account: key }, 'Credential stored in keychain');
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
this.logger.error({
|
|
107
|
+
storeId: this.id,
|
|
108
|
+
service: this.service,
|
|
109
|
+
account: key,
|
|
110
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
111
|
+
}, 'Error setting credential in keychain');
|
|
112
|
+
throw new Error(`Failed to store credential in keychain: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Check if a credential exists in the keychain
|
|
117
|
+
*/
|
|
118
|
+
async has(key) {
|
|
119
|
+
const credential = await this.get(key);
|
|
120
|
+
return credential !== null;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Delete a credential from the keychain
|
|
124
|
+
*/
|
|
125
|
+
async delete(key) {
|
|
126
|
+
await this.initializationPromise;
|
|
127
|
+
if (!this.keytarAvailable || !this.keytar) {
|
|
128
|
+
this.logger.warn({ storeId: this.id, key }, 'Keytar not available, cannot delete credential');
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
const result = await this.keytar.deletePassword(this.service, key);
|
|
133
|
+
if (result) {
|
|
134
|
+
this.logger.debug({ storeId: this.id, service: this.service, account: key }, 'Credential deleted from keychain');
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
this.logger.debug({ storeId: this.id, service: this.service, account: key }, 'Credential not found in keychain for deletion');
|
|
138
|
+
}
|
|
139
|
+
return result;
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
this.logger.error({
|
|
143
|
+
storeId: this.id,
|
|
144
|
+
service: this.service,
|
|
145
|
+
account: key,
|
|
146
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
147
|
+
}, 'Error deleting credential from keychain');
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Find all credentials for this service
|
|
153
|
+
* Useful for debugging and listing stored credentials
|
|
154
|
+
*/
|
|
155
|
+
async findAllCredentials() {
|
|
156
|
+
await this.initializationPromise;
|
|
157
|
+
if (!this.keytarAvailable || !this.keytar) {
|
|
158
|
+
return [];
|
|
159
|
+
}
|
|
160
|
+
try {
|
|
161
|
+
const credentials = await this.keytar.findCredentials(this.service);
|
|
162
|
+
return credentials || [];
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
this.logger.error({
|
|
166
|
+
storeId: this.id,
|
|
167
|
+
service: this.service,
|
|
168
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
169
|
+
}, 'Error finding credentials in keychain');
|
|
170
|
+
return [];
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Clear all credentials for this service
|
|
175
|
+
* WARNING: This will delete all credentials stored under this service
|
|
176
|
+
*/
|
|
177
|
+
async clearAll() {
|
|
178
|
+
const credentials = await this.findAllCredentials();
|
|
179
|
+
let deletedCount = 0;
|
|
180
|
+
for (const cred of credentials) {
|
|
181
|
+
const deleted = await this.delete(cred.account);
|
|
182
|
+
if (deleted) {
|
|
183
|
+
deletedCount++;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (deletedCount > 0) {
|
|
187
|
+
this.logger.info({
|
|
188
|
+
storeId: this.id,
|
|
189
|
+
service: this.service,
|
|
190
|
+
deletedCount,
|
|
191
|
+
}, 'Cleared all credentials from keychain');
|
|
192
|
+
}
|
|
193
|
+
return deletedCount;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Factory function to create KeyChainStore
|
|
198
|
+
* Provides consistent initialization and optional configuration
|
|
199
|
+
*
|
|
200
|
+
* ## Usage Recommendations for macOS Permission Handling
|
|
201
|
+
*
|
|
202
|
+
* 1. **First-time setup**: Inform users that they may see permission prompts
|
|
203
|
+
* 2. **Error handling**: Check for `null` returns from `get()` operations
|
|
204
|
+
* 3. **User guidance**: If credentials can't be retrieved, guide users to:
|
|
205
|
+
* - Check Keychain Access app for denied permissions
|
|
206
|
+
* - Re-run the application if they accidentally clicked "Deny"
|
|
207
|
+
* 4. **Development**: Use a consistent `servicePrefix` to avoid permission prompt spam
|
|
208
|
+
* 5. **Production**: Consider code-signing your distributed app for better permission prompts
|
|
209
|
+
*
|
|
210
|
+
* Example usage with permission handling:
|
|
211
|
+
* ```typescript
|
|
212
|
+
* const store = createKeyChainStore('my-app');
|
|
213
|
+
*
|
|
214
|
+
* // Always check for null when retrieving
|
|
215
|
+
* const apiKey = await store.get('api-key');
|
|
216
|
+
* if (!apiKey) {
|
|
217
|
+
* console.log('API key not found or access denied');
|
|
218
|
+
* // Guide user to check permissions or re-enter credentials
|
|
219
|
+
* }
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
222
|
+
export function createKeyChainStore(id, options) {
|
|
223
|
+
return new KeyChainStore(id, options?.servicePrefix);
|
|
224
|
+
}
|
|
225
|
+
//# sourceMappingURL=keychain-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keychain-store.js","sourceRoot":"","sources":["../../src/credential-stores/keychain-store.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,OAAO,aAAa;IACR,EAAE,CAAS;IACX,IAAI,GAAG,UAAU,CAAC;IACjB,OAAO,CAAS;IAChB,MAAM,GAAG,SAAS,CAAC,eAAe,CAAC,CAAC;IAC7C,eAAe,GAAG,KAAK,CAAC;IACxB,MAAM,GAAe,IAAI,CAAC;IAC1B,qBAAqB,CAAgB;IAE7C,YAAY,EAAU,EAAE,aAAa,GAAG,wBAAwB;QAC9D,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,wDAAwD;QACxD,IAAI,CAAC,OAAO,GAAG,GAAG,aAAa,IAAI,EAAE,EAAE,CAAC;QACxC,IAAI,CAAC,qBAAqB,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;IACvD,CAAC;IAED;;OAEG;IACK,KAAK,CAAC,gBAAgB;QAC5B,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;YAC5B,OAAO;QACT,CAAC;QAED,IAAI,CAAC;YACH,IAAI,CAAC,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,QAAe,CAAC,CAAC,CAAC,OAAO,CAAC;YACtD,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;YAC5B,IAAI,CAAC,MAAM,CAAC,IAAI,CACd;gBACE,OAAO,EAAE,IAAI,CAAC,EA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;gBACZ,YAAY,EAAE,CAAC;YACjB,CAAC;QACH,CAAC;QAED,IAAI,YAAY,GAAG,CAAC,EAAE,CAAC;YACrB,IAAI,CAAC,MAAM,CAAC,IAAI,CACd;gBACE,OAAO,EAAE,IAAI,CAAC,EAAE;gBAChB,OAAO,EAAE,IAAI,CAAC,OAAO;gBACrB,YAAY;aACb,EACD,uCAAuC,CACxC,CAAC;QACJ,CAAC;QAED,OAAO,YAAY,CAAC;IACtB,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,mBAAmB,CACjC,EAAU,EACV,OAEC;IAED,OAAO,IAAI,aAAa,CAAC,EAAE,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC;AACvD,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { CredentialStore } from '../types/server';
|
|
2
|
+
/**
|
|
3
|
+
* In-memory credential store implementation
|
|
4
|
+
* Automatically loads environment variables prefixed with CREDENTIAL_STORE_ on initialization
|
|
5
|
+
* Note: Runtime credentials are lost when the server restarts, but env vars are reloaded
|
|
6
|
+
*/
|
|
7
|
+
export declare class InMemoryCredentialStore implements CredentialStore {
|
|
8
|
+
readonly id: string;
|
|
9
|
+
readonly type = "memory";
|
|
10
|
+
private credentials;
|
|
11
|
+
constructor(id?: string);
|
|
12
|
+
/**
|
|
13
|
+
* Get a credential from the in memory store.
|
|
14
|
+
* If the key is not found in the in memory store then it is loaded from environment variables.
|
|
15
|
+
* If the key is not found in the environment variables or in the in memory store then returns null.
|
|
16
|
+
* @param key - The key of the credential to get
|
|
17
|
+
* @returns The credential value or null if not found
|
|
18
|
+
*/
|
|
19
|
+
get(key: string): Promise<string | null>;
|
|
20
|
+
/**
|
|
21
|
+
* Set a credential in the in memory store.
|
|
22
|
+
* @param key - The key of the credential to set
|
|
23
|
+
* @param value - The value of the credential to set
|
|
24
|
+
*/
|
|
25
|
+
set(key: string, value: string): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Check if a credential exists in the in memory store.
|
|
28
|
+
* @param key - The key of the credential to check
|
|
29
|
+
* @returns True if the credential exists, false otherwise
|
|
30
|
+
*/
|
|
31
|
+
has(key: string): Promise<boolean>;
|
|
32
|
+
/**
|
|
33
|
+
* Delete a credential from the in memory store.
|
|
34
|
+
* @param key - The key of the credential to delete
|
|
35
|
+
* @returns True if the credential was deleted, false otherwise
|
|
36
|
+
*/
|
|
37
|
+
delete(key: string): Promise<boolean>;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=memory-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-store.d.ts","sourceRoot":"","sources":["../../src/credential-stores/memory-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEvD;;;;GAIG;AACH,qBAAa,uBAAwB,YAAW,eAAe;IAC7D,SAAgB,EAAE,EAAE,MAAM,CAAC;IAC3B,SAAgB,IAAI,YAAY;IAChC,OAAO,CAAC,WAAW,CAA6B;gBAEpC,EAAE,SAAmB;IAIjC;;;;;;OAMG;IACG,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAgB9C;;;;OAIG;IACG,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIpD;;;;OAIG;IACG,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIxC;;;;OAIG;IACG,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAG5C"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-memory credential store implementation
|
|
3
|
+
* Automatically loads environment variables prefixed with CREDENTIAL_STORE_ on initialization
|
|
4
|
+
* Note: Runtime credentials are lost when the server restarts, but env vars are reloaded
|
|
5
|
+
*/
|
|
6
|
+
export class InMemoryCredentialStore {
|
|
7
|
+
id;
|
|
8
|
+
type = 'memory';
|
|
9
|
+
credentials = new Map();
|
|
10
|
+
constructor(id = 'memory-default') {
|
|
11
|
+
this.id = id;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Get a credential from the in memory store.
|
|
15
|
+
* If the key is not found in the in memory store then it is loaded from environment variables.
|
|
16
|
+
* If the key is not found in the environment variables or in the in memory store then returns null.
|
|
17
|
+
* @param key - The key of the credential to get
|
|
18
|
+
* @returns The credential value or null if not found
|
|
19
|
+
*/
|
|
20
|
+
async get(key) {
|
|
21
|
+
const credential = this.credentials.get(key);
|
|
22
|
+
if (!credential) {
|
|
23
|
+
// Try loading from environment variables
|
|
24
|
+
const envValue = process.env[key];
|
|
25
|
+
if (envValue) {
|
|
26
|
+
this.credentials.set(key, envValue);
|
|
27
|
+
return envValue;
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
return credential;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Set a credential in the in memory store.
|
|
35
|
+
* @param key - The key of the credential to set
|
|
36
|
+
* @param value - The value of the credential to set
|
|
37
|
+
*/
|
|
38
|
+
async set(key, value) {
|
|
39
|
+
this.credentials.set(key, value);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Check if a credential exists in the in memory store.
|
|
43
|
+
* @param key - The key of the credential to check
|
|
44
|
+
* @returns True if the credential exists, false otherwise
|
|
45
|
+
*/
|
|
46
|
+
async has(key) {
|
|
47
|
+
return this.credentials.has(key);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Delete a credential from the in memory store.
|
|
51
|
+
* @param key - The key of the credential to delete
|
|
52
|
+
* @returns True if the credential was deleted, false otherwise
|
|
53
|
+
*/
|
|
54
|
+
async delete(key) {
|
|
55
|
+
return this.credentials.delete(key);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=memory-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-store.js","sourceRoot":"","sources":["../../src/credential-stores/memory-store.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,OAAO,uBAAuB;IAClB,EAAE,CAAS;IACX,IAAI,GAAG,QAAQ,CAAC;IACxB,WAAW,GAAG,IAAI,GAAG,EAAkB,CAAC;IAEhD,YAAY,EAAE,GAAG,gBAAgB;QAC/B,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;IACf,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,GAAG,CAAC,GAAW;QACnB,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAE7C,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,yCAAyC;YACzC,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAClC,IAAI,QAAQ,EAAE,CAAC;gBACb,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;gBACpC,OAAO,QAAQ,CAAC;YAClB,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;QAED,OAAO,UAAU,CAAC;IACpB,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,GAAG,CAAC,GAAW,EAAE,KAAa;QAClC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACnC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,GAAG,CAAC,GAAW;QACnB,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACnC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,MAAM,CAAC,GAAW;QACtB,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACtC,CAAC;CACF"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { CredentialStore } from '../types/server';
|
|
2
|
+
export interface NangoConfig {
|
|
3
|
+
secretKey: string;
|
|
4
|
+
apiUrl?: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Nango-specific credential data with additional properties
|
|
8
|
+
*/
|
|
9
|
+
export interface NangoCredentialData {
|
|
10
|
+
connectionId: string;
|
|
11
|
+
providerConfigKey: string;
|
|
12
|
+
secretKey: string;
|
|
13
|
+
provider: string;
|
|
14
|
+
token?: string;
|
|
15
|
+
metadata?: Record<string, any>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Nango-based CredentialStore that fetches OAuth credentials from Nango API
|
|
19
|
+
* Uses connectionId and providerConfigKey from metadata to fetch live credentials
|
|
20
|
+
*/
|
|
21
|
+
export declare class NangoCredentialStore implements CredentialStore {
|
|
22
|
+
readonly id: string;
|
|
23
|
+
readonly type = "nango";
|
|
24
|
+
private nangoConfig;
|
|
25
|
+
private nangoClient;
|
|
26
|
+
constructor(id: string, config: NangoConfig);
|
|
27
|
+
private getAccessToken;
|
|
28
|
+
private sanitizeMetadata;
|
|
29
|
+
/**
|
|
30
|
+
* Fetch credentials from Nango API using connection information
|
|
31
|
+
* @param connectionId - The connection ID for the Nango connection
|
|
32
|
+
* @param providerConfigKey - The provider config key for the Nango connection
|
|
33
|
+
* @returns The credential data or null if the credentials are not found
|
|
34
|
+
*/
|
|
35
|
+
private fetchCredentialsFromNango;
|
|
36
|
+
/**
|
|
37
|
+
* Get credentials by key - implements CredentialStore interface
|
|
38
|
+
* Key format: JSON string with connectionId and providerConfigKey
|
|
39
|
+
*/
|
|
40
|
+
get(key: string): Promise<string | null>;
|
|
41
|
+
/**
|
|
42
|
+
* Set credentials - not supported for Nango (OAuth flow handles this)
|
|
43
|
+
*/
|
|
44
|
+
set(_key: string, _value: string): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Check if credentials exist by attempting to fetch them
|
|
47
|
+
*/
|
|
48
|
+
has(key: string): Promise<boolean>;
|
|
49
|
+
/**
|
|
50
|
+
* Delete credentials - not supported for Nango (revoke through Nango dashboard)
|
|
51
|
+
*/
|
|
52
|
+
delete(key: string): Promise<boolean>;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Factory function to create NangoCredentialStore
|
|
56
|
+
* Automatically reads NANGO_SECRET_KEY from environment and validates it
|
|
57
|
+
*/
|
|
58
|
+
export declare function createNangoCredentialStore(id: string, config?: Partial<NangoConfig>): NangoCredentialStore;
|
|
59
|
+
//# sourceMappingURL=nango-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nango-store.d.ts","sourceRoot":"","sources":["../../src/credential-stores/nango-store.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAWvD,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,YAAY,EAAE,MAAM,CAAC;IACrB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAChC;AAqBD;;;GAGG;AACH,qBAAa,oBAAqB,YAAW,eAAe;IAC1D,SAAgB,EAAE,EAAE,MAAM,CAAC;IAC3B,SAAgB,IAAI,WAAW;IAC/B,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,WAAW,CAAQ;gBAEf,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW;IAS3C,OAAO,CAAC,cAAc;IAsDtB,OAAO,CAAC,gBAAgB;IAYxB;;;;;OAKG;YACW,yBAA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