diff --git a/package.json b/package.json index 39c73fa0..f08bb7b5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-kakao", - "version": "4.2.4", + "version": "4.3.0", "description": "Loco protocol compatible library", "main": "./dist/index.js", "exports": { diff --git a/src/api/auth-api-client.ts b/src/api/auth-api-client.ts index 573fe7c4..53147a4c 100644 --- a/src/api/auth-api-client.ts +++ b/src/api/auth-api-client.ts @@ -21,7 +21,7 @@ export interface LoginData extends OAuthCredential { /** * User id */ - userId: number | Long; + userId: Long; /** * Country iso diff --git a/src/api/oauth-api-client.ts b/src/api/oauth-api-client.ts index 5ba26edd..ec49a532 100644 --- a/src/api/oauth-api-client.ts +++ b/src/api/oauth-api-client.ts @@ -59,6 +59,7 @@ export class OAuthApiClient { result: { type: res['token_type'] as string, credential: { + userId: credential.userId, deviceUUID: credential.deviceUUID, accessToken: res['access_token'] as string, refreshToken: res['refresh_token'] as string diff --git a/src/api/struct/login.ts b/src/api/struct/login.ts index 6ecda584..1cfd9cb1 100644 --- a/src/api/struct/login.ts +++ b/src/api/struct/login.ts @@ -42,7 +42,7 @@ export interface AccessDataStruct { export function structToLoginData(struct: AccessDataStruct, deviceUUID: string): LoginData { return { - userId: struct.userId, + userId: Long.fromValue(struct.userId), countryIso: struct.countryIso, countryCode: struct.countryCode, diff --git a/src/hook/session-factory-hook.ts b/src/hook/session-factory-hook.ts index 44215435..a559b14b 100644 --- a/src/hook/session-factory-hook.ts +++ b/src/hook/session-factory-hook.ts @@ -4,6 +4,7 @@ * Copyright (c) storycraft. Licensed under the MIT Licence. */ +import { Long } from 'bson'; import { SessionConfig } from '../config'; import { ConnectionSession, PacketResData, SessionFactory } from '../network/request-session'; import { DefaultReq, AsyncCommandResult, DefaultRes } from '../request'; @@ -36,8 +37,8 @@ export class HookedSessionFactory implements SessionFactory { } - async connect(config: SessionConfig): AsyncCommandResult { - const sessionRes = await this._factory.connect(config); + async connect(userId: Long, config: SessionConfig): AsyncCommandResult { + const sessionRes = await this._factory.connect(userId, config); if (!sessionRes.success) return sessionRes; return { status: sessionRes.status, success: true, result: new InspectSession(sessionRes.result, this._hook) }; diff --git a/src/network/request-session.ts b/src/network/request-session.ts index 5582fe97..9e7d690e 100644 --- a/src/network/request-session.ts +++ b/src/network/request-session.ts @@ -10,6 +10,7 @@ import { BsonDataCodec } from '../packet'; import { PacketAssembler } from './packet-assembler'; import { BiStream } from '../stream'; import { LocoPacketCodec } from './loco-packet-codec'; +import { Long } from 'bson'; export interface CommandSession { @@ -51,7 +52,7 @@ export interface PacketResData { */ export interface SessionFactory { - connect(config: SessionConfig): AsyncCommandResult; + connect(userId: Long, config: SessionConfig): AsyncCommandResult; } diff --git a/src/network/util/loco-entrance.ts b/src/network/util/loco-entrance.ts index b9e2cfda..fdbade30 100644 --- a/src/network/util/loco-entrance.ts +++ b/src/network/util/loco-entrance.ts @@ -46,7 +46,7 @@ export async function getBookingData(stream: BiStream, config: BookingConfig): A export async function getCheckinData( stream: BiStream, config: CheckinConfig, - userId?: Long, + userId: Long, ): AsyncCommandResult { const checkinSession = new LocoSession(stream); @@ -58,12 +58,9 @@ export async function getCheckinData( 'ntype': config.netType, 'useSub': config.subDevice, 'os': config.agent, + userId }; - if (userId) { - req['userId'] = userId; - } - const res = await checkinSession.request('CHECKIN', req); checkinSession.stream.close(); diff --git a/src/oauth/index.ts b/src/oauth/index.ts index 6b7a8d75..6597be0a 100644 --- a/src/oauth/index.ts +++ b/src/oauth/index.ts @@ -4,8 +4,12 @@ * Copyright (c) storycraft. Licensed under the MIT Licence. */ +import { Long } from "bson"; + export interface OAuthCredential { + readonly userId: Long; + readonly deviceUUID: string; readonly accessToken: string; diff --git a/src/talk/client/index.ts b/src/talk/client/index.ts index 7a834b21..490bcc13 100644 --- a/src/talk/client/index.ts +++ b/src/talk/client/index.ts @@ -116,7 +116,7 @@ export class TalkClient if (this.logon) this.close(); // Create session stream - const sessionRes = await this._sessionFactory.connect(this.configuration); + const sessionRes = await this._sessionFactory.connect(credential.userId, this.configuration); if (!sessionRes.success) return sessionRes; this._session = sessionRes.result; diff --git a/src/talk/network/index.ts b/src/talk/network/index.ts index e2321ac5..ce10cdac 100644 --- a/src/talk/network/index.ts +++ b/src/talk/network/index.ts @@ -18,6 +18,7 @@ import { AsyncCommandResult, KnownDataStatusCode } from '../../request'; import * as NetSocket from '../../network/socket'; import { GetConfRes } from '../../packet/booking'; import { CheckinRes } from '../../packet/checkin'; +import { Long } from 'bson'; /** * Create loco stream by performing booking and checkin. @@ -33,7 +34,7 @@ export class TalkSessionFactory implements SessionFactory { return getBookingData(bookingStream, config); } - async getCheckin(config: CheckinConfig): AsyncCommandResult { + async getCheckin(userId: Long, config: CheckinConfig): AsyncCommandResult { let checkinStream; const checkinCrypto = await newCryptoStore(config.locoPEMPublicKey); try { @@ -56,11 +57,11 @@ export class TalkSessionFactory implements SessionFactory { }), checkinCrypto); } - return getCheckinData(checkinStream, config); + return getCheckinData(checkinStream, config, userId); } - async connect(config: SessionConfig): AsyncCommandResult { - const checkinRes = await this.getCheckin(config); + async connect(userId: Long, config: SessionConfig): AsyncCommandResult { + const checkinRes = await this.getCheckin(userId, config); if (!checkinRes.success) return checkinRes; const locoStream = new LocoSecureLayer(await NetSocket.createTCPSocket({ diff --git a/tests/network.test.ts b/tests/network.test.ts index e4597af4..1f7debfd 100644 --- a/tests/network.test.ts +++ b/tests/network.test.ts @@ -4,14 +4,14 @@ * Copyright (c) storycraft. Licensed under the MIT Licence. */ -import { DefaultConfiguration } from '../src'; +import { DefaultConfiguration, Long } from '../src'; import { TalkSessionFactory } from '../src/talk'; describe('Network', () => { it('Create loco session', async () => { const factory = new TalkSessionFactory(); - const res = await factory.connect(DefaultConfiguration); + const res = await factory.connect(Long.fromValue(Math.floor(Math.random() * 9999999)), DefaultConfiguration); if (!res.success) throw new Error(`Session creation failed with status: ${res.status}`); res.result.stream.close(); });