@cosmoner/sdk 1.3.0 → 1.5.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 CHANGED
@@ -124,6 +124,71 @@ Needs `apps:read`.
124
124
  `client.apps.list()` and `client.apps.getDeployment(appId, deploymentId)` are
125
125
  the single calls underneath.
126
126
 
127
+ ## Hosting
128
+
129
+ Reads a project's shared hosting sites and where to reach their files. Needs an
130
+ API key with `hosting:read`.
131
+
132
+ ```ts
133
+ const { data: sites } = await client.hosting.list();
134
+ const { data: access } = await client.hosting.access(sites[0].id);
135
+ // access.username, access.host, access.sftp.port, access.ssh.{port,enabled}
136
+ ```
137
+
138
+ `client.hosting.get(siteId, { credentials: true })` also returns the site's
139
+ `sftpPassword`. It needs no scope beyond `hosting:read`, so guard the key
140
+ accordingly.
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
+
127
192
  ## Deployment files
128
193
 
129
194
  Validates a `.cosmoner/deployment.yaml` — the file you commit to describe how a
package/dist/client.d.ts CHANGED
@@ -2,6 +2,9 @@
2
2
  import { type CosmonerConfig } from "./config";
3
3
  import { AppsService } from "./services/apps";
4
4
  import { EmailService } from "./services/email";
5
+ import { HostingService } from "./services/hosting";
6
+ import { SecretsService } from "./services/secrets";
7
+ import { VariablesService } from "./services/variables";
5
8
  import { WebhooksService } from "./services/webhooks";
6
9
  /**
7
10
  * Cosmoner API client.
@@ -25,6 +28,9 @@ export declare class Cosmoner {
25
28
  private readonly transport;
26
29
  readonly apps: AppsService;
27
30
  readonly email: EmailService;
31
+ readonly hosting: HostingService;
32
+ readonly secrets: SecretsService;
33
+ readonly variables: VariablesService;
28
34
  readonly webhooks: WebhooksService;
29
35
  constructor(config: CosmonerConfig);
30
36
  }
package/dist/index.d.ts CHANGED
@@ -7,6 +7,10 @@ export { validateDeployment, validateDeploymentDocument, } from "./deployment/va
7
7
  export type { DeploymentBuild, DeploymentEnvVar, DeploymentIssue, DeploymentIssueSeverity, DeploymentService, DeploymentTemplate, DeploymentValidationResult, ValidateDeploymentOptions, } from "./deployment/types";
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
+ 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";
10
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";
11
15
  export { constructEvent, DEFAULT_TOLERANCE_SECONDS, DELIVERY_ID_HEADER, EVENT_TYPE_HEADER, SIGNATURE_HEADER, verifyWebhookSignature, type VerifyWebhookParams, type WebhookEvent, } from "./webhooks/signature";
12
16
  export { VERSION } from "./version";
package/dist/index.js CHANGED
@@ -39,14 +39,18 @@ __export(index_exports, {
39
39
  EVENT_TYPE_HEADER: () => EVENT_TYPE_HEADER,
40
40
  EmailService: () => EmailService,
41
41
  FINISHED_DEPLOYMENT_PHASES: () => FINISHED_DEPLOYMENT_PHASES,
42
+ HostingService: () => HostingService,
42
43
  InsufficientScopeError: () => InsufficientScopeError,
43
44
  MAX_DEPLOYMENT_BYTES: () => MAX_DEPLOYMENT_BYTES,
44
45
  NotFoundError: () => NotFoundError,
46
+ PROJECT_ENVIRONMENTS: () => PROJECT_ENVIRONMENTS,
45
47
  RateLimitError: () => RateLimitError,
46
48
  SIGNATURE_HEADER: () => SIGNATURE_HEADER,
49
+ SecretsService: () => SecretsService,
47
50
  ServerError: () => ServerError,
48
51
  VERSION: () => VERSION,
49
52
  ValidationError: () => ValidationError,
53
+ VariablesService: () => VariablesService,
50
54
  WEBHOOK_EVENT_TYPES: () => WEBHOOK_EVENT_TYPES,
51
55
  WebhookSignatureError: () => WebhookSignatureError,
52
56
  WebhooksService: () => WebhooksService,
@@ -208,6 +212,204 @@ var EmailService = class {
208
212
  }
209
213
  };
210
214
 
215
+ // src/services/hosting.ts
216
+ var HostingService = class {
217
+ constructor(transport, config) {
218
+ this.transport = transport;
219
+ this.config = config;
220
+ }
221
+ /** Builds the collection route for the resolved project. */
222
+ basePath(projectId) {
223
+ return `/v1/projects/${resolveProjectId(this.config, projectId)}/hosting/shared`;
224
+ }
225
+ /** Lists every hosting site in the project that has not been deprovisioned. */
226
+ async list(params = {}) {
227
+ return this.transport.request("GET", this.basePath(params.projectId));
228
+ }
229
+ async get(siteId, params = {}) {
230
+ if (!siteId) throw new Error("siteId is required");
231
+ return this.transport.request(
232
+ "GET",
233
+ `${this.basePath(params.projectId)}/${siteId}`,
234
+ { query: params.credentials ? { credentials: "true" } : void 0 }
235
+ );
236
+ }
237
+ /** Fetches the host, port and username for SFTP and SSH. */
238
+ async access(siteId, params = {}) {
239
+ if (!siteId) throw new Error("siteId is required");
240
+ return this.transport.request(
241
+ "GET",
242
+ `${this.basePath(params.projectId)}/${siteId}/access`
243
+ );
244
+ }
245
+ };
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
+
211
413
  // src/webhooks/signature.ts
