@open-wa/wa-automate 4.50.1 → 4.51.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -233,7 +237,7 @@ class Client {
233
237
  }
234
238
  catch (error) {
235
239
  console.error("middleware -> error", error);
236
- if (methodRequiresArgs && args == [])
240
+ if (methodRequiresArgs && Array.isArray(args))
237
241
  error.message = `${(req === null || req === void 0 ? void 0 : req.params) ? "Please set arguments in request json body, not in params." : "Args expected, none found."} ${error.message}`;
238
242
  return res.send({
239
243
  success: false,
@@ -307,7 +311,7 @@ class Client {
307
311
  yield ((_q = (_o = this._queues) === null || _o === void 0 ? void 0 : _o.onLogout) === null || _q === void 0 ? void 0 : _q.onIdle());
308
312
  yield (0, browser_1.invalidateSesssionData)(this._createConfig);
309
313
  if ((_r = this._createConfig) === null || _r === void 0 ? void 0 : _r.deleteSessionDataOnLogout)
310
- (0, browser_1.deleteSessionData)(this._createConfig);
314
+ yield (0, browser_1.deleteSessionData)(this._createConfig);
311
315
  if ((_s = this._createConfig) === null || _s === void 0 ? void 0 : _s.killClientOnLogout) {
312
316
  console.log("Session logged out. Killing client");
313
317
  logging_1.log.warn("Session logged out. Killing client");
@@ -3881,8 +3885,8 @@ class Client {
3881
3885
  * @param options The options for the collector. For example, how long the collector shall run for, how many messages it should collect, how long between messages before timing out, etc.
3882
3886
  */
3883
3887
  createMessageCollector(c, filter, options) {
3884
- var _a, _b, _c;
3885
- const chatId = (((_b = (_a = c) === null || _a === void 0 ? void 0 : _a.chat) === null || _b === void 0 ? void 0 : _b.id) || ((_c = c) === null || _c === void 0 ? void 0 : _c.id) || c);
3888
+ var _a;
3889
+ const chatId = (((_a = c === null || c === void 0 ? void 0 : c.chat) === null || _a === void 0 ? void 0 : _a.id) || (c === null || c === void 0 ? void 0 : c.id) || c);
3886
3890
  return new MessageCollector_1.MessageCollector(this.getSessionId(), this.getInstanceId(), chatId, filter, options, events_1.ev);
3887
3891
  }
3888
3892
  /**
@@ -1,26 +1,26 @@
1
- declare type Brand<K, T> = K & {
1
+ type Brand<K, T> = K & {
2
2
  __brand?: T;
3
3
  };
4
4
  /**
5
5
  * The suffix used to identify a non-group chat id
6
6
  */
7
- export declare type ChatServer = 'c.us';
7
+ export type ChatServer = 'c.us';
8
8
  /**
9
9
  * The suffix used to identify a group chat id
10
10
  */
11
- export declare type GroupChatServer = 'g.us';
11
+ export type GroupChatServer = 'g.us';
12
12
  /**
13
13
  * A type alias for all available "servers"
14
14
  */
15
- export declare type WaServers = ChatServer | GroupChatServer;
15
+ export type WaServers = ChatServer | GroupChatServer;
16
16
  /**
17
17
  * Type alias representing all available country codes
18
18
  */
19
- export declare type CountryCode = 1 | 7 | 20 | 27 | 30 | 31 | 32 | 33 | 34 | 36 | 39 | 40 | 41 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 81 | 82 | 84 | 86 | 90 | 91 | 92 | 93 | 94 | 95 | 98 | 211 | 212 | 213 | 216 | 218 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 290 | 291 | 297 | 298 | 299 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 380 | 381 | 382 | 383 | 385 | 386 | 387 | 389 | 420 | 421 | 423 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 670 | 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | 683 | 685 | 686 | 687 | 688 | 689 | 690 | 691 | 692 | 850 | 852 | 853 | 855 | 856 | 880 | 886 | 960 | 961 | 962 | 963 | 964 | 965 | 966 | 967 | 968 | 970 | 971 | 972 | 973 | 974 | 975 | 976 | 977 | 992 | 993 | 994 | 995 | 996 | 998;
19
+ export type CountryCode = 1 | 7 | 20 | 27 | 30 | 31 | 32 | 33 | 34 | 36 | 39 | 40 | 41 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 81 | 82 | 84 | 86 | 90 | 91 | 92 | 93 | 94 | 95 | 98 | 211 | 212 | 213 | 216 | 218 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 290 | 291 | 297 | 298 | 299 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 380 | 381 | 382 | 383 | 385 | 386 | 387 | 389 | 420 | 421 | 423 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 670 | 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | 683 | 685 | 686 | 687 | 688 | 689 | 690 | 691 | 692 | 850 | 852 | 853 | 855 | 856 | 880 | 886 | 960 | 961 | 962 | 963 | 964 | 965 | 966 | 967 | 968 | 970 | 971 | 972 | 973 | 974 | 975 | 976 | 977 | 992 | 993 | 994 | 995 | 996 | 998;
20
20
  /**
21
21
  * The account number. It is made up of a country code and then the local number without the preceeding 0. For example, if a UK (+44) wa account is linked to the number 07123456789 then the account number will be 447123456789.
22
22
  */
23
- export declare type AccountNumber = `${number}`;
23
+ export type AccountNumber = `${number}`;
24
24
  /**
25
25
  * A group chat ends with `@g.us` and usually has two parts, the timestamp of when it was created, and the user id of the number that created the group. For example `[creator number]-[timestamp]@g.us`
26
26
  *
@@ -28,7 +28,7 @@ export declare type AccountNumber = `${number}`;
28
28
  *
29
29
  * `"447123456789-1445627445@g.us"`
30
30
  */
31
- export declare type GroupChatId = `${AccountNumber}-${number}@${GroupChatServer}` | `${number}@${GroupChatServer}`;
31
+ export type GroupChatId = `${AccountNumber}-${number}@${GroupChatServer}` | `${number}@${GroupChatServer}`;
32
32
  /**
33
33
  * A contact id ends with `@c.us` and only contains the number of the contact. For example, if the country code of a contact is `44` and their number is `7123456789` then the contact id would be `447123456789@c.us`
34
34
  *
@@ -36,7 +36,7 @@ export declare type GroupChatId = `${AccountNumber}-${number}@${GroupChatServer}
36
36
  *
37
37
  * `"447123456789@c.us"`
38
38
  */
39
- export declare type ContactId = Brand<`${AccountNumber}@${ChatServer}`, "ContactId">;
39
+ export type ContactId = Brand<`${AccountNumber}@${ChatServer}`, "ContactId">;
40
40
  /**
41
41
  * A chat id ends with `@c.us` or `@g.us` for group chats.
42
42
  *
@@ -46,7 +46,7 @@ export declare type ContactId = Brand<`${AccountNumber}@${ChatServer}`, "Contact
46
46
  * A group chat: `"447123456789@g.us"`
47
47
  *
48
48
  */
49
- export declare type ChatId = ContactId | GroupChatId;
49
+ export type ChatId = ContactId | GroupChatId;
50
50
  /**
51
51
  * The id of a message. The format is `[boolean]_[ChatId]_[random character string]`
52
52
  *
@@ -54,7 +54,7 @@ export declare type ChatId = ContactId | GroupChatId;
54
54
  *
55
55
  * `"false_447123456789@c.us_9C4D0965EA5C09D591334AB6BDB07FEB"`
56
56
  */
57
- export declare type MessageId = Brand<`${boolean}_${ChatId}_${string}`, "MessageId">;
57
+ export type MessageId = Brand<`${boolean}_${ChatId}_${string}`, "MessageId">;
58
58
  /**
59
59
  * This is a generic type alias for the content of a message
60
60
  *
@@ -62,8 +62,8 @@ export declare type MessageId = Brand<`${boolean}_${ChatId}_${string}`, "Message
62
62
  *
63
63
  * `"hello!"`
64
64
  */
65
- export declare type Content = Brand<string, "Content">;
66
- export declare type NonSerializedId = {
65
+ export type Content = Brand<string, "Content">;
66
+ export type NonSerializedId = {
67
67
  server: WaServers;
68
68
  user: AccountNumber;
69
69
  _serialized: ContactId;
@@ -80,7 +80,7 @@ export declare type NonSerializedId = {
80
80
  *
81
81
  * Learn more here: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs
82
82
  */
83
- export declare type DataURL = Brand<`data:${string};base64,${Base64}`, "DataURL">;
83
+ export type DataURL = Brand<`data:${string};base64,${Base64}`, "DataURL">;
84
84
  /**
85
85
  * Base64 is basically a file encoded as a string.
86
86
  *
@@ -88,19 +88,19 @@ export declare type DataURL = Brand<`data:${string};base64,${Base64}`, "DataURL"
88
88
  *
89
89
  * Learn more here: https://developer.mozilla.org/en-US/docs/Glossary/Base64
90
90
  */
91
- export declare type Base64 = Brand<string, "Base64">;
91
+ export type Base64 = Brand<string, "Base64">;
92
92
  /**
93
93
  * The relative or absolute path of a file
94
94
  *
95
95
  * Learn more here: https://www.w3schools.com/html/html_filepaths.asp
96
96
  */
97
- export declare type FilePath = Brand<string, "FilePath">;
97
+ export type FilePath = Brand<string, "FilePath">;
98
98
  /**
99
99
  * A URL of a file used with a GET request
100
100
  */
101
- export declare type GetURL = Brand<string, "GetURL">;
101
+ export type GetURL = Brand<string, "GetURL">;
102
102
  /**
103
103
  * Some file based actions in open-wa are powerful enough to take a dataurl, url or filepath
104
104
  */
105
- export declare type AdvancedFile = DataURL | FilePath | GetURL;
105
+ export type AdvancedFile = DataURL | FilePath | GetURL;
106
106
  export {};
@@ -105,7 +105,7 @@ export interface GroupChat extends BaseChat {
105
105
  */
106
106
  isGroup: true;
107
107
  }
108
- export declare type Chat = SingleChat | GroupChat;
108
+ export type Chat = SingleChat | GroupChat;
109
109
  export interface LiveLocationChangedEvent {
110
110
  id: string;
111
111
  lat: number;
@@ -210,4 +210,4 @@ export interface GroupChatCreationResponse {
210
210
  /**
211
211
  * Ephemeral duration can be 1 day, 7 days or 90 days. The default is 1 day.
212
212
  */
213
- export declare type EphemeralDuration = 86400 | 604800 | 7776000;
213
+ export type EphemeralDuration = 86400 | 604800 | 7776000;
@@ -36,16 +36,16 @@ export declare enum DIRECTORY_STRATEGY {
36
36
  */
37
37
  DATE_CHAT = "DATE_CHAT"
38
38
  }
39
- declare type SessionId = string;
40
- declare type LicenseKey = string;
41
- declare type HostAccountNumber = `${number}`;
42
- declare type HostAccountNumberOrSessionID = HostAccountNumber | SessionId;
43
- declare type LicenseKeyConfigObject = {
39
+ type SessionId = string;
40
+ type LicenseKey = string;
41
+ type HostAccountNumber = `${number}`;
42
+ type HostAccountNumberOrSessionID = HostAccountNumber | SessionId;
43
+ type LicenseKeyConfigObject = {
44
44
  [key: HostAccountNumberOrSessionID]: LicenseKey;
45
45
  };
46
- declare type LicenseKeyConfigFunctionReturn = LicenseKeyConfigObject | LicenseKey;
47
- declare type LicenseKeyConfigFunction = (sessionId?: SessionId, number?: HostAccountNumber) => LicenseKeyConfigFunctionReturn | Promise<LicenseKeyConfigFunctionReturn>;
48
- declare type LicenseKeyConfig = LicenseKeyConfigFunction | LicenseKeyConfigObject | LicenseKey;
46
+ type LicenseKeyConfigFunctionReturn = LicenseKeyConfigObject | LicenseKey;
47
+ type LicenseKeyConfigFunction = (sessionId?: SessionId, number?: HostAccountNumber) => LicenseKeyConfigFunctionReturn | Promise<LicenseKeyConfigFunctionReturn>;
48
+ type LicenseKeyConfig = LicenseKeyConfigFunction | LicenseKeyConfigObject | LicenseKey;
49
49
  /**
50
50
  * The available languages for the host security notification
51
51
  */
@@ -799,7 +799,7 @@ export interface ConfigObject {
799
799
  /**@internal */
800
800
  [x: string]: any;
801
801
  }
802
- export declare type AdvancedConfig = ConfigObject & {
802
+ export type AdvancedConfig = ConfigObject & {
803
803
  licenseKey: LicenseKeyConfig;
804
804
  };
805
805
  export {};
@@ -100,7 +100,7 @@ export declare enum STATE {
100
100
  */
101
101
  DISCONNECTED = "DISCONNECTED"
102
102
  }
103
- export declare type EasyApiResponse = {
103
+ export type EasyApiResponse = {
104
104
  success: boolean;
105
105
  response: any;
106
106
  };
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,4 +1,4 @@
1
- export declare type StickerMetadata = {
1
+ export type StickerMetadata = {
2
2
  /**
3
3
  * The author of the sticker
4
4
  * @default ``
@@ -53,7 +53,7 @@ export declare type StickerMetadata = {
53
53
  */
54
54
  cornerRadius?: number;
55
55
  };
56
- export declare type Mp4StickerConversionProcessOptions = {
56
+ export type Mp4StickerConversionProcessOptions = {
57
57
  /**
58
58
  * Desired Frames per second of the sticker output
59
59
  * @default `10`
@@ -3,7 +3,7 @@ import { Message, MessageAck } from "./message";
3
3
  /**
4
4
  * A reaction is identified the specific emoji.
5
5
  */
6
- export declare type Reaction = {
6
+ export type Reaction = {
7
7
  /**
8
8
  * The aggregate emoji used for the reaction.
9
9
  */
@@ -24,7 +24,7 @@ export declare type Reaction = {
24
24
  /**
25
25
  * The specific reaction by a user
26
26
  */
27
- export declare type ReactionRecord = {
27
+ export type ReactionRecord = {
28
28
  /**
29
29
  * The acknowledgement of the reaction
30
30
  */
@@ -56,7 +56,7 @@ export declare type ReactionRecord = {
56
56
  /**
57
57
  * Emitted by onReaction
58
58
  */
59
- export declare type ReactionEvent = {
59
+ export type ReactionEvent = {
60
60
  /**
61
61
  * The message being reacted to
62
62
  */
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -2,6 +2,6 @@ import { Client } from '../..';
2
2
  import { cliFlags } from '../server';
3
3
  import { Request, Response } from "express";
4
4
  export declare const chatwoot_webhook_check_event_name = "cli.integrations.chatwoot.check";
5
- export declare type expressMiddleware = (req: Request, res: Response) => Promise<Response<any, Record<string, any>>>;
5
+ export type expressMiddleware = (req: Request, res: Response) => Promise<Response<any, Record<string, any>>>;
6
6
  export declare const chatwootMiddleware: (cliConfig: cliFlags, client: Client) => expressMiddleware;
7
7
  export declare const setupChatwootOutgoingMessageHandler: (cliConfig: cliFlags, client: Client) => Promise<void>;
@@ -3,7 +3,7 @@ import http from 'http';
3
3
  import { Client } from '..';
4
4
  export declare const app: import("express-serve-static-core").Express;
5
5
  export declare let server: http.Server;
6
- export declare type cliFlags = {
6
+ export type cliFlags = {
7
7
  [k: string]: number | string | boolean;
8
8
  };
9
9
  export declare const setupHttpServer: (cliConfig: cliFlags) => void;
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -239,7 +243,7 @@ const setupMetaMiddleware = () => {
239
243
  }
240
244
  }));
241
245
  };
242
- const getCommands = () => Object.entries(collections_1.collections['swagger'].paths).reduce((acc, [key, value]) => { var _a, _b, _c, _d, _e; acc[key.replace("/", "")] = ((_e = (_d = (_c = (_b = (_a = value) === null || _a === void 0 ? void 0 : _a.post) === null || _b === void 0 ? void 0 : _b.requestBody) === null || _c === void 0 ? void 0 : _c.content["application/json"]) === null || _d === void 0 ? void 0 : _d.example) === null || _e === void 0 ? void 0 : _e.args) || {}; return acc; }, {});
246
+ const getCommands = () => Object.entries(collections_1.collections['swagger'].paths).reduce((acc, [key, value]) => { var _a, _b, _c, _d; acc[key.replace("/", "")] = ((_d = (_c = (_b = (_a = value === null || value === void 0 ? void 0 : value.post) === null || _a === void 0 ? void 0 : _a.requestBody) === null || _b === void 0 ? void 0 : _b.content["application/json"]) === null || _c === void 0 ? void 0 : _c.example) === null || _d === void 0 ? void 0 : _d.args) || {}; return acc; }, {});
243
247
  exports.getCommands = getCommands;
244
248
  const listListeners = () => {
245
249
  return Object.keys(__1.SimpleListener).map(eventKey => __1.SimpleListener[eventKey]);
package/dist/cli/setup.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -4,9 +4,9 @@ import { ConfigObject } from '../api/model';
4
4
  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
- export declare const deleteSessionData: (config: ConfigObject) => boolean;
8
- export declare const invalidateSesssionData: (config: ConfigObject) => boolean;
9
- export declare const getSessionDataFilePath: (sessionId: string, config: ConfigObject) => string | false;
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
10
  export declare const addScript: (page: Page, js: string) => Promise<unknown>;
11
11
  export declare function injectPreApiScripts(page: Page, spinner?: Spin): Promise<Page>;
12
12
  export declare function injectWapi(page: Page, spinner?: Spin, force?: boolean): Promise<Page>;
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -33,7 +37,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
33
37
  Object.defineProperty(exports, "__esModule", { value: true });
34
38
  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
39
  const path = __importStar(require("path"));
36
- const fs = __importStar(require("fs"));
40
+ const fs = __importStar(require("fs/promises"));
37
41
  const death_1 = __importDefault(require("death"));
38
42
  // import puppeteer from 'puppeteer-extra';
39
43
  const puppeteer_config_1 = require("../config/puppeteer.config");
@@ -181,7 +185,7 @@ function initPage(sessionId, config, qrManager, customUserAgent, spinner, _page,
181
185
  * AUTH
182
186
  */
183
187
  spinner === null || spinner === void 0 ? void 0 : spinner.info('Loading session data');
184
- let sessionjson = getSessionDataFromFile(sessionId, config, spinner);
188
+ let sessionjson = yield getSessionDataFromFile(sessionId, config, spinner);
185
189
  if (!sessionjson && sessionjson !== "" && config.sessionDataBucketAuth) {
186
190
  try {
187
191
  spinner === null || spinner === void 0 ? void 0 : spinner.info('Unable to find session data file locally, attempting to find session data in cloud storage..');
@@ -255,17 +259,17 @@ function initPage(sessionId, config, qrManager, customUserAgent, spinner, _page,
255
259
  });
256
260
  }
257
261
  exports.initPage = initPage;
258
- const getSessionDataFromFile = (sessionId, config, spinner) => {
262
+ const getSessionDataFromFile = (sessionId, config, spinner) => __awaiter(void 0, void 0, void 0, function* () {
259
263
  if ((config === null || config === void 0 ? void 0 : config.sessionData) == "NUKE")
260
264
  return '';
261
265
  //check if [session].json exists in __dirname
262
- const sessionjsonpath = (0, exports.getSessionDataFilePath)(sessionId, config);
266
+ const sessionjsonpath = yield (0, exports.getSessionDataFilePath)(sessionId, config);
263
267
  let sessionjson = '';
264
268
  const sd = process.env[`${sessionId.toUpperCase()}_DATA_JSON`] ? JSON.parse(process.env[`${sessionId.toUpperCase()}_DATA_JSON`]) : config === null || config === void 0 ? void 0 : config.sessionData;
265
269
  sessionjson = (typeof sd === 'string' && sd !== "") ? JSON.parse(Buffer.from(sd, 'base64').toString('ascii')) : sd;
266
- if (sessionjsonpath && typeof sessionjsonpath == 'string' && fs.existsSync(sessionjsonpath)) {
270
+ if (sessionjsonpath && typeof sessionjsonpath == 'string' && (yield (0, tools_1.pathExists)(sessionjsonpath))) {
267
271
  spinner.succeed(`Found session data file: ${sessionjsonpath}`);
268
- const s = fs.readFileSync(sessionjsonpath, "utf8");
272
+ const s = yield fs.readFile(sessionjsonpath, "utf8");
269
273
  try {
270
274
  sessionjson = JSON.parse(s);
271
275
  }
@@ -288,53 +292,48 @@ const getSessionDataFromFile = (sessionId, config, spinner) => {
288
292
  spinner.succeed(`No session data file found for session : ${sessionId}`);
289
293
  }
290
294
  return sessionjson;
291
- };
292
- const deleteSessionData = (config) => {
293
- const sessionjsonpath = (0, exports.getSessionDataFilePath)((config === null || config === void 0 ? void 0 : config.sessionId) || 'session', config);
294
- if (typeof sessionjsonpath == 'string' && fs.existsSync(sessionjsonpath)) {
295
+ });
296
+ const deleteSessionData = (config) => __awaiter(void 0, void 0, void 0, function* () {
297
+ const sessionjsonpath = yield (0, exports.getSessionDataFilePath)((config === null || config === void 0 ? void 0 : config.sessionId) || 'session', config);
298
+ if (typeof sessionjsonpath == 'string' && (yield (0, tools_1.pathExists)(sessionjsonpath))) {
295
299
  const l = `logout detected, deleting session data file: ${sessionjsonpath}`;
296
300
  console.log(l);
297
301
  logging_1.log.info(l);
298
- fs.unlinkSync(sessionjsonpath);
302
+ yield fs.unlink(sessionjsonpath);
299
303
  }
300
- const mdDir = config['userDataDir'];
301
- if (mdDir) {
304
+ const mdDir = yield (0, tools_1.pathExists)(config['userDataDir']);
305
+ if (config['userDataDir'] && mdDir) {
302
306
  logging_1.log.info(`Deleting MD session directory: ${mdDir}`);
303
- //@ts-ignore
304
- fs.rmdirSync(mdDir, { force: true, recursive: true });
307
+ yield fs.rm(mdDir, { force: true, recursive: true });
308
+ logging_1.log.info(`MD directory ${mdDir} deleted: ${!(yield (0, tools_1.pathExists)(mdDir, true))}`);
305
309
  }
306
310
  return true;
307
- };
311
+ });
308
312
  exports.deleteSessionData = deleteSessionData;
309
- const invalidateSesssionData = (config) => {
310
- const sessionjsonpath = (0, exports.getSessionDataFilePath)((config === null || config === void 0 ? void 0 : config.sessionId) || 'session', config);
311
- if (typeof sessionjsonpath == 'string' && fs.existsSync(sessionjsonpath)) {
313
+ const invalidateSesssionData = (config) => __awaiter(void 0, void 0, void 0, function* () {
314
+ const sessionjsonpath = yield (0, exports.getSessionDataFilePath)((config === null || config === void 0 ? void 0 : config.sessionId) || 'session', config);
315
+ if (typeof sessionjsonpath == 'string' && (yield (0, tools_1.pathExists)(sessionjsonpath))) {
312
316
  const l = `logout detected, invalidating session data file: ${sessionjsonpath}`;
313
317
  console.log(l);
314
318
  logging_1.log.info(l);
315
- fs.writeFile(sessionjsonpath, "LOGGED OUT", (err) => {
316
- if (err) {
317
- console.error(err);
318
- return;
319
- }
320
- });
319
+ fs.writeFile(sessionjsonpath, "LOGGED OUT");
321
320
  }
322
321
  return true;
323
- };
322
+ });
324
323
  exports.invalidateSesssionData = invalidateSesssionData;
325
- const getSessionDataFilePath = (sessionId, config) => {
324
+ const getSessionDataFilePath = (sessionId, config) => __awaiter(void 0, void 0, void 0, function* () {
326
325
  var _a, _b;
327
326
  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);
328
327
  const sessionjsonpath = ((config === null || config === void 0 ? void 0 : config.sessionDataPath) && (config === null || config === void 0 ? void 0 : config.sessionDataPath.includes('.data.json'))) ? path.join(path.resolve(process.cwd(), (config === null || config === void 0 ? void 0 : config.sessionDataPath) || '')) : path.join(path.resolve(process.cwd(), (config === null || config === void 0 ? void 0 : config.sessionDataPath) || ''), `${sessionId || 'session'}.data.json`);
329
328
  const altSessionJsonPath = p ? ((config === null || config === void 0 ? void 0 : config.sessionDataPath) && (config === null || config === void 0 ? void 0 : config.sessionDataPath.includes('.data.json'))) ? path.join(path.resolve(p, (config === null || config === void 0 ? void 0 : config.sessionDataPath) || '')) : path.join(path.resolve(p, (config === null || config === void 0 ? void 0 : config.sessionDataPath) || ''), `${sessionId || 'session'}.data.json`) : false;
330
- if (fs.existsSync(sessionjsonpath)) {
329
+ if ((0, tools_1.pathExists)(sessionjsonpath)) {
331
330
  return sessionjsonpath;
332
331
  }
333
- else if (p && altSessionJsonPath && fs.existsSync(altSessionJsonPath)) {
332
+ else if (p && altSessionJsonPath && (yield (0, tools_1.pathExists)(altSessionJsonPath))) {
334
333
  return altSessionJsonPath;
335
334
  }
336
335
  return false;
337
- };
336
+ });
338
337
  exports.getSessionDataFilePath = getSessionDataFilePath;
339
338
  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)); });
340
339
  exports.addScript = addScript;
@@ -453,9 +452,9 @@ function initBrowser(sessionId, config = {}, spinner) {
453
452
  }
454
453
  if (config === null || config === void 0 ? void 0 : config.corsFix)
455
454
  args.push('--disable-web-security');
456
- if (config["userDataDir"] && !fs.existsSync(config["userDataDir"])) {
455
+ if (config["userDataDir"] && !(yield (0, tools_1.pathExists)(config["userDataDir"]))) {
457
456
  spinner === null || spinner === void 0 ? void 0 : spinner.info(`Data dir doesnt exist, creating...: ${config["userDataDir"]}`);
458
- fs.mkdirSync(config["userDataDir"], { recursive: true });
457
+ fs.mkdir(config["userDataDir"], { recursive: true });
459
458
  }
460
459
  const browser = (config === null || config === void 0 ? void 0 : config.browserWSEndpoint) ? yield puppeteer.connect(Object.assign({}, config)) : yield puppeteer.launch(Object.assign(Object.assign({ headless: true, args }, config), { devtools: false }));
461
460
  exports.BROWSER_START_TS = Date.now();
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -251,7 +255,7 @@ function create(config = {}) {
251
255
  spinner.fail("Session data most likely expired due to manual host account logout. Please re-authenticate this session.");
252
256
  yield (0, browser_1.kill)(waPage);
253
257
  if (config === null || config === void 0 ? void 0 : config.deleteSessionDataOnLogout)
254
- (0, browser_1.deleteSessionData)(config);
258
+ yield (0, browser_1.deleteSessionData)(config);
255
259
  if (config === null || config === void 0 ? void 0 : config.throwOnExpiredSessionData) {
256
260
  throw new index_1.SessionExpiredError();
257
261
  }
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -153,8 +157,9 @@ function getLicense(config, me, debugInfo, spinner) {
153
157
  //run the funciton to get the key
154
158
  config.licenseKey = yield config.licenseKey(config.sessionId, me._serialized);
155
159
  }
156
- if (typeof config.licenseKey === "object") {
160
+ if (config.licenseKey && typeof config.licenseKey === "object") {
157
161
  //attempt to get the key from the object
162
+ //@ts-ignore
158
163
  config.licenseKey = config.licenseKey[me._serialized] || config.licenseKey[config.sessionId];
159
164
  }
160
165
  //asume by now the key is a string
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
package/dist/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -29,7 +29,7 @@ export declare const addRotateFileLogTransport: (options?: any) => void;
29
29
  * @private
30
30
  */
31
31
  export declare const addSysLogTransport: (options?: any) => void;
32
- export declare type ConfigLogTransport = {
32
+ export type ConfigLogTransport = {
33
33
  /**
34
34
  * The type of winston transport. At the moment only `file`, `console`, `ev` and `syslog` are supported.
35
35
  */
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  /**
3
4
  * This code is a copy of the Discord Collector: https://github.com/discordjs/discord.js/blob/stable/src/structures/interfaces/Collector.js
4
5
  *
@@ -16,7 +17,7 @@ export declare class Collection<K, V> extends BaseCollection<K, V> {
16
17
  * @param {Collection} collection The items collected by this collector
17
18
  * @returns {boolean|Promise<boolean>}
18
19
  */
19
- export declare type CollectorFilter<T extends any[]> = (...args: T) => boolean | Promise<boolean>;
20
+ export type CollectorFilter<T extends any[]> = (...args: T) => boolean | Promise<boolean>;
20
21
  /**
21
22
  * Options to be applied to the collector.
22
23
  */
@@ -20,7 +20,7 @@ export interface DialogTemplate {
20
20
  [key: string]: DialogProperty;
21
21
  };
22
22
  }
23
- export declare type CheckFunction = (lastReceivedMessage: Message, currentProps: CurrentDialogProps) => boolean;
23
+ export type CheckFunction = (lastReceivedMessage: Message, currentProps: CurrentDialogProps) => boolean;
24
24
  export interface DialogProperty {
25
25
  "order": number;
26
26
  "key": string;
@@ -1,6 +1,6 @@
1
1
  import { Client } from "../api/Client";
2
2
  import { Message } from "../api/model/message";
3
- export declare type MessagePreProcessor = (message: Message, client?: Client) => Promise<Message>;
3
+ export type MessagePreProcessor = (message: Message, client?: Client) => Promise<Message>;
4
4
  /**
5
5
  * An object that contains all available [[PREPROCESSORS]].
6
6
  *
@@ -47,4 +47,4 @@ export declare enum PREPROCESSORS {
47
47
  /**
48
48
  * The actual type for [config.messagePreprocessor](/docs/api/interfaces/api_model_config.ConfigObject#messagepreprocessor)
49
49
  */
50
- export declare type MPConfigType = PREPROCESSORS | MessagePreProcessor | (PREPROCESSORS | MessagePreProcessor)[];
50
+ export type MPConfigType = PREPROCESSORS | MessagePreProcessor | (PREPROCESSORS | MessagePreProcessor)[];
@@ -1,6 +1,8 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
2
4
  import { AdvancedFile, ConfigObject, DataURL } from '../api/model';
3
- import { AxiosRequestConfig } from 'axios';
5
+ import { AxiosRequestConfig, AxiosResponseHeaders } from 'axios';
4
6
  import { SessionInfo } from '../api/model/sessionInfo';
5
7
  import { Readable } from "stream";
6
8
  export declare const timeout: (ms: any) => Promise<unknown>;
@@ -31,6 +33,13 @@ export declare const isBase64: (str: string) => boolean;
31
33
  * @returns
32
34
  */
33
35
  export declare const isDataURL: (s: string) => boolean;
36
+ /**
37
+ * @internal
38
+ * A convinience method to download the buffer of a downloaded file
39
+ * @param url The url
40
+ * @param optionsOverride You can use this to override the [axios request config](https://github.com/axios/axios#request-config)
41
+ */
42
+ export declare const getBufferFromUrl: (url: string, optionsOverride?: AxiosRequestConfig) => Promise<[Buffer, AxiosResponseHeaders]>;
34
43
  /**
35
44
  * @internal
36
45
  * A convinience method to download the [[DataURL]] of a file
@@ -117,3 +126,19 @@ export declare function rmFileAsync(file: string): Promise<unknown>;
117
126
  * @param requestConfig optional axios config if file parameter is a url
118
127
  */
119
128
  export declare const assertFile: (file: AdvancedFile | Buffer, outfileName: string, desiredOutputType: keyof typeof FileOutputTypes, requestConfig?: any) => Promise<string | Buffer | Readable>;
129
+ /**
130
+ * Checks if a given path exists.
131
+ *
132
+ * If exists, returns the resolved absolute path. Otherwise returns false.
133
+ *
134
+ * @param _path a relative, absolute or homedir path to a folder or a file
135
+ * @param failSilent If you're expecting for the file to not exist and just want the `false` response then set this to true to prevent false-positive error messages in the logs.
136
+ * @returns string | false
137
+ */
138
+ export declare const pathExists: (_path: string, failSilent?: boolean) => Promise<string | false>;
139
+ /**
140
+ * Returns an absolute file path reference
141
+ * @param _path a relative, absolute or homedir path to a folder or a file
142
+ * @returns string
143
+ */
144
+ export declare const fixPath: (_path: string) => string;
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -42,20 +46,31 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
42
46
  return (mod && mod.__esModule) ? mod : { "default": mod };
43
47
  };
44
48
  Object.defineProperty(exports, "__esModule", { value: true });
45
- exports.assertFile = exports.rmFileAsync = exports.FileOutputTypes = exports.FileInputTypes = exports.ensureDUrl = exports.generateGHIssueLink = exports.processSendData = exports.timePromise = exports.now = exports.perf = exports.processSend = exports.base64MimeType = exports.getDUrl = exports.isDataURL = exports.isBase64 = exports.camelize = exports.without = exports.getConfigFromProcessEnv = exports.smartUserAgent = exports.timeout = void 0;
49
+ exports.fixPath = exports.pathExists = exports.assertFile = exports.rmFileAsync = exports.FileOutputTypes = exports.FileInputTypes = exports.ensureDUrl = exports.generateGHIssueLink = exports.processSendData = exports.timePromise = exports.now = exports.perf = exports.processSend = exports.base64MimeType = exports.getDUrl = exports.getBufferFromUrl = exports.isDataURL = exports.isBase64 = exports.camelize = exports.without = exports.getConfigFromProcessEnv = exports.smartUserAgent = exports.timeout = void 0;
46
50
  const crypto_1 = __importDefault(require("crypto"));
47
51
  const fs = __importStar(require("fs"));
52
+ const fsp = __importStar(require("fs/promises"));
48
53
  const path = __importStar(require("path"));
49
54
  const datauri_1 = __importDefault(require("datauri"));
50
55
  const is_url_superb_1 = __importDefault(require("is-url-superb"));
51
56
  const model_1 = require("../api/model");
52
57
  const axios_1 = __importDefault(require("axios"));
53
58
  const child_process_1 = require("child_process");
59
+ const os_1 = require("os");
54
60
  const perf_hooks_1 = require("perf_hooks");
55
61
  const mime_1 = __importDefault(require("mime"));
56
- const os_1 = require("os");
62
+ const os_2 = require("os");
57
63
  const stream_1 = require("stream");
58
64
  const logging_1 = require("../logging/logging");
65
+ const import_1 = require("@brillout/import");
66
+ let _ft = null;
67
+ const ft = () => __awaiter(void 0, void 0, void 0, function* () {
68
+ if (!_ft) {
69
+ const x = yield (0, import_1.import_)('file-type');
70
+ _ft = x;
71
+ }
72
+ return _ft;
73
+ });
59
74
  //@ts-ignore
60
75
  process.send = process.send || function () { };
61
76
  const timeout = ms => new Promise(resolve => setTimeout(resolve, ms, 'timeout'));
@@ -139,18 +154,35 @@ const isDataURL = (s) => !!s.match(/^data:((?:\w+\/(?:(?!;).)+)?)((?:;[\w\W]*?[^
139
154
  exports.isDataURL = isDataURL;
140
155
  /**
141
156
  * @internal
142
- * A convinience method to download the [[DataURL]] of a file
157
+ * A convinience method to download the buffer of a downloaded file
143
158
  * @param url The url
144
159
  * @param optionsOverride You can use this to override the [axios request config](https://github.com/axios/axios#request-config)
145
160
  */
146
- const getDUrl = (url, optionsOverride = {}) => __awaiter(void 0, void 0, void 0, function* () {
161
+ const getBufferFromUrl = (url, optionsOverride = {}) => __awaiter(void 0, void 0, void 0, function* () {
147
162
  // eslint-disable-next-line no-useless-catch
148
163
  try {
149
164
  const res = yield (0, axios_1.default)(Object.assign(Object.assign({ method: 'get', url, headers: {
150
165
  DNT: 1,
151
166
  'Upgrade-Insecure-Requests': 1,
152
167
  } }, optionsOverride), { responseType: 'arraybuffer' }));
153
- const dUrl = `data:${res.headers['content-type']};base64,${Buffer.from(res.data, 'binary').toString('base64')}`;
168
+ return [Buffer.from(res.data, 'binary'), res.headers];
169
+ }
170
+ catch (error) {
171
+ throw error;
172
+ }
173
+ });
174
+ exports.getBufferFromUrl = getBufferFromUrl;
175
+ /**
176
+ * @internal
177
+ * A convinience method to download the [[DataURL]] of a file
178
+ * @param url The url
179
+ * @param optionsOverride You can use this to override the [axios request config](https://github.com/axios/axios#request-config)
180
+ */
181
+ const getDUrl = (url, optionsOverride = {}) => __awaiter(void 0, void 0, void 0, function* () {
182
+ // eslint-disable-next-line no-useless-catch
183
+ try {
184
+ const [buff, headers] = yield (0, exports.getBufferFromUrl)(url, optionsOverride);
185
+ const dUrl = `data:${headers['content-type']};base64,${buff.toString('base64')}`;
154
186
  return dUrl;
155
187
  }
156
188
  catch (error) {
@@ -270,6 +302,10 @@ exports.generateGHIssueLink = generateGHIssueLink;
270
302
  */
271
303
  const ensureDUrl = (file, requestConfig = {}, filename) => __awaiter(void 0, void 0, void 0, function* () {
272
304
  if (Buffer.isBuffer(file)) {
305
+ if (!filename) {
306
+ const { ext } = yield (yield ft()).fileTypeFromBuffer(file);
307
+ filename = `file.${ext}`;
308
+ }
273
309
  return `data:${mime_1.default.lookup(filename)};base64,${file.toString('base64').split(',')[1]}`;
274
310
  }
275
311
  else if (!(0, exports.isDataURL)(file) && !(0, exports.isBase64)(file)) {
@@ -284,6 +320,10 @@ const ensureDUrl = (file, requestConfig = {}, filename) => __awaiter(void 0, voi
284
320
  else
285
321
  throw new model_1.CustomError(model_1.ERROR_NAME.FILE_NOT_FOUND, 'Cannot find file. Make sure the file reference is relative, a valid URL or a valid DataURL');
286
322
  }
323
+ if (!filename) {
324
+ const { ext } = yield (yield ft()).fileTypeFromBuffer(Buffer.from(file.split(',')[1], 'base64'));
325
+ filename = `file.${ext}`;
326
+ }
287
327
  if (file.includes("data:") && file.includes("undefined") || file.includes("application/octet-stream") && filename && mime_1.default.lookup(filename)) {
288
328
  file = `data:${mime_1.default.lookup(filename)};base64,${file.split(',')[1]}`;
289
329
  }
@@ -367,13 +407,17 @@ const assertFile = (file, outfileName, desiredOutputType, requestConfig) => __aw
367
407
  /**
368
408
  * Create a temp file in tempdir, return the tempfile.
369
409
  */
370
- const tempFilePath = path.join((0, os_1.tmpdir)(), `${crypto_1.default.randomBytes(6).readUIntLE(0, 6).toString(36)}.${outfileName}`);
371
- logging_1.log.info(`Saved temporary file to ${tempFilePath}`);
410
+ let tfn = `${crypto_1.default.randomBytes(6).readUIntLE(0, 6).toString(36)}.${outfileName}`;
372
411
  if (inputType != exports.FileInputTypes.BUFFER) {
373
412
  file = yield (0, exports.ensureDUrl)(file, requestConfig, outfileName);
413
+ const ext = mime_1.default.extension(file.match(/[^:]\w+\/[\w-+\d.]+(?=;|,)/)[0]);
414
+ if (ext && !tfn.endsWith(ext))
415
+ tfn = `${tfn}.${ext}`;
374
416
  file = Buffer.from(file.split(',')[1], 'base64');
375
417
  }
418
+ const tempFilePath = path.join((0, os_2.tmpdir)(), tfn);
376
419
  yield fs.writeFileSync(tempFilePath, file);
420
+ logging_1.log.info(`Saved temporary file to ${tempFilePath}`);
377
421
  return tempFilePath;
378
422
  break;
379
423
  }
@@ -392,3 +436,36 @@ const assertFile = (file, outfileName, desiredOutputType, requestConfig) => __aw
392
436
  return file;
393
437
  });
394
438
  exports.assertFile = assertFile;
439
+ /**
440
+ * Checks if a given path exists.
441
+ *
442
+ * If exists, returns the resolved absolute path. Otherwise returns false.
443
+ *
444
+ * @param _path a relative, absolute or homedir path to a folder or a file
445
+ * @param failSilent If you're expecting for the file to not exist and just want the `false` response then set this to true to prevent false-positive error messages in the logs.
446
+ * @returns string | false
447
+ */
448
+ const pathExists = (_path, failSilent) => __awaiter(void 0, void 0, void 0, function* () {
449
+ _path = (0, exports.fixPath)(_path);
450
+ try {
451
+ yield fsp.access(_path, fsp.constants.R_OK | fsp.constants.W_OK);
452
+ return _path;
453
+ }
454
+ catch (error) {
455
+ if (!failSilent)
456
+ logging_1.log.error('Given check path threw an error', error);
457
+ return false;
458
+ }
459
+ });
460
+ exports.pathExists = pathExists;
461
+ /**
462
+ * Returns an absolute file path reference
463
+ * @param _path a relative, absolute or homedir path to a folder or a file
464
+ * @returns string
465
+ */
466
+ const fixPath = (_path) => {
467
+ _path = _path.replace("~", (0, os_1.homedir)());
468
+ _path = _path.includes('./') ? path.join(process.cwd(), _path) : _path;
469
+ return _path;
470
+ };
471
+ exports.fixPath = fixPath;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-wa/wa-automate",
3
- "version": "4.50.1",
3
+ "version": "4.51.0",
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",
@@ -97,14 +97,14 @@
97
97
  "shelljs": "^0.8.3",
98
98
  "tiny-glob": "^0.2.9",
99
99
  "ts-json-schema-generator": "^v1.1.0-next.5",
100
- "ts-node": "^10.0.0",
100
+ "ts-node": "^10.9.1",
101
101
  "tsc-watch": "^4.0.0",
102
102
  "typeconv": "^1.7.0",
103
- "typedoc": "^0.21.6",
104
- "typedoc-plugin-pages": "^1.0.1",
105
- "typescript": "^4.4.4"
103
+ "typedoc": "^0.23.21",
104
+ "typescript": "^4.9.3"
106
105
  },
107
106
  "dependencies": {
107
+ "@brillout/import": "^0.2.1",
108
108
  "@discordjs/collection": "^0.5.0",
109
109
  "@open-wa/wa-automate-socket-client": "*",
110
110
  "@open-wa/wa-decrypt": "^4.3.1",
@@ -127,6 +127,7 @@
127
127
  "express": "^4.17.1",
128
128
  "express-ipfilter": "^1.3.1",
129
129
  "express-robots-txt": "^1.0.0",
130
+ "file-type": "^18.0.0",
130
131
  "find-up": "^5.0.0",
131
132
  "form-data": "^4.0.0",
132
133
  "fs-extra": "^10.0.0",
@@ -170,6 +171,7 @@
170
171
  "terminal-link": "^2.1.1",
171
172
  "terminate": "^2.5.0",
172
173
  "traverse": "^0.6.6",
174
+ "ts-loader": "^9.4.1",
173
175
  "ts-morph": "^12.0.0",
174
176
  "type-fest": "^1.1.1",
175
177
  "update-notifier": "^5.0.0",