@quatrain/cloudwrapper-firebase 1.1.12 → 1.1.13
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/LICENSE.md +15 -0
- package/README.md +24 -0
- package/package.json +43 -42
- package/src/FirebaseCloudWrapper.ts +98 -0
- package/src/index.ts +3 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# LICENSE UPDATE NOTICE
|
|
2
|
+
|
|
3
|
+
As of 01/01/2026, Quatrain Core is licensed under the **GNU Affero General Public License v3.0 (AGPL v3)**.
|
|
4
|
+
Previous versions remain under the MIT License.
|
|
5
|
+
|
|
6
|
+
## Why AGPL?
|
|
7
|
+
|
|
8
|
+
We believe in open collaboration for the development ecosystem. The AGPL ensures that any modification or deployment of this BaaS stack, including over a network, benefits the entire community.
|
|
9
|
+
|
|
10
|
+
## Commercial Services & Enterprise Usage
|
|
11
|
+
|
|
12
|
+
We provide official deployment services, technical training, and certification for Quatrain Core.
|
|
13
|
+
For organizations requiring a non-copyleft license (commercial license) or custom proprietary integrations, please contact the copyright holder: **Quatrain Technologies**.
|
|
14
|
+
|
|
15
|
+
Copyright © 2024-2026 Quatrain Technologies. All Rights Reserved.
|
package/README.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# @quatrain/cloudwrapper-firebase
|
|
2
|
+
|
|
3
|
+
This package provides a Cloud Wrapper adapter for Firebase Functions. It allows you to invoke serverless functions in a consistent way across different BaaS providers.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Invokes Firebase Functions (2nd gen).
|
|
8
|
+
- Consistent interface provided by `@quatrain/cloudwrapper`.
|
|
9
|
+
- Uses the Firebase Admin SDK for secure, server-to-server calls.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @quatrain/cloudwrapper-firebase firebase-admin
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { CloudWrapper } from '@quatrain/cloudwrapper'
|
|
21
|
+
import { FirebaseCloudWrapperAdapter } from '@quatrain/cloudwrapper-firebase'
|
|
22
|
+
|
|
23
|
+
// Setup and use the adapter with the CloudWrapper singleton.
|
|
24
|
+
```
|
package/package.json
CHANGED
|
@@ -1,43 +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
|
-
}
|
|
2
|
+
"name": "@quatrain/cloudwrapper-firebase",
|
|
3
|
+
"version": "1.1.13",
|
|
4
|
+
"license": "AGPL-3.0-only",
|
|
5
|
+
"description": "Cloud Wrapper adapter for Firebase",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"types": "lib/index.d.ts",
|
|
8
|
+
"bun": "src/index.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"LICENSE.md",
|
|
11
|
+
"src/",
|
|
12
|
+
"lib/",
|
|
13
|
+
"README.md"
|
|
14
|
+
],
|
|
15
|
+
"author": "Quatrain Développement SAS <developers@quatrain.com>",
|
|
16
|
+
"peerDependencies": {
|
|
17
|
+
"@quatrain/core": "^1.1.42"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@quatrain/backend": "^1.1.26",
|
|
21
|
+
"@quatrain/cloudwrapper": "^1.1.15",
|
|
22
|
+
"@quatrain/core": "^1.1.42",
|
|
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
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { initializeApp } from 'firebase-admin/app'
|
|
2
|
+
import { credential } from 'firebase-admin'
|
|
3
|
+
import {
|
|
4
|
+
HttpsFunction,
|
|
5
|
+
HttpsOptions,
|
|
6
|
+
onRequest,
|
|
7
|
+
} from 'firebase-functions/v2/https'
|
|
8
|
+
import {
|
|
9
|
+
onDocumentWritten,
|
|
10
|
+
onDocumentCreated,
|
|
11
|
+
onDocumentUpdated,
|
|
12
|
+
onDocumentDeleted,
|
|
13
|
+
} from 'firebase-functions/v2/firestore'
|
|
14
|
+
import { CloudFunction, setGlobalOptions } from 'firebase-functions/v2'
|
|
15
|
+
import { onObjectFinalized } from 'firebase-functions/v2/storage'
|
|
16
|
+
import {
|
|
17
|
+
CloudWrapper,
|
|
18
|
+
AbstractCloudWrapper,
|
|
19
|
+
DatabaseTriggerType,
|
|
20
|
+
} from '@quatrain/cloudwrapper'
|
|
21
|
+
import { BackendAction } from '@quatrain/backend'
|
|
22
|
+
|
|
23
|
+
export type FirebaseParams = {
|
|
24
|
+
region?: string[]
|
|
25
|
+
useEmulator?: boolean
|
|
26
|
+
projectId?: string
|
|
27
|
+
serviceAccount?: string
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class FirebaseCloudWrapper extends AbstractCloudWrapper {
|
|
31
|
+
protected _isInitialized = false
|
|
32
|
+
|
|
33
|
+
constructor(params: FirebaseParams) {
|
|
34
|
+
super(params)
|
|
35
|
+
const { useEmulator, region } = params
|
|
36
|
+
if (useEmulator === false && region) {
|
|
37
|
+
setGlobalOptions({ region: region.join(',') })
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
httpsTrigger(
|
|
42
|
+
func: any,
|
|
43
|
+
params: HttpsOptions = { memory: '4GiB', timeoutSeconds: 500 }
|
|
44
|
+
): HttpsFunction {
|
|
45
|
+
this._initialize()
|
|
46
|
+
return onRequest(
|
|
47
|
+
{
|
|
48
|
+
concurrency: 500,
|
|
49
|
+
...params,
|
|
50
|
+
},
|
|
51
|
+
func
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// databaseTrigger(trigger: DatabaseTriggerType): CloudFunction<any> {
|
|
56
|
+
// this._initialize()
|
|
57
|
+
// switch (trigger.event) {
|
|
58
|
+
// case BackendAction.CREATE:
|
|
59
|
+
// return onDocumentCreated(trigger.path, trigger.script)
|
|
60
|
+
// case BackendAction.UPDATE:
|
|
61
|
+
// return onDocumentUpdated(trigger.path, trigger.script)
|
|
62
|
+
// case BackendAction.DELETE:
|
|
63
|
+
// return onDocumentDeleted(trigger.path, trigger.script)
|
|
64
|
+
// case BackendAction.WRITE:
|
|
65
|
+
// return onDocumentWritten(trigger.path, trigger.script)
|
|
66
|
+
// default:
|
|
67
|
+
// throw new Error(`Unknown event type '${trigger.event}'`)
|
|
68
|
+
// }
|
|
69
|
+
// }
|
|
70
|
+
|
|
71
|
+
storageTrigger(func: any, eventType: BackendAction) {
|
|
72
|
+
this._initialize()
|
|
73
|
+
switch (eventType) {
|
|
74
|
+
case BackendAction.CREATE:
|
|
75
|
+
return onObjectFinalized(async (object: any) => await func(object))
|
|
76
|
+
default:
|
|
77
|
+
throw new Error(`Unknown event type '${eventType}'`)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
protected _initialize() {
|
|
82
|
+
if (this._isInitialized === false) {
|
|
83
|
+
const { projectId, serviceAccount } = this._params
|
|
84
|
+
CloudWrapper.log(`[FCW] Firebase App init for project ${projectId}`)
|
|
85
|
+
//if (this._params.useEmulator === true) {
|
|
86
|
+
// if emulator is active, we need a service account to access storage functions
|
|
87
|
+
// @see bin/setServiceAccountPath.sh
|
|
88
|
+
const config = {
|
|
89
|
+
...(serviceAccount && {
|
|
90
|
+
credential: credential.cert(require(serviceAccount)),
|
|
91
|
+
}),
|
|
92
|
+
...(projectId && { projectId }),
|
|
93
|
+
}
|
|
94
|
+
initializeApp(config)
|
|
95
|
+
this._isInitialized = true
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
package/src/index.ts
ADDED