firebase-functions 3.15.7 → 3.17.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/bin/firebase-functions.d.ts +2 -0
- package/lib/bin/firebase-functions.js +48 -0
- package/lib/cloud-functions.d.ts +14 -8
- package/lib/cloud-functions.js +61 -1
- package/lib/common/debug.d.ts +1 -0
- package/lib/common/debug.js +54 -0
- package/lib/common/encoding.js +6 -0
- package/lib/common/providers/https.d.ts +92 -47
- package/lib/common/providers/https.js +171 -51
- package/lib/common/providers/identity.d.ts +29 -0
- package/lib/common/providers/identity.js +96 -0
- package/lib/function-builder.d.ts +7 -1
- package/lib/function-builder.js +8 -0
- package/lib/function-configuration.d.ts +1 -0
- package/lib/handler-builder.d.ts +19 -15
- package/lib/handler-builder.js +32 -15
- package/lib/providers/auth.d.ts +2 -21
- package/lib/providers/auth.js +5 -66
- package/lib/providers/database.js +2 -1
- package/lib/providers/https.d.ts +44 -2
- package/lib/providers/https.js +65 -2
- package/lib/runtime/loader.d.ts +1 -0
- package/lib/runtime/loader.js +101 -0
- package/lib/runtime/manifest.d.ts +55 -0
- package/lib/runtime/manifest.js +2 -0
- package/lib/v2/core.d.ts +10 -3
- package/lib/v2/index.d.ts +3 -1
- package/lib/v2/index.js +5 -1
- package/lib/v2/options.d.ts +1 -1
- package/lib/v2/options.js +47 -9
- package/lib/v2/params/types.d.ts +2 -1
- package/lib/v2/params/types.js +2 -0
- package/lib/v2/providers/alerts/alerts.d.ts +36 -0
- package/lib/v2/providers/alerts/alerts.js +72 -0
- package/lib/v2/providers/alerts/appDistribution.d.ts +35 -0
- package/lib/v2/providers/alerts/appDistribution.js +39 -0
- package/lib/v2/providers/alerts/billing.d.ts +38 -0
- package/lib/v2/providers/alerts/billing.js +30 -0
- package/lib/v2/providers/alerts/crashlytics.d.ts +123 -0
- package/lib/v2/providers/alerts/crashlytics.js +74 -0
- package/lib/v2/providers/alerts/index.d.ts +5 -0
- package/lib/v2/providers/alerts/index.js +20 -0
- package/lib/v2/providers/https.d.ts +23 -3
- package/lib/v2/providers/https.js +72 -3
- package/lib/v2/providers/pubsub.d.ts +1 -1
- package/lib/v2/providers/pubsub.js +19 -4
- package/lib/v2/providers/storage.d.ts +170 -0
- package/lib/v2/providers/storage.js +137 -0
- package/package.json +34 -7
package/lib/handler-builder.js
CHANGED
|
@@ -45,7 +45,7 @@ class HandlerBuilder {
|
|
|
45
45
|
constructor() { }
|
|
46
46
|
/**
|
|
47
47
|
* Create a handler for HTTPS events.
|
|
48
|
-
|
|
48
|
+
|
|
49
49
|
* `onRequest` handles an HTTPS request and has the same signature as an Express app.
|
|
50
50
|
*
|
|
51
51
|
* @example
|
|
@@ -65,13 +65,30 @@ class HandlerBuilder {
|
|
|
65
65
|
onRequest: (handler) => {
|
|
66
66
|
const func = https._onRequestWithOptions(handler, {});
|
|
67
67
|
func.__trigger = {};
|
|
68
|
+
func.__endpoint = undefined;
|
|
69
|
+
func.__requiredAPIs = undefined;
|
|
68
70
|
return func;
|
|
69
71
|
},
|
|
70
72
|
onCall: (handler) => {
|
|
71
73
|
const func = https._onCallWithOptions(handler, {});
|
|
72
74
|
func.__trigger = {};
|
|
75
|
+
func.__endpoint = undefined;
|
|
76
|
+
func.__requiredAPIs = undefined;
|
|
73
77
|
return func;
|
|
74
78
|
},
|
|
79
|
+
/** @hidden */
|
|
80
|
+
get taskQueue() {
|
|
81
|
+
return {
|
|
82
|
+
onEnqueue(handler) {
|
|
83
|
+
const builder = new https.TaskQueueBuilder();
|
|
84
|
+
const func = builder.onDispatch(handler);
|
|
85
|
+
func.__trigger = {};
|
|
86
|
+
func.__endpoint = undefined;
|
|
87
|
+
func.__requiredAPIs = undefined;
|
|
88
|
+
return func;
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
},
|
|
75
92
|
};
|
|
76
93
|
}
|
|
77
94
|
/**
|
|
@@ -90,7 +107,7 @@ class HandlerBuilder {
|
|
|
90
107
|
* ```javascript
|
|
91
108
|
* exports.myFunction = functions.handler.database.ref.onUpdate((change, context) => { ... })
|
|
92
109
|
* ```
|
|
93
|
-
|
|
110
|
+
|
|
94
111
|
* `ref.onDelete` handles the deletion of existing data.
|
|
95
112
|
*
|
|
96
113
|
* @example
|
|
@@ -129,14 +146,14 @@ class HandlerBuilder {
|
|
|
129
146
|
* ```javascript
|
|
130
147
|
* exports.myFunction = functions.handler.firestore.document.onCreate((snap, context) => { ... })
|
|
131
148
|
* ```
|
|
132
|
-
|
|
149
|
+
|
|
133
150
|
* `document.onUpdate` handles updates to existing documents.
|
|
134
151
|
*
|
|
135
152
|
* @example
|
|
136
153
|
* ```javascript
|
|
137
154
|
* exports.myFunction = functions.handler.firestore.document.onUpdate((change, context) => { ... })
|
|
138
155
|
* ```
|
|
139
|
-
|
|
156
|
+
|
|
140
157
|
* `document.onDelete` handles the deletion of existing documents.
|
|
141
158
|
*
|
|
142
159
|
* @example
|
|
@@ -144,7 +161,7 @@ class HandlerBuilder {
|
|
|
144
161
|
* exports.myFunction = functions.handler.firestore.document.onDelete((snap, context) =>
|
|
145
162
|
* { ... })
|
|
146
163
|
* ```
|
|
147
|
-
|
|
164
|
+
|
|
148
165
|
* `document.onWrite` handles the creation, update, or deletion of documents.
|
|
149
166
|
*
|
|
150
167
|
* @example
|
|
@@ -172,7 +189,7 @@ class HandlerBuilder {
|
|
|
172
189
|
* Create a handler for Firebase Remote Config events.
|
|
173
190
|
|
|
174
191
|
* `remoteConfig.onUpdate` handles events that update a Remote Config template.
|
|
175
|
-
|
|
192
|
+
|
|
176
193
|
* @example
|
|
177
194
|
* ```javascript
|
|
178
195
|
* exports.myFunction = functions.handler.remoteConfig.onUpdate() => { ... })
|
|
@@ -187,9 +204,9 @@ class HandlerBuilder {
|
|
|
187
204
|
}
|
|
188
205
|
/**
|
|
189
206
|
* Create a handler for Google Analytics events.
|
|
190
|
-
|
|
207
|
+
|
|
191
208
|
* `event.onLog` handles the logging of Analytics conversion events.
|
|
192
|
-
|
|
209
|
+
|
|
193
210
|
* @example
|
|
194
211
|
* ```javascript
|
|
195
212
|
* exports.myFunction = functions.handler.analytics.event.onLog((event) => { ... })
|
|
@@ -211,14 +228,14 @@ class HandlerBuilder {
|
|
|
211
228
|
* ```javascript
|
|
212
229
|
* exports.myFunction = functions.handler.storage.object.onArchive((object) => { ... })
|
|
213
230
|
* ```
|
|
214
|
-
|
|
231
|
+
|
|
215
232
|
* `object.onDelete` handles the deletion of Storage objects.
|
|
216
233
|
*
|
|
217
234
|
* @example
|
|
218
235
|
* ```javascript
|
|
219
236
|
* exports.myFunction = functions.handler.storage.object.onDelete((object) => { ... })
|
|
220
237
|
* ```
|
|
221
|
-
|
|
238
|
+
|
|
222
239
|
* `object.onFinalize` handles the creation of Storage objects.
|
|
223
240
|
*
|
|
224
241
|
* @example
|
|
@@ -226,7 +243,7 @@ class HandlerBuilder {
|
|
|
226
243
|
* exports.myFunction = functions.handler.storage.object.onFinalize((object) =>
|
|
227
244
|
* { ... })
|
|
228
245
|
* ```
|
|
229
|
-
|
|
246
|
+
|
|
230
247
|
* `object.onMetadataUpdate` handles changes to the metadata of existing Storage objects.
|
|
231
248
|
*
|
|
232
249
|
* @example
|
|
@@ -254,7 +271,7 @@ class HandlerBuilder {
|
|
|
254
271
|
* ```javascript
|
|
255
272
|
* exports.myFunction = functions.handler.pubsub.topic.onPublish((message) => { ... })
|
|
256
273
|
* ```
|
|
257
|
-
|
|
274
|
+
|
|
258
275
|
* `schedule.onPublish` handles messages published to a Pub/Sub topic on a schedule.
|
|
259
276
|
*
|
|
260
277
|
* @example
|
|
@@ -281,14 +298,14 @@ class HandlerBuilder {
|
|
|
281
298
|
* ```javascript
|
|
282
299
|
* exports.myFunction = functions.handler.auth.user.onCreate((user) => { ... })
|
|
283
300
|
* ```
|
|
284
|
-
|
|
301
|
+
|
|
285
302
|
* `user.onDelete` handles the deletion of users.
|
|
286
303
|
*
|
|
287
304
|
* @example
|
|
288
305
|
* ```javascript
|
|
289
306
|
* exports.myFunction = functions.handler.auth.user.onDelete((user => { ... })
|
|
290
307
|
* ```
|
|
291
|
-
|
|
308
|
+
|
|
292
309
|
*/
|
|
293
310
|
get auth() {
|
|
294
311
|
return {
|
|
@@ -301,7 +318,7 @@ class HandlerBuilder {
|
|
|
301
318
|
* Create a handler for Firebase Test Lab events.
|
|
302
319
|
|
|
303
320
|
* `testMatrix.onComplete` handles the completion of a test matrix.
|
|
304
|
-
|
|
321
|
+
|
|
305
322
|
* @example
|
|
306
323
|
* ```javascript
|
|
307
324
|
* exports.myFunction = functions.handler.testLab.testMatrix.onComplete((testMatrix) => { ... })
|
package/lib/providers/auth.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { UserRecord, UserInfo, UserRecordMetadata, userRecordConstructor } from '../common/providers/identity';
|
|
2
2
|
import { CloudFunction, EventContext } from '../cloud-functions';
|
|
3
3
|
import { DeploymentOptions } from '../function-configuration';
|
|
4
|
+
export { UserRecord, UserInfo, UserRecordMetadata, userRecordConstructor };
|
|
4
5
|
/** @hidden */
|
|
5
6
|
export declare const provider = "google.firebase.auth";
|
|
6
7
|
/** @hidden */
|
|
@@ -11,16 +12,6 @@ export declare const service = "firebaseauth.googleapis.com";
|
|
|
11
12
|
export declare function user(): UserBuilder;
|
|
12
13
|
/** @hidden */
|
|
13
14
|
export declare function _userWithOptions(options: DeploymentOptions): UserBuilder;
|
|
14
|
-
export declare class UserRecordMetadata implements firebase.auth.UserMetadata {
|
|
15
|
-
creationTime: string;
|
|
16
|
-
lastSignInTime: string;
|
|
17
|
-
constructor(creationTime: string, lastSignInTime: string);
|
|
18
|
-
/** Returns a plain JavaScript object with the properties of UserRecordMetadata. */
|
|
19
|
-
toJSON(): {
|
|
20
|
-
creationTime: string;
|
|
21
|
-
lastSignInTime: string;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
15
|
/** Builder used to create Cloud Functions for Firebase Auth user lifecycle events. */
|
|
25
16
|
export declare class UserBuilder {
|
|
26
17
|
private triggerResource;
|
|
@@ -34,13 +25,3 @@ export declare class UserBuilder {
|
|
|
34
25
|
onDelete(handler: (user: UserRecord, context: EventContext) => PromiseLike<any> | any): CloudFunction<UserRecord>;
|
|
35
26
|
private onOperation;
|
|
36
27
|
}
|
|
37
|
-
/**
|
|
38
|
-
* The UserRecord passed to Cloud Functions is the same UserRecord that is returned by the Firebase Admin
|
|
39
|
-
* SDK.
|
|
40
|
-
*/
|
|
41
|
-
export declare type UserRecord = firebase.auth.UserRecord;
|
|
42
|
-
/**
|
|
43
|
-
* UserInfo that is part of the UserRecord
|
|
44
|
-
*/
|
|
45
|
-
export declare type UserInfo = firebase.auth.UserInfo;
|
|
46
|
-
export declare function userRecordConstructor(wireData: Object): firebase.auth.UserRecord;
|
package/lib/providers/auth.js
CHANGED
|
@@ -21,8 +21,10 @@
|
|
|
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.
|
|
25
|
-
const
|
|
24
|
+
exports.UserBuilder = exports._userWithOptions = exports.user = exports.service = exports.provider = exports.userRecordConstructor = exports.UserRecordMetadata = void 0;
|
|
25
|
+
const identity_1 = require("../common/providers/identity");
|
|
26
|
+
Object.defineProperty(exports, "UserRecordMetadata", { enumerable: true, get: function () { return identity_1.UserRecordMetadata; } });
|
|
27
|
+
Object.defineProperty(exports, "userRecordConstructor", { enumerable: true, get: function () { return identity_1.userRecordConstructor; } });
|
|
26
28
|
const cloud_functions_1 = require("../cloud-functions");
|
|
27
29
|
/** @hidden */
|
|
28
30
|
exports.provider = 'google.firebase.auth';
|
|
@@ -45,20 +47,6 @@ function _userWithOptions(options) {
|
|
|
45
47
|
}, options);
|
|
46
48
|
}
|
|
47
49
|
exports._userWithOptions = _userWithOptions;
|
|
48
|
-
class UserRecordMetadata {
|
|
49
|
-
constructor(creationTime, lastSignInTime) {
|
|
50
|
-
this.creationTime = creationTime;
|
|
51
|
-
this.lastSignInTime = lastSignInTime;
|
|
52
|
-
}
|
|
53
|
-
/** Returns a plain JavaScript object with the properties of UserRecordMetadata. */
|
|
54
|
-
toJSON() {
|
|
55
|
-
return {
|
|
56
|
-
creationTime: this.creationTime,
|
|
57
|
-
lastSignInTime: this.lastSignInTime,
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
exports.UserRecordMetadata = UserRecordMetadata;
|
|
62
50
|
/** Builder used to create Cloud Functions for Firebase Auth user lifecycle events. */
|
|
63
51
|
class UserBuilder {
|
|
64
52
|
/** @hidden */
|
|
@@ -67,7 +55,7 @@ class UserBuilder {
|
|
|
67
55
|
this.options = options;
|
|
68
56
|
}
|
|
69
57
|
static dataConstructor(raw) {
|
|
70
|
-
return userRecordConstructor(raw.data);
|
|
58
|
+
return (0, identity_1.userRecordConstructor)(raw.data);
|
|
71
59
|
}
|
|
72
60
|
/** Respond to the creation of a Firebase Auth user. */
|
|
73
61
|
onCreate(handler) {
|
|
@@ -91,52 +79,3 @@ class UserBuilder {
|
|
|
91
79
|
}
|
|
92
80
|
}
|
|
93
81
|
exports.UserBuilder = UserBuilder;
|
|
94
|
-
function userRecordConstructor(wireData) {
|
|
95
|
-
// Falsey values from the wire format proto get lost when converted to JSON, this adds them back.
|
|
96
|
-
const falseyValues = {
|
|
97
|
-
email: null,
|
|
98
|
-
emailVerified: false,
|
|
99
|
-
displayName: null,
|
|
100
|
-
photoURL: null,
|
|
101
|
-
phoneNumber: null,
|
|
102
|
-
disabled: false,
|
|
103
|
-
providerData: [],
|
|
104
|
-
customClaims: {},
|
|
105
|
-
passwordSalt: null,
|
|
106
|
-
passwordHash: null,
|
|
107
|
-
tokensValidAfterTime: null,
|
|
108
|
-
};
|
|
109
|
-
const record = _.assign({}, falseyValues, wireData);
|
|
110
|
-
const meta = _.get(record, 'metadata');
|
|
111
|
-
if (meta) {
|
|
112
|
-
_.set(record, 'metadata', new UserRecordMetadata(meta.createdAt || meta.creationTime, meta.lastSignedInAt || meta.lastSignInTime));
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
_.set(record, 'metadata', new UserRecordMetadata(null, null));
|
|
116
|
-
}
|
|
117
|
-
_.forEach(record.providerData, (entry) => {
|
|
118
|
-
_.set(entry, 'toJSON', () => {
|
|
119
|
-
return entry;
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
_.set(record, 'toJSON', () => {
|
|
123
|
-
const json = _.pick(record, [
|
|
124
|
-
'uid',
|
|
125
|
-
'email',
|
|
126
|
-
'emailVerified',
|
|
127
|
-
'displayName',
|
|
128
|
-
'photoURL',
|
|
129
|
-
'phoneNumber',
|
|
130
|
-
'disabled',
|
|
131
|
-
'passwordHash',
|
|
132
|
-
'passwordSalt',
|
|
133
|
-
'tokensValidAfterTime',
|
|
134
|
-
]);
|
|
135
|
-
json.metadata = _.get(record, 'metadata').toJSON();
|
|
136
|
-
json.customClaims = _.cloneDeep(record.customClaims);
|
|
137
|
-
json.providerData = _.map(record.providerData, (entry) => entry.toJSON());
|
|
138
|
-
return json;
|
|
139
|
-
});
|
|
140
|
-
return record;
|
|
141
|
-
}
|
|
142
|
-
exports.userRecordConstructor = userRecordConstructor;
|
|
@@ -266,8 +266,9 @@ exports.extractInstanceAndPath = extractInstanceAndPath;
|
|
|
266
266
|
class DataSnapshot {
|
|
267
267
|
constructor(data, path, // path will be undefined for the database root
|
|
268
268
|
app, instance) {
|
|
269
|
+
var _a, _b;
|
|
269
270
|
this.app = app;
|
|
270
|
-
if (app
|
|
271
|
+
if ((_b = (_a = app === null || app === void 0 ? void 0 : app.options) === null || _a === void 0 ? void 0 : _a.databaseURL) === null || _b === void 0 ? void 0 : _b.startsWith('http:')) {
|
|
271
272
|
// In this case we're dealing with an emulator
|
|
272
273
|
this.instance = app.options.databaseURL;
|
|
273
274
|
}
|
package/lib/providers/https.d.ts
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import * as express from 'express';
|
|
2
2
|
import { HttpsFunction, Runnable } from '../cloud-functions';
|
|
3
|
-
import {
|
|
3
|
+
import { ManifestEndpoint, ManifestRequiredAPI } from '../runtime/manifest';
|
|
4
|
+
import { CallableContext, FunctionsErrorCode, HttpsError, Request, TaskContext, TaskRateLimits, TaskRetryConfig } from '../common/providers/https';
|
|
4
5
|
import { DeploymentOptions } from '../function-configuration';
|
|
5
|
-
export { Request, CallableContext, FunctionsErrorCode, HttpsError
|
|
6
|
+
export { Request, CallableContext, FunctionsErrorCode, HttpsError,
|
|
7
|
+
/** @hidden */
|
|
8
|
+
TaskRetryConfig as TaskRetryPolicy,
|
|
9
|
+
/** @hidden */
|
|
10
|
+
TaskRateLimits,
|
|
11
|
+
/** @hidden */
|
|
12
|
+
TaskContext, };
|
|
6
13
|
/**
|
|
7
14
|
* Handle HTTP requests.
|
|
8
15
|
* @param handler A function that takes a request and response object,
|
|
@@ -14,6 +21,41 @@ export declare function onRequest(handler: (req: Request, resp: express.Response
|
|
|
14
21
|
* @param handler A method that takes a data and context and returns a value.
|
|
15
22
|
*/
|
|
16
23
|
export declare function onCall(handler: (data: any, context: CallableContext) => any | Promise<any>): HttpsFunction & Runnable<any>;
|
|
24
|
+
/**
|
|
25
|
+
* Configurations for Task Queue Functions.
|
|
26
|
+
* @hidden
|
|
27
|
+
*/
|
|
28
|
+
export interface TaskQueueOptions {
|
|
29
|
+
retryConfig?: TaskRetryConfig;
|
|
30
|
+
rateLimits?: TaskRateLimits;
|
|
31
|
+
/**
|
|
32
|
+
* Who can enqueue tasks for this function.
|
|
33
|
+
* If left unspecified, only service accounts which have
|
|
34
|
+
* roles/cloudtasks.enqueuer and roles/cloudfunctions.invoker
|
|
35
|
+
* will have permissions.
|
|
36
|
+
*/
|
|
37
|
+
invoker?: 'private' | string | string[];
|
|
38
|
+
}
|
|
39
|
+
/** @hidden */
|
|
40
|
+
export interface TaskQueueFunction {
|
|
41
|
+
(req: Request, res: express.Response): Promise<void>;
|
|
42
|
+
__trigger: unknown;
|
|
43
|
+
__endpoint: ManifestEndpoint;
|
|
44
|
+
__requiredAPIs?: ManifestRequiredAPI[];
|
|
45
|
+
run(data: any, context: TaskContext): void | Promise<void>;
|
|
46
|
+
}
|
|
47
|
+
/** @hidden */
|
|
48
|
+
export declare class TaskQueueBuilder {
|
|
49
|
+
private readonly tqOpts?;
|
|
50
|
+
private readonly depOpts?;
|
|
51
|
+
onDispatch(handler: (data: any, context: TaskContext) => void | Promise<void>): TaskQueueFunction;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Declares a function that can handle tasks enqueued using the Firebase Admin SDK.
|
|
55
|
+
* @param options Configuration for the Task Queue that feeds into this function.
|
|
56
|
+
* @hidden
|
|
57
|
+
*/
|
|
58
|
+
export declare function taskQueue(options?: TaskQueueOptions): TaskQueueBuilder;
|
|
17
59
|
/** @hidden */
|
|
18
60
|
export declare function _onRequestWithOptions(handler: (req: Request, resp: express.Response) => void | Promise<void>, options: DeploymentOptions): HttpsFunction;
|
|
19
61
|
/** @hidden */
|
package/lib/providers/https.js
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
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._onCallWithOptions = exports._onRequestWithOptions = exports.onCall = exports.onRequest = exports.HttpsError = void 0;
|
|
24
|
+
exports._onCallWithOptions = exports._onRequestWithOptions = exports.taskQueue = exports.TaskQueueBuilder = exports.onCall = exports.onRequest = exports.HttpsError = void 0;
|
|
25
25
|
const cloud_functions_1 = require("../cloud-functions");
|
|
26
26
|
const encoding_1 = require("../common/encoding");
|
|
27
27
|
const https_1 = require("../common/providers/https");
|
|
@@ -44,6 +44,54 @@ function onCall(handler) {
|
|
|
44
44
|
}
|
|
45
45
|
exports.onCall = onCall;
|
|
46
46
|
/** @hidden */
|
|
47
|
+
class TaskQueueBuilder {
|
|
48
|
+
/** @internal */
|
|
49
|
+
constructor(tqOpts, depOpts) {
|
|
50
|
+
this.tqOpts = tqOpts;
|
|
51
|
+
this.depOpts = depOpts;
|
|
52
|
+
}
|
|
53
|
+
onDispatch(handler) {
|
|
54
|
+
// onEnqueueHandler sniffs the function length of the passed-in callback
|
|
55
|
+
// and the user could have only tried to listen to data. Wrap their handler
|
|
56
|
+
// in another handler to avoid accidentally triggering the v2 API
|
|
57
|
+
const fixedLen = (data, context) => handler(data, context);
|
|
58
|
+
const func = (0, https_1.onDispatchHandler)(fixedLen);
|
|
59
|
+
func.__trigger = {
|
|
60
|
+
...(0, cloud_functions_1.optionsToTrigger)(this.depOpts || {}),
|
|
61
|
+
taskQueueTrigger: {},
|
|
62
|
+
};
|
|
63
|
+
(0, encoding_1.copyIfPresent)(func.__trigger.taskQueueTrigger, this.tqOpts, 'retryConfig');
|
|
64
|
+
(0, encoding_1.copyIfPresent)(func.__trigger.taskQueueTrigger, this.tqOpts, 'rateLimits');
|
|
65
|
+
(0, encoding_1.convertIfPresent)(func.__trigger.taskQueueTrigger, this.tqOpts, 'invoker', 'invoker', encoding_1.convertInvoker);
|
|
66
|
+
func.__endpoint = {
|
|
67
|
+
platform: 'gcfv1',
|
|
68
|
+
...(0, cloud_functions_1.optionsToEndpoint)(this.depOpts),
|
|
69
|
+
taskQueueTrigger: {},
|
|
70
|
+
};
|
|
71
|
+
(0, encoding_1.copyIfPresent)(func.__endpoint.taskQueueTrigger, this.tqOpts, 'retryConfig');
|
|
72
|
+
(0, encoding_1.copyIfPresent)(func.__endpoint.taskQueueTrigger, this.tqOpts, 'rateLimits');
|
|
73
|
+
(0, encoding_1.convertIfPresent)(func.__endpoint.taskQueueTrigger, this.tqOpts, 'invoker', 'invoker', encoding_1.convertInvoker);
|
|
74
|
+
func.__requiredAPIs = [
|
|
75
|
+
{
|
|
76
|
+
api: 'cloudtasks.googleapis.com',
|
|
77
|
+
reason: 'Needed for task queue functions',
|
|
78
|
+
},
|
|
79
|
+
];
|
|
80
|
+
func.run = handler;
|
|
81
|
+
return func;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.TaskQueueBuilder = TaskQueueBuilder;
|
|
85
|
+
/**
|
|
86
|
+
* Declares a function that can handle tasks enqueued using the Firebase Admin SDK.
|
|
87
|
+
* @param options Configuration for the Task Queue that feeds into this function.
|
|
88
|
+
* @hidden
|
|
89
|
+
*/
|
|
90
|
+
function taskQueue(options) {
|
|
91
|
+
return new TaskQueueBuilder(options);
|
|
92
|
+
}
|
|
93
|
+
exports.taskQueue = taskQueue;
|
|
94
|
+
/** @hidden */
|
|
47
95
|
function _onRequestWithOptions(handler, options) {
|
|
48
96
|
// lets us add __trigger without altering handler:
|
|
49
97
|
const cloudFunction = (req, res) => {
|
|
@@ -55,6 +103,12 @@ function _onRequestWithOptions(handler, options) {
|
|
|
55
103
|
};
|
|
56
104
|
(0, encoding_1.convertIfPresent)(cloudFunction.__trigger.httpsTrigger, options, 'invoker', 'invoker', encoding_1.convertInvoker);
|
|
57
105
|
// TODO parse the options
|
|
106
|
+
cloudFunction.__endpoint = {
|
|
107
|
+
platform: 'gcfv1',
|
|
108
|
+
...(0, cloud_functions_1.optionsToEndpoint)(options),
|
|
109
|
+
httpsTrigger: {},
|
|
110
|
+
};
|
|
111
|
+
(0, encoding_1.convertIfPresent)(cloudFunction.__endpoint.httpsTrigger, options, 'invoker', 'invoker', encoding_1.convertInvoker);
|
|
58
112
|
return cloudFunction;
|
|
59
113
|
}
|
|
60
114
|
exports._onRequestWithOptions = _onRequestWithOptions;
|
|
@@ -64,13 +118,22 @@ function _onCallWithOptions(handler, options) {
|
|
|
64
118
|
// and the user could have only tried to listen to data. Wrap their handler
|
|
65
119
|
// in another handler to avoid accidentally triggering the v2 API
|
|
66
120
|
const fixedLen = (data, context) => handler(data, context);
|
|
67
|
-
const func = (0, https_1.onCallHandler)({
|
|
121
|
+
const func = (0, https_1.onCallHandler)({
|
|
122
|
+
allowInvalidAppCheckToken: options.allowInvalidAppCheckToken,
|
|
123
|
+
cors: { origin: true, methods: 'POST' },
|
|
124
|
+
}, fixedLen);
|
|
68
125
|
func.__trigger = {
|
|
69
126
|
labels: {},
|
|
70
127
|
...(0, cloud_functions_1.optionsToTrigger)(options),
|
|
71
128
|
httpsTrigger: {},
|
|
72
129
|
};
|
|
73
130
|
func.__trigger.labels['deployment-callable'] = 'true';
|
|
131
|
+
func.__endpoint = {
|
|
132
|
+
platform: 'gcfv1',
|
|
133
|
+
labels: {},
|
|
134
|
+
...(0, cloud_functions_1.optionsToEndpoint)(options),
|
|
135
|
+
callableTrigger: {},
|
|
136
|
+
};
|
|
74
137
|
func.run = handler;
|
|
75
138
|
return func;
|
|
76
139
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadStack = exports.mergeRequiredAPIs = exports.extractStack = void 0;
|
|
4
|
+
// The MIT License (MIT)
|
|
5
|
+
//
|
|
6
|
+
// Copyright (c) 2021 Firebase
|
|
7
|
+
//
|
|
8
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
// in the Software without restriction, including without limitation the rights
|
|
11
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
// furnished to do so, subject to the following conditions:
|
|
14
|
+
//
|
|
15
|
+
// The above copyright notice and this permission notice shall be included in
|
|
16
|
+
// all copies or substantial portions of the Software.
|
|
17
|
+
//
|
|
18
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
+
// SOFTWARE.
|
|
25
|
+
const url = require("url");
|
|
26
|
+
const path = require("path");
|
|
27
|
+
/**
|
|
28
|
+
* Dynamically load import function to prevent TypeScript from
|
|
29
|
+
* transpiling into a require.
|
|
30
|
+
*
|
|
31
|
+
* See https://github.com/microsoft/TypeScript/issues/43329.
|
|
32
|
+
*/
|
|
33
|
+
const dynamicImport = new Function('modulePath', 'return import(modulePath)');
|
|
34
|
+
async function loadModule(functionsDir) {
|
|
35
|
+
const absolutePath = path.resolve(functionsDir);
|
|
36
|
+
try {
|
|
37
|
+
return require(path.resolve(absolutePath));
|
|
38
|
+
}
|
|
39
|
+
catch (e) {
|
|
40
|
+
if (e.code === 'ERR_REQUIRE_ESM') {
|
|
41
|
+
// This is an ESM package!
|
|
42
|
+
const modulePath = require.resolve(absolutePath);
|
|
43
|
+
// Resolve module path to file:// URL. Required for windows support.
|
|
44
|
+
// @ts-ignore pathToFileURL exists for Node.js v10 and up. Since ESM support exists for Node.js v13 and up, we
|
|
45
|
+
// can be sure that this function exists here.
|
|
46
|
+
const moduleURL = url.pathToFileURL(modulePath).href;
|
|
47
|
+
return await dynamicImport(moduleURL);
|
|
48
|
+
}
|
|
49
|
+
throw e;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/* @internal */
|
|
53
|
+
function extractStack(module, endpoints, requiredAPIs, prefix = '') {
|
|
54
|
+
for (const [name, val] of Object.entries(module)) {
|
|
55
|
+
if (typeof val === 'function' &&
|
|
56
|
+
val['__endpoint'] &&
|
|
57
|
+
typeof val['__endpoint'] === 'object') {
|
|
58
|
+
const funcName = prefix + name;
|
|
59
|
+
endpoints[funcName] = {
|
|
60
|
+
...val['__endpoint'],
|
|
61
|
+
entryPoint: funcName.replace(/-/g, '.'),
|
|
62
|
+
};
|
|
63
|
+
if (val['__requiredAPIs'] && Array.isArray(val['__requiredAPIs'])) {
|
|
64
|
+
requiredAPIs.push(...val['__requiredAPIs']);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else if (typeof val === 'object' && val !== null) {
|
|
68
|
+
extractStack(val, endpoints, requiredAPIs, prefix + name + '-');
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.extractStack = extractStack;
|
|
73
|
+
/* @internal */
|
|
74
|
+
function mergeRequiredAPIs(requiredAPIs) {
|
|
75
|
+
const apiToReasons = {};
|
|
76
|
+
for (const { api, reason } of requiredAPIs) {
|
|
77
|
+
const reasons = apiToReasons[api] || new Set();
|
|
78
|
+
reasons.add(reason);
|
|
79
|
+
apiToReasons[api] = reasons;
|
|
80
|
+
}
|
|
81
|
+
const merged = [];
|
|
82
|
+
for (const [api, reasons] of Object.entries(apiToReasons)) {
|
|
83
|
+
merged.push({ api, reason: Array.from(reasons).join(' ') });
|
|
84
|
+
}
|
|
85
|
+
return merged;
|
|
86
|
+
}
|
|
87
|
+
exports.mergeRequiredAPIs = mergeRequiredAPIs;
|
|
88
|
+
/* @internal */
|
|
89
|
+
async function loadStack(functionsDir) {
|
|
90
|
+
const endpoints = {};
|
|
91
|
+
const requiredAPIs = [];
|
|
92
|
+
const mod = await loadModule(functionsDir);
|
|
93
|
+
extractStack(mod, endpoints, requiredAPIs);
|
|
94
|
+
const stack = {
|
|
95
|
+
endpoints,
|
|
96
|
+
specVersion: 'v1alpha1',
|
|
97
|
+
requiredAPIs: mergeRequiredAPIs(requiredAPIs),
|
|
98
|
+
};
|
|
99
|
+
return stack;
|
|
100
|
+
}
|
|
101
|
+
exports.loadStack = loadStack;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An definition of a function as appears in the Manifest.
|
|
3
|
+
*/
|
|
4
|
+
export interface ManifestEndpoint {
|
|
5
|
+
entryPoint?: string;
|
|
6
|
+
region?: string[];
|
|
7
|
+
platform?: string;
|
|
8
|
+
availableMemoryMb?: number;
|
|
9
|
+
maxInstances?: number;
|
|
10
|
+
minInstances?: number;
|
|
11
|
+
concurrency?: number;
|
|
12
|
+
serviceAccountEmail?: string;
|
|
13
|
+
timeoutSeconds?: number;
|
|
14
|
+
vpc?: {
|
|
15
|
+
connector: string;
|
|
16
|
+
egressSettings?: string;
|
|
17
|
+
};
|
|
18
|
+
labels?: Record<string, string>;
|
|
19
|
+
ingressSettings?: string;
|
|
20
|
+
environmentVariables?: Record<string, string>;
|
|
21
|
+
httpsTrigger?: {
|
|
22
|
+
invoker?: string[];
|
|
23
|
+
};
|
|
24
|
+
callableTrigger?: {};
|
|
25
|
+
eventTrigger?: {
|
|
26
|
+
eventFilters: Record<string, string>;
|
|
27
|
+
eventType: string;
|
|
28
|
+
retry: boolean;
|
|
29
|
+
region?: string;
|
|
30
|
+
serviceAccountEmail?: string;
|
|
31
|
+
};
|
|
32
|
+
scheduleTrigger?: {
|
|
33
|
+
schedule?: string;
|
|
34
|
+
timezone?: string;
|
|
35
|
+
retryConfig?: {
|
|
36
|
+
retryCount?: number;
|
|
37
|
+
maxRetryDuration?: string;
|
|
38
|
+
minBackoffDuration?: string;
|
|
39
|
+
maxBackoffDuration?: string;
|
|
40
|
+
maxDoublings?: number;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export interface ManifestRequiredAPI {
|
|
45
|
+
api: string;
|
|
46
|
+
reason: string;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* An definition of a function deployment as appears in the Manifest.
|
|
50
|
+
**/
|
|
51
|
+
export interface ManifestStack {
|
|
52
|
+
specVersion: 'v1alpha1';
|
|
53
|
+
requiredAPIs: ManifestRequiredAPI[];
|
|
54
|
+
endpoints: Record<string, ManifestEndpoint>;
|
|
55
|
+
}
|
package/lib/v2/core.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { ManifestEndpoint } from '../runtime/manifest';
|
|
1
2
|
/**
|
|
2
|
-
* A
|
|
3
|
+
* A CloudEventBase is the base of a cross-platform format for encoding a serverless event.
|
|
3
4
|
* More information can be found in https://github.com/cloudevents/spec
|
|
4
5
|
*/
|
|
5
|
-
|
|
6
|
+
interface CloudEventBase<T> {
|
|
6
7
|
/** Version of the CloudEvents spec for this event. */
|
|
7
8
|
readonly specversion: '1.0';
|
|
8
9
|
/** A globally unique ID for this event. */
|
|
@@ -31,9 +32,15 @@ export interface CloudEvent<T> {
|
|
|
31
32
|
*/
|
|
32
33
|
params?: Record<string, string>;
|
|
33
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* A CloudEvent with custom extension attributes
|
|
37
|
+
*/
|
|
38
|
+
export declare type CloudEvent<T = any, Ext = {}> = CloudEventBase<T> & Ext;
|
|
34
39
|
/** A handler for CloudEvents. */
|
|
35
40
|
export interface CloudFunction<T> {
|
|
36
41
|
(raw: CloudEvent<unknown>): any | Promise<any>;
|
|
37
|
-
__trigger
|
|
42
|
+
__trigger?: unknown;
|
|
43
|
+
__endpoint: ManifestEndpoint;
|
|
38
44
|
run(event: CloudEvent<T>): any | Promise<any>;
|
|
39
45
|
}
|
|
46
|
+
export {};
|
package/lib/v2/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import * as logger from '../logger';
|
|
2
2
|
import * as params from './params';
|
|
3
|
+
import * as alerts from './providers/alerts';
|
|
3
4
|
import * as https from './providers/https';
|
|
4
5
|
import * as pubsub from './providers/pubsub';
|
|
5
|
-
|
|
6
|
+
import * as storage from './providers/storage';
|
|
7
|
+
export { https, pubsub, storage, logger, params, alerts };
|
|
6
8
|
export { setGlobalOptions, GlobalOptions } from './options';
|
|
7
9
|
export { CloudFunction, CloudEvent } from './core';
|