firebase-functions 3.20.1 → 3.21.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/apps.js +1 -1
- package/lib/bin/firebase-functions.js +1 -1
- package/lib/cloud-functions.d.ts +8 -0
- package/lib/cloud-functions.js +12 -12
- package/lib/common/providers/https.js +8 -6
- package/lib/common/providers/identity.d.ts +7 -1
- package/lib/common/providers/identity.js +55 -207
- package/lib/function-builder.d.ts +1 -1
- package/lib/function-builder.js +1 -1
- package/lib/handler-builder.js +3 -3
- package/lib/index.js +6 -2
- package/lib/logger/compat.js +1 -1
- package/lib/providers/analytics.js +1 -1
- package/lib/providers/auth.d.ts +19 -6
- package/lib/providers/auth.js +62 -10
- package/lib/providers/database.js +11 -11
- package/lib/providers/firestore.js +7 -7
- package/lib/providers/https.js +7 -7
- package/lib/providers/pubsub.js +2 -2
- package/lib/providers/remoteConfig.js +1 -1
- package/lib/providers/storage.js +2 -2
- package/lib/providers/tasks.d.ts +1 -1
- package/lib/providers/tasks.js +9 -9
- package/lib/providers/testLab.js +1 -1
- package/lib/runtime/loader.js +9 -7
- package/lib/runtime/manifest.d.ts +5 -0
- package/lib/setup.js +3 -3
- package/lib/v2/core.d.ts +3 -21
- package/lib/v2/index.d.ts +3 -2
- package/lib/v2/index.js +5 -3
- package/lib/v2/options.d.ts +13 -2
- package/lib/v2/options.js +31 -39
- package/lib/v2/providers/alerts/alerts.d.ts +15 -7
- package/lib/v2/providers/alerts/appDistribution.d.ts +11 -11
- package/lib/v2/providers/alerts/appDistribution.js +1 -1
- package/lib/v2/providers/alerts/billing.d.ts +17 -11
- package/lib/v2/providers/alerts/billing.js +1 -1
- package/lib/v2/providers/alerts/crashlytics.d.ts +62 -29
- package/lib/v2/providers/alerts/crashlytics.js +1 -1
- package/lib/v2/providers/alerts/index.js +5 -1
- package/lib/v2/providers/eventarc.d.ts +1 -1
- package/lib/v2/providers/eventarc.js +3 -3
- package/lib/v2/providers/https.d.ts +6 -3
- package/lib/v2/providers/https.js +5 -11
- package/lib/v2/providers/identity.d.ts +22 -0
- package/lib/v2/providers/identity.js +73 -0
- package/lib/v2/providers/pubsub.d.ts +3 -3
- package/lib/v2/providers/pubsub.js +2 -5
- package/lib/v2/providers/storage.d.ts +17 -13
- package/lib/v2/providers/storage.js +5 -4
- package/lib/v2/providers/tasks.d.ts +1 -1
- package/lib/v2/providers/tasks.js +7 -8
- package/package.json +16 -3
package/lib/providers/auth.js
CHANGED
|
@@ -21,11 +21,12 @@
|
|
|
21
21
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
// SOFTWARE.
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.UserBuilder = exports._userWithOptions = exports.user = exports.service = exports.provider = exports.userRecordConstructor = exports.UserRecordMetadata = void 0;
|
|
24
|
+
exports.UserBuilder = exports._userWithOptions = exports.user = exports.service = exports.provider = exports.HttpsError = exports.userRecordConstructor = exports.UserRecordMetadata = void 0;
|
|
25
|
+
const cloud_functions_1 = require("../cloud-functions");
|
|
25
26
|
const identity_1 = require("../common/providers/identity");
|
|
26
|
-
Object.defineProperty(exports, "
|
|
27
|
+
Object.defineProperty(exports, "HttpsError", { enumerable: true, get: function () { return identity_1.HttpsError; } });
|
|
27
28
|
Object.defineProperty(exports, "userRecordConstructor", { enumerable: true, get: function () { return identity_1.userRecordConstructor; } });
|
|
28
|
-
|
|
29
|
+
Object.defineProperty(exports, "UserRecordMetadata", { enumerable: true, get: function () { return identity_1.UserRecordMetadata; } });
|
|
29
30
|
/** @hidden */
|
|
30
31
|
exports.provider = 'google.firebase.auth';
|
|
31
32
|
/** @hidden */
|
|
@@ -33,29 +34,30 @@ exports.service = 'firebaseauth.googleapis.com';
|
|
|
33
34
|
/**
|
|
34
35
|
* Handle events related to Firebase authentication users.
|
|
35
36
|
*/
|
|
36
|
-
function user() {
|
|
37
|
-
return _userWithOptions({});
|
|
37
|
+
function user(userOptions) {
|
|
38
|
+
return _userWithOptions({}, userOptions || {});
|
|
38
39
|
}
|
|
39
40
|
exports.user = user;
|
|
40
41
|
/** @hidden */
|
|
41
|
-
function _userWithOptions(options) {
|
|
42
|
+
function _userWithOptions(options, userOptions) {
|
|
42
43
|
return new UserBuilder(() => {
|
|
43
44
|
if (!process.env.GCLOUD_PROJECT) {
|
|
44
45
|
throw new Error('process.env.GCLOUD_PROJECT is not set.');
|
|
45
46
|
}
|
|
46
47
|
return 'projects/' + process.env.GCLOUD_PROJECT;
|
|
47
|
-
}, options);
|
|
48
|
+
}, options, userOptions);
|
|
48
49
|
}
|
|
49
50
|
exports._userWithOptions = _userWithOptions;
|
|
50
51
|
/** Builder used to create Cloud Functions for Firebase Auth user lifecycle events. */
|
|
51
52
|
class UserBuilder {
|
|
52
53
|
/** @hidden */
|
|
53
|
-
constructor(triggerResource, options) {
|
|
54
|
+
constructor(triggerResource, options, userOptions) {
|
|
54
55
|
this.triggerResource = triggerResource;
|
|
55
56
|
this.options = options;
|
|
57
|
+
this.userOptions = userOptions;
|
|
56
58
|
}
|
|
57
59
|
static dataConstructor(raw) {
|
|
58
|
-
return identity_1.userRecordConstructor(raw.data);
|
|
60
|
+
return (0, identity_1.userRecordConstructor)(raw.data);
|
|
59
61
|
}
|
|
60
62
|
/** Respond to the creation of a Firebase Auth user. */
|
|
61
63
|
onCreate(handler) {
|
|
@@ -65,8 +67,14 @@ class UserBuilder {
|
|
|
65
67
|
onDelete(handler) {
|
|
66
68
|
return this.onOperation(handler, 'user.delete');
|
|
67
69
|
}
|
|
70
|
+
beforeCreate(handler) {
|
|
71
|
+
return this.beforeOperation(handler, 'beforeCreate');
|
|
72
|
+
}
|
|
73
|
+
beforeSignIn(handler) {
|
|
74
|
+
return this.beforeOperation(handler, 'beforeSignIn');
|
|
75
|
+
}
|
|
68
76
|
onOperation(handler, eventType) {
|
|
69
|
-
return cloud_functions_1.makeCloudFunction({
|
|
77
|
+
return (0, cloud_functions_1.makeCloudFunction)({
|
|
70
78
|
handler,
|
|
71
79
|
provider: exports.provider,
|
|
72
80
|
eventType,
|
|
@@ -77,5 +85,49 @@ class UserBuilder {
|
|
|
77
85
|
options: this.options,
|
|
78
86
|
});
|
|
79
87
|
}
|
|
88
|
+
beforeOperation(handler, eventType) {
|
|
89
|
+
var _a, _b, _c, _d, _e, _f;
|
|
90
|
+
const accessToken = ((_b = (_a = this.userOptions) === null || _a === void 0 ? void 0 : _a.blockingOptions) === null || _b === void 0 ? void 0 : _b.accessToken) || false;
|
|
91
|
+
const idToken = ((_d = (_c = this.userOptions) === null || _c === void 0 ? void 0 : _c.blockingOptions) === null || _d === void 0 ? void 0 : _d.idToken) || false;
|
|
92
|
+
const refreshToken = ((_f = (_e = this.userOptions) === null || _e === void 0 ? void 0 : _e.blockingOptions) === null || _f === void 0 ? void 0 : _f.refreshToken) || false;
|
|
93
|
+
// Create our own function that just calls the provided function so we know for sure that
|
|
94
|
+
// handler takes two arguments. This is something common/providers/identity depends on.
|
|
95
|
+
const wrappedHandler = (user, context) => handler(user, context);
|
|
96
|
+
const func = (0, identity_1.wrapHandler)(eventType, wrappedHandler);
|
|
97
|
+
const legacyEventType = `providers/cloud.auth/eventTypes/user.${eventType}`;
|
|
98
|
+
func.__trigger = {
|
|
99
|
+
labels: {},
|
|
100
|
+
...(0, cloud_functions_1.optionsToTrigger)(this.options),
|
|
101
|
+
blockingTrigger: {
|
|
102
|
+
eventType: legacyEventType,
|
|
103
|
+
options: {
|
|
104
|
+
accessToken,
|
|
105
|
+
idToken,
|
|
106
|
+
refreshToken,
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
func.__endpoint = {
|
|
111
|
+
platform: 'gcfv1',
|
|
112
|
+
labels: {},
|
|
113
|
+
...(0, cloud_functions_1.optionsToEndpoint)(this.options),
|
|
114
|
+
blockingTrigger: {
|
|
115
|
+
eventType: legacyEventType,
|
|
116
|
+
options: {
|
|
117
|
+
accessToken,
|
|
118
|
+
idToken,
|
|
119
|
+
refreshToken,
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
func.__requiredAPIs = [
|
|
124
|
+
{
|
|
125
|
+
api: 'identitytoolkit.googleapis.com',
|
|
126
|
+
reason: 'Needed for auth blocking functions',
|
|
127
|
+
},
|
|
128
|
+
];
|
|
129
|
+
func.run = handler;
|
|
130
|
+
return func;
|
|
131
|
+
}
|
|
80
132
|
}
|
|
81
133
|
exports.UserBuilder = UserBuilder;
|
|
@@ -104,20 +104,20 @@ class InstanceBuilder {
|
|
|
104
104
|
* @return Firebase Realtime Database reference builder interface.
|
|
105
105
|
*/
|
|
106
106
|
ref(path) {
|
|
107
|
-
const normalized = path_1.normalizePath(path);
|
|
108
|
-
return new RefBuilder(apps_1.apps(), () => `projects/_/instances/${this.instance}/refs/${normalized}`, this.options);
|
|
107
|
+
const normalized = (0, path_1.normalizePath)(path);
|
|
108
|
+
return new RefBuilder((0, apps_1.apps)(), () => `projects/_/instances/${this.instance}/refs/${normalized}`, this.options);
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
exports.InstanceBuilder = InstanceBuilder;
|
|
112
112
|
/** @hidden */
|
|
113
113
|
function _refWithOptions(path, options) {
|
|
114
114
|
const resourceGetter = () => {
|
|
115
|
-
const normalized = path_1.normalizePath(path);
|
|
116
|
-
const databaseURL = config_1.firebaseConfig().databaseURL;
|
|
115
|
+
const normalized = (0, path_1.normalizePath)(path);
|
|
116
|
+
const databaseURL = (0, config_1.firebaseConfig)().databaseURL;
|
|
117
117
|
if (!databaseURL) {
|
|
118
118
|
throw new Error('Missing expected firebase config value databaseURL, ' +
|
|
119
119
|
'config is actually' +
|
|
120
|
-
JSON.stringify(config_1.firebaseConfig()) +
|
|
120
|
+
JSON.stringify((0, config_1.firebaseConfig)()) +
|
|
121
121
|
'\n If you are unit testing, please set process.env.FIREBASE_CONFIG');
|
|
122
122
|
}
|
|
123
123
|
let instance;
|
|
@@ -136,7 +136,7 @@ function _refWithOptions(path, options) {
|
|
|
136
136
|
}
|
|
137
137
|
return `projects/_/instances/${instance}/refs/${normalized}`;
|
|
138
138
|
};
|
|
139
|
-
return new RefBuilder(apps_1.apps(), resourceGetter, options);
|
|
139
|
+
return new RefBuilder((0, apps_1.apps)(), resourceGetter, options);
|
|
140
140
|
}
|
|
141
141
|
exports._refWithOptions = _refWithOptions;
|
|
142
142
|
/**
|
|
@@ -153,7 +153,7 @@ class RefBuilder {
|
|
|
153
153
|
this.changeConstructor = (raw) => {
|
|
154
154
|
const [dbInstance, path] = extractInstanceAndPath(raw.context.resource.name, raw.context.domain);
|
|
155
155
|
const before = new DataSnapshot(raw.data.data, path, this.apps.admin, dbInstance);
|
|
156
|
-
const after = new DataSnapshot(utils_1.applyChange(raw.data.data, raw.data.delta), path, this.apps.admin, dbInstance);
|
|
156
|
+
const after = new DataSnapshot((0, utils_1.applyChange)(raw.data.data, raw.data.delta), path, this.apps.admin, dbInstance);
|
|
157
157
|
return {
|
|
158
158
|
before,
|
|
159
159
|
after,
|
|
@@ -214,7 +214,7 @@ class RefBuilder {
|
|
|
214
214
|
return this.onOperation(handler, 'ref.delete', dataConstructor);
|
|
215
215
|
}
|
|
216
216
|
onOperation(handler, eventType, dataConstructor) {
|
|
217
|
-
return cloud_functions_1.makeCloudFunction({
|
|
217
|
+
return (0, cloud_functions_1.makeCloudFunction)({
|
|
218
218
|
handler,
|
|
219
219
|
provider: exports.provider,
|
|
220
220
|
service: exports.service,
|
|
@@ -311,7 +311,7 @@ class DataSnapshot {
|
|
|
311
311
|
* However, accessing the key on the root URL of a Database will return `null`.
|
|
312
312
|
*/
|
|
313
313
|
get key() {
|
|
314
|
-
const last = _.last(path_1.pathParts(this._fullPath()));
|
|
314
|
+
const last = _.last((0, path_1.pathParts)(this._fullPath()));
|
|
315
315
|
return !last || last === '' ? null : last;
|
|
316
316
|
}
|
|
317
317
|
/**
|
|
@@ -326,7 +326,7 @@ class DataSnapshot {
|
|
|
326
326
|
* Array, string, number, boolean, or `null`).
|
|
327
327
|
*/
|
|
328
328
|
val() {
|
|
329
|
-
const parts = path_1.pathParts(this._childPath);
|
|
329
|
+
const parts = (0, path_1.pathParts)(this._childPath);
|
|
330
330
|
const source = this._data;
|
|
331
331
|
const node = _.cloneDeep(parts.length ? _.get(source, parts, null) : source);
|
|
332
332
|
return this._checkAndConvertToArray(node);
|
|
@@ -494,7 +494,7 @@ class DataSnapshot {
|
|
|
494
494
|
const dup = new DataSnapshot(this._data, undefined, this.app, this.instance);
|
|
495
495
|
[dup._path, dup._childPath] = [this._path, this._childPath];
|
|
496
496
|
if (childPath) {
|
|
497
|
-
dup._childPath = path_1.joinPath(dup._childPath, childPath);
|
|
497
|
+
dup._childPath = (0, path_1.joinPath)(dup._childPath, childPath);
|
|
498
498
|
}
|
|
499
499
|
return dup;
|
|
500
500
|
}
|
|
@@ -113,8 +113,8 @@ function _getValueProto(data, resource, valueFieldName) {
|
|
|
113
113
|
}
|
|
114
114
|
const proto = {
|
|
115
115
|
fields: _.get(data, [valueFieldName, 'fields'], {}),
|
|
116
|
-
createTime: encoder_1.dateToTimestampProto(_.get(data, [valueFieldName, 'createTime'])),
|
|
117
|
-
updateTime: encoder_1.dateToTimestampProto(_.get(data, [valueFieldName, 'updateTime'])),
|
|
116
|
+
createTime: (0, encoder_1.dateToTimestampProto)(_.get(data, [valueFieldName, 'createTime'])),
|
|
117
|
+
updateTime: (0, encoder_1.dateToTimestampProto)(_.get(data, [valueFieldName, 'updateTime'])),
|
|
118
118
|
name: _.get(data, [valueFieldName, 'name'], resource),
|
|
119
119
|
};
|
|
120
120
|
return proto;
|
|
@@ -123,7 +123,7 @@ function _getValueProto(data, resource, valueFieldName) {
|
|
|
123
123
|
function snapshotConstructor(event) {
|
|
124
124
|
var _a;
|
|
125
125
|
if (!firestoreInstance) {
|
|
126
|
-
firestoreInstance = firebase.firestore(apps_1.apps().admin);
|
|
126
|
+
firestoreInstance = firebase.firestore((0, apps_1.apps)().admin);
|
|
127
127
|
}
|
|
128
128
|
const valueProto = _getValueProto(event.data, event.context.resource.name, 'value');
|
|
129
129
|
let timeString = (_a = _.get(event, 'data.value.readTime')) !== null && _a !== void 0 ? _a : _.get(event, 'data.value.updateTime');
|
|
@@ -131,7 +131,7 @@ function snapshotConstructor(event) {
|
|
|
131
131
|
logger.warn('Snapshot has no readTime. Using now()');
|
|
132
132
|
timeString = new Date().toISOString();
|
|
133
133
|
}
|
|
134
|
-
const readTime = encoder_1.dateToTimestampProto(timeString);
|
|
134
|
+
const readTime = (0, encoder_1.dateToTimestampProto)(timeString);
|
|
135
135
|
return firestoreInstance.snapshot_(valueProto, readTime, 'json');
|
|
136
136
|
}
|
|
137
137
|
exports.snapshotConstructor = snapshotConstructor;
|
|
@@ -139,10 +139,10 @@ exports.snapshotConstructor = snapshotConstructor;
|
|
|
139
139
|
// TODO remove this function when wire format changes to new format
|
|
140
140
|
function beforeSnapshotConstructor(event) {
|
|
141
141
|
if (!firestoreInstance) {
|
|
142
|
-
firestoreInstance = firebase.firestore(apps_1.apps().admin);
|
|
142
|
+
firestoreInstance = firebase.firestore((0, apps_1.apps)().admin);
|
|
143
143
|
}
|
|
144
144
|
const oldValueProto = _getValueProto(event.data, event.context.resource.name, 'oldValue');
|
|
145
|
-
const oldReadTime = encoder_1.dateToTimestampProto(_.get(event, 'data.oldValue.readTime'));
|
|
145
|
+
const oldReadTime = (0, encoder_1.dateToTimestampProto)(_.get(event, 'data.oldValue.readTime'));
|
|
146
146
|
return firestoreInstance.snapshot_(oldValueProto, oldReadTime, 'json');
|
|
147
147
|
}
|
|
148
148
|
exports.beforeSnapshotConstructor = beforeSnapshotConstructor;
|
|
@@ -173,7 +173,7 @@ class DocumentBuilder {
|
|
|
173
173
|
return this.onOperation(handler, 'document.delete', beforeSnapshotConstructor);
|
|
174
174
|
}
|
|
175
175
|
onOperation(handler, eventType, dataConstructor) {
|
|
176
|
-
return cloud_functions_1.makeCloudFunction({
|
|
176
|
+
return (0, cloud_functions_1.makeCloudFunction)({
|
|
177
177
|
handler,
|
|
178
178
|
provider: exports.provider,
|
|
179
179
|
eventType,
|
package/lib/providers/https.js
CHANGED
|
@@ -50,17 +50,17 @@ function _onRequestWithOptions(handler, options) {
|
|
|
50
50
|
return handler(req, res);
|
|
51
51
|
};
|
|
52
52
|
cloudFunction.__trigger = {
|
|
53
|
-
...cloud_functions_1.optionsToTrigger(options),
|
|
53
|
+
...(0, cloud_functions_1.optionsToTrigger)(options),
|
|
54
54
|
httpsTrigger: {},
|
|
55
55
|
};
|
|
56
|
-
encoding_1.convertIfPresent(cloudFunction.__trigger.httpsTrigger, options, 'invoker', 'invoker', encoding_1.convertInvoker);
|
|
56
|
+
(0, encoding_1.convertIfPresent)(cloudFunction.__trigger.httpsTrigger, options, 'invoker', 'invoker', encoding_1.convertInvoker);
|
|
57
57
|
// TODO parse the options
|
|
58
58
|
cloudFunction.__endpoint = {
|
|
59
59
|
platform: 'gcfv1',
|
|
60
|
-
...cloud_functions_1.optionsToEndpoint(options),
|
|
60
|
+
...(0, cloud_functions_1.optionsToEndpoint)(options),
|
|
61
61
|
httpsTrigger: {},
|
|
62
62
|
};
|
|
63
|
-
encoding_1.convertIfPresent(cloudFunction.__endpoint.httpsTrigger, options, 'invoker', 'invoker', encoding_1.convertInvoker);
|
|
63
|
+
(0, encoding_1.convertIfPresent)(cloudFunction.__endpoint.httpsTrigger, options, 'invoker', 'invoker', encoding_1.convertInvoker);
|
|
64
64
|
return cloudFunction;
|
|
65
65
|
}
|
|
66
66
|
exports._onRequestWithOptions = _onRequestWithOptions;
|
|
@@ -70,20 +70,20 @@ function _onCallWithOptions(handler, options) {
|
|
|
70
70
|
// and the user could have only tried to listen to data. Wrap their handler
|
|
71
71
|
// in another handler to avoid accidentally triggering the v2 API
|
|
72
72
|
const fixedLen = (data, context) => handler(data, context);
|
|
73
|
-
const func = https_1.onCallHandler({
|
|
73
|
+
const func = (0, https_1.onCallHandler)({
|
|
74
74
|
allowInvalidAppCheckToken: options.allowInvalidAppCheckToken,
|
|
75
75
|
cors: { origin: true, methods: 'POST' },
|
|
76
76
|
}, fixedLen);
|
|
77
77
|
func.__trigger = {
|
|
78
78
|
labels: {},
|
|
79
|
-
...cloud_functions_1.optionsToTrigger(options),
|
|
79
|
+
...(0, cloud_functions_1.optionsToTrigger)(options),
|
|
80
80
|
httpsTrigger: {},
|
|
81
81
|
};
|
|
82
82
|
func.__trigger.labels['deployment-callable'] = 'true';
|
|
83
83
|
func.__endpoint = {
|
|
84
84
|
platform: 'gcfv1',
|
|
85
85
|
labels: {},
|
|
86
|
-
...cloud_functions_1.optionsToEndpoint(options),
|
|
86
|
+
...(0, cloud_functions_1.optionsToEndpoint)(options),
|
|
87
87
|
callableTrigger: {},
|
|
88
88
|
};
|
|
89
89
|
func.run = handler;
|
package/lib/providers/pubsub.js
CHANGED
|
@@ -71,7 +71,7 @@ class TopicBuilder {
|
|
|
71
71
|
* @return A Cloud Function that you can export and deploy.
|
|
72
72
|
*/
|
|
73
73
|
onPublish(handler) {
|
|
74
|
-
return cloud_functions_1.makeCloudFunction({
|
|
74
|
+
return (0, cloud_functions_1.makeCloudFunction)({
|
|
75
75
|
handler,
|
|
76
76
|
provider: exports.provider,
|
|
77
77
|
service: exports.service,
|
|
@@ -140,7 +140,7 @@ class ScheduleBuilder {
|
|
|
140
140
|
* @return A Cloud Function that you can export and deploy.
|
|
141
141
|
*/
|
|
142
142
|
onRun(handler) {
|
|
143
|
-
const cloudFunction = cloud_functions_1.makeCloudFunction({
|
|
143
|
+
const cloudFunction = (0, cloud_functions_1.makeCloudFunction)({
|
|
144
144
|
contextOnlyHandler: handler,
|
|
145
145
|
provider: exports.provider,
|
|
146
146
|
service: exports.service,
|
|
@@ -65,7 +65,7 @@ class UpdateBuilder {
|
|
|
65
65
|
* version metadata as an argument.
|
|
66
66
|
*/
|
|
67
67
|
onUpdate(handler) {
|
|
68
|
-
return cloud_functions_1.makeCloudFunction({
|
|
68
|
+
return (0, cloud_functions_1.makeCloudFunction)({
|
|
69
69
|
handler,
|
|
70
70
|
provider: exports.provider,
|
|
71
71
|
service: exports.service,
|
package/lib/providers/storage.js
CHANGED
|
@@ -53,7 +53,7 @@ exports.object = object;
|
|
|
53
53
|
/** @hidden */
|
|
54
54
|
function _bucketWithOptions(options, bucket) {
|
|
55
55
|
const resourceGetter = () => {
|
|
56
|
-
bucket = bucket || config_1.firebaseConfig().storageBucket;
|
|
56
|
+
bucket = bucket || (0, config_1.firebaseConfig)().storageBucket;
|
|
57
57
|
if (!bucket) {
|
|
58
58
|
throw new Error('Missing bucket name. If you are unit testing, please provide a bucket name' +
|
|
59
59
|
' through `functions.storage.bucket(bucketName)`, or set process.env.FIREBASE_CONFIG.');
|
|
@@ -170,7 +170,7 @@ class ObjectBuilder {
|
|
|
170
170
|
}
|
|
171
171
|
/** @hidden */
|
|
172
172
|
onOperation(handler, eventType) {
|
|
173
|
-
return cloud_functions_1.makeCloudFunction({
|
|
173
|
+
return (0, cloud_functions_1.makeCloudFunction)({
|
|
174
174
|
handler,
|
|
175
175
|
provider: exports.provider,
|
|
176
176
|
service: exports.service,
|
package/lib/providers/tasks.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as express from 'express';
|
|
2
2
|
import { Request } from '../common/providers/https';
|
|
3
|
+
import { RateLimits, RetryConfig, TaskContext } from '../common/providers/tasks';
|
|
3
4
|
import { ManifestEndpoint, ManifestRequiredAPI } from '../runtime/manifest';
|
|
4
|
-
import { TaskContext, RateLimits, RetryConfig } from '../common/providers/tasks';
|
|
5
5
|
export {
|
|
6
6
|
/** @hidden */
|
|
7
7
|
RetryConfig as RetryPolicy,
|
package/lib/providers/tasks.js
CHANGED
|
@@ -37,22 +37,22 @@ class TaskQueueBuilder {
|
|
|
37
37
|
// and the user could have only tried to listen to data. Wrap their handler
|
|
38
38
|
// in another handler to avoid accidentally triggering the v2 API
|
|
39
39
|
const fixedLen = (data, context) => handler(data, context);
|
|
40
|
-
const func = tasks_1.onDispatchHandler(fixedLen);
|
|
40
|
+
const func = (0, tasks_1.onDispatchHandler)(fixedLen);
|
|
41
41
|
func.__trigger = {
|
|
42
|
-
...cloud_functions_1.optionsToTrigger(this.depOpts || {}),
|
|
42
|
+
...(0, cloud_functions_1.optionsToTrigger)(this.depOpts || {}),
|
|
43
43
|
taskQueueTrigger: {},
|
|
44
44
|
};
|
|
45
|
-
encoding_1.copyIfPresent(func.__trigger.taskQueueTrigger, this.tqOpts, 'retryConfig');
|
|
46
|
-
encoding_1.copyIfPresent(func.__trigger.taskQueueTrigger, this.tqOpts, 'rateLimits');
|
|
47
|
-
encoding_1.convertIfPresent(func.__trigger.taskQueueTrigger, this.tqOpts, 'invoker', 'invoker', encoding_1.convertInvoker);
|
|
45
|
+
(0, encoding_1.copyIfPresent)(func.__trigger.taskQueueTrigger, this.tqOpts, 'retryConfig');
|
|
46
|
+
(0, encoding_1.copyIfPresent)(func.__trigger.taskQueueTrigger, this.tqOpts, 'rateLimits');
|
|
47
|
+
(0, encoding_1.convertIfPresent)(func.__trigger.taskQueueTrigger, this.tqOpts, 'invoker', 'invoker', encoding_1.convertInvoker);
|
|
48
48
|
func.__endpoint = {
|
|
49
49
|
platform: 'gcfv1',
|
|
50
|
-
...cloud_functions_1.optionsToEndpoint(this.depOpts),
|
|
50
|
+
...(0, cloud_functions_1.optionsToEndpoint)(this.depOpts),
|
|
51
51
|
taskQueueTrigger: {},
|
|
52
52
|
};
|
|
53
|
-
encoding_1.copyIfPresent(func.__endpoint.taskQueueTrigger, this.tqOpts, 'retryConfig');
|
|
54
|
-
encoding_1.copyIfPresent(func.__endpoint.taskQueueTrigger, this.tqOpts, 'rateLimits');
|
|
55
|
-
encoding_1.convertIfPresent(func.__endpoint.taskQueueTrigger, this.tqOpts, 'invoker', 'invoker', encoding_1.convertInvoker);
|
|
53
|
+
(0, encoding_1.copyIfPresent)(func.__endpoint.taskQueueTrigger, this.tqOpts, 'retryConfig');
|
|
54
|
+
(0, encoding_1.copyIfPresent)(func.__endpoint.taskQueueTrigger, this.tqOpts, 'rateLimits');
|
|
55
|
+
(0, encoding_1.convertIfPresent)(func.__endpoint.taskQueueTrigger, this.tqOpts, 'invoker', 'invoker', encoding_1.convertInvoker);
|
|
56
56
|
func.__requiredAPIs = [
|
|
57
57
|
{
|
|
58
58
|
api: 'cloudtasks.googleapis.com',
|
package/lib/providers/testLab.js
CHANGED
|
@@ -57,7 +57,7 @@ class TestMatrixBuilder {
|
|
|
57
57
|
const dataConstructor = (raw) => {
|
|
58
58
|
return new TestMatrix(raw.data);
|
|
59
59
|
};
|
|
60
|
-
return cloud_functions_1.makeCloudFunction({
|
|
60
|
+
return (0, cloud_functions_1.makeCloudFunction)({
|
|
61
61
|
provider: exports.PROVIDER,
|
|
62
62
|
eventType: exports.TEST_MATRIX_COMPLETE_EVENT_TYPE,
|
|
63
63
|
triggerResource: this.triggerResource,
|
package/lib/runtime/loader.js
CHANGED
|
@@ -22,8 +22,8 @@ exports.loadStack = exports.mergeRequiredAPIs = exports.extractStack = void 0;
|
|
|
22
22
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
23
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
24
|
// SOFTWARE.
|
|
25
|
-
const url = require("url");
|
|
26
25
|
const path = require("path");
|
|
26
|
+
const url = require("url");
|
|
27
27
|
/**
|
|
28
28
|
* Dynamically load import function to prevent TypeScript from
|
|
29
29
|
* transpiling into a require.
|
|
@@ -51,17 +51,19 @@ async function loadModule(functionsDir) {
|
|
|
51
51
|
}
|
|
52
52
|
/* @internal */
|
|
53
53
|
function extractStack(module, endpoints, requiredAPIs, prefix = '') {
|
|
54
|
-
for (const [name,
|
|
54
|
+
for (const [name, valAsUnknown] of Object.entries(module)) {
|
|
55
|
+
// We're introspecting untrusted code here. Any is appropraite
|
|
56
|
+
const val = valAsUnknown;
|
|
55
57
|
if (typeof val === 'function' &&
|
|
56
|
-
val
|
|
57
|
-
typeof val
|
|
58
|
+
val.__endpoint &&
|
|
59
|
+
typeof val.__endpoint === 'object') {
|
|
58
60
|
const funcName = prefix + name;
|
|
59
61
|
endpoints[funcName] = {
|
|
60
|
-
...val
|
|
62
|
+
...val.__endpoint,
|
|
61
63
|
entryPoint: funcName.replace(/-/g, '.'),
|
|
62
64
|
};
|
|
63
|
-
if (val
|
|
64
|
-
requiredAPIs.push(...val
|
|
65
|
+
if (val.__requiredAPIs && Array.isArray(val.__requiredAPIs)) {
|
|
66
|
+
requiredAPIs.push(...val.__requiredAPIs);
|
|
65
67
|
}
|
|
66
68
|
}
|
|
67
69
|
else if (typeof val === 'object' && val !== null) {
|
|
@@ -11,6 +11,7 @@ export interface ManifestEndpoint {
|
|
|
11
11
|
concurrency?: number;
|
|
12
12
|
serviceAccountEmail?: string;
|
|
13
13
|
timeoutSeconds?: number;
|
|
14
|
+
cpu?: number | 'gcf_gen1';
|
|
14
15
|
vpc?: {
|
|
15
16
|
connector: string;
|
|
16
17
|
egressSettings?: string;
|
|
@@ -46,6 +47,10 @@ export interface ManifestEndpoint {
|
|
|
46
47
|
maxDoublings?: number;
|
|
47
48
|
};
|
|
48
49
|
};
|
|
50
|
+
blockingTrigger?: {
|
|
51
|
+
eventType: string;
|
|
52
|
+
options?: Record<string, unknown>;
|
|
53
|
+
};
|
|
49
54
|
}
|
|
50
55
|
export interface ManifestRequiredAPI {
|
|
51
56
|
api: string;
|
package/lib/setup.js
CHANGED
|
@@ -31,7 +31,7 @@ function setup() {
|
|
|
31
31
|
// Until the Cloud Functions builder can publish FIREBASE_CONFIG, automatically provide it on import based on what
|
|
32
32
|
// we can deduce.
|
|
33
33
|
if (!process.env.FIREBASE_CONFIG) {
|
|
34
|
-
const cfg = config_1.firebaseConfig();
|
|
34
|
+
const cfg = (0, config_1.firebaseConfig)();
|
|
35
35
|
if (cfg) {
|
|
36
36
|
process.env.FIREBASE_CONFIG = JSON.stringify(cfg);
|
|
37
37
|
}
|
|
@@ -43,7 +43,7 @@ function setup() {
|
|
|
43
43
|
// If FIREBASE_CONFIG is still not found, try using GCLOUD_PROJECT to estimate
|
|
44
44
|
if (!process.env.FIREBASE_CONFIG) {
|
|
45
45
|
if (process.env.GCLOUD_PROJECT) {
|
|
46
|
-
logger_1.warn('Warning, estimating Firebase Config based on GCLOUD_PROJECT. Initializing firebase-admin may fail');
|
|
46
|
+
(0, logger_1.warn)('Warning, estimating Firebase Config based on GCLOUD_PROJECT. Initializing firebase-admin may fail');
|
|
47
47
|
process.env.FIREBASE_CONFIG = JSON.stringify({
|
|
48
48
|
databaseURL: process.env.DATABASE_URL ||
|
|
49
49
|
`https://${process.env.GCLOUD_PROJECT}.firebaseio.com`,
|
|
@@ -53,7 +53,7 @@ function setup() {
|
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
55
|
else {
|
|
56
|
-
logger_1.warn('Warning, FIREBASE_CONFIG and GCLOUD_PROJECT environment variables are missing. Initializing firebase-admin will fail');
|
|
56
|
+
(0, logger_1.warn)('Warning, FIREBASE_CONFIG and GCLOUD_PROJECT environment variables are missing. Initializing firebase-admin will fail');
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
}
|
package/lib/v2/core.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { ManifestEndpoint } from '../runtime/manifest';
|
|
|
3
3
|
* A CloudEventBase is the base of a cross-platform format for encoding a serverless event.
|
|
4
4
|
* More information can be found in https://github.com/cloudevents/spec
|
|
5
5
|
*/
|
|
6
|
-
interface
|
|
6
|
+
export interface CloudEvent<T> {
|
|
7
7
|
/** Version of the CloudEvents spec for this event. */
|
|
8
8
|
readonly specversion: '1.0';
|
|
9
9
|
/** A globally unique ID for this event. */
|
|
@@ -18,29 +18,11 @@ interface CloudEventBase<T> {
|
|
|
18
18
|
time: string;
|
|
19
19
|
/** Information about this specific event. */
|
|
20
20
|
data: T;
|
|
21
|
-
/**
|
|
22
|
-
* A map of template parameter name to value for subject strings.
|
|
23
|
-
*
|
|
24
|
-
* This map is only available on some event types that allow templates
|
|
25
|
-
* in the subject string, such as Firestore. When listening to a document
|
|
26
|
-
* template "/users/{uid}", an event with subject "/documents/users/1234"
|
|
27
|
-
* would have a params of {"uid": "1234"}.
|
|
28
|
-
*
|
|
29
|
-
* Params are generated inside the firebase-functions SDK and are not
|
|
30
|
-
* part of the CloudEvents spec nor the payload that a Cloud Function
|
|
31
|
-
* actually receives.
|
|
32
|
-
*/
|
|
33
|
-
params?: Record<string, string>;
|
|
34
21
|
}
|
|
35
|
-
/**
|
|
36
|
-
* A CloudEvent with custom extension attributes
|
|
37
|
-
*/
|
|
38
|
-
export declare type CloudEvent<T = any, Ext = {}> = CloudEventBase<T> & Ext;
|
|
39
22
|
/** A handler for CloudEvents. */
|
|
40
|
-
export interface CloudFunction<
|
|
23
|
+
export interface CloudFunction<EventType extends CloudEvent<unknown>> {
|
|
41
24
|
(raw: CloudEvent<unknown>): any | Promise<any>;
|
|
42
25
|
__trigger?: unknown;
|
|
43
26
|
__endpoint: ManifestEndpoint;
|
|
44
|
-
run(event:
|
|
27
|
+
run(event: EventType): any | Promise<any>;
|
|
45
28
|
}
|
|
46
|
-
export {};
|
package/lib/v2/index.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import * as logger from '../logger';
|
|
2
2
|
import * as params from './params';
|
|
3
3
|
import * as alerts from './providers/alerts';
|
|
4
|
+
import * as eventarc from './providers/eventarc';
|
|
4
5
|
import * as https from './providers/https';
|
|
6
|
+
import * as identity from './providers/identity';
|
|
5
7
|
import * as pubsub from './providers/pubsub';
|
|
6
8
|
import * as storage from './providers/storage';
|
|
7
9
|
import * as tasks from './providers/tasks';
|
|
8
|
-
|
|
9
|
-
export { alerts, https, pubsub, storage, logger, params, tasks, eventarc };
|
|
10
|
+
export { alerts, https, identity, pubsub, storage, logger, params, tasks, eventarc, };
|
|
10
11
|
export { setGlobalOptions, GlobalOptions } from './options';
|
|
11
12
|
export { CloudFunction, CloudEvent } from './core';
|
package/lib/v2/index.js
CHANGED
|
@@ -21,22 +21,24 @@
|
|
|
21
21
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
// SOFTWARE.
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.setGlobalOptions = exports.eventarc = exports.tasks = exports.params = exports.logger = exports.storage = exports.pubsub = exports.https = exports.alerts = void 0;
|
|
24
|
+
exports.setGlobalOptions = exports.eventarc = exports.tasks = exports.params = exports.logger = exports.storage = exports.pubsub = exports.identity = exports.https = exports.alerts = void 0;
|
|
25
25
|
const logger = require("../logger");
|
|
26
26
|
exports.logger = logger;
|
|
27
27
|
const params = require("./params");
|
|
28
28
|
exports.params = params;
|
|
29
29
|
const alerts = require("./providers/alerts");
|
|
30
30
|
exports.alerts = alerts;
|
|
31
|
+
const eventarc = require("./providers/eventarc");
|
|
32
|
+
exports.eventarc = eventarc;
|
|
31
33
|
const https = require("./providers/https");
|
|
32
34
|
exports.https = https;
|
|
35
|
+
const identity = require("./providers/identity");
|
|
36
|
+
exports.identity = identity;
|
|
33
37
|
const pubsub = require("./providers/pubsub");
|
|
34
38
|
exports.pubsub = pubsub;
|
|
35
39
|
const storage = require("./providers/storage");
|
|
36
40
|
exports.storage = storage;
|
|
37
41
|
const tasks = require("./providers/tasks");
|
|
38
42
|
exports.tasks = tasks;
|
|
39
|
-
const eventarc = require("./providers/eventarc");
|
|
40
|
-
exports.eventarc = eventarc;
|
|
41
43
|
var options_1 = require("./options");
|
|
42
44
|
Object.defineProperty(exports, "setGlobalOptions", { enumerable: true, get: function () { return options_1.setGlobalOptions; } });
|
package/lib/v2/options.d.ts
CHANGED
|
@@ -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 ["
|
|
29
|
+
export declare const SUPPORTED_MEMORY_OPTIONS: readonly ["128MiB", "256MiB", "512MiB", "1GiB", "2GiB", "4GiB", "8GiB", "16GiB", "32GiB"];
|
|
30
30
|
/**
|
|
31
31
|
* A supported memory option.
|
|
32
32
|
*/
|
|
@@ -80,9 +80,19 @@ export interface GlobalOptions {
|
|
|
80
80
|
/**
|
|
81
81
|
* Number of requests a function can serve at once.
|
|
82
82
|
* Can only be applied to functions running on Cloud Functions v2.
|
|
83
|
-
* A value of null restores the default concurrency.
|
|
83
|
+
* A value of null restores the default concurrency (80 when CPU >= 1, 1 otherwise).
|
|
84
|
+
* Concurrency cannot be set to any value other than 1 if `cpu` is less than 1.
|
|
84
85
|
*/
|
|
85
86
|
concurrency?: number | null;
|
|
87
|
+
/**
|
|
88
|
+
* Fractional number of CPUs to allocate to a function.
|
|
89
|
+
* Defaults to 1 for functions with <= 2GB RAM and increases for larger memory sizes.
|
|
90
|
+
* This is different from the defaults when using the gcloud utility and is different from
|
|
91
|
+
* the fixed amount assigned in Google Cloud Functions generation 1.
|
|
92
|
+
* To revert to the CPU amounts used in gcloud or in Cloud Functions generation 1, set this
|
|
93
|
+
* to the value "gcf_gen1"
|
|
94
|
+
*/
|
|
95
|
+
cpu?: number | 'gcf_gen1';
|
|
86
96
|
/**
|
|
87
97
|
* Connect cloud function to specified VPC connector.
|
|
88
98
|
* A value of null removes the VPC connector
|
|
@@ -111,6 +121,7 @@ export interface GlobalOptions {
|
|
|
111
121
|
* Invoker to set access control on https functions.
|
|
112
122
|
*/
|
|
113
123
|
invoker?: 'public' | 'private' | string | string[];
|
|
124
|
+
secrets?: string[];
|
|
114
125
|
}
|
|
115
126
|
/**
|
|
116
127
|
* Sets default options for all functions written using the v2 SDK.
|