@aurabase/aurabase-js 0.3.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.
- package/.changeset/config.json +11 -0
- package/CHANGELOG.md +30 -0
- package/LICENSE +21 -0
- package/README.md +833 -0
- package/package.json +90 -0
- package/packages/ai/LICENSE +21 -0
- package/packages/ai/README.md +106 -0
- package/packages/ai/dist/index.cjs +229 -0
- package/packages/ai/dist/index.d.cts +139 -0
- package/packages/ai/dist/index.d.ts +139 -0
- package/packages/ai/dist/index.js +226 -0
- package/packages/ai/node_modules/.bin/esbuild +19 -0
- package/packages/ai/node_modules/.bin/tsc +22 -0
- package/packages/ai/node_modules/.bin/tsserver +22 -0
- package/packages/ai/node_modules/.bin/tsup +22 -0
- package/packages/ai/node_modules/.bin/tsup-node +22 -0
- package/packages/ai/node_modules/.bin/vite +22 -0
- package/packages/ai/node_modules/.bin/vitest +22 -0
- package/packages/ai/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +1 -0
- package/packages/ai/package.json +61 -0
- package/packages/ai/src/AiService.ts +226 -0
- package/packages/ai/src/index.ts +18 -0
- package/packages/ai/src/sse.ts +141 -0
- package/packages/ai/src/types.ts +30 -0
- package/packages/ai/tests/chat-stream.test.ts +151 -0
- package/packages/ai/tests/rag-namespaces.test.ts +54 -0
- package/packages/ai/tests/sse.test.ts +69 -0
- package/packages/ai/tsconfig.json +5 -0
- package/packages/ai/tsup.config.ts +11 -0
- package/packages/aurabase/LICENSE +21 -0
- package/packages/aurabase/README.md +64 -0
- package/packages/aurabase/dist/AuraClient-DAtDbfPB.d.cts +77 -0
- package/packages/aurabase/dist/AuraClient-DAtDbfPB.d.ts +77 -0
- package/packages/aurabase/dist/index.cjs +237 -0
- package/packages/aurabase/dist/index.d.cts +46 -0
- package/packages/aurabase/dist/index.d.ts +46 -0
- package/packages/aurabase/dist/index.js +177 -0
- package/packages/aurabase/dist/ssr.cjs +224 -0
- package/packages/aurabase/dist/ssr.d.cts +65 -0
- package/packages/aurabase/dist/ssr.d.ts +65 -0
- package/packages/aurabase/dist/ssr.js +214 -0
- package/packages/aurabase/node_modules/.bin/esbuild +19 -0
- package/packages/aurabase/node_modules/.bin/tsc +22 -0
- package/packages/aurabase/node_modules/.bin/tsserver +22 -0
- package/packages/aurabase/node_modules/.bin/tsup +22 -0
- package/packages/aurabase/node_modules/.bin/tsup-node +22 -0
- package/packages/aurabase/node_modules/.bin/vite +22 -0
- package/packages/aurabase/node_modules/.bin/vitest +22 -0
- package/packages/aurabase/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +1 -0
- package/packages/aurabase/package.json +80 -0
- package/packages/aurabase/src/AuraClient.ts +237 -0
- package/packages/aurabase/src/index.ts +152 -0
- package/packages/aurabase/src/ssr.ts +156 -0
- package/packages/aurabase/tests/ai-streaming-rag-e2e.test.ts +82 -0
- package/packages/aurabase/tests/ai.test.ts +111 -0
- package/packages/aurabase/tests/auth-admin.test.ts +515 -0
- package/packages/aurabase/tests/auth-e2e.test.ts +135 -0
- package/packages/aurabase/tests/auth-hardening.test.ts +206 -0
- package/packages/aurabase/tests/auth.test.ts +947 -0
- package/packages/aurabase/tests/database.test.ts +230 -0
- package/packages/aurabase/tests/db-types-e2e.test.ts +217 -0
- package/packages/aurabase/tests/dispose.test.ts +23 -0
- package/packages/aurabase/tests/foreign-token.e2e.test.ts +129 -0
- package/packages/aurabase/tests/functions.test.ts +107 -0
- package/packages/aurabase/tests/integration.test.ts +413 -0
- package/packages/aurabase/tests/live-production-validation.js +241 -0
- package/packages/aurabase/tests/live-sdk-production-validation.js +293 -0
- package/packages/aurabase/tests/mocks.ts +139 -0
- package/packages/aurabase/tests/notifications.test.ts +314 -0
- package/packages/aurabase/tests/observability-backup.test.ts +186 -0
- package/packages/aurabase/tests/observability-hook.test.ts +130 -0
- package/packages/aurabase/tests/production-robustness.test.ts +268 -0
- package/packages/aurabase/tests/public-api-surface.test.ts +53 -0
- package/packages/aurabase/tests/query-builder.test.ts +329 -0
- package/packages/aurabase/tests/readme-smoke-e2e.test.ts +231 -0
- package/packages/aurabase/tests/realtime-filter-e2e.test.ts +344 -0
- package/packages/aurabase/tests/refresh-locks.test.ts +210 -0
- package/packages/aurabase/tests/retry-option.test.ts +17 -0
- package/packages/aurabase/tests/rpc-e2e.test.ts +254 -0
- package/packages/aurabase/tests/rs256-local-e2e.test.ts +114 -0
- package/packages/aurabase/tests/rt-alias-public-e2e.test.ts +235 -0
- package/packages/aurabase/tests/rt-http-broadcast-e2e.test.ts +124 -0
- package/packages/aurabase/tests/service-role-guard.test.ts +99 -0
- package/packages/aurabase/tests/ssr.test.ts +91 -0
- package/packages/aurabase/tests/storage-backend-e2e.test.ts +481 -0
- package/packages/aurabase/tests/storage-sdk-parity-e2e.test.ts +104 -0
- package/packages/aurabase/tests/storage-transform-e2e.test.ts +684 -0
- package/packages/aurabase/tests/storage.test.ts +55 -0
- package/packages/aurabase/tests/types/client-generic.test-d.ts +79 -0
- package/packages/aurabase/tests/types/docs-snippets.test-d.ts +571 -0
- package/packages/aurabase/tests/types/error-code.test-d.ts +53 -0
- package/packages/aurabase/tsconfig.json +5 -0
- package/packages/aurabase/tsconfig.test-d.json +5 -0
- package/packages/aurabase/tsup.config.ts +11 -0
- package/packages/aurabase/vitest.config.ts +16 -0
- package/packages/aurabase/vitest.e2e.config.ts +9 -0
- package/packages/auth/LICENSE +21 -0
- package/packages/auth/README.md +215 -0
- package/packages/auth/dist/index.cjs +1175 -0
- package/packages/auth/dist/index.d.cts +397 -0
- package/packages/auth/dist/index.d.ts +397 -0
- package/packages/auth/dist/index.js +1170 -0
- package/packages/auth/node_modules/.bin/esbuild +19 -0
- package/packages/auth/node_modules/.bin/tsc +22 -0
- package/packages/auth/node_modules/.bin/tsserver +22 -0
- package/packages/auth/node_modules/.bin/tsup +22 -0
- package/packages/auth/node_modules/.bin/tsup-node +22 -0
- package/packages/auth/node_modules/.bin/vite +22 -0
- package/packages/auth/node_modules/.bin/vitest +22 -0
- package/packages/auth/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +1 -0
- package/packages/auth/package.json +61 -0
- package/packages/auth/src/AuthAdminService.ts +149 -0
- package/packages/auth/src/AuthService.ts +1166 -0
- package/packages/auth/src/SessionManager.ts +92 -0
- package/packages/auth/src/index.ts +17 -0
- package/packages/auth/src/jwks.ts +337 -0
- package/packages/auth/src/pkce.ts +27 -0
- package/packages/auth/src/types.ts +89 -0
- package/packages/auth/tests/auth-lifecycle.test.ts +149 -0
- package/packages/auth/tests/detect-session.test.ts +361 -0
- package/packages/auth/tests/getclaims.test.ts +780 -0
- package/packages/auth/tests/is-mfa-challenge.test.ts +27 -0
- package/packages/auth/tests/password-recovery.test.ts +124 -0
- package/packages/auth/tests/pkce.test.ts +192 -0
- package/packages/auth/tests/session-manager.test.ts +103 -0
- package/packages/auth/tests/set-session.test.ts +139 -0
- package/packages/auth/tests/verify-otp.test.ts +153 -0
- package/packages/auth/tsconfig.json +5 -0
- package/packages/auth/tsup.config.ts +11 -0
- package/packages/core/LICENSE +21 -0
- package/packages/core/README.md +132 -0
- package/packages/core/dist/index.cjs +695 -0
- package/packages/core/dist/index.d.cts +1137 -0
- package/packages/core/dist/index.d.ts +1137 -0
- package/packages/core/dist/index.js +673 -0
- package/packages/core/node_modules/.bin/esbuild +22 -0
- package/packages/core/node_modules/.bin/tsc +22 -0
- package/packages/core/node_modules/.bin/tsserver +22 -0
- package/packages/core/node_modules/.bin/tsup +22 -0
- package/packages/core/node_modules/.bin/tsup-node +22 -0
- package/packages/core/node_modules/.bin/vite +22 -0
- package/packages/core/node_modules/.bin/vitest +22 -0
- package/packages/core/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +1 -0
- package/packages/core/package.json +57 -0
- package/packages/core/src/AuraError.ts +89 -0
- package/packages/core/src/BaseService.ts +44 -0
- package/packages/core/src/client.ts +34 -0
- package/packages/core/src/cookie-utils.ts +42 -0
- package/packages/core/src/fetch.ts +435 -0
- package/packages/core/src/index.ts +22 -0
- package/packages/core/src/retry.ts +63 -0
- package/packages/core/src/serialize.ts +6 -0
- package/packages/core/src/stores/BaseAuthStore.ts +164 -0
- package/packages/core/src/stores/LocalAuthStore.ts +199 -0
- package/packages/core/src/types.ts +1042 -0
- package/packages/core/tests/auth-store.test.ts +300 -0
- package/packages/core/tests/error-code.test.ts +61 -0
- package/packages/core/tests/error.test.ts +24 -0
- package/packages/core/tests/fetch.test.ts +286 -0
- package/packages/core/tests/mocks.ts +139 -0
- package/packages/core/tests/observability.test.ts +86 -0
- package/packages/core/tests/refresh-hardening.test.ts +164 -0
- package/packages/core/tests/refresh-observability.test.ts +111 -0
- package/packages/core/tests/retry.test.ts +106 -0
- package/packages/core/tests/serialize.test.ts +12 -0
- package/packages/core/tests/timeout.test.ts +79 -0
- package/packages/core/tsconfig.json +5 -0
- package/packages/core/tsup.config.ts +11 -0
- package/packages/db/LICENSE +21 -0
- package/packages/db/README.md +152 -0
- package/packages/db/VENDORED.md +93 -0
- package/packages/db/dist/index.cjs +544 -0
- package/packages/db/dist/index.d.cts +1111 -0
- package/packages/db/dist/index.d.ts +1111 -0
- package/packages/db/dist/index.js +541 -0
- package/packages/db/node_modules/.bin/esbuild +19 -0
- package/packages/db/node_modules/.bin/tsc +22 -0
- package/packages/db/node_modules/.bin/tsserver +22 -0
- package/packages/db/node_modules/.bin/tsup +22 -0
- package/packages/db/node_modules/.bin/tsup-node +22 -0
- package/packages/db/node_modules/.bin/vite +22 -0
- package/packages/db/node_modules/.bin/vitest +22 -0
- package/packages/db/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +1 -0
- package/packages/db/package.json +62 -0
- package/packages/db/src/DatabaseService.ts +170 -0
- package/packages/db/src/QueryBuilder.ts +830 -0
- package/packages/db/src/index.ts +2 -0
- package/packages/db/src/pgrst-types/common/common.ts +86 -0
- package/packages/db/src/pgrst-types/common/rpc.ts +151 -0
- package/packages/db/src/pgrst-types/feature-flags.ts +20 -0
- package/packages/db/src/pgrst-types/types.ts +134 -0
- package/packages/db/src/select-query-parser/parser.ts +479 -0
- package/packages/db/src/select-query-parser/result.ts +553 -0
- package/packages/db/src/select-query-parser/types.ts +132 -0
- package/packages/db/src/select-query-parser/utils.ts +707 -0
- package/packages/db/tests/filters.test.ts +81 -0
- package/packages/db/tests/mutations-filtered.e2e.test.ts +132 -0
- package/packages/db/tests/mutations-filtered.test.ts +188 -0
- package/packages/db/tests/order.test.ts +45 -0
- package/packages/db/tests/rpc.test.ts +41 -0
- package/packages/db/tests/scale/build-large-schema.ts +94 -0
- package/packages/db/tests/scale/scale-compile.test.ts +167 -0
- package/packages/db/tests/schema.test.ts +77 -0
- package/packages/db/tests/single-accept.e2e.test.ts +123 -0
- package/packages/db/tests/single.test.ts +211 -0
- package/packages/db/tests/types/filters.test-d.ts +52 -0
- package/packages/db/tests/types/fixtures.ts +40 -0
- package/packages/db/tests/types/from-views.test-d.ts +18 -0
- package/packages/db/tests/types/mutations.test-d.ts +23 -0
- package/packages/db/tests/types/rpc.test-d.ts +60 -0
- package/packages/db/tests/types/schema-shape.test-d.ts +8 -0
- package/packages/db/tests/types/select-inference.test-d.ts +38 -0
- package/packages/db/tests/vendored/fixtures.ts +83 -0
- package/packages/db/tests/vendored/get-result.test-d.ts +75 -0
- package/packages/db/tsconfig.json +5 -0
- package/packages/db/tsconfig.test-d.json +5 -0
- package/packages/db/tsup.config.ts +11 -0
- package/packages/db/vitest.config.ts +8 -0
- package/packages/functions/LICENSE +21 -0
- package/packages/functions/README.md +96 -0
- package/packages/functions/dist/index.cjs +173 -0
- package/packages/functions/dist/index.d.cts +81 -0
- package/packages/functions/dist/index.d.ts +81 -0
- package/packages/functions/dist/index.js +168 -0
- package/packages/functions/node_modules/.bin/esbuild +19 -0
- package/packages/functions/node_modules/.bin/tsc +22 -0
- package/packages/functions/node_modules/.bin/tsserver +22 -0
- package/packages/functions/node_modules/.bin/tsup +22 -0
- package/packages/functions/node_modules/.bin/tsup-node +22 -0
- package/packages/functions/node_modules/.bin/vite +22 -0
- package/packages/functions/node_modules/.bin/vitest +22 -0
- package/packages/functions/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +1 -0
- package/packages/functions/package.json +60 -0
- package/packages/functions/src/FunctionsService.ts +188 -0
- package/packages/functions/src/errors.ts +70 -0
- package/packages/functions/src/index.ts +6 -0
- package/packages/functions/tests/invoke.test.ts +97 -0
- package/packages/functions/tests/response-type-errors.test.ts +135 -0
- package/packages/functions/tsconfig.json +5 -0
- package/packages/functions/tsup.config.ts +11 -0
- package/packages/gen/LICENSE +21 -0
- package/packages/gen/README.md +84 -0
- package/packages/gen/dist/cli.cjs +334 -0
- package/packages/gen/dist/cli.d.cts +1 -0
- package/packages/gen/dist/cli.d.ts +1 -0
- package/packages/gen/dist/cli.js +332 -0
- package/packages/gen/dist/index.cjs +257 -0
- package/packages/gen/dist/index.d.cts +12 -0
- package/packages/gen/dist/index.d.ts +12 -0
- package/packages/gen/dist/index.js +255 -0
- package/packages/gen/node_modules/.bin/esbuild +19 -0
- package/packages/gen/node_modules/.bin/tsc +22 -0
- package/packages/gen/node_modules/.bin/tsserver +22 -0
- package/packages/gen/node_modules/.bin/tsup +22 -0
- package/packages/gen/node_modules/.bin/tsup-node +22 -0
- package/packages/gen/node_modules/.bin/vite +22 -0
- package/packages/gen/node_modules/.bin/vitest +22 -0
- package/packages/gen/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +1 -0
- package/packages/gen/package.json +66 -0
- package/packages/gen/src/cli.ts +67 -0
- package/packages/gen/src/generate.ts +0 -0
- package/packages/gen/src/index.ts +2 -0
- package/packages/gen/tests/compile.test.ts +213 -0
- package/packages/gen/tests/e2e.test.ts +130 -0
- package/packages/gen/tests/generate.test.ts +396 -0
- package/packages/gen/tsconfig.json +5 -0
- package/packages/gen/tsup.config.ts +11 -0
- package/packages/notifications/LICENSE +21 -0
- package/packages/notifications/README.md +134 -0
- package/packages/notifications/dist/index.cjs +128 -0
- package/packages/notifications/dist/index.d.cts +81 -0
- package/packages/notifications/dist/index.d.ts +81 -0
- package/packages/notifications/dist/index.js +125 -0
- package/packages/notifications/node_modules/.bin/esbuild +19 -0
- package/packages/notifications/node_modules/.bin/tsc +22 -0
- package/packages/notifications/node_modules/.bin/tsserver +22 -0
- package/packages/notifications/node_modules/.bin/tsup +22 -0
- package/packages/notifications/node_modules/.bin/tsup-node +22 -0
- package/packages/notifications/node_modules/.bin/vite +22 -0
- package/packages/notifications/node_modules/.bin/vitest +22 -0
- package/packages/notifications/package.json +60 -0
- package/packages/notifications/src/NotificationsService.ts +230 -0
- package/packages/notifications/src/index.ts +19 -0
- package/packages/notifications/tsconfig.json +5 -0
- package/packages/notifications/tsup.config.ts +11 -0
- package/packages/realtime/LICENSE +21 -0
- package/packages/realtime/README.md +183 -0
- package/packages/realtime/dist/index.cjs +977 -0
- package/packages/realtime/dist/index.d.cts +259 -0
- package/packages/realtime/dist/index.d.ts +259 -0
- package/packages/realtime/dist/index.js +973 -0
- package/packages/realtime/node_modules/.bin/esbuild +19 -0
- package/packages/realtime/node_modules/.bin/tsc +22 -0
- package/packages/realtime/node_modules/.bin/tsserver +22 -0
- package/packages/realtime/node_modules/.bin/tsup +22 -0
- package/packages/realtime/node_modules/.bin/tsup-node +22 -0
- package/packages/realtime/node_modules/.bin/vite +22 -0
- package/packages/realtime/node_modules/.bin/vitest +22 -0
- package/packages/realtime/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +1 -0
- package/packages/realtime/package.json +60 -0
- package/packages/realtime/src/AuraChannel.ts +485 -0
- package/packages/realtime/src/HeartbeatManager.ts +73 -0
- package/packages/realtime/src/RealtimeService.ts +505 -0
- package/packages/realtime/src/columnFilter.ts +301 -0
- package/packages/realtime/src/index.ts +4 -0
- package/packages/realtime/tests/ack-routing.test.ts +81 -0
- package/packages/realtime/tests/column-filter.test.ts +144 -0
- package/packages/realtime/tests/dispatch.test.ts +191 -0
- package/packages/realtime/tests/heartbeat.test.ts +67 -0
- package/packages/realtime/tests/http-broadcast.test.ts +68 -0
- package/packages/realtime/tests/realtime-token.test.ts +43 -0
- package/packages/realtime/tests/reconnect-race.test.ts +149 -0
- package/packages/realtime/tests/ref-id.test.ts +34 -0
- package/packages/realtime/tests/set-auth.test.ts +70 -0
- package/packages/realtime/tsconfig.json +5 -0
- package/packages/realtime/tsup.config.ts +11 -0
- package/packages/storage/LICENSE +21 -0
- package/packages/storage/README.md +141 -0
- package/packages/storage/dist/index.cjs +333 -0
- package/packages/storage/dist/index.d.cts +185 -0
- package/packages/storage/dist/index.d.ts +185 -0
- package/packages/storage/dist/index.js +329 -0
- package/packages/storage/node_modules/.bin/esbuild +19 -0
- package/packages/storage/node_modules/.bin/tsc +22 -0
- package/packages/storage/node_modules/.bin/tsserver +22 -0
- package/packages/storage/node_modules/.bin/tsup +22 -0
- package/packages/storage/node_modules/.bin/tsup-node +22 -0
- package/packages/storage/node_modules/.bin/vite +22 -0
- package/packages/storage/node_modules/.bin/vitest +22 -0
- package/packages/storage/node_modules/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +1 -0
- package/packages/storage/package.json +60 -0
- package/packages/storage/src/DownloadBuilder.ts +60 -0
- package/packages/storage/src/StorageService.ts +323 -0
- package/packages/storage/src/index.ts +2 -0
- package/packages/storage/src/path.ts +35 -0
- package/packages/storage/src/transform.ts +15 -0
- package/packages/storage/tests/download.test.ts +64 -0
- package/packages/storage/tests/parity.test.ts +154 -0
- package/packages/storage/tests/path.test.ts +87 -0
- package/packages/storage/tests/transform.test.ts +79 -0
- package/packages/storage/tsconfig.json +5 -0
- package/packages/storage/tsup.config.ts +11 -0
- package/pnpm-workspace.yaml +24 -0
- package/tsconfig.base.json +15 -0
|
@@ -0,0 +1,111 @@
|
|
|
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
|
+
})
|
|
@@ -0,0 +1,515 @@
|
|
|
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
|
+
})
|