212
414
  var import_node_crypto = require("crypto");
213
415
 
@@ -592,7 +794,7 @@ function sleep(ms) {
592
794
  }
593
795
 
594
796
  // src/version.ts
595
- var VERSION = "1.3.0";
797
+ var VERSION = "1.5.0";
596
798
  var USER_AGENT = `cosmoner-node/${VERSION}`;
597
799
 
598
800
  // src/transport.ts
@@ -639,6 +841,7 @@ var Transport = class {
639
841
  }
640
842
  /** Parses a successful response body, or throws the mapped API error. */
641
843
  async decode(response) {
844
+ if (response.status === 204) return void 0;
642
845
  let body;
643
846
  try {
644
847
  body = await response.json();
@@ -716,6 +919,9 @@ var Cosmoner = class {
716
919
  this.transport = new Transport(this.config);
717
920
  this.apps = new AppsService(this.transport, this.config);
718
921
  this.email = new EmailService(this.transport, this.config);
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);
719
925
  this.webhooks = new WebhooksService(this.transport, this.config);
720
926
  }
721
927
  };
@@ -1074,14 +1280,18 @@ var index_default = Cosmoner;
1074
1280
  EVENT_TYPE_HEADER,
1075
1281
  EmailService,
1076
1282
  FINISHED_DEPLOYMENT_PHASES,
1283
+ HostingService,
1077
1284
  InsufficientScopeError,
1078
1285
  MAX_DEPLOYMENT_BYTES,
1079
1286
  NotFoundError,
1287
+ PROJECT_ENVIRONMENTS,
1080
1288
  RateLimitError,
1081
1289
  SIGNATURE_HEADER,
1290
+ SecretsService,
1082
1291
  ServerError,
1083
1292
  VERSION,
1084
1293
  ValidationError,
1294
+ VariablesService,
1085
1295
  WEBHOOK_EVENT_TYPES,
1086
1296
  WebhookSignatureError,
1087
1297
  WebhooksService,
package/dist/index.mjs CHANGED
@@ -148,6 +148,204 @@ var EmailService = class {
148
148
  }
149
149
  };
150
150
 
