No Description
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.

tasks.js 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.deleteExtensionInstanceTask = exports.configureExtensionInstanceTask = exports.updateExtensionInstanceTask = exports.createExtensionInstanceTask = exports.extensionsDeploymentHandler = void 0;
  4. const clc = require("colorette");
  5. const error_1 = require("../../error");
  6. const extensionsApi = require("../../extensions/extensionsApi");
  7. const extensionsHelper_1 = require("../../extensions/extensionsHelper");
  8. const refs = require("../../extensions/refs");
  9. const utils = require("../../utils");
  10. const isRetryable = (err) => err.status === 429 || err.status === 409;
  11. function extensionsDeploymentHandler(errorHandler) {
  12. return async (task) => {
  13. var _a, _b, _c, _d;
  14. let result;
  15. try {
  16. result = await task.run();
  17. }
  18. catch (err) {
  19. if (isRetryable(err)) {
  20. throw err;
  21. }
  22. errorHandler.record(task.spec.instanceId, task.type, (_d = (_c = (_b = (_a = 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.message) !== null && _d !== void 0 ? _d : err);
  23. }
  24. return result;
  25. };
  26. }
  27. exports.extensionsDeploymentHandler = extensionsDeploymentHandler;
  28. function createExtensionInstanceTask(projectId, instanceSpec, validateOnly = false) {
  29. const run = async () => {
  30. if (instanceSpec.ref) {
  31. await extensionsApi.createInstance({
  32. projectId,
  33. instanceId: instanceSpec.instanceId,
  34. params: instanceSpec.params,
  35. systemParams: instanceSpec.systemParams,
  36. extensionVersionRef: refs.toExtensionVersionRef(instanceSpec.ref),
  37. allowedEventTypes: instanceSpec.allowedEventTypes,
  38. eventarcChannel: instanceSpec.eventarcChannel,
  39. validateOnly,
  40. });
  41. }
  42. else if (instanceSpec.localPath) {
  43. const extensionSource = await (0, extensionsHelper_1.createSourceFromLocation)(projectId, instanceSpec.localPath);
  44. await extensionsApi.createInstance({
  45. projectId,
  46. instanceId: instanceSpec.instanceId,
  47. params: instanceSpec.params,
  48. systemParams: instanceSpec.systemParams,
  49. extensionSource,
  50. allowedEventTypes: instanceSpec.allowedEventTypes,
  51. eventarcChannel: instanceSpec.eventarcChannel,
  52. validateOnly,
  53. });
  54. }
  55. else {
  56. throw new error_1.FirebaseError(`Tried to create extension instance ${instanceSpec.instanceId} without a ref or a local path. This should never happen.`);
  57. }
  58. printSuccess(instanceSpec.instanceId, "create", validateOnly);
  59. return;
  60. };
  61. return {
  62. run,
  63. spec: instanceSpec,
  64. type: "create",
  65. };
  66. }
  67. exports.createExtensionInstanceTask = createExtensionInstanceTask;
  68. function updateExtensionInstanceTask(projectId, instanceSpec, validateOnly = false) {
  69. const run = async () => {
  70. if (instanceSpec.ref) {
  71. await extensionsApi.updateInstanceFromRegistry({
  72. projectId,
  73. instanceId: instanceSpec.instanceId,
  74. extRef: refs.toExtensionVersionRef(instanceSpec.ref),
  75. params: instanceSpec.params,
  76. systemParams: instanceSpec.systemParams,
  77. canEmitEvents: !!instanceSpec.allowedEventTypes,
  78. allowedEventTypes: instanceSpec.allowedEventTypes,
  79. eventarcChannel: instanceSpec.eventarcChannel,
  80. validateOnly,
  81. });
  82. }
  83. else if (instanceSpec.localPath) {
  84. const extensionSource = await (0, extensionsHelper_1.createSourceFromLocation)(projectId, instanceSpec.localPath);
  85. await extensionsApi.updateInstance({
  86. projectId,
  87. instanceId: instanceSpec.instanceId,
  88. extensionSource,
  89. validateOnly,
  90. params: instanceSpec.params,
  91. systemParams: instanceSpec.systemParams,
  92. canEmitEvents: !!instanceSpec.allowedEventTypes,
  93. allowedEventTypes: instanceSpec.allowedEventTypes,
  94. eventarcChannel: instanceSpec.eventarcChannel,
  95. });
  96. }
  97. else {
  98. throw new error_1.FirebaseError(`Tried to update extension instance ${instanceSpec.instanceId} without a ref or a local path. This should never happen.`);
  99. }
  100. printSuccess(instanceSpec.instanceId, "update", validateOnly);
  101. return;
  102. };
  103. return {
  104. run,
  105. spec: instanceSpec,
  106. type: "update",
  107. };
  108. }
  109. exports.updateExtensionInstanceTask = updateExtensionInstanceTask;
  110. function configureExtensionInstanceTask(projectId, instanceSpec, validateOnly = false) {
  111. const run = async () => {
  112. if (instanceSpec.ref) {
  113. await extensionsApi.configureInstance({
  114. projectId,
  115. instanceId: instanceSpec.instanceId,
  116. params: instanceSpec.params,
  117. systemParams: instanceSpec.systemParams,
  118. canEmitEvents: !!instanceSpec.allowedEventTypes,
  119. allowedEventTypes: instanceSpec.allowedEventTypes,
  120. eventarcChannel: instanceSpec.eventarcChannel,
  121. validateOnly,
  122. });
  123. }
  124. else if (instanceSpec.localPath) {
  125. throw new error_1.FirebaseError(`Tried to configure extension instance ${instanceSpec.instanceId} from a local path. This should never happen.`);
  126. }
  127. else {
  128. throw new error_1.FirebaseError(`Tried to configure extension instance ${instanceSpec.instanceId} without a ref or a local path. This should never happen.`);
  129. }
  130. printSuccess(instanceSpec.instanceId, "configure", validateOnly);
  131. return;
  132. };
  133. return {
  134. run,
  135. spec: instanceSpec,
  136. type: "configure",
  137. };
  138. }
  139. exports.configureExtensionInstanceTask = configureExtensionInstanceTask;
  140. function deleteExtensionInstanceTask(projectId, instanceSpec) {
  141. const run = async () => {
  142. await extensionsApi.deleteInstance(projectId, instanceSpec.instanceId);
  143. printSuccess(instanceSpec.instanceId, "delete", false);
  144. return;
  145. };
  146. return {
  147. run,
  148. spec: instanceSpec,
  149. type: "delete",
  150. };
  151. }
  152. exports.deleteExtensionInstanceTask = deleteExtensionInstanceTask;
  153. function printSuccess(instanceId, type, validateOnly) {
  154. const action = validateOnly ? `validated ${type} for` : `${type}d`;
  155. utils.logSuccess(clc.bold(clc.green("extensions")) + ` Successfully ${action} ${instanceId}`);
  156. }