acebase-server 1.10.0 → 1.12.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 (250) hide show
  1. package/dist/cjs/index.js +16 -0
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/cjs/logger.js +74 -0
  4. package/dist/cjs/logger.js.map +1 -0
  5. package/dist/cjs/middleware/admin-only.js +29 -0
  6. package/dist/cjs/middleware/admin-only.js.map +1 -0
  7. package/dist/cjs/middleware/user.js +4 -4
  8. package/dist/cjs/middleware/user.js.map +1 -1
  9. package/dist/cjs/oauth-providers/dropbox.js +3 -2
  10. package/dist/cjs/oauth-providers/dropbox.js.map +1 -1
  11. package/dist/cjs/oauth-providers/facebook.js +3 -2
  12. package/dist/cjs/oauth-providers/facebook.js.map +1 -1
  13. package/dist/cjs/oauth-providers/google.js +3 -2
  14. package/dist/cjs/oauth-providers/google.js.map +1 -1
  15. package/dist/cjs/oauth-providers/index.js.map +1 -1
  16. package/dist/cjs/oauth-providers/instagram.js +3 -2
  17. package/dist/cjs/oauth-providers/instagram.js.map +1 -1
  18. package/dist/cjs/oauth-providers/oauth-provider.js +23 -0
  19. package/dist/cjs/oauth-providers/oauth-provider.js.map +1 -1
  20. package/dist/cjs/oauth-providers/spotify.js +3 -2
  21. package/dist/cjs/oauth-providers/spotify.js.map +1 -1
  22. package/dist/cjs/routes/auth-change-password.js +7 -4
  23. package/dist/cjs/routes/auth-change-password.js.map +1 -1
  24. package/dist/cjs/routes/auth-delete.js +9 -7
  25. package/dist/cjs/routes/auth-delete.js.map +1 -1
  26. package/dist/cjs/routes/auth-forgot-password.js +9 -6
  27. package/dist/cjs/routes/auth-forgot-password.js.map +1 -1
  28. package/dist/cjs/routes/auth-reset-password.js +5 -3
  29. package/dist/cjs/routes/auth-reset-password.js.map +1 -1
  30. package/dist/cjs/routes/auth-signout.js +6 -4
  31. package/dist/cjs/routes/auth-signout.js.map +1 -1
  32. package/dist/cjs/routes/auth-signup.js +17 -15
  33. package/dist/cjs/routes/auth-signup.js.map +1 -1
  34. package/dist/cjs/routes/auth-update.js +9 -6
  35. package/dist/cjs/routes/auth-update.js.map +1 -1
  36. package/dist/cjs/routes/auth-verify-email.js +6 -3
  37. package/dist/cjs/routes/auth-verify-email.js.map +1 -1
  38. package/dist/cjs/routes/data-index-create.js +3 -5
  39. package/dist/cjs/routes/data-index-create.js.map +1 -1
  40. package/dist/cjs/routes/data-index-delete.js +2 -4
  41. package/dist/cjs/routes/data-index-delete.js.map +1 -1
  42. package/dist/cjs/routes/data-index-list.js +2 -4
  43. package/dist/cjs/routes/data-index-list.js.map +1 -1
  44. package/dist/cjs/routes/data-reflect.js +2 -4
  45. package/dist/cjs/routes/data-reflect.js.map +1 -1
  46. package/dist/cjs/routes/data-schema-get.js +2 -4
  47. package/dist/cjs/routes/data-schema-get.js.map +1 -1
  48. package/dist/cjs/routes/data-schema-set.js +2 -4
  49. package/dist/cjs/routes/data-schema-set.js.map +1 -1
  50. package/dist/cjs/routes/data-schema-test.js +2 -4
  51. package/dist/cjs/routes/data-schema-test.js.map +1 -1
  52. package/dist/cjs/routes/data-schemas-list.js +2 -4
  53. package/dist/cjs/routes/data-schemas-list.js.map +1 -1
  54. package/dist/cjs/routes/data-set.js +11 -7
  55. package/dist/cjs/routes/data-set.js.map +1 -1
  56. package/dist/cjs/routes/data-sync-changes.js.map +1 -1
  57. package/dist/cjs/routes/data-sync-mutations.js.map +1 -1
  58. package/dist/cjs/routes/data-transaction.js +30 -10
  59. package/dist/cjs/routes/data-transaction.js.map +1 -1
  60. package/dist/cjs/routes/data-update.js +11 -6
  61. package/dist/cjs/routes/data-update.js.map +1 -1
  62. package/dist/cjs/routes/meta-info.js.map +1 -1
  63. package/dist/cjs/routes/meta-logs.js +50 -0
  64. package/dist/cjs/routes/meta-logs.js.map +1 -0
  65. package/dist/cjs/routes/meta.js +3 -0
  66. package/dist/cjs/routes/meta.js.map +1 -1
  67. package/dist/cjs/routes/oauth2-signin.js +15 -11
  68. package/dist/cjs/routes/oauth2-signin.js.map +1 -1
  69. package/dist/cjs/rules.js +5 -5
  70. package/dist/cjs/rules.js.map +1 -1
  71. package/dist/cjs/server.js +6 -4
  72. package/dist/cjs/server.js.map +1 -1
  73. package/dist/cjs/settings/index.js +6 -7
  74. package/dist/cjs/settings/index.js.map +1 -1
  75. package/dist/cjs/shared/clients.js.map +1 -1
  76. package/dist/cjs/shared/env.js.map +1 -1
  77. package/dist/cjs/shared/http.js.map +1 -1
  78. package/dist/cjs/shared/signin.js +8 -3
  79. package/dist/cjs/shared/signin.js.map +1 -1
  80. package/dist/cjs/start.js +3 -0
  81. package/dist/cjs/start.js.map +1 -1
  82. package/dist/cjs/websocket/index.js +43 -24
  83. package/dist/cjs/websocket/index.js.map +1 -1
  84. package/dist/cjs/websocket/socket.io.js +8 -11
  85. package/dist/cjs/websocket/socket.io.js.map +1 -1
  86. package/dist/esm/index.js +2 -0
  87. package/dist/esm/index.js.map +1 -1
  88. package/dist/esm/logger.js +52 -0
  89. package/dist/esm/logger.js.map +1 -0
  90. package/dist/esm/middleware/admin-only.js +25 -0
  91. package/dist/esm/middleware/admin-only.js.map +1 -0
  92. package/dist/esm/middleware/user.js +4 -4
  93. package/dist/esm/middleware/user.js.map +1 -1
  94. package/dist/esm/oauth-providers/dropbox.js +3 -2
  95. package/dist/esm/oauth-providers/dropbox.js.map +1 -1
  96. package/dist/esm/oauth-providers/facebook.js +3 -2
  97. package/dist/esm/oauth-providers/facebook.js.map +1 -1
  98. package/dist/esm/oauth-providers/google.js +3 -2
  99. package/dist/esm/oauth-providers/google.js.map +1 -1
  100. package/dist/esm/oauth-providers/index.js.map +1 -1
  101. package/dist/esm/oauth-providers/instagram.js +3 -2
  102. package/dist/esm/oauth-providers/instagram.js.map +1 -1
  103. package/dist/esm/oauth-providers/oauth-provider.js +21 -1
  104. package/dist/esm/oauth-providers/oauth-provider.js.map +1 -1
  105. package/dist/esm/oauth-providers/spotify.js +3 -2
  106. package/dist/esm/oauth-providers/spotify.js.map +1 -1
  107. package/dist/esm/routes/auth-change-password.js +6 -3
  108. package/dist/esm/routes/auth-change-password.js.map +1 -1
  109. package/dist/esm/routes/auth-delete.js +7 -5
  110. package/dist/esm/routes/auth-delete.js.map +1 -1
  111. package/dist/esm/routes/auth-forgot-password.js +8 -6
  112. package/dist/esm/routes/auth-forgot-password.js.map +1 -1
  113. package/dist/esm/routes/auth-reset-password.js +4 -2
  114. package/dist/esm/routes/auth-reset-password.js.map +1 -1
  115. package/dist/esm/routes/auth-signout.js +4 -2
  116. package/dist/esm/routes/auth-signout.js.map +1 -1
  117. package/dist/esm/routes/auth-signup.js +12 -10
  118. package/dist/esm/routes/auth-signup.js.map +1 -1
  119. package/dist/esm/routes/auth-update.js +8 -6
  120. package/dist/esm/routes/auth-update.js.map +1 -1
  121. package/dist/esm/routes/auth-verify-email.js +6 -2
  122. package/dist/esm/routes/auth-verify-email.js.map +1 -1
  123. package/dist/esm/routes/data-index-create.js +4 -6
  124. package/dist/esm/routes/data-index-create.js.map +1 -1
  125. package/dist/esm/routes/data-index-delete.js +3 -5
  126. package/dist/esm/routes/data-index-delete.js.map +1 -1
  127. package/dist/esm/routes/data-index-list.js +3 -5
  128. package/dist/esm/routes/data-index-list.js.map +1 -1
  129. package/dist/esm/routes/data-reflect.js +1 -4
  130. package/dist/esm/routes/data-reflect.js.map +1 -1
  131. package/dist/esm/routes/data-schema-get.js +3 -5
  132. package/dist/esm/routes/data-schema-get.js.map +1 -1
  133. package/dist/esm/routes/data-schema-set.js +3 -5
  134. package/dist/esm/routes/data-schema-set.js.map +1 -1
  135. package/dist/esm/routes/data-schema-test.js +3 -5
  136. package/dist/esm/routes/data-schema-test.js.map +1 -1
  137. package/dist/esm/routes/data-schemas-list.js +3 -5
  138. package/dist/esm/routes/data-schemas-list.js.map +1 -1
  139. package/dist/esm/routes/data-set.js +9 -5
  140. package/dist/esm/routes/data-set.js.map +1 -1
  141. package/dist/esm/routes/data-sync-changes.js.map +1 -1
  142. package/dist/esm/routes/data-sync-mutations.js.map +1 -1
  143. package/dist/esm/routes/data-transaction.js +28 -8
  144. package/dist/esm/routes/data-transaction.js.map +1 -1
  145. package/dist/esm/routes/data-update.js +9 -4
  146. package/dist/esm/routes/data-update.js.map +1 -1
  147. package/dist/esm/routes/meta-info.js.map +1 -1
  148. package/dist/esm/routes/meta-logs.js +36 -0
  149. package/dist/esm/routes/meta-logs.js.map +1 -0
  150. package/dist/esm/routes/meta.js +3 -0
  151. package/dist/esm/routes/meta.js.map +1 -1
  152. package/dist/esm/routes/oauth2-signin.js +14 -10
  153. package/dist/esm/routes/oauth2-signin.js.map +1 -1
  154. package/dist/esm/rules.js +5 -5
  155. package/dist/esm/rules.js.map +1 -1
  156. package/dist/esm/server.js +6 -4
  157. package/dist/esm/server.js.map +1 -1
  158. package/dist/esm/settings/index.js +5 -6
  159. package/dist/esm/settings/index.js.map +1 -1
  160. package/dist/esm/shared/clients.js.map +1 -1
  161. package/dist/esm/shared/env.js.map +1 -1
  162. package/dist/esm/shared/http.js.map +1 -1
  163. package/dist/esm/shared/signin.js +7 -3
  164. package/dist/esm/shared/signin.js.map +1 -1
  165. package/dist/esm/start.js +3 -0
  166. package/dist/esm/start.js.map +1 -1
  167. package/dist/esm/websocket/index.js +38 -23
  168. package/dist/esm/websocket/index.js.map +1 -1
  169. package/dist/esm/websocket/socket.io.js +9 -11
  170. package/dist/esm/websocket/socket.io.js.map +1 -1
  171. package/dist/types/index.d.ts +2 -0
  172. package/dist/types/logger.d.ts +35 -0
  173. package/dist/types/middleware/admin-only.d.ts +19 -0
  174. package/dist/types/oauth-providers/dropbox.d.ts +3 -14
  175. package/dist/types/oauth-providers/facebook.d.ts +3 -7
  176. package/dist/types/oauth-providers/google.d.ts +3 -7
  177. package/dist/types/oauth-providers/index.d.ts +2 -10
  178. package/dist/types/oauth-providers/instagram.d.ts +3 -7
  179. package/dist/types/oauth-providers/oauth-provider.d.ts +25 -21
  180. package/dist/types/oauth-providers/spotify.d.ts +3 -7
  181. package/dist/types/routes/data-query.d.ts +1 -1
  182. package/dist/types/routes/meta-logs.d.ts +20 -0
  183. package/dist/types/rules.d.ts +4 -4
  184. package/dist/types/server.d.ts +9 -7
  185. package/dist/types/settings/email.d.ts +1 -1
  186. package/dist/types/settings/index.d.ts +5 -6
  187. package/dist/types/shared/clients.d.ts +3 -1
  188. package/dist/types/shared/env.d.ts +6 -4
  189. package/dist/types/shared/http.d.ts +2 -0
  190. package/dist/types/shared/signin.d.ts +1 -1
  191. package/dist/types/websocket/index.d.ts +4 -0
  192. package/dist/types/websocket/manager.d.ts +1 -1
  193. package/package.json +12 -11
  194. package/src/index.ts +3 -1
  195. package/src/logger.ts +56 -0
  196. package/src/middleware/admin-only.ts +29 -0
  197. package/src/middleware/user.ts +4 -4
  198. package/src/oauth-providers/dropbox.ts +5 -4
  199. package/src/oauth-providers/facebook.ts +5 -4
  200. package/src/oauth-providers/google.ts +5 -4
  201. package/src/oauth-providers/index.ts +2 -1
  202. package/src/oauth-providers/instagram.ts +5 -4
  203. package/src/oauth-providers/oauth-provider.ts +14 -4
  204. package/src/oauth-providers/spotify.ts +5 -4
  205. package/src/placeholder.d.ts +12 -0
  206. package/src/routes/auth-change-password.ts +6 -3
  207. package/src/routes/auth-delete.ts +7 -5
  208. package/src/routes/auth-forgot-password.ts +10 -6
  209. package/src/routes/auth-reset-password.ts +5 -2
  210. package/src/routes/auth-signout.ts +5 -2
  211. package/src/routes/auth-signup.ts +13 -10
  212. package/src/routes/auth-update.ts +8 -6
  213. package/src/routes/auth-verify-email.ts +11 -3
  214. package/src/routes/data-index-create.ts +4 -7
  215. package/src/routes/data-index-delete.ts +3 -6
  216. package/src/routes/data-index-list.ts +3 -6
  217. package/src/routes/data-query.ts +1 -1
  218. package/src/routes/data-reflect.ts +1 -4
  219. package/src/routes/data-schema-get.ts +3 -5
  220. package/src/routes/data-schema-set.ts +3 -6
  221. package/src/routes/data-schema-test.ts +3 -6
  222. package/src/routes/data-schemas-list.ts +3 -5
  223. package/src/routes/data-set.ts +14 -6
  224. package/src/routes/data-set.yaml +7 -1
  225. package/src/routes/data-sync-changes.ts +1 -1
  226. package/src/routes/data-sync-mutations.ts +1 -1
  227. package/src/routes/data-transaction-finish.yaml +6 -0
  228. package/src/routes/data-transaction.ts +35 -11
  229. package/src/routes/data-update.ts +12 -4
  230. package/src/routes/data-update.yaml +7 -1
  231. package/src/routes/meta-info.ts +1 -1
  232. package/src/routes/meta-logs.ts +57 -0
  233. package/src/routes/meta.ts +4 -0
  234. package/src/routes/oauth2-signin.ts +17 -12
  235. package/src/rules.ts +8 -8
  236. package/src/server.ts +13 -9
  237. package/src/settings/email.ts +1 -1
  238. package/src/settings/index.ts +7 -7
  239. package/src/shared/clients.ts +1 -1
  240. package/src/shared/env.ts +5 -4
  241. package/src/shared/http.ts +2 -0
  242. package/src/shared/signin.ts +10 -4
  243. package/src/start.ts +3 -0
  244. package/src/websocket/index.ts +41 -24
  245. package/src/websocket/manager.ts +1 -1
  246. package/src/websocket/socket.io.ts +9 -10
  247. package/webmanager/acebase-client-browser.min.js +16 -0
  248. package/webmanager/index.html +2 -2
  249. package/webmanager/index.js +3 -6
  250. package/.vscode/launch.json +0 -24
