@cosmoner/sdk 1.2.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
@@ -86,6 +86,59 @@ Set `maxRetries: 0` to disable retries entirely.
86
86
 
87
87
  \* At least one of `html` or `text` must be provided.
88
88
 
89
+ ## Apps
90
+
91
+ ```ts
92
+ const { data: apps } = await client.apps.list();
93
+ const web = apps.find((app) => app.name === "web")!;
94
+
95
+ const { data: started } = await client.apps.deploy(web.id, { tag: "v2" });
96
+ const finished = await client.apps.waitForDeployment(web.id, started.id);
97
+
98
+ if (finished.phase !== "ACTIVE") throw new Error(finished.error ?? finished.phase);
99
+ ```
100
+
101
+ ### `client.apps.deploy(appId, params?)`
102
+
103
+ Starts deploying an image app — one that runs an image from a Cosmoner registry
104
+ — and returns the deployment without waiting. Apps built from a repository are
105
+ refused. Needs an API key with `apps:write`.
106
+
107
+ | Parameter | Type | Required | Description |
108
+ | ----------- | -------- | -------- | ----------------------------------------------------- |
109
+ | `tag` | `string` | No | Tag to deploy from the app's repository |
110
+ | `digest` | `string` | No | Exact image, `sha256:<64 hex characters>` |
111
+ | `projectId` | `string` | No | Overrides the client-level project |
112
+
113
+ Pass `tag` or `digest`, not both. With neither, the image the app already names
114
+ is pulled again.
115
+
116
+ ### `client.apps.waitForDeployment(appId, deploymentId, params?)`
117
+
118
+ Polls until the deployment finishes and resolves with it in its final phase —
119
+ `ACTIVE`, `ERROR`, `CANCELED` or `SUPERSEDED`. It rejects only when a request
120
+ fails or `timeout` (default 10 minutes) passes; the deployment carries on either
121
+ way. `interval` defaults to 3 seconds, and `onPoll` is called with every result.
122
+ Needs `apps:read`.
123
+
124
+ `client.apps.list()` and `client.apps.getDeployment(appId, deploymentId)` are
125
+ the single calls underneath.
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
+
89
142
  ## Deployment files
90
143
 
91
144
  Validates a `.cosmoner/deployment.yaml` — the file you commit to describe how a
package/dist/client.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  /** Entry-point client exposing the API's service namespaces. */
2
2
  import { type CosmonerConfig } from "./config";
3
+ import { AppsService } from "./services/apps";
3
4
  import { EmailService } from "./services/email";
5
+ import { HostingService } from "./services/hosting";
4
6
  import { WebhooksService } from "./services/webhooks";