151
+ // src/services/hosting.ts
152
+ var HostingService = class {
153
+ constructor(transport, config) {
154
+ this.transport = transport;
155
+ this.config = config;
156
+ }
157
+ /** Builds the collection route for the resolved project. */
158
+ basePath(projectId) {
159
+ return `/v1/projects/${resolveProjectId(this.config, projectId)}/hosting/shared`;
160
+ }
161
+ /** Lists every hosting site in the project that has not been deprovisioned. */
162
+ async list(params = {}) {
163
+ return this.transport.request("GET", this.basePath(params.projectId));
164
+ }
165
+ async get(siteId, params = {}) {
166
+ if (!siteId) throw new Error("siteId is required");
167
+ return this.transport.request(
168
+ "GET",
169
+ `${this.basePath(params.projectId)}/${siteId}`,
170
+ { query: params.credentials ? { credentials: "true" } : void 0 }
171
+ );
172
+ }
173
+ /** Fetches the host, port and username for SFTP and SSH. */
174
+ async access(siteId, params = {}) {
175
+ if (!siteId) throw new Error("siteId is required");
176
+ return this.transport.request(
177
+ "GET",
178
+ `${this.basePath(params.projectId)}/${siteId}/access`
179
+ );
180
+ }
181
+ };
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
+
151
349
  // src/webhooks/signature.ts
152
350
  import { createHmac, timingSafeEqual } from "crypto";
153
351
 
@@ -532,7 +730,7 @@ function sleep(ms) {
532
730
  }
533
731
 
534
732
  // src/version.ts
535
- var VERSION = "1.3.0";
733
+ var VERSION = "1.5.0";
536
734
  var USER_AGENT = `cosmoner-node/${VERSION}`;
537
735
 
538
736
  // src/transport.ts
@@ -579,6 +777,7 @@ var Transport = class {
579
777
  }
580
778
  /** Parses a successful response body, or throws the mapped API error. */
581
779
  async decode(response) {
780
+ if (response.status === 204) return void 0;
582
781
  let body;
583
782
  try {
584
783
  body = await response.json();
@@ -656,6 +855,9 @@ var Cosmoner = class {
656
855
  this.transport = new Transport(this.config);
657
856
  this.apps = new AppsService(this.transport, this.config);
658
857
  this.email = new EmailService(this.transport, this.config);
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);
659
861
  this.webhooks = new WebhooksService(this.transport, this.config);
660
862
  }
661
863
  };
