firebase-app-distribution
Version:
A library that uses Firebase App Distribution APIs.
96 lines (93 loc) • 3.1 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var __async = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};
// src/releases/operations.ts
var operations_exports = {};
__export(operations_exports, {
Operations: () => Operations
});
module.exports = __toCommonJS(operations_exports);
// src/utils.ts
var APP_DISTRIBUTION_ENDPOINT = "https://firebaseappdistribution.googleapis.com";
var ENDPOINT_VERSION = "v1";
function makeRequest(input, init) {
return __async(this, null, function* () {
const response = yield fetch(input, init);
if (response.status !== 200) {
const errMessage = yield response.text();
throw new Error(
`Request failed with status code ${response.status} and message: ${errMessage}`
);
}
const responseText = yield response.text();
const responseObj = JSON.parse(responseText);
return responseObj;
});
}
// src/releases/operations.ts
function isValidOperationName(operationName) {
const regex = /^projects\/[^/]+\/apps\/[^/]+\/releases\/[^/]+\/operations\/[^/]+$/;
return regex.test(operationName);
}
var Operations = class {
constructor(parent) {
this.parent = parent;
}
get(operationName) {
return __async(this, null, function* () {
if (!isValidOperationName(operationName)) {
throw new Error(`Invalid operation name: ${operationName}`);
}
const accessToken = yield this.parent.getAccessToken();
const url = new URL(
`${APP_DISTRIBUTION_ENDPOINT}/${ENDPOINT_VERSION}/${operationName}`
);
const response = yield makeRequest(url.toString(), {
headers: {
authorization: `Bearer ${accessToken}`
}
});
return response;
});
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Operations
});
//# sourceMappingURL=operations.js.map