@rich-automation/lotto 0.0.4 → 0.1.0

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.
package/lib/cjs/index.js CHANGED
@@ -1,7 +1,24 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCurrentLottoRound = exports.LottoService = void 0;
17
+ exports.LogLevel = exports.getCurrentLottoRound = exports.LottoService = void 0;
4
18
  var lottoService_1 = require("./lottoService");
5
19
  Object.defineProperty(exports, "LottoService", { enumerable: true, get: function () { return lottoService_1.LottoService; } });
6
20
  var getCurrentLottoRound_1 = require("./utils/getCurrentLottoRound");
7
21
  Object.defineProperty(exports, "getCurrentLottoRound", { enumerable: true, get: function () { return getCurrentLottoRound_1.getCurrentLottoRound; } });
22
+ var logger_1 = require("./logger");
23
+ Object.defineProperty(exports, "LogLevel", { enumerable: true, get: function () { return logger_1.LogLevel; } });
24
+ __exportStar(require("./types"), exports);
@@ -99,35 +99,43 @@ class LottoService {
99
99
  this.purchase = (amount = 5) => __awaiter(this, void 0, void 0, function* () {
100
100
  if (!this.context.authenticated)
101
101
  throw lottoError_1.default.NotAuthenticated();
102
+ this.logger.debug('[purchase]', 'validatePurchaseAvailability');
102
103
  (0, validatePurchaseAvailability_1.validatePurchaseAvailability)();
103
104
  // move
105
+ this.logger.debug('[purchase]', 'move to lotto game page');
104
106
  const page = yield this.browserController.focus(0);
105
107
  yield page.goto(urls_1.URLS.LOTTO_645);
106
108
  // click auto button
109
+ this.logger.debug('[purchase]', 'click purchase type button -> auto');
107
110
  yield page.click(selectors_1.SELECTORS.PURCHASE_TYPE_RANDOM_BTN);
108
111
  // set and confirm amount
109
112
  const amountString = String(Math.max(1, Math.min(5, amount)));
113
+ this.logger.debug('[purchase]', `select purchase amount${amountString} -> amount confirm`);
110
114
  yield page.select(selectors_1.SELECTORS.PURCHASE_AMOUNT_SELECT, amountString);
111
115
  yield page.click(selectors_1.SELECTORS.PURCHASE_AMOUNT_CONFIRM_BTN);
112
116
  // click purchase button
117
+ this.logger.debug('[purchase]', 'click purchase button -> purchase confirm');
113
118
  yield page.click(selectors_1.SELECTORS.PURCHASE_BTN);
114
119
  yield page.click(selectors_1.SELECTORS.PURCHASE_CONFIRM_BTN);
115
120
  yield page.wait(1000);
116
121
  // game result
122
+ this.logger.debug('[purchase]', 'print result');
117
123
  return page.querySelectorAll(selectors_1.SELECTORS.PURCHASE_NUMBER_LIST, elems => {
118
124
  return elems.map(it => Array.from(it.children).map(child => Number(child.innerHTML)));
119
125
  });
120
126
  });
121
127
  this.check = (numbers, round = (0, getCurrentLottoRound_1.getCurrentLottoRound)()) => __awaiter(this, void 0, void 0, function* () {
122
128
  (0, validateLottoNumber_1.validateLottoNumber)(numbers);
129
+ this.logger.debug('[check]', 'getWinningNumbers');
123
130
  const winningNumbers = yield (0, getWinningNumbers_1.getWinningNumbers)(round);
124
131
  return (0, checkWinning_1.checkWinning)(numbers, winningNumbers);
125
132
  });
126
133
  this.getCheckWinningLink = (round, numbers) => {
134
+ this.logger.debug('[getCheckWinningLink]', 'getCheckWinningLink');
127
135
  return (0, getCheckWinningLink_1.getCheckWinningLink)(round, numbers);
128
136
  };
129
137
  this.logger = new logger_1.default(configs === null || configs === void 0 ? void 0 : configs.logLevel, '[LottoService]');
130
- this.browserController = (0, factory_1.createBrowserController)('puppeteer', Object.assign({ headless: false, defaultViewport: { width: 1080, height: 1024 } }, configs), this.logger);
138
+ this.browserController = (0, factory_1.createBrowserController)('puppeteer', Object.assign(Object.assign({ defaultViewport: { width: 1080, height: 1024 } }, configs), { headless: (configs === null || configs === void 0 ? void 0 : configs.headless) === false ? false : 'new' }), this.logger);
131
139
  }
132
140
  }
133
141
  exports.LottoService = LottoService;
@@ -0,0 +1 @@
1
+ {"type": "commonjs"}
package/lib/esm/index.js CHANGED
@@ -1,2 +1,4 @@
1
1
  export { LottoService } from './lottoService';
2
2
  export { getCurrentLottoRound } from './utils/getCurrentLottoRound';
