@open-wa/wa-automate 4.27.9 → 4.28.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.
@@ -397,7 +397,7 @@ export declare class Client {
397
397
  * Shuts down the page and browser
398
398
  * @returns true
399
399
  */
400
- kill(): Promise<boolean>;
400
+ kill(reason?: string): Promise<boolean>;
401
401
  /**
402
402
  * This is a convinient method to click the `Use Here` button in the WA web session.
403
403
  *
@@ -68,7 +68,7 @@ const MessageCollector_1 = require("../structures/MessageCollector");
68
68
  const init_patch_1 = require("../controllers/init_patch");
69
69
  const preProcessors_1 = require("../structures/preProcessors");
70
70
  const tools_1 = require("../utils/tools");
71
- const logging_1 = require("../utils/logging");
71
+ const logging_1 = require("../logging/logging");
72
72
  /** @ignore */
73
73
  const pkg = (0, fs_extra_1.readJsonSync)(path.join(__dirname, '../../package.json'));
74
74
  var namespace;
@@ -267,7 +267,7 @@ class Client {
267
267
  if ((_b = this._createConfig) === null || _b === void 0 ? void 0 : _b.killClientOnLogout) {
268
268
  console.log("Session logged out. Killing client");
269
269
  logging_1.log.warn("Session logged out. Killing client");
270
- this.kill();
270
+ this.kill("LOGGED_OUT");
271
271
  }
272
272
  });
273
273
  }
