firebase-functions 3.21.0 → 3.22.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 +21 -0
- package/lib/cloud-functions.d.ts +54 -88
- package/lib/cloud-functions.js +2 -59
- package/lib/common/change.d.ts +46 -0
- package/lib/common/change.js +82 -0
- package/lib/common/encoding.js +21 -1
- package/lib/common/providers/database.d.ts +145 -0
- package/lib/common/providers/database.js +271 -0
- package/lib/common/providers/https.d.ts +37 -17
- package/lib/common/providers/https.js +3 -0
- package/lib/common/providers/identity.d.ts +5 -1
- package/lib/common/providers/identity.js +12 -4
- package/lib/common/providers/tasks.d.ts +9 -0
- package/lib/common/providers/tasks.js +13 -12
- package/lib/function-builder.d.ts +3 -3
- package/lib/function-builder.js +2 -2
- package/lib/logger/common.js +21 -0
- package/lib/logger/compat.js +21 -0
- package/lib/logger/index.d.ts +14 -6
- package/lib/logger/index.js +33 -6
- package/lib/providers/auth.d.ts +26 -5
- package/lib/providers/auth.js +18 -4
- package/lib/providers/database.d.ts +4 -146
- package/lib/providers/database.js +7 -251
- package/lib/providers/firestore.d.ts +2 -1
- package/lib/providers/firestore.js +2 -1
- package/lib/providers/pubsub.d.ts +6 -6
- package/lib/providers/pubsub.js +6 -6
- package/lib/providers/tasks.d.ts +29 -14
- package/lib/providers/tasks.js +10 -3
- package/lib/utilities/path-pattern.d.ts +1 -0
- package/lib/utilities/path-pattern.js +142 -0
- package/lib/v2/core.d.ts +25 -1
- package/lib/v2/core.js +7 -0
- package/lib/v2/index.d.ts +11 -3
- package/lib/v2/index.js +12 -3
- package/lib/v2/options.d.ts +13 -34
- package/lib/v2/options.js +6 -58
- package/lib/v2/params/index.d.ts +4 -1
- package/lib/v2/params/index.js +25 -1
- package/lib/v2/params/types.js +21 -0
- package/lib/v2/providers/alerts/alerts.d.ts +94 -3
- package/lib/v2/providers/alerts/alerts.js +23 -7
- package/lib/v2/providers/alerts/appDistribution.d.ts +101 -1
- package/lib/v2/providers/alerts/appDistribution.js +28 -1
- package/lib/v2/providers/alerts/billing.d.ts +23 -2
- package/lib/v2/providers/alerts/billing.js +37 -0
- package/lib/v2/providers/alerts/crashlytics.d.ts +193 -18
- package/lib/v2/providers/alerts/crashlytics.js +62 -1
- package/lib/v2/providers/alerts/index.d.ts +6 -0
- package/lib/v2/providers/alerts/index.js +27 -0
- package/lib/v2/providers/database.d.ts +182 -0
- package/lib/v2/providers/database.js +204 -0
- package/lib/v2/providers/eventarc.d.ts +89 -5
- package/lib/v2/providers/eventarc.js +4 -0
- package/lib/v2/providers/https.d.ts +123 -2
- package/lib/v2/providers/https.js +13 -3
- package/lib/v2/providers/identity.d.ts +108 -4
- package/lib/v2/providers/identity.js +33 -2
- package/lib/v2/providers/pubsub.d.ts +122 -5
- package/lib/v2/providers/pubsub.js +58 -2
- package/lib/v2/providers/storage.d.ts +192 -4
- package/lib/v2/providers/storage.js +52 -9
- package/lib/v2/providers/tasks.d.ts +106 -6
- package/lib/v2/providers/tasks.js +4 -0
- package/package.json +12 -6
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// The MIT License (MIT)
|
|
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.onOperation = exports.onChangedOperation = exports.makeEndpoint = exports.makeParams = exports.getOpts = exports.onValueDeleted = exports.onValueUpdated = exports.onValueCreated = exports.onValueWritten = exports.deletedEventType = exports.updatedEventType = exports.createdEventType = exports.writtenEventType = exports.DataSnapshot = void 0;
|
|
25
|
+
const apps_1 = require("../../apps");
|
|
26
|
+
const database_1 = require("../../common/providers/database");
|
|
27
|
+
Object.defineProperty(exports, "DataSnapshot", { enumerable: true, get: function () { return database_1.DataSnapshot; } });
|
|
28
|
+
const path_1 = require("../../utilities/path");
|
|
29
|
+
const path_pattern_1 = require("../../utilities/path-pattern");
|
|
30
|
+
const utils_1 = require("../../utils");
|
|
31
|
+
const options = require("../options");
|
|
32
|
+
/** @internal */
|
|
33
|
+
exports.writtenEventType = 'google.firebase.database.ref.v1.written';
|
|
34
|
+
/** @internal */
|
|
35
|
+
exports.createdEventType = 'google.firebase.database.ref.v1.created';
|
|
36
|
+
/** @internal */
|
|
37
|
+
exports.updatedEventType = 'google.firebase.database.ref.v1.updated';
|
|
38
|
+
/** @internal */
|
|
39
|
+
exports.deletedEventType = 'google.firebase.database.ref.v1.deleted';
|
|
40
|
+
/**
|
|
41
|
+
* Event handler which triggers when data is created, updated, or deleted in Realtime Database.
|
|
42
|
+
*
|
|
43
|
+
* @param referenceOrOpts - Options or a string reference.
|
|
44
|
+
* @param handler - Event handler which is run every time a Realtime Database create, update, or delete occurs.
|
|
45
|
+
*/
|
|
46
|
+
function onValueWritten(referenceOrOpts, handler) {
|
|
47
|
+
return onChangedOperation(exports.writtenEventType, referenceOrOpts, handler);
|
|
48
|
+
}
|
|
49
|
+
exports.onValueWritten = onValueWritten;
|
|
50
|
+
/**
|
|
51
|
+
* Event handler which triggers when data is created in Realtime Database.
|
|
52
|
+
*
|
|
53
|
+
* @param referenceOrOpts - Options or a string reference.
|
|
54
|
+
* @param handler - Event handler which is run every time a Realtime Database create occurs.
|
|
55
|
+
*/
|
|
56
|
+
function onValueCreated(referenceOrOpts, handler) {
|
|
57
|
+
return onOperation(exports.createdEventType, referenceOrOpts, handler);
|
|
58
|
+
}
|
|
59
|
+
exports.onValueCreated = onValueCreated;
|
|
60
|
+
/**
|
|
61
|
+
* Event handler which triggers when data is updated in Realtime Database.
|
|
62
|
+
*
|
|
63
|
+
* @param referenceOrOpts - Options or a string reference.
|
|
64
|
+
* @param handler - Event handler which is run every time a Realtime Database update occurs.
|
|
65
|
+
*/
|
|
66
|
+
function onValueUpdated(referenceOrOpts, handler) {
|
|
67
|
+
return onChangedOperation(exports.updatedEventType, referenceOrOpts, handler);
|
|
68
|
+
}
|
|
69
|
+
exports.onValueUpdated = onValueUpdated;
|
|
70
|
+
/**
|
|
71
|
+
* Event handler which triggers when data is deleted in Realtime Database.
|
|
72
|
+
*
|
|
73
|
+
* @param referenceOrOpts - Options or a string reference.
|
|
74
|
+
* @param handler - Event handler which is run every time a Realtime Database deletion occurs.
|
|
75
|
+
*/
|
|
76
|
+
function onValueDeleted(referenceOrOpts, handler) {
|
|
77
|
+
// TODO - need to use event.data.delta
|
|
78
|
+
return onOperation(exports.deletedEventType, referenceOrOpts, handler);
|
|
79
|
+
}
|
|
80
|
+
exports.onValueDeleted = onValueDeleted;
|
|
81
|
+
/** @internal */
|
|
82
|
+
function getOpts(referenceOrOpts) {
|
|
83
|
+
let path, instance, opts;
|
|
84
|
+
if (typeof referenceOrOpts === 'string') {
|
|
85
|
+
path = (0, path_1.normalizePath)(referenceOrOpts);
|
|
86
|
+
instance = '*';
|
|
87
|
+
opts = {};
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
path = (0, path_1.normalizePath)(referenceOrOpts.ref);
|
|
91
|
+
instance = referenceOrOpts.instance || '*';
|
|
92
|
+
opts = { ...referenceOrOpts };
|
|
93
|
+
delete opts.ref;
|
|
94
|
+
delete opts.instance;
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
path,
|
|
98
|
+
instance,
|
|
99
|
+
opts,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
exports.getOpts = getOpts;
|
|
103
|
+
/** @internal */
|
|
104
|
+
function makeParams(event, path, instance) {
|
|
105
|
+
return {
|
|
106
|
+
...path.extractMatches(event.ref),
|
|
107
|
+
...instance.extractMatches(event.instance),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
exports.makeParams = makeParams;
|
|
111
|
+
/** @hidden */
|
|
112
|
+
function makeDatabaseEvent(event, data, instance, params) {
|
|
113
|
+
const snapshot = new database_1.DataSnapshot(data, event.ref, (0, apps_1.apps)().admin, instance);
|
|
114
|
+
const databaseEvent = {
|
|
115
|
+
...event,
|
|
116
|
+
firebaseDatabaseHost: event.firebasedatabasehost,
|
|
117
|
+
data: snapshot,
|
|
118
|
+
params,
|
|
119
|
+
};
|
|
120
|
+
delete databaseEvent.firebasedatabasehost;
|
|
121
|
+
return databaseEvent;
|
|
122
|
+
}
|
|
123
|
+
/** @hidden */
|
|
124
|
+
function makeChangedDatabaseEvent(event, instance, params) {
|
|
125
|
+
const before = new database_1.DataSnapshot(event.data.data, event.ref, (0, apps_1.apps)().admin, instance);
|
|
126
|
+
const after = new database_1.DataSnapshot((0, utils_1.applyChange)(event.data.data, event.data.delta), event.ref, (0, apps_1.apps)().admin, instance);
|
|
127
|
+
const databaseEvent = {
|
|
128
|
+
...event,
|
|
129
|
+
firebaseDatabaseHost: event.firebasedatabasehost,
|
|
130
|
+
data: {
|
|
131
|
+
before,
|
|
132
|
+
after,
|
|
133
|
+
},
|
|
134
|
+
params,
|
|
135
|
+
};
|
|
136
|
+
delete databaseEvent.firebasedatabasehost;
|
|
137
|
+
return databaseEvent;
|
|
138
|
+
}
|
|
139
|
+
/** @internal */
|
|
140
|
+
function makeEndpoint(eventType, opts, path, instance) {
|
|
141
|
+
const baseOpts = options.optionsToEndpoint(options.getGlobalOptions());
|
|
142
|
+
const specificOpts = options.optionsToEndpoint(opts);
|
|
143
|
+
const eventFilters = {};
|
|
144
|
+
const eventFilterPathPatterns = {
|
|
145
|
+
// Note: Eventarc always treats ref as a path pattern
|
|
146
|
+
ref: path.getValue(),
|
|
147
|
+
};
|
|
148
|
+
instance.hasWildcards()
|
|
149
|
+
? (eventFilterPathPatterns.instance = instance.getValue())
|
|
150
|
+
: (eventFilters.instance = instance.getValue());
|
|
151
|
+
return {
|
|
152
|
+
platform: 'gcfv2',
|
|
153
|
+
...baseOpts,
|
|
154
|
+
...specificOpts,
|
|
155
|
+
labels: {
|
|
156
|
+
...baseOpts === null || baseOpts === void 0 ? void 0 : baseOpts.labels,
|
|
157
|
+
...specificOpts === null || specificOpts === void 0 ? void 0 : specificOpts.labels,
|
|
158
|
+
},
|
|
159
|
+
eventTrigger: {
|
|
160
|
+
eventType,
|
|
161
|
+
eventFilters,
|
|
162
|
+
eventFilterPathPatterns,
|
|
163
|
+
retry: false,
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
exports.makeEndpoint = makeEndpoint;
|
|
168
|
+
/** @internal */
|
|
169
|
+
function onChangedOperation(eventType, referenceOrOpts, handler) {
|
|
170
|
+
const { path, instance, opts } = getOpts(referenceOrOpts);
|
|
171
|
+
const pathPattern = new path_pattern_1.PathPattern(path);
|
|
172
|
+
const instancePattern = new path_pattern_1.PathPattern(instance);
|
|
173
|
+
// wrap the handler
|
|
174
|
+
const func = (raw) => {
|
|
175
|
+
const event = raw;
|
|
176
|
+
const instanceUrl = `https://${event.instance}.${event.firebasedatabasehost}`;
|
|
177
|
+
const params = makeParams(event, pathPattern, instancePattern);
|
|
178
|
+
const databaseEvent = makeChangedDatabaseEvent(event, instanceUrl, params);
|
|
179
|
+
return handler(databaseEvent);
|
|
180
|
+
};
|
|
181
|
+
func.run = handler;
|
|
182
|
+
func.__endpoint = makeEndpoint(eventType, opts, pathPattern, instancePattern);
|
|
183
|
+
return func;
|
|
184
|
+
}
|
|
185
|
+
exports.onChangedOperation = onChangedOperation;
|
|
186
|
+
/** @internal */
|
|
187
|
+
function onOperation(eventType, referenceOrOpts, handler) {
|
|
188
|
+
const { path, instance, opts } = getOpts(referenceOrOpts);
|
|
189
|
+
const pathPattern = new path_pattern_1.PathPattern(path);
|
|
190
|
+
const instancePattern = new path_pattern_1.PathPattern(instance);
|
|
191
|
+
// wrap the handler
|
|
192
|
+
const func = (raw) => {
|
|
193
|
+
const event = raw;
|
|
194
|
+
const instanceUrl = `https://${event.instance}.${event.firebasedatabasehost}`;
|
|
195
|
+
const params = makeParams(event, pathPattern, instancePattern);
|
|
196
|
+
const data = eventType === exports.deletedEventType ? event.data.data : event.data.delta;
|
|
197
|
+
const databaseEvent = makeDatabaseEvent(event, data, instanceUrl, params);
|
|
198
|
+
return handler(databaseEvent);
|
|
199
|
+
};
|
|
200
|
+
func.run = handler;
|
|
201
|
+
func.__endpoint = makeEndpoint(eventType, opts, pathPattern, instancePattern);
|
|
202
|
+
return func;
|
|
203
|
+
}
|
|
204
|
+
exports.onOperation = onOperation;
|
|
@@ -3,7 +3,7 @@ import * as options from '../options';
|
|
|
3
3
|
/** Options that can be set on an Eventarc trigger. */
|
|
4
4
|
export interface EventarcTriggerOptions extends options.EventHandlerOptions {
|
|
5
5
|
/**
|
|
6
|
-
* Type of the event.
|
|
6
|
+
* Type of the event to trigger on.
|
|
7
7
|
*/
|
|
8
8
|
eventType: string;
|
|
9
9
|
/**
|
|
@@ -25,8 +25,92 @@ export interface EventarcTriggerOptions extends options.EventHandlerOptions {
|
|
|
25
25
|
* Eventarc event exact match filter.
|
|
26
26
|
*/
|
|
27
27
|
filters?: Record<string, string>;
|
|
28
|
+
/**
|
|
29
|
+
* Region where functions should be deployed.
|
|
30
|
+
*/
|
|
31
|
+
region?: options.SupportedRegion | string;
|
|
32
|
+
/**
|
|
33
|
+
* Amount of memory to allocate to a function.
|
|
34
|
+
* A value of null restores the defaults of 256MB.
|
|
35
|
+
*/
|
|
36
|
+
memory?: options.MemoryOption | null;
|
|
37
|
+
/**
|
|
38
|
+
* Timeout for the function in sections, possible values are 0 to 540.
|
|
39
|
+
* HTTPS functions can specify a higher timeout.
|
|
40
|
+
* A value of null restores the default of 60s
|
|
41
|
+
* The minimum timeout for a gen 2 function is 1s. The maximum timeout for a
|
|
42
|
+
* function depends on the type of function: Event handling functions have a
|
|
43
|
+
* maximum timeout of 540s (9 minutes). HTTPS and callable functions have a
|
|
44
|
+
* maximum timeout of 36,00s (1 hour). Task queue functions have a maximum
|
|
45
|
+
* timeout of 1,800s (30 minutes)
|
|
46
|
+
*/
|
|
47
|
+
timeoutSeconds?: number | null;
|
|
48
|
+
/**
|
|
49
|
+
* Min number of actual instances to be running at a given time.
|
|
50
|
+
* Instances will be billed for memory allocation and 10% of CPU allocation
|
|
51
|
+
* while idle.
|
|
52
|
+
* A value of null restores the default min instances.
|
|
53
|
+
*/
|
|
54
|
+
minInstances?: number | null;
|
|
55
|
+
/**
|
|
56
|
+
* Max number of instances to be running in parallel.
|
|
57
|
+
* A value of null restores the default max instances.
|
|
58
|
+
*/
|
|
59
|
+
maxInstances?: number | null;
|
|
60
|
+
/**
|
|
61
|
+
* Number of requests a function can serve at once.
|
|
62
|
+
* Can only be applied to functions running on Cloud Functions v2.
|
|
63
|
+
* A value of null restores the default concurrency (80 when CPU >= 1, 1 otherwise).
|
|
64
|
+
* Concurrency cannot be set to any value other than 1 if `cpu` is less than 1.
|
|
65
|
+
* The maximum value for concurrency is 1,000.
|
|
66
|
+
*/
|
|
67
|
+
concurrency?: number | null;
|
|
68
|
+
/**
|
|
69
|
+
* Fractional number of CPUs to allocate to a function.
|
|
70
|
+
* Defaults to 1 for functions with <= 2GB RAM and increases for larger memory sizes.
|
|
71
|
+
* This is different from the defaults when using the gcloud utility and is different from
|
|
72
|
+
* the fixed amount assigned in Google Cloud Functions generation 1.
|
|
73
|
+
* To revert to the CPU amounts used in gcloud or in Cloud Functions generation 1, set this
|
|
74
|
+
* to the value "gcf_gen1"
|
|
75
|
+
*/
|
|
76
|
+
cpu?: number | 'gcf_gen1';
|
|
77
|
+
/**
|
|
78
|
+
* Connect cloud function to specified VPC connector.
|
|
79
|
+
* A value of null removes the VPC connector
|
|
80
|
+
*/
|
|
81
|
+
vpcConnector?: string | null;
|
|
82
|
+
/**
|
|
83
|
+
* Egress settings for VPC connector.
|
|
84
|
+
* A value of null turns off VPC connector egress settings
|
|
85
|
+
*/
|
|
86
|
+
vpcConnectorEgressSettings?: options.VpcEgressSetting | null;
|
|
87
|
+
/**
|
|
88
|
+
* Specific service account for the function to run as.
|
|
89
|
+
* A value of null restores the default service account.
|
|
90
|
+
*/
|
|
91
|
+
serviceAccount?: string | null;
|
|
92
|
+
/**
|
|
93
|
+
* Ingress settings which control where this function can be called from.
|
|
94
|
+
* A value of null turns off ingress settings.
|
|
95
|
+
*/
|
|
96
|
+
ingressSettings?: options.IngressSetting | null;
|
|
97
|
+
/**
|
|
98
|
+
* User labels to set on the function.
|
|
99
|
+
*/
|
|
100
|
+
labels?: Record<string, string>;
|
|
101
|
+
secrets?: string[];
|
|
102
|
+
/** Whether failed executions should be delivered again. */
|
|
103
|
+
retry?: boolean;
|
|
28
104
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
105
|
+
/** Handles an Eventarc event published on the default channel.
|
|
106
|
+
* @param eventType - Type of the event to trigger on.
|
|
107
|
+
* @param handler - A function to execute when triggered.
|
|
108
|
+
* @returns A function that you can export and deploy.
|
|
109
|
+
*/
|
|
110
|
+
export declare function onCustomEventPublished<T = any>(eventType: string, handler: (event: CloudEvent<T>) => any | Promise<any>): CloudFunction<CloudEvent<T>>;
|
|
111
|
+
/** Handles an Eventarc event.
|
|
112
|
+
* @param opts - Options to set on this function
|
|
113
|
+
* @param handler - A function to execute when triggered.
|
|
114
|
+
* @returns A function that you can export and deploy.
|
|
115
|
+
*/
|
|
116
|
+
export declare function onCustomEventPublished<T = any>(opts: EventarcTriggerOptions, handler: (event: CloudEvent<T>) => any | Promise<any>): CloudFunction<CloudEvent<T>>;
|
|
@@ -22,6 +22,10 @@
|
|
|
22
22
|
// SOFTWARE.
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
24
|
exports.onCustomEventPublished = void 0;
|
|
25
|
+
/**
|
|
26
|
+
* Cloud functions to integrate directly with Eventarc.
|
|
27
|
+
* @packageDocumentation
|
|
28
|
+
*/
|
|
25
29
|
const encoding_1 = require("../../common/encoding");
|
|
26
30
|
const options = require("../options");
|
|
27
31
|
function onCustomEventPublished(eventTypeOrOpts, handler) {
|
|
@@ -1,23 +1,144 @@
|
|
|
1
1
|
import * as express from 'express';
|
|
2
2
|
import { CallableRequest, FunctionsErrorCode, HttpsError, Request } from '../../common/providers/https';
|
|
3
3
|
import { ManifestEndpoint } from '../../runtime/manifest';
|
|
4
|
+
import * as options from '../options';
|
|
4
5
|
import { GlobalOptions, SupportedRegion } from '../options';
|
|
5
6
|
export { Request, CallableRequest, FunctionsErrorCode, HttpsError };
|
|
6
7
|
/**
|
|
7
|
-
* Options that can be set on an individual HTTPS
|
|
8
|
+
* Options that can be set on an individual HTTPS function.
|
|
8
9
|
*/
|
|
9
10
|
export interface HttpsOptions extends Omit<GlobalOptions, 'region'> {
|
|
11
|
+
/** HTTP functions can override global options and can specify multiple regions to deploy to. */
|
|
10
12
|
region?: SupportedRegion | string | Array<SupportedRegion | string>;
|
|
13
|
+
/** If true, allows CORS on requests to this function.
|
|
14
|
+
* If this is a `string` or `RegExp`, allows requests from domains that match the provided value.
|
|
15
|
+
* If this is an `Array`, allows requests from domains matching at least one entry of the array.
|
|
16
|
+
* Defaults to true for {@link https.CallableFunction} and false otherwise.
|
|
17
|
+
*/
|
|
11
18
|
cors?: string | boolean | RegExp | Array<string | RegExp>;
|
|
19
|
+
/**
|
|
20
|
+
* Amount of memory to allocate to a function.
|
|
21
|
+
* A value of null restores the defaults of 256MB.
|
|
22
|
+
*/
|
|
23
|
+
memory?: options.MemoryOption | null;
|
|
24
|
+
/**
|
|
25
|
+
* Timeout for the function in sections, possible values are 0 to 540.
|
|
26
|
+
* HTTPS functions can specify a higher timeout.
|
|
27
|
+
* A value of null restores the default of 60s
|
|
28
|
+
* The minimum timeout for a gen 2 function is 1s. The maximum timeout for a
|
|
29
|
+
* function depends on the type of function: Event handling functions have a
|
|
30
|
+
* maximum timeout of 540s (9 minutes). HTTPS and callable functions have a
|
|
31
|
+
* maximum timeout of 36,00s (1 hour). Task queue functions have a maximum
|
|
32
|
+
* timeout of 1,800s (30 minutes)
|
|
33
|
+
*/
|
|
34
|
+
timeoutSeconds?: number | null;
|
|
35
|
+
/**
|
|
36
|
+
* Min number of actual instances to be running at a given time.
|
|
37
|
+
* Instances will be billed for memory allocation and 10% of CPU allocation
|
|
38
|
+
* while idle.
|
|
39
|
+
* A value of null restores the default min instances.
|
|
40
|
+
*/
|
|
41
|
+
minInstances?: number | null;
|
|
42
|
+
/**
|
|
43
|
+
* Max number of instances to be running in parallel.
|
|
44
|
+
* A value of null restores the default max instances.
|
|
45
|
+
*/
|
|
46
|
+
maxInstances?: number | null;
|
|
47
|
+
/**
|
|
48
|
+
* Number of requests a function can serve at once.
|
|
49
|
+
* Can only be applied to functions running on Cloud Functions v2.
|
|
50
|
+
* A value of null restores the default concurrency (80 when CPU >= 1, 1 otherwise).
|
|
51
|
+
* Concurrency cannot be set to any value other than 1 if `cpu` is less than 1.
|
|
52
|
+
* The maximum value for concurrency is 1,000.
|
|
53
|
+
*/
|
|
54
|
+
concurrency?: number | null;
|
|
55
|
+
/**
|
|
56
|
+
* Fractional number of CPUs to allocate to a function.
|
|
57
|
+
* Defaults to 1 for functions with <= 2GB RAM and increases for larger memory sizes.
|
|
58
|
+
* This is different from the defaults when using the gcloud utility and is different from
|
|
59
|
+
* the fixed amount assigned in Google Cloud Functions generation 1.
|
|
60
|
+
* To revert to the CPU amounts used in gcloud or in Cloud Functions generation 1, set this
|
|
61
|
+
* to the value "gcf_gen1"
|
|
62
|
+
*/
|
|
63
|
+
cpu?: number | 'gcf_gen1';
|
|
64
|
+
/**
|
|
65
|
+
* Connect cloud function to specified VPC connector.
|
|
66
|
+
* A value of null removes the VPC connector
|
|
67
|
+
*/
|
|
68
|
+
vpcConnector?: string | null;
|
|
69
|
+
/**
|
|
70
|
+
* Egress settings for VPC connector.
|
|
71
|
+
* A value of null turns off VPC connector egress settings
|
|
72
|
+
*/
|
|
73
|
+
vpcConnectorEgressSettings?: options.VpcEgressSetting | null;
|
|
74
|
+
/**
|
|
75
|
+
* Specific service account for the function to run as.
|
|
76
|
+
* A value of null restores the default service account.
|
|
77
|
+
*/
|
|
78
|
+
serviceAccount?: string | null;
|
|
79
|
+
/**
|
|
80
|
+
* Ingress settings which control where this function can be called from.
|
|
81
|
+
* A value of null turns off ingress settings.
|
|
82
|
+
*/
|
|
83
|
+
ingressSettings?: options.IngressSetting | null;
|
|
84
|
+
/**
|
|
85
|
+
* User labels to set on the function.
|
|
86
|
+
*/
|
|
87
|
+
labels?: Record<string, string>;
|
|
88
|
+
/**
|
|
89
|
+
* Invoker to set access control on https functions.
|
|
90
|
+
*/
|
|
91
|
+
invoker?: 'public' | 'private' | string | string[];
|
|
92
|
+
secrets?: string[];
|
|
93
|
+
/** Whether failed executions should be delivered again. */
|
|
94
|
+
retry?: boolean;
|
|
12
95
|
}
|
|
13
|
-
|
|
96
|
+
/**
|
|
97
|
+
* Handles HTTPS requests.
|
|
98
|
+
*/
|
|
99
|
+
export declare type HttpsFunction = ((
|
|
100
|
+
/** An Express request object representing the HTTPS call to the function. */
|
|
101
|
+
req: Request,
|
|
102
|
+
/** An Express response object, for this function to respond to callers. */
|
|
103
|
+
res: express.Response) => void | Promise<void>) & {
|
|
104
|
+
/** @alpha */
|
|
14
105
|
__trigger?: unknown;
|
|
106
|
+
/** @alpha */
|
|
15
107
|
__endpoint: ManifestEndpoint;
|
|
16
108
|
};
|
|
109
|
+
/**
|
|
110
|
+
* Creates a callable method for clients to call using a Firebase SDK.
|
|
111
|
+
*/
|
|
17
112
|
export interface CallableFunction<T, Return> extends HttpsFunction {
|
|
113
|
+
/** Executes the handler function with the provided data as input. Used for unit testing.
|
|
114
|
+
* @param data - An input for the handler function.
|
|
115
|
+
* @returns The output of the handler function.
|
|
116
|
+
*/
|
|
18
117
|
run(data: CallableRequest<T>): Return;
|
|
19
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* Handles HTTPS requests.
|
|
121
|
+
* @param opts - Options to set on this function
|
|
122
|
+
* @param handler - A function that takes a {@link https.Request} and response object, same signature as an Express app.
|
|
123
|
+
* @returns A function that you can export and deploy.
|
|
124
|
+
*/
|
|
20
125
|
export declare function onRequest(opts: HttpsOptions, handler: (request: Request, response: express.Response) => void | Promise<void>): HttpsFunction;
|
|
126
|
+
/**
|
|
127
|
+
* Handles HTTPS requests.
|
|
128
|
+
* @param handler - A function that takes a {@link https.Request} and response object, same signature as an Express app.
|
|
129
|
+
* @returns A function that you can export and deploy.
|
|
130
|
+
*/
|
|
21
131
|
export declare function onRequest(handler: (request: Request, response: express.Response) => void | Promise<void>): HttpsFunction;
|
|
132
|
+
/**
|
|
133
|
+
* Declares a callable method for clients to call using a Firebase SDK.
|
|
134
|
+
* @param opts - Options to set on this function.
|
|
135
|
+
* @param handler - A function that takes a {@link https.CallableRequest}.
|
|
136
|
+
* @returns A function that you can export and deploy.
|
|
137
|
+
*/
|
|
22
138
|
export declare function onCall<T = any, Return = any | Promise<any>>(opts: HttpsOptions, handler: (request: CallableRequest<T>) => Return): CallableFunction<T, Return>;
|
|
139
|
+
/**
|
|
140
|
+
* Declares a callable method for clients to call using a Firebase SDK.
|
|
141
|
+
* @param handler - A function that takes a {@link https.CallableRequest}.
|
|
142
|
+
* @returns A function that you can export and deploy.
|
|
143
|
+
*/
|
|
23
144
|
export declare function onCall<T = any, Return = any | Promise<any>>(handler: (request: CallableRequest<T>) => Return): CallableFunction<T, Return>;
|
|
@@ -22,8 +22,13 @@
|
|
|
22
22
|
// SOFTWARE.
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
24
|
exports.onCall = exports.onRequest = exports.HttpsError = void 0;
|
|
25
|
+
/**
|
|
26
|
+
* Cloud functions to handle HTTPS request or callable RPCs.
|
|
27
|
+
* @packageDocumentation
|
|
28
|
+
*/
|
|
25
29
|
const cors = require("cors");
|
|
26
30
|
const encoding_1 = require("../../common/encoding");
|
|
31
|
+
const debug_1 = require("../../common/debug");
|
|
27
32
|
const https_1 = require("../../common/providers/https");
|
|
28
33
|
Object.defineProperty(exports, "HttpsError", { enumerable: true, get: function () { return https_1.HttpsError; } });
|
|
29
34
|
const options = require("../options");
|
|
@@ -36,12 +41,13 @@ function onRequest(optsOrHandler, handler) {
|
|
|
36
41
|
else {
|
|
37
42
|
opts = optsOrHandler;
|
|
38
43
|
}
|
|
39
|
-
if ('cors' in opts) {
|
|
44
|
+
if ((0, debug_1.isDebugFeatureEnabled)('enableCors') || 'cors' in opts) {
|
|
45
|
+
const origin = (0, debug_1.isDebugFeatureEnabled)('enableCors') ? true : opts.cors;
|
|
40
46
|
const userProvidedHandler = handler;
|
|
41
47
|
handler = (req, res) => {
|
|
42
48
|
return new Promise((resolve) => {
|
|
43
49
|
res.on('finish', resolve);
|
|
44
|
-
cors({ origin
|
|
50
|
+
cors({ origin })(req, res, () => {
|
|
45
51
|
resolve(userProvidedHandler(req, res));
|
|
46
52
|
});
|
|
47
53
|
});
|
|
@@ -97,7 +103,11 @@ function onCall(optsOrHandler, handler) {
|
|
|
97
103
|
else {
|
|
98
104
|
opts = optsOrHandler;
|
|
99
105
|
}
|
|
100
|
-
const origin = '
|
|
106
|
+
const origin = (0, debug_1.isDebugFeatureEnabled)('enableCors')
|
|
107
|
+
? true
|
|
108
|
+
: 'cors' in opts
|
|
109
|
+
? opts.cors
|
|
110
|
+
: true;
|
|
101
111
|
// onCallHandler sniffs the function length to determine which API to present.
|
|
102
112
|
// fix the length to prevent api versions from being mismatched.
|
|
103
113
|
const fixedLen = (req) => handler(req);
|
|
@@ -1,22 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cloud functions to handle events from Google Cloud Identity Platform.
|
|
3
|
+
* @packageDocumentation
|
|
4
|
+
*/
|
|
1
5
|
import { BlockingFunction } from '../../cloud-functions';
|
|
2
|
-
import { AuthBlockingEvent, BeforeCreateResponse, BeforeSignInResponse, HttpsError } from '../../common/providers/identity';
|
|
6
|
+
import { AuthBlockingEvent, AuthBlockingEventType, BeforeCreateResponse, BeforeSignInResponse, HttpsError } from '../../common/providers/identity';
|
|
3
7
|
import * as options from '../options';
|
|
4
8
|
export { HttpsError };
|
|
9
|
+
/** @hidden Internally used when parsing the options. */
|
|
10
|
+
interface InternalOptions {
|
|
11
|
+
opts: options.GlobalOptions;
|
|
12
|
+
idToken: boolean;
|
|
13
|
+
accessToken: boolean;
|
|
14
|
+
refreshToken: boolean;
|
|
15
|
+
}
|
|
5
16
|
/**
|
|
6
17
|
* All function options plus idToken, accessToken, and refreshToken.
|
|
7
18
|
*/
|
|
8
|
-
export interface BlockingOptions
|
|
19
|
+
export interface BlockingOptions {
|
|
20
|
+
/** Pass the ID Token credential to the function. */
|
|
9
21
|
idToken?: boolean;
|
|
22
|
+
/** Pass the Access Token credential to the function. */
|
|
10
23
|
accessToken?: boolean;
|
|
24
|
+
/** Pass the Refresh Token credential to the function. */
|
|
11
25
|
refreshToken?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Region where functions should be deployed.
|
|
28
|
+
*/
|
|
29
|
+
region?: options.SupportedRegion | string;
|
|
30
|
+
/**
|
|
31
|
+
* Amount of memory to allocate to a function.
|
|
32
|
+
* A value of null restores the defaults of 256MB.
|
|
33
|
+
*/
|
|
34
|
+
memory?: options.MemoryOption | null;
|
|
35
|
+
/**
|
|
36
|
+
* Timeout for the function in sections, possible values are 0 to 540.
|
|
37
|
+
* HTTPS functions can specify a higher timeout.
|
|
38
|
+
* A value of null restores the default of 60s
|
|
39
|
+
* The minimum timeout for a gen 2 function is 1s. The maximum timeout for a
|
|
40
|
+
* function depends on the type of function: Event handling functions have a
|
|
41
|
+
* maximum timeout of 540s (9 minutes). HTTPS and callable functions have a
|
|
42
|
+
* maximum timeout of 36,00s (1 hour). Task queue functions have a maximum
|
|
43
|
+
* timeout of 1,800s (30 minutes)
|
|
44
|
+
*/
|
|
45
|
+
timeoutSeconds?: number | null;
|
|
46
|
+
/**
|
|
47
|
+
* Min number of actual instances to be running at a given time.
|
|
48
|
+
* Instances will be billed for memory allocation and 10% of CPU allocation
|
|
49
|
+
* while idle.
|
|
50
|
+
* A value of null restores the default min instances.
|
|
51
|
+
*/
|
|
52
|
+
minInstances?: number | null;
|
|
53
|
+
/**
|
|
54
|
+
* Max number of instances to be running in parallel.
|
|
55
|
+
* A value of null restores the default max instances.
|
|
56
|
+
*/
|
|
57
|
+
maxInstances?: number | null;
|
|
58
|
+
/**
|
|
59
|
+
* Number of requests a function can serve at once.
|
|
60
|
+
* Can only be applied to functions running on Cloud Functions v2.
|
|
61
|
+
* A value of null restores the default concurrency (80 when CPU >= 1, 1 otherwise).
|
|
62
|
+
* Concurrency cannot be set to any value other than 1 if `cpu` is less than 1.
|
|
63
|
+
* The maximum value for concurrency is 1,000.
|
|
64
|
+
*/
|
|
65
|
+
concurrency?: number | null;
|
|
66
|
+
/**
|
|
67
|
+
* Fractional number of CPUs to allocate to a function.
|
|
68
|
+
* Defaults to 1 for functions with <= 2GB RAM and increases for larger memory sizes.
|
|
69
|
+
* This is different from the defaults when using the gcloud utility and is different from
|
|
70
|
+
* the fixed amount assigned in Google Cloud Functions generation 1.
|
|
71
|
+
* To revert to the CPU amounts used in gcloud or in Cloud Functions generation 1, set this
|
|
72
|
+
* to the value "gcf_gen1"
|
|
73
|
+
*/
|
|
74
|
+
cpu?: number | 'gcf_gen1';
|
|
75
|
+
/**
|
|
76
|
+
* Connect cloud function to specified VPC connector.
|
|
77
|
+
* A value of null removes the VPC connector
|
|
78
|
+
*/
|
|
79
|
+
vpcConnector?: string | null;
|
|
80
|
+
/**
|
|
81
|
+
* Egress settings for VPC connector.
|
|
82
|
+
* A value of null turns off VPC connector egress settings
|
|
83
|
+
*/
|
|
84
|
+
vpcConnectorEgressSettings?: options.VpcEgressSetting | null;
|
|
85
|
+
/**
|
|
86
|
+
* Specific service account for the function to run as.
|
|
87
|
+
* A value of null restores the default service account.
|
|
88
|
+
*/
|
|
89
|
+
serviceAccount?: string | null;
|
|
90
|
+
/**
|
|
91
|
+
* Ingress settings which control where this function can be called from.
|
|
92
|
+
* A value of null turns off ingress settings.
|
|
93
|
+
*/
|
|
94
|
+
ingressSettings?: options.IngressSetting | null;
|
|
95
|
+
/**
|
|
96
|
+
* User labels to set on the function.
|
|
97
|
+
*/
|
|
98
|
+
labels?: Record<string, string>;
|
|
99
|
+
secrets?: string[];
|
|
12
100
|
}
|
|
13
101
|
/**
|
|
14
|
-
*
|
|
102
|
+
* Handles an event that is triggered before a user is created.
|
|
103
|
+
* @param handler - Event handler which is run every time before a user is created
|
|
15
104
|
*/
|
|
16
105
|
export declare function beforeUserCreated(handler: (event: AuthBlockingEvent) => BeforeCreateResponse | Promise<BeforeCreateResponse> | void | Promise<void>): BlockingFunction;
|
|
106
|
+
/**
|
|
107
|
+
* Handles an event that is triggered before a user is created.
|
|
108
|
+
* @param opts - Object containing function options
|
|
109
|
+
* @param handler - Event handler which is run every time before a user is created
|
|
110
|
+
*/
|
|
17
111
|
export declare function beforeUserCreated(opts: BlockingOptions, handler: (event: AuthBlockingEvent) => BeforeCreateResponse | Promise<BeforeCreateResponse> | void | Promise<void>): BlockingFunction;
|
|
18
112
|
/**
|
|
19
|
-
*
|
|
113
|
+
* Handles an event that is triggered before a user is signed in.
|
|
114
|
+
* @param handler - Event handler which is run every time before a user is signed in
|
|
20
115
|
*/
|
|
21
116
|
export declare function beforeUserSignedIn(handler: (event: AuthBlockingEvent) => BeforeSignInResponse | Promise<BeforeSignInResponse> | void | Promise<void>): BlockingFunction;
|
|
117
|
+
/**
|
|
118
|
+
* Handles an event that is triggered before a user is signed in.
|
|
119
|
+
* @param opts - Object containing function options
|
|
120
|
+
* @param handler - Event handler which is run every time before a user is signed in
|
|
121
|
+
*/
|
|
22
122
|
export declare function beforeUserSignedIn(opts: BlockingOptions, handler: (event: AuthBlockingEvent) => BeforeSignInResponse | Promise<BeforeSignInResponse> | void | Promise<void>): BlockingFunction;
|
|
123
|
+
/** @hidden */
|
|
124
|
+
export declare function beforeOperation(eventType: AuthBlockingEventType, optsOrHandler: BlockingOptions | ((event: AuthBlockingEvent) => BeforeCreateResponse | BeforeSignInResponse | void | Promise<BeforeCreateResponse> | Promise<BeforeSignInResponse> | Promise<void>), handler: (event: AuthBlockingEvent) => BeforeCreateResponse | BeforeSignInResponse | void | Promise<BeforeCreateResponse> | Promise<BeforeSignInResponse> | Promise<void>): BlockingFunction;
|
|
125
|
+
/** @hidden */
|
|
126
|
+
export declare function getOpts(blockingOptions: BlockingOptions): InternalOptions;
|