firebase-tools 15.32.1 → 15.33.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 (35) hide show
  1. package/lib/api.js +4 -2
  2. package/lib/commands/apps-create.js +34 -3
  3. package/lib/commands/functions-kits-uninstall.js +43 -21
  4. package/lib/commands/functions-lifecycle-list.js +5 -6
  5. package/lib/commands/hosting-channel-deploy.js +3 -3
  6. package/lib/commands/hosting-clone.js +60 -29
  7. package/lib/commands/hosting-disable.js +5 -1
  8. package/lib/crashlytics/onboarding.js +17 -2
  9. package/lib/deploy/functions/build.js +3 -0
  10. package/lib/deploy/functions/cel.js +89 -58
  11. package/lib/deploy/functions/functionsDeployHelper.js +10 -0
  12. package/lib/deploy/functions/prepare.js +25 -8
  13. package/lib/deploy/functions/release/fabricator.js +1 -5
  14. package/lib/deploy/functions/release/planner.js +3 -2
  15. package/lib/deploy/functions/validate.js +16 -0
  16. package/lib/deploy/hosting/prepare.js +1 -1
  17. package/lib/deploy/hosting/release.js +2 -2
  18. package/lib/experiments.js +12 -0
  19. package/lib/frameworks/next/constants.js +20 -12
  20. package/lib/frameworks/next/index.js +3 -0
  21. package/lib/functions/env.js +4 -2
  22. package/lib/gcp/artifactregistry.js +20 -0
  23. package/lib/gcp/cloudtasks.js +14 -0
  24. package/lib/gcp/cloudtrace.js +38 -0
  25. package/lib/gcp/run.js +5 -0
  26. package/lib/gcp/runv2.js +32 -11
  27. package/lib/hosting/api.js +15 -15
  28. package/lib/hosting/runTags.js +1 -1
  29. package/lib/init/features/auth.js +46 -8
  30. package/lib/mcp/tools/firestore/converter.js +2 -2
  31. package/lib/mcp/util.js +11 -10
  32. package/lib/profileReport.js +4 -4
  33. package/lib/tsconfig.compile.tsbuildinfo +1 -1
  34. package/lib/tsconfig.publish.tsbuildinfo +1 -1
  35. package/package.json +1 -1
package/lib/gcp/runv2.js CHANGED
@@ -28,33 +28,52 @@ const client = new apiv2_1.Client({
28
28
  apiVersion: exports.API_VERSION,
29
29
  });
30
30
  (0, metaprogramming_1.assertImplements)();
