@open-wa/wa-automate 4.31.10 → 4.31.13

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.
@@ -824,10 +824,10 @@ export declare class Client {
824
824
  isConnected(): Promise<boolean>;
825
825
  /**
826
826
  * Logs out from the session.
827
- *
827
+ * @param preserveSessionData skip session.data.json file invalidation
828
828
  * Please be careful when using this as it can exit the whole process depending on your config
829
829
  */
830
- logout(): Promise<boolean>;
830
+ logout(preserveSessionData?: boolean): Promise<boolean>;
831
831
  /**
832
832
  * Retrieves Battery Level
833
833
  * @returns Number
@@ -266,6 +266,7 @@ class Client {
266
266
  this.onLogout(() => __awaiter(this, void 0, void 0, function* () {
267
267
  var _k, _l;
268
268
  yield this.waitAllQEmpty();
269
+ yield (0, browser_1.invalidateSesssionData)(this._createConfig);
269
270
  if ((_k = this._createConfig) === null || _k === void 0 ? void 0 : _k.deleteSessionDataOnLogout)
270
271
  (0, browser_1.deleteSessionData)(this._createConfig);
271
272
  if ((_l = this._createConfig) === null || _l === void 0 ? void 0 : _l.killClientOnLogout) {
@@ -1882,11 +1883,15 @@ class Client {
1882
1883
  }
1883
1884
  /**
1884
1885
  * Logs out from the session.
1885
- *
1886
+ * @param preserveSessionData skip session.data.json file invalidation
1886
1887
  * Please be careful when using this as it can exit the whole process depending on your config
1887
1888
  */
1888
- logout() {
1889
+ logout(preserveSessionData = false) {
1889
1890
  return __awaiter(this, void 0, void 0, function* () {
1891
+ if (!preserveSessionData) {
1892
+ logging_1.log.info(`LOGOUT CALLED. INVALIDATING SESSION DATA`);
1893
+ yield (0, browser_1.invalidateSesssionData)(this._createConfig);
1894
+ }
1890
1895
  return yield this.pup(() => WAPI.logout());
1891
1896
  });
1892
1897
  }
@@ -40,6 +40,7 @@ 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 boxen_1 = __importDefault(require("boxen"));
43
44
  /**
44
45
  * isAuthenticated
45
46
  * Validates if client is authenticated
@@ -145,8 +146,11 @@ class QRManager {
145
146
  spinner.info(`First QR: ${Date.now() - browser_1.BROWSER_START_TS} ms`);
146
147
  if (qrData) {
147
148
  qrEv.emit(qrData, `qrData`);
148
- if (!config.qrLogSkip)
149
- qrcode.generate(qrData, { small: true });
149
+ if (!config.qrLogSkip) {
150
+ qrcode.generate(qrData, { small: true }, terminalQrCode => {
151
+ console.log((0, boxen_1.default)(terminalQrCode, { title: config.sessionId, padding: 1, titleAlignment: 'center' }));
152
+ });
153
+ }
150
154
  else {
151
155
  console.log(`New QR Code generated. Not printing in console because qrLogSkip is set to true`);
152
156
  logging_1.log.info(`New QR Code generated. Not printing in console because qrLogSkip is set to true`);
@@ -5,7 +5,8 @@ import { QRManager } from './auth';
5
5
  export declare let BROWSER_START_TS: number;
6
6
  export declare function initPage(sessionId?: string, config?: ConfigObject, qrManager?: QRManager, customUserAgent?: string, spinner?: Spin, _page?: Page, skipAuth?: boolean): Promise<Page>;
7
7
  export declare const deleteSessionData: (config: ConfigObject) => boolean;
8
- export declare const getSessionDataFilePath: (sessionId: string, config: ConfigObject) => string | boolean;
8
+ export declare const invalidateSesssionData: (config: ConfigObject) => boolean;
9
+ export declare const getSessionDataFilePath: (sessionId: string, config: ConfigObject) => string | false;
9
10
  export declare const addScript: (page: Page, js: string) => Promise<unknown>;
10
11
  export declare function injectPreApiScripts(page: Page, spinner?: Spin): Promise<Page>;
11
12
  export declare function injectWapi(page: Page, spinner?: Spin, force?: boolean): Promise<Page>;
@@ -31,7 +31,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
31
31
  return (mod && mod.__esModule) ? mod : { "default": mod };
32
32
  };
33
33
  Object.defineProperty(exports, "__esModule", { value: true });
34
- exports.kill = exports.injectApi = exports.injectWapi = exports.injectPreApiScripts = exports.addScript = exports.getSessionDataFilePath = exports.deleteSessionData = exports.initPage = exports.BROWSER_START_TS = void 0;
34
+ exports.kill = exports.injectApi = exports.injectWapi = exports.injectPreApiScripts = exports.addScript = exports.getSessionDataFilePath = exports.invalidateSesssionData = exports.deleteSessionData = exports.initPage = exports.BROWSER_START_TS = void 0;
35
35
  const path = __importStar(require("path"));
36
36
  const fs = __importStar(require("fs"));
37
37
  const death_1 = __importDefault(require("death"));
@@ -52,7 +52,7 @@ function initPage(sessionId, config, qrManager, customUserAgent, spinner, _page,
52
52
  var _a, _b, _c, _d, _e;
53
53
  return __awaiter(this, void 0, void 0, function* () {
54
54
  const setupPromises = [];
55
- script_preloader_1.scriptLoader.loadScripts();
55
+ yield script_preloader_1.scriptLoader.loadScripts();
56
56
  if ((config === null || config === void 0 ? void 0 : config.resizable) === undefined || !(config === null || config === void 0 ? void 0 : config.resizable) == false)
57
57
  config.defaultViewport = null;
58
58
  if (config === null || config === void 0 ? void 0 : config.useStealth) {
@@ -268,7 +268,7 @@ const getSessionDataFromFile = (sessionId, config, spinner) => {
268
268
  sessionjson = JSON.parse(Buffer.from(s, 'base64').toString('ascii'));
269
269
  }
270
270
  catch (error) {
271
- const msg = "Session data json file is corrupted. Please reauthenticate.";
271
+ const msg = `${s == "LOGGED OUT" ? "The session was logged out" : "Session data json file is corrupted"}. Please re-scan the QR code.`;
272
272
  if (spinner) {
273
273
  spinner.fail(msg);
274
274
  }
@@ -294,6 +294,22 @@ const deleteSessionData = (config) => {
294
294
  return true;
295
295
  };
296
296
  exports.deleteSessionData = deleteSessionData;
297
+ const invalidateSesssionData = (config) => {
298
+ const sessionjsonpath = (0, exports.getSessionDataFilePath)((config === null || config === void 0 ? void 0 : config.sessionId) || 'session', config);
299
+ if (typeof sessionjsonpath == 'string' && fs.existsSync(sessionjsonpath)) {
300
+ const l = `logout detected, invalidating session data file: ${sessionjsonpath}`;
301
+ console.log(l);
302
+ logging_1.log.info(l);
303
+ fs.writeFile(sessionjsonpath, "LOGGED OUT", (err) => {
304
+ if (err) {
305
+ console.error(err);
306
+ return;
307
+ }
308
+ });
309
+ }
310
+ return true;
311
+ };
312
+ exports.invalidateSesssionData = invalidateSesssionData;
297
313
  const getSessionDataFilePath = (sessionId, config) => {
298
314
  var _a, _b;
299
315
  const p = ((_a = require === null || require === void 0 ? void 0 : require.main) === null || _a === void 0 ? void 0 : _a.path) || ((_b = process === null || process === void 0 ? void 0 : process.mainModule) === null || _b === void 0 ? void 0 : _b.path);
@@ -338,7 +354,7 @@ function injectWapi(page, spinner, force = false) {
338
354
  if (initCheck)
339
355
  return;
340
356
  logging_1.log.info(`WAPI CHECK: ${initCheck}`);
341
- if (!check)
357
+ if (!initCheck)
342
358
  force = true;
343
359
  if (wapiInjected && !force)
344
360
  return page;
@@ -66,8 +66,10 @@ class ScriptLoader {
66
66
  return __awaiter(this, void 0, void 0, function* () {
67
67
  if (!this.contentRegistry[scriptName]) {
68
68
  this.contentRegistry[scriptName] = yield read(scriptName);
69
- logging_1.log.info("SCRIPT READY: " + scriptName);
69
+ logging_1.log.info(`SCRIPT READY: ${scriptName} ${this.contentRegistry[scriptName].length}`);
70
70
  }
71
+ else
72
+ logging_1.log.info(`GET SCRIPT: ${scriptName} ${this.contentRegistry[scriptName].length}`);
71
73
  return this.contentRegistry[scriptName];
72
74
  });
73
75
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-wa/wa-automate",
3
- "version": "4.31.10",
3
+ "version": "4.31.13",
4
4
  "licenseCheckUrl": "https://funcs.openwa.dev/license-check",
5
5
  "brokenMethodReportUrl": "https://funcs.openwa.dev/report-bm",
6
6
  "patches": "https://cdn.openwa.dev/patches.json",