firebase-functions 4.0.0 → 4.0.2
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/common/encoding.d.ts +8 -0
- package/lib/common/encoding.js +24 -2
- package/lib/params/types.d.ts +3 -1
- package/lib/params/types.js +13 -2
- package/lib/v1/cloud-functions.d.ts +41 -0
- package/lib/v1/cloud-functions.js +52 -2
- package/lib/v1/function-configuration.d.ts +1 -0
- package/lib/v1/function-configuration.js +4 -1
- package/lib/v1/providers/auth.js +12 -0
- package/lib/v1/providers/https.js +11 -0
- package/lib/v1/providers/tasks.d.ts +2 -0
- package/lib/v1/providers/tasks.js +7 -0
- package/lib/v2/core.d.ts +2 -0
- package/lib/v2/options.js +25 -1
- package/lib/v2/providers/alerts/appDistribution.d.ts +0 -8
- package/lib/v2/providers/alerts/appDistribution.js +0 -2
- package/lib/v2/providers/https.d.ts +2 -0
- package/lib/v2/providers/https.js +43 -0
- package/lib/v2/providers/pubsub.js +19 -0
- package/lib/v2/providers/storage.js +19 -0
- package/lib/v2/providers/tasks.js +22 -2
- package/package.json +18 -14
package/lib/common/encoding.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A type alias used to annotate interfaces as using a google.protobuf.Duration.
|
|
3
|
+
* This type is parsed/encoded as a string of seconds + the "s" prefix.
|
|
4
|
+
*/
|
|
5
|
+
export declare type Duration = string;
|
|
6
|
+
/** Get a google.protobuf.Duration for a number of seconds. */
|
|
7
|
+
export declare function durationFromSeconds(s: number): Duration;
|
|
1
8
|
/**
|
|
2
9
|
* Utility function to help copy fields from type A to B.
|
|
3
10
|
* As a safety net, catches typos or fields that aren't named the same
|
|
@@ -5,4 +12,5 @@
|
|
|
5
12
|
*/
|
|
6
13
|
export declare function copyIfPresent<Src, Dest>(dest: Dest, src: Src, ...fields: Array<keyof Src & keyof Dest>): void;
|
|
7
14
|
export declare function convertIfPresent<Src, Dest>(dest: Dest, src: Src, destField: keyof Dest, srcField: keyof Src, converter?: (from: any) => any): void;
|
|
15
|
+
export declare function serviceAccountFromShorthand(serviceAccount: string): string | null;
|
|
8
16
|
export declare function convertInvoker(invoker: string | string[]): string[];
|
package/lib/common/encoding.js
CHANGED
|
@@ -21,8 +21,12 @@
|
|
|
21
21
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
// SOFTWARE.
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.convertInvoker = exports.convertIfPresent = exports.copyIfPresent = void 0;
|
|
25
|
-
|
|
24
|
+
exports.convertInvoker = exports.serviceAccountFromShorthand = exports.convertIfPresent = exports.copyIfPresent = exports.durationFromSeconds = void 0;
|
|
25
|
+
/** Get a google.protobuf.Duration for a number of seconds. */
|
|
26
|
+
function durationFromSeconds(s) {
|
|
27
|
+
return `${s}s`;
|
|
28
|
+
}
|
|
29
|
+
exports.durationFromSeconds = durationFromSeconds;
|
|
26
30
|
/**
|
|
27
31
|
* Utility function to help copy fields from type A to B.
|
|
28
32
|
* As a safety net, catches typos or fields that aren't named the same
|
|
@@ -52,6 +56,24 @@ function convertIfPresent(dest, src, destField, srcField, converter = (from) =>
|
|
|
52
56
|
dest[destField] = converter(src[srcField]);
|
|
53
57
|
}
|
|
54
58
|
exports.convertIfPresent = convertIfPresent;
|
|
59
|
+
function serviceAccountFromShorthand(serviceAccount) {
|
|
60
|
+
if (serviceAccount === "default") {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
else if (serviceAccount.endsWith("@")) {
|
|
64
|
+
if (!process.env.GCLOUD_PROJECT) {
|
|
65
|
+
throw new Error(`Unable to determine email for service account '${serviceAccount}' because process.env.GCLOUD_PROJECT is not set.`);
|
|
66
|
+
}
|
|
67
|
+
return `${serviceAccount}${process.env.GCLOUD_PROJECT}.iam.gserviceaccount.com`;
|
|
68
|
+
}
|
|
69
|
+
else if (serviceAccount.includes("@")) {
|
|
70
|
+
return serviceAccount;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
throw new Error(`Invalid option for serviceAccount: '${serviceAccount}'. Valid options are 'default', a service account email, or '{serviceAccountName}@'`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.serviceAccountFromShorthand = serviceAccountFromShorthand;
|
|
55
77
|
function convertInvoker(invoker) {
|
|
56
78
|
if (typeof invoker === "string") {
|
|
57
79
|
invoker = [invoker];
|
package/lib/params/types.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ export declare class CompareExpression<T extends string | number | boolean | str
|
|
|
26
26
|
constructor(cmp: "==" | "!=" | ">" | ">=" | "<" | "<=", lhs: Expression<T>, rhs: T | Expression<T>);
|
|
27
27
|
toString(): string;
|
|
28
28
|
/** Returns a TernaryExpression which can resolve to one of two values, based on the resolution of this comparison. */
|
|
29
|
-
|
|
29
|
+
thenElse<retT extends string | number | boolean | string[]>(ifTrue: retT | Expression<retT>, ifFalse: retT | Expression<retT>): TernaryExpression<retT>;
|
|
30
30
|
}
|
|
31
31
|
/** @hidden */
|
|
32
32
|
declare type ParamValueType = "string" | "list" | "boolean" | "int" | "float" | "secret";
|
|
@@ -148,6 +148,8 @@ export declare class SecretParam {
|
|
|
148
148
|
static type: ParamValueType;
|
|
149
149
|
name: string;
|
|
150
150
|
constructor(name: string);
|
|
151
|
+
/** Returns the secret's value at runtime. Throws an error if accessed during deployment. */
|
|
152
|
+
value(): string;
|
|
151
153
|
}
|
|
152
154
|
/**
|
|
153
155
|
* A parametrized value of String type that will be read from .env files
|
package/lib/params/types.js
CHANGED
|
@@ -119,7 +119,7 @@ class CompareExpression extends Expression {
|
|
|
119
119
|
return `${this.lhs} ${this.cmp} ${rhsStr}`;
|
|
120
120
|
}
|
|
121
121
|
/** Returns a TernaryExpression which can resolve to one of two values, based on the resolution of this comparison. */
|
|
122
|
-
|
|
122
|
+
thenElse(ifTrue, ifFalse) {
|
|
123
123
|
return new TernaryExpression(this, ifTrue, ifFalse);
|
|
124
124
|
}
|
|
125
125
|
}
|
|
@@ -204,7 +204,11 @@ class SecretParam {
|
|
|
204
204
|
}
|
|
205
205
|
/** @internal */
|
|
206
206
|
runtimeValue() {
|
|
207
|
-
|
|
207
|
+
const val = process.env[this.name];
|
|
208
|
+
if (val === undefined) {
|
|
209
|
+
logger.warn(`No value found for secret parameter "${this.name}". A function can only access a secret if you include the secret in the function's dependency array.`);
|
|
210
|
+
}
|
|
211
|
+
return val || "";
|
|
208
212
|
}
|
|
209
213
|
/** @internal */
|
|
210
214
|
toSpec() {
|
|
@@ -213,6 +217,13 @@ class SecretParam {
|
|
|
213
217
|
name: this.name,
|
|
214
218
|
};
|
|
215
219
|
}
|
|
220
|
+
/** Returns the secret's value at runtime. Throws an error if accessed during deployment. */
|
|
221
|
+
value() {
|
|
222
|
+
if (process.env.FUNCTIONS_CONTROL_API === "true") {
|
|
223
|
+
throw new Error(`Cannot access the value of secret "${this.name}" during function deployment. Secret values are only available at runtime.`);
|
|
224
|
+
}
|
|
225
|
+
return this.runtimeValue();
|
|
226
|
+
}
|
|
216
227
|
}
|
|
217
228
|
exports.SecretParam = SecretParam;
|
|
218
229
|
SecretParam.type = "secret";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Request, Response } from "express";
|
|
2
|
+
import { DeploymentOptions, FailurePolicy, Schedule } from "./function-configuration";
|
|
2
3
|
export { Request, Response };
|
|
3
4
|
import { ManifestEndpoint, ManifestRequiredAPI } from "../runtime/manifest";
|
|
4
5
|
export { Change } from "../common/change";
|
|
@@ -174,6 +175,37 @@ export interface Resource {
|
|
|
174
175
|
[tag: string]: string;
|
|
175
176
|
};
|
|
176
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* TriggerAnnotion is used internally by the firebase CLI to understand what
|
|
180
|
+
* type of Cloud Function to deploy.
|
|
181
|
+
*/
|
|
182
|
+
interface TriggerAnnotation {
|
|
183
|
+
availableMemoryMb?: number;
|
|
184
|
+
blockingTrigger?: {
|
|
185
|
+
eventType: string;
|
|
186
|
+
options?: Record<string, unknown>;
|
|
187
|
+
};
|
|
188
|
+
eventTrigger?: {
|
|
189
|
+
eventType: string;
|
|
190
|
+
resource: string;
|
|
191
|
+
service: string;
|
|
192
|
+
};
|
|
193
|
+
failurePolicy?: FailurePolicy;
|
|
194
|
+
httpsTrigger?: {
|
|
195
|
+
invoker?: string[];
|
|
196
|
+
};
|
|
197
|
+
labels?: {
|
|
198
|
+
[key: string]: string;
|
|
199
|
+
};
|
|
200
|
+
regions?: string[];
|
|
201
|
+
schedule?: Schedule;
|
|
202
|
+
timeout?: string;
|
|
203
|
+
vpcConnector?: string;
|
|
204
|
+
vpcConnectorEgressSettings?: string;
|
|
205
|
+
serviceAccountEmail?: string;
|
|
206
|
+
ingressSettings?: string;
|
|
207
|
+
secrets?: string[];
|
|
208
|
+
}
|
|
177
209
|
/**
|
|
178
210
|
* A Runnable has a `run` method which directly invokes the user-defined
|
|
179
211
|
* function - useful for unit testing.
|
|
@@ -195,6 +227,8 @@ export interface Runnable<T> {
|
|
|
195
227
|
export interface HttpsFunction {
|
|
196
228
|
(req: Request, resp: Response): void | Promise<void>;
|
|
197
229
|
/** @alpha */
|
|
230
|
+
__trigger: TriggerAnnotation;
|
|
231
|
+
/** @alpha */
|
|
198
232
|
__endpoint: ManifestEndpoint;
|
|
199
233
|
/** @alpha */
|
|
200
234
|
__requiredAPIs?: ManifestRequiredAPI[];
|
|
@@ -212,6 +246,8 @@ export interface BlockingFunction {
|
|
|
212
246
|
/** @public */
|
|
213
247
|
(req: Request, resp: Response): void | Promise<void>;
|
|
214
248
|
/** @alpha */
|
|
249
|
+
__trigger: TriggerAnnotation;
|
|
250
|
+
/** @alpha */
|
|
215
251
|
__endpoint: ManifestEndpoint;
|
|
216
252
|
/** @alpha */
|
|
217
253
|
__requiredAPIs?: ManifestRequiredAPI[];
|
|
@@ -226,7 +262,12 @@ export interface BlockingFunction {
|
|
|
226
262
|
export interface CloudFunction<T> extends Runnable<T> {
|
|
227
263
|
(input: any, context?: any): PromiseLike<any> | any;
|
|
228
264
|
/** @alpha */
|
|
265
|
+
__trigger: TriggerAnnotation;
|
|
266
|
+
/** @alpha */
|
|
229
267
|
__endpoint: ManifestEndpoint;
|
|
230
268
|
/** @alpha */
|
|
231
269
|
__requiredAPIs?: ManifestRequiredAPI[];
|
|
232
270
|
}
|
|
271
|
+
/** @hidden */
|
|
272
|
+
export declare function optionsToTrigger(options: DeploymentOptions): any;
|
|
273
|
+
export declare function optionsToEndpoint(options: DeploymentOptions): ManifestEndpoint;
|
|
@@ -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.optionsToEndpoint = exports.makeCloudFunction = exports.Change = void 0;
|
|
24
|
+
exports.optionsToEndpoint = exports.optionsToTrigger = exports.makeCloudFunction = exports.Change = void 0;
|
|
25
25
|
const logger_1 = require("../logger");
|
|
26
26
|
const function_configuration_1 = require("./function-configuration");
|
|
27
27
|
const encoding_1 = require("../common/encoding");
|
|
@@ -83,6 +83,25 @@ function makeCloudFunction({ contextOnlyHandler, dataConstructor = (raw) => raw.
|
|
|
83
83
|
}
|
|
84
84
|
return Promise.resolve(promise);
|
|
85
85
|
};
|
|
86
|
+
Object.defineProperty(cloudFunction, "__trigger", {
|
|
87
|
+
get: () => {
|
|
88
|
+
if (triggerResource() == null) {
|
|
89
|
+
return {};
|
|
90
|
+
}
|
|
91
|
+
const trigger = {
|
|
92
|
+
...optionsToTrigger(options),
|
|
93
|
+
eventTrigger: {
|
|
94
|
+
resource: triggerResource(),
|
|
95
|
+
eventType: legacyEventType || provider + "." + eventType,
|
|
96
|
+
service,
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
if (!!labels && Object.keys(labels).length) {
|
|
100
|
+
trigger.labels = { ...trigger.labels, ...labels };
|
|
101
|
+
}
|
|
102
|
+
return trigger;
|
|
103
|
+
},
|
|
104
|
+
});
|
|
86
105
|
Object.defineProperty(cloudFunction, "__endpoint", {
|
|
87
106
|
get: () => {
|
|
88
107
|
if (triggerResource() == null) {
|
|
@@ -171,7 +190,38 @@ function _detectAuthType(event) {
|
|
|
171
190
|
}
|
|
172
191
|
return "UNAUTHENTICATED";
|
|
173
192
|
}
|
|
174
|
-
/** @
|
|
193
|
+
/** @hidden */
|
|
194
|
+
function optionsToTrigger(options) {
|
|
195
|
+
const trigger = {};
|
|
196
|
+
(0, encoding_1.copyIfPresent)(trigger, options, "regions", "schedule", "minInstances", "maxInstances", "ingressSettings", "vpcConnectorEgressSettings", "vpcConnector", "labels", "secrets");
|
|
197
|
+
(0, encoding_1.convertIfPresent)(trigger, options, "failurePolicy", "failurePolicy", (policy) => {
|
|
198
|
+
if (policy === false) {
|
|
199
|
+
return undefined;
|
|
200
|
+
}
|
|
201
|
+
else if (policy === true) {
|
|
202
|
+
return function_configuration_1.DEFAULT_FAILURE_POLICY;
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
return policy;
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
(0, encoding_1.convertIfPresent)(trigger, options, "timeout", "timeoutSeconds", encoding_1.durationFromSeconds);
|
|
209
|
+
(0, encoding_1.convertIfPresent)(trigger, options, "availableMemoryMb", "memory", (mem) => {
|
|
210
|
+
const memoryLookup = {
|
|
211
|
+
"128MB": 128,
|
|
212
|
+
"256MB": 256,
|
|
213
|
+
"512MB": 512,
|
|
214
|
+
"1GB": 1024,
|
|
215
|
+
"2GB": 2048,
|
|
216
|
+
"4GB": 4096,
|
|
217
|
+
"8GB": 8192,
|
|
218
|
+
};
|
|
219
|
+
return memoryLookup[mem];
|
|
220
|
+
});
|
|
221
|
+
(0, encoding_1.convertIfPresent)(trigger, options, "serviceAccountEmail", "serviceAccount", encoding_1.serviceAccountFromShorthand);
|
|
222
|
+
return trigger;
|
|
223
|
+
}
|
|
224
|
+
exports.optionsToTrigger = optionsToTrigger;
|
|
175
225
|
function optionsToEndpoint(options) {
|
|
176
226
|
const endpoint = {};
|
|
177
227
|
(0, encoding_1.copyIfPresent)(endpoint, options, "minInstances", "maxInstances", "ingressSettings", "labels", "timeoutSeconds");
|
|
@@ -107,6 +107,7 @@ export interface FailurePolicy {
|
|
|
107
107
|
*/
|
|
108
108
|
retry: Record<string, never>;
|
|
109
109
|
}
|
|
110
|
+
export declare const DEFAULT_FAILURE_POLICY: FailurePolicy;
|
|
110
111
|
export declare const MAX_NUMBER_USER_LABELS = 58;
|
|
111
112
|
/**
|
|
112
113
|
* Configuration options for a function that applicable at runtime.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MAX_NUMBER_USER_LABELS = exports.INGRESS_SETTINGS_OPTIONS = exports.VPC_EGRESS_SETTINGS_OPTIONS = exports.VALID_MEMORY_OPTIONS = exports.MAX_TIMEOUT_SECONDS = exports.MIN_TIMEOUT_SECONDS = exports.SUPPORTED_REGIONS = exports.RESET_VALUE = void 0;
|
|
3
|
+
exports.MAX_NUMBER_USER_LABELS = exports.DEFAULT_FAILURE_POLICY = exports.INGRESS_SETTINGS_OPTIONS = exports.VPC_EGRESS_SETTINGS_OPTIONS = exports.VALID_MEMORY_OPTIONS = exports.MAX_TIMEOUT_SECONDS = exports.MIN_TIMEOUT_SECONDS = exports.SUPPORTED_REGIONS = exports.RESET_VALUE = void 0;
|
|
4
4
|
var options_1 = require("../common/options");
|
|
5
5
|
Object.defineProperty(exports, "RESET_VALUE", { enumerable: true, get: function () { return options_1.RESET_VALUE; } });
|
|
6
6
|
/**
|
|
@@ -67,4 +67,7 @@ exports.INGRESS_SETTINGS_OPTIONS = [
|
|
|
67
67
|
"ALLOW_INTERNAL_ONLY",
|
|
68
68
|
"ALLOW_INTERNAL_AND_GCLB",
|
|
69
69
|
];
|
|
70
|
+
exports.DEFAULT_FAILURE_POLICY = {
|
|
71
|
+
retry: {},
|
|
72
|
+
};
|
|
70
73
|
exports.MAX_NUMBER_USER_LABELS = 58;
|
package/lib/v1/providers/auth.js
CHANGED
|
@@ -131,6 +131,18 @@ class UserBuilder {
|
|
|
131
131
|
const wrappedHandler = (user, context) => handler(user, context);
|
|
132
132
|
const func = (0, identity_1.wrapHandler)(eventType, wrappedHandler);
|
|
133
133
|
const legacyEventType = `providers/cloud.auth/eventTypes/user.${eventType}`;
|
|
134
|
+
func.__trigger = {
|
|
135
|
+
labels: {},
|
|
136
|
+
...(0, cloud_functions_1.optionsToTrigger)(this.options),
|
|
137
|
+
blockingTrigger: {
|
|
138
|
+
eventType: legacyEventType,
|
|
139
|
+
options: {
|
|
140
|
+
accessToken,
|
|
141
|
+
idToken,
|
|
142
|
+
refreshToken,
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
};
|
|
134
146
|
func.__endpoint = {
|
|
135
147
|
platform: "gcfv1",
|
|
136
148
|
labels: {},
|
|
@@ -50,6 +50,11 @@ function _onRequestWithOptions(handler, options) {
|
|
|
50
50
|
const cloudFunction = (req, res) => {
|
|
51
51
|
return handler(req, res);
|
|
52
52
|
};
|
|
53
|
+
cloudFunction.__trigger = {
|
|
54
|
+
...(0, cloud_functions_1.optionsToTrigger)(options),
|
|
55
|
+
httpsTrigger: {},
|
|
56
|
+
};
|
|
57
|
+
(0, encoding_1.convertIfPresent)(cloudFunction.__trigger.httpsTrigger, options, "invoker", "invoker", encoding_1.convertInvoker);
|
|
53
58
|
// TODO parse the options
|
|
54
59
|
cloudFunction.__endpoint = {
|
|
55
60
|
platform: "gcfv1",
|
|
@@ -71,6 +76,12 @@ function _onCallWithOptions(handler, options) {
|
|
|
71
76
|
enforceAppCheck: options.enforceAppCheck,
|
|
72
77
|
cors: { origin: true, methods: "POST" },
|
|
73
78
|
}, fixedLen);
|
|
79
|
+
func.__trigger = {
|
|
80
|
+
labels: {},
|
|
81
|
+
...(0, cloud_functions_1.optionsToTrigger)(options),
|
|
82
|
+
httpsTrigger: {},
|
|
83
|
+
};
|
|
84
|
+
func.__trigger.labels["deployment-callable"] = "true";
|
|
74
85
|
func.__endpoint = {
|
|
75
86
|
platform: "gcfv1",
|
|
76
87
|
labels: {},
|
|
@@ -25,6 +25,8 @@ export interface TaskQueueOptions {
|
|
|
25
25
|
export interface TaskQueueFunction {
|
|
26
26
|
(req: Request, res: express.Response): Promise<void>;
|
|
27
27
|
/** @alpha */
|
|
28
|
+
__trigger: unknown;
|
|
29
|
+
/** @alpha */
|
|
28
30
|
__endpoint: ManifestEndpoint;
|
|
29
31
|
/** @alpha */
|
|
30
32
|
__requiredAPIs?: ManifestRequiredAPI[];
|
|
@@ -46,6 +46,13 @@ class TaskQueueBuilder {
|
|
|
46
46
|
// in another handler to avoid accidentally triggering the v2 API
|
|
47
47
|
const fixedLen = (data, context) => handler(data, context);
|
|
48
48
|
const func = (0, tasks_1.onDispatchHandler)(fixedLen);
|
|
49
|
+
func.__trigger = {
|
|
50
|
+
...(0, cloud_functions_1.optionsToTrigger)(this.depOpts || {}),
|
|
51
|
+
taskQueueTrigger: {},
|
|
52
|
+
};
|
|
53
|
+
(0, encoding_1.copyIfPresent)(func.__trigger.taskQueueTrigger, this.tqOpts, "retryConfig");
|
|
54
|
+
(0, encoding_1.copyIfPresent)(func.__trigger.taskQueueTrigger, this.tqOpts, "rateLimits");
|
|
55
|
+
(0, encoding_1.convertIfPresent)(func.__trigger.taskQueueTrigger, this.tqOpts, "invoker", "invoker", encoding_1.convertInvoker);
|
|
49
56
|
func.__endpoint = {
|
|
50
57
|
platform: "gcfv1",
|
|
51
58
|
...(0, manifest_1.initV1Endpoint)(this.depOpts),
|
package/lib/v2/core.d.ts
CHANGED
|
@@ -37,6 +37,8 @@ export interface CloudEvent<T> {
|
|
|
37
37
|
export interface CloudFunction<EventType extends CloudEvent<unknown>> {
|
|
38
38
|
(raw: CloudEvent<unknown>): any | Promise<any>;
|
|
39
39
|
/** @alpha */
|
|
40
|
+
__trigger?: unknown;
|
|
41
|
+
/** @alpha */
|
|
40
42
|
__endpoint: ManifestEndpoint;
|
|
41
43
|
/**
|
|
42
44
|
* The callback passed to the CloudFunction constructor.
|
package/lib/v2/options.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.__getSpec = exports.optionsToEndpoint = exports.getGlobalOptions = exports.setGlobalOptions = exports.RESET_VALUE = void 0;
|
|
24
|
+
exports.__getSpec = exports.optionsToEndpoint = exports.optionsToTriggerAnnotations = exports.getGlobalOptions = exports.setGlobalOptions = exports.RESET_VALUE = void 0;
|
|
25
25
|
/**
|
|
26
26
|
* Options to configure cloud functions.
|
|
27
27
|
* @packageDocumentation
|
|
@@ -65,6 +65,30 @@ function getGlobalOptions() {
|
|
|
65
65
|
return globalOptions || {};
|
|
66
66
|
}
|
|
67
67
|
exports.getGlobalOptions = getGlobalOptions;
|
|
68
|
+
/**
|
|
69
|
+
* Apply GlobalOptions to trigger definitions.
|
|
70
|
+
* @internal
|
|
71
|
+
*/
|
|
72
|
+
function optionsToTriggerAnnotations(opts) {
|
|
73
|
+
const annotation = {};
|
|
74
|
+
(0, encoding_1.copyIfPresent)(annotation, opts, "concurrency", "minInstances", "maxInstances", "ingressSettings", "labels", "vpcConnector", "vpcConnectorEgressSettings", "secrets");
|
|
75
|
+
(0, encoding_1.convertIfPresent)(annotation, opts, "availableMemoryMb", "memory", (mem) => {
|
|
76
|
+
return MemoryOptionToMB[mem];
|
|
77
|
+
});
|
|
78
|
+
(0, encoding_1.convertIfPresent)(annotation, opts, "regions", "region", (region) => {
|
|
79
|
+
if (typeof region === "string") {
|
|
80
|
+
return [region];
|
|
81
|
+
}
|
|
82
|
+
return region;
|
|
83
|
+
});
|
|
84
|
+
(0, encoding_1.convertIfPresent)(annotation, opts, "serviceAccountEmail", "serviceAccount", encoding_1.serviceAccountFromShorthand);
|
|
85
|
+
(0, encoding_1.convertIfPresent)(annotation, opts, "timeout", "timeoutSeconds", encoding_1.durationFromSeconds);
|
|
86
|
+
(0, encoding_1.convertIfPresent)(annotation, opts, "failurePolicy", "retry", (retry) => {
|
|
87
|
+
return retry ? { retry: true } : null;
|
|
88
|
+
});
|
|
89
|
+
return annotation;
|
|
90
|
+
}
|
|
91
|
+
exports.optionsToTriggerAnnotations = optionsToTriggerAnnotations;
|
|
68
92
|
/**
|
|
69
93
|
* Apply GlobalOptions to endpoint manifest.
|
|
70
94
|
* @internal
|
|
@@ -26,8 +26,6 @@ export interface NewTesterDevicePayload {
|
|
|
26
26
|
/**
|
|
27
27
|
* The internal payload object for receiving in-app feedback from a tester.
|
|
28
28
|
* Payload is wrapped inside a `FirebaseAlertData` object.
|
|
29
|
-
*
|
|
30
|
-
* @alpha
|
|
31
29
|
*/
|
|
32
30
|
export interface InAppFeedbackPayload {
|
|
33
31
|
["@type"]: "type.googleapis.com/google.events.firebase.firebasealerts.v1.AppDistroInAppFeedbackPayload";
|
|
@@ -166,8 +164,6 @@ export declare function onNewTesterIosDevicePublished(opts: AppDistributionOptio
|
|
|
166
164
|
* Declares a function that can handle receiving new in-app feedback from a tester.
|
|
167
165
|
* @param handler - Event handler which is run every time new feedback is received.
|
|
168
166
|
* @returns A function that you can export and deploy.
|
|
169
|
-
*
|
|
170
|
-
* @alpha
|
|
171
167
|
*/
|
|
172
168
|
export declare function onInAppFeedbackPublished(handler: (event: AppDistributionEvent<InAppFeedbackPayload>) => any | Promise<any>): CloudFunction<AppDistributionEvent<InAppFeedbackPayload>>;
|
|
173
169
|
/**
|
|
@@ -175,8 +171,6 @@ export declare function onInAppFeedbackPublished(handler: (event: AppDistributio
|
|
|
175
171
|
* @param appId - A specific application the handler will trigger on.
|
|
176
172
|
* @param handler - Event handler which is run every time new feedback is received.
|
|
177
173
|
* @returns A function that you can export and deploy.
|
|
178
|
-
*
|
|
179
|
-
* @alpha
|
|
180
174
|
*/
|
|
181
175
|
export declare function onInAppFeedbackPublished(appId: string, handler: (event: AppDistributionEvent<InAppFeedbackPayload>) => any | Promise<any>): CloudFunction<AppDistributionEvent<InAppFeedbackPayload>>;
|
|
182
176
|
/**
|
|
@@ -184,7 +178,5 @@ export declare function onInAppFeedbackPublished(appId: string, handler: (event:
|
|
|
184
178
|
* @param opts - Options that can be set on the function.
|
|
185
179
|
* @param handler - Event handler which is run every time new feedback is received.
|
|
186
180
|
* @returns A function that you can export and deploy.
|
|
187
|
-
*
|
|
188
|
-
* @alpha
|
|
189
181
|
*/
|
|
190
182
|
export declare function onInAppFeedbackPublished(opts: AppDistributionOptions, handler: (event: AppDistributionEvent<InAppFeedbackPayload>) => any | Promise<any>): CloudFunction<AppDistributionEvent<InAppFeedbackPayload>>;
|
|
@@ -53,8 +53,6 @@ exports.onNewTesterIosDevicePublished = onNewTesterIosDevicePublished;
|
|
|
53
53
|
* @param appIdOrOptsOrHandler - A specific application, options, or an event-handling function.
|
|
54
54
|
* @param handler - Event handler which is run every time new feedback is received.
|
|
55
55
|
* @returns A function that you can export and deploy.
|
|
56
|
-
*
|
|
57
|
-
* @alpha
|
|
58
56
|
*/
|
|
59
57
|
function onInAppFeedbackPublished(appIdOrOptsOrHandler, handler) {
|
|
60
58
|
if (typeof appIdOrOptsOrHandler === "function") {
|
|
@@ -114,6 +114,8 @@ export declare type HttpsFunction = ((
|
|
|
114
114
|
req: Request,
|
|
115
115
|
/** An Express response object, for this function to respond to callers. */
|
|
116
116
|
res: express.Response) => void | Promise<void>) & {
|
|
117
|
+
/** @alpha */
|
|
118
|
+
__trigger?: unknown;
|
|
117
119
|
/** @alpha */
|
|
118
120
|
__endpoint: ManifestEndpoint;
|
|
119
121
|
};
|
|
@@ -56,6 +56,28 @@ function onRequest(optsOrHandler, handler) {
|
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
58
|
handler = (0, trace_1.wrapTraceContext)(handler);
|
|
59
|
+
Object.defineProperty(handler, "__trigger", {
|
|
60
|
+
get: () => {
|
|
61
|
+
const baseOpts = options.optionsToTriggerAnnotations(options.getGlobalOptions());
|
|
62
|
+
// global options calls region a scalar and https allows it to be an array,
|
|
63
|
+
// but optionsToTriggerAnnotations handles both cases.
|
|
64
|
+
const specificOpts = options.optionsToTriggerAnnotations(opts);
|
|
65
|
+
const trigger = {
|
|
66
|
+
platform: "gcfv2",
|
|
67
|
+
...baseOpts,
|
|
68
|
+
...specificOpts,
|
|
69
|
+
labels: {
|
|
70
|
+
...baseOpts === null || baseOpts === void 0 ? void 0 : baseOpts.labels,
|
|
71
|
+
...specificOpts === null || specificOpts === void 0 ? void 0 : specificOpts.labels,
|
|
72
|
+
},
|
|
73
|
+
httpsTrigger: {
|
|
74
|
+
allowInsecure: false,
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
(0, encoding_1.convertIfPresent)(trigger.httpsTrigger, opts, "invoker", "invoker", encoding_1.convertInvoker);
|
|
78
|
+
return trigger;
|
|
79
|
+
},
|
|
80
|
+
});
|
|
59
81
|
const baseOpts = options.optionsToEndpoint(options.getGlobalOptions());
|
|
60
82
|
// global options calls region a scalar and https allows it to be an array,
|
|
61
83
|
// but optionsToTriggerAnnotations handles both cases.
|
|
@@ -94,6 +116,27 @@ function onCall(optsOrHandler, handler) {
|
|
|
94
116
|
cors: { origin, methods: "POST" },
|
|
95
117
|
enforceAppCheck: (_a = opts.enforceAppCheck) !== null && _a !== void 0 ? _a : options.getGlobalOptions().enforceAppCheck,
|
|
96
118
|
}, fixedLen);
|
|
119
|
+
Object.defineProperty(func, "__trigger", {
|
|
120
|
+
get: () => {
|
|
121
|
+
const baseOpts = options.optionsToTriggerAnnotations(options.getGlobalOptions());
|
|
122
|
+
// global options calls region a scalar and https allows it to be an array,
|
|
123
|
+
// but optionsToTriggerAnnotations handles both cases.
|
|
124
|
+
const specificOpts = options.optionsToTriggerAnnotations(opts);
|
|
125
|
+
return {
|
|
126
|
+
platform: "gcfv2",
|
|
127
|
+
...baseOpts,
|
|
128
|
+
...specificOpts,
|
|
129
|
+
labels: {
|
|
130
|
+
...baseOpts === null || baseOpts === void 0 ? void 0 : baseOpts.labels,
|
|
131
|
+
...specificOpts === null || specificOpts === void 0 ? void 0 : specificOpts.labels,
|
|
132
|
+
"deployment-callable": "true",
|
|
133
|
+
},
|
|
134
|
+
httpsTrigger: {
|
|
135
|
+
allowInsecure: false,
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
},
|
|
139
|
+
});
|
|
97
140
|
const baseOpts = options.optionsToEndpoint(options.getGlobalOptions());
|
|
98
141
|
// global options calls region a scalar and https allows it to be an array,
|
|
99
142
|
// but optionsToEndpoint handles both cases.
|
|
@@ -128,6 +128,25 @@ function onMessagePublished(topicOrOptions, handler) {
|
|
|
128
128
|
return (0, trace_1.wrapTraceContext)(handler)(raw);
|
|
129
129
|
};
|
|
130
130
|
func.run = handler;
|
|
131
|
+
Object.defineProperty(func, "__trigger", {
|
|
132
|
+
get: () => {
|
|
133
|
+
const baseOpts = options.optionsToTriggerAnnotations(options.getGlobalOptions());
|
|
134
|
+
const specificOpts = options.optionsToTriggerAnnotations(opts);
|
|
135
|
+
return {
|
|
136
|
+
platform: "gcfv2",
|
|
137
|
+
...baseOpts,
|
|
138
|
+
...specificOpts,
|
|
139
|
+
labels: {
|
|
140
|
+
...baseOpts === null || baseOpts === void 0 ? void 0 : baseOpts.labels,
|
|
141
|
+
...specificOpts === null || specificOpts === void 0 ? void 0 : specificOpts.labels,
|
|
142
|
+
},
|
|
143
|
+
eventTrigger: {
|
|
144
|
+
eventType: "google.cloud.pubsub.topic.v1.messagePublished",
|
|
145
|
+
resource: `projects/${process.env.GCLOUD_PROJECT}/topics/${topic}`,
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
},
|
|
149
|
+
});
|
|
131
150
|
const baseOpts = options.optionsToEndpoint(options.getGlobalOptions());
|
|
132
151
|
const specificOpts = options.optionsToEndpoint(opts);
|
|
133
152
|
const endpoint = {
|
|
@@ -105,6 +105,25 @@ function onOperation(eventType, bucketOrOptsOrHandler, handler) {
|
|
|
105
105
|
return (0, trace_1.wrapTraceContext)(handler)(raw);
|
|
106
106
|
};
|
|
107
107
|
func.run = handler;
|
|
108
|
+
Object.defineProperty(func, "__trigger", {
|
|
109
|
+
get: () => {
|
|
110
|
+
const baseOpts = options.optionsToTriggerAnnotations(options.getGlobalOptions());
|
|
111
|
+
const specificOpts = options.optionsToTriggerAnnotations(opts);
|
|
112
|
+
return {
|
|
113
|
+
platform: "gcfv2",
|
|
114
|
+
...baseOpts,
|
|
115
|
+
...specificOpts,
|
|
116
|
+
labels: {
|
|
117
|
+
...baseOpts === null || baseOpts === void 0 ? void 0 : baseOpts.labels,
|
|
118
|
+
...specificOpts === null || specificOpts === void 0 ? void 0 : specificOpts.labels,
|
|
119
|
+
},
|
|
120
|
+
eventTrigger: {
|
|
121
|
+
eventType,
|
|
122
|
+
resource: bucket, // TODO(colerogers): replace with 'bucket,' eventually
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
},
|
|
126
|
+
});
|
|
108
127
|
// TypeScript doesn't recognize defineProperty as adding a property and complains
|
|
109
128
|
// that __endpoint doesn't exist. We can either cast to any and lose all type safety
|
|
110
129
|
// or we can just assign a meaningless value before calling defineProperty.
|
|
@@ -44,8 +44,28 @@ function onTaskDispatched(optsOrHandler, handler) {
|
|
|
44
44
|
// fix the length to prevent api versions from being mismatched.
|
|
45
45
|
const fixedLen = (req) => handler(req);
|
|
46
46
|
const func = (0, trace_1.wrapTraceContext)((0, tasks_1.onDispatchHandler)(fixedLen));
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
Object.defineProperty(func, "__trigger", {
|
|
48
|
+
get: () => {
|
|
49
|
+
const baseOpts = options.optionsToTriggerAnnotations(options.getGlobalOptions());
|
|
50
|
+
// global options calls region a scalar and https allows it to be an array,
|
|
51
|
+
// but optionsToTriggerAnnotations handles both cases.
|
|
52
|
+
const specificOpts = options.optionsToTriggerAnnotations(opts);
|
|
53
|
+
const taskQueueTrigger = {};
|
|
54
|
+
(0, encoding_1.copyIfPresent)(taskQueueTrigger, opts, "retryConfig", "rateLimits");
|
|
55
|
+
(0, encoding_1.convertIfPresent)(taskQueueTrigger, opts, "invoker", "invoker", encoding_1.convertInvoker);
|
|
56
|
+
return {
|
|
57
|
+
platform: "gcfv2",
|
|
58
|
+
...baseOpts,
|
|
59
|
+
...specificOpts,
|
|
60
|
+
labels: {
|
|
61
|
+
...baseOpts === null || baseOpts === void 0 ? void 0 : baseOpts.labels,
|
|
62
|
+
...specificOpts === null || specificOpts === void 0 ? void 0 : specificOpts.labels,
|
|
63
|
+
},
|
|
64
|
+
taskQueueTrigger,
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
const baseOpts = options.optionsToEndpoint(options.getGlobalOptions());
|
|
49
69
|
// global options calls region a scalar and https allows it to be an array,
|
|
50
70
|
// but optionsToManifestEndpoint handles both cases.
|
|
51
71
|
const specificOpts = options.optionsToEndpoint(opts);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "firebase-functions",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"description": "Firebase SDK for Cloud Functions",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"firebase",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"./v1/auth": "./lib/v1/providers/auth.js",
|
|
37
37
|
"./v1/database": "./lib/v1/providers/database.js",
|
|
38
38
|
"./v1/firestore": "./lib/v1/providers/firestore.js",
|
|
39
|
+
"./v1/https": "./lib/v1/providers/https.js",
|
|
39
40
|
"./v1/pubsub": "./lib/v1/providers/pubsub.js",
|
|
40
41
|
"./v1/remoteConfig": "./lib/v1/providers/remoteConfig.js",
|
|
41
42
|
"./v1/storage": "./lib/v1/providers/storage.js",
|
|
@@ -75,31 +76,34 @@
|
|
|
75
76
|
"lib/v1"
|
|
76
77
|
],
|
|
77
78
|
"v1/analytics": [
|
|
78
|
-
"
|
|
79
|
+
"lib/v1/providers/analytics"
|
|
79
80
|
],
|
|
80
81
|
"v1/auth": [
|
|
81
|
-
"
|
|
82
|
+
"lib/v1/providers/auth"
|
|
82
83
|
],
|
|
83
84
|
"v1/database": [
|
|
84
|
-
"
|
|
85
|
+
"lib/v1/privders/database"
|
|
85
86
|
],
|
|
86
87
|
"v1/firestore": [
|
|
87
|
-
"
|
|
88
|
+
"lib/v1/providers/firestore"
|
|
89
|
+
],
|
|
90
|
+
"v1/https": [
|
|
91
|
+
"./lib/v1/providers/https"
|
|
88
92
|
],
|
|
89
93
|
"v1/pubsub": [
|
|
90
|
-
"
|
|
94
|
+
"lib/v1/providers/pubsub"
|
|
91
95
|
],
|
|
92
|
-
"
|
|
93
|
-
"
|
|
96
|
+
"v1/remoteConfig": [
|
|
97
|
+
"lib/v1/providers/remoteConfig"
|
|
94
98
|
],
|
|
95
|
-
"
|
|
96
|
-
"
|
|
99
|
+
"v1/storage": [
|
|
100
|
+
"lib/v1/providers/storage"
|
|
97
101
|
],
|
|
98
|
-
"
|
|
99
|
-
"
|
|
102
|
+
"v1/tasks": [
|
|
103
|
+
"lib/v1/providers/tasks"
|
|
100
104
|
],
|
|
101
|
-
"
|
|
102
|
-
"
|
|
105
|
+
"v1/testLab": [
|
|
106
|
+
"lib/v1/providers/testLab"
|
|
103
107
|
],
|
|
104
108
|
"v2": [
|
|
105
109
|
"lib/v2"
|