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
@@ -34,6 +34,12 @@
34
34
  description: If successful returns the string `"done"`
35
35
  content:
36
36
  'text/plain':
37
+ headers:
38
+ 'AceBase-Context':
39
+ description: Returns the context that was passed to the transaction start endpoint, augmented with an `acebase_cursor` if transaction logging is enabled on the server.
40
+ schema:
41
+ type: string
42
+ example: '{ "acebase_cursor": "l3lf2iwd000109mgdn0d6pqt" }'
37
43
  schema:
38
44
  type: string
39
45
  value: done
@@ -1,5 +1,6 @@
1
1
  import { SchemaValidationError } from 'acebase';
2
2
  import { ID, Transport } from 'acebase-core';
3
+ import { Api } from 'acebase-core/src/api';
3
4
  import { SerializedValue } from 'acebase-core/types/transport';
4
5
  import { RouteInitEnvironment, RouteRequest } from '../shared/env';
5
6
  import { sendBadRequestError, sendError, sendUnauthorizedError, sendUnexpectedError } from '../shared/error';
@@ -34,7 +35,7 @@ export type FinishResponseBody = 'done' // 200
34
35
 
35
36
  export type FinishRequest = RouteRequest<any, FinishResponseBody, FinishRequestBody, FinishRequestQuery>;
36
37
 
37
- type Transaction = { id: string; started: number; path: string; context: any; finish?: (val?: any) => Promise<any>; timeout: NodeJS.Timeout };
38
+ type Transaction = { id: string; started: number; path: string; context: any; finish?: (val?: any) => ReturnType<Api['transaction']>; timeout: NodeJS.Timeout };
38
39
 
