firebase-tools 10.1.5 → 10.2.2

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 (134) hide show
  1. package/lib/api.js +1 -0
  2. package/lib/apiv2.js +3 -0
  3. package/lib/appdistribution/options-parser-util.js +1 -1
  4. package/lib/auth.js +62 -25
  5. package/lib/command.js +1 -1
  6. package/lib/commands/apps-android-sha-create.js +2 -2
  7. package/lib/commands/apps-sdkconfig.js +1 -1
  8. package/lib/commands/auth-import.js +1 -1
  9. package/lib/commands/database-rules-list.js +2 -2
  10. package/lib/commands/emulators-start.js +1 -1
  11. package/lib/commands/ext-configure.js +1 -0
  12. package/lib/commands/ext-dev-init.js +49 -49
  13. package/lib/commands/ext-export.js +12 -2
  14. package/lib/commands/ext-install.js +104 -103
  15. package/lib/commands/ext-uninstall.js +9 -8
  16. package/lib/commands/ext-update.js +10 -9
  17. package/lib/commands/functions-config-clone.js +1 -1
  18. package/lib/commands/functions-config-export.js +1 -1
  19. package/lib/commands/functions-secrets-access.js +17 -0
  20. package/lib/commands/functions-secrets-destroy.js +40 -0
  21. package/lib/commands/functions-secrets-get.js +21 -0
  22. package/lib/commands/functions-secrets-prune.js +50 -0
  23. package/lib/commands/functions-secrets-set.js +46 -0
  24. package/lib/commands/hosting-clone.js +3 -3
  25. package/lib/commands/index.js +7 -3
  26. package/lib/commands/login.js +1 -1
  27. package/lib/commands/remoteconfig-get.js +1 -1
  28. package/lib/deploy/extensions/deploymentSummary.js +3 -3
  29. package/lib/deploy/extensions/params.js +3 -0
  30. package/lib/deploy/extensions/planner.js +2 -1
  31. package/lib/deploy/extensions/tasks.js +1 -1
  32. package/lib/deploy/functions/backend.js +20 -5
  33. package/lib/deploy/functions/checkIam.js +1 -1
  34. package/lib/deploy/functions/containerCleaner.js +3 -3
  35. package/lib/deploy/functions/ensure.js +112 -0
  36. package/lib/deploy/functions/ensureCloudBuildEnabled.js +0 -49
  37. package/lib/deploy/functions/functionsDeployHelper.js +2 -2
  38. package/lib/deploy/functions/prepare.js +15 -20
  39. package/lib/deploy/functions/pricing.js +1 -1
  40. package/lib/deploy/functions/prompts.js +2 -2
  41. package/lib/deploy/functions/release/fabricator.js +3 -3
  42. package/lib/deploy/functions/release/index.js +1 -1
  43. package/lib/deploy/functions/release/planner.js +11 -8
  44. package/lib/deploy/functions/release/reporter.js +3 -0
  45. package/lib/deploy/functions/runtimes/discovery/index.js +6 -6
  46. package/lib/deploy/functions/runtimes/discovery/parsing.js +1 -1
  47. package/lib/deploy/functions/runtimes/discovery/v1alpha1.js +17 -11
  48. package/lib/deploy/functions/runtimes/golang/index.js +2 -2
  49. package/lib/deploy/functions/runtimes/node/index.js +26 -0
  50. package/lib/deploy/functions/runtimes/node/parseRuntimeAndValidateSDK.js +2 -2
  51. package/lib/deploy/functions/runtimes/node/parseTriggers.js +40 -7
  52. package/lib/deploy/functions/runtimes/node/versioning.js +2 -2
  53. package/lib/deploy/functions/validate.js +58 -3
  54. package/lib/deploy/hosting/client.js +9 -0
  55. package/lib/deploy/hosting/convertConfig.js +6 -0
  56. package/lib/deploy/hosting/deploy.js +2 -2
  57. package/lib/deploy/hosting/hashcache.js +21 -19
  58. package/lib/deploy/hosting/index.js +5 -5
  59. package/lib/deploy/hosting/prepare.js +25 -25
  60. package/lib/deploy/hosting/release.js +21 -24
  61. package/lib/deploy/hosting/uploader.js +5 -5
  62. package/lib/deploy/remoteconfig/functions.js +2 -2
  63. package/lib/emulator/auth/cloudFunctions.js +1 -1
  64. package/lib/emulator/auth/operations.js +1 -1
  65. package/lib/emulator/commandUtils.js +5 -1
  66. package/lib/emulator/constants.js +3 -0
  67. package/lib/emulator/controller.js +48 -18
  68. package/lib/emulator/download.js +18 -1
  69. package/lib/emulator/downloadableEmulators.js +30 -13
  70. package/lib/emulator/emulatorLogger.js +19 -1
  71. package/lib/emulator/extensions/validation.js +35 -0
  72. package/lib/emulator/extensionsEmulator.js +140 -0
  73. package/lib/emulator/functionsEmulator.js +175 -86
  74. package/lib/emulator/functionsEmulatorRuntime.js +108 -83
  75. package/lib/emulator/functionsEmulatorShared.js +51 -1
  76. package/lib/emulator/functionsEmulatorShell.js +1 -2
  77. package/lib/emulator/functionsEmulatorUtils.js +4 -4
  78. package/lib/emulator/functionsRuntimeWorker.js +3 -3
  79. package/lib/emulator/hub.js +4 -3
  80. package/lib/emulator/loggingEmulator.js +1 -1
  81. package/lib/emulator/pubsubEmulator.js +1 -1
  82. package/lib/emulator/registry.js +10 -2
  83. package/lib/emulator/storage/apis/firebase.js +31 -26
  84. package/lib/emulator/storage/apis/gcloud.js +7 -12
  85. package/lib/emulator/storage/files.js +36 -34
  86. package/lib/emulator/storage/index.js +2 -2
  87. package/lib/emulator/storage/metadata.js +2 -2
  88. package/lib/emulator/storage/rules/runtime.js +8 -7
  89. package/lib/emulator/types.js +3 -0
  90. package/lib/ensureApiEnabled.js +5 -1
  91. package/lib/error.js +1 -1
  92. package/lib/extensions/askUserForParam.js +2 -2
  93. package/lib/extensions/changelog.js +3 -1
  94. package/lib/extensions/checkProjectBilling.js +1 -1
  95. package/lib/extensions/diagnose.js +56 -0
  96. package/lib/extensions/displayExtensionInfo.js +1 -1
  97. package/lib/extensions/emulator/optionsHelper.js +24 -8
  98. package/lib/extensions/emulator/specHelper.js +10 -23
  99. package/lib/extensions/export.js +1 -51
  100. package/lib/extensions/extensionsApi.js +1 -1
  101. package/lib/extensions/extensionsHelper.js +23 -10
  102. package/lib/extensions/listExtensions.js +2 -0
  103. package/lib/extensions/manifest.js +48 -0
  104. package/lib/extensions/metricsUtils.js +4 -4
  105. package/lib/extensions/paramHelper.js +4 -4
  106. package/lib/extensions/refs.js +1 -1
  107. package/lib/extensions/secretsUtils.js +4 -4
  108. package/lib/functional.js +1 -1
  109. package/lib/functions/env.js +7 -8
  110. package/lib/functions/secrets.js +112 -0
  111. package/lib/gcp/cloudfunctions.js +24 -5
  112. package/lib/gcp/cloudfunctionsv2.js +18 -5
  113. package/lib/gcp/cloudtasks.js +1 -1
  114. package/lib/gcp/docker.js +2 -2
  115. package/lib/gcp/run.js +2 -2
  116. package/lib/gcp/secretManager.js +128 -46
  117. package/lib/gcp/storage.js +1 -0
  118. package/lib/hosting/api.js +1 -1
  119. package/lib/hosting/functionsProxy.js +15 -5
  120. package/lib/hosting/proxy.js +2 -2
  121. package/lib/init/features/account.js +1 -1
  122. package/lib/management/database.js +1 -1
  123. package/lib/previews.js +1 -1
  124. package/lib/responseToError.js +16 -7
  125. package/lib/serve/functions.js +2 -2
  126. package/lib/serve/hosting.js +1 -1
  127. package/lib/utils.js +7 -2
  128. package/npm-shrinkwrap.json +904 -412
  129. package/package.json +3 -3
  130. package/schema/firebase-config.json +32 -0
  131. package/templates/init/functions/javascript/package.lint.json +3 -3
  132. package/templates/init/functions/javascript/package.nolint.json +2 -2
  133. package/templates/init/functions/typescript/package.lint.json +7 -7
  134. package/templates/init/functions/typescript/package.nolint.json +3 -3
