firebase-functions 6.6.0 → 7.0.0-rc.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.
- package/lib/_virtual/rolldown_runtime.js +34 -0
- package/lib/bin/firebase-functions.js +78 -103
- package/lib/common/app.js +35 -55
- package/lib/common/change.js +54 -75
- package/lib/common/config.js +41 -41
- package/lib/common/debug.js +23 -47
- package/lib/common/encoding.js +59 -82
- package/lib/common/onInit.js +26 -28
- package/lib/common/options.js +22 -42
- package/lib/common/params.d.ts +6 -6
- package/lib/common/params.js +0 -23
- package/lib/common/providers/database.js +270 -300
- package/lib/common/providers/firestore.js +66 -92
- package/lib/common/providers/https.d.ts +0 -1
- package/lib/common/providers/https.js +537 -539
- package/lib/common/providers/identity.js +393 -444
- package/lib/common/providers/tasks.js +64 -98
- package/lib/common/timezone.js +544 -542
- package/lib/common/trace.d.ts +0 -1
- package/lib/common/trace.js +63 -55
- package/lib/common/utilities/assertions.d.ts +11 -0
- package/lib/common/utilities/assertions.js +18 -0
- package/lib/common/utilities/encoder.js +20 -37
- package/lib/common/utilities/path-pattern.js +106 -132
- package/lib/common/utilities/path.js +28 -27
- package/lib/common/utilities/utils.js +23 -45
- package/lib/esm/_virtual/rolldown_runtime.mjs +16 -0
- package/lib/esm/bin/firebase-functions.mjs +91 -0
- package/lib/esm/common/app.mjs +39 -0
- package/lib/esm/common/change.mjs +57 -0
- package/lib/esm/common/config.mjs +45 -0
- package/lib/esm/common/debug.mjs +28 -0
- package/lib/esm/common/encoding.mjs +69 -0
- package/lib/esm/common/onInit.mjs +33 -0
- package/lib/esm/common/options.mjs +22 -0
- package/lib/esm/common/params.mjs +1 -0
- package/lib/esm/common/providers/database.mjs +269 -0
- package/lib/esm/common/providers/firestore.mjs +78 -0
- package/lib/esm/common/providers/https.mjs +573 -0
- package/lib/esm/common/providers/identity.mjs +428 -0
- package/lib/esm/common/providers/tasks.mjs +67 -0
- package/lib/esm/common/timezone.mjs +544 -0
- package/lib/esm/common/trace.mjs +73 -0
- package/lib/esm/common/utilities/assertions.mjs +17 -0
- package/lib/esm/common/utilities/encoder.mjs +21 -0
- package/lib/esm/common/utilities/path-pattern.mjs +116 -0
- package/lib/esm/common/utilities/path.mjs +35 -0
- package/lib/esm/common/utilities/utils.mjs +29 -0
- package/lib/esm/function-configuration.mjs +1 -0
- package/lib/esm/logger/common.mjs +23 -0
- package/lib/esm/logger/compat.mjs +25 -0
- package/lib/esm/logger/index.mjs +131 -0
- package/lib/esm/params/index.mjs +160 -0
- package/lib/esm/params/types.mjs +400 -0
- package/lib/esm/runtime/loader.mjs +132 -0
- package/lib/esm/runtime/manifest.mjs +134 -0
- package/lib/esm/types/global.d.mjs +1 -0
- package/lib/esm/v1/cloud-functions.mjs +206 -0
- package/lib/esm/v1/config.mjs +14 -0
- package/lib/esm/v1/function-builder.mjs +252 -0
- package/lib/esm/v1/function-configuration.mjs +72 -0
- package/lib/esm/v1/index.mjs +27 -0
- package/lib/esm/v1/providers/analytics.mjs +212 -0
- package/lib/esm/v1/providers/auth.mjs +156 -0
- package/lib/esm/v1/providers/database.mjs +243 -0
- package/lib/esm/v1/providers/firestore.mjs +131 -0
- package/lib/esm/v1/providers/https.mjs +82 -0
- package/lib/esm/v1/providers/pubsub.mjs +175 -0
- package/lib/esm/v1/providers/remoteConfig.mjs +64 -0
- package/lib/esm/v1/providers/storage.mjs +163 -0
- package/lib/esm/v1/providers/tasks.mjs +63 -0
- package/lib/esm/v1/providers/testLab.mjs +94 -0
- package/lib/esm/v2/core.mjs +4 -0
- package/lib/esm/v2/index.mjs +28 -0
- package/lib/esm/v2/options.mjs +102 -0
- package/lib/esm/v2/providers/alerts/alerts.mjs +85 -0
- package/lib/esm/v2/providers/alerts/appDistribution.mjs +75 -0
- package/lib/esm/v2/providers/alerts/billing.mjs +51 -0
- package/lib/esm/v2/providers/alerts/crashlytics.mjs +122 -0
- package/lib/esm/v2/providers/alerts/index.mjs +22 -0
- package/lib/esm/v2/providers/alerts/performance.mjs +66 -0
- package/lib/esm/v2/providers/database.mjs +197 -0
- package/lib/esm/v2/providers/dataconnect.mjs +130 -0
- package/lib/esm/v2/providers/eventarc.mjs +51 -0
- package/lib/esm/v2/providers/firestore.mjs +294 -0
- package/lib/esm/v2/providers/https.mjs +210 -0
- package/lib/esm/v2/providers/identity.mjs +103 -0
- package/lib/esm/v2/providers/pubsub.mjs +148 -0
- package/lib/esm/v2/providers/remoteConfig.mjs +52 -0
- package/lib/esm/v2/providers/scheduler.mjs +84 -0
- package/lib/esm/v2/providers/storage.mjs +155 -0
- package/lib/esm/v2/providers/tasks.mjs +65 -0
- package/lib/esm/v2/providers/testLab.mjs +53 -0
- package/lib/esm/v2/trace.mjs +20 -0
- package/lib/function-configuration.d.ts +0 -0
- package/lib/function-configuration.js +0 -0
- package/lib/logger/common.js +21 -41
- package/lib/logger/compat.js +18 -33
- package/lib/logger/index.js +119 -130
- package/lib/params/index.d.ts +4 -2
- package/lib/params/index.js +150 -144
- package/lib/params/types.js +389 -423
- package/lib/runtime/loader.js +114 -148
- package/lib/runtime/manifest.js +106 -126
- package/lib/types/global.d.js +0 -0
- package/lib/v1/cloud-functions.d.ts +2 -2
- package/lib/v1/cloud-functions.js +193 -241
- package/lib/v1/config.d.ts +4 -7
- package/lib/v1/config.js +13 -75
- package/lib/v1/function-builder.js +239 -368
- package/lib/v1/function-configuration.js +70 -63
- package/lib/v1/index.js +118 -73
- package/lib/v1/providers/analytics.js +188 -235
- package/lib/v1/providers/auth.d.ts +2 -1
- package/lib/v1/providers/auth.js +159 -164
- package/lib/v1/providers/database.js +237 -242
- package/lib/v1/providers/firestore.js +131 -130
- package/lib/v1/providers/https.d.ts +2 -1
- package/lib/v1/providers/https.js +79 -86
- package/lib/v1/providers/pubsub.js +175 -172
- package/lib/v1/providers/remoteConfig.js +64 -68
- package/lib/v1/providers/storage.js +161 -163
- package/lib/v1/providers/tasks.d.ts +1 -1
- package/lib/v1/providers/tasks.js +65 -80
- package/lib/v1/providers/testLab.js +94 -94
- package/lib/v2/core.d.ts +1 -1
- package/lib/v2/core.js +5 -32
- package/lib/v2/index.d.ts +6 -3
- package/lib/v2/index.js +123 -75
- package/lib/v2/options.js +88 -114
- package/lib/v2/providers/alerts/alerts.js +76 -95
- package/lib/v2/providers/alerts/appDistribution.js +73 -78
- package/lib/v2/providers/alerts/billing.js +49 -53
- package/lib/v2/providers/alerts/crashlytics.js +110 -102
- package/lib/v2/providers/alerts/index.js +56 -53
- package/lib/v2/providers/alerts/performance.js +64 -74
- package/lib/v2/providers/database.js +177 -180
- package/lib/v2/providers/dataconnect.d.ts +95 -0
- package/lib/v2/providers/dataconnect.js +137 -0
- package/lib/v2/providers/eventarc.js +55 -77
- package/lib/v2/providers/firestore.js +262 -260
- package/lib/v2/providers/https.d.ts +3 -2
- package/lib/v2/providers/https.js +210 -247
- package/lib/v2/providers/identity.d.ts +2 -1
- package/lib/v2/providers/identity.js +96 -105
- package/lib/v2/providers/pubsub.js +149 -167
- package/lib/v2/providers/remoteConfig.js +54 -63
- package/lib/v2/providers/scheduler.js +84 -96
- package/lib/v2/providers/storage.js +147 -162
- package/lib/v2/providers/tasks.d.ts +1 -1
- package/lib/v2/providers/tasks.js +68 -95
- package/lib/v2/providers/testLab.js +55 -64
- package/lib/v2/trace.js +18 -19
- package/package.json +290 -226
- package/protos/compiledFirestore.mjs +3512 -0
- package/protos/update.sh +28 -7
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (all) => {
|
|
9
|
+
let target = {};
|
|
10
|
+
for (var name in all) __defProp(target, name, {
|
|
11
|
+
get: all[name],
|
|
12
|
+
enumerable: true
|
|
13
|
+
});
|
|
14
|
+
return target;
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
18
|
+
key = keys[i];
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
20
|
+
get: ((k) => from[k]).bind(null, key),
|
|
21
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
27
|
+
value: mod,
|
|
28
|
+
enumerable: true
|
|
29
|
+
}) : target, mod));
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
|
|
33
|
+
exports.__export = __export;
|
|
34
|
+
exports.__toESM = __toESM;
|
|
@@ -1,119 +1,94 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
//
|
|
14
|
-
// The above copyright notice and this permission notice shall be included in all
|
|
15
|
-
// copies or substantial portions of the Software.
|
|
16
|
-
//
|
|
17
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
-
// SOFTWARE.
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
const express = require("express");
|
|
26
|
-
const fs = require("fs/promises");
|
|
27
|
-
const path = require("path");
|
|
28
|
-
const loader_1 = require("../runtime/loader");
|
|
29
|
-
const manifest_1 = require("../runtime/manifest");
|
|
2
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.js');
|
|
3
|
+
const require_runtime_loader = require('../runtime/loader.js');
|
|
4
|
+
const require_runtime_manifest = require('../runtime/manifest.js');
|
|
5
|
+
let express = require("express");
|
|
6
|
+
express = require_rolldown_runtime.__toESM(express);
|
|
7
|
+
let fs_promises = require("fs/promises");
|
|
8
|
+
fs_promises = require_rolldown_runtime.__toESM(fs_promises);
|
|
9
|
+
let path = require("path");
|
|
10
|
+
path = require_rolldown_runtime.__toESM(path);
|
|
11
|
+
|
|
12
|
+
//#region src/bin/firebase-functions.ts
|
|
30
13
|
function printUsageAndExit() {
|
|
31
|
-
|
|
14
|
+
console.error(`
|
|
32
15
|
Usage: firebase-functions [functionsDir]
|
|
33
16
|
|
|
34
17
|
Arguments:
|
|
35
18
|
- functionsDir: Directory containing source code for Firebase Functions.
|
|
36
19
|
`);
|
|
37
|
-
|
|
20
|
+
process.exit(1);
|
|
38
21
|
}
|
|
39
22
|
let functionsDir = ".";
|
|
40
23
|
const args = process.argv.slice(2);
|
|
41
24
|
if (args.length > 1) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
25
|
+
if (args[0] === "-h" || args[0] === "--help") {
|
|
26
|
+
printUsageAndExit();
|
|
27
|
+
}
|
|
28
|
+
functionsDir = args[0];
|
|
46
29
|
}
|
|
47
30
|
function handleQuitquitquit(req, res, server) {
|
|
48
|
-
|
|
49
|
-
|
|
31
|
+
res.send("ok");
|
|
32
|
+
server.close();
|
|
50
33
|
}
|
|
51
34
|
if (process.env.FUNCTIONS_MANIFEST_OUTPUT_PATH) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
res.status(400).send(`Failed to generate manifest from function source: ${errorMessage}`);
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
let port = 8080;
|
|
114
|
-
if (process.env.PORT) {
|
|
115
|
-
port = Number.parseInt(process.env.PORT);
|
|
116
|
-
}
|
|
117
|
-
console.log("Serving at port", port);
|
|
118
|
-
server = app.listen(port);
|
|
35
|
+
void (async () => {
|
|
36
|
+
const outputPath = process.env.FUNCTIONS_MANIFEST_OUTPUT_PATH;
|
|
37
|
+
try {
|
|
38
|
+
const dir = path.dirname(outputPath);
|
|
39
|
+
try {
|
|
40
|
+
await fs_promises.default.access(dir, fs_promises.default.constants.W_OK);
|
|
41
|
+
} catch (e) {
|
|
42
|
+
console.error(`Error: Cannot write to directory '${dir}': ${e instanceof Error ? e.message : String(e)}`);
|
|
43
|
+
console.error("Please ensure the directory exists and you have write permissions.");
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
const stack = await require_runtime_loader.loadStack(functionsDir);
|
|
47
|
+
const wireFormat = require_runtime_manifest.stackToWire(stack);
|
|
48
|
+
await fs_promises.default.writeFile(outputPath, JSON.stringify(wireFormat, null, 2));
|
|
49
|
+
process.exit(0);
|
|
50
|
+
} catch (e) {
|
|
51
|
+
if (e.code === "ENOENT") {
|
|
52
|
+
console.error(`Error: Directory '${path.dirname(outputPath)}' does not exist.`);
|
|
53
|
+
console.error("Please create the directory or specify a valid path.");
|
|
54
|
+
} else if (e.code === "EACCES") {
|
|
55
|
+
console.error(`Error: Permission denied writing to '${outputPath}'.`);
|
|
56
|
+
console.error("Please check file permissions or choose a different location.");
|
|
57
|
+
} else if (e.message?.includes("Failed to generate manifest")) {
|
|
58
|
+
console.error(e.message);
|
|
59
|
+
} else {
|
|
60
|
+
console.error(`Failed to generate manifest from function source: ${e instanceof Error ? e.message : String(e)}`);
|
|
61
|
+
}
|
|
62
|
+
if (e instanceof Error && e.stack) {
|
|
63
|
+
console.error(e.stack);
|
|
64
|
+
}
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
67
|
+
})();
|
|
68
|
+
} else {
|
|
69
|
+
let server = undefined;
|
|
70
|
+
const app = (0, express.default)();
|
|
71
|
+
app.get("/__/quitquitquit", (req, res) => handleQuitquitquit(req, res, server));
|
|
72
|
+
app.post("/__/quitquitquit", (req, res) => handleQuitquitquit(req, res, server));
|
|
73
|
+
if (process.env.FUNCTIONS_CONTROL_API === "true") {
|
|
74
|
+
app.get("/__/functions.yaml", async (req, res) => {
|
|
75
|
+
try {
|
|
76
|
+
const stack = await require_runtime_loader.loadStack(functionsDir);
|
|
77
|
+
res.setHeader("content-type", "text/yaml");
|
|
78
|
+
res.send(JSON.stringify(require_runtime_manifest.stackToWire(stack)));
|
|
79
|
+
} catch (e) {
|
|
80
|
+
console.error(e);
|
|
81
|
+
const errorMessage = e instanceof Error ? e.message : String(e);
|
|
82
|
+
res.status(400).send(`Failed to generate manifest from function source: ${errorMessage}`);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
let port = 8080;
|
|
87
|
+
if (process.env.PORT) {
|
|
88
|
+
port = Number.parseInt(process.env.PORT);
|
|
89
|
+
}
|
|
90
|
+
console.log("Serving at port", port);
|
|
91
|
+
server = app.listen(port);
|
|
119
92
|
}
|
|
93
|
+
|
|
94
|
+
//#endregion
|
package/lib/common/app.js
CHANGED
|
@@ -1,62 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
// of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
// in the Software without restriction, including without limitation the rights
|
|
9
|
-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
// copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
// furnished to do so, subject to the following conditions:
|
|
12
|
-
//
|
|
13
|
-
// The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
// copies or substantial portions of the Software.
|
|
15
|
-
//
|
|
16
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
// SOFTWARE.
|
|
23
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.setApp = exports.getApp = void 0;
|
|
25
|
-
const app_1 = require("firebase-admin/app");
|
|
26
|
-
const config_1 = require("./config");
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.js');
|
|
2
|
+
const require_common_config = require('./config.js');
|
|
3
|
+
let firebase_admin_app = require("firebase-admin/app");
|
|
4
|
+
firebase_admin_app = require_rolldown_runtime.__toESM(firebase_admin_app);
|
|
5
|
+
|
|
6
|
+
//#region src/common/app.ts
|
|
27
7
|
const APP_NAME = "__FIREBASE_FUNCTIONS_SDK__";
|
|
28
8
|
let cache;
|
|
29
9
|
function getApp() {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
return cache;
|
|
10
|
+
if (typeof cache === "undefined") {
|
|
11
|
+
try {
|
|
12
|
+
cache = (0, firebase_admin_app.getApp)();
|
|
13
|
+
} catch {
|
|
14
|
+
cache = (0, firebase_admin_app.initializeApp)({
|
|
15
|
+
...require_common_config.firebaseConfig(),
|
|
16
|
+
credential: (0, firebase_admin_app.applicationDefault)()
|
|
17
|
+
}, APP_NAME);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return cache;
|
|
43
21
|
}
|
|
44
|
-
exports.getApp = getApp;
|
|
45
22
|
/**
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
23
|
+
* This function allows the Firebase Emulator Suite to override the FirebaseApp instance
|
|
24
|
+
* used by the Firebase Functions SDK. Developers should never call this function for
|
|
25
|
+
* other purposes.
|
|
26
|
+
* N.B. For clarity for use in testing this name has no mention of emulation, but
|
|
27
|
+
* it must be exported from index as app.setEmulatedAdminApp or we break the emulator.
|
|
28
|
+
* We can remove this export when:
|
|
29
|
+
* A) We complete the new emulator and no longer depend on monkeypatching
|
|
30
|
+
* B) We tweak the CLI to look for different APIs to monkeypatch depending on versions.
|
|
31
|
+
* @alpha
|
|
32
|
+
*/
|
|
56
33
|
function setApp(app) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
34
|
+
if (cache?.name === APP_NAME) {
|
|
35
|
+
void (0, firebase_admin_app.deleteApp)(cache);
|
|
36
|
+
}
|
|
37
|
+
cache = app;
|
|
61
38
|
}
|
|
62
|
-
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
exports.getApp = getApp;
|
|
42
|
+
exports.setApp = setApp;
|
package/lib/common/change.js
CHANGED
|
@@ -1,80 +1,59 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
//
|
|
4
|
-
// Copyright (c) 2022 Firebase
|
|
5
|
-
//
|
|
6
|
-
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
// of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
// in the Software without restriction, including without limitation the rights
|
|
9
|
-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
// copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
// furnished to do so, subject to the following conditions:
|
|
12
|
-
//
|
|
13
|
-
// The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
// copies or substantial portions of the Software.
|
|
15
|
-
//
|
|
16
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
// SOFTWARE.
|
|
23
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.Change = exports.applyFieldMask = void 0;
|
|
1
|
+
|
|
2
|
+
//#region src/common/change.ts
|
|
25
3
|
/** @internal */
|
|
26
4
|
function applyFieldMask(sparseBefore, after, fieldMask) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return before;
|
|
5
|
+
const before = { ...after };
|
|
6
|
+
const masks = fieldMask.split(",");
|
|
7
|
+
for (const mask of masks) {
|
|
8
|
+
const parts = mask.split(".");
|
|
9
|
+
const head = parts[0];
|
|
10
|
+
const tail = parts.slice(1).join(".");
|
|
11
|
+
if (parts.length > 1) {
|
|
12
|
+
before[head] = applyFieldMask(sparseBefore?.[head], after[head], tail);
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
const val = sparseBefore?.[head];
|
|
16
|
+
if (typeof val === "undefined") {
|
|
17
|
+
delete before[mask];
|
|
18
|
+
} else {
|
|
19
|
+
before[mask] = val;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return before;
|
|
46
23
|
}
|
|
47
|
-
exports.applyFieldMask = applyFieldMask;
|
|
48
24
|
/**
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
class Change {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
25
|
+
* The Cloud Functions interface for events that change state, such as
|
|
26
|
+
* Realtime Database or Cloud Firestore `onWrite` and `onUpdate` events.
|
|
27
|
+
*
|
|
28
|
+
* For more information about the format used to construct `Change` objects, see
|
|
29
|
+
* {@link ChangeJson} below.
|
|
30
|
+
*
|
|
31
|
+
*/
|
|
32
|
+
var Change = class Change {
|
|
33
|
+
/**
|
|
34
|
+
* Factory method for creating a `Change` from a `before` object and an `after`
|
|
35
|
+
* object.
|
|
36
|
+
*/
|
|
37
|
+
static fromObjects(before, after) {
|
|
38
|
+
return new Change(before, after);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Factory method for creating a `Change` from JSON and an optional customizer
|
|
42
|
+
* function to be applied to both the `before` and the `after` fields.
|
|
43
|
+
*/
|
|
44
|
+
static fromJSON(json, customizer = (x) => x) {
|
|
45
|
+
let before = { ...json.before };
|
|
46
|
+
if (json.fieldMask) {
|
|
47
|
+
before = applyFieldMask(before, json.after, json.fieldMask);
|
|
48
|
+
}
|
|
49
|
+
return Change.fromObjects(customizer(before || {}), customizer(json.after || {}));
|
|
50
|
+
}
|
|
51
|
+
constructor(before, after) {
|
|
52
|
+
this.before = before;
|
|
53
|
+
this.after = after;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
//#endregion
|
|
80
58
|
exports.Change = Change;
|
|
59
|
+
exports.applyFieldMask = applyFieldMask;
|
package/lib/common/config.js
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.js');
|
|
2
|
+
const require_logger_index = require('../logger/index.js');
|
|
3
|
+
let path = require("path");
|
|
4
|
+
path = require_rolldown_runtime.__toESM(path);
|
|
5
|
+
let fs = require("fs");
|
|
6
|
+
fs = require_rolldown_runtime.__toESM(fs);
|
|
7
|
+
|
|
8
|
+
//#region src/common/config.ts
|
|
7
9
|
let cache = null;
|
|
8
10
|
/**
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
* @internal
|
|
12
|
+
* @alpha
|
|
13
|
+
*/
|
|
12
14
|
function resetCache(newCache = null) {
|
|
13
|
-
|
|
15
|
+
cache = newCache;
|
|
14
16
|
}
|
|
15
|
-
exports.resetCache = resetCache;
|
|
16
17
|
/**
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
* Get the fields you need to initialize a Firebase app
|
|
19
|
+
* @alpha
|
|
20
|
+
*/
|
|
20
21
|
function firebaseConfig() {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
else {
|
|
45
|
-
logger.warn("Warning, FIREBASE_CONFIG and GCLOUD_PROJECT environment variables are missing. Initializing firebase-admin will fail");
|
|
46
|
-
}
|
|
47
|
-
return null;
|
|
22
|
+
if (cache) {
|
|
23
|
+
return cache;
|
|
24
|
+
}
|
|
25
|
+
let env = process.env.FIREBASE_CONFIG;
|
|
26
|
+
if (env) {
|
|
27
|
+
if (!env.startsWith("{")) {
|
|
28
|
+
env = fs.default.readFileSync(path.join(process.env.PWD, env)).toString("utf8");
|
|
29
|
+
}
|
|
30
|
+
cache = JSON.parse(env);
|
|
31
|
+
return cache;
|
|
32
|
+
}
|
|
33
|
+
if (process.env.GCLOUD_PROJECT) {
|
|
34
|
+
require_logger_index.warn("Warning, estimating Firebase Config based on GCLOUD_PROJECT. Initializing firebase-admin may fail");
|
|
35
|
+
cache = {
|
|
36
|
+
databaseURL: process.env.DATABASE_URL || `https://${process.env.GCLOUD_PROJECT}.firebaseio.com`,
|
|
37
|
+
storageBucket: process.env.STORAGE_BUCKET_URL || `${process.env.GCLOUD_PROJECT}.appspot.com`,
|
|
38
|
+
projectId: process.env.GCLOUD_PROJECT
|
|
39
|
+
};
|
|
40
|
+
return cache;
|
|
41
|
+
} else {
|
|
42
|
+
require_logger_index.warn("Warning, FIREBASE_CONFIG and GCLOUD_PROJECT environment variables are missing. Initializing firebase-admin will fail");
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
48
45
|
}
|
|
46
|
+
|
|
47
|
+
//#endregion
|
|
49
48
|
exports.firebaseConfig = firebaseConfig;
|
|
49
|
+
exports.resetCache = resetCache;
|
package/lib/common/debug.js
CHANGED
|
@@ -1,54 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
//
|
|
4
|
-
// Copyright (c) 2021 Firebase
|
|
5
|
-
//
|
|
6
|
-
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
// of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
// in the Software without restriction, including without limitation the rights
|
|
9
|
-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
// copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
// furnished to do so, subject to the following conditions:
|
|
12
|
-
//
|
|
13
|
-
// The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
// copies or substantial portions of the Software.
|
|
15
|
-
//
|
|
16
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
// SOFTWARE.
|
|
23
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.isDebugFeatureEnabled = exports.debugFeatureValue = void 0;
|
|
25
|
-
// Do NOT turn on a debug feature in production.
|
|
1
|
+
|
|
2
|
+
//#region src/common/debug.ts
|
|
26
3
|
const debugMode = process.env.FIREBASE_DEBUG_MODE === "true";
|
|
27
4
|
function loadDebugFeatures() {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
5
|
+
if (!debugMode) {
|
|
6
|
+
return {};
|
|
7
|
+
}
|
|
8
|
+
try {
|
|
9
|
+
const obj = JSON.parse(process.env.FIREBASE_DEBUG_FEATURES);
|
|
10
|
+
if (typeof obj !== "object") {
|
|
11
|
+
return {};
|
|
12
|
+
}
|
|
13
|
+
return obj;
|
|
14
|
+
} catch (_e) {
|
|
15
|
+
return {};
|
|
16
|
+
}
|
|
41
17
|
}
|
|
42
|
-
/* @internal */
|
|
43
18
|
function debugFeatureValue(feat) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
19
|
+
if (!debugMode) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
return loadDebugFeatures()[feat];
|
|
48
23
|
}
|
|
49
|
-
exports.debugFeatureValue = debugFeatureValue;
|
|
50
|
-
/* @internal */
|
|
51
24
|
function isDebugFeatureEnabled(feat) {
|
|
52
|
-
|
|
25
|
+
return debugMode && !!debugFeatureValue(feat);
|
|
53
26
|
}
|
|
54
|
-
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
exports.debugFeatureValue = debugFeatureValue;
|
|
30
|
+
exports.isDebugFeatureEnabled = isDebugFeatureEnabled;
|