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.
Files changed (63) hide show
  1. package/README.md +19 -33
  2. package/api-clients/thunder-client/README.md +32 -0
  3. package/api-clients/thunder-client/collection.json +1069 -0
  4. package/api-clients/thunder-client/environment.json +25 -0
  5. package/dist/cjs/auth.js +10 -7
  6. package/dist/cjs/logger.js +3 -3
  7. package/dist/cjs/middleware/user.js +6 -13
  8. package/dist/cjs/oauth-providers/facebook.js +1 -1
  9. package/dist/cjs/oauth-providers/instagram.js +1 -1
  10. package/dist/cjs/routes/auth-change-password.js +12 -9
  11. package/dist/cjs/routes/auth-reset-password.js +6 -5
  12. package/dist/cjs/routes/auth-signin.js +15 -2
  13. package/dist/cjs/routes/data-reflect.js +1 -1
  14. package/dist/cjs/routes/data-transaction.js +7 -7
  15. package/dist/cjs/routes/docs.js +1 -1
  16. package/dist/cjs/routes/meta-info.js +2 -2
  17. package/dist/cjs/routes/oauth2-signin.js +2 -2
  18. package/dist/cjs/rules.js +4 -2
  19. package/dist/cjs/sandbox.js +2 -3
  20. package/dist/cjs/server.js +5 -2
  21. package/dist/cjs/shared/admin.js +1 -2
  22. package/dist/cjs/shared/error.js +2 -1
  23. package/dist/cjs/shared/http.js +17 -0
  24. package/dist/cjs/shared/signin.js +72 -76
  25. package/dist/cjs/shared/simple-fetch.js +1 -2
  26. package/dist/cjs/shared/tokens.js +1 -1
  27. package/dist/cjs/start.js +1 -1
  28. package/dist/cjs/websocket/index.js +10 -10
  29. package/dist/cjs/websocket/socket.io.js +2 -2
  30. package/dist/esm/auth.js +10 -7
  31. package/dist/esm/middleware/user.js +6 -13
  32. package/dist/esm/oauth-providers/facebook.js +1 -1
  33. package/dist/esm/oauth-providers/instagram.js +1 -1
  34. package/dist/esm/routes/auth-change-password.js +11 -8
  35. package/dist/esm/routes/auth-reset-password.js +3 -3
  36. package/dist/esm/routes/auth-signin.js +17 -4
  37. package/dist/esm/routes/data-reflect.js +1 -1
  38. package/dist/esm/routes/docs.js +1 -1
  39. package/dist/esm/routes/meta-info.js +2 -2
  40. package/dist/esm/routes/oauth2-signin.js +2 -2
  41. package/dist/esm/rules.js +4 -2
  42. package/dist/esm/server.js +4 -1
  43. package/dist/esm/shared/error.js +1 -1
  44. package/dist/esm/shared/http.js +17 -0
  45. package/dist/esm/shared/signin.js +87 -75
  46. package/dist/esm/shared/tokens.js +1 -1
  47. package/dist/esm/start.js +1 -1
  48. package/dist/esm/websocket/socket.io.js +2 -2
  49. package/dist/types/routes/auth-change-password.d.ts +1 -0
  50. package/dist/types/rules.d.ts +1 -1
  51. package/dist/types/schema/user.d.ts +4 -0
  52. package/dist/types/settings/index.d.ts +0 -2
  53. package/dist/types/shared/clients.d.ts +0 -1
  54. package/dist/types/shared/env.d.ts +12 -11
  55. package/dist/types/shared/http.d.ts +2 -2
  56. package/dist/types/shared/password.d.ts +1 -1
  57. package/dist/types/shared/signin.d.ts +4 -6
  58. package/dist/types/shared/simple-fetch.d.ts +2 -2
  59. package/dist/types/shared/tokens.d.ts +1 -1
  60. package/package.json +10 -11
  61. package/release_notes.md +21 -2
  62. package/src/routes/auth-change-password.yaml +9 -0
  63. 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
- .then(redirectUrl => {
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
- .then(result => {
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
- .then(result => {
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
- .then(result => {
532
- // schedule a token refresh:
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
- .then(quote => {
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
- .then(quote => {
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
- .then(result => {
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.