@open-wa/wa-automate 4.28.0 → 4.28.4
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/dist/api/Client.d.ts +1 -1
- package/dist/api/Client.js +6 -3
- package/dist/cli/setup.js +1 -1
- package/dist/controllers/auth.js +3 -4
- package/dist/controllers/browser.d.ts +1 -1
- package/dist/controllers/browser.js +6 -1
- package/dist/controllers/initializer.js +2 -2
- package/dist/logging/logging.js +11 -1
- package/dist/utils/tools.d.ts +2 -0
- package/dist/utils/tools.js +13 -1
- package/package.json +1 -1
package/dist/api/Client.d.ts
CHANGED
@@ -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
|
*
|
package/dist/api/Client.js
CHANGED
@@ -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 {
|
package/dist/cli/setup.js
CHANGED
@@ -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,
|
package/dist/controllers/auth.js
CHANGED
@@ -40,7 +40,6 @@ const tools_1 = require("../utils/tools");
|
|
40
40
|
const browser_1 = require("./browser");
|
41
41
|
const axios_1 = __importDefault(require("axios"));
|
42
42
|
const logging_1 = require("../logging/logging");
|
43
|
-
const timeout = ms => new Promise(resolve => setTimeout(resolve, ms, 'timeout'));
|
44
43
|
/**
|
45
44
|
* Validates if client is authenticated
|
46
45
|
* @returns true if is authenticated, false otherwise
|
@@ -131,8 +130,8 @@ function smartQr(waPage, config, spinner) {
|
|
131
130
|
qrNum++;
|
132
131
|
(0, tools_1.processSend)('ready');
|
133
132
|
if (config.qrMax && qrNum >= config.qrMax) {
|
134
|
-
spinner.info('QR Code limit reached, exiting');
|
135
|
-
yield (0, browser_1.kill)(waPage, null, true);
|
133
|
+
spinner.info('QR Code limit reached, exiting...');
|
134
|
+
yield (0, browser_1.kill)(waPage, null, true, null, "QR_LIMIT_REACHED");
|
136
135
|
}
|
137
136
|
if (config.ezqr || config.inDocker) {
|
138
137
|
const host = 'https://qr.openwa.cloud/';
|
@@ -168,7 +167,7 @@ function smartQr(waPage, config, spinner) {
|
|
168
167
|
const _hasDefaultStateYet = yield waPage.evaluate("!!(window.Store && window.Store.State && window.Store.State.Socket)");
|
169
168
|
if (!_hasDefaultStateYet) {
|
170
169
|
//expecting issue, take a screenshot then wait a few seconds before continuing
|
171
|
-
yield timeout(2000);
|
170
|
+
yield (0, tools_1.timeout)(2000);
|
172
171
|
}
|
173
172
|
return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
|
174
173
|
const funcName = '_smartQr';
|
@@ -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>;
|
@@ -43,6 +43,7 @@ const pico_s3_1 = require("pico-s3");
|
|
43
43
|
const puppeteer = require('puppeteer-extra');
|
44
44
|
const tree_kill_1 = __importDefault(require("tree-kill"));
|
45
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
|
+
reason
|
384
|
+
});
|
385
|
+
(0, tools_1.timeout)(3000);
|
381
386
|
const killBrowser = (browser) => __awaiter(void 0, void 0, void 0, function* () {
|
382
387
|
if (!browser)
|
383
388
|
return;
|
@@ -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:',
|
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:',
|
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/logging/logging.js
CHANGED
@@ -69,12 +69,22 @@ 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
|
});
|
package/dist/utils/tools.d.ts
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import { DataURL } from '../api/model';
|
2
2
|
import { AxiosRequestConfig } from 'axios';
|
3
|
+
export declare const timeout: (ms: any) => Promise<unknown>;
|
3
4
|
/**
|
4
5
|
* 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.
|
5
6
|
* @param useragent Your custom user agent
|
@@ -25,3 +26,4 @@ export declare const getDUrl: (url: string, optionsOverride?: AxiosRequestConfig
|
|
25
26
|
*/
|
26
27
|
export declare const base64MimeType: (dUrl: DataURL) => string;
|
27
28
|
export declare const processSend: (message: string) => void;
|
29
|
+
export declare const processSendData: (data?: any) => void;
|
package/dist/utils/tools.js
CHANGED
@@ -23,8 +23,12 @@ 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 = exports.timeout = void 0;
|
27
27
|
const axios_1 = __importDefault(require("axios"));
|
28
|
+
//@ts-ignore
|
29
|
+
process.send = process.send || function () { };
|
30
|
+
const timeout = ms => new Promise(resolve => setTimeout(resolve, ms, 'timeout'));
|
31
|
+
exports.timeout = timeout;
|
28
32
|
/**
|
29
33
|
* 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.
|
30
34
|
* @param useragent Your custom user agent
|
@@ -133,3 +137,11 @@ const processSend = (message) => {
|
|
133
137
|
return;
|
134
138
|
};
|
135
139
|
exports.processSend = processSend;
|
140
|
+
const processSendData = (data = {}) => {
|
141
|
+
process.send({
|
142
|
+
type: 'process:msg',
|
143
|
+
data
|
144
|
+
});
|
145
|
+
return;
|
146
|
+
};
|
147
|
+
exports.processSendData = processSendData;
|
package/package.json
CHANGED