Skip to content

Commit

Permalink
Merge branch 'dev' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
storycraft committed Jun 23, 2021
2 parents 457358a + 3bd00aa commit 967d035
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion src/api/auth-api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface LoginData extends OAuthCredential {
/**
* User id
*/
userId: number | Long;
userId: Long;

/**
* Country iso
Expand Down
1 change: 1 addition & 0 deletions src/api/oauth-api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/api/struct/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions src/hook/session-factory-hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -36,8 +37,8 @@ export class HookedSessionFactory implements SessionFactory {

}

async connect(config: SessionConfig): AsyncCommandResult<ConnectionSession> {
const sessionRes = await this._factory.connect(config);
async connect(userId: Long, config: SessionConfig): AsyncCommandResult<ConnectionSession> {
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) };
Expand Down
3 changes: 2 additions & 1 deletion src/network/request-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -51,7 +52,7 @@ export interface PacketResData {
*/
export interface SessionFactory {

connect(config: SessionConfig): AsyncCommandResult<ConnectionSession>;
connect(userId: Long, config: SessionConfig): AsyncCommandResult<ConnectionSession>;

}

Expand Down
7 changes: 2 additions & 5 deletions src/network/util/loco-entrance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<CheckinRes> {
const checkinSession = new LocoSession(stream);

Expand All @@ -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<CheckinRes>('CHECKIN', req);
checkinSession.stream.close();

Expand Down
4 changes: 4 additions & 0 deletions src/oauth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/talk/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
9 changes: 5 additions & 4 deletions src/talk/network/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -33,7 +34,7 @@ export class TalkSessionFactory implements SessionFactory {
return getBookingData(bookingStream, config);
}

async getCheckin(config: CheckinConfig): AsyncCommandResult<CheckinRes> {
async getCheckin(userId: Long, config: CheckinConfig): AsyncCommandResult<CheckinRes> {
let checkinStream;
const checkinCrypto = await newCryptoStore(config.locoPEMPublicKey);
try {
Expand All @@ -56,11 +57,11 @@ export class TalkSessionFactory implements SessionFactory {
}), checkinCrypto);
}

return getCheckinData(checkinStream, config);
return getCheckinData(checkinStream, config, userId);
}

async connect(config: SessionConfig): AsyncCommandResult<ConnectionSession> {
const checkinRes = await this.getCheckin(config);
async connect(userId: Long, config: SessionConfig): AsyncCommandResult<ConnectionSession> {
const checkinRes = await this.getCheckin(userId, config);
if (!checkinRes.success) return checkinRes;

const locoStream = new LocoSecureLayer(await NetSocket.createTCPSocket({
Expand Down
4 changes: 2 additions & 2 deletions tests/network.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down

0 comments on commit 967d035

Please sign in to comment.