firebase-tools 9.18.0 → 9.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/CHANGELOG.md +3 -6
  2. package/lib/api.js +3 -0
  3. package/lib/apiv2.js +8 -5
  4. package/lib/command.js +1 -1
  5. package/lib/commands/crashlytics-symbols-upload.js +146 -0
  6. package/lib/commands/deploy.js +9 -1
  7. package/lib/commands/ext-configure.js +9 -2
  8. package/lib/commands/ext-dev-deprecate.js +63 -0
  9. package/lib/commands/ext-dev-extension-delete.js +2 -1
  10. package/lib/commands/ext-dev-publish.js +10 -4
  11. package/lib/commands/ext-dev-undeprecate.js +56 -0
  12. package/lib/commands/ext-dev-unpublish.js +12 -4
  13. package/lib/commands/ext-export.js +44 -0
  14. package/lib/commands/ext-install.js +50 -13
  15. package/lib/commands/ext-uninstall.js +6 -0
  16. package/lib/commands/ext-update.js +60 -18
  17. package/lib/commands/functions-config-export.js +115 -0
  18. package/lib/commands/functions-delete.js +47 -25
  19. package/lib/commands/functions-list.js +12 -12
  20. package/lib/commands/index.js +9 -0
  21. package/lib/commands/init.js +3 -0
  22. package/lib/config.js +3 -2
  23. package/lib/deploy/extensions/args.js +2 -0
  24. package/lib/deploy/extensions/deploy.js +49 -0
  25. package/lib/deploy/extensions/deploymentSummary.js +52 -0
  26. package/lib/deploy/extensions/errors.js +31 -0
  27. package/lib/deploy/extensions/index.js +8 -0
  28. package/lib/deploy/extensions/planner.js +95 -0
  29. package/lib/deploy/extensions/prepare.js +103 -0
  30. package/lib/deploy/extensions/release.js +43 -0
  31. package/lib/deploy/extensions/secrets.js +150 -0
  32. package/lib/deploy/extensions/tasks.js +98 -0
  33. package/lib/deploy/extensions/validate.js +17 -0
  34. package/lib/deploy/functions/backend.js +93 -115
  35. package/lib/deploy/functions/checkIam.js +8 -8
  36. package/lib/deploy/functions/containerCleaner.js +82 -22
  37. package/lib/deploy/functions/deploy.js +4 -10
  38. package/lib/deploy/functions/functionsDeployHelper.js +3 -68
  39. package/lib/deploy/functions/prepare.js +62 -27
  40. package/lib/deploy/functions/pricing.js +17 -17
  41. package/lib/deploy/functions/prompts.js +22 -21
  42. package/lib/deploy/functions/release/executor.js +39 -0
  43. package/lib/deploy/functions/release/fabricator.js +422 -0
  44. package/lib/deploy/functions/release/index.js +73 -0
  45. package/lib/deploy/functions/release/planner.js +162 -0
  46. package/lib/deploy/functions/release/reporter.js +165 -0
  47. package/lib/deploy/functions/release/sourceTokenScraper.js +28 -0
  48. package/lib/deploy/functions/release/timer.js +14 -0
  49. package/lib/deploy/functions/runtimes/discovery/v1alpha1.js +129 -126
  50. package/lib/deploy/functions/runtimes/node/parseTriggers.js +41 -45
  51. package/lib/deploy/functions/triggerRegionHelper.js +40 -0
  52. package/lib/deploy/functions/validate.js +1 -24
  53. package/lib/deploy/index.js +1 -0
  54. package/lib/downloadUtils.js +37 -0
  55. package/lib/emulator/auth/apiSpec.js +1788 -403
  56. package/lib/emulator/auth/handlers.js +6 -5
  57. package/lib/emulator/auth/operations.js +439 -40
  58. package/lib/emulator/auth/server.js +32 -11
  59. package/lib/emulator/auth/state.js +205 -5
  60. package/lib/emulator/auth/widget_ui.js +2 -2
  61. package/lib/emulator/download.js +2 -31
  62. package/lib/emulator/downloadableEmulators.js +7 -7
  63. package/lib/emulator/emulatorLogger.js +0 -3
  64. package/lib/emulator/events/types.js +16 -0
  65. package/lib/emulator/functionsEmulator.js +120 -21
  66. package/lib/emulator/functionsEmulatorRuntime.js +46 -121
  67. package/lib/emulator/functionsEmulatorShared.js +51 -7
  68. package/lib/emulator/functionsEmulatorShell.js +1 -1
  69. package/lib/emulator/pubsubEmulator.js +61 -40
  70. package/lib/emulator/storage/cloudFunctions.js +37 -7
  71. package/lib/extensions/askUserForConsent.js +14 -1
  72. package/lib/extensions/askUserForParam.js +81 -4
  73. package/lib/extensions/billingMigrationHelper.js +1 -11
  74. package/lib/extensions/changelog.js +2 -1
  75. package/lib/extensions/checkProjectBilling.js +7 -7
  76. package/lib/extensions/displayExtensionInfo.js +35 -33
  77. package/lib/extensions/emulator/optionsHelper.js +3 -3
  78. package/lib/extensions/emulator/triggerHelper.js +2 -32
  79. package/lib/extensions/export.js +107 -0
  80. package/lib/extensions/extensionsApi.js +149 -97
  81. package/lib/extensions/extensionsHelper.js +36 -32
  82. package/lib/extensions/listExtensions.js +16 -11
  83. package/lib/extensions/paramHelper.js +73 -40
  84. package/lib/extensions/provisioningHelper.js +16 -3
  85. package/lib/extensions/refs.js +67 -0
  86. package/lib/extensions/secretsUtils.js +59 -0
  87. package/lib/extensions/updateHelper.js +33 -47
  88. package/lib/extensions/versionHelper.js +14 -0
  89. package/lib/extensions/warnings.js +33 -1
  90. package/lib/functional.js +64 -0
  91. package/lib/functions/env.js +26 -13
  92. package/lib/functions/runtimeConfigExport.js +137 -0
  93. package/lib/gcp/artifactregistry.js +16 -0
  94. package/lib/gcp/cloudfunctions.js +65 -35
  95. package/lib/gcp/cloudfunctionsv2.js +56 -43
  96. package/lib/gcp/cloudscheduler.js +22 -16
  97. package/lib/gcp/cloudtasks.js +143 -0
  98. package/lib/gcp/docker.js +7 -1
  99. package/lib/gcp/proto.js +2 -2
  100. package/lib/gcp/pubsub.js +1 -9
  101. package/lib/gcp/secretManager.js +132 -0
  102. package/lib/gcp/storage.js +16 -0
  103. package/lib/previews.js +1 -1
  104. package/lib/requireInteractive.js +12 -0
  105. package/lib/utils.js +30 -1
  106. package/package.json +6 -4
  107. package/schema/firebase-config.json +9 -0
  108. package/lib/deploy/functions/deploymentPlanner.js +0 -113
  109. package/lib/deploy/functions/deploymentTimer.js +0 -23
  110. package/lib/deploy/functions/errorHandler.js +0 -75
  111. package/lib/deploy/functions/release.js +0 -116
  112. package/lib/deploy/functions/tasks.js +0 -324
  113. package/lib/functions/listFunctions.js +0 -10
  114. package/lib/functionsDelete.js +0 -60
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.prepare = void 0;
3
+ exports.inferDetailsFromExisting = exports.prepare = void 0;
4
4
  const clc = require("cli-color");
