// Copyright 2022 Luca Casonato. All rights reserved. MIT license. /** * Parameter Manager API Client for Deno * ===================================== * * Parameter Manager is a single source of truth to store, access and manage the lifecycle of your workload parameters. Parameter Manager aims to make management of sensitive application parameters effortless for customers without diminishing focus on security. * * Docs: https://cloud.google.com/secret-manager/parameter-manager/docs/overview * Source: https://googleapis.deno.dev/v1/parametermanager:v1.ts */ import { auth, CredentialsClient, GoogleAuth, request } from "/_/base@v1/mod.ts"; export { auth, GoogleAuth }; export type { CredentialsClient }; /** * Parameter Manager is a single source of truth to store, access and manage * the lifecycle of your workload parameters. Parameter Manager aims to make * management of sensitive application parameters effortless for customers * without diminishing focus on security. */ export class ParameterManager { #client: CredentialsClient | undefined; #baseUrl: string; constructor(client?: CredentialsClient, baseUrl: string = "https://parametermanager.googleapis.com/") { this.#client = client; this.#baseUrl = baseUrl; } /** * Gets information about a location. * * @param name Resource name for the location. */ async projectsLocationsGet(name: string): Promise { const url = new URL(`${this.#baseUrl}v1/${ name }`); const data = await request(url.href, { client: this.#client, method: "GET", }); return data as Location; } /** * Lists information about the supported locations for this service. * * @param name The resource that owns the locations collection, if applicable. */ async projectsLocationsList(name: string, opts: ProjectsLocationsListOptions = {}): Promise { const url = new URL(`${this.#baseUrl}v1/${ name }/locations`); if (opts.extraLocationTypes !== undefined) { url.searchParams.append("extraLocationTypes", String(opts.extraLocationTypes)); } 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 ListLocationsResponse; } /** * Creates a new Parameter in a given project and location. * * @param parent Required. Value for parent in the format `projects/*/locations/*`. */ async projectsLocationsParametersCreate(parent: string, req: Parameter, opts: ProjectsLocationsParametersCreateOptions = {}): Promise { const url = new URL(`${this.#baseUrl}v1/${ parent }/parameters`); if (opts.parameterId !== undefined) { url.searchParams.append("parameterId", String(opts.parameterId)); } if (opts.requestId !== undefined) { url.searchParams.append("requestId", String(opts.requestId)); } const body = JSON.stringify(req); const data = await request(url.href, { client: this.#client, method: "POST", body, }); return data as Parameter; } /** * Deletes a single Parameter. * * @param name Required. Name of the resource in the format `projects/*/locations/*/parameters/*`. */ async projectsLocationsParametersDelete(name: string, opts: ProjectsLocationsParametersDeleteOptions = {}): Promise { const url = new URL(`${this.#baseUrl}v1/${ name }`); if (opts.requestId !== undefined) { url.searchParams.append("requestId", String(opts.requestId)); } const data = await request(url.href, { client: this.#client, method: "DELETE", }); return data as Empty; } /** * Gets details of a single Parameter. * * @param name Required. Name of the resource in the format `projects/*/locations/*/parameters/*`. */ async projectsLocationsParametersGet(name: string): Promise { const url = new URL(`${this.#baseUrl}v1/${ name }`); const data = await request(url.href, { client: this.#client, method: "GET", }); return data as Parameter; } /** * Lists Parameters in a given project and location. * * @param parent Required. Parent value for ListParametersRequest in the format `projects/*/locations/*`. */ async projectsLocationsParametersList(parent: string, opts: ProjectsLocationsParametersListOptions = {}): Promise { const url = new URL(`${this.#baseUrl}v1/${ parent }/parameters`); if (opts.filter !== undefined) { url.searchParams.append("filter", String(opts.filter)); } if (opts.orderBy !== undefined) { url.searchParams.append("orderBy", String(opts.orderBy)); } 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 ListParametersResponse; } /** * Updates a single Parameter. * * @param name Identifier. [Output only] The resource name of the Parameter in the format `projects/*/locations/*/parameters/*`. */ async projectsLocationsParametersPatch(name: string, req: Parameter, opts: ProjectsLocationsParametersPatchOptions = {}): Promise { opts = serializeProjectsLocationsParametersPatchOptions(opts); const url = new URL(`${this.#baseUrl}v1/${ name }`); if (opts.requestId !== undefined) { url.searchParams.append("requestId", String(opts.requestId)); } if (opts.updateMask !== undefined) { url.searchParams.append("updateMask", String(opts.updateMask)); } const body = JSON.stringify(req); const data = await request(url.href, { client: this.#client, method: "PATCH", body, }); return data as Parameter; } /** * Creates a new ParameterVersion in a given project, location, and * parameter. * * @param parent Required. Value for parent in the format `projects/*/locations/*/parameters/*`. */ async projectsLocationsParametersVersionsCreate(parent: string, req: ParameterVersion, opts: ProjectsLocationsParametersVersionsCreateOptions = {}): Promise { req = serializeParameterVersion(req); const url = new URL(`${this.#baseUrl}v1/${ parent }/versions`); if (opts.parameterVersionId !== undefined) { url.searchParams.append("parameterVersionId", String(opts.parameterVersionId)); } if (opts.requestId !== undefined) { url.searchParams.append("requestId", String(opts.requestId)); } const body = JSON.stringify(req); const data = await request(url.href, { client: this.#client, method: "POST", body, }); return deserializeParameterVersion(data); } /** * Deletes a single ParameterVersion. * * @param name Required. Name of the resource in the format `projects/*/locations/*/parameters/*/versions/*`. */ async projectsLocationsParametersVersionsDelete(name: string, opts: ProjectsLocationsParametersVersionsDeleteOptions = {}): Promise { const url = new URL(`${this.#baseUrl}v1/${ name }`); if (opts.requestId !== undefined) { url.searchParams.append("requestId", String(opts.requestId)); } const data = await request(url.href, { client: this.#client, method: "DELETE", }); return data as Empty; } /** * Gets details of a single ParameterVersion. * * @param name Required. Name of the resource in the format `projects/*/locations/*/parameters/*/versions/*`. */ async projectsLocationsParametersVersionsGet(name: string, opts: ProjectsLocationsParametersVersionsGetOptions = {}): Promise { const url = new URL(`${this.#baseUrl}v1/${ name }`); if (opts.view !== undefined) { url.searchParams.append("view", String(opts.view)); } const data = await request(url.href, { client: this.#client, method: "GET", }); return deserializeParameterVersion(data); } /** * Lists ParameterVersions in a given project, location, and parameter. * * @param parent Required. Parent value for ListParameterVersionsRequest in the format `projects/*/locations/*/parameters/*`. */ async projectsLocationsParametersVersionsList(parent: string, opts: ProjectsLocationsParametersVersionsListOptions = {}): Promise { const url = new URL(`${this.#baseUrl}v1/${ parent }/versions`); if (opts.filter !== undefined) { url.searchParams.append("filter", String(opts.filter)); } if (opts.orderBy !== undefined) { url.searchParams.append("orderBy", String(opts.orderBy)); } 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 deserializeListParameterVersionsResponse(data); } /** * Updates a single ParameterVersion. * * @param name Identifier. [Output only] The resource name of the ParameterVersion in the format `projects/*/locations/*/parameters/*/versions/*`. */ async projectsLocationsParametersVersionsPatch(name: string, req: ParameterVersion, opts: ProjectsLocationsParametersVersionsPatchOptions = {}): Promise { req = serializeParameterVersion(req); opts = serializeProjectsLocationsParametersVersionsPatchOptions(opts); const url = new URL(`${this.#baseUrl}v1/${ name }`); if (opts.requestId !== undefined) { url.searchParams.append("requestId", String(opts.requestId)); } if (opts.updateMask !== undefined) { url.searchParams.append("updateMask", String(opts.updateMask)); } const body = JSON.stringify(req); const data = await request(url.href, { client: this.#client, method: "PATCH", body, }); return deserializeParameterVersion(data); } /** * Gets rendered version of a ParameterVersion. * * @param name Required. Name of the resource */ async projectsLocationsParametersVersionsRender(name: string): Promise { const url = new URL(`${this.#baseUrl}v1/${ name }:render`); const data = await request(url.href, { client: this.#client, method: "GET", }); return deserializeRenderParameterVersionResponse(data); } } /** * 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 { } /** * The response message for Locations.ListLocations. */ export interface ListLocationsResponse { /** * A list of locations that matches the specified filter in the request. */ locations?: Location[]; /** * The standard List next-page token. */ nextPageToken?: string; } /** * Message for response to listing Parameters */ export interface ListParametersResponse { /** * A token identifying a page of results the server should return. */ nextPageToken?: string; /** * The list of Parameters */ parameters?: Parameter[]; /** * Unordered list. Locations that could not be reached. */ unreachable?: string[]; } /** * Message for response to listing ParameterVersions */ export interface ListParameterVersionsResponse { /** * A token identifying a page of results the server should return. */ nextPageToken?: string; /** * The list of ParameterVersions */ parameterVersions?: ParameterVersion[]; /** * Unordered list. Locations that could not be reached. */ unreachable?: string[]; } function serializeListParameterVersionsResponse(data: any): ListParameterVersionsResponse { return { ...data, parameterVersions: data["parameterVersions"] !== undefined ? data["parameterVersions"].map((item: any) => (serializeParameterVersion(item))) : undefined, }; } function deserializeListParameterVersionsResponse(data: any): ListParameterVersionsResponse { return { ...data, parameterVersions: data["parameterVersions"] !== undefined ? data["parameterVersions"].map((item: any) => (deserializeParameterVersion(item))) : undefined, }; } /** * A resource that represents a Google Cloud location. */ export interface Location { /** * The friendly name for this location, typically a nearby city name. For * example, "Tokyo". */ displayName?: string; /** * Cross-service attributes for the location. For example * {"cloud.googleapis.com/region": "us-east1"} */ labels?: { [key: string]: string }; /** * The canonical id for this location. For example: `"us-east1"`. */ locationId?: string; /** * Service-specific metadata. For example the available capacity at the given * location. */ metadata?: { [key: string]: any }; /** * Resource name for the location, which may vary between implementations. * For example: `"projects/example-project/locations/us-east1"` */ name?: string; } /** * Message describing Parameter resource */ export interface Parameter { /** * Output only. [Output only] Create time stamp */ readonly createTime?: Date; /** * Optional. Specifies the format of a Parameter. */ format?: | "PARAMETER_FORMAT_UNSPECIFIED" | "UNFORMATTED" | "YAML" | "JSON"; /** * Optional. Customer managed encryption key (CMEK) to use for encrypting the * Parameter Versions. If not set, the default Google-managed encryption key * will be used. Cloud KMS CryptoKeys must reside in the same location as the * Parameter. The expected format is * `projects/*\/locations/*\/keyRings/*\/cryptoKeys/*`. */ kmsKey?: string; /** * Optional. Labels as key value pairs */ labels?: { [key: string]: string }; /** * Identifier. [Output only] The resource name of the Parameter in the format * `projects/*\/locations/*\/parameters/*`. */ name?: string; /** * Output only. [Output-only] policy member strings of a Google Cloud * resource. */ readonly policyMember?: ResourcePolicyMember; /** * Output only. [Output only] Update time stamp */ readonly updateTime?: Date; } /** * Message describing ParameterVersion resource */ export interface ParameterVersion { /** * Output only. [Output only] Create time stamp */ readonly createTime?: Date; /** * Optional. Disabled boolean to determine if a ParameterVersion acts as a * metadata only resource (payload is never returned if disabled is true). If * true any calls will always default to BASIC view even if the user * explicitly passes FULL view as part of the request. A render call on a * disabled resource fails with an error. Default value is False. */ disabled?: boolean; /** * Optional. Output only. [Output only] The resource name of the KMS key * version used to encrypt the ParameterVersion payload. This field is * populated only if the Parameter resource has customer managed encryption * key (CMEK) configured. */ readonly kmsKeyVersion?: string; /** * Identifier. [Output only] The resource name of the ParameterVersion in the * format `projects/*\/locations/*\/parameters/*\/versions/*`. */ name?: string; /** * Required. Immutable. Payload content of a ParameterVersion resource. This * is only returned when the request provides the View value of FULL (default * for GET request). */ payload?: ParameterVersionPayload; /** * Output only. [Output only] Update time stamp */ readonly updateTime?: Date; } function serializeParameterVersion(data: any): ParameterVersion { return { ...data, payload: data["payload"] !== undefined ? serializeParameterVersionPayload(data["payload"]) : undefined, }; } function deserializeParameterVersion(data: any): ParameterVersion { return { ...data, createTime: data["createTime"] !== undefined ? new Date(data["createTime"]) : undefined, payload: data["payload"] !== undefined ? deserializeParameterVersionPayload(data["payload"]) : undefined, updateTime: data["updateTime"] !== undefined ? new Date(data["updateTime"]) : undefined, }; } /** * Message for storing a ParameterVersion resource's payload data */ export interface ParameterVersionPayload { /** * Required. bytes data for storing payload. */ data?: Uint8Array; } function serializeParameterVersionPayload(data: any): ParameterVersionPayload { return { ...data, data: data["data"] !== undefined ? encodeBase64(data["data"]) : undefined, }; } function deserializeParameterVersionPayload(data: any): ParameterVersionPayload { return { ...data, data: data["data"] !== undefined ? decodeBase64(data["data"] as string) : undefined, }; } /** * Additional options for ParameterManager#projectsLocationsList. */ export interface ProjectsLocationsListOptions { /** * Optional. Do not use this field. It is unsupported and is ignored unless * explicitly documented otherwise. This is primarily for internal usage. */ extraLocationTypes?: string; /** * A filter to narrow down results to a preferred subset. The filtering * language accepts strings like `"displayName=tokyo"`, and is documented in * more detail in [AIP-160](https://google.aip.dev/160). */ filter?: string; /** * The maximum number of results to return. If not set, the service selects a * default. */ pageSize?: number; /** * A page token received from the `next_page_token` field in the response. * Send that page token to receive the subsequent page. */ pageToken?: string; } /** * Additional options for ParameterManager#projectsLocationsParametersCreate. */ export interface ProjectsLocationsParametersCreateOptions { /** * Required. Id of the Parameter resource */ parameterId?: string; /** * Optional. An optional request ID to identify requests. Specify a unique * request ID so that if you must retry your request, the server will know to * ignore the request if it has already been completed. The server will * guarantee that for at least 60 minutes since the first request. For * example, consider a situation where you make an initial request and the * request times out. If you make the request again with the same request ID, * the server can check if original operation with the same request ID was * received, and if so, will ignore the second request. This prevents clients * from accidentally creating duplicate commitments. The request ID must be a * valid UUID with the exception that zero UUID is not supported * (00000000-0000-0000-0000-000000000000). */ requestId?: string; } /** * Additional options for ParameterManager#projectsLocationsParametersDelete. */ export interface ProjectsLocationsParametersDeleteOptions { /** * Optional. An optional request ID to identify requests. Specify a unique * request ID so that if you must retry your request, the server will know to * ignore the request if it has already been completed. The server will * guarantee that for at least 60 minutes after the first request. For * example, consider a situation where you make an initial request and the * request times out. If you make the request again with the same request ID, * the server can check if original operation with the same request ID was * received, and if so, will ignore the second request. This prevents clients * from accidentally creating duplicate commitments. The request ID must be a * valid UUID with the exception that zero UUID is not supported * (00000000-0000-0000-0000-000000000000). */ requestId?: string; } /** * Additional options for ParameterManager#projectsLocationsParametersList. */ export interface ProjectsLocationsParametersListOptions { /** * Optional. Filtering results */ filter?: string; /** * Optional. Hint for how to order the results */ orderBy?: string; /** * Optional. Requested page size. Server may return fewer items than * requested. If unspecified, server will pick an appropriate default. */ pageSize?: number; /** * Optional. A page token, received from a previous `ListParameters` call. * Provide this to retrieve the subsequent page. When paginating, all other * parameters provided to `ListParameters` must match the call that provided * the page token. */ pageToken?: string; } /** * Additional options for ParameterManager#projectsLocationsParametersPatch. */ export interface ProjectsLocationsParametersPatchOptions { /** * Optional. An optional request ID to identify requests. Specify a unique * request ID so that if you must retry your request, the server will know to * ignore the request if it has already been completed. The server will * guarantee that for at least 60 minutes since the first request. For * example, consider a situation where you make an initial request and the * request times out. If you make the request again with the same request ID, * the server can check if original operation with the same request ID was * received, and if so, will ignore the second request. This prevents clients * from accidentally creating duplicate commitments. The request ID must be a * valid UUID with the exception that zero UUID is not supported * (00000000-0000-0000-0000-000000000000). */ requestId?: string; /** * Optional. Field mask is used to specify the fields to be overwritten in * the Parameter resource by the update. The fields specified in the * update_mask are relative to the resource, not the full request. A mutable * field will be overwritten if it is in the mask. If the user does not * provide a mask then all mutable fields present in the request will be * overwritten. */ updateMask?: string /* FieldMask */; } function serializeProjectsLocationsParametersPatchOptions(data: any): ProjectsLocationsParametersPatchOptions { return { ...data, updateMask: data["updateMask"] !== undefined ? data["updateMask"] : undefined, }; } function deserializeProjectsLocationsParametersPatchOptions(data: any): ProjectsLocationsParametersPatchOptions { return { ...data, updateMask: data["updateMask"] !== undefined ? data["updateMask"] : undefined, }; } /** * Additional options for * ParameterManager#projectsLocationsParametersVersionsCreate. */ export interface ProjectsLocationsParametersVersionsCreateOptions { /** * Required. Id of the ParameterVersion resource */ parameterVersionId?: string; /** * Optional. An optional request ID to identify requests. Specify a unique * request ID so that if you must retry your request, the server will know to * ignore the request if it has already been completed. The server will * guarantee that for at least 60 minutes since the first request. For * example, consider a situation where you make an initial request and the * request times out. If you make the request again with the same request ID, * the server can check if original operation with the same request ID was * received, and if so, will ignore the second request. This prevents clients * from accidentally creating duplicate commitments. The request ID must be a * valid UUID with the exception that zero UUID is not supported * (00000000-0000-0000-0000-000000000000). */ requestId?: string; } /** * Additional options for * ParameterManager#projectsLocationsParametersVersionsDelete. */ export interface ProjectsLocationsParametersVersionsDeleteOptions { /** * Optional. An optional request ID to identify requests. Specify a unique * request ID so that if you must retry your request, the server will know to * ignore the request if it has already been completed. The server will * guarantee that for at least 60 minutes after the first request. For * example, consider a situation where you make an initial request and the * request times out. If you make the request again with the same request ID, * the server can check if original operation with the same request ID was * received, and if so, will ignore the second request. This prevents clients * from accidentally creating duplicate commitments. The request ID must be a * valid UUID with the exception that zero UUID is not supported * (00000000-0000-0000-0000-000000000000). */ requestId?: string; } /** * Additional options for * ParameterManager#projectsLocationsParametersVersionsGet. */ export interface ProjectsLocationsParametersVersionsGetOptions { /** * Optional. View of the ParameterVersion. In the default FULL view, all * metadata & payload associated with the ParameterVersion will be returned. */ view?: | "VIEW_UNSPECIFIED" | "BASIC" | "FULL"; } /** * Additional options for * ParameterManager#projectsLocationsParametersVersionsList. */ export interface ProjectsLocationsParametersVersionsListOptions { /** * Optional. Filtering results */ filter?: string; /** * Optional. Hint for how to order the results */ orderBy?: string; /** * Optional. Requested page size. Server may return fewer items than * requested. If unspecified, server will pick an appropriate default. */ pageSize?: number; /** * Optional. A page token, received from a previous `ListParameterVersions` * call. Provide this to retrieve the subsequent page. When paginating, all * other parameters provided to `ListParameterVersions` must match the call * that provided the page token. */ pageToken?: string; } /** * Additional options for * ParameterManager#projectsLocationsParametersVersionsPatch. */ export interface ProjectsLocationsParametersVersionsPatchOptions { /** * Optional. An optional request ID to identify requests. Specify a unique * request ID so that if you must retry your request, the server will know to * ignore the request if it has already been completed. The server will * guarantee that for at least 60 minutes since the first request. For * example, consider a situation where you make an initial request and the * request times out. If you make the request again with the same request ID, * the server can check if original operation with the same request ID was * received, and if so, will ignore the second request. This prevents clients * from accidentally creating duplicate commitments. The request ID must be a * valid UUID with the exception that zero UUID is not supported * (00000000-0000-0000-0000-000000000000). */ requestId?: string; /** * Optional. Field mask is used to specify the fields to be overwritten in * the ParameterVersion resource by the update. The fields specified in the * update_mask are relative to the resource, not the full request. A mutable * field will be overwritten if it is in the mask. If the user does not * provide a mask then all mutable fields present in the request will be * overwritten. */ updateMask?: string /* FieldMask */; } function serializeProjectsLocationsParametersVersionsPatchOptions(data: any): ProjectsLocationsParametersVersionsPatchOptions { return { ...data, updateMask: data["updateMask"] !== undefined ? data["updateMask"] : undefined, }; } function deserializeProjectsLocationsParametersVersionsPatchOptions(data: any): ProjectsLocationsParametersVersionsPatchOptions { return { ...data, updateMask: data["updateMask"] !== undefined ? data["updateMask"] : undefined, }; } /** * Message describing RenderParameterVersionResponse resource */ export interface RenderParameterVersionResponse { /** * Output only. Resource identifier of a ParameterVersion in the format * `projects/*\/locations/*\/parameters/*\/versions/*`. */ readonly parameterVersion?: string; /** * Payload content of a ParameterVersion resource. */ payload?: ParameterVersionPayload; /** * Output only. Server generated rendered version of the user provided * payload data (ParameterVersionPayload) which has substitutions of all (if * any) references to a SecretManager SecretVersion resources. This * substitution only works for a Parameter which is in JSON or YAML format. */ readonly renderedPayload?: Uint8Array; } function serializeRenderParameterVersionResponse(data: any): RenderParameterVersionResponse { return { ...data, payload: data["payload"] !== undefined ? serializeParameterVersionPayload(data["payload"]) : undefined, }; } function deserializeRenderParameterVersionResponse(data: any): RenderParameterVersionResponse { return { ...data, payload: data["payload"] !== undefined ? deserializeParameterVersionPayload(data["payload"]) : undefined, renderedPayload: data["renderedPayload"] !== undefined ? decodeBase64(data["renderedPayload"] as string) : undefined, }; } /** * Output-only policy member strings of a Google Cloud resource's built-in * identity. */ export interface ResourcePolicyMember { /** * Output only. IAM policy binding member referring to a Google Cloud * resource by user-assigned name (https://google.aip.dev/122). If a resource * is deleted and recreated with the same name, the binding will be applicable * to the new resource. Example: * `principal://parametermanager.googleapis.com/projects/12345/name/locations/us-central1-a/parameters/my-parameter` */ readonly iamPolicyNamePrincipal?: string; /** * Output only. IAM policy binding member referring to a Google Cloud * resource by system-assigned unique identifier * (https://google.aip.dev/148#uid). If a resource is deleted and recreated * with the same name, the binding will not be applicable to the new resource * Example: * `principal://parametermanager.googleapis.com/projects/12345/uid/locations/us-central1-a/parameters/a918fed5` */ readonly iamPolicyUidPrincipal?: string; } function decodeBase64(b64: string): Uint8Array { const binString = atob(b64); const size = binString.length; const bytes = new Uint8Array(size); for (let i = 0; i < size; i++) { bytes[i] = binString.charCodeAt(i); } return bytes; } const base64abc = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9","+","/"]; /** * CREDIT: https://gist.github.com/enepomnyaschih/72c423f727d395eeaa09697058238727 * Encodes a given Uint8Array, ArrayBuffer or string into RFC4648 base64 representation * @param data */ function encodeBase64(uint8: Uint8Array): string { let result = "", i; const l = uint8.length; for (i = 2; i < l; i += 3) { result += base64abc[uint8[i - 2] >> 2]; result += base64abc[((uint8[i - 2] & 0x03) << 4) | (uint8[i - 1] >> 4)]; result += base64abc[((uint8[i - 1] & 0x0f) << 2) | (uint8[i] >> 6)]; result += base64abc[uint8[i] & 0x3f]; } if (i === l + 1) { // 1 octet yet to write result += base64abc[uint8[i - 2] >> 2]; result += base64abc[(uint8[i - 2] & 0x03) << 4]; result += "=="; } if (i === l) { // 2 octets yet to write result += base64abc[uint8[i - 2] >> 2]; result += base64abc[((uint8[i - 2] & 0x03) << 4) | (uint8[i - 1] >> 4)]; result += base64abc[(uint8[i - 1] & 0x0f) << 2]; result += "="; } return result; }