@@ -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;
@@ -0,0 +1,20 @@
1
+ import { QueryOperator } from 'acebase-core/types/data-reference';
2
+ import { RouteInitEnvironment, RouteRequest } from '../shared/env';
3
+ declare type AceBaseLogLine = {
4
+ action: string;
5
+ ip: string;
6
+ date: string;
7
+ };
8
+ export declare type RequestQuery = {
9
+ take?: string;
10
+ skip?: string;
11
+ sort?: 'date';
12
+ filter_col?: string;
13
+ filter_op?: QueryOperator;
14
+ filter_val?: string;
15
+ };
16
+ export declare type RequestBody = null;
17
+ export declare type ResponseBody = AceBaseLogLine[];
18
+ export declare type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>;
19
+ export declare const addRoute: (env: RouteInitEnvironment) => void;
20
+ export default addRoute;
@@ -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;
@@ -9,7 +9,7 @@ declare type HasAccessResult = {
9
9
  message?: string;
10
10
  rule?: string | boolean;
11
11
  rulePath?: string;
12
- details?: any;
12
+ details?: Error;
13
13
  } & ({
14
14
  allow: true;
15
15
  } | {
@@ -18,13 +18,13 @@ declare type HasAccessResult = {
18
18
  message: string;
19
19
  rule?: string | boolean;
20
20
  rulePath?: string;
21
- details?: any;
21
+ details?: Error;
22
22
  });
23
23
  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
  };
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  /// <reference types="express" />
3
4
  import type { HttpApp, Request } from './http';
