GSI - Employe Self Service Mobile
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
5.9 KiB

2 months ago
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.AppDistributionClient = exports.UploadReleaseResult = exports.IntegrationState = void 0;
  4. const utils = require("../utils");
  5. const operationPoller = require("../operation-poller");
  6. const error_1 = require("../error");
  7. const apiv2_1 = require("../apiv2");
  8. const api_1 = require("../api");
  9. var IntegrationState;
  10. (function (IntegrationState) {
  11. IntegrationState["AAB_INTEGRATION_STATE_UNSPECIFIED"] = "AAB_INTEGRATION_STATE_UNSPECIFIED";
  12. IntegrationState["INTEGRATED"] = "INTEGRATED";
  13. IntegrationState["PLAY_ACCOUNT_NOT_LINKED"] = "PLAY_ACCOUNT_NOT_LINKED";
  14. IntegrationState["NO_APP_WITH_GIVEN_BUNDLE_ID_IN_PLAY_ACCOUNT"] = "NO_APP_WITH_GIVEN_BUNDLE_ID_IN_PLAY_ACCOUNT";
  15. IntegrationState["APP_NOT_PUBLISHED"] = "APP_NOT_PUBLISHED";
  16. IntegrationState["AAB_STATE_UNAVAILABLE"] = "AAB_STATE_UNAVAILABLE";
  17. IntegrationState["PLAY_IAS_TERMS_NOT_ACCEPTED"] = "PLAY_IAS_TERMS_NOT_ACCEPTED";
  18. })(IntegrationState = exports.IntegrationState || (exports.IntegrationState = {}));
  19. var UploadReleaseResult;
  20. (function (UploadReleaseResult) {
  21. UploadReleaseResult["UPLOAD_RELEASE_RESULT_UNSPECIFIED"] = "UPLOAD_RELEASE_RESULT_UNSPECIFIED";
  22. UploadReleaseResult["RELEASE_CREATED"] = "RELEASE_CREATED";
  23. UploadReleaseResult["RELEASE_UPDATED"] = "RELEASE_UPDATED";
  24. UploadReleaseResult["RELEASE_UNMODIFIED"] = "RELEASE_UNMODIFIED";
  25. })(UploadReleaseResult = exports.UploadReleaseResult || (exports.UploadReleaseResult = {}));
  26. class AppDistributionClient {
  27. constructor() {
  28. this.appDistroV2Client = new apiv2_1.Client({
  29. urlPrefix: api_1.appDistributionOrigin,
  30. apiVersion: "v1",
  31. });
  32. }
  33. async getAabInfo(appName) {
  34. const apiResponse = await this.appDistroV2Client.get(`/${appName}/aabInfo`);
  35. return apiResponse.body;
  36. }
  37. async uploadRelease(appName, distribution) {
  38. const client = new apiv2_1.Client({ urlPrefix: api_1.appDistributionOrigin });
  39. const apiResponse = await client.request({
  40. method: "POST",
  41. path: `/upload/v1/${appName}/releases:upload`,
  42. headers: {
  43. "X-Goog-Upload-File-Name": distribution.getFileName(),
  44. "X-Goog-Upload-Protocol": "raw",
  45. "Content-Type": "application/octet-stream",
  46. },
  47. responseType: "json",
  48. body: distribution.readStream(),
  49. });
  50. return apiResponse.body.name;
  51. }
  52. async pollUploadStatus(operationName) {
  53. return operationPoller.pollOperation({
  54. pollerName: "App Distribution Upload Poller",
  55. apiOrigin: api_1.appDistributionOrigin,
  56. apiVersion: "v1",
  57. operationResourceName: operationName,
  58. masterTimeout: 5 * 60 * 1000,
  59. backoff: 1000,
  60. maxBackoff: 10 * 1000,
  61. });
  62. }
  63. async updateReleaseNotes(releaseName, releaseNotes) {
  64. if (!releaseNotes) {
  65. utils.logWarning("no release notes specified, skipping");
  66. return;
  67. }
  68. utils.logBullet("updating release notes...");
  69. const data = {
  70. name: releaseName,
  71. releaseNotes: {
  72. text: releaseNotes,
  73. },
  74. };
  75. const queryParams = { updateMask: "release_notes.text" };
  76. try {
  77. await this.appDistroV2Client.patch(`/${releaseName}`, data, { queryParams });
  78. }
  79. catch (err) {
  80. throw new error_1.FirebaseError(`failed to update release notes with ${err === null || err === void 0 ? void 0 : err.message}`);
  81. }
  82. utils.logSuccess("added release notes successfully");
  83. }
  84. async distribute(releaseName, testerEmails = [], groupAliases = []) {
  85. var _a, _b, _c;
  86. if (testerEmails.length === 0 && groupAliases.length === 0) {
  87. utils.logWarning("no testers or groups specified, skipping");
  88. return;
  89. }
  90. utils.logBullet("distributing to testers/groups...");
  91. const data = {
  92. testerEmails,
  93. groupAliases,
  94. };
  95. try {
  96. await this.appDistroV2Client.post(`/${releaseName}:distribute`, data);
  97. }
  98. catch (err) {
  99. let errorMessage = err.message;
  100. const errorStatus = (_c = (_b = (_a = err === null || err === void 0 ? void 0 : err.context) === null || _a === void 0 ? void 0 : _a.body) === null || _b === void 0 ? void 0 : _b.error) === null || _c === void 0 ? void 0 : _c.status;
  101. if (errorStatus === "FAILED_PRECONDITION") {
  102. errorMessage = "invalid testers";
  103. }
  104. else if (errorStatus === "INVALID_ARGUMENT") {
  105. errorMessage = "invalid groups";
  106. }
  107. throw new error_1.FirebaseError(`failed to distribute to testers/groups: ${errorMessage}`, {
  108. exit: 1,
  109. });
  110. }
  111. utils.logSuccess("distributed to testers/groups successfully");
  112. }
  113. async addTesters(projectName, emails) {
  114. try {
  115. await this.appDistroV2Client.request({
  116. method: "POST",
  117. path: `${projectName}/testers:batchAdd`,
  118. body: { emails: emails },
  119. });
  120. }
  121. catch (err) {
  122. throw new error_1.FirebaseError(`Failed to add testers ${err}`);
  123. }
  124. utils.logSuccess(`Testers created successfully`);
  125. }
  126. async removeTesters(projectName, emails) {
  127. let apiResponse;
  128. try {
  129. apiResponse = await this.appDistroV2Client.request({
  130. method: "POST",
  131. path: `${projectName}/testers:batchRemove`,
  132. body: { emails: emails },
  133. });
  134. }
  135. catch (err) {
  136. throw new error_1.FirebaseError(`Failed to remove testers ${err}`);
  137. }
  138. return apiResponse.body;
  139. }
  140. }
  141. exports.AppDistributionClient = AppDistributionClient;