@aurabase/aurabase-js 0.3.0 → 0.3.1

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 (258) hide show
  1. package/package.json +4 -4
  2. package/packages/ai/node_modules/.bin/esbuild +0 -19
  3. package/packages/ai/node_modules/.bin/tsc +0 -22
  4. package/packages/ai/node_modules/.bin/tsserver +0 -22
  5. package/packages/ai/node_modules/.bin/tsup +0 -22
  6. package/packages/ai/node_modules/.bin/tsup-node +0 -22
  7. package/packages/ai/node_modules/.bin/vite +0 -22
  8. package/packages/ai/node_modules/.bin/vitest +0 -22
  9. package/packages/ai/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +0 -1
  10. package/packages/ai/src/AiService.ts +0 -226
  11. package/packages/ai/src/index.ts +0 -18
  12. package/packages/ai/src/sse.ts +0 -141
  13. package/packages/ai/src/types.ts +0 -30
  14. package/packages/ai/tests/chat-stream.test.ts +0 -151
  15. package/packages/ai/tests/rag-namespaces.test.ts +0 -54
  16. package/packages/ai/tests/sse.test.ts +0 -69
  17. package/packages/ai/tsconfig.json +0 -5
  18. package/packages/ai/tsup.config.ts +0 -11
  19. package/packages/aurabase/node_modules/.bin/esbuild +0 -19
  20. package/packages/aurabase/node_modules/.bin/tsc +0 -22
  21. package/packages/aurabase/node_modules/.bin/tsserver +0 -22
  22. package/packages/aurabase/node_modules/.bin/tsup +0 -22
  23. package/packages/aurabase/node_modules/.bin/tsup-node +0 -22
  24. package/packages/aurabase/node_modules/.bin/vite +0 -22
  25. package/packages/aurabase/node_modules/.bin/vitest +0 -22
  26. package/packages/aurabase/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +0 -1
  27. package/packages/aurabase/src/AuraClient.ts +0 -237
  28. package/packages/aurabase/src/index.ts +0 -152
  29. package/packages/aurabase/src/ssr.ts +0 -156
  30. package/packages/aurabase/tests/ai-streaming-rag-e2e.test.ts +0 -82
  31. package/packages/aurabase/tests/ai.test.ts +0 -111
  32. package/packages/aurabase/tests/auth-admin.test.ts +0 -515
  33. package/packages/aurabase/tests/auth-e2e.test.ts +0 -135
  34. package/packages/aurabase/tests/auth-hardening.test.ts +0 -206
  35. package/packages/aurabase/tests/auth.test.ts +0 -947
  36. package/packages/aurabase/tests/database.test.ts +0 -230
  37. package/packages/aurabase/tests/db-types-e2e.test.ts +0 -217
  38. package/packages/aurabase/tests/dispose.test.ts +0 -23
  39. package/packages/aurabase/tests/foreign-token.e2e.test.ts +0 -129
  40. package/packages/aurabase/tests/functions.test.ts +0 -107
  41. package/packages/aurabase/tests/integration.test.ts +0 -413
  42. package/packages/aurabase/tests/live-production-validation.js +0 -241
  43. package/packages/aurabase/tests/live-sdk-production-validation.js +0 -293
  44. package/packages/aurabase/tests/mocks.ts +0 -139
  45. package/packages/aurabase/tests/notifications.test.ts +0 -314
  46. package/packages/aurabase/tests/observability-backup.test.ts +0 -186
  47. package/packages/aurabase/tests/observability-hook.test.ts +0 -130
  48. package/packages/aurabase/tests/production-robustness.test.ts +0 -268
  49. package/packages/aurabase/tests/public-api-surface.test.ts +0 -53
  50. package/packages/aurabase/tests/query-builder.test.ts +0 -329
  51. package/packages/aurabase/tests/readme-smoke-e2e.test.ts +0 -231
  52. package/packages/aurabase/tests/realtime-filter-e2e.test.ts +0 -344
  53. package/packages/aurabase/tests/refresh-locks.test.ts +0 -210
  54. package/packages/aurabase/tests/retry-option.test.ts +0 -17
  55. package/packages/aurabase/tests/rpc-e2e.test.ts +0 -254
  56. package/packages/aurabase/tests/rs256-local-e2e.test.ts +0 -114
  57. package/packages/aurabase/tests/rt-alias-public-e2e.test.ts +0 -235
  58. package/packages/aurabase/tests/rt-http-broadcast-e2e.test.ts +0 -124
  59. package/packages/aurabase/tests/service-role-guard.test.ts +0 -99
  60. package/packages/aurabase/tests/ssr.test.ts +0 -91
  61. package/packages/aurabase/tests/storage-backend-e2e.test.ts +0 -481
  62. package/packages/aurabase/tests/storage-sdk-parity-e2e.test.ts +0 -104
  63. package/packages/aurabase/tests/storage-transform-e2e.test.ts +0 -684
  64. package/packages/aurabase/tests/storage.test.ts +0 -55
  65. package/packages/aurabase/tests/types/client-generic.test-d.ts +0 -79
  66. package/packages/aurabase/tests/types/docs-snippets.test-d.ts +0 -571
  67. package/packages/aurabase/tests/types/error-code.test-d.ts +0 -53
  68. package/packages/aurabase/tsconfig.json +0 -5
  69. package/packages/aurabase/tsconfig.test-d.json +0 -5
  70. package/packages/aurabase/tsup.config.ts +0 -11
  71. package/packages/aurabase/vitest.config.ts +0 -16
  72. package/packages/auth/node_modules/.bin/esbuild +0 -19
  73. package/packages/auth/node_modules/.bin/tsc +0 -22
  74. package/packages/auth/node_modules/.bin/tsserver +0 -22
  75. package/packages/auth/node_modules/.bin/tsup +0 -22
  76. package/packages/auth/node_modules/.bin/tsup-node +0 -22
  77. package/packages/auth/node_modules/.bin/vite +0 -22
  78. package/packages/auth/node_modules/.bin/vitest +0 -22
  79. package/packages/auth/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +0 -1
  80. package/packages/auth/src/AuthAdminService.ts +0 -149
  81. package/packages/auth/src/AuthService.ts +0 -1166
  82. package/packages/auth/src/SessionManager.ts +0 -92
  83. package/packages/auth/src/index.ts +0 -17
  84. package/packages/auth/src/jwks.ts +0 -337
  85. package/packages/auth/src/pkce.ts +0 -27
  86. package/packages/auth/src/types.ts +0 -89
  87. package/packages/auth/tests/auth-lifecycle.test.ts +0 -149
  88. package/packages/auth/tests/detect-session.test.ts +0 -361
  89. package/packages/auth/tests/getclaims.test.ts +0 -780
  90. package/packages/auth/tests/is-mfa-challenge.test.ts +0 -27
  91. package/packages/auth/tests/password-recovery.test.ts +0 -124
  92. package/packages/auth/tests/pkce.test.ts +0 -192
  93. package/packages/auth/tests/session-manager.test.ts +0 -103
  94. package/packages/auth/tests/set-session.test.ts +0 -139
  95. package/packages/auth/tests/verify-otp.test.ts +0 -153
  96. package/packages/auth/tsconfig.json +0 -5
  97. package/packages/auth/tsup.config.ts +0 -11
  98. package/packages/core/node_modules/.bin/esbuild +0 -22
  99. package/packages/core/node_modules/.bin/tsc +0 -22
  100. package/packages/core/node_modules/.bin/tsserver +0 -22
  101. package/packages/core/node_modules/.bin/tsup +0 -22
  102. package/packages/core/node_modules/.bin/tsup-node +0 -22
  103. package/packages/core/node_modules/.bin/vite +0 -22
  104. package/packages/core/node_modules/.bin/vitest +0 -22
  105. package/packages/core/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +0 -1
  106. package/packages/core/src/AuraError.ts +0 -89
  107. package/packages/core/src/BaseService.ts +0 -44
  108. package/packages/core/src/client.ts +0 -34
  109. package/packages/core/src/cookie-utils.ts +0 -42
  110. package/packages/core/src/fetch.ts +0 -435
  111. package/packages/core/src/index.ts +0 -22
  112. package/packages/core/src/retry.ts +0 -63
  113. package/packages/core/src/serialize.ts +0 -6
  114. package/packages/core/src/stores/BaseAuthStore.ts +0 -164
  115. package/packages/core/src/stores/LocalAuthStore.ts +0 -199
  116. package/packages/core/src/types.ts +0 -1042
  117. package/packages/core/tests/auth-store.test.ts +0 -300
  118. package/packages/core/tests/error-code.test.ts +0 -61
  119. package/packages/core/tests/error.test.ts +0 -24
  120. package/packages/core/tests/fetch.test.ts +0 -286
  121. package/packages/core/tests/mocks.ts +0 -139
  122. package/packages/core/tests/observability.test.ts +0 -86
  123. package/packages/core/tests/refresh-hardening.test.ts +0 -164
  124. package/packages/core/tests/refresh-observability.test.ts +0 -111
  125. package/packages/core/tests/retry.test.ts +0 -106
  126. package/packages/core/tests/serialize.test.ts +0 -12
  127. package/packages/core/tests/timeout.test.ts +0 -79
  128. package/packages/core/tsconfig.json +0 -5
  129. package/packages/core/tsup.config.ts +0 -11
  130. package/packages/db/node_modules/.bin/esbuild +0 -19
  131. package/packages/db/node_modules/.bin/tsc +0 -22
  132. package/packages/db/node_modules/.bin/tsserver +0 -22
  133. package/packages/db/node_modules/.bin/tsup +0 -22
  134. package/packages/db/node_modules/.bin/tsup-node +0 -22
  135. package/packages/db/node_modules/.bin/vite +0 -22
  136. package/packages/db/node_modules/.bin/vitest +0 -22
  137. package/packages/db/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +0 -1
  138. package/packages/db/src/DatabaseService.ts +0 -170
  139. package/packages/db/src/QueryBuilder.ts +0 -830
  140. package/packages/db/src/index.ts +0 -2
  141. package/packages/db/src/pgrst-types/common/common.ts +0 -86
  142. package/packages/db/src/pgrst-types/common/rpc.ts +0 -151
  143. package/packages/db/src/pgrst-types/feature-flags.ts +0 -20
  144. package/packages/db/src/pgrst-types/types.ts +0 -134
  145. package/packages/db/src/select-query-parser/parser.ts +0 -479
  146. package/packages/db/src/select-query-parser/result.ts +0 -553
  147. package/packages/db/src/select-query-parser/types.ts +0 -132
  148. package/packages/db/src/select-query-parser/utils.ts +0 -707
  149. package/packages/db/tests/filters.test.ts +0 -81
  150. package/packages/db/tests/mutations-filtered.e2e.test.ts +0 -132
  151. package/packages/db/tests/mutations-filtered.test.ts +0 -188
  152. package/packages/db/tests/order.test.ts +0 -45
  153. package/packages/db/tests/rpc.test.ts +0 -41
  154. package/packages/db/tests/scale/build-large-schema.ts +0 -94
  155. package/packages/db/tests/scale/scale-compile.test.ts +0 -167
  156. package/packages/db/tests/schema.test.ts +0 -77
  157. package/packages/db/tests/single-accept.e2e.test.ts +0 -123
  158. package/packages/db/tests/single.test.ts +0 -211
  159. package/packages/db/tests/types/filters.test-d.ts +0 -52
  160. package/packages/db/tests/types/fixtures.ts +0 -40
  161. package/packages/db/tests/types/from-views.test-d.ts +0 -18
  162. package/packages/db/tests/types/mutations.test-d.ts +0 -23
  163. package/packages/db/tests/types/rpc.test-d.ts +0 -60
  164. package/packages/db/tests/types/schema-shape.test-d.ts +0 -8
  165. package/packages/db/tests/types/select-inference.test-d.ts +0 -38
  166. package/packages/db/tests/vendored/fixtures.ts +0 -83
  167. package/packages/db/tests/vendored/get-result.test-d.ts +0 -75
  168. package/packages/db/tsconfig.json +0 -5
  169. package/packages/db/tsconfig.test-d.json +0 -5
  170. package/packages/db/tsup.config.ts +0 -11
  171. package/packages/db/vitest.config.ts +0 -8
  172. package/packages/functions/node_modules/.bin/esbuild +0 -19
  173. package/packages/functions/node_modules/.bin/tsc +0 -22
  174. package/packages/functions/node_modules/.bin/tsserver +0 -22
  175. package/packages/functions/node_modules/.bin/tsup +0 -22
  176. package/packages/functions/node_modules/.bin/tsup-node +0 -22
  177. package/packages/functions/node_modules/.bin/vite +0 -22
  178. package/packages/functions/node_modules/.bin/vitest +0 -22
  179. package/packages/functions/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +0 -1
  180. package/packages/functions/src/FunctionsService.ts +0 -188
  181. package/packages/functions/src/errors.ts +0 -70
  182. package/packages/functions/src/index.ts +0 -6
  183. package/packages/functions/tests/invoke.test.ts +0 -97
  184. package/packages/functions/tests/response-type-errors.test.ts +0 -135
  185. package/packages/functions/tsconfig.json +0 -5
  186. package/packages/functions/tsup.config.ts +0 -11
  187. package/packages/gen/node_modules/.bin/esbuild +0 -19
  188. package/packages/gen/node_modules/.bin/tsc +0 -22
  189. package/packages/gen/node_modules/.bin/tsserver +0 -22
  190. package/packages/gen/node_modules/.bin/tsup +0 -22
  191. package/packages/gen/node_modules/.bin/tsup-node +0 -22
  192. package/packages/gen/node_modules/.bin/vite +0 -22
  193. package/packages/gen/node_modules/.bin/vitest +0 -22
  194. package/packages/gen/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +0 -1
  195. package/packages/gen/src/cli.ts +0 -67
  196. package/packages/gen/src/generate.ts +0 -0
  197. package/packages/gen/src/index.ts +0 -2
  198. package/packages/gen/tests/compile.test.ts +0 -213
  199. package/packages/gen/tests/e2e.test.ts +0 -130
  200. package/packages/gen/tests/generate.test.ts +0 -396
  201. package/packages/gen/tsconfig.json +0 -5
  202. package/packages/gen/tsup.config.ts +0 -11
  203. package/packages/notifications/node_modules/.bin/esbuild +0 -19
  204. package/packages/notifications/node_modules/.bin/tsc +0 -22
  205. package/packages/notifications/node_modules/.bin/tsserver +0 -22
  206. package/packages/notifications/node_modules/.bin/tsup +0 -22
  207. package/packages/notifications/node_modules/.bin/tsup-node +0 -22
  208. package/packages/notifications/node_modules/.bin/vite +0 -22
  209. package/packages/notifications/node_modules/.bin/vitest +0 -22
  210. package/packages/notifications/src/NotificationsService.ts +0 -230
  211. package/packages/notifications/src/index.ts +0 -19
  212. package/packages/notifications/tsconfig.json +0 -5
  213. package/packages/notifications/tsup.config.ts +0 -11
  214. package/packages/realtime/node_modules/.bin/esbuild +0 -19
  215. package/packages/realtime/node_modules/.bin/tsc +0 -22
  216. package/packages/realtime/node_modules/.bin/tsserver +0 -22
  217. package/packages/realtime/node_modules/.bin/tsup +0 -22
  218. package/packages/realtime/node_modules/.bin/tsup-node +0 -22
  219. package/packages/realtime/node_modules/.bin/vite +0 -22
  220. package/packages/realtime/node_modules/.bin/vitest +0 -22
  221. package/packages/realtime/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +0 -1
  222. package/packages/realtime/src/AuraChannel.ts +0 -485
  223. package/packages/realtime/src/HeartbeatManager.ts +0 -73
  224. package/packages/realtime/src/RealtimeService.ts +0 -505
  225. package/packages/realtime/src/columnFilter.ts +0 -301
  226. package/packages/realtime/src/index.ts +0 -4
  227. package/packages/realtime/tests/ack-routing.test.ts +0 -81
  228. package/packages/realtime/tests/column-filter.test.ts +0 -144
  229. package/packages/realtime/tests/dispatch.test.ts +0 -191
  230. package/packages/realtime/tests/heartbeat.test.ts +0 -67
  231. package/packages/realtime/tests/http-broadcast.test.ts +0 -68
  232. package/packages/realtime/tests/realtime-token.test.ts +0 -43
  233. package/packages/realtime/tests/reconnect-race.test.ts +0 -149
  234. package/packages/realtime/tests/ref-id.test.ts +0 -34
  235. package/packages/realtime/tests/set-auth.test.ts +0 -70
  236. package/packages/realtime/tsconfig.json +0 -5
  237. package/packages/realtime/tsup.config.ts +0 -11
  238. package/packages/storage/node_modules/.bin/esbuild +0 -19
  239. package/packages/storage/node_modules/.bin/tsc +0 -22
  240. package/packages/storage/node_modules/.bin/tsserver +0 -22
  241. package/packages/storage/node_modules/.bin/tsup +0 -22
  242. package/packages/storage/node_modules/.bin/tsup-node +0 -22
  243. package/packages/storage/node_modules/.bin/vite +0 -22
  244. package/packages/storage/node_modules/.bin/vitest +0 -22
  245. package/packages/storage/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +0 -1
  246. package/packages/storage/src/DownloadBuilder.ts +0 -60
  247. package/packages/storage/src/StorageService.ts +0 -323
  248. package/packages/storage/src/index.ts +0 -2
  249. package/packages/storage/src/path.ts +0 -35
  250. package/packages/storage/src/transform.ts +0 -15
  251. package/packages/storage/tests/download.test.ts +0 -64
  252. package/packages/storage/tests/parity.test.ts +0 -154
  253. package/packages/storage/tests/path.test.ts +0 -87
  254. package/packages/storage/tests/transform.test.ts +0 -79
  255. package/packages/storage/tsconfig.json +0 -5
  256. package/packages/storage/tsup.config.ts +0 -11
  257. package/pnpm-workspace.yaml +0 -24
  258. package/tsconfig.base.json +0 -15
