acebase-server 1.10.1 → 1.11.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 (127) hide show
  1. package/dist/cjs/index.js +16 -0
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/cjs/oauth-providers/dropbox.js +3 -2
  4. package/dist/cjs/oauth-providers/dropbox.js.map +1 -1
  5. package/dist/cjs/oauth-providers/facebook.js +3 -2
  6. package/dist/cjs/oauth-providers/facebook.js.map +1 -1
  7. package/dist/cjs/oauth-providers/google.js +3 -2
  8. package/dist/cjs/oauth-providers/google.js.map +1 -1
  9. package/dist/cjs/oauth-providers/index.js.map +1 -1
  10. package/dist/cjs/oauth-providers/instagram.js +3 -2
  11. package/dist/cjs/oauth-providers/instagram.js.map +1 -1
  12. package/dist/cjs/oauth-providers/oauth-provider.js +23 -0
  13. package/dist/cjs/oauth-providers/oauth-provider.js.map +1 -1
  14. package/dist/cjs/oauth-providers/spotify.js +3 -2
  15. package/dist/cjs/oauth-providers/spotify.js.map +1 -1
  16. package/dist/cjs/routes/data-set.js +3 -0
  17. package/dist/cjs/routes/data-set.js.map +1 -1
  18. package/dist/cjs/routes/data-sync-changes.js.map +1 -1
  19. package/dist/cjs/routes/data-sync-mutations.js.map +1 -1
  20. package/dist/cjs/routes/data-transaction.js +16 -3
  21. package/dist/cjs/routes/data-transaction.js.map +1 -1
  22. package/dist/cjs/routes/data-update.js +3 -0
  23. package/dist/cjs/routes/data-update.js.map +1 -1
  24. package/dist/cjs/routes/meta-info.js.map +1 -1
  25. package/dist/cjs/routes/oauth2-signin.js +6 -5
  26. package/dist/cjs/routes/oauth2-signin.js.map +1 -1
  27. package/dist/cjs/rules.js +5 -5
  28. package/dist/cjs/rules.js.map +1 -1
  29. package/dist/cjs/server.js +3 -3
  30. package/dist/cjs/server.js.map +1 -1
  31. package/dist/cjs/settings/index.js +6 -7
  32. package/dist/cjs/settings/index.js.map +1 -1
  33. package/dist/cjs/shared/clients.js.map +1 -1
  34. package/dist/cjs/shared/http.js.map +1 -1
  35. package/dist/cjs/websocket/index.js +3 -3
  36. package/dist/cjs/websocket/index.js.map +1 -1
  37. package/dist/cjs/websocket/socket.io.js +8 -11
  38. package/dist/cjs/websocket/socket.io.js.map +1 -1
  39. package/dist/esm/index.js +2 -0
  40. package/dist/esm/index.js.map +1 -1
  41. package/dist/esm/oauth-providers/dropbox.js +3 -2
  42. package/dist/esm/oauth-providers/dropbox.js.map +1 -1
  43. package/dist/esm/oauth-providers/facebook.js +3 -2
  44. package/dist/esm/oauth-providers/facebook.js.map +1 -1
  45. package/dist/esm/oauth-providers/google.js +3 -2
  46. package/dist/esm/oauth-providers/google.js.map +1 -1
  47. package/dist/esm/oauth-providers/index.js.map +1 -1
  48. package/dist/esm/oauth-providers/instagram.js +3 -2
  49. package/dist/esm/oauth-providers/instagram.js.map +1 -1
  50. package/dist/esm/oauth-providers/oauth-provider.js +21 -1
  51. package/dist/esm/oauth-providers/oauth-provider.js.map +1 -1
  52. package/dist/esm/oauth-providers/spotify.js +3 -2
  53. package/dist/esm/oauth-providers/spotify.js.map +1 -1
  54. package/dist/esm/routes/data-set.js +3 -0
  55. package/dist/esm/routes/data-set.js.map +1 -1
  56. package/dist/esm/routes/data-sync-changes.js.map +1 -1
  57. package/dist/esm/routes/data-sync-mutations.js.map +1 -1
  58. package/dist/esm/routes/data-transaction.js +16 -3
  59. package/dist/esm/routes/data-transaction.js.map +1 -1
  60. package/dist/esm/routes/data-update.js +3 -0
  61. package/dist/esm/routes/data-update.js.map +1 -1
  62. package/dist/esm/routes/meta-info.js.map +1 -1
  63. package/dist/esm/routes/oauth2-signin.js +6 -5
  64. package/dist/esm/routes/oauth2-signin.js.map +1 -1
  65. package/dist/esm/rules.js +5 -5
  66. package/dist/esm/rules.js.map +1 -1
  67. package/dist/esm/server.js +3 -3
  68. package/dist/esm/server.js.map +1 -1
  69. package/dist/esm/settings/index.js +5 -6
  70. package/dist/esm/settings/index.js.map +1 -1
  71. package/dist/esm/shared/clients.js.map +1 -1
  72. package/dist/esm/shared/http.js.map +1 -1
  73. package/dist/esm/websocket/index.js +3 -3
  74. package/dist/esm/websocket/index.js.map +1 -1
  75. package/dist/esm/websocket/socket.io.js +9 -11
  76. package/dist/esm/websocket/socket.io.js.map +1 -1
  77. package/dist/types/index.d.ts +2 -0
  78. package/dist/types/oauth-providers/dropbox.d.ts +3 -14
  79. package/dist/types/oauth-providers/facebook.d.ts +3 -7
  80. package/dist/types/oauth-providers/google.d.ts +3 -7
  81. package/dist/types/oauth-providers/index.d.ts +2 -10
  82. package/dist/types/oauth-providers/instagram.d.ts +3 -7
  83. package/dist/types/oauth-providers/oauth-provider.d.ts +25 -21
  84. package/dist/types/oauth-providers/spotify.d.ts +3 -7
  85. package/dist/types/routes/data-query.d.ts +1 -1
  86. package/dist/types/rules.d.ts +2 -2
  87. package/dist/types/server.d.ts +9 -7
  88. package/dist/types/settings/email.d.ts +1 -1
  89. package/dist/types/settings/index.d.ts +5 -6
  90. package/dist/types/shared/clients.d.ts +3 -1
  91. package/dist/types/shared/env.d.ts +3 -3
  92. package/dist/types/shared/http.d.ts +2 -0
  93. package/dist/types/websocket/manager.d.ts +1 -1
  94. package/package.json +7 -7
  95. package/src/index.ts +3 -1
  96. package/src/oauth-providers/dropbox.ts +5 -4
  97. package/src/oauth-providers/facebook.ts +5 -4
  98. package/src/oauth-providers/google.ts +5 -4
  99. package/src/oauth-providers/index.ts +2 -1
  100. package/src/oauth-providers/instagram.ts +5 -4
  101. package/src/oauth-providers/oauth-provider.ts +14 -4
  102. package/src/oauth-providers/spotify.ts +5 -4
  103. package/src/placeholder.d.ts +12 -0
  104. package/src/routes/data-query.ts +1 -1
  105. package/src/routes/data-set.ts +4 -0
  106. package/src/routes/data-set.yaml +7 -1
  107. package/src/routes/data-sync-changes.ts +1 -1
  108. package/src/routes/data-sync-mutations.ts +1 -1
  109. package/src/routes/data-transaction-finish.yaml +6 -0
  110. package/src/routes/data-transaction.ts +21 -6
  111. package/src/routes/data-update.ts +4 -0
  112. package/src/routes/data-update.yaml +7 -1
  113. package/src/routes/meta-info.ts +1 -1
  114. package/src/routes/oauth2-signin.ts +6 -5
  115. package/src/rules.ts +7 -7
  116. package/src/server.ts +10 -8
  117. package/src/settings/email.ts +1 -1
  118. package/src/settings/index.ts +7 -6
  119. package/src/shared/clients.ts +1 -1
  120. package/src/shared/env.ts +3 -3
  121. package/src/shared/http.ts +2 -0
  122. package/src/websocket/index.ts +3 -3
  123. package/src/websocket/manager.ts +1 -1
  124. package/src/websocket/socket.io.ts +9 -10
  125. package/webmanager/acebase-client-browser.min.js +16 -0
  126. package/webmanager/index.html +2 -2
  127. package/webmanager/index.js +3 -6