@@ -1013,14 +1215,18 @@ export {
1013
1215
  EVENT_TYPE_HEADER,
1014
1216
  EmailService,
1015
1217
  FINISHED_DEPLOYMENT_PHASES,
1218
+ HostingService,
1016
1219
  InsufficientScopeError,
1017
1220
  MAX_DEPLOYMENT_BYTES,
1018
1221
  NotFoundError,
1222
+ PROJECT_ENVIRONMENTS,
1019
1223
  RateLimitError,
1020
1224
  SIGNATURE_HEADER,
1225
+ SecretsService,
1021
1226
  ServerError,
1022
1227
  VERSION,
1023
1228
  ValidationError,
1229
+ VariablesService,
1024
1230
  WEBHOOK_EVENT_TYPES,
1025
1231
  WebhookSignatureError,
1026
1232
  WebhooksService,
@@ -0,0 +1,90 @@
1
+ /** Hosting service namespace — shared web hosting sites and how to reach their files. */
2
+ import { type ResolvedConfig } from "../config";
3
+ import type { Transport } from "../transport";
4
+ /** Lifecycle state of a hosting site. */
5
+ export type HostingSiteStatus = "PROVISIONING" | "ACTIVE" | "SUSPENDED" | "DEPROVISIONED" | "ERROR";
6
+ /**
7
+ * A shared hosting site as the API lists it.
8
+ *
9
+ * Only the fields a deploy script is likely to read are typed; the API returns
10
+ * more, and they are present on the object at runtime.
11
+ */
12
+ export interface HostingSite {
13
+ id: string;
14
+ siteName: string;
15
+ phpVersion: string;
16
+ /** The SFTP username, null until the site is provisioned. */
17
+ unixUser: string | null;
18
+ /**
19
+ * Absolute path the platform hostname serves, e.g.
20
+ * `/var/www/<unixUser>/<hostname>/public_html`. An SFTP login is chrooted to
21
+ * `/var/www/<unixUser>`, so strip that prefix to get the path a client sees.
22
+ */
23
+ documentRoot: string | null;
24
+ internalHostname: string | null;
25
+ url: string | null;
26
+ tier: string;
27
+ sshEnabled: boolean;
28
+ status: HostingSiteStatus;
29
+ /** Public SFTP/SSH hostname; null when the environment has none configured. */
30
+ sftpHost: string | null;
31
+ sftpPort: number | null;
32
+ createdAt: string;
33
+ }
34
+ /** A site read with `credentials: true`. */
35
+ export interface HostingSiteWithCredentials extends HostingSite {
36
+ /** Null while the site is not ACTIVE. */
37
+ sftpPassword: string | null;
38
+ /** Whether the site's pod is serving right now. */
39
+ ready: boolean;
40
+ }
41
+ /** Where and how to connect to a site's files. */
42
+ export interface HostingAccess {
43
+ username: string | null;
44
+ host: string | null;
45
+ sftp: {
46
+ port: number;
47
+ };
48
+ ssh: {
49
+ port: number;
50
+ enabled: boolean;
51
+ };
52
+ }
53
+ /** Options accepted by every method, for working across projects. */
54
+ export interface ProjectScopedParams {
55
+ /** Overrides the client-level default project for this call. */
56
+ projectId?: string;
57
+ }
58
+ /** Arguments accepted by `client.hosting.get()`. */
59
+ export interface GetHostingSiteParams extends ProjectScopedParams {
60
+ /** Include the SFTP password. Needs only hosting:read, so guard the key accordingly. */
61
+ credentials?: boolean;
62
+ }
63
+ interface Envelope<T> {
64
+ success: true;
65
+ data: T;
66
+ }
67
+ export type ListHostingSitesResponse = Envelope<HostingSite[]>;
68
+ export type GetHostingSiteResponse = Envelope<HostingSite & {
69
+ ready: boolean;
70
+ }>;
71
+ export type GetHostingSiteWithCredentialsResponse = Envelope<HostingSiteWithCredentials>;
72
+ export type GetHostingAccessResponse = Envelope<HostingAccess>;
73
+ /** Read operations on a project's shared hosting sites. */
74
+ export declare class HostingService {
75
+ private readonly transport;
76
+ private readonly config;
77
+ constructor(transport: Transport, config: ResolvedConfig);
78
+ /** Builds the collection route for the resolved project. */
79
+ private basePath;
80
+ /** Lists every hosting site in the project that has not been deprovisioned. */
81
+ list(params?: ProjectScopedParams): Promise<ListHostingSitesResponse>;
82
+ /** Fetches one site, with its SFTP password when `credentials` is true. */
83
+ get(siteId: string, params: GetHostingSiteParams & {
84
+ credentials: true;
85
+ }): Promise<GetHostingSiteWithCredentialsResponse>;
86
+ get(siteId: string, params?: GetHostingSiteParams): Promise<GetHostingSiteResponse>;
87
+ /** Fetches the host, port and username for SFTP and SSH. */
88
+ access(siteId: string, params?: ProjectScopedParams): Promise<GetHostingAccessResponse>;
89
+ }
90
+ export {};
@@ -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.3.0";
12
- export declare const USER_AGENT = "cosmoner-node/1.3.0";
11
+ export declare const VERSION = "1.5.0";
12
+ export declare const USER_AGENT = "cosmoner-node/1.5.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cosmoner/sdk",
3
- "version": "1.3.0",
3
+ "version": "1.5.0",
4
4
  "description": "Cosmoner SDK for Node.js",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",