@quatrain/cloudwrapper-firebase 1.1.15 → 1.1.16
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/dist/FirebaseCloudWrapper.d.ts +17 -0
- package/dist/FirebaseCloudWrapper.js +72 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -0
- package/package.json +43 -43
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { HttpsFunction, HttpsOptions } from 'firebase-functions/v2/https';
|
|
2
|
+
import { CloudFunction } from 'firebase-functions/v2';
|
|
3
|
+
import { AbstractCloudWrapper } from '@quatrain/cloudwrapper';
|
|
4
|
+
import { BackendAction } from '@quatrain/backend';
|
|
5
|
+
export type FirebaseParams = {
|
|
6
|
+
region?: string[];
|
|
7
|
+
useEmulator?: boolean;
|
|
8
|
+
projectId?: string;
|
|
9
|
+
serviceAccount?: string;
|
|
10
|
+
};
|
|
11
|
+
export declare class FirebaseCloudWrapper extends AbstractCloudWrapper {
|
|
12
|
+
protected _isInitialized: boolean;
|
|
13
|
+
constructor(params: FirebaseParams);
|
|
14
|
+
httpsTrigger(func: any, params?: HttpsOptions): HttpsFunction;
|
|
15
|
+
storageTrigger(func: any, eventType: BackendAction): CloudFunction<import("firebase-functions/v2/storage").StorageEvent>;
|
|
16
|
+
protected _initialize(): void;
|
|
17
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.FirebaseCloudWrapper = void 0;
|
|
13
|
+
const app_1 = require("firebase-admin/app");
|
|
14
|
+
const firebase_admin_1 = require("firebase-admin");
|
|
15
|
+
const https_1 = require("firebase-functions/v2/https");
|
|
16
|
+
const v2_1 = require("firebase-functions/v2");
|
|
17
|
+
const storage_1 = require("firebase-functions/v2/storage");
|
|
18
|
+
const cloudwrapper_1 = require("@quatrain/cloudwrapper");
|
|
19
|
+
const backend_1 = require("@quatrain/backend");
|
|
20
|
+
class FirebaseCloudWrapper extends cloudwrapper_1.AbstractCloudWrapper {
|
|
21
|
+
constructor(params) {
|
|
22
|
+
super(params);
|
|
23
|
+
this._isInitialized = false;
|
|
24
|
+
const { useEmulator, region } = params;
|
|
25
|
+
if (useEmulator === false && region) {
|
|
26
|
+
(0, v2_1.setGlobalOptions)({ region: region.join(',') });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
httpsTrigger(func, params = { memory: '4GiB', timeoutSeconds: 500 }) {
|
|
30
|
+
this._initialize();
|
|
31
|
+
return (0, https_1.onRequest)(Object.assign({ concurrency: 500 }, params), func);
|
|
32
|
+
}
|
|
33
|
+
// databaseTrigger(trigger: DatabaseTriggerType): CloudFunction<any> {
|
|
34
|
+
// this._initialize()
|
|
35
|
+
// switch (trigger.event) {
|
|
36
|
+
// case BackendAction.CREATE:
|
|
37
|
+
// return onDocumentCreated(trigger.path, trigger.script)
|
|
38
|
+
// case BackendAction.UPDATE:
|
|
39
|
+
// return onDocumentUpdated(trigger.path, trigger.script)
|
|
40
|
+
// case BackendAction.DELETE:
|
|
41
|
+
// return onDocumentDeleted(trigger.path, trigger.script)
|
|
42
|
+
// case BackendAction.WRITE:
|
|
43
|
+
// return onDocumentWritten(trigger.path, trigger.script)
|
|
44
|
+
// default:
|
|
45
|
+
// throw new Error(`Unknown event type '${trigger.event}'`)
|
|
46
|
+
// }
|
|
47
|
+
// }
|
|
48
|
+
storageTrigger(func, eventType) {
|
|
49
|
+
this._initialize();
|
|
50
|
+
switch (eventType) {
|
|
51
|
+
case backend_1.BackendAction.CREATE:
|
|
52
|
+
return (0, storage_1.onObjectFinalized)((object) => __awaiter(this, void 0, void 0, function* () { return yield func(object); }));
|
|
53
|
+
default:
|
|
54
|
+
throw new Error(`Unknown event type '${eventType}'`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
_initialize() {
|
|
58
|
+
if (this._isInitialized === false) {
|
|
59
|
+
const { projectId, serviceAccount } = this._params;
|
|
60
|
+
cloudwrapper_1.CloudWrapper.log(`[FCW] Firebase App init for project ${projectId}`);
|
|
61
|
+
//if (this._params.useEmulator === true) {
|
|
62
|
+
// if emulator is active, we need a service account to access storage functions
|
|
63
|
+
// @see bin/setServiceAccountPath.sh
|
|
64
|
+
const config = Object.assign(Object.assign({}, (serviceAccount && {
|
|
65
|
+
credential: firebase_admin_1.credential.cert(require(serviceAccount)),
|
|
66
|
+
})), (projectId && { projectId }));
|
|
67
|
+
(0, app_1.initializeApp)(config);
|
|
68
|
+
this._isInitialized = true;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.FirebaseCloudWrapper = FirebaseCloudWrapper;
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FirebaseCloudWrapper = void 0;
|
|
4
|
+
const FirebaseCloudWrapper_1 = require("./FirebaseCloudWrapper");
|
|
5
|
+
Object.defineProperty(exports, "FirebaseCloudWrapper", { enumerable: true, get: function () { return FirebaseCloudWrapper_1.FirebaseCloudWrapper; } });
|
package/package.json
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
2
|
+
"name": "@quatrain/cloudwrapper-firebase",
|
|
3
|
+
"version": "1.1.16",
|
|
4
|
+
"license": "AGPL-3.0-only",
|
|
5
|
+
"description": "Cloud Wrapper adapter for Firebase",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"bun": "src/index.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"LICENSE.md",
|
|
11
|
+
"src/",
|
|
12
|
+
"dist/",
|
|
13
|
+
"README.md"
|
|
14
|
+
],
|
|
15
|
+
"author": "Quatrain Développement SAS <developers@quatrain.com>",
|
|
16
|
+
"peerDependencies": {
|
|
17
|
+
"@quatrain/core": "^1.1.44"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@quatrain/backend": "^1.1.29",
|
|
21
|
+
"@quatrain/cloudwrapper": "^1.1.18",
|
|
22
|
+
"@quatrain/core": "^1.1.44",
|
|
23
|
+
"firebase-admin": "^13.4.0",
|
|
24
|
+
"firebase-functions": "^6.4.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@tsconfig/recommended": "^1.0.1",
|
|
28
|
+
"@types/jest": "^27.0.3",
|
|
29
|
+
"@types/pg": "^8.11.4",
|
|
30
|
+
"jest": "^30.2.0",
|
|
31
|
+
"jest-node-exports-resolver": "^1.1.6",
|
|
32
|
+
"jest-serial-runner": "^1.2.1",
|
|
33
|
+
"trace-unhandled": "^2.0.1",
|
|
34
|
+
"ts-jest": "^27.1.2",
|
|
35
|
+
"ts-node": "^10.9.1",
|
|
36
|
+
"typescript": "^5.1.5"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"test-ci": "jest --runInBand",
|
|
40
|
+
"build": "tsc",
|
|
41
|
+
"wbuild": "tsc --watch",
|
|
42
|
+
"bump-to": "yarn version"
|
|
43
|
+
}
|
|
44
|
+
}
|