acebase-server 1.16.2 → 1.17.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/README.md +180 -10
  2. package/build-vars.js +2 -1
  3. package/dist/cjs/auth.js +88 -88
  4. package/dist/cjs/cluster.js +56 -56
  5. package/dist/cjs/index.d.ts +1 -1
  6. package/dist/cjs/index.js +24 -24
  7. package/dist/cjs/logger.js +73 -73
  8. package/dist/cjs/middleware/404.js +14 -14
  9. package/dist/cjs/middleware/admin-only.js +28 -28
  10. package/dist/cjs/middleware/cache.js +14 -14
  11. package/dist/cjs/middleware/connection.js +49 -49
  12. package/dist/cjs/middleware/context.js +20 -20
  13. package/dist/cjs/middleware/cors.js +50 -50
  14. package/dist/cjs/middleware/swagger.js +17 -17
  15. package/dist/cjs/middleware/user.js +57 -57
  16. package/dist/cjs/oauth-providers/dropbox.js +109 -109
  17. package/dist/cjs/oauth-providers/facebook.js +85 -85
  18. package/dist/cjs/oauth-providers/google.js +119 -119
  19. package/dist/cjs/oauth-providers/index.js +26 -26
  20. package/dist/cjs/oauth-providers/instagram.js +80 -80
  21. package/dist/cjs/oauth-providers/oauth-provider.js +20 -20
  22. package/dist/cjs/oauth-providers/spotify.js +113 -113
  23. package/dist/cjs/routes/auth-change-password.js +87 -87
  24. package/dist/cjs/routes/auth-delete.js +52 -52
  25. package/dist/cjs/routes/auth-forgot-password.js +77 -77
  26. package/dist/cjs/routes/auth-reset-password.js +97 -97
  27. package/dist/cjs/routes/auth-signin.js +46 -46
  28. package/dist/cjs/routes/auth-signout.js +61 -61
  29. package/dist/cjs/routes/auth-signup.js +142 -142
  30. package/dist/cjs/routes/auth-state.js +25 -25
  31. package/dist/cjs/routes/auth-update.js +131 -131
  32. package/dist/cjs/routes/auth-verify-email.js +71 -71
  33. package/dist/cjs/routes/auth.js +57 -54
  34. package/dist/cjs/routes/data-exists.js +33 -33
  35. package/dist/cjs/routes/data-export.js +48 -48
  36. package/dist/cjs/routes/data-get.js +70 -66
  37. package/dist/cjs/routes/data-import.js +54 -54
  38. package/dist/cjs/routes/data-index-create.js +42 -42
  39. package/dist/cjs/routes/data-index-delete.js +33 -33
  40. package/dist/cjs/routes/data-index-list.js +31 -31
  41. package/dist/cjs/routes/data-query.js +80 -70
  42. package/dist/cjs/routes/data-reflect.js +97 -86
  43. package/dist/cjs/routes/data-schema-get.js +36 -36
  44. package/dist/cjs/routes/data-schema-set.js +30 -30
  45. package/dist/cjs/routes/data-schema-test.js +43 -43
  46. package/dist/cjs/routes/data-schemas-list.js +32 -32
  47. package/dist/cjs/routes/data-set.js +85 -75
  48. package/dist/cjs/routes/data-sync-changes.js +81 -67
  49. package/dist/cjs/routes/data-sync-mutations.js +81 -67
  50. package/dist/cjs/routes/data-transaction.js +159 -139
  51. package/dist/cjs/routes/data-update.js +86 -75
  52. package/dist/cjs/routes/data.js +62 -62
  53. package/dist/cjs/routes/docs.js +258 -251
  54. package/dist/cjs/routes/meta-info.js +63 -63
  55. package/dist/cjs/routes/meta-logs.js +49 -49
  56. package/dist/cjs/routes/meta-ping.js +11 -11
  57. package/dist/cjs/routes/meta-stats.js +27 -27
  58. package/dist/cjs/routes/meta.js +19 -19
  59. package/dist/cjs/routes/oauth2-init.js +54 -54
  60. package/dist/cjs/routes/oauth2-refresh.js +42 -42
  61. package/dist/cjs/routes/oauth2-signin.js +265 -265
  62. package/dist/cjs/routes/webmanager.js +26 -26
  63. package/dist/cjs/rules.js +380 -167
  64. package/dist/cjs/sandbox.js +28 -0
  65. package/dist/cjs/schema/user.js +24 -24
  66. package/dist/cjs/server.js +415 -407
  67. package/dist/cjs/settings/email.js +2 -2
  68. package/dist/cjs/settings/index.js +175 -172
  69. package/dist/cjs/shared/clients.js +26 -26
  70. package/dist/cjs/shared/email.js +2 -2
  71. package/dist/cjs/shared/env.js +2 -2
  72. package/dist/cjs/shared/error.js +33 -33
  73. package/dist/cjs/shared/http.js +28 -28
  74. package/dist/cjs/shared/password.js +45 -45
  75. package/dist/cjs/shared/rootpath.js +16 -16
  76. package/dist/cjs/shared/signin.js +143 -143
  77. package/dist/cjs/shared/simple-fetch.js +76 -76
  78. package/dist/cjs/shared/tokens.js +79 -79
  79. package/dist/cjs/shared/validate.js +61 -61
  80. package/dist/cjs/start.js +53 -53
  81. package/dist/cjs/test.js +10 -10
  82. package/dist/cjs/websocket/index.js +331 -319
  83. package/dist/cjs/websocket/manager.js +15 -15
  84. package/dist/cjs/websocket/socket.io.js +76 -76
  85. package/dist/esm/auth.js +75 -75
  86. package/dist/esm/cluster.js +54 -54
  87. package/dist/esm/index.d.ts +1 -1
  88. package/dist/esm/index.js +4 -4
  89. package/dist/esm/logger.js +51 -51
  90. package/dist/esm/middleware/404.js +10 -10
  91. package/dist/esm/middleware/admin-only.js +24 -24
  92. package/dist/esm/middleware/cache.js +10 -10
  93. package/dist/esm/middleware/connection.js +45 -45
  94. package/dist/esm/middleware/context.js +16 -16
  95. package/dist/esm/middleware/cors.js +44 -44
  96. package/dist/esm/middleware/swagger.js +13 -13
  97. package/dist/esm/middleware/user.js +44 -44
  98. package/dist/esm/oauth-providers/dropbox.js +90 -90
  99. package/dist/esm/oauth-providers/facebook.js +66 -66
  100. package/dist/esm/oauth-providers/google.js +96 -96
  101. package/dist/esm/oauth-providers/index.js +18 -18
  102. package/dist/esm/oauth-providers/instagram.js +61 -61
  103. package/dist/esm/oauth-providers/oauth-provider.js +16 -16
  104. package/dist/esm/oauth-providers/spotify.js +92 -92
  105. package/dist/esm/routes/auth-change-password.js +72 -72
  106. package/dist/esm/routes/auth-delete.js +37 -37
  107. package/dist/esm/routes/auth-forgot-password.js +62 -62
  108. package/dist/esm/routes/auth-reset-password.js +81 -81
  109. package/dist/esm/routes/auth-signin.js +33 -33
  110. package/dist/esm/routes/auth-signout.js +47 -47
  111. package/dist/esm/routes/auth-signup.js +127 -127
  112. package/dist/esm/routes/auth-state.js +12 -12
  113. package/dist/esm/routes/auth-update.js +116 -116
  114. package/dist/esm/routes/auth-verify-email.js +57 -57
  115. package/dist/esm/routes/auth.js +53 -50
  116. package/dist/esm/routes/data-exists.js +20 -20
  117. package/dist/esm/routes/data-export.js +35 -35
  118. package/dist/esm/routes/data-get.js +56 -52
  119. package/dist/esm/routes/data-import.js +41 -41
  120. package/dist/esm/routes/data-index-create.js +28 -28
  121. package/dist/esm/routes/data-index-delete.js +20 -20
  122. package/dist/esm/routes/data-index-list.js +18 -18
  123. package/dist/esm/routes/data-query.js +66 -56
  124. package/dist/esm/routes/data-reflect.js +83 -72
  125. package/dist/esm/routes/data-schema-get.js +23 -23
  126. package/dist/esm/routes/data-schema-set.js +17 -17
  127. package/dist/esm/routes/data-schema-test.js +29 -29
  128. package/dist/esm/routes/data-schemas-list.js +19 -19
  129. package/dist/esm/routes/data-set.js +70 -60
  130. package/dist/esm/routes/data-sync-changes.js +67 -53
  131. package/dist/esm/routes/data-sync-mutations.js +67 -53
  132. package/dist/esm/routes/data-transaction.js +142 -123
  133. package/dist/esm/routes/data-update.js +71 -60
  134. package/dist/esm/routes/data.js +58 -58
  135. package/dist/esm/routes/docs.js +252 -245
  136. package/dist/esm/routes/meta-info.js +59 -59
  137. package/dist/esm/routes/meta-logs.js +35 -35
  138. package/dist/esm/routes/meta-ping.js +7 -7
  139. package/dist/esm/routes/meta-stats.js +14 -14
  140. package/dist/esm/routes/meta.js +15 -15
  141. package/dist/esm/routes/oauth2-init.js +41 -41
  142. package/dist/esm/routes/oauth2-refresh.js +29 -29
  143. package/dist/esm/routes/oauth2-signin.js +251 -251
  144. package/dist/esm/routes/webmanager.js +22 -22
  145. package/dist/esm/rules.js +374 -163
  146. package/dist/esm/sandbox.js +12 -0
  147. package/dist/esm/schema/user.js +19 -19
  148. package/dist/esm/server.js +395 -387
  149. package/dist/esm/settings/email.js +1 -1
  150. package/dist/esm/settings/index.js +168 -165
  151. package/dist/esm/shared/clients.js +22 -22
  152. package/dist/esm/shared/email.js +1 -1
  153. package/dist/esm/shared/env.js +1 -1
  154. package/dist/esm/shared/error.js +25 -25
  155. package/dist/esm/shared/http.js +22 -22
  156. package/dist/esm/shared/password.js +38 -38
  157. package/dist/esm/shared/rootpath.js +13 -13
  158. package/dist/esm/shared/signin.js +128 -128
  159. package/dist/esm/shared/simple-fetch.js +59 -59
  160. package/dist/esm/shared/tokens.js +72 -72
  161. package/dist/esm/shared/validate.js +41 -41
  162. package/dist/esm/start.js +50 -50
  163. package/dist/esm/test.js +8 -8
  164. package/dist/esm/websocket/index.js +313 -302
  165. package/dist/esm/websocket/manager.js +11 -11
  166. package/dist/esm/websocket/socket.io.js +71 -71
  167. package/dist/types/auth.d.ts +3 -3
  168. package/dist/types/cluster.d.ts +1 -1
  169. package/dist/types/index.d.ts +4 -4
  170. package/dist/types/logger.d.ts +35 -35
  171. package/dist/types/middleware/404.d.ts +7 -7
  172. package/dist/types/middleware/admin-only.d.ts +19 -19
  173. package/dist/types/middleware/cache.d.ts +3 -3
  174. package/dist/types/middleware/connection.d.ts +7 -7
  175. package/dist/types/middleware/context.d.ts +3 -3
  176. package/dist/types/middleware/cors.d.ts +25 -25
  177. package/dist/types/middleware/swagger.d.ts +3 -3
  178. package/dist/types/middleware/user.d.ts +2 -2
  179. package/dist/types/oauth-providers/dropbox.d.ts +52 -52
  180. package/dist/types/oauth-providers/facebook.d.ts +41 -41
  181. package/dist/types/oauth-providers/google.d.ts +43 -43
  182. package/dist/types/oauth-providers/index.d.ts +10 -10
  183. package/dist/types/oauth-providers/instagram.d.ts +50 -50
  184. package/dist/types/oauth-providers/oauth-provider.d.ts +74 -74
  185. package/dist/types/oauth-providers/spotify.d.ts +53 -53
  186. package/dist/types/routes/auth-change-password.d.ts +20 -20
  187. package/dist/types/routes/auth-delete.d.ts +16 -16
  188. package/dist/types/routes/auth-forgot-password.d.ts +16 -16
  189. package/dist/types/routes/auth-reset-password.d.ts +23 -23
  190. package/dist/types/routes/auth-signin.d.ts +24 -24
  191. package/dist/types/routes/auth-signout.d.ts +14 -14
  192. package/dist/types/routes/auth-signup.d.ts +32 -32
  193. package/dist/types/routes/auth-state.d.ts +13 -13
  194. package/dist/types/routes/auth-update.d.ts +33 -33
  195. package/dist/types/routes/auth-verify-email.d.ts +21 -21
  196. package/dist/types/routes/auth.d.ts +6 -6
  197. package/dist/types/routes/data-exists.d.ts +9 -9
  198. package/dist/types/routes/data-export.d.ts +10 -10
  199. package/dist/types/routes/data-get.d.ts +14 -14
  200. package/dist/types/routes/data-import.d.ts +13 -13
  201. package/dist/types/routes/data-index-create.d.ts +51 -51
  202. package/dist/types/routes/data-index-delete.d.ts +17 -17
  203. package/dist/types/routes/data-index-list.d.ts +21 -21
  204. package/dist/types/routes/data-query.d.ts +49 -49
  205. package/dist/types/routes/data-reflect.d.ts +29 -29
  206. package/dist/types/routes/data-schema-get.d.ts +11 -11
  207. package/dist/types/routes/data-schema-set.d.ts +19 -19
  208. package/dist/types/routes/data-schema-test.d.ts +19 -19
  209. package/dist/types/routes/data-schemas-list.d.ts +11 -11
  210. package/dist/types/routes/data-set.d.ts +27 -27
  211. package/dist/types/routes/data-sync-changes.d.ts +25 -28
  212. package/dist/types/routes/data-sync-mutations.d.ts +25 -28
  213. package/dist/types/routes/data-transaction.d.ts +34 -34
  214. package/dist/types/routes/data-update.d.ts +27 -27
  215. package/dist/types/routes/data.d.ts +3 -3
  216. package/dist/types/routes/docs.d.ts +3 -3
  217. package/dist/types/routes/meta-info.d.ts +11 -11
  218. package/dist/types/routes/meta-logs.d.ts +20 -20
  219. package/dist/types/routes/meta-ping.d.ts +7 -7
  220. package/dist/types/routes/meta-stats.d.ts +13 -13
  221. package/dist/types/routes/meta.d.ts +3 -3
  222. package/dist/types/routes/oauth2-init.d.ts +13 -13
  223. package/dist/types/routes/oauth2-refresh.d.ts +17 -17
  224. package/dist/types/routes/oauth2-signin.d.ts +15 -15
  225. package/dist/types/routes/webmanager.d.ts +3 -3
  226. package/dist/types/rules.d.ts +73 -34
  227. package/dist/types/sandbox.d.ts +3 -0
  228. package/dist/types/schema/user.d.ts +85 -85
  229. package/dist/types/server.d.ts +117 -111
  230. package/dist/types/settings/email.d.ts +14 -14
  231. package/dist/types/settings/index.d.ts +195 -187
  232. package/dist/types/shared/clients.d.ts +46 -46
  233. package/dist/types/shared/email.d.ts +34 -34
  234. package/dist/types/shared/env.d.ts +47 -44
  235. package/dist/types/shared/error.d.ts +15 -15
  236. package/dist/types/shared/http.d.ts +22 -21
  237. package/dist/types/shared/password.d.ts +19 -19
  238. package/dist/types/shared/rootpath.d.ts +2 -2
  239. package/dist/types/shared/signin.d.ts +31 -31
  240. package/dist/types/shared/simple-fetch.d.ts +21 -21
  241. package/dist/types/shared/tokens.d.ts +24 -24
  242. package/dist/types/shared/validate.d.ts +22 -22
  243. package/dist/types/start.d.ts +1 -1
  244. package/dist/types/test.d.ts +1 -1
  245. package/dist/types/websocket/index.d.ts +6 -6
  246. package/dist/types/websocket/manager.d.ts +99 -99
  247. package/dist/types/websocket/socket.io.d.ts +10 -10
  248. package/package.json +4 -4
  249. package/src/routes/data-set.yaml +5 -5
  250. package/src/routes/data-update.yaml +4 -4
