@open-wa/wa-automate 4.76.0 → 5.0.0-alpha.2
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/README.md +14 -165
- package/dist/cli-runtime-B7_3MM0c.cjs +798 -0
- package/dist/cli-runtime-B7_3MM0c.cjs.map +1 -0
- package/dist/cli-runtime-CmpYxFCk.d.cts +31 -0
- package/dist/cli-runtime-CmpYxFCk.d.cts.map +1 -0
- package/dist/cli.cjs +17 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +2 -0
- package/dist/index.cjs +224 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +81 -0
- package/dist/index.d.cts.map +1 -0
- package/package.json +34 -177
- package/CNAME +0 -1
- package/_tsconfig.docs.json +0 -140
- package/bin/config-schema.json +0 -1
- package/bin/oas-type-schemas.json +0 -1
- package/bin/server.js +0 -45
- package/build/build-config-json-for-bin.ts +0 -56
- package/build/generate-oas-types.ts +0 -31
- package/dist/api/Client.d.ts +0 -2255
- package/dist/api/Client.js +0 -4358
- package/dist/api/functions/exposed.enum.d.ts +0 -7
- package/dist/api/functions/exposed.enum.js +0 -11
- package/dist/api/model/aliases.d.ts +0 -110
- package/dist/api/model/aliases.js +0 -3
- package/dist/api/model/button.d.ts +0 -24
- package/dist/api/model/button.js +0 -2
- package/dist/api/model/call.d.ts +0 -51
- package/dist/api/model/call.js +0 -18
- package/dist/api/model/chat.d.ts +0 -221
- package/dist/api/model/chat.js +0 -52
- package/dist/api/model/config.d.ts +0 -836
- package/dist/api/model/config.js +0 -111
- package/dist/api/model/contact.d.ts +0 -143
- package/dist/api/model/contact.js +0 -2
- package/dist/api/model/errors.d.ts +0 -90
- package/dist/api/model/errors.js +0 -117
- package/dist/api/model/events.d.ts +0 -120
- package/dist/api/model/events.js +0 -127
- package/dist/api/model/group-metadata.d.ts +0 -124
- package/dist/api/model/group-metadata.js +0 -25
- package/dist/api/model/id.d.ts +0 -5
- package/dist/api/model/id.js +0 -2
- package/dist/api/model/index.d.ts +0 -110
- package/dist/api/model/index.js +0 -128
- package/dist/api/model/label.d.ts +0 -24
- package/dist/api/model/label.js +0 -2
- package/dist/api/model/media.d.ts +0 -93
- package/dist/api/model/media.js +0 -12
- package/dist/api/model/message.d.ts +0 -422
- package/dist/api/model/message.js +0 -40
- package/dist/api/model/product.d.ts +0 -141
- package/dist/api/model/product.js +0 -2
- package/dist/api/model/reactions.d.ts +0 -76
- package/dist/api/model/reactions.js +0 -2
- package/dist/api/model/sessionInfo.d.ts +0 -77
- package/dist/api/model/sessionInfo.js +0 -2
- package/dist/build/build-postman.d.ts +0 -1
- package/dist/build/build-postman.js +0 -262
- package/dist/cli/cli-options.d.ts +0 -9
- package/dist/cli/cli-options.js +0 -289
- package/dist/cli/collections.d.ts +0 -2
- package/dist/cli/collections.js +0 -251
- package/dist/cli/file-utils.d.ts +0 -1
- package/dist/cli/file-utils.js +0 -71
- package/dist/cli/index.d.ts +0 -1
- package/dist/cli/index.js +0 -231
- package/dist/cli/integrations/chatwoot.d.ts +0 -49
- package/dist/cli/integrations/chatwoot.js +0 -672
- package/dist/cli/integrations/cloudflare.d.ts +0 -6
- package/dist/cli/integrations/cloudflare.js +0 -76
- package/dist/cli/logo.d.ts +0 -1
- package/dist/cli/logo.js +0 -49
- package/dist/cli/server.d.ts +0 -24
- package/dist/cli/server.js +0 -540
- package/dist/cli/setup.d.ts +0 -30
- package/dist/cli/setup.js +0 -308
- package/dist/config/puppeteer.config.d.ts +0 -11
- package/dist/config/puppeteer.config.js +0 -65
- package/dist/controllers/auth.d.ts +0 -36
- package/dist/controllers/auth.js +0 -322
- package/dist/controllers/browser.d.ts +0 -17
- package/dist/controllers/browser.js +0 -603
- package/dist/controllers/events.d.ts +0 -82
- package/dist/controllers/events.js +0 -173
- package/dist/controllers/init_patch.d.ts +0 -13
- package/dist/controllers/init_patch.js +0 -42
- package/dist/controllers/initializer.d.ts +0 -22
- package/dist/controllers/initializer.js +0 -511
- package/dist/controllers/launch_checks.d.ts +0 -8
- package/dist/controllers/launch_checks.js +0 -130
- package/dist/controllers/patch_manager.d.ts +0 -37
- package/dist/controllers/patch_manager.js +0 -231
- package/dist/controllers/popup/index.d.ts +0 -3
- package/dist/controllers/popup/index.html +0 -168
- package/dist/controllers/popup/index.js +0 -148
- package/dist/controllers/script_preloader.d.ts +0 -17
- package/dist/controllers/script_preloader.js +0 -88
- package/dist/index.d.ts +0 -13
- package/dist/index.js +0 -36
- package/dist/lib/README.md +0 -5
- package/dist/lib/base64.js +0 -1
- package/dist/lib/hash.js +0 -1
- package/dist/lib/jsSha.min.js +0 -1
- package/dist/lib/launch.js +0 -1
- package/dist/lib/qr.min.js +0 -1
- package/dist/lib/wapi.js +0 -2163
- package/dist/logging/custom_transport.d.ts +0 -9
- package/dist/logging/custom_transport.js +0 -35
- package/dist/logging/logging.d.ts +0 -50
- package/dist/logging/logging.js +0 -196
- package/dist/structures/Collector.d.ts +0 -202
- package/dist/structures/Collector.js +0 -391
- package/dist/structures/Dialog.d.ts +0 -55
- package/dist/structures/Dialog.js +0 -21
- package/dist/structures/MessageCollector.d.ts +0 -78
- package/dist/structures/MessageCollector.js +0 -145
- package/dist/structures/preProcessors.d.ts +0 -58
- package/dist/structures/preProcessors.js +0 -181
- package/dist/utils/pid_utils.d.ts +0 -1
- package/dist/utils/pid_utils.js +0 -26
- package/dist/utils/tools.d.ts +0 -152
- package/dist/utils/tools.js +0 -494
- package/tos.md +0 -77
package/dist/controllers/auth.js
DELETED
|
@@ -1,322 +0,0 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
-
};
|
|
37
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.QRManager = exports.phoneIsOutOfReach = exports.sessionDataInvalid = exports.waitForRipeSession = exports.needsToScan = exports.isAuthenticated = void 0;
|
|
39
|
-
const qrcode = __importStar(require("qrcode-terminal"));
|
|
40
|
-
const rxjs_1 = require("rxjs");
|
|
41
|
-
const events_1 = require("./events");
|
|
42
|
-
const initializer_1 = require("./initializer");
|
|
43
|
-
const tools_1 = require("../utils/tools");
|
|
44
|
-
const browser_1 = require("./browser");
|
|
45
|
-
const axios_1 = __importDefault(require("axios"));
|
|
46
|
-
const logging_1 = require("../logging/logging");
|
|
47
|
-
const boxen_1 = __importDefault(require("boxen"));
|
|
48
|
-
/**
|
|
49
|
-
* isAuthenticated
|
|
50
|
-
* Validates if client is authenticated
|
|
51
|
-
* @returns true if is authenticated, false otherwise
|
|
52
|
-
* @param waPage
|
|
53
|
-
*/
|
|
54
|
-
const isAuthenticated = (waPage) => (0, rxjs_1.race)((0, exports.needsToScan)(waPage), isInsideChat(waPage), (0, exports.sessionDataInvalid)(waPage)).toPromise();
|
|
55
|
-
exports.isAuthenticated = isAuthenticated;
|
|
56
|
-
const needsToScan = (waPage) => {
|
|
57
|
-
return (0, rxjs_1.from)(new Promise((resolve) => __awaiter(void 0, void 0, void 0, function* () {
|
|
58
|
-
try {
|
|
59
|
-
/**
|
|
60
|
-
* TODO: COMMENTING OUT THE BELOW LINES MAY CAUSE A REGRESSION IN RELOGIN? REVERT IF NEEDED.
|
|
61
|
-
*/
|
|
62
|
-
// const raceResult = await Promise.race([
|
|
63
|
-
// waPage.waitForFunction('checkQrRefresh()', { timeout: 0, polling: 1000 }).catch(() => { }),
|
|
64
|
-
// await waPage
|
|
65
|
-
// .waitForSelector('body > div > div > .landing-wrapper', {
|
|
66
|
-
// timeout: 0
|
|
67
|
-
// }).catch(() => resolve(true))
|
|
68
|
-
// ]).catch(() => { })
|
|
69
|
-
// console.log("🚀 ~ needsToScan ~ raceResult:", raceResult)
|
|
70
|
-
const elementResult = yield Promise.race([
|
|
71
|
-
waPage.waitForSelector("canvas[aria-label='Scan this QR code to link a device!']", { timeout: 0 }).catch(() => { }),
|
|
72
|
-
waPage.waitForSelector("canvas[aria-label]", { timeout: 0 }).catch(() => { })
|
|
73
|
-
]);
|
|
74
|
-
logging_1.log.info("🚀 ~ needsToScan ~ elementResult:", elementResult);
|
|
75
|
-
resolve(false);
|
|
76
|
-
}
|
|
77
|
-
catch (error) {
|
|
78
|
-
console.log("needsToScan -> error", error);
|
|
79
|
-
logging_1.log.error("needsToScan -> error", error);
|
|
80
|
-
}
|
|
81
|
-
})));
|
|
82
|
-
};
|
|
83
|
-
exports.needsToScan = needsToScan;
|
|
84
|
-
const isInsideChat = (waPage) => {
|
|
85
|
-
return (0, rxjs_1.from)(waPage
|
|
86
|
-
.waitForFunction("!!window.WA_AUTHENTICATED || (document.getElementsByClassName('app')[0] && document.getElementsByClassName('app')[0].attributes && !!document.getElementsByClassName('app')[0].attributes.tabindex) || (document.getElementsByClassName('two')[0] && document.getElementsByClassName('two')[0].attributes && !!document.getElementsByClassName('two')[0].attributes.tabindex)", { timeout: 0 })
|
|
87
|
-
.then(() => true));
|
|
88
|
-
};
|
|
89
|
-
const isTosBlocked = (waPage) => {
|
|
90
|
-
return (0, rxjs_1.from)(waPage
|
|
91
|
-
.waitForFunction(`document.getElementsByTagName("html")[0].classList[0] === 'no-js'`, { timeout: 0 })
|
|
92
|
-
.then(() => false));
|
|
93
|
-
};
|
|
94
|
-
const waitForRipeSession = (waPage, waitForRipeSessionTimeout) => __awaiter(void 0, void 0, void 0, function* () {
|
|
95
|
-
try {
|
|
96
|
-
yield waPage.waitForFunction(`window.isRipeSession()`, { timeout: (waitForRipeSessionTimeout !== null && waitForRipeSessionTimeout !== void 0 ? waitForRipeSessionTimeout : 5) * 1000, polling: 1000 });
|
|
97
|
-
return true;
|
|
98
|
-
}
|
|
99
|
-
catch (error) {
|
|
100
|
-
return false;
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
exports.waitForRipeSession = waitForRipeSession;
|
|
104
|
-
const sessionDataInvalid = (waPage) => __awaiter(void 0, void 0, void 0, function* () {
|
|
105
|
-
const check = `Object.keys(localStorage).includes("old-logout-cred")`;
|
|
106
|
-
yield waPage
|
|
107
|
-
.waitForFunction(check, { timeout: 0, polling: 'mutation' });
|
|
108
|
-
// await injectApi(waPage, null, true);
|
|
109
|
-
// await waPage
|
|
110
|
-
// .waitForFunction(
|
|
111
|
-
// '!window.getQrPng',
|
|
112
|
-
// { timeout: 0, polling: 'mutation' }
|
|
113
|
-
// )
|
|
114
|
-
// await timeout(1000000)
|
|
115
|
-
//NEED A DIFFERENT WAY TO DETERMINE IF THE SESSION WAS LOGGED OUT!!!!
|
|
116
|
-
//if the code reaches here it means the browser was refreshed. Nuke the session data and restart `create`
|
|
117
|
-
return 'NUKE';
|
|
118
|
-
});
|
|
119
|
-
exports.sessionDataInvalid = sessionDataInvalid;
|
|
120
|
-
const phoneIsOutOfReach = (waPage) => __awaiter(void 0, void 0, void 0, function* () {
|
|
121
|
-
return yield waPage
|
|
122
|
-
.waitForFunction('document.querySelector("body").innerText.includes("Trying to reach phone")', { timeout: 0, polling: 'mutation' })
|
|
123
|
-
.then(() => true)
|
|
124
|
-
.catch(() => false);
|
|
125
|
-
});
|
|
126
|
-
exports.phoneIsOutOfReach = phoneIsOutOfReach;
|
|
127
|
-
class QRManager {
|
|
128
|
-
constructor(config = null) {
|
|
129
|
-
this.qrEv = null;
|
|
130
|
-
this.qrNum = 0;
|
|
131
|
-
this.hash = 'START';
|
|
132
|
-
this.config = null;
|
|
133
|
-
this.firstEmitted = false;
|
|
134
|
-
this._internalQrPngLoaded = false;
|
|
135
|
-
this.qrCheck = `document.querySelector("canvas[aria-label]")?document.querySelector("canvas[aria-label]").parentElement.getAttribute("data-ref"):false`;
|
|
136
|
-
this.config = config;
|
|
137
|
-
this.setConfig(this.config);
|
|
138
|
-
}
|
|
139
|
-
setConfig(config) {
|
|
140
|
-
this.config = config;
|
|
141
|
-
this.qrEvF(this.config);
|
|
142
|
-
}
|
|
143
|
-
qrEvF(config = this.config) {
|
|
144
|
-
// return new EvEmitter(config.sessionId || 'session', 'qr');
|
|
145
|
-
if (!this.qrEv)
|
|
146
|
-
this.qrEv = new events_1.EvEmitter(config.sessionId || 'session', 'qr');
|
|
147
|
-
return this.qrEv;
|
|
148
|
-
}
|
|
149
|
-
grabAndEmit(qrData, waPage, config, spinner) {
|
|
150
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
151
|
-
const isLinkCode = qrData.length === 9;
|
|
152
|
-
this.qrNum++;
|
|
153
|
-
if (config.qrMax && this.qrNum > config.qrMax) {
|
|
154
|
-
spinner.info('QR Code limit reached, exiting...');
|
|
155
|
-
yield (0, browser_1.kill)(waPage, null, true, null, "QR_LIMIT_REACHED");
|
|
156
|
-
}
|
|
157
|
-
const qrEv = this.qrEvF(config);
|
|
158
|
-
if ((!this.qrNum || this.qrNum == 1) && browser_1.BROWSER_START_TS)
|
|
159
|
-
spinner.info(`First QR: ${Date.now() - browser_1.BROWSER_START_TS} ms`);
|
|
160
|
-
if (qrData) {
|
|
161
|
-
qrEv.emit(qrData, `qrData`);
|
|
162
|
-
if (!config.qrLogSkip) {
|
|
163
|
-
if (isLinkCode) {
|
|
164
|
-
console.log((0, boxen_1.default)(qrData, { title: `ENTER THIS CODE ON THE HOST ACCOUNT DEVICE: ${config.sessionId}`, padding: 1, titleAlignment: 'center' }));
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
qrcode.generate(qrData, { small: true }, terminalQrCode => {
|
|
168
|
-
console.log((0, boxen_1.default)(terminalQrCode, { title: config.sessionId, padding: 1, titleAlignment: 'center' }));
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
else {
|
|
173
|
-
console.log(`New QR Code generated. Not printing in console because qrLogSkip is set to true`);
|
|
174
|
-
logging_1.log.info(`New QR Code generated. Not printing in console because qrLogSkip is set to true`);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
if (!this._internalQrPngLoaded) {
|
|
178
|
-
logging_1.log.info("Waiting for internal QR renderer to load");
|
|
179
|
-
const t = yield (0, tools_1.timePromise)(() => waPage.waitForFunction(`window.getQrPng || false`, { timeout: 0, polling: 'mutation' }));
|
|
180
|
-
logging_1.log.info(`Internal QR renderer loaded in ${t} ms`);
|
|
181
|
-
this._internalQrPngLoaded = true;
|
|
182
|
-
}
|
|
183
|
-
try {
|
|
184
|
-
const qrPng = isLinkCode ? qrData : yield waPage.evaluate(`window.getQrPng()`);
|
|
185
|
-
if (qrPng) {
|
|
186
|
-
qrEv.emit(qrPng);
|
|
187
|
-
(0, tools_1.processSend)('ready');
|
|
188
|
-
if (config.ezqr) {
|
|
189
|
-
const host = 'https://qr.openwa.cloud/';
|
|
190
|
-
yield axios_1.default.post(host, {
|
|
191
|
-
value: qrPng,
|
|
192
|
-
hash: this.hash
|
|
193
|
-
}).then(({ data }) => {
|
|
194
|
-
if (this.hash === 'START') {
|
|
195
|
-
const qrUrl = `${host}${data}`;
|
|
196
|
-
qrEv.emit(qrUrl, `qrUrl`);
|
|
197
|
-
console.log(`Scan the qr code at ${qrUrl}`);
|
|
198
|
-
logging_1.log.info(`Scan the qr code at ${qrUrl}`);
|
|
199
|
-
}
|
|
200
|
-
this.hash = data;
|
|
201
|
-
}).catch(e => {
|
|
202
|
-
console.error(e);
|
|
203
|
-
this.hash = 'START';
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
else {
|
|
208
|
-
spinner.info("Something went wrong while retreiving new the QR code but it should not affect the session launch procedure.");
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
catch (error) {
|
|
212
|
-
//@ts-ignore
|
|
213
|
-
const lr = yield waPage.evaluate("window.launchres");
|
|
214
|
-
console.log(lr);
|
|
215
|
-
logging_1.log.info('smartQr -> error', { lr });
|
|
216
|
-
spinner.info(`Something went wrong while retreiving new the QR code but it should not affect the session launch procedure: ${error.message}`);
|
|
217
|
-
}
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
linkCode(waPage, config, spinner) {
|
|
221
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
222
|
-
const evalResult = yield waPage.evaluate("window.Store && window.Store.State");
|
|
223
|
-
if (evalResult === false) {
|
|
224
|
-
console.log('Seems as though you have been TOS_BLOCKed, unable to refresh QR Code. Please see https://github.com/open-wa/wa-automate-nodejs#best-practice for information on how to prevent this from happeing. You will most likely not get a QR Code');
|
|
225
|
-
logging_1.log.warn('Seems as though you have been TOS_BLOCKed, unable to refresh QR Code. Please see https://github.com/open-wa/wa-automate-nodejs#best-practice for information on how to prevent this from happeing. You will most likely not get a QR Code');
|
|
226
|
-
if (config.throwErrorOnTosBlock)
|
|
227
|
-
throw new Error('TOSBLOCK');
|
|
228
|
-
}
|
|
229
|
-
const isAuthed = yield (0, exports.isAuthenticated)(waPage);
|
|
230
|
-
if (isAuthed)
|
|
231
|
-
return true;
|
|
232
|
-
const _hasDefaultStateYet = yield waPage.evaluate("!!(window.Store && window.Store.State && window.Store.State.Socket)");
|
|
233
|
-
if (!_hasDefaultStateYet) {
|
|
234
|
-
//expecting issue, take a screenshot then wait a few seconds before continuing
|
|
235
|
-
yield (0, tools_1.timeout)(2000);
|
|
236
|
-
}
|
|
237
|
-
spinner.info('Link Code requested, please use the link code to login from your host account device');
|
|
238
|
-
const linkCode = yield waPage.evaluate((number) => window['linkCode'](number), config === null || config === void 0 ? void 0 : config.linkCode);
|
|
239
|
-
spinner === null || spinner === void 0 ? void 0 : spinner.succeed(`Link Code please use this to login from your host account device: ${linkCode}`);
|
|
240
|
-
yield this.grabAndEmit(linkCode, waPage, config, spinner);
|
|
241
|
-
return yield isInsideChat(waPage).toPromise();
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
smartQr(waPage, config, spinner) {
|
|
245
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
246
|
-
const evalResult = yield waPage.evaluate("window.Store && window.Store.State");
|
|
247
|
-
if (evalResult === false) {
|
|
248
|
-
console.log('Seems as though you have been TOS_BLOCKed, unable to refresh QR Code. Please see https://github.com/open-wa/wa-automate-nodejs#best-practice for information on how to prevent this from happeing. You will most likely not get a QR Code');
|
|
249
|
-
logging_1.log.warn('Seems as though you have been TOS_BLOCKed, unable to refresh QR Code. Please see https://github.com/open-wa/wa-automate-nodejs#best-practice for information on how to prevent this from happeing. You will most likely not get a QR Code');
|
|
250
|
-
if (config.throwErrorOnTosBlock)
|
|
251
|
-
throw new Error('TOSBLOCK');
|
|
252
|
-
}
|
|
253
|
-
const isAuthed = yield (0, exports.isAuthenticated)(waPage);
|
|
254
|
-
if (isAuthed)
|
|
255
|
-
return true;
|
|
256
|
-
const _hasDefaultStateYet = yield waPage.evaluate("!!(window.Store && window.Store.State && window.Store.State.Socket)");
|
|
257
|
-
if (!_hasDefaultStateYet) {
|
|
258
|
-
//expecting issue, take a screenshot then wait a few seconds before continuing
|
|
259
|
-
yield (0, tools_1.timeout)(2000);
|
|
260
|
-
}
|
|
261
|
-
return new Promise((resolve) => __awaiter(this, void 0, void 0, function* () {
|
|
262
|
-
const funcName = '_smartQr';
|
|
263
|
-
const md = "MULTI_DEVICE_DETECTED";
|
|
264
|
-
let gotResult = false;
|
|
265
|
-
const fn = (qrData) => __awaiter(this, void 0, void 0, function* () {
|
|
266
|
-
if (qrData.length > 200 && !(config === null || config === void 0 ? void 0 : config.multiDevice)) {
|
|
267
|
-
spinner.fail(`Multi-Device detected, please set multiDevice to true in your config or add the --multi-device flag`);
|
|
268
|
-
spinner.emit(true, "MD_DETECT");
|
|
269
|
-
return resolve(md);
|
|
270
|
-
}
|
|
271
|
-
if (!gotResult && (qrData === 'QR_CODE_SUCCESS' || qrData === md)) {
|
|
272
|
-
gotResult = true;
|
|
273
|
-
spinner === null || spinner === void 0 ? void 0 : spinner.succeed("QR code scanned. Loading session...");
|
|
274
|
-
return resolve(yield isInsideChat(waPage).toPromise());
|
|
275
|
-
}
|
|
276
|
-
if (!gotResult)
|
|
277
|
-
this.grabAndEmit(qrData, waPage, config, spinner);
|
|
278
|
-
});
|
|
279
|
-
const set = () => waPage.evaluate(({ funcName }) => {
|
|
280
|
-
//@ts-ignore
|
|
281
|
-
return window['smartQr'] ? window[`smartQr`](obj => window[funcName](obj)) : false;
|
|
282
|
-
}, { funcName });
|
|
283
|
-
yield waPage.exposeFunction(funcName, (obj) => fn(obj)).then(set).catch((e) => __awaiter(this, void 0, void 0, function* () {
|
|
284
|
-
//if an error occurs during the qr launcher then take a screenshot.
|
|
285
|
-
yield (0, initializer_1.screenshot)(waPage);
|
|
286
|
-
console.log("qr -> e", e);
|
|
287
|
-
logging_1.log.error("qr -> e", e);
|
|
288
|
-
}));
|
|
289
|
-
yield this.emitFirst(waPage, config, spinner);
|
|
290
|
-
}));
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
emitFirst(waPage, config, spinner) {
|
|
294
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
295
|
-
if (this.firstEmitted)
|
|
296
|
-
return;
|
|
297
|
-
this.firstEmitted = true;
|
|
298
|
-
const firstQr = yield waPage.evaluate(this.qrCheck);
|
|
299
|
-
yield this.grabAndEmit(firstQr, waPage, config, spinner);
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
/**
|
|
303
|
-
* Wait 10 seconds for the qr element to show.
|
|
304
|
-
* If it doesn't show up within 10 seconds then assume the session is authed already or blocked therefore ignore and return promise
|
|
305
|
-
*/
|
|
306
|
-
waitFirstQr(waPage, config, spinner) {
|
|
307
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
308
|
-
/**
|
|
309
|
-
* Check if session is authed already
|
|
310
|
-
*/
|
|
311
|
-
const fqr = yield waPage.waitForFunction(`!!(${this.qrCheck})`, {
|
|
312
|
-
polling: 500,
|
|
313
|
-
timeout: 10000
|
|
314
|
-
})
|
|
315
|
-
.catch(() => false);
|
|
316
|
-
if (fqr)
|
|
317
|
-
yield this.emitFirst(waPage, config, spinner);
|
|
318
|
-
return;
|
|
319
|
-
});
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
exports.QRManager = QRManager;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Browser, Page } from 'puppeteer';
|
|
2
|
-
import { Spin } from './events';
|
|
3
|
-
import { ConfigObject } from '../api/model';
|
|
4
|
-
import { QRManager } from './auth';
|
|
5
|
-
export declare let BROWSER_START_TS: number;
|
|
6
|
-
export declare function initPage(sessionId?: string, config?: ConfigObject, qrManager?: QRManager, customUserAgent?: string, spinner?: Spin, _page?: Page, skipAuth?: boolean): Promise<Page>;
|
|
7
|
-
export declare const deleteSessionData: (config: ConfigObject) => Promise<boolean>;
|
|
8
|
-
export declare const invalidateSesssionData: (config: ConfigObject) => Promise<boolean>;
|
|
9
|
-
export declare const getSessionDataFilePath: (sessionId: string, config: ConfigObject) => Promise<string | false>;
|
|
10
|
-
export declare const addScript: (page: Page, js: string, asScriptTag?: boolean) => Promise<unknown>;
|
|
11
|
-
export declare function injectPreApiScripts(page: Page, spinner?: Spin): Promise<Page>;
|
|
12
|
-
export declare function injectWapi(page: Page, spinner?: Spin, force?: boolean): Promise<Page>;
|
|
13
|
-
export declare function injectApi(page: Page, spinner?: Spin, force?: boolean): Promise<Page>;
|
|
14
|
-
/**
|
|
15
|
-
* @internal
|
|
16
|
-
*/
|
|
17
|
-
export declare const kill: (p: Page, b?: Browser, exit?: boolean, pid?: number, reason?: string) => Promise<void>;
|