UNPKG

firebase-app-distribution

Version:
119 lines (118 loc) 3.6 kB
import { Groups } from "./chunk-2OREYMMB.mjs"; import { Testers } from "./chunk-NR2SZD6J.mjs"; import { Releases } from "./chunk-UGTPM7SF.mjs"; import "./chunk-N4JVPYC6.mjs"; import { AUTH_SCOPES, __async, __spreadProps, __spreadValues } from "./chunk-PTPJZ7KZ.mjs"; // src/index.ts import { GoogleAuth } from "google-auth-library"; var FirebaseAppDistribution = class { constructor(authOptions) { this.projectNumber = null; this.projectId = null; this.googleAuth = new GoogleAuth(__spreadProps(__spreadValues({}, authOptions), { scopes: AUTH_SCOPES })); this.testers = new Testers(this); this.groups = new Groups(this); this.releases = new Releases(this); } getProjectId() { return __async(this, null, function* () { if (this.projectId) { return this.projectId; } yield this.getAccessToken(); this.projectId = yield this.googleAuth.getProjectId(); return this.projectId; }); } getProjectNumber() { return __async(this, null, function* () { if (this.projectNumber) { return this.projectNumber; } const projectId = yield this.getProjectId(); const client = yield this.googleAuth.getClient(); const url = `https://cloudresourcemanager.googleapis.com/v1/projects/${projectId}`; const res = yield client.request({ url }); this.projectNumber = res.data.projectNumber; if (!this.projectNumber) { throw new Error("Failed to retrieve project number"); } return this.projectNumber; }); } getAccessToken() { return __async(this, null, function* () { if (this.accessToken) { return this.accessToken; } const accessToken = yield this.googleAuth.getAccessToken(); if (!accessToken) { throw new Error("Failed to retrieve access token"); } this.accessToken = accessToken; return this.accessToken; }); } uploadAndDistribute(_0) { return __async(this, arguments, function* ({ appId, binaryPath, fileName, testerEmails = [], groupAliases = [], releaseNotes, uploadOperationInteval = 500, uploadOperationTimeout = 5e3 }) { const operation = yield this.releases.upload(appId, binaryPath, fileName); const operationName = operation.name; const uploadTimeout = setTimeout(() => { throw new Error("Upload operation timed out"); }, uploadOperationTimeout); let doneUploading = false; let releaseName = null; while (!doneUploading) { const operationData = yield this.releases.operations.get(operationName); if (operationData.done) { doneUploading = true; releaseName = operationData.response.release.name; clearTimeout(uploadTimeout); } if (operationData.error) { throw new Error( `Upload operation failed with code ${operationData.error.code} and error: ${operationData.error.message}` ); } yield new Promise((res) => setTimeout(res, uploadOperationInteval)); } if (testerEmails.length !== 0 || groupAliases.length !== 0) { yield this.releases.distribute(releaseName, { testerEmails, groupAliases }); } if (releaseNotes) { yield this.releases.addReleaseNotes(releaseName, releaseNotes); } const finalReleaseData = yield this.releases.get(releaseName); return finalReleaseData; }); } }; export { FirebaseAppDistribution }; //# sourceMappingURL=index.mjs.map