@quatrain/cloudwrapper-firebase 0.1.1 → 0.1.3
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.
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import { HttpsOptions } from 'firebase-functions/v2/https';
|
|
1
|
+
import { HttpsFunction, HttpsOptions } from 'firebase-functions/v2/https';
|
|
2
2
|
import { AbstractCloudWrapper, BackendAction } from '@quatrain/core';
|
|
3
3
|
export type FirebaseParams = {
|
|
4
4
|
region?: string;
|
|
5
5
|
useEmulator?: boolean;
|
|
6
|
+
projectId?: string;
|
|
7
|
+
serviceAccount?: string;
|
|
6
8
|
};
|
|
7
9
|
export declare class FirebaseCloudWrapper extends AbstractCloudWrapper {
|
|
8
10
|
protected _isInitialized: boolean;
|
|
9
11
|
constructor(params: FirebaseParams);
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
httpsTrigger(func: any, params?: HttpsOptions): HttpsFunction;
|
|
13
|
+
databaseTrigger(func: any, eventType: BackendAction, rule?: string): import("firebase-functions/v2").CloudFunction<import("firebase-functions/v2/firestore").FirestoreEvent<import("firebase-functions/v2/firestore").QueryDocumentSnapshot | undefined, Record<string, string>>> | import("firebase-functions/v2").CloudFunction<import("firebase-functions/v2/firestore").FirestoreEvent<import("firebase-functions/v2").Change<import("firebase-functions/v2/firestore").QueryDocumentSnapshot> | undefined, Record<string, string>>>;
|
|
12
14
|
protected _initialize(): void;
|
|
13
15
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FirebaseCloudWrapper = void 0;
|
|
4
4
|
const app_1 = require("firebase-admin/app");
|
|
5
|
+
const firebase_admin_1 = require("firebase-admin");
|
|
5
6
|
const https_1 = require("firebase-functions/v2/https");
|
|
6
7
|
const firestore_1 = require("firebase-functions/v2/firestore");
|
|
7
8
|
const v2_1 = require("firebase-functions/v2");
|
|
@@ -15,11 +16,11 @@ class FirebaseCloudWrapper extends core_1.AbstractCloudWrapper {
|
|
|
15
16
|
(0, v2_1.setGlobalOptions)({ region });
|
|
16
17
|
}
|
|
17
18
|
}
|
|
18
|
-
|
|
19
|
+
httpsTrigger(func, params = { memory: '4GiB', timeoutSeconds: 500 }) {
|
|
19
20
|
this._initialize();
|
|
20
21
|
return (0, https_1.onRequest)(Object.assign({ concurrency: 500 }, params), func);
|
|
21
22
|
}
|
|
22
|
-
|
|
23
|
+
databaseTrigger(func, eventType, rule = '') {
|
|
23
24
|
this._initialize();
|
|
24
25
|
switch (eventType) {
|
|
25
26
|
case core_1.BackendAction.CREATE:
|
|
@@ -34,19 +35,21 @@ class FirebaseCloudWrapper extends core_1.AbstractCloudWrapper {
|
|
|
34
35
|
throw new Error(`Unknown event type '${eventType}'`);
|
|
35
36
|
}
|
|
36
37
|
}
|
|
38
|
+
// getConfig(key?:string) {
|
|
39
|
+
// const config = functions.config()
|
|
40
|
+
// return key ? config[key] : config
|
|
41
|
+
// }
|
|
37
42
|
_initialize() {
|
|
38
43
|
if (this._isInitialized === false) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
(0, app_1.initializeApp)();
|
|
49
|
-
}
|
|
44
|
+
const { projectId, serviceAccount } = this._params;
|
|
45
|
+
core_1.Core.log(`[FCW] Firebase App init for project ${projectId}`);
|
|
46
|
+
//if (this._params.useEmulator === true) {
|
|
47
|
+
// if emulator is active, we need a service account to access storage functions
|
|
48
|
+
// @see bin/setServiceAccountPath.sh
|
|
49
|
+
const config = Object.assign(Object.assign({}, (serviceAccount && {
|
|
50
|
+
credential: firebase_admin_1.credential.cert(require(serviceAccount)),
|
|
51
|
+
})), (projectId && { projectId }));
|
|
52
|
+
(0, app_1.initializeApp)(config);
|
|
50
53
|
this._isInitialized = true;
|
|
51
54
|
}
|
|
52
55
|
}
|