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,114 +1,114 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.AuthProvider = exports.SpotifyAuthProvider = void 0;
13
- const oauth_provider_1 = require("./oauth-provider");
14
- const simple_fetch_1 = require("../shared/simple-fetch");
15
- class SpotifyAuthProvider extends oauth_provider_1.OAuth2Provider {
16
- constructor(settings) {
17
- super(settings);
18
- if (!settings.scopes) {
19
- settings.scopes = [];
20
- }
21
- if (!settings.scopes.includes('user-read-email')) {
22
- settings.scopes.push('user-read-email');
23
- }
24
- if (!settings.scopes.includes('user-read-private')) {
25
- settings.scopes.push('user-read-private');
26
- }
27
- }
28
- /**
29
- * Starts auth flow by getting the url the user should be redirected to
30
- * @param info.redirectUrl Url spotify will redirect to after authorizing
31
- * @param info.state Optional state that will be passed to redirectUri by spotify
32
- */
33
- init(info) {
34
- return __awaiter(this, void 0, void 0, function* () {
35
- // Return url to get authorization code with
36
- 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)}`;
37
- return authUrl;
38
- });
39
- }
40
- getAccessToken(params) {
41
- return __awaiter(this, void 0, void 0, function* () {
42
- // Request access & refresh tokens with authorization code
43
- const response = yield (0, simple_fetch_1.fetch)('https://accounts.spotify.com/api/token', {
44
- method: 'POST',
45
- headers: {
46
- 'Content-Type': 'application/x-www-form-urlencoded',
47
- },
48
- body: `client_id=${this.settings.client_id}&client_secret=${this.settings.client_secret}` +
49
- (params.type === 'refresh'
50
- ? `&grant_type=refresh_token&refresh_token=${params.refresh_token}`
51
- : `&grant_type=authorization_code&code=${params.auth_code}&redirect_uri=${encodeURIComponent(params.redirect_url)}`),
52
- });
53
- const result = yield response.json();
54
- if (result.error) {
55
- throw new Error(result.error);
56
- }
57
- const secondsToExpiry = result.expires_in;
58
- result.expires = new Date(Date.now() + (secondsToExpiry * 1000));
59
- return result;
60
- });
61
- }
62
- getClientAccessToken() {
63
- return __awaiter(this, void 0, void 0, function* () {
64
- // Gets client only access to Spotify API, without signed in user
65
- const response = yield (0, simple_fetch_1.fetch)('https://accounts.spotify.com/api/token', {
66
- method: 'POST',
67
- headers: {
68
- 'Content-Type': 'application/x-www-form-urlencoded',
69
- 'Authorization': `Basic ${Buffer.from(`${this.settings.client_id}:${this.settings.client_secret}`).toString('base64')}`,
70
- },
71
- body: `grant_type=client_credentials`,
72
- });
73
- const result = yield response.json();
74
- if (result.error) {
75
- throw new Error(result.error);
76
- }
77
- return result;
78
- });
79
- }
80
- getUserInfo(access_token) {
81
- return __awaiter(this, void 0, void 0, function* () {
82
- const response = yield (0, simple_fetch_1.fetch)('https://api.spotify.com/v1/me', {
83
- method: 'GET',
84
- headers: {
85
- 'Authorization': `Bearer ${access_token}`,
86
- },
87
- });
88
- const result = yield response.json();
89
- if (response.status !== 200) {
90
- const error = result;
91
- throw new Error(`${error.status}: ${error.message}`);
92
- }
93
- const user = result;
94
- return {
95
- id: user.id,
96
- name: user.display_name,
97
- display_name: user.display_name,
98
- picture: user.images,
99
- email: user.email,
100
- email_verified: false,
101
- other: {
102
- premium: user.product === 'premium',
103
- followers: user.followers ? user.followers.total : null,
104
- country: user.country,
105
- // external_urls: user.external_urls,
106
- uri: user.uri,
107
- },
108
- };
109
- });
110
- }
111
- }
112
- exports.SpotifyAuthProvider = SpotifyAuthProvider;
113
- exports.AuthProvider = SpotifyAuthProvider;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.AuthProvider = exports.SpotifyAuthProvider = void 0;
13
+ const oauth_provider_1 = require("./oauth-provider");
14
+ const simple_fetch_1 = require("../shared/simple-fetch");
15
+ class SpotifyAuthProvider extends oauth_provider_1.OAuth2Provider {
16
+ constructor(settings) {
17
+ super(settings);
18
+ if (!settings.scopes) {
19
+ settings.scopes = [];
20
+ }
21
+ if (!settings.scopes.includes('user-read-email')) {
22
+ settings.scopes.push('user-read-email');
23
+ }
24
+ if (!settings.scopes.includes('user-read-private')) {
25
+ settings.scopes.push('user-read-private');
26
+ }
27
+ }
28
+ /**
29
+ * Starts auth flow by getting the url the user should be redirected to
30
+ * @param info.redirectUrl Url spotify will redirect to after authorizing
31
+ * @param info.state Optional state that will be passed to redirectUri by spotify
32
+ */
33
+ init(info) {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ // Return url to get authorization code with
36
+ 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)}`;
37
+ return authUrl;
38
+ });
39
+ }
40
+ getAccessToken(params) {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ // Request access & refresh tokens with authorization code
43
+ const response = yield (0, simple_fetch_1.fetch)('https://accounts.spotify.com/api/token', {
44
+ method: 'POST',
45
+ headers: {
46
+ 'Content-Type': 'application/x-www-form-urlencoded',
47
+ },
48
+ body: `client_id=${this.settings.client_id}&client_secret=${this.settings.client_secret}` +
49
+ (params.type === 'refresh'
50
+ ? `&grant_type=refresh_token&refresh_token=${params.refresh_token}`
51
+ : `&grant_type=authorization_code&code=${params.auth_code}&redirect_uri=${encodeURIComponent(params.redirect_url)}`),
52
+ });
53
+ const result = yield response.json();
54
+ if (result.error) {
55
+ throw new Error(result.error);
56
+ }
57
+ const secondsToExpiry = result.expires_in;
58
+ result.expires = new Date(Date.now() + (secondsToExpiry * 1000));
59
+ return result;
60
+ });
61
+ }
62
+ getClientAccessToken() {
63
+ return __awaiter(this, void 0, void 0, function* () {
64
+ // Gets client only access to Spotify API, without signed in user
65
+ const response = yield (0, simple_fetch_1.fetch)('https://accounts.spotify.com/api/token', {
66
+ method: 'POST',
67
+ headers: {
68
+ 'Content-Type': 'application/x-www-form-urlencoded',
69
+ 'Authorization': `Basic ${Buffer.from(`${this.settings.client_id}:${this.settings.client_secret}`).toString('base64')}`,
70
+ },
71
+ body: `grant_type=client_credentials`,
72
+ });
73
+ const result = yield response.json();
74
+ if (result.error) {
75
+ throw new Error(result.error);
76
+ }
77
+ return result;
78
+ });
79
+ }
80
+ getUserInfo(access_token) {
81
+ return __awaiter(this, void 0, void 0, function* () {
82
+ const response = yield (0, simple_fetch_1.fetch)('https://api.spotify.com/v1/me', {
83
+ method: 'GET',
84
+ headers: {
85
+ 'Authorization': `Bearer ${access_token}`,
86
+ },
87
+ });
88
+ const result = yield response.json();
89
+ if (response.status !== 200) {
90
+ const error = result;
91
+ throw new Error(`${error.status}: ${error.message}`);
92
+ }
93
+ const user = result;
94
+ return {
95
+ id: user.id,
96
+ name: user.display_name,
97
+ display_name: user.display_name,
98
+ picture: user.images,
99
+ email: user.email,
100
+ email_verified: false,
101
+ other: {
102
+ premium: user.product === 'premium',
103
+ followers: user.followers ? user.followers.total : null,
104
+ country: user.country,
105
+ // external_urls: user.external_urls,
106
+ uri: user.uri,
107
+ },
108
+ };
109
+ });
110
+ }
111
+ }
112
+ exports.SpotifyAuthProvider = SpotifyAuthProvider;
113
+ exports.AuthProvider = SpotifyAuthProvider;
114
114
  //# sourceMappingURL=spotify.js.map