@@ -1,11 +1,11 @@
1
- export const addMiddleware = (env) => {
2
- env.app.use((req, res, next) => {
3
- // Disable cache for GET requests to make sure browsers do not use cached responses
4
- if (req.method === 'GET') {
5
- res.setHeader('Cache-Control', 'no-cache');
6
- }
7
- next();
8
- });
9
- };
10
- export default addMiddleware;
1
+ export const addMiddleware = (env) => {
2
+ env.router.use((req, res, next) => {
3
+ // Disable cache for GET requests to make sure browsers do not use cached responses
4
+ if (req.method === 'GET') {
5
+ res.setHeader('Cache-Control', 'no-cache');
6
+ }
7
+ next();
8
+ });
9
+ };
10
+ export default addMiddleware;
11
11
  //# sourceMappingURL=cache.js.map
@@ -1,46 +1,46 @@
1
- /**
2
- * Adds connection management middleware. Add this as very first handler!
3
- * @param env
4
- */
5
- export const addMiddleware = (env) => {
6
- const sockets = new Set();
7
- let terminating = false;
8
- const destroySocket = (socket) => {
9
- socket.destroy();
10
- };
11
- const addConnection = (socket) => {
12
- // console.log(`event: server.connection`);
13
- if (terminating) {
14
- destroySocket(socket);
15
- }
16
- else {
17
- sockets.add(socket);
18
- socket.once('close', () => {
19
- // console.log(`event: socket.close`);
20
- sockets.delete(socket);
21
- });
22
- }
23
- };
24
- env.server.on('connection', addConnection);
25
- env.server.on('secureConnection', addConnection);
26
- // Don't enable this: it'll make every other request real slow
27
- // env.app.use((req, res, next) => {
28
- // res.setHeader('Connection', 'close');
29
- // next();
30
- // });
31
- const terminate = () => {
32
- terminating = true;
33
- console.warn(`Terminating ${sockets.size} open connections`);
34
- sockets.forEach(socket => {
35
- try {
36
- destroySocket(socket);
37
- }
38
- catch (err) {
39
- console.error(`Cannot destroy socket: ${err.message}`);
40
- }
41
- });
42
- };
43
- return terminate;
44
- };
45
- export default addMiddleware;
1
+ /**
2
+ * Adds connection management middleware. Add this as very first handler!
3
+ * @param env
4
+ */
5
+ export const addMiddleware = (env) => {
6
+ const sockets = new Set();
7
+ let terminating = false;
8
+ const destroySocket = (socket) => {
9
+ socket.destroy();
10
+ };
11
+ const addConnection = (socket) => {
12
+ // console.log(`event: server.connection`);
13
+ if (terminating) {
14
+ destroySocket(socket);
15
+ }
16
+ else {
17
+ sockets.add(socket);
18
+ socket.once('close', () => {
19
+ // console.log(`event: socket.close`);
20
+ sockets.delete(socket);
21
+ });
22
+ }
23
+ };
24
+ env.server.on('connection', addConnection);
25
+ env.server.on('secureConnection', addConnection);
26
+ // Don't enable this: it'll make every other request real slow
27
+ // env.app.use((req, res, next) => {
28
+ // res.setHeader('Connection', 'close');
29
+ // next();
30
+ // });
31
+ const terminate = () => {
32
+ terminating = true;
33
+ console.warn(`Terminating ${sockets.size} open connections`);
34
+ sockets.forEach(socket => {
35
+ try {
36
+ destroySocket(socket);
37
+ }
38
+ catch (err) {
39
+ console.error(`Cannot destroy socket: ${err.message}`);
40
+ }
41
+ });
42
+ };
43
+ return terminate;
44
+ };
45
+ export default addMiddleware;
46
46
  //# sourceMappingURL=connection.js.map
