acebase-server 1.19.2 → 1.20.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.
- package/README.md +19 -33
- package/api-clients/thunder-client/README.md +32 -0
- package/api-clients/thunder-client/collection.json +1069 -0
- package/api-clients/thunder-client/environment.json +25 -0
- package/dist/cjs/auth.js +10 -7
- package/dist/cjs/logger.js +3 -3
- package/dist/cjs/middleware/user.js +6 -13
- package/dist/cjs/oauth-providers/facebook.js +1 -1
- package/dist/cjs/oauth-providers/instagram.js +1 -1
- package/dist/cjs/routes/auth-change-password.js +12 -9
- package/dist/cjs/routes/auth-reset-password.js +6 -5
- package/dist/cjs/routes/auth-signin.js +15 -2
- package/dist/cjs/routes/data-reflect.js +1 -1
- package/dist/cjs/routes/data-transaction.js +7 -7
- package/dist/cjs/routes/docs.js +1 -1
- package/dist/cjs/routes/meta-info.js +2 -2
- package/dist/cjs/routes/oauth2-signin.js +2 -2
- package/dist/cjs/rules.js +4 -2
- package/dist/cjs/sandbox.js +2 -3
- package/dist/cjs/server.js +5 -2
- package/dist/cjs/shared/admin.js +1 -2
- package/dist/cjs/shared/error.js +2 -1
- package/dist/cjs/shared/http.js +17 -0
- package/dist/cjs/shared/signin.js +72 -76
- package/dist/cjs/shared/simple-fetch.js +1 -2
- package/dist/cjs/shared/tokens.js +1 -1
- package/dist/cjs/start.js +1 -1
- package/dist/cjs/websocket/index.js +10 -10
- package/dist/cjs/websocket/socket.io.js +2 -2
- package/dist/esm/auth.js +10 -7
- package/dist/esm/middleware/user.js +6 -13
- package/dist/esm/oauth-providers/facebook.js +1 -1
- package/dist/esm/oauth-providers/instagram.js +1 -1
- package/dist/esm/routes/auth-change-password.js +11 -8
- package/dist/esm/routes/auth-reset-password.js +3 -3
- package/dist/esm/routes/auth-signin.js +17 -4
- package/dist/esm/routes/data-reflect.js +1 -1
- package/dist/esm/routes/docs.js +1 -1
- package/dist/esm/routes/meta-info.js +2 -2
- package/dist/esm/routes/oauth2-signin.js +2 -2
- package/dist/esm/rules.js +4 -2
- package/dist/esm/server.js +4 -1
- package/dist/esm/shared/error.js +1 -1
- package/dist/esm/shared/http.js +17 -0
- package/dist/esm/shared/signin.js +87 -75
- package/dist/esm/shared/tokens.js +1 -1
- package/dist/esm/start.js +1 -1
- package/dist/esm/websocket/socket.io.js +2 -2
- package/dist/types/routes/auth-change-password.d.ts +1 -0
- package/dist/types/rules.d.ts +1 -1
- package/dist/types/schema/user.d.ts +4 -0
- package/dist/types/settings/index.d.ts +0 -2
- package/dist/types/shared/clients.d.ts +0 -1
- package/dist/types/shared/env.d.ts +12 -11
- package/dist/types/shared/http.d.ts +2 -2
- package/dist/types/shared/password.d.ts +1 -1
- package/dist/types/shared/signin.d.ts +4 -6
- package/dist/types/shared/simple-fetch.d.ts +2 -2
- package/dist/types/shared/tokens.d.ts +1 -1
- package/package.json +10 -11
- package/release_notes.md +21 -2
- package/src/routes/auth-change-password.yaml +9 -0
- package/src/routes/auth-signin.yaml +2 -1
package/README.md
CHANGED
|
@@ -497,20 +497,16 @@ server.configAuthProvider('facebook', { client_id: '[your fb app_id]', client_se
|
|
|
497
497
|
```javascript
|
|
498
498
|
// In your login.js:
|
|
499
499
|
const callbackUrl = 'http://your.app.url/authenticated';
|
|
500
|
-
client.auth.startAuthProviderSignIn('facebook', callbackUrl)
|
|
501
|
-
.
|
|
502
|
-
window.location = redirectUrl; // Send user to auth provider's login screen
|
|
503
|
-
});
|
|
500
|
+
const redirectUrl = await client.auth.startAuthProviderSignIn('facebook', callbackUrl);
|
|
501
|
+
window.location = redirectUrl; // Send user to auth provider's login screen
|
|
504
502
|
```
|
|
505
503
|
|
|
506
504
|
* Once the user authenticated your request, they are redirected back to your website (your callbackUrl):
|
|
507
505
|
```javascript
|
|
508
506
|
// In your authenticated.js: (executes from /authenticated?result=awefi873r4gqw...)
|
|
509
507
|
const callbackResult = window.location.search.match(/[?&]result=(.*?)(?:&|$)/)[1]; // Or some other way you'd get the ?result from the url
|
|
510
|
-
client.auth.finishAuthProviderSignIn(callbackResult)
|
|
511
|
-
.
|
|
512
|
-
console.log(`User ${result.user.email} signed in with ${result.provider.name}`);
|
|
513
|
-
})
|
|
508
|
+
const result = await client.auth.finishAuthProviderSignIn(callbackResult);
|
|
509
|
+
console.log(`User ${result.user.email} signed in with ${result.provider.name}`);
|
|
514
510
|
```
|
|
515
511
|
|
|
516
512
|
The `result` object will also contain the provider's `access_token` and `refresh_token` in case you want to make custom calls to the provider's API. If you want to keep the provider's access_token active, you will have to call `client.auth.refreshAuthProviderToken` before it expires:
|
|
@@ -519,19 +515,15 @@ The `result` object will also contain the provider's `access_token` and `refresh
|
|
|
519
515
|
const keepAlive = (provider) => {
|
|
520
516
|
// Schedule token refresh 1 minute before it expires
|
|
521
517
|
const refreshMs = (provider.expires_in - 60) * 1000;
|
|
522
|
-
setTimeout(() => {
|
|
523
|
-
client.auth.refreshAuthProviderToken(provider.refresh_token)
|
|
524
|
-
|
|
525
|
-
keepAlive(result.provider); // Schedule again
|
|
526
|
-
})
|
|
518
|
+
setTimeout(async () => {
|
|
519
|
+
const result = await client.auth.refreshAuthProviderToken(provider.refresh_token);
|
|
520
|
+
keepAlive(result.provider); // Schedule again
|
|
527
521
|
}, refreshMs);
|
|
528
522
|
};
|
|
529
523
|
|
|
530
|
-
client.auth.finishAuthProviderSignIn(callbackResult)
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
keepAlive(result.provider);
|
|
534
|
-
});
|
|
524
|
+
const result = await client.auth.finishAuthProviderSignIn(callbackResult);
|
|
525
|
+
// schedule a token refresh:
|
|
526
|
+
keepAlive(result.provider);
|
|
535
527
|
```
|
|
536
528
|
|
|
537
529
|
Currently implemented auth providers are:
|
|
@@ -551,7 +543,7 @@ const server = new AceBaseServer(dbname, settings);
|
|
|
551
543
|
await server.ready();
|
|
552
544
|
|
|
553
545
|
// Monitor images being added by users, resize them to multiple sizes:
|
|
554
|
-
server.db.ref('uploads/images').on('child_added', async snap => {
|
|
546
|
+
server.db.ref('uploads/images').on('child_added', async (snap) => {
|
|
555
547
|
const image = snap.val();
|
|
556
548
|
const resizedImages = await createImageSizes(image); // Some function that creates multiple image sizes in a worker thread
|
|
557
549
|
const targetRef = await db.ref('images').push(resizedImages); // Store them somewhere else
|
|
@@ -567,7 +559,7 @@ await db.ready();
|
|
|
567
559
|
await db.auth.signIn('admin', 'thepassword');
|
|
568
560
|
|
|
569
561
|
// Monitor images being added by users, resize them to multiple sizes:
|
|
570
|
-
db.ref('uploads/images').on('child_added', async snap => {
|
|
562
|
+
db.ref('uploads/images').on('child_added', async (snap) => {
|
|
571
563
|
const image = snap.val();
|
|
572
564
|
const resizedImages = createImageSizes(image); // Some function that creates multiple image sizes
|
|
573
565
|
const targetRef = await db.ref('images').push(resizedImages); // Store them somewhere else
|
|
@@ -633,24 +625,18 @@ server.extend('post', 'quotes/add', (req, res) => {
|
|
|
633
625
|
You can then call your API methods on the client side as follows:
|
|
634
626
|
```javascript
|
|
635
627
|
// Get random quote:
|
|
636
|
-
client.callExtension('get', 'quotes/random')
|
|
637
|
-
.
|
|
638
|
-
console.log(`Got random quote: `, quote);
|
|
639
|
-
});
|
|
628
|
+
const quote = await client.callExtension('get', 'quotes/random');
|
|
629
|
+
console.log(`Got random quote: `, quote);
|
|
640
630
|
|
|
641
631
|
// Get specific quote:
|
|
642
|
-
client.callExtension('get', 'quotes/specific', { index: 15 })
|
|
643
|
-
.
|
|
644
|
-
console.log(`Got quotes[15]: `, quote);
|
|
645
|
-
});
|
|
632
|
+
const quote = await client.callExtension('get', 'quotes/specific', { index: 15 });
|
|
633
|
+
console.log(`Got quotes[15]: `, quote);
|
|
646
634
|
|
|
647
635
|
// Add a quote
|
|
648
|
-
client.callExtension('post', 'quotes/add', {
|
|
636
|
+
const result = await client.callExtension('post', 'quotes/add', {
|
|
649
637
|
text: 'The greatest glory in living lies not in never falling, but in rising every time we fall',
|
|
650
|
-
author: 'Nelson Mandela' })
|
|
651
|
-
|
|
652
|
-
// "thanks!"
|
|
653
|
-
});
|
|
638
|
+
author: 'Nelson Mandela' });
|
|
639
|
+
// "thanks!"
|
|
654
640
|
```
|
|
655
641
|
|
|
656
642
|
## Running in a cluster
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Thunder Client — AceBase Server API Collection
|
|
2
|
+
|
|
3
|
+
This directory contains an importable collection of all available `acebase-server` API endpoints and an environment file that pre-configures the `dbname` and `access_token` for each request.
|
|
4
|
+
|
|
5
|
+
## Files
|
|
6
|
+
|
|
7
|
+
| File | Description |
|
|
8
|
+
|------|-------------|
|
|
9
|
+
| `collection.json` | All API endpoints, organized by category |
|
|
10
|
+
| `environment.json` | Environment variables (`dbname`, `access_token`, `host`) |
|
|
11
|
+
|
|
12
|
+
## How to import
|
|
13
|
+
|
|
14
|
+
1. Open [Thunder Client](https://www.thunderclient.com/) in VS Code (install it from the Extensions marketplace if needed).
|
|
15
|
+
2. In the Thunder Client sidebar, click the **Collections** tab.
|
|
16
|
+
3. Click the menu icon (⋮) next to "Collections" and choose **Import**.
|
|
17
|
+
4. Select `collection.json` from this directory.
|
|
18
|
+
5. Switch to the **Env** tab in the sidebar, click the menu icon and choose **Import**.
|
|
19
|
+
6. Select `environment.json` from this directory.
|
|
20
|
+
7. Make the imported environment active by clicking it and selecting **Set Active**.
|
|
21
|
+
|
|
22
|
+
## Configuration
|
|
23
|
+
|
|
24
|
+
Edit the active environment to match your local setup:
|
|
25
|
+
|
|
26
|
+
| Variable | Description | Default |
|
|
27
|
+
|----------|-------------|---------|
|
|
28
|
+
| `host` | Base URL of your AceBase server | `http://localhost:3000` |
|
|
29
|
+
| `dbname` | Name of the database | `default` |
|
|
30
|
+
| `access_token` | Bearer token for authenticated requests | _(empty)_ |
|
|
31
|
+
|
|
32
|
+
To get an `access_token`, run the **Sign in** request first — the response includes a token you can copy into the environment.
|