firebase-functions 3.20.1 → 3.21.2
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 +22 -1
- package/lib/cloud-functions.d.ts +56 -35
- package/lib/cloud-functions.js +12 -12
- package/lib/common/encoding.js +21 -1
- package/lib/common/providers/https.d.ts +37 -17
- package/lib/common/providers/https.js +11 -6
- package/lib/common/providers/identity.d.ts +11 -1
- package/lib/common/providers/identity.js +59 -207
- package/lib/common/providers/tasks.d.ts +9 -0
- package/lib/function-builder.d.ts +2 -2
- package/lib/function-builder.js +1 -1
- package/lib/handler-builder.js +3 -3
- package/lib/index.js +6 -2
- package/lib/logger/common.js +21 -0
- package/lib/logger/compat.js +22 -1
- package/lib/logger/index.d.ts +14 -6
- package/lib/logger/index.js +33 -6
- package/lib/providers/analytics.js +1 -1
- package/lib/providers/auth.d.ts +44 -10
- package/lib/providers/auth.js +80 -14
- 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.d.ts +6 -6
- package/lib/providers/pubsub.js +8 -8
- package/lib/providers/remoteConfig.js +1 -1
- package/lib/providers/storage.js +2 -2
- package/lib/providers/tasks.d.ts +30 -15
- package/lib/providers/tasks.js +19 -12
- 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 +24 -20
- package/lib/v2/index.d.ts +11 -4
- package/lib/v2/index.js +12 -5
- package/lib/v2/options.d.ts +25 -35
- package/lib/v2/options.js +28 -88
- 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 +107 -8
- package/lib/v2/providers/alerts/alerts.js +23 -7
- package/lib/v2/providers/alerts/appDistribution.d.ts +112 -12
- package/lib/v2/providers/alerts/appDistribution.js +29 -2
- package/lib/v2/providers/alerts/billing.d.ts +39 -12
- package/lib/v2/providers/alerts/billing.js +38 -1
- package/lib/v2/providers/alerts/crashlytics.d.ts +255 -47
- package/lib/v2/providers/alerts/crashlytics.js +63 -2
- package/lib/v2/providers/alerts/index.d.ts +6 -0
- package/lib/v2/providers/alerts/index.js +32 -1
- package/lib/v2/providers/eventarc.d.ts +90 -6
- package/lib/v2/providers/eventarc.js +7 -3
- package/lib/v2/providers/https.d.ts +128 -4
- package/lib/v2/providers/https.js +18 -14
- package/lib/v2/providers/identity.d.ts +126 -0
- package/lib/v2/providers/identity.js +104 -0
- package/lib/v2/providers/pubsub.d.ts +125 -8
- package/lib/v2/providers/pubsub.js +60 -7
- package/lib/v2/providers/storage.d.ts +209 -17
- package/lib/v2/providers/storage.js +57 -13
- package/lib/v2/providers/tasks.d.ts +107 -7
- package/lib/v2/providers/tasks.js +11 -8
- package/package.json +18 -3
package/lib/providers/auth.d.ts
CHANGED
|
@@ -1,27 +1,61 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { BlockingFunction, CloudFunction, EventContext } from '../cloud-functions';
|
|
2
|
+
import { AuthEventContext, AuthUserRecord, BeforeCreateResponse, BeforeSignInResponse, HttpsError, UserInfo, UserRecord, userRecordConstructor, UserRecordMetadata } from '../common/providers/identity';
|
|
3
3
|
import { DeploymentOptions } from '../function-configuration';
|
|
4
4
|
export { UserRecord, UserInfo, UserRecordMetadata, userRecordConstructor };
|
|
5
|
+
export { HttpsError };
|
|
5
6
|
/** @hidden */
|
|
6
7
|
export declare const provider = "google.firebase.auth";
|
|
7
8
|
/** @hidden */
|
|
8
9
|
export declare const service = "firebaseauth.googleapis.com";
|
|
9
10
|
/**
|
|
10
|
-
*
|
|
11
|
+
* Resource level options
|
|
12
|
+
* @public
|
|
11
13
|
*/
|
|
12
|
-
export
|
|
14
|
+
export interface UserOptions {
|
|
15
|
+
/** Options to set configuration at the resource level for blocking functions. */
|
|
16
|
+
blockingOptions?: {
|
|
17
|
+
/** Pass the ID Token credential to the function. */
|
|
18
|
+
idToken?: boolean;
|
|
19
|
+
/** Pass the Access Token credential to the function. */
|
|
20
|
+
accessToken?: boolean;
|
|
21
|
+
/** Pass the Refresh Token credential to the function. */
|
|
22
|
+
refreshToken?: boolean;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Handles events related to Firebase authentication users.
|
|
27
|
+
* @param userOptions - Resource level options
|
|
28
|
+
* @returns UserBuilder - Builder used to create Cloud Functions for Firebase Auth user lifecycle events
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
export declare function user(userOptions?: UserOptions): UserBuilder;
|
|
13
32
|
/** @hidden */
|
|
14
|
-
export declare function _userWithOptions(options: DeploymentOptions): UserBuilder;
|
|
15
|
-
/**
|
|
33
|
+
export declare function _userWithOptions(options: DeploymentOptions, userOptions: UserOptions): UserBuilder;
|
|
34
|
+
/**
|
|
35
|
+
* Builder used to create Cloud Functions for Firebase Auth user lifecycle events.
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
16
38
|
export declare class UserBuilder {
|
|
17
39
|
private triggerResource;
|
|
18
|
-
private options
|
|
40
|
+
private options;
|
|
41
|
+
private userOptions?;
|
|
19
42
|
private static dataConstructor;
|
|
20
43
|
/** @hidden */
|
|
21
|
-
constructor(triggerResource: () => string, options?:
|
|
22
|
-
/**
|
|
44
|
+
constructor(triggerResource: () => string, options: DeploymentOptions, userOptions?: UserOptions);
|
|
45
|
+
/**
|
|
46
|
+
* Responds to the creation of a Firebase Auth user.
|
|
47
|
+
* @public
|
|
48
|
+
*/
|
|
23
49
|
onCreate(handler: (user: UserRecord, context: EventContext) => PromiseLike<any> | any): CloudFunction<UserRecord>;
|
|
24
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* Responds to the deletion of a Firebase Auth user.
|
|
52
|
+
* @public
|
|
53
|
+
*/
|
|
25
54
|
onDelete(handler: (user: UserRecord, context: EventContext) => PromiseLike<any> | any): CloudFunction<UserRecord>;
|
|
55
|
+
beforeCreate(handler: (user: AuthUserRecord, context: AuthEventContext) => BeforeCreateResponse | void | Promise<BeforeCreateResponse> | Promise<void>): BlockingFunction;
|
|
56
|
+
beforeSignIn(handler: (user: AuthUserRecord, context: AuthEventContext) => BeforeSignInResponse | void | Promise<BeforeSignInResponse> | Promise<void>): BlockingFunction;
|
|
57
|
+
/** @hidden */
|
|
26
58
|
private onOperation;
|
|
59
|
+
/** @hidden */
|
|
60
|
+
private beforeOperation;
|
|
27
61
|
}
|
package/lib/providers/auth.js
CHANGED
|
@@ -21,52 +21,73 @@
|
|
|
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 */
|
|
32
33
|
exports.service = 'firebaseauth.googleapis.com';
|
|
33
34
|
/**
|
|
34
|
-
*
|
|
35
|
+
* Handles events related to Firebase authentication users.
|
|
36
|
+
* @param userOptions - Resource level options
|
|
37
|
+
* @returns UserBuilder - Builder used to create Cloud Functions for Firebase Auth user lifecycle events
|
|
38
|
+
* @public
|
|
35
39
|
*/
|
|
36
|
-
function user() {
|
|
37
|
-
return _userWithOptions({});
|
|
40
|
+
function user(userOptions) {
|
|
41
|
+
return _userWithOptions({}, userOptions || {});
|
|
38
42
|
}
|
|
39
43
|
exports.user = user;
|
|
40
44
|
/** @hidden */
|
|
41
|
-
function _userWithOptions(options) {
|
|
45
|
+
function _userWithOptions(options, userOptions) {
|
|
42
46
|
return new UserBuilder(() => {
|
|
43
47
|
if (!process.env.GCLOUD_PROJECT) {
|
|
44
48
|
throw new Error('process.env.GCLOUD_PROJECT is not set.');
|
|
45
49
|
}
|
|
46
50
|
return 'projects/' + process.env.GCLOUD_PROJECT;
|
|
47
|
-
}, options);
|
|
51
|
+
}, options, userOptions);
|
|
48
52
|
}
|
|
49
53
|
exports._userWithOptions = _userWithOptions;
|
|
50
|
-
/**
|
|
54
|
+
/**
|
|
55
|
+
* Builder used to create Cloud Functions for Firebase Auth user lifecycle events.
|
|
56
|
+
* @public
|
|
57
|
+
*/
|
|
51
58
|
class UserBuilder {
|
|
52
59
|
/** @hidden */
|
|
53
|
-
constructor(triggerResource, options) {
|
|
60
|
+
constructor(triggerResource, options, userOptions) {
|
|
54
61
|
this.triggerResource = triggerResource;
|
|
55
62
|
this.options = options;
|
|
63
|
+
this.userOptions = userOptions;
|
|
56
64
|
}
|
|
57
65
|
static dataConstructor(raw) {
|
|
58
|
-
return identity_1.userRecordConstructor(raw.data);
|
|
66
|
+
return (0, identity_1.userRecordConstructor)(raw.data);
|
|
59
67
|
}
|
|
60
|
-
/**
|
|
68
|
+
/**
|
|
69
|
+
* Responds to the creation of a Firebase Auth user.
|
|
70
|
+
* @public
|
|
71
|
+
*/
|
|
61
72
|
onCreate(handler) {
|
|
62
73
|
return this.onOperation(handler, 'user.create');
|
|
63
74
|
}
|
|
64
|
-
/**
|
|
75
|
+
/**
|
|
76
|
+
* Responds to the deletion of a Firebase Auth user.
|
|
77
|
+
* @public
|
|
78
|
+
*/
|
|
65
79
|
onDelete(handler) {
|
|
66
80
|
return this.onOperation(handler, 'user.delete');
|
|
67
81
|
}
|
|
82
|
+
beforeCreate(handler) {
|
|
83
|
+
return this.beforeOperation(handler, 'beforeCreate');
|
|
84
|
+
}
|
|
85
|
+
beforeSignIn(handler) {
|
|
86
|
+
return this.beforeOperation(handler, 'beforeSignIn');
|
|
87
|
+
}
|
|
88
|
+
/** @hidden */
|
|
68
89
|
onOperation(handler, eventType) {
|
|
69
|
-
return cloud_functions_1.makeCloudFunction({
|
|
90
|
+
return (0, cloud_functions_1.makeCloudFunction)({
|
|
70
91
|
handler,
|
|
71
92
|
provider: exports.provider,
|
|
72
93
|
eventType,
|
|
@@ -77,5 +98,50 @@ class UserBuilder {
|
|
|
77
98
|
options: this.options,
|
|
78
99
|
});
|
|
79
100
|
}
|
|
101
|
+
/** @hidden */
|
|
102
|
+
beforeOperation(handler, eventType) {
|
|
103
|
+
var _a, _b, _c, _d, _e, _f;
|
|
104
|
+
const accessToken = ((_b = (_a = this.userOptions) === null || _a === void 0 ? void 0 : _a.blockingOptions) === null || _b === void 0 ? void 0 : _b.accessToken) || false;
|
|
105
|
+
const idToken = ((_d = (_c = this.userOptions) === null || _c === void 0 ? void 0 : _c.blockingOptions) === null || _d === void 0 ? void 0 : _d.idToken) || false;
|
|
106
|
+
const refreshToken = ((_f = (_e = this.userOptions) === null || _e === void 0 ? void 0 : _e.blockingOptions) === null || _f === void 0 ? void 0 : _f.refreshToken) || false;
|
|
107
|
+
// Create our own function that just calls the provided function so we know for sure that
|
|
108
|
+
// handler takes two arguments. This is something common/providers/identity depends on.
|
|
109
|
+
const wrappedHandler = (user, context) => handler(user, context);
|
|
110
|
+
const func = (0, identity_1.wrapHandler)(eventType, wrappedHandler);
|
|
111
|
+
const legacyEventType = `providers/cloud.auth/eventTypes/user.${eventType}`;
|
|
112
|
+
func.__trigger = {
|
|
113
|
+
labels: {},
|
|
114
|
+
...(0, cloud_functions_1.optionsToTrigger)(this.options),
|
|
115
|
+
blockingTrigger: {
|
|
116
|
+
eventType: legacyEventType,
|
|
117
|
+
options: {
|
|
118
|
+
accessToken,
|
|
119
|
+
idToken,
|
|
120
|
+
refreshToken,
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
func.__endpoint = {
|
|
125
|
+
platform: 'gcfv1',
|
|
126
|
+
labels: {},
|
|
127
|
+
...(0, cloud_functions_1.optionsToEndpoint)(this.options),
|
|
128
|
+
blockingTrigger: {
|
|
129
|
+
eventType: legacyEventType,
|
|
130
|
+
options: {
|
|
131
|
+
accessToken,
|
|
132
|
+
idToken,
|
|
133
|
+
refreshToken,
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
func.__requiredAPIs = [
|
|
138
|
+
{
|
|
139
|
+
api: 'identitytoolkit.googleapis.com',
|
|
140
|
+
reason: 'Needed for auth blocking functions',
|
|
141
|
+
},
|
|
142
|
+
];
|
|
143
|
+
func.run = handler;
|
|
144
|
+
return func;
|
|
145
|
+
}
|
|
80
146
|
}
|
|
81
147
|
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;
|
|
@@ -8,8 +8,8 @@ export declare const service = "pubsub.googleapis.com";
|
|
|
8
8
|
* Registers a Cloud Function triggered when a Google Cloud Pub/Sub message
|
|
9
9
|
* is sent to a specified topic.
|
|
10
10
|
*
|
|
11
|
-
* @param topic The Pub/Sub topic to watch for message events.
|
|
12
|
-
* @
|
|
11
|
+
* @param topic - The Pub/Sub topic to watch for message events.
|
|
12
|
+
* @returns Pub/Sub topic builder interface.
|
|
13
13
|
*/
|
|
14
14
|
export declare function topic(topic: string): TopicBuilder;
|
|
15
15
|
/** @hidden */
|
|
@@ -28,7 +28,7 @@ export declare class TopicBuilder {
|
|
|
28
28
|
* Event handler that fires every time a Cloud Pub/Sub message is
|
|
29
29
|
* published.
|
|
30
30
|
*
|
|
31
|
-
* @param handler Event handler that runs every time a Cloud Pub/Sub message
|
|
31
|
+
* @param handler - Event handler that runs every time a Cloud Pub/Sub message
|
|
32
32
|
* is published.
|
|
33
33
|
* @return A Cloud Function that you can export and deploy.
|
|
34
34
|
*/
|
|
@@ -37,7 +37,7 @@ export declare class TopicBuilder {
|
|
|
37
37
|
/**
|
|
38
38
|
* Registers a Cloud Function to run at specified times.
|
|
39
39
|
*
|
|
40
|
-
* @param schedule The schedule, in Unix Crontab or AppEngine syntax.
|
|
40
|
+
* @param schedule - The schedule, in Unix Crontab or AppEngine syntax.
|
|
41
41
|
* @return ScheduleBuilder interface.
|
|
42
42
|
*/
|
|
43
43
|
export declare function schedule(schedule: string): ScheduleBuilder;
|
|
@@ -63,7 +63,7 @@ export declare class ScheduleBuilder {
|
|
|
63
63
|
* Event handler for scheduled functions. Triggered whenever the associated
|
|
64
64
|
* scheduler job sends a Pub/Sub message.
|
|
65
65
|
*
|
|
66
|
-
* @param handler Handler that fires whenever the associated
|
|
66
|
+
* @param handler - Handler that fires whenever the associated
|
|
67
67
|
* scheduler job sends a Pub/Sub message.
|
|
68
68
|
* @return A Cloud Function that you can export and deploy.
|
|
69
69
|
*/
|
|
@@ -72,7 +72,7 @@ export declare class ScheduleBuilder {
|
|
|
72
72
|
/**
|
|
73
73
|
* Interface representing a Google Cloud Pub/Sub message.
|
|
74
74
|
*
|
|
75
|
-
* @param data Payload of a Pub/Sub message.
|
|
75
|
+
* @param data - Payload of a Pub/Sub message.
|
|
76
76
|
*/
|
|
77
77
|
export declare class Message {
|
|
78
78
|
/**
|
package/lib/providers/pubsub.js
CHANGED
|
@@ -31,8 +31,8 @@ exports.service = 'pubsub.googleapis.com';
|
|
|
31
31
|
* Registers a Cloud Function triggered when a Google Cloud Pub/Sub message
|
|
32
32
|
* is sent to a specified topic.
|
|
33
33
|
*
|
|
34
|
-
* @param topic The Pub/Sub topic to watch for message events.
|
|
35
|
-
* @
|
|
34
|
+
* @param topic - The Pub/Sub topic to watch for message events.
|
|
35
|
+
* @returns Pub/Sub topic builder interface.
|
|
36
36
|
*/
|
|
37
37
|
function topic(topic) {
|
|
38
38
|
return _topicWithOptions(topic, {});
|
|
@@ -66,12 +66,12 @@ class TopicBuilder {
|
|
|
66
66
|
* Event handler that fires every time a Cloud Pub/Sub message is
|
|
67
67
|
* published.
|
|
68
68
|
*
|
|
69
|
-
* @param handler Event handler that runs every time a Cloud Pub/Sub message
|
|
69
|
+
* @param handler - Event handler that runs every time a Cloud Pub/Sub message
|
|
70
70
|
* is published.
|
|
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,
|
|
@@ -86,7 +86,7 @@ exports.TopicBuilder = TopicBuilder;
|
|
|
86
86
|
/**
|
|
87
87
|
* Registers a Cloud Function to run at specified times.
|
|
88
88
|
*
|
|
89
|
-
* @param schedule The schedule, in Unix Crontab or AppEngine syntax.
|
|
89
|
+
* @param schedule - The schedule, in Unix Crontab or AppEngine syntax.
|
|
90
90
|
* @return ScheduleBuilder interface.
|
|
91
91
|
*/
|
|
92
92
|
function schedule(schedule) {
|
|
@@ -135,12 +135,12 @@ class ScheduleBuilder {
|
|
|
135
135
|
* Event handler for scheduled functions. Triggered whenever the associated
|
|
136
136
|
* scheduler job sends a Pub/Sub message.
|
|
137
137
|
*
|
|
138
|
-
* @param handler Handler that fires whenever the associated
|
|
138
|
+
* @param handler - Handler that fires whenever the associated
|
|
139
139
|
* scheduler job sends a Pub/Sub message.
|
|
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,
|
|
@@ -156,7 +156,7 @@ exports.ScheduleBuilder = ScheduleBuilder;
|
|
|
156
156
|
/**
|
|
157
157
|
* Interface representing a Google Cloud Pub/Sub message.
|
|
158
158
|
*
|
|
159
|
-
* @param data Payload of a Pub/Sub message.
|
|
159
|
+
* @param data - Payload of a Pub/Sub message.
|
|
160
160
|
*/
|
|
161
161
|
class Message {
|
|
162
162
|
constructor(data) {
|
|
@@ -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,46 +1,61 @@
|
|
|
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
|
-
|
|
5
|
-
export {
|
|
6
|
-
/** @hidden */
|
|
7
|
-
RetryConfig as RetryPolicy,
|
|
8
|
-
/** @hidden */
|
|
9
|
-
RateLimits,
|
|
10
|
-
/** @hidden */
|
|
11
|
-
TaskContext, };
|
|
5
|
+
export { RetryConfig, RateLimits, TaskContext };
|
|
12
6
|
/**
|
|
13
|
-
*
|
|
14
|
-
* @hidden
|
|
7
|
+
* Options for configuring the task queue to listen to.
|
|
15
8
|
*/
|
|
16
9
|
export interface TaskQueueOptions {
|
|
10
|
+
/** How a task should be retried in the event of a non-2xx return. */
|
|
17
11
|
retryConfig?: RetryConfig;
|
|
12
|
+
/** How congestion control should be applied to the function. */
|
|
18
13
|
rateLimits?: RateLimits;
|
|
19
14
|
/**
|
|
20
15
|
* Who can enqueue tasks for this function.
|
|
21
16
|
* If left unspecified, only service accounts which have
|
|
22
|
-
* roles/cloudtasks.enqueuer and roles/cloudfunctions.invoker
|
|
17
|
+
* `roles/cloudtasks.enqueuer` and `roles/cloudfunctions.invoker`
|
|
23
18
|
* will have permissions.
|
|
24
19
|
*/
|
|
25
20
|
invoker?: 'private' | string | string[];
|
|
26
21
|
}
|
|
27
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* A handler for tasks.
|
|
24
|
+
*/
|
|
28
25
|
export interface TaskQueueFunction {
|
|
29
26
|
(req: Request, res: express.Response): Promise<void>;
|
|
27
|
+
/** @alpha */
|
|
30
28
|
__trigger: unknown;
|
|
29
|
+
/** @alpha */
|
|
31
30
|
__endpoint: ManifestEndpoint;
|
|
31
|
+
/** @alpha */
|
|
32
32
|
__requiredAPIs?: ManifestRequiredAPI[];
|
|
33
|
+
/**
|
|
34
|
+
* The callback passed to the `TaskQueueFunction` constructor.
|
|
35
|
+
* @param data - The body enqueued into a task queue.
|
|
36
|
+
* @param context - The request context of the enqueued task
|
|
37
|
+
* @returns Any return value. Google Cloud Functions will await any promise
|
|
38
|
+
* before shutting down your function. Resolved return values
|
|
39
|
+
* are only used for unit testing purposes.
|
|
40
|
+
*/
|
|
33
41
|
run(data: any, context: TaskContext): void | Promise<void>;
|
|
34
42
|
}
|
|
35
|
-
/**
|
|
43
|
+
/**
|
|
44
|
+
* Builder for creating a `TaskQueueFunction`.
|
|
45
|
+
*/
|
|
36
46
|
export declare class TaskQueueBuilder {
|
|
37
47
|
private readonly tqOpts?;
|
|
38
48
|
private readonly depOpts?;
|
|
49
|
+
/**
|
|
50
|
+
* Creates a handler for tasks sent to a Google Cloud Tasks queue.
|
|
51
|
+
* @param handler - A callback to handle task requests.
|
|
52
|
+
* @returns A Cloud Function you can export and deploy.
|
|
53
|
+
*/
|
|
39
54
|
onDispatch(handler: (data: any, context: TaskContext) => void | Promise<void>): TaskQueueFunction;
|
|
40
55
|
}
|
|
41
56
|
/**
|
|
42
57
|
* Declares a function that can handle tasks enqueued using the Firebase Admin SDK.
|
|
43
|
-
* @param options Configuration for the Task Queue that feeds into this function.
|
|
44
|
-
*
|
|
58
|
+
* @param options - Configuration for the Task Queue that feeds into this function.
|
|
59
|
+
* Omitting options will configure a Task Queue with default settings.
|
|
45
60
|
*/
|
|
46
61
|
export declare function taskQueue(options?: TaskQueueOptions): TaskQueueBuilder;
|
package/lib/providers/tasks.js
CHANGED
|
@@ -25,34 +25,41 @@ exports.taskQueue = exports.TaskQueueBuilder = void 0;
|
|
|
25
25
|
const cloud_functions_1 = require("../cloud-functions");
|
|
26
26
|
const encoding_1 = require("../common/encoding");
|
|
27
27
|
const tasks_1 = require("../common/providers/tasks");
|
|
28
|
-
/**
|
|
28
|
+
/**
|
|
29
|
+
* Builder for creating a `TaskQueueFunction`.
|
|
30
|
+
*/
|
|
29
31
|
class TaskQueueBuilder {
|
|
30
32
|
/** @internal */
|
|
31
33
|
constructor(tqOpts, depOpts) {
|
|
32
34
|
this.tqOpts = tqOpts;
|
|
33
35
|
this.depOpts = depOpts;
|
|
34
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Creates a handler for tasks sent to a Google Cloud Tasks queue.
|
|
39
|
+
* @param handler - A callback to handle task requests.
|
|
40
|
+
* @returns A Cloud Function you can export and deploy.
|
|
41
|
+
*/
|
|
35
42
|
onDispatch(handler) {
|
|
36
43
|
// onEnqueueHandler sniffs the function length of the passed-in callback
|
|
37
44
|
// and the user could have only tried to listen to data. Wrap their handler
|
|
38
45
|
// in another handler to avoid accidentally triggering the v2 API
|
|
39
46
|
const fixedLen = (data, context) => handler(data, context);
|
|
40
|
-
const func = tasks_1.onDispatchHandler(fixedLen);
|
|
47
|
+
const func = (0, tasks_1.onDispatchHandler)(fixedLen);
|
|
41
48
|
func.__trigger = {
|
|
42
|
-
...cloud_functions_1.optionsToTrigger(this.depOpts || {}),
|
|
49
|
+
...(0, cloud_functions_1.optionsToTrigger)(this.depOpts || {}),
|
|
43
50
|
taskQueueTrigger: {},
|
|
44
51
|
};
|
|
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);
|
|
52
|
+
(0, encoding_1.copyIfPresent)(func.__trigger.taskQueueTrigger, this.tqOpts, 'retryConfig');
|
|
53
|
+
(0, encoding_1.copyIfPresent)(func.__trigger.taskQueueTrigger, this.tqOpts, 'rateLimits');
|
|
54
|
+
(0, encoding_1.convertIfPresent)(func.__trigger.taskQueueTrigger, this.tqOpts, 'invoker', 'invoker', encoding_1.convertInvoker);
|
|
48
55
|
func.__endpoint = {
|
|
49
56
|
platform: 'gcfv1',
|
|
50
|
-
...cloud_functions_1.optionsToEndpoint(this.depOpts),
|
|
57
|
+
...(0, cloud_functions_1.optionsToEndpoint)(this.depOpts),
|
|
51
58
|
taskQueueTrigger: {},
|
|
52
59
|
};
|
|
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);
|
|
60
|
+
(0, encoding_1.copyIfPresent)(func.__endpoint.taskQueueTrigger, this.tqOpts, 'retryConfig');
|
|
61
|
+
(0, encoding_1.copyIfPresent)(func.__endpoint.taskQueueTrigger, this.tqOpts, 'rateLimits');
|
|
62
|
+
(0, encoding_1.convertIfPresent)(func.__endpoint.taskQueueTrigger, this.tqOpts, 'invoker', 'invoker', encoding_1.convertInvoker);
|
|
56
63
|
func.__requiredAPIs = [
|
|
57
64
|
{
|
|
58
65
|
api: 'cloudtasks.googleapis.com',
|
|
@@ -66,8 +73,8 @@ class TaskQueueBuilder {
|
|
|
66
73
|
exports.TaskQueueBuilder = TaskQueueBuilder;
|
|
67
74
|
/**
|
|
68
75
|
* Declares a function that can handle tasks enqueued using the Firebase Admin SDK.
|
|
69
|
-
* @param options Configuration for the Task Queue that feeds into this function.
|
|
70
|
-
*
|
|
76
|
+
* @param options - Configuration for the Task Queue that feeds into this function.
|
|
77
|
+
* Omitting options will configure a Task Queue with default settings.
|
|
71
78
|
*/
|
|
72
79
|
function taskQueue(options) {
|
|
73
80
|
return new TaskQueueBuilder(options);
|