firebase-tools 11.6.0 → 11.7.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.
@@ -161,9 +161,11 @@ function writeUserEnvs(toWrite, envOpts) {
161
161
  return;
162
162
  }
163
163
  const { functionsSource, projectId, projectAlias, isEmulator } = envOpts;
164
- let envFiles = findEnvfiles(functionsSource, projectId, projectAlias, isEmulator);
165
- if (envFiles.length === 0) {
166
- envFiles = [createEnvFile(envOpts)];
164
+ const envFiles = findEnvfiles(functionsSource, projectId, projectAlias, isEmulator);
165
+ const projectScopedFileName = `.env.${projectId}`;
166
+ const projectScopedFileExists = envFiles.includes(projectScopedFileName);
167
+ if (!projectScopedFileExists) {
168
+ createEnvFile(envOpts);
167
169
  }
168
170
  const currentEnvs = loadUserEnvs(envOpts);
169
171
  for (const k of Object.keys(toWrite)) {
@@ -172,17 +174,15 @@ function writeUserEnvs(toWrite, envOpts) {
172
174
  throw new error_1.FirebaseError(`Attempted to write param-defined key ${k} to .env files, but it was already defined.`);
173
175
  }
174
176
  }
175
- const mostSpecificEnv = path.join(functionsSource, envFiles[envFiles.length - 1]);
176
- (0, utils_1.logBullet)(clc.cyan(clc.bold("functions: ")) + `Writing new parameter values to disk: ${mostSpecificEnv}`);
177
+ (0, utils_1.logBullet)(clc.cyan(clc.bold("functions: ")) +
178
+ `Writing new parameter values to disk: ${projectScopedFileName}`);
177
179
  for (const k of Object.keys(toWrite)) {
178
- fs.appendFileSync(mostSpecificEnv, formatUserEnvForWrite(k, toWrite[k]));
180
+ fs.appendFileSync(path.join(functionsSource, projectScopedFileName), formatUserEnvForWrite(k, toWrite[k]));
179
181
  }
180
182
  }
181
183
  exports.writeUserEnvs = writeUserEnvs;
182
184
  function createEnvFile(envOpts) {
183
- const fileToWrite = envOpts.isEmulator
184
- ? FUNCTIONS_EMULATOR_DOTENV
185
- : `.env.${envOpts.projectAlias || envOpts.projectId}`;
185
+ const fileToWrite = envOpts.isEmulator ? FUNCTIONS_EMULATOR_DOTENV : `.env.${envOpts.projectId}`;
186
186
  logger_1.logger.debug(`Creating ${fileToWrite}...`);
187
187
  fs.writeFileSync(path.join(envOpts.functionsSource, fileToWrite), "", { flag: "wx" });
188
188
  return fileToWrite;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.jobFromEndpoint = exports.topicNameForEndpoint = exports.jobNameForEndpoint = exports.createOrReplaceJob = exports.updateJob = exports.getJob = exports.deleteJob = exports.createJob = void 0;
3
+ exports.jobFromEndpoint = exports.topicNameForEndpoint = exports.jobNameForEndpoint = exports.createOrReplaceJob = exports.deleteJob = void 0;
4
4
  const _ = require("lodash");
5
5
  const error_1 = require("../error");
6
6
  const logger_1 = require("../logger");
@@ -8,15 +8,18 @@ const api_1 = require("../api");
8
8
  const apiv2_1 = require("../apiv2");
9
9
  const backend = require("../deploy/functions/backend");
10
10
  const proto = require("./proto");
11
+ const checkIam_1 = require("../deploy/functions/checkIam");
11
12
  const functional_1 = require("../functional");
12
13
  const VERSION = "v1";
13
- const DEFAULT_TIME_ZONE = "America/Los_Angeles";
14
+ const DEFAULT_TIME_ZONE_V1 = "America/Los_Angeles";
15
+ const DEFAULT_TIME_ZONE_V2 = "UTC";
14
16
  const apiClient = new apiv2_1.Client({ urlPrefix: api_1.cloudschedulerOrigin, apiVersion: VERSION });
15
17
  function createJob(job) {
16
18
  const strippedName = job.name.substring(0, job.name.lastIndexOf("/"));
17
- return apiClient.post(`/${strippedName}`, Object.assign({ timeZone: DEFAULT_TIME_ZONE }, job));
19
+ const json = job.pubsubTarget
20
+ ? Object.assign({ timeZone: DEFAULT_TIME_ZONE_V1 }, job) : Object.assign({ timeZone: DEFAULT_TIME_ZONE_V2 }, job);
21
+ return apiClient.post(`/${strippedName}`, json);
18
22
  }
19
- exports.createJob = createJob;
20
23
  function deleteJob(name) {
21
24
  return apiClient.delete(`/${name}`);
22
25
  }
@@ -26,16 +29,23 @@ function getJob(name) {
26
29
  resolveOnHTTPError: true,
27
30
  });
28
31
  }