@@ -290,7 +290,7 @@ class Client {
290
290
  if (!this._refreshing) {
291
291
  console.log("Browser page has closed. Killing client");
292
292
  logging_1.log.warn("Browser page has closed. Killing client");
293
- this.kill();
293
+ this.kill("PAGE_CLOSED");
294
294
  if ((_a = this._createConfig) === null || _a === void 0 ? void 0 : _a.killProcessOnBrowserClose)
295
295
  process.exit();
296
296
  }
@@ -1038,7 +1038,7 @@ class Client {
1038
1038
  * Shuts down the page and browser
1039
1039
  * @returns true
1040
1040
  */
1041
- kill() {
1041
+ kill(reason = "MANUALLY_KILLED") {
1042
1042
  var _a, _b, _c, _d, _e, _f, _g;
1043
1043
  return __awaiter(this, void 0, void 0, function* () {
1044
1044
  if (this._currentlyBeingKilled)
@@ -1046,6 +1046,9 @@ class Client {
1046
1046
  this._currentlyBeingKilled = true;
1047
1047
  console.log('Killing client. Shutting Down');
1048
1048
  logging_1.log.info('Killing client. Shutting Down');
1049
+ (0, tools_1.processSendData)({
1050
+ reason
1051
+ });
1049
1052
  const browser = yield ((_a = this === null || this === void 0 ? void 0 : this._page) === null || _a === void 0 ? void 0 : _a.browser());
1050
1053
  const pid = (browser === null || browser === void 0 ? void 0 : browser.process()) ? (_b = browser === null || browser === void 0 ? void 0 : browser.process()) === null || _b === void 0 ? void 0 : _b.pid : null;
1051
1054
  try {
@@ -1,6 +1,6 @@
1
1
  import { AxiosRequestConfig } from 'axios';
2
2
  import { PREPROCESSORS } from '../../structures/preProcessors';
3
- import { ConfigLogTransport } from '../../utils/logging';
3
+ import { ConfigLogTransport } from '../../logging/logging';
4
4
  import { Base64 } from "./aliases";
5
5
  import { SimpleListener } from './events';
6
6
  /**
package/dist/cli/setup.js CHANGED
@@ -43,7 +43,7 @@ const uuid_apikey_1 = __importDefault(require("uuid-apikey"));
43
43
  const events_1 = require("../controllers/events");
44
44
  const is_url_superb_1 = __importDefault(require("is-url-superb"));
45
45
  const path = __importStar(require("path"));
46
- const logging_1 = require("../utils/logging");
46
+ const logging_1 = require("../logging/logging");
47
47
  let checkUrl = url => typeof url === 'string' ? (0, is_url_superb_1.default)(url) : false;
48
48
  const configWithCases = (0, fs_extra_1.readJsonSync)(path.join(__dirname, '../../bin/config-schema.json'));
49
49
  const optionList = [{
@@ -273,7 +273,7 @@ const optionList = [{
273
273
  }
274
274
  ];
275
275
  exports.optionKeys = optionList.map(({ name }) => (0, tools_1.camelize)(name));
276
- exports.optionKeysWithDefalts = optionList.filter(o => o.hasOwnProperty('default')).map(({ name }) => (0, tools_1.camelize)(name));
276
+ exports.optionKeysWithDefalts = [...optionList.filter(o => o.hasOwnProperty('default')).map(({ name }) => (0, tools_1.camelize)(name)), 'popup'];
277
277
  exports.PrimitiveConverter = {
278
278
  Number: 1,
279
279
  Boolean: true,
@@ -39,7 +39,7 @@ const initializer_1 = require("./initializer");
39
39
  const tools_1 = require("../utils/tools");
40
40
  const browser_1 = require("./browser");
41
41
  const axios_1 = __importDefault(require("axios"));
42
- const logging_1 = require("../utils/logging");
42
+ const logging_1 = require("../logging/logging");
43
43
  const timeout = ms => new Promise(resolve => setTimeout(resolve, ms, 'timeout'));
44
44
  /**
45
45
  * Validates if client is authenticated
@@ -131,8 +131,9 @@ function smartQr(waPage, config, spinner) {
131
131
  qrNum++;
132
132
  (0, tools_1.processSend)('ready');
133
133
  if (config.qrMax && qrNum >= config.qrMax) {
134
- spinner.info('QR Code limit reached, exiting');
135
- yield (0, browser_1.kill)(waPage, null, true);
134
+ spinner.info('QR Code limit reached, exiting...');
135
+ yield timeout(3000);
136
+ yield (0, browser_1.kill)(waPage, null, true, null, "QR_LIMIT_REACHED");
136
137
  }
137
138
  if (config.ezqr || config.inDocker) {
138
139
  const host = 'https://qr.openwa.cloud/';
@@ -9,4 +9,4 @@ export declare function injectApi(page: Page): Promise<Page>;
9
9
  /**
10
10
  * @internal
11
11
  */
12
- export declare const kill: (p: Page, b?: Browser, exit?: boolean, pid?: number) => Promise<void>;
12
+ export declare const kill: (p: Page, b?: Browser, exit?: boolean, pid?: number, reason?: string) => Promise<void>;
@@ -42,7 +42,8 @@ const pico_s3_1 = require("pico-s3");
42
42
  // eslint-disable-next-line @typescript-eslint/no-var-requires
43
43
  const puppeteer = require('puppeteer-extra');
44
44
  const tree_kill_1 = __importDefault(require("tree-kill"));
45
- const logging_1 = require("../utils/logging");
45
+ const logging_1 = require("../logging/logging");
46
+ const tools_1 = require("../utils/tools");
46
47
  let browser;
47
48
  function initPage(sessionId, config, customUserAgent, spinner, _page, skipAuth) {
48
49
  var _a, _b, _c, _d, _e;
@@ -377,7 +378,11 @@ function getWAPage(browser) {
377
378
  /**
378
379
  * @internal
379
380
  */
380
- const kill = (p, b, exit, pid) => __awaiter(void 0, void 0, void 0, function* () {
381
+ const kill = (p, b, exit, pid, reason = "LAUNCH_KILL") => __awaiter(void 0, void 0, void 0, function* () {
382
+ (0, tools_1.processSendData)({
383
+ type: "close",
384
+ reason
385
+ });
381
386
  const killBrowser = (browser) => __awaiter(void 0, void 0, void 0, function* () {
382
387
  if (!browser)
383
388
  return;
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Spin = exports.EvEmitter = exports.ev = void 0;
7
7
  const eventemitter2_1 = require("eventemitter2");
8
8
  const spinnies_1 = __importDefault(require("spinnies"));
9
- const logging_1 = require("../utils/logging");
9
+ const logging_1 = require("../logging/logging");
10
10
  const spinner = {
11
11
  "interval": 80,
12
12
  "frames": [
@@ -61,7 +61,7 @@ const fs_extra_1 = require("fs-extra");
61
61
  const pico_s3_1 = require("pico-s3");
62
62
  const init_patch_1 = require("./init_patch");
63
63
  const patch_manager_1 = require("./patch_manager");
64
- const logging_1 = require("../utils/logging");
64
+ const logging_1 = require("../logging/logging");
65
65
  const timeout = (ms) => {
66
66
  return new Promise(resolve => setTimeout(resolve, ms, 'timeout'));
67
67
  };
@@ -367,12 +367,12 @@ function create(config = {}) {
367
367
  waPage.on('console', msg => {
368
368
  if (config === null || config === void 0 ? void 0 : config.logConsole)
369
369
  console.log(msg);
370
- logging_1.log.info('Page Console:', { msg });
370
+ logging_1.log.info('Page Console:', msg.text());
371
371
  });
372
372
  waPage.on('error', error => {
373
373
  if (config === null || config === void 0 ? void 0 : config.logConsoleErrors)
374
374
  console.error(error);
375
- logging_1.log.error('Page Console:', { error });
375
+ logging_1.log.error('Page Console Error:', error.text());
376
376
  });
377
377
  if (config === null || config === void 0 ? void 0 : config.restartOnCrash)
378
378
  waPage.on('error', (error) => __awaiter(this, void 0, void 0, function* () {
package/dist/index.d.ts CHANGED
@@ -4,6 +4,7 @@ export { create } from './controllers/initializer';
4
4
  export * from '@open-wa/wa-decrypt';
5
5
  export { ev, Spin } from './controllers/events';
6
6
  export * from './utils/tools';
7
+ export * from './logging/logging';
7
8
  export * from './structures/preProcessors';
8
9
  export * from './connect';
9
10
  export * from './build/build-postman';
package/dist/index.js CHANGED
@@ -20,6 +20,7 @@ var events_1 = require("./controllers/events");
20
20
  Object.defineProperty(exports, "ev", { enumerable: true, get: function () { return events_1.ev; } });
21
21
  Object.defineProperty(exports, "Spin", { enumerable: true, get: function () { return events_1.Spin; } });
22
22
  __exportStar(require("./utils/tools"), exports);
23
+ __exportStar(require("./logging/logging"), exports);
23
24
  __exportStar(require("./structures/preProcessors"), exports);
24
25
  __exportStar(require("./connect"), exports);
25
26
  //dont need to export this
File without changes
File without changes
@@ -0,0 +1,50 @@
1
+ import * as winston from 'winston';
2
+ /**
3
+ * You can access the log in your code and add your own custom transports
4
+ * https://github.com/winstonjs/winston#transports
5
+ * see [Logger](https://github.com/winstonjs/winston#transports) for more details.
6
+ *
7
+ * Here is an example of adding the GCP stackdriver transport:
8
+ *
9
+ * ```
10
+ * import { log } from '@open-wa/wa-automate'
11
+ * import { LoggingWinston } from '@google-cloud/logging-winston';
12
+ *
13
+ * const gcpTransport = new LoggingWinston({
14
+ * projectId: 'your-project-id',
15
+ * keyFilename: '/path/to/keyfile.json'
16
+ * });
17
+ *
18
+ * ...
19
+ * log.add(
20
+ * gcpTransport
21
+ * )
22
+ *
23
+ * //Congrats! Now all of your session logs will also go to GCP Stackdriver
24
+ * ```
25
+ */
26
+ export declare const log: winston.Logger;
27
+ export declare const addRotateFileLogTransport: (options?: any) => void;
28
+ /**
29
+ * @private
30
+ */
31
+ export declare const addSysLogTransport: (options?: any) => void;
32
+ export declare type ConfigLogTransport = {
33
+ /**
34
+ * The type of winston transport. At the moment only `file`, `console`, `ev` and `syslog` are supported.
35
+ */
36
+ type: 'syslog' | 'console' | 'file' | 'ev';
37
+ /**
38
+ * The options for the transport. Generally only required for syslog but you can use this to override default options for other types of transports.
39
+ */
40
+ options?: any;
41
+ /**
42
+ * If the transport has already been added to the logger. The logging set up command handles this for you.
43
+ * @readonly
44
+ */
45
+ done?: boolean;
46
+ };
47
+ /**
48
+ * @private
49
+ */
50
+ export declare const setupLogging: (logging: ConfigLogTransport[], sessionId?: string) => ConfigLogTransport[];
@@ -22,7 +22,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
22
22
  return (mod && mod.__esModule) ? mod : { "default": mod };
23
23
  };
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.setupLogging = exports.addRotateFileLogTransport = exports.log = void 0;
25
+ exports.setupLogging = exports.addSysLogTransport = exports.addRotateFileLogTransport = exports.log = void 0;
26
26
  const os_1 = __importDefault(require("os"));
27
27
  const winston = __importStar(require("winston"));
28
28
  const winston_daily_rotate_file_1 = __importDefault(require("winston-daily-rotate-file"));
@@ -69,17 +69,48 @@ function truncate(str, n) {
69
69
  return str.length > n ? str.substr(0, n - 1) + '...[TRUNCATED]...' : str;
70
70
  }
71
71
  const formatRedact = winston.format(redact);
72
+ const stringSaver = winston.format((info) => {
73
+ const copy = (0, full_1.klona)(info);
74
+ const splat = copy[Symbol.for("splat")];
75
+ if (splat) {
76
+ copy.message = `${copy.message} ${splat.filter((x) => typeof x !== 'object').join(' ')}`;
77
+ copy[Symbol.for("splat")] = splat.filter((x) => typeof x == 'object');
78
+ return copy;
79
+ }
80
+ return info;
81
+ });
72
82
  /**
73
83
  * To prevent "Attempt to write logs with no transports" error
74
84
  */
75
85
  const placeholderTransport = new custom_transport_1.NoOpTransport();
76
86
  const makeLogger = () => winston.createLogger({
77
- format: combine(timestamp(), winston.format.json(), formatRedact(), winston.format.splat(), winston.format.simple()),
87
+ format: combine(stringSaver(), timestamp(), winston.format.json(), formatRedact(), winston.format.splat(), winston.format.simple()),
78
88
  levels: winston.config.syslog.levels,
79
89
  transports: [placeholderTransport]
80
90
  });
81
91
  /**
82
92
  * You can access the log in your code and add your own custom transports
93
+ * https://github.com/winstonjs/winston#transports
94
+ * see [Logger](https://github.com/winstonjs/winston#transports) for more details.
95
+ *
96
+ * Here is an example of adding the GCP stackdriver transport:
97
+ *
98
+ * ```
99
+ * import { log } from '@open-wa/wa-automate'
100
+ * import { LoggingWinston } from '@google-cloud/logging-winston';
101
+ *
102
+ * const gcpTransport = new LoggingWinston({
103
+ * projectId: 'your-project-id',
104
+ * keyFilename: '/path/to/keyfile.json'
105
+ * });
106
+ *
107
+ * ...
108
+ * log.add(
109
+ * gcpTransport
110
+ * )
111
+ *
112
+ * //Congrats! Now all of your session logs will also go to GCP Stackdriver
113
+ * ```
83
114
  */
84
115
  exports.log = makeLogger();
85
116
  if (exports.log.warning && !exports.log.warn)
@@ -90,9 +121,13 @@ const addRotateFileLogTransport = (options = {}) => {
90
121
  exports.log.add(new winston_daily_rotate_file_1.default(Object.assign({ filename: 'application-%DATE%.log', datePattern: 'YYYY-MM-DD-HH', zippedArchive: true, maxSize: '2m', maxFiles: '14d' }, options)));
91
122
  };
92
123
  exports.addRotateFileLogTransport = addRotateFileLogTransport;
124
+ /**
125
+ * @private
126
+ */
93
127
  const addSysLogTransport = (options = {}) => {
94
128
  exports.log.add(new winston_syslog_1.Syslog(Object.assign({ localhost: os_1.default.hostname() }, options)));
95
129
  };
130
+ exports.addSysLogTransport = addSysLogTransport;
96
131
  const enableConsoleLogger = (options = {}) => {
97
132
  if (_consoleSet)
98
133
  return;
@@ -105,6 +140,9 @@ function enableLogToEv(options = {}) {
105
140
  exports.log.add(new custom_transport_1.LogToEvTransport(Object.assign({ format: winston.format.json() }, options)));
106
141
  _evSet = true;
107
142
  }
143
+ /**
144
+ * @private
145
+ */
108
146
  const setupLogging = (logging, sessionId = "session") => {
109
147
  const currentlySetup = [];
110
148
  const _logging = logging.map((l) => {
@@ -120,7 +158,7 @@ const setupLogging = (logging, sessionId = "session") => {
120
158
  (0, exports.addRotateFileLogTransport)(Object.assign({}, (l.options || {})));
121
159
  }
122
160
  else if (l.type === 'syslog') {
123
- addSysLogTransport(Object.assign(Object.assign({}, (l.options || {})), { appName: `owa-${sessionId}-${d}` }));
161
+ (0, exports.addSysLogTransport)(Object.assign(Object.assign({}, (l.options || {})), { appName: `owa-${sessionId}-${d}` }));
124
162
  }
125
163
  currentlySetup.push(l);
126
164
  return Object.assign(Object.assign({}, l), { done: true });
@@ -25,3 +25,4 @@ export declare const getDUrl: (url: string, optionsOverride?: AxiosRequestConfig
25
25
  */
26
26
  export declare const base64MimeType: (dUrl: DataURL) => string;
27
27
  export declare const processSend: (message: string) => void;
28
+ export declare const processSendData: (data?: any) => boolean;
@@ -23,7 +23,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
23
23
  return (mod && mod.__esModule) ? mod : { "default": mod };
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.processSend = exports.base64MimeType = exports.getDUrl = exports.isDataURL = exports.isBase64 = exports.camelize = exports.without = exports.getConfigFromProcessEnv = exports.smartUserAgent = void 0;
26
+ exports.processSendData = exports.processSend = exports.base64MimeType = exports.getDUrl = exports.isDataURL = exports.isBase64 = exports.camelize = exports.without = exports.getConfigFromProcessEnv = exports.smartUserAgent = void 0;
27
27
  const axios_1 = __importDefault(require("axios"));
28
28
  /**
29
29
  * Use this to generate a more likely valid user agent. It makes sure it has the WA part and replaces any windows or linux os info with mac.
@@ -133,3 +133,10 @@ const processSend = (message) => {
133
133
  return;
134
134
  };
135
135
  exports.processSend = processSend;
136
+ const processSendData = (data = {}) => {
137
+ return process.send({
138
+ type: 'process:msg',
139
+ data
140
+ });
141
+ };
142
+ exports.processSendData = processSendData;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-wa/wa-automate",
3
- "version": "4.27.9",
3
+ "version": "4.28.3",
4
4
  "licenseCheckUrl": "https://openwa.dev/license-check",
5
5
  "brokenMethodReportUrl": "https://openwa.dev/report-bm",
6
6
  "patches": "https://cdn.openwa.dev/patches.json",
@@ -1,18 +0,0 @@
1
- import * as winston from 'winston';
2
- /**
3
- * You can access the log in your code and add your own custom transports
4
- */
5
- export declare const log: winston.Logger;
6
- export declare const addRotateFileLogTransport: (options?: any) => void;
7
- export declare type ConfigLogTransport = {
8
- /**
9
- * The type of winston transport. At the moment only file, console, ev and syslog are supported.
10
- */
11
- type: 'syslog' | 'console' | 'file' | 'ev';
12
- /**
13
- * The options for the transport. Generally only required for syslog but you can use this to override default options for other types of transports.
14
- */
15
- options?: any;
16
- done?: boolean;
17
- };
18
- export declare const setupLogging: (logging: ConfigLogTransport[], sessionId?: string) => ConfigLogTransport[];