firebase-tools 9.20.0 → 9.23.1

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 (98) hide show
  1. package/CHANGELOG.md +5 -1
  2. package/lib/api.js +2 -0
  3. package/lib/apiv2.js +7 -4
  4. package/lib/commands/crashlytics-symbols-upload.js +2 -2
  5. package/lib/commands/deploy.js +9 -1
  6. package/lib/commands/ext-configure.js +1 -1
  7. package/lib/commands/ext-dev-deprecate.js +63 -0
  8. package/lib/commands/ext-dev-undeprecate.js +56 -0
  9. package/lib/commands/ext-dev-unpublish.js +10 -3
  10. package/lib/commands/ext-export.js +44 -0
  11. package/lib/commands/ext-install.js +1 -1
  12. package/lib/commands/ext-update.js +1 -1
  13. package/lib/commands/functions-delete.js +55 -42
  14. package/lib/commands/functions-list.js +11 -11
  15. package/lib/commands/index.js +6 -5
  16. package/lib/commands/init.js +3 -0
  17. package/lib/config.js +3 -2
  18. package/lib/deploy/extensions/args.js +2 -0
  19. package/lib/deploy/extensions/deploy.js +49 -0
  20. package/lib/deploy/extensions/deploymentSummary.js +52 -0
  21. package/lib/deploy/extensions/errors.js +31 -0
  22. package/lib/deploy/extensions/index.js +8 -0
  23. package/lib/deploy/extensions/params.js +39 -0
  24. package/lib/deploy/extensions/planner.js +94 -0
  25. package/lib/deploy/extensions/prepare.js +111 -0
  26. package/lib/deploy/extensions/release.js +43 -0
  27. package/lib/deploy/extensions/secrets.js +150 -0
  28. package/lib/deploy/extensions/tasks.js +98 -0
  29. package/lib/deploy/extensions/validate.js +17 -0
  30. package/lib/deploy/functions/backend.js +84 -115
  31. package/lib/deploy/functions/checkIam.js +73 -12
  32. package/lib/deploy/functions/containerCleaner.js +97 -50
  33. package/lib/deploy/functions/deploy.js +4 -10
  34. package/lib/deploy/functions/eventTypes.js +10 -0
  35. package/lib/deploy/functions/functionsDeployHelper.js +3 -68
  36. package/lib/deploy/functions/prepare.js +72 -29
  37. package/lib/deploy/functions/pricing.js +17 -17
  38. package/lib/deploy/functions/prompts.js +22 -21
  39. package/lib/deploy/functions/release/executor.js +39 -0
  40. package/lib/deploy/functions/release/fabricator.js +425 -0
  41. package/lib/deploy/functions/release/index.js +73 -0
  42. package/lib/deploy/functions/release/planner.js +162 -0
  43. package/lib/deploy/functions/release/reporter.js +165 -0
  44. package/lib/deploy/functions/release/sourceTokenScraper.js +28 -0
  45. package/lib/deploy/functions/release/timer.js +14 -0
  46. package/lib/deploy/functions/runtimes/discovery/v1alpha1.js +129 -126
  47. package/lib/deploy/functions/runtimes/node/parseTriggers.js +32 -54
  48. package/lib/deploy/functions/services/index.js +38 -0
  49. package/lib/deploy/functions/services/storage.js +43 -0
  50. package/lib/deploy/functions/triggerRegionHelper.js +9 -25
  51. package/lib/deploy/functions/validate.js +1 -24
  52. package/lib/deploy/index.js +10 -1
  53. package/lib/emulator/auth/apiSpec.js +37 -6
  54. package/lib/emulator/auth/operations.js +45 -17
  55. package/lib/emulator/auth/server.js +16 -2
  56. package/lib/emulator/auth/state.js +34 -15
  57. package/lib/emulator/auth/widget_ui.js +14 -0
  58. package/lib/emulator/downloadableEmulators.js +7 -7
  59. package/lib/emulator/functionsEmulator.js +18 -4
  60. package/lib/emulator/storage/cloudFunctions.js +37 -7
  61. package/lib/ensureApiEnabled.js +10 -12
  62. package/lib/extensions/askUserForParam.js +14 -6
  63. package/lib/extensions/checkProjectBilling.js +7 -7
  64. package/lib/extensions/export.js +107 -0
  65. package/lib/extensions/extensionsApi.js +103 -21
  66. package/lib/extensions/extensionsHelper.js +5 -2
  67. package/lib/extensions/listExtensions.js +16 -11
  68. package/lib/extensions/paramHelper.js +6 -4
  69. package/lib/extensions/provisioningHelper.js +16 -3
  70. package/lib/extensions/refs.js +9 -1
  71. package/lib/extensions/secretsUtils.js +10 -9
  72. package/lib/extensions/updateHelper.js +12 -2
  73. package/lib/extensions/versionHelper.js +14 -0
  74. package/lib/extensions/warnings.js +33 -1
  75. package/lib/gcp/artifactregistry.js +16 -0
  76. package/lib/gcp/cloudfunctions.js +25 -72
  77. package/lib/gcp/cloudfunctionsv2.js +46 -98
  78. package/lib/gcp/cloudscheduler.js +22 -16
  79. package/lib/gcp/cloudtasks.js +143 -0
  80. package/lib/gcp/docker.js +36 -2
  81. package/lib/gcp/location.js +44 -0
  82. package/lib/gcp/proto.js +2 -2
  83. package/lib/gcp/pubsub.js +1 -9
  84. package/lib/gcp/secretManager.js +27 -6
  85. package/lib/gcp/storage.js +48 -32
  86. package/lib/init/features/project.js +2 -1
  87. package/lib/previews.js +1 -1
  88. package/lib/projectUtils.js +10 -1
  89. package/lib/utils.js +30 -1
  90. package/package.json +5 -4
  91. package/schema/firebase-config.json +9 -0
  92. package/lib/deploy/functions/deploymentPlanner.js +0 -113
  93. package/lib/deploy/functions/deploymentTimer.js +0 -23
  94. package/lib/deploy/functions/errorHandler.js +0 -75
  95. package/lib/deploy/functions/release.js +0 -116
  96. package/lib/deploy/functions/tasks.js +0 -324
  97. package/lib/functions/listFunctions.js +0 -10
  98. package/lib/functionsDelete.js +0 -60