3
+ export { LogLevel } from './logger';
4
+ export * from './types';
@@ -93,34 +93,42 @@ export class LottoService {
93
93
  this.purchase = (amount = 5) => __awaiter(this, void 0, void 0, function* () {
94
94
  if (!this.context.authenticated)
95
95
  throw LottoError.NotAuthenticated();
96
+ this.logger.debug('[purchase]', 'validatePurchaseAvailability');
96
97
  validatePurchaseAvailability();
97
98
  // move
99
+ this.logger.debug('[purchase]', 'move to lotto game page');
98
100
  const page = yield this.browserController.focus(0);
99
101
  yield page.goto(URLS.LOTTO_645);
100
102
  // click auto button
103
+ this.logger.debug('[purchase]', 'click purchase type button -> auto');
101
104
  yield page.click(SELECTORS.PURCHASE_TYPE_RANDOM_BTN);
102
105
  // set and confirm amount
103
106
  const amountString = String(Math.max(1, Math.min(5, amount)));
107
+ this.logger.debug('[purchase]', `select purchase amount${amountString} -> amount confirm`);
104
108
  yield page.select(SELECTORS.PURCHASE_AMOUNT_SELECT, amountString);
105
109
  yield page.click(SELECTORS.PURCHASE_AMOUNT_CONFIRM_BTN);
106
110
  // click purchase button
111
+ this.logger.debug('[purchase]', 'click purchase button -> purchase confirm');
107
112
  yield page.click(SELECTORS.PURCHASE_BTN);
108
113
  yield page.click(SELECTORS.PURCHASE_CONFIRM_BTN);
109
114
  yield page.wait(1000);
110
115
  // game result
116
+ this.logger.debug('[purchase]', 'print result');
111
117
  return page.querySelectorAll(SELECTORS.PURCHASE_NUMBER_LIST, elems => {
112
118
  return elems.map(it => Array.from(it.children).map(child => Number(child.innerHTML)));
113
119
  });
114
120
  });
115
121
  this.check = (numbers, round = getCurrentLottoRound()) => __awaiter(this, void 0, void 0, function* () {
116
122
  validateLottoNumber(numbers);
123
+ this.logger.debug('[check]', 'getWinningNumbers');
117
124
  const winningNumbers = yield getWinningNumbers(round);
118
125
  return checkWinning(numbers, winningNumbers);
119
126
  });
120
127
  this.getCheckWinningLink = (round, numbers) => {
128
+ this.logger.debug('[getCheckWinningLink]', 'getCheckWinningLink');
121
129
  return getCheckWinningLink(round, numbers);
122
130
  };
123
131
  this.logger = new Logger(configs === null || configs === void 0 ? void 0 : configs.logLevel, '[LottoService]');
124
- this.browserController = createBrowserController('puppeteer', Object.assign({ headless: false, defaultViewport: { width: 1080, height: 1024 } }, configs), this.logger);
132
+ this.browserController = createBrowserController('puppeteer', Object.assign(Object.assign({ defaultViewport: { width: 1080, height: 1024 } }, configs), { headless: (configs === null || configs === void 0 ? void 0 : configs.headless) === false ? false : 'new' }), this.logger);
125
133
  }
126
134
  }
@@ -0,0 +1 @@
1
+ {"type": "module"}
@@ -12,5 +12,5 @@ export declare class PuppeteerPage implements BrowserPageInterface {
12
12
  getCookies(): Promise<string>;
13
13
  setCookies(cookies: StringifiedCookies): Promise<void>;
14
14
  wait(param: 'idle' | 'load' | number): Promise<void>;
15
- on(event: BrowserPageEvents, callback: (...args: unknown[]) => void): () => import("puppeteer").EventEmitter;
15
+ on(event: BrowserPageEvents, callback: (...args: unknown[]) => void): () => Page;
16
16
  }
@@ -1,2 +1,4 @@
1
1
  export { LottoService } from './lottoService';
2
2
  export { getCurrentLottoRound } from './utils/getCurrentLottoRound';
3
+ export { LogLevel } from './logger';
4
+ export * from './types';
@@ -12,7 +12,7 @@ export interface LottoServiceInterface {
12
12
  }
13
13
  export interface BrowserConfigs {
14
14
  logLevel?: LogLevel;
15
- headless?: boolean;
15
+ headless?: boolean | 'new';
16
16
  defaultViewport?: {
17
17
  width: number;
18
18
  height: number;
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@rich-automation/lotto",
3
- "version": "0.0.4",
3
+ "version": "0.1.0",
4
4
  "description": "Lotto module",
5
5
  "publishConfig": {
6
- "access": "public"
6
+ "access": "public",
7
+ "registry": "https://registry.npmjs.org"
7
8
  },
8
9
  "contributors": [
9
10
  {
@@ -26,10 +27,12 @@
26
27
  "packageManager": "yarn@1.22.19",
27
28
  "scripts": {
28
29
  "prepack": "yarn build",
30
+ "release:ci": "release-it --ci --npm.skipChecks",
31
+ "release:ci:test": "release-it --ci --npm.skipChecks --dry-run",
29
32
  "start": "ts-node ./example/app",
30
33
  "build": "rm -rf lib && yarn build:cjs && yarn build:esm && yarn build:dts",
31
- "build:cjs": "tsc --project tsconfig.cjs.json --verbatimModuleSyntax false",
32
- "build:esm": "tsc --project tsconfig.esm.json",
34
+ "build:cjs": "tsc --project tsconfig.cjs.json --verbatimModuleSyntax false && echo '{\"type\": \"commonjs\"}' > lib/cjs/package.json",
35
+ "build:esm": "tsc --project tsconfig.esm.json && echo '{\"type\": \"module\"}' > lib/esm/package.json",
33
36
  "build:dts": "tsc --project tsconfig.json --emitDeclarationOnly --declaration --declarationDir lib/typescript",
34
37
  "test": "jest --forceExit --detectOpenHandles",
35
38
  "install:chrome": "node ./node_modules/puppeteer/install.js",
@@ -44,7 +47,7 @@
44
47
  "dependencies": {
45
48
  "axios": "^1.3.5",
46
49
  "dayjs": "^1.11.7",
47
- "puppeteer": "^19.8.5"
50
+ "puppeteer": "^20.5.0"
48
51
  },
49
52
  "devDependencies": {
50
53
  "@babel/core": "^7.21.4",