@luxexchange/sessions 1.0.2 → 1.0.3

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 (54) hide show
  1. package/.depcheckrc +20 -0
  2. package/.eslintrc.js +21 -0
  3. package/README.md +1 -0
  4. package/env.d.ts +12 -0
  5. package/package.json +3 -4
  6. package/project.json +1 -7
  7. package/src/challenge-solvers/createChallengeSolverService.ts +2 -2
  8. package/src/challenge-solvers/createHashcashMockSolver.ts +2 -2
  9. package/src/challenge-solvers/createHashcashSolver.test.ts +6 -6
  10. package/src/challenge-solvers/createHashcashSolver.ts +18 -3
  11. package/src/challenge-solvers/createNoneMockSolver.ts +1 -1
  12. package/src/challenge-solvers/createTurnstileMockSolver.ts +2 -2
  13. package/src/challenge-solvers/createTurnstileSolver.ts +9 -5
  14. package/src/challenge-solvers/hashcash/core.native.ts +1 -1
  15. package/src/challenge-solvers/hashcash/core.test.ts +10 -10
  16. package/src/challenge-solvers/hashcash/core.ts +1 -1
  17. package/src/challenge-solvers/hashcash/createWorkerHashcashSolver.test.ts +4 -4
  18. package/src/challenge-solvers/hashcash/worker/createHashcashMultiWorkerChannel.native.ts +1 -1
  19. package/src/challenge-solvers/hashcash/worker/createHashcashMultiWorkerChannel.ts +1 -1
  20. package/src/challenge-solvers/hashcash/worker/createHashcashWorkerChannel.native.ts +1 -1
  21. package/src/challenge-solvers/hashcash/worker/createHashcashWorkerChannel.ts +1 -1
  22. package/src/challenge-solvers/hashcash/worker/hashcash.worker.ts +3 -3
  23. package/src/challenge-solvers/turnstileSolver.integration.test.ts +1 -1
  24. package/src/challengeFlow.integration.test.ts +41 -41
  25. package/src/device-id/createDeviceIdService.ts +1 -1
  26. package/src/index.ts +8 -6
  27. package/src/oauth-service/types.ts +1 -1
  28. package/src/session-initialization/createSessionInitializationService.ts +29 -38
  29. package/src/session-repository/createSessionClient.ts +1 -1
  30. package/src/session-repository/createSessionRepository.test.ts +2 -2
  31. package/src/session-repository/createSessionRepository.ts +11 -11
  32. package/src/session-repository/types.ts +1 -1
  33. package/src/session-service/createNoopSessionService.ts +2 -2
  34. package/src/session-service/createSessionService.test.ts +29 -29
  35. package/src/session-service/createSessionService.ts +4 -4
  36. package/src/session-service/types.ts +1 -1
  37. package/src/session-storage/createSessionStorage.ts +1 -1
  38. package/src/session.integration.test.ts +116 -80
  39. package/src/sessionLifecycle.integration.test.ts +22 -22
  40. package/src/test-utils/createLocalCookieTransport.ts +1 -1
  41. package/src/test-utils/createLocalHeaderTransport.ts +1 -1
  42. package/src/test-utils/mocks.ts +3 -3
  43. package/src/test-utils.ts +24 -24
  44. package/src/uniswap-identifier/createUniswapIdentifierService.ts +19 -0
  45. package/src/uniswap-identifier/types.ts +11 -0
  46. package/src/uniswap-identifier/uniswapIdentifierQuery.ts +20 -0
  47. package/tsconfig.json +10 -3
  48. package/tsconfig.lint.json +8 -0
  49. package/tsconfig.spec.json +8 -0
  50. package/vitest.config.ts +20 -0
  51. package/vitest.integration.config.ts +14 -0
  52. package/src/lux-identifier/createLuxIdentifierService.ts +0 -19
  53. package/src/lux-identifier/luxIdentifierQuery.ts +0 -20
  54. package/src/lux-identifier/types.ts +0 -11