@@ -1,17 +1,17 @@
1
- export const addMiddleware = (env) => {
2
- env.app.use((req, res, next) => {
3
- // Setup AceBase context, to allow clients to pass contextual info with data updates,
4
- // that will be sent along to data event subscribers on affected data.
5
- const context = req.get('AceBase-Context') || '{}';
6
- try {
7
- req.context = JSON.parse(context);
8
- }
9
- catch (err) {
10
- env.debug.error(`Failed to parse AceBase-Context header: "${context}" in request at ${req.url} from client ${req.ip}`);
11
- return res.status(500).end('Invalid request context');
12
- }
13
- next();
14
- });
15
- };
16
- export default addMiddleware;
1
+ export const addMiddleware = (env) => {
2
+ env.router.use((req, res, next) => {
3
+ // Setup AceBase context, to allow clients to pass contextual info with data updates,
4
+ // that will be sent along to data event subscribers on affected data.
5
+ const context = req.get('AceBase-Context') || '{}';
6
+ try {
7
+ req.context = JSON.parse(context);
8
+ }
9
+ catch (err) {
10
+ env.debug.error(`Failed to parse AceBase-Context header: "${context}" in request at ${req.url} from client ${req.ip}`);
11
+ return res.status(500).end('Invalid request context');
12
+ }
13
+ next();
14
+ });
15
+ };
16
+ export default addMiddleware;
17
17
  //# sourceMappingURL=context.js.map
