firebase-functions 4.8.0 → 4.8.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/params.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Expression } from "../params";
|
|
1
2
|
/**
|
|
2
3
|
* A type that splits literal string S with delimiter D.
|
|
3
4
|
*
|
|
@@ -27,6 +28,6 @@ export type Extract<Part extends string> = Part extends `{${infer Param}=**}` ?
|
|
|
27
28
|
*
|
|
28
29
|
* For flexibility reasons, ParamsOf<string> is Record<string, string>
|
|
29
30
|
*/
|
|
30
|
-
export type ParamsOf<PathPattern extends string
|
|
31
|
-
[Key in Extract<Split<NullSafe<PathPattern
|
|
31
|
+
export type ParamsOf<PathPattern extends string | Expression<string>> = PathPattern extends Expression<string> ? Record<string, string> : string extends PathPattern ? Record<string, string> : {
|
|
32
|
+
[Key in Extract<Split<NullSafe<Exclude<PathPattern, Expression<string>>>, "/">[number]>]: string;
|
|
32
33
|
};
|
|
@@ -35,6 +35,7 @@ Object.defineProperty(exports, "Change", { enumerable: true, get: function () {
|
|
|
35
35
|
const WILDCARD_REGEX = new RegExp("{[^/{}]*}", "g");
|
|
36
36
|
/** @internal */
|
|
37
37
|
function makeCloudFunction({ contextOnlyHandler, dataConstructor = (raw) => raw.data, eventType, handler, labels = {}, legacyEventType, options = {}, provider, service, triggerResource, }) {
|
|
38
|
+
handler = (0, onInit_1.withInit)(handler !== null && handler !== void 0 ? handler : contextOnlyHandler);
|
|
38
39
|
const cloudFunction = (data, context) => {
|
|
39
40
|
if (legacyEventType && context.eventType === legacyEventType) {
|
|
40
41
|
/*
|
|
@@ -70,7 +71,6 @@ function makeCloudFunction({ contextOnlyHandler, dataConstructor = (raw) => raw.
|
|
|
70
71
|
else {
|
|
71
72
|
context.params = context.params || _makeParams(context, triggerResource);
|
|
72
73
|
}
|
|
73
|
-
handler = (0, onInit_1.withInit)(handler);
|
|
74
74
|
let promise;
|
|
75
75
|
if (labels && labels["deployment-scheduled"]) {
|
|
76
76
|
// Scheduled function do not have meaningful data, so exclude it
|
|
@@ -2,6 +2,7 @@ import * as firestore from "firebase-admin/firestore";
|
|
|
2
2
|
import { ParamsOf } from "../../common/params";
|
|
3
3
|
import { Change, CloudEvent, CloudFunction } from "../core";
|
|
4
4
|
import { EventHandlerOptions } from "../options";
|
|
5
|
+
import { Expression } from "../../params";
|
|
5
6
|
export { Change };
|
|
6
7
|
/** A Firestore DocumentSnapshot */
|
|
7
8
|
export type DocumentSnapshot = firestore.DocumentSnapshot;
|
|
@@ -28,11 +29,11 @@ export interface FirestoreEvent<T, Params = Record<string, string>> extends Clou
|
|
|
28
29
|
/** DocumentOptions extend EventHandlerOptions with provided document and optional database and namespace. */
|
|
29
30
|
export interface DocumentOptions<Document extends string = string> extends EventHandlerOptions {
|
|
30
31
|
/** The document path */
|
|
31
|
-
document: Document
|
|
32
|
+
document: Document | Expression<string>;
|
|
32
33
|
/** The Firestore database */
|
|
33
|
-
database?: string
|
|
34
|
+
database?: string | Expression<string>;
|
|
34
35
|
/** The Firestore namespace */
|
|
35
|
-
namespace?: string
|
|
36
|
+
namespace?: string | Expression<string>;
|
|
36
37
|
}
|
|
37
38
|
/**
|
|
38
39
|
* Event handler which triggers when a document is created, updated, or deleted in Firestore.
|
|
@@ -93,7 +93,10 @@ function getOpts(documentOrOpts) {
|
|
|
93
93
|
opts = {};
|
|
94
94
|
}
|
|
95
95
|
else {
|
|
96
|
-
document =
|
|
96
|
+
document =
|
|
97
|
+
typeof documentOrOpts.document === "string"
|
|
98
|
+
? (0, path_1.normalizePath)(documentOrOpts.document)
|
|
99
|
+
: documentOrOpts.document;
|
|
97
100
|
database = documentOrOpts.database || "(default)";
|
|
98
101
|
namespace = documentOrOpts.namespace || "(default)";
|
|
99
102
|
opts = { ...documentOrOpts };
|
|
@@ -191,9 +194,13 @@ function makeEndpoint(eventType, opts, document, database, namespace) {
|
|
|
191
194
|
namespace,
|
|
192
195
|
};
|
|
193
196
|
const eventFilterPathPatterns = {};
|
|
194
|
-
document.hasWildcards()
|
|
195
|
-
|
|
196
|
-
|
|
197
|
+
const maybePattern = typeof document === "string" ? new path_pattern_1.PathPattern(document).hasWildcards() : true;
|
|
198
|
+
if (maybePattern) {
|
|
199
|
+
eventFilterPathPatterns.document = document;
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
eventFilters.document = document;
|
|
203
|
+
}
|
|
197
204
|
return {
|
|
198
205
|
...(0, manifest_1.initV2Endpoint)((0, options_1.getGlobalOptions)(), opts),
|
|
199
206
|
platform: "gcfv2",
|
|
@@ -215,32 +222,32 @@ exports.makeEndpoint = makeEndpoint;
|
|
|
215
222
|
/** @internal */
|
|
216
223
|
function onOperation(eventType, documentOrOpts, handler) {
|
|
217
224
|
const { document, database, namespace, opts } = getOpts(documentOrOpts);
|
|
218
|
-
const documentPattern = new path_pattern_1.PathPattern(document);
|
|
219
225
|
// wrap the handler
|
|
220
226
|
const func = (raw) => {
|
|
221
227
|
const event = raw;
|
|
228
|
+
const documentPattern = new path_pattern_1.PathPattern(typeof document === "string" ? document : document.value());
|
|
222
229
|
const params = makeParams(event.document, documentPattern);
|
|
223
230
|
const firestoreEvent = makeFirestoreEvent(eventType, event, params);
|
|
224
231
|
return (0, trace_1.wrapTraceContext)((0, onInit_1.withInit)(handler))(firestoreEvent);
|
|
225
232
|
};
|
|
226
233
|
func.run = handler;
|
|
227
|
-
func.__endpoint = makeEndpoint(eventType, opts,
|
|
234
|
+
func.__endpoint = makeEndpoint(eventType, opts, document, database, namespace);
|
|
228
235
|
return func;
|
|
229
236
|
}
|
|
230
237
|
exports.onOperation = onOperation;
|
|
231
238
|
/** @internal */
|
|
232
239
|
function onChangedOperation(eventType, documentOrOpts, handler) {
|
|
233
240
|
const { document, database, namespace, opts } = getOpts(documentOrOpts);
|
|
234
|
-
const documentPattern = new path_pattern_1.PathPattern(document);
|
|
235
241
|
// wrap the handler
|
|
236
242
|
const func = (raw) => {
|
|
237
243
|
const event = raw;
|
|
244
|
+
const documentPattern = new path_pattern_1.PathPattern(typeof document === "string" ? document : document.value());
|
|
238
245
|
const params = makeParams(event.document, documentPattern);
|
|
239
246
|
const firestoreEvent = makeChangedFirestoreEvent(event, params);
|
|
240
247
|
return (0, trace_1.wrapTraceContext)((0, onInit_1.withInit)(handler))(firestoreEvent);
|
|
241
248
|
};
|
|
242
249
|
func.run = handler;
|
|
243
|
-
func.__endpoint = makeEndpoint(eventType, opts,
|
|
250
|
+
func.__endpoint = makeEndpoint(eventType, opts, document, database, namespace);
|
|
244
251
|
return func;
|
|
245
252
|
}
|
|
246
253
|
exports.onChangedOperation = onChangedOperation;
|
|
@@ -50,11 +50,18 @@ function onRequest(optsOrHandler, handler) {
|
|
|
50
50
|
// Respect `cors: false` to turn off cors even if debug feature is enabled.
|
|
51
51
|
origin = opts.cors === false ? false : true;
|
|
52
52
|
}
|
|
53
|
+
// Arrays cause the access-control-allow-origin header to be dynamic based
|
|
54
|
+
// on the origin header of the request. If there is only one element in the
|
|
55
|
+
// array, this is unnecessary.
|
|
56
|
+
if (Array.isArray(origin) && origin.length === 1) {
|
|
57
|
+
origin = origin[0];
|
|
58
|
+
}
|
|
59
|
+
const middleware = cors({ origin });
|
|
53
60
|
const userProvidedHandler = handler;
|
|
54
61
|
handler = (req, res) => {
|
|
55
62
|
return new Promise((resolve) => {
|
|
56
63
|
res.on("finish", resolve);
|
|
57
|
-
|
|
64
|
+
middleware(req, res, () => {
|
|
58
65
|
resolve(userProvidedHandler(req, res));
|
|
59
66
|
});
|
|
60
67
|
});
|
|
@@ -116,7 +123,13 @@ function onCall(optsOrHandler, handler) {
|
|
|
116
123
|
else {
|
|
117
124
|
opts = optsOrHandler;
|
|
118
125
|
}
|
|
119
|
-
|
|
126
|
+
let origin = (0, debug_1.isDebugFeatureEnabled)("enableCors") ? true : "cors" in opts ? opts.cors : true;
|
|
127
|
+
// Arrays cause the access-control-allow-origin header to be dynamic based
|
|
128
|
+
// on the origin header of the request. If there is only one element in the
|
|
129
|
+
// array, this is unnecessary.
|
|
130
|
+
if (Array.isArray(origin) && origin.length === 1) {
|
|
131
|
+
origin = origin[1];
|
|
132
|
+
}
|
|
120
133
|
// onCallHandler sniffs the function length to determine which API to present.
|
|
121
134
|
// fix the length to prevent api versions from being mismatched.
|
|
122
135
|
const fixedLen = (req) => (0, onInit_1.withInit)(handler)(req);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "firebase-functions",
|
|
3
|
-
"version": "4.8.
|
|
3
|
+
"version": "4.8.2",
|
|
4
4
|
"description": "Firebase SDK for Cloud Functions",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"firebase",
|
|
@@ -201,7 +201,6 @@
|
|
|
201
201
|
"@types/express": "4.17.3",
|
|
202
202
|
"cors": "^2.8.5",
|
|
203
203
|
"express": "^4.17.1",
|
|
204
|
-
"node-fetch": "^2.6.7",
|
|
205
204
|
"protobufjs": "^7.2.2"
|
|
206
205
|
},
|
|
207
206
|
"devDependencies": {
|