package/src/test-utils.ts CHANGED
@@ -17,30 +17,30 @@ import {
17
17
  type UpdateSessionResponse,
18
18
  type VerifyRequest,
19
19
  type VerifyResponse,
20
- } from '@luxdex/client-platform-service/dist/uniswap/platformservice/v1/sessionService_pb'
21
- import type { DeviceIdService } from '@luxfi/sessions/src/device-id/types'
22
- import type { SessionServiceClient } from '@luxfi/sessions/src/session-repository/createSessionClient'
23
- import type { SessionState, SessionStorage } from '@luxfi/sessions/src/session-storage/types'
24
- import type { LuxIdentifierService } from '@luxfi/sessions/src/lux-identifier/types'
20
+ } from '@luxamm/client-platform-service/dist/uniswap/platformservice/v1/sessionService_pb'
21
+ import type { DeviceIdService } from '@luxexchange/sessions/src/device-id/types'
22
+ import type { SessionServiceClient } from '@luxexchange/sessions/src/session-repository/createSessionClient'
23
+ import type { SessionState, SessionStorage } from '@luxexchange/sessions/src/session-storage/types'
24
+ import type { LxIdentifierService } from '@luxexchange/sessions/src/uniswap-identifier/types'
25
25
  // Types for our test transport
26
26
  export interface MockEndpointHandler {
27
27
  (request: any, headers: Record<string, string>): Promise<any>
28
28
  }
29
29
 
30
30
  export interface MockEndpoints {
31
- '/lux.platformservice.v1.SessionService/InitSession': MockEndpointHandler
32
- '/lux.platformservice.v1.SessionService/Challenge': MockEndpointHandler
33
- '/lux.platformservice.v1.SessionService/Verify': MockEndpointHandler
34
- '/lux.platformservice.v1.SessionService/IntrospectSession': MockEndpointHandler
35
- '/lux.platformservice.v1.SessionService/UpdateSession': MockEndpointHandler
36
- '/lux.platformservice.v1.SessionService/GetChallengeTypes': MockEndpointHandler
37
- '/lux.platformservice.v1.SessionService/Signout': MockEndpointHandler
31
+ '/uniswap.platformservice.v1.SessionService/InitSession': MockEndpointHandler
32
+ '/uniswap.platformservice.v1.SessionService/Challenge': MockEndpointHandler
33
+ '/uniswap.platformservice.v1.SessionService/Verify': MockEndpointHandler
34
+ '/uniswap.platformservice.v1.SessionService/IntrospectSession': MockEndpointHandler
35
+ '/uniswap.platformservice.v1.SessionService/UpdateSession': MockEndpointHandler
36
+ '/uniswap.platformservice.v1.SessionService/GetChallengeTypes': MockEndpointHandler
37
+ '/uniswap.platformservice.v1.SessionService/Signout': MockEndpointHandler
38
38
  }
39
39
 
40
40
  // Test transport that intercepts requests and returns mock responses
