@luxexchange/sessions 1.0.1 → 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.
- package/.depcheckrc +20 -0
- package/.eslintrc.js +21 -0
- package/README.md +1 -0
- package/env.d.ts +12 -0
- package/package.json +3 -4
- package/project.json +2 -8
- package/src/challenge-solvers/createChallengeSolverService.ts +5 -5
- package/src/challenge-solvers/createHashcashMockSolver.ts +1 -1
- package/src/challenge-solvers/createHashcashSolver.test.ts +10 -10
- package/src/challenge-solvers/createHashcashSolver.ts +22 -7
- package/src/challenge-solvers/createNoneMockSolver.ts +1 -1
- package/src/challenge-solvers/createTurnstileMockSolver.ts +1 -1
- package/src/challenge-solvers/createTurnstileSolver.ts +12 -8
- package/src/challenge-solvers/hashcash/core.native.ts +3 -3
- package/src/challenge-solvers/hashcash/core.test.ts +10 -10
- package/src/challenge-solvers/hashcash/core.ts +3 -3
- package/src/challenge-solvers/hashcash/core.web.ts +4 -4
- package/src/challenge-solvers/hashcash/createWorkerHashcashSolver.test.ts +7 -7
- package/src/challenge-solvers/hashcash/createWorkerHashcashSolver.ts +4 -4
- package/src/challenge-solvers/hashcash/worker/createHashcashMultiWorkerChannel.native.ts +1 -1
- package/src/challenge-solvers/hashcash/worker/createHashcashMultiWorkerChannel.ts +1 -1
- package/src/challenge-solvers/hashcash/worker/createHashcashMultiWorkerChannel.web.ts +2 -2
- package/src/challenge-solvers/hashcash/worker/createHashcashWorkerChannel.native.ts +1 -1
- package/src/challenge-solvers/hashcash/worker/createHashcashWorkerChannel.ts +1 -1
- package/src/challenge-solvers/hashcash/worker/createHashcashWorkerChannel.web.ts +2 -2
- package/src/challenge-solvers/hashcash/worker/hashcash.worker.ts +3 -3
- package/src/challenge-solvers/hashcash/worker/types.ts +1 -1
- package/src/challenge-solvers/turnstileErrors.ts +1 -1
- package/src/challenge-solvers/turnstileScriptLoader.ts +2 -2
- package/src/challenge-solvers/turnstileSolver.integration.test.ts +4 -4
- package/src/challenge-solvers/types.ts +2 -2
- package/src/challengeFlow.integration.test.ts +49 -49
- package/src/device-id/createDeviceIdService.ts +1 -1
- package/src/index.ts +50 -48
- package/src/oauth-service/createOAuthService.ts +2 -2
- package/src/oauth-service/types.ts +1 -1
- package/src/performance/createNoopPerformanceTracker.ts +2 -2
- package/src/performance/createPerformanceTracker.ts +1 -1
- package/src/performance/index.ts +3 -3
- package/src/session-initialization/createSessionInitializationService.test.ts +4 -4
- package/src/session-initialization/createSessionInitializationService.ts +32 -41
- package/src/session-repository/createSessionClient.ts +1 -1
- package/src/session-repository/createSessionRepository.test.ts +5 -5
- package/src/session-repository/createSessionRepository.ts +14 -14
- package/src/session-repository/errors.ts +1 -1
- package/src/session-repository/types.ts +1 -1
- package/src/session-service/createNoopSessionService.ts +2 -2
- package/src/session-service/createSessionService.test.ts +29 -29
- package/src/session-service/createSessionService.ts +8 -8
- package/src/session-service/types.ts +3 -3
- package/src/session-storage/createSessionStorage.ts +1 -1
- package/src/session.integration.test.ts +130 -94
- package/src/sessionLifecycle.integration.test.ts +22 -22
- package/src/test-utils/createLocalCookieTransport.ts +1 -1
- package/src/test-utils/createLocalHeaderTransport.ts +1 -1
- package/src/test-utils/mocks.ts +3 -3
- package/src/test-utils.ts +24 -24
- package/src/uniswap-identifier/createUniswapIdentifierService.ts +19 -0
- package/src/uniswap-identifier/types.ts +11 -0
- package/src/uniswap-identifier/uniswapIdentifierQuery.ts +20 -0
- package/tsconfig.json +10 -3
- package/tsconfig.lint.json +8 -0
- package/tsconfig.spec.json +8 -0
- package/vitest.config.ts +20 -0
- package/vitest.integration.config.ts +14 -0
- package/src/lux-identifier/createLuxIdentifierService.ts +0 -19
- package/src/lux-identifier/luxIdentifierQuery.ts +0 -20
- package/src/lux-identifier/types.ts +0 -11
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { ChallengeSolverService } from '@
|
|
2
|
-
import type { PerformanceTracker } from '@
|
|
1
|
+
import type { ChallengeSolverService } from '@luxexchange/sessions/src/challenge-solvers/types'
|
|
2
|
+
import type { PerformanceTracker } from '@luxexchange/sessions/src/performance/types'
|
|
3
3
|
import {
|
|
4
4
|
MaxChallengeRetriesError,
|
|
5
5
|
NoSolverAvailableError,
|
|
6
|
-
} from '@
|
|
7
|
-
import type { SessionService } from '@
|
|
6
|
+
} from '@luxexchange/sessions/src/session-initialization/sessionErrors'
|
|
7
|
+
import type { SessionService } from '@luxexchange/sessions/src/session-service/types'
|
|
8
8
|
import type { Logger } from 'utilities/src/logger/logger'
|
|
9
9
|
|
|
10
10
|
interface SessionInitResult {
|
|
@@ -61,22 +61,23 @@ function createSessionInitializationService(ctx: {
|
|
|
61
61
|
/** Analytics callbacks for tracking session initialization lifecycle */
|
|
62
62
|
analytics?: SessionInitAnalytics
|
|
63
63
|
}): SessionInitializationService {
|
|
64
|
+
const log = ctx.getLogger?.()
|
|
65
|
+
|
|
64
66
|
async function handleChallengeFlow(attemptCount = 0, flowStartTime?: number): Promise<void> {
|
|
65
67
|
const startTime = flowStartTime ?? ctx.performanceTracker.now()
|
|
66
68
|
const maxRetries = ctx.maxChallengeRetries ?? 3
|
|
67
69
|
|
|
68
70
|
const challenge = await ctx.getSessionService().requestChallenge()
|
|
69
71
|
|
|
70
|
-
|
|
72
|
+
log?.debug('createSessionInitializationService', 'handleChallengeFlow', 'Requesting challenge', {
|
|
71
73
|
challenge,
|
|
72
74
|
})
|
|
73
75
|
|
|
74
76
|
// Report challenge received (only on first attempt)
|
|
75
77
|
if (attemptCount === 0) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
})
|
|
78
|
+
const data = { challengeType: String(challenge.challengeType), challengeId: challenge.challengeId }
|
|
79
|
+
ctx.analytics?.onChallengeReceived?.(data)
|
|
80
|
+
log?.info('sessions', 'challengeReceived', 'Challenge received', data)
|
|
80
81
|
}
|
|
81
82
|
|
|
82
83
|
// get our solver for the challenge type
|
|
@@ -99,20 +100,16 @@ function createSessionInitializationService(ctx: {
|
|
|
99
100
|
challengeData: challenge.challengeData,
|
|
100
101
|
})
|
|
101
102
|
} catch (solverError) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
{ error: solverError, challengeType: challenge.challengeType },
|
|
109
|
-
)
|
|
103
|
+
log?.warn(
|
|
104
|
+
'createSessionInitializationService',
|
|
105
|
+
'handleChallengeFlow',
|
|
106
|
+
'Solver failed, submitting placeholder solution to trigger fallback',
|
|
107
|
+
{ error: solverError, challengeType: challenge.challengeType },
|
|
108
|
+
)
|
|
110
109
|
solution = 'solver-failed'
|
|
111
110
|
}
|
|
112
111
|
|
|
113
|
-
|
|
114
|
-
.getLogger?.()
|
|
115
|
-
.debug('createSessionInitializationService', 'handleChallengeFlow', 'Solved challenge', { solution })
|
|
112
|
+
log?.debug('createSessionInitializationService', 'handleChallengeFlow', 'Solved challenge', { solution })
|
|
116
113
|
|
|
117
114
|
// Verify session with the solution
|
|
118
115
|
const result = await ctx.getSessionService().verifySession({
|
|
@@ -121,23 +118,18 @@ function createSessionInitializationService(ctx: {
|
|
|
121
118
|
challengeType: challenge.challengeType,
|
|
122
119
|
})
|
|
123
120
|
|
|
121
|
+
const verifyData = {
|
|
122
|
+
success: !result.retry,
|
|
123
|
+
attemptNumber: attemptCount + 1,
|
|
124
|
+
totalDurationMs: ctx.performanceTracker.now() - startTime,
|
|
125
|
+
}
|
|
126
|
+
ctx.analytics?.onVerifyCompleted?.(verifyData)
|
|
127
|
+
log?.info('sessions', 'verifyCompleted', 'Verify completed', verifyData)
|
|
128
|
+
|
|
124
129
|
if (!result.retry) {
|
|
125
|
-
// Verification was successful
|
|
126
|
-
ctx.analytics?.onVerifyCompleted?.({
|
|
127
|
-
success: true,
|
|
128
|
-
attemptNumber: attemptCount + 1,
|
|
129
|
-
totalDurationMs: ctx.performanceTracker.now() - startTime,
|
|
130
|
-
})
|
|
131
130
|
return
|
|
132
131
|
}
|
|
133
132
|
|
|
134
|
-
// Report retry (verification failed but will retry)
|
|
135
|
-
ctx.analytics?.onVerifyCompleted?.({
|
|
136
|
-
success: false,
|
|
137
|
-
attemptNumber: attemptCount + 1,
|
|
138
|
-
totalDurationMs: ctx.performanceTracker.now() - startTime,
|
|
139
|
-
})
|
|
140
|
-
|
|
141
133
|
// Handle server retry request
|
|
142
134
|
if (attemptCount >= maxRetries) {
|
|
143
135
|
throw new MaxChallengeRetriesError(maxRetries, attemptCount + 1)
|
|
@@ -157,22 +149,21 @@ function createSessionInitializationService(ctx: {
|
|
|
157
149
|
needChallenge = options.needChallenge
|
|
158
150
|
sessionId = undefined
|
|
159
151
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
})
|
|
152
|
+
const data = { needChallenge, durationMs: 0 }
|
|
153
|
+
ctx.analytics?.onInitCompleted?.(data)
|
|
154
|
+
log?.info('sessions', 'initCompleted', 'Session init completed', data)
|
|
164
155
|
} else {
|
|
165
156
|
// Discover from backend
|
|
166
157
|
ctx.analytics?.onInitStarted?.()
|
|
158
|
+
log?.info('sessions', 'initStarted', 'Session init started')
|
|
167
159
|
|
|
168
160
|
const initResponse = await ctx.getSessionService().initSession()
|
|
169
161
|
needChallenge = initResponse.needChallenge
|
|
170
162
|
sessionId = initResponse.sessionId
|
|
171
163
|
|
|
172
|
-
ctx.
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
})
|
|
164
|
+
const data = { needChallenge, durationMs: ctx.performanceTracker.now() - initStartTime }
|
|
165
|
+
ctx.analytics?.onInitCompleted?.(data)
|
|
166
|
+
log?.info('sessions', 'initCompleted', 'Session init completed', data)
|
|
176
167
|
}
|
|
177
168
|
|
|
178
169
|
// Handle challenge if required and enabled
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createPromiseClient, type PromiseClient, type Transport } from '@connectrpc/connect'
|
|
2
|
-
import { SessionService } from '@
|
|
2
|
+
import { SessionService } from '@luxamm/client-platform-service/dist/uniswap/platformservice/v1/sessionService_connect'
|
|
3
3
|
|
|
4
4
|
type SessionServiceClient = PromiseClient<typeof SessionService>
|
|
5
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PromiseClient } from '@connectrpc/connect'
|
|
2
|
-
import type { SessionService } from '@
|
|
2
|
+
import type { SessionService } from '@luxamm/client-platform-service/dist/uniswap/platformservice/v1/sessionService_connect'
|
|
3
3
|
import {
|
|
4
4
|
ChallengeFailure,
|
|
5
5
|
ChallengeFailure_Reason,
|
|
@@ -7,10 +7,10 @@ import {
|
|
|
7
7
|
GetChallengeTypesResponse,
|
|
8
8
|
InitSessionResponse,
|
|
9
9
|
SignoutResponse,
|
|
10
|
-
} from '@
|
|
11
|
-
import { createSessionRepository } from '@
|
|
12
|
-
import { ChallengeRejectedError } from '@
|
|
13
|
-
import { ChallengeType } from '@
|
|
10
|
+
} from '@luxamm/client-platform-service/dist/uniswap/platformservice/v1/sessionService_pb'
|
|
11
|
+
import { createSessionRepository } from '@luxexchange/sessions/src/session-repository/createSessionRepository'
|
|
12
|
+
import { ChallengeRejectedError } from '@luxexchange/sessions/src/session-repository/errors'
|
|
13
|
+
import { ChallengeType } from '@luxexchange/sessions/src/session-service/types'
|
|
14
14
|
import { describe, expect, it, type MockedFunction, vi } from 'vitest'
|
|
15
15
|
|
|
16
16
|
type MockedClient = {
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ChallengeFailure_Reason,
|
|
3
3
|
VerifyFailure_Reason,
|
|
4
|
-
} from '@
|
|
5
|
-
import type { SessionServiceClient } from '@
|
|
6
|
-
import { ChallengeRejectedError } from '@
|
|
7
|
-
import type { SessionRepository, TypedChallengeData } from '@
|
|
8
|
-
import { ChallengeFailureReason, VerifyFailureReason } from '@
|
|
4
|
+
} from '@luxamm/client-platform-service/dist/uniswap/platformservice/v1/sessionService_pb'
|
|
5
|
+
import type { SessionServiceClient } from '@luxexchange/sessions/src/session-repository/createSessionClient'
|
|
6
|
+
import { ChallengeRejectedError } from '@luxexchange/sessions/src/session-repository/errors'
|
|
7
|
+
import type { SessionRepository, TypedChallengeData } from '@luxexchange/sessions/src/session-repository/types'
|
|
8
|
+
import { ChallengeFailureReason, VerifyFailureReason } from '@luxexchange/sessions/src/session-repository/types'
|
|
9
9
|
import type { Logger } from 'utilities/src/logger/logger'
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Creates a session repository that handles communication with the session service.
|
|
13
13
|
* This is the layer that makes actual API calls to the backend.
|
|
14
14
|
*
|
|
15
|
-
* TODO(proto): `VerifyResponse` in `@
|
|
15
|
+
* TODO(proto): `VerifyResponse` in `@luxamm/client-platform-service` still has a proto3
|
|
16
16
|
* issue where an empty `VerifySuccess` message gets silently dropped, leaving
|
|
17
17
|
* `outcome.case === undefined`. The `verifySession()` method works around this by using
|
|
18
18
|
* the `retry` flag as a discriminator.
|
|
@@ -23,7 +23,7 @@ import type { Logger } from 'utilities/src/logger/logger'
|
|
|
23
23
|
function createSessionRepository(ctx: { client: SessionServiceClient; getLogger?: () => Logger }): SessionRepository {
|
|
24
24
|
const initSession: SessionRepository['initSession'] = async () => {
|
|
25
25
|
try {
|
|
26
|
-
const response = await ctx.client
|
|
26
|
+
const response = await ctx.client.initSession({})
|
|
27
27
|
|
|
28
28
|
return {
|
|
29
29
|
sessionId: response.sessionId,
|
|
@@ -39,7 +39,7 @@ function createSessionRepository(ctx: { client: SessionServiceClient; getLogger?
|
|
|
39
39
|
|
|
40
40
|
const challenge: SessionRepository['challenge'] = async (request) => {
|
|
41
41
|
try {
|
|
42
|
-
const response = await ctx.client
|
|
42
|
+
const response = await ctx.client.challenge({
|
|
43
43
|
challengeType: request.challengeType,
|
|
44
44
|
identifier: request.identifier,
|
|
45
45
|
})
|
|
@@ -140,7 +140,7 @@ function createSessionRepository(ctx: { client: SessionServiceClient; getLogger?
|
|
|
140
140
|
|
|
141
141
|
const verifySession: SessionRepository['verifySession'] = async (request) => {
|
|
142
142
|
try {
|
|
143
|
-
const response = await ctx.client
|
|
143
|
+
const response = await ctx.client.verify({
|
|
144
144
|
solution: request.solution,
|
|
145
145
|
challengeId: request.challengeId,
|
|
146
146
|
type: request.challengeType,
|
|
@@ -209,7 +209,7 @@ function createSessionRepository(ctx: { client: SessionServiceClient; getLogger?
|
|
|
209
209
|
const deleteSession: SessionRepository['deleteSession'] = async () => {
|
|
210
210
|
try {
|
|
211
211
|
// Proto renamed deleteSession to signout
|
|
212
|
-
await ctx.client
|
|
212
|
+
await ctx.client.signout({})
|
|
213
213
|
return {}
|
|
214
214
|
} catch (error) {
|
|
215
215
|
const errorMessage = error instanceof Error ? error.message : String(error)
|
|
@@ -219,10 +219,10 @@ function createSessionRepository(ctx: { client: SessionServiceClient; getLogger?
|
|
|
219
219
|
|
|
220
220
|
const getChallengeTypes: SessionRepository['getChallengeTypes'] = async () => {
|
|
221
221
|
try {
|
|
222
|
-
const response = await ctx.client
|
|
223
|
-
return response.challengeTypeConfig.map((
|
|
224
|
-
type:
|
|
225
|
-
config:
|
|
222
|
+
const response = await ctx.client.getChallengeTypes({})
|
|
223
|
+
return response.challengeTypeConfig.map((config) => ({
|
|
224
|
+
type: config.type,
|
|
225
|
+
config: config.config,
|
|
226
226
|
}))
|
|
227
227
|
} catch (error) {
|
|
228
228
|
const errorMessage = error instanceof Error ? error.message : String(error)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChallengeType } from '@
|
|
1
|
+
import { ChallengeType } from '@luxamm/client-platform-service/dist/uniswap/platformservice/v1/sessionService_pb'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Typed challenge data for Turnstile bot detection
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ChallengeType } from '@
|
|
2
|
-
import type { SessionService } from '@
|
|
1
|
+
import { ChallengeType } from '@luxamm/client-platform-service/dist/uniswap/platformservice/v1/sessionService_pb'
|
|
2
|
+
import type { SessionService } from '@luxexchange/sessions/src/session-service/types'
|
|
3
3
|
|
|
4
4
|
function createNoopSessionService(): SessionService {
|
|
5
5
|
const initSession: SessionService['initSession'] = async () => ({ needChallenge: false, extra: {} })
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import type { DeviceIdService } from '@
|
|
2
|
-
import type { SessionRepository } from '@
|
|
3
|
-
import { createSessionService } from '@
|
|
4
|
-
import type { SessionService } from '@
|
|
5
|
-
import type { SessionStorage } from '@
|
|
6
|
-
import type {
|
|
1
|
+
import type { DeviceIdService } from '@luxexchange/sessions/src/device-id/types'
|
|
2
|
+
import type { SessionRepository } from '@luxexchange/sessions/src/session-repository/types'
|
|
3
|
+
import { createSessionService } from '@luxexchange/sessions/src/session-service/createSessionService'
|
|
4
|
+
import type { SessionService } from '@luxexchange/sessions/src/session-service/types'
|
|
5
|
+
import type { SessionStorage } from '@luxexchange/sessions/src/session-storage/types'
|
|
6
|
+
import type { LxIdentifierService } from '@luxexchange/sessions/src/uniswap-identifier/types'
|
|
7
7
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
8
8
|
|
|
9
9
|
describe('createSessionService', () => {
|
|
10
10
|
let storage: SessionStorage
|
|
11
11
|
let repository: SessionRepository
|
|
12
12
|
let deviceIdService: DeviceIdService
|
|
13
|
-
let
|
|
13
|
+
let lxIdentifierService: LxIdentifierService
|
|
14
14
|
let service: SessionService
|
|
15
15
|
|
|
16
16
|
beforeEach(() => {
|
|
@@ -37,14 +37,14 @@ describe('createSessionService', () => {
|
|
|
37
37
|
},
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
let
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
let lxIdentifierData: string | null = null
|
|
41
|
+
lxIdentifierService = {
|
|
42
|
+
getLxIdentifier: async (): Promise<string | null> => lxIdentifierData,
|
|
43
|
+
setLxIdentifier: async (identifier: string): Promise<void> => {
|
|
44
|
+
lxIdentifierData = identifier
|
|
45
45
|
},
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
removeLxIdentifier: async (): Promise<void> => {
|
|
47
|
+
lxIdentifierData = null
|
|
48
48
|
},
|
|
49
49
|
}
|
|
50
50
|
|
|
@@ -68,7 +68,7 @@ describe('createSessionService', () => {
|
|
|
68
68
|
sessionStorage: storage,
|
|
69
69
|
sessionRepository: repository,
|
|
70
70
|
deviceIdService,
|
|
71
|
-
|
|
71
|
+
lxIdentifierService,
|
|
72
72
|
})
|
|
73
73
|
})
|
|
74
74
|
|
|
@@ -103,7 +103,7 @@ describe('createSessionService', () => {
|
|
|
103
103
|
sessionStorage: storage,
|
|
104
104
|
sessionRepository: repository,
|
|
105
105
|
deviceIdService,
|
|
106
|
-
|
|
106
|
+
lxIdentifierService,
|
|
107
107
|
})
|
|
108
108
|
|
|
109
109
|
await service.initSession()
|
|
@@ -178,7 +178,7 @@ describe('createSessionService', () => {
|
|
|
178
178
|
sessionStorage: storage,
|
|
179
179
|
sessionRepository: repository,
|
|
180
180
|
deviceIdService,
|
|
181
|
-
|
|
181
|
+
lxIdentifierService,
|
|
182
182
|
})
|
|
183
183
|
|
|
184
184
|
expect(await service2.getSessionState()).toEqual({ sessionId: 'test-session-123' })
|
|
@@ -201,7 +201,7 @@ describe('createSessionService', () => {
|
|
|
201
201
|
sessionStorage: storage2,
|
|
202
202
|
sessionRepository: repository,
|
|
203
203
|
deviceIdService,
|
|
204
|
-
|
|
204
|
+
lxIdentifierService,
|
|
205
205
|
})
|
|
206
206
|
|
|
207
207
|
await service.initSession()
|
|
@@ -326,8 +326,8 @@ describe('createSessionService', () => {
|
|
|
326
326
|
})
|
|
327
327
|
})
|
|
328
328
|
|
|
329
|
-
describe('
|
|
330
|
-
it('persists
|
|
329
|
+
describe('uniswap identifier handling', () => {
|
|
330
|
+
it('persists lxIdentifier when provided in extra', async () => {
|
|
331
331
|
repository.initSession = async (): Promise<{
|
|
332
332
|
sessionId?: string
|
|
333
333
|
needChallenge: boolean
|
|
@@ -335,14 +335,14 @@ describe('createSessionService', () => {
|
|
|
335
335
|
}> => ({
|
|
336
336
|
sessionId: 'test-session-123',
|
|
337
337
|
needChallenge: false,
|
|
338
|
-
extra: {
|
|
338
|
+
extra: { lxIdentifier: '71cef16f-4d99-4082-987c-a6f810f9ca7f' },
|
|
339
339
|
})
|
|
340
340
|
|
|
341
341
|
await service.initSession()
|
|
342
|
-
expect(await
|
|
342
|
+
expect(await lxIdentifierService.getLxIdentifier()).toBe('71cef16f-4d99-4082-987c-a6f810f9ca7f')
|
|
343
343
|
})
|
|
344
344
|
|
|
345
|
-
it('does not persist
|
|
345
|
+
it('does not persist lxIdentifier when not provided', async () => {
|
|
346
346
|
repository.initSession = async (): Promise<{
|
|
347
347
|
sessionId?: string
|
|
348
348
|
needChallenge: boolean
|
|
@@ -354,10 +354,10 @@ describe('createSessionService', () => {
|
|
|
354
354
|
})
|
|
355
355
|
|
|
356
356
|
await service.initSession()
|
|
357
|
-
expect(await
|
|
357
|
+
expect(await lxIdentifierService.getLxIdentifier()).toBeNull()
|
|
358
358
|
})
|
|
359
359
|
|
|
360
|
-
it('updates
|
|
360
|
+
it('updates lxIdentifier on subsequent initSession calls', async () => {
|
|
361
361
|
repository.initSession = async (): Promise<{
|
|
362
362
|
sessionId?: string
|
|
363
363
|
needChallenge: boolean
|
|
@@ -365,11 +365,11 @@ describe('createSessionService', () => {
|
|
|
365
365
|
}> => ({
|
|
366
366
|
sessionId: 'test-session-123',
|
|
367
367
|
needChallenge: false,
|
|
368
|
-
extra: {
|
|
368
|
+
extra: { lxIdentifier: 'first-identifier' },
|
|
369
369
|
})
|
|
370
370
|
|
|
371
371
|
await service.initSession()
|
|
372
|
-
expect(await
|
|
372
|
+
expect(await lxIdentifierService.getLxIdentifier()).toBe('first-identifier')
|
|
373
373
|
|
|
374
374
|
repository.initSession = async (): Promise<{
|
|
375
375
|
sessionId?: string
|
|
@@ -378,11 +378,11 @@ describe('createSessionService', () => {
|
|
|
378
378
|
}> => ({
|
|
379
379
|
sessionId: 'test-session-456',
|
|
380
380
|
needChallenge: false,
|
|
381
|
-
extra: {
|
|
381
|
+
extra: { lxIdentifier: 'second-identifier' },
|
|
382
382
|
})
|
|
383
383
|
|
|
384
384
|
await service.initSession()
|
|
385
|
-
expect(await
|
|
385
|
+
expect(await lxIdentifierService.getLxIdentifier()).toBe('second-identifier')
|
|
386
386
|
})
|
|
387
387
|
})
|
|
388
388
|
})
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { DeviceIdService } from '@
|
|
2
|
-
import type { SessionRepository } from '@
|
|
1
|
+
import type { DeviceIdService } from '@luxexchange/sessions/src/device-id/types'
|
|
2
|
+
import type { SessionRepository } from '@luxexchange/sessions/src/session-repository/types'
|
|
3
3
|
import type {
|
|
4
4
|
ChallengeRequest,
|
|
5
5
|
ChallengeResponse,
|
|
@@ -7,9 +7,9 @@ import type {
|
|
|
7
7
|
SessionService,
|
|
8
8
|
VerifySessionRequest,
|
|
9
9
|
VerifySessionResponse,
|
|
10
|
-
} from '@
|
|
11
|
-
import type { SessionStorage } from '@
|
|
12
|
-
import type {
|
|
10
|
+
} from '@luxexchange/sessions/src/session-service/types'
|
|
11
|
+
import type { SessionStorage } from '@luxexchange/sessions/src/session-storage/types'
|
|
12
|
+
import type { LxIdentifierService } from '@luxexchange/sessions/src/uniswap-identifier/types'
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Creates a Session Service instance.
|
|
@@ -18,7 +18,7 @@ import type { LuxIdentifierService } from '@universe/sessions/src/lux-identifier
|
|
|
18
18
|
export function createSessionService(ctx: {
|
|
19
19
|
sessionStorage: SessionStorage
|
|
20
20
|
deviceIdService: DeviceIdService
|
|
21
|
-
|
|
21
|
+
lxIdentifierService: LxIdentifierService
|
|
22
22
|
sessionRepository: SessionRepository
|
|
23
23
|
}): SessionService {
|
|
24
24
|
async function initSession(): Promise<InitSessionResponse> {
|
|
@@ -29,8 +29,8 @@ export function createSessionService(ctx: {
|
|
|
29
29
|
if (result.deviceId) {
|
|
30
30
|
await ctx.deviceIdService.setDeviceId(result.deviceId)
|
|
31
31
|
}
|
|
32
|
-
if (result.extra['
|
|
33
|
-
await ctx.
|
|
32
|
+
if (result.extra['lxIdentifier']) {
|
|
33
|
+
await ctx.lxIdentifierService.setLxIdentifier(result.extra['lxIdentifier'])
|
|
34
34
|
}
|
|
35
35
|
return result
|
|
36
36
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ChallengeType } from '@
|
|
2
|
-
import type { TypedChallengeData } from '@
|
|
3
|
-
import { SessionState } from '@
|
|
1
|
+
import { ChallengeType } from '@luxamm/client-platform-service/dist/uniswap/platformservice/v1/sessionService_pb'
|
|
2
|
+
import type { TypedChallengeData } from '@luxexchange/sessions/src/session-repository/types'
|
|
3
|
+
import { SessionState } from '@luxexchange/sessions/src/session-storage/types'
|
|
4
4
|
|
|
5
5
|
interface InitSessionResponse {
|
|
6
6
|
sessionId?: string
|