firebase-functions 3.15.7 → 3.17.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/bin/firebase-functions.d.ts +2 -0
- package/lib/bin/firebase-functions.js +48 -0
- package/lib/cloud-functions.d.ts +14 -8
- package/lib/cloud-functions.js +61 -1
- package/lib/common/debug.d.ts +1 -0
- package/lib/common/debug.js +54 -0
- package/lib/common/encoding.js +6 -0
- package/lib/common/providers/https.d.ts +92 -47
- package/lib/common/providers/https.js +171 -51
- package/lib/common/providers/identity.d.ts +29 -0
- package/lib/common/providers/identity.js +96 -0
- package/lib/function-builder.d.ts +7 -1
- package/lib/function-builder.js +8 -0
- package/lib/function-configuration.d.ts +1 -0
- package/lib/handler-builder.d.ts +19 -15
- package/lib/handler-builder.js +32 -15
- package/lib/providers/auth.d.ts +2 -21
- package/lib/providers/auth.js +5 -66
- package/lib/providers/database.js +2 -1
- package/lib/providers/https.d.ts +44 -2
- package/lib/providers/https.js +65 -2
- package/lib/runtime/loader.d.ts +1 -0
- package/lib/runtime/loader.js +101 -0
- package/lib/runtime/manifest.d.ts +55 -0
- package/lib/runtime/manifest.js +2 -0
- package/lib/v2/core.d.ts +10 -3
- package/lib/v2/index.d.ts +3 -1
- package/lib/v2/index.js +5 -1
- package/lib/v2/options.d.ts +1 -1
- package/lib/v2/options.js +47 -9
- package/lib/v2/params/types.d.ts +2 -1
- package/lib/v2/params/types.js +2 -0
- package/lib/v2/providers/alerts/alerts.d.ts +36 -0
- package/lib/v2/providers/alerts/alerts.js +72 -0
- package/lib/v2/providers/alerts/appDistribution.d.ts +35 -0
- package/lib/v2/providers/alerts/appDistribution.js +39 -0
- package/lib/v2/providers/alerts/billing.d.ts +38 -0
- package/lib/v2/providers/alerts/billing.js +30 -0
- package/lib/v2/providers/alerts/crashlytics.d.ts +123 -0
- package/lib/v2/providers/alerts/crashlytics.js +74 -0
- package/lib/v2/providers/alerts/index.d.ts +5 -0
- package/lib/v2/providers/alerts/index.js +20 -0
- package/lib/v2/providers/https.d.ts +23 -3
- package/lib/v2/providers/https.js +72 -3
- package/lib/v2/providers/pubsub.d.ts +1 -1
- package/lib/v2/providers/pubsub.js +19 -4
- package/lib/v2/providers/storage.d.ts +170 -0
- package/lib/v2/providers/storage.js +137 -0
- package/package.json +34 -7
|
@@ -1,18 +1,38 @@
|
|
|
1
1
|
import * as express from 'express';
|
|
2
|
-
import { CallableRequest, FunctionsErrorCode, HttpsError, Request } from '../../common/providers/https';
|
|
3
2
|
import * as options from '../options';
|
|
4
|
-
|
|
3
|
+
import { CallableRequest, FunctionsErrorCode, HttpsError, Request, TaskRateLimits, TaskRequest, TaskRetryConfig } from '../../common/providers/https';
|
|
4
|
+
import { ManifestEndpoint } from '../../runtime/manifest';
|
|
5
|
+
export { Request, CallableRequest, FunctionsErrorCode, HttpsError, TaskRateLimits, TaskRequest, TaskRetryConfig as TaskRetryPolicy, };
|
|
5
6
|
export interface HttpsOptions extends Omit<options.GlobalOptions, 'region'> {
|
|
6
7
|
region?: options.SupportedRegion | string | Array<options.SupportedRegion | string>;
|
|
7
8
|
cors?: string | boolean | RegExp | Array<string | RegExp>;
|
|
8
9
|
}
|
|
10
|
+
export interface TaskQueueOptions extends options.GlobalOptions {
|
|
11
|
+
retryConfig?: TaskRetryConfig;
|
|
12
|
+
rateLimits?: TaskRateLimits;
|
|
13
|
+
/**
|
|
14
|
+
* Who can enqueue tasks for this function.
|
|
15
|
+
* If left unspecified, only service accounts which have
|
|
16
|
+
* roles/cloudtasks.enqueuer and roles/cloudfunctions.invoker
|
|
17
|
+
* will have permissions.
|
|
18
|
+
*/
|
|
19
|
+
invoker?: 'private' | string | string[];
|
|
20
|
+
}
|
|
9
21
|
export declare type HttpsFunction = ((req: Request, res: express.Response) => void | Promise<void>) & {
|
|
10
|
-
__trigger
|
|
22
|
+
__trigger?: unknown;
|
|
23
|
+
__endpoint: ManifestEndpoint;
|
|
11
24
|
};
|
|
12
25
|
export interface CallableFunction<T, Return> extends HttpsFunction {
|
|
13
26
|
run(data: CallableRequest<T>): Return;
|
|
14
27
|
}
|
|
28
|
+
export interface TaskQueueFunction<T = any> extends HttpsFunction {
|
|
29
|
+
run(data: TaskRequest<T>): void | Promise<void>;
|
|
30
|
+
}
|
|
15
31
|
export declare function onRequest(opts: HttpsOptions, handler: (request: Request, response: express.Response) => void | Promise<void>): HttpsFunction;
|
|
16
32
|
export declare function onRequest(handler: (request: Request, response: express.Response) => void | Promise<void>): HttpsFunction;
|
|
17
33
|
export declare function onCall<T = any, Return = any | Promise<any>>(opts: HttpsOptions, handler: (request: CallableRequest<T>) => Return): CallableFunction<T, Return>;
|
|
18
34
|
export declare function onCall<T = any, Return = any | Promise<any>>(handler: (request: CallableRequest<T>) => Return): CallableFunction<T, Return>;
|
|
35
|
+
/** Handle a request sent to a Cloud Tasks queue. */
|
|
36
|
+
export declare function onTaskDispatched<Args = any>(handler: (request: TaskRequest<Args>) => void | Promise<void>): TaskQueueFunction<Args>;
|
|
37
|
+
/** Handle a request sent to a Cloud Tasks queue. */
|
|
38
|
+
export declare function onTaskDispatched<Args = any>(options: TaskQueueOptions, handler: (request: TaskRequest<Args>) => void | Promise<void>): TaskQueueFunction<Args>;
|
|
@@ -21,12 +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.onCall = exports.onRequest = exports.HttpsError = void 0;
|
|
24
|
+
exports.onTaskDispatched = exports.onCall = exports.onRequest = exports.HttpsError = void 0;
|
|
25
25
|
const cors = require("cors");
|
|
26
26
|
const encoding_1 = require("../../common/encoding");
|
|
27
|
+
const options = require("../options");
|
|
27
28
|
const https_1 = require("../../common/providers/https");
|
|
28
29
|
Object.defineProperty(exports, "HttpsError", { enumerable: true, get: function () { return https_1.HttpsError; } });
|
|
29
|
-
const options = require("../options");
|
|
30
30
|
function onRequest(optsOrHandler, handler) {
|
|
31
31
|
let opts;
|
|
32
32
|
if (arguments.length === 1) {
|
|
@@ -72,6 +72,22 @@ function onRequest(optsOrHandler, handler) {
|
|
|
72
72
|
return trigger;
|
|
73
73
|
},
|
|
74
74
|
});
|
|
75
|
+
const baseOpts = options.optionsToEndpoint(options.getGlobalOptions());
|
|
76
|
+
// global options calls region a scalar and https allows it to be an array,
|
|
77
|
+
// but optionsToTriggerAnnotations handles both cases.
|
|
78
|
+
const specificOpts = options.optionsToEndpoint(opts);
|
|
79
|
+
const endpoint = {
|
|
80
|
+
platform: 'gcfv2',
|
|
81
|
+
...baseOpts,
|
|
82
|
+
...specificOpts,
|
|
83
|
+
labels: {
|
|
84
|
+
...baseOpts === null || baseOpts === void 0 ? void 0 : baseOpts.labels,
|
|
85
|
+
...specificOpts === null || specificOpts === void 0 ? void 0 : specificOpts.labels,
|
|
86
|
+
},
|
|
87
|
+
httpsTrigger: {},
|
|
88
|
+
};
|
|
89
|
+
(0, encoding_1.convertIfPresent)(endpoint.httpsTrigger, opts, 'invoker', 'invoker', encoding_1.convertInvoker);
|
|
90
|
+
handler.__endpoint = endpoint;
|
|
75
91
|
return handler;
|
|
76
92
|
}
|
|
77
93
|
exports.onRequest = onRequest;
|
|
@@ -88,7 +104,7 @@ function onCall(optsOrHandler, handler) {
|
|
|
88
104
|
// onCallHandler sniffs the function length to determine which API to present.
|
|
89
105
|
// fix the length to prevent api versions from being mismatched.
|
|
90
106
|
const fixedLen = (req) => handler(req);
|
|
91
|
-
const func = (0, https_1.onCallHandler)({ origin, methods: 'POST' }, fixedLen);
|
|
107
|
+
const func = (0, https_1.onCallHandler)({ cors: { origin, methods: 'POST' } }, fixedLen);
|
|
92
108
|
Object.defineProperty(func, '__trigger', {
|
|
93
109
|
get: () => {
|
|
94
110
|
const baseOpts = options.optionsToTriggerAnnotations(options.getGlobalOptions());
|
|
@@ -113,7 +129,60 @@ function onCall(optsOrHandler, handler) {
|
|
|
113
129
|
};
|
|
114
130
|
},
|
|
115
131
|
});
|
|
132
|
+
const baseOpts = options.optionsToEndpoint(options.getGlobalOptions());
|
|
133
|
+
// global options calls region a scalar and https allows it to be an array,
|
|
134
|
+
// but optionsToManifestEndpoint handles both cases.
|
|
135
|
+
const specificOpts = options.optionsToEndpoint(opts);
|
|
136
|
+
func.__endpoint = {
|
|
137
|
+
platform: 'gcfv2',
|
|
138
|
+
...baseOpts,
|
|
139
|
+
...specificOpts,
|
|
140
|
+
labels: {
|
|
141
|
+
...baseOpts === null || baseOpts === void 0 ? void 0 : baseOpts.labels,
|
|
142
|
+
...specificOpts === null || specificOpts === void 0 ? void 0 : specificOpts.labels,
|
|
143
|
+
},
|
|
144
|
+
callableTrigger: {},
|
|
145
|
+
};
|
|
116
146
|
func.run = handler;
|
|
117
147
|
return func;
|
|
118
148
|
}
|
|
119
149
|
exports.onCall = onCall;
|
|
150
|
+
function onTaskDispatched(optsOrHandler, handler) {
|
|
151
|
+
let opts;
|
|
152
|
+
if (arguments.length == 1) {
|
|
153
|
+
opts = {};
|
|
154
|
+
handler = optsOrHandler;
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
opts = optsOrHandler;
|
|
158
|
+
}
|
|
159
|
+
// onEnqueueHandler sniffs the function length to determine which API to present.
|
|
160
|
+
// fix the length to prevent api versions from being mismatched.
|
|
161
|
+
const fixedLen = (req) => handler(req);
|
|
162
|
+
const func = (0, https_1.onDispatchHandler)(fixedLen);
|
|
163
|
+
Object.defineProperty(func, '__trigger', {
|
|
164
|
+
get: () => {
|
|
165
|
+
const baseOpts = options.optionsToTriggerAnnotations(options.getGlobalOptions());
|
|
166
|
+
// global options calls region a scalar and https allows it to be an array,
|
|
167
|
+
// but optionsToTriggerAnnotations handles both cases.
|
|
168
|
+
const specificOpts = options.optionsToTriggerAnnotations(opts);
|
|
169
|
+
const taskQueueTrigger = {};
|
|
170
|
+
(0, encoding_1.copyIfPresent)(taskQueueTrigger, opts, 'retryConfig', 'rateLimits');
|
|
171
|
+
(0, encoding_1.convertIfPresent)(taskQueueTrigger, opts, 'invoker', 'invoker', encoding_1.convertInvoker);
|
|
172
|
+
return {
|
|
173
|
+
apiVersion: 2,
|
|
174
|
+
platform: 'gcfv2',
|
|
175
|
+
...baseOpts,
|
|
176
|
+
...specificOpts,
|
|
177
|
+
labels: {
|
|
178
|
+
...baseOpts === null || baseOpts === void 0 ? void 0 : baseOpts.labels,
|
|
179
|
+
...specificOpts === null || specificOpts === void 0 ? void 0 : specificOpts.labels,
|
|
180
|
+
},
|
|
181
|
+
taskQueueTrigger,
|
|
182
|
+
};
|
|
183
|
+
},
|
|
184
|
+
});
|
|
185
|
+
func.run = handler;
|
|
186
|
+
return func;
|
|
187
|
+
}
|
|
188
|
+
exports.onTaskDispatched = onTaskDispatched;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.onMessagePublished = exports.Message = void 0;
|
|
4
4
|
const options = require("../options");
|
|
5
|
+
const encoding_1 = require("../../common/encoding");
|
|
5
6
|
/**
|
|
6
7
|
* Interface representing a Google Cloud Pub/Sub message.
|
|
7
8
|
*
|
|
@@ -69,10 +70,6 @@ function onMessagePublished(topicOrOptions, handler) {
|
|
|
69
70
|
return handler(raw);
|
|
70
71
|
};
|
|
71
72
|
func.run = handler;
|
|
72
|
-
// TypeScript doesn't recongize defineProperty as adding a property and complains
|
|
73
|
-
// that __trigger doesn't exist. We can either cast to any and lose all type safety
|
|
74
|
-
// or we can just assign a meaningless value before calling defineProperty.
|
|
75
|
-
func.__trigger = 'silence the transpiler';
|
|
76
73
|
Object.defineProperty(func, '__trigger', {
|
|
77
74
|
get: () => {
|
|
78
75
|
const baseOpts = options.optionsToTriggerAnnotations(options.getGlobalOptions());
|
|
@@ -95,6 +92,24 @@ function onMessagePublished(topicOrOptions, handler) {
|
|
|
95
92
|
};
|
|
96
93
|
},
|
|
97
94
|
});
|
|
95
|
+
const baseOpts = options.optionsToEndpoint(options.getGlobalOptions());
|
|
96
|
+
const specificOpts = options.optionsToEndpoint(opts);
|
|
97
|
+
const endpoint = {
|
|
98
|
+
platform: 'gcfv2',
|
|
99
|
+
...baseOpts,
|
|
100
|
+
...specificOpts,
|
|
101
|
+
labels: {
|
|
102
|
+
...baseOpts === null || baseOpts === void 0 ? void 0 : baseOpts.labels,
|
|
103
|
+
...specificOpts === null || specificOpts === void 0 ? void 0 : specificOpts.labels,
|
|
104
|
+
},
|
|
105
|
+
eventTrigger: {
|
|
106
|
+
eventType: 'google.cloud.pubsub.topic.v1.messagePublished',
|
|
107
|
+
eventFilters: { topic },
|
|
108
|
+
retry: false,
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
(0, encoding_1.copyIfPresent)(endpoint.eventTrigger, opts, 'retry', 'retry');
|
|
112
|
+
func.__endpoint = endpoint;
|
|
98
113
|
return func;
|
|
99
114
|
}
|
|
100
115
|
exports.onMessagePublished = onMessagePublished;
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import * as options from '../options';
|
|
2
|
+
import { CloudEvent, CloudFunction } from '../core';
|
|
3
|
+
/**
|
|
4
|
+
* An object within Google Cloud Storage.
|
|
5
|
+
* Ref: https://github.com/googleapis/google-cloudevents-nodejs/blob/main/cloud/storage/v1/StorageObjectData.ts
|
|
6
|
+
*/
|
|
7
|
+
export interface StorageObjectData {
|
|
8
|
+
/**
|
|
9
|
+
* The name of the bucket containing this object.
|
|
10
|
+
*/
|
|
11
|
+
bucket?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Cache-Control directive for the object data, matching
|
|
14
|
+
* [https://tools.ietf.org/html/rfc7234#section-5.2"][RFC 7234 §5.2].
|
|
15
|
+
*/
|
|
16
|
+
cacheControl?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Number of underlying components that make up this object. Components are
|
|
19
|
+
* accumulated by compose operations.
|
|
20
|
+
* Attempting to set this field will result in an error.
|
|
21
|
+
*/
|
|
22
|
+
componentCount?: number;
|
|
23
|
+
/**
|
|
24
|
+
* Content-Disposition of the object data, matching
|
|
25
|
+
* [https://tools.ietf.org/html/rfc6266][RFC 6266].
|
|
26
|
+
*/
|
|
27
|
+
contentDisposition?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Content-Encoding of the object data, matching
|
|
30
|
+
* [https://tools.ietf.org/html/rfc7231#section-3.1.2.2][RFC 7231 §3.1.2.2]
|
|
31
|
+
*/
|
|
32
|
+
contentEncoding?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Content-Language of the object data, matching
|
|
35
|
+
* [https://tools.ietf.org/html/rfc7231#section-3.1.3.2][RFC 7231 §3.1.3.2].
|
|
36
|
+
*/
|
|
37
|
+
contentLanguage?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Content-Type of the object data, matching
|
|
40
|
+
* [https://tools.ietf.org/html/rfc7231#section-3.1.1.5][RFC 7231 §3.1.1.5].
|
|
41
|
+
* If an object is stored without a Content-Type, it is served as
|
|
42
|
+
* `application/octet-stream`.
|
|
43
|
+
*/
|
|
44
|
+
contentType?: string;
|
|
45
|
+
/**
|
|
46
|
+
* CRC32c checksum. For more information about using the CRC32c
|
|
47
|
+
* checksum, see
|
|
48
|
+
* [https://cloud.google.com/storage/docs/hashes-etags#_JSONAPI][Hashes and
|
|
49
|
+
* ETags: Best Practices].
|
|
50
|
+
*/
|
|
51
|
+
crc32c?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Metadata of customer-supplied encryption key, if the object is encrypted by
|
|
54
|
+
* such a key.
|
|
55
|
+
*/
|
|
56
|
+
customerEncryption?: CustomerEncryption;
|
|
57
|
+
/**
|
|
58
|
+
* HTTP 1.1 Entity tag for the object. See
|
|
59
|
+
* [https://tools.ietf.org/html/rfc7232#section-2.3][RFC 7232 §2.3].
|
|
60
|
+
*/
|
|
61
|
+
etag?: string;
|
|
62
|
+
/**
|
|
63
|
+
* The content generation of this object. Used for object versioning.
|
|
64
|
+
* Attempting to set this field will result in an error.
|
|
65
|
+
*/
|
|
66
|
+
generation?: number;
|
|
67
|
+
/**
|
|
68
|
+
* The ID of the object, including the bucket name, object name, and
|
|
69
|
+
* generation number.
|
|
70
|
+
*/
|
|
71
|
+
id?: string;
|
|
72
|
+
/**
|
|
73
|
+
* The kind of item this is. For objects, this is always "storage#object".
|
|
74
|
+
*/
|
|
75
|
+
kind?: string;
|
|
76
|
+
/**
|
|
77
|
+
* MD5 hash of the data; encoded using base64 as per
|
|
78
|
+
* [https://tools.ietf.org/html/rfc4648#section-4][RFC 4648 §4]. For more
|
|
79
|
+
* information about using the MD5 hash, see
|
|
80
|
+
* [https://cloud.google.com/storage/docs/hashes-etags#_JSONAPI][Hashes and
|
|
81
|
+
* ETags: Best Practices].
|
|
82
|
+
*/
|
|
83
|
+
md5Hash?: string;
|
|
84
|
+
/**
|
|
85
|
+
* Media download link.
|
|
86
|
+
*/
|
|
87
|
+
mediaLink?: string;
|
|
88
|
+
/**
|
|
89
|
+
* User-provided metadata, in key/value pairs.
|
|
90
|
+
*/
|
|
91
|
+
metadata?: {
|
|
92
|
+
[key: string]: string;
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* The version of the metadata for this object at this generation. Used for
|
|
96
|
+
* preconditions and for detecting changes in metadata. A metageneration
|
|
97
|
+
* number is only meaningful in the context of a particular generation of a
|
|
98
|
+
* particular object.
|
|
99
|
+
*/
|
|
100
|
+
metageneration?: number;
|
|
101
|
+
/**
|
|
102
|
+
* The name of the object.
|
|
103
|
+
*/
|
|
104
|
+
name?: string;
|
|
105
|
+
/**
|
|
106
|
+
* The link to this object.
|
|
107
|
+
*/
|
|
108
|
+
selfLink?: string;
|
|
109
|
+
/**
|
|
110
|
+
* Content-Length of the object data in bytes, matching
|
|
111
|
+
* [https://tools.ietf.org/html/rfc7230#section-3.3.2][RFC 7230 §3.3.2].
|
|
112
|
+
*/
|
|
113
|
+
size?: number;
|
|
114
|
+
/**
|
|
115
|
+
* Storage class of the object.
|
|
116
|
+
*/
|
|
117
|
+
storageClass?: string;
|
|
118
|
+
/**
|
|
119
|
+
* The creation time of the object.
|
|
120
|
+
* Attempting to set this field will result in an error.
|
|
121
|
+
*/
|
|
122
|
+
timeCreated?: Date | string;
|
|
123
|
+
/**
|
|
124
|
+
* The deletion time of the object. Will be returned if and only if this
|
|
125
|
+
* version of the object has been deleted.
|
|
126
|
+
*/
|
|
127
|
+
timeDeleted?: Date | string;
|
|
128
|
+
/**
|
|
129
|
+
* The time at which the object's storage class was last changed.
|
|
130
|
+
*/
|
|
131
|
+
timeStorageClassUpdated?: Date | string;
|
|
132
|
+
/**
|
|
133
|
+
* The modification time of the object metadata.
|
|
134
|
+
*/
|
|
135
|
+
updated?: Date | string;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Metadata of customer-supplied encryption key, if the object is encrypted by
|
|
139
|
+
* such a key.
|
|
140
|
+
*/
|
|
141
|
+
export interface CustomerEncryption {
|
|
142
|
+
/**
|
|
143
|
+
* The encryption algorithm.
|
|
144
|
+
*/
|
|
145
|
+
encryptionAlgorithm?: string;
|
|
146
|
+
/**
|
|
147
|
+
* SHA256 hash value of the encryption key.
|
|
148
|
+
*/
|
|
149
|
+
keySha256?: string;
|
|
150
|
+
}
|
|
151
|
+
/** StorageOptions extend EventHandlerOptions with a bucket name */
|
|
152
|
+
export interface StorageOptions extends options.EventHandlerOptions {
|
|
153
|
+
bucket?: string;
|
|
154
|
+
}
|
|
155
|
+
/** Handle a storage object archived */
|
|
156
|
+
export declare function onObjectArchived(handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any>): CloudFunction<StorageObjectData>;
|
|
157
|
+
export declare function onObjectArchived(bucket: string, handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any>): CloudFunction<StorageObjectData>;
|
|
158
|
+
export declare function onObjectArchived(opts: StorageOptions, handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any>): CloudFunction<StorageObjectData>;
|
|
159
|
+
/** Handle a storage object finalized */
|
|
160
|
+
export declare function onObjectFinalized(handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any>): CloudFunction<StorageObjectData>;
|
|
161
|
+
export declare function onObjectFinalized(bucket: string, handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any>): CloudFunction<StorageObjectData>;
|
|
162
|
+
export declare function onObjectFinalized(opts: StorageOptions, handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any>): CloudFunction<StorageObjectData>;
|
|
163
|
+
/** Handle a storage object deleted */
|
|
164
|
+
export declare function onObjectDeleted(handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any>): CloudFunction<StorageObjectData>;
|
|
165
|
+
export declare function onObjectDeleted(bucket: string, handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any>): CloudFunction<StorageObjectData>;
|
|
166
|
+
export declare function onObjectDeleted(opts: StorageOptions, handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any>): CloudFunction<StorageObjectData>;
|
|
167
|
+
/** Handle a storage object metadata updated */
|
|
168
|
+
export declare function onObjectMetadataUpdated(handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any>): CloudFunction<StorageObjectData>;
|
|
169
|
+
export declare function onObjectMetadataUpdated(bucket: string, handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any>): CloudFunction<StorageObjectData>;
|
|
170
|
+
export declare function onObjectMetadataUpdated(opts: StorageOptions, handler: (event: CloudEvent<StorageObjectData>) => any | Promise<any>): CloudFunction<StorageObjectData>;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// The MIT License (MIT)
|
|
3
|
+
//
|
|
4
|
+
// Copyright (c) 2017 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.getOptsAndBucket = exports.onOperation = exports.onObjectMetadataUpdated = exports.onObjectDeleted = exports.onObjectFinalized = exports.onObjectArchived = exports.metadataUpdatedEvent = exports.deletedEvent = exports.finalizedEvent = exports.archivedEvent = void 0;
|
|
25
|
+
const options = require("../options");
|
|
26
|
+
const config_1 = require("../../config");
|
|
27
|
+
const encoding_1 = require("../../common/encoding");
|
|
28
|
+
/** @internal */
|
|
29
|
+
exports.archivedEvent = 'google.cloud.storage.object.v1.archived';
|
|
30
|
+
/** @internal */
|
|
31
|
+
exports.finalizedEvent = 'google.cloud.storage.object.v1.finalized';
|
|
32
|
+
/** @internal */
|
|
33
|
+
exports.deletedEvent = 'google.cloud.storage.object.v1.deleted';
|
|
34
|
+
/** @internal */
|
|
35
|
+
exports.metadataUpdatedEvent = 'google.cloud.storage.object.v1.metadataUpdated';
|
|
36
|
+
function onObjectArchived(buketOrOptsOrHandler, handler) {
|
|
37
|
+
return onOperation(exports.archivedEvent, buketOrOptsOrHandler, handler);
|
|
38
|
+
}
|
|
39
|
+
exports.onObjectArchived = onObjectArchived;
|
|
40
|
+
function onObjectFinalized(buketOrOptsOrHandler, handler) {
|
|
41
|
+
return onOperation(exports.finalizedEvent, buketOrOptsOrHandler, handler);
|
|
42
|
+
}
|
|
43
|
+
exports.onObjectFinalized = onObjectFinalized;
|
|
44
|
+
function onObjectDeleted(buketOrOptsOrHandler, handler) {
|
|
45
|
+
return onOperation(exports.deletedEvent, buketOrOptsOrHandler, handler);
|
|
46
|
+
}
|
|
47
|
+
exports.onObjectDeleted = onObjectDeleted;
|
|
48
|
+
function onObjectMetadataUpdated(buketOrOptsOrHandler, handler) {
|
|
49
|
+
return onOperation(exports.metadataUpdatedEvent, buketOrOptsOrHandler, handler);
|
|
50
|
+
}
|
|
51
|
+
exports.onObjectMetadataUpdated = onObjectMetadataUpdated;
|
|
52
|
+
/** @internal */
|
|
53
|
+
function onOperation(eventType, bucketOrOptsOrHandler, handler) {
|
|
54
|
+
if (typeof bucketOrOptsOrHandler === 'function') {
|
|
55
|
+
handler = bucketOrOptsOrHandler;
|
|
56
|
+
bucketOrOptsOrHandler = {};
|
|
57
|
+
}
|
|
58
|
+
const [opts, bucket] = getOptsAndBucket(bucketOrOptsOrHandler);
|
|
59
|
+
const func = (raw) => {
|
|
60
|
+
return handler(raw);
|
|
61
|
+
};
|
|
62
|
+
func.run = handler;
|
|
63
|
+
Object.defineProperty(func, '__trigger', {
|
|
64
|
+
get: () => {
|
|
65
|
+
const baseOpts = options.optionsToTriggerAnnotations(options.getGlobalOptions());
|
|
66
|
+
const specificOpts = options.optionsToTriggerAnnotations(opts);
|
|
67
|
+
return {
|
|
68
|
+
platform: 'gcfv2',
|
|
69
|
+
...baseOpts,
|
|
70
|
+
...specificOpts,
|
|
71
|
+
labels: {
|
|
72
|
+
...baseOpts === null || baseOpts === void 0 ? void 0 : baseOpts.labels,
|
|
73
|
+
...specificOpts === null || specificOpts === void 0 ? void 0 : specificOpts.labels,
|
|
74
|
+
},
|
|
75
|
+
eventTrigger: {
|
|
76
|
+
eventType,
|
|
77
|
+
resource: bucket, // TODO(colerogers): replace with 'bucket,' eventually
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
// TypeScript doesn't recognize defineProperty as adding a property and complains
|
|
83
|
+
// that __endpoint doesn't exist. We can either cast to any and lose all type safety
|
|
84
|
+
// or we can just assign a meaningless value before calling defineProperty.
|
|
85
|
+
func.__endpoint = {};
|
|
86
|
+
// SDK may attempt to read FIREBASE_CONFIG env var to fetch the default bucket name.
|
|
87
|
+
// To prevent runtime errors when FIREBASE_CONFIG env var is missing, we use getters.
|
|
88
|
+
Object.defineProperty(func, '__endpoint', {
|
|
89
|
+
get: () => {
|
|
90
|
+
const baseOpts = options.optionsToEndpoint(options.getGlobalOptions());
|
|
91
|
+
const specificOpts = options.optionsToEndpoint(opts);
|
|
92
|
+
const endpoint = {
|
|
93
|
+
platform: 'gcfv2',
|
|
94
|
+
...baseOpts,
|
|
95
|
+
...specificOpts,
|
|
96
|
+
labels: {
|
|
97
|
+
...baseOpts === null || baseOpts === void 0 ? void 0 : baseOpts.labels,
|
|
98
|
+
...specificOpts === null || specificOpts === void 0 ? void 0 : specificOpts.labels,
|
|
99
|
+
},
|
|
100
|
+
eventTrigger: {
|
|
101
|
+
eventType,
|
|
102
|
+
eventFilters: {
|
|
103
|
+
bucket,
|
|
104
|
+
},
|
|
105
|
+
retry: false,
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
(0, encoding_1.copyIfPresent)(endpoint.eventTrigger, opts, 'retry', 'retry');
|
|
109
|
+
return endpoint;
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
return func;
|
|
113
|
+
}
|
|
114
|
+
exports.onOperation = onOperation;
|
|
115
|
+
/** @internal */
|
|
116
|
+
function getOptsAndBucket(bucketOrOpts) {
|
|
117
|
+
let bucket;
|
|
118
|
+
let opts;
|
|
119
|
+
if (typeof bucketOrOpts === 'string') {
|
|
120
|
+
bucket = bucketOrOpts;
|
|
121
|
+
opts = {};
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
bucket = bucketOrOpts.bucket || (0, config_1.firebaseConfig)().storageBucket;
|
|
125
|
+
opts = { ...bucketOrOpts };
|
|
126
|
+
delete opts.bucket;
|
|
127
|
+
}
|
|
128
|
+
if (!bucket) {
|
|
129
|
+
throw new Error('Missing bucket name. If you are unit testing, please provide a bucket name' +
|
|
130
|
+
' by providing bucket name directly in the event handler or by setting process.env.FIREBASE_CONFIG.');
|
|
131
|
+
}
|
|
132
|
+
if (!/^[a-z\d][a-z\d\\._-]{1,230}[a-z\d]$/.test(bucket)) {
|
|
133
|
+
throw new Error(`Invalid bucket name ${bucket}`);
|
|
134
|
+
}
|
|
135
|
+
return [opts, bucket];
|
|
136
|
+
}
|
|
137
|
+
exports.getOptsAndBucket = getOptsAndBucket;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "firebase-functions",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.17.2",
|
|
4
4
|
"description": "Firebase SDK for Cloud Functions",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"firebase",
|
|
@@ -22,6 +22,9 @@
|
|
|
22
22
|
"lib"
|
|
23
23
|
],
|
|
24
24
|
"main": "lib/index.js",
|
|
25
|
+
"bin": {
|
|
26
|
+
"firebase-functions": "./lib/bin/firebase-functions.js"
|
|
27
|
+
},
|
|
25
28
|
"types": "lib/index.d.ts",
|
|
26
29
|
"exports": {
|
|
27
30
|
".": "./lib/index.js",
|
|
@@ -53,7 +56,12 @@
|
|
|
53
56
|
"./v2/options": "./lib/v2/options.js",
|
|
54
57
|
"./v2/https": "./lib/v2/providers/https.js",
|
|
55
58
|
"./v2/params": "./lib/v2/params/index.js",
|
|
56
|
-
"./v2/pubsub": "./lib/v2/providers/pubsub.js"
|
|
59
|
+
"./v2/pubsub": "./lib/v2/providers/pubsub.js",
|
|
60
|
+
"./v2/storage": "./lib/v2/providers/storage.js",
|
|
61
|
+
"./v2/alerts": "./lib/v2/providers/alerts/index.js",
|
|
62
|
+
"./v2/alerts/appDistribution": "./lib/v2/providers/alerts/appDistribution.js",
|
|
63
|
+
"./v2/alerts/billing": "./lib/v2/providers/alerts/billing.js",
|
|
64
|
+
"./v2/alerts/crashlytics": "./lib/v2/providers/alerts/crashlytics.js"
|
|
57
65
|
},
|
|
58
66
|
"typesVersions": {
|
|
59
67
|
"*": {
|
|
@@ -110,6 +118,21 @@
|
|
|
110
118
|
],
|
|
111
119
|
"v2/pubsub": [
|
|
112
120
|
"lib/v2/providers/pubsub"
|
|
121
|
+
],
|
|
122
|
+
"v2/storage": [
|
|
123
|
+
"lib/v2/providers/storage"
|
|
124
|
+
],
|
|
125
|
+
"v2/alerts": [
|
|
126
|
+
"lib/v2/providers/alerts"
|
|
127
|
+
],
|
|
128
|
+
"v2/alerts/appDistribution": [
|
|
129
|
+
"lib/v2/providers/alerts/appDistribution"
|
|
130
|
+
],
|
|
131
|
+
"v2/alerts/billing": [
|
|
132
|
+
"lib/v2/providers/alerts/billing"
|
|
133
|
+
],
|
|
134
|
+
"v2/alerts/crashlytics": [
|
|
135
|
+
"lib/v2/providers/alerts/crashlytics"
|
|
113
136
|
]
|
|
114
137
|
}
|
|
115
138
|
},
|
|
@@ -126,7 +149,8 @@
|
|
|
126
149
|
"format:fix": "prettier --write '**/*.{json,md,ts,yml,yaml}'",
|
|
127
150
|
"lint": "tslint --config tslint.json --project tsconfig.json ",
|
|
128
151
|
"lint:fix": "tslint --config tslint.json --fix --project tsconfig.json",
|
|
129
|
-
"test": "mocha"
|
|
152
|
+
"test": "mocha --file ./mocha/setup.ts spec/**/*.spec.ts ",
|
|
153
|
+
"test:bin": "./scripts/bin-test/run.sh"
|
|
130
154
|
},
|
|
131
155
|
"dependencies": {
|
|
132
156
|
"@types/cors": "^2.8.5",
|
|
@@ -148,7 +172,7 @@
|
|
|
148
172
|
"chai": "^4.2.0",
|
|
149
173
|
"chai-as-promised": "^7.1.1",
|
|
150
174
|
"child-process-promise": "^2.2.1",
|
|
151
|
-
"firebase-admin": "
|
|
175
|
+
"firebase-admin": "10.0.0",
|
|
152
176
|
"js-yaml": "^3.13.1",
|
|
153
177
|
"jsdom": "^16.2.1",
|
|
154
178
|
"jsonwebtoken": "^8.5.1",
|
|
@@ -157,19 +181,22 @@
|
|
|
157
181
|
"mock-require": "^3.0.3",
|
|
158
182
|
"mz": "^2.7.0",
|
|
159
183
|
"nock": "^10.0.6",
|
|
184
|
+
"node-fetch": "^2.6.7",
|
|
185
|
+
"portfinder": "^1.0.28",
|
|
160
186
|
"prettier": "^1.18.2",
|
|
187
|
+
"semver": "^7.3.5",
|
|
161
188
|
"sinon": "^7.3.2",
|
|
162
|
-
"ts-node": "^
|
|
189
|
+
"ts-node": "^10.4.0",
|
|
163
190
|
"tslint": "^5.18.0",
|
|
164
191
|
"tslint-config-prettier": "^1.18.0",
|
|
165
192
|
"tslint-no-unused-expression-chai": "^0.1.4",
|
|
166
193
|
"tslint-plugin-prettier": "^2.0.1",
|
|
167
|
-
"typedoc": "
|
|
194
|
+
"typedoc": "0.21.2",
|
|
168
195
|
"typescript": "^4.3.5",
|
|
169
196
|
"yargs": "^15.3.1"
|
|
170
197
|
},
|
|
171
198
|
"peerDependencies": {
|
|
172
|
-
"firebase-admin": "^8.0.0 || ^9.0.0"
|
|
199
|
+
"firebase-admin": "^8.0.0 || ^9.0.0 || ^10.0.0"
|
|
173
200
|
},
|
|
174
201
|
"engines": {
|
|
175
202
|
"node": "^8.13.0 || >=10.10.0"
|