5
7
  /**
6
8
  * Cosmoner API client.
@@ -22,7 +24,9 @@ export declare class Cosmoner {
22
24
  readonly maxRetries: number;
23
25
  private readonly config;
24
26
  private readonly transport;
27
+ readonly apps: AppsService;
25
28
  readonly email: EmailService;
29
+ readonly hosting: HostingService;
26
30
  readonly webhooks: WebhooksService;
27
31
  constructor(config: CosmonerConfig);
28
32
  }
package/dist/index.d.ts CHANGED
@@ -5,7 +5,9 @@ export { AuthenticationError, ConflictError, CosmonerConnectionError, CosmonerEr
5
5
  export { APP_SCHEMA_URL, DEPLOYMENT_FILE_PATHS, DEPLOYMENT_KEY_ORDER, DEPLOYMENT_VERSION, MAX_DEPLOYMENT_BYTES, } from "./deployment/spec";
6
6
  export { validateDeployment, validateDeploymentDocument, } from "./deployment/validate";
7
7
  export type { DeploymentBuild, DeploymentEnvVar, DeploymentIssue, DeploymentIssueSeverity, DeploymentService, DeploymentTemplate, DeploymentValidationResult, ValidateDeploymentOptions, } from "./deployment/types";
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";
8
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";
9
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";
10
12
  export { constructEvent, DEFAULT_TOLERANCE_SECONDS, DELIVERY_ID_HEADER, EVENT_TYPE_HEADER, SIGNATURE_HEADER, verifyWebhookSignature, type VerifyWebhookParams, type WebhookEvent, } from "./webhooks/signature";
11
13
  export { VERSION } from "./version";
package/dist/index.js CHANGED
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  APP_SCHEMA_URL: () => APP_SCHEMA_URL,
24
+ AppsService: () => AppsService,
24
25
  AuthenticationError: () => AuthenticationError,
25
26
  ConflictError: () => ConflictError,
26
27
  Cosmoner: () => Cosmoner,
@@ -37,6 +38,8 @@ __export(index_exports, {
37
38
  DEPLOYMENT_VERSION: () => DEPLOYMENT_VERSION,
38
39
  EVENT_TYPE_HEADER: () => EVENT_TYPE_HEADER,
39
40
  EmailService: () => EmailService,
41
+ FINISHED_DEPLOYMENT_PHASES: () => FINISHED_DEPLOYMENT_PHASES,
42
+ HostingService: () => HostingService,
40
43
  InsufficientScopeError: () => InsufficientScopeError,
41
44
  MAX_DEPLOYMENT_BYTES: () => MAX_DEPLOYMENT_BYTES,
42
45
  NotFoundError: () => NotFoundError,
@@ -87,6 +90,89 @@ function resolveProjectId(config, override) {
87
90
  return projectId;
88
91
  }
89
92
 
93
+ // src/services/apps.ts
94
+ var FINISHED_DEPLOYMENT_PHASES = [
95
+ "ACTIVE",
96
+ "ERROR",
97
+ "CANCELED",
98
+ "SUPERSEDED"
99
+ ];
100
+ var DEFAULT_POLL_INTERVAL_MS = 3e3;
101
+ var DEFAULT_WAIT_TIMEOUT_MS = 10 * 6e4;
102
+ var TAG_PATTERN = /^[A-Za-z0-9_][A-Za-z0-9_.-]{0,127}$/;
103
+ var DIGEST_PATTERN = /^sha256:[a-f0-9]{64}$/;
104
+ var AppsService = class {
105
+ constructor(transport, config) {
106
+ this.transport = transport;
107
+ this.config = config;
108
+ }
109
+ /** Builds the collection route for the resolved project. */
110
+ basePath(projectId) {
111
+ return `/v1/projects/${resolveProjectId(this.config, projectId)}/apps`;
112
+ }
113
+ /** Lists every app in the project, newest first. */
114
+ async list(params = {}) {
115
+ return this.transport.request("GET", this.basePath(params.projectId));
116
+ }
117
+ /**
118
+ * Starts deploying an image app and returns the deployment without waiting.
119
+ *
120
+ * Only image apps pulling from a Cosmoner registry can be deployed this way;
121
+ * the API rejects apps built from a repository. Pair with
122
+ * `waitForDeployment()` to learn whether the rollout succeeded.
123
+ */
124
+ async deploy(appId, params = {}) {
125
+ if (!appId) throw new Error("appId is required");
126
+ if (params.tag && params.digest) throw new Error("Pass either tag or digest, not both");
127
+ if (params.tag !== void 0 && !TAG_PATTERN.test(params.tag)) {
128
+ throw new Error(`Invalid image tag "${params.tag}"`);
129
+ }
130
+ if (params.digest !== void 0 && !DIGEST_PATTERN.test(params.digest)) {
131
+ throw new Error("digest must be sha256:<64 hex characters>");
132
+ }
133
+ return this.transport.request(
134
+ "POST",
135
+ `${this.basePath(params.projectId)}/${appId}/deployments`,
136
+ { body: { tag: params.tag, digest: params.digest } }
137
+ );
138
+ }
139
+ /** Fetches one deployment's current phase. */
140
+ async getDeployment(appId, deploymentId, params = {}) {
141
+ if (!appId) throw new Error("appId is required");
142
+ if (!deploymentId) throw new Error("deploymentId is required");
143
+ return this.transport.request(
144
+ "GET",
145
+ `${this.basePath(params.projectId)}/${appId}/deployments/${deploymentId}`
146
+ );
147
+ }
148
+ /**
149
+ * Polls a deployment until it finishes, and returns it in its final phase.
150
+ *
151
+ * Resolves for every finished phase, failures included — check `phase` for
152
+ * `ACTIVE`. Rejects only when the request fails or `timeout` passes first,
153
+ * in which case the deployment keeps going server-side.
154
+ */
155
+ async waitForDeployment(appId, deploymentId, params = {}) {
156
+ const interval = params.interval ?? DEFAULT_POLL_INTERVAL_MS;
157
+ const timeout = params.timeout ?? DEFAULT_WAIT_TIMEOUT_MS;
158
+ if (interval <= 0) throw new Error("interval must be greater than 0");
159
+ if (timeout <= 0) throw new Error("timeout must be greater than 0");
160
+ const deadline = Date.now() + timeout;
161
+ for (; ; ) {
162
+ const { data } = await this.getDeployment(appId, deploymentId, params);
163
+ params.onPoll?.(data);
164
+ if (FINISHED_DEPLOYMENT_PHASES.includes(data.phase)) return data;
165
+ const remaining = deadline - Date.now();
166
+ if (remaining <= 0) {
167
+ throw new Error(
168
+ `Deployment ${deploymentId} was still ${data.phase} after ${Math.round(timeout / 1e3)}s`
169
+ );
170
+ }
171
+ await new Promise((resolve) => setTimeout(resolve, Math.min(interval, remaining)));
172
+ }
173
+ }
174
+ };
175
+
90
176
  // src/services/email.ts
