@cosmoner/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 +50 -0
- package/dist/client.d.ts +4 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +176 -1
- package/dist/index.mjs +173 -1
- package/dist/services/project-config.d.ts +20 -0
- package/dist/services/secrets.d.ts +147 -0
- package/dist/services/variables.d.ts +89 -0
- package/dist/version.d.ts +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -139,6 +139,56 @@ const { data: access } = await client.hosting.access(sites[0].id);
|
|
|
139
139
|
`sftpPassword`. It needs no scope beyond `hosting:read`, so guard the key
|
|
140
140
|
accordingly.
|
|
141
141
|
|
|
142
|
+
## Secrets
|
|
143
|
+
|
|
144
|
+
Stores the values a deployment file refers to with `from_secret`. Needs an API
|
|
145
|
+
key with `secrets:read`, and `secrets:write` to change anything.
|
|
146
|
+
|
|
147
|
+
```ts
|
|
148
|
+
const { data: secret } = await client.secrets.create({
|
|
149
|
+
name: "DB_PASSWORD",
|
|
150
|
+
value: "hunter2",
|
|
151
|
+
environment: "production",
|
|
152
|
+
});
|
|
153
|
+
secret.value; // "hunter2" — returned here and nowhere else
|
|
154
|
+
secret.maskedValue; // "hu••••r2", safe to display
|
|
155
|
+
|
|
156
|
+
const { data: secrets } = await client.secrets.list({ environment: "production" });
|
|
157
|
+
// name, environment, version, who changed it and when — never the value
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
A secret's value is encrypted at rest and returned exactly once, by the call
|
|
161
|
+
that sets it. `list()` and `get()` describe a secret without its value, and no
|
|
162
|
+
route decrypts one, so a lost value is replaced rather than recovered.
|
|
163
|
+
|
|
164
|
+
`update(id, { value })` replaces a value and bumps `version`; `delete(id)`
|
|
165
|
+
removes it; `usage()` reports how many secrets the project holds and may hold;
|
|
166
|
+
`audit(id)` reads who changed it and when.
|
|
167
|
+
|
|
168
|
+
Two API behaviours are worth knowing before you debug them:
|
|
169
|
+
|
|
170
|
+
- **Writes need an owner or admin.** The API checks the member's role
|
|
171
|
+
independently of the key's scopes, so a plain member's key is refused with a
|
|
172
|
+
403 even when it carries `secrets:write`.
|
|
173
|
+
- **Creating is rate-limited** to 10 requests per 10 minutes, and a project at
|
|
174
|
+
its secret limit answers 402.
|
|
175
|
+
|
|
176
|
+
## Variables
|
|
177
|
+
|
|
178
|
+
The plaintext sibling of secrets, for non-sensitive configuration a deployment
|
|
179
|
+
file refers to with `from_variable`. Needs `variables:read`, and
|
|
180
|
+
`variables:write` to change anything.
|
|
181
|
+
|
|
182
|
+
```ts
|
|
183
|
+
await client.variables.create({ name: "LOG_LEVEL", value: "debug" });
|
|
184
|
+
const { data: variables } = await client.variables.list();
|
|
185
|
+
variables[0].value; // "debug" — returned in full on every read
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
That is the difference between the two resources, not an oversight: anything
|
|
189
|
+
worth hiding belongs in `client.secrets`. `update()` here takes a value, a
|
|
190
|
+
description, or both.
|
|
191
|
+
|
|
142
192
|
## Deployment files
|
|
143
193
|
|
|
144
194
|
Validates a `.cosmoner/deployment.yaml` — the file you commit to describe how a
|
package/dist/client.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ import { type CosmonerConfig } from "./config";
|
|
|
3
3
|
import { AppsService } from "./services/apps";
|
|
4
4
|
import { EmailService } from "./services/email";
|
|
5
5
|
import { HostingService } from "./services/hosting";
|
|
6
|
+
import { SecretsService } from "./services/secrets";
|
|
7
|
+
import { VariablesService } from "./services/variables";
|
|
6
8
|
import { WebhooksService } from "./services/webhooks";
|
|
7
9
|
/**
|
|
8
10
|
* Cosmoner API client.
|
|
@@ -27,6 +29,8 @@ export declare class Cosmoner {
|
|
|
27
29
|
readonly apps: AppsService;
|
|
28
30
|
readonly email: EmailService;
|
|
29
31
|
readonly hosting: HostingService;
|
|
32
|
+
readonly secrets: SecretsService;
|
|
33
|
+
readonly variables: VariablesService;
|
|
30
34
|
readonly webhooks: WebhooksService;
|
|
31
35
|
constructor(config: CosmonerConfig);
|
|
32
36
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,9 @@ export type { DeploymentBuild, DeploymentEnvVar, DeploymentIssue, DeploymentIssu
|
|
|
8
8
|
export { AppsService, FINISHED_DEPLOYMENT_PHASES, type App, type AppDeployment, type AppStatus, type DeployAppParams, type DeployAppResponse, type DeploymentPhase, type GetDeploymentResponse, type ImageDeployPolicy, type ListAppsResponse, type WaitForDeploymentParams, } from "./services/apps";
|
|
9
9
|
export { EmailService, type SendEmailParams, type SendEmailResponse, } from "./services/email";
|
|
10
10
|
export { HostingService, type GetHostingAccessResponse, type GetHostingSiteParams, type GetHostingSiteResponse, type GetHostingSiteWithCredentialsResponse, type HostingAccess, type HostingSite, type HostingSiteStatus, type HostingSiteWithCredentials, type ListHostingSitesResponse, } from "./services/hosting";
|
|
11
|
+
export { PROJECT_ENVIRONMENTS, type Actor, type ProjectEnvironment, } from "./services/project-config";
|
|
12
|
+
export { SecretsService, type CreateSecretParams, type GetSecretAuditResponse, type GetSecretResponse, type GetSecretsUsageResponse, type ListSecretsParams, type ListSecretsResponse, type ProjectSecret, type RevealedProjectSecret, type SecretAuditEntry, type SecretsUsage, type SetSecretResponse, type UpdateSecretParams, } from "./services/secrets";
|
|
13
|
+
export { VariablesService, type CreateVariableParams, type GetVariableResponse, type ListVariablesParams, type ListVariablesResponse, type ProjectVariable, type SetVariableResponse, type UpdateVariableParams, } from "./services/variables";
|
|
11
14
|
export { WEBHOOK_EVENT_TYPES, WebhooksService, type CreateWebhookEndpointParams, type CreateWebhookEndpointResponse, type DeleteWebhookEndpointResponse, type GetWebhookEndpointResponse, type ListDeliveriesParams, type ListWebhookDeliveriesResponse, type ListWebhookEndpointsResponse, type ReplayWebhookDeliveryResponse, type ResumeWebhookEndpointResponse, type RotateWebhookSecretResponse, type TestWebhookEndpointResponse, type UpdateWebhookEndpointParams, type UpdateWebhookEndpointResponse, type WebhookDelivery, type WebhookDeliveryStatus, type WebhookDisabledReason, type WebhookEndpoint, type WebhookEndpointStats, type WebhookEndpointWithSecret, type WebhookEventType, } from "./services/webhooks";
|
|
12
15
|
export { constructEvent, DEFAULT_TOLERANCE_SECONDS, DELIVERY_ID_HEADER, EVENT_TYPE_HEADER, SIGNATURE_HEADER, verifyWebhookSignature, type VerifyWebhookParams, type WebhookEvent, } from "./webhooks/signature";
|
|
13
16
|
export { VERSION } from "./version";
|
package/dist/index.js
CHANGED
|
@@ -43,11 +43,14 @@ __export(index_exports, {
|
|
|
43
43
|
InsufficientScopeError: () => InsufficientScopeError,
|
|
44
44
|
MAX_DEPLOYMENT_BYTES: () => MAX_DEPLOYMENT_BYTES,
|
|
45
45
|
NotFoundError: () => NotFoundError,
|
|
46
|
+
PROJECT_ENVIRONMENTS: () => PROJECT_ENVIRONMENTS,
|
|
46
47
|
RateLimitError: () => RateLimitError,
|
|
47
48
|
SIGNATURE_HEADER: () => SIGNATURE_HEADER,
|
|
49
|
+
SecretsService: () => SecretsService,
|
|
48
50
|
ServerError: () => ServerError,
|
|
49
51
|
VERSION: () => VERSION,
|
|
50
52
|
ValidationError: () => ValidationError,
|
|
53
|
+
VariablesService: () => VariablesService,
|
|
51
54
|
WEBHOOK_EVENT_TYPES: () => WEBHOOK_EVENT_TYPES,
|
|
52
55
|
WebhookSignatureError: () => WebhookSignatureError,
|
|
53
56
|
WebhooksService: () => WebhooksService,
|
|
@@ -241,6 +244,172 @@ var HostingService = class {
|
|
|
241
244
|
}
|
|
242
245
|
};
|
|
243
246
|
|
|
247
|
+
// src/services/project-config.ts
|
|
248
|
+
var PROJECT_ENVIRONMENTS = [
|
|
249
|
+
"default",
|
|
250
|
+
"development",
|
|
251
|
+
"staging",
|
|
252
|
+
"production"
|
|
253
|
+
];
|
|
254
|
+
var NAME_PATTERN = /^[A-Z][A-Z0-9_]*$/;
|
|
255
|
+
var MAX_NAME_LENGTH = 100;
|
|
256
|
+
var MAX_VALUE_LENGTH = 1e4;
|
|
257
|
+
function requireEntryName(name) {
|
|
258
|
+
if (!name) throw new Error("name is required");
|
|
259
|
+
if (!NAME_PATTERN.test(name)) {
|
|
260
|
+
throw new Error(
|
|
261
|
+
"Name must be uppercase letters, numbers, or underscores, and start with a letter (e.g. DB_PASSWORD)"
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
if (name.length > MAX_NAME_LENGTH) {
|
|
265
|
+
throw new Error(`name must be at most ${MAX_NAME_LENGTH} characters`);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
function requireEntryValue(value) {
|
|
269
|
+
if (!value) throw new Error("value is required");
|
|
270
|
+
if (value.length > MAX_VALUE_LENGTH) {
|
|
271
|
+
throw new Error(`value must be at most ${MAX_VALUE_LENGTH} characters`);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// src/services/secrets.ts
|
|
276
|
+
var SecretsService = class {
|
|
277
|
+
constructor(transport, config) {
|
|
278
|
+
this.transport = transport;
|
|
279
|
+
this.config = config;
|
|
280
|
+
}
|
|
281
|
+
/** Builds the collection route for the resolved project. */
|
|
282
|
+
basePath(projectId) {
|
|
283
|
+
return `/v1/projects/${resolveProjectId(this.config, projectId)}/secrets`;
|
|
284
|
+
}
|
|
285
|
+
/** Lists the project's secrets as metadata. Values are never included. */
|
|
286
|
+
async list(params = {}) {
|
|
287
|
+
return this.transport.request("GET", this.basePath(params.projectId), {
|
|
288
|
+
query: { environment: params.environment }
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
/** Fetches one secret's metadata. The value is not part of the response. */
|
|
292
|
+
async get(secretId, params = {}) {
|
|
293
|
+
if (!secretId) throw new Error("secretId is required");
|
|
294
|
+
return this.transport.request(
|
|
295
|
+
"GET",
|
|
296
|
+
`${this.basePath(params.projectId)}/${secretId}`
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Stores a new secret, and returns its plaintext value once.
|
|
301
|
+
*
|
|
302
|
+
* Creation is rate-limited to 10 requests per 10 minutes, so a loop that
|
|
303
|
+
* imports many secrets will meet a `RateLimitError`. A project at its limit
|
|
304
|
+
* answers 402 — see `usage()`.
|
|
305
|
+
*/
|
|
306
|
+
async create(params) {
|
|
307
|
+
requireEntryName(params.name);
|
|
308
|
+
requireEntryValue(params.value);
|
|
309
|
+
return this.transport.request("POST", this.basePath(params.projectId), {
|
|
310
|
+
body: {
|
|
311
|
+
name: params.name,
|
|
312
|
+
value: params.value,
|
|
313
|
+
description: params.description,
|
|
314
|
+
environment: params.environment
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
/** Replaces a secret's value, bumps its version, and returns the new value once. */
|
|
319
|
+
async update(secretId, params) {
|
|
320
|
+
if (!secretId) throw new Error("secretId is required");
|
|
321
|
+
requireEntryValue(params.value);
|
|
322
|
+
return this.transport.request(
|
|
323
|
+
"PATCH",
|
|
324
|
+
`${this.basePath(params.projectId)}/${secretId}`,
|
|
325
|
+
{ body: { value: params.value, description: params.description } }
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
/** Permanently removes a secret. The API answers 204, so there is nothing to return. */
|
|
329
|
+
async delete(secretId, params = {}) {
|
|
330
|
+
if (!secretId) throw new Error("secretId is required");
|
|
331
|
+
await this.transport.request(
|
|
332
|
+
"DELETE",
|
|
333
|
+
`${this.basePath(params.projectId)}/${secretId}`
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
/** Reports how many secrets the project holds, how many it may hold, and the price of more. */
|
|
337
|
+
async usage(params = {}) {
|
|
338
|
+
return this.transport.request(
|
|
339
|
+
"GET",
|
|
340
|
+
`${this.basePath(params.projectId)}/usage`
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
/** Reads a secret's audit trail: who changed it and when, never what it was changed to. */
|
|
344
|
+
async audit(secretId, params = {}) {
|
|
345
|
+
if (!secretId) throw new Error("secretId is required");
|
|
346
|
+
return this.transport.request(
|
|
347
|
+
"GET",
|
|
348
|
+
`${this.basePath(params.projectId)}/${secretId}/audit`
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
// src/services/variables.ts
|
|
354
|
+
var VariablesService = class {
|
|
355
|
+
constructor(transport, config) {
|
|
356
|
+
this.transport = transport;
|
|
357
|
+
this.config = config;
|
|
358
|
+
}
|
|
359
|
+
/** Builds the collection route for the resolved project. */
|
|
360
|
+
basePath(projectId) {
|
|
361
|
+
return `/v1/projects/${resolveProjectId(this.config, projectId)}/variables`;
|
|
362
|
+
}
|
|
363
|
+
/** Lists the project's variables, values included. */
|
|
364
|
+
async list(params = {}) {
|
|
365
|
+
return this.transport.request("GET", this.basePath(params.projectId), {
|
|
366
|
+
query: { environment: params.environment }
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
/** Fetches one variable, value included. */
|
|
370
|
+
async get(variableId, params = {}) {
|
|
371
|
+
if (!variableId) throw new Error("variableId is required");
|
|
372
|
+
return this.transport.request(
|
|
373
|
+
"GET",
|
|
374
|
+
`${this.basePath(params.projectId)}/${variableId}`
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
/** Stores a new variable. */
|
|
378
|
+
async create(params) {
|
|
379
|
+
requireEntryName(params.name);
|
|
380
|
+
requireEntryValue(params.value);
|
|
381
|
+
return this.transport.request("POST", this.basePath(params.projectId), {
|
|
382
|
+
body: {
|
|
383
|
+
name: params.name,
|
|
384
|
+
value: params.value,
|
|
385
|
+
description: params.description,
|
|
386
|
+
environment: params.environment
|
|
387
|
+
}
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
/** Changes a variable's value, its description, or both. */
|
|
391
|
+
async update(variableId, params) {
|
|
392
|
+
if (!variableId) throw new Error("variableId is required");
|
|
393
|
+
if (params.value === void 0 && params.description === void 0) {
|
|
394
|
+
throw new Error("Provide a value or description to update");
|
|
395
|
+
}
|
|
396
|
+
if (params.value !== void 0) requireEntryValue(params.value);
|
|
397
|
+
return this.transport.request(
|
|
398
|
+
"PATCH",
|
|
399
|
+
`${this.basePath(params.projectId)}/${variableId}`,
|
|
400
|
+
{ body: { value: params.value, description: params.description } }
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
/** Permanently removes a variable. The API answers 204, so there is nothing to return. */
|
|
404
|
+
async delete(variableId, params = {}) {
|
|
405
|
+
if (!variableId) throw new Error("variableId is required");
|
|
406
|
+
await this.transport.request(
|
|
407
|
+
"DELETE",
|
|
408
|
+
`${this.basePath(params.projectId)}/${variableId}`
|
|
409
|
+
);
|
|
410
|
+
}
|
|
411
|
+
};
|
|
412
|
+
|
|
244
413
|
// src/webhooks/signature.ts
|
|
245
414
|
var import_node_crypto = require("crypto");
|
|
246
415
|
|
|
@@ -625,7 +794,7 @@ function sleep(ms) {
|
|
|
625
794
|
}
|
|
626
795
|
|
|
627
796
|
// src/version.ts
|
|
628
|
-
var VERSION = "1.
|
|
797
|
+
var VERSION = "1.6.0";
|
|
629
798
|
var USER_AGENT = `cosmoner-node/${VERSION}`;
|
|
630
799
|
|
|
631
800
|
// src/transport.ts
|
|
@@ -672,6 +841,7 @@ var Transport = class {
|
|
|
672
841
|
}
|
|
673
842
|
/** Parses a successful response body, or throws the mapped API error. */
|
|
674
843
|
async decode(response) {
|
|
844
|
+
if (response.status === 204) return void 0;
|
|
675
845
|
let body;
|
|
676
846
|
try {
|
|
677
847
|
body = await response.json();
|
|
@@ -750,6 +920,8 @@ var Cosmoner = class {
|
|
|
750
920
|
this.apps = new AppsService(this.transport, this.config);
|
|
751
921
|
this.email = new EmailService(this.transport, this.config);
|
|
752
922
|
this.hosting = new HostingService(this.transport, this.config);
|
|
923
|
+
this.secrets = new SecretsService(this.transport, this.config);
|
|
924
|
+
this.variables = new VariablesService(this.transport, this.config);
|
|
753
925
|
this.webhooks = new WebhooksService(this.transport, this.config);
|
|
754
926
|
}
|
|
755
927
|
};
|
|
@@ -1112,11 +1284,14 @@ var index_default = Cosmoner;
|
|
|
1112
1284
|
InsufficientScopeError,
|
|
1113
1285
|
MAX_DEPLOYMENT_BYTES,
|
|
1114
1286
|
NotFoundError,
|
|
1287
|
+
PROJECT_ENVIRONMENTS,
|
|
1115
1288
|
RateLimitError,
|
|
1116
1289
|
SIGNATURE_HEADER,
|
|
1290
|
+
SecretsService,
|
|
1117
1291
|
ServerError,
|
|
1118
1292
|
VERSION,
|
|
1119
1293
|
ValidationError,
|
|
1294
|
+
VariablesService,
|
|
1120
1295
|
WEBHOOK_EVENT_TYPES,
|
|
1121
1296
|
WebhookSignatureError,
|
|
1122
1297
|
WebhooksService,
|
package/dist/index.mjs
CHANGED
|
@@ -180,6 +180,172 @@ var HostingService = class {
|
|
|
180
180
|
}
|
|
181
181
|
};
|
|
182
182
|
|
|
183
|
+
// src/services/project-config.ts
|
|
184
|
+
var PROJECT_ENVIRONMENTS = [
|
|
185
|
+
"default",
|
|
186
|
+
"development",
|
|
187
|
+
"staging",
|
|
188
|
+
"production"
|
|
189
|
+
];
|
|
190
|
+
var NAME_PATTERN = /^[A-Z][A-Z0-9_]*$/;
|
|
191
|
+
var MAX_NAME_LENGTH = 100;
|
|
192
|
+
var MAX_VALUE_LENGTH = 1e4;
|
|
193
|
+
function requireEntryName(name) {
|
|
194
|
+
if (!name) throw new Error("name is required");
|
|
195
|
+
if (!NAME_PATTERN.test(name)) {
|
|
196
|
+
throw new Error(
|
|
197
|
+
"Name must be uppercase letters, numbers, or underscores, and start with a letter (e.g. DB_PASSWORD)"
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
if (name.length > MAX_NAME_LENGTH) {
|
|
201
|
+
throw new Error(`name must be at most ${MAX_NAME_LENGTH} characters`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
function requireEntryValue(value) {
|
|
205
|
+
if (!value) throw new Error("value is required");
|
|
206
|
+
if (value.length > MAX_VALUE_LENGTH) {
|
|
207
|
+
throw new Error(`value must be at most ${MAX_VALUE_LENGTH} characters`);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// src/services/secrets.ts
|
|
212
|
+
var SecretsService = class {
|
|
213
|
+
constructor(transport, config) {
|
|
214
|
+
this.transport = transport;
|
|
215
|
+
this.config = config;
|
|
216
|
+
}
|
|
217
|
+
/** Builds the collection route for the resolved project. */
|
|
218
|
+
basePath(projectId) {
|
|
219
|
+
return `/v1/projects/${resolveProjectId(this.config, projectId)}/secrets`;
|
|
220
|
+
}
|
|
221
|
+
/** Lists the project's secrets as metadata. Values are never included. */
|
|
222
|
+
async list(params = {}) {
|
|
223
|
+
return this.transport.request("GET", this.basePath(params.projectId), {
|
|
224
|
+
query: { environment: params.environment }
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
/** Fetches one secret's metadata. The value is not part of the response. */
|
|
228
|
+
async get(secretId, params = {}) {
|
|
229
|
+
if (!secretId) throw new Error("secretId is required");
|
|
230
|
+
return this.transport.request(
|
|
231
|
+
"GET",
|
|
232
|
+
`${this.basePath(params.projectId)}/${secretId}`
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Stores a new secret, and returns its plaintext value once.
|
|
237
|
+
*
|
|
238
|
+
* Creation is rate-limited to 10 requests per 10 minutes, so a loop that
|
|
239
|
+
* imports many secrets will meet a `RateLimitError`. A project at its limit
|
|
240
|
+
* answers 402 — see `usage()`.
|
|
241
|
+
*/
|
|
242
|
+
async create(params) {
|
|
243
|
+
requireEntryName(params.name);
|
|
244
|
+
requireEntryValue(params.value);
|
|
245
|
+
return this.transport.request("POST", this.basePath(params.projectId), {
|
|
246
|
+
body: {
|
|
247
|
+
name: params.name,
|
|
248
|
+
value: params.value,
|
|
249
|
+
description: params.description,
|
|
250
|
+
environment: params.environment
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
/** Replaces a secret's value, bumps its version, and returns the new value once. */
|
|
255
|
+
async update(secretId, params) {
|
|
256
|
+
if (!secretId) throw new Error("secretId is required");
|
|
257
|
+
requireEntryValue(params.value);
|
|
258
|
+
return this.transport.request(
|
|
259
|
+
"PATCH",
|
|
260
|
+
`${this.basePath(params.projectId)}/${secretId}`,
|
|
261
|
+
{ body: { value: params.value, description: params.description } }
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
/** Permanently removes a secret. The API answers 204, so there is nothing to return. */
|
|
265
|
+
async delete(secretId, params = {}) {
|
|
266
|
+
if (!secretId) throw new Error("secretId is required");
|
|
267
|
+
await this.transport.request(
|
|
268
|
+
"DELETE",
|
|
269
|
+
`${this.basePath(params.projectId)}/${secretId}`
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
/** Reports how many secrets the project holds, how many it may hold, and the price of more. */
|
|
273
|
+
async usage(params = {}) {
|
|
274
|
+
return this.transport.request(
|
|
275
|
+
"GET",
|
|
276
|
+
`${this.basePath(params.projectId)}/usage`
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
/** Reads a secret's audit trail: who changed it and when, never what it was changed to. */
|
|
280
|
+
async audit(secretId, params = {}) {
|
|
281
|
+
if (!secretId) throw new Error("secretId is required");
|
|
282
|
+
return this.transport.request(
|
|
283
|
+
"GET",
|
|
284
|
+
`${this.basePath(params.projectId)}/${secretId}/audit`
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
// src/services/variables.ts
|
|
290
|
+
var VariablesService = class {
|
|
291
|
+
constructor(transport, config) {
|
|
292
|
+
this.transport = transport;
|
|
293
|
+
this.config = config;
|
|
294
|
+
}
|
|
295
|
+
/** Builds the collection route for the resolved project. */
|
|
296
|
+
basePath(projectId) {
|
|
297
|
+
return `/v1/projects/${resolveProjectId(this.config, projectId)}/variables`;
|
|
298
|
+
}
|
|
299
|
+
/** Lists the project's variables, values included. */
|
|
300
|
+
async list(params = {}) {
|
|
301
|
+
return this.transport.request("GET", this.basePath(params.projectId), {
|
|
302
|
+
query: { environment: params.environment }
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
/** Fetches one variable, value included. */
|
|
306
|
+
async get(variableId, params = {}) {
|
|
307
|
+
if (!variableId) throw new Error("variableId is required");
|
|
308
|
+
return this.transport.request(
|
|
309
|
+
"GET",
|
|
310
|
+
`${this.basePath(params.projectId)}/${variableId}`
|
|
311
|
+
);
|
|
312
|
+
}
|
|
313
|
+
/** Stores a new variable. */
|
|
314
|
+
async create(params) {
|
|
315
|
+
requireEntryName(params.name);
|
|
316
|
+
requireEntryValue(params.value);
|
|
317
|
+
return this.transport.request("POST", this.basePath(params.projectId), {
|
|
318
|
+
body: {
|
|
319
|
+
name: params.name,
|
|
320
|
+
value: params.value,
|
|
321
|
+
description: params.description,
|
|
322
|
+
environment: params.environment
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
/** Changes a variable's value, its description, or both. */
|
|
327
|
+
async update(variableId, params) {
|
|
328
|
+
if (!variableId) throw new Error("variableId is required");
|
|
329
|
+
if (params.value === void 0 && params.description === void 0) {
|
|
330
|
+
throw new Error("Provide a value or description to update");
|
|
331
|
+
}
|
|
332
|
+
if (params.value !== void 0) requireEntryValue(params.value);
|
|
333
|
+
return this.transport.request(
|
|
334
|
+
"PATCH",
|
|
335
|
+
`${this.basePath(params.projectId)}/${variableId}`,
|
|
336
|
+
{ body: { value: params.value, description: params.description } }
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
/** Permanently removes a variable. The API answers 204, so there is nothing to return. */
|
|
340
|
+
async delete(variableId, params = {}) {
|
|
341
|
+
if (!variableId) throw new Error("variableId is required");
|
|
342
|
+
await this.transport.request(
|
|
343
|
+
"DELETE",
|
|
344
|
+
`${this.basePath(params.projectId)}/${variableId}`
|
|
345
|
+
);
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
|
|
183
349
|
// src/webhooks/signature.ts
|
|
184
350
|
import { createHmac, timingSafeEqual } from "crypto";
|
|
185
351
|
|
|
@@ -564,7 +730,7 @@ function sleep(ms) {
|
|
|
564
730
|
}
|
|
565
731
|
|
|
566
732
|
// src/version.ts
|
|
567
|
-
var VERSION = "1.
|
|
733
|
+
var VERSION = "1.6.0";
|
|
568
734
|
var USER_AGENT = `cosmoner-node/${VERSION}`;
|
|
569
735
|
|
|
570
736
|
// src/transport.ts
|
|
@@ -611,6 +777,7 @@ var Transport = class {
|
|
|
611
777
|
}
|
|
612
778
|
/** Parses a successful response body, or throws the mapped API error. */
|
|
613
779
|
async decode(response) {
|
|
780
|
+
if (response.status === 204) return void 0;
|
|
614
781
|
let body;
|
|
615
782
|
try {
|
|
616
783
|
body = await response.json();
|
|
@@ -689,6 +856,8 @@ var Cosmoner = class {
|
|
|
689
856
|
this.apps = new AppsService(this.transport, this.config);
|
|
690
857
|
this.email = new EmailService(this.transport, this.config);
|
|
691
858
|
this.hosting = new HostingService(this.transport, this.config);
|
|
859
|
+
this.secrets = new SecretsService(this.transport, this.config);
|
|
860
|
+
this.variables = new VariablesService(this.transport, this.config);
|
|
692
861
|
this.webhooks = new WebhooksService(this.transport, this.config);
|
|
693
862
|
}
|
|
694
863
|
};
|
|
@@ -1050,11 +1219,14 @@ export {
|
|
|
1050
1219
|
InsufficientScopeError,
|
|
1051
1220
|
MAX_DEPLOYMENT_BYTES,
|
|
1052
1221
|
NotFoundError,
|
|
1222
|
+
PROJECT_ENVIRONMENTS,
|
|
1053
1223
|
RateLimitError,
|
|
1054
1224
|
SIGNATURE_HEADER,
|
|
1225
|
+
SecretsService,
|
|
1055
1226
|
ServerError,
|
|
1056
1227
|
VERSION,
|
|
1057
1228
|
ValidationError,
|
|
1229
|
+
VariablesService,
|
|
1058
1230
|
WEBHOOK_EVENT_TYPES,
|
|
1059
1231
|
WebhookSignatureError,
|
|
1060
1232
|
WebhooksService,
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Shapes and rules shared by the `secrets` and `variables` namespaces. */
|
|
2
|
+
/**
|
|
3
|
+
* Which environment an entry resolves against.
|
|
4
|
+
*
|
|
5
|
+
* `default` applies everywhere unless an environment-specific entry of the
|
|
6
|
+
* same name exists, which then wins.
|
|
7
|
+
*/
|
|
8
|
+
export type ProjectEnvironment = "default" | "development" | "staging" | "production";
|
|
9
|
+
/** Every environment the API accepts. */
|
|
10
|
+
export declare const PROJECT_ENVIRONMENTS: readonly ProjectEnvironment[];
|
|
11
|
+
/** A project member, as embedded in the audit fields of a secret or variable. */
|
|
12
|
+
export interface Actor {
|
|
13
|
+
id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
email: string;
|
|
16
|
+
}
|
|
17
|
+
/** Rejects a name the API would reject, using the message the API would send. */
|
|
18
|
+
export declare function requireEntryName(name: string): void;
|
|
19
|
+
/** Rejects a value the API would reject. */
|
|
20
|
+
export declare function requireEntryValue(value: string): void;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/** Secrets service namespace — encrypted project configuration, revealed only as it is set. */
|
|
2
|
+
import { type ResolvedConfig } from "../config";
|
|
3
|
+
import type { Transport } from "../transport";
|
|
4
|
+
import { type Actor, type ProjectEnvironment } from "./project-config";
|
|
5
|
+
/**
|
|
6
|
+
* A secret's metadata.
|
|
7
|
+
*
|
|
8
|
+
* The value is deliberately absent: it is encrypted at rest and returned
|
|
9
|
+
* exactly once, by the call that sets it. Reads describe the secret without
|
|
10
|
+
* ever handing the plaintext back, and no API route decrypts one.
|
|
11
|
+
*/
|
|
12
|
+
export interface ProjectSecret {
|
|
13
|
+
id: string;
|
|
14
|
+
/** Uppercase, underscore-separated, e.g. `DB_PASSWORD`. */
|
|
15
|
+
name: string;
|
|
16
|
+
description: string | null;
|
|
17
|
+
environment: ProjectEnvironment;
|
|
18
|
+
/** Incremented every time the value is replaced. Starts at 1. */
|
|
19
|
+
version: number;
|
|
20
|
+
/** Id of the member who created it. */
|
|
21
|
+
createdBy: string;
|
|
22
|
+
/** Id of the member who last changed it. */
|
|
23
|
+
updatedBy: string;
|
|
24
|
+
createdByUser: Actor;
|
|
25
|
+
updatedByUser: Actor;
|
|
26
|
+
createdAt: string;
|
|
27
|
+
updatedAt: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* A secret together with its plaintext value, returned once at the moment it
|
|
31
|
+
* is set.
|
|
32
|
+
*
|
|
33
|
+
* There is no way to read the value back afterwards, so a caller that discards
|
|
34
|
+
* this response has to set a new value rather than recover this one.
|
|
35
|
+
*/
|
|
36
|
+
export interface RevealedProjectSecret {
|
|
37
|
+
id: string;
|
|
38
|
+
name: string;
|
|
39
|
+
description: string | null;
|
|
40
|
+
environment: ProjectEnvironment;
|
|
41
|
+
version: number;
|
|
42
|
+
/** Present on create. */
|
|
43
|
+
createdAt?: string;
|
|
44
|
+
/** Present on update. */
|
|
45
|
+
updatedAt?: string;
|
|
46
|
+
/** The plaintext value. Returned only here — store it before discarding the response. */
|
|
47
|
+
value: string;
|
|
48
|
+
/** The value with its middle replaced, e.g. `su••••et`. Safe to display. */
|
|
49
|
+
maskedValue: string;
|
|
50
|
+
}
|
|
51
|
+
/** Secret capacity and what it costs to add more. */
|
|
52
|
+
export interface SecretsUsage {
|
|
53
|
+
/** Secrets currently stored on the project. */
|
|
54
|
+
used: number;
|
|
55
|
+
/** How many the project may store, free allowance plus purchased packs. */
|
|
56
|
+
limit: number;
|
|
57
|
+
/** Secrets included before any pack is bought. */
|
|
58
|
+
freeLimit: number;
|
|
59
|
+
/** How many secrets one pack adds. */
|
|
60
|
+
packSize: number;
|
|
61
|
+
/** Packs currently on the subscription. */
|
|
62
|
+
paidPacks: number;
|
|
63
|
+
/** Null when pack pricing is unavailable. */
|
|
64
|
+
packPrice: {
|
|
65
|
+
monthly: number;
|
|
66
|
+
currency: string;
|
|
67
|
+
} | null;
|
|
68
|
+
}
|
|
69
|
+
/** One entry in a secret's audit trail. Values never appear here — only who did what, and when. */
|
|
70
|
+
export interface SecretAuditEntry {
|
|
71
|
+
id: string;
|
|
72
|
+
secretId: string;
|
|
73
|
+
action: "CREATED" | "UPDATED" | "DELETED";
|
|
74
|
+
actorId: string;
|
|
75
|
+
actor: Actor;
|
|
76
|
+
metadata: string | null;
|
|
77
|
+
createdAt: string;
|
|
78
|
+
}
|
|
79
|
+
/** Options accepted by every method, for working across projects. */
|
|
80
|
+
export interface ProjectScopedParams {
|
|
81
|
+
/** Overrides the client-level default project for this call. */
|
|
82
|
+
projectId?: string;
|
|
83
|
+
}
|
|
84
|
+
/** Arguments accepted by `client.secrets.list()`. */
|
|
85
|
+
export interface ListSecretsParams extends ProjectScopedParams {
|
|
86
|
+
/** Limits the list to one environment. Omit to list them all. */
|
|
87
|
+
environment?: ProjectEnvironment;
|
|
88
|
+
}
|
|
89
|
+
/** Arguments accepted by `client.secrets.create()`. */
|
|
90
|
+
export interface CreateSecretParams extends ProjectScopedParams {
|
|
91
|
+
/** Uppercase, underscore-separated, e.g. `DB_PASSWORD`. */
|
|
92
|
+
name: string;
|
|
93
|
+
value: string;
|
|
94
|
+
description?: string;
|
|
95
|
+
/** Defaults to `default` server-side. */
|
|
96
|
+
environment?: ProjectEnvironment;
|
|
97
|
+
}
|
|
98
|
+
/** Arguments accepted by `client.secrets.update()`. */
|
|
99
|
+
export interface UpdateSecretParams extends ProjectScopedParams {
|
|
100
|
+
/** Replaces the stored value and bumps `version`. */
|
|
101
|
+
value: string;
|
|
102
|
+
description?: string;
|
|
103
|
+
}
|
|
104
|
+
interface Envelope<T> {
|
|
105
|
+
success: true;
|
|
106
|
+
data: T;
|
|
107
|
+
}
|
|
108
|
+
export type ListSecretsResponse = Envelope<ProjectSecret[]>;
|
|
109
|
+
export type GetSecretResponse = Envelope<ProjectSecret>;
|
|
110
|
+
export type SetSecretResponse = Envelope<RevealedProjectSecret>;
|
|
111
|
+
export type GetSecretsUsageResponse = Envelope<SecretsUsage>;
|
|
112
|
+
export type GetSecretAuditResponse = Envelope<SecretAuditEntry[]>;
|
|
113
|
+
/**
|
|
114
|
+
* Manages a project's secrets.
|
|
115
|
+
*
|
|
116
|
+
* Reads need `secrets:read`. Writes need `secrets:write` *and* an owner or
|
|
117
|
+
* admin: the API checks the member's role independently of the key's scopes,
|
|
118
|
+
* so a plain member's key is refused even when it carries the scope.
|
|
119
|
+
*/
|
|
120
|
+
export declare class SecretsService {
|
|
121
|
+
private readonly transport;
|
|
122
|
+
private readonly config;
|
|
123
|
+
constructor(transport: Transport, config: ResolvedConfig);
|
|
124
|
+
/** Builds the collection route for the resolved project. */
|
|
125
|
+
private basePath;
|
|
126
|
+
/** Lists the project's secrets as metadata. Values are never included. */
|
|
127
|
+
list(params?: ListSecretsParams): Promise<ListSecretsResponse>;
|
|
128
|
+
/** Fetches one secret's metadata. The value is not part of the response. */
|
|
129
|
+
get(secretId: string, params?: ProjectScopedParams): Promise<GetSecretResponse>;
|
|
130
|
+
/**
|
|
131
|
+
* Stores a new secret, and returns its plaintext value once.
|
|
132
|
+
*
|
|
133
|
+
* Creation is rate-limited to 10 requests per 10 minutes, so a loop that
|
|
134
|
+
* imports many secrets will meet a `RateLimitError`. A project at its limit
|
|
135
|
+
* answers 402 — see `usage()`.
|
|
136
|
+
*/
|
|
137
|
+
create(params: CreateSecretParams): Promise<SetSecretResponse>;
|
|
138
|
+
/** Replaces a secret's value, bumps its version, and returns the new value once. */
|
|
139
|
+
update(secretId: string, params: UpdateSecretParams): Promise<SetSecretResponse>;
|
|
140
|
+
/** Permanently removes a secret. The API answers 204, so there is nothing to return. */
|
|
141
|
+
delete(secretId: string, params?: ProjectScopedParams): Promise<void>;
|
|
142
|
+
/** Reports how many secrets the project holds, how many it may hold, and the price of more. */
|
|
143
|
+
usage(params?: ProjectScopedParams): Promise<GetSecretsUsageResponse>;
|
|
144
|
+
/** Reads a secret's audit trail: who changed it and when, never what it was changed to. */
|
|
145
|
+
audit(secretId: string, params?: ProjectScopedParams): Promise<GetSecretAuditResponse>;
|
|
146
|
+
}
|
|
147
|
+
export {};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/** Variables service namespace — non-sensitive project configuration, held in plaintext. */
|
|
2
|
+
import { type ResolvedConfig } from "../config";
|
|
3
|
+
import type { Transport } from "../transport";
|
|
4
|
+
import { type Actor, type ProjectEnvironment } from "./project-config";
|
|
5
|
+
/**
|
|
6
|
+
* A project variable: non-sensitive configuration held in plaintext.
|
|
7
|
+
*
|
|
8
|
+
* Unlike a secret, the value is returned in full on every read. That is the
|
|
9
|
+
* difference between the two resources, not an oversight — anything worth
|
|
10
|
+
* hiding belongs in `client.secrets`.
|
|
11
|
+
*/
|
|
12
|
+
export interface ProjectVariable {
|
|
13
|
+
id: string;
|
|
14
|
+
/** Uppercase, underscore-separated, e.g. `LOG_LEVEL`. */
|
|
15
|
+
name: string;
|
|
16
|
+
description: string | null;
|
|
17
|
+
value: string;
|
|
18
|
+
environment: ProjectEnvironment;
|
|
19
|
+
/** Id of the member who created it. */
|
|
20
|
+
createdBy: string;
|
|
21
|
+
/** Id of the member who last changed it. */
|
|
22
|
+
updatedBy: string;
|
|
23
|
+
createdByUser: Actor;
|
|
24
|
+
updatedByUser: Actor;
|
|
25
|
+
createdAt: string;
|
|
26
|
+
updatedAt: string;
|
|
27
|
+
}
|
|
28
|
+
/** Options accepted by every method, for working across projects. */
|
|
29
|
+
export interface ProjectScopedParams {
|
|
30
|
+
/** Overrides the client-level default project for this call. */
|
|
31
|
+
projectId?: string;
|
|
32
|
+
}
|
|
33
|
+
/** Arguments accepted by `client.variables.list()`. */
|
|
34
|
+
export interface ListVariablesParams extends ProjectScopedParams {
|
|
35
|
+
/** Limits the list to one environment. Omit to list them all. */
|
|
36
|
+
environment?: ProjectEnvironment;
|
|
37
|
+
}
|
|
38
|
+
/** Arguments accepted by `client.variables.create()`. */
|
|
39
|
+
export interface CreateVariableParams extends ProjectScopedParams {
|
|
40
|
+
/** Uppercase, underscore-separated, e.g. `LOG_LEVEL`. */
|
|
41
|
+
name: string;
|
|
42
|
+
value: string;
|
|
43
|
+
description?: string;
|
|
44
|
+
/** Defaults to `default` server-side. */
|
|
45
|
+
environment?: ProjectEnvironment;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Arguments accepted by `client.variables.update()`.
|
|
49
|
+
*
|
|
50
|
+
* Both fields are optional, but at least one has to be present — unlike a
|
|
51
|
+
* secret, a variable can have its description changed without resetting its
|
|
52
|
+
* value.
|
|
53
|
+
*/
|
|
54
|
+
export interface UpdateVariableParams extends ProjectScopedParams {
|
|
55
|
+
value?: string;
|
|
56
|
+
description?: string;
|
|
57
|
+
}
|
|
58
|
+
interface Envelope<T> {
|
|
59
|
+
success: true;
|
|
60
|
+
data: T;
|
|
61
|
+
}
|
|
62
|
+
export type ListVariablesResponse = Envelope<ProjectVariable[]>;
|
|
63
|
+
export type GetVariableResponse = Envelope<ProjectVariable>;
|
|
64
|
+
export type SetVariableResponse = Envelope<ProjectVariable>;
|
|
65
|
+
/**
|
|
66
|
+
* Manages a project's variables.
|
|
67
|
+
*
|
|
68
|
+
* Reads need `variables:read`. Writes need `variables:write` *and* an owner or
|
|
69
|
+
* admin: the API checks the member's role independently of the key's scopes,
|
|
70
|
+
* so a plain member's key is refused even when it carries the scope.
|
|
71
|
+
*/
|
|
72
|
+
export declare class VariablesService {
|
|
73
|
+
private readonly transport;
|
|
74
|
+
private readonly config;
|
|
75
|
+
constructor(transport: Transport, config: ResolvedConfig);
|
|
76
|
+
/** Builds the collection route for the resolved project. */
|
|
77
|
+
private basePath;
|
|
78
|
+
/** Lists the project's variables, values included. */
|
|
79
|
+
list(params?: ListVariablesParams): Promise<ListVariablesResponse>;
|
|
80
|
+
/** Fetches one variable, value included. */
|
|
81
|
+
get(variableId: string, params?: ProjectScopedParams): Promise<GetVariableResponse>;
|
|
82
|
+
/** Stores a new variable. */
|
|
83
|
+
create(params: CreateVariableParams): Promise<SetVariableResponse>;
|
|
84
|
+
/** Changes a variable's value, its description, or both. */
|
|
85
|
+
update(variableId: string, params: UpdateVariableParams): Promise<SetVariableResponse>;
|
|
86
|
+
/** Permanently removes a variable. The API answers 204, so there is nothing to return. */
|
|
87
|
+
delete(variableId: string, params?: ProjectScopedParams): Promise<void>;
|
|
88
|
+
}
|
|
89
|
+
export {};
|
package/dist/version.d.ts
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
* the release workflow runs that straight after `npm version`, and
|
|
9
9
|
* `version.test.ts` fails the build if the two ever disagree.
|
|
10
10
|
*/
|
|
11
|
-
export declare const VERSION = "1.
|
|
12
|
-
export declare const USER_AGENT = "cosmoner-node/1.
|
|
11
|
+
export declare const VERSION = "1.6.0";
|
|
12
|
+
export declare const USER_AGENT = "cosmoner-node/1.6.0";
|