Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.tabSize": 2
}
4 changes: 4 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
coverage:
status:
project: no
patch: no
2 changes: 1 addition & 1 deletion example/naver/printPaymentHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const printNaverPayHistory = async (id: string, password: string) => {
const module = NaverApp.ModuleFactory.create(page);
const crawlService = new NaverApp.Service(module);

await crawlService.login(id, password);
await crawlService.normalLogin(id, password);

const history = await crawlService.getHistory();
console.log(history);
Expand Down
56 changes: 56 additions & 0 deletions example/naver/reactivelyPrintPaymentHistory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import puppeteer from "puppeteer";
import { NaverApp } from "trackpurchase";

import readline from "readline";
import { concat, defer, filter, from, tap } from "rxjs";

const printNaverPayHistory = async (id: string, password: string) => {
const MOBILE_UA =
"Mozilla/5.0 (iPhone; CPU iPhone OS 15_1_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.1 Mobile/15E148 Safari/604.1";

const browser = await puppeteer.launch({
headless: false,
args: ["--start-maximized"],
});

const page = await browser.newPage();
await page.setViewport({ height: 800, width: 1200 });
await page.setUserAgent(MOBILE_UA);

const module = NaverApp.ModuleFactory.create(page);
const crawlService = new NaverApp.Service(module);

const loginEvent$ = crawlService.interactiveLogin(id, password);
const history$ = defer(() => from(crawlService.getHistory()));
const closePage$ = defer(() => from(page.close()));
const closeBrowser$ = defer(() => from(browser.close()));

const final$ = concat(loginEvent$, history$, closePage$, closeBrowser$).pipe(
tap((event) => {
if (event === "otp-required") {
console.log("스마트폰 앱에서 OTP 인증을 완료해주세요.");
}
}),
tap((event) => {
if (event === "manual-otp-required") {
rl.question("otp code: ", async (code) => {
module.pageInteractor.fillManualOTPInput(code);
});
}
}),
filter((event) => event instanceof Array)
);
final$.subscribe((event) => {
console.log(event);
});
};

const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
rl.question("Naver ID: ", (id) => {
rl.question("Naver Password: ", (password) => {
printNaverPayHistory(id, password);
});
});
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "trackpurchase",
"version": "0.1.14",
"version": "1.0.0",
"main": "dist/index.js",
"license": "MIT",
"repository": {
Expand All @@ -21,7 +21,11 @@
"preset": "jest-puppeteer",
"coveragePathIgnorePatterns": [
"dist/",
"elementParser.ts"
"elementParser.ts",
"pageInteractor.ts"
],
"testPathIgnorePatterns": [
"dist/"
]
},
"scripts": {
Expand All @@ -30,7 +34,8 @@
"build": "tsc -p ."
},
"dependencies": {
"puppeteer": "^12.0.1"
"puppeteer": "^12.0.1",
"rxjs": "^7.5.2"
},
"devDependencies": {
"@babel/core": "^7.16.5",
Expand Down
4 changes: 4 additions & 0 deletions src/app/naver/elementParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,8 @@ export default class ElementParser {
};
return paymentHistory;
}

async parseManualOTPInputElement() {
return await this.page.$("#otp");
}
}
3 changes: 2 additions & 1 deletion src/app/naver/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Module from "./module";
import ModuleFactory from "./moduleFactory";
import URLChanger from "./urlChanger";
import PageInteractor from "./pageInteractor";
import PageInteractor, { LoginEvent } from "./pageInteractor";
import ElementParser from "./elementParser";
import Service from "./service";

Expand All @@ -12,4 +12,5 @@ export {
PageInteractor,
ElementParser,
Service,
LoginEvent,
};
2 changes: 1 addition & 1 deletion src/app/naver/moduleFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { Module, URLChanger, ElementParser, PageInteractor } from ".";

export default class ModuleFactory {
static create(page: puppeteer.Page): Module {
const pageInteractor = new PageInteractor(page);
const urlChanger = new URLChanger(page);
const elementParser = new ElementParser(page);
const pageInteractor = new PageInteractor(page, elementParser);

return {
urlChanger,
Expand Down
Loading