@open-wa/wa-automate 4.31.12 → 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.
package/dist/api/Client.d.ts
CHANGED
@@ -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
|
package/dist/api/Client.js
CHANGED
@@ -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
|
}
|
@@ -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
|
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"));
|
@@ -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
|
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);
|
package/package.json
CHANGED