5
5
  const ensureCloudBuildEnabled_1 = require("./ensureCloudBuildEnabled");
6
6
  const functionsDeployHelper_1 = require("./functionsDeployHelper");
@@ -18,6 +18,7 @@ const runtimes = require("./runtimes");
18
18
  const validate = require("./validate");
19
19
  const utils = require("../../utils");
20
20
  const logger_1 = require("../../logger");
21
+ const triggerRegionHelper_1 = require("./triggerRegionHelper");
21
22
  function hasUserConfig(config) {
22
23
  return Object.keys(config).length > 1;
23
24
  }
@@ -52,56 +53,90 @@ async function prepare(context, options, payload) {
52
53
  projectAlias: options.projectAlias,
53
54
  };
54
55
  const userEnvs = functionsEnv.loadUserEnvs(userEnvOpt);
56
+ const usedDotenv = hasDotenv(userEnvOpt);
55
57
  const tag = hasUserConfig(runtimeConfig)
56
- ? hasDotenv(userEnvOpt)
58
+ ? usedDotenv
57
59
  ? "mixed"
58
60
  : "runtime_config"
59
- : hasDotenv(userEnvOpt)
61
+ : usedDotenv
60
62
  ? "dotenv"
61
63
  : "none";
62
- track_1.track("functions_codebase_deploy_env_method", tag);
64
+ await track_1.track("functions_codebase_deploy_env_method", tag);
63
65
  logger_1.logger.debug(`Analyzing ${runtimeDelegate.name} backend spec`);