@@ -13,6 +13,7 @@ const TYPE_VERBOSITY = {
13
13
  USER: 2,
14
14
  WARN: 2,
15
15
  WARN_ONCE: 2,
16
+ ERROR: 2,
16
17
  };
17
18
  var Verbosity;
18
19
  (function (Verbosity) {
@@ -33,7 +34,7 @@ class EmulatorLogger {
33
34
  },
34
35
  });
35
36
  }
36
- static forFunction(functionName) {
37
+ static forFunction(functionName, extensionLogInfo) {
37
38
  return new EmulatorLogger({
38
39
  metadata: {
39
40
  emulator: {
@@ -42,6 +43,17 @@ class EmulatorLogger {
42
43
  function: {
43
44
  name: functionName,
44
45
  },
46
+ extension: extensionLogInfo,
47
+ },
48
+ });
49
+ }
50
+ static forExtension(extensionLogInfo) {
51
+ return new EmulatorLogger({
52
+ metadata: {
53
+ emulator: {
54
+ name: "extensions",
55
+ },
56
+ extension: extensionLogInfo,
45
57
  },
46
58
  });
47
59
  }
@@ -79,6 +91,9 @@ class EmulatorLogger {
79
91
  case "SUCCESS":
80
92
  utils.logSuccess(text, "info", mergedData);
81
93
  break;
94
+ case "ERROR":
95
+ utils.logBullet(text, "error", mergedData);
96
+ break;
82
97
  }
83
98
  }
84
99
  handleRuntimeLog(log, ignore = []) {
@@ -196,6 +211,9 @@ You can probably fix this by running "npm install ${systemLog.data.name}@latest"
196
211
  EmulatorLogger.warnOnceCache.add(text);
197
212
  }
198
213
  break;
214
+ case "ERROR":
215
+ utils.logLabeledError(label, text, "error", mergedData);
216
+ break;
199
217
  }
200
218
  }