@@ -1,45 +1,45 @@
1
- /**
2
- * Gets CORS options that are compatible with the 'cors' package (used by Socket.IO 3+)
3
- * @param allowedOrigins
4
- * @returns
5
- */
6
- export const getCorsOptions = (allowedOrigins) => {
7
- return {
8
- origin: allowedOrigins === '*' ? true : allowedOrigins === '' ? false : allowedOrigins.split(/,\s*/),
9
- methods: 'GET,PUT,POST,DELETE,OPTIONS',
10
- allowedHeaders: 'Content-Type, Authorization, Content-Length, Accept, Origin, X-Requested-With, AceBase-Context',
11
- };
12
- };
13
- /**
14
- * Gets CORS headers that can be sent in preflight (OPTIONS) requests
15
- * @param allowedOrigins configured allowed origin(s). Examples: `'https://my.server.com'` for a specific allowed origin, `'*'` for any origin (returns current origin), `''` to disable CORS (only allows localhost), or `'http://server1.com,https://server1.com,https://server2.com'` for multiple allowed origins
16
- * @param currentOrigin current origin from request headers
17
- * @returns
18
- */
19
- export const getCorsHeaders = (allowedOrigins, currentOrigin) => {
20
- const corsOptions = getCorsOptions(allowedOrigins);
21
- const origins = typeof corsOptions.origin === 'boolean'
22
- ? corsOptions.origin ? currentOrigin ?? '*' : ''
23
- : corsOptions.origin instanceof Array ? corsOptions.origin.join(',') : corsOptions.origin;
24
- return {
25
- 'Access-Control-Allow-Origin': origins,
26
- 'Access-Control-Allow-Methods': corsOptions.methods,
27
- 'Access-Control-Allow-Headers': corsOptions.allowedHeaders,
28
- 'Access-Control-Expose-Headers': 'Date, AceBase-Context', // Prevent browsers from stripping these headers from the response for programmatic access in cross-origin requests
29
- };
30
- };
31
- export const addMiddleware = (env) => {
32
- env.app.use((req, res, next) => {
33
- const headers = getCorsHeaders(env.config.allowOrigin, req.headers.origin);
34
- for (const name in headers) {
35
- res.setHeader(name, headers[name]);
36
- }
37
- if (req.method === 'OPTIONS') {
38
- // Return 200 OK
39
- return res.status(200).end();
40
- }
41
- next();
42
- });
43
- };
44
- export default addMiddleware;
1
+ /**
2
+ * Gets CORS options that are compatible with the 'cors' package (used by Socket.IO 3+)
3
+ * @param allowedOrigins
4
+ * @returns
5
+ */
6
+ export const getCorsOptions = (allowedOrigins) => {
7
+ return {
8
+ origin: allowedOrigins === '*' ? true : allowedOrigins === '' ? false : allowedOrigins.split(/,\s*/),
9
+ methods: 'GET,PUT,POST,DELETE,OPTIONS',
10
+ allowedHeaders: 'Content-Type, Authorization, Content-Length, Accept, Origin, X-Requested-With, AceBase-Context',
11
+ };
12
+ };
13
+ /**
14
+ * Gets CORS headers that can be sent in preflight (OPTIONS) requests
15
+ * @param allowedOrigins configured allowed origin(s). Examples: `'https://my.server.com'` for a specific allowed origin, `'*'` for any origin (returns current origin), `''` to disable CORS (only allows localhost), or `'http://server1.com,https://server1.com,https://server2.com'` for multiple allowed origins
16
+ * @param currentOrigin current origin from request headers
17
+ * @returns
18
+ */
19
+ export const getCorsHeaders = (allowedOrigins, currentOrigin) => {
20
+ const corsOptions = getCorsOptions(allowedOrigins);
21
+ const origins = typeof corsOptions.origin === 'boolean'
22
+ ? corsOptions.origin ? currentOrigin ?? '*' : ''
23
+ : corsOptions.origin instanceof Array ? corsOptions.origin.join(',') : corsOptions.origin;
24
+ return {
25
+ 'Access-Control-Allow-Origin': origins,
26
+ 'Access-Control-Allow-Methods': corsOptions.methods,
27
+ 'Access-Control-Allow-Headers': corsOptions.allowedHeaders,
28
+ 'Access-Control-Expose-Headers': 'Date, AceBase-Context', // Prevent browsers from stripping these headers from the response for programmatic access in cross-origin requests
29
+ };
30
+ };
31
+ export const addMiddleware = (env) => {
32
+ env.router.use((req, res, next) => {
33
+ const headers = getCorsHeaders(env.config.allowOrigin, req.headers.origin);
34
+ for (const name in headers) {
35
+ res.setHeader(name, headers[name]);
36
+ }
37
+ if (req.method === 'OPTIONS') {
38
+ // Return 200 OK
39
+ return res.status(200).end();
40
+ }
41
+ next();
42
+ });
43
+ };
44
+ export default addMiddleware;
45
45
  //# sourceMappingURL=cors.js.map
