firebase-functions 3.20.1 → 3.21.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/apps.js +1 -1
- package/lib/bin/firebase-functions.js +22 -1
- package/lib/cloud-functions.d.ts +56 -35
- package/lib/cloud-functions.js +12 -12
- package/lib/common/encoding.js +21 -1
- package/lib/common/providers/https.d.ts +37 -17
- package/lib/common/providers/https.js +11 -6
- package/lib/common/providers/identity.d.ts +11 -1
- package/lib/common/providers/identity.js +59 -207
- package/lib/common/providers/tasks.d.ts +9 -0
- package/lib/function-builder.d.ts +2 -2
- package/lib/function-builder.js +1 -1
- package/lib/handler-builder.js +3 -3
- package/lib/index.js +6 -2
- package/lib/logger/common.js +21 -0
- package/lib/logger/compat.js +22 -1
- package/lib/logger/index.d.ts +14 -6
- package/lib/logger/index.js +33 -6
- package/lib/providers/analytics.js +1 -1
- package/lib/providers/auth.d.ts +44 -10
- package/lib/providers/auth.js +80 -14
- package/lib/providers/database.js +11 -11
- package/lib/providers/firestore.js +7 -7
- package/lib/providers/https.js +7 -7
- package/lib/providers/pubsub.d.ts +6 -6
- package/lib/providers/pubsub.js +8 -8
- package/lib/providers/remoteConfig.js +1 -1
- package/lib/providers/storage.js +2 -2
- package/lib/providers/tasks.d.ts +30 -15
- package/lib/providers/tasks.js +19 -12
- package/lib/providers/testLab.js +1 -1
- package/lib/runtime/loader.js +9 -7
- package/lib/runtime/manifest.d.ts +5 -0
- package/lib/setup.js +3 -3
- package/lib/v2/core.d.ts +24 -20
- package/lib/v2/index.d.ts +11 -4
- package/lib/v2/index.js +12 -5
- package/lib/v2/options.d.ts +25 -35
- package/lib/v2/options.js +28 -88
- package/lib/v2/params/index.d.ts +4 -1
- package/lib/v2/params/index.js +25 -1
- package/lib/v2/params/types.js +21 -0
- package/lib/v2/providers/alerts/alerts.d.ts +107 -8
- package/lib/v2/providers/alerts/alerts.js +23 -7
- package/lib/v2/providers/alerts/appDistribution.d.ts +112 -12
- package/lib/v2/providers/alerts/appDistribution.js +29 -2
- package/lib/v2/providers/alerts/billing.d.ts +39 -12
- package/lib/v2/providers/alerts/billing.js +38 -1
- package/lib/v2/providers/alerts/crashlytics.d.ts +255 -47
- package/lib/v2/providers/alerts/crashlytics.js +63 -2
- package/lib/v2/providers/alerts/index.d.ts +6 -0
- package/lib/v2/providers/alerts/index.js +32 -1
- package/lib/v2/providers/eventarc.d.ts +90 -6
- package/lib/v2/providers/eventarc.js +7 -3
- package/lib/v2/providers/https.d.ts +128 -4
- package/lib/v2/providers/https.js +18 -14
- package/lib/v2/providers/identity.d.ts +126 -0
- package/lib/v2/providers/identity.js +104 -0
- package/lib/v2/providers/pubsub.d.ts +125 -8
- package/lib/v2/providers/pubsub.js +60 -7
- package/lib/v2/providers/storage.d.ts +209 -17
- package/lib/v2/providers/storage.js +57 -13
- package/lib/v2/providers/tasks.d.ts +107 -7
- package/lib/v2/providers/tasks.js +11 -8
- package/package.json +18 -3
|
@@ -1,14 +1,64 @@
|
|
|
1
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.
|
|
2
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
24
|
exports.onMessagePublished = exports.Message = void 0;
|
|
4
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Cloud functions to handle events from Google Cloud Pub/Sub.
|
|
27
|
+
* @packageDocumentation
|
|
28
|
+
*/
|
|
5
29
|
const encoding_1 = require("../../common/encoding");
|
|
30
|
+
const options = require("../options");
|
|
31
|
+
/**
|
|
32
|
+
* Google Cloud Pub/Sub is a globally distributed message bus that automatically scales as you need it.
|
|
33
|
+
* You can create a function ({@link onMessagePublished}) that handles pub/sub events by using functions.pubsub.
|
|
34
|
+
*
|
|
35
|
+
* This function triggers whenever a new pub/sub message is sent to a specific topic.
|
|
36
|
+
* You must specify the Pub/Sub topic name that you want to trigger your function, and set the event within the
|
|
37
|
+
* onPublish() event handler.
|
|
38
|
+
*
|
|
39
|
+
* PubSub Topic:
|
|
40
|
+
* <ul>
|
|
41
|
+
* <li>A resource that you can publish messages to and then consume those messages via subscriptions.
|
|
42
|
+
* <li>An isolated data stream for pub/sub messages.
|
|
43
|
+
* <li>Messages are published to a topic.
|
|
44
|
+
* <li>Messages are listened to via a subscription.
|
|
45
|
+
* <li>Each subscription listens to the messages published to exactly one topic.
|
|
46
|
+
*
|
|
47
|
+
* Subscriptions - Resource that listens to the messages published by exactly one topic.
|
|
48
|
+
*
|
|
49
|
+
* [More info here](https://firebase.google.com/docs/functions/pubsub-events)
|
|
50
|
+
*/
|
|
6
51
|
/**
|
|
7
52
|
* Interface representing a Google Cloud Pub/Sub message.
|
|
8
53
|
*
|
|
9
|
-
* @param data Payload of a Pub/Sub message.
|
|
54
|
+
* @param data - Payload of a Pub/Sub message.
|
|
55
|
+
* @typeParam T - Type representing `Message.data`'s JSON format
|
|
10
56
|
*/
|
|
11
57
|
class Message {
|
|
58
|
+
/**
|
|
59
|
+
* @hidden
|
|
60
|
+
* @alpha
|
|
61
|
+
*/
|
|
12
62
|
constructor(data) {
|
|
13
63
|
this.messageId = data.messageId;
|
|
14
64
|
this.data = data.data;
|
|
@@ -34,7 +84,7 @@ class Message {
|
|
|
34
84
|
/**
|
|
35
85
|
* Returns a JSON-serializable representation of this object.
|
|
36
86
|
*
|
|
37
|
-
* @
|
|
87
|
+
* @returns A JSON-serializable representation of this object.
|
|
38
88
|
*/
|
|
39
89
|
toJSON() {
|
|
40
90
|
const json = {
|
|
@@ -52,6 +102,12 @@ class Message {
|
|
|
52
102
|
}
|
|
53
103
|
}
|
|
54
104
|
exports.Message = Message;
|
|
105
|
+
/**
|
|
106
|
+
* Handle a message being published to a Pub/Sub topic.
|
|
107
|
+
* @param topicOrOptions - A string representing the PubSub topic or an option (which contains the topic)
|
|
108
|
+
* @param handler - runs every time a Cloud Pub/Sub message is published
|
|
109
|
+
* @typeParam T - Type representing `Message.data`'s JSON format
|
|
110
|
+
*/
|
|
55
111
|
function onMessagePublished(topicOrOptions, handler) {
|
|
56
112
|
let topic;
|
|
57
113
|
let opts;
|
|
@@ -75,9 +131,6 @@ function onMessagePublished(topicOrOptions, handler) {
|
|
|
75
131
|
const baseOpts = options.optionsToTriggerAnnotations(options.getGlobalOptions());
|
|
76
132
|
const specificOpts = options.optionsToTriggerAnnotations(opts);
|
|
77
133
|
return {
|
|
78
|
-
// TODO(inlined): Remove "apiVersion" once the CLI has migrated to
|
|
79
|
-
// "platform"
|
|
80
|
-
apiVersion: 2,
|
|
81
134
|
platform: 'gcfv2',
|
|
82
135
|
...baseOpts,
|
|
83
136
|
...specificOpts,
|
|
@@ -108,7 +161,7 @@ function onMessagePublished(topicOrOptions, handler) {
|
|
|
108
161
|
retry: false,
|
|
109
162
|
},
|
|
110
163
|
};
|
|
111
|
-
encoding_1.copyIfPresent(endpoint.eventTrigger, opts, 'retry', 'retry');
|
|
164
|
+
(0, encoding_1.copyIfPresent)(endpoint.eventTrigger, opts, 'retry', 'retry');
|
|
112
165
|
func.__endpoint = endpoint;
|
|
113
166
|
return func;
|
|
114
167
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import * as options from '../options';
|
|
2
1
|
import { CloudEvent, CloudFunction } from '../core';
|
|
2
|
+
import * as options from '../options';
|
|
3
3
|
/**
|
|
4
4
|
* An object within Google Cloud Storage.
|
|
5
5
|
* Ref: https://github.com/googleapis/google-cloudevents-nodejs/blob/main/cloud/storage/v1/StorageObjectData.ts
|
|
@@ -148,23 +148,215 @@ export interface CustomerEncryption {
|
|
|
148
148
|
*/
|
|
149
149
|
keySha256?: string;
|
|
150
150
|
}
|
|
151
|
+
/** A CloudEvent that contains StorageObjectData */
|
|
152
|
+
export interface StorageEvent extends CloudEvent<StorageObjectData> {
|
|
153
|
+
/** The name of the bucket containing this object. */
|
|
154
|
+
bucket: string;
|
|
155
|
+
}
|
|
151
156
|
/** StorageOptions extend EventHandlerOptions with a bucket name */
|
|
152
157
|
export interface StorageOptions extends options.EventHandlerOptions {
|
|
158
|
+
/** The name of the bucket containing this object. */
|
|
153
159
|
bucket?: string;
|
|
160
|
+
/**
|
|
161
|
+
* Region where functions should be deployed.
|
|
162
|
+
*/
|
|
163
|
+
region?: options.SupportedRegion | string;
|
|
164
|
+
/**
|
|
165
|
+
* Amount of memory to allocate to a function.
|
|
166
|
+
* A value of null restores the defaults of 256MB.
|
|
167
|
+
*/
|
|
168
|
+
memory?: options.MemoryOption | null;
|
|
169
|
+
/**
|
|
170
|
+
* Timeout for the function in sections, possible values are 0 to 540.
|
|
171
|
+
* HTTPS functions can specify a higher timeout.
|
|
172
|
+
* A value of null restores the default of 60s
|
|
173
|
+
* The minimum timeout for a gen 2 function is 1s. The maximum timeout for a
|
|
174
|
+
* function depends on the type of function: Event handling functions have a
|
|
175
|
+
* maximum timeout of 540s (9 minutes). HTTPS and callable functions have a
|
|
176
|
+
* maximum timeout of 36,00s (1 hour). Task queue functions have a maximum
|
|
177
|
+
* timeout of 1,800s (30 minutes)
|
|
178
|
+
*/
|
|
179
|
+
timeoutSeconds?: number | null;
|
|
180
|
+
/**
|
|
181
|
+
* Min number of actual instances to be running at a given time.
|
|
182
|
+
* Instances will be billed for memory allocation and 10% of CPU allocation
|
|
183
|
+
* while idle.
|
|
184
|
+
* A value of null restores the default min instances.
|
|
185
|
+
*/
|
|
186
|
+
minInstances?: number | null;
|
|
187
|
+
/**
|
|
188
|
+
* Max number of instances to be running in parallel.
|
|
189
|
+
* A value of null restores the default max instances.
|
|
190
|
+
*/
|
|
191
|
+
maxInstances?: number | null;
|
|
192
|
+
/**
|
|
193
|
+
* Number of requests a function can serve at once.
|
|
194
|
+
* Can only be applied to functions running on Cloud Functions v2.
|
|
195
|
+
* A value of null restores the default concurrency (80 when CPU >= 1, 1 otherwise).
|
|
196
|
+
* Concurrency cannot be set to any value other than 1 if `cpu` is less than 1.
|
|
197
|
+
* The maximum value for concurrency is 1,000.
|
|
198
|
+
*/
|
|
199
|
+
concurrency?: number | null;
|
|
200
|
+
/**
|
|
201
|
+
* Fractional number of CPUs to allocate to a function.
|
|
202
|
+
* Defaults to 1 for functions with <= 2GB RAM and increases for larger memory sizes.
|
|
203
|
+
* This is different from the defaults when using the gcloud utility and is different from
|
|
204
|
+
* the fixed amount assigned in Google Cloud Functions generation 1.
|
|
205
|
+
* To revert to the CPU amounts used in gcloud or in Cloud Functions generation 1, set this
|
|
206
|
+
* to the value "gcf_gen1"
|
|
207
|
+
*/
|
|
208
|
+
cpu?: number | 'gcf_gen1';
|
|
209
|
+
/**
|
|
210
|
+
* Connect cloud function to specified VPC connector.
|
|
211
|
+
* A value of null removes the VPC connector
|
|
212
|
+
*/
|
|
213
|
+
vpcConnector?: string | null;
|
|
214
|
+
/**
|
|
215
|
+
* Egress settings for VPC connector.
|
|
216
|
+
* A value of null turns off VPC connector egress settings
|
|
217
|
+
*/
|
|
218
|
+
vpcConnectorEgressSettings?: options.VpcEgressSetting | null;
|
|
219
|
+
/**
|
|
220
|
+
* Specific service account for the function to run as.
|
|
221
|
+
* A value of null restores the default service account.
|
|
222
|
+
*/
|
|
223
|
+
serviceAccount?: string | null;
|
|
224
|
+
/**
|
|
225
|
+
* Ingress settings which control where this function can be called from.
|
|
226
|
+
* A value of null turns off ingress settings.
|
|
227
|
+
*/
|
|
228
|
+
ingressSettings?: options.IngressSetting | null;
|
|
229
|
+
/**
|
|
230
|
+
* User labels to set on the function.
|
|
231
|
+
*/
|
|
232
|
+
labels?: Record<string, string>;
|
|
233
|
+
secrets?: string[];
|
|
234
|
+
/** Whether failed executions should be delivered again. */
|
|
235
|
+
retry?: boolean;
|
|
154
236
|
}
|
|
155
|
-
/**
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
237
|
+
/**
|
|
238
|
+
* Event handler sent only when a bucket has enabled object versioning.
|
|
239
|
+
* This event indicates that the live version of an object has become an
|
|
240
|
+
* archived version, either because it was archived or because it was
|
|
241
|
+
* overwritten by the upload of an object of the same name.
|
|
242
|
+
*
|
|
243
|
+
* @param handler - Event handler which is run every time a Google Cloud Storage archival occurs.
|
|
244
|
+
*/
|
|
245
|
+
export declare function onObjectArchived(handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;
|
|
246
|
+
/**
|
|
247
|
+
* Event handler sent only when a bucket has enabled object versioning.
|
|
248
|
+
* This event indicates that the live version of an object has become an
|
|
249
|
+
* archived version, either because it was archived or because it was
|
|
250
|
+
* overwritten by the upload of an object of the same name.
|
|
251
|
+
*
|
|
252
|
+
* @param bucket - The name of the bucket containing this object.
|
|
253
|
+
* @param handler - Event handler which is run every time a Google Cloud Storage archival occurs.
|
|
254
|
+
*/
|
|
255
|
+
export declare function onObjectArchived(bucket: string, handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;
|
|
256
|
+
/**
|
|
257
|
+
* Event handler sent only when a bucket has enabled object versioning.
|
|
258
|
+
* This event indicates that the live version of an object has become an
|
|
259
|
+
* archived version, either because it was archived or because it was
|
|
260
|
+
* overwritten by the upload of an object of the same name.
|
|
261
|
+
*
|
|
262
|
+
* @param opts - Options that can be set on an individual event-handling function.
|
|
263
|
+
* @param handler - Event handler which is run every time a Google Cloud Storage archival occurs.
|
|
264
|
+
*/
|
|
265
|
+
export declare function onObjectArchived(opts: StorageOptions, handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;
|
|
266
|
+
/**
|
|
267
|
+
* Event handler which fires every time a Google Cloud Storage object
|
|
268
|
+
* creation occurs.
|
|
269
|
+
*
|
|
270
|
+
* Sent when a new object (or a new generation of an existing object)
|
|
271
|
+
* is successfully created in the bucket. This includes copying or rewriting
|
|
272
|
+
* an existing object. A failed upload does not trigger this event.
|
|
273
|
+
*
|
|
274
|
+
* @param handler - Event handler which is run every time a Google Cloud Storage object creation occurs.
|
|
275
|
+
*/
|
|
276
|
+
export declare function onObjectFinalized(handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;
|
|
277
|
+
/**
|
|
278
|
+
* Event handler which fires every time a Google Cloud Storage object
|
|
279
|
+
* creation occurs.
|
|
280
|
+
*
|
|
281
|
+
* Sent when a new object (or a new generation of an existing object)
|
|
282
|
+
* is successfully created in the bucket. This includes copying or rewriting
|
|
283
|
+
* an existing object. A failed upload does not trigger this event.
|
|
284
|
+
*
|
|
285
|
+
* @param bucket - The name of the bucket containing this object.
|
|
286
|
+
* @param handler - Event handler which is run every time a Google Cloud Storage object creation occurs.
|
|
287
|
+
*/
|
|
288
|
+
export declare function onObjectFinalized(bucket: string, handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;
|
|
289
|
+
/**
|
|
290
|
+
* Event handler which fires every time a Google Cloud Storage object
|
|
291
|
+
* creation occurs.
|
|
292
|
+
*
|
|
293
|
+
* Sent when a new object (or a new generation of an existing object)
|
|
294
|
+
* is successfully created in the bucket. This includes copying or rewriting
|
|
295
|
+
* an existing object. A failed upload does not trigger this event.
|
|
296
|
+
*
|
|
297
|
+
* @param opts - Options that can be set on an individual event-handling function.
|
|
298
|
+
* @param handler - Event handler which is run every time a Google Cloud Storage object creation occurs.
|
|
299
|
+
*/
|
|
300
|
+
export declare function onObjectFinalized(opts: StorageOptions, handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;
|
|
301
|
+
/**
|
|
302
|
+
* Event handler which fires every time a Google Cloud Storage deletion occurs.
|
|
303
|
+
*
|
|
304
|
+
* Sent when an object has been permanently deleted. This includes objects
|
|
305
|
+
* that are overwritten or are deleted as part of the bucket's lifecycle
|
|
306
|
+
* configuration. For buckets with object versioning enabled, this is not
|
|
307
|
+
* sent when an object is archived, even if archival occurs
|
|
308
|
+
* via the `storage.objects.delete` method.
|
|
309
|
+
*
|
|
310
|
+
* @param handler - Event handler which is run every time a Google Cloud Storage object deletion occurs.
|
|
311
|
+
*/
|
|
312
|
+
export declare function onObjectDeleted(handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;
|
|
313
|
+
/**
|
|
314
|
+
* Event handler which fires every time a Google Cloud Storage deletion occurs.
|
|
315
|
+
*
|
|
316
|
+
* Sent when an object has been permanently deleted. This includes objects
|
|
317
|
+
* that are overwritten or are deleted as part of the bucket's lifecycle
|
|
318
|
+
* configuration. For buckets with object versioning enabled, this is not
|
|
319
|
+
* sent when an object is archived, even if archival occurs
|
|
320
|
+
* via the `storage.objects.delete` method.
|
|
321
|
+
*
|
|
322
|
+
* @param bucket - The name of the bucket containing this object.
|
|
323
|
+
* @param handler - Event handler which is run every time a Google Cloud Storage object deletion occurs.
|
|
324
|
+
*/
|
|
325
|
+
export declare function onObjectDeleted(bucket: string, handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;
|
|
326
|
+
/**
|
|
327
|
+
* Event handler which fires every time a Google Cloud Storage deletion occurs.
|
|
328
|
+
*
|
|
329
|
+
* Sent when an object has been permanently deleted. This includes objects
|
|
330
|
+
* that are overwritten or are deleted as part of the bucket's lifecycle
|
|
331
|
+
* configuration. For buckets with object versioning enabled, this is not
|
|
332
|
+
* sent when an object is archived, even if archival occurs
|
|
333
|
+
* via the `storage.objects.delete` method.
|
|
334
|
+
*
|
|
335
|
+
* @param opts - Options that can be set on an individual event-handling function.
|
|
336
|
+
* @param handler - Event handler which is run every time a Google Cloud Storage object deletion occurs.
|
|
337
|
+
*/
|
|
338
|
+
export declare function onObjectDeleted(opts: StorageOptions, handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;
|
|
339
|
+
/**
|
|
340
|
+
* Event handler which fires every time the metadata of an existing object
|
|
341
|
+
* changes.
|
|
342
|
+
*
|
|
343
|
+
* @param bucketOrOptsOrHandler - Options or string that may (or may not) define the bucket to be used.
|
|
344
|
+
* @param handler - Event handler which is run every time a Google Cloud Storage object metadata update occurs.
|
|
345
|
+
*/
|
|
346
|
+
export declare function onObjectMetadataUpdated(handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;
|
|
347
|
+
/**
|
|
348
|
+
* Event handler which fires every time the metadata of an existing object
|
|
349
|
+
* changes.
|
|
350
|
+
*
|
|
351
|
+
* @param bucket - The name of the bucket containing this object.
|
|
352
|
+
* @param handler - Event handler which is run every time a Google Cloud Storage object metadata update occurs.
|
|
353
|
+
*/
|
|
354
|
+
export declare function onObjectMetadataUpdated(bucket: string, handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;
|
|
355
|
+
/**
|
|
356
|
+
* Event handler which fires every time the metadata of an existing object
|
|
357
|
+
* changes.
|
|
358
|
+
*
|
|
359
|
+
* @param opts - Options that can be set on an individual event-handling function.
|
|
360
|
+
* @param handler - Event handler which is run every time a Google Cloud Storage object metadata update occurs.
|
|
361
|
+
*/
|
|
362
|
+
export declare function onObjectMetadataUpdated(opts: StorageOptions, handler: (event: StorageEvent) => any | Promise<any>): CloudFunction<StorageEvent>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// The MIT License (MIT)
|
|
3
3
|
//
|
|
4
|
-
// Copyright (c)
|
|
4
|
+
// Copyright (c) 2022 Firebase
|
|
5
5
|
//
|
|
6
6
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
// of this software and associated documentation files (the "Software"), to deal
|
|
@@ -22,9 +22,13 @@
|
|
|
22
22
|
// SOFTWARE.
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
24
|
exports.getOptsAndBucket = exports.onOperation = exports.onObjectMetadataUpdated = exports.onObjectDeleted = exports.onObjectFinalized = exports.onObjectArchived = exports.metadataUpdatedEvent = exports.deletedEvent = exports.finalizedEvent = exports.archivedEvent = void 0;
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Cloud functions to handle events from Google Cloud Storage.
|
|
27
|
+
* @packageDocumentation
|
|
28
|
+
*/
|
|
27
29
|
const encoding_1 = require("../../common/encoding");
|
|
30
|
+
const config_1 = require("../../config");
|
|
31
|
+
const options = require("../options");
|
|
28
32
|
/** @internal */
|
|
29
33
|
exports.archivedEvent = 'google.cloud.storage.object.v1.archived';
|
|
30
34
|
/** @internal */
|
|
@@ -33,20 +37,59 @@ exports.finalizedEvent = 'google.cloud.storage.object.v1.finalized';
|
|
|
33
37
|
exports.deletedEvent = 'google.cloud.storage.object.v1.deleted';
|
|
34
38
|
/** @internal */
|
|
35
39
|
exports.metadataUpdatedEvent = 'google.cloud.storage.object.v1.metadataUpdated';
|
|
36
|
-
|
|
37
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Event handler sent only when a bucket has enabled object versioning.
|
|
42
|
+
* This event indicates that the live version of an object has become an
|
|
43
|
+
* archived version, either because it was archived or because it was
|
|
44
|
+
* overwritten by the upload of an object of the same name.
|
|
45
|
+
*
|
|
46
|
+
* @param bucketOrOptsOrHandler - Options or string that may (or may not) define the bucket to be used.
|
|
47
|
+
* @param handler - Event handler which is run every time a Google Cloud Storage archival occurs.
|
|
48
|
+
*/
|
|
49
|
+
function onObjectArchived(bucketOrOptsOrHandler, handler) {
|
|
50
|
+
return onOperation(exports.archivedEvent, bucketOrOptsOrHandler, handler);
|
|
38
51
|
}
|
|
39
52
|
exports.onObjectArchived = onObjectArchived;
|
|
40
|
-
|
|
41
|
-
|
|
53
|
+
/**
|
|
54
|
+
* Event handler which fires every time a Google Cloud Storage object
|
|
55
|
+
* creation occurs.
|
|
56
|
+
*
|
|
57
|
+
* Sent when a new object (or a new generation of an existing object)
|
|
58
|
+
* is successfully created in the bucket. This includes copying or rewriting
|
|
59
|
+
* an existing object. A failed upload does not trigger this event.
|
|
60
|
+
*
|
|
61
|
+
* @param bucketOrOptsOrHandler - Options or string that may (or may not) define the bucket to be used.
|
|
62
|
+
* @param handler - Event handler which is run every time a Google Cloud Storage object creation occurs.
|
|
63
|
+
*/
|
|
64
|
+
function onObjectFinalized(bucketOrOptsOrHandler, handler) {
|
|
65
|
+
return onOperation(exports.finalizedEvent, bucketOrOptsOrHandler, handler);
|
|
42
66
|
}
|
|
43
67
|
exports.onObjectFinalized = onObjectFinalized;
|
|
44
|
-
|
|
45
|
-
|
|
68
|
+
/**
|
|
69
|
+
* Event handler which fires every time a Google Cloud Storage deletion occurs.
|
|
70
|
+
*
|
|
71
|
+
* Sent when an object has been permanently deleted. This includes objects
|
|
72
|
+
* that are overwritten or are deleted as part of the bucket's lifecycle
|
|
73
|
+
* configuration. For buckets with object versioning enabled, this is not
|
|
74
|
+
* sent when an object is archived, even if archival occurs
|
|
75
|
+
* via the `storage.objects.delete` method.
|
|
76
|
+
*
|
|
77
|
+
* @param bucketOrOptsOrHandler - Options or string that may (or may not) define the bucket to be used.
|
|
78
|
+
* @param handler - Event handler which is run every time a Google Cloud Storage object deletion occurs.
|
|
79
|
+
*/
|
|
80
|
+
function onObjectDeleted(bucketOrOptsOrHandler, handler) {
|
|
81
|
+
return onOperation(exports.deletedEvent, bucketOrOptsOrHandler, handler);
|
|
46
82
|
}
|
|
47
83
|
exports.onObjectDeleted = onObjectDeleted;
|
|
48
|
-
|
|
49
|
-
|
|
84
|
+
/**
|
|
85
|
+
* Event handler which fires every time the metadata of an existing object
|
|
86
|
+
* changes.
|
|
87
|
+
*
|
|
88
|
+
* @param bucketOrOptsOrHandler - Options or string that may (or may not) define the bucket to be used.
|
|
89
|
+
* @param handler - Event handler which is run every time a Google Cloud Storage object metadata update occurs.
|
|
90
|
+
*/
|
|
91
|
+
function onObjectMetadataUpdated(bucketOrOptsOrHandler, handler) {
|
|
92
|
+
return onOperation(exports.metadataUpdatedEvent, bucketOrOptsOrHandler, handler);
|
|
50
93
|
}
|
|
51
94
|
exports.onObjectMetadataUpdated = onObjectMetadataUpdated;
|
|
52
95
|
/** @internal */
|
|
@@ -103,7 +146,7 @@ function onOperation(eventType, bucketOrOptsOrHandler, handler) {
|
|
|
103
146
|
retry: false,
|
|
104
147
|
},
|
|
105
148
|
};
|
|
106
|
-
encoding_1.copyIfPresent(endpoint.eventTrigger, opts, 'retry', 'retry');
|
|
149
|
+
(0, encoding_1.copyIfPresent)(endpoint.eventTrigger, opts, 'retry', 'retry');
|
|
107
150
|
return endpoint;
|
|
108
151
|
},
|
|
109
152
|
});
|
|
@@ -112,6 +155,7 @@ function onOperation(eventType, bucketOrOptsOrHandler, handler) {
|
|
|
112
155
|
exports.onOperation = onOperation;
|
|
113
156
|
/** @internal */
|
|
114
157
|
function getOptsAndBucket(bucketOrOpts) {
|
|
158
|
+
var _a;
|
|
115
159
|
let bucket;
|
|
116
160
|
let opts;
|
|
117
161
|
if (typeof bucketOrOpts === 'string') {
|
|
@@ -119,7 +163,7 @@ function getOptsAndBucket(bucketOrOpts) {
|
|
|
119
163
|
opts = {};
|
|
120
164
|
}
|
|
121
165
|
else {
|
|
122
|
-
bucket = bucketOrOpts.bucket || config_1.firebaseConfig().storageBucket;
|
|
166
|
+
bucket = bucketOrOpts.bucket || ((_a = (0, config_1.firebaseConfig)()) === null || _a === void 0 ? void 0 : _a.storageBucket);
|
|
123
167
|
opts = { ...bucketOrOpts };
|
|
124
168
|
delete opts.bucket;
|
|
125
169
|
}
|
|
@@ -1,22 +1,122 @@
|
|
|
1
|
+
import { AuthData, RateLimits, Request, RetryConfig } from '../../common/providers/tasks';
|
|
1
2
|
import * as options from '../options';
|
|
2
3
|
import { HttpsFunction } from './https';
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
|
|
4
|
+
export { AuthData, RateLimits, Request, RetryConfig };
|
|
5
|
+
export interface TaskQueueOptions extends options.EventHandlerOptions {
|
|
6
|
+
/** How a task should be retried in the event of a non-2xx return. */
|
|
6
7
|
retryConfig?: RetryConfig;
|
|
8
|
+
/** How congestion control should be applied to the function. */
|
|
7
9
|
rateLimits?: RateLimits;
|
|
8
10
|
/**
|
|
9
11
|
* Who can enqueue tasks for this function.
|
|
10
12
|
* If left unspecified, only service accounts which have
|
|
11
|
-
* roles/cloudtasks.enqueuer and roles/cloudfunctions.invoker
|
|
13
|
+
* `roles/cloudtasks.enqueuer` and `roles/cloudfunctions.invoker`
|
|
12
14
|
* will have permissions.
|
|
13
15
|
*/
|
|
14
16
|
invoker?: 'private' | string | string[];
|
|
17
|
+
/**
|
|
18
|
+
* Region where functions should be deployed.
|
|
19
|
+
*/
|
|
20
|
+
region?: options.SupportedRegion | string;
|
|
21
|
+
/**
|
|
22
|
+
* Amount of memory to allocate to a function.
|
|
23
|
+
* A value of null restores the defaults of 256MB.
|
|
24
|
+
*/
|
|
25
|
+
memory?: options.MemoryOption | null;
|
|
26
|
+
/**
|
|
27
|
+
* Timeout for the function in sections, possible values are 0 to 540.
|
|
28
|
+
* HTTPS functions can specify a higher timeout.
|
|
29
|
+
* A value of null restores the default of 60s
|
|
30
|
+
* The minimum timeout for a gen 2 function is 1s. The maximum timeout for a
|
|
31
|
+
* function depends on the type of function: Event handling functions have a
|
|
32
|
+
* maximum timeout of 540s (9 minutes). HTTPS and callable functions have a
|
|
33
|
+
* maximum timeout of 36,00s (1 hour). Task queue functions have a maximum
|
|
34
|
+
* timeout of 1,800s (30 minutes)
|
|
35
|
+
*/
|
|
36
|
+
timeoutSeconds?: number | null;
|
|
37
|
+
/**
|
|
38
|
+
* Min number of actual instances to be running at a given time.
|
|
39
|
+
* Instances will be billed for memory allocation and 10% of CPU allocation
|
|
40
|
+
* while idle.
|
|
41
|
+
* A value of null restores the default min instances.
|
|
42
|
+
*/
|
|
43
|
+
minInstances?: number | null;
|
|
44
|
+
/**
|
|
45
|
+
* Max number of instances to be running in parallel.
|
|
46
|
+
* A value of null restores the default max instances.
|
|
47
|
+
*/
|
|
48
|
+
maxInstances?: number | null;
|
|
49
|
+
/**
|
|
50
|
+
* Number of requests a function can serve at once.
|
|
51
|
+
* Can only be applied to functions running on Cloud Functions v2.
|
|
52
|
+
* A value of null restores the default concurrency (80 when CPU >= 1, 1 otherwise).
|
|
53
|
+
* Concurrency cannot be set to any value other than 1 if `cpu` is less than 1.
|
|
54
|
+
* The maximum value for concurrency is 1,000.
|
|
55
|
+
*/
|
|
56
|
+
concurrency?: number | null;
|
|
57
|
+
/**
|
|
58
|
+
* Fractional number of CPUs to allocate to a function.
|
|
59
|
+
* Defaults to 1 for functions with <= 2GB RAM and increases for larger memory sizes.
|
|
60
|
+
* This is different from the defaults when using the gcloud utility and is different from
|
|
61
|
+
* the fixed amount assigned in Google Cloud Functions generation 1.
|
|
62
|
+
* To revert to the CPU amounts used in gcloud or in Cloud Functions generation 1, set this
|
|
63
|
+
* to the value "gcf_gen1"
|
|
64
|
+
*/
|
|
65
|
+
cpu?: number | 'gcf_gen1';
|
|
66
|
+
/**
|
|
67
|
+
* Connect cloud function to specified VPC connector.
|
|
68
|
+
* A value of null removes the VPC connector
|
|
69
|
+
*/
|
|
70
|
+
vpcConnector?: string | null;
|
|
71
|
+
/**
|
|
72
|
+
* Egress settings for VPC connector.
|
|
73
|
+
* A value of null turns off VPC connector egress settings
|
|
74
|
+
*/
|
|
75
|
+
vpcConnectorEgressSettings?: options.VpcEgressSetting | null;
|
|
76
|
+
/**
|
|
77
|
+
* Specific service account for the function to run as.
|
|
78
|
+
* A value of null restores the default service account.
|
|
79
|
+
*/
|
|
80
|
+
serviceAccount?: string | null;
|
|
81
|
+
/**
|
|
82
|
+
* Ingress settings which control where this function can be called from.
|
|
83
|
+
* A value of null turns off ingress settings.
|
|
84
|
+
*/
|
|
85
|
+
ingressSettings?: options.IngressSetting | null;
|
|
86
|
+
/**
|
|
87
|
+
* User labels to set on the function.
|
|
88
|
+
*/
|
|
89
|
+
labels?: Record<string, string>;
|
|
90
|
+
secrets?: string[];
|
|
91
|
+
/** Whether failed executions should be delivered again. */
|
|
92
|
+
retry?: boolean;
|
|
15
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* A handler for tasks.
|
|
96
|
+
* @typeParam T - The task data interface. Task data is unmarshaled from JSON.
|
|
97
|
+
*/
|
|
16
98
|
export interface TaskQueueFunction<T = any> extends HttpsFunction {
|
|
17
|
-
|
|
99
|
+
/**
|
|
100
|
+
* The callback passed to the `TaskQueueFunction` constructor.
|
|
101
|
+
* @param request - A TaskRequest containing data and auth information.
|
|
102
|
+
* @returns Any return value. Google Cloud Functions will await any promise
|
|
103
|
+
* before shutting down your function. Resolved return values
|
|
104
|
+
* are only used for unit testing purposes.
|
|
105
|
+
*/
|
|
106
|
+
run(request: Request<T>): void | Promise<void>;
|
|
18
107
|
}
|
|
19
|
-
/**
|
|
108
|
+
/**
|
|
109
|
+
* Creates a handler for tasks sent to a Google Cloud Tasks queue.
|
|
110
|
+
* @param handler - A callback to handle task requests.
|
|
111
|
+
* @typeParam Args - The interface for the request's `data` field.
|
|
112
|
+
* @returns A Cloud Function you can export and deploy.
|
|
113
|
+
*/
|
|
20
114
|
export declare function onTaskDispatched<Args = any>(handler: (request: Request<Args>) => void | Promise<void>): TaskQueueFunction<Args>;
|
|
21
|
-
/**
|
|
115
|
+
/**
|
|
116
|
+
* Creates a handler for tasks sent to a Google Cloud Tasks queue.
|
|
117
|
+
* @param options - Configuration for the task queue or Cloud Function.
|
|
118
|
+
* @param handler - A callback to handle task requests.
|
|
119
|
+
* @typeParam Args - The interface for the request's `data` field.
|
|
120
|
+
* @returns A Cloud Function you can export and deploy.
|
|
121
|
+
*/
|
|
22
122
|
export declare function onTaskDispatched<Args = any>(options: TaskQueueOptions, handler: (request: Request<Args>) => void | Promise<void>): TaskQueueFunction<Args>;
|
|
@@ -22,9 +22,13 @@
|
|
|
22
22
|
// SOFTWARE.
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
24
|
exports.onTaskDispatched = void 0;
|
|
25
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Cloud functions to handle Tasks enqueued with Google Cloud Tasks.
|
|
27
|
+
* @packageDocumentation
|
|
28
|
+
*/
|
|
26
29
|
const encoding_1 = require("../../common/encoding");
|
|
27
30
|
const tasks_1 = require("../../common/providers/tasks");
|
|
31
|
+
const options = require("../options");
|
|
28
32
|
function onTaskDispatched(optsOrHandler, handler) {
|
|
29
33
|
let opts;
|
|
30
34
|
if (arguments.length == 1) {
|
|
@@ -37,7 +41,7 @@ function onTaskDispatched(optsOrHandler, handler) {
|
|
|
37
41
|
// onDispatchHandler sniffs the function length to determine which API to present.
|
|
38
42
|
// fix the length to prevent api versions from being mismatched.
|
|
39
43
|
const fixedLen = (req) => handler(req);
|
|
40
|
-
const func = tasks_1.onDispatchHandler(fixedLen);
|
|
44
|
+
const func = (0, tasks_1.onDispatchHandler)(fixedLen);
|
|
41
45
|
Object.defineProperty(func, '__trigger', {
|
|
42
46
|
get: () => {
|
|
43
47
|
const baseOpts = options.optionsToTriggerAnnotations(options.getGlobalOptions());
|
|
@@ -45,10 +49,9 @@ function onTaskDispatched(optsOrHandler, handler) {
|
|
|
45
49
|
// but optionsToTriggerAnnotations handles both cases.
|
|
46
50
|
const specificOpts = options.optionsToTriggerAnnotations(opts);
|
|
47
51
|
const taskQueueTrigger = {};
|
|
48
|
-
encoding_1.copyIfPresent(taskQueueTrigger, opts, 'retryConfig', 'rateLimits');
|
|
49
|
-
encoding_1.convertIfPresent(taskQueueTrigger, opts, 'invoker', 'invoker', encoding_1.convertInvoker);
|
|
52
|
+
(0, encoding_1.copyIfPresent)(taskQueueTrigger, opts, 'retryConfig', 'rateLimits');
|
|
53
|
+
(0, encoding_1.convertIfPresent)(taskQueueTrigger, opts, 'invoker', 'invoker', encoding_1.convertInvoker);
|
|
50
54
|
return {
|
|
51
|
-
apiVersion: 2,
|
|
52
55
|
platform: 'gcfv2',
|
|
53
56
|
...baseOpts,
|
|
54
57
|
...specificOpts,
|
|
@@ -74,9 +77,9 @@ function onTaskDispatched(optsOrHandler, handler) {
|
|
|
74
77
|
},
|
|
75
78
|
taskQueueTrigger: {},
|
|
76
79
|
};
|
|
77
|
-
encoding_1.copyIfPresent(func.__endpoint.taskQueueTrigger, opts, 'retryConfig');
|
|
78
|
-
encoding_1.copyIfPresent(func.__endpoint.taskQueueTrigger, opts, 'rateLimits');
|
|
79
|
-
encoding_1.convertIfPresent(func.__endpoint.taskQueueTrigger, opts, 'invoker', 'invoker', encoding_1.convertInvoker);
|
|
80
|
+
(0, encoding_1.copyIfPresent)(func.__endpoint.taskQueueTrigger, opts, 'retryConfig');
|
|
81
|
+
(0, encoding_1.copyIfPresent)(func.__endpoint.taskQueueTrigger, opts, 'rateLimits');
|
|
82
|
+
(0, encoding_1.convertIfPresent)(func.__endpoint.taskQueueTrigger, opts, 'invoker', 'invoker', encoding_1.convertInvoker);
|
|
80
83
|
func.__requiredAPIs = [
|
|
81
84
|
{
|
|
82
85
|
api: 'cloudtasks.googleapis.com',
|