201
219
  static shouldSupress(type) {
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getUnemulatedAPIs = void 0;
4
+ const planner = require("../../deploy/extensions/planner");
5
+ const ensureApiEnabled_1 = require("../../ensureApiEnabled");
6
+ const EMULATED_APIS = [
7
+ "storage-component.googleapis.com",
8
+ "firestore.googleapis.com",
9
+ "pubsub.googleapis.com",
10
+ "identitytoolkit.googleapis.com",
11
+ ];
12
+ async function getUnemulatedAPIs(projectId, instances) {
13
+ var _a;
14
+ const unemulatedAPIs = {};
15
+ for (const i of instances) {
16
+ const extensionVersion = await planner.getExtensionVersion(i);
17
+ for (const api of (_a = extensionVersion.spec.apis) !== null && _a !== void 0 ? _a : []) {
18
+ if (!EMULATED_APIS.includes(api.apiName)) {
19
+ if (unemulatedAPIs[api.apiName]) {
20
+ unemulatedAPIs[api.apiName].instanceIds.push(i.instanceId);
21
+ }
22
+ else {
23
+ const enabled = await (0, ensureApiEnabled_1.check)(projectId, api.apiName, "extensions", true);
24
+ unemulatedAPIs[api.apiName] = {
25
+ apiName: api.apiName,
26
+ instanceIds: [i.instanceId],
27
+ enabled,
28
+ };
29
+ }
30
+ }
31
+ }
32
+ }
33
+ return Object.values(unemulatedAPIs);
34
+ }
35
+ exports.getUnemulatedAPIs = getUnemulatedAPIs;
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExtensionsEmulator = void 0;
4
+ const fs = require("fs-extra");
5
+ const os = require("os");
6
+ const path = require("path");
7
+ const clc = require("cli-color");
8
+ const Table = require("cli-table");
9
+ const child_process_1 = require("child_process");
10
+ const planner = require("../deploy/extensions/planner");
11
+ const error_1 = require("../error");
12
+ const refs_1 = require("../extensions/refs");
13
+ const download_1 = require("./download");
14
+ const optionsHelper_1 = require("../extensions/emulator/optionsHelper");
15
+ const emulatorLogger_1 = require("./emulatorLogger");
16
+ const types_1 = require("./types");
17
+ const validation_1 = require("./extensions/validation");
18
+ const ensureApiEnabled_1 = require("../ensureApiEnabled");
19
+ const shortenUrl_1 = require("../shortenUrl");
20
+ class ExtensionsEmulator {
21
+ constructor(args) {
22
+ this.want = [];
23
+ this.logger = emulatorLogger_1.EmulatorLogger.forEmulator(types_1.Emulators.EXTENSIONS);
24
+ this.args = args;
25
+ }
26
+ async readManifest() {
27
+ var _a;
28
+ this.want = await planner.want({
29
+ projectId: this.args.projectId,
30
+ projectNumber: this.args.projectNumber,
31
+ aliases: (_a = this.args.aliases) !== null && _a !== void 0 ? _a : [],
32
+ projectDir: this.args.projectDir,
33
+ extensions: this.args.extensions,
34
+ checkLocal: true,
35
+ });
36
+ }
37
+ async ensureSourceCode(instance) {
38
+ if (!instance.ref) {
39
+ throw new error_1.FirebaseError(`No ref found for ${instance.instanceId}. Emulating local extensions is not yet supported.`);
40
+ }
41
+ const ref = (0, refs_1.toExtensionVersionRef)(instance.ref);
42
+ const cacheDir = process.env.FIREBASE_EXTENSIONS_CACHE_PATH ||
43
+ path.join(os.homedir(), ".cache", "firebase", "extensions");
44
+ const sourceCodePath = path.join(cacheDir, ref);
45
+ if (!this.hasValidSource({ path: sourceCodePath, extRef: ref })) {
46
+ const extensionVersion = await planner.getExtensionVersion(instance);
47
+ await (0, download_1.downloadExtensionVersion)(ref, extensionVersion.sourceDownloadUri, sourceCodePath);
48
+ this.installAndBuildSourceCode(sourceCodePath);
49
+ }
50
+ return sourceCodePath;
51
+ }
52
+ hasValidSource(args) {
53
+ const requiredFiles = [
54
+ "./extension.yaml",
55
+ "./functions/package.json",
56
+ "./functions/node_modules",
57
+ ];
58
+ for (const requiredFile of requiredFiles) {
59
+ const f = path.join(args.path, requiredFile);
60
+ if (!fs.existsSync(f)) {
61
+ emulatorLogger_1.EmulatorLogger.forExtension({ ref: args.extRef }).logLabeled("BULLET", "extensions", `Detected invalid source code for ${args.extRef}, expected to find ${f}`);
62
+ return false;
63
+ }
64
+ }
65
+ return true;
66
+ }
67
+ installAndBuildSourceCode(sourceCodePath) {
68
+ const npmInstall = (0, child_process_1.spawnSync)("npm", ["--prefix", `/${sourceCodePath}/functions/`, "install"], {
69
+ encoding: "utf8",
70
+ });
71
+ if (npmInstall.error) {
72
+ throw npmInstall.error;
73
+ }
74
+ const npmRunGCPBuild = (0, child_process_1.spawnSync)("npm", ["--prefix", `/${sourceCodePath}/functions/`, "run", "gcp-build"], { encoding: "utf8" });
75
+ if (npmRunGCPBuild.error) {
76
+ throw npmRunGCPBuild.error;
77
+ }
78
+ }
79
+ async getExtensionBackends() {
80
+ await this.readManifest();
81
+ await this.checkAndWarnAPIs(this.want);
82
+ return Promise.all(this.want.map((i) => {
83
+ return this.toEmulatableBackend(i);
84
+ }));
85
+ }
86
+ async toEmulatableBackend(instance) {
87
+ const extensionDir = await this.ensureSourceCode(instance);
88
+ const functionsDir = path.join(extensionDir, "functions");
89
+ const env = Object.assign(this.autoPopulatedParams(instance), instance.params);
90
+ const { extensionTriggers, nodeMajorVersion } = await (0, optionsHelper_1.getExtensionFunctionInfo)(extensionDir, instance.instanceId, env);
91
+ const extension = await planner.getExtension(instance);
92
+ const extensionVersion = await planner.getExtensionVersion(instance);
93
+ return {
94
+ functionsDir,
95
+ env,
96
+ predefinedTriggers: extensionTriggers,
97
+ nodeMajorVersion: nodeMajorVersion,
98
+ extensionInstanceId: instance.instanceId,
99
+ extension,
100
+ extensionVersion,
101
+ };
102
+ }
103
+ autoPopulatedParams(instance) {
104
+ const projectId = this.args.projectId;
105
+ return {
106
+ PROJECT_ID: projectId !== null && projectId !== void 0 ? projectId : "",
107
+ EXT_INSTANCE_ID: instance.instanceId,
108
+ DATABASE_INSTANCE: projectId !== null && projectId !== void 0 ? projectId : "",
109
+ DATABASE_URL: `https://${projectId}.firebaseio.com`,
110
+ STORAGE_BUCKET: `${projectId}.appspot.com`,
111
+ };
112
+ }
113
+ async checkAndWarnAPIs(instances) {
114
+ const apisToWarn = await (0, validation_1.getUnemulatedAPIs)(this.args.projectId, instances);
115
+ if (apisToWarn.length) {
116
+ const table = new Table({
117
+ head: [
118
+ "API Name",
119
+ "Instances using this API",
120
+ `Enabled on ${this.args.projectId}`,
121
+ `Enable this API`,
122
+ ],
123
+ style: { head: ["yellow"] },
124
+ });
125
+ for (const apiToWarn of apisToWarn) {
126
+ const enablementUri = await (0, shortenUrl_1.shortenUrl)((0, ensureApiEnabled_1.enableApiURI)(this.args.projectId, apiToWarn.apiName));
127
+ table.push([
128
+ apiToWarn.apiName,
129
+ apiToWarn.instanceIds,
130
+ apiToWarn.enabled ? "Yes" : "No",
131
+ apiToWarn.enabled ? "" : clc.bold.underline(enablementUri),
132
+ ]);
133
+ }
134
+ this.logger.logLabeled("WARN", "Extensions", `The following Extensions make calls to Google Cloud APIs that do not have Emulators. ` +
135
+ `These calls will go to production Google Cloud APIs which may have real effects on ${this.args.projectId}.\n` +
136
+ table.toString());
137
+ }
138
+ }
139
+ }
140
+ exports.ExtensionsEmulator = ExtensionsEmulator;