@@ -1,14 +1,14 @@
1
- export const addMiddleware = (env) => {
2
- env.app.use((req, res, next) => {
3
- // Swagger UI escapes path variables, so "some/path" in a path variable of an endpoint becomes "some%2Fpath". This middleware fixes that
4
- if (req.path.includes('%2F')) {
5
- const [url, query] = req.url.split('?');
6
- const newUrl = url.replace(/\%2F/g, '/') + (query ? `?${query}` : '');
7
- env.debug.warn(`API: replacing escaped slashes in request path for Swagger UI: ${req.url} -> ${newUrl}`);
8
- req.url = newUrl;
9
- }
10
- next();
11
- });
12
- };
13
- export default addMiddleware;
1
+ export const addMiddleware = (env) => {
2
+ env.router.use((req, res, next) => {
3
+ // Swagger UI escapes path variables, so "some/path" in a path variable of an endpoint becomes "some%2Fpath". This middleware fixes that
4
+ if (req.path.includes('%2F')) {
5
+ const [url, query] = req.url.split('?');
6
+ const newUrl = url.replace(/\%2F/g, '/') + (query ? `?${query}` : '');
7
+ env.debug.warn(`API: replacing escaped slashes in request path for Swagger UI: ${req.url} -> ${newUrl}`);
8
+ req.url = newUrl;
9
+ }
10
+ next();
11
+ });
12
+ };
13
+ export default addMiddleware;
14
14
  //# sourceMappingURL=swagger.js.map