4
5
  import type { AceBase, DataReference } from 'acebase';
@@ -6,11 +7,12 @@ import type { AceBaseServerConfig } from '../settings';
6
7
  import type { DbUserAccountDetails } from '../schema/user';
7
8
  import type { ConnectedClient } from './clients';
8
9
  import type { DebugLogger, SimpleCache } from 'acebase-core';
9
- import type { IOAuth2Provider } from '../oauth-providers/oauth-provider';
10
+ import type { OAuth2Provider } from '../oauth-providers/oauth-provider';
10
11
  import type { Server as HttpServer } from 'http';
11
12
  import type { Server as SecureHttpServer } from 'https';
12
13
  import type { PathBasedRules } from '../rules';
13
14
  import { Api } from 'acebase-core/src/api';
15
+ import { DatabaseLog } from '../logger';
14
16
  export interface RouteInitEnvironment {
15
17
  server: HttpServer | SecureHttpServer;
16
18
  app: HttpApp;
@@ -22,12 +24,12 @@ export interface RouteInitEnvironment {
22
24
  debug: DebugLogger;
23
25
  securityRef: DataReference;
24
26
  authRef: DataReference;
25
- logRef: DataReference;
27
+ log: DatabaseLog;
26
28
  tokenSalt: string;
27
29
  clients: Map<string, ConnectedClient>;
28
30
  authCache: SimpleCache<string, DbUserAccountDetails>;
29
31
  authProviders: {
30
- [providerName: string]: IOAuth2Provider;
32
+ [providerName: string]: OAuth2Provider;
31
33
  };
32
34
  rules: PathBasedRules;
33
35
  }
@@ -35,7 +37,7 @@ export interface RouteRequestEnvironment {
35
37
  /** If the request has an Authentication: bearer token, the user will be bound to the incoming request */
36
38
  user?: DbUserAccountDetails;
37
39
  /** If context is sent through AceBase-Context header, it will be bound to the incoming request */
38
- context?: {
40
+ context: {
39
41
  [key: string]: any;
40
42
  };
41
43
  }
@@ -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
@@ -4,7 +4,7 @@ export declare type SignInCredentials = {
4
4
  method: 'token';
5
5
  access_token: string;
6
6
  } | {
7
- method: 'private_token';
7
+ method: 'internal';
8
8
  access_token: string;
9
9
  } | {
10
10
  method: 'email';
@@ -1,2 +1,6 @@
1
1
  import { RouteInitEnvironment } from "../shared/env";
2
+ export declare class SocketRequestError extends Error {
3
+ code: string;
4
+ constructor(code: string, message: string);
5
+ }
2
6
  export declare const addWebsocketServer: (env: RouteInitEnvironment) => import("./socket.io").SocketIOManager;
@@ -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.0",
3
+ "version": "1.12.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,13 +14,14 @@
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 AUTH=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/*",
21
21
  "build:esm": "tsc -p tsconfig.json && npx tsc-esm-fix ---target='dist/esm'",
22
22
  "build:cjs": "tsc -p tsconfig-cjs.json",
23
- "build:packages": "bash ./create-package-files"
23
+ "build:packages": "bash ./create-package-files",
24
+ "npmfix": "echo 'Regenerating package-lock.json...' && npm i --package--lock-only"
24
25
  },
25
26
  "keywords": [
26
27
  "database",
@@ -56,18 +57,18 @@
56
57
  "author": "Ewout Stortenbeker <me@appy.one> (http://appy.one)",
57
58
  "license": "MIT",
58
59
  "dependencies": {
59
- "acebase": "^1.17.0",
60
- "acebase-core": "^1.15.0",
60
+ "acebase": "^1.22.0",
61
+ "acebase-core": "^1.20.0",
61
62
  "express": "^4.17.1",
62
- "socket.io": "^2.4.1"
63
+ "socket.io": "^4.5.0",
64
+ "swagger-jsdoc": "^6.1.0",
65
+ "swagger-ui-express": "^4.3.0"
63
66
  },
64
67
  "devDependencies": {
65
68
  "@types/express": "^4.17.13",
66
- "@types/node": "^14.0.14",
67
- "@types/socket.io": "^2.1.13",
68
- "swagger-jsdoc": "^6.1.0",
69
- "swagger-ui-express": "^4.3.0",
69
+ "@types/node": "^10.17.60",
70
+ "@types/socket.io": "^3.0.2",
70
71
  "tsc-esm-fix": "^2.12.4",
71
- "typescript": "^4.6.3"
72
+ "typescript": "^4.7.4"
72
73
  }
73
74
  }
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';
package/src/logger.ts ADDED
@@ -0,0 +1,56 @@
1
+ import { DataReference } from "acebase-core";
2
+
3
+ export class DatabaseLog {
4
+ constructor(private logRef: DataReference) {}
5
+
6
+ /**
7
+ * Logs an action initiated by a client/user with a positive or negative outcome. Used by `success` and `failure`
8
+ * @param action action identifier
9
+ * @param success whether the action was successful
10
+ * @param details any additional details to be logged
11
+ */
12
+ async event(action: string, details: any) {
13
+ await this.logRef?.push({ type: 'event', action, date: new Date(), ...details });
14
+ }
15
+
16
+ /**
17
+ * Logs a system warning
18
+ * @param action action identifier
19
+ * @param code warning code
20
+ * @param details any additional details to be logged
21
+ */
22
+ async warning(action: string, code: string, details: any) {
23
+ await this.logRef?.push({ type: 'warning', action, code, date: new Date(), ...details });
24
+ }
25
+
26
+ /**
27
+ * Logs a system or client/user error
28
+ * @param action action identifier
29
+ * @param code error code
30
+ * @param details any additional details to be logged
31
+ */
32
+ async error(action: string, code: string, details: any, unexpectedError?: any) {
33
+ const errorDetails = unexpectedError instanceof Error
34
+ ? { error: unexpectedError.stack ?? unexpectedError.message }
35
+ : { error: unexpectedError?.message ?? unexpectedError?.toString() ?? null };
36
+ await this.logRef?.push({ type: 'error', action, code, date: new Date(), ...errorDetails, ...details });
37
+ }
38
+
39
+ /**
40
+ * Query the logs
41
+ * @returns
42
+ */
43
+ query() {
44
+ if (!this.logRef) {
45
+ throw new Error('Logging is not enabled');
46
+ }
47
+ return this.logRef.query();
48
+ }
49
+
50
+ /**
51
+ * Reference to the logs database collection
52
+ */
53
+ get ref() {
54
+ return this?.logRef;
55
+ }
56
+ }
@@ -0,0 +1,29 @@
1
+ import { NextFunction } from "express"
2
+ import { RouteInitEnvironment, RouteRequest } from "../shared/env"
3
+ import { sendUnauthorizedError } from "../shared/error"
4
+ import type { Response } from "../shared/http"
5
+
6
+ /**
7
+ * Middleware function that checks if the current user is `admin`. An 403 Forbidden error will be sent in the response if
8
+ * authentication is enabled on the server and the user is not signed in as admin.
9
+ *
10
+ * Can be applied to any route by adding it in the router chain.
11
+ * @example
12
+ * app.get('/endpoint', adminOnly(env), (req, res) => {
13
+ * // If we get here we are either an admin,
14
+ * // or the server doesn't have authentication enabled.
15
+ * })
16
+ * @param env Middle
17
+ * @param errorMessage
18
+ * @returns
19
+ */
20
+ export const adminOnly = (env: RouteInitEnvironment, errorMessage: string = 'only admin can perform this operation') => {
21
+ return (req: RouteRequest, res: Response, next: NextFunction) => {
22
+ if (env.config.auth.enabled && (!req.user || req.user.uid !== 'admin')) {
23
+ return sendUnauthorizedError(res, 'admin_only', errorMessage);
24
+ }
25
+ next();
26
+ }
27
+ }
28
+
29
+ export default adminOnly;
@@ -10,9 +10,9 @@ export const addMiddleware = (env: RouteInitEnvironment) => {
10
10
 
11
11
  let authorization = req.get('Authorization');
12
12
  if (typeof authorization !== 'string' && 'auth_token' in req.query) {
13
- // Enables browser calls to be authenticated
14
- if (req.path.startsWith('/export/')) {
15
- // For now, only allow this if the intention is to call '/export' api call
13
+ // Enables browser calls to be authenticated by adding the access token as auth_token query parameter
14
+ if (req.path.startsWith('/export/') || req.path.startsWith('/logs')) {
15
+ // For now, only allow '/export' or '/logs' api calls
16
16
  // In the future, use these prerequisites:
17
17
  // - user must be currently authenticated (in cache)
18
18
  // - ip address must match the token
@@ -35,7 +35,7 @@ export const addMiddleware = (env: RouteInitEnvironment) => {
35
35
  if (!req.user) {
36
36
  // Query database to get user for this token
37
37
  try {
38
- await signIn({ method: 'private_token', access_token: tokenDetails.access_token }, env, req);
38
+ await signIn({ method: 'internal', access_token: tokenDetails.access_token }, env, req);
39
39
  }
40
40
  catch (err) {
41
41
  return sendNotAuthenticatedError(res, err.code, err.message);
@@ -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
+ }