@open-wa/wa-automate 4.31.2 → 4.31.6
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/cli-options.js +12 -0
- package/dist/cli/index.js +2 -2
- package/dist/cli/setup.js +11 -2
- package/dist/controllers/browser.js +12 -7
- package/dist/controllers/patch_manager.js +1 -1
- package/package.json +1 -1
package/dist/api/Client.js
CHANGED
@@ -3395,7 +3395,7 @@ class Client {
|
|
3395
3395
|
const t = ((0, tools_1.now)() - whStart).toFixed(0);
|
3396
3396
|
logging_1.log.info("Client Webhook", event, status, t);
|
3397
3397
|
})
|
3398
|
-
.catch(err => logging_1.log.error(`WEBHOOK ERROR: `, url, err.message));
|
3398
|
+
.catch(err => logging_1.log.error(`CLIENT WEBHOOK ERROR: `, url, err.message));
|
3399
3399
|
}));
|
3400
3400
|
}));
|
3401
3401
|
}), 10000);
|
package/dist/cli/cli-options.js
CHANGED
@@ -38,6 +38,11 @@ exports.optionList = [{
|
|
38
38
|
typeLabel: '{blue {underline 8080}}',
|
39
39
|
description: "Set the port for the api. Default to 8002."
|
40
40
|
},
|
41
|
+
{
|
42
|
+
name: 'forcePort',
|
43
|
+
type: Number,
|
44
|
+
description: "Sometimes --port is overridden by environmental variables or the config file. Use this flag to force the port to be used."
|
45
|
+
},
|
41
46
|
{
|
42
47
|
name: 'api-host',
|
43
48
|
type: String,
|
@@ -59,6 +64,13 @@ exports.optionList = [{
|
|
59
64
|
typeLabel: '{yellow {underline https://webhook.site/....}}',
|
60
65
|
description: "Webhook to use for the listeners."
|
61
66
|
},
|
67
|
+
{
|
68
|
+
name: 'verbose',
|
69
|
+
alias: 'v',
|
70
|
+
default: false,
|
71
|
+
type: Boolean,
|
72
|
+
description: "Enable console transport for internal logger."
|
73
|
+
},
|
62
74
|
{
|
63
75
|
name: 'ev',
|
64
76
|
alias: 'e',
|
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 => index_1.log.error(`WEBHOOK ERROR: ${config.readyWebhook} ${err.message}`));
|
37
|
+
}).catch(err => index_1.log.error(`READY 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 => index_1.log.error(`WEBHOOK ERROR: ${cliConfig.ev} ${err.message}`));
|
96
|
+
}).catch(err => index_1.log.error(`EV 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/setup.js
CHANGED
@@ -161,11 +161,15 @@ const cli = () => {
|
|
161
161
|
cli_options_1.optionList.filter(option => option.default);
|
162
162
|
const cliConfig = Object.assign(Object.assign(Object.assign({ sessionId: "session" }, nonCliConfigs), _cli.flags), exports.optionKeysWithDefalts.reduce((p, c) => nonCliConfigs.hasOwnProperty(c) ? Object.assign(Object.assign({}, p), { [c]: nonCliConfigs[c] }) : p, {}));
|
163
163
|
//firstly set up logger
|
164
|
-
if (cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.logging) {
|
164
|
+
if ((cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.logging) || (cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.verbose)) {
|
165
|
+
if (!(cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.logging) && (cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.verbose))
|
166
|
+
cliConfig.logging = [];
|
167
|
+
if ((cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.logging) && !((cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.logging) || []).find(transport => transport.type === "console"))
|
168
|
+
cliConfig.logging.push({ type: 'console' });
|
165
169
|
if (Array.isArray(cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.logging))
|
166
170
|
cliConfig.logging = (0, logging_1.setupLogging)(cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.logging, `easy-api-${(cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.sessionId) || 'session'}`);
|
167
171
|
}
|
168
|
-
const PORT = Number(cliConfig.port || process.env.PORT || 8080);
|
172
|
+
const PORT = Number((typeof cliConfig.forcePort === "boolean" && cliConfig.forcePort ? process.env.PORT : cliConfig.forcePort) || cliConfig.port || process.env.PORT || 8080);
|
169
173
|
const spinner = new events_1.Spin(cliConfig.sessionId, 'STARTUP', cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.disableSpins);
|
170
174
|
const createConfig = Object.assign({}, cliConfig);
|
171
175
|
if (cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.session) {
|
@@ -234,7 +238,12 @@ const cli = () => {
|
|
234
238
|
if (cliConfig.apiHost) {
|
235
239
|
cliConfig.apiHost = cliConfig.apiHost.replace(/\/$/, '');
|
236
240
|
}
|
241
|
+
/**
|
242
|
+
* Check the port in the config
|
243
|
+
*/
|
244
|
+
cliConfig.port = PORT;
|
237
245
|
if (cliConfig.debug) {
|
246
|
+
spinner.succeed(`DEBUG - PORT: ${PORT}`);
|
238
247
|
spinner.succeed(`DEBUG - flags: ${JSON.stringify(cliConfig)}`);
|
239
248
|
const WA_ENV = {};
|
240
249
|
Object.keys(process.env).map(k => {
|
@@ -132,14 +132,19 @@ function initPage(sessionId, config, customUserAgent, spinner, _page, skipAuth)
|
|
132
132
|
if (interceptAuthentication || proxyAddr || blockCrashLogs || true) {
|
133
133
|
yield waPage.setRequestInterception(true);
|
134
134
|
waPage.on('response', (response) => __awaiter(this, void 0, void 0, function* () {
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
135
|
+
try {
|
136
|
+
if (response.request().url() == "https://web.whatsapp.com/") {
|
137
|
+
const t = yield response.text();
|
138
|
+
if (t.includes(`class="no-js"`) && t.includes(`self.`) && !dumbCache) {
|
139
|
+
//this is a valid response, save it for later
|
140
|
+
dumbCache = t;
|
141
|
+
logging_1.log.info("saving valid page to dumb cache");
|
142
|
+
}
|
141
143
|
}
|
142
144
|
}
|
145
|
+
catch (error) {
|
146
|
+
logging_1.log.error("dumb cache error", error);
|
147
|
+
}
|
143
148
|
}));
|
144
149
|
const authCompleteEv = new events_1.EvEmitter(sessionId, 'AUTH');
|
145
150
|
waPage.on('request', (request) => __awaiter(this, void 0, void 0, function* () {
|
@@ -304,7 +309,7 @@ const getSessionDataFilePath = (sessionId, config) => {
|
|
304
309
|
return false;
|
305
310
|
};
|
306
311
|
exports.getSessionDataFilePath = getSessionDataFilePath;
|
307
|
-
const addScript = (page, js) => __awaiter(void 0, void 0, void 0, function* () { return page.evaluate(yield script_preloader_1.scriptLoader.getScript(js)); });
|
312
|
+
const addScript = (page, js) => __awaiter(void 0, void 0, void 0, function* () { return page.evaluate(yield script_preloader_1.scriptLoader.getScript(js)).catch(e => logging_1.log.error(`Injection error: ${js}`, e)); });
|
308
313
|
exports.addScript = addScript;
|
309
314
|
// (page: Page, js : string) : Promise<unknown> => page.addScriptTag({
|
310
315
|
// path: require.resolve(path.join(__dirname, '../lib', js))
|
@@ -147,7 +147,7 @@ function getLicense(config, me, debugInfo, spinner) {
|
|
147
147
|
const hasSpin = !!spinner;
|
148
148
|
if (!spinner)
|
149
149
|
spinner = new events_1.Spin(config.sessionId || "session", "FETCH_LICENSE", config.disableSpins, true);
|
150
|
-
spinner === null || spinner === void 0 ? void 0 : spinner.start(`Fetching License: ${Array.isArray(config.licenseKey) ? config.licenseKey : config.licenseKey.indexOf("-") == -1 ? config.licenseKey.slice(-4) : config.licenseKey.split("-").slice(-1)[0]}`, hasSpin ? undefined : 2);
|
150
|
+
spinner === null || spinner === void 0 ? void 0 : spinner.start(`Fetching License: ${Array.isArray(config.licenseKey) ? config.licenseKey : typeof config.licenseKey === "string" ? config.licenseKey.indexOf("-") == -1 ? config.licenseKey.slice(-4) : config.licenseKey.split("-").slice(-1)[0] : config.licenseKey}`, hasSpin ? undefined : 2);
|
151
151
|
try {
|
152
152
|
const START = Date.now();
|
153
153
|
const { data } = yield axios_1.default.post(initializer_1.pkg.licenseCheckUrl, Object.assign({ key: config.licenseKey, number: me._serialized }, debugInfo));
|
package/package.json
CHANGED