@@ -1,45 +1,45 @@
1
- import { sendNotAuthenticatedError } from '../shared/error.js';
2
- import { signIn } from '../shared/signin.js';
3
- import { decodePublicAccessToken } from '../shared/tokens.js';
4
- export const addMiddleware = (env) => {
5
- // Add bearer authentication middleware
6
- env.app.use(async (req, res, next) => {
7
- let authorization = req.get('Authorization');
8
- if (typeof authorization !== 'string' && 'auth_token' in req.query) {
9
- // Enables browser calls to be authenticated by adding the access token as auth_token query parameter
10
- if (req.path.startsWith('/export/') || req.path.startsWith('/logs')) {
11
- // For now, only allow '/export' or '/logs' api calls
12
- // In the future, use these prerequisites:
13
- // - user must be currently authenticated (in cache)
14
- // - ip address must match the token
15
- authorization = 'Bearer ' + req.query.auth_token;
16
- }
17
- }
18
- if (typeof authorization === 'string' && authorization.startsWith('Bearer ')) {
19
- const token = authorization.slice(7);
20
- let tokenDetails;
21
- try {
22
- tokenDetails = decodePublicAccessToken(token, env.tokenSalt);
23
- }
24
- catch (err) {
25
- return sendNotAuthenticatedError(res, 'invalid_token', 'The passed token is invalid. Sign in again');
26
- }
27
- // Is this token cached?
28
- req.user = env.authCache.get(tokenDetails.uid);
29
- if (!req.user) {
30
- // Query database to get user for this token
31
- try {
32
- await signIn({ method: 'internal', access_token: tokenDetails.access_token }, env, req);
33
- }
34
- catch (err) {
35
- return sendNotAuthenticatedError(res, err.code, err.message);
36
- }
37
- }
38
- if (req.user.is_disabled === true) {
39
- return sendNotAuthenticatedError(res, 'account_disabled', 'Your account has been disabled. Contact your database administrator');
40
- }
41
- }
42
- next();
43
- });
44
- };
1
+ import { sendNotAuthenticatedError } from '../shared/error.js';
2
+ import { signIn } from '../shared/signin.js';
3
+ import { decodePublicAccessToken } from '../shared/tokens.js';
4
+ export const addMiddleware = (env) => {
5
+ // Add bearer authentication middleware
6
+ env.router.use(async (req, res, next) => {
7
+ let authorization = req.get('Authorization');
8
+ if (typeof authorization !== 'string' && 'auth_token' in req.query) {
9
+ // Enables browser calls to be authenticated by adding the access token as auth_token query parameter
10
+ if (req.path.startsWith('/export/') || req.path.startsWith('/logs')) {
11
+ // For now, only allow '/export' or '/logs' api calls
12
+ // In the future, use these prerequisites:
13
+ // - user must be currently authenticated (in cache)
14
+ // - ip address must match the token
15
+ authorization = 'Bearer ' + req.query.auth_token;
16
+ }
17
+ }
18
+ if (typeof authorization === 'string' && authorization.startsWith('Bearer ')) {
19
+ const token = authorization.slice(7);
20
+ let tokenDetails;
21
+ try {
22
+ tokenDetails = decodePublicAccessToken(token, env.tokenSalt);
23
+ }
24
+ catch (err) {
25
+ return sendNotAuthenticatedError(res, 'invalid_token', 'The passed token is invalid. Sign in again');
26
+ }
27
+ // Is this token cached?
28
+ req.user = env.authCache.get(tokenDetails.uid);
29
+ if (!req.user) {
30
+ // Query database to get user for this token
31
+ try {
32
+ req.user = await signIn({ method: 'internal', access_token: tokenDetails.access_token }, env, req);
33
+ }
34
+ catch (err) {
35
+ return sendNotAuthenticatedError(res, err.code, err.message);
36
+ }
37
+ }
38
+ if (req.user.is_disabled === true) {
39
+ return sendNotAuthenticatedError(res, 'account_disabled', 'Your account has been disabled. Contact your database administrator');
40
+ }
41
+ }
42
+ next();
43
+ });
44
+ };
45
45
  //# sourceMappingURL=user.js.map
