firebase-tools 12.2.0 → 12.2.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.
@@ -82,11 +82,6 @@ class StorageEmulator {
82
82
  getApp() {
83
83
  return this._app;
84
84
  }
85
- async replaceRules(rules) {
86
- await this._rulesManager.stop();
87
- this._rulesManager = this.createRulesManager(rules);
88
- return this._rulesManager.start();
89
- }
90
85
  createRulesManager(rules) {
91
86
  return (0, manager_1.createStorageRulesManager)(rules, this._rulesRuntime);
92
87
  }
@@ -20,6 +20,7 @@ class DefaultStorageRulesManager {
20
20
  this._rules = _rules;
21
21
  }
22
22
  async start() {
23
+ this._runtime.start();
23
24
  const issues = await this.loadRuleset();
24
25
  this.updateWatcher(this._rules.name);
25
26
  return issues;
@@ -29,6 +30,9 @@ class DefaultStorageRulesManager {
29
30
  }
30
31
  async stop() {
31
32
  await this._watcher.close();
33
+ if (this._runtime.alive) {
34
+ await this._runtime.stop();
35
+ }
32
36
  }
33
37
  updateWatcher(rulesFile) {
34
38
  this._watcher = chokidar
@@ -71,6 +71,9 @@ class StorageRulesRuntime {
71
71
  }
72
72
  async start(autoDownload = true) {
73
73
  var _a, _b;
74
+ if (this.alive) {
75
+ return;
76
+ }
74
77
  const downloadDetails = downloadableEmulators_1.DownloadDetails[types_2.Emulators.STORAGE];
75
78
  const hasEmulator = fs.existsSync(downloadDetails.downloadPath);
76
79
  if (!hasEmulator) {
@@ -90,11 +93,11 @@ class StorageRulesRuntime {
90
93
  this._childprocess = (0, cross_spawn_1.spawn)(command.binary, command.args, {
91
94
  stdio: ["pipe", "pipe", "pipe"],
92
95
  });
93
- this._childprocess.on("exit", (code) => {
96
+ this._childprocess.on("exit", () => {
97
+ var _a;
94
98
  this._alive = false;
95
- if (code !== 130) {
96
- throw new error_1.FirebaseError("Storage Emulator Rules runtime exited unexpectedly.");
97
- }
99
+ (_a = this._childprocess) === null || _a === void 0 ? void 0 : _a.removeAllListeners();
100
+ this._childprocess = undefined;
98
101
  });
99
102
  const startPromise = new Promise((resolve) => {
100
103
  this._requests[-1] = {
@@ -152,12 +155,23 @@ class StorageRulesRuntime {
152
155
  return startPromise;
153
156
  }
154
157
  stop() {
155
- var _a;
156
- (_a = this._childprocess) === null || _a === void 0 ? void 0 : _a.kill("SIGINT");
158
+ emulatorLogger_1.EmulatorLogger.forEmulator(types_2.Emulators.STORAGE).log("DEBUG", "Stopping rules runtime.");
159
+ return new Promise((resolve) => {
160
+ var _a;
161
+ if (this.alive) {
162
+ this._childprocess.on("exit", () => {
163
+ resolve();
164
+ });
165
+ (_a = this._childprocess) === null || _a === void 0 ? void 0 : _a.kill("SIGINT");
166
+ }
167
+ else {
168
+ resolve();
169
+ }
170
+ });
157
171
  }
158
172
  async _sendRequest(rab, overrideId) {
159
173
  if (!this._childprocess) {
160
- throw new error_1.FirebaseError("Attempted to send Cloud Storage rules request before child was ready");
174
+ throw new error_1.FirebaseError("Failed to send Cloud Storage rules request due to rules runtime not available.");
161
175
  }
162
176
  const runtimeActionRequest = Object.assign(Object.assign({}, rab), { id: overrideId !== null && overrideId !== void 0 ? overrideId : this._requestCount++ });
163
177
  if (overrideId !== undefined) {
@@ -8,7 +8,6 @@ const types_1 = require("../types");
8
8
  const bodyParser = require("body-parser");
9
9
  const gcloud_1 = require("./apis/gcloud");
10
10
  const firebase_1 = require("./apis/firebase");
11
- const errors_1 = require("../auth/errors");
12
11
  function createApp(defaultProjectId, emulator) {
13
12
  const { storageLayer } = emulator;
14
13
  const app = express();
@@ -51,54 +50,6 @@ function createApp(defaultProjectId, emulator) {
51
50
  await storageLayer.export(path, { initiatedBy });
52
51
  res.sendStatus(200);
53
52
  });
54
- app.put("/internal/setRules", async (req, res) => {
55
- const rulesRaw = req.body.rules;
56
- if (!(rulesRaw && Array.isArray(rulesRaw.files) && rulesRaw.files.length > 0)) {
57
- res.status(400).json({
58
- message: "Request body must include 'rules.files' array",
59
- });
60
- return;
61
- }
62
- const { files } = rulesRaw;
63
- function parseRulesFromFiles(files) {
64
- if (files.length === 1) {
65
- const file = files[0];
66
- if (!isRulesFile(file)) {
67
- throw new errors_1.InvalidArgumentError("Each member of 'rules.files' array must contain 'name' and 'content'");
68
- }
69
- return { name: file.name, content: file.content };
70
- }
71
- const rules = [];
72
- for (const file of files) {
73
- if (!isRulesFile(file) || !file.resource) {
74
- throw new errors_1.InvalidArgumentError("Each member of 'rules.files' array must contain 'name', 'content', and 'resource'");
75
- }
76
- rules.push({ resource: file.resource, rules: { name: file.name, content: file.content } });
77
- }
78
- return rules;
79
- }
80
- let rules;
81
- try {
82
- rules = parseRulesFromFiles(files);
83
- }
84
- catch (err) {
85
- if (err instanceof errors_1.InvalidArgumentError) {
86
- res.status(400).json({ message: err.message });
87
- return;
88
- }
89
- throw err;
90
- }
91
- const issues = await emulator.replaceRules(rules);
92
- if (issues.errors.length > 0) {
93
- res.status(400).json({
94
- message: "There was an error updating rules, see logs for more details",
95
- });
96
- return;
97
- }
98
- res.status(200).json({
99
- message: "Rules updated successfully",
100
- });
101
- });
102
53
  app.post("/internal/reset", (req, res) => {
103
54
  emulator.reset();
104
55
  res.sendStatus(200);
@@ -108,6 +59,3 @@ function createApp(defaultProjectId, emulator) {
108
59
  return Promise.resolve(app);
109
60
  }
110
61
  exports.createApp = createApp;
111
- function isRulesFile(file) {
112
- return (typeof file.name === "string" && typeof file.content === "string");
113
- }
@@ -183,6 +183,9 @@ function getFrameworksBuildTarget(purpose, validOptions) {
183
183
  }
184
184
  return frameworksBuild;
185
185
  }
186
+ else if (purpose === "deploy") {
187
+ return "production";
188
+ }
186
189
  else if (process.env.NODE_ENV) {
187
190
  switch (process.env.NODE_ENV) {
188
191
  case "development":
@@ -194,7 +197,7 @@ function getFrameworksBuildTarget(purpose, validOptions) {
194
197
  throw new error_1.FirebaseError(`We cannot infer your build target from a non-standard NODE_ENV. Please set the FIREBASE_FRAMEWORKS_BUILD_TARGET environment variable. Valid values are: ${validOptions.join(", ")}`);
195
198
  }
196
199
  }
197
- else if (purpose !== "serve") {
200
+ else if (purpose === "test") {
198
201
  return "production";
199
202
  }
200
203
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "firebase-tools",
3
- "version": "12.2.0",
3
+ "version": "12.2.1",
4
4
  "description": "Command-Line Interface for Firebase",
5
5
  "main": "./lib/index.js",
6
6
  "bin": {
@@ -1,4 +1,8 @@
1
1
  rules_version = '2';
2
+
3
+ // Craft rules based on data in your Firestore database
4
+ // allow write: if firestore.get(
5
+ // /databases/(default)/documents/users/$(request.auth.uid)).data.isAdmin;
2
6
  service firebase.storage {
3
7
  match /b/{bucket}/o {
4
8
  match /{allPaths=**} {