firebase-functions 3.19.0 → 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/cloud-functions.d.ts +8 -0
- package/lib/cloud-functions.js +4 -7
- package/lib/common/providers/https.d.ts +20 -49
- package/lib/common/providers/https.js +7 -45
- package/lib/common/providers/identity.d.ts +193 -4
- package/lib/common/providers/identity.js +402 -28
- package/lib/common/providers/tasks.d.ts +58 -0
- package/lib/common/providers/tasks.js +77 -0
- package/lib/function-builder.d.ts +5 -2
- package/lib/function-builder.js +7 -2
- package/lib/handler-builder.d.ts +13 -2
- package/lib/handler-builder.js +17 -4
- package/lib/index.d.ts +2 -1
- package/lib/index.js +3 -1
- package/lib/providers/auth.d.ts +19 -6
- package/lib/providers/auth.js +60 -8
- package/lib/providers/https.d.ts +2 -44
- package/lib/providers/https.js +1 -49
- package/lib/providers/tasks.d.ts +46 -0
- package/lib/providers/tasks.js +75 -0
- package/lib/runtime/loader.js +9 -7
- package/lib/runtime/manifest.d.ts +8 -10
- package/lib/runtime/manifest.js +21 -0
- package/lib/v2/core.d.ts +3 -21
- package/lib/v2/index.d.ts +4 -1
- package/lib/v2/index.js +7 -1
- package/lib/v2/options.d.ts +13 -2
- package/lib/v2/options.js +22 -30
- package/lib/v2/providers/alerts/alerts.d.ts +15 -7
- package/lib/v2/providers/alerts/alerts.js +4 -10
- package/lib/v2/providers/alerts/appDistribution.d.ts +11 -11
- package/lib/v2/providers/alerts/billing.d.ts +17 -11
- package/lib/v2/providers/alerts/crashlytics.d.ts +62 -29
- package/lib/v2/providers/eventarc.d.ts +32 -0
- package/lib/v2/providers/eventarc.js +65 -0
- package/lib/v2/providers/https.d.ts +8 -23
- package/lib/v2/providers/https.js +3 -48
- 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 +22 -0
- package/lib/v2/providers/tasks.js +88 -0
- package/package.json +42 -15
package/lib/handler-builder.js
CHANGED
|
@@ -31,6 +31,7 @@ const https = require("./providers/https");
|
|
|
31
31
|
const pubsub = require("./providers/pubsub");
|
|
32
32
|
const remoteConfig = require("./providers/remoteConfig");
|
|
33
33
|
const storage = require("./providers/storage");
|
|
34
|
+
const tasks = require("./providers/tasks");
|
|
34
35
|
const testLab = require("./providers/testLab");
|
|
35
36
|
/**
|
|
36
37
|
* The `HandlerBuilder` class facilitates the writing of functions by developers
|
|
@@ -76,11 +77,23 @@ class HandlerBuilder {
|
|
|
76
77
|
func.__requiredAPIs = undefined;
|
|
77
78
|
return func;
|
|
78
79
|
},
|
|
79
|
-
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Create a handler for tasks functions.
|
|
84
|
+
*
|
|
85
|
+
* @example
|
|
86
|
+
* ```javascript
|
|
87
|
+
* exports.myFunction = functions.handler.tasks.onDispatch((data, context) => { ... })
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
/** @hidden */
|
|
91
|
+
get tasks() {
|
|
92
|
+
return {
|
|
80
93
|
get taskQueue() {
|
|
81
94
|
return {
|
|
82
|
-
|
|
83
|
-
const builder = new
|
|
95
|
+
onDispatch: (handler) => {
|
|
96
|
+
const builder = new tasks.TaskQueueBuilder();
|
|
84
97
|
const func = builder.onDispatch(handler);
|
|
85
98
|
func.__trigger = {};
|
|
86
99
|
func.__endpoint = undefined;
|
|
@@ -310,7 +323,7 @@ class HandlerBuilder {
|
|
|
310
323
|
get auth() {
|
|
311
324
|
return {
|
|
312
325
|
get user() {
|
|
313
|
-
return new auth.UserBuilder(() => null, {});
|
|
326
|
+
return new auth.UserBuilder(() => null, {}, {});
|
|
314
327
|
},
|
|
315
328
|
};
|
|
316
329
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -6,12 +6,13 @@ import * as https from './providers/https';
|
|
|
6
6
|
import * as pubsub from './providers/pubsub';
|
|
7
7
|
import * as remoteConfig from './providers/remoteConfig';
|
|
8
8
|
import * as storage from './providers/storage';
|
|
9
|
+
import * as tasks from './providers/tasks';
|
|
9
10
|
import * as testLab from './providers/testLab';
|
|
10
11
|
import * as apps from './apps';
|
|
11
12
|
import { handler } from './handler-builder';
|
|
12
13
|
import * as logger from './logger';
|
|
13
14
|
declare const app: apps.apps.Apps;
|
|
14
|
-
export { analytics, app, auth, database, firestore, handler, https, pubsub, remoteConfig, storage, testLab, logger, };
|
|
15
|
+
export { analytics, app, auth, database, firestore, handler, https, pubsub, remoteConfig, storage, tasks, testLab, logger, };
|
|
15
16
|
export * from './cloud-functions';
|
|
16
17
|
export * from './config';
|
|
17
18
|
export * from './function-builder';
|
package/lib/index.js
CHANGED
|
@@ -35,7 +35,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
35
35
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.logger = exports.testLab = exports.storage = exports.remoteConfig = exports.pubsub = exports.https = exports.handler = exports.firestore = exports.database = exports.auth = exports.app = exports.analytics = void 0;
|
|
38
|
+
exports.logger = exports.testLab = exports.tasks = exports.storage = exports.remoteConfig = exports.pubsub = exports.https = exports.handler = exports.firestore = exports.database = exports.auth = exports.app = exports.analytics = void 0;
|
|
39
39
|
// Providers:
|
|
40
40
|
const analytics = require("./providers/analytics");
|
|
41
41
|
exports.analytics = analytics;
|
|
@@ -53,6 +53,8 @@ const remoteConfig = require("./providers/remoteConfig");
|
|
|
53
53
|
exports.remoteConfig = remoteConfig;
|
|
54
54
|
const storage = require("./providers/storage");
|
|
55
55
|
exports.storage = storage;
|
|
56
|
+
const tasks = require("./providers/tasks");
|
|
57
|
+
exports.tasks = tasks;
|
|
56
58
|
const testLab = require("./providers/testLab");
|
|
57
59
|
exports.testLab = testLab;
|
|
58
60
|
const apps = require("./apps");
|
package/lib/providers/auth.d.ts
CHANGED
|
@@ -1,27 +1,40 @@
|
|
|
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";
|
|
10
|
+
/** Resource level options */
|
|
11
|
+
export interface UserOptions {
|
|
12
|
+
blockingOptions?: {
|
|
13
|
+
idToken?: boolean;
|
|
14
|
+
accessToken?: boolean;
|
|
15
|
+
refreshToken?: boolean;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
9
18
|
/**
|
|
10
19
|
* Handle events related to Firebase authentication users.
|
|
11
20
|
*/
|
|
12
|
-
export declare function user(): UserBuilder;
|
|
21
|
+
export declare function user(userOptions?: UserOptions): UserBuilder;
|
|
13
22
|
/** @hidden */
|
|
14
|
-
export declare function _userWithOptions(options: DeploymentOptions): UserBuilder;
|
|
23
|
+
export declare function _userWithOptions(options: DeploymentOptions, userOptions: UserOptions): UserBuilder;
|
|
15
24
|
/** Builder used to create Cloud Functions for Firebase Auth user lifecycle events. */
|
|
16
25
|
export declare class UserBuilder {
|
|
17
26
|
private triggerResource;
|
|
18
|
-
private options
|
|
27
|
+
private options;
|
|
28
|
+
private userOptions?;
|
|
19
29
|
private static dataConstructor;
|
|
20
30
|
/** @hidden */
|
|
21
|
-
constructor(triggerResource: () => string, options?:
|
|
31
|
+
constructor(triggerResource: () => string, options: DeploymentOptions, userOptions?: UserOptions);
|
|
22
32
|
/** Respond to the creation of a Firebase Auth user. */
|
|
23
33
|
onCreate(handler: (user: UserRecord, context: EventContext) => PromiseLike<any> | any): CloudFunction<UserRecord>;
|
|
24
34
|
/** Respond to the deletion of a Firebase Auth user. */
|
|
25
35
|
onDelete(handler: (user: UserRecord, context: EventContext) => PromiseLike<any> | any): CloudFunction<UserRecord>;
|
|
36
|
+
beforeCreate(handler: (user: AuthUserRecord, context: AuthEventContext) => BeforeCreateResponse | void | Promise<BeforeCreateResponse> | Promise<void>): BlockingFunction;
|
|
37
|
+
beforeSignIn(handler: (user: AuthUserRecord, context: AuthEventContext) => BeforeSignInResponse | void | Promise<BeforeSignInResponse> | Promise<void>): BlockingFunction;
|
|
26
38
|
private onOperation;
|
|
39
|
+
private beforeOperation;
|
|
27
40
|
}
|
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,26 +34,27 @@ 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
60
|
return (0, identity_1.userRecordConstructor)(raw.data);
|
|
@@ -65,6 +67,12 @@ 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
77
|
return (0, cloud_functions_1.makeCloudFunction)({
|
|
70
78
|
handler,
|
|
@@ -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;
|
package/lib/providers/https.d.ts
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
1
|
import * as express from 'express';
|
|
2
2
|
import { HttpsFunction, Runnable } from '../cloud-functions';
|
|
3
|
-
import {
|
|
4
|
-
import { CallableContext, FunctionsErrorCode, HttpsError, Request, TaskContext, TaskRateLimits, TaskRetryConfig } from '../common/providers/https';
|
|
3
|
+
import { CallableContext, FunctionsErrorCode, HttpsError, Request } from '../common/providers/https';
|
|
5
4
|
import { DeploymentOptions } from '../function-configuration';
|
|
6
|
-
export { Request, CallableContext, FunctionsErrorCode, HttpsError
|
|
7
|
-
/** @hidden */
|
|
8
|
-
TaskRetryConfig as TaskRetryPolicy,
|
|
9
|
-
/** @hidden */
|
|
10
|
-
TaskRateLimits,
|
|
11
|
-
/** @hidden */
|
|
12
|
-
TaskContext, };
|
|
5
|
+
export { Request, CallableContext, FunctionsErrorCode, HttpsError };
|
|
13
6
|
/**
|
|
14
7
|
* Handle HTTP requests.
|
|
15
8
|
* @param handler A function that takes a request and response object,
|
|
@@ -21,41 +14,6 @@ export declare function onRequest(handler: (req: Request, resp: express.Response
|
|
|
21
14
|
* @param handler A method that takes a data and context and returns a value.
|
|
22
15
|
*/
|
|
23
16
|
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;
|
|
59
17
|
/** @hidden */
|
|
60
18
|
export declare function _onRequestWithOptions(handler: (req: Request, resp: express.Response) => void | Promise<void>, options: DeploymentOptions): HttpsFunction;
|
|
61
19
|
/** @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.
|
|
24
|
+
exports._onCallWithOptions = exports._onRequestWithOptions = 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,54 +44,6 @@ 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 */
|
|
95
47
|
function _onRequestWithOptions(handler, options) {
|
|
96
48
|
// lets us add __trigger without altering handler:
|
|
97
49
|
const cloudFunction = (req, res) => {
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as express from 'express';
|
|
2
|
+
import { Request } from '../common/providers/https';
|
|
3
|
+
import { RateLimits, RetryConfig, TaskContext } from '../common/providers/tasks';
|
|
4
|
+
import { ManifestEndpoint, ManifestRequiredAPI } from '../runtime/manifest';
|
|
5
|
+
export {
|
|
6
|
+
/** @hidden */
|
|
7
|
+
RetryConfig as RetryPolicy,
|
|
8
|
+
/** @hidden */
|
|
9
|
+
RateLimits,
|
|
10
|
+
/** @hidden */
|
|
11
|
+
TaskContext, };
|
|
12
|
+
/**
|
|
13
|
+
* Configurations for Task Queue Functions.
|
|
14
|
+
* @hidden
|
|
15
|
+
*/
|
|
16
|
+
export interface TaskQueueOptions {
|
|
17
|
+
retryConfig?: RetryConfig;
|
|
18
|
+
rateLimits?: RateLimits;
|
|
19
|
+
/**
|
|
20
|
+
* Who can enqueue tasks for this function.
|
|
21
|
+
* If left unspecified, only service accounts which have
|
|
22
|
+
* roles/cloudtasks.enqueuer and roles/cloudfunctions.invoker
|
|
23
|
+
* will have permissions.
|
|
24
|
+
*/
|
|
25
|
+
invoker?: 'private' | string | string[];
|
|
26
|
+
}
|
|
27
|
+
/** @hidden */
|
|
28
|
+
export interface TaskQueueFunction {
|
|
29
|
+
(req: Request, res: express.Response): Promise<void>;
|
|
30
|
+
__trigger: unknown;
|
|
31
|
+
__endpoint: ManifestEndpoint;
|
|
32
|
+
__requiredAPIs?: ManifestRequiredAPI[];
|
|
33
|
+
run(data: any, context: TaskContext): void | Promise<void>;
|
|
34
|
+
}
|
|
35
|
+
/** @hidden */
|
|
36
|
+
export declare class TaskQueueBuilder {
|
|
37
|
+
private readonly tqOpts?;
|
|
38
|
+
private readonly depOpts?;
|
|
39
|
+
onDispatch(handler: (data: any, context: TaskContext) => void | Promise<void>): TaskQueueFunction;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* 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
|
+
* @hidden
|
|
45
|
+
*/
|
|
46
|
+
export declare function taskQueue(options?: TaskQueueOptions): TaskQueueBuilder;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// The MIT License (MIT)
|
|
3
|
+
//
|
|
4
|
+
// Copyright (c) 2022 Firebase
|
|
5
|
+
//
|
|
6
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
// in the Software without restriction, including without limitation the rights
|
|
9
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
// furnished to do so, subject to the following conditions:
|
|
12
|
+
//
|
|
13
|
+
// The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
// copies or substantial portions of the Software.
|
|
15
|
+
//
|
|
16
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
// SOFTWARE.
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.taskQueue = exports.TaskQueueBuilder = void 0;
|
|
25
|
+
const cloud_functions_1 = require("../cloud-functions");
|
|
26
|
+
const encoding_1 = require("../common/encoding");
|
|
27
|
+
const tasks_1 = require("../common/providers/tasks");
|
|
28
|
+
/** @hidden */
|
|
29
|
+
class TaskQueueBuilder {
|
|
30
|
+
/** @internal */
|
|
31
|
+
constructor(tqOpts, depOpts) {
|
|
32
|
+
this.tqOpts = tqOpts;
|
|
33
|
+
this.depOpts = depOpts;
|
|
34
|
+
}
|
|
35
|
+
onDispatch(handler) {
|
|
36
|
+
// onEnqueueHandler sniffs the function length of the passed-in callback
|
|
37
|
+
// and the user could have only tried to listen to data. Wrap their handler
|
|
38
|
+
// in another handler to avoid accidentally triggering the v2 API
|
|
39
|
+
const fixedLen = (data, context) => handler(data, context);
|
|
40
|
+
const func = (0, tasks_1.onDispatchHandler)(fixedLen);
|
|
41
|
+
func.__trigger = {
|
|
42
|
+
...(0, cloud_functions_1.optionsToTrigger)(this.depOpts || {}),
|
|
43
|
+
taskQueueTrigger: {},
|
|
44
|
+
};
|
|
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
|
+
func.__endpoint = {
|
|
49
|
+
platform: 'gcfv1',
|
|
50
|
+
...(0, cloud_functions_1.optionsToEndpoint)(this.depOpts),
|
|
51
|
+
taskQueueTrigger: {},
|
|
52
|
+
};
|
|
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
|
+
func.__requiredAPIs = [
|
|
57
|
+
{
|
|
58
|
+
api: 'cloudtasks.googleapis.com',
|
|
59
|
+
reason: 'Needed for task queue functions',
|
|
60
|
+
},
|
|
61
|
+
];
|
|
62
|
+
func.run = handler;
|
|
63
|
+
return func;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.TaskQueueBuilder = TaskQueueBuilder;
|
|
67
|
+
/**
|
|
68
|
+
* 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
|
+
* @hidden
|
|
71
|
+
*/
|
|
72
|
+
function taskQueue(options) {
|
|
73
|
+
return new TaskQueueBuilder(options);
|
|
74
|
+
}
|
|
75
|
+
exports.taskQueue = taskQueue;
|
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) {
|
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* One or more event filters restrict the set of events delivered to an EventTrigger.
|
|
3
|
-
*/
|
|
4
|
-
interface EventFilter {
|
|
5
|
-
attribute: string;
|
|
6
|
-
value: string;
|
|
7
|
-
operator?: string;
|
|
8
|
-
}
|
|
9
1
|
/**
|
|
10
2
|
* An definition of a function as appears in the Manifest.
|
|
11
3
|
*/
|
|
@@ -19,6 +11,7 @@ export interface ManifestEndpoint {
|
|
|
19
11
|
concurrency?: number;
|
|
20
12
|
serviceAccountEmail?: string;
|
|
21
13
|
timeoutSeconds?: number;
|
|
14
|
+
cpu?: number | 'gcf_gen1';
|
|
22
15
|
vpc?: {
|
|
23
16
|
connector: string;
|
|
24
17
|
egressSettings?: string;
|
|
@@ -35,7 +28,9 @@ export interface ManifestEndpoint {
|
|
|
35
28
|
};
|
|
36
29
|
callableTrigger?: {};
|
|
37
30
|
eventTrigger?: {
|
|
38
|
-
eventFilters:
|
|
31
|
+
eventFilters: Record<string, string>;
|
|
32
|
+
eventFilterPathPatterns?: Record<string, string>;
|
|
33
|
+
channel?: string;
|
|
39
34
|
eventType: string;
|
|
40
35
|
retry: boolean;
|
|
41
36
|
region?: string;
|
|
@@ -52,6 +47,10 @@ export interface ManifestEndpoint {
|
|
|
52
47
|
maxDoublings?: number;
|
|
53
48
|
};
|
|
54
49
|
};
|
|
50
|
+
blockingTrigger?: {
|
|
51
|
+
eventType: string;
|
|
52
|
+
options?: Record<string, unknown>;
|
|
53
|
+
};
|
|
55
54
|
}
|
|
56
55
|
export interface ManifestRequiredAPI {
|
|
57
56
|
api: string;
|
|
@@ -65,4 +64,3 @@ export interface ManifestStack {
|
|
|
65
64
|
requiredAPIs: ManifestRequiredAPI[];
|
|
66
65
|
endpoints: Record<string, ManifestEndpoint>;
|
|
67
66
|
}
|
|
68
|
-
export {};
|
package/lib/runtime/manifest.js
CHANGED
|
@@ -1,2 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// The MIT License (MIT)
|
|
3
|
+
//
|
|
4
|
+
// Copyright (c) 2021 Firebase
|
|
5
|
+
//
|
|
6
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
// in the Software without restriction, including without limitation the rights
|
|
9
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
// furnished to do so, subject to the following conditions:
|
|
12
|
+
//
|
|
13
|
+
// The above copyright notice and this permission notice shall be included in
|
|
14
|
+
// all copies or substantial portions of the Software.
|
|
15
|
+
//
|
|
16
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
// SOFTWARE.
|
|
2
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
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,9 +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';
|
|
10
|
+
export { alerts, https, identity, pubsub, storage, logger, params, tasks, eventarc, };
|
|
8
11
|
export { setGlobalOptions, GlobalOptions } from './options';
|
|
9
12
|
export { CloudFunction, CloudEvent } from './core';
|