@flowerforce/flowerbase 1.0.1-beta.13 → 1.0.1-beta.15
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/README.md +228 -95
- package/dist/auth/controller.d.ts.map +1 -1
- package/dist/auth/controller.js +3 -1
- package/dist/auth/providers/local-userpass/controller.d.ts.map +1 -1
- package/dist/auth/providers/local-userpass/controller.js +15 -15
- package/dist/auth/utils.d.ts +2 -1
- package/dist/auth/utils.d.ts.map +1 -1
- package/dist/auth/utils.js +9 -8
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +3 -3
- package/dist/features/functions/controller.d.ts.map +1 -1
- package/dist/features/functions/controller.js +9 -6
- package/dist/features/functions/dtos.d.ts +1 -1
- package/dist/features/functions/dtos.d.ts.map +1 -1
- package/dist/features/functions/interface.d.ts +1 -1
- package/dist/features/functions/utils.d.ts.map +1 -1
- package/dist/features/functions/utils.js +2 -2
- package/dist/features/triggers/index.d.ts.map +1 -1
- package/dist/features/triggers/index.js +9 -3
- package/dist/features/triggers/interface.d.ts +4 -4
- package/dist/features/triggers/interface.d.ts.map +1 -1
- package/dist/features/triggers/utils.d.ts.map +1 -1
- package/dist/features/triggers/utils.js +10 -5
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/model.d.ts.map +1 -1
- package/dist/services/api/index.d.ts.map +1 -1
- package/dist/services/api/index.js +6 -1
- package/dist/services/aws/index.d.ts.map +1 -1
- package/dist/services/aws/index.js +5 -5
- package/dist/services/index.d.ts.map +1 -1
- package/dist/services/mongodb-atlas/index.d.ts.map +1 -1
- package/dist/services/mongodb-atlas/index.js +76 -71
- package/dist/services/mongodb-atlas/model.d.ts +3 -3
- package/dist/services/mongodb-atlas/model.d.ts.map +1 -1
- package/dist/services/mongodb-atlas/utils.d.ts.map +1 -1
- package/dist/state.d.ts +2 -2
- package/dist/state.d.ts.map +1 -1
- package/dist/utils/context/helpers.d.ts.map +1 -1
- package/dist/utils/context/helpers.js +1 -1
- package/dist/utils/context/index.d.ts.map +1 -1
- package/dist/utils/helpers/someAsync.d.ts.map +1 -1
- package/dist/utils/initializer/exposeRoutes.d.ts.map +1 -1
- package/dist/utils/initializer/exposeRoutes.js +44 -1
- package/dist/utils/initializer/registerPlugins.d.ts.map +1 -1
- package/dist/utils/initializer/registerPlugins.js +8 -8
- package/dist/utils/roles/helpers.d.ts.map +1 -1
- package/dist/utils/roles/helpers.js +9 -7
- package/dist/utils/roles/interface.d.ts.map +1 -1
- package/dist/utils/roles/machines/commonValidators.d.ts +2 -2
- package/dist/utils/roles/machines/commonValidators.d.ts.map +1 -1
- package/dist/utils/roles/machines/commonValidators.js +5 -6
- package/dist/utils/roles/machines/index.d.ts.map +1 -1
- package/dist/utils/roles/machines/interface.d.ts.map +1 -1
- package/dist/utils/roles/machines/machine.d.ts +3 -3
- package/dist/utils/roles/machines/machine.d.ts.map +1 -1
- package/dist/utils/roles/machines/machine.js +12 -4
- package/dist/utils/roles/machines/read/A/index.d.ts.map +1 -1
- package/dist/utils/roles/machines/read/A/index.js +12 -2
- package/dist/utils/roles/machines/read/B/index.d.ts.map +1 -1
- package/dist/utils/roles/machines/read/B/index.js +20 -5
- package/dist/utils/roles/machines/read/C/index.d.ts.map +1 -1
- package/dist/utils/roles/machines/read/C/index.js +20 -5
- package/dist/utils/roles/machines/read/D/index.d.ts.map +1 -1
- package/dist/utils/roles/machines/read/D/index.js +13 -3
- package/dist/utils/roles/machines/read/D/validators.d.ts +1 -1
- package/dist/utils/roles/machines/read/D/validators.d.ts.map +1 -1
- package/dist/utils/roles/machines/read/D/validators.js +8 -4
- package/dist/utils/roles/machines/utils.d.ts +4 -4
- package/dist/utils/roles/machines/utils.d.ts.map +1 -1
- package/dist/utils/roles/machines/utils.js +5 -1
- package/dist/utils/roles/machines/write/A/index.d.ts.map +1 -1
- package/dist/utils/roles/machines/write/A/index.js +13 -3
- package/dist/utils/roles/machines/write/B/index.d.ts.map +1 -1
- package/dist/utils/roles/machines/write/B/index.js +37 -10
- package/dist/utils/roles/machines/write/C/index.d.ts.map +1 -1
- package/dist/utils/roles/machines/write/C/index.js +13 -3
- package/dist/utils/roles/machines/write/C/validators.d.ts +1 -1
- package/dist/utils/roles/machines/write/C/validators.d.ts.map +1 -1
- package/dist/utils/roles/machines/write/C/validators.js +8 -4
- package/dist/utils/rules-matcher/interface.d.ts.map +1 -1
- package/dist/utils/rules-matcher/utils.d.ts.map +1 -1
- package/dist/utils/rules.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/auth/controller.ts +3 -1
- package/src/auth/providers/local-userpass/controller.ts +47 -39
- package/src/auth/providers/local-userpass/dtos.ts +1 -1
- package/src/auth/utils.ts +19 -16
- package/src/constants.ts +7 -3
- package/src/features/functions/controller.ts +20 -20
- package/src/features/functions/dtos.ts +8 -9
- package/src/features/functions/interface.ts +1 -1
- package/src/features/functions/utils.ts +9 -10
- package/src/features/triggers/index.ts +9 -6
- package/src/features/triggers/interface.ts +9 -10
- package/src/features/triggers/utils.ts +42 -20
- package/src/index.ts +8 -6
- package/src/model.ts +1 -1
- package/src/services/api/index.ts +6 -1
- package/src/services/aws/index.ts +19 -17
- package/src/services/mongodb-atlas/index.ts +204 -163
- package/src/services/mongodb-atlas/model.ts +13 -13
- package/src/services/mongodb-atlas/utils.ts +6 -4
- package/src/state.ts +32 -20
- package/src/utils/__tests__/STEP_A_STATES.test.ts +78 -47
- package/src/utils/__tests__/STEP_B_STATES.test.ts +168 -105
- package/src/utils/__tests__/STEP_C_STATES.test.ts +150 -78
- package/src/utils/__tests__/STEP_D_STATES.test.ts +129 -86
- package/src/utils/__tests__/checkAdditionalFieldsFn.test.ts +35 -35
- package/src/utils/__tests__/checkApplyWhen.test.ts +40 -41
- package/src/utils/__tests__/checkFieldsPropertyExists.test.ts +40 -40
- package/src/utils/__tests__/checkIsValidFieldNameFn.test.ts +185 -184
- package/src/utils/__tests__/comparePassword.test.ts +27 -30
- package/src/utils/__tests__/evaluateDocumentsFiltersReadFn.test.ts +55 -47
- package/src/utils/__tests__/evaluateDocumentsFiltersWriteFn.test.ts +61 -47
- package/src/utils/__tests__/evaluateTopLevelReadFn.test.ts +48 -48
- package/src/utils/__tests__/evaluateTopLevelWriteFn.test.ts +56 -56
- package/src/utils/__tests__/exposeRoutes.test.ts +46 -44
- package/src/utils/__tests__/generateContextData.test.ts +57 -51
- package/src/utils/__tests__/getDefaultRule.test.ts +32 -27
- package/src/utils/__tests__/getKey.test.ts +10 -10
- package/src/utils/__tests__/getKeys.test.ts +10 -9
- package/src/utils/__tests__/getWinningRole.test.ts +57 -50
- package/src/utils/__tests__/hashPassword.test.ts +24 -25
- package/src/utils/__tests__/isEmpty.test.ts +14 -15
- package/src/utils/__tests__/logMachineInfo.test.ts +12 -12
- package/src/utils/__tests__/operators.test.ts +94 -96
- package/src/utils/__tests__/readFileContent.test.ts +28 -28
- package/src/utils/__tests__/registerPlugins.test.ts +44 -32
- package/src/utils/__tests__/rule.test.ts +47 -49
- package/src/utils/__tests__/rulesMatcherInterfaces.test.ts +57 -52
- package/src/utils/__tests__/rulesMatcherUtils.test.ts +64 -53
- package/src/utils/__tests__/someAsync.test.ts +46 -49
- package/src/utils/context/helpers.ts +1 -1
- package/src/utils/context/index.ts +1 -2
- package/src/utils/crypto/index.ts +2 -2
- package/src/utils/helpers/someAsync.ts +11 -11
- package/src/utils/initializer/exposeRoutes.ts +56 -2
- package/src/utils/initializer/registerPlugins.ts +10 -12
- package/src/utils/roles/helpers.ts +22 -15
- package/src/utils/roles/interface.ts +2 -3
- package/src/utils/roles/machines/commonValidators.ts +23 -14
- package/src/utils/roles/machines/index.ts +7 -4
- package/src/utils/roles/machines/interface.ts +17 -5
- package/src/utils/roles/machines/machine.ts +97 -72
- package/src/utils/roles/machines/read/A/index.ts +12 -4
- package/src/utils/roles/machines/read/B/index.ts +20 -7
- package/src/utils/roles/machines/read/C/index.ts +24 -8
- package/src/utils/roles/machines/read/D/index.ts +14 -8
- package/src/utils/roles/machines/read/D/validators.ts +21 -13
- package/src/utils/roles/machines/read/index.ts +5 -5
- package/src/utils/roles/machines/utils.ts +30 -13
- package/src/utils/roles/machines/write/A/index.ts +13 -5
- package/src/utils/roles/machines/write/B/index.ts +42 -16
- package/src/utils/roles/machines/write/C/index.ts +14 -8
- package/src/utils/roles/machines/write/C/validators.ts +21 -13
- package/src/utils/roles/machines/write/index.ts +4 -4
- package/src/utils/rules-matcher/interface.ts +4 -4
- package/src/utils/rules-matcher/utils.ts +10 -6
- package/src/utils/rules.ts +12 -5
package/README.md
CHANGED
|
@@ -1,12 +1,38 @@
|
|
|
1
1
|
# flowerbase
|
|
2
2
|
|
|
3
|
-
> **A serverless-native MongoDB package designed for modern cloud applications
|
|
3
|
+
> **A serverless-native MongoDB package designed for modern cloud applications**
|
|
4
4
|
|
|
5
|
+
Unlike MongoDB Realm or other cloud platforms, we do not offer a graphical interface where you can configure services through a dashboard.
|
|
6
|
+
Instead, everything is code-based and developer-driven, offering full flexibility through configuration files and source code.
|
|
5
7
|
|
|
8
|
+
This documentation is structured to guide both experienced Realm users and newcomers alike — whether you’re migrating or starting clean.
|
|
9
|
+
|
|
10
|
+
#### 🧠 Features Summary
|
|
11
|
+
| Feature | Status |
|
|
12
|
+
|--------------------------|-----------------------------------------|
|
|
13
|
+
| Realm-compatible schema | ✅ Supported (unchanged) |
|
|
14
|
+
| Authentication strategy | ✅ Local Email/Password only |
|
|
15
|
+
| OAuth / API Keys / etc. | 🚫 Not supported (for now) |
|
|
16
|
+
| User data accessibility | ✅ Stored in your main DB |
|
|
17
|
+
| Device Sync | 🚫 Not supported (for now) |
|
|
18
|
+
| Functions | ✅ Supported (unchanged) |
|
|
19
|
+
| Triggers | ✅ Supported (unchanged) |
|
|
20
|
+
| HTTP Endpoints | ✅ Supported (unchanged) |
|
|
6
21
|
|
|
7
|
-
## 🗂️ MongoDB Atlas Migration Guide
|
|
8
22
|
|
|
9
|
-
|
|
23
|
+
|
|
24
|
+
> ⚠️ **Already have an existing Realm project?**
|
|
25
|
+
> You can skip ahead to the [Migration Guide](#migration) to quickly adapt your project to Flowerbase.
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
## 🚀 Creating a New Project from Scratch
|
|
29
|
+
|
|
30
|
+
If you're starting fresh, you’ll learn how to:
|
|
31
|
+
|
|
32
|
+
- Scaffold a minimal Node.js + TypeScript backend
|
|
33
|
+
- Install and configure `@flowerforce/flowerbase`
|
|
34
|
+
- Set up authentication, data models, rules, and custom logic
|
|
35
|
+
- Deploy your app and connect it to any frontend (React, Vue, mobile, etc.)
|
|
10
36
|
|
|
11
37
|
## 📁 1. Project Setup
|
|
12
38
|
|
|
@@ -42,6 +68,17 @@ touch src/index.ts
|
|
|
42
68
|
## 🌿 3. Environment Variables
|
|
43
69
|
Ensure the following environment variables are set in your .env file or deployment environment:
|
|
44
70
|
|
|
71
|
+
|
|
72
|
+
| Variable | Description | Example |
|
|
73
|
+
| ---------------------- | --------------------------------------------------------------------------- | -------------------------------------------------- |
|
|
74
|
+
| `PROJECT_ID` | A unique ID to identify your project. This value can be freely invented — it's preserved mainly for compatibility with the old Realm-style project structure. | `my-flowerbase-app` |
|
|
75
|
+
| `PORT` | The port on which the server will run. | `3000` |
|
|
76
|
+
| `DB_CONNECTION_STRING` | MongoDB connection URI, including username, password, and database name. | `mongodb+srv://user:pass@cluster.mongodb.net/mydb` |
|
|
77
|
+
| `APP_SECRET` | Secret used to sign and verify JWT tokens (choose a strong secret). | `supersecretkey123!` |
|
|
78
|
+
| `HOST` | The host address the server binds to (usually `0.0.0.0` for public access). | `0.0.0.0` |
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
Example:
|
|
45
82
|
```env
|
|
46
83
|
PROJECT_ID=your-project-id
|
|
47
84
|
PORT=3000
|
|
@@ -50,26 +87,6 @@ APP_SECRET=your-jwt-secret
|
|
|
50
87
|
HOST=0.0.0.0
|
|
51
88
|
```
|
|
52
89
|
|
|
53
|
-
#### 🔹 projectId
|
|
54
|
-
- `Purpose`: Serves as a unique identifier for your project within the Flowerbase ecosystem.
|
|
55
|
-
|
|
56
|
-
- `Requirement`: This value is user-defined; you must create a unique string to identify your project.
|
|
57
|
-
|
|
58
|
-
> Example:
|
|
59
|
-
```env
|
|
60
|
-
PROJECT_ID=my-cool-app-5678
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
#### 🔹 jwtSecret
|
|
64
|
-
- `Purpose`: Used as the secret key for signing and verifying JSON Web Tokens (JWTs) in your application, ensuring secure authentication.
|
|
65
|
-
|
|
66
|
-
- `Requirement`: This is a user-defined secret; you must generate a secure, random string.
|
|
67
|
-
|
|
68
|
-
> Example:
|
|
69
|
-
```env
|
|
70
|
-
APP_SECRET=supersecurejwtsecret987
|
|
71
|
-
```
|
|
72
|
-
|
|
73
90
|
🛡️ Note: Never commit .env files to source control. Use a .gitignore file to exclude it.
|
|
74
91
|
|
|
75
92
|
|
|
@@ -79,7 +96,7 @@ In your index.ts file, import the initialize function from the `@flowerforce/flo
|
|
|
79
96
|
```ts
|
|
80
97
|
// src/index.ts
|
|
81
98
|
|
|
82
|
-
import { initialize } from '@
|
|
99
|
+
import { initialize } from '@flowerforce/flowerbase';
|
|
83
100
|
|
|
84
101
|
initialize({
|
|
85
102
|
projectId: process.env.PROJECT_ID,
|
|
@@ -143,68 +160,17 @@ After setting up the base Flowerbase integration, you can now configure advanced
|
|
|
143
160
|
└── 📄 .env
|
|
144
161
|
```
|
|
145
162
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
If you're using TypeScript:
|
|
156
|
-
|
|
157
|
-
```bash
|
|
158
|
-
npx tsc
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
Or if you're using a bundler like esbuild:
|
|
162
|
-
|
|
163
|
-
```bash
|
|
164
|
-
npx esbuild src/index.ts --bundle --outfile=dist/index.js
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
You can deploy the application using any Node.js-compatible platform.
|
|
168
|
-
Once deployed, you'll receive a public URL (e.g. https://your-app-name.up.example.app).
|
|
163
|
+
#### 📖 Structure summary
|
|
164
|
+
| Area | Description | Link |
|
|
165
|
+
| ---------------------- | ------------------------------------------------------ | ----------------------------------------------------------------------------------------- |
|
|
166
|
+
| 🧠 Functions | Overview of server-side functions in Realm | [Functions Documentation](https://www.mongodb.com/docs/atlas/app-services/functions/) |
|
|
167
|
+
| ⏰ Triggers | Triggers that run on database events or schedules | [Triggers Documentation](https://www.mongodb.com/docs/atlas/app-services/triggers/) |
|
|
168
|
+
| 👤 User Management | Managing users, authentication, and providers | [Users Documentation](https://www.mongodb.com/docs/atlas/app-services/users/) |
|
|
169
|
+
| 🌐 Custom Endpoints | HTTP endpoints to expose backend functionality via API | [Custom Endpoints](http://mongodb.com/docs/atlas/app-services/data-api/custom-endpoints/) |
|
|
170
|
+
| 🔐 Rules & Permissions | Define fine-grained access control for collections | [Rules Documentation](https://www.mongodb.com/docs/atlas/app-services/rules/) |
|
|
169
171
|
|
|
170
|
-
>This URL should be used as the base URL in your frontend application, as explained in the next section.
|
|
171
172
|
|
|
172
|
-
##
|
|
173
|
-
|
|
174
|
-
You can use the official `realm-web` SDK to integrate MongoDB Realm into a React application.
|
|
175
|
-
This serves as a sample setup — similar logic can be applied using other official Realm SDKs **(e.g. React Native, Node, or Flutter)**.
|
|
176
|
-
|
|
177
|
-
### 📦 Install Realm SDK
|
|
178
|
-
|
|
179
|
-
```bash
|
|
180
|
-
npm install realm-web
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
### ⚙️ Configure Realm in React
|
|
184
|
-
|
|
185
|
-
Create a file to initialize and export the Realm App instance:
|
|
186
|
-
|
|
187
|
-
```ts
|
|
188
|
-
// src/realm/realmApp.ts
|
|
189
|
-
|
|
190
|
-
import * as Realm from "realm-web";
|
|
191
|
-
|
|
192
|
-
// Replace with your actual Realm App ID and your deployed backend URL
|
|
193
|
-
const app = new Realm.App({
|
|
194
|
-
id: "your-realm-app-id", // e.g., my-app-abcde
|
|
195
|
-
baseUrl: "https://your-deployed-backend-url.com" // e.g., https://your-app-name.up.example.app
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
export default app;
|
|
199
|
-
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
>🔗 The baseUrl should point to the backend URL you deployed earlier using Flowerbase.
|
|
203
|
-
This tells the frontend SDK where to send authentication and data requests.
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
## 🔐 8. Authentication – Local Email/Password (User-Pass)
|
|
173
|
+
## 🔐 6. Authentication – Local Email/Password (User-Pass)
|
|
208
174
|
|
|
209
175
|
The authentication system in `@flowerforce/flowerbase` reimplements the classic **email/password** login method (called local-userpass), similar to the one used by MongoDB Realm.
|
|
210
176
|
|
|
@@ -230,11 +196,9 @@ The only authentication mode currently re-implemented in `@flowerforce/flowerbas
|
|
|
230
196
|
> Other methods (OAuth, API key, anonymous, etc.) are not supported yet.
|
|
231
197
|
|
|
232
198
|
#### Example user:
|
|
233
|
-
```
|
|
199
|
+
```js
|
|
234
200
|
{
|
|
235
|
-
"_id":
|
|
236
|
-
"$oid": "example-user-id"
|
|
237
|
-
},
|
|
201
|
+
"_id": ObjectId("2scgsb3gev99gsty2ev3g2g323d2hs"),
|
|
238
202
|
"email": "myuser@flowerbase.example",
|
|
239
203
|
"password": "your-encrypted-password",
|
|
240
204
|
"status": "confirmed",
|
|
@@ -277,11 +241,180 @@ Example
|
|
|
277
241
|
}
|
|
278
242
|
|
|
279
243
|
```
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
244
|
+
If you're configuring the project from scratch, you can skip ahead to the [Build](#build) step.
|
|
245
|
+
|
|
246
|
+
--------
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
<a id="migration"></a>
|
|
250
|
+
## 🔄 [Migration Guide](#migration) - Migrating Your Realm Project
|
|
251
|
+
|
|
252
|
+
Follow these steps to rebuild your backend in a clean and modern Node.js environment:
|
|
253
|
+
|
|
254
|
+
## 🪜 Step-by-Step Migration
|
|
255
|
+
|
|
256
|
+
### 📥 Download Your Realm App from MongoDB Atlas
|
|
257
|
+
|
|
258
|
+
Follow these steps to export and download your Realm app from MongoDB Cloud.
|
|
259
|
+
|
|
260
|
+
---
|
|
261
|
+
|
|
262
|
+
#### 1. Log In to MongoDB Cloud
|
|
263
|
+
|
|
264
|
+
Go to [https://cloud.mongodb.com/](https://cloud.mongodb.com/) and sign in with your credentials.
|
|
265
|
+
|
|
266
|
+
---
|
|
267
|
+
|
|
268
|
+
#### 2. Select Your Project
|
|
269
|
+
|
|
270
|
+
From the dashboard, choose the **project** that contains the Realm app you want to download.
|
|
271
|
+
|
|
272
|
+
---
|
|
273
|
+
|
|
274
|
+
#### 3. Open the Realm App List
|
|
275
|
+
|
|
276
|
+
- In the left-hand sidebar, under the **Services** section, click on **"Triggers"**.
|
|
277
|
+
- Then click the **"View All Apps"** button in the top-right corner.
|
|
278
|
+
|
|
279
|
+
---
|
|
280
|
+
|
|
281
|
+
#### 4. Select the Desired App
|
|
282
|
+
|
|
283
|
+
From the list of applications, click on the **app name** you wish to export.
|
|
284
|
+
|
|
285
|
+
---
|
|
286
|
+
|
|
287
|
+
#### 5. Go to Deployment
|
|
288
|
+
|
|
289
|
+
In the left sidebar, under the **Manage** section, click on **"Deployment"**.
|
|
290
|
+
|
|
291
|
+
---
|
|
292
|
+
|
|
293
|
+
#### 6. Export the App
|
|
294
|
+
|
|
295
|
+
Click on the **"Export App"** tab at the top of the page.
|
|
296
|
+
|
|
297
|
+
---
|
|
298
|
+
|
|
299
|
+
#### 7. Download the App
|
|
300
|
+
|
|
301
|
+
Scroll to the bottom and click the **"Download App"** button.
|
|
302
|
+
|
|
303
|
+
This will download a `.zip` file containing your Realm app's full structure and configuration.
|
|
304
|
+
|
|
305
|
+
---
|
|
306
|
+
|
|
307
|
+
✅ You are now ready to migrate or inspect your Realm app locally!
|
|
308
|
+
|
|
309
|
+
In your existing project folder, initialize a new Node.js project, Run:
|
|
310
|
+
|
|
311
|
+
```bash
|
|
312
|
+
npm init -y
|
|
313
|
+
```
|
|
314
|
+
Install Flowerbase
|
|
315
|
+
|
|
316
|
+
```bash
|
|
317
|
+
npm install @flowerforce/flowerbase
|
|
318
|
+
```
|
|
319
|
+
Create an index.ts file
|
|
320
|
+
|
|
321
|
+
Inside your project, create index.ts:
|
|
322
|
+
|
|
323
|
+
```bash
|
|
324
|
+
touch index.ts
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
Initialize the Flowerbase App
|
|
328
|
+
|
|
329
|
+
In index.ts, add:
|
|
330
|
+
|
|
331
|
+
```ts
|
|
332
|
+
import { initialize } from "@flowerforce/flowerbase";
|
|
333
|
+
|
|
334
|
+
initialize({
|
|
335
|
+
projectId: process.env.PROJECT_ID,
|
|
336
|
+
port: Number(process.env.PORT),
|
|
337
|
+
mongodbUrl: process.env.DB_CONNECTION_STRING,
|
|
338
|
+
jwtSecret: process.env.APP_SECRET,
|
|
339
|
+
host: process.env.HOST
|
|
340
|
+
});
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
Ensure the following environment variables are set in your .env file or deployment environment:
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
| Variable | Description | Example |
|
|
347
|
+
| ---------------------- | --------------------------------------------------------------------------- | -------------------------------------------------- |
|
|
348
|
+
| `PROJECT_ID` | A unique ID to identify your project. This value can be freely invented — it's preserved mainly for compatibility with the old Realm-style project structure. | `my-flowerbase-app` |
|
|
349
|
+
| `PORT` | The port on which the server will run. | `3000` |
|
|
350
|
+
| `DB_CONNECTION_STRING` | MongoDB connection URI, including username, password, and database name. | `mongodb+srv://user:pass@cluster.mongodb.net/mydb` |
|
|
351
|
+
| `APP_SECRET` | Secret used to sign and verify JWT tokens (choose a strong secret). | `supersecretkey123!` |
|
|
352
|
+
| `HOST` | The host address the server binds to (usually `0.0.0.0` for public access). | `0.0.0.0` |
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
Example:
|
|
356
|
+
```env
|
|
357
|
+
PROJECT_ID=your-project-id
|
|
358
|
+
PORT=3000
|
|
359
|
+
DB_CONNECTION_STRING=mongodb+srv://username:password@cluster.mongodb.net/dbname
|
|
360
|
+
APP_SECRET=your-jwt-secret
|
|
361
|
+
HOST=0.0.0.0
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
🛡️ Note: Never commit .env files to source control. Use a .gitignore file to exclude it.
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
<a id="build"></a>
|
|
368
|
+
## 🚀 Build & Deploy the Server
|
|
369
|
+
|
|
370
|
+
Once your migration or first configuration is complete, it’s time to build and deploy the backend so it can be accessed by your frontend or external clients.
|
|
371
|
+
|
|
372
|
+
### 🔧 Build the App
|
|
373
|
+
|
|
374
|
+
If you're using for example TypeScript:
|
|
375
|
+
|
|
376
|
+
```bash
|
|
377
|
+
npx tsc
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
You can deploy the application using any Node.js-compatible platform.
|
|
382
|
+
Once deployed, you'll receive a public URL (e.g. https://your-app-name.up.example.app).
|
|
383
|
+
|
|
384
|
+
>This URL should be used as the base URL in your frontend application, as explained in the next section.
|
|
385
|
+
|
|
386
|
+
## 🌐 Frontend Setup – Realm SDK in React (Example)
|
|
387
|
+
|
|
388
|
+
You can use the official `realm-web` SDK to integrate MongoDB Realm into a React application.
|
|
389
|
+
This serves as a sample setup — similar logic can be applied using other official Realm SDKs **(e.g. React Native, Node, or Flutter)**.
|
|
390
|
+
|
|
391
|
+
### 📦 Install Realm SDK
|
|
392
|
+
|
|
393
|
+
```bash
|
|
394
|
+
npm install realm-web
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
### ⚙️ Configure Realm in React
|
|
398
|
+
|
|
399
|
+
Create a file to initialize and export the Realm App instance:
|
|
400
|
+
|
|
401
|
+
```ts
|
|
402
|
+
// src/realm/realmApp.ts
|
|
403
|
+
|
|
404
|
+
import * as Realm from "realm-web";
|
|
405
|
+
|
|
406
|
+
// Replace with your actual Realm App ID and your deployed backend URL
|
|
407
|
+
const app = new Realm.App({
|
|
408
|
+
id: "your-realm-app-id", // e.g., my-app-abcde
|
|
409
|
+
baseUrl: "https://your-deployed-backend-url.com" // e.g., https://your-app-name.up.example.app
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
export default app;
|
|
413
|
+
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
>🔗 The baseUrl should point to the backend URL you deployed earlier using Flowerbase.
|
|
417
|
+
This tells the frontend SDK where to send authentication and data requests.
|
|
418
|
+
|
|
419
|
+
|
|
287
420
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../src/auth/controller.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAOzC;;;;GAIG;AACH,wBAAsB,cAAc,CAAC,GAAG,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../src/auth/controller.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAOzC;;;;GAIG;AACH,wBAAsB,cAAc,CAAC,GAAG,EAAE,eAAe,iBAkExD"}
|
package/dist/auth/controller.js
CHANGED
|
@@ -65,7 +65,9 @@ function authController(app) {
|
|
|
65
65
|
if (!auth_user) {
|
|
66
66
|
throw new Error(`User with ID ${req.user.sub} not found`);
|
|
67
67
|
}
|
|
68
|
-
const user = yield db
|
|
68
|
+
const user = yield db
|
|
69
|
+
.collection(userCollection)
|
|
70
|
+
.findOne({ [constants_1.AUTH_CONFIG.user_id_field]: req.user.sub });
|
|
69
71
|
res.status(201);
|
|
70
72
|
return {
|
|
71
73
|
access_token: this.createAccessToken(Object.assign(Object.assign({}, auth_user), { user_data: user }))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../../src/auth/providers/local-userpass/controller.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../../src/auth/providers/local-userpass/controller.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAsBzC;;;;GAIG;AACH,wBAAsB,uBAAuB,CAAC,GAAG,EAAE,eAAe,iBA6MjE"}
|
|
@@ -108,12 +108,12 @@ function localUserPassController(app) {
|
|
|
108
108
|
});
|
|
109
109
|
});
|
|
110
110
|
/**
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
111
|
+
* Endpoint for reset password.
|
|
112
|
+
*
|
|
113
|
+
* @route {POST} /reset/call
|
|
114
|
+
* @param {ResetPasswordDto} req - The request object with th reset request.
|
|
115
|
+
* @returns {Promise<void>}
|
|
116
|
+
*/
|
|
117
117
|
app.post(utils_1.AUTH_ENDPOINTS.RESET, {
|
|
118
118
|
schema: utils_1.RESET_SCHEMA
|
|
119
119
|
}, function (req) {
|
|
@@ -130,8 +130,8 @@ function localUserPassController(app) {
|
|
|
130
130
|
const tokenId = (0, crypto_1.generateToken)();
|
|
131
131
|
yield (db === null || db === void 0 ? void 0 : db.collection(resetPasswordCollection).updateOne({ email }, { $set: { token, tokenId, email, createdAt: new Date() } }, { upsert: true }));
|
|
132
132
|
if (resetPasswordConfig.runResetFunction && resetPasswordConfig.resetFunctionName) {
|
|
133
|
-
const functionsList = state_1.StateManager.select(
|
|
134
|
-
const services = state_1.StateManager.select(
|
|
133
|
+
const functionsList = state_1.StateManager.select('functions');
|
|
134
|
+
const services = state_1.StateManager.select('services');
|
|
135
135
|
const currentFunction = functionsList[resetPasswordConfig.resetFunctionName];
|
|
136
136
|
yield (0, context_1.GenerateContext)({
|
|
137
137
|
args: [{ token, tokenId, email }],
|
|
@@ -155,12 +155,12 @@ function localUserPassController(app) {
|
|
|
155
155
|
});
|
|
156
156
|
});
|
|
157
157
|
/**
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
158
|
+
* Endpoint for confirm reset password.
|
|
159
|
+
*
|
|
160
|
+
* @route {POST} /reset
|
|
161
|
+
* @param {ConfirmResetPasswordDto} req - The request object with reset data.
|
|
162
|
+
* @returns {Promise<void>}
|
|
163
|
+
*/
|
|
164
164
|
app.post(utils_1.AUTH_ENDPOINTS.CONFIRM_RESET, {
|
|
165
165
|
schema: utils_1.CONFIRM_RESET_SCHEMA
|
|
166
166
|
}, function (req) {
|
|
@@ -172,7 +172,7 @@ function localUserPassController(app) {
|
|
|
172
172
|
throw new Error(utils_1.AUTH_ERRORS.INVALID_RESET_PARAMS);
|
|
173
173
|
}
|
|
174
174
|
const hashedPassword = yield (0, crypto_1.hashPassword)(password);
|
|
175
|
-
yield db.collection(authCollection).updateOne({ email: resetRequest.email
|
|
175
|
+
yield db.collection(authCollection).updateOne({ email: resetRequest.email }, {
|
|
176
176
|
$set: {
|
|
177
177
|
password: hashedPassword
|
|
178
178
|
}
|
package/dist/auth/utils.d.ts
CHANGED
|
@@ -63,7 +63,8 @@ export declare enum AUTH_ENDPOINTS {
|
|
|
63
63
|
PROFILE = "/profile",
|
|
64
64
|
SESSION = "/session",
|
|
65
65
|
RESET = "/reset/call",
|
|
66
|
-
CONFIRM_RESET = "/reset"
|
|
66
|
+
CONFIRM_RESET = "/reset",
|
|
67
|
+
FIRST_USER = "/setup/first-user"
|
|
67
68
|
}
|
|
68
69
|
export declare enum AUTH_ERRORS {
|
|
69
70
|
INVALID_CREDENTIALS = "Invalid credentials",
|
package/dist/auth/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/auth/utils.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,YAAY;;;;;;;;;;;;;CASxB,CAAA;AAED,eAAO,MAAM,YAAY;;;;;;;;;;;;;CASxB,CAAA;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/auth/utils.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,YAAY;;;;;;;;;;;;;CASxB,CAAA;AAED,eAAO,MAAM,YAAY;;;;;;;;;;;;;CASxB,CAAA;AAED,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;CAUhC,CAAA;AAED,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;CAS/B,CAAA;AAED,oBAAY,cAAc;IACxB,KAAK,WAAW;IAChB,YAAY,cAAc;IAC1B,OAAO,aAAa;IACpB,OAAO,aAAa;IACpB,KAAK,gBAAgB;IACrB,aAAa,WAAW;IACxB,UAAU,sBAAsB;CACjC;AAED,oBAAY,WAAW;IACrB,mBAAmB,wBAAwB;IAC3C,aAAa,mCAAmC;IAChD,oBAAoB,sCAAsC;CAC3D;AAED,MAAM,WAAW,UAAU;IACzB,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,SAAS,EAAE,MAAM,CAAA;IACjB,gBAAgB,EAAE,aAAa,CAAA;CAChC;AAED,UAAU,MAAM;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,OAAO,CAAA;CAClB;AACD,UAAU,aAAa;IACrB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,OAAO,CAAA;IACjB,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,MAAM;IACrB,WAAW,EAAE,OAAO,CAAA;IACpB,iBAAiB,EAAE,MAAM,CAAA;IACzB,gBAAgB,EAAE,MAAM,CAAA;IACxB,uBAAuB,EAAE,OAAO,CAAA;IAChC,gBAAgB,EAAE,OAAO,CAAA;IACzB,UAAU,EAAE;QACV,IAAI,EAAE,MAAM,CAAA;QACZ,OAAO,EAAE,MAAM,CAAA;QACf,SAAS,EAAE,MAAM,CAAA;KAClB,CAAA;CACF;AAED,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,OAAO,CAAA;IAChB,kBAAkB,EAAE,MAAM,CAAA;IAC1B,aAAa,EAAE,MAAM,CAAA;IACrB,eAAe,EAAE,MAAM,CAAA;IACvB,aAAa,EAAE,MAAM,CAAA;CACtB;AAED,eAAO,MAAM,aAAa,mBAAmB,CAAA;AAE7C;;;GAGG;AACH,eAAO,MAAM,cAAc,QAAO,UAGjC,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,kBAAkB,QAAO,oBAGrC,CAAA;AAED,eAAO,MAAM,aAAa,GACxB,qBAAqB,MAAM,EAC3B,OAAO,MAAM,EACb,SAAS,MAAM;;;;;CA4ChB,CAAA"}
|
package/dist/auth/utils.js
CHANGED
|
@@ -55,6 +55,7 @@ var AUTH_ENDPOINTS;
|
|
|
55
55
|
AUTH_ENDPOINTS["SESSION"] = "/session";
|
|
56
56
|
AUTH_ENDPOINTS["RESET"] = "/reset/call";
|
|
57
57
|
AUTH_ENDPOINTS["CONFIRM_RESET"] = "/reset";
|
|
58
|
+
AUTH_ENDPOINTS["FIRST_USER"] = "/setup/first-user";
|
|
58
59
|
})(AUTH_ENDPOINTS || (exports.AUTH_ENDPOINTS = AUTH_ENDPOINTS = {}));
|
|
59
60
|
var AUTH_ERRORS;
|
|
60
61
|
(function (AUTH_ERRORS) {
|
|
@@ -84,14 +85,14 @@ exports.loadCustomUserData = loadCustomUserData;
|
|
|
84
85
|
const getMailConfig = (resetPasswordConfig, token, tokenId) => {
|
|
85
86
|
var _a, _b, _c;
|
|
86
87
|
const { mailConfig, resetPasswordUrl } = resetPasswordConfig;
|
|
87
|
-
const ENV_PREFIX =
|
|
88
|
+
const ENV_PREFIX = 'ENV';
|
|
88
89
|
const { from, subject, mailToken } = mailConfig;
|
|
89
|
-
const [fromPrefix, fromPath] = from.split(
|
|
90
|
-
const currentSender = (_a = (fromPrefix === ENV_PREFIX ? process.env[fromPath] : from)) !== null && _a !== void 0 ? _a :
|
|
91
|
-
const [subjectPrefix, subjectPath] = subject.split(
|
|
92
|
-
const currentSubject = (_b = (subjectPrefix === ENV_PREFIX ? process.env[subjectPath] : subject)) !== null && _b !== void 0 ? _b :
|
|
93
|
-
const [mailTokenPrefix, mailTokenPath] = mailToken.split(
|
|
94
|
-
const currentMailToken = (_c = (mailTokenPrefix ===
|
|
90
|
+
const [fromPrefix, fromPath] = from.split('.');
|
|
91
|
+
const currentSender = (_a = (fromPrefix === ENV_PREFIX ? process.env[fromPath] : from)) !== null && _a !== void 0 ? _a : '';
|
|
92
|
+
const [subjectPrefix, subjectPath] = subject.split('.');
|
|
93
|
+
const currentSubject = (_b = (subjectPrefix === ENV_PREFIX ? process.env[subjectPath] : subject)) !== null && _b !== void 0 ? _b : '';
|
|
94
|
+
const [mailTokenPrefix, mailTokenPath] = mailToken.split('.');
|
|
95
|
+
const currentMailToken = (_c = (mailTokenPrefix === 'ENV' ? process.env[mailTokenPath] : mailToken)) !== null && _c !== void 0 ? _c : '';
|
|
95
96
|
const link = `${resetPasswordUrl}/${token}/${tokenId}`;
|
|
96
97
|
const body = `<body style="font-family: Arial, sans-serif; background-color: #f4f4f4; text-align: center; padding: 20px;">
|
|
97
98
|
<table width="100%" cellspacing="0" cellpadding="0">
|
|
@@ -116,7 +117,7 @@ const getMailConfig = (resetPasswordConfig, token, tokenId) => {
|
|
|
116
117
|
</table>
|
|
117
118
|
</body>`;
|
|
118
119
|
return {
|
|
119
|
-
from: currentSender !== null && currentSender !== void 0 ? currentSender :
|
|
120
|
+
from: currentSender !== null && currentSender !== void 0 ? currentSender : '',
|
|
120
121
|
subject: currentSubject,
|
|
121
122
|
mailToken: currentMailToken,
|
|
122
123
|
body
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,cAAc;;;;;;;;CAQ1B,CAAA;AACD,eAAO,MAAM,WAAW,QAA8C,CAAA;AACtE,eAAO,MAAM,YAAY,QAA8B,CAAA;AACvD,eAAO,MAAM,OAAO,QAAgB,CAAA;AACpC,eAAO,MAAM,WAAW;;;;;;CAMvB,CAAA"}
|
package/dist/constants.js
CHANGED
|
@@ -13,13 +13,13 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
exports.AUTH_CONFIG = exports.DB_NAME = exports.HTTPS_SCHEMA = exports.API_VERSION = exports.DEFAULT_CONFIG = void 0;
|
|
15
15
|
const utils_1 = require("./auth/utils");
|
|
16
|
-
const { database_name, collection_name = 'users', user_id_field =
|
|
16
|
+
const { database_name, collection_name = 'users', user_id_field = 'id' } = (0, utils_1.loadCustomUserData)();
|
|
17
17
|
const _a = (0, utils_1.loadAuthConfig)(), { auth_collection = 'auth_users' } = _a, configuration = __rest(_a, ["auth_collection"]);
|
|
18
18
|
exports.DEFAULT_CONFIG = {
|
|
19
19
|
PORT: Number(process.env.PORT) || 3000,
|
|
20
20
|
MONGODB_URL: process.env.MONGODB_URL || '',
|
|
21
21
|
JWT_SECRET: process.env.JWT_SECRET || '',
|
|
22
|
-
API_VERSION: process.env.API_VERSION ||
|
|
22
|
+
API_VERSION: process.env.API_VERSION || 'v2.0',
|
|
23
23
|
HTTPS_SCHEMA: process.env.HTTPS_SCHEMA || 'https',
|
|
24
24
|
HOST: process.env.HOST || '0.0.0.0',
|
|
25
25
|
ENABLE_LOGGER: process.env.ENABLE_LOGGER
|
|
@@ -30,7 +30,7 @@ exports.DB_NAME = database_name;
|
|
|
30
30
|
exports.AUTH_CONFIG = {
|
|
31
31
|
authCollection: auth_collection,
|
|
32
32
|
userCollection: collection_name,
|
|
33
|
-
resetPasswordCollection:
|
|
33
|
+
resetPasswordCollection: 'reset-password-requests',
|
|
34
34
|
resetPasswordConfig: configuration['local-userpass'].config,
|
|
35
35
|
user_id_field
|
|
36
36
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../src/features/functions/controller.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../src/features/functions/controller.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAGhD;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,EAAE,kBAuFjC,CAAA"}
|
|
@@ -60,20 +60,23 @@ const functionsController = (app_1, _a) => __awaiter(void 0, [app_1, _a], void 0
|
|
|
60
60
|
functionsList,
|
|
61
61
|
services: services_1.services
|
|
62
62
|
});
|
|
63
|
-
res.type(
|
|
63
|
+
res.type('application/json');
|
|
64
64
|
return JSON.stringify(result);
|
|
65
65
|
}));
|
|
66
66
|
app.get('/call', (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
67
67
|
const { query, user } = req;
|
|
68
68
|
const { baas_request, stitch_request } = query;
|
|
69
|
-
const config = JSON.parse(Buffer.from(baas_request || stitch_request ||
|
|
69
|
+
const config = JSON.parse(Buffer.from(baas_request || stitch_request || '', 'base64').toString('utf8'));
|
|
70
70
|
const [{ database, collection }] = config.arguments;
|
|
71
|
-
const app = state_1.StateManager.select(
|
|
72
|
-
const services = state_1.StateManager.select(
|
|
73
|
-
const changeStream = yield services[
|
|
71
|
+
const app = state_1.StateManager.select('app');
|
|
72
|
+
const services = state_1.StateManager.select('services');
|
|
73
|
+
const changeStream = yield services['mongodb-atlas'](app, {
|
|
74
74
|
user,
|
|
75
75
|
rules
|
|
76
|
-
})
|
|
76
|
+
})
|
|
77
|
+
.db(database)
|
|
78
|
+
.collection(collection)
|
|
79
|
+
.watch([], { fullDocument: 'whenAvailable' });
|
|
77
80
|
res.header('Content-Type', 'text/event-stream');
|
|
78
81
|
res.header('Cache-Control', 'no-cache');
|
|
79
82
|
res.header('Connection', 'keep-alive');
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Document } from
|
|
1
|
+
import { Document } from 'mongodb';
|
|
2
2
|
import { Arguments } from '../../auth/dtos';
|
|
3
3
|
import { GetOperatorsFunction } from '../../services/mongodb-atlas/model';
|
|
4
4
|
type MethodName = Exclude<keyof ReturnType<GetOperatorsFunction>, 'match'>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dtos.d.ts","sourceRoot":"","sources":["../../../src/features/functions/dtos.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAA;AAEzE,KAAK,UAAU,GAAG,OAAO,CAAC,MAAM,UAAU,CAAC,oBAAoB,CAAC,EAAE,OAAO,CAAC,CAAA;AAE1E,MAAM,MAAM,eAAe,GACvB;
|
|
1
|
+
{"version":3,"file":"dtos.d.ts","sourceRoot":"","sources":["../../../src/features/functions/dtos.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAA;AAEzE,KAAK,UAAU,GAAG,OAAO,CAAC,MAAM,UAAU,CAAC,oBAAoB,CAAC,EAAE,OAAO,CAAC,CAAA;AAE1E,MAAM,MAAM,eAAe,GACvB;IACE,IAAI,EAAE,UAAU,CAAA;IAChB,SAAS,EAAE,aAAa,CAAA;CACzB,GACD;IACE,SAAS,EAAE,aAAa,CAAA;IACxB,IAAI,EAAE,UAAU,CAAA;IAChB,OAAO,EAAE,eAAe,CAAA;CACzB,CAAA;AAEL,MAAM,MAAM,qBAAqB,GAAG;IAClC,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB,CAAA;AAED,KAAK,aAAa,GAAG,SAAS,CAAC;IAC7B,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,MAAM,CAAA;IAClB,KAAK,EAAE,UAAU,CAAC,oBAAoB,CAAC,CAAA;IACvC,MAAM,EAAE,QAAQ,CAAA;IAChB,QAAQ,EAAE,QAAQ,CAAA;IAClB,SAAS,EAAE,QAAQ,EAAE,CAAA;CACtB,CAAC,CAAA;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,QAAQ,EAAE,CAAA;IACrB,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,KAAK,QAAQ,GAAG;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,MAAM,CAAA;CACnB,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FastifyInstance } from 'fastify';
|
|
2
|
-
import { Document } from
|
|
2
|
+
import { Document } from 'mongodb';
|
|
3
3
|
import { GetOperatorsFunction } from '../../services/mongodb-atlas/model';
|
|
4
4
|
import { Rules } from '../rules/interface';
|
|
5
5
|
export interface FunctionConfig {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/features/functions/utils.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAE3D;;;GAGG;AACH,eAAO,MAAM,aAAa,GAAU,gBAAuB,KAAG,OAAO,CAAC,SAAS,CAwB9E,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GAAU,uDAMhC,kBAAkB;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/features/functions/utils.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAE3D;;;GAGG;AACH,eAAO,MAAM,aAAa,GAAU,gBAAuB,KAAG,OAAO,CAAC,SAAS,CAwB9E,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GAAU,uDAMhC,kBAAkB;;;;;;;;;EAiCpB,CAAA"}
|
|
@@ -40,7 +40,7 @@ const loadFunctions = (...args_1) => __awaiter(void 0, [...args_1], void 0, func
|
|
|
40
40
|
const extensions = ['.js', '.ts'];
|
|
41
41
|
let code = '';
|
|
42
42
|
const fnPath = extensions
|
|
43
|
-
.map(ext => node_path_1.default.join(rootDir, fnDir, `${name}${ext}`))
|
|
43
|
+
.map((ext) => node_path_1.default.join(rootDir, fnDir, `${name}${ext}`))
|
|
44
44
|
.find(fs_1.default.existsSync);
|
|
45
45
|
if (!fnPath) {
|
|
46
46
|
throw new Error(`File ${name}.js or ${name}.ts not found`);
|
|
@@ -69,7 +69,7 @@ const executeQuery = (_a) => __awaiter(void 0, [_a], void 0, function* ({ curren
|
|
|
69
69
|
updateOne: () => currentMethod(bson_1.EJSON.deserialize(query), bson_1.EJSON.deserialize(update)),
|
|
70
70
|
aggregate: () => currentMethod(bson_1.EJSON.deserialize(query)),
|
|
71
71
|
insertMany: () => currentMethod(bson_1.EJSON.deserialize(documents)),
|
|
72
|
-
updateMany: () => currentMethod(bson_1.EJSON.deserialize(query), bson_1.EJSON.deserialize(update))
|
|
72
|
+
updateMany: () => currentMethod(bson_1.EJSON.deserialize(query), bson_1.EJSON.deserialize(update))
|
|
73
73
|
};
|
|
74
74
|
});
|
|
75
75
|
exports.executeQuery = executeQuery;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/features/triggers/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,QAAQ,CAAA;AAG/C;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,GAAU,0CAIpC,sBAAsB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/features/triggers/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,QAAQ,CAAA;AAG/C;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,GAAU,0CAIpC,sBAAsB,kBAsBxB,CAAA"}
|