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
|
@@ -1,383 +1,254 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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.FunctionBuilder = exports.runWith = exports.region = void 0;
|
|
25
|
-
const options_1 = require("../common/options");
|
|
26
|
-
const types_1 = require("../params/types");
|
|
27
|
-
const function_configuration_1 = require("./function-configuration");
|
|
28
|
-
const analytics = require("./providers/analytics");
|
|
29
|
-
const auth = require("./providers/auth");
|
|
30
|
-
const database = require("./providers/database");
|
|
31
|
-
const firestore = require("./providers/firestore");
|
|
32
|
-
const https = require("./providers/https");
|
|
33
|
-
const pubsub = require("./providers/pubsub");
|
|
34
|
-
const remoteConfig = require("./providers/remoteConfig");
|
|
35
|
-
const storage = require("./providers/storage");
|
|
36
|
-
const tasks = require("./providers/tasks");
|
|
37
|
-
const testLab = require("./providers/testLab");
|
|
1
|
+
const require_params_types = require('../params/types.js');
|
|
2
|
+
const require_common_options = require('../common/options.js');
|
|
3
|
+
const require_v1_function_configuration = require('./function-configuration.js');
|
|
4
|
+
const require_v1_providers_analytics = require('./providers/analytics.js');
|
|
5
|
+
const require_v1_providers_auth = require('./providers/auth.js');
|
|
6
|
+
const require_v1_providers_database = require('./providers/database.js');
|
|
7
|
+
const require_v1_providers_firestore = require('./providers/firestore.js');
|
|
8
|
+
const require_v1_providers_https = require('./providers/https.js');
|
|
9
|
+
const require_v1_providers_pubsub = require('./providers/pubsub.js');
|
|
10
|
+
const require_v1_providers_remoteConfig = require('./providers/remoteConfig.js');
|
|
11
|
+
const require_v1_providers_storage = require('./providers/storage.js');
|
|
12
|
+
const require_v1_providers_tasks = require('./providers/tasks.js');
|
|
13
|
+
const require_v1_providers_testLab = require('./providers/testLab.js');
|
|
14
|
+
|
|
15
|
+
//#region src/v1/function-builder.ts
|
|
38
16
|
/**
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
17
|
+
* Assert that the runtime options passed in are valid.
|
|
18
|
+
* @param runtimeOptions object containing memory and timeout information.
|
|
19
|
+
* @throws { Error } Memory and TimeoutSeconds values must be valid.
|
|
20
|
+
*/
|
|
43
21
|
function assertRuntimeOptionsValid(runtimeOptions) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
throw new Error("Invalid invoker array, a service account cannot be set to the 'private' identifier");
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
if (runtimeOptions.secrets !== undefined) {
|
|
123
|
-
const invalidSecrets = runtimeOptions.secrets.filter((s) => !/^[A-Za-z\d\-_]+$/.test(s instanceof types_1.SecretParam ? s.name : s));
|
|
124
|
-
if (invalidSecrets.length > 0) {
|
|
125
|
-
throw new Error(`Invalid secrets: ${invalidSecrets.join(",")}. ` +
|
|
126
|
-
"Secret must be configured using the resource id (e.g. API_KEY)");
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
if ("allowInvalidAppCheckToken" in runtimeOptions) {
|
|
130
|
-
throw new Error('runWith option "allowInvalidAppCheckToken" has been inverted and ' +
|
|
131
|
-
'renamed "enforceAppCheck"');
|
|
132
|
-
}
|
|
133
|
-
return true;
|
|
22
|
+
const mem = runtimeOptions.memory;
|
|
23
|
+
if (mem && typeof mem !== "object" && !require_v1_function_configuration.VALID_MEMORY_OPTIONS.includes(mem)) {
|
|
24
|
+
throw new Error(`The only valid memory allocation values are: ${require_v1_function_configuration.VALID_MEMORY_OPTIONS.join(", ")}`);
|
|
25
|
+
}
|
|
26
|
+
if (typeof runtimeOptions.timeoutSeconds === "number" && (runtimeOptions.timeoutSeconds > require_v1_function_configuration.MAX_TIMEOUT_SECONDS || runtimeOptions.timeoutSeconds < 0)) {
|
|
27
|
+
throw new Error(`TimeoutSeconds must be between 0 and ${require_v1_function_configuration.MAX_TIMEOUT_SECONDS}`);
|
|
28
|
+
}
|
|
29
|
+
if (runtimeOptions.ingressSettings && !(runtimeOptions.ingressSettings instanceof require_common_options.ResetValue) && !require_v1_function_configuration.INGRESS_SETTINGS_OPTIONS.includes(runtimeOptions.ingressSettings)) {
|
|
30
|
+
throw new Error(`The only valid ingressSettings values are: ${require_v1_function_configuration.INGRESS_SETTINGS_OPTIONS.join(",")}`);
|
|
31
|
+
}
|
|
32
|
+
if (runtimeOptions.vpcConnectorEgressSettings && !(runtimeOptions.vpcConnectorEgressSettings instanceof require_common_options.ResetValue) && !require_v1_function_configuration.VPC_EGRESS_SETTINGS_OPTIONS.includes(runtimeOptions.vpcConnectorEgressSettings)) {
|
|
33
|
+
throw new Error(`The only valid vpcConnectorEgressSettings values are: ${require_v1_function_configuration.VPC_EGRESS_SETTINGS_OPTIONS.join(",")}`);
|
|
34
|
+
}
|
|
35
|
+
validateFailurePolicy(runtimeOptions.failurePolicy);
|
|
36
|
+
const serviceAccount = runtimeOptions.serviceAccount;
|
|
37
|
+
if (serviceAccount && !(serviceAccount === "default" || serviceAccount instanceof require_common_options.ResetValue || serviceAccount instanceof require_params_types.Expression || serviceAccount.includes("@"))) {
|
|
38
|
+
throw new Error(`serviceAccount must be set to 'default', a string expression, a service account email, or '{serviceAccountName}@'`);
|
|
39
|
+
}
|
|
40
|
+
if (runtimeOptions.labels) {
|
|
41
|
+
if (Object.keys(runtimeOptions.labels).length > require_v1_function_configuration.MAX_NUMBER_USER_LABELS) {
|
|
42
|
+
throw new Error(`A function must not have more than ${require_v1_function_configuration.MAX_NUMBER_USER_LABELS} user-defined labels.`);
|
|
43
|
+
}
|
|
44
|
+
const reservedKeys = Object.keys(runtimeOptions.labels).filter((key) => key.startsWith("deployment") || key.startsWith("firebase"));
|
|
45
|
+
if (reservedKeys.length) {
|
|
46
|
+
throw new Error(`Invalid labels: ${reservedKeys.join(", ")}. Labels may not start with reserved names 'deployment' or 'firebase'`);
|
|
47
|
+
}
|
|
48
|
+
const invalidLengthKeys = Object.keys(runtimeOptions.labels).filter((key) => key.length < 1 || key.length > 63);
|
|
49
|
+
if (invalidLengthKeys.length > 0) {
|
|
50
|
+
throw new Error(`Invalid labels: ${invalidLengthKeys.join(", ")}. Label keys must be between 1 and 63 characters in length.`);
|
|
51
|
+
}
|
|
52
|
+
const invalidLengthValues = Object.values(runtimeOptions.labels).filter((value) => value.length > 63);
|
|
53
|
+
if (invalidLengthValues.length > 0) {
|
|
54
|
+
throw new Error(`Invalid labels: ${invalidLengthValues.join(", ")}. Label values must be less than 64 charcters.`);
|
|
55
|
+
}
|
|
56
|
+
const validKeyPattern = /^[\p{Ll}\p{Lo}][\p{Ll}\p{Lo}\p{N}_-]{0,62}$/u;
|
|
57
|
+
const invalidKeys = Object.keys(runtimeOptions.labels).filter((key) => !validKeyPattern.test(key));
|
|
58
|
+
if (invalidKeys.length > 0) {
|
|
59
|
+
throw new Error(`Invalid labels: ${invalidKeys.join(", ")}. Label keys can only contain lowercase letters, international characters, numbers, _ or -, and must start with a letter.`);
|
|
60
|
+
}
|
|
61
|
+
const validValuePattern = /^[\p{Ll}\p{Lo}\p{N}_-]{0,63}$/u;
|
|
62
|
+
const invalidValues = Object.values(runtimeOptions.labels).filter((value) => !validValuePattern.test(value));
|
|
63
|
+
if (invalidValues.length > 0) {
|
|
64
|
+
throw new Error(`Invalid labels: ${invalidValues.join(", ")}. Label values can only contain lowercase letters, international characters, numbers, _ or -.`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (typeof runtimeOptions.invoker === "string" && runtimeOptions.invoker.length === 0) {
|
|
68
|
+
throw new Error("Invalid service account for function invoker, must be a non-empty string");
|
|
69
|
+
}
|
|
70
|
+
if (runtimeOptions.invoker !== undefined && Array.isArray(runtimeOptions.invoker)) {
|
|
71
|
+
if (runtimeOptions.invoker.length === 0) {
|
|
72
|
+
throw new Error("Invalid invoker array, must contain at least 1 service account entry");
|
|
73
|
+
}
|
|
74
|
+
for (const serviceAccount$1 of runtimeOptions.invoker) {
|
|
75
|
+
if (serviceAccount$1.length === 0) {
|
|
76
|
+
throw new Error("Invalid invoker array, a service account must be a non-empty string");
|
|
77
|
+
}
|
|
78
|
+
if (serviceAccount$1 === "public") {
|
|
79
|
+
throw new Error("Invalid invoker array, a service account cannot be set to the 'public' identifier");
|
|
80
|
+
}
|
|
81
|
+
if (serviceAccount$1 === "private") {
|
|
82
|
+
throw new Error("Invalid invoker array, a service account cannot be set to the 'private' identifier");
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (runtimeOptions.secrets !== undefined) {
|
|
87
|
+
const invalidSecrets = runtimeOptions.secrets.filter((s) => !/^[A-Za-z\d\-_]+$/.test(s instanceof require_params_types.SecretParam ? s.name : s));
|
|
88
|
+
if (invalidSecrets.length > 0) {
|
|
89
|
+
throw new Error(`Invalid secrets: ${invalidSecrets.join(",")}. ` + "Secret must be configured using the resource id (e.g. API_KEY)");
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if ("allowInvalidAppCheckToken" in runtimeOptions) {
|
|
93
|
+
throw new Error("runWith option \"allowInvalidAppCheckToken\" has been inverted and " + "renamed \"enforceAppCheck\"");
|
|
94
|
+
}
|
|
95
|
+
return true;
|
|
134
96
|
}
|
|
135
97
|
function validateFailurePolicy(policy) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
98
|
+
if (typeof policy === "boolean" || typeof policy === "undefined") {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (typeof policy !== "object") {
|
|
102
|
+
throw new Error(`failurePolicy must be a boolean or an object.`);
|
|
103
|
+
}
|
|
104
|
+
const retry = policy.retry;
|
|
105
|
+
if (typeof retry !== "object" || Object.keys(retry).length) {
|
|
106
|
+
throw new Error("failurePolicy.retry must be an empty object.");
|
|
107
|
+
}
|
|
146
108
|
}
|
|
147
109
|
/**
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
110
|
+
* Assert regions specified are valid.
|
|
111
|
+
* @param regions list of regions.
|
|
112
|
+
* @throws { Error } Regions must be in list of supported regions.
|
|
113
|
+
*/
|
|
152
114
|
function assertRegionsAreValid(regions) {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
115
|
+
if (!regions.length) {
|
|
116
|
+
throw new Error("You must specify at least one region");
|
|
117
|
+
}
|
|
118
|
+
return true;
|
|
157
119
|
}
|
|
158
120
|
/**
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
121
|
+
* Configure the regions that the function is deployed to.
|
|
122
|
+
* @param regions One of more region strings.
|
|
123
|
+
* @example
|
|
124
|
+
* functions.region('us-east1')
|
|
125
|
+
* @example
|
|
126
|
+
* functions.region('us-east1', 'us-central1')
|
|
127
|
+
*/
|
|
166
128
|
function region(...regions) {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
129
|
+
if (assertRegionsAreValid(regions)) {
|
|
130
|
+
return new FunctionBuilder({ regions });
|
|
131
|
+
}
|
|
170
132
|
}
|
|
171
|
-
exports.region = region;
|
|
172
133
|
/**
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
134
|
+
* Configure runtime options for the function.
|
|
135
|
+
* @param runtimeOptions Object with optional fields:
|
|
136
|
+
* 1. `memory`: amount of memory to allocate to the function, possible values
|
|
137
|
+
* are: '128MB', '256MB', '512MB', '1GB', '2GB', '4GB', and '8GB'.
|
|
138
|
+
* 2. `timeoutSeconds`: timeout for the function in seconds, possible values are
|
|
139
|
+
* 0 to 540.
|
|
140
|
+
* 3. `failurePolicy`: failure policy of the function, with boolean `true` being
|
|
141
|
+
* equivalent to providing an empty retry object.
|
|
142
|
+
* 4. `vpcConnector`: id of a VPC connector in same project and region.
|
|
143
|
+
* 5. `vpcConnectorEgressSettings`: when a vpcConnector is set, control which
|
|
144
|
+
* egress traffic is sent through the vpcConnector.
|
|
145
|
+
* 6. `serviceAccount`: Specific service account for the function.
|
|
146
|
+
* 7. `ingressSettings`: ingress settings for the function, which control where a HTTPS
|
|
147
|
+
* function can be called from.
|
|
148
|
+
*
|
|
149
|
+
* Value must not be null.
|
|
150
|
+
*/
|
|
190
151
|
function runWith(runtimeOptions) {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
}
|
|
195
|
-
exports.runWith = runWith;
|
|
196
|
-
class FunctionBuilder {
|
|
197
|
-
constructor(options) {
|
|
198
|
-
this.options = options;
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Configure the regions that the function is deployed to.
|
|
202
|
-
* @param regions One or more region strings.
|
|
203
|
-
* @example
|
|
204
|
-
* functions.region('us-east1')
|
|
205
|
-
* @example
|
|
206
|
-
* functions.region('us-east1', 'us-central1')
|
|
207
|
-
*/
|
|
208
|
-
region(...regions) {
|
|
209
|
-
if (assertRegionsAreValid(regions)) {
|
|
210
|
-
this.options.regions = regions;
|
|
211
|
-
return this;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Configure runtime options for the function.
|
|
216
|
-
* @param runtimeOptions Object with optional fields:
|
|
217
|
-
* 1. `memory`: amount of memory to allocate to the function, possible values
|
|
218
|
-
* are: '128MB', '256MB', '512MB', '1GB', '2GB', '4GB', and '8GB'.
|
|
219
|
-
* 2. `timeoutSeconds`: timeout for the function in seconds, possible values are
|
|
220
|
-
* 0 to 540.
|
|
221
|
-
* 3. `failurePolicy`: failure policy of the function, with boolean `true` being
|
|
222
|
-
* equivalent to providing an empty retry object.
|
|
223
|
-
* 4. `vpcConnector`: id of a VPC connector in the same project and region
|
|
224
|
-
* 5. `vpcConnectorEgressSettings`: when a `vpcConnector` is set, control which
|
|
225
|
-
* egress traffic is sent through the `vpcConnector`.
|
|
226
|
-
*
|
|
227
|
-
* Value must not be null.
|
|
228
|
-
*/
|
|
229
|
-
runWith(runtimeOptions) {
|
|
230
|
-
if (assertRuntimeOptionsValid(runtimeOptions)) {
|
|
231
|
-
this.options = {
|
|
232
|
-
...this.options,
|
|
233
|
-
...runtimeOptions,
|
|
234
|
-
};
|
|
235
|
-
return this;
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
get https() {
|
|
239
|
-
if (this.options.failurePolicy !== undefined) {
|
|
240
|
-
console.warn("RuntimeOptions.failurePolicy is not supported in https functions.");
|
|
241
|
-
}
|
|
242
|
-
return {
|
|
243
|
-
/**
|
|
244
|
-
* Handle HTTP requests.
|
|
245
|
-
* @param handler A function that takes a request and response object,
|
|
246
|
-
* same signature as an Express app.
|
|
247
|
-
*/
|
|
248
|
-
onRequest: (handler) => https._onRequestWithOptions(handler, this.options),
|
|
249
|
-
/**
|
|
250
|
-
* Declares a callable method for clients to call using a Firebase SDK.
|
|
251
|
-
* @param handler A method that takes a data and context and returns a value.
|
|
252
|
-
*/
|
|
253
|
-
onCall: (handler) => https._onCallWithOptions(handler, this.options),
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
get tasks() {
|
|
257
|
-
return {
|
|
258
|
-
/**
|
|
259
|
-
* Declares a task queue function for clients to call using a Firebase Admin SDK.
|
|
260
|
-
* @param options Configurations for the task queue function.
|
|
261
|
-
*/
|
|
262
|
-
/** @hidden */
|
|
263
|
-
taskQueue: (options) => {
|
|
264
|
-
return new tasks.TaskQueueBuilder(options, this.options);
|
|
265
|
-
},
|
|
266
|
-
};
|
|
267
|
-
}
|
|
268
|
-
get database() {
|
|
269
|
-
return {
|
|
270
|
-
/**
|
|
271
|
-
* Selects a database instance that will trigger the function. If omitted,
|
|
272
|
-
* will pick the default database for your project.
|
|
273
|
-
* @param instance The Realtime Database instance to use.
|
|
274
|
-
*/
|
|
275
|
-
instance: (instance) => database._instanceWithOptions(instance, this.options),
|
|
276
|
-
/**
|
|
277
|
-
* Select Firebase Realtime Database Reference to listen to.
|
|
278
|
-
*
|
|
279
|
-
* This method behaves very similarly to the method of the same name in
|
|
280
|
-
* the client and Admin Firebase SDKs. Any change to the Database that
|
|
281
|
-
* affects the data at or below the provided `path` will fire an event in
|
|
282
|
-
* Cloud Functions.
|
|
283
|
-
*
|
|
284
|
-
* There are three important differences between listening to a Realtime
|
|
285
|
-
* Database event in Cloud Functions and using the Realtime Database in
|
|
286
|
-
* the client and Admin SDKs:
|
|
287
|
-
* 1. Cloud Functions allows wildcards in the `path` name. Any `path`
|
|
288
|
-
* component in curly brackets (`{}`) is a wildcard that matches all
|
|
289
|
-
* strings. The value that matched a certain invocation of a Cloud
|
|
290
|
-
* Function is returned as part of the `context.params` object. For
|
|
291
|
-
* example, `ref("messages/{messageId}")` matches changes at
|
|
292
|
-
* `/messages/message1` or `/messages/message2`, resulting in
|
|
293
|
-
* `context.params.messageId` being set to `"message1"` or
|
|
294
|
-
* `"message2"`, respectively.
|
|
295
|
-
* 2. Cloud Functions do not fire an event for data that already existed
|
|
296
|
-
* before the Cloud Function was deployed.
|
|
297
|
-
* 3. Cloud Function events have access to more information, including
|
|
298
|
-
* information about the user who triggered the Cloud Function.
|
|
299
|
-
* @param ref Path of the database to listen to.
|
|
300
|
-
*/
|
|
301
|
-
ref: (path) => database._refWithOptions(path, this.options),
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
get firestore() {
|
|
305
|
-
return {
|
|
306
|
-
/**
|
|
307
|
-
* Select the Firestore document to listen to for events.
|
|
308
|
-
* @param path Full database path to listen to. This includes the name of
|
|
309
|
-
* the collection that the document is a part of. For example, if the
|
|
310
|
-
* collection is named "users" and the document is named "Ada", then the
|
|
311
|
-
* path is "/users/Ada".
|
|
312
|
-
*/
|
|
313
|
-
document: (path) => firestore._documentWithOptions(path, this.options),
|
|
314
|
-
/** @hidden */
|
|
315
|
-
namespace: (namespace) => firestore._namespaceWithOptions(namespace, this.options),
|
|
316
|
-
/** @hidden */
|
|
317
|
-
database: (database) => firestore._databaseWithOptions(database, this.options),
|
|
318
|
-
};
|
|
319
|
-
}
|
|
320
|
-
get analytics() {
|
|
321
|
-
return {
|
|
322
|
-
/**
|
|
323
|
-
* Select analytics events to listen to for events.
|
|
324
|
-
* @param analyticsEventType Name of the analytics event type.
|
|
325
|
-
*/
|
|
326
|
-
event: (analyticsEventType) => analytics._eventWithOptions(analyticsEventType, this.options),
|
|
327
|
-
};
|
|
328
|
-
}
|
|
329
|
-
get remoteConfig() {
|
|
330
|
-
return {
|
|
331
|
-
/**
|
|
332
|
-
* Handle all updates (including rollbacks) that affect a Remote Config
|
|
333
|
-
* project.
|
|
334
|
-
* @param handler A function that takes the updated Remote Config template
|
|
335
|
-
* version metadata as an argument.
|
|
336
|
-
*/
|
|
337
|
-
onUpdate: (handler) => remoteConfig._onUpdateWithOptions(handler, this.options),
|
|
338
|
-
};
|
|
339
|
-
}
|
|
340
|
-
get storage() {
|
|
341
|
-
return {
|
|
342
|
-
/**
|
|
343
|
-
* The optional bucket function allows you to choose which buckets' events
|
|
344
|
-
* to handle. This step can be bypassed by calling object() directly,
|
|
345
|
-
* which will use the default Cloud Storage for Firebase bucket.
|
|
346
|
-
* @param bucket Name of the Google Cloud Storage bucket to listen to.
|
|
347
|
-
*/
|
|
348
|
-
bucket: (bucket) => storage._bucketWithOptions(this.options, bucket),
|
|
349
|
-
/**
|
|
350
|
-
* Handle events related to Cloud Storage objects.
|
|
351
|
-
*/
|
|
352
|
-
object: () => storage._objectWithOptions(this.options),
|
|
353
|
-
};
|
|
354
|
-
}
|
|
355
|
-
get pubsub() {
|
|
356
|
-
return {
|
|
357
|
-
/**
|
|
358
|
-
* Select Cloud Pub/Sub topic to listen to.
|
|
359
|
-
* @param topic Name of Pub/Sub topic, must belong to the same project as
|
|
360
|
-
* the function.
|
|
361
|
-
*/
|
|
362
|
-
topic: (topic) => pubsub._topicWithOptions(topic, this.options),
|
|
363
|
-
schedule: (schedule) => pubsub._scheduleWithOptions(schedule, this.options),
|
|
364
|
-
};
|
|
365
|
-
}
|
|
366
|
-
get auth() {
|
|
367
|
-
return {
|
|
368
|
-
/**
|
|
369
|
-
* Handle events related to Firebase authentication users.
|
|
370
|
-
*/
|
|
371
|
-
user: (userOptions) => auth._userWithOptions(this.options, userOptions),
|
|
372
|
-
};
|
|
373
|
-
}
|
|
374
|
-
get testLab() {
|
|
375
|
-
return {
|
|
376
|
-
/**
|
|
377
|
-
* Handle events related to Test Lab test matrices.
|
|
378
|
-
*/
|
|
379
|
-
testMatrix: () => testLab._testMatrixWithOpts(this.options),
|
|
380
|
-
};
|
|
381
|
-
}
|
|
152
|
+
if (assertRuntimeOptionsValid(runtimeOptions)) {
|
|
153
|
+
return new FunctionBuilder(runtimeOptions);
|
|
154
|
+
}
|
|
382
155
|
}
|
|
156
|
+
var FunctionBuilder = class {
|
|
157
|
+
constructor(options) {
|
|
158
|
+
this.options = options;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Configure the regions that the function is deployed to.
|
|
162
|
+
* @param regions One or more region strings.
|
|
163
|
+
* @example
|
|
164
|
+
* functions.region('us-east1')
|
|
165
|
+
* @example
|
|
166
|
+
* functions.region('us-east1', 'us-central1')
|
|
167
|
+
*/
|
|
168
|
+
region(...regions) {
|
|
169
|
+
if (assertRegionsAreValid(regions)) {
|
|
170
|
+
this.options.regions = regions;
|
|
171
|
+
return this;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Configure runtime options for the function.
|
|
176
|
+
* @param runtimeOptions Object with optional fields:
|
|
177
|
+
* 1. `memory`: amount of memory to allocate to the function, possible values
|
|
178
|
+
* are: '128MB', '256MB', '512MB', '1GB', '2GB', '4GB', and '8GB'.
|
|
179
|
+
* 2. `timeoutSeconds`: timeout for the function in seconds, possible values are
|
|
180
|
+
* 0 to 540.
|
|
181
|
+
* 3. `failurePolicy`: failure policy of the function, with boolean `true` being
|
|
182
|
+
* equivalent to providing an empty retry object.
|
|
183
|
+
* 4. `vpcConnector`: id of a VPC connector in the same project and region
|
|
184
|
+
* 5. `vpcConnectorEgressSettings`: when a `vpcConnector` is set, control which
|
|
185
|
+
* egress traffic is sent through the `vpcConnector`.
|
|
186
|
+
*
|
|
187
|
+
* Value must not be null.
|
|
188
|
+
*/
|
|
189
|
+
runWith(runtimeOptions) {
|
|
190
|
+
if (assertRuntimeOptionsValid(runtimeOptions)) {
|
|
191
|
+
this.options = {
|
|
192
|
+
...this.options,
|
|
193
|
+
...runtimeOptions
|
|
194
|
+
};
|
|
195
|
+
return this;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
get https() {
|
|
199
|
+
if (this.options.failurePolicy !== undefined) {
|
|
200
|
+
console.warn("RuntimeOptions.failurePolicy is not supported in https functions.");
|
|
201
|
+
}
|
|
202
|
+
return {
|
|
203
|
+
onRequest: (handler) => require_v1_providers_https._onRequestWithOptions(handler, this.options),
|
|
204
|
+
onCall: (handler) => require_v1_providers_https._onCallWithOptions(handler, this.options)
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
get tasks() {
|
|
208
|
+
return { taskQueue: (options) => {
|
|
209
|
+
return new require_v1_providers_tasks.TaskQueueBuilder(options, this.options);
|
|
210
|
+
} };
|
|
211
|
+
}
|
|
212
|
+
get database() {
|
|
213
|
+
return {
|
|
214
|
+
instance: (instance) => require_v1_providers_database._instanceWithOptions(instance, this.options),
|
|
215
|
+
ref: (path) => require_v1_providers_database._refWithOptions(path, this.options)
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
get firestore() {
|
|
219
|
+
return {
|
|
220
|
+
document: (path) => require_v1_providers_firestore._documentWithOptions(path, this.options),
|
|
221
|
+
namespace: (namespace) => require_v1_providers_firestore._namespaceWithOptions(namespace, this.options),
|
|
222
|
+
database: (database) => require_v1_providers_firestore._databaseWithOptions(database, this.options)
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
get analytics() {
|
|
226
|
+
return { event: (analyticsEventType) => require_v1_providers_analytics._eventWithOptions(analyticsEventType, this.options) };
|
|
227
|
+
}
|
|
228
|
+
get remoteConfig() {
|
|
229
|
+
return { onUpdate: (handler) => require_v1_providers_remoteConfig._onUpdateWithOptions(handler, this.options) };
|
|
230
|
+
}
|
|
231
|
+
get storage() {
|
|
232
|
+
return {
|
|
233
|
+
bucket: (bucket) => require_v1_providers_storage._bucketWithOptions(this.options, bucket),
|
|
234
|
+
object: () => require_v1_providers_storage._objectWithOptions(this.options)
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
get pubsub() {
|
|
238
|
+
return {
|
|
239
|
+
topic: (topic) => require_v1_providers_pubsub._topicWithOptions(topic, this.options),
|
|
240
|
+
schedule: (schedule) => require_v1_providers_pubsub._scheduleWithOptions(schedule, this.options)
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
get auth() {
|
|
244
|
+
return { user: (userOptions) => require_v1_providers_auth._userWithOptions(this.options, userOptions) };
|
|
245
|
+
}
|
|
246
|
+
get testLab() {
|
|
247
|
+
return { testMatrix: () => require_v1_providers_testLab._testMatrixWithOpts(this.options) };
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
//#endregion
|
|
383
252
|
exports.FunctionBuilder = FunctionBuilder;
|
|
253
|
+
exports.region = region;
|
|
254
|
+
exports.runWith = runWith;
|