@@ -1,91 +1,91 @@
1
- import { OAuth2Provider } from './oauth-provider.js';
2
- import { fetch } from '../shared/simple-fetch.js';
3
- export class DropboxAuthProvider extends OAuth2Provider {
4
- constructor(settings) {
5
- super(settings);
6
- if (!settings.scopes) {
7
- settings.scopes = [];
8
- }
9
- if (settings.scopes.length > 0 && !settings.scopes.includes('account_info.read')) {
10
- settings.scopes.push('account_info.read');
11
- }
12
- }
13
- /**
14
- * Starts auth flow by getting the url the user should be redirected to
15
- * @param info.redirectUrl Url dropbox will redirect to after authorizing
16
- * @param info.state Optional state that will be passed to redirectUri by dropbox
17
- * @param info.options Optional Dropbox specific authentication settings
18
- * @param info.options.require_role If this parameter is specified, the user will be asked to authorize with a particular type of Dropbox account, either work for a team account or personal for a personal account. Your app should still verify the type of Dropbox account after authorization since the user could modify or remove the require_role parameter.
19
- * @param info.options.force_reapprove Whether or not to force the user to approve the app again if they've already done so. If false (default), a user who has already approved the application may be automatically redirected to the URI specified by redirect_uri. If true, the user will not be automatically redirected and will have to approve the app again.
20
- * @param info.options.disable_signup When true (default is false) users will not be able to sign up for a Dropbox account via the authorization page. Instead, the authorization page will show a link to the Dropbox iOS app in the App Store. This is only intended for use when necessary for compliance with App Store policies.
21
- * @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.
22
- * @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.
23
- */
24
- async init(info) {
25
- // Return url to get authorization code with
26
- const options = info.options || {};
27
- 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)}`;
28
- return authUrl;
29
- }
30
- async getAccessToken(params) {
31
- // Request access & refresh tokens with authorization code
32
- const response = await fetch('https://api.dropbox.com/oauth2/token', {
33
- method: 'POST',
34
- headers: {
35
- 'Content-Type': 'application/x-www-form-urlencoded',
36
- },
37
- body: `client_id=${this.settings.client_id}&client_secret=${this.settings.client_secret}` +
38
- (params.type === 'refresh'
39
- ? `&grant_type=refresh_token&refresh_token=${params.refresh_token}`
40
- : `&grant_type=authorization_code&code=${params.auth_code}&redirect_uri=${encodeURIComponent(params.redirect_url)}`),
41
- });
42
- if (response.status !== 200) {
43
- // Handle error
44
- const code = response.status;
45
- const hasJSON = response.headers.get('Content-Type') === 'application/json';
46
- const details = await (hasJSON ? response.json() : response.text());
47
- throw new Error(`${code}: ${hasJSON ? details.error_description ? `${details.error}, ${details.error_description}` : details.error_summary : details}`);
48
- }
49
- const result = await response.json();
50
- const secondsToExpiry = result.expires_in;
51
- result.expires = new Date(Date.now() + (secondsToExpiry * 1000));
52
- return result;
53
- }
54
- async getUserInfo(access_token) {
55
- const response = await fetch(`https://api.dropboxapi.com/2/users/get_current_account`, {
56
- method: 'POST',
57
- headers: {
58
- 'Authorization': `Bearer ${access_token}`,
59
- },
60
- });
61
- if (response.status !== 200) {
62
- const code = response.status;
63
- const hasJSON = response.headers.get('Content-Type') === 'application/json';
64
- const details = await (hasJSON ? response.json() : response.text());
65
- throw new Error(`${code}: ${hasJSON ? details.error_summary : details}`);
66
- }
67
- const result = await response.json();
68
- const user = result;
69
- return {
70
- id: user.account_id,
71
- name: `${user.name.given_name} ${user.name.surname}`,
72
- display_name: user.name.display_name,
73
- picture: user.profile_photo_url ? [{ url: user.profile_photo_url }] : null,
74
- email: user.email,
75
- email_verified: user.email_verified,
76
- other: {
77
- account_type: user.account_type['.tag'],
78
- disabled: user.disabled,
79
- locale: user.locale,
80
- country: user.country,
81
- // include the following?
82
- // referral_link: user.referral_link,
83
- // team_id: user.team.id,
84
- // team_name: user.team.name,
85
- // team_member_id: user.team_member_id
86
- },
87
- };
88
- }
89
- }
90
- export const AuthProvider = DropboxAuthProvider;
1
+ import { OAuth2Provider } from './oauth-provider.js';
2
+ import { fetch } from '../shared/simple-fetch.js';
3
+ export class DropboxAuthProvider extends OAuth2Provider {
4
+ constructor(settings) {
5
+ super(settings);
6
+ if (!settings.scopes) {
7
+ settings.scopes = [];
8
+ }
9
+ if (settings.scopes.length > 0 && !settings.scopes.includes('account_info.read')) {
10
+ settings.scopes.push('account_info.read');
11
+ }
12
+ }
13
+ /**
14
+ * Starts auth flow by getting the url the user should be redirected to
15
+ * @param info.redirectUrl Url dropbox will redirect to after authorizing
16
+ * @param info.state Optional state that will be passed to redirectUri by dropbox
17
+ * @param info.options Optional Dropbox specific authentication settings
18
+ * @param info.options.require_role If this parameter is specified, the user will be asked to authorize with a particular type of Dropbox account, either work for a team account or personal for a personal account. Your app should still verify the type of Dropbox account after authorization since the user could modify or remove the require_role parameter.
19
+ * @param info.options.force_reapprove Whether or not to force the user to approve the app again if they've already done so. If false (default), a user who has already approved the application may be automatically redirected to the URI specified by redirect_uri. If true, the user will not be automatically redirected and will have to approve the app again.
20
+ * @param info.options.disable_signup When true (default is false) users will not be able to sign up for a Dropbox account via the authorization page. Instead, the authorization page will show a link to the Dropbox iOS app in the App Store. This is only intended for use when necessary for compliance with App Store policies.
21
+ * @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.
22
+ * @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.
23
+ */
24
+ async init(info) {
25
+ // Return url to get authorization code with
26
+ const options = info.options || {};
27
+ 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)}`;
28
+ return authUrl;
29
+ }
30
+ async getAccessToken(params) {
31
+ // Request access & refresh tokens with authorization code
32
+ const response = await fetch('https://api.dropbox.com/oauth2/token', {
33
+ method: 'POST',
34
+ headers: {
35
+ 'Content-Type': 'application/x-www-form-urlencoded',
36
+ },
37
+ body: `client_id=${this.settings.client_id}&client_secret=${this.settings.client_secret}` +
38
+ (params.type === 'refresh'
39
+ ? `&grant_type=refresh_token&refresh_token=${params.refresh_token}`
40
+ : `&grant_type=authorization_code&code=${params.auth_code}&redirect_uri=${encodeURIComponent(params.redirect_url)}`),
41
+ });
42
+ if (response.status !== 200) {
43
+ // Handle error
44
+ const code = response.status;
45
+ const hasJSON = response.headers.get('Content-Type') === 'application/json';
46
+ const details = await (hasJSON ? response.json() : response.text());
47
+ throw new Error(`${code}: ${hasJSON ? details.error_description ? `${details.error}, ${details.error_description}` : details.error_summary : details}`);
48
+ }
49
+ const result = await response.json();
50
+ const secondsToExpiry = result.expires_in;
51
+ result.expires = new Date(Date.now() + (secondsToExpiry * 1000));
52
+ return result;
53
+ }
54
+ async getUserInfo(access_token) {
55
+ const response = await fetch(`https://api.dropboxapi.com/2/users/get_current_account`, {
56
+ method: 'POST',
57
+ headers: {
58
+ 'Authorization': `Bearer ${access_token}`,
59
+ },
60
+ });
61
+ if (response.status !== 200) {
62
+ const code = response.status;
63
+ const hasJSON = response.headers.get('Content-Type') === 'application/json';
64
+ const details = await (hasJSON ? response.json() : response.text());
65
+ throw new Error(`${code}: ${hasJSON ? details.error_summary : details}`);
66
+ }
67
+ const result = await response.json();
68
+ const user = result;
69
+ return {
70
+ id: user.account_id,
71
+ name: `${user.name.given_name} ${user.name.surname}`,
72
+ display_name: user.name.display_name,
73
+ picture: user.profile_photo_url ? [{ url: user.profile_photo_url }] : null,
74
+ email: user.email,
75
+ email_verified: user.email_verified,
76
+ other: {
77
+ account_type: user.account_type['.tag'],
78
+ disabled: user.disabled,
79
+ locale: user.locale,
80
+ country: user.country,
81
+ // include the following?
82
+ // referral_link: user.referral_link,
83
+ // team_id: user.team.id,
84
+ // team_name: user.team.name,
85
+ // team_member_id: user.team_member_id
86
+ },
87
+ };
88
+ }
89
+ }
90
+ export const AuthProvider = DropboxAuthProvider;
91
91
  //# sourceMappingURL=dropbox.js.map