@@ -1,88 +1,88 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.addRoute = exports.ChangePasswordError = void 0;
13
- const error_1 = require("../shared/error");
14
- const password_1 = require("../shared/password");
15
- const acebase_core_1 = require("acebase-core");
16
- const tokens_1 = require("../shared/tokens");
17
- class ChangePasswordError extends Error {
18
- constructor(code, message) {
19
- super(message);
20
- this.code = code;
21
- }
22
- }
23
- exports.ChangePasswordError = ChangePasswordError;
24
- const addRoute = (env) => {
25
- env.app.post(`/auth/${env.db.name}/change_password`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
26
- var _a, _b;
27
- const access_token = (_a = req.user) === null || _a === void 0 ? void 0 : _a.access_token;
28
- const details = req.body;
29
- const LOG_ACTION = 'auth.change_password';
30
- const LOG_DETAILS = { ip: req.ip, uid: (_b = details.uid) !== null && _b !== void 0 ? _b : null };
31
- if (typeof details !== 'object' || typeof details.uid !== 'string' || typeof details.password !== 'string' || typeof details.new_password !== 'string') {
32
- env.log.error(LOG_ACTION, 'invalid_details', LOG_DETAILS);
33
- res.status(400).send('Bad Request'); // Bad Request
34
- return;
35
- }
36
- if (details.new_password.length < 8 || details.new_password.includes(' ') || !/[0-9]/.test(details.new_password) || !/[a-z]/.test(details.new_password) || !/[A-Z]/.test(details.new_password)) {
37
- env.log.error(LOG_ACTION, 'new_password_denied', LOG_DETAILS);
38
- const err = 'Invalid new password, must be at least 8 characters and contain a combination of numbers and letters (both lower and uppercase)';
39
- res.status(422).send(err); // Unprocessable Entity
40
- return;
41
- }
42
- try {
43
- let publicAccessToken;
44
- yield env.authRef.child(details.uid).transaction(snap => {
45
- if (!snap.exists()) {
46
- throw new ChangePasswordError('unknown_uid', `Unknown uid`);
47
- }
48
- const user = snap.val();
49
- user.uid = snap.key;
50
- const hash = user.password_salt ? (0, password_1.getPasswordHash)(details.password, user.password_salt) : (0, password_1.getOldPasswordHash)(details.password);
51
- if (user.password !== hash) {
52
- throw new ChangePasswordError('wrong_password', `Wrong password`);
53
- }
54
- if (access_token && access_token !== user.access_token) {
55
- throw new ChangePasswordError('wrong_access_token', `Cannot change password while signed in as other user, or with an old token`);
56
- }
57
- const pwd = (0, password_1.createPasswordHash)(details.new_password);
58
- const updates = {
59
- access_token: acebase_core_1.ID.generate(),
60
- access_token_created: new Date(),
61
- password: pwd.hash,
62
- password_salt: pwd.salt,
63
- };
64
- // Update user object
65
- Object.assign(user, updates);
66
- // Set or update cache
67
- env.authCache.set(user.uid, user);
68
- // Create new public access token
69
- publicAccessToken = (0, tokens_1.createPublicAccessToken)(user.uid, req.ip, user.access_token, env.tokenSalt);
70
- return user; // Update db
71
- });
72
- env.log.event(LOG_ACTION, LOG_DETAILS);
73
- res.send({ access_token: publicAccessToken }); // Client must use this new access token from now on
74
- }
75
- catch (err) {
76
- env.log.error(LOG_ACTION, err.code, LOG_DETAILS);
77
- if (err.code) {
78
- (0, error_1.sendBadRequestError)(res, err);
79
- }
80
- else {
81
- (0, error_1.sendUnexpectedError)(res, err);
82
- }
83
- }
84
- }));
85
- };
86
- exports.addRoute = addRoute;
87
- exports.default = exports.addRoute;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.addRoute = exports.ChangePasswordError = void 0;
13
+ const error_1 = require("../shared/error");
14
+ const password_1 = require("../shared/password");
15
+ const acebase_core_1 = require("acebase-core");
16
+ const tokens_1 = require("../shared/tokens");
17
+ class ChangePasswordError extends Error {
18
+ constructor(code, message) {
19
+ super(message);
20
+ this.code = code;
21
+ }
22
+ }
23
+ exports.ChangePasswordError = ChangePasswordError;
24
+ const addRoute = (env) => {
25
+ env.router.post(`/auth/${env.db.name}/change_password`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
26
+ var _a, _b;
27
+ const access_token = (_a = req.user) === null || _a === void 0 ? void 0 : _a.access_token;
28
+ const details = req.body;
29
+ const LOG_ACTION = 'auth.change_password';
30
+ const LOG_DETAILS = { ip: req.ip, uid: (_b = details.uid) !== null && _b !== void 0 ? _b : null };
31
+ if (typeof details !== 'object' || typeof details.uid !== 'string' || typeof details.password !== 'string' || typeof details.new_password !== 'string') {
32
+ env.log.error(LOG_ACTION, 'invalid_details', LOG_DETAILS);
33
+ res.status(400).send('Bad Request'); // Bad Request
34
+ return;
35
+ }
36
+ if (details.new_password.length < 8 || details.new_password.includes(' ') || !/[0-9]/.test(details.new_password) || !/[a-z]/.test(details.new_password) || !/[A-Z]/.test(details.new_password)) {
37
+ env.log.error(LOG_ACTION, 'new_password_denied', LOG_DETAILS);
38
+ const err = 'Invalid new password, must be at least 8 characters and contain a combination of numbers and letters (both lower and uppercase)';
39
+ res.status(422).send(err); // Unprocessable Entity
40
+ return;
41
+ }
42
+ try {
43
+ let publicAccessToken;
44
+ yield env.authRef.child(details.uid).transaction(snap => {
45
+ if (!snap.exists()) {
46
+ throw new ChangePasswordError('unknown_uid', `Unknown uid`);
47
+ }
48
+ const user = snap.val();
49
+ user.uid = snap.key;
50
+ const hash = user.password_salt ? (0, password_1.getPasswordHash)(details.password, user.password_salt) : (0, password_1.getOldPasswordHash)(details.password);
51
+ if (user.password !== hash) {
52
+ throw new ChangePasswordError('wrong_password', `Wrong password`);
53
+ }
54
+ if (access_token && access_token !== user.access_token) {
55
+ throw new ChangePasswordError('wrong_access_token', `Cannot change password while signed in as other user, or with an old token`);
56
+ }
57
+ const pwd = (0, password_1.createPasswordHash)(details.new_password);
58
+ const updates = {
59
+ access_token: acebase_core_1.ID.generate(),
60
+ access_token_created: new Date(),
61
+ password: pwd.hash,
62
+ password_salt: pwd.salt,
63
+ };
64
+ // Update user object
65
+ Object.assign(user, updates);
66
+ // Set or update cache
67
+ env.authCache.set(user.uid, user);
68
+ // Create new public access token
69
+ publicAccessToken = (0, tokens_1.createPublicAccessToken)(user.uid, req.ip, user.access_token, env.tokenSalt);
70
+ return user; // Update db
71
+ });
72
+ env.log.event(LOG_ACTION, LOG_DETAILS);
73
+ res.send({ access_token: publicAccessToken }); // Client must use this new access token from now on
74
+ }
75
+ catch (err) {
76
+ env.log.error(LOG_ACTION, err.code, LOG_DETAILS);
77
+ if (err.code) {
78
+ (0, error_1.sendBadRequestError)(res, err);
79
+ }
80
+ else {
81
+ (0, error_1.sendUnexpectedError)(res, err);
82
+ }
83
+ }
84
+ }));
85
+ };
86
+ exports.addRoute = addRoute;
87
+ exports.default = exports.addRoute;
88
88
  //# sourceMappingURL=auth-change-password.js.map