64
66
  const wantBackend = await runtimeDelegate.discoverSpec(runtimeConfig, firebaseEnvs);
65
67
  wantBackend.environmentVariables = Object.assign(Object.assign({}, userEnvs), firebaseEnvs);
66
68
  payload.functions = { backend: wantBackend };
67
- if (wantBackend.cloudFunctions.find((f) => f.platform === "gcfv2")) {
68
- const V2_APIS = {
69
- artifactregistry: "artifactregistry.googleapis.com",
70
- cloudrun: "run.googleapis.com",
71
- eventarc: "eventarc.googleapis.com",
72
- pubsub: "pubsub.googleapis.com",
73
- };
74
- const enablements = Object.entries(V2_APIS).map(([tag, api]) => {
75
- return ensureApiEnabled.ensure(context.projectId, api, tag);
69
+ if (backend.someEndpoint(wantBackend, (e) => e.platform === "gcfv2")) {
70
+ const V2_APIS = [
71
+ "artifactregistry.googleapis.com",
72
+ "run.googleapis.com",
73
+ "eventarc.googleapis.com",
74
+ "pubsub.googleapis.com",
75
+ "storage.googleapis.com",
76
+ ];
77
+ const enablements = V2_APIS.map((api) => {
78
+ return ensureApiEnabled.ensure(context.projectId, api, "functions");
76
79
  });
77
80
  await Promise.all(enablements);
78
81
  }
79
- if (wantBackend.cloudFunctions.length) {
82
+ if (backend.someEndpoint(wantBackend, () => true)) {
80
83
  utils_1.logBullet(clc.cyan.bold("functions:") +
81
84
  " preparing " +
82
85
  clc.bold(options.config.src.functions.source) +
83
86
  " directory for uploading...");
84
87
  }
85
- if (wantBackend.cloudFunctions.find((fn) => fn.platform === "gcfv1")) {
88
+ if (backend.someEndpoint(wantBackend, (e) => e.platform === "gcfv1")) {
86
89
  context.functionsSourceV1 = await prepareFunctionsUpload_1.prepareFunctionsUpload(runtimeConfig, options);
87
90
  }
88
- if (wantBackend.cloudFunctions.find((fn) => fn.platform === "gcfv2")) {
91
+ if (backend.someEndpoint(wantBackend, (e) => e.platform === "gcfv2")) {
89
92
  context.functionsSourceV2 = await prepareFunctionsUpload_1.prepareFunctionsUpload(undefined, options);
90
93
  }
91
- wantBackend.cloudFunctions.forEach((fn) => {
92
- fn.environmentVariables = wantBackend.environmentVariables;
93
- });
94
- await Promise.all(Object.keys(wantBackend.requiredAPIs).map((friendlyName) => {
95
- ensureApiEnabled.ensure(projectId, wantBackend.requiredAPIs[friendlyName], friendlyName, false);
94
+ for (const endpoint of backend.allEndpoints(wantBackend)) {
95
+ endpoint.environmentVariables = wantBackend.environmentVariables;
96
+ }
97
+ await Promise.all(Object.values(wantBackend.requiredAPIs).map((api) => {
98
+ return ensureApiEnabled.ensure(projectId, api, "functions", false);
96
99
  }));
97
- validate.functionIdsAreValid(wantBackend.cloudFunctions);
100
+ validate.functionIdsAreValid(backend.allEndpoints(wantBackend));
98
101
  context.filters = functionsDeployHelper_1.getFilterGroups(options);
99
- const wantFunctions = wantBackend.cloudFunctions.filter((fn) => {
100
- return functionsDeployHelper_1.functionMatchesAnyGroup(fn, context.filters);
102
+ const matchingBackend = backend.matchingBackend(wantBackend, (endpoint) => {
103
+ return functionsDeployHelper_1.functionMatchesAnyGroup(endpoint, context.filters);
101
104
  });
102
- const haveFunctions = (await backend.existingBackend(context)).cloudFunctions;
103
- await prompts_1.promptForFailurePolicies(options, wantFunctions, haveFunctions);
104
- await prompts_1.promptForMinInstances(options, wantFunctions, haveFunctions);
105
+ const haveBackend = await backend.existingBackend(context);
106
+ inferDetailsFromExisting(wantBackend, haveBackend, usedDotenv);
107
+ await triggerRegionHelper_1.lookupMissingTriggerRegions(wantBackend);
108
+ await prompts_1.promptForFailurePolicies(options, matchingBackend, haveBackend);
109
+ await prompts_1.promptForMinInstances(options, matchingBackend, haveBackend);
105
110
  await backend.checkAvailability(context, wantBackend);
106
111
  }
107
112
  exports.prepare = prepare;
113
+ function inferDetailsFromExisting(want, have, usedDotenv) {
114
+ var _a;
115
+ for (const wantE of backend.allEndpoints(want)) {
116
+ const haveE = (_a = have.endpoints[wantE.region]) === null || _a === void 0 ? void 0 : _a[wantE.id];
117
+ if (!haveE) {
118
+ continue;
119
+ }
120
+ if (!usedDotenv) {
121
+ wantE.environmentVariables = Object.assign(Object.assign({}, haveE.environmentVariables), wantE.environmentVariables);
122
+ }
123
+ if (!wantE.availableMemoryMb && haveE.availableMemoryMb) {
124
+ wantE.availableMemoryMb = haveE.availableMemoryMb;
125
+ }
126
+ maybeCopyTriggerRegion(wantE, haveE);
127
+ }
128
+ }
129
+ exports.inferDetailsFromExisting = inferDetailsFromExisting;
130
+ function maybeCopyTriggerRegion(wantE, haveE) {
131
+ if (!backend.isEventTriggered(wantE) || !backend.isEventTriggered(haveE)) {
132
+ return;
133
+ }
134
+ if (wantE.eventTrigger.region || !haveE.eventTrigger.region) {
135
+ return;
136
+ }
137
+ if (JSON.stringify(haveE.eventTrigger.eventFilters) !==
138
+ JSON.stringify(wantE.eventTrigger.eventFilters)) {
139
+ return;
140
+ }
141
+ wantE.eventTrigger.region = haveE.eventTrigger.region;
142
+ }
@@ -102,52 +102,52 @@ const MB_TO_GHZ = {
102
102
  4096: 4.8,
103
103
  8192: 4.8,
104
104
  };
105
- function canCalculateMinInstanceCost(functionSpec) {
106
- if (!functionSpec.minInstances) {
105
+ function canCalculateMinInstanceCost(endpoint) {
106
+ if (!endpoint.minInstances) {
107
107
  return true;
108
108
  }
109
- if (functionSpec.platform == "gcfv1") {
110
- if (!MB_TO_GHZ[functionSpec.availableMemoryMb || 256]) {
109
+ if (endpoint.platform == "gcfv1") {
110
+ if (!MB_TO_GHZ[endpoint.availableMemoryMb || 256]) {
111
111
  return false;
112
112
  }
113
- if (!V1_REGION_TO_TIER[functionSpec.region]) {
113
+ if (!V1_REGION_TO_TIER[endpoint.region]) {
114
114
  return false;
115
115
  }
116
116
  return true;
117
117
  }
118
- if (!V2_REGION_TO_TIER[functionSpec.region]) {
118
+ if (!V2_REGION_TO_TIER[endpoint.region]) {
119
119
  return false;
120
120
  }
121
121
  return true;
122
122
  }
123
123
  exports.canCalculateMinInstanceCost = canCalculateMinInstanceCost;
124
124
  const SECONDS_PER_MONTH = 30 * 24 * 60 * 60;
125
- function monthlyMinInstanceCost(functions) {
125
+ function monthlyMinInstanceCost(endpoints) {
126
126
  const usage = {
127
127
  gcfv1: { 1: { ram: 0, cpu: 0 }, 2: { ram: 0, cpu: 0 } },
128
128
  gcfv2: { 1: { ram: 0, cpu: 0 }, 2: { ram: 0, cpu: 0 } },
129
129
  };
130
- for (const func of functions) {
131
- if (!func.minInstances) {
130
+ for (const endpoint of endpoints) {
131
+ if (!endpoint.minInstances) {
132
132
  continue;
133
133
  }
134
- const ramMb = func.availableMemoryMb || 256;
134
+ const ramMb = endpoint.availableMemoryMb || 256;
135
135
  const ramGb = ramMb / 1024;
136
- if (func.platform === "gcfv1") {
136
+ if (endpoint.platform === "gcfv1") {
137
137
  const cpu = MB_TO_GHZ[ramMb];
138
- const tier = V1_REGION_TO_TIER[func.region];
138
+ const tier = V1_REGION_TO_TIER[endpoint.region];
139
139
  usage["gcfv1"][tier].ram =
140
- usage["gcfv1"][tier].ram + ramGb * SECONDS_PER_MONTH * func.minInstances;
140
+ usage["gcfv1"][tier].ram + ramGb * SECONDS_PER_MONTH * endpoint.minInstances;
141
141
  usage["gcfv1"][tier].cpu =
142
- usage["gcfv1"][tier].cpu + MB_TO_GHZ[ramMb] * SECONDS_PER_MONTH * func.minInstances;
142
+ usage["gcfv1"][tier].cpu + cpu * SECONDS_PER_MONTH * endpoint.minInstances;
143
143
  }
144
144
  else {
145
145
  const cpu = 1;
146
- const tier = V2_REGION_TO_TIER[func.region];
146
+ const tier = V2_REGION_TO_TIER[endpoint.region];
147
147
  usage["gcfv2"][tier].ram =
148
- usage["gcfv2"][tier].ram + ramGb * SECONDS_PER_MONTH * func.minInstances;
148
+ usage["gcfv2"][tier].ram + ramGb * SECONDS_PER_MONTH * endpoint.minInstances;
149
149
  usage["gcfv2"][tier].cpu =
150
- usage["gcfv2"][tier].cpu + cpu * SECONDS_PER_MONTH * func.minInstances;
150
+ usage["gcfv2"][tier].cpu + cpu * SECONDS_PER_MONTH * endpoint.minInstances;
151
151
  }
152
152
  }
153
153
  let v1MemoryBill = usage["gcfv1"][1].ram * exports.V1_RATES.memoryGb[1] + usage["gcfv1"][2].ram * exports.V1_RATES.memoryGb[2];
@@ -10,23 +10,22 @@ const backend = require("./backend");
10
10
  const pricing = require("./pricing");
11
11
  const utils = require("../../utils");
12
12
  async function promptForFailurePolicies(options, want, have) {
13
- const retryFunctions = want.filter((fn) => {
14
- return backend.isEventTrigger(fn.trigger) && fn.trigger.retry;
13
+ const retryEndpoints = backend.allEndpoints(want).filter((e) => {
14
+ return backend.isEventTriggered(e) && e.eventTrigger.retry;
15
15
  });
16
- if (retryFunctions.length === 0) {
16
+ if (retryEndpoints.length === 0) {
17
17
  return;
18
18
  }
19
- const existingRetryFunctions = have.filter((fn) => {
20
- return backend.isEventTrigger(fn.trigger) && fn.trigger.retry;
19
+ const newRetryEndpoints = retryEndpoints.filter((endpoint) => {
20
+ var _a;
21
+ const existing = (_a = have.endpoints[endpoint.region]) === null || _a === void 0 ? void 0 : _a[endpoint.id];
22
+ return !(existing && backend.isEventTriggered(existing) && existing.eventTrigger.retry);
21
23
  });
22
- const newRetryFunctions = retryFunctions.filter((fn) => {
23
- return !existingRetryFunctions.some(backend.sameFunctionName(fn));
24
- });
25
- if (newRetryFunctions.length == 0) {
24
+ if (newRetryEndpoints.length == 0) {
26
25
  return;
27
26
  }
28
27
  const warnMessage = "The following functions will newly be retried in case of failure: " +
29
- clc.bold(newRetryFunctions.sort(backend.compareFunctions).map(functionsDeployHelper_1.getFunctionLabel).join(", ")) +
28
+ clc.bold(newRetryEndpoints.sort(backend.compareFunctions).map(functionsDeployHelper_1.getFunctionLabel).join(", ")) +
30
29
  ". " +
31
30
  "Retried executions are billed as any other execution, and functions are retried repeatedly until they either successfully execute or the maximum retry period has elapsed, which can be up to 7 days. " +
32
31
  "For safety, you might want to ensure that your functions are idempotent; see https://firebase.google.com/docs/functions/retries to learn more.";
@@ -90,21 +89,22 @@ async function promptForMinInstances(options, want, have) {
90
89
  if (options.force) {
91
90
  return;
92
91
  }
93
- const increasesCost = want.some((wantFn) => {
94
- if (!pricing.canCalculateMinInstanceCost(wantFn)) {
92
+ const increasesCost = backend.someEndpoint(want, (wantE) => {
93
+ var _a;
94
+ if (!pricing.canCalculateMinInstanceCost(wantE)) {
95
95
  return true;
96
96
  }
97
- const wantCost = pricing.monthlyMinInstanceCost([wantFn]);
98
- const haveFn = have.find(backend.sameFunctionName(wantFn));
97
+ const wantCost = pricing.monthlyMinInstanceCost([wantE]);
98
+ const haveE = (_a = have.endpoints[wantE.region]) === null || _a === void 0 ? void 0 : _a[wantE.id];
99
99
  let haveCost;
100
- if (!haveFn) {
100
+ if (!haveE) {
101
101
  haveCost = 0;
102
102
  }
103
- else if (!pricing.canCalculateMinInstanceCost(wantFn)) {
103
+ else if (!pricing.canCalculateMinInstanceCost(wantE)) {
104
104
  return true;
105
105
  }
106
106
  else {
107
- haveCost = pricing.monthlyMinInstanceCost([haveFn]);
107
+ haveCost = pricing.monthlyMinInstanceCost([haveE]);
108
108
  }
109
109
  return wantCost > haveCost;
110
110
  });
@@ -116,7 +116,8 @@ async function promptForMinInstances(options, want, have) {
116
116
  exit: 1,
117
117
  });
118
118
  }
119
- const functionLines = want
119
+ const functionLines = backend
120
+ .allEndpoints(want)
120
121
  .filter((fn) => fn.minInstances)
121
122
  .sort(backend.compareFunctions)
122
123
  .map((fn) => {
@@ -126,17 +127,17 @@ async function promptForMinInstances(options, want, have) {
126
127
  })
127
128
  .join("\n");
128
129
  let costLine;
129
- if (want.some((fn) => !pricing.canCalculateMinInstanceCost(fn))) {
130
+ if (backend.someEndpoint(want, (fn) => !pricing.canCalculateMinInstanceCost(fn))) {
130
131
  costLine =
131
132
  "Cannot calculate the minimum monthly bill for this configuration. Consider running " +
132
133
  clc.bold("npm install -g firebase-tools");
133
134
  }
134
135
  else {
135
- const cost = pricing.monthlyMinInstanceCost(want).toFixed(2);
136
+ const cost = pricing.monthlyMinInstanceCost(backend.allEndpoints(want)).toFixed(2);
136
137
  costLine = `With these options, your minimum bill will be $${cost} in a 30-day month`;
137
138
  }
138
139
  let cudAnnotation = "";
139
- if (want.some((fn) => fn.platform == "gcfv2" && fn.minInstances)) {
140
+ if (backend.someEndpoint(want, (fn) => fn.platform == "gcfv2" && !!fn.minInstances)) {
140
141
  cudAnnotation =
141
142
  "\nThis bill can be lowered with a one year commitment. See https://cloud.google.com/run/cud for more";
142
143
  }
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InlineExecutor = exports.QueueExecutor = void 0;
4
+ const queue_1 = require("../../../throttler/queue");
5
+ async function handler(op) {
6
+ var _a, _b, _c, _d, _e, _f;
7
+ try {
8
+ op.result = await op.func();
9
+ }
10
+ catch (err) {
11
+ const code = err.status ||
12
+ err.code || ((_b = (_a = err.context) === null || _a === void 0 ? void 0 : _a.response) === null || _b === void 0 ? void 0 : _b.statusCode) || ((_c = err.original) === null || _c === void 0 ? void 0 : _c.code) || ((_f = (_e = (_d = err.original) === null || _d === void 0 ? void 0 : _d.context) === null || _e === void 0 ? void 0 : _e.response) === null || _f === void 0 ? void 0 : _f.statusCode);
13
+ if (code === 429 || code === 409) {
14
+ throw err;
15
+ }
16
+ op.error = err;
17
+ }
18
+ return;
19
+ }
20
+ class QueueExecutor {
21
+ constructor(options) {
22
+ this.queue = new queue_1.Queue(Object.assign(Object.assign({}, options), { handler }));
23
+ }
24
+ async run(func) {
25
+ const op = { func };
26
+ await this.queue.run(op);
27
+ if (op.error) {
28
+ throw op.error;
29
+ }
30
+ return op.result;
31
+ }
32
+ }
33
+ exports.QueueExecutor = QueueExecutor;
34
+ class InlineExecutor {
35
+ run(func) {
36
+ return func();
37
+ }
38
+ }
39
+ exports.InlineExecutor = InlineExecutor;