@cosmoner/sdk 1.19.1 → 1.20.1

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
@@ -222,6 +222,20 @@ through a new SMTP credential, and every email it sends is billed on the
222
222
  project's email plan. `enableMail` and `disableMail` need `email:write` as well
223
223
  as `hosting:write`.
224
224
 
225
+ ```ts
226
+ const { data: domains } = await client.hosting.domains(siteId);
227
+ const { data: attached } = await client.hosting.attachDomain(siteId, { hostname: "shop.example.com" });
228
+ // attached.dnsRecordsCreated — true when Cosmoner runs the domain's DNS and added attached.instructions
229
+ await client.hosting.updateDomain(siteId, attached.domainId, { kind: "REDIRECT", redirectTarget: "https://example.com" });
230
+ await client.hosting.detachDomain(siteId, attached.domainId);
231
+ ```
232
+
233
+ `attachDomain` takes one of the project's verified domains, or a subdomain of
234
+ one; anything else is refused with a 422. A website is served from
235
+ `<hostname>/public_html` unless `path` names another folder. `updateDomain`
236
+ replaces the whole behaviour, so `{ kind: "SITE" }` alone moves it back to its
237
+ default folder. These need `hosting:write`; `domains` needs `hosting:read`.
238
+
225
239
  ## Resource namespaces
226
240
 
227
241
  Each of these works on one kind of resource and returns the API envelope.