@@ -18,28 +18,32 @@ export interface IOAuth2TokenResult {
18
18
  expires_in?: number;
19
19
  refresh_token?: string;
20
20
  }
21
- export interface IOAuth2Provider {
22
- init(info: {
23
- redirect_url: string;
24
- state?: string;
25
- options?: any;
26
- }): Promise<string>;
27
- getAccessToken(params: IOAuth2AuthCodeParams | IOAuth2RefreshTokenParams): Promise<IOAuth2TokenResult>;
28
- getUserInfo(access_token: string): Promise<{
29
- id: string;
30
- name: string;
31
- display_name: string;
32
- picture?: Array<{
33
- width?: number;
34
- height?: number;
35
- url: string;
36
- }>;
37
- email: string;
38
- email_verified: boolean;
39
- other?: {
40
- [key: string]: string | number | boolean;
41
- };
21
+ export declare type OAuth2ProviderInitInfo = {
22
+ redirect_url: string;
23
+ state?: string;
24
+ options?: any;
25
+ };
26
+ export declare type OAuth2ProviderUserInfo = {
27
+ id: string;
28
+ name: string;
29
+ display_name: string;
30
+ picture?: Array<{
31
+ width?: number;
32
+ height?: number;
33
+ url: string;
42
34
  }>;
35
+ email: string;
36
+ email_verified: boolean;
37
+ other?: {
38
+ [key: string]: string | number | boolean;
39
+ };
40
+ };
41
+ export declare class OAuth2Provider {
42
+ protected settings: IOAuth2ProviderSettings;
43
+ constructor(settings: IOAuth2ProviderSettings);
44
+ init(info: OAuth2ProviderInitInfo): Promise<string>;
45
+ getAccessToken(param: IOAuth2AuthCodeParams | IOAuth2RefreshTokenParams): Promise<IOAuth2TokenResult>;
46
+ getUserInfo(access_token: string): Promise<OAuth2ProviderUserInfo>;
43
47
  }
44
48
  export interface IOpenIDToken {
45
49
  email: string;
@@ -1,4 +1,4 @@
1
- import { IOAuth2Provider, IOAuth2ProviderSettings, IOAuth2AuthCodeParams, IOAuth2RefreshTokenParams } from "./oauth-provider";
1
+ import { IOAuth2ProviderSettings, IOAuth2AuthCodeParams, IOAuth2RefreshTokenParams, OAuth2Provider, OAuth2ProviderInitInfo } from "./oauth-provider";
2
2
  /**
3
3
  * Details of your app to access the Spotify API
4
4
  */
@@ -24,18 +24,14 @@ interface ISpotifyImage {
24
24
  height: number;
25
25
  url: string;
26
26
  }
27
- export declare class SpotifyAuthProvider implements IOAuth2Provider {
28
- private settings;
27
+ export declare class SpotifyAuthProvider extends OAuth2Provider {
29
28
  constructor(settings: ISpotifyAuthSettings);
30
29
  /**
31
30
  * Starts auth flow by getting the url the user should be redirected to
32
31
  * @param info.redirectUrl Url spotify will redirect to after authorizing
33
32
  * @param info.state Optional state that will be passed to redirectUri by spotify
34
33
  */
35
- init(info: {
36
- redirect_url: string;
37
- state?: string;
38
- }): Promise<string>;
34
+ init(info: OAuth2ProviderInitInfo): Promise<string>;
39
35
  getAccessToken(params: IOAuth2AuthCodeParams | IOAuth2RefreshTokenParams): Promise<ISpotifyAuthToken>;
40
36
  getClientAccessToken(): Promise<ISpotifyClientAuthToken>;
41
37
  getUserInfo(access_token: string): Promise<{
@@ -42,7 +42,7 @@ export declare type ResponseBody = {
42
42
  count: number;
43
43
  list: any[];
44
44
  };
45
- map: any;
45
+ map?: any;
46
46
  };
47
47
  export declare type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>;
48
48
  export declare const addRoute: (env: RouteInitEnvironment) => void;
@@ -1,7 +1,7 @@
1
1
  import { AceBase } from 'acebase';
2
2
  import { DebugLogger } from 'acebase-core';
3
3
  import { DbUserAccountDetails } from './schema/user';
4
- import { AUTH_ACCESS_DEFAULT } from './settings';
4
+ import { AuthAccessDefault } from './settings';
5
5
  export declare type RuleValidationFailCode = 'rule' | 'no_rule' | 'private' | 'exception';
6
6
  declare type HasAccessResult = {
7
7
  allow: boolean;
@@ -24,7 +24,7 @@ export declare class PathBasedRules {
24
24
  private authEnabled;
25
25
  private accessRules;
26
26
  stop(): void;
27
- constructor(rulesFilePath: string, defaultAccess: AUTH_ACCESS_DEFAULT, env: {
27
+ constructor(rulesFilePath: string, defaultAccess: AuthAccessDefault, env: {
28
28
  debug: DebugLogger;
29
29
  db: AceBase;
30
30
  authEnabled: boolean;
@@ -1,12 +1,13 @@
1
- /// <reference types="express-serve-static-core" />
2
1
  import { DebugLogger, SimpleEventEmitter } from 'acebase-core';
3
2
  import { AceBaseServerSettings, AceBaseServerConfig } from './settings';
4
- import { createApp } from './shared/http';
3
+ import { createApp, HttpRequest, HttpResponse } from './shared/http';
5
4
  import { AceBase } from 'acebase';
5
+ import { OAuth2Provider } from './oauth-providers/oauth-provider';
6
6
  import { DbUserAccountDetails } from './schema/user';
7
7
  export declare class AceBaseServerNotReadyError extends Error {
8
8
  constructor();
9
9
  }
10
+ declare type HttpMethod = 'get' | 'GET' | 'put' | 'PUT' | 'post' | 'POST' | 'delete' | 'DELETE';
10
11
  export declare class AceBaseServer extends SimpleEventEmitter {
11
12
  private _ready;
12
13
  get isReady(): boolean;
@@ -91,16 +92,17 @@ export declare class AceBaseServer extends SimpleEventEmitter {
91
92
  * .then(quote => {
92
93
  * console.log(`Got random quote: ${quote}`);
93
94
  * })
94
- * @param {'get'|'put'|'post'|'delete'} method
95
- * @param {string} ext_path
96
- * @param {(req: Express.Request, res: Express.Response)} handler
95
+ * @param method http method to bind to
96
+ * @param ext_path path to bind to (appended to /ext/)
97
+ * @param handler your Express request handler callback
97
98
  */
98
- extend(method: 'get' | 'put' | 'post' | 'delete', ext_path: string, handler: (req: Express.Request, res: Express.Response) => void): void;
99
+ extend(method: HttpMethod, ext_path: string, handler: (req: HttpRequest, res: HttpResponse) => void): void;
99
100
  /**
100
101
  * Configure an auth provider to allow users to sign in with Facebook, Google, etc
101
102
  * @param providerName name of the third party OAuth provider. Eg: "Facebook", "Google", "spotify" etc
102
103
  * @param settings API key & secret for the OAuth provider
103
104
  * @returns Returns the created auth provider instance, which can be used to call non-user specific methods the provider might support. (example: the Spotify auth provider supports getClientAuthToken, which allows API calls to be made to the core (non-user) spotify service)
104
105
  */
105
- configAuthProvider(providerName: string, settings: any): any;
106
+ configAuthProvider(providerName: string, settings: any): OAuth2Provider;
106
107
  }
108
+ export {};
@@ -10,5 +10,5 @@ export interface AceBaseServerEmailSettings {
10
10
  /** NOT IMPLEMENTED YET - Use send property for your own implementation */
11
11
  server?: AceBaseServerEmailServerSettings;
12
12
  /** function to call when an e-mail needs to be sent */
13
- send: (request: AceBaseEmailRequest) => Promise<boolean>;
13
+ send: (request: AceBaseEmailRequest) => Promise<void>;
14
14
  }
@@ -22,11 +22,10 @@ export declare class AceBaseServerHttpsConfig {
22
22
  passphrase?: string;
23
23
  constructor(settings: AceBaseServerHttpsSettings);
24
24
  }
25
- export declare enum AUTH_ACCESS_DEFAULT {
26
- DENY_ALL = "deny",
27
- ALLOW_ALL = "allow",
28
- ALLOW_AUTHENTICATED = "auth"
29
- }
25
+ export declare type AuthAccessDefault = 'deny' | 'allow' | 'auth';
26
+ export declare const AUTH_ACCESS_DEFAULT: {
27
+ [key: string]: AuthAccessDefault;
28
+ };
30
29
  export declare class AceBaseServerAuthenticationSettings {
31
30
  /**
32
31
  * Whether to enable authorization. Without authorization the entire db can be read and written to by anyone (not recommended 🤷🏼‍♂️)
@@ -47,7 +46,7 @@ export declare class AceBaseServerAuthenticationSettings {
47
46
  /**
48
47
  * When the server runs for the first time, what defaults to use to generate the rules.json file with. Options are: 'auth' (only authenticated access to db, default), 'deny' (deny access to anyone except admin user), 'allow' (allow access to anyone)
49
48
  */
50
- readonly defaultAccessRule: AUTH_ACCESS_DEFAULT;
49
+ readonly defaultAccessRule: AuthAccessDefault;
51
50
  /**
52
51
  * When the server runs for the first time, what password to use for the admin user. If not supplied, a generated password will be used and shown ONCE in the console output.
53
52
  */
@@ -37,7 +37,9 @@ export declare class ConnectedClient {
37
37
  started: number;
38
38
  path: string;
39
39
  context: any;
40
- finish?: (val?: any) => Promise<any>;
40
+ finish?: (val?: any) => Promise<{
41
+ cursor?: string;
42
+ }>;
41
43
  timeout: NodeJS.Timeout;
42
44
  };
43
45
  };
@@ -6,7 +6,7 @@ import type { AceBaseServerConfig } from '../settings';
6
6
  import type { DbUserAccountDetails } from '../schema/user';
7
7
  import type { ConnectedClient } from './clients';
8
8
  import type { DebugLogger, SimpleCache } from 'acebase-core';
9
- import type { IOAuth2Provider } from '../oauth-providers/oauth-provider';
9
+ import type { OAuth2Provider } from '../oauth-providers/oauth-provider';
10
10
  import type { Server as HttpServer } from 'http';
11
11
  import type { Server as SecureHttpServer } from 'https';
12
12
  import type { PathBasedRules } from '../rules';
@@ -27,7 +27,7 @@ export interface RouteInitEnvironment {
27
27
  clients: Map<string, ConnectedClient>;
28
28
  authCache: SimpleCache<string, DbUserAccountDetails>;
29
29
  authProviders: {
30
- [providerName: string]: IOAuth2Provider;
30
+ [providerName: string]: OAuth2Provider;
31
31
  };
32
32
  rules: PathBasedRules;
33
33
  }
@@ -35,7 +35,7 @@ export interface RouteRequestEnvironment {
35
35
  /** If the request has an Authentication: bearer token, the user will be bound to the incoming request */
36
36
  user?: DbUserAccountDetails;
37
37
  /** If context is sent through AceBase-Context header, it will be bound to the incoming request */
38
- context?: {
38
+ context: {
39
39
  [key: string]: any;
40
40
  };
41
41
  }
@@ -3,6 +3,8 @@ export type { Express, Request, Response } from 'express';
3
3
  import * as express from 'express';
4
4
  export declare type HttpApp = express.Express;
5
5
  export declare type HttpSocket = Socket;
6
+ export declare type HttpRequest = express.Request;
7
+ export declare type HttpResponse = express.Response;
6
8
  /**
7
9
  * Creates an app that handles http requests, adds json body parsing.
8
10
  * @param settings
@@ -54,7 +54,7 @@ export declare abstract class WebSocketManager<SocketType> extends SimpleEventEm
54
54
  value: any;
55
55
  }>): void;
56
56
  emit(event: 'connect', data: WebSocketEventData<SocketType>): void;
57
- emit(event: 'disconnect', data: WebSocketEventData<SocketType>): void;
57
+ emit(event: 'disconnect', data: WebSocketEventData<SocketType, string>): void;
58
58
  /** @deprecated deprecated since client v0.9.4 */
59
59
  emit(event: 'signin', data: WebSocketEventData<SocketType, {
60
60
  accessToken: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "acebase-server",
3
- "version": "1.10.1",
3
+ "version": "1.11.0",
4
4
  "description": "AceBase realtime database server (webserver endpoint to allow remote connections)",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -14,7 +14,7 @@
14
14
  "private": false,
15
15
  "repository": "github:appy-one/acebase-server",
16
16
  "scripts": {
17
- "start": "node dist/esm/start.js DBNAME=default HOST=localhost PORT=3000 TXLOG=1",
17
+ "start": "node dist/esm/start.js DBNAME=default DBPATH=.. HOST=localhost PORT=3000 TXLOG=1",
18
18
  "test": "set NODE_ENV=development && npm run start",
19
19
  "build": "npm run build:clean && npm run build:esm && npm run build:cjs && npm run build:packages && echo Done!",
20
20
  "build:clean": "rm -fr dist/*",
@@ -57,17 +57,17 @@
57
57
  "author": "Ewout Stortenbeker <me@appy.one> (http://appy.one)",
58
58
  "license": "MIT",
59
59
  "dependencies": {
60
- "acebase": "^1.19.0",
61
- "acebase-core": "^1.16.0",
60
+ "acebase": "^1.21.1",
61
+ "acebase-core": "^1.18.0",
62
62
  "express": "^4.17.1",
63
- "socket.io": "^2.4.1",
63
+ "socket.io": "^4.5.0",
64
64
  "swagger-jsdoc": "^6.1.0",
65
65
  "swagger-ui-express": "^4.3.0"
66
66
  },
67
67
  "devDependencies": {
68
68
  "@types/express": "^4.17.13",
69
- "@types/node": "^14.0.14",
70
- "@types/socket.io": "^2.1.13",
69
+ "@types/node": "^10.17.60",
70
+ "@types/socket.io": "^3.0.2",
71
71
  "tsc-esm-fix": "^2.12.4",
72
72
  "typescript": "^4.6.3"
73
73
  }
package/src/index.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  export { AceBaseServer } from './server';
2
- export { AceBaseServerSettings, AceBaseServerHttpsSettings, AceBaseServerTransactionSettings, AceBaseServerAuthenticationSettings } from './settings';
2
+ export { AceBaseServerSettings, AceBaseServerHttpsSettings, AceBaseServerTransactionSettings, AceBaseServerAuthenticationSettings } from './settings';
3
+ export * from './shared/email';
4
+ export * from './oauth-providers';
@@ -1,4 +1,4 @@
1
- import { IOAuth2Provider, IOAuth2ProviderSettings, IOAuth2AuthCodeParams, IOAuth2RefreshTokenParams } from "./oauth-provider";
1
+ import { IOAuth2ProviderSettings, IOAuth2AuthCodeParams, IOAuth2RefreshTokenParams, OAuth2Provider, OAuth2ProviderInitInfo } from "./oauth-provider";
2
2
  import { fetch } from '../shared/simple-fetch';
3
3
 
4
4
  /**
@@ -48,9 +48,10 @@ interface IDropboxUser {
48
48
  }
49
49
  team_member_id?: string
50
50
  }
51
- export class DropboxAuthProvider implements IOAuth2Provider {
51
+ export class DropboxAuthProvider extends OAuth2Provider {
52
52
 
53
- constructor(private settings: IDropboxAuthSettings) {
53
+ constructor(settings: IDropboxAuthSettings) {
54
+ super(settings);
54
55
  if (!settings.scopes) { settings.scopes = []; }
55
56
  if (settings.scopes.length > 0 && !settings.scopes.includes('account_info.read')) { settings.scopes.push('account_info.read'); }
56
57
  }
@@ -66,7 +67,7 @@ export class DropboxAuthProvider implements IOAuth2Provider {
66
67
  * @param info.options.locale If the locale specified is a supported language, Dropbox will direct users to a translated version of the authorization website. Locale tags should be IETF language tags.
67
68
  * @param info.options.force_reauthentication When true (default is false) users will be signed out if they are currently signed in. This will make sure the user is brought to a page where they can create a new account or sign in to another account. This should only be used when there is a definite reason to believe that the user needs to sign in to a new or different account.
68
69
  */
69
- async init(info: { redirect_url: string, state?: string, options?: { locale?: string, require_role?: string, disable_signup?: boolean, force_reapprove?: boolean, force_reauthentication?: boolean } }) {
70
+ async init(info: OAuth2ProviderInitInfo) {
70
71
  // Return url to get authorization code with
71
72
  const options = info.options || {};
72
73
  const authUrl = `https://www.dropbox.com/oauth2/authorize?response_type=code&token_access_type=offline&client_id=${this.settings.client_id}&scope=${encodeURIComponent(this.settings.scopes.join(' '))}&redirect_uri=${encodeURIComponent(info.redirect_url)}&locale=${options.locale || ''}&require_role=${options.require_role || ''}&force_reauthentication=${options.force_reauthentication === true}&force_reapprove=${options.force_reapprove === true}&disable_signup=${options.disable_signup === true}&state=${encodeURIComponent(info.state)}`;
@@ -1,4 +1,4 @@
1
- import { IOAuth2Provider, IOAuth2ProviderSettings, IOAuth2AuthCodeParams, IOAuth2RefreshTokenParams } from "./oauth-provider";
1
+ import { IOAuth2ProviderSettings, IOAuth2AuthCodeParams, IOAuth2RefreshTokenParams, OAuth2Provider, OAuth2ProviderInitInfo } from "./oauth-provider";
2
2
  import { fetch } from '../shared/simple-fetch';
3
3
 
4
4
  /**
@@ -28,9 +28,10 @@ interface IFacebookUser {
28
28
  }
29
29
  }
30
30
  }
31
- export class FacebookAuthProvider implements IOAuth2Provider {
31
+ export class FacebookAuthProvider extends OAuth2Provider {
32
32
 
33
- constructor(private settings: IFacebookAuthSettings) {
33
+ constructor(settings: IFacebookAuthSettings) {
34
+ super(settings);
34
35
  if (!settings.scopes) { settings.scopes = []; }
35
36
  if (!settings.scopes.includes('email')) { settings.scopes.push('email'); }
36
37
  }
@@ -40,7 +41,7 @@ export class FacebookAuthProvider implements IOAuth2Provider {
40
41
  * @param info.redirectUrl Url spotify will redirect to after authorizing, should be the url
41
42
  * @param info.state Optional state that will be passed to redirectUri by spotify
42
43
  */
43
- async init(info: { redirect_url: string, state?: string }) {
44
+ async init(info: OAuth2ProviderInitInfo) {
44
45
  // Return url to get authorization code with
45
46
  const authUrl = `https://www.facebook.com/v7.0/dialog/oauth?response_type=code&client_id=${this.settings.client_id}&scope=${encodeURIComponent(this.settings.scopes.join(' '))}&redirect_uri=${encodeURIComponent(info.redirect_url)}&state=${encodeURIComponent(info.state)}`;
46
47
  return authUrl;
@@ -1,4 +1,4 @@
1
- import { IOAuth2Provider, IOAuth2ProviderSettings, IOpenIDToken, IOpenIDConfiguration, IOAuth2AuthCodeParams, IOAuth2RefreshTokenParams } from "./oauth-provider";
1
+ import { IOAuth2ProviderSettings, IOpenIDToken, IOpenIDConfiguration, IOAuth2AuthCodeParams, IOAuth2RefreshTokenParams, OAuth2ProviderInitInfo, OAuth2Provider } from "./oauth-provider";
2
2
  import { fetch } from '../shared/simple-fetch';
3
3
 
4
4
  /**
@@ -43,11 +43,12 @@ interface IGoogleUser {
43
43
  updated_at: number
44
44
  }
45
45
 
46
- export class GoogleAuthProvider implements IOAuth2Provider {
46
+ export class GoogleAuthProvider extends OAuth2Provider {
47
47
 
48
48
  _config: IOpenIDConfiguration
49
49
 
50
- constructor(private settings: IGoogleAuthSettings) {
50
+ constructor(settings: IGoogleAuthSettings) {
51
+ super(settings);
51
52
  if (!settings.scopes) { settings.scopes = []; }
52
53
  if (!settings.scopes.includes('email')) { settings.scopes.push('email'); }
53
54
  if (!settings.scopes.includes('profile')) { settings.scopes.push('profile'); }
@@ -66,7 +67,7 @@ export class GoogleAuthProvider implements IOAuth2Provider {
66
67
  * @param info.redirectUrl Url spotify will redirect to after authorizing, should be the url
67
68
  * @param info.state Optional state that will be passed to redirectUri by spotify
68
69
  */
69
- async init(info: { redirect_url: string, state?: string }) {
70
+ async init(info: OAuth2ProviderInitInfo) {
70
71
  // Return url to get authorization code with
71
72
  // See https://developers.google.com/identity/protocols/oauth2/web-server#httprest
72
73
 
@@ -2,6 +2,7 @@ import { DropboxAuthProvider } from './dropbox';
2
2
  import { FacebookAuthProvider } from './facebook';
3
3
  import { GoogleAuthProvider } from './google';
4
4
  import { InstagramAuthProvider } from './instagram';
5
+ import { OAuth2Provider } from './oauth-provider';
5
6
  import { SpotifyAuthProvider } from './spotify';
6
7
 
7
8
  export { DropboxAuthProvider, IDropboxAuthSettings } from './dropbox';
@@ -10,7 +11,7 @@ export { GoogleAuthProvider, IGoogleAuthSettings } from './google';
10
11
  export { InstagramAuthProvider, IInstagramAuthSettings } from './instagram';
11
12
  export { SpotifyAuthProvider, ISpotifyAuthSettings } from './spotify';
12
13
 
13
- const oAuth2Providers = {
14
+ const oAuth2Providers: { [key: string]: typeof OAuth2Provider } = {
14
15
  dropbox: DropboxAuthProvider,
15
16
  facebook: FacebookAuthProvider,
16
17
  google: GoogleAuthProvider,
@@ -1,4 +1,4 @@
1
- import { IOAuth2Provider, IOAuth2ProviderSettings, IOAuth2AuthCodeParams } from "./oauth-provider";
1
+ import { IOAuth2ProviderSettings, IOAuth2AuthCodeParams, OAuth2Provider, OAuth2ProviderInitInfo } from "./oauth-provider";
2
2
  import { fetch } from '../shared/simple-fetch';
3
3
 
4
4
  /**
@@ -28,9 +28,10 @@ interface IInstagramUser {
28
28
  followed_by: number
29
29
  }
30
30
  }
31
- export class InstagramAuthProvider implements IOAuth2Provider {
31
+ export class InstagramAuthProvider extends OAuth2Provider {
32
32
 
33
- constructor(private settings: IInstagramAuthSettings) {
33
+ constructor(settings: IInstagramAuthSettings) {
34
+ super(settings);
34
35
  if (!settings.scopes) { settings.scopes = []; }
35
36
  if (!settings.scopes.includes('basic')) { settings.scopes.push('basic'); }
36
37
 
@@ -44,7 +45,7 @@ export class InstagramAuthProvider implements IOAuth2Provider {
44
45
  * @param info.redirectUrl Url spotify will redirect to after authorizing, should be the url
45
46
  * @param info.state Optional state that will be passed to redirectUri by spotify
46
47
  */
47
- async init(info: { redirect_url: string, state?: string }) {
48
+ async init(info: OAuth2ProviderInitInfo) {
48
49
  // Return url to get authorization code with
49
50
  // See https://www.instagram.com/developer/authorization/
50
51
  const authUrl = `https://api.instagram.com/oauth/authorize/?response_type=code&client_id=${this.settings.client_id}&scope=${encodeURIComponent(this.settings.scopes.join(' '))}&redirect_uri=${encodeURIComponent(info.redirect_url)}&state=${encodeURIComponent(info.state)}`;
@@ -18,10 +18,20 @@ export interface IOAuth2TokenResult {
18
18
  expires_in?: number,
19
19
  refresh_token?: string
20
20
  }
21
- export interface IOAuth2Provider {
22
- init(info: { redirect_url: string, state?: string, options?: any }): Promise<string>
23
- getAccessToken(params: IOAuth2AuthCodeParams | IOAuth2RefreshTokenParams): Promise<IOAuth2TokenResult>
24
- getUserInfo(access_token: string): Promise<{ id: string, name: string, display_name: string, picture?: Array<{ width?: number, height?: number, url: string }>, email: string, email_verified: boolean, other?: { [key:string]: string|number|boolean } }>
21
+
22
+ export type OAuth2ProviderInitInfo = { redirect_url: string, state?: string, options?: any };
23
+ export type OAuth2ProviderUserInfo = { id: string, name: string, display_name: string, picture?: Array<{ width?: number, height?: number, url: string }>, email: string, email_verified: boolean, other?: { [key:string]: string|number|boolean } };
24
+ // export interface IOAuth2Provider {
25
+ // init(info: OAuth2ProviderInitInfo): Promise<string>;
26
+ // getAccessToken(param: OAuth2ProviderGetAccessTokenParams): Promise<IOAuth2TokenResult>;
27
+ // getUserInfo(access_token: string): Promise<OAuth2ProviderUserInfo>;
28
+ // }
29
+ class NotImplementedError extends Error { constructor() { super('Not implemented'); } }
30
+ export class OAuth2Provider { //implements IOAuth2Provider
31
+ constructor(protected settings: IOAuth2ProviderSettings) {}
32
+ init(info: OAuth2ProviderInitInfo): Promise<string> { throw new NotImplementedError(); };
33
+ getAccessToken(param: IOAuth2AuthCodeParams|IOAuth2RefreshTokenParams): Promise<IOAuth2TokenResult> { throw new NotImplementedError(); };;
34
+ getUserInfo(access_token: string): Promise<OAuth2ProviderUserInfo> { throw new NotImplementedError(); };;
25
35
  }
26
36
  // For OAuth2.0 providers with id_token in getAccessToken, see https://auth0.com/docs/tokens/concepts/jwts
27
37
  export interface IOpenIDToken {
@@ -1,4 +1,4 @@
1
- import { IOAuth2Provider, IOAuth2ProviderSettings, IOAuth2AuthCodeParams, IOAuth2RefreshTokenParams } from "./oauth-provider";
1
+ import { IOAuth2ProviderSettings, IOAuth2AuthCodeParams, IOAuth2RefreshTokenParams, OAuth2Provider, OAuth2ProviderInitInfo } from "./oauth-provider";
2
2
  import { fetch } from '../shared/simple-fetch';
3
3
 
4
4
  /**
@@ -28,9 +28,10 @@ interface ISpotifyUser {
28
28
  type: 'user',
29
29
  uri: string
30
30
  }
31
- export class SpotifyAuthProvider implements IOAuth2Provider {
31
+ export class SpotifyAuthProvider extends OAuth2Provider {
32
32
 
33
- constructor(private settings: ISpotifyAuthSettings) {
33
+ constructor(settings: ISpotifyAuthSettings) {
34
+ super(settings);
34
35
  if (!settings.scopes) { settings.scopes = []; }
35
36
  if (!settings.scopes.includes('user-read-email')) { settings.scopes.push('user-read-email'); }
36
37
  if (!settings.scopes.includes('user-read-private')) { settings.scopes.push('user-read-private'); }
@@ -41,7 +42,7 @@ export class SpotifyAuthProvider implements IOAuth2Provider {
41
42
  * @param info.redirectUrl Url spotify will redirect to after authorizing
42
43
  * @param info.state Optional state that will be passed to redirectUri by spotify
43
44
  */
44
- async init(info: { redirect_url: string, state?: string }) {
45
+ async init(info: OAuth2ProviderInitInfo) {
45
46
  // Return url to get authorization code with
46
47
  const authUrl = `https://accounts.spotify.com/authorize?response_type=code&client_id=${this.settings.client_id}&scope=${encodeURIComponent(this.settings.scopes.join(' '))}&redirect_uri=${encodeURIComponent(info.redirect_url)}&state=${encodeURIComponent(info.state)}`;
47
48
  return authUrl;
@@ -0,0 +1,12 @@
1
+
2
+ /**
3
+ * When using `@types/node@10.17.60` to check for backward compatibility with Node.js 10,
4
+ * tsc will throw errors on `@types/fs-extra` that references types `fs.Dir`,
5
+ * `fs.OpenDirOptions` and `fs.RmDirOptions`, which are not declared.
6
+ * @see https://github.com/DefinitelyTyped/DefinitelyTyped/issues/44946
7
+ */
8
+ declare module 'fs' {
9
+ interface Dir {}
10
+ interface OpenDirOptions {}
11
+ interface RmDirOptions {}
12
+ }
@@ -34,7 +34,7 @@ export type ResponseBody = {
34
34
  count: number;
35
35
  list: any[]
36
36
  },
37
- map: any
37
+ map?: any
38
38
  };
39
39
  export type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>;
40
40
 
@@ -52,6 +52,10 @@ export const addRoute = (env: RouteInitEnvironment) => {
52
52
  .context(req.context)
53
53
  .set(val);
54
54
 
55
+ // NEW: add cursor to response context, which was added to the request context in `acebase_cursor` if transaction logging is enabled
56
+ const returnContext = { acebase_cursor: req.context.acebase_cursor };
57
+ res.setHeader('AceBase-Context', JSON.stringify(returnContext) );
58
+
55
59
  res.send({ success: true });
56
60
  }
57
61
  catch(err) {
@@ -24,7 +24,7 @@
24
24
  description: Contextual info about the database operation (must be valid JSON). This info is included in event notifications sent to clients watching data at this or child paths
25
25
  schema:
26
26
  type: string
27
- example: {}
27
+ example: '{}'
28
28
  requestBody:
29
29
  description: serialized value to store in the database
30
30
  content:
@@ -36,6 +36,12 @@
36
36
  description: Returns "200 OK" when the database operation succeeded
37
37
  content:
38
38
  'application/json':
39
+ headers:
40
+ 'AceBase-Context':
41
+ description: Returns contextual information, such as the `acebase_cursor` if transaction logging is enabled on the server.
42
+ schema:
43
+ type: string
44
+ example: '{ "acebase_cursor": "l3lf2iwd000109mgdn0d6pqt" }'
39
45
  schema:
40
46
  type: object
41
47
  properties:
@@ -65,7 +65,7 @@ export const addRoute = (env: RouteInitEnvironment) => {
65
65
  res.contentType('application/json');
66
66
 
67
67
  const serialized = Transport.serialize2(result.changes);
68
- res.send(serialized);
68
+ res.send(serialized as ValueChange[]);
69
69
  }
70
70
  catch(err) {
71
71
  sendError(res, err);
@@ -65,7 +65,7 @@ export const addRoute = (env: RouteInitEnvironment) => {
65
65
  res.contentType('application/json');
66
66
 
67
67
  const serialized = Transport.serialize2(result.mutations);
68
- res.send(serialized);
68
+ res.send(serialized as ValueMutation[]);
69
69
  }
70
70
  catch(err) {
71
71
  sendError(res, err);
@@ -34,6 +34,12 @@
34
34
  description: If successful returns the string `"done"`
35
35
  content:
36
36
  'text/plain':
37
+ headers:
38
+ 'AceBase-Context':
39
+ description: Returns the context that was passed to the transaction start endpoint, augmented with an `acebase_cursor` if transaction logging is enabled on the server.
40
+ schema:
41
+ type: string
42
+ example: '{ "acebase_cursor": "l3lf2iwd000109mgdn0d6pqt" }'
37
43
  schema:
38
44
  type: string
39
45
  value: done