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.

53 lines
1.8 KiB

2 months ago
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.EmulatorHubClient = void 0;
  4. const hub_1 = require("./hub");
  5. const error_1 = require("../error");
  6. const apiv2_1 = require("../apiv2");
  7. class EmulatorHubClient {
  8. constructor(projectId) {
  9. this.projectId = projectId;
  10. this.locator = hub_1.EmulatorHub.readLocatorFile(projectId);
  11. }
  12. foundHub() {
  13. return this.locator !== undefined;
  14. }
  15. getStatus() {
  16. return this.tryOrigins(async (client, origin) => {
  17. await client.get("/");
  18. return origin;
  19. });
  20. }
  21. async tryOrigins(task) {
  22. const origins = this.assertLocator().origins;
  23. let err = undefined;
  24. for (const origin of origins) {
  25. try {
  26. const apiClient = new apiv2_1.Client({ urlPrefix: origin, auth: false });
  27. return await task(apiClient, origin);
  28. }
  29. catch (e) {
  30. if (!err) {
  31. err = e;
  32. }
  33. }
  34. }
  35. throw err !== null && err !== void 0 ? err : new Error("Cannot find working hub origin. Tried:" + origins.join(" "));
  36. }
  37. async getEmulators() {
  38. const res = await this.tryOrigins((client) => client.get(hub_1.EmulatorHub.PATH_EMULATORS));
  39. return res.body;
  40. }
  41. async postExport(options) {
  42. const origin = await this.getStatus();
  43. const apiClient = new apiv2_1.Client({ urlPrefix: origin, auth: false });
  44. await apiClient.post(hub_1.EmulatorHub.PATH_EXPORT, options);
  45. }
  46. assertLocator() {
  47. if (this.locator === undefined) {
  48. throw new error_1.FirebaseError(`Cannot contact the Emulator Hub for project ${this.projectId}`);
  49. }
  50. return this.locator;
  51. }
  52. }
  53. exports.EmulatorHubClient = EmulatorHubClient;