// Copyright 2022 Luca Casonato. All rights reserved. MIT license. /** * Firebase Hosting API Client for Deno * ==================================== * * The Firebase Hosting REST API enables programmatic and customizable management and deployments to your Firebase-hosted sites. Use this REST API to create and manage channels and sites as well as to deploy new or updated hosting configurations and content files. * * Docs: https://firebase.google.com/docs/hosting/ * Source: https://googleapis.deno.dev/v1/firebasehosting:v1.ts */ import { auth, CredentialsClient, GoogleAuth, request } from "/_/base@v1/mod.ts"; export { auth, GoogleAuth }; export type { CredentialsClient }; /** * The Firebase Hosting REST API enables programmatic and customizable * management and deployments to your Firebase-hosted sites. Use this REST API * to create and manage channels and sites as well as to deploy new or updated * hosting configurations and content files. */ export class FirebaseHosting { #client: CredentialsClient | undefined; #baseUrl: string; constructor(client?: CredentialsClient, baseUrl: string = "https://firebasehosting.googleapis.com/") { this.#client = client; this.#baseUrl = baseUrl; } /** * Starts asynchronous cancellation on a long-running operation. The server * makes a best effort to cancel the operation, but success is not guaranteed. * If the server doesn't support this method, it returns * `google.rpc.Code.UNIMPLEMENTED`. Clients can use Operations.GetOperation or * other methods to check whether the cancellation succeeded or whether the * operation completed despite cancellation. On successful cancellation, the * operation is not deleted; instead, it becomes an operation with an * Operation.error value with a google.rpc.Status.code of `1`, corresponding * to `Code.CANCELLED`. * * @param name The name of the operation resource to be cancelled. */ async operationsCancel(name: string, req: CancelOperationRequest): Promise { const url = new URL(`${this.#baseUrl}v1/${ name }:cancel`); const body = JSON.stringify(req); const data = await request(url.href, { client: this.#client, method: "POST", body, }); return data as Empty; } /** * Deletes a long-running operation. This method indicates that the client is * no longer interested in the operation result. It does not cancel the * operation. If the server doesn't support this method, it returns * `google.rpc.Code.UNIMPLEMENTED`. * * @param name The name of the operation resource to be deleted. */ async operationsDelete(name: string): Promise { const url = new URL(`${this.#baseUrl}v1/${ name }`); const data = await request(url.href, { client: this.#client, method: "DELETE", }); return data as Empty; } /** * Lists operations that match the specified filter in the request. If the * server doesn't support this method, it returns `UNIMPLEMENTED`. * * @param name The name of the operation's parent resource. */ async operationsList(name: string, opts: OperationsListOptions = {}): Promise { const url = new URL(`${this.#baseUrl}v1/${ name }`); if (opts.filter !== undefined) { url.searchParams.append("filter", String(opts.filter)); } if (opts.pageSize !== undefined) { url.searchParams.append("pageSize", String(opts.pageSize)); } if (opts.pageToken !== undefined) { url.searchParams.append("pageToken", String(opts.pageToken)); } const data = await request(url.href, { client: this.#client, method: "GET", }); return data as ListOperationsResponse; } /** * CancelOperation is a part of the google.longrunning.Operations interface, * but is not implemented for CustomDomain resources. * * @param name The name of the operation resource to be cancelled. */ async projectsSitesCustomDomainsOperationsCancel(name: string, req: CancelOperationRequest): Promise { const url = new URL(`${this.#baseUrl}v1/${ name }:cancel`); const body = JSON.stringify(req); const data = await request(url.href, { client: this.#client, method: "POST", body, }); return data as Empty; } /** * DeleteOperation is a part of the google.longrunning.Operations interface, * but is not implemented for CustomDomain resources. * * @param name The name of the operation resource to be deleted. */ async projectsSitesCustomDomainsOperationsDelete(name: string): Promise { const url = new URL(`${this.#baseUrl}v1/${ name }`); const data = await request(url.href, { client: this.#client, method: "DELETE", }); return data as Empty; } } /** * The request message for Operations.CancelOperation. */ export interface CancelOperationRequest { } /** * A set of ACME challenges you can use to allow Hosting to create an SSL * certificate for your domain name before directing traffic to Hosting servers. * Use either the DNS or HTTP challenge; it's not necessary to provide both. */ export interface CertVerification { /** * Output only. A `TXT` record to add to your DNS records that confirms your * intent to let Hosting create an SSL cert for your domain name. */ readonly dns?: DnsUpdates; /** * Output only. A file to add to your existing, non-Hosting hosting service * that confirms your intent to let Hosting create an SSL cert for your domain * name. */ readonly http?: HttpUpdate; } /** * Metadata associated with a`CustomDomain` operation. */ export interface CustomDomainMetadata { /** * The `CertState` of the domain name's SSL certificate. */ certState?: | "CERT_STATE_UNSPECIFIED" | "CERT_PREPARING" | "CERT_VALIDATING" | "CERT_PROPAGATING" | "CERT_ACTIVE" | "CERT_EXPIRING_SOON" | "CERT_EXPIRED"; /** * The `HostState` of the domain name this `CustomDomain` refers to. */ hostState?: | "HOST_STATE_UNSPECIFIED" | "HOST_UNHOSTED" | "HOST_UNREACHABLE" | "HOST_MISMATCH" | "HOST_CONFLICT" | "HOST_ACTIVE"; /** * A list of issues that are currently preventing Hosting from completing the * operation. These are generally DNS-related issues that Hosting encounters * when querying a domain name's records or attempting to mint an SSL * certificate. */ issues?: Status[]; /** * A set of DNS record updates and ACME challenges that allow you to * transition domain names to Firebase Hosting with zero downtime. These * updates allow Hosting to create an SSL certificate and establish ownership * for your custom domain before Hosting begins serving traffic on it. If your * domain name is already in active use with another provider, add one of the * challenges and make the recommended DNS updates. After adding challenges * and adjusting DNS records as necessary, wait for the `ownershipState` to be * `OWNERSHIP_ACTIVE` and the `certState` to be `CERT_ACTIVE` before sending * traffic to Hosting. */ liveMigrationSteps?: LiveMigrationStep[]; /** * The `OwnershipState` of the domain name this `CustomDomain` refers to. */ ownershipState?: | "OWNERSHIP_STATE_UNSPECIFIED" | "OWNERSHIP_MISSING" | "OWNERSHIP_UNREACHABLE" | "OWNERSHIP_MISMATCH" | "OWNERSHIP_CONFLICT" | "OWNERSHIP_PENDING" | "OWNERSHIP_ACTIVE"; /** * A set of DNS record updates that allow Hosting to serve secure content on * your domain name. The record type determines the update's purpose: - `A` * and `AAAA`: Updates your domain name's IP addresses so that they direct * traffic to Hosting servers. - `TXT`: Updates ownership permissions on your * domain name, letting Hosting know that your custom domain's project has * permission to perform actions for that domain name. - `CAA`: Updates your * domain name's list of authorized Certificate Authorities (CAs). Only * present if you have existing `CAA` records that prohibit Hosting's CA from * minting certs for your domain name. These updates include all DNS changes * you'll need to get started with Hosting, but, if made all at once, can * result in a brief period of downtime for your domain name--while Hosting * creates and uploads an SSL cert, for example. If you'd like to add your * domain name to Hosting without downtime, complete the `liveMigrationSteps` * first, before making the remaining updates in this field. */ quickSetupUpdates?: DnsUpdates; } function serializeCustomDomainMetadata(data: any): CustomDomainMetadata { return { ...data, quickSetupUpdates: data["quickSetupUpdates"] !== undefined ? serializeDnsUpdates(data["quickSetupUpdates"]) : undefined, }; } function deserializeCustomDomainMetadata(data: any): CustomDomainMetadata { return { ...data, quickSetupUpdates: data["quickSetupUpdates"] !== undefined ? deserializeDnsUpdates(data["quickSetupUpdates"]) : undefined, }; } /** * DNS records are resource records that define how systems and services should * behave when handling requests for a domain name. For example, when you add * `A` records to your domain name's DNS records, you're informing other systems * (such as your users' web browsers) to contact those IPv4 addresses to * retrieve resources relevant to your domain name (such as your Hosting site * files). */ export interface DnsRecord { /** * Output only. The domain name the record pertains to, e.g. `foo.bar.com.`. */ readonly domainName?: string; /** * Output only. The data of the record. The meaning of the value depends on * record type: - A and AAAA: IP addresses for the domain name. - CNAME: * Another domain to check for records. - TXT: Arbitrary text strings * associated with the domain name. Hosting uses TXT records to determine * which Firebase projects have permission to act on the domain name's behalf. * - CAA: The record's flags, tag, and value, e.g. `0 issue "pki.goog"`. */ readonly rdata?: string; /** * Output only. An enum that indicates the a required action for this record. */ readonly requiredAction?: | "NONE" | "ADD" | "REMOVE"; /** * Output only. The record's type, which determines what data the record * contains. */ readonly type?: | "TYPE_UNSPECIFIED" | "A" | "CNAME" | "TXT" | "AAAA" | "CAA"; } /** * A set of DNS records relevant to the setup and maintenance of a custom * domain in Firebase Hosting. */ export interface DnsRecordSet { /** * Output only. An error Hosting services encountered when querying your * domain name's DNS records. Note: Hosting ignores `NXDOMAIN` errors, as * those generally just mean that a domain name hasn't been set up yet. */ readonly checkError?: Status; /** * Output only. The domain name the record set pertains to. */ readonly domainName?: string; /** * Output only. Records on the domain. */ readonly records?: DnsRecord[]; } /** * A set of DNS record updates that you should make to allow Hosting to serve * secure content in response to requests against your domain name. These * updates present the current state of your domain name's DNS records when * Hosting last queried them, and the desired set of records that Hosting needs * to see before your custom domain can be fully active. */ export interface DnsUpdates { /** * The last time Hosting checked your custom domain's DNS records. */ checkTime?: Date; /** * The set of DNS records Hosting needs to serve secure content on the * domain. */ desired?: DnsRecordSet[]; /** * The set of DNS records Hosting discovered when inspecting a domain. */ discovered?: DnsRecordSet[]; } function serializeDnsUpdates(data: any): DnsUpdates { return { ...data, checkTime: data["checkTime"] !== undefined ? data["checkTime"].toISOString() : undefined, }; } function deserializeDnsUpdates(data: any): DnsUpdates { return { ...data, checkTime: data["checkTime"] !== undefined ? new Date(data["checkTime"]) : undefined, }; } /** * A generic empty message that you can re-use to avoid defining duplicated * empty messages in your APIs. A typical example is to use it as the request or * the response type of an API method. For instance: service Foo { rpc * Bar(google.protobuf.Empty) returns (google.protobuf.Empty); } */ export interface Empty { } /** * A file you can add to your existing, non-Hosting hosting service that * confirms your intent to allow Hosting's Certificate Authorities to create an * SSL certificate for your domain. */ export interface HttpUpdate { /** * Output only. An error encountered during the last contents check. If null, * the check completed successfully. */ readonly checkError?: Status; /** * Output only. A text string to serve at the path. */ readonly desired?: string; /** * Output only. Whether Hosting was able to find the required file contents * on the specified path during its last check. */ readonly discovered?: string; /** * Output only. The last time Hosting systems checked for the file contents. */ readonly lastCheckTime?: Date; /** * Output only. The path to the file. */ readonly path?: string; } /** * The response message for Operations.ListOperations. */ export interface ListOperationsResponse { /** * The standard List next-page token. */ nextPageToken?: string; /** * A list of operations that matches the specified filter in the request. */ operations?: Operation[]; } /** * A set of updates including ACME challenges and DNS records that allow * Hosting to create an SSL certificate and establish project ownership for your * domain name before you direct traffic to Hosting servers. Use these updates * to facilitate zero downtime migrations to Hosting from other services. After * you've made the recommended updates, check your custom domain's * `ownershipState` and `certState`. To avoid downtime, they should be * `OWNERSHIP_ACTIVE` and `CERT_ACTIVE`, respectively, before you update your * `A` and `AAAA` records. */ export interface LiveMigrationStep { /** * Output only. A pair of ACME challenges that Hosting's Certificate * Authority (CA) can use to create an SSL cert for your domain name. Use * either the DNS or HTTP challenge; it's not necessary to provide both. */ readonly certVerification?: CertVerification; /** * Output only. DNS updates to facilitate your domain's zero-downtime * migration to Hosting. */ readonly dnsUpdates?: DnsUpdates; /** * Output only. Issues that prevent the current step from completing. */ readonly issues?: Status[]; /** * Output only. The state of the live migration step, indicates whether you * should work to complete the step now, in the future, or have already * completed it. */ readonly state?: | "STATE_UNSPECIFIED" | "PREPARING" | "PENDING" | "INCOMPLETE" | "PROCESSING" | "COMPLETE"; } /** * This resource represents a long-running operation that is the result of a * network API call. */ export interface Operation { /** * If the value is `false`, it means the operation is still in progress. If * `true`, the operation is completed, and either `error` or `response` is * available. */ done?: boolean; /** * The error result of the operation in case of failure or cancellation. */ error?: Status; /** * Service-specific metadata associated with the operation. It typically * contains progress information and common metadata such as create time. Some * services might not provide such metadata. Any method that returns a * long-running operation should document the metadata type, if any. */ metadata?: { [key: string]: any }; /** * The server-assigned name, which is only unique within the same service * that originally returns it. If you use the default HTTP mapping, the `name` * should be a resource name ending with `operations/{unique_id}`. */ name?: string; /** * The normal, successful response of the operation. If the original method * returns no data on success, such as `Delete`, the response is * `google.protobuf.Empty`. If the original method is standard * `Get`/`Create`/`Update`, the response should be the resource. For other * methods, the response should have the type `XxxResponse`, where `Xxx` is * the original method name. For example, if the original method name is * `TakeSnapshot()`, the inferred response type is `TakeSnapshotResponse`. */ response?: { [key: string]: any }; } /** * Additional options for FirebaseHosting#operationsList. */ export interface OperationsListOptions { /** * The standard list filter. */ filter?: string; /** * The standard list page size. */ pageSize?: number; /** * The standard list page token. */ pageToken?: string; } /** * The `Status` type defines a logical error model that is suitable for * different programming environments, including REST APIs and RPC APIs. It is * used by [gRPC](https://github.com/grpc). Each `Status` message contains three * pieces of data: error code, error message, and error details. You can find * out more about this error model and how to work with it in the [API Design * Guide](https://cloud.google.com/apis/design/errors). */ export interface Status { /** * The status code, which should be an enum value of google.rpc.Code. */ code?: number; /** * A list of messages that carry the error details. There is a common set of * message types for APIs to use. */ details?: { [key: string]: any }[]; /** * A developer-facing error message, which should be in English. Any * user-facing error message should be localized and sent in the * google.rpc.Status.details field, or localized by the client. */ message?: string; }