@@ -1,111 +0,0 @@
1
- import { describe, it, expect, beforeEach, afterEach } from 'vitest'
2
- import { AuraClient } from '../src/AuraClient'
3
- import { FetchMock, fakeTokenPair } from './mocks'
4
-
5
- const BASE = 'http://localhost:8080'
6
- const PROJECT = '00000000-0000-0000-0000-000000000001'
7
- const PREFIX = `${BASE}/v1/ai/${PROJECT}`
8
-
9
- let fetchMock: FetchMock
10
- let client: AuraClient
11
-
12
- beforeEach(() => {
13
- fetchMock = new FetchMock()
14
- fetchMock.init()
15
- client = new AuraClient(BASE, PROJECT, 'aura_anon_test', {
16
- auth: { persistSession: false },
17
- })
18
- const tp = fakeTokenPair()
19
- client.authStore.save(tp.access_token, tp.refresh_token, tp.user)
20
- })
21
-
22
- afterEach(() => {
23
- fetchMock.restore()
24
- fetchMock.clearMocks()
25
- })
26
-
27
- describe('AiService route contract', () => {
28
- it('sends chat messages to /chat', async () => {
29
- fetchMock.on({
30
- method: 'POST',
31
- url: `${PREFIX}/chat`,
32
- replyCode: 200,
33
- replyBody: { data: { content: 'ok', model: 'test' } },
34
- })
35
-
36
- await client.ai.chat([{ role: 'user', content: 'hello' }], { max_tokens: 32 })
37
-
38
- expect(fetchMock.calls[0].body).toEqual({
39
- messages: [{ role: 'user', content: 'hello' }],
40
- max_tokens: 32,
41
- })
42
- })
43
-
44
- it('uses backend embed payload shape', async () => {
45
- fetchMock.on({
46
- method: 'POST',
47
- url: `${PREFIX}/embed`,
48
- replyCode: 200,
49
- replyBody: { data: { id: 'emb-1', dimensions: 1536 } },
50
- })
51
-
52
- await client.ai.embed({ text: 'doc', namespace: 'kb', metadata: { source: 'test' } })
53
-
54
- expect(fetchMock.calls[0].body).toEqual({
55
- text: 'doc',
56
- namespace: 'kb',
57
- metadata: { source: 'test' },
58
- })
59
- })
60
-
61
- it('queries and ingests RAG using backend routes', async () => {
62
- fetchMock.on({
63
- method: 'POST',
64
- url: `${PREFIX}/rag/query`,
65
- replyCode: 200,
66
- replyBody: { data: { answer: 'ok', sources: [], model: 'test' } },
67
- })
68
- fetchMock.on({
69
- method: 'POST',
70
- url: `${PREFIX}/rag/ingest`,
71
- replyCode: 200,
72
- replyBody: { data: { id: 'ing-1', chunks: 1 } },
73
- })
74
-
75
- await client.ai.rag({ question: 'what?', namespace: 'kb' })
76
- await client.ai.ragIngest({ namespace: 'kb', content: 'hello' })
77
-
78
- expect(fetchMock.calls[0].body).toEqual({ question: 'what?', namespace: 'kb' })
79
- expect(fetchMock.calls[1].body).toEqual({ namespace: 'kb', content: 'hello' })
80
- })
81
-
82
- it('performs semantic search with GET query params', async () => {
83
- fetchMock.on({
84
- method: 'GET',
85
- url: `${PREFIX}/search?query=hello&namespace=kb&top_k=3&threshold=0.7`,
86
- replyCode: 200,
87
- replyBody: { data: [] },
88
- })
89
-
90
- await client.ai.semanticSearch('hello', 'kb', { top_k: 3, threshold: 0.7 })
91
-
92
- expect(fetchMock.calls[0].url).toBe(`${PREFIX}/search?query=hello&namespace=kb&top_k=3&threshold=0.7`)
93
- })
94
-
95
- it('sends nl2sql backend payload shape', async () => {
96
- fetchMock.on({
97
- method: 'POST',
98
- url: `${PREFIX}/nl2sql`,
99
- replyCode: 200,
100
- replyBody: { data: { sql: 'SELECT 1', explanation: 'ok' } },
101
- })
102
-
103
- await client.ai.nl2sql('count users', 'CREATE TABLE users (id uuid);', { dialect: 'postgres' })
104
-
105
- expect(fetchMock.calls[0].body).toEqual({
106
- question: 'count users',
107
- schema: 'CREATE TABLE users (id uuid);',
108
- dialect: 'postgres',
109
- })
110
- })
111
- })
@@ -1,515 +0,0 @@
1
- // ---------------------------------------------------------------------------
2
- // AuthAdminService tests
3
- // ---------------------------------------------------------------------------
4
-
5
- import { describe, it, expect, beforeEach, afterEach } from 'vitest'
6
- import { AuraClient } from '../src/AuraClient'
7
- import { FetchMock, fakeUser } from './mocks'
8
-
9
- const BASE = 'http://localhost:8080'
10
- const PROJECT = 'test-project'
11
- const ADMIN_PREFIX = `${BASE}/v1/auth/${PROJECT}/admin`
12
-
13
- let fetchMock: FetchMock
14
- let client: AuraClient
15
-
16
- beforeEach(() => {
17
- fetchMock = new FetchMock()
18
- fetchMock.init()
19
- client = new AuraClient(BASE, PROJECT, {
20
- auth: { persistSession: false },
21
- })
22
- })
23
-
24
- afterEach(() => {
25
- fetchMock.restore()
26
- fetchMock.clearMocks()
27
- })
28
-
29
- // ---------------------------------------------------------------------------
30
- describe('AuthAdminService.listUsers', () => {
31
- it('sends GET /admin/users with query params', async () => {
32
- fetchMock.on({
33
- method: 'GET',
34
- url: new RegExp(`${ADMIN_PREFIX}/users`),
35
- replyCode: 200,
36
- replyBody: { data: [fakeUser()] },
37
- })
38
-
39
- const res = await client.authAdmin.listUsers({ limit: 10, offset: 5, search: 'test' })
40
-
41
- expect(res.error).toBeNull()
42
- expect(fetchMock.calls[0].method).toBe('GET')
43
- expect(fetchMock.calls[0].url).toContain('limit=10')
44
- expect(fetchMock.calls[0].url).toContain('offset=5')
45
- expect(fetchMock.calls[0].url).toContain('search=test')
46
- })
47
-
48
- it('sends GET /admin/users without params', async () => {
49
- fetchMock.on({
50
- method: 'GET',
51
- url: `${ADMIN_PREFIX}/users`,
52
- replyCode: 200,
53
- replyBody: { data: [] },
54
- })
55
-
56
- const res = await client.authAdmin.listUsers()
57
-
58
- expect(res.error).toBeNull()
59
- expect(fetchMock.calls[0].url).toBe(`${ADMIN_PREFIX}/users`)
60
- })
61
-
62
- it('sends limit=0 and offset=0 explicitly (falsy-but-defined values must not be dropped)', async () => {
63
- fetchMock.on({
64
- method: 'GET',
65
- url: new RegExp(`${ADMIN_PREFIX}/users`),
66
- replyCode: 200,
67
- replyBody: { data: [] },
68
- })
69
-
70
- const res = await client.authAdmin.listUsers({ limit: 0, offset: 0 })
71
-
72
- expect(res.error).toBeNull()
73
- expect(fetchMock.calls[0].url).toContain('limit=0')
74
- expect(fetchMock.calls[0].url).toContain('offset=0')
75
- })
76
- })
77
-
78
- // ---------------------------------------------------------------------------
79
- describe('AuthAdminService.getUser', () => {
80
- it('sends GET /admin/users/{id}', async () => {
81
- const user = fakeUser({ id: 'uid-42' })
82
- fetchMock.on({
83
- method: 'GET',
84
- url: `${ADMIN_PREFIX}/users/uid-42`,
85
- replyCode: 200,
86
- replyBody: { data: user },
87
- })
88
-
89
- const res = await client.authAdmin.getUser('uid-42')
90
-
91
- expect(res.error).toBeNull()
92
- expect(res.data?.id).toBe('uid-42')
93
- })
94
- })
95
-
96
- // ---------------------------------------------------------------------------
97
- describe('AuthAdminService.createUser', () => {
98
- it('sends POST /admin/users with body', async () => {
99
- const user = fakeUser()
100
- fetchMock.on({
101
- method: 'POST',
102
- url: `${ADMIN_PREFIX}/users`,
103
- replyCode: 201,
104
- replyBody: { data: user },
105
- })
106
-
107
- const res = await client.authAdmin.createUser({
108
- email: 'new@example.com',
109
- password: 'strongpass',
110
- })
111
-
112
- expect(res.error).toBeNull()
113
- expect(fetchMock.calls[0].method).toBe('POST')
114
- expect((fetchMock.calls[0].body as any).email).toBe('new@example.com')
115
- })
116
- })
117
-
118
- // ---------------------------------------------------------------------------
119
- describe('AuthAdminService.updateUser', () => {
120
- it('sends PUT /admin/users/{id} with body', async () => {
121
- const user = fakeUser({ email: 'updated@example.com' })
122
- fetchMock.on({
123
- method: 'PUT',
124
- url: `${ADMIN_PREFIX}/users/uid-42`,
125
- replyCode: 200,
126
- replyBody: { data: user },
127
- })
128
-
129
- const res = await client.authAdmin.updateUser('uid-42', { email: 'updated@example.com' })
130
-
131
- expect(res.error).toBeNull()
132
- expect(fetchMock.calls[0].method).toBe('PUT')
133
- expect((fetchMock.calls[0].body as any).email).toBe('updated@example.com')
134
- })
135
- })
136
-
137
- // ---------------------------------------------------------------------------
138
- describe('AuthAdminService.deleteUser', () => {
139
- it('sends DELETE /admin/users/{id} and returns AuraResponse<null>', async () => {
140
- fetchMock.on({
141
- method: 'DELETE',
142
- url: `${ADMIN_PREFIX}/users/uid-42`,
143
- replyCode: 200,
144
- replyBody: { data: null },
145
- })
146
-
147
- const res = await client.authAdmin.deleteUser('uid-42')
148
-
149
- expect(res.error).toBeNull()
150
- // LOT 3 (I5) : `deleteUser` backend (`services/aura-auth/src/handlers/admin.rs::
151
- // delete_user_admin`) renvoie réellement `ApiResponse::<()>::empty()` (data null) —
152
- // `fetch.ts` honore maintenant ce `null` explicite (`'data' in body`, pas
153
- // `body.data ?? body`) au lieu de retomber sur l'enveloppe entière.
154
- expect(res.data).toBeNull()
155
- expect(fetchMock.calls[0].method).toBe('DELETE')
156
- })
157
- })
158
-
159
- // ---------------------------------------------------------------------------
160
- describe('AuthAdminService.banUser', () => {
161
- it('sends POST /admin/users/{id}/ban and returns AuraResponse<null>', async () => {
162
- fetchMock.on({
163
- method: 'POST',
164
- url: `${ADMIN_PREFIX}/users/uid-42/ban`,
165
- replyCode: 200,
166
- replyBody: { data: null },
167
- })
168
-
169
- const res = await client.authAdmin.banUser('uid-42')
170
-
171
- expect(res.error).toBeNull()
172
- // LOT 3 (I5) : voir note deleteUser ci-dessus — `ban_user` backend renvoie aussi
173
- // `ApiResponse::<()>::empty()`, honnêtement `null` côté SDK désormais.
174
- expect(res.data).toBeNull()
175
- expect(fetchMock.calls[0].url).toContain('/ban')
176
- expect(fetchMock.calls[0].method).toBe('POST')
177
- expect(fetchMock.calls[0].body).toEqual({})
178
- })
179
- })
180
-
181
- // ---------------------------------------------------------------------------
182
- describe('AuthAdminService.unbanUser', () => {
183
- it('sends POST /admin/users/{id}/unban and returns AuraResponse<null>', async () => {
184
- fetchMock.on({
185
- method: 'POST',
186
- url: `${ADMIN_PREFIX}/users/uid-42/unban`,
187
- replyCode: 200,
188
- replyBody: { data: null },
189
- })
190
-
191
- const res = await client.authAdmin.unbanUser('uid-42')
192
-
193
- expect(res.error).toBeNull()
194
- // LOT 3 (I5) : voir note deleteUser ci-dessus.
195
- expect(res.data).toBeNull()
196
- expect(fetchMock.calls[0].url).toContain('/unban')
197
- expect(fetchMock.calls[0].body).toEqual({})
198
- })
199
- })
200
-
201
- // ---------------------------------------------------------------------------
202
- describe('AuthAdminService.generateLink', () => {
203
- it('accepts the magic type and returns { link, token } (no redirect_to sent)', async () => {
204
- fetchMock.on({
205
- method: 'POST',
206
- url: `${ADMIN_PREFIX}/users/uid-42/generate-link`,
207
- replyCode: 200,
208
- replyBody: { data: { link: 'https://example.com/verify?token=abc', token: 'abc' } },
209
- })
210
-
211
- const res = await client.authAdmin.generateLink('uid-42', 'magic')
212
-
213
- expect(res.error).toBeNull()
214
- expect(res.data).toEqual({ link: 'https://example.com/verify?token=abc', token: 'abc' })
215
- expect((fetchMock.calls[0].body as any).type).toBe('magic')
216
- expect((fetchMock.calls[0].body as any).redirect_to).toBeUndefined()
217
- })
218
-
219
- it('accepts the recovery and invite types', async () => {
220
- fetchMock.on({
221
- method: 'POST',
222
- url: `${ADMIN_PREFIX}/users/uid-42/generate-link`,
223
- replyCode: 200,
224
- replyBody: { data: { link: 'https://example.com/recover', token: 'tok' } },
225
- })
226
-
227
- const res = await client.authAdmin.generateLink('uid-42', 'recovery')
228
-
229
- expect(res.error).toBeNull()
230
- expect((fetchMock.calls[0].body as any).type).toBe('recovery')
231
- })
232
- })
233
-
234
- // ---------------------------------------------------------------------------
235
- describe('AuthAdminService.getAuditLog', () => {
236
- it('sends GET /admin/audit-log with pagination', async () => {
237
- fetchMock.on({
238
- method: 'GET',
239
- url: new RegExp(`${ADMIN_PREFIX}/audit-log`),
240
- replyCode: 200,
241
- replyBody: { data: [{ id: 'evt-1', action: 'login' }] },
242
- })
243
-
244
- const res = await client.authAdmin.getAuditLog({ limit: 20, offset: 0 })
245
-
246
- expect(res.error).toBeNull()
247
- expect(fetchMock.calls[0].url).toContain('limit=20')
248
- })
249
-
250
- it('sends GET /admin/audit-log with user_id filter', async () => {
251
- fetchMock.on({
252
- method: 'GET',
253
- url: new RegExp(`${ADMIN_PREFIX}/audit-log`),
254
- replyCode: 200,
255
- replyBody: { data: [{ id: 'evt-1', user_id: 'uid-42', action: 'login' }] },
256
- })
257
-
258
- const res = await client.authAdmin.getAuditLog({ userId: 'uid-42' })
259
-
260
- expect(res.error).toBeNull()
261
- expect(fetchMock.calls[0].url).toContain('user_id=uid-42')
262
- })
263
- })
264
-
265
- // ---------------------------------------------------------------------------
266
- describe('AuthAdminService.getUserStats', () => {
267
- it('sends GET /admin/users/stats and returns the stats envelope', async () => {
268
- fetchMock.on({
269
- method: 'GET',
270
- url: `${ADMIN_PREFIX}/users/stats`,
271
- replyCode: 200,
272
- replyBody: { data: { total: 10, verified: 8, banned: 1, mfa_enabled: 3, new_7d: 2 } },
273
- })
274
-
275
- const res = await client.authAdmin.getUserStats()
276
-
277
- expect(res.error).toBeNull()
278
- expect(fetchMock.calls[0].method).toBe('GET')
279
- expect(res.data).toEqual({ total: 10, verified: 8, banned: 1, mfa_enabled: 3, new_7d: 2 })
280
- })
281
- })
282
-
283
- // ---------------------------------------------------------------------------
284
- describe('AuthAdminService.listSessions', () => {
285
- it('sends GET /admin/sessions with limit/offset query params', async () => {
286
- fetchMock.on({
287
- method: 'GET',
288
- url: new RegExp(`${ADMIN_PREFIX}/sessions`),
289
- replyCode: 200,
290
- replyBody: { data: [{ id: 'sess-1', user_id: 'uid-42' }] },
291
- })
292
-
293
- const res = await client.authAdmin.listSessions({ limit: 10, offset: 5 })
294
-
295
- expect(res.error).toBeNull()
296
- expect(fetchMock.calls[0].method).toBe('GET')
297
- expect(fetchMock.calls[0].url).toContain('limit=10')
298
- expect(fetchMock.calls[0].url).toContain('offset=5')
299
- })
300
-
301
- it('sends GET /admin/sessions without query params', async () => {
302
- fetchMock.on({
303
- method: 'GET',
304
- url: `${ADMIN_PREFIX}/sessions`,
305
- replyCode: 200,
306
- replyBody: { data: [] },
307
- })
308
-
309
- const res = await client.authAdmin.listSessions()
310
-
311
- expect(res.error).toBeNull()
312
- expect(fetchMock.calls[0].url).toBe(`${ADMIN_PREFIX}/sessions`)
313
- })
314
- })
315
-
316
- // ---------------------------------------------------------------------------
317
- describe('AuthAdminService.revokeSession', () => {
318
- it('sends DELETE /admin/sessions/{id}', async () => {
319
- fetchMock.on({
320
- method: 'DELETE',
321
- url: `${ADMIN_PREFIX}/sessions/sess-1`,
322
- replyCode: 200,
323
- replyBody: { data: null },
324
- })
325
-
326
- const res = await client.authAdmin.revokeSession('sess-1')
327
-
328
- expect(res.error).toBeNull()
329
- // LOT 3 (I5) : `revoke_session_admin` renvoie `ApiResponse::<()>::empty()`.
330
- expect(res.data).toBeNull()
331
- expect(fetchMock.calls[0].method).toBe('DELETE')
332
- expect(fetchMock.calls[0].url).toBe(`${ADMIN_PREFIX}/sessions/sess-1`)
333
- })
334
- })
335
-
336
- // ---------------------------------------------------------------------------
337
- describe('AuthAdminService.listUserIdentities', () => {
338
- it('sends GET /admin/users/{id}/identities', async () => {
339
- fetchMock.on({
340
- method: 'GET',
341
- url: `${ADMIN_PREFIX}/users/uid-42/identities`,
342
- replyCode: 200,
343
- replyBody: {
344
- data: [
345
- {
346
- id: 'id-1',
347
- provider: 'google',
348
- provider_id: 'g-123',
349
- identity_data: {},
350
- auto_linked: false,
351
- created_at: '2025-01-01T00:00:00Z',
352
- },
353
- ],
354
- },
355
- })
356
-
357
- const res = await client.authAdmin.listUserIdentities('uid-42')
358
-
359
- expect(res.error).toBeNull()
360
- expect(fetchMock.calls[0].method).toBe('GET')
361
- expect(res.data).toHaveLength(1)
362
- expect((res.data as any)[0].provider).toBe('google')
363
- })
364
- })
365
-
366
- // ---------------------------------------------------------------------------
367
- describe('AuthAdminService.testEmailTemplate', () => {
368
- it('sends POST /admin/email-templates/{type}/test with { to_email }', async () => {
369
- fetchMock.on({
370
- method: 'POST',
371
- url: `${ADMIN_PREFIX}/email-templates/confirmation/test`,
372
- replyCode: 200,
373
- replyBody: { data: null },
374
- })
375
-
376
- const res = await client.authAdmin.testEmailTemplate('confirmation', {
377
- to_email: 'dest@example.com',
378
- })
379
-
380
- expect(res.error).toBeNull()
381
- // LOT 3 (I5) : `test_email_template` renvoie `ApiResponse::<()>::empty()`.
382
- expect(res.data).toBeNull()
383
- expect(fetchMock.calls[0].method).toBe('POST')
384
- expect(fetchMock.calls[0].url).toBe(`${ADMIN_PREFIX}/email-templates/confirmation/test`)
385
- expect(fetchMock.calls[0].body).toEqual({ to_email: 'dest@example.com' })
386
- })
387
- })
388
-
389
- // ---------------------------------------------------------------------------
390
- describe('AuthAdminService.updateUser (extended admin fields)', () => {
391
- it('passes mfa_enabled and revoke_sessions through in the PUT body', async () => {
392
- const user = fakeUser({ id: 'uid-42' })
393
- fetchMock.on({
394
- method: 'PUT',
395
- url: `${ADMIN_PREFIX}/users/uid-42`,
396
- replyCode: 200,
397
- replyBody: { data: user },
398
- })
399
-
400
- const res = await client.authAdmin.updateUser('uid-42', {
401
- mfa_enabled: false,
402
- revoke_sessions: true,
403
- })
404
-
405
- expect(res.error).toBeNull()
406
- expect(fetchMock.calls[0].method).toBe('PUT')
407
- expect(fetchMock.calls[0].body).toEqual({ mfa_enabled: false, revoke_sessions: true })
408
- })
409
- })
410
-
411
- // ---------------------------------------------------------------------------
412
- describe('AuthAdminService.getSettings', () => {
413
- it('sends GET /admin/settings', async () => {
414
- fetchMock.on({
415
- method: 'GET',
416
- url: `${ADMIN_PREFIX}/settings`,
417
- replyCode: 200,
418
- replyBody: { data: { email_confirmation_required: true } },
419
- })
420
-
421
- const res = await client.authAdmin.getSettings()
422
-
423
- expect(res.error).toBeNull()
424
- expect((res.data as any).email_confirmation_required).toBe(true)
425
- })
426
- })
427
-
428
- // ---------------------------------------------------------------------------
429
- describe('AuthAdminService.updateSettings', () => {
430
- it('sends PUT /admin/settings with body', async () => {
431
- fetchMock.on({
432
- method: 'PUT',
433
- url: `${ADMIN_PREFIX}/settings`,
434
- replyCode: 200,
435
- replyBody: { data: { email_confirmation_required: false } },
436
- })
437
-
438
- const res = await client.authAdmin.updateSettings({ email_confirmation_required: false } as any)
439
-
440
- expect(res.error).toBeNull()
441
- expect(fetchMock.calls[0].method).toBe('PUT')
442
- })
443
- })
444
-
445
- // ---------------------------------------------------------------------------
446
- describe('AuthAdminService.listEmailTemplates', () => {
447
- it('sends GET /admin/email-templates', async () => {
448
- fetchMock.on({
449
- method: 'GET',
450
- url: `${ADMIN_PREFIX}/email-templates`,
451
- replyCode: 200,
452
- replyBody: { data: [{ type: 'confirmation' }, { type: 'recovery' }] },
453
- })
454
-
455
- const res = await client.authAdmin.listEmailTemplates()
456
-
457
- expect(res.error).toBeNull()
458
- expect(res.data).toHaveLength(2)
459
- })
460
- })
461
-
462
- // ---------------------------------------------------------------------------
463
- describe('AuthAdminService.getEmailTemplate', () => {
464
- it('sends GET /admin/email-templates/{type}', async () => {
465
- fetchMock.on({
466
- method: 'GET',
467
- url: `${ADMIN_PREFIX}/email-templates/confirmation`,
468
- replyCode: 200,
469
- replyBody: { data: { type: 'confirmation', subject: 'Confirm' } },
470
- })
471
-
472
- const res = await client.authAdmin.getEmailTemplate('confirmation')
473
-
474
- expect(res.error).toBeNull()
475
- expect((res.data as any).type).toBe('confirmation')
476
- })
477
- })
478
-
479
- // ---------------------------------------------------------------------------
480
- describe('AuthAdminService.updateEmailTemplate', () => {
481
- it('sends PUT /admin/email-templates/{type} with { subject, html_body }', async () => {
482
- fetchMock.on({
483
- method: 'PUT',
484
- url: `${ADMIN_PREFIX}/email-templates/confirmation`,
485
- replyCode: 200,
486
- replyBody: { data: { type: 'confirmation', subject: 'S' } },
487
- })
488
-
489
- await client.authAdmin.updateEmailTemplate('confirmation', {
490
- subject: 'S',
491
- html_body: '<p>x</p>',
492
- })
493
-
494
- expect(fetchMock.calls[0].method).toBe('PUT')
495
- expect(fetchMock.calls[0].body).toEqual({ subject: 'S', html_body: '<p>x</p>' })
496
- expect((fetchMock.calls[0].body as any).body).toBeUndefined()
497
- })
498
- })
499
-
500
- // ---------------------------------------------------------------------------
501
- describe('AuthAdminService.deleteEmailTemplate', () => {
502
- it('sends DELETE /admin/email-templates/{type}', async () => {
503
- fetchMock.on({
504
- method: 'DELETE',
505
- url: `${ADMIN_PREFIX}/email-templates/confirmation`,
506
- replyCode: 200,
507
- replyBody: { data: { message: 'Reset to default' } },
508
- })
509
-
510
- const res = await client.authAdmin.deleteEmailTemplate('confirmation')
511
-
512
- expect(res.error).toBeNull()
513
- expect(fetchMock.calls[0].method).toBe('DELETE')
514
- })
515
- })