firebase-functions 3.20.0 → 3.20.1
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.
|
@@ -27,17 +27,26 @@ const https = require("./https");
|
|
|
27
27
|
/** @internal */
|
|
28
28
|
function onDispatchHandler(handler) {
|
|
29
29
|
return async (req, res) => {
|
|
30
|
+
var _a;
|
|
30
31
|
try {
|
|
31
32
|
if (!https.isValidRequest(req)) {
|
|
32
33
|
logger.error('Invalid request, unable to process.');
|
|
33
34
|
throw new https.HttpsError('invalid-argument', 'Bad Request');
|
|
34
35
|
}
|
|
35
|
-
const
|
|
36
|
-
const
|
|
36
|
+
const authHeader = req.header('Authorization') || '';
|
|
37
|
+
const token = (_a = authHeader.match(/^Bearer (.*)$/)) === null || _a === void 0 ? void 0 : _a[1];
|
|
37
38
|
// Note: this should never happen since task queue functions are guarded by IAM.
|
|
38
|
-
if (
|
|
39
|
+
if (!token) {
|
|
39
40
|
throw new https.HttpsError('unauthenticated', 'Unauthenticated');
|
|
40
41
|
}
|
|
42
|
+
// We skip authenticating the token since tq functions are guarded by IAM.
|
|
43
|
+
const authToken = await https.unsafeDecodeIdToken(token);
|
|
44
|
+
const context = {
|
|
45
|
+
auth: {
|
|
46
|
+
uid: authToken.uid,
|
|
47
|
+
token: authToken,
|
|
48
|
+
},
|
|
49
|
+
};
|
|
41
50
|
const data = https.decode(req.body.data);
|
|
42
51
|
if (handler.length === 2) {
|
|
43
52
|
await handler(data, context);
|
package/lib/v2/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import * as https from './providers/https';
|
|
|
5
5
|
import * as pubsub from './providers/pubsub';
|
|
6
6
|
import * as storage from './providers/storage';
|
|
7
7
|
import * as tasks from './providers/tasks';
|
|
8
|
-
|
|
8
|
+
import * as eventarc from './providers/eventarc';
|
|
9
|
+
export { alerts, https, pubsub, storage, logger, params, tasks, eventarc };
|
|
9
10
|
export { setGlobalOptions, GlobalOptions } from './options';
|
|
10
11
|
export { CloudFunction, CloudEvent } from './core';
|
package/lib/v2/index.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.setGlobalOptions = exports.tasks = exports.params = exports.logger = exports.storage = exports.pubsub = exports.https = exports.alerts = void 0;
|
|
24
|
+
exports.setGlobalOptions = exports.eventarc = exports.tasks = exports.params = exports.logger = exports.storage = exports.pubsub = exports.https = exports.alerts = void 0;
|
|
25
25
|
const logger = require("../logger");
|
|
26
26
|
exports.logger = logger;
|
|
27
27
|
const params = require("./params");
|
|
@@ -36,5 +36,7 @@ const storage = require("./providers/storage");
|
|
|
36
36
|
exports.storage = storage;
|
|
37
37
|
const tasks = require("./providers/tasks");
|
|
38
38
|
exports.tasks = tasks;
|
|
39
|
+
const eventarc = require("./providers/eventarc");
|
|
40
|
+
exports.eventarc = eventarc;
|
|
39
41
|
var options_1 = require("./options");
|
|
40
42
|
Object.defineProperty(exports, "setGlobalOptions", { enumerable: true, get: function () { return options_1.setGlobalOptions; } });
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as options from '../options';
|
|
2
|
+
import { CloudEvent, CloudFunction } from '../core';
|
|
3
|
+
/** Options that can be set on an Eventarc trigger. */
|
|
4
|
+
export interface EventarcTriggerOptions extends options.EventHandlerOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Type of the event.
|
|
7
|
+
*/
|
|
8
|
+
eventType: string;
|
|
9
|
+
/**
|
|
10
|
+
* ID of the channel. Can be either:
|
|
11
|
+
* * fully qualified channel resource name:
|
|
12
|
+
* `projects/{project}/locations/{location}/channels/{channel-id}`
|
|
13
|
+
* * partial resource name with location and channel ID, in which case
|
|
14
|
+
* the runtime project ID of the function will be used:
|
|
15
|
+
* `locations/{location}/channels/{channel-id}`
|
|
16
|
+
* * partial channel ID, in which case the runtime project ID of the
|
|
17
|
+
* function and `us-central1` as location will be used:
|
|
18
|
+
* `{channel-id}`
|
|
19
|
+
*
|
|
20
|
+
* If not specified, the default Firebase channel will be used:
|
|
21
|
+
* `projects/{project}/locations/us-central1/channels/firebase`
|
|
22
|
+
*/
|
|
23
|
+
channel?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Eventarc event exact match filter.
|
|
26
|
+
*/
|
|
27
|
+
filters?: Record<string, string>;
|
|
28
|
+
}
|
|
29
|
+
export declare type CloudEventHandler = (event: CloudEvent<any>) => any | Promise<any>;
|
|
30
|
+
/** Handle an Eventarc event published on the default channel. */
|
|
31
|
+
export declare function onCustomEventPublished<T = any>(eventType: string, handler: CloudEventHandler): CloudFunction<CloudEvent<T>>;
|
|
32
|
+
export declare function onCustomEventPublished<T = any>(opts: EventarcTriggerOptions, handler: CloudEventHandler): CloudFunction<CloudEvent<T>>;
|
|
@@ -0,0 +1,65 @@
|
|
|
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.onCustomEventPublished = void 0;
|
|
25
|
+
const options = require("../options");
|
|
26
|
+
const encoding_1 = require("../../common/encoding");
|
|
27
|
+
function onCustomEventPublished(eventTypeOrOpts, handler) {
|
|
28
|
+
var _a;
|
|
29
|
+
let opts;
|
|
30
|
+
if (typeof eventTypeOrOpts === 'string') {
|
|
31
|
+
opts = {
|
|
32
|
+
eventType: eventTypeOrOpts,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
else if (typeof eventTypeOrOpts === 'object') {
|
|
36
|
+
opts = eventTypeOrOpts;
|
|
37
|
+
}
|
|
38
|
+
const func = (raw) => {
|
|
39
|
+
return handler(raw);
|
|
40
|
+
};
|
|
41
|
+
func.run = handler;
|
|
42
|
+
const channel = (_a = opts.channel) !== null && _a !== void 0 ? _a : 'locations/us-central1/channels/firebase';
|
|
43
|
+
const baseOpts = options.optionsToEndpoint(options.getGlobalOptions());
|
|
44
|
+
const specificOpts = options.optionsToEndpoint(opts);
|
|
45
|
+
const endpoint = {
|
|
46
|
+
platform: 'gcfv2',
|
|
47
|
+
...baseOpts,
|
|
48
|
+
...specificOpts,
|
|
49
|
+
labels: {
|
|
50
|
+
...baseOpts === null || baseOpts === void 0 ? void 0 : baseOpts.labels,
|
|
51
|
+
...specificOpts === null || specificOpts === void 0 ? void 0 : specificOpts.labels,
|
|
52
|
+
},
|
|
53
|
+
eventTrigger: {
|
|
54
|
+
eventType: opts.eventType,
|
|
55
|
+
eventFilters: {},
|
|
56
|
+
retry: false,
|
|
57
|
+
channel,
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
encoding_1.convertIfPresent(endpoint.eventTrigger, opts, 'eventFilters', 'filters');
|
|
61
|
+
encoding_1.copyIfPresent(endpoint.eventTrigger, opts, 'retry');
|
|
62
|
+
func.__endpoint = endpoint;
|
|
63
|
+
return func;
|
|
64
|
+
}
|
|
65
|
+
exports.onCustomEventPublished = onCustomEventPublished;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "firebase-functions",
|
|
3
|
-
"version": "3.20.
|
|
3
|
+
"version": "3.20.1",
|
|
4
4
|
"description": "Firebase SDK for Cloud Functions",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"firebase",
|
|
@@ -63,7 +63,8 @@
|
|
|
63
63
|
"./v2/alerts": "./lib/v2/providers/alerts/index.js",
|
|
64
64
|
"./v2/alerts/appDistribution": "./lib/v2/providers/alerts/appDistribution.js",
|
|
65
65
|
"./v2/alerts/billing": "./lib/v2/providers/alerts/billing.js",
|
|
66
|
-
"./v2/alerts/crashlytics": "./lib/v2/providers/alerts/crashlytics.js"
|
|
66
|
+
"./v2/alerts/crashlytics": "./lib/v2/providers/alerts/crashlytics.js",
|
|
67
|
+
"./v2/eventarc": "./lib/v2/providers/eventarc.js"
|
|
67
68
|
},
|
|
68
69
|
"typesVersions": {
|
|
69
70
|
"*": {
|
|
@@ -124,6 +125,9 @@
|
|
|
124
125
|
"v2/base": [
|
|
125
126
|
"lib/v2/base"
|
|
126
127
|
],
|
|
128
|
+
"v2/eventarc": [
|
|
129
|
+
"lib/v2/providers/eventarc"
|
|
130
|
+
],
|
|
127
131
|
"v2/options": [
|
|
128
132
|
"lib/v2/options"
|
|
129
133
|
],
|