firebase-functions 3.17.2 → 3.19.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/bin/firebase-functions.js +16 -14
- package/lib/cloud-functions.d.ts +1 -0
- package/lib/cloud-functions.js +8 -4
- package/lib/function-builder.js +7 -0
- package/lib/function-configuration.d.ts +1 -0
- package/lib/index.js +5 -1
- package/lib/providers/database.js +1 -1
- package/lib/runtime/loader.js +1 -2
- package/lib/runtime/manifest.d.ts +15 -2
- package/lib/v2/options.d.ts +2 -2
- package/lib/v2/options.js +12 -3
- package/lib/v2/providers/alerts/alerts.js +10 -4
- package/lib/v2/providers/alerts/billing.d.ts +2 -2
- package/lib/v2/providers/alerts/billing.js +5 -5
- package/lib/v2/providers/alerts/index.js +5 -1
- package/lib/v2/providers/pubsub.js +1 -1
- package/lib/v2/providers/storage.js +1 -3
- package/package.json +2 -2
|
@@ -28,21 +28,23 @@ async function handleQuitquitquit(req, res) {
|
|
|
28
28
|
}
|
|
29
29
|
app.get('/__/quitquitquit', handleQuitquitquit);
|
|
30
30
|
app.post('/__/quitquitquit', handleQuitquitquit);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
31
|
+
if (process.env.FUNCTIONS_CONTROL_API === 'true') {
|
|
32
|
+
app.get('/__/functions.yaml', async (req, res) => {
|
|
33
|
+
try {
|
|
34
|
+
const stack = await (0, loader_1.loadStack)(functionsDir);
|
|
35
|
+
res.setHeader('content-type', 'text/yaml');
|
|
36
|
+
res.send(JSON.stringify(stack));
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
res
|
|
40
|
+
.status(400)
|
|
41
|
+
.send(`Failed to generate manifest from function source: ${e}`);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
43
45
|
let port = 8080;
|
|
44
|
-
if (process.env.
|
|
45
|
-
port = Number.parseInt(process.env.
|
|
46
|
+
if (process.env.PORT) {
|
|
47
|
+
port = Number.parseInt(process.env.PORT);
|
|
46
48
|
}
|
|
47
49
|
console.log('Serving at port', port);
|
|
48
50
|
server = app.listen(port);
|
package/lib/cloud-functions.d.ts
CHANGED
package/lib/cloud-functions.js
CHANGED
|
@@ -180,9 +180,12 @@ function makeCloudFunction({ after = () => { }, before = () => { }, contextOnlyH
|
|
|
180
180
|
else {
|
|
181
181
|
endpoint.eventTrigger = {
|
|
182
182
|
eventType: legacyEventType || provider + '.' + eventType,
|
|
183
|
-
eventFilters:
|
|
184
|
-
|
|
185
|
-
|
|
183
|
+
eventFilters: [
|
|
184
|
+
{
|
|
185
|
+
attribute: 'resource',
|
|
186
|
+
value: triggerResource(),
|
|
187
|
+
},
|
|
188
|
+
],
|
|
186
189
|
retry: !!options.failurePolicy,
|
|
187
190
|
};
|
|
188
191
|
}
|
|
@@ -252,7 +255,7 @@ function _detectAuthType(event) {
|
|
|
252
255
|
/** @hidden */
|
|
253
256
|
function optionsToTrigger(options) {
|
|
254
257
|
const trigger = {};
|
|
255
|
-
(0, encoding_1.copyIfPresent)(trigger, options, 'regions', 'schedule', 'minInstances', 'maxInstances', 'ingressSettings', 'vpcConnectorEgressSettings', 'vpcConnector', 'labels');
|
|
258
|
+
(0, encoding_1.copyIfPresent)(trigger, options, 'regions', 'schedule', 'minInstances', 'maxInstances', 'ingressSettings', 'vpcConnectorEgressSettings', 'vpcConnector', 'labels', 'secrets');
|
|
256
259
|
(0, encoding_1.convertIfPresent)(trigger, options, 'failurePolicy', 'failurePolicy', (policy) => {
|
|
257
260
|
if (policy === false) {
|
|
258
261
|
return undefined;
|
|
@@ -286,6 +289,7 @@ function optionsToEndpoint(options) {
|
|
|
286
289
|
(0, encoding_1.copyIfPresent)(endpoint, options, 'minInstances', 'maxInstances', 'ingressSettings', 'labels', 'timeoutSeconds');
|
|
287
290
|
(0, encoding_1.convertIfPresent)(endpoint, options, 'region', 'regions');
|
|
288
291
|
(0, encoding_1.convertIfPresent)(endpoint, options, 'serviceAccountEmail', 'serviceAccount', (sa) => sa);
|
|
292
|
+
(0, encoding_1.convertIfPresent)(endpoint, options, 'secretEnvironmentVariables', 'secrets', (secrets) => secrets.map((secret) => ({ secret, key: secret })));
|
|
289
293
|
if (options === null || options === void 0 ? void 0 : options.vpcConnector) {
|
|
290
294
|
endpoint.vpc = { connector: options.vpcConnector };
|
|
291
295
|
(0, encoding_1.convertIfPresent)(endpoint.vpc, options, 'egressSettings', 'vpcConnectorEgressSettings');
|
package/lib/function-builder.js
CHANGED
|
@@ -125,6 +125,13 @@ function assertRuntimeOptionsValid(runtimeOptions) {
|
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
|
+
if (runtimeOptions.secrets !== undefined) {
|
|
129
|
+
const invalidSecrets = runtimeOptions.secrets.filter((s) => !/^[A-Za-z\d\-_]+$/.test(s));
|
|
130
|
+
if (invalidSecrets.length > 0) {
|
|
131
|
+
throw new Error(`Invalid secrets: ${invalidSecrets.join(',')}. ` +
|
|
132
|
+
'Secret must be configured using the resource id (e.g. API_KEY)');
|
|
133
|
+
}
|
|
134
|
+
}
|
|
128
135
|
return true;
|
|
129
136
|
}
|
|
130
137
|
/**
|
|
@@ -99,6 +99,7 @@ export interface RuntimeOptions {
|
|
|
99
99
|
*/
|
|
100
100
|
invoker?: 'public' | 'private' | string | string[];
|
|
101
101
|
allowInvalidAppCheckToken?: boolean;
|
|
102
|
+
secrets?: string[];
|
|
102
103
|
}
|
|
103
104
|
export interface DeploymentOptions extends RuntimeOptions {
|
|
104
105
|
regions?: Array<typeof SUPPORTED_REGIONS[number] | string>;
|
package/lib/index.js
CHANGED
|
@@ -22,7 +22,11 @@
|
|
|
22
22
|
// SOFTWARE.
|
|
23
23
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
24
24
|
if (k2 === undefined) k2 = k;
|
|
25
|
-
Object.
|
|
25
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
26
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
27
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
28
|
+
}
|
|
29
|
+
Object.defineProperty(o, k2, desc);
|
|
26
30
|
}) : (function(o, m, k, k2) {
|
|
27
31
|
if (k2 === undefined) k2 = k;
|
|
28
32
|
o[k2] = m[k];
|
|
@@ -229,6 +229,7 @@ class RefBuilder {
|
|
|
229
229
|
}
|
|
230
230
|
}
|
|
231
231
|
exports.RefBuilder = RefBuilder;
|
|
232
|
+
const resourceRegex = /^projects\/([^/]+)\/instances\/([a-zA-Z0-9-]+)\/refs(\/.+)?/;
|
|
232
233
|
/**
|
|
233
234
|
* Utility function to extract database reference from resource string
|
|
234
235
|
*
|
|
@@ -239,7 +240,6 @@ exports.RefBuilder = RefBuilder;
|
|
|
239
240
|
*/
|
|
240
241
|
/** @hidden */
|
|
241
242
|
function extractInstanceAndPath(resource, domain = 'firebaseio.com') {
|
|
242
|
-
const resourceRegex = `projects/([^/]+)/instances/([a-zA-Z0-9\-^/]+)/refs(/.+)?`;
|
|
243
243
|
const match = resource.match(new RegExp(resourceRegex));
|
|
244
244
|
if (!match) {
|
|
245
245
|
throw new Error(`Unexpected resource string for Firebase Realtime Database event: ${resource}. ` +
|
package/lib/runtime/loader.js
CHANGED
|
@@ -91,11 +91,10 @@ async function loadStack(functionsDir) {
|
|
|
91
91
|
const requiredAPIs = [];
|
|
92
92
|
const mod = await loadModule(functionsDir);
|
|
93
93
|
extractStack(mod, endpoints, requiredAPIs);
|
|
94
|
-
|
|
94
|
+
return {
|
|
95
95
|
endpoints,
|
|
96
96
|
specVersion: 'v1alpha1',
|
|
97
97
|
requiredAPIs: mergeRequiredAPIs(requiredAPIs),
|
|
98
98
|
};
|
|
99
|
-
return stack;
|
|
100
99
|
}
|
|
101
100
|
exports.loadStack = loadStack;
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One or more event filters restrict the set of events delivered to an EventTrigger.
|
|
3
|
+
*/
|
|
4
|
+
interface EventFilter {
|
|
5
|
+
attribute: string;
|
|
6
|
+
value: string;
|
|
7
|
+
operator?: string;
|
|
8
|
+
}
|
|
1
9
|
/**
|
|
2
10
|
* An definition of a function as appears in the Manifest.
|
|
3
11
|
*/
|
|
@@ -18,12 +26,16 @@ export interface ManifestEndpoint {
|
|
|
18
26
|
labels?: Record<string, string>;
|
|
19
27
|
ingressSettings?: string;
|
|
20
28
|
environmentVariables?: Record<string, string>;
|
|
29
|
+
secretEnvironmentVariables?: Array<{
|
|
30
|
+
key: string;
|
|
31
|
+
secret?: string;
|
|
32
|
+
}>;
|
|
21
33
|
httpsTrigger?: {
|
|
22
34
|
invoker?: string[];
|
|
23
35
|
};
|
|
24
36
|
callableTrigger?: {};
|
|
25
37
|
eventTrigger?: {
|
|
26
|
-
eventFilters:
|
|
38
|
+
eventFilters: EventFilter[];
|
|
27
39
|
eventType: string;
|
|
28
40
|
retry: boolean;
|
|
29
41
|
region?: string;
|
|
@@ -47,9 +59,10 @@ export interface ManifestRequiredAPI {
|
|
|
47
59
|
}
|
|
48
60
|
/**
|
|
49
61
|
* An definition of a function deployment as appears in the Manifest.
|
|
50
|
-
|
|
62
|
+
*/
|
|
51
63
|
export interface ManifestStack {
|
|
52
64
|
specVersion: 'v1alpha1';
|
|
53
65
|
requiredAPIs: ManifestRequiredAPI[];
|
|
54
66
|
endpoints: Record<string, ManifestEndpoint>;
|
|
55
67
|
}
|
|
68
|
+
export {};
|
package/lib/v2/options.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { ParamSpec } from './params/types';
|
|
|
2
2
|
/**
|
|
3
3
|
* List of all regions supported by Cloud Functions v2
|
|
4
4
|
*/
|
|
5
|
-
export declare const SUPPORTED_REGIONS: readonly ["
|
|
5
|
+
export declare const SUPPORTED_REGIONS: readonly ["asia-northeast1", "europe-north1", "europe-west1", "europe-west4", "us-central1", "us-east1", "us-west1"];
|
|
6
6
|
/**
|
|
7
7
|
* A region known to be supported by CloudFunctions v2
|
|
8
8
|
*/
|
|
@@ -26,7 +26,7 @@ export declare const MAX_CONCURRENCY = 1000;
|
|
|
26
26
|
/**
|
|
27
27
|
* List of available memory options supported by Cloud Functions.
|
|
28
28
|
*/
|
|
29
|
-
export declare const SUPPORTED_MEMORY_OPTIONS: readonly ["256MB", "512MB", "1GB", "2GB", "4GB", "8GB"];
|
|
29
|
+
export declare const SUPPORTED_MEMORY_OPTIONS: readonly ["128MB", "256MB", "512MB", "1GB", "2GB", "4GB", "8GB", "16GB", "32GB"];
|
|
30
30
|
/**
|
|
31
31
|
* A supported memory option.
|
|
32
32
|
*/
|
package/lib/v2/options.js
CHANGED
|
@@ -29,10 +29,13 @@ const params_1 = require("./params");
|
|
|
29
29
|
* List of all regions supported by Cloud Functions v2
|
|
30
30
|
*/
|
|
31
31
|
exports.SUPPORTED_REGIONS = [
|
|
32
|
-
'us-west1',
|
|
33
|
-
'us-central1',
|
|
34
|
-
'europe-west4',
|
|
35
32
|
'asia-northeast1',
|
|
33
|
+
'europe-north1',
|
|
34
|
+
'europe-west1',
|
|
35
|
+
'europe-west4',
|
|
36
|
+
'us-central1',
|
|
37
|
+
'us-east1',
|
|
38
|
+
'us-west1',
|
|
36
39
|
];
|
|
37
40
|
/**
|
|
38
41
|
* Cloud Functions v2 min timeout value.
|
|
@@ -54,20 +57,26 @@ exports.MAX_CONCURRENCY = 1000;
|
|
|
54
57
|
* List of available memory options supported by Cloud Functions.
|
|
55
58
|
*/
|
|
56
59
|
exports.SUPPORTED_MEMORY_OPTIONS = [
|
|
60
|
+
'128MB',
|
|
57
61
|
'256MB',
|
|
58
62
|
'512MB',
|
|
59
63
|
'1GB',
|
|
60
64
|
'2GB',
|
|
61
65
|
'4GB',
|
|
62
66
|
'8GB',
|
|
67
|
+
'16GB',
|
|
68
|
+
'32GB',
|
|
63
69
|
];
|
|
64
70
|
const MemoryOptionToMB = {
|
|
71
|
+
'128MB': 128,
|
|
65
72
|
'256MB': 256,
|
|
66
73
|
'512MB': 512,
|
|
67
74
|
'1GB': 1024,
|
|
68
75
|
'2GB': 2048,
|
|
69
76
|
'4GB': 4096,
|
|
70
77
|
'8GB': 8192,
|
|
78
|
+
'16GB': 16384,
|
|
79
|
+
'32GB': 32768,
|
|
71
80
|
};
|
|
72
81
|
/**
|
|
73
82
|
* List of available options for VpcConnectorEgressSettings.
|
|
@@ -36,14 +36,20 @@ function getEndpointAnnotation(opts, alertType, appId) {
|
|
|
36
36
|
},
|
|
37
37
|
eventTrigger: {
|
|
38
38
|
eventType: exports.eventType,
|
|
39
|
-
eventFilters:
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
eventFilters: [
|
|
40
|
+
{
|
|
41
|
+
attribute: 'alerttype',
|
|
42
|
+
value: alertType,
|
|
43
|
+
},
|
|
44
|
+
],
|
|
42
45
|
retry: !!opts.retry,
|
|
43
46
|
},
|
|
44
47
|
};
|
|
45
48
|
if (appId) {
|
|
46
|
-
endpoint.eventTrigger.eventFilters.
|
|
49
|
+
endpoint.eventTrigger.eventFilters.push({
|
|
50
|
+
attribute: 'appid',
|
|
51
|
+
value: appId,
|
|
52
|
+
});
|
|
47
53
|
}
|
|
48
54
|
return endpoint;
|
|
49
55
|
}
|
|
@@ -33,6 +33,6 @@ export declare function onPlanUpdatePublished(opts: options.EventHandlerOptions,
|
|
|
33
33
|
/**
|
|
34
34
|
* Declares a function that can handle an automated billing plan update event.
|
|
35
35
|
*/
|
|
36
|
-
export declare function
|
|
37
|
-
export declare function
|
|
36
|
+
export declare function onPlanAutomatedUpdatePublished(handler: (event: BillingEvent<PlanAutomatedUpdatePayload>) => any | Promise<any>): CloudFunction<FirebaseAlertData<PlanAutomatedUpdatePayload>>;
|
|
37
|
+
export declare function onPlanAutomatedUpdatePublished(opts: options.EventHandlerOptions, handler: (event: BillingEvent<PlanAutomatedUpdatePayload>) => any | Promise<any>): CloudFunction<FirebaseAlertData<PlanAutomatedUpdatePayload>>;
|
|
38
38
|
export {};
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.onOperation = exports.
|
|
3
|
+
exports.onOperation = exports.onPlanAutomatedUpdatePublished = exports.onPlanUpdatePublished = exports.planAutomatedUpdateAlert = exports.planUpdateAlert = void 0;
|
|
4
4
|
const _1 = require(".");
|
|
5
5
|
/** @internal */
|
|
6
6
|
exports.planUpdateAlert = 'billing.planUpdate';
|
|
7
7
|
/** @internal */
|
|
8
|
-
exports.
|
|
8
|
+
exports.planAutomatedUpdateAlert = 'billing.planAutomatedUpdate';
|
|
9
9
|
function onPlanUpdatePublished(optsOrHandler, handler) {
|
|
10
10
|
return onOperation(exports.planUpdateAlert, optsOrHandler, handler);
|
|
11
11
|
}
|
|
12
12
|
exports.onPlanUpdatePublished = onPlanUpdatePublished;
|
|
13
|
-
function
|
|
14
|
-
return onOperation(exports.
|
|
13
|
+
function onPlanAutomatedUpdatePublished(optsOrHandler, handler) {
|
|
14
|
+
return onOperation(exports.planAutomatedUpdateAlert, optsOrHandler, handler);
|
|
15
15
|
}
|
|
16
|
-
exports.
|
|
16
|
+
exports.onPlanAutomatedUpdatePublished = onPlanAutomatedUpdatePublished;
|
|
17
17
|
/** @internal */
|
|
18
18
|
function onOperation(alertType, optsOrHandler, handler) {
|
|
19
19
|
if (typeof optsOrHandler === 'function') {
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -104,7 +104,7 @@ function onMessagePublished(topicOrOptions, handler) {
|
|
|
104
104
|
},
|
|
105
105
|
eventTrigger: {
|
|
106
106
|
eventType: 'google.cloud.pubsub.topic.v1.messagePublished',
|
|
107
|
-
eventFilters: { topic },
|
|
107
|
+
eventFilters: [{ attribute: 'topic', value: topic }],
|
|
108
108
|
retry: false,
|
|
109
109
|
},
|
|
110
110
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "firebase-functions",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.19.0",
|
|
4
4
|
"description": "Firebase SDK for Cloud Functions",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"firebase",
|
|
@@ -149,7 +149,7 @@
|
|
|
149
149
|
"format:fix": "prettier --write '**/*.{json,md,ts,yml,yaml}'",
|
|
150
150
|
"lint": "tslint --config tslint.json --project tsconfig.json ",
|
|
151
151
|
"lint:fix": "tslint --config tslint.json --fix --project tsconfig.json",
|
|
152
|
-
"test": "mocha --file ./mocha/setup.ts spec/**/*.spec.ts
|
|
152
|
+
"test": "mocha --file ./mocha/setup.ts \"spec/**/*.spec.ts\"",
|
|
153
153
|
"test:bin": "./scripts/bin-test/run.sh"
|
|
154
154
|
},
|
|
155
155
|
"dependencies": {
|