29
- exports.getJob = getJob;
30
32
  function updateJob(job) {
31
- const fieldMasks = proto.fieldMasks(job, "pubsubTarget");
32
- return apiClient.patch(`/${job.name}`, Object.assign({ timeZone: DEFAULT_TIME_ZONE }, job), {
33
+ let fieldMasks;
34
+ let json;
35
+ if (job.pubsubTarget) {
36
+ fieldMasks = proto.fieldMasks(job, "pubsubTarget");
37
+ json = Object.assign({ timeZone: DEFAULT_TIME_ZONE_V1 }, job);
38
+ }
39
+ else {
40
+ fieldMasks = proto.fieldMasks(job, "httpTarget");
41
+ json = Object.assign({ timeZone: DEFAULT_TIME_ZONE_V2 }, job);
42
+ }
43
+ return apiClient.patch(`/${job.name}`, json, {
33
44
  queryParams: {
34
45
  updateMask: fieldMasks.join(","),
35
46
  },
36
47
  });
37
48
  }
38
- exports.updateJob = updateJob;
39
49
  async function createOrReplaceJob(job) {
40
50
  var _a, _b;
41
51
  const jobName = job.name.split("/").pop();
@@ -56,7 +66,7 @@ async function createOrReplaceJob(job) {
56
66
  return newJob;
57
67
  }
58
68
  if (!job.timeZone) {
59
- job.timeZone = DEFAULT_TIME_ZONE;
69
+ job.timeZone = job.pubsubTarget ? DEFAULT_TIME_ZONE_V1 : DEFAULT_TIME_ZONE_V2;
60
70
  }
61
71
  if (!needUpdate(existingJob.body, job)) {
62
72
  logger_1.logger.debug(`scheduler job ${jobName} is up to date, no changes required`);
@@ -90,9 +100,9 @@ function needUpdate(existingJob, newJob) {
90
100
  }
91
101
  return false;
92
102
  }
93
- function jobNameForEndpoint(endpoint, appEngineLocation) {
103
+ function jobNameForEndpoint(endpoint, location) {
94
104
  const id = backend.scheduleIdForFunction(endpoint);
95
- return `projects/${endpoint.project}/locations/${appEngineLocation}/jobs/${id}`;
105
+ return `projects/${endpoint.project}/locations/${location}/jobs/${id}`;
96
106
  }
97
107
  exports.jobNameForEndpoint = jobNameForEndpoint;
98
108
  function topicNameForEndpoint(endpoint) {
@@ -100,10 +110,11 @@ function topicNameForEndpoint(endpoint) {
100
110
  return `projects/${endpoint.project}/topics/${id}`;
101
111
  }
102
112
  exports.topicNameForEndpoint = topicNameForEndpoint;
103
- function jobFromEndpoint(endpoint, appEngineLocation) {
113
+ function jobFromEndpoint(endpoint, location, projectNumber) {
104
114
  const job = {};
115
+ job.name = jobNameForEndpoint(endpoint, location);
105
116
  if (endpoint.platform === "gcfv1") {
106
- job.name = jobNameForEndpoint(endpoint, appEngineLocation);
117
+ job.timeZone = endpoint.scheduleTrigger.timeZone || DEFAULT_TIME_ZONE_V1;
107
118
  job.pubsubTarget = {
108
119
  topicName: topicNameForEndpoint(endpoint),
109
120
  attributes: {
@@ -112,7 +123,14 @@ function jobFromEndpoint(endpoint, appEngineLocation) {
112
123
  };
113
124
  }
114
125
  else if (endpoint.platform === "gcfv2") {
115
- throw new error_1.FirebaseError("Do not know how to create a scheduled GCFv2 function");
126
+ job.timeZone = endpoint.scheduleTrigger.timeZone || DEFAULT_TIME_ZONE_V2;
127
+ job.httpTarget = {
128
+ uri: endpoint.uri,
129
+ httpMethod: "POST",
130
+ oidcToken: {
131
+ serviceAccountEmail: (0, checkIam_1.getDefaultComputeServiceAgent)(projectNumber),
132
+ },
133
+ };
116
134
  }
117
135
  else {
118
136
  (0, functional_1.assertExhaustive)(endpoint.platform);
@@ -121,7 +139,6 @@ function jobFromEndpoint(endpoint, appEngineLocation) {
121
139
  throw new error_1.FirebaseError("Cannot create a scheduler job without a schedule:" + JSON.stringify(endpoint));
122
140
  }
123
141
  job.schedule = endpoint.scheduleTrigger.schedule;
124
- job.timeZone = endpoint.scheduleTrigger.timeZone || DEFAULT_TIME_ZONE;
125
142
  if (endpoint.scheduleTrigger.retryConfig) {
126
143
  job.retryConfig = {};
127
144
  proto.copyIfPresent(job.retryConfig, endpoint.scheduleTrigger.retryConfig, "maxDoublings", "retryCount");
package/lib/track.js CHANGED
@@ -47,6 +47,9 @@ const EMULATOR_GA4_USER_PROPS = {
47
47
  node_version: {
48
48
  value: process.version,
49
49
  },
50
+ firebase_tools_version: {
51
+ value: pkg.version,
52
+ },
50
53
  firepit_version: {
51
54
  value: process.env.FIREPIT_VERSION || "none",
52
55
  },