firebase-tools 12.4.3 → 12.4.4
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.
- package/lib/apiv2.js +1 -0
- package/lib/commands/database-instances-list.js +23 -46
- package/lib/deploy/functions/prepare.js +1 -1
- package/lib/emulator/functionsRuntimeWorker.js +6 -2
- package/lib/functionsShellCommandAction.js +3 -3
- package/lib/localFunction.js +183 -170
- package/lib/requireAuth.js +9 -0
- package/package.json +2 -2
- package/standalone/package.json +1 -1
- package/lib/gcp/firedata.js +0 -27
package/lib/apiv2.js
CHANGED
|
@@ -233,6 +233,7 @@ class Client {
|
|
|
233
233
|
}
|
|
234
234
|
catch (thrown) {
|
|
235
235
|
const err = thrown instanceof Error ? thrown : new Error(thrown);
|
|
236
|
+
logger_1.logger.debug(`*** [apiv2] error from fetch(${fetchURL}, ${JSON.stringify(fetchOptions)}): ${err}`);
|
|
236
237
|
const isAbortError = err.name.includes("AbortError");
|
|
237
238
|
if (isAbortError) {
|
|
238
239
|
throw new error_1.FirebaseError(`Timeout reached making request to ${fetchURL}`, {
|
|
@@ -1,76 +1,53 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.command = void 0;
|
|
4
|
-
const command_1 = require("../command");
|
|
5
4
|
const Table = require("cli-table");
|
|
5
|
+
const command_1 = require("../command");
|
|
6
6
|
const clc = require("colorette");
|
|
7
7
|
const ora = require("ora");
|
|
8
8
|
const logger_1 = require("../logger");
|
|
9
9
|
const requirePermissions_1 = require("../requirePermissions");
|
|
10
|
-
const projectUtils_1 = require("../projectUtils");
|
|
11
|
-
const firedata = require("../gcp/firedata");
|
|
12
10
|
const types_1 = require("../emulator/types");
|
|
13
11
|
const commandUtils_1 = require("../emulator/commandUtils");
|
|
14
12
|
const experiments = require("../experiments");
|
|
15
|
-
const
|
|
13
|
+
const projectUtils_1 = require("../projectUtils");
|
|
16
14
|
const database_1 = require("../management/database");
|
|
17
|
-
function logInstances(instances) {
|
|
18
|
-
if (instances.length === 0) {
|
|
19
|
-
logger_1.logger.info(clc.bold("No database instances found."));
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
const tableHead = ["Database Instance Name", "Location", "Type", "State"];
|
|
23
|
-
const table = new Table({ head: tableHead, style: { head: ["green"] } });
|
|
24
|
-
instances.forEach((db) => {
|
|
25
|
-
table.push([db.name, db.location, db.type, db.state]);
|
|
26
|
-
});
|
|
27
|
-
logger_1.logger.info(table.toString());
|
|
28
|
-
}
|
|
29
|
-
function logInstancesCount(count = 0) {
|
|
30
|
-
if (count === 0) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
logger_1.logger.info("");
|
|
34
|
-
logger_1.logger.info(`${count} database instance(s) total.`);
|
|
35
|
-
}
|
|
36
15
|
exports.command = new command_1.Command("database:instances:list")
|
|
37
16
|
.description("list realtime database instances, optionally filtered by a specified location")
|
|
38
17
|
.before(requirePermissions_1.requirePermissions, ["firebasedatabase.instances.list"])
|
|
18
|
+
.option("-l, --location <location>", "(optional) location for the database instance, defaults to all regions")
|
|
39
19
|
.before(commandUtils_1.warnEmulatorNotSupported, types_1.Emulators.DATABASE)
|
|
40
20
|
.action(async (options) => {
|
|
41
21
|
const location = (0, database_1.parseDatabaseLocation)(options.location, database_1.DatabaseLocation.ANY);
|
|
42
22
|
const spinner = ora("Preparing the list of your Firebase Realtime Database instances" +
|
|
43
23
|
`${location === database_1.DatabaseLocation.ANY ? "" : ` for location: ${location}`}`).start();
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const projectId = (0, projectUtils_2.needProjectId)(options);
|
|
47
|
-
try {
|
|
48
|
-
instances = await (0, database_1.listDatabaseInstances)(projectId, location);
|
|
49
|
-
}
|
|
50
|
-
catch (err) {
|
|
51
|
-
spinner.fail();
|
|
52
|
-
throw err;
|
|
53
|
-
}
|
|
54
|
-
spinner.succeed();
|
|
55
|
-
logInstances(instances);
|
|
56
|
-
logInstancesCount(instances.length);
|
|
57
|
-
return instances;
|
|
58
|
-
}
|
|
59
|
-
const projectNumber = await (0, projectUtils_1.needProjectNumber)(options);
|
|
24
|
+
const projectId = (0, projectUtils_1.needProjectId)(options);
|
|
25
|
+
let instances = [];
|
|
60
26
|
try {
|
|
61
|
-
instances = await
|
|
27
|
+
instances = await (0, database_1.listDatabaseInstances)(projectId, location);
|
|
62
28
|
}
|
|
63
29
|
catch (err) {
|
|
64
30
|
spinner.fail();
|
|
65
31
|
throw err;
|
|
66
32
|
}
|
|
67
33
|
spinner.succeed();
|
|
68
|
-
|
|
69
|
-
logger_1.logger.info(
|
|
34
|
+
if (instances.length === 0) {
|
|
35
|
+
logger_1.logger.info(clc.bold("No database instances found."));
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (!experiments.isEnabled("rtdbmanagement")) {
|
|
39
|
+
for (const instance of instances) {
|
|
40
|
+
logger_1.logger.info(instance.name);
|
|
41
|
+
}
|
|
42
|
+
logger_1.logger.info(`Project ${options.project} has ${instances.length} database instances`);
|
|
43
|
+
return instances;
|
|
70
44
|
}
|
|
71
|
-
|
|
45
|
+
const tableHead = ["Database Instance Name", "Location", "Type", "State"];
|
|
46
|
+
const table = new Table({ head: tableHead, style: { head: ["green"] } });
|
|
47
|
+
for (const db of instances) {
|
|
48
|
+
table.push([db.name, db.location, db.type, db.state]);
|
|
49
|
+
}
|
|
50
|
+
logger_1.logger.info(table.toString());
|
|
51
|
+
logger_1.logger.info(`${instances.length} database instance(s) total.`);
|
|
72
52
|
return instances;
|
|
73
53
|
});
|
|
74
|
-
if (experiments.isEnabled("rtdbmanagement")) {
|
|
75
|
-
exports.command = exports.command.option("-l, --location <location>", "(optional) location for the database instance, defaults to us-central1");
|
|
76
|
-
}
|
|
@@ -295,7 +295,7 @@ async function loadCodebases(config, options, firebaseConfig, runtimeConfig, fil
|
|
|
295
295
|
logger_1.logger.debug(`Building ${runtimeDelegate.name} source`);
|
|
296
296
|
await runtimeDelegate.build();
|
|
297
297
|
const firebaseEnvs = functionsEnv.loadFirebaseEnvs(firebaseConfig, projectId);
|
|
298
|
-
(0, utils_1.logLabeledBullet)("functions", `Loading and
|
|
298
|
+
(0, utils_1.logLabeledBullet)("functions", `Loading and analyzing source code for codebase ${codebase} to determine what to deploy`);
|
|
299
299
|
wantBuilds[codebase] = await runtimeDelegate.discoverBuild(runtimeConfig, Object.assign(Object.assign({}, firebaseEnvs), { GOOGLE_CLOUD_QUOTA_PROJECT: projectId }));
|
|
300
300
|
wantBuilds[codebase].runtime = codebaseConfig.runtime;
|
|
301
301
|
}
|
|
@@ -84,7 +84,7 @@ class RuntimeWorker {
|
|
|
84
84
|
});
|
|
85
85
|
});
|
|
86
86
|
}
|
|
87
|
-
request(req, resp, body) {
|
|
87
|
+
request(req, resp, body, debug) {
|
|
88
88
|
if (this.triggerKey !== FREE_WORKER_KEY) {
|
|
89
89
|
this.logInfo(`Beginning execution of "${this.triggerKey}"`);
|
|
90
90
|
}
|
|
@@ -124,6 +124,10 @@ class RuntimeWorker {
|
|
|
124
124
|
const piped = _resp.pipe(resp);
|
|
125
125
|
piped.on("finish", () => finishReq("finish"));
|
|
126
126
|
});
|
|
127
|
+
if (debug) {
|
|
128
|
+
proxy.setSocketKeepAlive(false);
|
|
129
|
+
proxy.setTimeout(0);
|
|
130
|
+
}
|
|
127
131
|
proxy.on("timeout", () => {
|
|
128
132
|
this.logger.log("ERROR", `Your function timed out after ~${this.timeoutSeconds}s. To configure this timeout, see
|
|
129
133
|
https://firebase.google.com/docs/functions/manage-functions#set_timeout_and_memory_allocation.`);
|
|
@@ -260,7 +264,7 @@ class RuntimeWorkerPool {
|
|
|
260
264
|
if (debug) {
|
|
261
265
|
await worker.sendDebugMsg(debug);
|
|
262
266
|
}
|
|
263
|
-
return worker.request(req, resp, body);
|
|
267
|
+
return worker.request(req, resp, body, !!debug);
|
|
264
268
|
}
|
|
265
269
|
getIdleWorker(triggerId) {
|
|
266
270
|
this.cleanUpWorkers();
|
|
@@ -7,7 +7,7 @@ const _ = require("lodash");
|
|
|
7
7
|
const request = require("request");
|
|
8
8
|
const util = require("util");
|
|
9
9
|
const functions_1 = require("./serve/functions");
|
|
10
|
-
const
|
|
10
|
+
const localFunction_1 = require("./localFunction");
|
|
11
11
|
const utils = require("./utils");
|
|
12
12
|
const logger_1 = require("./logger");
|
|
13
13
|
const shell = require("./emulator/functionsEmulatorShell");
|
|
@@ -73,9 +73,9 @@ const actionFunction = async (options) => {
|
|
|
73
73
|
const initializeContext = (context) => {
|
|
74
74
|
for (const trigger of emulator.triggers) {
|
|
75
75
|
if (emulator.emulatedFunctions.includes(trigger.id)) {
|
|
76
|
-
const localFunction = new
|
|
76
|
+
const localFunction = new localFunction_1.default(trigger, emulator.urls, emulator);
|
|
77
77
|
const triggerNameDotNotation = trigger.name.replace(/-/g, ".");
|
|
78
|
-
_.set(context, triggerNameDotNotation, localFunction.
|
|
78
|
+
_.set(context, triggerNameDotNotation, localFunction.makeFn());
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
context.help =
|
package/lib/localFunction.js
CHANGED
|
@@ -1,191 +1,204 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
this.controller = controller;
|
|
13
|
-
this.url = _.get(urls, this.id);
|
|
14
|
-
if (this.httpsTrigger) {
|
|
15
|
-
if (isCallable == "true") {
|
|
16
|
-
this.call = this._constructCallableFunc.bind(this);
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
this.call = request.defaults({
|
|
20
|
-
callback: this._requestCallBack,
|
|
21
|
-
baseUrl: this.url,
|
|
22
|
-
uri: "",
|
|
23
|
-
});
|
|
24
|
-
}
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const request = require("request");
|
|
4
|
+
const utils = require("./utils");
|
|
5
|
+
const encodeFirestoreValue_1 = require("./firestore/encodeFirestoreValue");
|
|
6
|
+
class LocalFunction {
|
|
7
|
+
constructor(trigger, urls, controller) {
|
|
8
|
+
this.trigger = trigger;
|
|
9
|
+
this.controller = controller;
|
|
10
|
+
this.paramWildcardRegex = new RegExp("{[^/{}]*}", "g");
|
|
11
|
+
this.url = urls[trigger.id];
|
|
25
12
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
};
|
|
36
|
-
LocalFunction.prototype._substituteParams = function (resource, params) {
|
|
37
|
-
var wildcardRegex = new RegExp("{[^/{}]*}", "g");
|
|
38
|
-
return resource.replace(wildcardRegex, function (wildcard) {
|
|
39
|
-
var wildcardNoBraces = wildcard.slice(1, -1);
|
|
40
|
-
var sub = _.get(params, wildcardNoBraces);
|
|
41
|
-
return sub || wildcardNoBraces + utils.randomInt(1, 9);
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
LocalFunction.prototype._constructCallableFunc = function (data, opts) {
|
|
45
|
-
opts = opts || {};
|
|
46
|
-
var headers = {};
|
|
47
|
-
if (opts.instanceIdToken) {
|
|
48
|
-
headers["Firebase-Instance-ID-Token"] = opts.instanceIdToken;
|
|
13
|
+
substituteParams(resource, params) {
|
|
14
|
+
if (!params) {
|
|
15
|
+
return resource;
|
|
16
|
+
}
|
|
17
|
+
return resource.replace(this.paramWildcardRegex, (wildcard) => {
|
|
18
|
+
const wildcardNoBraces = wildcard.slice(1, -1);
|
|
19
|
+
const sub = params === null || params === void 0 ? void 0 : params[wildcardNoBraces];
|
|
20
|
+
return sub || `${wildcardNoBraces}${utils.randomInt(1, 9)}`;
|
|
21
|
+
});
|
|
49
22
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
23
|
+
constructCallableFunc(data, opts) {
|
|
24
|
+
opts = opts || {};
|
|
25
|
+
const headers = {};
|
|
26
|
+
if (opts.instanceIdToken) {
|
|
27
|
+
headers["Firebase-Instance-ID-Token"] = opts.instanceIdToken;
|
|
28
|
+
}
|
|
29
|
+
return request.post({
|
|
30
|
+
callback: (...args) => this.requestCallBack(...args),
|
|
31
|
+
baseUrl: this.url,
|
|
32
|
+
uri: "",
|
|
33
|
+
body: { data },
|
|
34
|
+
json: true,
|
|
35
|
+
headers: headers,
|
|
36
|
+
});
|
|
62
37
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
},
|
|
71
|
-
};
|
|
72
|
-
case "ADMIN":
|
|
73
|
-
if (_.get(auth, "uid") || _.get(auth, "token")) {
|
|
74
|
-
throw new Error("authType and auth are incompatible.");
|
|
75
|
-
}
|
|
76
|
-
return { admin: true };
|
|
77
|
-
case "UNAUTHENTICATED":
|
|
78
|
-
if (_.get(auth, "uid") || _.get(auth, "token")) {
|
|
79
|
-
throw new Error("authType and auth are incompatible.");
|
|
80
|
-
}
|
|
81
|
-
return { admin: false };
|
|
82
|
-
default:
|
|
83
|
-
throw new Error("Unrecognized authType, valid values are: " + "ADMIN, USER, and UNAUTHENTICATED");
|
|
38
|
+
constructAuth(auth, authType) {
|
|
39
|
+
var _a, _b, _c;
|
|
40
|
+
if ((auth === null || auth === void 0 ? void 0 : auth.admin) || (auth === null || auth === void 0 ? void 0 : auth.variable)) {
|
|
41
|
+
return {
|
|
42
|
+
admin: auth.admin || false,
|
|
43
|
+
variable: auth.variable,
|
|
44
|
+
};
|
|
84
45
|
}
|
|
46
|
+
if (authType) {
|
|
47
|
+
switch (authType) {
|
|
48
|
+
case "USER":
|
|
49
|
+
return {
|
|
50
|
+
admin: false,
|
|
51
|
+
variable: {
|
|
52
|
+
uid: (_a = auth === null || auth === void 0 ? void 0 : auth.uid) !== null && _a !== void 0 ? _a : "",
|
|
53
|
+
token: (_b = auth === null || auth === void 0 ? void 0 : auth.token) !== null && _b !== void 0 ? _b : {},
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
case "ADMIN":
|
|
57
|
+
if ((auth === null || auth === void 0 ? void 0 : auth.uid) || (auth === null || auth === void 0 ? void 0 : auth.token)) {
|
|
58
|
+
throw new Error("authType and auth are incompatible.");
|
|
59
|
+
}
|
|
60
|
+
return { admin: true };
|
|
61
|
+
case "UNAUTHENTICATED":
|
|
62
|
+
if ((auth === null || auth === void 0 ? void 0 : auth.uid) || (auth === null || auth === void 0 ? void 0 : auth.token)) {
|
|
63
|
+
throw new Error("authType and auth are incompatible.");
|
|
64
|
+
}
|
|
65
|
+
return { admin: false };
|
|
66
|
+
default:
|
|
67
|
+
throw new Error("Unrecognized authType, valid values are: " + "ADMIN, USER, and UNAUTHENTICATED");
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (auth) {
|
|
71
|
+
return {
|
|
72
|
+
admin: false,
|
|
73
|
+
variable: {
|
|
74
|
+
uid: (_c = auth.uid) !== null && _c !== void 0 ? _c : "",
|
|
75
|
+
token: auth.token || {},
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
return { admin: true };
|
|
85
80
|
}
|
|
86
|
-
|
|
81
|
+
makeFirestoreValue(input) {
|
|
82
|
+
if (typeof input === "undefined" ||
|
|
83
|
+
input === null ||
|
|
84
|
+
(typeof input === "object" && Object.keys(input).length === 0)) {
|
|
85
|
+
return {};
|
|
86
|
+
}
|
|
87
|
+
if (typeof input !== "object") {
|
|
88
|
+
throw new Error("Firestore data must be key-value pairs.");
|
|
89
|
+
}
|
|
90
|
+
const currentTime = new Date().toISOString();
|
|
87
91
|
return {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
},
|
|
92
|
+
fields: (0, encodeFirestoreValue_1.encodeFirestoreValue)(input),
|
|
93
|
+
createTime: currentTime,
|
|
94
|
+
updateTime: currentTime,
|
|
92
95
|
};
|
|
93
96
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if (typeof input === "undefined" || _.isEmpty(input)) {
|
|
98
|
-
return {};
|
|
99
|
-
}
|
|
100
|
-
if (typeof input !== "object") {
|
|
101
|
-
throw new Error("Firestore data must be key-value pairs.");
|
|
102
|
-
}
|
|
103
|
-
var currentTime = new Date().toISOString();
|
|
104
|
-
return {
|
|
105
|
-
fields: encodeFirestoreValue(input),
|
|
106
|
-
createTime: currentTime,
|
|
107
|
-
updateTime: currentTime,
|
|
108
|
-
};
|
|
109
|
-
};
|
|
110
|
-
LocalFunction.prototype._requestCallBack = function (err, response, body) {
|
|
111
|
-
if (err) {
|
|
112
|
-
return console.warn("\nERROR SENDING REQUEST: " + err);
|
|
113
|
-
}
|
|
114
|
-
var status = response ? response.statusCode + ", " : "";
|
|
115
|
-
var bodyString = body;
|
|
116
|
-
if (typeof body === "string") {
|
|
117
|
-
try {
|
|
118
|
-
bodyString = JSON.stringify(JSON.parse(bodyString), null, 2);
|
|
97
|
+
requestCallBack(err, response, body) {
|
|
98
|
+
if (err) {
|
|
99
|
+
return console.warn("\nERROR SENDING REQUEST: " + err);
|
|
119
100
|
}
|
|
120
|
-
|
|
101
|
+
const status = response ? response.statusCode + ", " : "";
|
|
102
|
+
let bodyString = body;
|
|
103
|
+
if (typeof bodyString === "string") {
|
|
104
|
+
try {
|
|
105
|
+
bodyString = JSON.stringify(JSON.parse(bodyString), null, 2);
|
|
106
|
+
}
|
|
107
|
+
catch (e) {
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
bodyString = JSON.stringify(body, null, 2);
|
|
121
112
|
}
|
|
113
|
+
return console.log("\nRESPONSE RECEIVED FROM FUNCTION: " + status + bodyString);
|
|
122
114
|
}
|
|
123
|
-
|
|
124
|
-
|
|
115
|
+
isDatabaseFn(eventTrigger) {
|
|
116
|
+
return utils.getFunctionsEventProvider(eventTrigger.eventType) === "Database";
|
|
125
117
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
LocalFunction.prototype._call = function (data, opts) {
|
|
129
|
-
opts = opts || {};
|
|
130
|
-
var operationType;
|
|
131
|
-
var dataPayload;
|
|
132
|
-
if (this.httpsTrigger) {
|
|
133
|
-
this.controller.call(this.name, data || {});
|
|
118
|
+
isFirestoreFunc(eventTrigger) {
|
|
119
|
+
return utils.getFunctionsEventProvider(eventTrigger.eventType) === "Firestore";
|
|
134
120
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
121
|
+
triggerEvent(data, opts) {
|
|
122
|
+
opts = opts || {};
|
|
123
|
+
let operationType;
|
|
124
|
+
let dataPayload;
|
|
125
|
+
if (this.trigger.httpsTrigger) {
|
|
126
|
+
this.controller.call(this.trigger.name, data || {}, opts);
|
|
127
|
+
}
|
|
128
|
+
else if (this.trigger.eventTrigger) {
|
|
129
|
+
if (this.isDatabaseFn(this.trigger.eventTrigger)) {
|
|
130
|
+
operationType = utils.last(this.trigger.eventTrigger.eventType.split("."));
|
|
131
|
+
switch (operationType) {
|
|
132
|
+
case "create":
|
|
133
|
+
dataPayload = {
|
|
134
|
+
data: null,
|
|
135
|
+
delta: data,
|
|
136
|
+
};
|
|
137
|
+
break;
|
|
138
|
+
case "delete":
|
|
139
|
+
dataPayload = {
|
|
140
|
+
data: data,
|
|
141
|
+
delta: null,
|
|
142
|
+
};
|
|
143
|
+
break;
|
|
144
|
+
default:
|
|
145
|
+
dataPayload = {
|
|
146
|
+
data: data.before,
|
|
147
|
+
delta: data.after,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
opts.resource = this.substituteParams(this.trigger.eventTrigger.resource, opts.params);
|
|
151
|
+
opts.auth = this.constructAuth(opts.auth, opts.authType);
|
|
152
|
+
this.controller.call(this.trigger.name, dataPayload, opts);
|
|
153
|
+
}
|
|
154
|
+
else if (this.isFirestoreFunc(this.trigger.eventTrigger)) {
|
|
155
|
+
operationType = utils.last(this.trigger.eventTrigger.eventType.split("."));
|
|
156
|
+
switch (operationType) {
|
|
157
|
+
case "create":
|
|
158
|
+
dataPayload = {
|
|
159
|
+
value: this.makeFirestoreValue(data),
|
|
160
|
+
oldValue: {},
|
|
161
|
+
};
|
|
162
|
+
break;
|
|
163
|
+
case "delete":
|
|
164
|
+
dataPayload = {
|
|
165
|
+
value: {},
|
|
166
|
+
oldValue: this.makeFirestoreValue(data),
|
|
167
|
+
};
|
|
168
|
+
break;
|
|
169
|
+
default:
|
|
170
|
+
dataPayload = {
|
|
171
|
+
value: this.makeFirestoreValue(data.after),
|
|
172
|
+
oldValue: this.makeFirestoreValue(data.before),
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
opts.resource = this.substituteParams(this.trigger.eventTrigger.resource, opts.params);
|
|
176
|
+
this.controller.call(this.trigger.name, dataPayload, opts);
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
this.controller.call(this.trigger.name, data || {}, opts);
|
|
156
180
|
}
|
|
157
|
-
opts.resource = this._substituteParams(this.eventTrigger.resource, opts.params);
|
|
158
|
-
opts.auth = this._constructAuth(opts.auth, opts.authType);
|
|
159
|
-
this.controller.call(this.name, dataPayload, opts);
|
|
160
181
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
default:
|
|
177
|
-
dataPayload = {
|
|
178
|
-
value: this._makeFirestoreValue(data.after),
|
|
179
|
-
oldValue: this._makeFirestoreValue(data.before),
|
|
180
|
-
};
|
|
182
|
+
return console.log("Successfully invoked function.");
|
|
183
|
+
}
|
|
184
|
+
makeFn() {
|
|
185
|
+
var _a;
|
|
186
|
+
if (this.trigger.httpsTrigger) {
|
|
187
|
+
const isCallable = !!((_a = this.trigger.labels) === null || _a === void 0 ? void 0 : _a["deployment-callable"]);
|
|
188
|
+
if (isCallable) {
|
|
189
|
+
return (data, opt) => this.constructCallableFunc(data, opt);
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
return request.defaults({
|
|
193
|
+
callback: (...args) => this.requestCallBack(...args),
|
|
194
|
+
baseUrl: this.url,
|
|
195
|
+
uri: "",
|
|
196
|
+
});
|
|
181
197
|
}
|
|
182
|
-
opts.resource = this._substituteParams(this.eventTrigger.resource, opts.params);
|
|
183
|
-
this.controller.call(this.name, dataPayload, opts);
|
|
184
198
|
}
|
|
185
199
|
else {
|
|
186
|
-
|
|
200
|
+
return (data, opt) => this.triggerEvent(data, opt);
|
|
187
201
|
}
|
|
188
202
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
module.exports = LocalFunction;
|
|
203
|
+
}
|
|
204
|
+
exports.default = LocalFunction;
|
package/lib/requireAuth.js
CHANGED
|
@@ -24,6 +24,14 @@ async function autoAuth(options, authScopes) {
|
|
|
24
24
|
const client = getAuthClient({ scopes: authScopes, projectId: options.project });
|
|
25
25
|
const token = await client.getAccessToken();
|
|
26
26
|
token !== null ? apiv2.setAccessToken(token) : false;
|
|
27
|
+
let clientEmail;
|
|
28
|
+
try {
|
|
29
|
+
const credentials = await client.getCredentials();
|
|
30
|
+
clientEmail = credentials.client_email;
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
logger_1.logger.debug(`Error getting account credentials.`);
|
|
34
|
+
}
|
|
27
35
|
if (!options.isVSCE && (0, monospace_1.isMonospaceEnv)()) {
|
|
28
36
|
await (0, monospace_1.selectProjectInMonospace)({
|
|
29
37
|
projectRoot: options.config.projectDir,
|
|
@@ -31,6 +39,7 @@ async function autoAuth(options, authScopes) {
|
|
|
31
39
|
isVSCE: options.isVSCE,
|
|
32
40
|
});
|
|
33
41
|
}
|
|
42
|
+
return clientEmail;
|
|
34
43
|
}
|
|
35
44
|
async function requireAuth(options) {
|
|
36
45
|
api.setScopes([scopes.CLOUD_PLATFORM, scopes.FIREBASE_PLATFORM]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "firebase-tools",
|
|
3
|
-
"version": "12.4.
|
|
3
|
+
"version": "12.4.4",
|
|
4
4
|
"description": "Command-Line Interface for Firebase",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -103,7 +103,7 @@
|
|
|
103
103
|
"request": "^2.87.0",
|
|
104
104
|
"retry": "^0.13.1",
|
|
105
105
|
"rimraf": "^3.0.0",
|
|
106
|
-
"semver": "^5.
|
|
106
|
+
"semver": "^7.5.2",
|
|
107
107
|
"stream-chain": "^2.2.4",
|
|
108
108
|
"stream-json": "^1.7.3",
|
|
109
109
|
"strip-ansi": "^6.0.1",
|
package/standalone/package.json
CHANGED
package/lib/gcp/firedata.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.listDatabaseInstances = void 0;
|
|
4
|
-
const api_1 = require("../api");
|
|
5
|
-
const apiv2_1 = require("../apiv2");
|
|
6
|
-
const logger_1 = require("../logger");
|
|
7
|
-
const utils = require("../utils");
|
|
8
|
-
function _handleErrorResponse(response) {
|
|
9
|
-
if (response.body && response.body.error) {
|
|
10
|
-
return utils.reject(response.body.error, { code: 2 });
|
|
11
|
-
}
|
|
12
|
-
logger_1.logger.debug("[firedata] error:", response.status, response.body);
|
|
13
|
-
return utils.reject("Unexpected error encountered with FireData.", {
|
|
14
|
-
code: 2,
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
async function listDatabaseInstances(projectNumber) {
|
|
18
|
-
const client = new apiv2_1.Client({ urlPrefix: api_1.firedataOrigin, apiVersion: "v1" });
|
|
19
|
-
const response = await client.get(`/projects/${projectNumber}/databases`, {
|
|
20
|
-
resolveOnHTTPError: true,
|
|
21
|
-
});
|
|
22
|
-
if (response.status === 200) {
|
|
23
|
-
return response.body.instance;
|
|
24
|
-
}
|
|
25
|
-
return _handleErrorResponse(response);
|
|
26
|
-
}
|
|
27
|
-
exports.listDatabaseInstances = listDatabaseInstances;
|