@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,153 +0,0 @@
1
- import { describe, it, expect, afterEach, vi } from 'vitest'
2
- import { AuthService } from '../src/AuthService'
3
- import { BaseAuthStore } from '@aurabase/core'
4
- import type { AuraClientLike, TokenPair, User, AuthEvent } from '@aurabase/core'
5
-
6
- function fakeUser(id = 'u1'): User {
7
- return { id, email: 't@e.com', phone: null, role: 'authenticated', email_verified: true, is_banned: false, is_anonymous: false, mfa_enabled: false, user_metadata: {}, app_metadata: {}, created_at: '2025-01-01T00:00:00Z' }
8
- }
9
- function tokenPair(): TokenPair {
10
- return { access_token: 'AT', refresh_token: 'RT', token_type: 'bearer', expires_in: 3600, user: fakeUser() }
11
- }
12
-
13
- afterEach(() => { vi.restoreAllMocks() })
14
-
15
- function make() {
16
- const seen: Array<{ url: string; method: string; body: unknown }> = []
17
- const responders: Record<string, (body: unknown) => Response> = {}
18
- const client: AuraClientLike = {
19
- baseUrl: 'http://x', projectId: 'p', apiKey: 'k', authStore: new BaseAuthStore(),
20
- fetchFn: (async (url: string, init: RequestInit) => {
21
- const u = String(url)
22
- let body: unknown = undefined
23
- try { body = init.body ? JSON.parse(String(init.body)) : undefined } catch { /* FormData etc. */ }
24
- seen.push({ url: u, method: String(init.method), body })
25
- const key = Object.keys(responders).find((k) => u.includes(k))
26
- if (key) return responders[key]!(body)
27
- return new Response(JSON.stringify({ data: tokenPair() }), { status: 200, headers: { 'Content-Type': 'application/json' } })
28
- }) as unknown as typeof globalThis.fetch,
29
- auth: null as unknown as AuraClientLike['auth'],
30
- }
31
- const svc = new AuthService(client, { autoRefresh: false, persistSession: false })
32
- ;(client as { auth: unknown }).auth = svc
33
- const events: AuthEvent[] = []
34
- svc.onAuthStateChange((p) => events.push(p.event))
35
- return { svc, client, seen, responders, events }
36
- }
37
- const okUser = () => new Response(JSON.stringify({ data: fakeUser() }), { status: 200, headers: { 'Content-Type': 'application/json' } })
38
-
39
- describe('auth.verifyOtp — façade unifiée', () => {
40
- it('signup → POST /verify-email {token}, save session + SIGNED_IN', async () => {
41
- const { svc, seen, client, events } = make()
42
- const { data } = await svc.verifyOtp({ type: 'signup', token: 'TK' })
43
- expect((data as TokenPair).access_token).toBe('AT')
44
- const c = seen.find((s) => s.url.includes('/verify-email'))!
45
- expect(c.method).toBe('POST')
46
- expect(c.body).toEqual({ token: 'TK' })
47
- expect(client.authStore.token).toBe('AT')
48
- expect(events).toContain('SIGNED_IN')
49
- })
50
-
51
- it('magiclink → POST /magic-link/verify {token}', async () => {
52
- const { svc, seen } = make()
53
- await svc.verifyOtp({ type: 'magiclink', token: 'ML' })
54
- const c = seen.find((s) => s.url.includes('/magic-link/verify'))!
55
- expect(c.body).toEqual({ token: 'ML' })
56
- })
57
-
58
- it('email → POST /email-otp/verify {email, code}', async () => {
59
- const { svc, seen } = make()
60
- await svc.verifyOtp({ type: 'email', email: 'a@b.c', token: '123456' })
61
- const c = seen.find((s) => s.url.includes('/email-otp/verify'))!
62
- expect(c.body).toEqual({ email: 'a@b.c', code: '123456' })
63
- })
64
-
65
- it('sms → POST /sms/verify {phone, code}', async () => {
66
- const { svc, seen } = make()
67
- await svc.verifyOtp({ type: 'sms', phone: '+33600', token: '999' })
68
- const c = seen.find((s) => s.url.includes('/sms/verify'))!
69
- expect(c.body).toEqual({ phone: '+33600', code: '999' })
70
- })
71
-
72
- it('recovery → POST /reset-password {token, password}, SIGNED_IN', async () => {
73
- const { svc, seen, events } = make()
74
- await svc.verifyOtp({ type: 'recovery', token: 'RCV', password: 'newpass' })
75
- const c = seen.find((s) => s.url.includes('/reset-password'))!
76
- expect(c.body).toEqual({ token: 'RCV', password: 'newpass' })
77
- expect(events).toContain('SIGNED_IN')
78
- })
79
-
80
- it('email_change → POST /user/confirm-email-change {token}, émet USER_UPDATED', async () => {
81
- const { svc, seen, responders, events } = make()
82
- responders['/user/confirm-email-change'] = okUser
83
- const { data } = await svc.verifyOtp({ type: 'email_change', token: 'EC' })
84
- expect((data as User).id).toBe('u1')
85
- const c = seen.find((s) => s.url.includes('/user/confirm-email-change'))!
86
- expect(c.body).toEqual({ token: 'EC' })
87
- expect(events).toContain('USER_UPDATED')
88
- expect(events).not.toContain('SIGNED_IN')
89
- })
90
-
91
- it('recovery sans password → missing_password SANS appel réseau', async () => {
92
- const { svc, seen } = make()
93
- // Cast : on simule un appelant JS qui omet le password (le type l'exige).
94
- const { error } = await svc.verifyOtp({ type: 'recovery', token: 'RCV' } as unknown as { type: 'recovery'; token: string; password: string })
95
- expect(error?.code).toBe('missing_password')
96
- expect(seen.length).toBe(0)
97
- })
98
-
99
- it('invite → otp_type_unsupported SANS appel réseau', async () => {
100
- const { svc, seen } = make()
101
- const { error } = await svc.verifyOtp({ type: 'invite', token: 'X' })
102
- expect(error?.code).toBe('otp_type_unsupported')
103
- expect(seen.length).toBe(0)
104
- })
105
-
106
- it('phone_change → otp_type_unsupported SANS appel réseau', async () => {
107
- const { svc, seen } = make()
108
- const { error } = await svc.verifyOtp({ type: 'phone_change', phone: '+1', token: 'X' })
109
- expect(error?.code).toBe('otp_type_unsupported')
110
- expect(seen.length).toBe(0)
111
- })
112
- })
113
-
114
- describe('auth — rétrocompat des méthodes historiques (délégation à verifyOtp)', () => {
115
- it('verifyEmail(token) → POST /verify-email {token} (inchangé)', async () => {
116
- const { svc, seen } = make()
117
- await svc.verifyEmail('TK')
118
- const c = seen.find((s) => s.url.includes('/verify-email'))!
119
- expect(c.method).toBe('POST')
120
- expect(c.body).toEqual({ token: 'TK' })
121
- })
122
- it('verifyEmailOtp(email, code) → POST /email-otp/verify {email, code}', async () => {
123
- const { svc, seen } = make()
124
- await svc.verifyEmailOtp('a@b.c', '111')
125
- const c = seen.find((s) => s.url.includes('/email-otp/verify'))!
126
- expect(c.body).toEqual({ email: 'a@b.c', code: '111' })
127
- })
128
- it('verifySmsOtp(phone, code) → POST /sms/verify {phone, code}', async () => {
129
- const { svc, seen } = make()
130
- await svc.verifySmsOtp('+33', '222')
131
- const c = seen.find((s) => s.url.includes('/sms/verify'))!
132
- expect(c.body).toEqual({ phone: '+33', code: '222' })
133
- })
134
- it('verifyMagicLink(token) → POST /magic-link/verify {token}', async () => {
135
- const { svc, seen } = make()
136
- await svc.verifyMagicLink('ML')
137
- const c = seen.find((s) => s.url.includes('/magic-link/verify'))!
138
- expect(c.body).toEqual({ token: 'ML' })
139
- })
140
- it('resetPassword(token, pass) → POST /reset-password {token, password}', async () => {
141
- const { svc, seen } = make()
142
- await svc.resetPassword('RCV', 'np')
143
- const c = seen.find((s) => s.url.includes('/reset-password'))!
144
- expect(c.body).toEqual({ token: 'RCV', password: 'np' })
145
- })
146
- it('confirmEmailChange(token) → POST /user/confirm-email-change {token}', async () => {
147
- const { svc, seen, responders } = make()
148
- responders['/user/confirm-email-change'] = okUser
149
- await svc.confirmEmailChange('EC')
150
- const c = seen.find((s) => s.url.includes('/user/confirm-email-change'))!
151
- expect(c.body).toEqual({ token: 'EC' })
152
- })
153
- })
@@ -1,5 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": { "outDir": "dist", "rootDir": "src" },
4
- "include": ["src"]
5
- }
@@ -1,11 +0,0 @@
1
- import { defineConfig } from 'tsup'
2
-
3
- export default defineConfig({
4
- entry: ['src/index.ts'],
5
- format: ['cjs', 'esm'],
6
- dts: true,
7
- splitting: false,
8
- clean: true,
9
- treeshake: true,
10
- minify: false,
11
- })
@@ -1,22 +0,0 @@
1
- #!/bin/sh
2
- basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3
-
4
- case `uname` in
5
- *CYGWIN*|*MINGW*|*MSYS*)
6
- if command -v cygpath > /dev/null 2>&1; then
7
- basedir=`cygpath -w "$basedir"`
8
- fi
9
- ;;
10
- esac
11
-
12
- if [ -z "$NODE_PATH" ]; then
13
- export NODE_PATH="/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/esbuild@0.27.7/node_modules/esbuild/node_modules:/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/esbuild@0.27.7/node_modules:/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/node_modules"
14
- else
15
- export NODE_PATH="/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/esbuild@0.27.7/node_modules/esbuild/node_modules:/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/esbuild@0.27.7/node_modules:/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/node_modules:$NODE_PATH"
16
- fi
17
- if [ -x "$basedir/node" ]; then
18
- exec "$basedir/node" "$basedir/../../../../node_modules/.pnpm/esbuild@0.27.7/node_modules/esbuild/bin/esbuild" "$@"
19
- else
20
- exec node "$basedir/../../../../node_modules/.pnpm/esbuild@0.27.7/node_modules/esbuild/bin/esbuild" "$@"
21
- fi
22
- # cmd-shim-target=/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/esbuild@0.27.7/node_modules/esbuild/bin/esbuild
@@ -1,22 +0,0 @@
1
- #!/bin/sh
2
- basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3
-
4
- case `uname` in
5
- *CYGWIN*|*MINGW*|*MSYS*)
6
- if command -v cygpath > /dev/null 2>&1; then
7
- basedir=`cygpath -w "$basedir"`
8
- fi
9
- ;;
10
- esac
11
-
12
- if [ -z "$NODE_PATH" ]; then
13
- export NODE_PATH="/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/node_modules:/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/typescript@5.9.3/node_modules:/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/node_modules"
14
- else
15
- export NODE_PATH="/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/node_modules:/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/typescript@5.9.3/node_modules:/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/node_modules:$NODE_PATH"
16
- fi
17
- if [ -x "$basedir/node" ]; then
18
- exec "$basedir/node" "$basedir/../typescript/bin/tsc" "$@"
19
- else
20
- exec node "$basedir/../typescript/bin/tsc" "$@"
21
- fi
22
- # cmd-shim-target=/Users/affanedaylami/aurabase/aurabase-js/packages/core/node_modules/typescript/bin/tsc
@@ -1,22 +0,0 @@
1
- #!/bin/sh
2
- basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3
-
4
- case `uname` in
5
- *CYGWIN*|*MINGW*|*MSYS*)
6
- if command -v cygpath > /dev/null 2>&1; then
7
- basedir=`cygpath -w "$basedir"`
8
- fi
9
- ;;
10
- esac
11
-
12
- if [ -z "$NODE_PATH" ]; then
13
- export NODE_PATH="/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/node_modules:/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/typescript@5.9.3/node_modules:/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/node_modules"
14
- else
15
- export NODE_PATH="/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/typescript@5.9.3/node_modules/typescript/node_modules:/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/typescript@5.9.3/node_modules:/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/node_modules:$NODE_PATH"
16
- fi
17
- if [ -x "$basedir/node" ]; then
18
- exec "$basedir/node" "$basedir/../typescript/bin/tsserver" "$@"
19
- else
20
- exec node "$basedir/../typescript/bin/tsserver" "$@"
21
- fi
22
- # cmd-shim-target=/Users/affanedaylami/aurabase/aurabase-js/packages/core/node_modules/typescript/bin/tsserver
@@ -1,22 +0,0 @@
1
- #!/bin/sh
2
- basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3
-
4
- case `uname` in
5
- *CYGWIN*|*MINGW*|*MSYS*)
6
- if command -v cygpath > /dev/null 2>&1; then
7
- basedir=`cygpath -w "$basedir"`
8
- fi
9
- ;;
10
- esac
11
-
12
- if [ -z "$NODE_PATH" ]; then
13
- export NODE_PATH="/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/tsup@8.5.1_postcss@8.5.16_typescript@5.9.3/node_modules/tsup/node_modules:/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/tsup@8.5.1_postcss@8.5.16_typescript@5.9.3/node_modules:/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/node_modules"
14
- else
15
- export NODE_PATH="/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/tsup@8.5.1_postcss@8.5.16_typescript@5.9.3/node_modules/tsup/node_modules:/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/tsup@8.5.1_postcss@8.5.16_typescript@5.9.3/node_modules:/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/node_modules:$NODE_PATH"
16
- fi
17
- if [ -x "$basedir/node" ]; then
18
- exec "$basedir/node" "$basedir/../tsup/dist/cli-default.js" "$@"
19
- else
20
- exec node "$basedir/../tsup/dist/cli-default.js" "$@"
21
- fi
22
- # cmd-shim-target=/Users/affanedaylami/aurabase/aurabase-js/packages/core/node_modules/tsup/dist/cli-default.js
@@ -1,22 +0,0 @@
1
- #!/bin/sh
2
- basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3
-
4
- case `uname` in
5
- *CYGWIN*|*MINGW*|*MSYS*)
6
- if command -v cygpath > /dev/null 2>&1; then
7
- basedir=`cygpath -w "$basedir"`
8
- fi
9
- ;;
10
- esac
11
-
12
- if [ -z "$NODE_PATH" ]; then
13
- export NODE_PATH="/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/tsup@8.5.1_postcss@8.5.16_typescript@5.9.3/node_modules/tsup/node_modules:/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/tsup@8.5.1_postcss@8.5.16_typescript@5.9.3/node_modules:/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/node_modules"
14
- else
15
- export NODE_PATH="/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/tsup@8.5.1_postcss@8.5.16_typescript@5.9.3/node_modules/tsup/node_modules:/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/tsup@8.5.1_postcss@8.5.16_typescript@5.9.3/node_modules:/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/node_modules:$NODE_PATH"
16
- fi
17
- if [ -x "$basedir/node" ]; then
18
- exec "$basedir/node" "$basedir/../tsup/dist/cli-node.js" "$@"
19
- else
20
- exec node "$basedir/../tsup/dist/cli-node.js" "$@"
21
- fi
22
- # cmd-shim-target=/Users/affanedaylami/aurabase/aurabase-js/packages/core/node_modules/tsup/dist/cli-node.js
@@ -1,22 +0,0 @@
1
- #!/bin/sh
2
- basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3
-
4
- case `uname` in
5
- *CYGWIN*|*MINGW*|*MSYS*)
6
- if command -v cygpath > /dev/null 2>&1; then
7
- basedir=`cygpath -w "$basedir"`
8
- fi
9
- ;;
10
- esac
11
-
12
- if [ -z "$NODE_PATH" ]; then
13
- export NODE_PATH="/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/vite@8.1.3_@types+node@20.14.15_esbuild@0.27.7/node_modules/vite/node_modules:/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/vite@8.1.3_@types+node@20.14.15_esbuild@0.27.7/node_modules:/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/node_modules"
14
- else
15
- export NODE_PATH="/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/vite@8.1.3_@types+node@20.14.15_esbuild@0.27.7/node_modules/vite/node_modules:/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/vite@8.1.3_@types+node@20.14.15_esbuild@0.27.7/node_modules:/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/node_modules:$NODE_PATH"
16
- fi
17
- if [ -x "$basedir/node" ]; then
18
- exec "$basedir/node" "$basedir/../../../../node_modules/.pnpm/vite@8.1.3_@types+node@20.14.15_esbuild@0.27.7/node_modules/vite/bin/vite.js" "$@"
19
- else
20
- exec node "$basedir/../../../../node_modules/.pnpm/vite@8.1.3_@types+node@20.14.15_esbuild@0.27.7/node_modules/vite/bin/vite.js" "$@"
21
- fi
22
- # cmd-shim-target=/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/vite@8.1.3_@types+node@20.14.15_esbuild@0.27.7/node_modules/vite/bin/vite.js
@@ -1,22 +0,0 @@
1
- #!/bin/sh
2
- basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3
-
4
- case `uname` in
5
- *CYGWIN*|*MINGW*|*MSYS*)
6
- if command -v cygpath > /dev/null 2>&1; then
7
- basedir=`cygpath -w "$basedir"`
8
- fi
9
- ;;
10
- esac
11
-
12
- if [ -z "$NODE_PATH" ]; then
13
- export NODE_PATH="/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/vitest@4.1.9_@types+node@20.14.15_vite@8.1.3_@types+node@20.14.15_esbuild@0.27.7_/node_modules/vitest/node_modules:/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/vitest@4.1.9_@types+node@20.14.15_vite@8.1.3_@types+node@20.14.15_esbuild@0.27.7_/node_modules:/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/node_modules"
14
- else
15
- export NODE_PATH="/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/vitest@4.1.9_@types+node@20.14.15_vite@8.1.3_@types+node@20.14.15_esbuild@0.27.7_/node_modules/vitest/node_modules:/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/vitest@4.1.9_@types+node@20.14.15_vite@8.1.3_@types+node@20.14.15_esbuild@0.27.7_/node_modules:/Users/affanedaylami/aurabase/aurabase-js/node_modules/.pnpm/node_modules:$NODE_PATH"
16
- fi
17
- if [ -x "$basedir/node" ]; then
18
- exec "$basedir/node" "$basedir/../vitest/vitest.mjs" "$@"
19
- else
20
- exec node "$basedir/../vitest/vitest.mjs" "$@"
21
- fi
22
- # cmd-shim-target=/Users/affanedaylami/aurabase/aurabase-js/packages/core/node_modules/vitest/vitest.mjs
@@ -1 +0,0 @@
1
- {"version":"4.1.9","results":[[":tests/auth-store.test.ts",{"duration":29.471584000000348,"failed":false}],[":tests/retry.test.ts",{"duration":187.4342919999999,"failed":false}],[":tests/serialize.test.ts",{"duration":6.90783300000021,"failed":false}],[":tests/error.test.ts",{"duration":120.81179199999951,"failed":false}],[":tests/fetch.test.ts",{"duration":966.9932919999997,"failed":false}],[":tests/refresh-hardening.test.ts",{"duration":641.2061669999998,"failed":false}],[":tests/timeout.test.ts",{"duration":815.5460000000003,"failed":false}],[":tests/observability.test.ts",{"duration":25.504042000000027,"failed":false}],[":tests/refresh-observability.test.ts",{"duration":647.6677500000001,"failed":false}],[":tests/error-code.test.ts",{"duration":421.46225000000004,"failed":false}]]}
@@ -1,89 +0,0 @@
1
- /**
2
- * Codes d'erreur produits par le SDK (LOT 3, finding I4 : taxonomie ad hoc non
3
- * typée). Union fermée de tous les codes émis SDK-side (`grep new AuraError` sur
4
- * `packages/*\/src`) + les codes backend usuels rencontrés (`PGRST116`), plus
5
- * `(string & {})` pour rester ouvert à tout code backend arbitraire (`error.error.code`)
6
- * sans perdre l'autocomplétion sur les codes connus (pattern "LiteralUnion").
7
- *
8
- * Provenance des codes SDK-side :
9
- * - fetch.ts (core) : no_session, network_error, invalid_response, refresh_discarded, timeout
10
- * - AuthService.ts : no_session, pkce_generation_failed, no_code_verifier, missing_email,
11
- * unverifiable_token, invalid_issuer, invalid_audience
12
- * - jwks.ts : jwks_fetch_failed, no_matching_key, signature_invalid, token_expired,
13
- * token_not_yet_valid, invalid_jwt, unsupported_alg
14
- * - storage/path.ts : invalid_path
15
- * - db/QueryBuilder.ts: PGRST116 (parité PostgREST : `.single()` sur 0/plusieurs lignes)
16
- */
17
- export type AuraErrorCode =
18
- | 'no_session'
19
- | 'timeout'
20
- | 'network_error'
21
- | 'invalid_response'
22
- | 'refresh_discarded'
23
- | 'unverifiable_token'
24
- | 'no_code_verifier'
25
- | 'pkce_generation_failed'
26
- | 'missing_email'
27
- | 'jwks_fetch_failed'
28
- | 'signature_invalid'
29
- | 'token_expired'
30
- | 'token_not_yet_valid'
31
- | 'invalid_jwt'
32
- | 'unsupported_alg'
33
- | 'no_matching_key'
34
- | 'invalid_issuer'
35
- | 'invalid_audience'
36
- | 'invalid_path'
37
- | 'PGRST116'
38
- // eslint-disable-next-line @typescript-eslint/ban-types -- pattern LiteralUnion (type-fest) : garde l'autocomplétion tout en acceptant tout code backend.
39
- | (string & {})
40
-
41
- /**
42
- * Structured error thrown/returned by the Aurabase SDK.
43
- * Mirrors the backend's `AuraError` JSON shape.
44
- */
45
- export class AuraError extends Error {
46
- readonly status: number
47
- readonly code: AuraErrorCode
48
- readonly details: unknown
49
- /** Marqueur runtime pour `isAuraError` (détection cross-realm/cross-bundle). */
50
- protected readonly __isAuraError = true
51
-
52
- constructor(
53
- status: number,
54
- body?: { error?: { code?: string; message?: string }; message?: string } | null,
55
- ) {
56
- const message = body?.error?.message ?? body?.message ?? `HTTP ${status}`
57
- super(message)
58
- this.name = 'AuraError'
59
- this.status = status
60
- this.code = body?.error?.code ?? `http_${status}`
61
- this.details = body
62
- Object.setPrototypeOf(this, AuraError.prototype)
63
- }
64
-
65
- get isNotFound(): boolean {
66
- return this.status === 404
67
- }
68
-
69
- get isUnauthorized(): boolean {
70
- return this.status === 401
71
- }
72
-
73
- get isForbidden(): boolean {
74
- return this.status === 403
75
- }
76
-
77
- get isRateLimited(): boolean {
78
- return this.status === 429
79
- }
80
- }
81
-
82
- export function isAuraError(error: unknown): error is AuraError {
83
- return (
84
- error instanceof AuraError ||
85
- (typeof error === 'object' &&
86
- error !== null &&
87
- (error as Record<string, unknown>).__isAuraError === true)
88
- )
89
- }
@@ -1,44 +0,0 @@
1
- import type { AuraClientLike } from './client'
2
- import type { AuraResponse } from './types'
3
- import { fetchWithAuth, type FetchInit } from './fetch'
4
-
5
- /**
6
- * Abstract base class for all service modules.
7
- * Provides the shared HTTP helper and URL builder.
8
- */
9
- export abstract class BaseService {
10
- protected readonly client: AuraClientLike
11
-
12
- constructor(client: AuraClientLike) {
13
- this.client = client
14
- }
15
-
16
- /** Build a full URL for the given path. */
17
- protected url(path: string): string {
18
- return `${this.client.baseUrl}${path}`
19
- }
20
-
21
- /** Convenience HTTP helper that delegates to fetchWithAuth. */
22
- protected request<T>(
23
- method: string,
24
- path: string,
25
- body?: unknown,
26
- options?: {
27
- headers?: Record<string, string>
28
- signal?: AbortSignal
29
- skipAuthRefresh?: boolean
30
- /** Override explicite du Bearer (LOT D) — valide un token arbitraire. */
31
- authToken?: string
32
- },
33
- ): Promise<AuraResponse<T>> {
34
- const init: FetchInit = {
35
- method,
36
- body,
37
- headers: options?.headers,
38
- signal: options?.signal,
39
- skipAuthRefresh: options?.skipAuthRefresh,
40
- authToken: options?.authToken,
41
- }
42
- return fetchWithAuth<T>(this.url(path), init, this.client)
43
- }
44
- }
@@ -1,34 +0,0 @@
1
- import type { BaseAuthStore } from './stores/BaseAuthStore'
2
- import type { AuraResponse, TokenPair, AuraObservabilityEvent } from './types'
3
-
4
- /**
5
- * Forme minimale du client consommée par `fetchWithAuth`, `BaseService`,
6
- * le `QueryBuilder` et les services. Le `AuraClient` concret (meta-package)
7
- * satisfait cette interface structurellement — ce qui casse le cycle de
8
- * dépendance core → meta (les services n'importent plus la classe concrète).
9
- */
10
- export interface AuraClientLike {
11
- readonly baseUrl: string
12
- readonly projectId: string
13
- readonly apiKey: string | null
14
- readonly fetchFn: typeof globalThis.fetch
15
- readonly authStore: BaseAuthStore
16
- /** Consommé uniquement par le service realtime (refresh proactif du token). */
17
- readonly auth: { refreshSession(): Promise<AuraResponse<TokenPair>> }
18
- /** Config du retry transitoire. Défauts appliqués si absent : enabled=true, maxRetries=3. */
19
- readonly retryConfig?: { enabled: boolean; maxRetries: number }
20
- /**
21
- * Timeout par défaut (ms) des requêtes HTTP. Appliqué UNIQUEMENT aux requêtes
22
- * JSON sans `signal` fourni (donc pas aux uploads FormData ni aux appels qui
23
- * gèrent déjà leur propre annulation). `0` désactive. Défaut : 30 000 ms.
24
- */
25
- readonly requestTimeoutMs?: number
26
- /**
27
- * Hook d'observabilité (LOT 3, finding I8), optionnel — n'importe quelle implémentation
28
- * structurelle de `AuraClientLike` reste compatible sans le fournir (pas de breaking
29
- * change). Consommé par `fetchWithAuth`/`refreshOnce` pour émettre retry/timeout/refresh.
30
- */
31
- readonly onEvent?: (event: AuraObservabilityEvent) => void
32
- /** Si `true`, chaque `AuraObservabilityEvent` est aussi journalisé via `console.debug`. */
33
- readonly debug?: boolean
34
- }
@@ -1,42 +0,0 @@
1
- /**
2
- * Parse a raw Cookie header string into key-value pairs.
3
- */
4
- export function parseCookieHeader(header: string): Record<string, string> {
5
- const result: Record<string, string> = {}
6
- if (!header) return result
7
- for (const pair of header.split(';')) {
8
- const idx = pair.indexOf('=')
9
- if (idx === -1) continue
10
- const key = pair.slice(0, idx).trim()
11
- const value = pair.slice(idx + 1).trim()
12
- if (key) result[key] = decodeURIComponent(value)
13
- }
14
- return result
15
- }
16
-
17
- export interface SerializeCookieOptions {
18
- path?: string
19
- domain?: string
20
- maxAge?: number
21
- secure?: boolean
22
- sameSite?: 'Strict' | 'Lax' | 'None'
23
- httpOnly?: boolean
24
- }
25
-
26
- /**
27
- * Serialize a cookie name + value + options into a Set-Cookie header value.
28
- */
29
- export function serializeCookieHeader(
30
- name: string,
31
- value: string,
32
- options: SerializeCookieOptions = {},
33
- ): string {
34
- const parts = [`${name}=${encodeURIComponent(value)}`]
35
- if (options.path) parts.push(`Path=${options.path}`)
36
- if (options.domain) parts.push(`Domain=${options.domain}`)
37
- if (options.maxAge !== undefined) parts.push(`Max-Age=${options.maxAge}`)
38
- if (options.secure) parts.push('Secure')
39
- if (options.sameSite) parts.push(`SameSite=${options.sameSite}`)
40
- if (options.httpOnly) parts.push('HttpOnly')
41
- return parts.join('; ')
42
- }