package/dist/index.d.ts CHANGED
@@ -11,7 +11,7 @@ export { CatalogService, type AppSize, type CatalogRegion, type DatabaseCatalog,
11
11
  export { DatabasesService, type CreateDedicatedDatabaseParams, type CreateDedicatedDatabaseResponse, type DatabaseSummary, type DedicatedDatabase, type DedicatedDatabaseDetail, type DeleteDatabaseResponse, type GetDedicatedDatabaseResponse, type GetSharedDatabaseResponse, type ListDatabasesResponse, type ListDedicatedDatabasesResponse, type ListSharedDatabasesResponse, type PreviewDedicatedDatabaseParams, type PreviewDedicatedDatabaseResponse, type RotateSharedDatabasePasswordResponse, type RotatedSharedDatabasePassword, type SharedDatabase, } from "./services/databases";
12
12
  export { DomainsService, type CreateDomainResponse, type DeleteDomainResponse, type DnsRecord, type Domain, type GetDomainResponse, type ListDomainsResponse, type VerificationRecord, type VerifyDomainResponse, } from "./services/domains";
13
13
  export { EmailService, type CreateEmailDomainParams, type CreateEmailDomainResponse, type CreateExternalEmailDomainParams, type CreateSmtpCredentialParams, type CreateSmtpCredentialResponse, type EmailDomain, type EmailDomainDetail, type EmailDomainVerification, type EmailLimits, type EmailTemplateRef, type GetEmailDomainResponse, type GetEmailLimitsResponse, type ListEmailDomainsResponse, type NewSmtpCredential, type SendEmailParams, type SendEmailResponse, type SendRawEmailParams, type SendTemplateEmailParams, type SentEmailTemplate, type VerifyEmailDomainResponse, } from "./services/email";
14
- export { HostingService, type CreateHostingSiteParams, type CreateHostingSiteResponse, type DeleteHostingSiteResponse, type EnableHostingMailParams, type GetHostingAccessResponse, type GetHostingSiteParams, type GetHostingSiteResponse, type GetHostingSiteWithCredentialsResponse, type HostingAccess, type HostingImageBuild, type HostingImageStatus, type HostingImageStatusResponse, type HostingImageUpdate, type HostingMailStatus, type HostingMailStatusResponse, type HostingPrice, type HostingSite, type HostingSiteStatus, type HostingSiteWithCredentials, type HostingTier, type ListHostingPricesResponse, type ListHostingSitesResponse, type PreviewHostingSiteParams, type PreviewHostingSiteResponse, type SetHostingPhpVersionParams, } from "./services/hosting";
14
+ export { HostingService, type CreateHostingSiteParams, type CreateHostingSiteResponse, type DeleteHostingSiteResponse, type AttachHostingDomainParams, type AttachHostingDomainResponse, type DetachHostingDomainResponse, type EnableHostingMailParams, type GetHostingAccessResponse, type GetHostingSiteParams, type GetHostingSiteResponse, type GetHostingSiteWithCredentialsResponse, type HostingAccess, type HostingDomain, type HostingDomainAttached, type HostingDomainBehaviour, type HostingDomainDnsInstructions, type HostingDomainKind, type HostingImageBuild, type HostingImageStatus, type HostingImageStatusResponse, type HostingImageUpdate, type HostingMailStatus, type HostingMailStatusResponse, type HostingPrice, type HostingSite, type HostingSiteStatus, type HostingSiteWithCredentials, type HostingTier, type ListHostingDomainsResponse, type ListHostingPricesResponse, type ListHostingSitesResponse, type PreviewHostingSiteParams, type PreviewHostingSiteResponse, type SetHostingPhpVersionParams, type UpdateHostingDomainParams, type UpdateHostingDomainResponse, } from "./services/hosting";
15
15
  export { IamService, type CreateIamCredentialParams, type CreateIamCredentialResponse, type GetIamCredentialResponse, type IamCredential, type IamCredentialList, type IamRegistryGrant, type IamStorageGrant, type ListIamCredentialsResponse, type NewIamCredential, } from "./services/iam";
16
16
  export { MembersService, type ListMembersResponse, type ProjectMember, type ProjectMembers } from "./services/members";
17
17
  export type { CheckoutPreview, PlanChangePreview } from "./services/preview";
package/dist/index.js CHANGED
@@ -721,6 +721,14 @@ var EmailService = class {
721
721
  };
722
722
 
723
723
  // src/services/hosting.ts
724
+ function behaviourBody(params) {
725
+ const body = {};
726
+ if (params.kind !== void 0) body.kind = params.kind;
727
+ if (params.path !== void 0) body.path = params.path;
728
+ if (params.redirectTarget !== void 0) body.redirectTarget = params.redirectTarget;
729
+ if (params.redirectStatus !== void 0) body.redirectStatus = params.redirectStatus;
730
+ return body;
731
+ }
724
732
  var HostingService = class {
725
733
  constructor(transport, config) {
726
734
  this.transport = transport;
@@ -855,6 +863,47 @@ var HostingService = class {
855
863
  if (!siteId) throw new Error("siteId is required");
856
864
  return this.transport.request("DELETE", `${this.basePath(params.projectId)}/${siteId}/mail`);
857
865
  }
866
+ /** Lists the hostnames attached to a site, newest first, and what each does. */
867
+ async domains(siteId, params = {}) {
868
+ if (!siteId) throw new Error("siteId is required");
869
+ return this.transport.request("GET", `${this.basePath(params.projectId)}/${siteId}/domains`);
870
+ }
871
+ /**
872
+ * Attaches a hostname to a site: one of the project's verified domains, or a
873
+ * subdomain of one. Anything else is refused with a 422. When Cosmoner runs
874
+ * the domain's DNS, the records are added for you (`dnsRecordsCreated`);
875
+ * otherwise add `instructions` at your DNS provider.
876
+ */
877
+ async attachDomain(siteId, params) {
878
+ if (!siteId) throw new Error("siteId is required");
879
+ if (!params?.hostname) throw new Error("hostname is required");
880
+ return this.transport.request("POST", `${this.basePath(params.projectId)}/${siteId}/domains`, {
881
+ body: { hostname: params.hostname, ...behaviourBody(params) }
882
+ });
883
+ }
884
+ /**
885
+ * Changes what an attached hostname does. The whole behaviour is replaced:
886
+ * `{ kind: "SITE" }` alone moves it back to its default folder. Its DNS
887
+ * records and certificate are untouched.
888
+ */
889
+ async updateDomain(siteId, domainId, params = {}) {
890
+ if (!siteId) throw new Error("siteId is required");
891
+ if (!domainId) throw new Error("domainId is required");
892
+ return this.transport.request(
893
+ "PATCH",
894
+ `${this.basePath(params.projectId)}/${siteId}/domains/${domainId}`,
895
+ { body: { kind: "SITE", ...behaviourBody(params) } }
896
+ );
897
+ }
898
+ /**
899
+ * Detaches a hostname from a site. Any folder it served stays, with its
900
+ * files; DNS records Cosmoner added for it are removed.
901
+ */
902
+ async detachDomain(siteId, domainId, params = {}) {
903
+ if (!siteId) throw new Error("siteId is required");
904
+ if (!domainId) throw new Error("domainId is required");
905
+ return this.transport.request("DELETE", `${this.basePath(params.projectId)}/${siteId}/domains/${domainId}`);
906
+ }
858
907
  };
859
908
 
860
909
  // src/services/iam.ts
@@ -1735,7 +1784,7 @@ function sleep(ms) {
1735
1784
  }
1736
1785
 
1737
1786
  // src/version.ts
1738
- var VERSION = "1.19.1";
1787
+ var VERSION = "1.20.1";
1739
1788
  var USER_AGENT = `cosmoner-node/${VERSION}`;
1740
1789
 
1741
1790
  // src/transport.ts
package/dist/index.mjs CHANGED
@@ -646,6 +646,14 @@ var EmailService = class {
646
646
  };
647
647
 
648
648
  // src/services/hosting.ts
649
+ function behaviourBody(params) {
650
+ const body = {};
651
+ if (params.kind !== void 0) body.kind = params.kind;
652
+ if (params.path !== void 0) body.path = params.path;
653
+ if (params.redirectTarget !== void 0) body.redirectTarget = params.redirectTarget;
654
+ if (params.redirectStatus !== void 0) body.redirectStatus = params.redirectStatus;
655
+ return body;
656
+ }
649
657
  var HostingService = class {
650
658
  constructor(transport, config) {
651
659
  this.transport = transport;
@@ -780,6 +788,47 @@ var HostingService = class {
780
788
  if (!siteId) throw new Error("siteId is required");
781
789
  return this.transport.request("DELETE", `${this.basePath(params.projectId)}/${siteId}/mail`);
782
790
  }
791
+ /** Lists the hostnames attached to a site, newest first, and what each does. */
792
+ async domains(siteId, params = {}) {
793
+ if (!siteId) throw new Error("siteId is required");
794
+ return this.transport.request("GET", `${this.basePath(params.projectId)}/${siteId}/domains`);
795
+ }
796
+ /**
797
+ * Attaches a hostname to a site: one of the project's verified domains, or a
798
+ * subdomain of one. Anything else is refused with a 422. When Cosmoner runs
799
+ * the domain's DNS, the records are added for you (`dnsRecordsCreated`);
800
+ * otherwise add `instructions` at your DNS provider.
801
+ */
802
+ async attachDomain(siteId, params) {
803
+ if (!siteId) throw new Error("siteId is required");
804
+ if (!params?.hostname) throw new Error("hostname is required");
805
+ return this.transport.request("POST", `${this.basePath(params.projectId)}/${siteId}/domains`, {
806
+ body: { hostname: params.hostname, ...behaviourBody(params) }
807
+ });
808
+ }
809
+ /**
810
+ * Changes what an attached hostname does. The whole behaviour is replaced:
811
+ * `{ kind: "SITE" }` alone moves it back to its default folder. Its DNS
812
+ * records and certificate are untouched.
813
+ */
814
+ async updateDomain(siteId, domainId, params = {}) {
815
+ if (!siteId) throw new Error("siteId is required");
816
+ if (!domainId) throw new Error("domainId is required");
817
+ return this.transport.request(
818
+ "PATCH",
819
+ `${this.basePath(params.projectId)}/${siteId}/domains/${domainId}`,
820
+ { body: { kind: "SITE", ...behaviourBody(params) } }
821
+ );
822
+ }
823
+ /**
824
+ * Detaches a hostname from a site. Any folder it served stays, with its
825
+ * files; DNS records Cosmoner added for it are removed.
826
+ */
827
+ async detachDomain(siteId, domainId, params = {}) {
828
+ if (!siteId) throw new Error("siteId is required");
829
+ if (!domainId) throw new Error("domainId is required");
830
+ return this.transport.request("DELETE", `${this.basePath(params.projectId)}/${siteId}/domains/${domainId}`);
831
+ }
783
832
  };
784
833
 
785
834
  // src/services/iam.ts
@@ -1660,7 +1709,7 @@ function sleep(ms) {
1660
1709
  }
1661
1710
 
1662
1711
  // src/version.ts
1663
- var VERSION = "1.19.1";
1712
+ var VERSION = "1.20.1";
1664
1713
  var USER_AGENT = `cosmoner-node/${VERSION}`;
1665
1714
 
1666
1715
  // src/transport.ts
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Hosting service namespace — shared web hosting sites, how to reach their
3
- * files, the site image they run and whether they can send email.
3
+ * files, the site image they run, whether they can send email, and the
4
+ * domains they answer on.
4
5
  */
5
6
  import { type ResolvedConfig } from "../config";
6
7
  import type { CheckoutPreview } from "./preview";
@@ -202,6 +203,80 @@ export interface EnableHostingMailParams extends ProjectScopedParams {
202
203
  /** The part before the @ of the address the site sends as, e.g. `wordpress`. */
203
204
  localPart: string;
204
205
  }
206
+ /** What an attached hostname does: serve a folder of the site, redirect, or show a placeholder. */
207
+ export type HostingDomainKind = "SITE" | "REDIRECT" | "PARKED";
208
+ /** A hostname attached to a site. */
209
+ export interface HostingDomain {
210
+ id: string;
211
+ tenantId: string;
212
+ /** Lower-cased, e.g. `example.com` or `shop.example.com`. */
213
+ hostname: string;
214
+ kind: HostingDomainKind;
215
+ /** The folder served, as an absolute path inside the site's container. Null unless `kind` is `SITE`. */
216
+ documentRoot: string | null;
217
+ /** Where visitors are sent, with the requested path appended. Null unless `kind` is `REDIRECT`. */
218
+ redirectTarget: string | null;
219
+ redirectStatus: 301 | 302 | null;
220
+ status: "PROVISIONING" | "ACTIVE" | "ERROR";
221
+ /** `VERIFYING` until the hostname's DNS and certificate are in place, then `ACTIVE`. */
222
+ routingStatus: string;
223
+ createdAt: string;
224
+ }
225
+ /** The DNS records a newly attached hostname needs. */
226
+ export interface HostingDomainDnsInstructions {
227
+ recordType: "CNAME";
228
+ name: string;
229
+ value: string;
230
+ /** A second record proving control of the hostname, when one is needed. */
231
+ ownershipVerification: {
232
+ type: string;
233
+ name: string;
234
+ value: string;
235
+ } | null;
236
+ status: string;
237
+ }
238
+ /** A hostname just attached to a site. */
239
+ export interface HostingDomainAttached {
240
+ domainId: string;
241
+ hostname: string;
242
+ instructions: HostingDomainDnsInstructions;
243
+ /**
244
+ * `true` when Cosmoner runs the domain's DNS and added `instructions` for
245
+ * you; `false` when they are yours to add at your DNS provider.
246
+ */
247
+ dnsRecordsCreated: boolean;
248
+ }
249
+ /**
250
+ * What a hostname does. The whole behaviour is sent each time: `{ kind: "SITE" }`
251
+ * alone serves the hostname's default folder.
252
+ */
253
+ export interface HostingDomainBehaviour {
254
+ /** Defaults to `SITE`. */
255
+ kind?: HostingDomainKind;
256
+ /**
257
+ * `SITE` only: the folder to serve, relative to the site's home folder, e.g.
258
+ * `example.com/public_html`. Omitted, it is `<hostname>/public_html`, or for a
259
+ * subdomain of a domain the site already serves a folder inside that one's.
260
+ * The folder is created if it does not exist.
261
+ */
262
+ path?: string;
263
+ /** `REDIRECT` only: a full `http` or `https` address without a query string. */
264
+ redirectTarget?: string;
265
+ /** `REDIRECT` only: `301` (the default) or `302`. */
266
+ redirectStatus?: 301 | 302;
267
+ }
268
+ /** Arguments accepted by `client.hosting.attachDomain()`. */
269
+ export interface AttachHostingDomainParams extends ProjectScopedParams, HostingDomainBehaviour {
270
+ /** One of the project's verified domains, or a subdomain of one. */
271
+ hostname: string;
272
+ }
273
+ /** Arguments accepted by `client.hosting.updateDomain()`. */
274
+ export interface UpdateHostingDomainParams extends ProjectScopedParams, HostingDomainBehaviour {
275
+ }
276
+ export type ListHostingDomainsResponse = Envelope<HostingDomain[]>;
277
+ export type AttachHostingDomainResponse = Envelope<HostingDomainAttached>;
278
+ export type UpdateHostingDomainResponse = Envelope<Record<string, never>>;
279
+ export type DetachHostingDomainResponse = Envelope<Record<string, never>>;
205
280
  /** Every image route answers with the site's image status as it stands afterwards. */
206
281
  export type HostingImageStatusResponse = Envelope<HostingImageStatus>;
207
282
  /** Every mail route answers with the site's mail status as it stands afterwards. */
@@ -278,5 +353,25 @@ export declare class HostingService {
278
353
  * `mail()` returns `false`. Needs `email:write` as well as `hosting:write`.
279
354
  */
280
355
  disableMail(siteId: string, params?: ProjectScopedParams): Promise<HostingMailStatusResponse>;
356
+ /** Lists the hostnames attached to a site, newest first, and what each does. */
357
+ domains(siteId: string, params?: ProjectScopedParams): Promise<ListHostingDomainsResponse>;
358
+ /**
359
+ * Attaches a hostname to a site: one of the project's verified domains, or a
360
+ * subdomain of one. Anything else is refused with a 422. When Cosmoner runs
361
+ * the domain's DNS, the records are added for you (`dnsRecordsCreated`);
362
+ * otherwise add `instructions` at your DNS provider.
363
+ */
364
+ attachDomain(siteId: string, params: AttachHostingDomainParams): Promise<AttachHostingDomainResponse>;
365
+ /**
366
+ * Changes what an attached hostname does. The whole behaviour is replaced:
367
+ * `{ kind: "SITE" }` alone moves it back to its default folder. Its DNS
368
+ * records and certificate are untouched.
369
+ */
370
+ updateDomain(siteId: string, domainId: string, params?: UpdateHostingDomainParams): Promise<UpdateHostingDomainResponse>;
371
+ /**
372
+ * Detaches a hostname from a site. Any folder it served stays, with its
373
+ * files; DNS records Cosmoner added for it are removed.
374
+ */
375
+ detachDomain(siteId: string, domainId: string, params?: ProjectScopedParams): Promise<DetachHostingDomainResponse>;
281
376
  }
282
377
  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.19.1";
12
- export declare const USER_AGENT = "cosmoner-node/1.19.1";
11
+ export declare const VERSION = "1.20.1";
12
+ export declare const USER_AGENT = "cosmoner-node/1.20.1";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cosmoner/sdk",
3
- "version": "1.19.1",
3
+ "version": "1.20.1",
4
4
  "description": "Cosmoner SDK for Node.js",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",