31
+ const PENDING_BUILD_STATUSES = ["STATUS_UNKNOWN", "PENDING", "QUEUED", "WORKING"];
31
32
  async function submitBuild(projectId, location, build) {
32
- const res = await client.post(`/projects/${projectId}/locations/${location}/builds`, build);
33
- if (res.status !== 200) {
34
- throw new error_1.FirebaseError(`Failed to submit build: ${res.status} ${res.body}`);
33
+ const res = await client.post(`/projects/${projectId}/locations/${location}/builds:submit`, build);
34
+ if (res.body?.baseImageWarning) {
35
+ logger_1.logger.warn(res.body.baseImageWarning);
35
36
  }
37
+ const cloudBuild = res.body?.buildOperation?.metadata?.build;
38
+ if (!cloudBuild) {
39
+ throw new error_1.FirebaseError("Failed to submit build: no build was returned.");
40
+ }
41
+ let status;
36
42
  await (0, operation_poller_1.pollOperation)({
37
43
  apiOrigin: (0, api_1.cloudbuildOrigin)(),
38
44
  apiVersion: "v1",
39
- operationResourceName: res.body.buildOperation,
45
+ operationResourceName: cloudBuild.name,
46
+ masterTimeout: 30 * 60 * 1000,
47
+ maxBackoff: 10000,
48
+ doneFn: (b) => {
49
+ status = b?.status;
50
+ return !b?.status || !PENDING_BUILD_STATUSES.includes(b.status);
51
+ },
40
52
  });
53
+ if (status !== "SUCCESS") {
54
+ throw new error_1.FirebaseError(`Cloud Build failed with status ${status ?? "UNKNOWN"}. View the build logs at ${cloudBuild.logUrl ?? ""}`);
55
+ }
41
56
  }
42
- async function updateService(service) {
43
- const fieldMask = proto.fieldMasks(service, "labels", "annotations", "tags");
44
- fieldMask.push("template.revision");
57
+ async function updateService(service, opts = {}) {
58
+ let updateMask = opts.updateMask;
59
+ if (!updateMask) {
60
+ updateMask = proto.fieldMasks(service, "labels", "annotations", "tags");
61
+ updateMask.push("template.revision");
62
+ }
45
63
  const res = await client.patch(service.name, service, {
46
64
  queryParams: {
47
- updateMask: fieldMask.join(","),
65
+ updateMask: updateMask.join(","),
48
66
  },
49
67
  });
50
68
  const svc = await (0, operation_poller_1.pollOperation)({
51
69
  apiOrigin: (0, api_1.runOrigin)(),
52
70
  apiVersion: exports.API_VERSION,
53
71
  operationResourceName: res.body.name,
72
+ masterTimeout: opts.pollTimeoutMs,
54
73
  });
55
74
  return svc;
56
75
  }
57
- async function createService(projectId, location, serviceId, service) {
76
+ async function createService(projectId, location, serviceId, service, opts = {}) {
58
77
  const { name, ...serviceBody } = service;
59
78
  const res = await client.post(`/projects/${projectId}/locations/${location}/services`, serviceBody, {
60
79
  queryParams: {
@@ -65,6 +84,7 @@ async function createService(projectId, location, serviceId, service) {
65
84
  apiOrigin: (0, api_1.runOrigin)(),
66
85
  apiVersion: exports.API_VERSION,
67
86
  operationResourceName: res.body.name,
87
+ masterTimeout: opts.pollTimeoutMs,
68
88
  });
69
89
  return svc;
70
90
  }
@@ -82,7 +102,7 @@ async function getService(projectId, location, serviceId) {
82
102
  const res = await client.get(name);
83
103
  return res.body;
84
104
  }
85
- async function listServices(projectId) {
105
+ async function listServices(projectId, functionsOnly = true) {
86
106
  const allServices = [];
87
107
  let pageToken = undefined;
88
108
  do {
@@ -98,7 +118,8 @@ async function listServices(projectId) {
98
118
  }
99
119
  if (res.body.services) {
100
120
  for (const service of res.body.services) {
101
- if (service.labels?.[exports.CLIENT_NAME_LABEL] === "cloud-functions" ||
121
+ if (!functionsOnly ||
122
+ service.labels?.[exports.CLIENT_NAME_LABEL] === "cloud-functions" ||
102
123
  service.labels?.[exports.CLIENT_NAME_LABEL] === "cloudfunctions" ||
103
124
  service.labels?.[exports.CLIENT_NAME_LABEL] === "firebase-functions") {
104
125
  allServices.push(service);
@@ -56,7 +56,7 @@ const apiClient = new apiv2_1.Client({
56
56
  apiVersion: "v1beta1",
57
57
  auth: true,
58
58
  });
59
- async function getChannel(project = "-", site, channelId) {
59
+ async function getChannel(project, site, channelId) {
60
60
  try {
61
61
  const res = await apiClient.get(`/projects/${project}/sites/${site}/channels/${channelId}`);
62
62
  return res.body;
@@ -68,7 +68,7 @@ async function getChannel(project = "-", site, channelId) {
68
68
  throw e;
69
69
  }
70
70
  }
71
- async function listChannels(project = "-", site) {
71
+ async function listChannels(project, site) {
72
72
  const channels = [];
73
73
  let nextPageToken = "";
74
74
  for (;;) {
@@ -90,30 +90,30 @@ async function listChannels(project = "-", site) {
90
90
  }
91
91
  }
92
92
  }
93
- async function createChannel(project = "-", site, channelId, ttlMillis = expireUtils_1.DEFAULT_DURATION) {
93
+ async function createChannel(project, site, channelId, ttlMillis = expireUtils_1.DEFAULT_DURATION) {
94
94
  const res = await apiClient.post(`/projects/${project}/sites/${site}/channels?channelId=${channelId}`, { ttl: `${ttlMillis / 1000}s` });
95
95
  return res.body;
96
96
  }
97
- async function updateChannelTtl(project = "-", site, channelId, ttlMillis = ONE_WEEK_MS) {
97
+ async function updateChannelTtl(project, site, channelId, ttlMillis = ONE_WEEK_MS) {
98
98
  const res = await apiClient.patch(`/projects/${project}/sites/${site}/channels/${channelId}`, { ttl: `${ttlMillis / 1000}s` }, { queryParams: { updateMask: "ttl" } });
99
99
  return res.body;
100
100
  }
101
- async function deleteChannel(project = "-", site, channelId) {
101
+ async function deleteChannel(project, site, channelId) {
102
102
  await apiClient.delete(`/projects/${project}/sites/${site}/channels/${channelId}`);
103
103
  }
104
- async function createVersion(siteId, version) {
105
- const res = await apiClient.post(`projects/-/sites/${siteId}/versions`, version);
104
+ async function createVersion(project, siteId, version) {
105
+ const res = await apiClient.post(`/projects/${project}/sites/${siteId}/versions`, version);
106
106
  return res.body.name;
107
107
  }
108
- async function updateVersion(site, versionId, version) {
109
- const res = await apiClient.patch(`projects/-/sites/${site}/versions/${versionId}`, version, {
108
+ async function updateVersion(project, site, versionId, version) {
109
+ const res = await apiClient.patch(`/projects/${project}/sites/${site}/versions/${versionId}`, version, {
110
110
  queryParams: {
111
111
  updateMask: proto.fieldMasks(version, "labels", "config").join(","),
112
112
  },
113
113
  });
114
114
  return res.body;
115
115
  }
116
- async function listVersions(site) {
116
+ async function listVersions(project, site) {
117
117
  let pageToken = undefined;
118
118
  const versions = [];
119
119
  do {
@@ -121,7 +121,7 @@ async function listVersions(site) {
121
121
  if (pageToken) {
122
122
  queryParams.pageToken = pageToken;
123
123
  }
124
- const res = await apiClient.get(`projects/-/sites/${site}/versions`, {
124
+ const res = await apiClient.get(`/projects/${project}/sites/${site}/versions`, {
125
125
  queryParams,
126
126
  });
127
127
  versions.push(...(res.body.versions ?? []));
@@ -129,8 +129,8 @@ async function listVersions(site) {
129
129
  } while (pageToken);
130
130
  return versions;
131
131
  }
132
- async function cloneVersion(site, versionName, finalize = false) {
133
- const res = await apiClient.post(`/projects/-/sites/${site}/versions:clone`, {
132
+ async function cloneVersion(project, site, versionName, finalize = false) {
133
+ const res = await apiClient.post(`/projects/${project}/sites/${site}/versions:clone`, {
134
134
  sourceVersion: versionName,
135
135
  finalize,
136
136
  });
@@ -143,8 +143,8 @@ async function cloneVersion(site, versionName, finalize = false) {
143
143
  });
144
144
  return pollRes;
145
145
  }
146
- async function createRelease(site, channel, version, partialRelease) {
147
- const res = await apiClient.post(`/projects/-/sites/${site}/channels/${channel}/releases`, partialRelease, { queryParams: { versionName: version } });
146
+ async function createRelease(project, site, channel, version, partialRelease) {
147
+ const res = await apiClient.post(`/projects/${project}/sites/${site}/channels/${channel}/releases`, partialRelease, { queryParams: { versionName: version } });
148
148
  return res.body;
149
149
  }
150
150
  async function listSites(project) {
@@ -14,7 +14,7 @@ exports.TODO_TAG_NAME = "this is an invalid tag name so it cannot be real";
14
14
  async function gcTagsForServices(project, services) {
15
15
  const validTagsByServiceByRegion = {};
16
16
  const sites = await api.listSites(project);
17
- const allVersionsNested = await Promise.all(sites.map((site) => api.listVersions(node_path_1.posix.basename(site.name))));
17
+ const allVersionsNested = await Promise.all(sites.map((site) => api.listVersions(project, node_path_1.posix.basename(site.name))));
18
18
  const activeVersions = [...(0, functional_1.flattenArray)(allVersionsNested)].filter((version) => {
19
19
  return version.status === "CREATED" || version.status === "FINALIZED";
20
20
  });
@@ -5,7 +5,11 @@ exports.actuate = actuate;
5
5
  const clc = require("colorette");
6
6
  const prompt_1 = require("../../prompt");
7
7
  const logger_1 = require("../../logger");
8
- async function askQuestions(setup) {
8
+ const getDefaultHostingSite_1 = require("../../getDefaultHostingSite");
9
+ const interactive_1 = require("../../hosting/interactive");
10
+ const api_1 = require("../../hosting/api");
11
+ const utils_1 = require("../../utils");
12
+ async function askQuestions(setup, config, options) {
9
13
  const authConfig = setup.config.auth;
10
14
  const choices = [
11
15
  {
@@ -38,33 +42,67 @@ async function askQuestions(setup) {
38
42
  if (providers.includes("google")) {
39
43
  logger_1.logger.info("");
40
44
  logger_1.logger.info("Configuring Google Sign-In...");
45
+ const projectId = setup.projectId;
46
+ const defaultDisplayName = authConfig?.providers?.googleSignIn?.oAuthBrandDisplayName || projectId || "My App";
41
47
  const oAuthBrandDisplayName = await (0, prompt_1.input)({
42
48
  message: "What display name would you like to use for your OAuth brand?",
43
- default: authConfig?.providers?.googleSignIn?.oAuthBrandDisplayName ||
44
- setup.project?.projectId ||
45
- "My App",
49
+ default: defaultDisplayName,
46
50
  });
51
+ const defaultEmail = authConfig?.providers?.googleSignIn?.supportEmail ||
52
+ (projectId ? `support@${projectId}.firebaseapp.com` : undefined);
47
53
  const supportEmail = await (0, prompt_1.input)({
48
54
  message: "What support email would you like to register for your OAuth brand?",
49
- default: authConfig?.providers?.googleSignIn?.supportEmail ||
50
- (setup.project ? `support@${setup.project.projectId}.firebaseapp.com` : undefined),
55
+ default: defaultEmail,
51
56
  });
52
57
  providersConfig.googleSignIn = {
53
58
  oAuthBrandDisplayName,
54
59
  supportEmail,
55
60
  };
56
61
  }
62
+ let newSiteId;
63
+ if (setup.projectId) {
64
+ let existingSite = setup.featureInfo?.hosting?.newSiteId;
65
+ if (!existingSite) {
66
+ try {
67
+ existingSite = await (0, getDefaultHostingSite_1.getDefaultHostingSite)({ projectId: setup.projectId });
68
+ }
69
+ catch (err) {
70
+ if (err !== getDefaultHostingSite_1.errNoDefaultSite) {
71
+ throw err;
72
+ }
73
+ }
74
+ }
75
+ if (existingSite) {
76
+ logger_1.logger.info(`Firebase Hosting site is present: ${clc.bold(existingSite)}.`);
77
+ }
78
+ else if (await (0, prompt_1.confirm)({
79
+ message: "A Firebase Hosting site is required for Firebase Authentication. Would you like to create a default site now?",
80
+ default: true,
81
+ nonInteractive: options?.nonInteractive,
82
+ })) {
83
+ newSiteId = await (0, interactive_1.pickHostingSiteName)("", {
84
+ projectId: setup.projectId,
85
+ nonInteractive: options?.nonInteractive,
86
+ });
87
+ }
88
+ }
57
89
  if (!setup.featureInfo) {
58
90
  setup.featureInfo = {};
59
91
  }
60
- setup.featureInfo.auth = { providers: providersConfig };
92
+ setup.featureInfo.auth = { providers: providersConfig, newSiteId };
61
93
  }
62
94
  async function actuate(setup, config) {
63
95
  const authConfig = setup.featureInfo?.auth;
64
96
  if (!authConfig) {
65
97
  return;
66
98
  }
67
- config.set("auth", authConfig);
99
+ if (authConfig.newSiteId && setup.projectId) {
100
+ await (0, api_1.createSite)(setup.projectId, authConfig.newSiteId);
101
+ logger_1.logger.info("");
102
+ (0, utils_1.logSuccess)(`Firebase Hosting site ${authConfig.newSiteId} created!`);
103
+ logger_1.logger.info("");
104
+ }
105
+ config.set("auth", { providers: authConfig.providers });
68
106
  config.writeProjectFile("firebase.json", config.src);
69
107
  logger_1.logger.info("");
70
108
  logger_1.logger.info("Generated firebase.json with auth configuration.");
@@ -28,9 +28,9 @@ function convertInputToValue(inputValue) {
28
28
  return { arrayValue: arrayValue };
29
29
  }
30
30
  else if (typeof inputValue === "object") {
31
- if (inputValue.hasOwnProperty("latitude") &&
31
+ if (Object.prototype.hasOwnProperty.call(inputValue, "latitude") &&
32
32
  typeof inputValue.latitude === "number" &&
33
- inputValue.hasOwnProperty("longitude") &&
33
+ Object.prototype.hasOwnProperty.call(inputValue, "longitude") &&
34
34
  typeof inputValue.longitude === "number") {
35
35
  return { geoPointValue: inputValue };
36
36
  }
package/lib/mcp/util.js CHANGED
@@ -114,13 +114,13 @@ function deepClean(obj, isRootLevel = false) {
114
114
  return obj;
115
115
  }
116
116
  const cleanedObj = { ...obj };
117
- if (cleanedObj.hasOwnProperty("$schema")) {
117
+ if (Object.prototype.hasOwnProperty.call(cleanedObj, "$schema")) {
118
118
  delete cleanedObj.$schema;
119
119
  }
120
- if (cleanedObj.hasOwnProperty("additionalProperties")) {
120
+ if (Object.prototype.hasOwnProperty.call(cleanedObj, "additionalProperties")) {
121
121
  delete cleanedObj.additionalProperties;
122
122
  }
123
- if (cleanedObj.hasOwnProperty("type")) {
123
+ if (Object.prototype.hasOwnProperty.call(cleanedObj, "type")) {
124
124
  const currentType = cleanedObj.type;
125
125
  if (Array.isArray(currentType)) {
126
126
  let filteredTypes = currentType.filter((t) => t !== "null");
@@ -159,12 +159,12 @@ function deepClean(obj, isRootLevel = false) {
159
159
  }
160
160
  }
161
161
  }
162
- if (cleanedObj.hasOwnProperty("properties") &&
162
+ if (Object.prototype.hasOwnProperty.call(cleanedObj, "properties") &&
163
163
  typeof cleanedObj.properties === "object" &&
164
164
  cleanedObj.properties !== null) {
165
165
  const newProperties = {};
166
166
  for (const key in cleanedObj.properties) {
167
- if (cleanedObj.properties.hasOwnProperty(key)) {
167
+ if (Object.prototype.hasOwnProperty.call(cleanedObj.properties, key)) {
168
168
  const cleanedPropertySchema = deepClean(cleanedObj.properties[key], false);
169
169
  if (cleanedPropertySchema !== null) {
170
170
  newProperties[key] = cleanedPropertySchema;
@@ -178,7 +178,7 @@ function deepClean(obj, isRootLevel = false) {
178
178
  cleanedObj.properties = newProperties;
179
179
  }
180
180
  }
181
- if (cleanedObj.hasOwnProperty("items") &&
181
+ if (Object.prototype.hasOwnProperty.call(cleanedObj, "items") &&
182
182
  typeof cleanedObj.items === "object" &&
183
183
  cleanedObj.items !== null) {
184
184
  const cleanedItemsSchema = deepClean(cleanedObj.items, false);
@@ -191,12 +191,12 @@ function deepClean(obj, isRootLevel = false) {
191
191
  }
192
192
  const defKeywords = ["$defs", "definitions"];
193
193
  for (const keyword of defKeywords) {
194
- if (cleanedObj.hasOwnProperty(keyword) &&
194
+ if (Object.prototype.hasOwnProperty.call(cleanedObj, keyword) &&
195
195
  typeof cleanedObj[keyword] === "object" &&
196
196
  cleanedObj[keyword] !== null) {
197
197
  const newDefs = {};
198
198
  for (const defKey in cleanedObj[keyword]) {
199
- if (cleanedObj[keyword].hasOwnProperty(defKey)) {
199
+ if (Object.prototype.hasOwnProperty.call(cleanedObj[keyword], defKey)) {
200
200
  const cleanedDef = deepClean(cleanedObj[keyword][defKey], false);
201
201
  if (cleanedDef !== null) {
202
202
  newDefs[defKey] = cleanedDef;
@@ -213,7 +213,8 @@ function deepClean(obj, isRootLevel = false) {
213
213
  }
214
214
  const schemaArrayKeywords = ["anyOf", "allOf", "oneOf"];
215
215
  for (const keyword of schemaArrayKeywords) {
216
- if (cleanedObj.hasOwnProperty(keyword) && Array.isArray(cleanedObj[keyword])) {
216
+ if (Object.prototype.hasOwnProperty.call(cleanedObj, keyword) &&
217
+ Array.isArray(cleanedObj[keyword])) {
217
218
  const newSchemaArray = cleanedObj[keyword]
218
219
  .map((subSchema) => deepClean(subSchema, false))
219
220
  .filter((subSchema) => subSchema !== null);
@@ -228,7 +229,7 @@ function deepClean(obj, isRootLevel = false) {
228
229
  return cleanedObj;
229
230
  }
230
231
  function cleanSchema(schema) {
231
- if (schema && schema.hasOwnProperty("type")) {
232
+ if (schema && Object.prototype.hasOwnProperty.call(schema, "type")) {
232
233
  const topLevelType = schema.type;
233
234
  if (topLevelType === "array") {
234
235
  return {};
@@ -120,10 +120,10 @@ class ProfileReport {
120
120
  opStats.rejected = 0;
121
121
  }
122
122
  opStats.times += 1;
123
- if (data.hasOwnProperty("millis")) {
123
+ if (Object.prototype.hasOwnProperty.call(data, "millis")) {
124
124
  opStats.millis += data.millis;
125
125
  }
126
- if (data.hasOwnProperty("pendingTime")) {
126
+ if (Object.prototype.hasOwnProperty.call(data, "pendingTime")) {
127
127
  opStats.pendingCount++;
128
128
  opStats.pendingTime += data.pendingTime;
129
129
  }
@@ -143,10 +143,10 @@ class ProfileReport {
143
143
  }
144
144
  const node = opType[path];
145
145
  node.times += 1;
146
- if (data.hasOwnProperty("millis")) {
146
+ if (Object.prototype.hasOwnProperty.call(data, "millis")) {
147
147
  node.millis += data.millis;
148
148
  }
149
- if (data.hasOwnProperty("pendingTime")) {
149
+ if (Object.prototype.hasOwnProperty.call(data, "pendingTime")) {
150
150
  node.pendingCount++;
151
151
  node.pendingTime += data.pendingTime;
152
152
  }