learn-secrets-sdk 1.4.0 → 1.6.0
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/README.md +192 -72
- package/bin/learn-secrets.js +5 -2
- package/dist/chunk-AS6G7JYX.mjs +1 -0
- package/dist/cli/chunk-Y6FXYEAI.mjs +10 -0
- package/dist/cli/env-resolver-4ASC2IMR.mjs +66 -0
- package/dist/cli/{index.d.ts → index.d.mts} +0 -1
- package/dist/cli/index.mjs +1020 -0
- package/dist/env-resolver-Y4SFGOKB.mjs +1 -0
- package/dist/index.d.mts +432 -0
- package/dist/index.d.ts +432 -5
- package/dist/index.global.js +11 -0
- package/dist/index.mjs +11 -0
- package/package.json +12 -5
- package/dist/cli/commands/init.d.ts +0 -11
- package/dist/cli/commands/init.js +0 -113
- package/dist/cli/commands/login.d.ts +0 -7
- package/dist/cli/commands/login.js +0 -22
- package/dist/cli/index.js +0 -35
- package/dist/cli/utils/env-parser.d.ts +0 -19
- package/dist/cli/utils/env-parser.js +0 -47
- package/dist/cli/utils/key-detector.d.ts +0 -33
- package/dist/cli/utils/key-detector.js +0 -153
- package/dist/client.d.ts +0 -65
- package/dist/client.js +0 -172
- package/dist/credentials.d.ts +0 -24
- package/dist/credentials.js +0 -86
- package/dist/env-resolver.d.ts +0 -23
- package/dist/env-resolver.js +0 -73
- package/dist/index.js +0 -4
- package/dist/management.d.ts +0 -98
- package/dist/management.js +0 -214
- package/dist/types.d.ts +0 -123
- package/dist/types.js +0 -29
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a,b,c,d}from"./chunk-AS6G7JYX.mjs";export{d as loadSecretsConfig,b as resolveEnvInSecret,c as resolveEnvInSecrets,a as resolveEnvString};
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
interface SecretsSDKOptions {
|
|
2
|
+
/**
|
|
3
|
+
* App ID from dashboard (optional in zero-config mode)
|
|
4
|
+
* If omitted, SDK uses origin-based authentication
|
|
5
|
+
*/
|
|
6
|
+
appId?: string;
|
|
7
|
+
/**
|
|
8
|
+
* SDK token (optional in zero-config mode)
|
|
9
|
+
* If omitted, SDK uses origin-based authentication
|
|
10
|
+
*/
|
|
11
|
+
token?: string;
|
|
12
|
+
sessionToken?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Base URL of the proxy server
|
|
15
|
+
* Default: https://ctklearn.carsontkempf.workers.dev
|
|
16
|
+
*/
|
|
17
|
+
baseUrl?: string;
|
|
18
|
+
timeout?: number;
|
|
19
|
+
retryOn429?: boolean;
|
|
20
|
+
}
|
|
21
|
+
interface ProxyRequest {
|
|
22
|
+
keyName: string;
|
|
23
|
+
endpoint: string;
|
|
24
|
+
method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
25
|
+
body?: any;
|
|
26
|
+
headers?: Record<string, string>;
|
|
27
|
+
}
|
|
28
|
+
interface ProxyResponse<T = any> {
|
|
29
|
+
success: boolean;
|
|
30
|
+
status: number;
|
|
31
|
+
data: T;
|
|
32
|
+
}
|
|
33
|
+
interface RateLimitInfo {
|
|
34
|
+
limit: number;
|
|
35
|
+
remaining: number;
|
|
36
|
+
reset: number;
|
|
37
|
+
}
|
|
38
|
+
declare class SecretsSDKError extends Error {
|
|
39
|
+
status: number;
|
|
40
|
+
response?: any | undefined;
|
|
41
|
+
constructor(message: string, status: number, response?: any | undefined);
|
|
42
|
+
}
|
|
43
|
+
declare class OriginMismatchError extends SecretsSDKError {
|
|
44
|
+
constructor(message?: string);
|
|
45
|
+
}
|
|
46
|
+
declare class RateLimitError extends SecretsSDKError {
|
|
47
|
+
retryAfter: number;
|
|
48
|
+
remaining: number;
|
|
49
|
+
limit: number;
|
|
50
|
+
constructor(message?: string, retryAfter?: number, remaining?: number, limit?: number);
|
|
51
|
+
}
|
|
52
|
+
declare class InvalidTokenError extends SecretsSDKError {
|
|
53
|
+
constructor(message?: string);
|
|
54
|
+
}
|
|
55
|
+
interface SecretsManagementOptions {
|
|
56
|
+
appId: string;
|
|
57
|
+
baseUrl?: string;
|
|
58
|
+
timeout?: number;
|
|
59
|
+
}
|
|
60
|
+
interface SecretConfig {
|
|
61
|
+
name: string;
|
|
62
|
+
provider: string;
|
|
63
|
+
api_key: string;
|
|
64
|
+
base_url?: string;
|
|
65
|
+
auth_header?: string;
|
|
66
|
+
auth_prefix?: string;
|
|
67
|
+
}
|
|
68
|
+
interface MaskedSecret {
|
|
69
|
+
id: string;
|
|
70
|
+
name: string;
|
|
71
|
+
provider: string;
|
|
72
|
+
api_key: string;
|
|
73
|
+
base_url?: string;
|
|
74
|
+
auth_header?: string;
|
|
75
|
+
auth_prefix?: string;
|
|
76
|
+
created?: string;
|
|
77
|
+
updated?: string;
|
|
78
|
+
}
|
|
79
|
+
interface SyncOptions {
|
|
80
|
+
deleteMissing?: boolean;
|
|
81
|
+
dryRun?: boolean;
|
|
82
|
+
}
|
|
83
|
+
interface SyncDiffItem {
|
|
84
|
+
name: string;
|
|
85
|
+
provider?: string;
|
|
86
|
+
changes?: string[];
|
|
87
|
+
}
|
|
88
|
+
interface SyncResult {
|
|
89
|
+
success: boolean;
|
|
90
|
+
diff: {
|
|
91
|
+
created: SyncDiffItem[];
|
|
92
|
+
updated: SyncDiffItem[];
|
|
93
|
+
deleted: SyncDiffItem[];
|
|
94
|
+
unchanged: SyncDiffItem[];
|
|
95
|
+
};
|
|
96
|
+
summary: {
|
|
97
|
+
created: number;
|
|
98
|
+
updated: number;
|
|
99
|
+
deleted: number;
|
|
100
|
+
unchanged: number;
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
interface CLICredentials {
|
|
104
|
+
access_token: string;
|
|
105
|
+
refresh_token: string | null;
|
|
106
|
+
expires_at: string | null;
|
|
107
|
+
user_id: string;
|
|
108
|
+
machine_id?: string;
|
|
109
|
+
sdk_name?: string;
|
|
110
|
+
authorized_at?: string;
|
|
111
|
+
}
|
|
112
|
+
interface SDKCredentialsStore {
|
|
113
|
+
'learn-secrets-sdk'?: CLICredentials;
|
|
114
|
+
'learn-auth-sdk'?: CLICredentials;
|
|
115
|
+
}
|
|
116
|
+
type SDKName = 'learn-secrets-sdk' | 'learn-auth-sdk';
|
|
117
|
+
|
|
118
|
+
declare class SecretsSDK {
|
|
119
|
+
private appId;
|
|
120
|
+
private token;
|
|
121
|
+
private baseUrl;
|
|
122
|
+
private timeout;
|
|
123
|
+
private retryOn429;
|
|
124
|
+
private rateLimitInfo;
|
|
125
|
+
private zeroConfigMode;
|
|
126
|
+
/**
|
|
127
|
+
* Create a new SecretsSDK instance
|
|
128
|
+
*
|
|
129
|
+
* Zero-config mode (recommended for static sites):
|
|
130
|
+
* const sdk = new SecretsSDK();
|
|
131
|
+
* // Origin header is used for authentication
|
|
132
|
+
*
|
|
133
|
+
* Token mode (for backward compatibility):
|
|
134
|
+
* const sdk = new SecretsSDK({ appId: '...', token: 'sk_live_...' });
|
|
135
|
+
*/
|
|
136
|
+
constructor(options?: SecretsSDKOptions);
|
|
137
|
+
/**
|
|
138
|
+
* Get current rate limit information
|
|
139
|
+
*/
|
|
140
|
+
getUsage(): RateLimitInfo | null;
|
|
141
|
+
/**
|
|
142
|
+
* Parse rate limit headers from response
|
|
143
|
+
*/
|
|
144
|
+
private parseRateLimitHeaders;
|
|
145
|
+
/**
|
|
146
|
+
* Sleep utility for retry backoff
|
|
147
|
+
*/
|
|
148
|
+
private sleep;
|
|
149
|
+
/**
|
|
150
|
+
* Make fetch request with timeout
|
|
151
|
+
*/
|
|
152
|
+
private fetchWithTimeout;
|
|
153
|
+
/**
|
|
154
|
+
* Call an external API securely through the proxy
|
|
155
|
+
* @param keyName - Name of the API key to use
|
|
156
|
+
* @param endpoint - API endpoint path (e.g., '/v1/chat/completions')
|
|
157
|
+
* @param options - Request options (method, body, headers)
|
|
158
|
+
* @returns Promise with the API response
|
|
159
|
+
*/
|
|
160
|
+
call<T = any>(keyName: string, endpoint: string, options?: Omit<ProxyRequest, 'keyName' | 'endpoint'>): Promise<T>;
|
|
161
|
+
/**
|
|
162
|
+
* Make a GET request
|
|
163
|
+
*/
|
|
164
|
+
get<T = any>(keyName: string, endpoint: string, headers?: Record<string, string>): Promise<T>;
|
|
165
|
+
/**
|
|
166
|
+
* Make a POST request
|
|
167
|
+
*/
|
|
168
|
+
post<T = any>(keyName: string, endpoint: string, body: any, headers?: Record<string, string>): Promise<T>;
|
|
169
|
+
/**
|
|
170
|
+
* Make a PUT request
|
|
171
|
+
*/
|
|
172
|
+
put<T = any>(keyName: string, endpoint: string, body: any, headers?: Record<string, string>): Promise<T>;
|
|
173
|
+
/**
|
|
174
|
+
* Make a DELETE request
|
|
175
|
+
*/
|
|
176
|
+
delete<T = any>(keyName: string, endpoint: string, headers?: Record<string, string>): Promise<T>;
|
|
177
|
+
/**
|
|
178
|
+
* Make a PATCH request
|
|
179
|
+
*/
|
|
180
|
+
patch<T = any>(keyName: string, endpoint: string, body: any, headers?: Record<string, string>): Promise<T>;
|
|
181
|
+
/**
|
|
182
|
+
* Secrets Management API (zero-config mode)
|
|
183
|
+
* These methods allow programmatic CRUD operations on project secrets
|
|
184
|
+
* Requires appId to be set (can be set in constructor or via setAppId)
|
|
185
|
+
*/
|
|
186
|
+
/**
|
|
187
|
+
* Set App ID for secrets management
|
|
188
|
+
* Required before calling secrets management methods
|
|
189
|
+
*/
|
|
190
|
+
setAppId(appId: string): void;
|
|
191
|
+
/**
|
|
192
|
+
* Make authenticated request to secrets management API
|
|
193
|
+
*/
|
|
194
|
+
private secretsRequest;
|
|
195
|
+
/**
|
|
196
|
+
* List all secrets for the project
|
|
197
|
+
* Returns secret metadata (no API keys)
|
|
198
|
+
*/
|
|
199
|
+
listSecrets(): Promise<{
|
|
200
|
+
success: boolean;
|
|
201
|
+
secrets: Array<{
|
|
202
|
+
name: string;
|
|
203
|
+
provider: string;
|
|
204
|
+
base_url: string;
|
|
205
|
+
auth_header: string;
|
|
206
|
+
auth_prefix: string;
|
|
207
|
+
created: string;
|
|
208
|
+
updated: string;
|
|
209
|
+
}>;
|
|
210
|
+
count: number;
|
|
211
|
+
}>;
|
|
212
|
+
/**
|
|
213
|
+
* Create a new secret
|
|
214
|
+
*/
|
|
215
|
+
createSecret(secret: {
|
|
216
|
+
name: string;
|
|
217
|
+
provider: string;
|
|
218
|
+
api_key: string;
|
|
219
|
+
base_url?: string;
|
|
220
|
+
auth_header?: string;
|
|
221
|
+
auth_prefix?: string;
|
|
222
|
+
}): Promise<{
|
|
223
|
+
success: boolean;
|
|
224
|
+
message: string;
|
|
225
|
+
secret: any;
|
|
226
|
+
}>;
|
|
227
|
+
/**
|
|
228
|
+
* Update an existing secret
|
|
229
|
+
*/
|
|
230
|
+
updateSecret(update: {
|
|
231
|
+
name: string;
|
|
232
|
+
api_key?: string;
|
|
233
|
+
provider?: string;
|
|
234
|
+
base_url?: string;
|
|
235
|
+
auth_header?: string;
|
|
236
|
+
auth_prefix?: string;
|
|
237
|
+
}): Promise<{
|
|
238
|
+
success: boolean;
|
|
239
|
+
message: string;
|
|
240
|
+
secret: any;
|
|
241
|
+
}>;
|
|
242
|
+
/**
|
|
243
|
+
* Delete a secret
|
|
244
|
+
*/
|
|
245
|
+
deleteSecret(name: string): Promise<{
|
|
246
|
+
success: boolean;
|
|
247
|
+
message: string;
|
|
248
|
+
}>;
|
|
249
|
+
/**
|
|
250
|
+
* Sync secrets from .env file format
|
|
251
|
+
* Bulk upload/update secrets
|
|
252
|
+
*/
|
|
253
|
+
syncEnv(secrets: Record<string, string>, provider?: string): Promise<{
|
|
254
|
+
success: boolean;
|
|
255
|
+
message: string;
|
|
256
|
+
results: {
|
|
257
|
+
created: number;
|
|
258
|
+
updated: number;
|
|
259
|
+
failed: number;
|
|
260
|
+
details: {
|
|
261
|
+
created: string[];
|
|
262
|
+
updated: string[];
|
|
263
|
+
failed: Array<{
|
|
264
|
+
name: string;
|
|
265
|
+
error: string;
|
|
266
|
+
}>;
|
|
267
|
+
};
|
|
268
|
+
};
|
|
269
|
+
}>;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* SecretsManagement class for CLI authentication and secrets management
|
|
274
|
+
*/
|
|
275
|
+
declare class SecretsManagement {
|
|
276
|
+
private appId;
|
|
277
|
+
private baseUrl;
|
|
278
|
+
private timeout;
|
|
279
|
+
constructor(options: SecretsManagementOptions);
|
|
280
|
+
/**
|
|
281
|
+
* Open a URL in the default browser
|
|
282
|
+
*/
|
|
283
|
+
private openBrowser;
|
|
284
|
+
/**
|
|
285
|
+
* Sleep for specified milliseconds
|
|
286
|
+
*/
|
|
287
|
+
private sleep;
|
|
288
|
+
/**
|
|
289
|
+
* Browser OAuth login flow with 2FA
|
|
290
|
+
* Opens browser for user to authorize, then prompts for 2FA code
|
|
291
|
+
*/
|
|
292
|
+
login(): Promise<{
|
|
293
|
+
success: boolean;
|
|
294
|
+
user: string;
|
|
295
|
+
}>;
|
|
296
|
+
/**
|
|
297
|
+
* Check if user is authenticated
|
|
298
|
+
*/
|
|
299
|
+
isAuthenticated(): Promise<boolean>;
|
|
300
|
+
/**
|
|
301
|
+
* Logout - clear stored credentials
|
|
302
|
+
*/
|
|
303
|
+
logout(): void;
|
|
304
|
+
/**
|
|
305
|
+
* Get access token from stored credentials
|
|
306
|
+
* Throws error if not authenticated
|
|
307
|
+
*/
|
|
308
|
+
private getAccessToken;
|
|
309
|
+
/**
|
|
310
|
+
* Make authenticated request
|
|
311
|
+
*/
|
|
312
|
+
private request;
|
|
313
|
+
/**
|
|
314
|
+
* List all secrets (with masked API keys)
|
|
315
|
+
*/
|
|
316
|
+
list(): Promise<MaskedSecret[]>;
|
|
317
|
+
/**
|
|
318
|
+
* Sync secrets from config
|
|
319
|
+
*/
|
|
320
|
+
sync(secrets: SecretConfig[], options?: SyncOptions): Promise<SyncResult>;
|
|
321
|
+
/**
|
|
322
|
+
* Import secrets from a config object (bulk import)
|
|
323
|
+
* Also creates SDK token if origins are provided
|
|
324
|
+
*
|
|
325
|
+
* @param config - The secrets configuration
|
|
326
|
+
* @returns Import results including created/updated counts and optional SDK token
|
|
327
|
+
*/
|
|
328
|
+
importSecrets(config: {
|
|
329
|
+
version?: string;
|
|
330
|
+
origins?: string[];
|
|
331
|
+
secrets: SecretConfig[];
|
|
332
|
+
}): Promise<{
|
|
333
|
+
success: boolean;
|
|
334
|
+
results: {
|
|
335
|
+
created: number;
|
|
336
|
+
updated: number;
|
|
337
|
+
failed: number;
|
|
338
|
+
details: {
|
|
339
|
+
created: string[];
|
|
340
|
+
updated: string[];
|
|
341
|
+
failed: {
|
|
342
|
+
name: string;
|
|
343
|
+
error: string;
|
|
344
|
+
}[];
|
|
345
|
+
};
|
|
346
|
+
};
|
|
347
|
+
sdkToken?: {
|
|
348
|
+
token: string;
|
|
349
|
+
message: string;
|
|
350
|
+
};
|
|
351
|
+
}>;
|
|
352
|
+
/**
|
|
353
|
+
* Import secrets from a JSON file path
|
|
354
|
+
* Resolves environment variables in the config
|
|
355
|
+
*/
|
|
356
|
+
importFromFile(configPath: string): Promise<{
|
|
357
|
+
success: boolean;
|
|
358
|
+
results: {
|
|
359
|
+
created: number;
|
|
360
|
+
updated: number;
|
|
361
|
+
failed: number;
|
|
362
|
+
};
|
|
363
|
+
sdkToken?: {
|
|
364
|
+
token: string;
|
|
365
|
+
message: string;
|
|
366
|
+
};
|
|
367
|
+
}>;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Resolve environment variable references in a string
|
|
372
|
+
* Supports ${VAR} and $VAR syntax
|
|
373
|
+
*/
|
|
374
|
+
declare function resolveEnvString(value: string): string;
|
|
375
|
+
/**
|
|
376
|
+
* Resolve environment variables in a single secret config
|
|
377
|
+
*/
|
|
378
|
+
declare function resolveEnvInSecret(secret: SecretConfig): SecretConfig;
|
|
379
|
+
/**
|
|
380
|
+
* Resolve environment variables in an array of secrets
|
|
381
|
+
*/
|
|
382
|
+
declare function resolveEnvInSecrets(secrets: SecretConfig[]): SecretConfig[];
|
|
383
|
+
/**
|
|
384
|
+
* Load and parse a secrets config file
|
|
385
|
+
* Resolves environment variables in the config
|
|
386
|
+
*/
|
|
387
|
+
declare function loadSecretsConfig(configPath: string): {
|
|
388
|
+
version: string;
|
|
389
|
+
project: string;
|
|
390
|
+
secrets: SecretConfig[];
|
|
391
|
+
};
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Machine ID Generation
|
|
395
|
+
* Cross-platform machine identification for CLI authentication
|
|
396
|
+
*/
|
|
397
|
+
interface MachineInfo {
|
|
398
|
+
machineId: string;
|
|
399
|
+
fingerprint: string;
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Get a unique machine identifier
|
|
403
|
+
* This ID persists across reboots and SDK reinstalls
|
|
404
|
+
*/
|
|
405
|
+
declare function getMachineId(): Promise<MachineInfo>;
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* Read all credentials from file (SDK-keyed format)
|
|
409
|
+
*/
|
|
410
|
+
declare function readAllCredentials(): SDKCredentialsStore | null;
|
|
411
|
+
/**
|
|
412
|
+
* Write all credentials to file (SDK-keyed format)
|
|
413
|
+
*/
|
|
414
|
+
declare function writeAllCredentials(store: SDKCredentialsStore): void;
|
|
415
|
+
/**
|
|
416
|
+
* Read credentials for a specific SDK
|
|
417
|
+
*/
|
|
418
|
+
declare function readSDKCredentials(sdkName: SDKName): CLICredentials | null;
|
|
419
|
+
/**
|
|
420
|
+
* Write credentials for a specific SDK
|
|
421
|
+
*/
|
|
422
|
+
declare function writeSDKCredentials(sdkName: SDKName, creds: CLICredentials): void;
|
|
423
|
+
/**
|
|
424
|
+
* Delete credentials for a specific SDK
|
|
425
|
+
*/
|
|
426
|
+
declare function deleteSDKCredentials(sdkName: SDKName): void;
|
|
427
|
+
/**
|
|
428
|
+
* Check if credentials exist for a specific SDK
|
|
429
|
+
*/
|
|
430
|
+
declare function hasSDKCredentials(sdkName: SDKName): boolean;
|
|
431
|
+
|
|
432
|
+
export { type CLICredentials, InvalidTokenError, type MachineInfo, type MaskedSecret, OriginMismatchError, type ProxyRequest, type ProxyResponse, RateLimitError, type RateLimitInfo, type SDKCredentialsStore, type SDKName, type SecretConfig, SecretsManagement, type SecretsManagementOptions, SecretsSDK, SecretsSDKError, type SecretsSDKOptions, type SyncOptions, type SyncResult, deleteSDKCredentials, getMachineId, hasSDKCredentials, loadSecretsConfig, readAllCredentials, readSDKCredentials, resolveEnvInSecret, resolveEnvInSecrets, resolveEnvString, writeAllCredentials, writeSDKCredentials };
|