firebase-functions 3.18.1 → 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.
- package/lib/apps.js +1 -1
- package/lib/bin/firebase-functions.js +1 -1
- package/lib/cloud-functions.js +12 -12
- package/lib/common/providers/https.d.ts +20 -49
- package/lib/common/providers/https.js +10 -50
- package/lib/common/providers/identity.d.ts +187 -4
- package/lib/common/providers/identity.js +553 -27
- package/lib/common/providers/tasks.d.ts +58 -0
- package/lib/common/providers/tasks.js +77 -0
- package/lib/function-builder.d.ts +4 -1
- package/lib/function-builder.js +6 -1
- package/lib/handler-builder.d.ts +13 -2
- package/lib/handler-builder.js +18 -5
- package/lib/index.d.ts +2 -1
- package/lib/index.js +4 -2
- package/lib/logger/compat.js +1 -1
- package/lib/providers/analytics.js +1 -1
- package/lib/providers/auth.js +2 -2
- package/lib/providers/database.js +12 -12
- package/lib/providers/firestore.js +7 -7
- package/lib/providers/https.d.ts +2 -44
- package/lib/providers/https.js +8 -56
- package/lib/providers/pubsub.js +2 -2
- package/lib/providers/remoteConfig.js +1 -1
- package/lib/providers/storage.js +2 -2
- package/lib/providers/tasks.d.ts +46 -0
- package/lib/providers/tasks.js +75 -0
- package/lib/providers/testLab.js +1 -1
- package/lib/runtime/manifest.d.ts +5 -3
- package/lib/runtime/manifest.js +21 -0
- package/lib/setup.js +3 -3
- package/lib/v2/index.d.ts +3 -1
- package/lib/v2/index.js +5 -1
- package/lib/v2/options.d.ts +2 -2
- package/lib/v2/options.js +23 -14
- package/lib/v2/providers/alerts/alerts.js +2 -2
- package/lib/v2/providers/alerts/appDistribution.js +1 -1
- package/lib/v2/providers/alerts/billing.d.ts +2 -2
- package/lib/v2/providers/alerts/billing.js +6 -6
- package/lib/v2/providers/alerts/crashlytics.js +1 -1
- package/lib/v2/providers/eventarc.d.ts +32 -0
- package/lib/v2/providers/eventarc.js +65 -0
- package/lib/v2/providers/https.d.ts +2 -20
- package/lib/v2/providers/https.js +4 -43
- package/lib/v2/providers/pubsub.js +1 -1
- package/lib/v2/providers/storage.js +3 -5
- package/lib/v2/providers/tasks.d.ts +22 -0
- package/lib/v2/providers/tasks.js +89 -0
- package/package.json +29 -15
|
@@ -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.
|
|
24
|
+
exports.onCall = exports.onRequest = exports.HttpsError = void 0;
|
|
25
25
|
const cors = require("cors");
|
|
26
26
|
const encoding_1 = require("../../common/encoding");
|
|
27
27
|
const options = require("../options");
|
|
@@ -68,7 +68,7 @@ function onRequest(optsOrHandler, handler) {
|
|
|
68
68
|
allowInsecure: false,
|
|
69
69
|
},
|
|
70
70
|
};
|
|
71
|
-
|
|
71
|
+
encoding_1.convertIfPresent(trigger.httpsTrigger, opts, 'invoker', 'invoker', encoding_1.convertInvoker);
|
|
72
72
|
return trigger;
|
|
73
73
|
},
|
|
74
74
|
});
|
|
@@ -86,7 +86,7 @@ function onRequest(optsOrHandler, handler) {
|
|
|
86
86
|
},
|
|
87
87
|
httpsTrigger: {},
|
|
88
88
|
};
|
|
89
|
-
|
|
89
|
+
encoding_1.convertIfPresent(endpoint.httpsTrigger, opts, 'invoker', 'invoker', encoding_1.convertInvoker);
|
|
90
90
|
handler.__endpoint = endpoint;
|
|
91
91
|
return handler;
|
|
92
92
|
}
|
|
@@ -104,7 +104,7 @@ function onCall(optsOrHandler, handler) {
|
|
|
104
104
|
// onCallHandler sniffs the function length to determine which API to present.
|
|
105
105
|
// fix the length to prevent api versions from being mismatched.
|
|
106
106
|
const fixedLen = (req) => handler(req);
|
|
107
|
-
const func =
|
|
107
|
+
const func = https_1.onCallHandler({ cors: { origin, methods: 'POST' } }, fixedLen);
|
|
108
108
|
Object.defineProperty(func, '__trigger', {
|
|
109
109
|
get: () => {
|
|
110
110
|
const baseOpts = options.optionsToTriggerAnnotations(options.getGlobalOptions());
|
|
@@ -147,42 +147,3 @@ function onCall(optsOrHandler, handler) {
|
|
|
147
147
|
return func;
|
|
148
148
|
}
|
|
149
149
|
exports.onCall = onCall;
|
|
150
|
-
function onTaskDispatched(optsOrHandler, handler) {
|
|
151
|
-
let opts;
|
|
152
|
-
if (arguments.length == 1) {
|
|
153
|
-
opts = {};
|
|
154
|
-
handler = optsOrHandler;
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
opts = optsOrHandler;
|
|
158
|
-
}
|
|
159
|
-
// onEnqueueHandler sniffs the function length to determine which API to present.
|
|
160
|
-
// fix the length to prevent api versions from being mismatched.
|
|
161
|
-
const fixedLen = (req) => handler(req);
|
|
162
|
-
const func = (0, https_1.onDispatchHandler)(fixedLen);
|
|
163
|
-
Object.defineProperty(func, '__trigger', {
|
|
164
|
-
get: () => {
|
|
165
|
-
const baseOpts = options.optionsToTriggerAnnotations(options.getGlobalOptions());
|
|
166
|
-
// global options calls region a scalar and https allows it to be an array,
|
|
167
|
-
// but optionsToTriggerAnnotations handles both cases.
|
|
168
|
-
const specificOpts = options.optionsToTriggerAnnotations(opts);
|
|
169
|
-
const taskQueueTrigger = {};
|
|
170
|
-
(0, encoding_1.copyIfPresent)(taskQueueTrigger, opts, 'retryConfig', 'rateLimits');
|
|
171
|
-
(0, encoding_1.convertIfPresent)(taskQueueTrigger, opts, 'invoker', 'invoker', encoding_1.convertInvoker);
|
|
172
|
-
return {
|
|
173
|
-
apiVersion: 2,
|
|
174
|
-
platform: 'gcfv2',
|
|
175
|
-
...baseOpts,
|
|
176
|
-
...specificOpts,
|
|
177
|
-
labels: {
|
|
178
|
-
...baseOpts === null || baseOpts === void 0 ? void 0 : baseOpts.labels,
|
|
179
|
-
...specificOpts === null || specificOpts === void 0 ? void 0 : specificOpts.labels,
|
|
180
|
-
},
|
|
181
|
-
taskQueueTrigger,
|
|
182
|
-
};
|
|
183
|
-
},
|
|
184
|
-
});
|
|
185
|
-
func.run = handler;
|
|
186
|
-
return func;
|
|
187
|
-
}
|
|
188
|
-
exports.onTaskDispatched = onTaskDispatched;
|
|
@@ -108,7 +108,7 @@ function onMessagePublished(topicOrOptions, handler) {
|
|
|
108
108
|
retry: false,
|
|
109
109
|
},
|
|
110
110
|
};
|
|
111
|
-
|
|
111
|
+
encoding_1.copyIfPresent(endpoint.eventTrigger, opts, 'retry', 'retry');
|
|
112
112
|
func.__endpoint = endpoint;
|
|
113
113
|
return func;
|
|
114
114
|
}
|
|
@@ -99,13 +99,11 @@ function onOperation(eventType, bucketOrOptsOrHandler, handler) {
|
|
|
99
99
|
},
|
|
100
100
|
eventTrigger: {
|
|
101
101
|
eventType,
|
|
102
|
-
eventFilters: {
|
|
103
|
-
bucket,
|
|
104
|
-
},
|
|
102
|
+
eventFilters: { bucket },
|
|
105
103
|
retry: false,
|
|
106
104
|
},
|
|
107
105
|
};
|
|
108
|
-
|
|
106
|
+
encoding_1.copyIfPresent(endpoint.eventTrigger, opts, 'retry', 'retry');
|
|
109
107
|
return endpoint;
|
|
110
108
|
},
|
|
111
109
|
});
|
|
@@ -121,7 +119,7 @@ function getOptsAndBucket(bucketOrOpts) {
|
|
|
121
119
|
opts = {};
|
|
122
120
|
}
|
|
123
121
|
else {
|
|
124
|
-
bucket = bucketOrOpts.bucket ||
|
|
122
|
+
bucket = bucketOrOpts.bucket || config_1.firebaseConfig().storageBucket;
|
|
125
123
|
opts = { ...bucketOrOpts };
|
|
126
124
|
delete opts.bucket;
|
|
127
125
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as options from '../options';
|
|
2
|
+
import { HttpsFunction } from './https';
|
|
3
|
+
import { AuthData, RateLimits, Request, RetryConfig } from '../../common/providers/tasks';
|
|
4
|
+
export { AuthData, RateLimits, Request, RetryConfig as RetryPolicy };
|
|
5
|
+
export interface TaskQueueOptions extends options.GlobalOptions {
|
|
6
|
+
retryConfig?: RetryConfig;
|
|
7
|
+
rateLimits?: RateLimits;
|
|
8
|
+
/**
|
|
9
|
+
* Who can enqueue tasks for this function.
|
|
10
|
+
* If left unspecified, only service accounts which have
|
|
11
|
+
* roles/cloudtasks.enqueuer and roles/cloudfunctions.invoker
|
|
12
|
+
* will have permissions.
|
|
13
|
+
*/
|
|
14
|
+
invoker?: 'private' | string | string[];
|
|
15
|
+
}
|
|
16
|
+
export interface TaskQueueFunction<T = any> extends HttpsFunction {
|
|
17
|
+
run(data: Request<T>): void | Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
/** Handle a request sent to a Cloud Tasks queue. */
|
|
20
|
+
export declare function onTaskDispatched<Args = any>(handler: (request: Request<Args>) => void | Promise<void>): TaskQueueFunction<Args>;
|
|
21
|
+
/** Handle a request sent to a Cloud Tasks queue. */
|
|
22
|
+
export declare function onTaskDispatched<Args = any>(options: TaskQueueOptions, handler: (request: Request<Args>) => void | Promise<void>): TaskQueueFunction<Args>;
|
|
@@ -0,0 +1,89 @@
|
|
|
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.onTaskDispatched = void 0;
|
|
25
|
+
const options = require("../options");
|
|
26
|
+
const encoding_1 = require("../../common/encoding");
|
|
27
|
+
const tasks_1 = require("../../common/providers/tasks");
|
|
28
|
+
function onTaskDispatched(optsOrHandler, handler) {
|
|
29
|
+
let opts;
|
|
30
|
+
if (arguments.length == 1) {
|
|
31
|
+
opts = {};
|
|
32
|
+
handler = optsOrHandler;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
opts = optsOrHandler;
|
|
36
|
+
}
|
|
37
|
+
// onDispatchHandler sniffs the function length to determine which API to present.
|
|
38
|
+
// fix the length to prevent api versions from being mismatched.
|
|
39
|
+
const fixedLen = (req) => handler(req);
|
|
40
|
+
const func = tasks_1.onDispatchHandler(fixedLen);
|
|
41
|
+
Object.defineProperty(func, '__trigger', {
|
|
42
|
+
get: () => {
|
|
43
|
+
const baseOpts = options.optionsToTriggerAnnotations(options.getGlobalOptions());
|
|
44
|
+
// global options calls region a scalar and https allows it to be an array,
|
|
45
|
+
// but optionsToTriggerAnnotations handles both cases.
|
|
46
|
+
const specificOpts = options.optionsToTriggerAnnotations(opts);
|
|
47
|
+
const taskQueueTrigger = {};
|
|
48
|
+
encoding_1.copyIfPresent(taskQueueTrigger, opts, 'retryConfig', 'rateLimits');
|
|
49
|
+
encoding_1.convertIfPresent(taskQueueTrigger, opts, 'invoker', 'invoker', encoding_1.convertInvoker);
|
|
50
|
+
return {
|
|
51
|
+
apiVersion: 2,
|
|
52
|
+
platform: 'gcfv2',
|
|
53
|
+
...baseOpts,
|
|
54
|
+
...specificOpts,
|
|
55
|
+
labels: {
|
|
56
|
+
...baseOpts === null || baseOpts === void 0 ? void 0 : baseOpts.labels,
|
|
57
|
+
...specificOpts === null || specificOpts === void 0 ? void 0 : specificOpts.labels,
|
|
58
|
+
},
|
|
59
|
+
taskQueueTrigger,
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
const baseOpts = options.optionsToEndpoint(options.getGlobalOptions());
|
|
64
|
+
// global options calls region a scalar and https allows it to be an array,
|
|
65
|
+
// but optionsToManifestEndpoint handles both cases.
|
|
66
|
+
const specificOpts = options.optionsToEndpoint(opts);
|
|
67
|
+
func.__endpoint = {
|
|
68
|
+
platform: 'gcfv2',
|
|
69
|
+
...baseOpts,
|
|
70
|
+
...specificOpts,
|
|
71
|
+
labels: {
|
|
72
|
+
...baseOpts === null || baseOpts === void 0 ? void 0 : baseOpts.labels,
|
|
73
|
+
...specificOpts === null || specificOpts === void 0 ? void 0 : specificOpts.labels,
|
|
74
|
+
},
|
|
75
|
+
taskQueueTrigger: {},
|
|
76
|
+
};
|
|
77
|
+
encoding_1.copyIfPresent(func.__endpoint.taskQueueTrigger, opts, 'retryConfig');
|
|
78
|
+
encoding_1.copyIfPresent(func.__endpoint.taskQueueTrigger, opts, 'rateLimits');
|
|
79
|
+
encoding_1.convertIfPresent(func.__endpoint.taskQueueTrigger, opts, 'invoker', 'invoker', encoding_1.convertInvoker);
|
|
80
|
+
func.__requiredAPIs = [
|
|
81
|
+
{
|
|
82
|
+
api: 'cloudtasks.googleapis.com',
|
|
83
|
+
reason: 'Needed for task queue functions',
|
|
84
|
+
},
|
|
85
|
+
];
|
|
86
|
+
func.run = handler;
|
|
87
|
+
return func;
|
|
88
|
+
}
|
|
89
|
+
exports.onTaskDispatched = onTaskDispatched;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "firebase-functions",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.20.1",
|
|
4
4
|
"description": "Firebase SDK for Cloud Functions",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"firebase",
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"./lib/providers/pubsub": "./lib/providers/pubsub.js",
|
|
41
41
|
"./lib/providers/remoteConfig": "./lib/providers/remoteConfig.js",
|
|
42
42
|
"./lib/providers/storage": "./lib/providers/storage.js",
|
|
43
|
+
"./lib/providers/tasks": "./lib/providers/tasks.js",
|
|
43
44
|
"./lib/providers/testLab": "./lib/providers/testLab.js",
|
|
44
45
|
"./v1": "./lib/index.js",
|
|
45
46
|
"./v1/analytics": "./lib/providers/analytics.js",
|
|
@@ -58,10 +59,12 @@
|
|
|
58
59
|
"./v2/params": "./lib/v2/params/index.js",
|
|
59
60
|
"./v2/pubsub": "./lib/v2/providers/pubsub.js",
|
|
60
61
|
"./v2/storage": "./lib/v2/providers/storage.js",
|
|
62
|
+
"./v2/tasks": "./lib/v2/providers/tasks.js",
|
|
61
63
|
"./v2/alerts": "./lib/v2/providers/alerts/index.js",
|
|
62
64
|
"./v2/alerts/appDistribution": "./lib/v2/providers/alerts/appDistribution.js",
|
|
63
65
|
"./v2/alerts/billing": "./lib/v2/providers/alerts/billing.js",
|
|
64
|
-
"./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"
|
|
65
68
|
},
|
|
66
69
|
"typesVersions": {
|
|
67
70
|
"*": {
|
|
@@ -98,15 +101,33 @@
|
|
|
98
101
|
"v1/storage": [
|
|
99
102
|
"lib/providers/storage"
|
|
100
103
|
],
|
|
104
|
+
"v1/tasks": [
|
|
105
|
+
"lib/providers/tasks"
|
|
106
|
+
],
|
|
101
107
|
"v1/testLab": [
|
|
102
108
|
"lib/providers/testLab"
|
|
103
109
|
],
|
|
104
110
|
"v2": [
|
|
105
111
|
"lib/v2"
|
|
106
112
|
],
|
|
113
|
+
"v2/alerts": [
|
|
114
|
+
"lib/v2/providers/alerts"
|
|
115
|
+
],
|
|
116
|
+
"v2/alerts/appDistribution": [
|
|
117
|
+
"lib/v2/providers/alerts/appDistribution"
|
|
118
|
+
],
|
|
119
|
+
"v2/alerts/billing": [
|
|
120
|
+
"lib/v2/providers/alerts/billing"
|
|
121
|
+
],
|
|
122
|
+
"v2/alerts/crashlytics": [
|
|
123
|
+
"lib/v2/providers/alerts/crashlytics"
|
|
124
|
+
],
|
|
107
125
|
"v2/base": [
|
|
108
126
|
"lib/v2/base"
|
|
109
127
|
],
|
|
128
|
+
"v2/eventarc": [
|
|
129
|
+
"lib/v2/providers/eventarc"
|
|
130
|
+
],
|
|
110
131
|
"v2/options": [
|
|
111
132
|
"lib/v2/options"
|
|
112
133
|
],
|
|
@@ -122,17 +143,8 @@
|
|
|
122
143
|
"v2/storage": [
|
|
123
144
|
"lib/v2/providers/storage"
|
|
124
145
|
],
|
|
125
|
-
"v2/
|
|
126
|
-
"lib/v2/providers/
|
|
127
|
-
],
|
|
128
|
-
"v2/alerts/appDistribution": [
|
|
129
|
-
"lib/v2/providers/alerts/appDistribution"
|
|
130
|
-
],
|
|
131
|
-
"v2/alerts/billing": [
|
|
132
|
-
"lib/v2/providers/alerts/billing"
|
|
133
|
-
],
|
|
134
|
-
"v2/alerts/crashlytics": [
|
|
135
|
-
"lib/v2/providers/alerts/crashlytics"
|
|
146
|
+
"v2/tasks": [
|
|
147
|
+
"lib/v2/providers/tasks"
|
|
136
148
|
]
|
|
137
149
|
}
|
|
138
150
|
},
|
|
@@ -149,7 +161,7 @@
|
|
|
149
161
|
"format:fix": "prettier --write '**/*.{json,md,ts,yml,yaml}'",
|
|
150
162
|
"lint": "tslint --config tslint.json --project tsconfig.json ",
|
|
151
163
|
"lint:fix": "tslint --config tslint.json --fix --project tsconfig.json",
|
|
152
|
-
"test": "mocha --file ./mocha/setup.ts spec/**/*.spec.ts
|
|
164
|
+
"test": "mocha --file ./mocha/setup.ts \"spec/**/*.spec.ts\"",
|
|
153
165
|
"test:bin": "./scripts/bin-test/run.sh"
|
|
154
166
|
},
|
|
155
167
|
"dependencies": {
|
|
@@ -157,7 +169,8 @@
|
|
|
157
169
|
"@types/express": "4.17.3",
|
|
158
170
|
"cors": "^2.8.5",
|
|
159
171
|
"express": "^4.17.1",
|
|
160
|
-
"lodash": "^4.17.14"
|
|
172
|
+
"lodash": "^4.17.14",
|
|
173
|
+
"node-fetch": "^2.6.7"
|
|
161
174
|
},
|
|
162
175
|
"devDependencies": {
|
|
163
176
|
"@types/chai": "^4.1.7",
|
|
@@ -168,6 +181,7 @@
|
|
|
168
181
|
"@types/mock-require": "^2.0.0",
|
|
169
182
|
"@types/nock": "^10.0.3",
|
|
170
183
|
"@types/node": "^8.10.50",
|
|
184
|
+
"@types/node-fetch": "^3.0.3",
|
|
171
185
|
"@types/sinon": "^7.0.13",
|
|
172
186
|
"chai": "^4.2.0",
|
|
173
187
|
"chai-as-promised": "^7.1.1",
|