firebase-functions 3.24.1 → 4.0.0-rc.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/README.md +7 -9
- package/lib/bin/firebase-functions.js +13 -15
- package/lib/common/app.d.ts +14 -0
- package/lib/common/app.js +62 -0
- package/lib/common/change.d.ts +0 -5
- package/lib/common/change.js +5 -7
- package/lib/common/config.d.ts +6 -0
- package/lib/common/config.js +49 -0
- package/lib/common/debug.js +2 -2
- package/lib/common/encoding.d.ts +0 -8
- package/lib/common/encoding.js +6 -29
- package/lib/common/options.d.ts +14 -0
- package/lib/common/options.js +44 -0
- package/lib/common/params.d.ts +32 -0
- package/lib/common/params.js +23 -0
- package/lib/common/providers/database.d.ts +17 -19
- package/lib/common/providers/database.js +68 -39
- package/lib/common/providers/https.d.ts +11 -52
- package/lib/common/providers/https.js +115 -110
- package/lib/common/providers/identity.d.ts +8 -8
- package/lib/common/providers/identity.js +71 -79
- package/lib/common/providers/tasks.d.ts +11 -10
- package/lib/common/providers/tasks.js +10 -9
- package/lib/common/timezone.js +538 -538
- package/lib/common/trace.d.ts +14 -0
- package/lib/common/trace.js +69 -0
- package/lib/{encoder.d.ts → common/utilities/encoder.d.ts} +0 -0
- package/lib/{encoder.js → common/utilities/encoder.js} +1 -1
- package/lib/{utilities → common/utilities}/path-pattern.d.ts +0 -0
- package/lib/{utilities → common/utilities}/path-pattern.js +17 -16
- package/lib/{utilities → common/utilities}/path.d.ts +0 -0
- package/lib/{utilities → common/utilities}/path.js +5 -7
- package/lib/{utils.d.ts → common/utilities/utils.d.ts} +1 -1
- package/lib/{utils.js → common/utilities/utils.js} +18 -12
- package/lib/logger/common.d.ts +1 -3
- package/lib/logger/common.js +9 -14
- package/lib/logger/compat.js +9 -9
- package/lib/logger/index.d.ts +1 -1
- package/lib/logger/index.js +24 -30
- package/lib/{v2/params → params}/index.d.ts +22 -9
- package/lib/{v2/params → params}/index.js +22 -14
- package/lib/params/types.d.ts +180 -0
- package/lib/params/types.js +289 -0
- package/lib/runtime/loader.js +12 -14
- package/lib/runtime/manifest.d.ts +56 -24
- package/lib/runtime/manifest.js +114 -4
- package/lib/v1/cloud-functions.d.ts +232 -0
- package/lib/v1/cloud-functions.js +205 -0
- package/lib/v1/config.d.ts +8 -0
- package/lib/v1/config.js +75 -0
- package/lib/{function-builder.d.ts → v1/function-builder.d.ts} +16 -16
- package/lib/{function-builder.js → v1/function-builder.js} +56 -46
- package/lib/v1/function-configuration.d.ts +197 -0
- package/lib/v1/function-configuration.js +70 -0
- package/lib/v1/index.d.ts +20 -0
- package/lib/{index.js → v1/index.js} +5 -10
- package/lib/{providers → v1/providers}/analytics.d.ts +5 -11
- package/lib/{providers → v1/providers}/analytics.js +49 -43
- package/lib/{providers → v1/providers}/auth.d.ts +28 -18
- package/lib/{providers → v1/providers}/auth.js +45 -34
- package/lib/{providers → v1/providers}/database.d.ts +25 -42
- package/lib/{providers → v1/providers}/database.js +46 -46
- package/lib/{providers → v1/providers}/firestore.d.ts +15 -33
- package/lib/{providers → v1/providers}/firestore.js +40 -44
- package/lib/{providers → v1/providers}/https.d.ts +3 -8
- package/lib/{providers → v1/providers}/https.js +14 -22
- package/lib/{providers → v1/providers}/pubsub.d.ts +8 -16
- package/lib/{providers → v1/providers}/pubsub.js +22 -26
- package/lib/{providers → v1/providers}/remoteConfig.d.ts +2 -11
- package/lib/{providers → v1/providers}/remoteConfig.js +9 -9
- package/lib/{providers → v1/providers}/storage.d.ts +11 -26
- package/lib/{providers → v1/providers}/storage.js +24 -29
- package/lib/{providers → v1/providers}/tasks.d.ts +6 -8
- package/lib/{providers → v1/providers}/tasks.js +12 -17
- package/lib/{providers → v1/providers}/testLab.d.ts +86 -46
- package/lib/{providers → v1/providers}/testLab.js +14 -14
- package/lib/v2/core.d.ts +4 -5
- package/lib/v2/index.d.ts +16 -14
- package/lib/v2/index.js +5 -1
- package/lib/v2/options.d.ts +52 -32
- package/lib/v2/options.js +32 -47
- package/lib/v2/providers/alerts/alerts.d.ts +20 -18
- package/lib/v2/providers/alerts/alerts.js +9 -6
- package/lib/v2/providers/alerts/appDistribution.d.ts +28 -26
- package/lib/v2/providers/alerts/appDistribution.js +8 -7
- package/lib/v2/providers/alerts/billing.d.ts +5 -5
- package/lib/v2/providers/alerts/billing.js +5 -4
- package/lib/v2/providers/alerts/crashlytics.d.ts +32 -30
- package/lib/v2/providers/alerts/crashlytics.js +10 -9
- package/lib/v2/providers/alerts/index.d.ts +5 -5
- package/lib/v2/providers/alerts/performance.d.ts +3 -3
- package/lib/v2/providers/alerts/performance.js +5 -7
- package/lib/v2/providers/database.d.ts +41 -38
- package/lib/v2/providers/database.js +22 -17
- package/lib/v2/providers/eventarc.d.ts +25 -23
- package/lib/v2/providers/eventarc.js +10 -7
- package/lib/v2/providers/https.d.ts +43 -33
- package/lib/v2/providers/https.js +18 -56
- package/lib/v2/providers/identity.d.ts +25 -23
- package/lib/v2/providers/identity.js +10 -7
- package/lib/v2/providers/pubsub.d.ts +25 -23
- package/lib/v2/providers/pubsub.js +11 -27
- package/lib/v2/providers/remoteConfig.d.ts +63 -0
- package/lib/v2/providers/remoteConfig.js +65 -0
- package/lib/v2/providers/scheduler.d.ts +14 -12
- package/lib/v2/providers/scheduler.js +16 -14
- package/lib/v2/providers/storage.d.ts +32 -30
- package/lib/v2/providers/storage.js +16 -32
- package/lib/v2/providers/tasks.d.ts +30 -26
- package/lib/v2/providers/tasks.js +14 -31
- package/lib/v2/providers/testLab.d.ts +110 -0
- package/lib/v2/providers/testLab.js +65 -0
- package/lib/v2/trace.d.ts +4 -0
- package/lib/v2/trace.js +21 -0
- package/package.json +61 -66
- package/lib/apps.d.ts +0 -35
- package/lib/apps.js +0 -112
- package/lib/cloud-functions.d.ts +0 -231
- package/lib/cloud-functions.js +0 -251
- package/lib/config.d.ts +0 -24
- package/lib/config.js +0 -117
- package/lib/function-configuration.d.ts +0 -108
- package/lib/function-configuration.js +0 -71
- package/lib/handler-builder.d.ts +0 -256
- package/lib/handler-builder.js +0 -349
- package/lib/index.d.ts +0 -19
- package/lib/setup.d.ts +0 -1
- package/lib/setup.js +0 -60
- package/lib/v2/params/types.d.ts +0 -118
- package/lib/v2/params/types.js +0 -196
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { CloudEvent, CloudFunction } from "../core";
|
|
2
|
+
import { EventHandlerOptions } from "../options";
|
|
3
|
+
/** All the fields associated with the person/service account that wrote a Remote Config template. */
|
|
4
|
+
export interface ConfigUser {
|
|
5
|
+
/** Display name. */
|
|
6
|
+
name: string;
|
|
7
|
+
/** Email address. */
|
|
8
|
+
email: string;
|
|
9
|
+
/** Image URL. */
|
|
10
|
+
imageUrl: string;
|
|
11
|
+
}
|
|
12
|
+
/** What type of update was associated with the Remote Config template version. */
|
|
13
|
+
export declare type ConfigUpdateOrigin =
|
|
14
|
+
/** Catch-all for unrecognized values. */
|
|
15
|
+
"REMOTE_CONFIG_UPDATE_ORIGIN_UNSPECIFIED"
|
|
16
|
+
/** The update came from the Firebase UI. */
|
|
17
|
+
| "CONSOLE"
|
|
18
|
+
/** The update came from the Remote Config REST API. */
|
|
19
|
+
| "REST_API"
|
|
20
|
+
/** The update came from the Firebase Admin Node SDK. */
|
|
21
|
+
| "ADMIN_SDK_NODE";
|
|
22
|
+
/** Where the Remote Config update action originated. */
|
|
23
|
+
export declare type ConfigUpdateType =
|
|
24
|
+
/** Catch-all for unrecognized enum values */
|
|
25
|
+
"REMOTE_CONFIG_UPDATE_TYPE_UNSPECIFIED"
|
|
26
|
+
/** A regular incremental update */
|
|
27
|
+
| "INCREMENTAL_UPDATE"
|
|
28
|
+
/** A forced update. The ETag was specified as "*" in an UpdateRemoteConfigRequest request or the "Force Update" button was pressed on the console */
|
|
29
|
+
| "FORCED_UPDATE"
|
|
30
|
+
/** A rollback to a previous Remote Config template */
|
|
31
|
+
| "ROLLBACK";
|
|
32
|
+
/** The data within Firebase Remote Config update events. */
|
|
33
|
+
export interface ConfigUpdateData {
|
|
34
|
+
/** The version number of the version's corresponding Remote Config template. */
|
|
35
|
+
versionNumber: number;
|
|
36
|
+
/** When the Remote Config template was written to the Remote Config server. */
|
|
37
|
+
updateTime: string;
|
|
38
|
+
/** Aggregation of all metadata fields about the account that performed the update. */
|
|
39
|
+
updateUser: ConfigUser;
|
|
40
|
+
/** The user-provided description of the corresponding Remote Config template. */
|
|
41
|
+
description: string;
|
|
42
|
+
/** Where the update action originated. */
|
|
43
|
+
updateOrigin: ConfigUpdateOrigin;
|
|
44
|
+
/** What type of update was made. */
|
|
45
|
+
updateType: ConfigUpdateType;
|
|
46
|
+
/** Only present if this version is the result of a rollback, and will be the version number of the Remote Config template that was rolled-back to. */
|
|
47
|
+
rollbackSource: number;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Event handler which triggers when data is updated in a Remote Config.
|
|
51
|
+
*
|
|
52
|
+
* @param handler - Event handler which is run every time a Remote Config update occurs.
|
|
53
|
+
* @returns A function that you can export and deploy.
|
|
54
|
+
*/
|
|
55
|
+
export declare function onConfigUpdated(handler: (event: CloudEvent<ConfigUpdateData>) => any | Promise<any>): CloudFunction<CloudEvent<ConfigUpdateData>>;
|
|
56
|
+
/**
|
|
57
|
+
* Event handler which triggers when data is updated in a Remote Config.
|
|
58
|
+
*
|
|
59
|
+
* @param opts - Options that can be set on an individual event-handling function.
|
|
60
|
+
* @param handler - Event handler which is run every time a Remote Config update occurs.
|
|
61
|
+
* @returns A function that you can export and deploy.
|
|
62
|
+
*/
|
|
63
|
+
export declare function onConfigUpdated(opts: EventHandlerOptions, handler: (event: CloudEvent<ConfigUpdateData>) => any | Promise<any>): CloudFunction<CloudEvent<ConfigUpdateData>>;
|
|
@@ -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.onConfigUpdated = exports.eventType = void 0;
|
|
25
|
+
const manifest_1 = require("../../runtime/manifest");
|
|
26
|
+
const options_1 = require("../options");
|
|
27
|
+
/** @internal */
|
|
28
|
+
exports.eventType = "google.firebase.remoteconfig.remoteConfig.v1.updated";
|
|
29
|
+
/**
|
|
30
|
+
* Event handler which triggers when data is updated in a Remote Config.
|
|
31
|
+
*
|
|
32
|
+
* @param optsOrHandler - Options or an event handler.
|
|
33
|
+
* @param handler - Event handler which is run every time a Remote Config update occurs.
|
|
34
|
+
* @returns A function that you can export and deploy.
|
|
35
|
+
*/
|
|
36
|
+
function onConfigUpdated(optsOrHandler, handler) {
|
|
37
|
+
if (typeof optsOrHandler === "function") {
|
|
38
|
+
handler = optsOrHandler;
|
|
39
|
+
optsOrHandler = {};
|
|
40
|
+
}
|
|
41
|
+
const baseOpts = (0, options_1.optionsToEndpoint)((0, options_1.getGlobalOptions)());
|
|
42
|
+
const specificOpts = (0, options_1.optionsToEndpoint)(optsOrHandler);
|
|
43
|
+
const func = (raw) => {
|
|
44
|
+
return handler(raw);
|
|
45
|
+
};
|
|
46
|
+
func.run = handler;
|
|
47
|
+
const ep = {
|
|
48
|
+
...(0, manifest_1.initV2Endpoint)((0, options_1.getGlobalOptions)(), optsOrHandler),
|
|
49
|
+
platform: "gcfv2",
|
|
50
|
+
...baseOpts,
|
|
51
|
+
...specificOpts,
|
|
52
|
+
labels: {
|
|
53
|
+
...baseOpts === null || baseOpts === void 0 ? void 0 : baseOpts.labels,
|
|
54
|
+
...specificOpts === null || specificOpts === void 0 ? void 0 : specificOpts.labels,
|
|
55
|
+
},
|
|
56
|
+
eventTrigger: {
|
|
57
|
+
eventType: exports.eventType,
|
|
58
|
+
eventFilters: {},
|
|
59
|
+
retry: !!optsOrHandler.retry,
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
func.__endpoint = ep;
|
|
63
|
+
return func;
|
|
64
|
+
}
|
|
65
|
+
exports.onConfigUpdated = onConfigUpdated;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import { HttpsFunction } from
|
|
1
|
+
import { ResetValue } from "../../common/options";
|
|
2
|
+
import { timezone } from "../../common/timezone";
|
|
3
|
+
import { ManifestRequiredAPI } from "../../runtime/manifest";
|
|
4
|
+
import { HttpsFunction } from "./https";
|
|
5
|
+
import { Expression } from "../../params";
|
|
6
|
+
import * as options from "../options";
|
|
5
7
|
/**
|
|
6
8
|
* Interface representing a ScheduleEvent that is passed to the function handler.
|
|
7
9
|
*/
|
|
@@ -33,17 +35,17 @@ export interface ScheduleOptions extends options.GlobalOptions {
|
|
|
33
35
|
/** The schedule, in Unix Crontab or AppEngine syntax. */
|
|
34
36
|
schedule: string;
|
|
35
37
|
/** The timezone that the schedule executes in. */
|
|
36
|
-
timeZone?: timezone;
|
|
38
|
+
timeZone?: timezone | Expression<string> | ResetValue;
|
|
37
39
|
/** The number of retry attempts for a failed run. */
|
|
38
|
-
retryCount?: number;
|
|
40
|
+
retryCount?: number | Expression<number> | ResetValue;
|
|
39
41
|
/** The time limit for retrying. */
|
|
40
|
-
maxRetrySeconds?: number;
|
|
42
|
+
maxRetrySeconds?: number | Expression<number> | ResetValue;
|
|
41
43
|
/** The minimum time to wait before retying. */
|
|
42
|
-
minBackoffSeconds?: number;
|
|
44
|
+
minBackoffSeconds?: number | Expression<number> | ResetValue;
|
|
43
45
|
/** The maximum time to wait before retrying. */
|
|
44
|
-
maxBackoffSeconds?: number;
|
|
46
|
+
maxBackoffSeconds?: number | Expression<number> | ResetValue;
|
|
45
47
|
/** The time between will double max doublings times. */
|
|
46
|
-
maxDoublings?: number;
|
|
48
|
+
maxDoublings?: number | Expression<number> | ResetValue;
|
|
47
49
|
}
|
|
48
50
|
/**
|
|
49
51
|
* Handler for scheduled functions. Triggered whenever the associated
|
|
@@ -52,7 +54,7 @@ export interface ScheduleOptions extends options.GlobalOptions {
|
|
|
52
54
|
* @param handler - A function to execute when triggered.
|
|
53
55
|
* @returns A function that you can export and deploy.
|
|
54
56
|
*/
|
|
55
|
-
export declare function onSchedule(schedule: string, handler: (
|
|
57
|
+
export declare function onSchedule(schedule: string, handler: (event: ScheduledEvent) => void | Promise<void>): ScheduleFunction;
|
|
56
58
|
/**
|
|
57
59
|
* Handler for scheduled functions. Triggered whenever the associated
|
|
58
60
|
* scheduler job sends a http request.
|
|
@@ -60,4 +62,4 @@ export declare function onSchedule(schedule: string, handler: (req: ScheduledEve
|
|
|
60
62
|
* @param handler - A function to execute when triggered.
|
|
61
63
|
* @returns A function that you can export and deploy.
|
|
62
64
|
*/
|
|
63
|
-
export declare function onSchedule(options: ScheduleOptions, handler: (
|
|
65
|
+
export declare function onSchedule(options: ScheduleOptions, handler: (event: ScheduledEvent) => void | Promise<void>): ScheduleFunction;
|
|
@@ -23,11 +23,13 @@
|
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
24
|
exports.onSchedule = exports.getOpts = void 0;
|
|
25
25
|
const encoding_1 = require("../../common/encoding");
|
|
26
|
+
const manifest_1 = require("../../runtime/manifest");
|
|
27
|
+
const trace_1 = require("../trace");
|
|
26
28
|
const logger = require("../../logger");
|
|
27
29
|
const options = require("../options");
|
|
28
30
|
/** @internal */
|
|
29
31
|
function getOpts(args) {
|
|
30
|
-
if (typeof args ===
|
|
32
|
+
if (typeof args === "string") {
|
|
31
33
|
return {
|
|
32
34
|
schedule: args,
|
|
33
35
|
opts: {},
|
|
@@ -54,10 +56,10 @@ exports.getOpts = getOpts;
|
|
|
54
56
|
*/
|
|
55
57
|
function onSchedule(args, handler) {
|
|
56
58
|
const separatedOpts = getOpts(args);
|
|
57
|
-
const
|
|
59
|
+
const httpFunc = async (req, res) => {
|
|
58
60
|
const event = {
|
|
59
|
-
jobName: req.header(
|
|
60
|
-
scheduleTime: req.header(
|
|
61
|
+
jobName: req.header("X-CloudScheduler-JobName") || undefined,
|
|
62
|
+
scheduleTime: req.header("X-CloudScheduler-ScheduleTime") || new Date().toISOString(),
|
|
61
63
|
};
|
|
62
64
|
try {
|
|
63
65
|
await handler(event);
|
|
@@ -68,29 +70,29 @@ function onSchedule(args, handler) {
|
|
|
68
70
|
res.status(500).send();
|
|
69
71
|
}
|
|
70
72
|
};
|
|
73
|
+
const func = (0, trace_1.wrapTraceContext)(httpFunc);
|
|
71
74
|
func.run = handler;
|
|
72
|
-
const
|
|
75
|
+
const globalOpts = options.getGlobalOptions();
|
|
76
|
+
const baseOptsEndpoint = options.optionsToEndpoint(globalOpts);
|
|
73
77
|
const specificOptsEndpoint = options.optionsToEndpoint(separatedOpts.opts);
|
|
74
78
|
const ep = {
|
|
75
|
-
|
|
79
|
+
...(0, manifest_1.initV2Endpoint)(globalOpts, separatedOpts.opts),
|
|
80
|
+
platform: "gcfv2",
|
|
76
81
|
...baseOptsEndpoint,
|
|
77
82
|
...specificOptsEndpoint,
|
|
78
83
|
labels: {
|
|
79
84
|
...baseOptsEndpoint === null || baseOptsEndpoint === void 0 ? void 0 : baseOptsEndpoint.labels,
|
|
80
85
|
...specificOptsEndpoint === null || specificOptsEndpoint === void 0 ? void 0 : specificOptsEndpoint.labels,
|
|
81
86
|
},
|
|
82
|
-
scheduleTrigger:
|
|
83
|
-
schedule: separatedOpts.schedule,
|
|
84
|
-
retryConfig: {},
|
|
85
|
-
},
|
|
87
|
+
scheduleTrigger: (0, manifest_1.initV2ScheduleTrigger)(separatedOpts.schedule, globalOpts, separatedOpts.opts),
|
|
86
88
|
};
|
|
87
|
-
(0, encoding_1.copyIfPresent)(ep.scheduleTrigger, separatedOpts,
|
|
88
|
-
(0, encoding_1.copyIfPresent)(ep.scheduleTrigger.retryConfig, separatedOpts,
|
|
89
|
+
(0, encoding_1.copyIfPresent)(ep.scheduleTrigger, separatedOpts, "timeZone");
|
|
90
|
+
(0, encoding_1.copyIfPresent)(ep.scheduleTrigger.retryConfig, separatedOpts, "retryCount", "maxRetrySeconds", "minBackoffSeconds", "maxBackoffSeconds", "maxDoublings");
|
|
89
91
|
func.__endpoint = ep;
|
|
90
92
|
func.__requiredAPIs = [
|
|
91
93
|
{
|
|
92
|
-
api:
|
|
93
|
-
reason:
|
|
94
|
+
api: "cloudscheduler.googleapis.com",
|
|
95
|
+
reason: "Needed for scheduled functions.",
|
|
94
96
|
},
|
|
95
97
|
];
|
|
96
98
|
return func;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import { Expression } from
|
|
1
|
+
import { ResetValue } from "../../common/options";
|
|
2
|
+
import { CloudEvent, CloudFunction } from "../core";
|
|
3
|
+
import { Expression } from "../../params";
|
|
4
|
+
import * as options from "../options";
|
|
5
|
+
import { SecretParam } from "../../params/types";
|
|
4
6
|
/**
|
|
5
7
|
* An object within Google Cloud Storage.
|
|
6
8
|
* Ref: https://github.com/googleapis/google-cloudevents-nodejs/blob/main/cloud/storage/v1/StorageObjectData.ts
|
|
@@ -9,7 +11,7 @@ export interface StorageObjectData {
|
|
|
9
11
|
/**
|
|
10
12
|
* The name of the bucket containing this object.
|
|
11
13
|
*/
|
|
12
|
-
bucket
|
|
14
|
+
bucket: string;
|
|
13
15
|
/**
|
|
14
16
|
* Cache-Control directive for the object data, matching
|
|
15
17
|
* [https://tools.ietf.org/html/rfc7234#section-5.2"][RFC 7234 §5.2].
|
|
@@ -64,12 +66,12 @@ export interface StorageObjectData {
|
|
|
64
66
|
* The content generation of this object. Used for object versioning.
|
|
65
67
|
* Attempting to set this field will result in an error.
|
|
66
68
|
*/
|
|
67
|
-
generation
|
|
69
|
+
generation: number;
|
|
68
70
|
/**
|
|
69
71
|
* The ID of the object, including the bucket name, object name, and
|
|
70
72
|
* generation number.
|
|
71
73
|
*/
|
|
72
|
-
id
|
|
74
|
+
id: string;
|
|
73
75
|
/**
|
|
74
76
|
* The kind of item this is. For objects, this is always "storage#object".
|
|
75
77
|
*/
|
|
@@ -98,11 +100,11 @@ export interface StorageObjectData {
|
|
|
98
100
|
* number is only meaningful in the context of a particular generation of a
|
|
99
101
|
* particular object.
|
|
100
102
|
*/
|
|
101
|
-
metageneration
|
|
103
|
+
metageneration: number;
|
|
102
104
|
/**
|
|
103
105
|
* The name of the object.
|
|
104
106
|
*/
|
|
105
|
-
name
|
|
107
|
+
name: string;
|
|
106
108
|
/**
|
|
107
109
|
* The link to this object.
|
|
108
110
|
*/
|
|
@@ -111,11 +113,11 @@ export interface StorageObjectData {
|
|
|
111
113
|
* Content-Length of the object data in bytes, matching
|
|
112
114
|
* [https://tools.ietf.org/html/rfc7230#section-3.3.2][RFC 7230 §3.3.2].
|
|
113
115
|
*/
|
|
114
|
-
size
|
|
116
|
+
size: number;
|
|
115
117
|
/**
|
|
116
118
|
* Storage class of the object.
|
|
117
119
|
*/
|
|
118
|
-
storageClass
|
|
120
|
+
storageClass: string;
|
|
119
121
|
/**
|
|
120
122
|
* The creation time of the object.
|
|
121
123
|
* Attempting to set this field will result in an error.
|
|
@@ -164,76 +166,76 @@ export interface StorageOptions extends options.EventHandlerOptions {
|
|
|
164
166
|
region?: options.SupportedRegion | string;
|
|
165
167
|
/**
|
|
166
168
|
* Amount of memory to allocate to a function.
|
|
167
|
-
* A value of null restores the defaults of 256MB.
|
|
168
169
|
*/
|
|
169
|
-
memory?: options.MemoryOption | Expression<number> |
|
|
170
|
+
memory?: options.MemoryOption | Expression<number> | ResetValue;
|
|
170
171
|
/**
|
|
171
172
|
* Timeout for the function in sections, possible values are 0 to 540.
|
|
172
173
|
* HTTPS functions can specify a higher timeout.
|
|
173
|
-
*
|
|
174
|
+
*
|
|
175
|
+
* @remarks
|
|
174
176
|
* The minimum timeout for a gen 2 function is 1s. The maximum timeout for a
|
|
175
177
|
* function depends on the type of function: Event handling functions have a
|
|
176
178
|
* maximum timeout of 540s (9 minutes). HTTPS and callable functions have a
|
|
177
179
|
* maximum timeout of 36,00s (1 hour). Task queue functions have a maximum
|
|
178
180
|
* timeout of 1,800s (30 minutes)
|
|
179
181
|
*/
|
|
180
|
-
timeoutSeconds?: number | Expression<number> |
|
|
182
|
+
timeoutSeconds?: number | Expression<number> | ResetValue;
|
|
181
183
|
/**
|
|
182
184
|
* Min number of actual instances to be running at a given time.
|
|
185
|
+
*
|
|
186
|
+
* @remarks
|
|
183
187
|
* Instances will be billed for memory allocation and 10% of CPU allocation
|
|
184
188
|
* while idle.
|
|
185
|
-
* A value of null restores the default min instances.
|
|
186
189
|
*/
|
|
187
|
-
minInstances?: number | Expression<number> |
|
|
190
|
+
minInstances?: number | Expression<number> | ResetValue;
|
|
188
191
|
/**
|
|
189
192
|
* Max number of instances to be running in parallel.
|
|
190
|
-
* A value of null restores the default max instances.
|
|
191
193
|
*/
|
|
192
|
-
maxInstances?: number | Expression<number> |
|
|
194
|
+
maxInstances?: number | Expression<number> | ResetValue;
|
|
193
195
|
/**
|
|
194
196
|
* Number of requests a function can serve at once.
|
|
197
|
+
*
|
|
198
|
+
* @remarks
|
|
195
199
|
* Can only be applied to functions running on Cloud Functions v2.
|
|
196
200
|
* A value of null restores the default concurrency (80 when CPU >= 1, 1 otherwise).
|
|
197
201
|
* Concurrency cannot be set to any value other than 1 if `cpu` is less than 1.
|
|
198
202
|
* The maximum value for concurrency is 1,000.
|
|
199
203
|
*/
|
|
200
|
-
concurrency?: number | Expression<number> |
|
|
204
|
+
concurrency?: number | Expression<number> | ResetValue;
|
|
201
205
|
/**
|
|
202
206
|
* Fractional number of CPUs to allocate to a function.
|
|
207
|
+
*
|
|
208
|
+
* @remarks
|
|
203
209
|
* Defaults to 1 for functions with <= 2GB RAM and increases for larger memory sizes.
|
|
204
210
|
* This is different from the defaults when using the gcloud utility and is different from
|
|
205
211
|
* the fixed amount assigned in Google Cloud Functions generation 1.
|
|
206
212
|
* To revert to the CPU amounts used in gcloud or in Cloud Functions generation 1, set this
|
|
207
213
|
* to the value "gcf_gen1"
|
|
208
214
|
*/
|
|
209
|
-
cpu?: number |
|
|
215
|
+
cpu?: number | "gcf_gen1";
|
|
210
216
|
/**
|
|
211
217
|
* Connect cloud function to specified VPC connector.
|
|
212
|
-
* A value of null removes the VPC connector
|
|
213
218
|
*/
|
|
214
|
-
vpcConnector?: string |
|
|
219
|
+
vpcConnector?: string | ResetValue;
|
|
215
220
|
/**
|
|
216
221
|
* Egress settings for VPC connector.
|
|
217
|
-
* A value of null turns off VPC connector egress settings
|
|
218
222
|
*/
|
|
219
|
-
vpcConnectorEgressSettings?: options.VpcEgressSetting |
|
|
223
|
+
vpcConnectorEgressSettings?: options.VpcEgressSetting | ResetValue;
|
|
220
224
|
/**
|
|
221
225
|
* Specific service account for the function to run as.
|
|
222
|
-
* A value of null restores the default service account.
|
|
223
226
|
*/
|
|
224
|
-
serviceAccount?: string |
|
|
227
|
+
serviceAccount?: string | ResetValue;
|
|
225
228
|
/**
|
|
226
229
|
* Ingress settings which control where this function can be called from.
|
|
227
|
-
* A value of null turns off ingress settings.
|
|
228
230
|
*/
|
|
229
|
-
ingressSettings?: options.IngressSetting |
|
|
231
|
+
ingressSettings?: options.IngressSetting | ResetValue;
|
|
230
232
|
/**
|
|
231
233
|
* User labels to set on the function.
|
|
232
234
|
*/
|
|
233
235
|
labels?: Record<string, string>;
|
|
234
|
-
secrets?: string[];
|
|
236
|
+
secrets?: (string | SecretParam)[];
|
|
235
237
|
/** Whether failed executions should be delivered again. */
|
|
236
|
-
retry?: boolean;
|
|
238
|
+
retry?: boolean | Expression<boolean> | ResetValue;
|
|
237
239
|
}
|
|
238
240
|
/**
|
|
239
241
|
* Event handler sent only when a bucket has enabled object versioning.
|
|
@@ -26,17 +26,19 @@ exports.getOptsAndBucket = exports.onOperation = exports.onObjectMetadataUpdated
|
|
|
26
26
|
* Cloud functions to handle events from Google Cloud Storage.
|
|
27
27
|
* @packageDocumentation
|
|
28
28
|
*/
|
|
29
|
+
const config_1 = require("../../common/config");
|
|
29
30
|
const encoding_1 = require("../../common/encoding");
|
|
30
|
-
const
|
|
31
|
+
const manifest_1 = require("../../runtime/manifest");
|
|
32
|
+
const trace_1 = require("../trace");
|
|
31
33
|
const options = require("../options");
|
|
32
34
|
/** @internal */
|
|
33
|
-
exports.archivedEvent =
|
|
35
|
+
exports.archivedEvent = "google.cloud.storage.object.v1.archived";
|
|
34
36
|
/** @internal */
|
|
35
|
-
exports.finalizedEvent =
|
|
37
|
+
exports.finalizedEvent = "google.cloud.storage.object.v1.finalized";
|
|
36
38
|
/** @internal */
|
|
37
|
-
exports.deletedEvent =
|
|
39
|
+
exports.deletedEvent = "google.cloud.storage.object.v1.deleted";
|
|
38
40
|
/** @internal */
|
|
39
|
-
exports.metadataUpdatedEvent =
|
|
41
|
+
exports.metadataUpdatedEvent = "google.cloud.storage.object.v1.metadataUpdated";
|
|
40
42
|
/**
|
|
41
43
|
* Event handler sent only when a bucket has enabled object versioning.
|
|
42
44
|
* This event indicates that the live version of an object has become an
|
|
@@ -94,46 +96,28 @@ function onObjectMetadataUpdated(bucketOrOptsOrHandler, handler) {
|
|
|
94
96
|
exports.onObjectMetadataUpdated = onObjectMetadataUpdated;
|
|
95
97
|
/** @internal */
|
|
96
98
|
function onOperation(eventType, bucketOrOptsOrHandler, handler) {
|
|
97
|
-
if (typeof bucketOrOptsOrHandler ===
|
|
99
|
+
if (typeof bucketOrOptsOrHandler === "function") {
|
|
98
100
|
handler = bucketOrOptsOrHandler;
|
|
99
101
|
bucketOrOptsOrHandler = {};
|
|
100
102
|
}
|
|
101
103
|
const [opts, bucket] = getOptsAndBucket(bucketOrOptsOrHandler);
|
|
102
104
|
const func = (raw) => {
|
|
103
|
-
return handler(raw);
|
|
105
|
+
return (0, trace_1.wrapTraceContext)(handler)(raw);
|
|
104
106
|
};
|
|
105
107
|
func.run = handler;
|
|
106
|
-
Object.defineProperty(func, '__trigger', {
|
|
107
|
-
get: () => {
|
|
108
|
-
const baseOpts = options.optionsToTriggerAnnotations(options.getGlobalOptions());
|
|
109
|
-
const specificOpts = options.optionsToTriggerAnnotations(opts);
|
|
110
|
-
return {
|
|
111
|
-
platform: 'gcfv2',
|
|
112
|
-
...baseOpts,
|
|
113
|
-
...specificOpts,
|
|
114
|
-
labels: {
|
|
115
|
-
...baseOpts === null || baseOpts === void 0 ? void 0 : baseOpts.labels,
|
|
116
|
-
...specificOpts === null || specificOpts === void 0 ? void 0 : specificOpts.labels,
|
|
117
|
-
},
|
|
118
|
-
eventTrigger: {
|
|
119
|
-
eventType,
|
|
120
|
-
resource: bucket, // TODO(colerogers): replace with 'bucket,' eventually
|
|
121
|
-
},
|
|
122
|
-
};
|
|
123
|
-
},
|
|
124
|
-
});
|
|
125
108
|
// TypeScript doesn't recognize defineProperty as adding a property and complains
|
|
126
109
|
// that __endpoint doesn't exist. We can either cast to any and lose all type safety
|
|
127
110
|
// or we can just assign a meaningless value before calling defineProperty.
|
|
128
111
|
func.__endpoint = {};
|
|
129
112
|
// SDK may attempt to read FIREBASE_CONFIG env var to fetch the default bucket name.
|
|
130
113
|
// To prevent runtime errors when FIREBASE_CONFIG env var is missing, we use getters.
|
|
131
|
-
Object.defineProperty(func,
|
|
114
|
+
Object.defineProperty(func, "__endpoint", {
|
|
132
115
|
get: () => {
|
|
133
116
|
const baseOpts = options.optionsToEndpoint(options.getGlobalOptions());
|
|
134
117
|
const specificOpts = options.optionsToEndpoint(opts);
|
|
135
118
|
const endpoint = {
|
|
136
|
-
platform:
|
|
119
|
+
platform: "gcfv2",
|
|
120
|
+
...(0, manifest_1.initV2Endpoint)(options.getGlobalOptions(), opts),
|
|
137
121
|
...baseOpts,
|
|
138
122
|
...specificOpts,
|
|
139
123
|
labels: {
|
|
@@ -146,7 +130,7 @@ function onOperation(eventType, bucketOrOptsOrHandler, handler) {
|
|
|
146
130
|
retry: false,
|
|
147
131
|
},
|
|
148
132
|
};
|
|
149
|
-
(0, encoding_1.copyIfPresent)(endpoint.eventTrigger, opts,
|
|
133
|
+
(0, encoding_1.copyIfPresent)(endpoint.eventTrigger, opts, "retry", "retry");
|
|
150
134
|
return endpoint;
|
|
151
135
|
},
|
|
152
136
|
});
|
|
@@ -158,7 +142,7 @@ function getOptsAndBucket(bucketOrOpts) {
|
|
|
158
142
|
var _a;
|
|
159
143
|
let bucket;
|
|
160
144
|
let opts;
|
|
161
|
-
if (typeof bucketOrOpts ===
|
|
145
|
+
if (typeof bucketOrOpts === "string") {
|
|
162
146
|
bucket = bucketOrOpts;
|
|
163
147
|
opts = {};
|
|
164
148
|
}
|
|
@@ -168,8 +152,8 @@ function getOptsAndBucket(bucketOrOpts) {
|
|
|
168
152
|
delete opts.bucket;
|
|
169
153
|
}
|
|
170
154
|
if (!bucket) {
|
|
171
|
-
throw new Error(
|
|
172
|
-
|
|
155
|
+
throw new Error("Missing bucket name. If you are unit testing, please provide a bucket name" +
|
|
156
|
+
" by providing bucket name directly in the event handler or by setting process.env.FIREBASE_CONFIG.");
|
|
173
157
|
}
|
|
174
158
|
if (!/^[a-z\d][a-z\d\\._-]{1,230}[a-z\d]$/.test(bucket)) {
|
|
175
159
|
throw new Error(`Invalid bucket name ${bucket}`);
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { HttpsFunction } from
|
|
1
|
+
import { ResetValue } from "../../common/options";
|
|
2
|
+
import { AuthData, RateLimits, Request, RetryConfig } from "../../common/providers/tasks";
|
|
3
|
+
import * as options from "../options";
|
|
4
|
+
import { HttpsFunction } from "./https";
|
|
5
|
+
import { Expression } from "../../params";
|
|
6
|
+
import { SecretParam } from "../../params/types";
|
|
5
7
|
export { AuthData, Request };
|
|
6
8
|
export interface TaskQueueOptions extends options.EventHandlerOptions {
|
|
7
9
|
/** How a task should be retried in the event of a non-2xx return. */
|
|
@@ -10,85 +12,87 @@ export interface TaskQueueOptions extends options.EventHandlerOptions {
|
|
|
10
12
|
rateLimits?: RateLimits;
|
|
11
13
|
/**
|
|
12
14
|
* Who can enqueue tasks for this function.
|
|
15
|
+
*
|
|
16
|
+
* @remakrs
|
|
13
17
|
* If left unspecified, only service accounts which have
|
|
14
18
|
* `roles/cloudtasks.enqueuer` and `roles/cloudfunctions.invoker`
|
|
15
19
|
* will have permissions.
|
|
16
20
|
*/
|
|
17
|
-
invoker?:
|
|
21
|
+
invoker?: "private" | string | string[];
|
|
18
22
|
/**
|
|
19
23
|
* Region where functions should be deployed.
|
|
20
24
|
*/
|
|
21
25
|
region?: options.SupportedRegion | string;
|
|
22
26
|
/**
|
|
23
27
|
* Amount of memory to allocate to a function.
|
|
24
|
-
* A value of null restores the defaults of 256MB.
|
|
25
28
|
*/
|
|
26
|
-
memory?: options.MemoryOption | Expression<number> |
|
|
29
|
+
memory?: options.MemoryOption | Expression<number> | ResetValue;
|
|
27
30
|
/**
|
|
28
31
|
* Timeout for the function in sections, possible values are 0 to 540.
|
|
29
32
|
* HTTPS functions can specify a higher timeout.
|
|
30
|
-
*
|
|
33
|
+
*
|
|
34
|
+
* @remarks
|
|
31
35
|
* The minimum timeout for a gen 2 function is 1s. The maximum timeout for a
|
|
32
36
|
* function depends on the type of function: Event handling functions have a
|
|
33
37
|
* maximum timeout of 540s (9 minutes). HTTPS and callable functions have a
|
|
34
38
|
* maximum timeout of 36,00s (1 hour). Task queue functions have a maximum
|
|
35
39
|
* timeout of 1,800s (30 minutes)
|
|
36
40
|
*/
|
|
37
|
-
timeoutSeconds?: number | Expression<number> |
|
|
41
|
+
timeoutSeconds?: number | Expression<number> | ResetValue;
|
|
38
42
|
/**
|
|
39
43
|
* Min number of actual instances to be running at a given time.
|
|
44
|
+
*
|
|
45
|
+
* @remarks
|
|
40
46
|
* Instances will be billed for memory allocation and 10% of CPU allocation
|
|
41
47
|
* while idle.
|
|
42
|
-
* A value of null restores the default min instances.
|
|
43
48
|
*/
|
|
44
|
-
minInstances?: number | Expression<number> |
|
|
49
|
+
minInstances?: number | Expression<number> | ResetValue;
|
|
45
50
|
/**
|
|
46
51
|
* Max number of instances to be running in parallel.
|
|
47
|
-
* A value of null restores the default max instances.
|
|
48
52
|
*/
|
|
49
|
-
maxInstances?: number | Expression<number> |
|
|
53
|
+
maxInstances?: number | Expression<number> | ResetValue;
|
|
50
54
|
/**
|
|
51
55
|
* Number of requests a function can serve at once.
|
|
56
|
+
*
|
|
57
|
+
* @remarks
|
|
52
58
|
* Can only be applied to functions running on Cloud Functions v2.
|
|
53
59
|
* A value of null restores the default concurrency (80 when CPU >= 1, 1 otherwise).
|
|
54
60
|
* Concurrency cannot be set to any value other than 1 if `cpu` is less than 1.
|
|
55
61
|
* The maximum value for concurrency is 1,000.
|
|
56
62
|
*/
|
|
57
|
-
concurrency?: number | Expression<number> |
|
|
63
|
+
concurrency?: number | Expression<number> | ResetValue;
|
|
58
64
|
/**
|
|
59
65
|
* Fractional number of CPUs to allocate to a function.
|
|
66
|
+
*
|
|
67
|
+
* @remarks
|
|
60
68
|
* Defaults to 1 for functions with <= 2GB RAM and increases for larger memory sizes.
|
|
61
69
|
* This is different from the defaults when using the gcloud utility and is different from
|
|
62
70
|
* the fixed amount assigned in Google Cloud Functions generation 1.
|
|
63
71
|
* To revert to the CPU amounts used in gcloud or in Cloud Functions generation 1, set this
|
|
64
72
|
* to the value "gcf_gen1"
|
|
65
73
|
*/
|
|
66
|
-
cpu?: number |
|
|
74
|
+
cpu?: number | "gcf_gen1";
|
|
67
75
|
/**
|
|
68
76
|
* Connect cloud function to specified VPC connector.
|
|
69
|
-
* A value of null removes the VPC connector
|
|
70
77
|
*/
|
|
71
|
-
vpcConnector?: string |
|
|
78
|
+
vpcConnector?: string | ResetValue;
|
|
72
79
|
/**
|
|
73
80
|
* Egress settings for VPC connector.
|
|
74
|
-
* A value of null turns off VPC connector egress settings
|
|
75
81
|
*/
|
|
76
|
-
vpcConnectorEgressSettings?: options.VpcEgressSetting |
|
|
82
|
+
vpcConnectorEgressSettings?: options.VpcEgressSetting | ResetValue;
|
|
77
83
|
/**
|
|
78
84
|
* Specific service account for the function to run as.
|
|
79
|
-
* A value of null restores the default service account.
|
|
80
85
|
*/
|
|
81
|
-
serviceAccount?: string |
|
|
86
|
+
serviceAccount?: string | ResetValue;
|
|
82
87
|
/**
|
|
83
88
|
* Ingress settings which control where this function can be called from.
|
|
84
|
-
* A value of null turns off ingress settings.
|
|
85
89
|
*/
|
|
86
|
-
ingressSettings?: options.IngressSetting |
|
|
90
|
+
ingressSettings?: options.IngressSetting | ResetValue;
|
|
87
91
|
/**
|
|
88
92
|
* User labels to set on the function.
|
|
89
93
|
*/
|
|
90
94
|
labels?: Record<string, string>;
|
|
91
|
-
secrets?: string[];
|
|
95
|
+
secrets?: (string | SecretParam)[];
|
|
92
96
|
/** Whether failed executions should be delivered again. */
|
|
93
97
|
retry?: boolean;
|
|
94
98
|
}
|
|
@@ -110,7 +114,7 @@ export interface TaskQueueFunction<T = any> extends HttpsFunction {
|
|
|
110
114
|
* Creates a handler for tasks sent to a Google Cloud Tasks queue.
|
|
111
115
|
* @param handler - A callback to handle task requests.
|
|
112
116
|
* @typeParam Args - The interface for the request's `data` field.
|
|
113
|
-
* @returns A
|
|
117
|
+
* @returns A function you can export and deploy.
|
|
114
118
|
*/
|
|
115
119
|
export declare function onTaskDispatched<Args = any>(handler: (request: Request<Args>) => void | Promise<void>): TaskQueueFunction<Args>;
|
|
116
120
|
/**
|
|
@@ -118,6 +122,6 @@ export declare function onTaskDispatched<Args = any>(handler: (request: Request<
|
|
|
118
122
|
* @param options - Configuration for the task queue or Cloud Function.
|
|
119
123
|
* @param handler - A callback to handle task requests.
|
|
120
124
|
* @typeParam Args - The interface for the request's `data` field.
|
|
121
|
-
* @returns A
|
|
125
|
+
* @returns A function you can export and deploy.
|
|
122
126
|
*/
|
|
123
127
|
export declare function onTaskDispatched<Args = any>(options: TaskQueueOptions, handler: (request: Request<Args>) => void | Promise<void>): TaskQueueFunction<Args>;
|