@envshed/node 0.1.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 +1055 -0
- package/dist/index.cjs +423 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +375 -0
- package/dist/index.d.ts +375 -0
- package/dist/index.js +394 -0
- package/dist/index.js.map +1 -0
- package/package.json +56 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
interface EnvshedClientOptions {
|
|
2
|
+
/** API authentication token (envshed_ or envshed_svc_ prefixed) */
|
|
3
|
+
token: string;
|
|
4
|
+
/** Base URL for the Envshed API. Defaults to "https://app.envshed.com" */
|
|
5
|
+
apiUrl?: string;
|
|
6
|
+
/** Retry configuration for transient failures */
|
|
7
|
+
retry?: RetryOptions;
|
|
8
|
+
}
|
|
9
|
+
interface RetryOptions {
|
|
10
|
+
/** Maximum number of retry attempts. Defaults to 3. Set to 0 to disable. */
|
|
11
|
+
maxRetries?: number;
|
|
12
|
+
/** Initial delay between retries in ms. Defaults to 1000. */
|
|
13
|
+
initialDelayMs?: number;
|
|
14
|
+
/** Maximum delay between retries in ms. Defaults to 10000. */
|
|
15
|
+
maxDelayMs?: number;
|
|
16
|
+
/**
|
|
17
|
+
* Backoff strategy between retries.
|
|
18
|
+
* - `"exponential"` (default) — delay doubles each attempt: `initialDelayMs * 2^(attempt-1)`
|
|
19
|
+
* - `"linear"` — constant delay: `initialDelayMs` for every attempt
|
|
20
|
+
* - `(attempt: number, initialDelayMs: number) => number` — custom function returning delay in ms
|
|
21
|
+
*/
|
|
22
|
+
backoff?: "exponential" | "linear" | BackoffFunction;
|
|
23
|
+
/**
|
|
24
|
+
* Custom function to determine whether a failed request should be retried.
|
|
25
|
+
* Receives the error and the current attempt number (starting at 1).
|
|
26
|
+
* Return `true` to retry, `false` to throw immediately.
|
|
27
|
+
*
|
|
28
|
+
* Defaults to retrying on 5xx server errors and network errors.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* // Retry on 429 (rate limited) in addition to the defaults
|
|
32
|
+
* shouldRetry: (error, attempt) => {
|
|
33
|
+
* if (error instanceof EnvshedError) return error.status >= 500 || error.status === 429;
|
|
34
|
+
* return true; // always retry network errors
|
|
35
|
+
* }
|
|
36
|
+
*/
|
|
37
|
+
shouldRetry?: ShouldRetryFunction;
|
|
38
|
+
/**
|
|
39
|
+
* Callback invoked before each retry attempt, useful for logging or monitoring.
|
|
40
|
+
* Receives the error that triggered the retry and the upcoming attempt number.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* onRetry: (error, attempt) => {
|
|
44
|
+
* console.warn(`Retry attempt ${attempt}:`, error.message);
|
|
45
|
+
* }
|
|
46
|
+
*/
|
|
47
|
+
onRetry?: OnRetryFunction;
|
|
48
|
+
}
|
|
49
|
+
/** Custom backoff function. Receives the attempt number (1-based) and the configured initialDelayMs. Returns the delay in ms before the next retry. */
|
|
50
|
+
type BackoffFunction = (attempt: number, initialDelayMs: number) => number;
|
|
51
|
+
/** Custom function to determine if a request should be retried. Return `true` to retry. */
|
|
52
|
+
type ShouldRetryFunction = (error: Error, attempt: number) => boolean;
|
|
53
|
+
/** Callback invoked before each retry. */
|
|
54
|
+
type OnRetryFunction = (error: Error, attempt: number) => void;
|
|
55
|
+
type TokenScope = "org" | "project" | "environment";
|
|
56
|
+
type TokenPermission = "read" | "read_write";
|
|
57
|
+
/** Coordinates identifying a specific environment */
|
|
58
|
+
interface EnvPath {
|
|
59
|
+
org: string;
|
|
60
|
+
project: string;
|
|
61
|
+
env: string;
|
|
62
|
+
}
|
|
63
|
+
interface GetSecretsResponse {
|
|
64
|
+
secrets: Record<string, string>;
|
|
65
|
+
placeholders: string[];
|
|
66
|
+
version: number;
|
|
67
|
+
linkedKeys?: string[];
|
|
68
|
+
decryptErrors?: string[];
|
|
69
|
+
}
|
|
70
|
+
interface SetSecretsRequest {
|
|
71
|
+
secrets: Record<string, string>;
|
|
72
|
+
}
|
|
73
|
+
interface SetSecretsResponse {
|
|
74
|
+
ok: true;
|
|
75
|
+
version: number;
|
|
76
|
+
}
|
|
77
|
+
interface Organization {
|
|
78
|
+
name: string;
|
|
79
|
+
slug: string;
|
|
80
|
+
role: string;
|
|
81
|
+
}
|
|
82
|
+
interface ListOrgsResponse {
|
|
83
|
+
organizations: Organization[];
|
|
84
|
+
}
|
|
85
|
+
interface CreateOrgRequest {
|
|
86
|
+
name: string;
|
|
87
|
+
slug?: string;
|
|
88
|
+
description?: string;
|
|
89
|
+
}
|
|
90
|
+
interface CreateOrgResponse {
|
|
91
|
+
organization: {
|
|
92
|
+
name: string;
|
|
93
|
+
slug: string;
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
interface Project {
|
|
97
|
+
id: string;
|
|
98
|
+
name: string;
|
|
99
|
+
slug: string;
|
|
100
|
+
description: string | null;
|
|
101
|
+
}
|
|
102
|
+
interface ListProjectsResponse {
|
|
103
|
+
projects: Project[];
|
|
104
|
+
}
|
|
105
|
+
interface CreateProjectRequest {
|
|
106
|
+
name: string;
|
|
107
|
+
description?: string;
|
|
108
|
+
}
|
|
109
|
+
interface CreateProjectResponse {
|
|
110
|
+
project: {
|
|
111
|
+
name: string;
|
|
112
|
+
slug: string;
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
interface Environment {
|
|
116
|
+
id: string;
|
|
117
|
+
name: string;
|
|
118
|
+
slug: string;
|
|
119
|
+
description: string | null;
|
|
120
|
+
}
|
|
121
|
+
interface ListEnvironmentsResponse {
|
|
122
|
+
environments: Environment[];
|
|
123
|
+
}
|
|
124
|
+
interface CreateEnvironmentRequest {
|
|
125
|
+
name: string;
|
|
126
|
+
description?: string;
|
|
127
|
+
}
|
|
128
|
+
interface CreateEnvironmentResponse {
|
|
129
|
+
environment: {
|
|
130
|
+
name: string;
|
|
131
|
+
slug: string;
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
interface GetVersionResponse {
|
|
135
|
+
version: number;
|
|
136
|
+
updatedAt: string;
|
|
137
|
+
}
|
|
138
|
+
interface SecretVersion {
|
|
139
|
+
version: number;
|
|
140
|
+
changeType: string;
|
|
141
|
+
changedBy: string | null;
|
|
142
|
+
comment: string | null;
|
|
143
|
+
createdAt: string;
|
|
144
|
+
}
|
|
145
|
+
interface ListSecretVersionsResponse {
|
|
146
|
+
versions: SecretVersion[];
|
|
147
|
+
}
|
|
148
|
+
interface ListSecretVersionsOptions {
|
|
149
|
+
limit?: number;
|
|
150
|
+
offset?: number;
|
|
151
|
+
}
|
|
152
|
+
interface RollbackSecretResponse {
|
|
153
|
+
ok: true;
|
|
154
|
+
newVersion: number;
|
|
155
|
+
}
|
|
156
|
+
interface Snapshot {
|
|
157
|
+
id: string;
|
|
158
|
+
name: string | null;
|
|
159
|
+
description: string | null;
|
|
160
|
+
createdBy: string | null;
|
|
161
|
+
createdAt: string;
|
|
162
|
+
}
|
|
163
|
+
interface ListSnapshotsResponse {
|
|
164
|
+
snapshots: Snapshot[];
|
|
165
|
+
}
|
|
166
|
+
interface CreateSnapshotRequest {
|
|
167
|
+
name?: string;
|
|
168
|
+
description?: string;
|
|
169
|
+
}
|
|
170
|
+
interface CreateSnapshotResponse {
|
|
171
|
+
id: string;
|
|
172
|
+
name: string | null;
|
|
173
|
+
createdAt: string;
|
|
174
|
+
}
|
|
175
|
+
interface RestoreSnapshotRequest {
|
|
176
|
+
snapshotId: string;
|
|
177
|
+
}
|
|
178
|
+
interface RestoreSnapshotResponse {
|
|
179
|
+
ok: true;
|
|
180
|
+
restoredCount: number;
|
|
181
|
+
}
|
|
182
|
+
interface MeUserResponse {
|
|
183
|
+
email: string;
|
|
184
|
+
}
|
|
185
|
+
interface MeServiceTokenResponse {
|
|
186
|
+
type: "service_token";
|
|
187
|
+
org: string | null;
|
|
188
|
+
scope: TokenScope;
|
|
189
|
+
permission: TokenPermission;
|
|
190
|
+
}
|
|
191
|
+
type MeResponse = MeUserResponse | MeServiceTokenResponse;
|
|
192
|
+
interface ServiceToken {
|
|
193
|
+
id: string;
|
|
194
|
+
name: string;
|
|
195
|
+
description: string | null;
|
|
196
|
+
token_prefix: string;
|
|
197
|
+
scope: TokenScope;
|
|
198
|
+
project_id: string | null;
|
|
199
|
+
environment_id: string | null;
|
|
200
|
+
permission: TokenPermission;
|
|
201
|
+
expires_at: string | null;
|
|
202
|
+
last_used_at: string | null;
|
|
203
|
+
is_active: boolean;
|
|
204
|
+
created_at: string;
|
|
205
|
+
created_by_email: string;
|
|
206
|
+
created_by_name: string | null;
|
|
207
|
+
}
|
|
208
|
+
interface ListServiceTokensResponse {
|
|
209
|
+
tokens: ServiceToken[];
|
|
210
|
+
}
|
|
211
|
+
interface CreateServiceTokenRequest {
|
|
212
|
+
name: string;
|
|
213
|
+
description?: string;
|
|
214
|
+
scope?: TokenScope;
|
|
215
|
+
projectId?: string;
|
|
216
|
+
environmentId?: string;
|
|
217
|
+
permission?: TokenPermission;
|
|
218
|
+
expiresAt?: string;
|
|
219
|
+
}
|
|
220
|
+
interface CreateServiceTokenResponse {
|
|
221
|
+
token: string;
|
|
222
|
+
id: string;
|
|
223
|
+
name: string;
|
|
224
|
+
}
|
|
225
|
+
interface DeleteServiceTokenResponse {
|
|
226
|
+
ok: true;
|
|
227
|
+
}
|
|
228
|
+
/** @internal */
|
|
229
|
+
interface RequestOptions {
|
|
230
|
+
method: "GET" | "POST" | "PUT" | "DELETE";
|
|
231
|
+
path: string;
|
|
232
|
+
body?: unknown;
|
|
233
|
+
headers?: Record<string, string>;
|
|
234
|
+
query?: Record<string, string | number>;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
declare class EnvshedClient {
|
|
238
|
+
private readonly token;
|
|
239
|
+
private readonly apiUrl;
|
|
240
|
+
private readonly retryConfig;
|
|
241
|
+
/** Manage secrets in an environment */
|
|
242
|
+
readonly secrets: SecretsAPI;
|
|
243
|
+
/** Manage organizations */
|
|
244
|
+
readonly orgs: OrgsAPI;
|
|
245
|
+
/** Manage projects within an organization */
|
|
246
|
+
readonly projects: ProjectsAPI;
|
|
247
|
+
/** Manage environments within a project */
|
|
248
|
+
readonly environments: EnvironmentsAPI;
|
|
249
|
+
/** Query environment version (supports ETag) */
|
|
250
|
+
readonly version: VersionAPI;
|
|
251
|
+
/** Manage secret version history and rollbacks */
|
|
252
|
+
readonly versions: VersionsAPI;
|
|
253
|
+
/** Manage environment snapshots */
|
|
254
|
+
readonly snapshots: SnapshotsAPI;
|
|
255
|
+
/** Manage service tokens (admin only) */
|
|
256
|
+
readonly serviceTokens: ServiceTokensAPI;
|
|
257
|
+
constructor(options: EnvshedClientOptions);
|
|
258
|
+
/** Check authentication and return current user/token info */
|
|
259
|
+
me(): Promise<MeResponse>;
|
|
260
|
+
/** @internal */
|
|
261
|
+
_request<T>(options: RequestOptions): Promise<T>;
|
|
262
|
+
}
|
|
263
|
+
declare class SecretsAPI {
|
|
264
|
+
private readonly client;
|
|
265
|
+
constructor(client: EnvshedClient);
|
|
266
|
+
/** Get all secrets for an environment */
|
|
267
|
+
get(path: EnvPath): Promise<GetSecretsResponse>;
|
|
268
|
+
/** Set (upsert) secrets for an environment */
|
|
269
|
+
set(path: EnvPath, secrets: Record<string, string>): Promise<SetSecretsResponse>;
|
|
270
|
+
}
|
|
271
|
+
declare class OrgsAPI {
|
|
272
|
+
private readonly client;
|
|
273
|
+
constructor(client: EnvshedClient);
|
|
274
|
+
/** List all organizations the authenticated user belongs to */
|
|
275
|
+
list(): Promise<ListOrgsResponse>;
|
|
276
|
+
/** Create a new organization */
|
|
277
|
+
create(data: CreateOrgRequest): Promise<CreateOrgResponse>;
|
|
278
|
+
}
|
|
279
|
+
declare class ProjectsAPI {
|
|
280
|
+
private readonly client;
|
|
281
|
+
constructor(client: EnvshedClient);
|
|
282
|
+
/** List all projects in an organization */
|
|
283
|
+
list(org: string): Promise<ListProjectsResponse>;
|
|
284
|
+
/** Create a new project in an organization */
|
|
285
|
+
create(org: string, data: CreateProjectRequest): Promise<CreateProjectResponse>;
|
|
286
|
+
}
|
|
287
|
+
declare class EnvironmentsAPI {
|
|
288
|
+
private readonly client;
|
|
289
|
+
constructor(client: EnvshedClient);
|
|
290
|
+
/** List all environments in a project */
|
|
291
|
+
list(org: string, project: string): Promise<ListEnvironmentsResponse>;
|
|
292
|
+
/** Create a new environment in a project */
|
|
293
|
+
create(org: string, project: string, data: CreateEnvironmentRequest): Promise<CreateEnvironmentResponse>;
|
|
294
|
+
}
|
|
295
|
+
declare class VersionAPI {
|
|
296
|
+
private readonly client;
|
|
297
|
+
constructor(client: EnvshedClient);
|
|
298
|
+
/** Get the current version of an environment. Returns null if unchanged (304). */
|
|
299
|
+
get(path: EnvPath, etag?: string): Promise<GetVersionResponse | null>;
|
|
300
|
+
}
|
|
301
|
+
declare class VersionsAPI {
|
|
302
|
+
private readonly client;
|
|
303
|
+
constructor(client: EnvshedClient);
|
|
304
|
+
/** List version history for a specific secret key */
|
|
305
|
+
list(path: EnvPath, secretKey: string, options?: ListSecretVersionsOptions): Promise<ListSecretVersionsResponse>;
|
|
306
|
+
/** Rollback a secret to a previous version */
|
|
307
|
+
rollback(path: EnvPath, secretKey: string, targetVersion: number): Promise<RollbackSecretResponse>;
|
|
308
|
+
}
|
|
309
|
+
declare class SnapshotsAPI {
|
|
310
|
+
private readonly client;
|
|
311
|
+
constructor(client: EnvshedClient);
|
|
312
|
+
/** List all snapshots for an environment */
|
|
313
|
+
list(path: EnvPath): Promise<ListSnapshotsResponse>;
|
|
314
|
+
/** Create a snapshot of the current environment state */
|
|
315
|
+
create(path: EnvPath, data?: CreateSnapshotRequest): Promise<CreateSnapshotResponse>;
|
|
316
|
+
/** Restore an environment from a snapshot */
|
|
317
|
+
restore(path: EnvPath, snapshotId: string): Promise<RestoreSnapshotResponse>;
|
|
318
|
+
}
|
|
319
|
+
declare class ServiceTokensAPI {
|
|
320
|
+
private readonly client;
|
|
321
|
+
constructor(client: EnvshedClient);
|
|
322
|
+
/** List all service tokens for an organization (admin only) */
|
|
323
|
+
list(org: string): Promise<ListServiceTokensResponse>;
|
|
324
|
+
/** Create a new service token (admin only) */
|
|
325
|
+
create(org: string, data: CreateServiceTokenRequest): Promise<CreateServiceTokenResponse>;
|
|
326
|
+
/** Delete a service token (admin only) */
|
|
327
|
+
delete(org: string, tokenId: string): Promise<DeleteServiceTokenResponse>;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Error thrown when the Envshed API returns an HTTP error response (4xx or 5xx).
|
|
332
|
+
*/
|
|
333
|
+
declare class EnvshedError extends Error {
|
|
334
|
+
/** HTTP status code from the API */
|
|
335
|
+
readonly status: number;
|
|
336
|
+
/** Error message from the API response body */
|
|
337
|
+
readonly apiMessage: string;
|
|
338
|
+
/** HTTP method of the failed request */
|
|
339
|
+
readonly method: string;
|
|
340
|
+
/** URL path of the failed request */
|
|
341
|
+
readonly path: string;
|
|
342
|
+
constructor(options: {
|
|
343
|
+
status: number;
|
|
344
|
+
apiMessage: string;
|
|
345
|
+
method: string;
|
|
346
|
+
path: string;
|
|
347
|
+
});
|
|
348
|
+
/** Whether this is an authentication error (401) */
|
|
349
|
+
get isUnauthorized(): boolean;
|
|
350
|
+
/** Whether this is a permissions error (403) */
|
|
351
|
+
get isForbidden(): boolean;
|
|
352
|
+
/** Whether this is a not found error (404) */
|
|
353
|
+
get isNotFound(): boolean;
|
|
354
|
+
/** Whether this is a subscription-related error (402) */
|
|
355
|
+
get isSubscriptionRequired(): boolean;
|
|
356
|
+
/** Whether this error is retryable (5xx server errors) */
|
|
357
|
+
get isRetryable(): boolean;
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Error thrown when a network-level failure occurs (no HTTP response).
|
|
361
|
+
* Always considered retryable.
|
|
362
|
+
*/
|
|
363
|
+
declare class EnvshedNetworkError extends Error {
|
|
364
|
+
readonly method: string;
|
|
365
|
+
readonly path: string;
|
|
366
|
+
readonly cause: Error;
|
|
367
|
+
constructor(options: {
|
|
368
|
+
method: string;
|
|
369
|
+
path: string;
|
|
370
|
+
cause: Error;
|
|
371
|
+
});
|
|
372
|
+
get isRetryable(): boolean;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
export { type BackoffFunction, type CreateEnvironmentRequest, type CreateEnvironmentResponse, type CreateOrgRequest, type CreateOrgResponse, type CreateProjectRequest, type CreateProjectResponse, type CreateServiceTokenRequest, type CreateServiceTokenResponse, type CreateSnapshotRequest, type CreateSnapshotResponse, type DeleteServiceTokenResponse, type EnvPath, type Environment, EnvshedClient, type EnvshedClientOptions, EnvshedError, EnvshedNetworkError, type GetSecretsResponse, type GetVersionResponse, type ListEnvironmentsResponse, type ListOrgsResponse, type ListProjectsResponse, type ListSecretVersionsOptions, type ListSecretVersionsResponse, type ListServiceTokensResponse, type ListSnapshotsResponse, type MeResponse, type MeServiceTokenResponse, type MeUserResponse, type OnRetryFunction, type Organization, type Project, type RestoreSnapshotRequest, type RestoreSnapshotResponse, type RetryOptions, type RollbackSecretResponse, type SecretVersion, type ServiceToken, type SetSecretsRequest, type SetSecretsResponse, type ShouldRetryFunction, type Snapshot, type TokenPermission, type TokenScope };
|