91
177
  var EmailService = class {
92
178
  constructor(transport, config) {
@@ -123,6 +209,38 @@ var EmailService = class {
123
209
  }
124
210
  };
125
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
+
126
244
  // src/webhooks/signature.ts
127
245
  var import_node_crypto = require("crypto");
128
246
 
@@ -507,7 +625,7 @@ function sleep(ms) {
507
625
  }
508
626
 
509
627
  // src/version.ts
510
- var VERSION = "1.2.0";
628
+ var VERSION = "1.4.0";
511
629
  var USER_AGENT = `cosmoner-node/${VERSION}`;
512
630
 
513
631
  // src/transport.ts
@@ -629,7 +747,9 @@ var Cosmoner = class {
629
747
  this.timeout = this.config.timeout;
630
748
  this.maxRetries = this.config.maxRetries;
631
749
  this.transport = new Transport(this.config);
750
+ this.apps = new AppsService(this.transport, this.config);
632
751
  this.email = new EmailService(this.transport, this.config);
752
+ this.hosting = new HostingService(this.transport, this.config);
633
753
  this.webhooks = new WebhooksService(this.transport, this.config);
634
754
  }
635
755
  };
@@ -970,6 +1090,7 @@ var index_default = Cosmoner;
970
1090
  // Annotate the CommonJS export names for ESM import in node:
971
1091
  0 && (module.exports = {
972
1092
  APP_SCHEMA_URL,
1093
+ AppsService,
973
1094
  AuthenticationError,
974
1095
  ConflictError,
975
1096
  Cosmoner,
@@ -986,6 +1107,8 @@ var index_default = Cosmoner;
986
1107
  DEPLOYMENT_VERSION,
987
1108
  EVENT_TYPE_HEADER,
988
1109
  EmailService,
1110
+ FINISHED_DEPLOYMENT_PHASES,
1111
+ HostingService,
989
1112
  InsufficientScopeError,
990
1113
  MAX_DEPLOYMENT_BYTES,
991
1114
  NotFoundError,
package/dist/index.mjs CHANGED
@@ -29,6 +29,89 @@ function resolveProjectId(config, override) {
29
29
  return projectId;
30
30
  }
31
31
 
32
+ // src/services/apps.ts
33
+ var FINISHED_DEPLOYMENT_PHASES = [
34
+ "ACTIVE",
35
+ "ERROR",
36
+ "CANCELED",
37
+ "SUPERSEDED"
38
+ ];
39
+ var DEFAULT_POLL_INTERVAL_MS = 3e3;
40
+ var DEFAULT_WAIT_TIMEOUT_MS = 10 * 6e4;
41
+ var TAG_PATTERN = /^[A-Za-z0-9_][A-Za-z0-9_.-]{0,127}$/;
42
+ var DIGEST_PATTERN = /^sha256:[a-f0-9]{64}$/;
43
+ var AppsService = class {
44
+ constructor(transport, config) {
45
+ this.transport = transport;
46
+ this.config = config;
47
+ }
48
+ /** Builds the collection route for the resolved project. */
49
+ basePath(projectId) {
50
+ return `/v1/projects/${resolveProjectId(this.config, projectId)}/apps`;
51
+ }
52
+ /** Lists every app in the project, newest first. */
53
+ async list(params = {}) {
54
+ return this.transport.request("GET", this.basePath(params.projectId));
55
+ }
56
+ /**
57
+ * Starts deploying an image app and returns the deployment without waiting.
58
+ *
59
+ * Only image apps pulling from a Cosmoner registry can be deployed this way;
60
+ * the API rejects apps built from a repository. Pair with
61
+ * `waitForDeployment()` to learn whether the rollout succeeded.
62
+ */
63
+ async deploy(appId, params = {}) {
64
+ if (!appId) throw new Error("appId is required");
65
+ if (params.tag && params.digest) throw new Error("Pass either tag or digest, not both");
66
+ if (params.tag !== void 0 && !TAG_PATTERN.test(params.tag)) {
67
+ throw new Error(`Invalid image tag "${params.tag}"`);
68
+ }
69
+ if (params.digest !== void 0 && !DIGEST_PATTERN.test(params.digest)) {
70
+ throw new Error("digest must be sha256:<64 hex characters>");
71
+ }
72
+ return this.transport.request(
73
+ "POST",
74
+ `${this.basePath(params.projectId)}/${appId}/deployments`,
75
+ { body: { tag: params.tag, digest: params.digest } }
76
+ );
77
+ }
78
+ /** Fetches one deployment's current phase. */
79
+ async getDeployment(appId, deploymentId, params = {}) {
80
+ if (!appId) throw new Error("appId is required");
81
+ if (!deploymentId) throw new Error("deploymentId is required");
82
+ return this.transport.request(
83
+ "GET",
84
+ `${this.basePath(params.projectId)}/${appId}/deployments/${deploymentId}`
85
+ );
86
+ }
87
+ /**
88
+ * Polls a deployment until it finishes, and returns it in its final phase.
89
+ *
90
+ * Resolves for every finished phase, failures included — check `phase` for
91
+ * `ACTIVE`. Rejects only when the request fails or `timeout` passes first,
92
+ * in which case the deployment keeps going server-side.
93
+ */
94
+ async waitForDeployment(appId, deploymentId, params = {}) {
95
+ const interval = params.interval ?? DEFAULT_POLL_INTERVAL_MS;
96
+ const timeout = params.timeout ?? DEFAULT_WAIT_TIMEOUT_MS;
97
+ if (interval <= 0) throw new Error("interval must be greater than 0");
98
+ if (timeout <= 0) throw new Error("timeout must be greater than 0");
99
+ const deadline = Date.now() + timeout;
100
+ for (; ; ) {
101
+ const { data } = await this.getDeployment(appId, deploymentId, params);
102
+ params.onPoll?.(data);
103
+ if (FINISHED_DEPLOYMENT_PHASES.includes(data.phase)) return data;
104
+ const remaining = deadline - Date.now();
105
+ if (remaining <= 0) {
106
+ throw new Error(
107
+ `Deployment ${deploymentId} was still ${data.phase} after ${Math.round(timeout / 1e3)}s`
108
+ );
109
+ }
110
+ await new Promise((resolve) => setTimeout(resolve, Math.min(interval, remaining)));
111
+ }
112
+ }
113
+ };
114
+
32
115
  // src/services/email.ts
33
116
  var EmailService = class {
34
117
  constructor(transport, config) {
@@ -65,6 +148,38 @@ var EmailService = class {
65
148
  }
66
149
  };
67
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
+
68
183
  // src/webhooks/signature.ts
69
184
  import { createHmac, timingSafeEqual } from "crypto";
70
185
 
@@ -449,7 +564,7 @@ function sleep(ms) {
449
564
  }
450
565
 
451
566
  // src/version.ts
452
- var VERSION = "1.2.0";
567
+ var VERSION = "1.4.0";
453
568
  var USER_AGENT = `cosmoner-node/${VERSION}`;
454
569
 
455
570
  // src/transport.ts
@@ -571,7 +686,9 @@ var Cosmoner = class {
571
686
  this.timeout = this.config.timeout;
572
687
  this.maxRetries = this.config.maxRetries;
573
688
  this.transport = new Transport(this.config);
689
+ this.apps = new AppsService(this.transport, this.config);
574
690
  this.email = new EmailService(this.transport, this.config);
691
+ this.hosting = new HostingService(this.transport, this.config);
575
692
  this.webhooks = new WebhooksService(this.transport, this.config);
576
693
  }
577
694
  };
@@ -911,6 +1028,7 @@ function result(issues, template, options) {
911
1028
  var index_default = Cosmoner;
912
1029
  export {
913
1030
  APP_SCHEMA_URL,
1031
+ AppsService,
914
1032
  AuthenticationError,
915
1033
  ConflictError,
916
1034
  Cosmoner,
@@ -927,6 +1045,8 @@ export {
927
1045
  DEPLOYMENT_VERSION,
928
1046
  EVENT_TYPE_HEADER,
929
1047
  EmailService,
1048
+ FINISHED_DEPLOYMENT_PHASES,
1049
+ HostingService,
930
1050
  InsufficientScopeError,
931
1051
  MAX_DEPLOYMENT_BYTES,
932
1052
  NotFoundError,
@@ -0,0 +1,105 @@
1
+ /** Apps service namespace — finding apps and rolling image apps onto a new image. */
2
+ import { type ResolvedConfig } from "../config";
3
+ import type { Transport } from "../transport";
4
+ /** Lifecycle state of an app as a whole. */
5
+ export type AppStatus = "DEPLOYING" | "RUNNING" | "STOPPED" | "ERROR" | "TERMINATED";
6
+ /** What a registry push does to an image app. */
7
+ export type ImageDeployPolicy = "TAG" | "NEWEST" | "MANUAL";
8
+ /**
9
+ * An app as the API lists it.
10
+ *
11
+ * Only the fields a deploy script is likely to read are typed; the API returns
12
+ * more, and they are present on the object at runtime.
13
+ */
14
+ export interface App {
15
+ id: string;
16
+ name: string;
17
+ subdomain: string;
18
+ status: AppStatus;
19
+ url: string | null;
20
+ /** Set for apps built from a repository, null for image apps. */
21
+ gitRepo: string | null;
22
+ /** The image an image app runs, null for apps built from a repository. */
23
+ containerImage: string | null;
24
+ imageDeployPolicy: ImageDeployPolicy;
25
+ createdAt: string;
26
+ updatedAt: string;
27
+ }
28
+ /** Phase of one deployment. */
29
+ export type DeploymentPhase = "PENDING" | "BUILDING" | "DEPLOYING" | "ACTIVE" | "ERROR" | "CANCELED" | "SUPERSEDED";
30
+ /** Phases after which a deployment will not change again. */
31
+ export declare const FINISHED_DEPLOYMENT_PHASES: readonly DeploymentPhase[];
32
+ /** One deployment of an app. */
33
+ export interface AppDeployment {
34
+ id: string;
35
+ phase: DeploymentPhase;
36
+ /** Why it happened, e.g. "registry push" or "api deploy". */
37
+ cause: string | null;
38
+ /** The image reference that was deployed. */
39
+ imageRef: string | null;
40
+ imageDigest: string | null;
41
+ error: string | null;
42
+ startedAt: string;
43
+ finishedAt: string | null;
44
+ }
45
+ /** Options accepted by every method, for working across projects. */
46
+ export interface ProjectScopedParams {
47
+ /** Overrides the client-level default project for this call. */
48
+ projectId?: string;
49
+ }
50
+ /**
51
+ * Arguments accepted by `client.apps.deploy()`.
52
+ *
53
+ * Pass `tag` or `digest` to roll onto that image from the repository the app
54
+ * already pulls from, or neither to re-resolve the image the app names now.
55
+ */
56
+ export interface DeployAppParams extends ProjectScopedParams {
57
+ tag?: string;
58
+ /** `sha256:` followed by 64 hex characters. */
59
+ digest?: string;
60
+ }
61
+ /** Options accepted by `client.apps.waitForDeployment()`. */
62
+ export interface WaitForDeploymentParams extends ProjectScopedParams {
63
+ /** Milliseconds between polls. Defaults to 3s. */
64
+ interval?: number;
65
+ /** Milliseconds to wait in total before giving up. Defaults to 10 minutes. */
66
+ timeout?: number;
67
+ /** Called with every poll result, including the last. */
68
+ onPoll?: (deployment: AppDeployment) => void;
69
+ }
70
+ interface Envelope<T> {
71
+ success: true;
72
+ data: T;
73
+ }
74
+ export type ListAppsResponse = Envelope<App[]>;
75
+ export type DeployAppResponse = Envelope<AppDeployment>;
76
+ export type GetDeploymentResponse = Envelope<AppDeployment>;
77
+ /** App lookup and image deploy operations for a project. */
78
+ export declare class AppsService {
79
+ private readonly transport;
80
+ private readonly config;
81
+ constructor(transport: Transport, config: ResolvedConfig);
82
+ /** Builds the collection route for the resolved project. */
83
+ private basePath;
84
+ /** Lists every app in the project, newest first. */
85
+ list(params?: ProjectScopedParams): Promise<ListAppsResponse>;
86
+ /**
87
+ * Starts deploying an image app and returns the deployment without waiting.
88
+ *
89
+ * Only image apps pulling from a Cosmoner registry can be deployed this way;
90
+ * the API rejects apps built from a repository. Pair with
91
+ * `waitForDeployment()` to learn whether the rollout succeeded.
92
+ */
93
+ deploy(appId: string, params?: DeployAppParams): Promise<DeployAppResponse>;
94
+ /** Fetches one deployment's current phase. */
95
+ getDeployment(appId: string, deploymentId: string, params?: ProjectScopedParams): Promise<GetDeploymentResponse>;
96
+ /**
97
+ * Polls a deployment until it finishes, and returns it in its final phase.
98
+ *
99
+ * Resolves for every finished phase, failures included — check `phase` for
100
+ * `ACTIVE`. Rejects only when the request fails or `timeout` passes first,
101
+ * in which case the deployment keeps going server-side.
102
+ */
103
+ waitForDeployment(appId: string, deploymentId: string, params?: WaitForDeploymentParams): Promise<AppDeployment>;
104
+ }
105
+ export {};
@@ -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.2.0";
12
- export declare const USER_AGENT = "cosmoner-node/1.2.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.2.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",
@@ -30,6 +30,11 @@
30
30
  "cosmoner",
31
31
  "sdk"
32
32
  ],
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "git+https://github.com/datablock-dev/cosmoner-sdk.git",
36
+ "directory": "javascript"
37
+ },
33
38
  "license": "MIT",
34
39
  "dependencies": {
35
40
  "yaml": "^2.6.0"