@rich-automation/lotto 0.1.2 → 0.1.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.
@@ -45,14 +45,14 @@ class PuppeteerController {
45
45
  const pages = yield browser.pages();
46
46
  if (pages.length === 0) {
47
47
  const page = yield browser.newPage();
48
- return new puppeteer_page_1.PuppeteerPage(page);
48
+ return new puppeteer_page_1.PuppeteerPage(page, this.logger);
49
49
  }
50
50
  else {
51
51
  const isWithinRange = Math.max(0, Math.min(pageIndex, pages.length - 1)) === pageIndex;
52
52
  const page = pages.at(isWithinRange ? pageIndex : -1);
53
53
  if (!page)
54
54
  throw new Error('Page is not found');
55
- return new puppeteer_page_1.PuppeteerPage(page);
55
+ return new puppeteer_page_1.PuppeteerPage(page, this.logger);
56
56
  }
57
57
  });
58
58
  this.close = () => __awaiter(this, void 0, void 0, function* () {
@@ -13,7 +13,9 @@ exports.PuppeteerPage = void 0;
13
13
  const deferred_1 = require("../../utils/deferred");
14
14
  const lazyRun_1 = require("../../utils/lazyRun");
15
15
  class PuppeteerPage {
16
- constructor(page) {
16
+ constructor(page, logger) {
17
+ this.page = page;
18
+ this.logger = logger;
17
19
  this.page = page;
18
20
  }
19
21
  url() {
@@ -32,9 +34,11 @@ class PuppeteerPage {
32
34
  });
33
35
  }
34
36
  click(selector, useWaitForSelector = false) {
37
+ var _a;
35
38
  return __awaiter(this, void 0, void 0, function* () {
36
39
  if (useWaitForSelector) {
37
40
  const handle = yield this.page.waitForSelector(selector, { timeout: 15000 });
41
+ (_a = this.logger) === null || _a === void 0 ? void 0 : _a.debug('[PuppeteerPage]', '[click]', 'handle', handle);
38
42
  handle === null || handle === void 0 ? void 0 : handle.click();
39
43
  }
40
44
  else {
@@ -110,7 +110,7 @@ class LottoService {
110
110
  yield page.click(selectors_1.SELECTORS.PURCHASE_TYPE_RANDOM_BTN);
111
111
  // set and confirm amount
112
112
  const amountString = String(Math.max(1, Math.min(5, amount)));
113
- this.logger.debug('[purchase]', `select purchase amount${amountString} -> amount confirm`);
113
+ this.logger.debug('[purchase]', `select purchase amount(${amountString}) -> amount confirm`);
114
114
  yield page.select(selectors_1.SELECTORS.PURCHASE_AMOUNT_SELECT, amountString);
115
115
  yield page.click(selectors_1.SELECTORS.PURCHASE_AMOUNT_CONFIRM_BTN);
116
116
  // click purchase button
@@ -40,14 +40,14 @@ export class PuppeteerController {
40
40
  const pages = yield browser.pages();
41
41
  if (pages.length === 0) {
42
42
  const page = yield browser.newPage();
43
- return new PuppeteerPage(page);
43
+ return new PuppeteerPage(page, this.logger);
44
44
  }
45
45
  else {
46
46
  const isWithinRange = Math.max(0, Math.min(pageIndex, pages.length - 1)) === pageIndex;
47
47
  const page = pages.at(isWithinRange ? pageIndex : -1);
48
48
  if (!page)
49
49
  throw new Error('Page is not found');
50
- return new PuppeteerPage(page);
50
+ return new PuppeteerPage(page, this.logger);
51
51
  }
52
52
  });
53
53
  this.close = () => __awaiter(this, void 0, void 0, function* () {
@@ -11,7 +11,9 @@ import { Page } from 'puppeteer';
11
11
  import { deferred } from '../../utils/deferred';
12
12
  import { lazyRun } from '../../utils/lazyRun';
13
13
  export class PuppeteerPage {
14
- constructor(page) {
14
+ constructor(page, logger) {
15
+ this.page = page;
16
+ this.logger = logger;
15
17
  this.page = page;
16
18
  }
17
19
  url() {
@@ -30,9 +32,11 @@ export class PuppeteerPage {
30
32
  });
31
33
  }
32
34
  click(selector, useWaitForSelector = false) {
35
+ var _a;
33
36
  return __awaiter(this, void 0, void 0, function* () {
34
37
  if (useWaitForSelector) {
35
38
  const handle = yield this.page.waitForSelector(selector, { timeout: 15000 });
39
+ (_a = this.logger) === null || _a === void 0 ? void 0 : _a.debug('[PuppeteerPage]', '[click]', 'handle', handle);
36
40
  handle === null || handle === void 0 ? void 0 : handle.click();
37
41
  }
38
42
  else {
@@ -104,7 +104,7 @@ export class LottoService {
104
104
  yield page.click(SELECTORS.PURCHASE_TYPE_RANDOM_BTN);
105
105
  // set and confirm amount
106
106
  const amountString = String(Math.max(1, Math.min(5, amount)));
107
- this.logger.debug('[purchase]', `select purchase amount${amountString} -> amount confirm`);
107
+ this.logger.debug('[purchase]', `select purchase amount(${amountString}) -> amount confirm`);
108
108
  yield page.select(SELECTORS.PURCHASE_AMOUNT_SELECT, amountString);
109
109
  yield page.click(SELECTORS.PURCHASE_AMOUNT_CONFIRM_BTN);
110
110
  // click purchase button
@@ -1,8 +1,10 @@
1
1
  import type { BrowserPageEvents, BrowserPageInterface, FakeDOMElement, StringifiedCookies } from '../../types';
2
2
  import { Page } from 'puppeteer';
3
+ import type { LoggerInterface } from '../../logger';
3
4
  export declare class PuppeteerPage implements BrowserPageInterface {
4
5
  page: Page;
5
- constructor(page: Page);
6
+ logger?: LoggerInterface | undefined;
7
+ constructor(page: Page, logger?: LoggerInterface | undefined);
6
8
  url(): Promise<string>;
7
9
  goto(url: string): Promise<void>;
8
10
  fill(selector: string, value: string | number): Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rich-automation/lotto",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Lotto module",
5
5
  "publishConfig": {
6
6
  "access": "public",