@open-wa/wa-automate 4.30.12 → 4.31.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.
@@ -257,7 +257,7 @@ class Client {
257
257
  const emojiId = message.body.replace(new RegExp(ident, 'g'), "");
258
258
  if (!emojiId)
259
259
  return;
260
- return yield this.sendEmoji(message.from, emojiId, message.id);
260
+ return yield this.sendEmoji(message.from, emojiId, message.id).catch(() => { });
261
261
  }
262
262
  }));
263
263
  this._autoEmojiSet = true;
@@ -303,7 +303,7 @@ class Client {
303
303
  }
304
304
  _reInjectWapi(newTab) {
305
305
  return __awaiter(this, void 0, void 0, function* () {
306
- yield (0, browser_1.injectApi)(newTab || this._page);
306
+ yield (0, browser_1.injectApi)(newTab || this._page, null, true);
307
307
  });
308
308
  }
309
309
  _reRegisterListeners() {
@@ -315,7 +315,7 @@ class Client {
315
315
  * A convinience method to download the [[DataURL]] of a file
316
316
  * @param url The url
317
317
  * @param optionsOverride You can use this to override the [axios request config](https://github.com/axios/axios#request-config)
318
- * @returns Promise<DataURL>
318
+ * @returns `Promise<DataURL>`
319
319
  */
320
320
  download(url, optionsOverride = {}) {
321
321
  return __awaiter(this, void 0, void 0, function* () {
@@ -364,7 +364,6 @@ class Client {
364
364
  /**
365
365
  * Wait for the new page to be loaded up before closing existing page
366
366
  */
367
- yield (0, patch_manager_1.earlyInjectionCheck)(newTab);
368
367
  spinner.info("Checking if fresh session is authenticated...");
369
368
  if (yield (0, auth_1.isAuthenticated)(newTab)) {
370
369
  /**
@@ -813,7 +812,8 @@ class Client {
813
812
  *
814
813
  * Here is an example of the fired object:
815
814
  *
816
- * @fires ```javascript
815
+ * @fires
816
+ * ```javascript
817
817
  * {
818
818
  * "chat": "00000000000-1111111111@g.us", //the chat in which this state is occuring
819
819
  * "user": "22222222222@c.us", //the user that is causing this state
@@ -931,7 +931,7 @@ class Client {
931
931
  * @param chatId the chat from which you want to subscribes to live location updates
932
932
  * @param fn callback that takes in a LiveLocationChangedEvent
933
933
  * @returns boolean, if returns false then there were no valid live locations in the chat of chatId
934
- * @emits <LiveLocationChangedEvent> LiveLocationChangedEvent
934
+ * @emits `<LiveLocationChangedEvent>` LiveLocationChangedEvent
935
935
  */
936
936
  onLiveLocation(chatId, fn) {
937
937
  return __awaiter(this, void 0, void 0, function* () {
@@ -943,6 +943,20 @@ class Client {
943
943
  }, { chatId, funcName }));
944
944
  });
945
945
  }
946
+ /**
947
+ * Use this simple command to test firing callback events.
948
+ *
949
+ * @param callbackToTest
950
+ * @param testData
951
+ * @returns `false` if the callback was not registered/does not exist
952
+ */
953
+ testCallback(callbackToTest, testData) {
954
+ return __awaiter(this, void 0, void 0, function* () {
955
+ return this.pup(({ callbackToTest, testData }) => {
956
+ return WAPI.testCallback(callbackToTest, testData);
957
+ }, { callbackToTest, testData });
958
+ });
959
+ }
946
960
  /**
947
961
  * Set presence to available or unavailable.
948
962
  * @param available if true it will set your presence to 'online', false will set to unavailable (i.e no 'online' on recipients' phone);
@@ -1148,7 +1162,7 @@ class Client {
1148
1162
  * A list of participants in the chat who have their live location on. If the chat does not exist, or the chat does not have any contacts actively sharing their live locations, it will return false. If it's a chat with a single contact, there will be only 1 value in the array if the contact has their livelocation on.
1149
1163
  * Please note. This should only be called once every 30 or so seconds. This forces the phone to grab the latest live location data for the number. This can be used in conjunction with onLiveLocation (this will trigger onLiveLocation).
1150
1164
  * @param chatId string Id of the chat you want to force the phone to get the livelocation data for.
1151
- * @returns Promise<LiveLocationChangedEvent []> | boolean
1165
+ * @returns `Promise<LiveLocationChangedEvent []>` | boolean
1152
1166
  */
1153
1167
  forceUpdateLiveLocation(chatId) {
1154
1168
  return __awaiter(this, void 0, void 0, function* () {
@@ -1266,6 +1280,8 @@ class Client {
1266
1280
  });
1267
1281
  }
1268
1282
  /**
1283
+ * {@license:insiders@}
1284
+ * <span theme="badge contrast license">Insiders</span>
1269
1285
  * [REQUIRES AN INSIDERS LICENSE-KEY](https://gum.co/open-wa?tier=Insiders%20Program)
1270
1286
  *
1271
1287
  * Send a list message. This will not work when being sent from business accounts!
@@ -1310,7 +1326,7 @@ class Client {
1310
1326
  * @param groupId group chat id: `xxxxx@g.us`
1311
1327
  * @param content text message to add under all of the tags
1312
1328
  * @param hideTags Removes all tags within the message
1313
- * @returns Promise<MessageId>
1329
+ * @returns `Promise<MessageId>`
1314
1330
  */
1315
1331
  tagEveryone(groupId, content, hideTags) {
1316
1332
  return __awaiter(this, void 0, void 0, function* () {
@@ -1367,7 +1383,7 @@ class Client {
1367
1383
  /**
1368
1384
  * Decrypts a media message.
1369
1385
  * @param message This can be the serialized [[MessageId]] or the whole [[Message]] object. It is advised to just use the serialized message ID.
1370
- * @returns Promise<[[DataURL]]>
1386
+ * @returns `Promise<[[DataURL]]>`
1371
1387
  */
1372
1388
  decryptMedia(message) {
1373
1389
  return __awaiter(this, void 0, void 0, function* () {
@@ -1398,7 +1414,7 @@ class Client {
1398
1414
  * @param caption string xxxxx
1399
1415
  * @param waitForKey boolean default: false set this to true if you want to wait for the id of the message. By default this is set to false as it will take a few seconds to retrieve to the key of the message and this waiting may not be desirable for the majority of users.
1400
1416
  * @param hideTags boolean default: false [INSIDERS] set this to try silent tag someone in the caption
1401
- * @returns Promise <boolean | string> This will either return true or the id of the message. It will return true after 10 seconds even if waitForId is true
1417
+ * @returns `Promise <boolean | string>` This will either return true or the id of the message. It will return true after 10 seconds even if waitForId is true
1402
1418
  */
1403
1419
  sendImage(to, file, filename, caption, quotedMsgId, waitForId, ptt, withoutPreview, hideTags, viewOnce) {
1404
1420
  return __awaiter(this, void 0, void 0, function* () {
@@ -1462,7 +1478,7 @@ class Client {
1462
1478
  * @param content string reply text
1463
1479
  * @param quotedMsgId string the msg id to reply to.
1464
1480
  * @param sendSeen boolean If set to true, the chat will 'blue tick' all messages before sending the reply
1465
- * @returns Promise<MessageId | false> false if didn't work, otherwise returns message id.
1481
+ * @returns `Promise<MessageId | false>` false if didn't work, otherwise returns message id.
1466
1482
  */
1467
1483
  reply(to, content, quotedMsgId, sendSeen) {
1468
1484
  return __awaiter(this, void 0, void 0, function* () {
@@ -1479,7 +1495,7 @@ class Client {
1479
1495
  * This will only work if you have chats sent back and forth between you and the contact 1-1.
1480
1496
  *
1481
1497
  * @param contactId The Id of the contact with which you have an existing conversation with messages already.
1482
- * @returns Promise<string | boolean> true or false or a string with an explaintaion of why it wasn't able to determine the read receipts.
1498
+ * @returns `Promise<string | boolean>` true or false or a string with an explaintaion of why it wasn't able to determine the read receipts.
1483
1499
  *
1484
1500
  */
1485
1501
  checkReadReceipts(contactId) {
@@ -1504,7 +1520,7 @@ class Client {
1504
1520
  * @param ptt boolean default: false set this to true if you want to send the file as a push to talk file.
1505
1521
  * @param withoutPreview boolean default: false set this to true if you want to send the file without a preview (i.e as a file). This is useful for preventing auto downloads on recipient devices.
1506
1522
  * @param hideTags boolean default: false [INSIDERS] set this to try silent tag someone in the caption
1507
- * @returns Promise <boolean | MessageId> This will either return true or the id of the message. It will return true after 10 seconds even if waitForId is true
1523
+ * @returns `Promise <boolean | MessageId>` This will either return true or the id of the message. It will return true after 10 seconds even if waitForId is true
1508
1524
  */
1509
1525
  sendFile(to, file, filename, caption, quotedMsgId, waitForId, ptt, withoutPreview, hideTags, viewOnce) {
1510
1526
  return __awaiter(this, void 0, void 0, function* () {
@@ -1516,7 +1532,7 @@ class Client {
1516
1532
  *
1517
1533
  * Checks whether or not the group id provided is known to be unsafe by the contributors of the library.
1518
1534
  * @param groupChatId The group chat you want to deteremine is unsafe
1519
- * @returns Promise <boolean | string> This will either return a boolean indiciating whether this group chat id is considered unsafe or an error message as a string
1535
+ * @returns `Promise <boolean | string>` This will either return a boolean indiciating whether this group chat id is considered unsafe or an error message as a string
1520
1536
  */
1521
1537
  isGroupIdUnsafe(groupChatId) {
1522
1538
  return __awaiter(this, void 0, void 0, function* () {
@@ -1535,7 +1551,7 @@ class Client {
1535
1551
  * @param to chat id `xxxxx@c.us`
1536
1552
  * @param file base64 data:image/xxx;base64,xxx or the path of the file you want to send.
1537
1553
  * @param quotedMsgId string true_0000000000@c.us_JHB2HB23HJ4B234HJB to send as a reply to a message
1538
- * @returns Promise <boolean | string> This will either return true or the id of the message. It will return true after 10 seconds even if waitForId is true
1554
+ * @returns `Promise <boolean | string>` This will either return true or the id of the message. It will return true after 10 seconds even if waitForId is true
1539
1555
  */
1540
1556
  sendPtt(to, file, quotedMsgId) {
1541
1557
  return __awaiter(this, void 0, void 0, function* () {
@@ -1635,7 +1651,7 @@ class Client {
1635
1651
  }
1636
1652
  /**
1637
1653
  * Returns a PNG DataURL screenshot of the session
1638
- * @returns Promise<DataURL>
1654
+ * @returns `Promise<DataURL>`
1639
1655
  */
1640
1656
  getSnapshot() {
1641
1657
  return __awaiter(this, void 0, void 0, function* () {
@@ -1825,7 +1841,7 @@ class Client {
1825
1841
  * Any potential abuse of this method will see it become paywalled.
1826
1842
  * @param to: Chat id to forward the message to
1827
1843
  * @param messageId: message id of the message to forward. Please note that if it is not loaded, this will return false - even if it exists.
1828
- * @returns Promise<MessageId | boolean>
1844
+ * @returns `Promise<MessageId | boolean>`
1829
1845
  */
1830
1846
  ghostForward(to, messageId) {
1831
1847
  return __awaiter(this, void 0, void 0, function* () {
@@ -1944,7 +1960,7 @@ class Client {
1944
1960
  }
1945
1961
  /**
1946
1962
  * retrieves an array of IDs of accounts blocked by the host account.
1947
- * @returns Promise<ChatId[]>
1963
+ * @returns `Promise<ChatId[]>`
1948
1964
  */
1949
1965
  getBlockedIds() {
1950
1966
  return __awaiter(this, void 0, void 0, function* () {
@@ -2011,7 +2027,7 @@ class Client {
2011
2027
  * @param returnChatObj boolean When this is set to true and if the group was joined successfully, it will return a serialzed Chat object which includes group information and metadata. This is useful when you want to immediately do something with group metadata.
2012
2028
  *
2013
2029
  *
2014
- * @returns Promise<string | boolean | number> Either false if it didn't work, or the group id.
2030
+ * @returns `Promise<string | boolean | number>` Either false if it didn't work, or the group id.
2015
2031
  */
2016
2032
  joinGroupViaLink(link, returnChatObj) {
2017
2033
  return __awaiter(this, void 0, void 0, function* () {
@@ -2407,7 +2423,7 @@ class Client {
2407
2423
  /**
2408
2424
  * Retrieves an invite link for a group chat. returns false if chat is not a group.
2409
2425
  * @param chatId
2410
- * @returns Promise<string>
2426
+ * @returns `Promise<string>`
2411
2427
  */
2412
2428
  getGroupInviteLink(chatId) {
2413
2429
  return __awaiter(this, void 0, void 0, function* () {
@@ -2427,7 +2443,7 @@ class Client {
2427
2443
  /**
2428
2444
  * Revokes the current invite link for a group chat. Any previous links will stop working
2429
2445
  * @param chatId
2430
- * @returns Promise<boolean>
2446
+ * @returns `Promise<boolean>`
2431
2447
  */
2432
2448
  revokeGroupInviteLink(chatId) {
2433
2449
  return __awaiter(this, void 0, void 0, function* () {
@@ -2542,21 +2558,6 @@ class Client {
2542
2558
  *
2543
2559
  * @param groupName group name: 'New group'
2544
2560
  * @param contacts: A single contact id or an array of contact ids.
2545
- * @returns Promise<GroupCreationResponse> :
2546
- * ```javascript
2547
- * {
2548
- * status: 200,
2549
- * gid: {
2550
- * server: 'g.us',
2551
- * user: '447777777777-1583678870',
2552
- * _serialized: '447777777777-1583678870@g.us'
2553
- * },
2554
- * participants: [
2555
- * { '447777777777@c.us': [Object] },
2556
- * { '447444444444@c.us': [Object] }
2557
- * ]
2558
- * }
2559
- * ```
2560
2561
  */
2561
2562
  createGroup(groupName, contacts) {
2562
2563
  return __awaiter(this, void 0, void 0, function* () {
@@ -2791,7 +2792,7 @@ class Client {
2791
2792
  * @param url: The url of the image
2792
2793
  * @param requestConfig {} By default the request is a get request, however you can override that and many other options by sending this parameter. You can read more about this parameter here: https://github.com/axios/axios#request-config
2793
2794
  *
2794
- * @returns Promise<MessageId | boolean>
2795
+ * @returns `Promise<MessageId | boolean>`
2795
2796
  */
2796
2797
  sendStickerfromUrl(to, url, requestConfig = {}, stickerMetadata) {
2797
2798
  return __awaiter(this, void 0, void 0, function* () {
@@ -2808,7 +2809,7 @@ class Client {
2808
2809
  * @param messageId The id of the message to reply to
2809
2810
  * @param requestConfig {} By default the request is a get request, however you can override that and many other options by sending this parameter. You can read more about this parameter here: https://github.com/axios/axios#request-config
2810
2811
  *
2811
- * @returns Promise<MessageId | boolean>
2812
+ * @returns `Promise<MessageId | boolean>`
2812
2813
  */
2813
2814
  sendStickerfromUrlAsReply(to, url, messageId, requestConfig = {}, stickerMetadata) {
2814
2815
  return __awaiter(this, void 0, void 0, function* () {
@@ -3096,7 +3097,7 @@ class Client {
3096
3097
  * Turn the ephemeral setting in a chat to on or off
3097
3098
  * @param chatId The ID of the chat
3098
3099
  * @param ephemeral `true` to turn on the ephemeral setting, `false` to turn off the ephemeral setting. Please note, if the setting is already on the requested setting, this method will return `true`.
3099
- * @returns Promise<boolean> true if the setting was set, `false` if the chat does not exist
3100
+ * @returns `Promise<boolean>` true if the setting was set, `false` if the chat does not exist
3100
3101
  */
3101
3102
  setChatEphemeral(chatId, ephemeral) {
3102
3103
  return __awaiter(this, void 0, void 0, function* () {
@@ -3127,7 +3128,7 @@ class Client {
3127
3128
  * 3: [Bryndan Write](https://www.dafontfree.net/freefonts-bryndan-write-f160189.htm)
3128
3129
  * 4: [Bebasneue Regular](https://www.dafont.com/bebas-neue.font)
3129
3130
  * 5: [Oswald Heavy](https://www.fontsquirrel.com/fonts/oswald)
3130
- * @returns Promise<string | boolean> returns status id if it worked, false if it didn't
3131
+ * @returns `Promise<string | boolean>` returns status id if it worked, false if it didn't
3131
3132
  */
3132
3133
  postTextStatus(text, textRgba, backgroundRgba, font) {
3133
3134
  return __awaiter(this, void 0, void 0, function* () {
@@ -3140,7 +3141,7 @@ class Client {
3140
3141
  * Posts an image story.
3141
3142
  * @param data data url string `data:[<MIME-type>][;charset=<encoding>][;base64],<data>`
3142
3143
  * @param caption The caption for the story
3143
- * @returns Promise<string | boolean> returns status id if it worked, false if it didn't
3144
+ * @returns `Promise<string | boolean>` returns status id if it worked, false if it didn't
3144
3145
  */
3145
3146
  postImageStatus(data, caption) {
3146
3147
  return __awaiter(this, void 0, void 0, function* () {
@@ -3153,7 +3154,7 @@ class Client {
3153
3154
  * Posts a video story.
3154
3155
  * @param data data url string `data:[<MIME-type>][;charset=<encoding>][;base64],<data>`
3155
3156
  * @param caption The caption for the story
3156
- * @returns Promise<string | boolean> returns status id if it worked, false if it didn't
3157
+ * @returns `Promise<string | boolean>` returns status id if it worked, false if it didn't
3157
3158
  */
3158
3159
  postVideoStatus(data, caption) {
3159
3160
  return __awaiter(this, void 0, void 0, function* () {
@@ -3276,7 +3277,7 @@ class Client {
3276
3277
  *
3277
3278
  * Sets the profile pic of the host number.
3278
3279
  * @param data string data url image string.
3279
- * @returns Promise<boolean> success if true
3280
+ * @returns `Promise<boolean>` success if true
3280
3281
  */
3281
3282
  setProfilePic(data) {
3282
3283
  return __awaiter(this, void 0, void 0, function* () {
@@ -1,3 +1,6 @@
1
+ declare type Brand<K, T> = K & {
2
+ __brand?: T;
3
+ };
1
4
  /**
2
5
  * The suffix used to identify a non-group chat id
3
6
  */
@@ -33,7 +36,7 @@ export declare type GroupChatId = `${AccountNumber}-${number}@${GroupChatServer}
33
36
  *
34
37
  * `"447123456789@c.us"`
35
38
  */
36
- export declare type ContactId = `${AccountNumber}@${ChatServer}`;
39
+ export declare type ContactId = Brand<`${AccountNumber}@${ChatServer}`, "ContactId">;
37
40
  /**
38
41
  * A chat id ends with `@c.us` or `@g.us` for group chats.
39
42
  *
@@ -51,7 +54,7 @@ export declare type ChatId = ContactId | GroupChatId;
51
54
  *
52
55
  * `"false_447123456789@c.us_9C4D0965EA5C09D591334AB6BDB07FEB"`
53
56
  */
54
- export declare type MessageId = `${boolean}_${ChatId}_${string}`;
57
+ export declare type MessageId = Brand<`${boolean}_${ChatId}_${string}`, "MessageId">;
55
58
  /**
56
59
  * This is a generic type alias for the content of a message
57
60
  *
@@ -59,7 +62,7 @@ export declare type MessageId = `${boolean}_${ChatId}_${string}`;
59
62
  *
60
63
  * `"hello!"`
61
64
  */
62
- export declare type Content = string;
65
+ export declare type Content = Brand<string, "Content">;
63
66
  export declare type NonSerializedId = {
64
67
  server: WaServers;
65
68
  user: AccountNumber;
@@ -77,7 +80,7 @@ export declare type NonSerializedId = {
77
80
  *
78
81
  * Learn more here: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs
79
82
  */
80
- export declare type DataURL = string;
83
+ export declare type DataURL = Brand<`data:${string};base64,${Base64}`, "DataURL">;
81
84
  /**
82
85
  * Base64 is basically a file encoded as a string.
83
86
  *
@@ -85,10 +88,11 @@ export declare type DataURL = string;
85
88
  *
86
89
  * Learn more here: https://developer.mozilla.org/en-US/docs/Glossary/Base64
87
90
  */
88
- export declare type Base64 = string;
91
+ export declare type Base64 = Brand<string, "Base64">;
89
92
  /**
90
93
  * The relative or absolute path of a file
91
94
  *
92
95
  * Learn more here: https://www.w3schools.com/html/html_filepaths.asp
93
96
  */
94
- export declare type FilePath = string;
97
+ export declare type FilePath = Brand<string, "FilePath">;
98
+ export {};
@@ -1,2 +1,3 @@
1
1
  "use strict";
2
+ // declare const tag: unique symbol
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -687,7 +687,7 @@ export interface ConfigObject {
687
687
  /**
688
688
  * What to do when an error is detected on a client method.
689
689
  *
690
- * @default `NOTHING`
690
+ * @default `OnError.NOTHING`
691
691
  */
692
692
  onError?: OnError;
693
693
  /**
@@ -697,6 +697,9 @@ export interface ConfigObject {
697
697
  * Set this to true if you're using the multidevice beta.
698
698
  *
699
699
  * @default `false`
700
+ * :::danger
701
+ * Some features (e.g [[sendLinkWithAutoPreview]]) **do not** work with multi-device beta. Check [this `api`](#).
702
+ * :::
700
703
  */
701
704
  multiDevice?: boolean;
702
705
  /**
@@ -3,6 +3,7 @@ export * from './contact';
3
3
  export * from './message';
4
4
  export * from './errors';
5
5
  export * from './events';
6
+ export * from './product';
6
7
  /**
7
8
  * Client status
8
9
  * @readonly
@@ -16,6 +16,7 @@ __exportStar(require("./contact"), exports);
16
16
  __exportStar(require("./message"), exports);
17
17
  __exportStar(require("./errors"), exports);
18
18
  __exportStar(require("./events"), exports);
19
+ __exportStar(require("./product"), exports);
19
20
  /**
20
21
  * Client status
21
22
  * @readonly
@@ -75,7 +75,7 @@ export interface Product {
75
75
  description?: string;
76
76
  /**
77
77
  * The availiable quantity of this product.
78
- * @default `"unknown"``
78
+ * @default "unknown"`
79
79
  */
80
80
  availability?: number | "unknown";
81
81
  /**
@@ -3,13 +3,13 @@ import { Spin } from './events';
3
3
  import { ConfigObject } from '../api/model';
4
4
  import { Page } from 'puppeteer';
5
5
  /**
6
+ * isAuthenticated
6
7
  * Validates if client is authenticated
7
8
  * @returns true if is authenticated, false otherwise
8
9
  * @param waPage
9
10
  */
10
11
  export declare const isAuthenticated: (waPage: Page) => Promise<unknown>;
11
12
  export declare const needsToScan: (waPage: Page) => Observable<unknown>;
12
- export declare const isInsideChat: (waPage: Page) => Observable<boolean>;
13
13
  export declare const waitForRipeSession: (waPage: Page) => Promise<boolean>;
14
14
  export declare const sessionDataInvalid: (waPage: Page) => Promise<string>;
15
15
  export declare const phoneIsOutOfReach: (waPage: Page) => Promise<boolean>;
@@ -27,6 +27,10 @@ export declare class QRManager {
27
27
  grabAndEmit(qrData: any, waPage: Page, config: ConfigObject, spinner: Spin): Promise<void>;
28
28
  smartQr(waPage: Page, config?: ConfigObject, spinner?: Spin): Promise<boolean | void | string>;
29
29
  emitFirst(waPage: Page, config?: ConfigObject, spinner?: Spin): Promise<void>;
30
+ /**
31
+ * Wait 10 seconds for the qr element to show.
32
+ * If it doesn't show up within 10 seconds then assume the session is authed already or blocked therefore ignore and return promise
33
+ */
30
34
  waitFirstQr(waPage: Page, config?: ConfigObject, spinner?: Spin): Promise<void>;
31
35
  }
32
36
  export declare const qrManager: QRManager;
@@ -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.qrManager = exports.QRManager = exports.phoneIsOutOfReach = exports.sessionDataInvalid = exports.waitForRipeSession = exports.isInsideChat = exports.needsToScan = exports.isAuthenticated = void 0;
34
+ exports.qrManager = exports.QRManager = exports.phoneIsOutOfReach = exports.sessionDataInvalid = exports.waitForRipeSession = exports.needsToScan = exports.isAuthenticated = void 0;
35
35
  const qrcode = __importStar(require("qrcode-terminal"));
36
36
  const rxjs_1 = require("rxjs");
37
37
  const events_1 = require("./events");
@@ -41,11 +41,12 @@ const browser_1 = require("./browser");
41
41
  const axios_1 = __importDefault(require("axios"));
42
42
  const logging_1 = require("../logging/logging");
43
43
  /**
44
+ * isAuthenticated
44
45
  * Validates if client is authenticated
45
46
  * @returns true if is authenticated, false otherwise
46
47
  * @param waPage
47
48
  */
48
- const isAuthenticated = (waPage) => (0, rxjs_1.race)((0, exports.needsToScan)(waPage), (0, exports.isInsideChat)(waPage), (0, exports.sessionDataInvalid)(waPage)).toPromise();
49
+ const isAuthenticated = (waPage) => (0, rxjs_1.race)((0, exports.needsToScan)(waPage), isInsideChat(waPage), (0, exports.sessionDataInvalid)(waPage)).toPromise();
49
50
  exports.isAuthenticated = isAuthenticated;
50
51
  const needsToScan = (waPage) => {
51
52
  return (0, rxjs_1.from)(new Promise((resolve) => __awaiter(void 0, void 0, void 0, function* () {
@@ -72,7 +73,11 @@ const isInsideChat = (waPage) => {
72
73
  .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 })
73
74
  .then(() => true));
74
75
  };
75
- exports.isInsideChat = isInsideChat;
76
+ const isTosBlocked = (waPage) => {
77
+ return (0, rxjs_1.from)(waPage
78
+ .waitForFunction(`document.getElementsByTagName("html")[0].classList[0] === 'no-js'`, { timeout: 0 })
79
+ .then(() => false));
80
+ };
76
81
  const waitForRipeSession = (waPage) => __awaiter(void 0, void 0, void 0, function* () {
77
82
  try {
78
83
  yield waPage.waitForFunction(`window.isRipeSession()`, { timeout: 0, polling: 'mutation' });
@@ -84,11 +89,17 @@ const waitForRipeSession = (waPage) => __awaiter(void 0, void 0, void 0, functio
84
89
  });
85
90
  exports.waitForRipeSession = waitForRipeSession;
86
91
  const sessionDataInvalid = (waPage) => __awaiter(void 0, void 0, void 0, function* () {
92
+ const check = `Object.keys(localStorage).includes("old-logout-cred")`;
87
93
  yield waPage
88
- .waitForFunction('!window.getQrPng', { timeout: 0, polling: 'mutation' });
89
- yield (0, browser_1.injectApi)(waPage);
90
- yield waPage
91
- .waitForFunction('!window.getQrPng', { timeout: 0, polling: 'mutation' });
94
+ .waitForFunction(check, { timeout: 0, polling: 'mutation' });
95
+ // await injectApi(waPage, null, true);
96
+ // await waPage
97
+ // .waitForFunction(
98
+ // '!window.getQrPng',
99
+ // { timeout: 0, polling: 'mutation' }
100
+ // )
101
+ // await timeout(1000000)
102
+ //NEED A DIFFERENT WAY TO DETERMINE IF THE SESSION WAS LOGGED OUT!!!!
92
103
  //if the code reaches here it means the browser was refreshed. Nuke the session data and restart `create`
93
104
  return 'NUKE';
94
105
  });
@@ -116,6 +127,7 @@ class QRManager {
116
127
  this.qrEvF(this.config);
117
128
  }
118
129
  qrEvF(config = this.config) {
130
+ return new events_1.EvEmitter(config.sessionId || 'session', 'qr');
119
131
  if (!this.qrEv)
120
132
  this.qrEv = new events_1.EvEmitter(config.sessionId || 'session', 'qr');
121
133
  return this.qrEv;
@@ -211,7 +223,7 @@ class QRManager {
211
223
  if (!gotResult && (qrData === 'QR_CODE_SUCCESS' || qrData === md)) {
212
224
  gotResult = true;
213
225
  spinner === null || spinner === void 0 ? void 0 : spinner.succeed(qrData === md ? "Multi device support for this project is EXPERIMENTAL. Some things may not work...." : "QR code scanned. Loading session...");
214
- return resolve(yield (0, exports.isInsideChat)(waPage).toPromise());
226
+ return resolve(yield isInsideChat(waPage).toPromise());
215
227
  }
216
228
  if (!gotResult)
217
229
  this.grabAndEmit(qrData, waPage, config, spinner);
@@ -239,13 +251,17 @@ class QRManager {
239
251
  yield this.grabAndEmit(firstQr, waPage, config, spinner);
240
252
  });
241
253
  }
254
+ /**
255
+ * Wait 10 seconds for the qr element to show.
256
+ * If it doesn't show up within 10 seconds then assume the session is authed already or blocked therefore ignore and return promise
257
+ */
242
258
  waitFirstQr(waPage, config, spinner) {
243
259
  return __awaiter(this, void 0, void 0, function* () {
244
260
  const fqr = yield waPage.waitForFunction(`!!(${this.qrCheck})`, {
245
261
  polling: 500,
246
262
  timeout: 10000
247
263
  })
248
- .catch(e => false);
264
+ .catch(() => false);
249
265
  if (fqr)
250
266
  yield this.emitFirst(waPage, config, spinner);
251
267
  return;