firebase-app-distribution
Version:
A library that uses Firebase App Distribution APIs.
176 lines (174 loc) • 5.71 kB
JavaScript
import {
APP_DISTRIBUTION_ENDPOINT,
ENDPOINT_VERSION,
__async,
__spreadProps,
__spreadValues,
makeRequest
} from "./chunk-PTPJZ7KZ.mjs";
// src/testers.ts
function getEmailFromName(testerName) {
return testerName.split("/").pop();
}
var Testers = class {
constructor(parent) {
this.parent = parent;
}
add(emails) {
return __async(this, null, function* () {
const accessToken = yield this.parent.getAccessToken();
const projectNumber = yield this.parent.getProjectNumber();
const testers = [];
const url = new URL(
`${APP_DISTRIBUTION_ENDPOINT}/${ENDPOINT_VERSION}/projects/${projectNumber}/testers:batchAdd`
);
const requestBody = JSON.stringify({
emails
});
const response = yield makeRequest(url.toString(), {
headers: {
authorization: `Bearer ${accessToken}`
},
body: requestBody,
method: "POST"
});
for (let tester of response.testers) {
testers.push(__spreadProps(__spreadValues({}, tester), {
email: getEmailFromName(tester.name)
}));
}
return testers;
});
}
remove(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}/testers:batchRemove`
);
const requestBody = JSON.stringify({
emails
});
const response = yield makeRequest(url.toString(), {
headers: {
authorization: `Bearer ${accessToken}`
},
body: requestBody,
method: "POST"
});
return response.emails || [];
});
}
list() {
return __async(this, arguments, function* ({
pageSize = 50,
email,
displayName,
groups,
maxPages = 10
} = {}) {
const accessToken = yield this.parent.getAccessToken();
const projectNumber = yield this.parent.getProjectNumber();
const testerList = [];
const url = new URL(
`${APP_DISTRIBUTION_ENDPOINT}/${ENDPOINT_VERSION}/projects/${projectNumber}/testers`
);
url.searchParams.set("pageSize", pageSize.toString());
let filterParts = [];
if (email) filterParts.push(`name="projects/-/testers/${email}"`);
if (displayName) filterParts.push(`displayName="${displayName}"`);
if (groups) filterParts.push(`groups="projects/*/groups/${groups}"`);
if (filterParts.length > 0) {
url.searchParams.set("filter", filterParts.join(" "));
}
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.toString(), {
headers: {
authorization: `Bearer ${accessToken}`
},
body: null,
method: "GET"
});
if (response.testers === void 0) {
break;
}
for (let tester of response.testers) {
testerList.push(__spreadProps(__spreadValues({}, tester), {
email: getEmailFromName(tester.name)
}));
}
if (response.nextPageToken !== void 0) {
nextPageToken = response.nextPageToken;
} else {
break;
}
}
return testerList;
});
}
get(email) {
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}/testers`
);
url.searchParams.append("pageSize", "1");
url.searchParams.append("filter", `name="projects/-/testers/${email}"`);
const response = yield makeRequest(url.toString(), {
headers: {
authorization: `Bearer ${accessToken}`
},
body: null,
method: "GET"
});
return response.testers !== void 0 ? __spreadProps(__spreadValues({}, response.testers[0]), {
email: getEmailFromName(response.testers[0].name)
}) : null;
});
}
update(_0) {
return __async(this, arguments, function* (email, { displayName, groups } = {}) {
const accessToken = yield this.parent.getAccessToken();
const projectNumber = yield this.parent.getProjectNumber();
const url = new URL(
`${APP_DISTRIBUTION_ENDPOINT}/${ENDPOINT_VERSION}/projects/${projectNumber}/testers/${email}`
);
let updateMaskParts = [];
if (displayName !== void 0) {
updateMaskParts.push("displayName");
}
if (groups !== void 0) {
updateMaskParts.push("groups");
}
if (updateMaskParts.length > 0) {
url.searchParams.append("updateMask", updateMaskParts.join(","));
}
const formattedGroups = groups == null ? void 0 : groups.map(
(group) => `projects/${projectNumber}/groups/${group}`
);
const response = yield makeRequest(url.toString(), {
headers: {
authorization: `Bearer ${accessToken}`
},
body: JSON.stringify({
displayName: displayName || void 0,
groups: formattedGroups || void 0
}),
method: "PATCH"
});
return __spreadProps(__spreadValues({}, response), { email: getEmailFromName(response.name) });
});
}
};
export {
Testers
};
//# sourceMappingURL=chunk-NR2SZD6J.mjs.map