41
41
  export function createTestTransport(mockEndpoints: MockEndpoints): ReturnType<typeof createConnectTransport> {
42
42
  return createConnectTransport({
43
- baseUrl: 'https://test.api.lux.org',
43
+ baseUrl: 'https://test.api.lux.exchange',
44
44
  interceptors: [
45
45
  (_next) => async (request) => {
46
46
  const url = request.url
@@ -109,18 +109,18 @@ export class InMemoryDeviceIdService implements DeviceIdService {
109
109
  }
110
110
  }
111
111
 
112
- export class InMemoryLuxIdentifierService implements LuxIdentifierService {
112
+ export class InMemoryLxIdentifierService implements LxIdentifierService {
113
113
  private identifier: string | null = null
114
114
 
115
- async getLuxIdentifier(): Promise<string | null> {
115
+ async getLxIdentifier(): Promise<string | null> {
116
116
  return this.identifier
117
117
  }
118
118
 
119
- async setLuxIdentifier(id: string): Promise<void> {
119
+ async setLxIdentifier(id: string): Promise<void> {
120
120
  this.identifier = id
121
121
  }
122
122
 
123
- async removeLuxIdentifier(): Promise<void> {
123
+ async removeLxIdentifier(): Promise<void> {
124
124
  this.identifier = null
125
125
  }
126
126
  }
@@ -137,7 +137,7 @@ export function createMockSessionClient(
137
137
  request: PartialMessage<InitSessionRequest>,
138
138
  _options?: CallOptions,
139
139
  ): Promise<InitSessionResponse> => {
140
- const response = await mockEndpoints['/lux.platformservice.v1.SessionService/InitSession'](request, {})
140
+ const response = await mockEndpoints['/uniswap.platformservice.v1.SessionService/InitSession'](request, {})
141
141
  return response as InitSessionResponse
142
142
  },
143
143
  challenge: async (
@@ -154,7 +154,7 @@ export function createMockSessionClient(
154
154
  headers['X-Device-ID'] = deviceId
155
155
  }
156
156
 
157
- const response = await mockEndpoints['/lux.platformservice.v1.SessionService/Challenge'](request, headers)
157
+ const response = await mockEndpoints['/uniswap.platformservice.v1.SessionService/Challenge'](request, headers)
158
158
  return response as ChallengeResponse
159
159
  },
160
160
  verify: async (request: PartialMessage<VerifyRequest>, _options?: CallOptions): Promise<VerifyResponse> => {
@@ -168,32 +168,32 @@ export function createMockSessionClient(
168
168
  headers['X-Device-ID'] = deviceId
169
169
  }
170
170
 
171
- const response = await mockEndpoints['/lux.platformservice.v1.SessionService/Verify'](request, headers)
171
+ const response = await mockEndpoints['/uniswap.platformservice.v1.SessionService/Verify'](request, headers)
172
172
  return response as VerifyResponse
173
173
  },
174
174
  introspectSession: async (
175
175
  request: PartialMessage<IntrospectSessionRequest>,
176
176
  _options?: CallOptions,
177
177
  ): Promise<IntrospectSessionResponse> => {
178
- const response = await mockEndpoints['/lux.platformservice.v1.SessionService/IntrospectSession'](request, {})
178
+ const response = await mockEndpoints['/uniswap.platformservice.v1.SessionService/IntrospectSession'](request, {})
179
179
  return response as IntrospectSessionResponse
180
180
  },
181
181
  updateSession: async (
182
182
  request: PartialMessage<UpdateSessionRequest>,
183
183
  _options?: CallOptions,
184
184
  ): Promise<UpdateSessionResponse> => {
185
- const response = await mockEndpoints['/lux.platformservice.v1.SessionService/UpdateSession'](request, {})
185
+ const response = await mockEndpoints['/uniswap.platformservice.v1.SessionService/UpdateSession'](request, {})
186
186
  return response as UpdateSessionResponse
187
187
  },
188
188
  getChallengeTypes: async (
189
189
  request: PartialMessage<GetChallengeTypesRequest>,
190
190
  _options?: CallOptions,
191
191
  ): Promise<GetChallengeTypesResponse> => {
192
- const response = await mockEndpoints['/lux.platformservice.v1.SessionService/GetChallengeTypes'](request, {})
192
+ const response = await mockEndpoints['/uniswap.platformservice.v1.SessionService/GetChallengeTypes'](request, {})
193
193
  return response as GetChallengeTypesResponse
194
194
  },
195
195
  signout: async (request: PartialMessage<SignoutRequest>, _options?: CallOptions): Promise<SignoutResponse> => {
196
- const response = await mockEndpoints['/lux.platformservice.v1.SessionService/Signout'](request, {})
196
+ const response = await mockEndpoints['/uniswap.platformservice.v1.SessionService/Signout'](request, {})
197
197
  return response as SignoutResponse
198
198
  },
199
199
  }
@@ -0,0 +1,19 @@
1
+ import type { LxIdentifierService } from '@luxexchange/sessions/src/uniswap-identifier/types'
2
+
3
+ function createLxIdentifierService(ctx: {
4
+ getLxIdentifier: () => Promise<string | null>
5
+ setLxIdentifier: (identifier: string) => Promise<void>
6
+ removeLxIdentifier: () => Promise<void>
7
+ }): LxIdentifierService {
8
+ const getLxIdentifier = ctx.getLxIdentifier
9
+ const setLxIdentifier = ctx.setLxIdentifier
10
+ const removeLxIdentifier = ctx.removeLxIdentifier
11
+
12
+ return {
13
+ getLxIdentifier,
14
+ setLxIdentifier,
15
+ removeLxIdentifier,
16
+ }
17
+ }
18
+
19
+ export { createLxIdentifierService }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Uniswap Identifier provider interface
3
+ * Platform-specific implementations handle uniswap identifier persistence
4
+ */
5
+ interface LxIdentifierService {
6
+ getLxIdentifier(): Promise<string | null>
7
+ setLxIdentifier(identifier: string): Promise<void>
8
+ removeLxIdentifier(): Promise<void>
9
+ }
10
+
11
+ export type { LxIdentifierService }
@@ -0,0 +1,20 @@
1
+ import { queryOptions } from '@tanstack/react-query'
2
+ import type { LxIdentifierService } from '@luxexchange/sessions/src/uniswap-identifier/types'
3
+ import { ReactQueryCacheKey } from 'utilities/src/reactQuery/cache'
4
+ import type { QueryOptionsResult } from 'utilities/src/reactQuery/queryOptions'
5
+
6
+ type LxIdentifierQueryOptions = QueryOptionsResult<
7
+ string | null,
8
+ Error,
9
+ string | null,
10
+ [ReactQueryCacheKey.LxIdentifier]
11
+ >
12
+
13
+ export function lxIdentifierQuery(getService: () => LxIdentifierService): LxIdentifierQueryOptions {
14
+ return queryOptions({
15
+ queryKey: [ReactQueryCacheKey.LxIdentifier],
16
+ queryFn: async () => getService().getLxIdentifier(),
17
+ staleTime: Infinity,
18
+ gcTime: Infinity,
19
+ })
20
+ }
package/tsconfig.json CHANGED
@@ -1,19 +1,26 @@
1
1
  {
2
2
  "extends": "../../config/tsconfig/app.json",
3
3
  "include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.json", "env.d.ts"],
4
- "exclude": ["src/**/*.spec.ts", "src/**/*.spec.tsx", "src/**/*.test.ts", "src/**/*.test.tsx"],
4
+ "exclude": [
5
+ "src/**/*.spec.ts",
6
+ "src/**/*.spec.tsx",
7
+ "src/**/*.test.ts",
8
+ "src/**/*.test.tsx"
9
+ ],
5
10
  "compilerOptions": {
6
11
  "emitDeclarationOnly": true,
7
12
  "noEmit": false,
8
13
  "paths": {
9
- "@universe/sessions/*": ["./src/*"],
10
- "@luxdex/client-platform-service/*": ["../../node_modules/@uniswap/client-platform-service/*"]
14
+ "@luxexchange/sessions/*": ["./src/*"]
11
15
  },
12
16
  "types": ["chrome", "node"]
13
17
  },
14
18
  "references": [
15
19
  {
16
20
  "path": "../utilities"
21
+ },
22
+ {
23
+ "path": "../eslint-config"
17
24
  }
18
25
  ]
19
26
  }
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "preserveSymlinks": true
5
+ },
6
+ "include": ["src/**/*.ts", "src/**/*.tsx", "*.config.ts"],
7
+ "exclude": []
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "types": ["node"]
5
+ },
6
+ "include": ["src/**/*.test.ts", "src/**/*.spec.ts", "src/**/*.d.ts"],
7
+ "exclude": []
8
+ }
@@ -0,0 +1,20 @@
1
+ import { defineConfig } from 'vitest/config'
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ watch: false,
6
+ environment: 'edge-runtime',
7
+ exclude: [
8
+ '**/node_modules/**',
9
+ '**/dist/**',
10
+ // Exclude real backend integration tests - these run in a separate optional CI workflow
11
+ '**/session.integration.test.ts',
12
+ ],
13
+ coverage: {
14
+ exclude: ['**/__generated__/**', '**/node_modules/**', '**/dist/**', '**/*.config.*', '**/scripts/**'],
15
+ },
16
+ },
17
+ resolve: {
18
+ extensions: ['.web.ts', '.web.tsx', '.ts', '.tsx', '.js', '.jsx', '.json'],
19
+ },
20
+ })
@@ -0,0 +1,14 @@
1
+ import { defineConfig } from 'vitest/config'
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ watch: false,
6
+ environment: 'edge-runtime',
7
+ include: ['**/session.integration.test.ts'],
8
+ testTimeout: 60000,
9
+ hookTimeout: 60000,
10
+ },
11
+ resolve: {
12
+ extensions: ['.web.ts', '.web.tsx', '.ts', '.tsx', '.js', '.jsx', '.json'],
13
+ },
14
+ })
@@ -1,19 +0,0 @@
1
- import type { LuxIdentifierService } from '@luxfi/sessions/src/lux-identifier/types'
2
-
3
- function createLuxIdentifierService(ctx: {
4
- getLuxIdentifier: () => Promise<string | null>
5
- setLuxIdentifier: (identifier: string) => Promise<void>
6
- removeLuxIdentifier: () => Promise<void>
7
- }): LuxIdentifierService {
8
- const getLuxIdentifier = ctx.getLuxIdentifier
9
- const setLuxIdentifier = ctx.setLuxIdentifier
10
- const removeLuxIdentifier = ctx.removeLuxIdentifier
11
-
12
- return {
13
- getLuxIdentifier,
14
- setLuxIdentifier,
15
- removeLuxIdentifier,
16
- }
17
- }
18
-
19
- export { createLuxIdentifierService }
@@ -1,20 +0,0 @@
1
- import { queryOptions } from '@tanstack/react-query'
2
- import type { LuxIdentifierService } from '@luxexchange/sessions/src/lux-identifier/types'
3
- import { ReactQueryCacheKey } from '@luxfi/utilities/src/reactQuery/cache'
4
- import type { QueryOptionsResult } from '@luxfi/utilities/src/reactQuery/queryOptions'
5
-
6
- type LuxIdentifierQueryOptions = QueryOptionsResult<
7
- string | null,
8
- Error,
9
- string | null,
10
- [ReactQueryCacheKey.LuxIdentifier]
11
- >
12
-
13
- export function luxIdentifierQuery(getService: () => LuxIdentifierService): LuxIdentifierQueryOptions {
14
- return queryOptions({
15
- queryKey: [ReactQueryCacheKey.LuxIdentifier],
16
- queryFn: async () => getService().getLuxIdentifier(),
17
- staleTime: Infinity,
18
- gcTime: Infinity,
19
- })
20
- }
@@ -1,11 +0,0 @@
1
- /**
2
- * Lux Identifier provider interface
3
- * Platform-specific implementations handle lux identifier persistence
4
- */
5
- interface LuxIdentifierService {
6
- getLuxIdentifier(): Promise<string | null>
7
- setLuxIdentifier(identifier: string): Promise<void>
8
- removeLuxIdentifier(): Promise<void>
9
- }
10
-
11
- export type { LuxIdentifierService }