@@ -4,13 +4,13 @@ exports.readEnvFile = exports.getParamsFromFile = exports.promptForNewParams = e
4
4
  const _ = require("lodash");
5
5
  const path = require("path");
6
6
  const clc = require("cli-color");
7
- const dotenv = require("dotenv");
8
7
  const fs = require("fs-extra");
9
8
  const error_1 = require("../error");
10
9
  const logger_1 = require("../logger");
11
10
  const extensionsHelper_1 = require("./extensionsHelper");
12
11
  const askUserForParam = require("./askUserForParam");
13
12
  const track = require("../track");
13
+ const env = require("../functions/env");
14
14
  function setNewDefaults(params, newDefaults) {
15
15
  params.forEach((param) => {
16
16
  if (newDefaults[param.param.toUpperCase()]) {
@@ -42,7 +42,6 @@ async function getParams(args) {
42
42
  params = getParamsFromFile({
43
43
  projectId: args.projectId,
44
44
  paramSpecs: args.paramSpecs,
45
- noninteractive: args.nonInteractive,
46
45
  paramsEnvPath: args.paramsEnvPath,
47
46
  });
48
47
  }
@@ -71,7 +70,6 @@ async function getParamsForUpdate(args) {
71
70
  params = getParamsFromFile({
72
71
  projectId: args.projectId,
73
72
  paramSpecs: args.newSpec.params,
74
- noninteractive: args.nonInteractive,
75
73
  paramsEnvPath: args.paramsEnvPath,
76
74
  });
77
75
  }
@@ -132,6 +130,10 @@ function getParamsFromFile(args) {
132
130
  exports.getParamsFromFile = getParamsFromFile;
133
131
  function readEnvFile(envPath) {
134
132
  const buf = fs.readFileSync(path.resolve(envPath), "utf8");
135
- return dotenv.parse(buf.toString().trim(), { debug: true });
133
+ const result = env.parse(buf.toString().trim());
134
+ if (result.errors.length) {
135
+ throw new error_1.FirebaseError(`Error while parsing ${envPath} - unable to parse following lines:\n${result.errors.join("\n")}`);
136
+ }
137
+ return result.envs;
136
138
  }
137
139
  exports.readEnvFile = readEnvFile;
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getUsedProducts = exports.checkProductsProvisioned = exports.DeferredProduct = void 0;
3
+ exports.getUsedProducts = exports.bulkCheckProductsProvisioned = exports.checkProductsProvisioned = exports.DeferredProduct = void 0;
4
4
  const marked = require("marked");
5
5
  const api = require("../api");
6
+ const functional_1 = require("../functional");
6
7
  const error_1 = require("../error");
8
+ const planner_1 = require("../deploy/extensions/planner");
7
9
  var DeferredProduct;
8
10
  (function (DeferredProduct) {
9
11
  DeferredProduct[DeferredProduct["STORAGE"] = 0] = "STORAGE";
@@ -11,6 +13,18 @@ var DeferredProduct;
11
13
  })(DeferredProduct = exports.DeferredProduct || (exports.DeferredProduct = {}));
12
14
  async function checkProductsProvisioned(projectId, spec) {
13
15
  const usedProducts = getUsedProducts(spec);
16
+ await checkProducts(projectId, usedProducts);
17
+ }
18
+ exports.checkProductsProvisioned = checkProductsProvisioned;
19
+ async function bulkCheckProductsProvisioned(projectId, instanceSpecs) {
20
+ const usedProducts = await Promise.all(instanceSpecs.map(async (i) => {
21
+ const extensionVersion = await planner_1.getExtensionVersion(i);
22
+ return getUsedProducts(extensionVersion.spec);
23
+ }));
24
+ await checkProducts(projectId, [...functional_1.flattenArray(usedProducts)]);
25
+ }
26
+ exports.bulkCheckProductsProvisioned = bulkCheckProductsProvisioned;
27
+ async function checkProducts(projectId, usedProducts) {
14
28
  const needProvisioning = [];
15
29
  let isStorageProvisionedPromise;
16
30
  let isAuthProvisionedPromise;
@@ -29,7 +43,7 @@ async function checkProductsProvisioned(projectId, spec) {
29
43
  if (needProvisioning.length > 0) {
30
44
  let errorMessage = "Some services used by this extension have not been set up on your " +
31
45
  "Firebase project. To ensure this extension works as intended, you must enable these " +
32
- "services by following the provided links, then retry installing the extension\n\n";
46
+ "services by following the provided links, then retry this command\n\n";
33
47
  if (needProvisioning.includes(DeferredProduct.STORAGE)) {
34
48
  errorMessage +=
35
49
  " - Firebase Storage: store and retrieve user-generated files like images, audio, and " +
@@ -46,7 +60,6 @@ async function checkProductsProvisioned(projectId, spec) {
46
60
  throw new error_1.FirebaseError(marked(errorMessage), { exit: 2 });
47
61
  }
48
62
  }
49
- exports.checkProductsProvisioned = checkProductsProvisioned;
50
63
  function getUsedProducts(spec) {
51
64
  var _a, _b;
52
65
  const usedProducts = [];
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toExtensionVersionName = exports.toExtensionName = exports.toExtensionVersionRef = exports.toExtensionRef = exports.parse = void 0;
3
+ exports.equal = exports.toExtensionVersionName = exports.toExtensionName = exports.toExtensionVersionRef = exports.toExtensionRef = exports.parse = void 0;
4
4
  const semver = require("semver");
5
5
  const error_1 = require("../error");
6
6
  const refRegex = new RegExp(/^([^/@\n]+)\/{1}([^/@\n]+)(@{1}([^\n]+)|)$/);
@@ -57,3 +57,11 @@ function toExtensionVersionName(ref) {
57
57
  return `publishers/${ref.publisherId}/extensions/${ref.extensionId}/versions/${ref.version}`;
58
58
  }
59
59
  exports.toExtensionVersionName = toExtensionVersionName;
60
+ function equal(a, b) {
61
+ return (!!a &&
62
+ !!b &&
63
+ a.publisherId === b.publisherId &&
64
+ a.extensionId === b.extensionId &&
65
+ a.version === b.version);
66
+ }
67
+ exports.equal = equal;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.prettySecretName = exports.getSecretLabels = exports.getManagedSecrets = exports.grantFirexServiceAgentSecretAdminRole = exports.usesSecrets = exports.ensureSecretManagerApiEnabled = void 0;
3
+ exports.prettySecretName = exports.getSecretLabels = exports.getActiveSecrets = exports.getManagedSecrets = exports.grantFirexServiceAgentSecretAdminRole = exports.usesSecrets = exports.ensureSecretManagerApiEnabled = exports.SECRET_LABEL = void 0;
4
4
  const getProjectNumber_1 = require("../getProjectNumber");
5
5
  const utils = require("../utils");
6
6
  const ensureApiEnabled_1 = require("../ensureApiEnabled");
@@ -8,7 +8,7 @@ const projectUtils_1 = require("../projectUtils");
8
8
  const extensionsApi = require("./extensionsApi");
9
9
  const secretManagerApi = require("../gcp/secretManager");
10
10
  const logger_1 = require("../logger");
11
- const SECRET_LABEL = "firebase-extensions-managed";
11
+ exports.SECRET_LABEL = "firebase-extensions-managed";
12
12
  async function ensureSecretManagerApiEnabled(options) {
13
13
  const projectId = projectUtils_1.needProjectId(options);
14
14
  return await ensureApiEnabled_1.ensure(projectId, "secretmanager.googleapis.com", "extensions", options.markdown);
@@ -26,24 +26,25 @@ async function grantFirexServiceAgentSecretAdminRole(secret) {
26
26
  }
27
27
  exports.grantFirexServiceAgentSecretAdminRole = grantFirexServiceAgentSecretAdminRole;
28
28
  async function getManagedSecrets(instance) {
29
- return (await Promise.all(getActiveSecrets(instance).map(async (secretResourceName) => {
29
+ return (await Promise.all(getActiveSecrets(instance.config.source.spec, instance.config.params).map(async (secretResourceName) => {
30
30
  const secret = secretManagerApi.parseSecretResourceName(secretResourceName);
31
- const labels = await secretManagerApi.getSecretLabels(secret.projectId, secret.name);
32
- if (labels && labels[SECRET_LABEL]) {
31
+ const labels = (await secretManagerApi.getSecret(secret.projectId, secret.name)).labels;
32
+ if (labels && labels[exports.SECRET_LABEL]) {
33
33
  return secretResourceName;
34
34
  }
35
35
  return Promise.resolve("");
36
36
  }))).filter((secretId) => !!secretId);
37
37
  }
38
38
  exports.getManagedSecrets = getManagedSecrets;
39
- function getActiveSecrets(instance) {
40
- return instance.config.source.spec.params
41
- .map((p) => p.type == extensionsApi.ParamType.SECRET && instance.config.params[p.param])
39
+ function getActiveSecrets(spec, params) {
40
+ return spec.params
41
+ .map((p) => (p.type == extensionsApi.ParamType.SECRET ? params[p.param] : ""))
42
42
  .filter((pv) => !!pv);
43
43
  }
44
+ exports.getActiveSecrets = getActiveSecrets;
44
45
  function getSecretLabels(instanceId) {
45
46
  const labels = {};
46
- labels[SECRET_LABEL] = instanceId;
47
+ labels[exports.SECRET_LABEL] = instanceId;
47
48
  return labels;
48
49
  }
49
50
  exports.getSecretLabels = getSecretLabels;
@@ -62,10 +62,20 @@ exports.displayChanges = displayChanges;
62
62
  async function update(updateOptions) {
63
63
  const { projectId, instanceId, source, extRef, params } = updateOptions;
64
64
  if (extRef) {
65
- return await extensionsApi.updateInstanceFromRegistry(projectId, instanceId, extRef, params);
65
+ return await extensionsApi.updateInstanceFromRegistry({
66
+ projectId,
67
+ instanceId,
68
+ extRef,
69
+ params,
70
+ });
66
71
  }
67
72
  else if (source) {
68
- return await extensionsApi.updateInstance(projectId, instanceId, source, params);
73
+ return await extensionsApi.updateInstance({
74
+ projectId,
75
+ instanceId,
76
+ extensionSource: source,
77
+ params,
78
+ });
69
79
  }
70
80
  throw new error_1.FirebaseError(`Neither a source nor a version of the extension was supplied for ${instanceId}. Please make sure this is a valid extension and try again.`);
71
81
  }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseVersionPredicate = void 0;
4
+ const error_1 = require("../error");
5
+ function parseVersionPredicate(versionPredicate) {
6
+ const versionPredicateRegex = "^(?<comparator>>=|<=|>|<)?(?<targetSemVer>.*)";
7
+ const matches = versionPredicate.match(versionPredicateRegex);
8
+ if (!matches || !matches.groups.targetSemVer) {
9
+ throw new error_1.FirebaseError("Invalid version predicate.");
10
+ }
11
+ const comparator = matches.groups.comparator || "=";
12
+ return { comparator, targetSemVer: matches.groups.targetSemVer };
13
+ }
14
+ exports.parseVersionPredicate = parseVersionPredicate;
@@ -1,12 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.displayWarningPrompts = void 0;
3
+ exports.displayWarningsForDeploy = exports.displayWarningPrompts = void 0;
4
4
  const marked = require("marked");
5
5
  const clc = require("cli-color");
6
6
  const extensionsApi_1 = require("./extensionsApi");
7
7
  const displayExtensionInfo_1 = require("./displayExtensionInfo");
8
8
  const extensionsHelper_1 = require("./extensionsHelper");
9
9
  const resolveSource_1 = require("./resolveSource");
10
+ const deploymentSummary_1 = require("../deploy/extensions/deploymentSummary");
11
+ const planner_1 = require("../deploy/extensions/planner");
12
+ const functional_1 = require("../functional");
10
13
  const utils = require("../utils");
11
14
  function displayEAPWarning({ publisherId, sourceDownloadUri, githubLink, }) {
12
15
  const publisherNameLink = githubLink ? `[${publisherId}](${githubLink})` : publisherId;
@@ -35,3 +38,32 @@ async function displayWarningPrompts(publisherId, launchStage, extensionVersion)
35
38
  }
36
39
  }
37
40
  exports.displayWarningPrompts = displayWarningPrompts;
41
+ const toListEntry = (i) => {
42
+ var _a, _b, _c, _d;
43
+ const idAndRef = deploymentSummary_1.humanReadable(i);
44
+ const sourceCodeLink = `\n\t[Source Code](${(_a = i.extensionVersion) === null || _a === void 0 ? void 0 : _a.sourceDownloadUri})`;
45
+ const githubLink = ((_c = (_b = i.extensionVersion) === null || _b === void 0 ? void 0 : _b.spec) === null || _c === void 0 ? void 0 : _c.sourceUrl) ? `\n\t[Publisher Contact](${(_d = i.extensionVersion) === null || _d === void 0 ? void 0 : _d.spec.sourceUrl})`
46
+ : "";
47
+ return `${idAndRef}${sourceCodeLink}${githubLink}`;
48
+ };
49
+ async function displayWarningsForDeploy(instancesToCreate) {
50
+ const trustedPublishers = await resolveSource_1.getTrustedPublishers();
51
+ for (const i of instancesToCreate) {
52
+ await planner_1.getExtension(i);
53
+ await planner_1.getExtensionVersion(i);
54
+ }
55
+ const [eapExtensions, nonEapExtensions] = functional_1.partition(instancesToCreate, (i) => { var _a, _b; return !trustedPublishers.includes((_b = (_a = i.ref) === null || _a === void 0 ? void 0 : _a.publisherId) !== null && _b !== void 0 ? _b : ""); });
56
+ const experimental = nonEapExtensions.filter((i) => i.extension.registryLaunchStage === extensionsApi_1.RegistryLaunchStage.EXPERIMENTAL);
57
+ if (experimental.length) {
58
+ const humanReadableList = experimental.map((i) => `\t${deploymentSummary_1.humanReadable(i)}`).join("\n");
59
+ utils.logLabeledBullet(extensionsHelper_1.logPrefix, marked(`The following are instances of ${clc.bold("experimental")} extensions.They may not be production-ready. Their functionality may change in backward-incompatible ways before their official release, or they may be discontinued.\n${humanReadableList}\n`));
60
+ }
61
+ if (eapExtensions.length) {
62
+ const humanReadableList = eapExtensions.map(toListEntry).join("\n");
63
+ utils.logLabeledBullet(extensionsHelper_1.logPrefix, marked(`These extensions are in preview and are built by a developer in the Extensions Publisher Early Access Program (http://bit.ly/firex-provider. Their functionality might change in backwards-incompatible ways. Since these extensions aren't built by Firebase, reach out to their publisher with questions about them.` +
64
+ ` They are provided “AS IS”, without any warranty, express or implied, from Google.` +
65
+ ` Google disclaims all liability for any damages, direct or indirect, resulting from the use of these extensions\n${humanReadableList}`));
66
+ }
67
+ return experimental.length > 0 || eapExtensions.length > 0;
68
+ }
69
+ exports.displayWarningsForDeploy = displayWarningsForDeploy;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deletePackage = exports.API_VERSION = void 0;
4
+ const apiv2_1 = require("../apiv2");
5
+ const api_1 = require("../api");
6
+ exports.API_VERSION = "v1beta2";
7
+ const client = new apiv2_1.Client({
8
+ urlPrefix: api_1.artifactRegistryDomain,
9
+ auth: true,
10
+ apiVersion: exports.API_VERSION,
11
+ });
12
+ async function deletePackage(name) {
13
+ const res = await client.delete(name);
14
+ return res.body;
15
+ }
16
+ exports.deletePackage = deletePackage;
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.functionFromEndpoint = exports.endpointFromFunction = exports.functionFromSpec = exports.specFromFunction = exports.listAllFunctions = exports.listFunctions = exports.deleteFunction = exports.updateFunction = exports.setInvokerUpdate = exports.setInvokerCreate = exports.getIamPolicy = exports.setIamPolicy = exports.createFunction = exports.generateUploadUrl = exports.API_VERSION = void 0;
3
+ exports.functionFromEndpoint = exports.endpointFromFunction = exports.listAllFunctions = exports.listFunctions = exports.deleteFunction = exports.updateFunction = exports.setInvokerUpdate = exports.setInvokerCreate = exports.getIamPolicy = exports.setIamPolicy = exports.createFunction = exports.generateUploadUrl = exports.API_VERSION = void 0;
4
4
  const clc = require("cli-color");
5
5
  const error_1 = require("../error");
6
6
  const logger_1 = require("../logger");
7
+ const previews_1 = require("../previews");
7
8
  const api = require("../api");
8
9
  const backend = require("../deploy/functions/backend");
9
10
  const utils = require("../utils");
@@ -50,7 +51,12 @@ async function createFunction(cloudFunction) {
50
51
  const apiPath = cloudFunction.name.substring(0, cloudFunction.name.lastIndexOf("/"));
51
52
  const endpoint = `/${exports.API_VERSION}/${apiPath}`;
52
53
  try {
54
+ const headers = {};
55
+ if (previews_1.previews.artifactregistry) {
56
+ headers["X-Firebase-Artifact-Registry"] = "optin";
57
+ }
53
58
  const res = await api.request("POST", endpoint, {
59
+ headers,
54
60
  auth: true,
55
61
  data: cloudFunction,
56
62
  origin: api.functionsOrigin,
@@ -145,7 +151,12 @@ async function updateFunction(cloudFunction) {
145
151
  const endpoint = `/${exports.API_VERSION}/${cloudFunction.name}`;
146
152
  const fieldMasks = proto.fieldMasks(cloudFunction, "labels", "environmentVariables");
147
153
  try {
154
+ const headers = {};
155
+ if (previews_1.previews.artifactregistry) {
156
+ headers["X-Firebase-Artifact-Registry"] = "optin";
157
+ }
148
158
  const res = await api.request("PATCH", endpoint, {
159
+ headers,
149
160
  qs: {
150
161
  updateMask: fieldMasks.join(","),
151
162
  },
@@ -214,87 +225,25 @@ async function listAllFunctions(projectId) {
214
225
  return list(projectId, "-");
215
226
  }
216
227
  exports.listAllFunctions = listAllFunctions;
217
- function specFromFunction(gcfFunction) {
218
- var _a;
228
+ function endpointFromFunction(gcfFunction) {
229
+ var _a, _b, _c;
219
230
  const [, project, , region, , id] = gcfFunction.name.split("/");
220
231
  let trigger;
221
232
  let uri;
222
- if (gcfFunction.httpsTrigger) {
223
- trigger = {};
224
- uri = gcfFunction.httpsTrigger.url;
225
- }
226
- else {
233
+ if ((_a = gcfFunction.labels) === null || _a === void 0 ? void 0 : _a["deployment-scheduled"]) {
227
234
  trigger = {
228
- eventType: gcfFunction.eventTrigger.eventType,
229
- eventFilters: {
230
- resource: gcfFunction.eventTrigger.resource,
231
- },
232
- retry: !!((_a = gcfFunction.eventTrigger.failurePolicy) === null || _a === void 0 ? void 0 : _a.retry),
235
+ scheduleTrigger: {},
233
236
  };
234
237
  }
235
- if (!runtimes.isValidRuntime(gcfFunction.runtime)) {
236
- logger_1.logger.debug("GCFv1 function has a deprecated runtime:", JSON.stringify(gcfFunction, null, 2));
237
- }
238
- const cloudFunction = {
239
- platform: "gcfv1",
240
- id,
241
- project,
242
- region,
243
- trigger,
244
- entryPoint: gcfFunction.entryPoint,
245
- runtime: gcfFunction.runtime,
246
- };
247
- if (uri) {
248
- cloudFunction.uri = uri;
249
- }
250
- proto.copyIfPresent(cloudFunction, gcfFunction, "serviceAccountEmail", "availableMemoryMb", "timeout", "minInstances", "maxInstances", "vpcConnector", "vpcConnectorEgressSettings", "ingressSettings", "labels", "environmentVariables", "sourceUploadUrl");
251
- return cloudFunction;
252
- }
253
- exports.specFromFunction = specFromFunction;
254
- function functionFromSpec(cloudFunction, sourceUploadUrl) {
255
- if (cloudFunction.platform != "gcfv1") {
256
- throw new error_1.FirebaseError("Trying to create a v1 CloudFunction with v2 API. This should never happen");
257
- }
258
- if (!runtimes.isValidRuntime(cloudFunction.runtime)) {
259
- throw new error_1.FirebaseError("Failed internal assertion. Trying to deploy a new function with a deprecated runtime." +
260
- " This should never happen");
261
- }
262
- const gcfFunction = {
263
- name: backend.functionName(cloudFunction),
264
- sourceUploadUrl: sourceUploadUrl,
265
- entryPoint: cloudFunction.entryPoint,
266
- runtime: cloudFunction.runtime,
267
- };
268
- if (backend.isEventTrigger(cloudFunction.trigger)) {
269
- gcfFunction.eventTrigger = {
270
- eventType: cloudFunction.trigger.eventType,
271
- resource: cloudFunction.trigger.eventFilters.resource,
238
+ else if ((_b = gcfFunction.labels) === null || _b === void 0 ? void 0 : _b["deployment-taskqueue"]) {
239
+ trigger = {
240
+ taskQueueTrigger: {},
272
241
  };
273
- gcfFunction.eventTrigger.failurePolicy = cloudFunction.trigger.retry
274
- ? { retry: {} }
275
- : undefined;
276
242
  }
277
- else {
278
- gcfFunction.httpsTrigger = {};
279
- }
280
- proto.copyIfPresent(gcfFunction, cloudFunction, "serviceAccountEmail", "timeout", "availableMemoryMb", "minInstances", "maxInstances", "vpcConnector", "vpcConnectorEgressSettings", "ingressSettings", "labels", "environmentVariables");
281
- return gcfFunction;
282
- }
283
- exports.functionFromSpec = functionFromSpec;
284
- function endpointFromFunction(gcfFunction) {
285
- var _a, _b;
286
- const [, project, , region, , id] = gcfFunction.name.split("/");
287
- let trigger;
288
- let uri;
289
- if (gcfFunction.httpsTrigger) {
243
+ else if (gcfFunction.httpsTrigger) {
290
244
  trigger = { httpsTrigger: {} };
291
245
  uri = gcfFunction.httpsTrigger.url;
292
246
  }
293
- else if ((_a = gcfFunction.labels) === null || _a === void 0 ? void 0 : _a["deployment-scheduled"]) {
294
- trigger = {
295
- scheduleTrigger: {},
296
- };
297
- }
298
247
  else {
299
248
  trigger = {
300
249
  eventTrigger: {
@@ -302,7 +251,7 @@ function endpointFromFunction(gcfFunction) {
302
251
  eventFilters: {
303
252
  resource: gcfFunction.eventTrigger.resource,
304
253
  },
305
- retry: !!((_b = gcfFunction.eventTrigger.failurePolicy) === null || _b === void 0 ? void 0 : _b.retry),
254
+ retry: !!((_c = gcfFunction.eventTrigger.failurePolicy) === null || _c === void 0 ? void 0 : _c.retry),
306
255
  },
307
256
  };
308
257
  }
@@ -351,6 +300,10 @@ function functionFromEndpoint(endpoint, sourceUploadUrl) {
351
300
  };
352
301
  gcfFunction.labels = Object.assign(Object.assign({}, gcfFunction.labels), { "deployment-scheduled": "true" });
353
302
  }
303
+ else if (backend.isTaskQueueTriggered(endpoint)) {
304
+ gcfFunction.httpsTrigger = {};
305
+ gcfFunction.labels = Object.assign(Object.assign({}, gcfFunction.labels), { "deployment-taskqueue": "true" });
306
+ }
354
307
  else {
355
308
  gcfFunction.httpsTrigger = {};
356
309
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.endpointFromFunction = exports.functionFromEndpoint = exports.specFromFunction = exports.functionFromSpec = exports.deleteFunction = exports.updateFunction = exports.listAllFunctions = exports.listFunctions = exports.getFunction = exports.createFunction = exports.generateUploadUrl = exports.PUBSUB_PUBLISH_EVENT = exports.API_VERSION = void 0;
3
+ exports.endpointFromFunction = exports.functionFromEndpoint = exports.deleteFunction = exports.updateFunction = exports.listAllFunctions = exports.listFunctions = exports.getFunction = exports.createFunction = exports.generateUploadUrl = exports.megabytes = exports.PUBSUB_PUBLISH_EVENT = exports.API_VERSION = void 0;
4
4
  const clc = require("cli-color");
5
5
  const apiv2_1 = require("../apiv2");
6
6
  const error_1 = require("../error");
@@ -17,6 +17,35 @@ const client = new apiv2_1.Client({
17
17
  apiVersion: exports.API_VERSION,
18
18
  });
19
19
  exports.PUBSUB_PUBLISH_EVENT = "google.cloud.pubsub.topic.v1.messagePublished";
20
+ const BYTES_PER_UNIT = {
21
+ "": 1,
22
+ k: 1e3,
23
+ M: 1e6,
24
+ G: 1e9,
25
+ T: 1e12,
26
+ Ki: 1 << 10,
27
+ Mi: 1 << 20,
28
+ Gi: 1 << 30,
29
+ Ti: 1 << 40,
30
+ };
31
+ function megabytes(memory) {
32
+ const re = /^([0-9]+(\.[0-9]*)?)(Ki|Mi|Gi|Ti|k|M|G|T|([eE]([0-9]+)))?$/;
33
+ const matches = re.exec(memory);
34
+ if (!matches) {
35
+ throw new Error(`Invalid memory quantity "${memory}""`);
36
+ }
37
+ const quantity = Number.parseFloat(matches[1]);
38
+ let bytes;
39
+ if (matches[5]) {
40
+ bytes = quantity * Math.pow(10, Number.parseFloat(matches[5]));
41
+ }
42
+ else {
43
+ const suffix = matches[3] || "";
44
+ bytes = quantity * BYTES_PER_UNIT[suffix];
45
+ }
46
+ return bytes / 1e6;
47
+ }
48
+ exports.megabytes = megabytes;
20
49
  function functionsOpLogReject(funcName, type, err) {
21
50
  var _a, _b;
22
51
  if (((_b = (_a = err === null || err === void 0 ? void 0 : err.context) === null || _a === void 0 ? void 0 : _a.response) === null || _b === void 0 ? void 0 : _b.statusCode) === 429) {
@@ -115,99 +144,6 @@ async function deleteFunction(cloudFunction) {
115
144
  }
116
145
  }
117
146
  exports.deleteFunction = deleteFunction;
118
- function functionFromSpec(cloudFunction, source) {
119
- if (cloudFunction.platform != "gcfv2") {
120
- throw new error_1.FirebaseError("Trying to create a v2 CloudFunction with v1 API. This should never happen");
121
- }
122
- if (!runtimes.isValidRuntime(cloudFunction.runtime)) {
123
- throw new error_1.FirebaseError("Failed internal assertion. Trying to deploy a new function with a deprecated runtime." +
124
- " This should never happen");
125
- }
126
- const gcfFunction = {
127
- name: backend.functionName(cloudFunction),
128
- buildConfig: {
129
- runtime: cloudFunction.runtime,
130
- entryPoint: cloudFunction.entryPoint,
131
- source: {
132
- storageSource: source,
133
- },
134
- environmentVariables: {},
135
- },
136
- serviceConfig: {},
137
- };
138
- proto.copyIfPresent(gcfFunction.serviceConfig, cloudFunction, "availableMemoryMb", "environmentVariables", "vpcConnector", "vpcConnectorEgressSettings", "serviceAccountEmail", "ingressSettings");
139
- proto.renameIfPresent(gcfFunction.serviceConfig, cloudFunction, "timeoutSeconds", "timeout", proto.secondsFromDuration);
140
- proto.renameIfPresent(gcfFunction.serviceConfig, cloudFunction, "minInstanceCount", "minInstances");
141
- proto.renameIfPresent(gcfFunction.serviceConfig, cloudFunction, "maxInstanceCount", "maxInstances");
142
- if (backend.isEventTrigger(cloudFunction.trigger)) {
143
- gcfFunction.eventTrigger = {
144
- eventType: cloudFunction.trigger.eventType,
145
- };
146
- if (cloudFunction.trigger.region) {
147
- gcfFunction.eventTrigger.triggerRegion = cloudFunction.trigger.region;
148
- }
149
- if (gcfFunction.eventTrigger.eventType === exports.PUBSUB_PUBLISH_EVENT) {
150
- gcfFunction.eventTrigger.pubsubTopic = cloudFunction.trigger.eventFilters.resource;
151
- }
152
- else {
153
- gcfFunction.eventTrigger.eventFilters = [];
154
- for (const [attribute, value] of Object.entries(cloudFunction.trigger.eventFilters)) {
155
- gcfFunction.eventTrigger.eventFilters.push({ attribute, value });
156
- }
157
- }
158
- if (cloudFunction.trigger.retry) {
159
- logger_1.logger.warn("Cannot set a retry policy on Cloud Function", cloudFunction.id);
160
- }
161
- }
162
- proto.copyIfPresent(gcfFunction, cloudFunction, "labels");
163
- return gcfFunction;
164
- }
165
- exports.functionFromSpec = functionFromSpec;
166
- function specFromFunction(gcfFunction) {
167
- const [, project, , region, , id] = gcfFunction.name.split("/");
168
- let trigger;
169
- if (gcfFunction.eventTrigger) {
170
- trigger = {
171
- eventType: gcfFunction.eventTrigger.eventType,
172
- eventFilters: {},
173
- retry: false,
174
- };
175
- if (gcfFunction.eventTrigger.triggerRegion) {
176
- trigger.region = gcfFunction.eventTrigger.triggerRegion;
177
- }
178
- if (gcfFunction.eventTrigger.pubsubTopic) {
179
- trigger.eventFilters.resource = gcfFunction.eventTrigger.pubsubTopic;
180
- }
181
- else {
182
- for (const { attribute, value } of gcfFunction.eventTrigger.eventFilters || []) {
183
- trigger.eventFilters[attribute] = value;
184
- }
185
- }
186
- }
187
- else {
188
- trigger = {};
189
- }
190
- if (!runtimes.isValidRuntime(gcfFunction.buildConfig.runtime)) {
191
- logger_1.logger.debug("GCFv2 function has a deprecated runtime:", JSON.stringify(gcfFunction, null, 2));
192
- }
193
- const cloudFunction = {
194
- platform: "gcfv2",
195
- id,
196
- project,
197
- region,
198
- trigger,
199
- entryPoint: gcfFunction.buildConfig.entryPoint,
200
- runtime: gcfFunction.buildConfig.runtime,
201
- uri: gcfFunction.serviceConfig.uri,
202
- };
203
- proto.copyIfPresent(cloudFunction, gcfFunction.serviceConfig, "serviceAccountEmail", "availableMemoryMb", "vpcConnector", "vpcConnectorEgressSettings", "ingressSettings", "environmentVariables");
204
- proto.renameIfPresent(cloudFunction, gcfFunction.serviceConfig, "timeout", "timeoutSeconds", proto.durationFromSeconds);
205
- proto.renameIfPresent(cloudFunction, gcfFunction.serviceConfig, "minInstances", "minInstanceCount");
206
- proto.renameIfPresent(cloudFunction, gcfFunction.serviceConfig, "maxInstances", "maxInstanceCount");
207
- proto.copyIfPresent(cloudFunction, gcfFunction, "labels");
208
- return cloudFunction;
209
- }
210
- exports.specFromFunction = specFromFunction;
211
147
  function functionFromEndpoint(endpoint, source) {
212
148
  if (endpoint.platform != "gcfv2") {
213
149
  throw new error_1.FirebaseError("Trying to create a v2 CloudFunction with v1 API. This should never happen");
@@ -229,7 +165,8 @@ function functionFromEndpoint(endpoint, source) {
229
165
  serviceConfig: {},
230
166
  };
231
167
  proto.copyIfPresent(gcfFunction, endpoint, "labels");
232
- proto.copyIfPresent(gcfFunction.serviceConfig, endpoint, "availableMemoryMb", "environmentVariables", "vpcConnector", "vpcConnectorEgressSettings", "serviceAccountEmail", "ingressSettings");
168
+ proto.copyIfPresent(gcfFunction.serviceConfig, endpoint, "environmentVariables", "vpcConnector", "vpcConnectorEgressSettings", "serviceAccountEmail", "ingressSettings");
169
+ proto.renameIfPresent(gcfFunction.serviceConfig, endpoint, "availableMemory", "availableMemoryMb", (mb) => `${mb}M`);
233
170
  proto.renameIfPresent(gcfFunction.serviceConfig, endpoint, "timeoutSeconds", "timeout", proto.secondsFromDuration);
234
171
  proto.renameIfPresent(gcfFunction.serviceConfig, endpoint, "minInstanceCount", "minInstances");
235
172
  proto.renameIfPresent(gcfFunction.serviceConfig, endpoint, "maxInstanceCount", "maxInstances");
@@ -246,18 +183,22 @@ function functionFromEndpoint(endpoint, source) {
246
183
  gcfFunction.eventTrigger.eventFilters.push({ attribute, value });
247
184
  }
248
185
  }
186
+ proto.renameIfPresent(gcfFunction.eventTrigger, endpoint.eventTrigger, "triggerRegion", "region");
249
187
  if (endpoint.eventTrigger.retry) {
250
188
  logger_1.logger.warn("Cannot set a retry policy on Cloud Function", endpoint.id);
251
189
  }
252
190
  }
253
191
  else if (backend.isScheduleTriggered(endpoint)) {
254
- gcfFunction.labels = Object.assign(Object.assign({}, gcfFunction.labels), { ["deployment-scheduled"]: "true" });
192
+ gcfFunction.labels = Object.assign(Object.assign({}, gcfFunction.labels), { "deployment-scheduled": "true" });
193
+ }
194
+ else if (backend.isTaskQueueTriggered(endpoint)) {
195
+ gcfFunction.labels = Object.assign(Object.assign({}, gcfFunction.labels), { "deployment-taskqueue": "true" });
255
196
  }
256
197
  return gcfFunction;
257
198
  }
258
199
  exports.functionFromEndpoint = functionFromEndpoint;
259
200
  function endpointFromFunction(gcfFunction) {
260
- var _a;
201
+ var _a, _b;
261
202
  const [, project, , region, , id] = gcfFunction.name.split("/");
262
203
  let trigger;
263
204
  if (((_a = gcfFunction.labels) === null || _a === void 0 ? void 0 : _a["deployment-scheduled"]) === "true") {
@@ -265,6 +206,11 @@ function endpointFromFunction(gcfFunction) {
265
206
  scheduleTrigger: {},
266
207
  };
267
208
  }
209
+ else if (((_b = gcfFunction.labels) === null || _b === void 0 ? void 0 : _b["deployment-taskqueue"]) === "true") {
210
+ trigger = {
211
+ taskQueueTrigger: {},
212
+ };
213
+ }
268
214
  else if (gcfFunction.eventTrigger) {
269
215
  trigger = {
270
216
  eventTrigger: {
@@ -281,6 +227,7 @@ function endpointFromFunction(gcfFunction) {
281
227
  trigger.eventTrigger.eventFilters[attribute] = value;
282
228
  }
283
229
  }
230
+ proto.renameIfPresent(trigger.eventTrigger, gcfFunction.eventTrigger, "region", "triggerRegion");
284
231
  }
285
232
  else {
286
233
  trigger = { httpsTrigger: {} };
@@ -291,7 +238,8 @@ function endpointFromFunction(gcfFunction) {
291
238
  const endpoint = Object.assign(Object.assign({ platform: "gcfv2", id,
292
239
  project,
293
240
  region }, trigger), { entryPoint: gcfFunction.buildConfig.entryPoint, runtime: gcfFunction.buildConfig.runtime, uri: gcfFunction.serviceConfig.uri });
294
- proto.copyIfPresent(endpoint, gcfFunction.serviceConfig, "serviceAccountEmail", "availableMemoryMb", "vpcConnector", "vpcConnectorEgressSettings", "ingressSettings", "environmentVariables");
241
+ proto.copyIfPresent(endpoint, gcfFunction.serviceConfig, "serviceAccountEmail", "vpcConnector", "vpcConnectorEgressSettings", "ingressSettings", "environmentVariables");
242
+ proto.renameIfPresent(endpoint, gcfFunction.serviceConfig, "availableMemoryMb", "availableMemory", megabytes);
295
243
  proto.renameIfPresent(endpoint, gcfFunction.serviceConfig, "timeout", "timeoutSeconds", proto.durationFromSeconds);
296
244
  proto.renameIfPresent(endpoint, gcfFunction.serviceConfig, "minInstances", "minInstanceCount");
297
245
  proto.renameIfPresent(endpoint, gcfFunction.serviceConfig, "maxInstances", "maxInstanceCount");