From 55cd7ddc29f9f95086df32112cc2781b238ff691 Mon Sep 17 00:00:00 2001 From: EdamAme <121654029+EdamAme-x@users.noreply.github.com> Date: Sun, 21 Jan 2024 04:05:22 +0900 Subject: [PATCH] chore: format --- src/base/index.test.ts | 2 +- src/base/index.ts | 31 ++++++++++++++----------------- src/types.ts | 14 +++++++------- src/utils/is.test.ts | 10 +++++----- src/utils/is.ts | 7 +++---- src/utils/parse.test.ts | 18 ++++++++++-------- src/utils/parse.ts | 22 +++++++++++++++------- src/utils/uuid.test.ts | 1 - src/utils/uuid.ts | 11 ++++++----- 9 files changed, 61 insertions(+), 55 deletions(-) diff --git a/src/base/index.test.ts b/src/base/index.test.ts index 29a9b72..34a7e35 100644 --- a/src/base/index.test.ts +++ b/src/base/index.test.ts @@ -8,7 +8,7 @@ describe('PayPayError', () => { test('PayPay Fail', async () => { expect(await paypay.login()).toStrictEqual({ success: false, - status: PayPayStatus.LoginFailed + status: PayPayStatus.LoginFailed, }) }) }) diff --git a/src/base/index.ts b/src/base/index.ts index 6c02252..8cc764d 100644 --- a/src/base/index.ts +++ b/src/base/index.ts @@ -211,9 +211,7 @@ export class PayPay { 'resultCode' in result['header'] && 'resultMessage' in result['header'] ) { - if ( - result['header']['resultCode'] === 'S0001' - ) { + if (result['header']['resultCode'] === 'S0001') { // Refresh await this.login({ uuid: this.uuid, @@ -302,7 +300,7 @@ export class PayPay { return parseCreateLink(result, true) } - + async getLink(link: string): Promise { if (!this.isLogged()) { throw new PayPayError('Do not logged in', 2).fire() @@ -370,7 +368,7 @@ export class PayPay { } return parseReceiveLink(result, true) - }catch (_e) { + } catch (_e) { throw new PayPayError('Invalid link', 1).fire() } } @@ -410,7 +408,6 @@ export class PayPay { } async sendMoney(amount: number, external_id: string): Promise { - if (!this.isLogged()) { throw new PayPayError('Do not logged in', 2).fire() } @@ -437,7 +434,7 @@ export class PayPay { 'https://www.paypay.ne.jp/app/v2/p2p-api/executeP2PSendMoney', { method: 'POST', - body: JSON.stringify(ctx), + body: JSON.stringify(ctx), } ) @@ -446,22 +443,25 @@ export class PayPay { } if (result.header.resultCode === 'S9999') { - throw new PayPayError('You\'re not friends with user', 1).fire() + throw new PayPayError("You're not friends with user", 1).fire() } return parseAny(result, true) } - async request(path: 'getProfileDisplayInfo' | 'getPay2BalanceHistory' | 'getPaymentMethodList'): Promise { + async request( + path: 'getProfileDisplayInfo' | 'getPay2BalanceHistory' | 'getPaymentMethodList' + ): Promise { if (!this.isLogged()) { throw new PayPayError('Do not logged in', 2).fire() } const { response, result } = await this.baseFetch( `https://www.paypay.ne.jp/app/v2/bff/${path}`, - { - method: 'GET' - }) + { + method: 'GET', + } + ) if (!response.ok) { return parseAny(result, false) @@ -496,9 +496,7 @@ export class PayPayRecovery { public password: string public uuid: string - constructor( - code: string - ) { + constructor(code: string) { const object = unparseRecoveryCode(code) this.phone = object.phone this.password = object.password @@ -506,9 +504,8 @@ export class PayPayRecovery { } async recovery(): Promise { - const paypay = new PayPay(this.phone, this.password) - + const result = await paypay.login({ uuid: this.uuid, }) diff --git a/src/types.ts b/src/types.ts index 545c4b0..2ed8fa5 100644 --- a/src/types.ts +++ b/src/types.ts @@ -52,12 +52,12 @@ export type ReceiveLinkContext = { } export type SendMoneyContext = { - theme: string, - externalReceiverId: string, - amount: number, - requestId: string, - requestAt: string, - iosMinimumVersion: string, + theme: string + externalReceiverId: string + amount: number + requestId: string + requestAt: string + iosMinimumVersion: string androidMinimumVersion: string } @@ -190,4 +190,4 @@ export type ResponseAnyone = { [key: string]: Anyone } } -} \ No newline at end of file +} diff --git a/src/utils/is.test.ts b/src/utils/is.test.ts index 04699d4..6cafa07 100644 --- a/src/utils/is.test.ts +++ b/src/utils/is.test.ts @@ -37,10 +37,10 @@ describe('Util', () => { }, payload: { paypay: 'resultCode', - oosugi: 'dounikashite' - } + oosugi: 'dounikashite', + }, } - + const invalidSuccess = { header: { resultCode: 'S0001', @@ -48,8 +48,8 @@ describe('Util', () => { }, payload: { paypay: 'resultCode', - oosugi: 'dounikashite' - } + oosugi: 'dounikashite', + }, } expect(util.isSuccess(validSuccess)).toBeTruthy() diff --git a/src/utils/is.ts b/src/utils/is.ts index 8927e04..cf2f514 100644 --- a/src/utils/is.ts +++ b/src/utils/is.ts @@ -51,17 +51,16 @@ export function isUuid(uuid: string): boolean { return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(uuid) } - export function isSuccess(raw: { header: { resultCode: string resultMessage: string - }, + } payload: Anyone }): boolean { try { return raw.header.resultCode === 'S0000' - }catch (e) { + } catch (e) { return false } -} \ No newline at end of file +} diff --git a/src/utils/parse.test.ts b/src/utils/parse.test.ts index 707d948..1b6c040 100644 --- a/src/utils/parse.test.ts +++ b/src/utils/parse.test.ts @@ -16,7 +16,9 @@ describe('Util', () => { const password = 'ctkpaarR2' const uuid = 'a9b3d5c6-7d8e-9f0a-bcde-fghijk' - expect(util.parseRecoveryCode(phone, password, uuid)).toBe('eyJhbGcMDkwMTkxOTQ1NDU=.Y3RrcGFhclIy.YTliM2Q1YzYtN2Q4ZS05ZjBhLWJjZGUtZmdoaWpr') + expect(util.parseRecoveryCode(phone, password, uuid)).toBe( + 'eyJhbGcMDkwMTkxOTQ1NDU=.Y3RrcGFhclIy.YTliM2Q1YzYtN2Q4ZS05ZjBhLWJjZGUtZmdoaWpr' + ) }) test('unparseRecoveryCode', () => { @@ -37,8 +39,8 @@ describe('Util', () => { }, payload: { paypay: 'resultCode', - oosugi: 'dounikashite' - } + oosugi: 'dounikashite', + }, } expect(util.parseBalanceContext(failResponse, false)).toStrictEqual({ @@ -47,7 +49,7 @@ describe('Util', () => { total: 0, currency: 'JPY', updated_at: new Date(0).toISOString(), - raw: failResponse + raw: failResponse, }) }) @@ -59,8 +61,8 @@ describe('Util', () => { }, payload: { paypay: 'resultCode', - oosugi: 'dounikashite' - } + oosugi: 'dounikashite', + }, } expect(util.parseResultMessage(eg1)).toBe('Example 1') @@ -69,8 +71,8 @@ describe('Util', () => { header: {}, payload: { paypay: 'resultCode', - oosugi: 'dounikashite' - } + oosugi: 'dounikashite', + }, } expect(util.parseResultMessage(eg2)).toBe('unknown') diff --git a/src/utils/parse.ts b/src/utils/parse.ts index 0a2bce4..81850bb 100644 --- a/src/utils/parse.ts +++ b/src/utils/parse.ts @@ -1,5 +1,13 @@ import { PayPayError, isSuccess } from '..' -import type { Anyone, ResponseAnyone, ResponseBalance, ResponseCreateLink, ResponseGetLink, ResponseReceiveLink, ResponseUserInfo } from '../types' +import type { + Anyone, + ResponseAnyone, + ResponseBalance, + ResponseCreateLink, + ResponseGetLink, + ResponseReceiveLink, + ResponseUserInfo, +} from '../types' export function parseCookieFromMap(map: Map): string { return Array.from(map.entries()) @@ -62,7 +70,7 @@ export function parseBalanceContext(result: Anyone, success: boolean): ResponseB updated_at: new Date(0).toISOString(), raw: result, } - }catch (_e) { + } catch (_e) { return { success: false, message: parseResultMessage(result), @@ -92,7 +100,7 @@ export function parseUserInfoContext(result: Anyone, success: boolean): Response external_id: result.payload.external_id ?? 'unknown', raw: result, } - }catch (_e) { + } catch (_e) { return { success: false, message: parseResultMessage(result), @@ -124,7 +132,7 @@ export function parseCreateLink(result: Anyone, success: boolean): ResponseCreat expiry: result.payload.expiry ?? new Date(0).toISOString(), raw: result, } - }catch (_e) { + } catch (_e) { return { success: false, message: parseResultMessage(result), @@ -160,7 +168,7 @@ export function parseGetLink(result: Anyone, success: boolean): ResponseGetLink raw: result, } } - + return { success: success && isSuccess(result), message: parseResultMessage(result), @@ -179,7 +187,7 @@ export function parseGetLink(result: Anyone, success: boolean): ResponseGetLink photo_url: result.payload.sender.photoUrl ?? 'unknown', raw: result, } - }catch (_e) { + } catch (_e) { return { success: false, message: parseResultMessage(result), @@ -237,4 +245,4 @@ export function parseAny(result: Anyone, success: boolean): ResponseAnyone { raw: result, } } -} \ No newline at end of file +} diff --git a/src/utils/uuid.test.ts b/src/utils/uuid.test.ts index f68152b..1e13c30 100644 --- a/src/utils/uuid.test.ts +++ b/src/utils/uuid.test.ts @@ -2,7 +2,6 @@ import { isUuid } from './is' import { randomUUID } from './uuid' describe('UUIDError', () => { - test('UUID', async () => { expect(isUuid(randomUUID())).toBeTruthy() }) diff --git a/src/utils/uuid.ts b/src/utils/uuid.ts index eee8977..2e949d7 100644 --- a/src/utils/uuid.ts +++ b/src/utils/uuid.ts @@ -1,6 +1,7 @@ export function randomUUID() { - return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (a) => { - const r = (new Date().getTime() + Math.random() * 16) % 16 | 0, v = a == 'x' ? r : (r & 0x3 | 0x8) - return v.toString(16) - }) -} \ No newline at end of file + return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (a) => { + const r = (new Date().getTime() + Math.random() * 16) % 16 | 0, + v = a == 'x' ? r : (r & 0x3) | 0x8 + return v.toString(16) + }) +}