39
40
  export const addRoutes = (env: RouteInitEnvironment) => {
40
41
 
@@ -43,8 +44,13 @@ export const addRoutes = (env: RouteInitEnvironment) => {
43
44
  // Start transaction endpoint:
44
45
  env.app.post(`/transaction/${env.db.name}/start`, (req: StartRequest, res) => {
45
46
  const data = req.body;
47
+
48
+ const LOG_ACTION = 'data.transaction.start';
49
+ const LOG_DETAILS = { ip: req.ip, uid: req.user?.uid ?? null, path: data.path };
50
+
46
51
  const access = env.rules.userHasAccess(req.user, data.path, true);
47
52
  if (!access.allow) {
53
+ env.log.error(LOG_ACTION, 'unauthorized', { ...LOG_DETAILS, rule_code: access.code, rule_path: access.rulePath ?? null }, access.details);
48
54
  return sendUnauthorizedError(res, access.code, access.message);
49
55
  }
50
56
 
@@ -69,7 +75,7 @@ export const addRoutes = (env: RouteInitEnvironment) => {
69
75
  const donePromise = env.db.api.transaction(tx.path, val => {
70
76
  env.debug.verbose(`Transaction ${tx.id} started with value: `, val);
71
77
  const currentValue = Transport.serialize(val);
72
- const promise = new Promise((resolve) => {
78
+ const promise = new Promise<any>((resolve) => {
73
79
  tx.finish = (val: any) => {
74
80
  env.debug.verbose(`Transaction ${tx.id} finishing with value: `, val);
75
81
  _transactions.delete(tx.id);
@@ -83,7 +89,7 @@ export const addRoutes = (env: RouteInitEnvironment) => {
83
89
  }
84
90
  catch (err) {
85
91
  env.debug.error(`failed to start transaction on "${tx.path}":`, err);
86
- env.logRef?.push({ action: 'tx_start', success: false, code: err.code ?? 'unknown_error', path: tx.path, error: err.message, ip: req.ip, uid: req.user?.uid ?? null });
92
+ env.log.error(LOG_ACTION, err.code ?? 'unexpected', LOG_DETAILS, typeof err.code === 'undefined' ? err : null);
87
93
  sendUnexpectedError(res, err);
88
94
  }
89
95
  });
@@ -91,9 +97,12 @@ export const addRoutes = (env: RouteInitEnvironment) => {
91
97
  // Finish transaction endpoint:
92
98
  env.app.post(`/transaction/${env.db.name}/finish`, async (req: FinishRequest, res) => {
93
99
  const data = req.body;
100
+ const LOG_ACTION = 'data.transaction.finish';
101
+ const LOG_DETAILS = { ip: req.ip, uid: req.user?.uid ?? null, path: data.path };
94
102
 
95
103
  const tx = _transactions.get(data.id);
96
104
  if (!tx || tx.path !== data.path) {
105
+ env.log.error(LOG_ACTION, tx ? 'wrong_path' : 'not_found', { ...LOG_DETAILS, id: data.id, tx_path: tx?.path ?? null });
97
106
  res.statusCode = 410; // Gone
98
107
  res.send(`transaction not found`);
99
108
  return;
@@ -103,41 +112,56 @@ export const addRoutes = (env: RouteInitEnvironment) => {
103
112
 
104
113
  const access = env.rules.userHasAccess(req.user, tx.path, true);
105
114
  if (!access.allow) {
115
+ env.log.error(LOG_ACTION, 'unauthorized', { ...LOG_DETAILS, rule_code: access.code, rule_path: access.rulePath ?? null }, access.details);
106
116
  return sendUnauthorizedError(res, access.code, access.message);
107
117
  }
108
118
 
109
119
  // Finish transaction
110
120
  try {
111
- if (typeof data.value?.val === 'undefined' || !['string','object','undefined'].includes(typeof data.value?.map)) {
121
+ let cancel = false;
122
+ if (typeof data.value === 'object' && (data.value === null || Object.keys(data.value).length === 0)) {
123
+ // Returning undefined from a transaction callback should cancel the transaction
124
+ // acebase-client (Transport.serialize) serializes value undefined as { val: undefined, map: undefined }, which
125
+ // then is sent to the server as an empty object: {}
126
+ cancel = true;
127
+ }
128
+ else if (typeof data.value?.val === 'undefined' || !['string','object','undefined'].includes(typeof data.value?.map)) {
112
129
  throw new DataTransactionError('invalid_serialized_value', 'The sent value is not properly serialized');
113
130
  }
114
- const newValue = Transport.deserialize(data.value);
131
+ const newValue = cancel ? undefined : Transport.deserialize(data.value);
115
132
 
116
133
  if (tx.path === '' && req.user?.uid !== 'admin' && newValue !== null && typeof newValue === 'object') {
117
134
  // Non-admin user: remove any private properties from the update object
118
135
  Object.keys(newValue).filter(key => key.startsWith('__')).forEach(key => delete newValue[key]);
119
136
  }
120
137
 
121
- await tx.finish(newValue);
138
+
139
+ const result = await tx.finish(newValue);
140
+
141
+ // NEW: capture cursor and return it in the response context header
142
+ if (!tx.context) { tx.context = {}; }
143
+ tx.context.acebase_cursor = result.cursor;
144
+ res.setHeader('AceBase-Context', JSON.stringify(tx.context));
145
+
122
146
  res.send('done');
123
147
  }
124
148
  catch (err) {
125
149
  tx.finish(); // Finish without value cancels the transaction
126
150
  if (err instanceof SchemaValidationError) {
127
- env.logRef?.push({ action: 'tx_finish', success: false, code: 'schema_validation_failed', path: tx.path, error: err.reason, ip: req.ip, uid: req.user?.uid ?? null });
151
+ env.log.error(LOG_ACTION, 'schema_validation_failed', { ...LOG_DETAILS, reason: err.reason });
128
152
  res.status(422).send({ code: 'schema_validation_failed', message: err.message });
129
153
  }
130
154
  else if (err instanceof DataTransactionError) {
131
- env.logRef?.push({ action: 'tx_finish', success: false, code: err.code, path: tx.path, ip: req.ip, uid: req.user?.uid ?? null });
155
+ env.log.error(LOG_ACTION, err.code, { ...LOG_DETAILS, message: err.message });
132
156
  sendBadRequestError(res, err);
133
157
  }
134
158
  else {
135
- env.debug.error(`failed to finsih transaction on "${tx.path}":`, err);
136
- env.logRef?.push({ action: 'tx_finish', success: false, code: 'unknown_error', path: tx.path, error: err.message, ip: req.ip, uid: req.user?.uid ?? null });
159
+ env.debug.error(`failed to finish transaction on "${tx.path}":`, err);
160
+ env.log.error(LOG_ACTION, 'unexpected', LOG_DETAILS, err);
137
161
  sendError(res, err);
138
162
  }
139
163
  }
140
- });
164
+ });
141
165
 
142
166
  };
143
167
 
@@ -24,10 +24,14 @@ export type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>
24
24
  export const addRoute = (env: RouteInitEnvironment) => {
25
25
 
26
26
  env.app.post(`/data/${env.db.name}/*`, async (req: Request, res) => {
27
- // update data
27
+
28
28
  const path = req.path.slice(env.db.name.length + 7);
29
+ const LOG_ACTION = 'data.update';
30
+ const LOG_DETAILS = { ip: req.ip, uid: req.user?.uid ?? null, path };
31
+
29
32
  const access = env.rules.userHasAccess(req.user, path, true);
30
33
  if (!access.allow) {
34
+ env.log.error(LOG_ACTION, 'unauthorized', { ...LOG_DETAILS, rule_code: access.code, rule_path: access.rulePath ?? null, rule_error: access.details?.message ?? null });
31
35
  return sendUnauthorizedError(res, access.code, access.message);
32
36
  }
33
37
 
@@ -53,20 +57,24 @@ export const addRoute = (env: RouteInitEnvironment) => {
53
57
  .context(req.context)
54
58
  .update(val);
55
59
 
60
+ // NEW: add cursor to response context, which was added to the request context in `acebase_cursor` if transaction logging is enabled
61
+ const returnContext = { acebase_cursor: req.context.acebase_cursor };
62
+ res.setHeader('AceBase-Context', JSON.stringify(returnContext) );
63
+
56
64
  res.send({ success: true });
57
65
  }
58
66
  catch(err) {
59
67
  if (err instanceof SchemaValidationError) {
60
- env.logRef?.push({ action: 'update_data', success: false, code: 'schema_validation_failed', path, error: err.reason, ip: req.ip, uid: req.user?.uid ?? null });
68
+ env.log.error(LOG_ACTION, 'schema_validation_failed', { ...LOG_DETAILS, reason: err.reason });
61
69
  res.status(422).send({ code: 'schema_validation_failed', message: err.message });
62
70
  }
63
71
  else if (err instanceof UpdateDataError) {
64
- env.logRef?.push({ action: 'update_data', success: false, code: err.code, path, ip: req.ip, uid: req.user?.uid ?? null });
72
+ env.log.error(LOG_ACTION, err.code, { ...LOG_DETAILS, message: err.message });
65
73
  sendBadRequestError(res, err);
66
74
  }
67
75
  else {
68
76
  env.debug.error(`failed to update "${path}":`, err);
69
- env.logRef?.push({ action: 'update_data', success: false, code: `unknown_error`, path, error: err.message, ip: req.ip, uid: req.user?.uid ?? null });
77
+ env.log.error(LOG_ACTION, 'unexpected', LOG_DETAILS, err);
70
78
  sendError(res, err);
71
79
  }
72
80
  }
@@ -24,7 +24,7 @@
24
24
  description: Contextual info about the database operation (must be valid JSON). This info is included in event notifications sent to clients watching data at this or child paths
25
25
  schema:
26
26
  type: string
27
- example: {}
27
+ example: '{}'
28
28
  requestBody:
29
29
  description: serialized value to store in the database
30
30
  content:
@@ -36,6 +36,12 @@
36
36
  description: Returns "200 OK" when the database operation succeeded
37
37
  content:
38
38
  'application/json':
39
+ headers:
40
+ 'AceBase-Context':
41
+ description: Returns contextual information, such as the `acebase_cursor` if transaction logging is enabled on the server.
42
+ schema:
43
+ type: string
44
+ example: '{ "acebase_cursor": "l3lf2iwd000109mgdn0d6pqt" }'
39
45
  schema:
40
46
  type: object
41
47
  properties:
@@ -58,7 +58,7 @@ export const addRoute = (env: RouteInitEnvironment) => {
58
58
  total: numberToByteSize(os.totalmem()),
59
59
  free: numberToByteSize(os.freemem()),
60
60
  process: {
61
- arrayBuffers: numberToByteSize(mem.arrayBuffers),
61
+ arrayBuffers: numberToByteSize((mem as any).arrayBuffers), // arrayBuffers was added in Node v13.9.0, v12.17.0
62
62
  external: numberToByteSize(mem.external),
63
63
  heapTotal: numberToByteSize(mem.heapTotal),
64
64
  heapUsed: numberToByteSize(mem.heapUsed),
@@ -0,0 +1,57 @@
1
+ import { AceBase } from 'acebase';
2
+ import { QueryOperator } from 'acebase-core/types/data-reference';
3
+ import adminOnly from '../middleware/admin-only';
4
+ import { RouteInitEnvironment, RouteRequest } from '../shared/env';
5
+
6
+ type AceBaseLogLine = {
7
+ action: string;
8
+ ip: string;
9
+ date: string;
10
+ };
11
+
12
+ export type RequestQuery = { take?: string; skip?: string; sort?: 'date'; filter_col?: string; filter_op?: QueryOperator; filter_val?: string };
13
+ export type RequestBody = null;
14
+ export type ResponseBody = AceBaseLogLine[];
15
+ export type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>;
16
+
17
+ export const addRoute = (env: RouteInitEnvironment) => {
18
+
19
+ env.app.get(`/logs/${env.db.name}`, adminOnly(env), async (req: Request, res) => {
20
+ // Get database logs
21
+
22
+ // Create indexes if not there yet
23
+ const db = (env.log.ref as any).db as AceBase;
24
+ const createIndexes = [
25
+ db.indexes.create(env.log.ref.path, 'date')
26
+ ];
27
+ if (req.query.filter_col === 'action') {
28
+ createIndexes.push(db.indexes.create(env.log.ref.path, 'action', { include: ['date'] }));
29
+ }
30
+ if (req.query.filter_col === 'code') {
31
+ createIndexes.push(db.indexes.create(env.log.ref.path, 'code', { include: ['date'] }));
32
+ }
33
+ await Promise.all(createIndexes);
34
+
35
+ try {
36
+ const query = env.log.query()
37
+ .take(parseInt(req.query.take ?? '100'))
38
+ .skip(parseInt(req.query.skip ?? '0'))
39
+ .sort(req.query.sort ?? 'date', false);
40
+
41
+ if (req.query.filter_col) {
42
+ query.filter(req.query.filter_col, req.query.filter_op, req.query.filter_val);
43
+ }
44
+
45
+ const snaps = await query.get();
46
+ const logs = snaps.getValues() as AceBaseLogLine[];
47
+ res.send(logs);
48
+ }
49
+ catch (err) {
50
+ res.statusCode = 500;
51
+ res.send(err.message);
52
+ }
53
+ });
54
+
55
+ };
56
+
57
+ export default addRoute;
@@ -2,6 +2,7 @@ import type { RouteInitEnvironment } from '../shared/env';
2
2
  import addInfoRoute from './meta-info';
3
3
  import addPingRoute from './meta-ping';
4
4
  import addStatsRoute from './meta-stats';
5
+ import addLogsRoute from './meta-logs';
5
6
 
6
7
  export const addRoutes = (env: RouteInitEnvironment) => {
7
8
 
@@ -13,6 +14,9 @@ export const addRoutes = (env: RouteInitEnvironment) => {
13
14
 
14
15
  // Add database stats endpoint
15
16
  addStatsRoute(env);
17
+
18
+ // Add logs endpoint (admin only)
19
+ addLogsRoute(env);
16
20
  };
17
21
 
18
22
  export default addRoutes;
@@ -17,10 +17,13 @@ export type Request = RouteRequest<any, ResponseBody, RequestBody, RequestQuery>
17
17
  export const addRoute = (env: RouteInitEnvironment) => {
18
18
 
19
19
  env.app.get(`/oauth2/${env.db.name}/signin`, async (req: Request, res) => {
20
-
21
20
  // This is where the user is redirected to by the provider after signin or error
21
+
22
+ const LOG_ACTION = 'oauth2.signin';
23
+ const LOG_DETAILS = { ip: req.ip, provider: null };
24
+
22
25
  try {
23
- const state = parseSignedPublicToken(req.query.state, env.tokenSalt);
26
+ const state = parseSignedPublicToken(req.query.state, env.tokenSalt) as { provider: string; client_id: string; flow: 'socket'|'http'; callbackUrl: string; uid?: string };
24
27
  if (req.query.error) {
25
28
  if (state.flow === 'socket') {
26
29
  const client = env.clients.get(state.client_id);
@@ -36,6 +39,7 @@ export const addRoute = (env: RouteInitEnvironment) => {
36
39
  // Got authorization code
37
40
  const authCode = req.query.code;
38
41
  const provider = env.authProviders[state.provider];
42
+ LOG_DETAILS.provider = state.provider;
39
43
 
40
44
  // Get access & refresh tokens
41
45
  const tokens = await provider.getAccessToken({ type: 'auth', auth_code: authCode, redirect_url: `${req.protocol}://${req.headers.host}/oauth2/${env.db.name}/signin` });
@@ -58,12 +62,13 @@ export const addRoute = (env: RouteInitEnvironment) => {
58
62
  if (contentType === 'image/png') { //state.provider === 'google' &&
59
63
  // Don't accept image/png, because it's probably a placeholder image. Google does this by creating a png with people's initials
60
64
  user_details.picture = [];
61
- return;
62
65
  }
63
- const image = await response.arrayBuffer();
64
- let buff = Buffer.from(image);
65
- best.url = `data:${contentType};base64,${buff.toString('base64')}`;
66
- user_details.picture = [best]; // Only keep the best one
66
+ else {
67
+ const image = await response.arrayBuffer();
68
+ let buff = Buffer.from(image);
69
+ best.url = `data:${contentType};base64,${buff.toString('base64')}`;
70
+ user_details.picture = [best]; // Only keep the best one
71
+ }
67
72
  }
68
73
  catch(err) {
69
74
  env.debug.warn(`Could not fetch profile picture from "${best.url}": `, err);
@@ -148,7 +153,7 @@ export const addRoute = (env: RouteInitEnvironment) => {
148
153
  await env.authRef.child(uid).child('settings').update(getProviderSettings());
149
154
 
150
155
  // Log success
151
- env.logRef.push({ action: 'oauth2_signin', success: true, ip: req.ip, date: new Date(), uid });
156
+ env.log.event(LOG_ACTION, { ...LOG_DETAILS, uid });
152
157
 
153
158
  // Cache the user
154
159
  env.authCache.set(user.uid, user);
@@ -171,14 +176,14 @@ export const addRoute = (env: RouteInitEnvironment) => {
171
176
  };
172
177
 
173
178
  env.config.email?.send(request).catch(err => {
174
- env.logRef.push({ action: 'oauth2_login_email', success: false, code: 'unexpected', ip: req.ip, date: new Date(), error: err.message, request });
179
+ env.log.error(LOG_ACTION + '.email', 'unexpected', { ...LOG_DETAILS, uid, request }, err);
175
180
  });
176
181
  }
177
182
  else if (snaps.length === 0) {
178
183
  // User does not exist, create
179
184
 
180
185
  if (!env.config.auth.allowUserSignup) {
181
- env.logRef.push({ action: 'oauth2_signup', success: false, code: 'user_signup_disabled', provider: state.provider, email: user_details.email, date: new Date() });
186
+ env.log.error(LOG_ACTION, 'user_signup_disabled', { ...LOG_DETAILS, email: user_details.email });
182
187
  res.statusCode = 403; // Forbidden
183
188
  return res.send({ code: 'admin_only', message: 'Only admin is allowed to create users' });
184
189
  }
@@ -208,7 +213,7 @@ export const addRoute = (env: RouteInitEnvironment) => {
208
213
  user.uid = uid;
209
214
 
210
215
  // Log success
211
- env.logRef.push({ action: 'oauth2_signup', success: true, ip: req.ip, date: new Date(), uid });
216
+ env.log.event(LOG_ACTION, { ...LOG_DETAILS, uid });
212
217
 
213
218
  // Cache the user
214
219
  env.authCache.set(user.uid, user);
@@ -231,7 +236,7 @@ export const addRoute = (env: RouteInitEnvironment) => {
231
236
  };
232
237
 
233
238
  env.config.email?.send(request).catch(err => {
234
- env.logRef.push({ action: 'oauth2_signup_email', success: false, code: 'unexpected', ip: req.ip, date: new Date(), error: err.message, request });
239
+ env.log.error(LOG_ACTION + '.email', 'unexpected', { ...LOG_DETAILS, uid, request }, err);
235
240
  });
236
241
  }
237
242
  else {
package/src/rules.ts CHANGED
@@ -2,7 +2,7 @@ import { AceBase } from 'acebase';
2
2
  import { DebugLogger, PathInfo } from 'acebase-core';
3
3
  import * as fs from 'fs';
4
4
  import { DbUserAccountDetails } from './schema/user';
5
- import { AUTH_ACCESS_DEFAULT } from './settings';
5
+ import { AUTH_ACCESS_DEFAULT, AuthAccessDefault } from './settings';
6
6
 
7
7
  type PathRuleFunction = ((env: any) => boolean) & { getText(): string };
8
8
  type PathRules = {} & {
@@ -16,7 +16,7 @@ type RulesData = {
16
16
  }
17
17
  export type RuleValidationFailCode = 'rule'|'no_rule'|'private'|'exception';
18
18
  // type HasAccessResult = { allow: true } | { allow: false; code: RuleValidationFailCode; message: string; rule?: string|boolean; rulePath?: string; details?: any };
19
- type HasAccessResult = { allow: boolean; code?: RuleValidationFailCode; message?: string; rule?: string|boolean; rulePath?: string; details?: any } & ({ allow: true } | { allow: false; code: RuleValidationFailCode; message: string; rule?: string|boolean; rulePath?: string; details?: any });
19
+ type HasAccessResult = { allow: boolean; code?: RuleValidationFailCode; message?: string; rule?: string|boolean; rulePath?: string; details?: Error } & ({ allow: true } | { allow: false; code: RuleValidationFailCode; message: string; rule?: string|boolean; rulePath?: string; details?: Error });
20
20
 
21
21
  export class PathBasedRules {
22
22
 
@@ -24,7 +24,7 @@ export class PathBasedRules {
24
24
  private accessRules: RulesData;
25
25
  stop(): void { throw new Error('not started yet'); }
26
26
 
27
- constructor(rulesFilePath: string, defaultAccess: AUTH_ACCESS_DEFAULT, env: { debug: DebugLogger, db: AceBase, authEnabled: boolean } ) {
27
+ constructor(rulesFilePath: string, defaultAccess: AuthAccessDefault, env: { debug: DebugLogger, db: AceBase, authEnabled: boolean } ) {
28
28
  // Reads rules from a file and monitors it
29
29
  // Check if there is a rules file, load it or generate default
30
30
 
@@ -85,11 +85,11 @@ export class PathBasedRules {
85
85
  rule.getText = () => {
86
86
  return text;
87
87
  }
88
- parent[key] = rule;
88
+ return parent[key] = rule;
89
89
  }
90
90
  else if (key === '.schema') {
91
91
  // Add schema
92
- env.db.schema.set(path, rule)
92
+ return env.db.schema.set(path, rule)
93
93
  .catch(err => {
94
94
  env.debug.error(`Error parsing ${path}/.schema: ${err.message}`)
95
95
  });
@@ -105,15 +105,15 @@ export class PathBasedRules {
105
105
  processRules('', accessRules.rules, []);
106
106
 
107
107
  // Watch file for changes
108
- const wacthFileListener = () => {
108
+ const watchFileListener = () => {
109
109
  // Reload access rules
110
110
  const accessRules = readRules();
111
111
  processRules('', accessRules, []);
112
112
  this.accessRules = accessRules;
113
113
  };
114
- fs.watchFile(rulesFilePath, wacthFileListener);
114
+ fs.watchFile(rulesFilePath, watchFileListener);
115
115
  this.stop = () => {
116
- fs.unwatchFile(rulesFilePath, wacthFileListener);
116
+ fs.unwatchFile(rulesFilePath, watchFileListener);
117
117
  }
118
118
  process.on('SIGINT', this.stop);
119
119
 
package/src/server.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  import { ColorStyle, DebugLogger, SimpleEventEmitter } from 'acebase-core';
2
2
  import { AceBaseServerSettings, AceBaseServerConfig } from './settings';
3
- import { createApp } from './shared/http';
3
+ import { createApp, HttpRequest, HttpResponse } from './shared/http';
4
4
  import { addWebsocketServer } from './websocket';
5
5
  import { RouteInitEnvironment } from './shared/env';
6
6
  import { ConnectedClient } from './shared/clients';
7
7
  import { AceBase, AceBaseLocalSettings, AceBaseStorageSettings } from 'acebase';
8
8
  import { createServer } from 'http';
9
9
  import { createServer as createSecureServer } from 'https';
10
- import { IOAuth2Provider } from './oauth-providers/oauth-provider';
10
+ import { OAuth2Provider } from './oauth-providers/oauth-provider';
11
11
  import oAuth2Providers from './oauth-providers';
12
12
  import { PathBasedRules } from './rules';
13
13
  import { DbUserAccountDetails } from './schema/user';
@@ -23,6 +23,7 @@ import addMetadataRoutes from './routes/meta';
23
23
  import add404Middleware from './middleware/404';
24
24
  import addSwaggerMiddleware from './middleware/swagger';
25
25
  import addCacheMiddleware from './middleware/cache';
26
+ import { DatabaseLog } from './logger';
26
27
 
27
28
  type PrivateStorageSettings = AceBaseStorageSettings & { info?: string; type?: 'data'|'transaction'|'auth'|'log' };
28
29
  // type PrivateLocalSettings = AceBaseLocalSettings & { storage: PrivateStorageSettings };
@@ -31,6 +32,8 @@ export class AceBaseServerNotReadyError extends Error {
31
32
  constructor() { super('Server is not ready yet'); }
32
33
  }
33
34
 
35
+ type HttpMethod = 'get'|'GET'|'put'|'PUT'|'post'|'POST'|'delete'|'DELETE';
36
+
34
37
  export class AceBaseServer extends SimpleEventEmitter {
35
38
 
36
39
  private _ready: boolean = false;
@@ -83,7 +86,7 @@ export class AceBaseServer extends SimpleEventEmitter {
83
86
  */
84
87
  readonly app: ReturnType<typeof createApp>;
85
88
 
86
- private readonly authProviders: { [provider: string]: IOAuth2Provider } = {};
89
+ private readonly authProviders: { [provider: string]: OAuth2Provider } = {};
87
90
 
88
91
  constructor(dbname: string, options?: AceBaseServerSettings) {
89
92
  super();
@@ -153,6 +156,7 @@ export class AceBaseServer extends SimpleEventEmitter {
153
156
  const securityRef = authDb ? authDb === db ? db.ref('__auth__/security') : authDb.ref('security') : null;
154
157
  const authRef = authDb ? authDb === db ? db.ref('__auth__/accounts') : authDb.ref('accounts') : null;
155
158
  const logRef = authDb ? authDb === db ? db.ref('__log__') : authDb.ref('log') : null;
159
+ const logger = new DatabaseLog(logRef);
156
160
 
157
161
  // Setup rules
158
162
  const rulesFilePath = `${this.config.path}/${this.db.name}.acebase/rules.json`;
@@ -167,7 +171,7 @@ export class AceBaseServer extends SimpleEventEmitter {
167
171
  debug: this.debug,
168
172
  securityRef,
169
173
  authRef,
170
- logRef,
174
+ log: logger,
171
175
  tokenSalt: null,
172
176
  clients,
173
177
  authCache: null,
@@ -211,7 +215,7 @@ export class AceBaseServer extends SimpleEventEmitter {
211
215
  addWebManagerRoutes(routeEnv);
212
216
 
213
217
  // Allow adding custom routes
214
- this.extend = (method: 'get'|'put'|'post'|'delete', ext_path: string, handler: (req: Express.Request, res: Express.Response) => any) => {
218
+ this.extend = (method: HttpMethod, ext_path: string, handler: (req: HttpRequest, res: HttpResponse) => any) => {
215
219
  const route = `/ext/${db.name}/${ext_path}`;
216
220
  this.debug.log(`Extending server: `, method, route);
217
221
  routeEnv.app[method.toLowerCase()](route, handler);
@@ -385,11 +389,11 @@ export class AceBaseServer extends SimpleEventEmitter {
385
389
  * .then(quote => {
386
390
  * console.log(`Got random quote: ${quote}`);
387
391
  * })
388
- * @param {'get'|'put'|'post'|'delete'} method
389
- * @param {string} ext_path
390
- * @param {(req: Express.Request, res: Express.Response)} handler
392
+ * @param method http method to bind to
393
+ * @param ext_path path to bind to (appended to /ext/)
394
+ * @param handler your Express request handler callback
391
395
  */
392
- extend(method: 'get'|'put'|'post'|'delete', ext_path: string, handler: (req: Express.Request, res: Express.Response) => void) {
396
+ extend(method: HttpMethod, ext_path: string, handler: (req: HttpRequest, res: HttpResponse) => void) {
393
397
  throw new AceBaseServerNotReadyError();
394
398
  }
395
399
 
@@ -14,5 +14,5 @@ export interface AceBaseServerEmailSettings {
14
14
  server?: AceBaseServerEmailServerSettings;
15
15
 
16
16
  /** function to call when an e-mail needs to be sent */
17
- send: (request: AceBaseEmailRequest) => Promise<boolean>;
17
+ send: (request: AceBaseEmailRequest) => Promise<void>;
18
18
  };
@@ -35,11 +35,12 @@ export class AceBaseServerHttpsConfig {
35
35
  }
36
36
  }
37
37
 
38
- export enum AUTH_ACCESS_DEFAULT {
39
- DENY_ALL = 'deny',
40
- ALLOW_ALL = 'allow',
41
- ALLOW_AUTHENTICATED = 'auth'
42
- }
38
+ export type AuthAccessDefault = 'deny'|'allow'|'auth';
39
+ export const AUTH_ACCESS_DEFAULT: { [key: string]: AuthAccessDefault } = {
40
+ DENY_ALL: 'deny',
41
+ ALLOW_ALL: 'allow',
42
+ ALLOW_AUTHENTICATED: 'auth'
43
+ };
43
44
 
44
45
  export class AceBaseServerAuthenticationSettings {
45
46
 
@@ -66,7 +67,7 @@ export class AceBaseServerAuthenticationSettings {
66
67
  /**
67
68
  * 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)
68
69
  */
69
- readonly defaultAccessRule: AUTH_ACCESS_DEFAULT = AUTH_ACCESS_DEFAULT.ALLOW_AUTHENTICATED;
70
+ readonly defaultAccessRule: AuthAccessDefault = AUTH_ACCESS_DEFAULT.ALLOW_AUTHENTICATED;
70
71
 
71
72
  /**
72
73
  * 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.
@@ -220,7 +221,6 @@ export class AceBaseServerConfig {
220
221
  readonly email: AceBaseServerEmailSettings;
221
222
  readonly transactions: AceBaseServerTransactionSettings;
222
223
  readonly ipc: IPCClientSettings;
223
-
224
224
  readonly storage?: AceBaseStorageSettings;
225
225
 
226
226
  constructor(settings: AceBaseServerSettings) {
@@ -27,5 +27,5 @@ export class ConnectedClient {
27
27
  realtimeQueries: { [id: string]: { path: string; query: IApiQuery, options: IApiQueryOptions }} = {};
28
28
 
29
29
  /** Currently running transactions */
30
- transactions: { [id: string]: { id: string; started: number; path: string; context: any; finish?: (val?: any) => Promise<any>; timeout: NodeJS.Timeout } } = {};
30
+ transactions: { [id: string]: { id: string; started: number; path: string; context: any; finish?: (val?: any) => Promise<{ cursor?: string }>; timeout: NodeJS.Timeout } } = {};
31
31
  }
package/src/shared/env.ts CHANGED
@@ -4,11 +4,12 @@ import type { AceBaseServerConfig } from '../settings';
4
4
  import type { DbUserAccountDetails } from '../schema/user';
5
5
  import type { ConnectedClient } from './clients';
6
6
  import type { DebugLogger, SimpleCache } from 'acebase-core';
7
- import type { IOAuth2Provider } from '../oauth-providers/oauth-provider';
7
+ import type { OAuth2Provider } from '../oauth-providers/oauth-provider';
8
8
  import type { Server as HttpServer } from 'http';
9
9
  import type { Server as SecureHttpServer } from 'https';
10
10
  import type { PathBasedRules } from '../rules';
11
11
  import { Api } from 'acebase-core/src/api';
12
+ import { DatabaseLog } from '../logger';
12
13
 
13
14
  export interface RouteInitEnvironment {
14
15
  server: HttpServer | SecureHttpServer;
@@ -19,11 +20,11 @@ export interface RouteInitEnvironment {
19
20
  debug: DebugLogger;
20
21
  securityRef: DataReference;
21
22
  authRef: DataReference;
22
- logRef: DataReference;
23
+ log: DatabaseLog; // logRef: DataReference;
23
24
  tokenSalt: string;
24
25
  clients: Map<string, ConnectedClient>;
25
26
  authCache: SimpleCache<string, DbUserAccountDetails>;
26
- authProviders: { [providerName: string]: IOAuth2Provider };
27
+ authProviders: { [providerName: string]: OAuth2Provider };
27
28
  rules: PathBasedRules
28
29
  };
29
30
 
@@ -32,7 +33,7 @@ export interface RouteRequestEnvironment {
32
33
  user?: DbUserAccountDetails;
33
34
 
34
35
  /** If context is sent through AceBase-Context header, it will be bound to the incoming request */
35
- context?: { [key: string]: any };
36
+ context: { [key: string]: any };
36
37
  };
37
38
 
38
39
  export type RouteRequest<Params = any, ResBody = any, ReqBody = any, ReqQuery = any, Locals extends Record<string, any> = Record<string, any>> = Request<Params, ResBody, ReqBody, ReqQuery, Locals> & RouteRequestEnvironment;
@@ -5,6 +5,8 @@ const createExpress = (express as any).default ?? express; // ESM and CJS compat
5
5
 
6
6
  export type HttpApp = express.Express;
7
7
  export type HttpSocket = Socket;
8
+ export type HttpRequest = express.Request;
9
+ export type HttpResponse = express.Response;
8
10
 
9
11
  /**
10
12
  * Creates an app that handles http requests, adds json body parsing.