@@ -1,53 +1,53 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.addRoute = exports.DeleteError = void 0;
13
- const error_1 = require("../shared/error");
14
- class DeleteError extends Error {
15
- constructor(code, message) {
16
- super(message);
17
- this.code = code;
18
- }
19
- }
20
- exports.DeleteError = DeleteError;
21
- const addRoute = (env) => {
22
- env.app.post(`/auth/${env.db.name}/delete`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
23
- var _a, _b, _c, _d;
24
- const details = req.body;
25
- const LOG_ACTION = 'auth.delete';
26
- const LOG_DETAILS = { ip: req.ip, uid: (_b = (_a = req.user) === null || _a === void 0 ? void 0 : _a.uid) !== null && _b !== void 0 ? _b : null, delete_uid: details.uid };
27
- if (!req.user) {
28
- env.log.error(LOG_ACTION, 'unauthenticated_delete', LOG_DETAILS);
29
- return (0, error_1.sendNotAuthenticatedError)(res, 'unauthenticated_delete', 'You are not authorized to perform this operation, your attempt has been logged');
30
- }
31
- if (req.user.uid !== 'admin' && details.uid !== req.user.uid) {
32
- env.log.error(LOG_ACTION, 'unauthorized_delete', LOG_DETAILS);
33
- return (0, error_1.sendUnauthorizedError)(res, 'unauthorized_delete', 'You are not authorized to perform this operation, your attempt has been logged');
34
- }
35
- const uid = (_c = details.uid) !== null && _c !== void 0 ? _c : req.user.uid;
36
- if (uid === 'admin') {
37
- env.log.error(LOG_ACTION, 'unauthorized_delete', LOG_DETAILS);
38
- return (0, error_1.sendUnauthorizedError)(res, 'unauthorized_delete', 'The admin account cannot be deleted, your attempt has been logged');
39
- }
40
- try {
41
- yield env.authRef.child(uid).remove();
42
- env.log.event(LOG_ACTION, LOG_DETAILS);
43
- res.send('Farewell');
44
- }
45
- catch (err) {
46
- env.log.error(LOG_ACTION, 'unexpected', Object.assign(Object.assign({}, LOG_DETAILS), { message: (_d = (err instanceof Error && err.message)) !== null && _d !== void 0 ? _d : err.toString() }));
47
- (0, error_1.sendUnexpectedError)(res, err);
48
- }
49
- }));
50
- };
51
- exports.addRoute = addRoute;
52
- exports.default = exports.addRoute;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.addRoute = exports.DeleteError = void 0;
13
+ const error_1 = require("../shared/error");
14
+ class DeleteError extends Error {
15
+ constructor(code, message) {
16
+ super(message);
17
+ this.code = code;
18
+ }
19
+ }
20
+ exports.DeleteError = DeleteError;
21
+ const addRoute = (env) => {
22
+ env.router.post(`/auth/${env.db.name}/delete`, (req, res) => __awaiter(void 0, void 0, void 0, function* () {
23
+ var _a, _b, _c, _d;
24
+ const details = req.body;
25
+ const LOG_ACTION = 'auth.delete';
26
+ const LOG_DETAILS = { ip: req.ip, uid: (_b = (_a = req.user) === null || _a === void 0 ? void 0 : _a.uid) !== null && _b !== void 0 ? _b : null, delete_uid: details.uid };
27
+ if (!req.user) {
28
+ env.log.error(LOG_ACTION, 'unauthenticated_delete', LOG_DETAILS);
29
+ return (0, error_1.sendNotAuthenticatedError)(res, 'unauthenticated_delete', 'You are not authorized to perform this operation, your attempt has been logged');
30
+ }
31
+ if (req.user.uid !== 'admin' && details.uid !== req.user.uid) {
32
+ env.log.error(LOG_ACTION, 'unauthorized_delete', LOG_DETAILS);
33
+ return (0, error_1.sendUnauthorizedError)(res, 'unauthorized_delete', 'You are not authorized to perform this operation, your attempt has been logged');
34
+ }
35
+ const uid = (_c = details.uid) !== null && _c !== void 0 ? _c : req.user.uid;
36
+ if (uid === 'admin') {
37
+ env.log.error(LOG_ACTION, 'unauthorized_delete', LOG_DETAILS);
38
+ return (0, error_1.sendUnauthorizedError)(res, 'unauthorized_delete', 'The admin account cannot be deleted, your attempt has been logged');
39
+ }
40
+ try {
41
+ yield env.authRef.child(uid).remove();
42
+ env.log.event(LOG_ACTION, LOG_DETAILS);
43
+ res.send('Farewell');
44
+ }
45
+ catch (err) {
46
+ env.log.error(LOG_ACTION, 'unexpected', Object.assign(Object.assign({}, LOG_DETAILS), { message: (_d = (err instanceof Error && err.message)) !== null && _d !== void 0 ? _d : err.toString() }));
47
+ (0, error_1.sendUnexpectedError)(res, err);
48
+ }
49
+ }));
50
+ };
51
+ exports.addRoute = addRoute;
52
+ exports.default = exports.addRoute;
53
53
  //# sourceMappingURL=auth-delete.js.map