firebase-functions 4.8.2 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -48,9 +48,9 @@ function _getValueProto(data, resource, valueFieldName) {
|
|
|
48
48
|
return proto;
|
|
49
49
|
}
|
|
50
50
|
/** @internal */
|
|
51
|
-
function createSnapshotFromProtobuf(data, path) {
|
|
51
|
+
function createSnapshotFromProtobuf(data, path, databaseId) {
|
|
52
52
|
if (!firestoreInstance) {
|
|
53
|
-
firestoreInstance = firestore.getFirestore(
|
|
53
|
+
firestoreInstance = firestore.getFirestore(databaseId);
|
|
54
54
|
}
|
|
55
55
|
try {
|
|
56
56
|
const dataBuffer = Buffer.from(data);
|
|
@@ -64,9 +64,9 @@ function createSnapshotFromProtobuf(data, path) {
|
|
|
64
64
|
}
|
|
65
65
|
exports.createSnapshotFromProtobuf = createSnapshotFromProtobuf;
|
|
66
66
|
/** @internal */
|
|
67
|
-
function createBeforeSnapshotFromProtobuf(data, path) {
|
|
67
|
+
function createBeforeSnapshotFromProtobuf(data, path, databaseId) {
|
|
68
68
|
if (!firestoreInstance) {
|
|
69
|
-
firestoreInstance = firestore.getFirestore(
|
|
69
|
+
firestoreInstance = firestore.getFirestore(databaseId);
|
|
70
70
|
}
|
|
71
71
|
try {
|
|
72
72
|
const dataBuffer = Buffer.from(data);
|
|
@@ -80,9 +80,11 @@ function createBeforeSnapshotFromProtobuf(data, path) {
|
|
|
80
80
|
}
|
|
81
81
|
exports.createBeforeSnapshotFromProtobuf = createBeforeSnapshotFromProtobuf;
|
|
82
82
|
/** @internal */
|
|
83
|
-
function createSnapshotFromJson(data, source, createTime, updateTime) {
|
|
83
|
+
function createSnapshotFromJson(data, source, createTime, updateTime, databaseId) {
|
|
84
84
|
if (!firestoreInstance) {
|
|
85
|
-
firestoreInstance =
|
|
85
|
+
firestoreInstance = databaseId
|
|
86
|
+
? firestore.getFirestore(databaseId)
|
|
87
|
+
: firestore.getFirestore((0, app_1.getApp)());
|
|
86
88
|
}
|
|
87
89
|
const valueProto = _getValueProto(data, source, "value");
|
|
88
90
|
let timeString = createTime || updateTime;
|
|
@@ -95,9 +97,11 @@ function createSnapshotFromJson(data, source, createTime, updateTime) {
|
|
|
95
97
|
}
|
|
96
98
|
exports.createSnapshotFromJson = createSnapshotFromJson;
|
|
97
99
|
/** @internal */
|
|
98
|
-
function createBeforeSnapshotFromJson(data, source, createTime, updateTime) {
|
|
100
|
+
function createBeforeSnapshotFromJson(data, source, createTime, updateTime, databaseId) {
|
|
99
101
|
if (!firestoreInstance) {
|
|
100
|
-
firestoreInstance =
|
|
102
|
+
firestoreInstance = databaseId
|
|
103
|
+
? firestore.getFirestore(databaseId)
|
|
104
|
+
: firestore.getFirestore((0, app_1.getApp)());
|
|
101
105
|
}
|
|
102
106
|
const oldValueProto = _getValueProto(data, source, "oldValue");
|
|
103
107
|
const oldReadTime = (0, encoder_1.dateToTimestampProto)(createTime || updateTime);
|
|
@@ -8,6 +8,15 @@ export { Change };
|
|
|
8
8
|
export type DocumentSnapshot = firestore.DocumentSnapshot;
|
|
9
9
|
/** A Firestore QueryDocumentSnapshot */
|
|
10
10
|
export type QueryDocumentSnapshot = firestore.QueryDocumentSnapshot;
|
|
11
|
+
/**
|
|
12
|
+
* AuthType defines the possible values for the authType field in a Firestore event with auth context.
|
|
13
|
+
* - service_account: a non-user principal used to identify a workload or machine user.
|
|
14
|
+
* - api_key: a non-user client API key.
|
|
15
|
+
* - system: an obscured identity used when Cloud Platform or another system triggered the event. Examples include a database record which was deleted based on a TTL.
|
|
16
|
+
* - unauthenticated: an unauthenticated action.
|
|
17
|
+
* - unknown: a general type to capture all other principals not captured in the other auth types.
|
|
18
|
+
*/
|
|
19
|
+
export type AuthType = "service_account" | "api_key" | "system" | "unauthenticated" | "unknown";
|
|
11
20
|
/** A CloudEvent that contains a DocumentSnapshot or a Change<DocumentSnapshot> */
|
|
12
21
|
export interface FirestoreEvent<T, Params = Record<string, string>> extends CloudEvent<T> {
|
|
13
22
|
/** The location of the Firestore instance */
|
|
@@ -26,6 +35,12 @@ export interface FirestoreEvent<T, Params = Record<string, string>> extends Clou
|
|
|
26
35
|
*/
|
|
27
36
|
params: Params;
|
|
28
37
|
}
|
|
38
|
+
export interface FirestoreAuthEvent<T, Params = Record<string, string>> extends FirestoreEvent<T, Params> {
|
|
39
|
+
/** The type of principal that triggered the event */
|
|
40
|
+
authType: AuthType;
|
|
41
|
+
/** The unique identifier for the principal */
|
|
42
|
+
authId?: string;
|
|
43
|
+
}
|
|
29
44
|
/** DocumentOptions extend EventHandlerOptions with provided document and optional database and namespace. */
|
|
30
45
|
export interface DocumentOptions<Document extends string = string> extends EventHandlerOptions {
|
|
31
46
|
/** The document path */
|
|
@@ -36,58 +51,122 @@ export interface DocumentOptions<Document extends string = string> extends Event
|
|
|
36
51
|
namespace?: string | Expression<string>;
|
|
37
52
|
}
|
|
38
53
|
/**
|
|
39
|
-
* Event handler
|
|
54
|
+
* Event handler that triggers when a document is created, updated, or deleted in Firestore.
|
|
40
55
|
*
|
|
41
56
|
* @param document - The Firestore document path to trigger on.
|
|
42
57
|
* @param handler - Event handler which is run every time a Firestore create, update, or delete occurs.
|
|
43
58
|
*/
|
|
44
59
|
export declare function onDocumentWritten<Document extends string>(document: Document, handler: (event: FirestoreEvent<Change<DocumentSnapshot> | undefined, ParamsOf<Document>>) => any | Promise<any>): CloudFunction<FirestoreEvent<Change<DocumentSnapshot> | undefined, ParamsOf<Document>>>;
|
|
45
60
|
/**
|
|
46
|
-
* Event handler
|
|
61
|
+
* Event handler that triggers when a document is created, updated, or deleted in Firestore.
|
|
47
62
|
*
|
|
48
63
|
* @param opts - Options that can be set on an individual event-handling function.
|
|
49
64
|
* @param handler - Event handler which is run every time a Firestore create, update, or delete occurs.
|
|
50
65
|
*/
|
|
51
66
|
export declare function onDocumentWritten<Document extends string>(opts: DocumentOptions<Document>, handler: (event: FirestoreEvent<Change<DocumentSnapshot> | undefined, ParamsOf<Document>>) => any | Promise<any>): CloudFunction<FirestoreEvent<Change<DocumentSnapshot> | undefined, ParamsOf<Document>>>;
|
|
52
67
|
/**
|
|
53
|
-
* Event handler
|
|
68
|
+
* Event handler that triggers when a document is created, updated, or deleted in Firestore.
|
|
69
|
+
* This trigger also provides the authentication context of the principal who triggered the event.
|
|
70
|
+
*
|
|
71
|
+
* @param document - The Firestore document path to trigger on.
|
|
72
|
+
* @param handler - Event handler which is run every time a Firestore create, update, or delete occurs.
|
|
73
|
+
*/
|
|
74
|
+
export declare function onDocumentWrittenWithAuthContext<Document extends string>(document: Document, handler: (event: FirestoreAuthEvent<Change<DocumentSnapshot> | undefined, ParamsOf<Document>>) => any | Promise<any>): CloudFunction<FirestoreAuthEvent<Change<DocumentSnapshot> | undefined, ParamsOf<Document>>>;
|
|
75
|
+
/**
|
|
76
|
+
* Event handler that triggers when a document is created, updated, or deleted in Firestore.
|
|
77
|
+
* This trigger also provides the authentication context of the principal who triggered the event.
|
|
78
|
+
*
|
|
79
|
+
* @param opts - Options that can be set on an individual event-handling function.
|
|
80
|
+
* @param handler - Event handler which is run every time a Firestore create, update, or delete occurs.
|
|
81
|
+
*/
|
|
82
|
+
export declare function onDocumentWrittenWithAuthContext<Document extends string>(opts: DocumentOptions<Document>, handler: (event: FirestoreAuthEvent<Change<DocumentSnapshot> | undefined, ParamsOf<Document>>) => any | Promise<any>): CloudFunction<FirestoreAuthEvent<Change<DocumentSnapshot> | undefined, ParamsOf<Document>>>;
|
|
83
|
+
/**
|
|
84
|
+
* Event handler that triggers when a document is created in Firestore.
|
|
54
85
|
*
|
|
55
86
|
* @param document - The Firestore document path to trigger on.
|
|
56
87
|
* @param handler - Event handler which is run every time a Firestore create occurs.
|
|
57
88
|
*/
|
|
58
89
|
export declare function onDocumentCreated<Document extends string>(document: Document, handler: (event: FirestoreEvent<QueryDocumentSnapshot | undefined, ParamsOf<Document>>) => any | Promise<any>): CloudFunction<FirestoreEvent<QueryDocumentSnapshot | undefined, ParamsOf<Document>>>;
|
|
59
90
|
/**
|
|
60
|
-
* Event handler
|
|
91
|
+
* Event handler that triggers when a document is created in Firestore.
|
|
61
92
|
*
|
|
62
93
|
* @param opts - Options that can be set on an individual event-handling function.
|
|
63
94
|
* @param handler - Event handler which is run every time a Firestore create occurs.
|
|
64
95
|
*/
|
|
65
96
|
export declare function onDocumentCreated<Document extends string>(opts: DocumentOptions<Document>, handler: (event: FirestoreEvent<QueryDocumentSnapshot | undefined, ParamsOf<Document>>) => any | Promise<any>): CloudFunction<FirestoreEvent<QueryDocumentSnapshot | undefined, ParamsOf<Document>>>;
|
|
66
97
|
/**
|
|
67
|
-
* Event handler
|
|
98
|
+
* Event handler that triggers when a document is created in Firestore.
|
|
99
|
+
* This trigger also provides the authentication context of the principal who triggered the event.
|
|
100
|
+
*
|
|
101
|
+
* @param document - The Firestore document path to trigger on.
|
|
102
|
+
* @param handler - Event handler which is run every time a Firestore create occurs.
|
|
103
|
+
*/
|
|
104
|
+
export declare function onDocumentCreatedWithAuthContext<Document extends string>(document: Document, handler: (event: FirestoreAuthEvent<QueryDocumentSnapshot | undefined, ParamsOf<Document>>) => any | Promise<any>): CloudFunction<FirestoreAuthEvent<QueryDocumentSnapshot | undefined, ParamsOf<Document>>>;
|
|
105
|
+
/**
|
|
106
|
+
* Event handler that triggers when a document is created in Firestore.
|
|
107
|
+
* This trigger also provides the authentication context of the principal who triggered the event.
|
|
108
|
+
*
|
|
109
|
+
* @param opts - Options that can be set on an individual event-handling function.
|
|
110
|
+
* @param handler - Event handler which is run every time a Firestore create occurs.
|
|
111
|
+
*/
|
|
112
|
+
export declare function onDocumentCreatedWithAuthContext<Document extends string>(opts: DocumentOptions<Document>, handler: (event: FirestoreAuthEvent<QueryDocumentSnapshot | undefined, ParamsOf<Document>>) => any | Promise<any>): CloudFunction<FirestoreAuthEvent<QueryDocumentSnapshot | undefined, ParamsOf<Document>>>;
|
|
113
|
+
/**
|
|
114
|
+
* Event handler that triggers when a document is updated in Firestore.
|
|
68
115
|
*
|
|
69
116
|
* @param document - The Firestore document path to trigger on.
|
|
70
117
|
* @param handler - Event handler which is run every time a Firestore update occurs.
|
|
71
118
|
*/
|
|
72
119
|
export declare function onDocumentUpdated<Document extends string>(document: Document, handler: (event: FirestoreEvent<Change<QueryDocumentSnapshot> | undefined, ParamsOf<Document>>) => any | Promise<any>): CloudFunction<FirestoreEvent<Change<QueryDocumentSnapshot> | undefined, ParamsOf<Document>>>;
|
|
73
120
|
/**
|
|
74
|
-
* Event handler
|
|
121
|
+
* Event handler that triggers when a document is updated in Firestore.
|
|
75
122
|
*
|
|
76
123
|
* @param opts - Options that can be set on an individual event-handling function.
|
|
77
124
|
* @param handler - Event handler which is run every time a Firestore update occurs.
|
|
78
125
|
*/
|
|
79
126
|
export declare function onDocumentUpdated<Document extends string>(opts: DocumentOptions<Document>, handler: (event: FirestoreEvent<Change<QueryDocumentSnapshot> | undefined, ParamsOf<Document>>) => any | Promise<any>): CloudFunction<FirestoreEvent<Change<QueryDocumentSnapshot> | undefined, ParamsOf<Document>>>;
|
|
80
127
|
/**
|
|
81
|
-
* Event handler
|
|
128
|
+
* Event handler that triggers when a document is updated in Firestore.
|
|
129
|
+
* This trigger also provides the authentication context of the principal who triggered the event.
|
|
130
|
+
*
|
|
131
|
+
* @param document - The Firestore document path to trigger on.
|
|
132
|
+
* @param handler - Event handler which is run every time a Firestore update occurs.
|
|
133
|
+
*/
|
|
134
|
+
export declare function onDocumentUpdatedWithAuthContext<Document extends string>(document: Document, handler: (event: FirestoreAuthEvent<Change<QueryDocumentSnapshot> | undefined, ParamsOf<Document>>) => any | Promise<any>): CloudFunction<FirestoreAuthEvent<Change<QueryDocumentSnapshot> | undefined, ParamsOf<Document>>>;
|
|
135
|
+
/**
|
|
136
|
+
* Event handler that triggers when a document is updated in Firestore.
|
|
137
|
+
* This trigger also provides the authentication context of the principal who triggered the event.
|
|
138
|
+
*
|
|
139
|
+
* @param opts - Options that can be set on an individual event-handling function.
|
|
140
|
+
* @param handler - Event handler which is run every time a Firestore update occurs.
|
|
141
|
+
*/
|
|
142
|
+
export declare function onDocumentUpdatedWithAuthContext<Document extends string>(opts: DocumentOptions<Document>, handler: (event: FirestoreAuthEvent<Change<QueryDocumentSnapshot> | undefined, ParamsOf<Document>>) => any | Promise<any>): CloudFunction<FirestoreAuthEvent<Change<QueryDocumentSnapshot> | undefined, ParamsOf<Document>>>;
|
|
143
|
+
/**
|
|
144
|
+
* Event handler that triggers when a document is deleted in Firestore.
|
|
82
145
|
*
|
|
83
146
|
* @param document - The Firestore document path to trigger on.
|
|
84
147
|
* @param handler - Event handler which is run every time a Firestore delete occurs.
|
|
85
148
|
*/
|
|
86
149
|
export declare function onDocumentDeleted<Document extends string>(document: Document, handler: (event: FirestoreEvent<QueryDocumentSnapshot | undefined, ParamsOf<Document>>) => any | Promise<any>): CloudFunction<FirestoreEvent<QueryDocumentSnapshot | undefined, ParamsOf<Document>>>;
|
|
87
150
|
/**
|
|
88
|
-
* Event handler
|
|
151
|
+
* Event handler that triggers when a document is deleted in Firestore.
|
|
89
152
|
*
|
|
90
153
|
* @param opts - Options that can be set on an individual event-handling function.
|
|
91
154
|
* @param handler - Event handler which is run every time a Firestore delete occurs.
|
|
92
155
|
*/
|
|
93
156
|
export declare function onDocumentDeleted<Document extends string>(opts: DocumentOptions<Document>, handler: (event: FirestoreEvent<QueryDocumentSnapshot | undefined, ParamsOf<Document>>) => any | Promise<any>): CloudFunction<FirestoreEvent<QueryDocumentSnapshot | undefined, ParamsOf<Document>>>;
|
|
157
|
+
/**
|
|
158
|
+
* Event handler that triggers when a document is deleted in Firestore.
|
|
159
|
+
* This trigger also provides the authentication context of the principal who triggered the event.
|
|
160
|
+
*
|
|
161
|
+
* @param document - The Firestore document path to trigger on.
|
|
162
|
+
* @param handler - Event handler which is run every time a Firestore delete occurs.
|
|
163
|
+
*/
|
|
164
|
+
export declare function onDocumentDeletedWithAuthContext<Document extends string>(document: Document, handler: (event: FirestoreAuthEvent<QueryDocumentSnapshot | undefined, ParamsOf<Document>>) => any | Promise<any>): CloudFunction<FirestoreAuthEvent<QueryDocumentSnapshot | undefined, ParamsOf<Document>>>;
|
|
165
|
+
/**
|
|
166
|
+
* Event handler that triggers when a document is deleted in Firestore.
|
|
167
|
+
* This trigger also provides the authentication context of the principal who triggered the event.
|
|
168
|
+
*
|
|
169
|
+
* @param opts - Options that can be set on an individual event-handling function.
|
|
170
|
+
* @param handler - Event handler which is run every time a Firestore delete occurs.
|
|
171
|
+
*/
|
|
172
|
+
export declare function onDocumentDeletedWithAuthContext<Document extends string>(opts: DocumentOptions<Document>, handler: (event: FirestoreAuthEvent<QueryDocumentSnapshot | undefined, ParamsOf<Document>>) => any | Promise<any>): CloudFunction<FirestoreAuthEvent<QueryDocumentSnapshot | undefined, ParamsOf<Document>>>;
|
|
@@ -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.onChangedOperation = exports.onOperation = exports.makeEndpoint = exports.makeChangedFirestoreEvent = exports.makeFirestoreEvent = exports.makeParams = exports.createBeforeSnapshot = exports.createSnapshot = exports.getOpts = exports.onDocumentDeleted = exports.onDocumentUpdated = exports.onDocumentCreated = exports.onDocumentWritten = exports.deletedEventType = exports.updatedEventType = exports.createdEventType = exports.writtenEventType = exports.Change = void 0;
|
|
24
|
+
exports.onChangedOperation = exports.onOperation = exports.makeEndpoint = exports.makeChangedFirestoreEvent = exports.makeFirestoreEvent = exports.makeParams = exports.createBeforeSnapshot = exports.createSnapshot = exports.getOpts = exports.onDocumentDeletedWithAuthContext = exports.onDocumentDeleted = exports.onDocumentUpdatedWithAuthContext = exports.onDocumentUpdated = exports.onDocumentCreatedWithAuthContext = exports.onDocumentCreated = exports.onDocumentWrittenWithAuthContext = exports.onDocumentWritten = exports.deletedEventWithAuthContextType = exports.updatedEventWithAuthContextType = exports.createdEventWithAuthContextType = exports.writtenEventWithAuthContextType = exports.deletedEventType = exports.updatedEventType = exports.createdEventType = exports.writtenEventType = exports.Change = void 0;
|
|
25
25
|
const logger = require("../../logger");
|
|
26
26
|
const path_1 = require("../../common/utilities/path");
|
|
27
27
|
const path_pattern_1 = require("../../common/utilities/path-pattern");
|
|
@@ -40,8 +40,16 @@ exports.createdEventType = "google.cloud.firestore.document.v1.created";
|
|
|
40
40
|
exports.updatedEventType = "google.cloud.firestore.document.v1.updated";
|
|
41
41
|
/** @internal */
|
|
42
42
|
exports.deletedEventType = "google.cloud.firestore.document.v1.deleted";
|
|
43
|
+
/** @internal */
|
|
44
|
+
exports.writtenEventWithAuthContextType = "google.cloud.firestore.document.v1.written.withAuthContext";
|
|
45
|
+
/** @internal */
|
|
46
|
+
exports.createdEventWithAuthContextType = "google.cloud.firestore.document.v1.created.withAuthContext";
|
|
47
|
+
/** @internal */
|
|
48
|
+
exports.updatedEventWithAuthContextType = "google.cloud.firestore.document.v1.updated.withAuthContext";
|
|
49
|
+
/** @internal */
|
|
50
|
+
exports.deletedEventWithAuthContextType = "google.cloud.firestore.document.v1.deleted.withAuthContext";
|
|
43
51
|
/**
|
|
44
|
-
* Event handler
|
|
52
|
+
* Event handler that triggers when a document is created, updated, or deleted in Firestore.
|
|
45
53
|
*
|
|
46
54
|
* @param documentOrOpts - Options or a string document path.
|
|
47
55
|
* @param handler - Event handler which is run every time a Firestore create, update, or delete occurs.
|
|
@@ -51,7 +59,18 @@ function onDocumentWritten(documentOrOpts, handler) {
|
|
|
51
59
|
}
|
|
52
60
|
exports.onDocumentWritten = onDocumentWritten;
|
|
53
61
|
/**
|
|
54
|
-
* Event handler
|
|
62
|
+
* Event handler that triggers when a document is created, updated, or deleted in Firestore.
|
|
63
|
+
* This trigger also provides the authentication context of the principal who triggered the event.
|
|
64
|
+
*
|
|
65
|
+
* @param opts - Options or a string document path.
|
|
66
|
+
* @param handler - Event handler which is run every time a Firestore create, update, or delete occurs.
|
|
67
|
+
*/
|
|
68
|
+
function onDocumentWrittenWithAuthContext(documentOrOpts, handler) {
|
|
69
|
+
return onChangedOperation(exports.writtenEventWithAuthContextType, documentOrOpts, handler);
|
|
70
|
+
}
|
|
71
|
+
exports.onDocumentWrittenWithAuthContext = onDocumentWrittenWithAuthContext;
|
|
72
|
+
/**
|
|
73
|
+
* Event handler that triggers when a document is created in Firestore.
|
|
55
74
|
*
|
|
56
75
|
* @param documentOrOpts - Options or a string document path.
|
|
57
76
|
* @param handler - Event handler which is run every time a Firestore create occurs.
|
|
@@ -61,7 +80,17 @@ function onDocumentCreated(documentOrOpts, handler) {
|
|
|
61
80
|
}
|
|
62
81
|
exports.onDocumentCreated = onDocumentCreated;
|
|
63
82
|
/**
|
|
64
|
-
* Event handler
|
|
83
|
+
* Event handler that triggers when a document is created in Firestore.
|
|
84
|
+
*
|
|
85
|
+
* @param documentOrOpts - Options or a string document path.
|
|
86
|
+
* @param handler - Event handler which is run every time a Firestore create occurs.
|
|
87
|
+
*/
|
|
88
|
+
function onDocumentCreatedWithAuthContext(documentOrOpts, handler) {
|
|
89
|
+
return onOperation(exports.createdEventWithAuthContextType, documentOrOpts, handler);
|
|
90
|
+
}
|
|
91
|
+
exports.onDocumentCreatedWithAuthContext = onDocumentCreatedWithAuthContext;
|
|
92
|
+
/**
|
|
93
|
+
* Event handler that triggers when a document is updated in Firestore.
|
|
65
94
|
*
|
|
66
95
|
* @param documentOrOpts - Options or a string document path.
|
|
67
96
|
* @param handler - Event handler which is run every time a Firestore update occurs.
|
|
@@ -71,7 +100,17 @@ function onDocumentUpdated(documentOrOpts, handler) {
|
|
|
71
100
|
}
|
|
72
101
|
exports.onDocumentUpdated = onDocumentUpdated;
|
|
73
102
|
/**
|
|
74
|
-
* Event handler
|
|
103
|
+
* Event handler that triggers when a document is updated in Firestore.
|
|
104
|
+
*
|
|
105
|
+
* @param documentOrOpts - Options or a string document path.
|
|
106
|
+
* @param handler - Event handler which is run every time a Firestore update occurs.
|
|
107
|
+
*/
|
|
108
|
+
function onDocumentUpdatedWithAuthContext(documentOrOpts, handler) {
|
|
109
|
+
return onChangedOperation(exports.updatedEventWithAuthContextType, documentOrOpts, handler);
|
|
110
|
+
}
|
|
111
|
+
exports.onDocumentUpdatedWithAuthContext = onDocumentUpdatedWithAuthContext;
|
|
112
|
+
/**
|
|
113
|
+
* Event handler that triggers when a document is deleted in Firestore.
|
|
75
114
|
*
|
|
76
115
|
* @param documentOrOpts - Options or a string document path.
|
|
77
116
|
* @param handler - Event handler which is run every time a Firestore delete occurs.
|
|
@@ -80,6 +119,16 @@ function onDocumentDeleted(documentOrOpts, handler) {
|
|
|
80
119
|
return onOperation(exports.deletedEventType, documentOrOpts, handler);
|
|
81
120
|
}
|
|
82
121
|
exports.onDocumentDeleted = onDocumentDeleted;
|
|
122
|
+
/**
|
|
123
|
+
* Event handler that triggers when a document is deleted in Firestore.
|
|
124
|
+
*
|
|
125
|
+
* @param documentOrOpts - Options or a string document path.
|
|
126
|
+
* @param handler - Event handler which is run every time a Firestore delete occurs.
|
|
127
|
+
*/
|
|
128
|
+
function onDocumentDeletedWithAuthContext(documentOrOpts, handler) {
|
|
129
|
+
return onOperation(exports.deletedEventWithAuthContextType, documentOrOpts, handler);
|
|
130
|
+
}
|
|
131
|
+
exports.onDocumentDeletedWithAuthContext = onDocumentDeletedWithAuthContext;
|
|
83
132
|
/** @internal */
|
|
84
133
|
function getOpts(documentOrOpts) {
|
|
85
134
|
let document;
|
|
@@ -120,10 +169,10 @@ function getPath(event) {
|
|
|
120
169
|
function createSnapshot(event) {
|
|
121
170
|
var _a, _b, _c, _d;
|
|
122
171
|
if (((_a = event.datacontenttype) === null || _a === void 0 ? void 0 : _a.includes("application/protobuf")) || Buffer.isBuffer(event.data)) {
|
|
123
|
-
return (0, firestore_1.createSnapshotFromProtobuf)(event.data, getPath(event));
|
|
172
|
+
return (0, firestore_1.createSnapshotFromProtobuf)(event.data, getPath(event), event.database);
|
|
124
173
|
}
|
|
125
174
|
else if ((_b = event.datacontenttype) === null || _b === void 0 ? void 0 : _b.includes("application/json")) {
|
|
126
|
-
return (0, firestore_1.createSnapshotFromJson)(event.data, event.source, (_c = event.data.value) === null || _c === void 0 ? void 0 : _c.createTime, (_d = event.data.value) === null || _d === void 0 ? void 0 : _d.updateTime);
|
|
175
|
+
return (0, firestore_1.createSnapshotFromJson)(event.data, event.source, (_c = event.data.value) === null || _c === void 0 ? void 0 : _c.createTime, (_d = event.data.value) === null || _d === void 0 ? void 0 : _d.updateTime, event.database);
|
|
127
176
|
}
|
|
128
177
|
else {
|
|
129
178
|
logger.error(`Cannot determine payload type, datacontenttype is ${event.datacontenttype}, failing out.`);
|
|
@@ -135,10 +184,10 @@ exports.createSnapshot = createSnapshot;
|
|
|
135
184
|
function createBeforeSnapshot(event) {
|
|
136
185
|
var _a, _b, _c, _d;
|
|
137
186
|
if (((_a = event.datacontenttype) === null || _a === void 0 ? void 0 : _a.includes("application/protobuf")) || Buffer.isBuffer(event.data)) {
|
|
138
|
-
return (0, firestore_1.createBeforeSnapshotFromProtobuf)(event.data, getPath(event));
|
|
187
|
+
return (0, firestore_1.createBeforeSnapshotFromProtobuf)(event.data, getPath(event), event.database);
|
|
139
188
|
}
|
|
140
189
|
else if ((_b = event.datacontenttype) === null || _b === void 0 ? void 0 : _b.includes("application/json")) {
|
|
141
|
-
return (0, firestore_1.createBeforeSnapshotFromJson)(event.data, event.source, (_c = event.data.oldValue) === null || _c === void 0 ? void 0 : _c.createTime, (_d = event.data.oldValue) === null || _d === void 0 ? void 0 : _d.updateTime);
|
|
190
|
+
return (0, firestore_1.createBeforeSnapshotFromJson)(event.data, event.source, (_c = event.data.oldValue) === null || _c === void 0 ? void 0 : _c.createTime, (_d = event.data.oldValue) === null || _d === void 0 ? void 0 : _d.updateTime, event.database);
|
|
142
191
|
}
|
|
143
192
|
else {
|
|
144
193
|
logger.error(`Cannot determine payload type, datacontenttype is ${event.datacontenttype}, failing out.`);
|
|
@@ -156,7 +205,7 @@ exports.makeParams = makeParams;
|
|
|
156
205
|
/** @internal */
|
|
157
206
|
function makeFirestoreEvent(eventType, event, params) {
|
|
158
207
|
const data = event.data
|
|
159
|
-
? eventType === exports.createdEventType
|
|
208
|
+
? eventType === exports.createdEventType || eventType === exports.createdEventWithAuthContextType
|
|
160
209
|
? createSnapshot(event)
|
|
161
210
|
: createBeforeSnapshot(event)
|
|
162
211
|
: undefined;
|
|
@@ -167,6 +216,16 @@ function makeFirestoreEvent(eventType, event, params) {
|
|
|
167
216
|
};
|
|
168
217
|
delete firestoreEvent.datacontenttype;
|
|
169
218
|
delete firestoreEvent.dataschema;
|
|
219
|
+
if ("authtype" in event) {
|
|
220
|
+
const eventWithAuth = {
|
|
221
|
+
...firestoreEvent,
|
|
222
|
+
authType: event.authtype,
|
|
223
|
+
authId: event.authid,
|
|
224
|
+
};
|
|
225
|
+
delete eventWithAuth.authtype;
|
|
226
|
+
delete eventWithAuth.authid;
|
|
227
|
+
return eventWithAuth;
|
|
228
|
+
}
|
|
170
229
|
return firestoreEvent;
|
|
171
230
|
}
|
|
172
231
|
exports.makeFirestoreEvent = makeFirestoreEvent;
|
|
@@ -182,6 +241,16 @@ function makeChangedFirestoreEvent(event, params) {
|
|
|
182
241
|
};
|
|
183
242
|
delete firestoreEvent.datacontenttype;
|
|
184
243
|
delete firestoreEvent.dataschema;
|
|
244
|
+
if ("authtype" in event) {
|
|
245
|
+
const eventWithAuth = {
|
|
246
|
+
...firestoreEvent,
|
|
247
|
+
authType: event.authtype,
|
|
248
|
+
authId: event.authid,
|
|
249
|
+
};
|
|
250
|
+
delete eventWithAuth.authtype;
|
|
251
|
+
delete eventWithAuth.authid;
|
|
252
|
+
return eventWithAuth;
|
|
253
|
+
}
|
|
185
254
|
return firestoreEvent;
|
|
186
255
|
}
|
|
187
256
|
exports.makeChangedFirestoreEvent = makeChangedFirestoreEvent;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "firebase-functions",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Firebase SDK for Cloud Functions",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"firebase",
|
|
@@ -227,7 +227,7 @@
|
|
|
227
227
|
"eslint-config-prettier": "^8.3.0",
|
|
228
228
|
"eslint-plugin-jsdoc": "^39.2.9",
|
|
229
229
|
"eslint-plugin-prettier": "^4.0.0",
|
|
230
|
-
"firebase-admin": "^12.
|
|
230
|
+
"firebase-admin": "^12.1.0",
|
|
231
231
|
"js-yaml": "^3.13.1",
|
|
232
232
|
"jsdom": "^16.2.1",
|
|
233
233
|
"jsonwebtoken": "^9.0.0",
|
|
@@ -247,7 +247,7 @@
|
|
|
247
247
|
"yargs": "^15.3.1"
|
|
248
248
|
},
|
|
249
249
|
"peerDependencies": {
|
|
250
|
-
"firebase-admin": "^
|
|
250
|
+
"firebase-admin": "^11.10.0 || ^12.0.0"
|
|
251
251
|
},
|
|
252
252
|
"engines": {
|
|
253
253
|
"node": ">=14.10.0"
|