@cosmoner/sdk 1.3.0 → 1.4.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,21 @@ 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
+
127
142
  ## Deployment files
128
143
 
129
144
  Validates a `.cosmoner/deployment.yaml` — the file you commit to describe how a
package/dist/client.d.ts CHANGED
@@ -2,6 +2,7 @@
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";
5
6
  import { WebhooksService } from "./services/webhooks";
6
7
  /**
7
8
  * Cosmoner API client.
@@ -25,6 +26,7 @@ export declare class Cosmoner {
25
26
  private readonly transport;
26
27
  readonly apps: AppsService;
27
28
  readonly email: EmailService;
29
+ readonly hosting: HostingService;
28
30
  readonly webhooks: WebhooksService;
29
31
  constructor(config: CosmonerConfig);
30
32
  }
package/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@ 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";
10
11
  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
12
  export { constructEvent, DEFAULT_TOLERANCE_SECONDS, DELIVERY_ID_HEADER, EVENT_TYPE_HEADER, SIGNATURE_HEADER, verifyWebhookSignature, type VerifyWebhookParams, type WebhookEvent, } from "./webhooks/signature";
12
13
  export { VERSION } from "./version";
package/dist/index.js CHANGED
@@ -39,6 +39,7 @@ __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,
@@ -208,6 +209,38 @@ var EmailService = class {
208
209
  }
209
210
  };
210
211
 
212
+ // src/services/hosting.ts
213
+ var HostingService = class {
214
+ constructor(transport, config) {
215
+ this.transport = transport;
216
+ this.config = config;
217
+ }
218
+ /** Builds the collection route for the resolved project. */
219
+ basePath(projectId) {
220
+ return `/v1/projects/${resolveProjectId(this.config, projectId)}/hosting/shared`;
221
+ }
222
+ /** Lists every hosting site in the project that has not been deprovisioned. */
223
+ async list(params = {}) {
224
+ return this.transport.request("GET", this.basePath(params.projectId));
225
+ }
226
+ async get(siteId, params = {}) {
227
+ if (!siteId) throw new Error("siteId is required");
228
+ return this.transport.request(
229
+ "GET",
230
+ `${this.basePath(params.projectId)}/${siteId}`,
231
+ { query: params.credentials ? { credentials: "true" } : void 0 }
232
+ );
233
+ }
234
+ /** Fetches the host, port and username for SFTP and SSH. */
235
+ async access(siteId, params = {}) {
236
+ if (!siteId) throw new Error("siteId is required");
237
+ return this.transport.request(
238
+ "GET",
239
+ `${this.basePath(params.projectId)}/${siteId}/access`
240
+ );
241
+ }
242
+ };
243
+
211
244
  // src/webhooks/signature.ts
212
245
  var import_node_crypto = require("crypto");
213
246
 
@@ -592,7 +625,7 @@ function sleep(ms) {
592
625
  }
593
626
 
594
627
  // src/version.ts
595
- var VERSION = "1.3.0";
628
+ var VERSION = "1.4.0";
596
629
  var USER_AGENT = `cosmoner-node/${VERSION}`;
597
630
 
598
631
  // src/transport.ts
@@ -716,6 +749,7 @@ var Cosmoner = class {
716
749
  this.transport = new Transport(this.config);
717
750
  this.apps = new AppsService(this.transport, this.config);
718
751
  this.email = new EmailService(this.transport, this.config);
752
+ this.hosting = new HostingService(this.transport, this.config);
719
753
  this.webhooks = new WebhooksService(this.transport, this.config);
720
754
  }
721
755
  };
@@ -1074,6 +1108,7 @@ var index_default = Cosmoner;
1074
1108
  EVENT_TYPE_HEADER,
1075
1109
  EmailService,
1076
1110
  FINISHED_DEPLOYMENT_PHASES,
1111
+ HostingService,
1077
1112
  InsufficientScopeError,
1078
1113
  MAX_DEPLOYMENT_BYTES,
1079
1114
  NotFoundError,
package/dist/index.mjs CHANGED
@@ -148,6 +148,38 @@ 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
+
151
183
  // src/webhooks/signature.ts
152
184
  import { createHmac, timingSafeEqual } from "crypto";
153
185
 
@@ -532,7 +564,7 @@ function sleep(ms) {
532
564
  }
533
565
 
534
566
  // src/version.ts
535
- var VERSION = "1.3.0";
567
+ var VERSION = "1.4.0";
536
568
  var USER_AGENT = `cosmoner-node/${VERSION}`;
537
569
 
538
570
  // src/transport.ts
@@ -656,6 +688,7 @@ var Cosmoner = class {
656
688
  this.transport = new Transport(this.config);
657
689
  this.apps = new AppsService(this.transport, this.config);
658
690
  this.email = new EmailService(this.transport, this.config);
691
+ this.hosting = new HostingService(this.transport, this.config);
659
692
  this.webhooks = new WebhooksService(this.transport, this.config);
660
693
  }
661
694
  };
@@ -1013,6 +1046,7 @@ export {
1013
1046
  EVENT_TYPE_HEADER,
1014
1047
  EmailService,
1015
1048
  FINISHED_DEPLOYMENT_PHASES,
1049
+ HostingService,
1016
1050
  InsufficientScopeError,
1017
1051
  MAX_DEPLOYMENT_BYTES,
1018
1052
  NotFoundError,
@@ -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 {};
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.4.0";
12
+ export declare const USER_AGENT = "cosmoner-node/1.4.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cosmoner/sdk",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "Cosmoner SDK for Node.js",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",