firebase-app-distribution
Version:
A library that uses Firebase App Distribution APIs.
259 lines (256 loc) • 8.66 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
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/groups.ts
var groups_exports = {};
__export(groups_exports, {
Groups: () => Groups
});
module.exports = __toCommonJS(groups_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/groups.ts
function getGroupIdFromName(groupName) {
return groupName.split("/").pop();
}
var Groups = class {
constructor(parent) {
this.parent = parent;
}
create(displayName, groupId) {
return __async(this, null, function* () {
const accessToken = yield this.parent.getAccessToken();
const projectNumber = yield this.parent.getProjectNumber();
const url = new URL(
`${APP_DISTRIBUTION_ENDPOINT}/${ENDPOINT_VERSION}/projects/${projectNumber}/groups`
);
if (groupId) {
url.searchParams.set("groupId", groupId);
}
const requestBody = JSON.stringify({
displayName
});
const response = yield makeRequest(url, {
headers: {
authorization: `Bearer ${accessToken}`
},
body: requestBody,
method: "POST"
});
return __spreadProps(__spreadValues({}, response), { id: getGroupIdFromName(response.name) });
});
}
delete(groupId) {
return __async(this, null, function* () {
const accessToken = yield this.parent.getAccessToken();
const projectNumber = yield this.parent.getProjectNumber();
const url = new URL(
`${APP_DISTRIBUTION_ENDPOINT}/${ENDPOINT_VERSION}/projects/${projectNumber}/groups/${groupId}`
);
const response = yield makeRequest(url, {
headers: {
authorization: `Bearer ${accessToken}`
},
body: null,
method: "DELETE"
});
return response;
});
}
get(groupId) {
return __async(this, null, function* () {
const accessToken = yield this.parent.getAccessToken();
const projectNumber = yield this.parent.getProjectNumber();
const url = new URL(
`${APP_DISTRIBUTION_ENDPOINT}/${ENDPOINT_VERSION}/projects/${projectNumber}/groups/${groupId}`
);
const response = yield makeRequest(url, {
headers: {
authorization: `Bearer ${accessToken}`
},
body: null,
method: "GET"
});
if (response.name === void 0) {
return null;
}
return __spreadProps(__spreadValues({}, response), { id: getGroupIdFromName(response.name) });
});
}
list() {
return __async(this, arguments, function* ({ pageSize = 25, maxPages = 10 } = {}) {
const accessToken = yield this.parent.getAccessToken();
const projectNumber = yield this.parent.getProjectNumber();
const groupList = [];
const url = new URL(
`${APP_DISTRIBUTION_ENDPOINT}/${ENDPOINT_VERSION}/projects/${projectNumber}/groups`
);
url.searchParams.set("pageSize", pageSize.toString());
let nextPageToken = "";
for (let page = 0; page < maxPages; page++) {
if (nextPageToken) {
url.searchParams.set("pageToken", nextPageToken);
} else {
url.searchParams.delete("pageToken");
}
const response = yield makeRequest(url, {
headers: {
authorization: `Bearer ${accessToken}`
},
body: null,
method: "GET"
});
if (response.groups === void 0) {
break;
}
for (let group of response.groups) {
groupList.push(__spreadProps(__spreadValues({}, group), {
id: getGroupIdFromName(group.name)
}));
}
if (response.nextPageToken !== void 0) {
nextPageToken = response.nextPageToken;
} else {
break;
}
}
return groupList;
});
}
update(_0, _1) {
return __async(this, arguments, function* (groupId, { displayName }) {
const accessToken = yield this.parent.getAccessToken();
const projectNumber = yield this.parent.getProjectNumber();
const url = new URL(
`${APP_DISTRIBUTION_ENDPOINT}/${ENDPOINT_VERSION}/projects/${projectNumber}/groups/${groupId}`
);
if (displayName) {
url.searchParams.set("updateMask", "displayName");
}
const requestBody = JSON.stringify({
displayName
});
const response = yield makeRequest(url, {
headers: {
authorization: `Bearer ${accessToken}`
},
body: requestBody,
method: "PATCH"
});
return __spreadProps(__spreadValues({}, response), { id: getGroupIdFromName(response.name) });
});
}
removeTesters(groupId, emails) {
return __async(this, null, function* () {
const accessToken = yield this.parent.getAccessToken();
const projectNumber = yield this.parent.getProjectNumber();
const url = new URL(
`${APP_DISTRIBUTION_ENDPOINT}/${ENDPOINT_VERSION}/projects/${projectNumber}/groups/${groupId}:batchLeave`
);
const reuqestBody = JSON.stringify({
emails
});
const response = yield makeRequest(url, {
headers: {
authorization: `Bearer ${accessToken}`
},
body: reuqestBody,
method: "POST"
});
return response;
});
}
addTesters(groupId, emails) {
return __async(this, null, function* () {
const accessToken = yield this.parent.getAccessToken();
const projectNumber = yield this.parent.getProjectNumber();
const url = new URL(
`${APP_DISTRIBUTION_ENDPOINT}/${ENDPOINT_VERSION}/projects/${projectNumber}/groups/${groupId}:batchJoin`
);
const reuqestBody = JSON.stringify({
emails,
createMissingTesters: true
});
const response = yield makeRequest(url, {
headers: {
authorization: `Bearer ${accessToken}`
},
body: reuqestBody,
method: "POST"
});
return response;
});
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Groups
});
//# sourceMappingURL=groups.js.map