firebase-functions 3.18.0 → 3.20.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/apps.js +1 -1
- package/lib/bin/firebase-functions.js +16 -14
- 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 +68 -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/loader.js +1 -2
- 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 +2 -1
- package/lib/v2/index.js +3 -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/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 +24 -14
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as express from 'express';
|
|
2
|
+
import { Request } from '../common/providers/https';
|
|
3
|
+
import { ManifestEndpoint, ManifestRequiredAPI } from '../runtime/manifest';
|
|
4
|
+
import { TaskContext, RateLimits, RetryConfig } from '../common/providers/tasks';
|
|
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 = tasks_1.onDispatchHandler(fixedLen);
|
|
41
|
+
func.__trigger = {
|
|
42
|
+
...cloud_functions_1.optionsToTrigger(this.depOpts || {}),
|
|
43
|
+
taskQueueTrigger: {},
|
|
44
|
+
};
|
|
45
|
+
encoding_1.copyIfPresent(func.__trigger.taskQueueTrigger, this.tqOpts, 'retryConfig');
|
|
46
|
+
encoding_1.copyIfPresent(func.__trigger.taskQueueTrigger, this.tqOpts, 'rateLimits');
|
|
47
|
+
encoding_1.convertIfPresent(func.__trigger.taskQueueTrigger, this.tqOpts, 'invoker', 'invoker', encoding_1.convertInvoker);
|
|
48
|
+
func.__endpoint = {
|
|
49
|
+
platform: 'gcfv1',
|
|
50
|
+
...cloud_functions_1.optionsToEndpoint(this.depOpts),
|
|
51
|
+
taskQueueTrigger: {},
|
|
52
|
+
};
|
|
53
|
+
encoding_1.copyIfPresent(func.__endpoint.taskQueueTrigger, this.tqOpts, 'retryConfig');
|
|
54
|
+
encoding_1.copyIfPresent(func.__endpoint.taskQueueTrigger, this.tqOpts, 'rateLimits');
|
|
55
|
+
encoding_1.convertIfPresent(func.__endpoint.taskQueueTrigger, this.tqOpts, 'invoker', 'invoker', encoding_1.convertInvoker);
|
|
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/providers/testLab.js
CHANGED
|
@@ -57,7 +57,7 @@ class TestMatrixBuilder {
|
|
|
57
57
|
const dataConstructor = (raw) => {
|
|
58
58
|
return new TestMatrix(raw.data);
|
|
59
59
|
};
|
|
60
|
-
return
|
|
60
|
+
return cloud_functions_1.makeCloudFunction({
|
|
61
61
|
provider: exports.PROVIDER,
|
|
62
62
|
eventType: exports.TEST_MATRIX_COMPLETE_EVENT_TYPE,
|
|
63
63
|
triggerResource: this.triggerResource,
|
package/lib/runtime/loader.js
CHANGED
|
@@ -91,11 +91,10 @@ async function loadStack(functionsDir) {
|
|
|
91
91
|
const requiredAPIs = [];
|
|
92
92
|
const mod = await loadModule(functionsDir);
|
|
93
93
|
extractStack(mod, endpoints, requiredAPIs);
|
|
94
|
-
|
|
94
|
+
return {
|
|
95
95
|
endpoints,
|
|
96
96
|
specVersion: 'v1alpha1',
|
|
97
97
|
requiredAPIs: mergeRequiredAPIs(requiredAPIs),
|
|
98
98
|
};
|
|
99
|
-
return stack;
|
|
100
99
|
}
|
|
101
100
|
exports.loadStack = loadStack;
|
|
@@ -18,16 +18,18 @@ export interface ManifestEndpoint {
|
|
|
18
18
|
labels?: Record<string, string>;
|
|
19
19
|
ingressSettings?: string;
|
|
20
20
|
environmentVariables?: Record<string, string>;
|
|
21
|
-
secretEnvironmentVariables?: {
|
|
21
|
+
secretEnvironmentVariables?: Array<{
|
|
22
22
|
key: string;
|
|
23
23
|
secret?: string;
|
|
24
|
-
}
|
|
24
|
+
}>;
|
|
25
25
|
httpsTrigger?: {
|
|
26
26
|
invoker?: string[];
|
|
27
27
|
};
|
|
28
28
|
callableTrigger?: {};
|
|
29
29
|
eventTrigger?: {
|
|
30
30
|
eventFilters: Record<string, string>;
|
|
31
|
+
eventFilterPathPatterns?: Record<string, string>;
|
|
32
|
+
channel?: string;
|
|
31
33
|
eventType: string;
|
|
32
34
|
retry: boolean;
|
|
33
35
|
region?: string;
|
|
@@ -51,7 +53,7 @@ export interface ManifestRequiredAPI {
|
|
|
51
53
|
}
|
|
52
54
|
/**
|
|
53
55
|
* An definition of a function deployment as appears in the Manifest.
|
|
54
|
-
|
|
56
|
+
*/
|
|
55
57
|
export interface ManifestStack {
|
|
56
58
|
specVersion: 'v1alpha1';
|
|
57
59
|
requiredAPIs: ManifestRequiredAPI[];
|
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/setup.js
CHANGED
|
@@ -31,7 +31,7 @@ function setup() {
|
|
|
31
31
|
// Until the Cloud Functions builder can publish FIREBASE_CONFIG, automatically provide it on import based on what
|
|
32
32
|
// we can deduce.
|
|
33
33
|
if (!process.env.FIREBASE_CONFIG) {
|
|
34
|
-
const cfg =
|
|
34
|
+
const cfg = config_1.firebaseConfig();
|
|
35
35
|
if (cfg) {
|
|
36
36
|
process.env.FIREBASE_CONFIG = JSON.stringify(cfg);
|
|
37
37
|
}
|
|
@@ -43,7 +43,7 @@ function setup() {
|
|
|
43
43
|
// If FIREBASE_CONFIG is still not found, try using GCLOUD_PROJECT to estimate
|
|
44
44
|
if (!process.env.FIREBASE_CONFIG) {
|
|
45
45
|
if (process.env.GCLOUD_PROJECT) {
|
|
46
|
-
|
|
46
|
+
logger_1.warn('Warning, estimating Firebase Config based on GCLOUD_PROJECT. Initializing firebase-admin may fail');
|
|
47
47
|
process.env.FIREBASE_CONFIG = JSON.stringify({
|
|
48
48
|
databaseURL: process.env.DATABASE_URL ||
|
|
49
49
|
`https://${process.env.GCLOUD_PROJECT}.firebaseio.com`,
|
|
@@ -53,7 +53,7 @@ function setup() {
|
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
55
|
else {
|
|
56
|
-
|
|
56
|
+
logger_1.warn('Warning, FIREBASE_CONFIG and GCLOUD_PROJECT environment variables are missing. Initializing firebase-admin will fail');
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
}
|
package/lib/v2/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import * as alerts from './providers/alerts';
|
|
|
4
4
|
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
|
+
export { alerts, https, pubsub, storage, logger, params, tasks };
|
|
8
9
|
export { setGlobalOptions, GlobalOptions } from './options';
|
|
9
10
|
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.
|
|
24
|
+
exports.setGlobalOptions = 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");
|
|
@@ -34,5 +34,7 @@ const pubsub = require("./providers/pubsub");
|
|
|
34
34
|
exports.pubsub = pubsub;
|
|
35
35
|
const storage = require("./providers/storage");
|
|
36
36
|
exports.storage = storage;
|
|
37
|
+
const tasks = require("./providers/tasks");
|
|
38
|
+
exports.tasks = tasks;
|
|
37
39
|
var options_1 = require("./options");
|
|
38
40
|
Object.defineProperty(exports, "setGlobalOptions", { enumerable: true, get: function () { return options_1.setGlobalOptions; } });
|
package/lib/v2/options.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { ParamSpec } from './params/types';
|
|
|
2
2
|
/**
|
|
3
3
|
* List of all regions supported by Cloud Functions v2
|
|
4
4
|
*/
|
|
5
|
-
export declare const SUPPORTED_REGIONS: readonly ["
|
|
5
|
+
export declare const SUPPORTED_REGIONS: readonly ["asia-northeast1", "europe-north1", "europe-west1", "europe-west4", "us-central1", "us-east1", "us-west1"];
|
|
6
6
|
/**
|
|
7
7
|
* A region known to be supported by CloudFunctions v2
|
|
8
8
|
*/
|
|
@@ -26,7 +26,7 @@ export declare const MAX_CONCURRENCY = 1000;
|
|
|
26
26
|
/**
|
|
27
27
|
* List of available memory options supported by Cloud Functions.
|
|
28
28
|
*/
|
|
29
|
-
export declare const SUPPORTED_MEMORY_OPTIONS: readonly ["256MB", "512MB", "1GB", "2GB", "4GB", "8GB"];
|
|
29
|
+
export declare const SUPPORTED_MEMORY_OPTIONS: readonly ["128MB", "256MB", "512MB", "1GB", "2GB", "4GB", "8GB", "16GB", "32GB"];
|
|
30
30
|
/**
|
|
31
31
|
* A supported memory option.
|
|
32
32
|
*/
|
package/lib/v2/options.js
CHANGED
|
@@ -29,10 +29,13 @@ const params_1 = require("./params");
|
|
|
29
29
|
* List of all regions supported by Cloud Functions v2
|
|
30
30
|
*/
|
|
31
31
|
exports.SUPPORTED_REGIONS = [
|
|
32
|
-
'us-west1',
|
|
33
|
-
'us-central1',
|
|
34
|
-
'europe-west4',
|
|
35
32
|
'asia-northeast1',
|
|
33
|
+
'europe-north1',
|
|
34
|
+
'europe-west1',
|
|
35
|
+
'europe-west4',
|
|
36
|
+
'us-central1',
|
|
37
|
+
'us-east1',
|
|
38
|
+
'us-west1',
|
|
36
39
|
];
|
|
37
40
|
/**
|
|
38
41
|
* Cloud Functions v2 min timeout value.
|
|
@@ -54,20 +57,26 @@ exports.MAX_CONCURRENCY = 1000;
|
|
|
54
57
|
* List of available memory options supported by Cloud Functions.
|
|
55
58
|
*/
|
|
56
59
|
exports.SUPPORTED_MEMORY_OPTIONS = [
|
|
60
|
+
'128MB',
|
|
57
61
|
'256MB',
|
|
58
62
|
'512MB',
|
|
59
63
|
'1GB',
|
|
60
64
|
'2GB',
|
|
61
65
|
'4GB',
|
|
62
66
|
'8GB',
|
|
67
|
+
'16GB',
|
|
68
|
+
'32GB',
|
|
63
69
|
];
|
|
64
70
|
const MemoryOptionToMB = {
|
|
71
|
+
'128MB': 128,
|
|
65
72
|
'256MB': 256,
|
|
66
73
|
'512MB': 512,
|
|
67
74
|
'1GB': 1024,
|
|
68
75
|
'2GB': 2048,
|
|
69
76
|
'4GB': 4096,
|
|
70
77
|
'8GB': 8192,
|
|
78
|
+
'16GB': 16384,
|
|
79
|
+
'32GB': 32768,
|
|
71
80
|
};
|
|
72
81
|
/**
|
|
73
82
|
* List of available options for VpcConnectorEgressSettings.
|
|
@@ -111,19 +120,19 @@ exports.getGlobalOptions = getGlobalOptions;
|
|
|
111
120
|
*/
|
|
112
121
|
function optionsToTriggerAnnotations(opts) {
|
|
113
122
|
const annotation = {};
|
|
114
|
-
|
|
115
|
-
|
|
123
|
+
encoding_1.copyIfPresent(annotation, opts, 'concurrency', 'minInstances', 'maxInstances', 'ingressSettings', 'labels', 'vpcConnector', 'vpcConnectorEgressSettings');
|
|
124
|
+
encoding_1.convertIfPresent(annotation, opts, 'availableMemoryMb', 'memory', (mem) => {
|
|
116
125
|
return MemoryOptionToMB[mem];
|
|
117
126
|
});
|
|
118
|
-
|
|
127
|
+
encoding_1.convertIfPresent(annotation, opts, 'regions', 'region', (region) => {
|
|
119
128
|
if (typeof region === 'string') {
|
|
120
129
|
return [region];
|
|
121
130
|
}
|
|
122
131
|
return region;
|
|
123
132
|
});
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
133
|
+
encoding_1.convertIfPresent(annotation, opts, 'serviceAccountEmail', 'serviceAccount', encoding_1.serviceAccountFromShorthand);
|
|
134
|
+
encoding_1.convertIfPresent(annotation, opts, 'timeout', 'timeoutSeconds', encoding_1.durationFromSeconds);
|
|
135
|
+
encoding_1.convertIfPresent(annotation, opts, 'failurePolicy', 'retry', (retry) => {
|
|
127
136
|
return retry ? { retry: true } : null;
|
|
128
137
|
});
|
|
129
138
|
return annotation;
|
|
@@ -135,14 +144,14 @@ exports.optionsToTriggerAnnotations = optionsToTriggerAnnotations;
|
|
|
135
144
|
*/
|
|
136
145
|
function optionsToEndpoint(opts) {
|
|
137
146
|
const endpoint = {};
|
|
138
|
-
|
|
139
|
-
|
|
147
|
+
encoding_1.copyIfPresent(endpoint, opts, 'concurrency', 'minInstances', 'maxInstances', 'ingressSettings', 'labels', 'timeoutSeconds');
|
|
148
|
+
encoding_1.convertIfPresent(endpoint, opts, 'serviceAccountEmail', 'serviceAccount');
|
|
140
149
|
if (opts.vpcConnector) {
|
|
141
150
|
const vpc = { connector: opts.vpcConnector };
|
|
142
|
-
|
|
151
|
+
encoding_1.convertIfPresent(vpc, opts, 'egressSettings', 'vpcConnectorEgressSettings');
|
|
143
152
|
endpoint.vpc = vpc;
|
|
144
153
|
}
|
|
145
|
-
|
|
154
|
+
encoding_1.convertIfPresent(endpoint, opts, 'availableMemoryMb', 'memory', (mem) => {
|
|
146
155
|
const memoryLookup = {
|
|
147
156
|
'128MB': 128,
|
|
148
157
|
'256MB': 256,
|
|
@@ -154,7 +163,7 @@ function optionsToEndpoint(opts) {
|
|
|
154
163
|
};
|
|
155
164
|
return memoryLookup[mem];
|
|
156
165
|
});
|
|
157
|
-
|
|
166
|
+
encoding_1.convertIfPresent(endpoint, opts, 'region', 'region', (region) => {
|
|
158
167
|
if (typeof region === 'string') {
|
|
159
168
|
return [region];
|
|
160
169
|
}
|
|
@@ -37,13 +37,13 @@ function getEndpointAnnotation(opts, alertType, appId) {
|
|
|
37
37
|
eventTrigger: {
|
|
38
38
|
eventType: exports.eventType,
|
|
39
39
|
eventFilters: {
|
|
40
|
-
alertType,
|
|
40
|
+
alerttype: alertType,
|
|
41
41
|
},
|
|
42
42
|
retry: !!opts.retry,
|
|
43
43
|
},
|
|
44
44
|
};
|
|
45
45
|
if (appId) {
|
|
46
|
-
endpoint.eventTrigger.eventFilters.
|
|
46
|
+
endpoint.eventTrigger.eventFilters.appid = appId;
|
|
47
47
|
}
|
|
48
48
|
return endpoint;
|
|
49
49
|
}
|
|
@@ -14,7 +14,7 @@ function onNewTesterIosDevicePublished(appIdOrOptsOrHandler, handler) {
|
|
|
14
14
|
return handler(raw);
|
|
15
15
|
};
|
|
16
16
|
func.run = handler;
|
|
17
|
-
func.__endpoint =
|
|
17
|
+
func.__endpoint = alerts_1.getEndpointAnnotation(opts, exports.newTesterIosDeviceAlert, appId);
|
|
18
18
|
return func;
|
|
19
19
|
}
|
|
20
20
|
exports.onNewTesterIosDevicePublished = onNewTesterIosDevicePublished;
|
|
@@ -33,6 +33,6 @@ export declare function onPlanUpdatePublished(opts: options.EventHandlerOptions,
|
|
|
33
33
|
/**
|
|
34
34
|
* Declares a function that can handle an automated billing plan update event.
|
|
35
35
|
*/
|
|
36
|
-
export declare function
|
|
37
|
-
export declare function
|
|
36
|
+
export declare function onPlanAutomatedUpdatePublished(handler: (event: BillingEvent<PlanAutomatedUpdatePayload>) => any | Promise<any>): CloudFunction<FirebaseAlertData<PlanAutomatedUpdatePayload>>;
|
|
37
|
+
export declare function onPlanAutomatedUpdatePublished(opts: options.EventHandlerOptions, handler: (event: BillingEvent<PlanAutomatedUpdatePayload>) => any | Promise<any>): CloudFunction<FirebaseAlertData<PlanAutomatedUpdatePayload>>;
|
|
38
38
|
export {};
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.onOperation = exports.
|
|
3
|
+
exports.onOperation = exports.onPlanAutomatedUpdatePublished = exports.onPlanUpdatePublished = exports.planAutomatedUpdateAlert = exports.planUpdateAlert = void 0;
|
|
4
4
|
const _1 = require(".");
|
|
5
5
|
/** @internal */
|
|
6
6
|
exports.planUpdateAlert = 'billing.planUpdate';
|
|
7
7
|
/** @internal */
|
|
8
|
-
exports.
|
|
8
|
+
exports.planAutomatedUpdateAlert = 'billing.planAutomatedUpdate';
|
|
9
9
|
function onPlanUpdatePublished(optsOrHandler, handler) {
|
|
10
10
|
return onOperation(exports.planUpdateAlert, optsOrHandler, handler);
|
|
11
11
|
}
|
|
12
12
|
exports.onPlanUpdatePublished = onPlanUpdatePublished;
|
|
13
|
-
function
|
|
14
|
-
return onOperation(exports.
|
|
13
|
+
function onPlanAutomatedUpdatePublished(optsOrHandler, handler) {
|
|
14
|
+
return onOperation(exports.planAutomatedUpdateAlert, optsOrHandler, handler);
|
|
15
15
|
}
|
|
16
|
-
exports.
|
|
16
|
+
exports.onPlanAutomatedUpdatePublished = onPlanAutomatedUpdatePublished;
|
|
17
17
|
/** @internal */
|
|
18
18
|
function onOperation(alertType, optsOrHandler, handler) {
|
|
19
19
|
if (typeof optsOrHandler === 'function') {
|
|
@@ -24,7 +24,7 @@ function onOperation(alertType, optsOrHandler, handler) {
|
|
|
24
24
|
return handler(raw);
|
|
25
25
|
};
|
|
26
26
|
func.run = handler;
|
|
27
|
-
func.__endpoint =
|
|
27
|
+
func.__endpoint = _1.getEndpointAnnotation(optsOrHandler, alertType);
|
|
28
28
|
return func;
|
|
29
29
|
}
|
|
30
30
|
exports.onOperation = onOperation;
|
|
@@ -49,7 +49,7 @@ function onOperation(alertType, appIdOrOptsOrHandler, handler) {
|
|
|
49
49
|
return handler(raw);
|
|
50
50
|
};
|
|
51
51
|
func.run = handler;
|
|
52
|
-
func.__endpoint =
|
|
52
|
+
func.__endpoint = _1.getEndpointAnnotation(opts, alertType, appId);
|
|
53
53
|
return func;
|
|
54
54
|
}
|
|
55
55
|
exports.onOperation = onOperation;
|
|
@@ -1,23 +1,12 @@
|
|
|
1
1
|
import * as express from 'express';
|
|
2
2
|
import * as options from '../options';
|
|
3
|
-
import { CallableRequest, FunctionsErrorCode, HttpsError, Request
|
|
3
|
+
import { CallableRequest, FunctionsErrorCode, HttpsError, Request } from '../../common/providers/https';
|
|
4
4
|
import { ManifestEndpoint } from '../../runtime/manifest';
|
|
5
|
-
export { Request, CallableRequest, FunctionsErrorCode, HttpsError
|
|
5
|
+
export { Request, CallableRequest, FunctionsErrorCode, HttpsError };
|
|
6
6
|
export interface HttpsOptions extends Omit<options.GlobalOptions, 'region'> {
|
|
7
7
|
region?: options.SupportedRegion | string | Array<options.SupportedRegion | string>;
|
|
8
8
|
cors?: string | boolean | RegExp | Array<string | RegExp>;
|
|
9
9
|
}
|
|
10
|
-
export interface TaskQueueOptions extends options.GlobalOptions {
|
|
11
|
-
retryConfig?: TaskRetryConfig;
|
|
12
|
-
rateLimits?: TaskRateLimits;
|
|
13
|
-
/**
|
|
14
|
-
* Who can enqueue tasks for this function.
|
|
15
|
-
* If left unspecified, only service accounts which have
|
|
16
|
-
* roles/cloudtasks.enqueuer and roles/cloudfunctions.invoker
|
|
17
|
-
* will have permissions.
|
|
18
|
-
*/
|
|
19
|
-
invoker?: 'private' | string | string[];
|
|
20
|
-
}
|
|
21
10
|
export declare type HttpsFunction = ((req: Request, res: express.Response) => void | Promise<void>) & {
|
|
22
11
|
__trigger?: unknown;
|
|
23
12
|
__endpoint: ManifestEndpoint;
|
|
@@ -25,14 +14,7 @@ export declare type HttpsFunction = ((req: Request, res: express.Response) => vo
|
|
|
25
14
|
export interface CallableFunction<T, Return> extends HttpsFunction {
|
|
26
15
|
run(data: CallableRequest<T>): Return;
|
|
27
16
|
}
|
|
28
|
-
export interface TaskQueueFunction<T = any> extends HttpsFunction {
|
|
29
|
-
run(data: TaskRequest<T>): void | Promise<void>;
|
|
30
|
-
}
|
|
31
17
|
export declare function onRequest(opts: HttpsOptions, handler: (request: Request, response: express.Response) => void | Promise<void>): HttpsFunction;
|
|
32
18
|
export declare function onRequest(handler: (request: Request, response: express.Response) => void | Promise<void>): HttpsFunction;
|
|
33
19
|
export declare function onCall<T = any, Return = any | Promise<any>>(opts: HttpsOptions, handler: (request: CallableRequest<T>) => Return): CallableFunction<T, Return>;
|
|
34
20
|
export declare function onCall<T = any, Return = any | Promise<any>>(handler: (request: CallableRequest<T>) => Return): CallableFunction<T, Return>;
|
|
35
|
-
/** Handle a request sent to a Cloud Tasks queue. */
|
|
36
|
-
export declare function onTaskDispatched<Args = any>(handler: (request: TaskRequest<Args>) => void | Promise<void>): TaskQueueFunction<Args>;
|
|
37
|
-
/** Handle a request sent to a Cloud Tasks queue. */
|
|
38
|
-
export declare function onTaskDispatched<Args = any>(options: TaskQueueOptions, handler: (request: TaskRequest<Args>) => void | Promise<void>): TaskQueueFunction<Args>;
|
|
@@ -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>;
|