@open-wa/wa-automate 4.30.4 → 4.30.8
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.js +1 -1
- package/dist/cli/index.js +2 -2
- package/dist/cli/server.js +11 -3
- package/dist/controllers/browser.d.ts +2 -2
- package/dist/controllers/browser.js +16 -17
- package/dist/controllers/initializer.js +7 -2
- package/dist/utils/tools.d.ts +2 -1
- package/dist/utils/tools.js +2 -1
- package/package.json +3 -3
package/dist/api/Client.js
CHANGED
@@ -3393,7 +3393,7 @@ class Client {
|
|
3393
3393
|
const t = ((0, tools_1.now)() - whStart).toFixed(0);
|
3394
3394
|
logging_1.log.info("Client Webhook", event, status, t);
|
3395
3395
|
})
|
3396
|
-
.catch(err =>
|
3396
|
+
.catch(err => logging_1.log.error(`WEBHOOK ERROR: `, url, err.message));
|
3397
3397
|
}));
|
3398
3398
|
}));
|
3399
3399
|
}), 10000);
|
package/dist/cli/index.js
CHANGED
@@ -34,7 +34,7 @@ const ready = (config) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
34
|
sessionId: config.sessionId,
|
35
35
|
namespace: "READY"
|
36
36
|
}
|
37
|
-
}).catch(err =>
|
37
|
+
}).catch(err => index_1.log.error(`WEBHOOK ERROR: ${config.readyWebhook} ${err.message}`));
|
38
38
|
});
|
39
39
|
function start() {
|
40
40
|
return __awaiter(this, void 0, void 0, function* () {
|
@@ -93,7 +93,7 @@ function start() {
|
|
93
93
|
}).then(({ status }) => {
|
94
94
|
const t = ((0, index_1.now)() - whStart).toFixed(0);
|
95
95
|
index_1.log.info("EV Webhook", namespace, status, t);
|
96
|
-
}).catch(err =>
|
96
|
+
}).catch(err => index_1.log.error(`WEBHOOK ERROR: ${cliConfig.ev} ${err.message}`));
|
97
97
|
}));
|
98
98
|
}
|
99
99
|
//These things can be done before the client is created
|
package/dist/cli/server.js
CHANGED
@@ -232,7 +232,7 @@ const setupTwilioCompatibleWebhook = (cliConfig, client) => {
|
|
232
232
|
return yield client.sendText(message.from, msg['#']);
|
233
233
|
}
|
234
234
|
catch (error) {
|
235
|
-
|
235
|
+
__1.log.error("TWILIO-COMPAT WEBHOOK ERROR", url, error.message);
|
236
236
|
}
|
237
237
|
}));
|
238
238
|
};
|
@@ -365,8 +365,16 @@ const setupSocketServer = (cliConfig, client) => __awaiter(void 0, void 0, void
|
|
365
365
|
args = (0, parse_function_1.default)().parse(client[m]).args.map(argName => args[argName]);
|
366
366
|
else if (!args)
|
367
367
|
args = [];
|
368
|
-
|
369
|
-
|
368
|
+
try {
|
369
|
+
const data = yield client[m](...args);
|
370
|
+
callbacks[0](data);
|
371
|
+
}
|
372
|
+
catch (error) {
|
373
|
+
callbacks[0]({ error: {
|
374
|
+
message: error.message,
|
375
|
+
stack: error.stack || ""
|
376
|
+
} });
|
377
|
+
}
|
370
378
|
}
|
371
379
|
}
|
372
380
|
return;
|
@@ -7,8 +7,8 @@ export declare const deleteSessionData: (config: ConfigObject) => boolean;
|
|
7
7
|
export declare const getSessionDataFilePath: (sessionId: string, config: ConfigObject) => string | boolean;
|
8
8
|
export declare const addScript: (page: Page, js: string) => Promise<unknown>;
|
9
9
|
export declare function injectPreApiScripts(page: Page, spinner?: Spin): Promise<Page>;
|
10
|
-
export declare function injectWapi(page: Page, spinner?: Spin): Promise<Page>;
|
11
|
-
export declare function injectApi(page: Page, spinner?: Spin): Promise<Page>;
|
10
|
+
export declare function injectWapi(page: Page, spinner?: Spin, force?: boolean): Promise<Page>;
|
11
|
+
export declare function injectApi(page: Page, spinner?: Spin, force?: boolean): Promise<Page>;
|
12
12
|
/**
|
13
13
|
* @internal
|
14
14
|
*/
|
@@ -45,7 +45,7 @@ const promise_1 = __importDefault(require("terminate/promise"));
|
|
45
45
|
const logging_1 = require("../logging/logging");
|
46
46
|
const tools_1 = require("../utils/tools");
|
47
47
|
const auth_1 = require("./auth");
|
48
|
-
let browser;
|
48
|
+
let browser, wapiInjected = false, wapiAttempts = 1;
|
49
49
|
exports.BROWSER_START_TS = 0;
|
50
50
|
function initPage(sessionId, config, customUserAgent, spinner, _page, skipAuth) {
|
51
51
|
var _a, _b, _c, _d, _e;
|
@@ -280,30 +280,29 @@ function injectPreApiScripts(page, spinner) {
|
|
280
280
|
});
|
281
281
|
}
|
282
282
|
exports.injectPreApiScripts = injectPreApiScripts;
|
283
|
-
function injectWapi(page, spinner) {
|
283
|
+
function injectWapi(page, spinner, force = false) {
|
284
284
|
return __awaiter(this, void 0, void 0, function* () {
|
285
|
+
if (wapiInjected && !force)
|
286
|
+
return page;
|
287
|
+
const check = `window.WAPI && window.Store ? true : false`;
|
285
288
|
const wapi = yield (0, tools_1.timePromise)(() => (0, exports.addScript)(page, 'wapi.js'));
|
286
289
|
spinner === null || spinner === void 0 ? void 0 : spinner.info(`WAPI inject: ${wapi}ms`);
|
287
|
-
spinner === null || spinner === void 0 ? void 0 : spinner.info("Checking
|
288
|
-
|
289
|
-
yield page.waitForFunction(check
|
290
|
-
|
290
|
+
spinner === null || spinner === void 0 ? void 0 : spinner.info("Checking session integrity");
|
291
|
+
wapiAttempts++;
|
292
|
+
wapiInjected = !!(yield page.waitForFunction(check, { timeout: 3000, polling: 200 }).catch(e => false));
|
293
|
+
if (!wapiInjected) {
|
294
|
+
spinner === null || spinner === void 0 ? void 0 : spinner.info(`Session integrity check failed, trying again... ${wapiAttempts}`);
|
295
|
+
return yield injectWapi(page, spinner);
|
296
|
+
}
|
297
|
+
spinner === null || spinner === void 0 ? void 0 : spinner.info("Session integrity check passed");
|
298
|
+
return page;
|
291
299
|
});
|
292
300
|
}
|
293
301
|
exports.injectWapi = injectWapi;
|
294
|
-
function injectApi(page, spinner) {
|
302
|
+
function injectApi(page, spinner, force = false) {
|
295
303
|
return __awaiter(this, void 0, void 0, function* () {
|
296
304
|
yield injectPreApiScripts(page, spinner);
|
297
|
-
yield injectWapi(page, spinner);
|
298
|
-
// const wapi = await timePromise(()=>addScript(page,'wapi.js'))
|
299
|
-
// spinner?.info(`WAPI inject: ${wapi}ms`)
|
300
|
-
// await addScript(page,'wapi.js')
|
301
|
-
// await addScript(page,'wapi.js')
|
302
|
-
// await addScript(page,'wapi.js')
|
303
|
-
// await addScript(page,'wapi.js')
|
304
|
-
// await addScript(page,'wapi.js')
|
305
|
-
// await addScript(page,'wapi.js')
|
306
|
-
// await addScript(page,'wapi.js')
|
305
|
+
yield injectWapi(page, spinner, force);
|
307
306
|
const launch = yield (0, tools_1.timePromise)(() => (0, exports.addScript)(page, 'launch.js'));
|
308
307
|
spinner === null || spinner === void 0 ? void 0 : spinner.info(`Launch inject: ${launch}ms`);
|
309
308
|
return page;
|
@@ -303,7 +303,7 @@ function create(config = {}) {
|
|
303
303
|
}
|
304
304
|
const pre = canInjectEarly ? 'Rei' : 'I';
|
305
305
|
spinner.start(`${pre}njecting api`);
|
306
|
-
waPage = yield (0, browser_1.injectApi)(waPage, spinner);
|
306
|
+
waPage = yield (0, browser_1.injectApi)(waPage, spinner, true);
|
307
307
|
spinner.succeed(`WAPI ${pre}njected`);
|
308
308
|
if (canInjectEarly) {
|
309
309
|
//check if page is valid after 5 seconds
|
@@ -312,7 +312,7 @@ function create(config = {}) {
|
|
312
312
|
yield (0, exports.timeout)(5000);
|
313
313
|
}
|
314
314
|
//@ts-ignore
|
315
|
-
const VALID_SESSION = yield waPage.
|
315
|
+
const VALID_SESSION = yield waPage.waitForFunction(`window.Store && window.Store.Msg ? true : false`, { timeout: 9000, polling: 200 }).catch(e => false);
|
316
316
|
if (VALID_SESSION) {
|
317
317
|
/**
|
318
318
|
* Session is valid, attempt to preload patches
|
@@ -426,6 +426,11 @@ function create(config = {}) {
|
|
426
426
|
}
|
427
427
|
catch (error) {
|
428
428
|
spinner.emit(error.message);
|
429
|
+
logging_1.log.error(error.message);
|
430
|
+
if (error.stack) {
|
431
|
+
logging_1.log.error(error.stack);
|
432
|
+
console.error(error.stack);
|
433
|
+
}
|
429
434
|
yield (0, browser_1.kill)(waPage);
|
430
435
|
if (error.name === "ProtocolError" && ((_c = error.message) === null || _c === void 0 ? void 0 : _c.includes("Target closed"))) {
|
431
436
|
spinner.fail(error.message);
|
package/dist/utils/tools.d.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
/// <reference types="node" />
|
1
2
|
import { ConfigObject, DataURL } from '../api/model';
|
2
3
|
import { AxiosRequestConfig } from 'axios';
|
3
4
|
import { SessionInfo } from '../api/model/sessionInfo';
|
@@ -27,7 +28,7 @@ export declare const getDUrl: (url: string, optionsOverride?: AxiosRequestConfig
|
|
27
28
|
*/
|
28
29
|
export declare const base64MimeType: (dUrl: DataURL) => string;
|
29
30
|
export declare const processSend: (message: string) => void;
|
30
|
-
export declare const perf: () => DateConstructor | Performance;
|
31
|
+
export declare const perf: () => DateConstructor | import("perf_hooks").Performance;
|
31
32
|
export declare const now: () => number;
|
32
33
|
export declare function timePromise(fn: () => Promise<any>): Promise<string>;
|
33
34
|
export declare const processSendData: (data?: any) => void;
|
package/dist/utils/tools.js
CHANGED
@@ -26,6 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.generateGHIssueLink = exports.processSendData = exports.timePromise = exports.now = exports.perf = 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
28
|
const child_process_1 = require("child_process");
|
29
|
+
const perf_hooks_1 = require("perf_hooks");
|
29
30
|
//@ts-ignore
|
30
31
|
process.send = process.send || function () { };
|
31
32
|
const timeout = ms => new Promise(resolve => setTimeout(resolve, ms, 'timeout'));
|
@@ -138,7 +139,7 @@ const processSend = (message) => {
|
|
138
139
|
return;
|
139
140
|
};
|
140
141
|
exports.processSend = processSend;
|
141
|
-
const perf = () => performance || Date;
|
142
|
+
const perf = () => perf_hooks_1.performance || Date;
|
142
143
|
exports.perf = perf;
|
143
144
|
const now = () => (0, exports.perf)().now();
|
144
145
|
exports.now = now;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@open-wa/wa-automate",
|
3
|
-
"version": "4.30.
|
3
|
+
"version": "4.30.8",
|
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",
|
@@ -84,7 +84,6 @@
|
|
84
84
|
"auto-changelog": "^2.0.0",
|
85
85
|
"ava": "^3.13.0",
|
86
86
|
"changelog-parser": "^2.8.0",
|
87
|
-
"typeconv": "^1.7.0",
|
88
87
|
"command-line-args": "^5.1.1",
|
89
88
|
"eslint": "^8.1.0",
|
90
89
|
"husky": "^7.0.0",
|
@@ -96,9 +95,10 @@
|
|
96
95
|
"prettier": "^2.0.1",
|
97
96
|
"release-it": "^14.0.3",
|
98
97
|
"shelljs": "^0.8.3",
|
98
|
+
"tiny-glob": "^0.2.9",
|
99
99
|
"ts-node": "^10.0.0",
|
100
100
|
"tsc-watch": "^4.0.0",
|
101
|
-
"
|
101
|
+
"typeconv": "^1.7.0",
|
102
102
|
"typedoc": "^0.21.6",
|
103
103
|
"typedoc-plugin-pages": "^1.0.1",
|
104
104
|
"typescript": "^4.2.4"
|