@open-wa/wa-automate 4.23.18 → 4.24.0

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.
@@ -471,20 +471,28 @@ class Client {
471
471
  const res = yield this._page.evaluate(pageFunction, ...args);
472
472
  if (this._createConfig.onError && typeof res == "string" && (res.startsWith("Error") || res.startsWith("ERROR"))) {
473
473
  const e = this._createConfig.onError;
474
- if (e == model_1.OnError.AS_STRING || e == model_1.OnError.NOTHING)
475
- return res;
476
- if (e == model_1.OnError.LOG_AND_FALSE) {
477
- console.error(res);
478
- return true;
479
- }
480
- if (e == model_1.OnError.LOG_AND_STRING) {
474
+ /**
475
+ * Log error
476
+ */
477
+ if (e == model_1.OnError.LOG_AND_FALSE ||
478
+ e == model_1.OnError.LOG_AND_STRING ||
479
+ res.includes("get.openwa.dev"))
481
480
  console.error(res);
481
+ /**
482
+ * Return res
483
+ */
484
+ if (e == model_1.OnError.AS_STRING ||
485
+ e == model_1.OnError.NOTHING ||
486
+ e == model_1.OnError.LOG_AND_STRING)
482
487
  return res;
483
- }
488
+ /**
489
+ * Return false
490
+ */
491
+ if (e == model_1.OnError.LOG_AND_FALSE ||
492
+ e == model_1.OnError.RETURN_FALSE)
493
+ return false;
484
494
  if (e == model_1.OnError.RETURN_ERROR)
485
495
  return new Error(res);
486
- if (e == model_1.OnError.RETURN_FALSE)
487
- return false;
488
496
  if (e == model_1.OnError.THROW)
489
497
  throw new Error(res);
490
498
  }
@@ -37,7 +37,8 @@ const postman_2_swagger_1 = __importDefault(require("postman-2-swagger"));
37
37
  const fs_extra_1 = require("fs-extra");
38
38
  const typeconv_1 = require("typeconv");
39
39
  const fs = __importStar(require("fs"));
40
- const glob_promise_1 = __importDefault(require("glob-promise"));
40
+ const glob = require("tiny-glob");
41
+ const path = __importStar(require("path"));
41
42
  exports.collections = {};
42
43
  const generateCollections = (config, spinner) => __awaiter(void 0, void 0, void 0, function* () {
43
44
  let swCol = null;
@@ -118,7 +119,7 @@ const getTypeSchemas = () => __awaiter(void 0, void 0, void 0, function* () {
118
119
  const { convert } = typeconv_1.makeConverter(reader, writer, {
119
120
  simplify: true
120
121
  });
121
- const s = (yield Promise.all([...(yield glob_promise_1.default('../**/*.d.ts')), ...(yield glob_promise_1.default('../**/message.js')), ...(yield glob_promise_1.default('../**/chat.js'))])).filter(f => !f.includes('node_modules'));
122
+ const s = (yield Promise.all([...(yield glob(path.resolve(__dirname, '../**/*.d.ts'))), ...(yield glob(path.resolve(__dirname, '../**/message.js'))), ...(yield glob(path.resolve(__dirname, '../**/chat.js')))])).filter(f => !f.includes('node_modules'));
122
123
  const res = {};
123
124
  yield Promise.all(s.map((x) => __awaiter(void 0, void 0, void 0, function* () {
124
125
  var _a, _b;
package/dist/cli/index.js CHANGED
@@ -20,6 +20,7 @@ const axios_1 = __importDefault(require("axios"));
20
20
  const setup_1 = require("./setup");
21
21
  const collections_1 = require("./collections");
22
22
  const server_1 = require("./server");
23
+ const localtunnel_1 = __importDefault(require("localtunnel"));
23
24
  let checkUrl = (s) => (typeof s === "string") && is_url_superb_1.default(s);
24
25
  const ready = (config) => __awaiter(void 0, void 0, void 0, function* () {
25
26
  if (process.send) {
@@ -176,6 +177,11 @@ function start() {
176
177
  spinner.succeed(`\n• Listening on port ${PORT}!`);
177
178
  yield ready(Object.assign(Object.assign(Object.assign(Object.assign({}, cliConfig), createConfig), client.getSessionInfo()), { hostAccountNumber: yield client.getHostNumber() }));
178
179
  }));
180
+ if (cliConfig.tunnel) {
181
+ spinner.info(`\n• Setting up external tunnel`);
182
+ const tunnel = yield localtunnel_1.default({ port: PORT });
183
+ spinner.succeed(`\n\t${terminal_link_1.default('External address', tunnel.url)}`);
184
+ }
179
185
  const apiDocsUrl = cliConfig.apiHost ? `${cliConfig.apiHost}/api-docs/ ` : `${cliConfig.host.includes('http') ? '' : 'http://'}${cliConfig.host}:${PORT}/api-docs/ `;
180
186
  const link = terminal_link_1.default('API Explorer', apiDocsUrl);
181
187
  if (cliConfig && cliConfig.generateApiDocs)
package/dist/cli/setup.js CHANGED
@@ -251,6 +251,11 @@ const optionList = [{
251
251
  type: Boolean,
252
252
  description: "Don't validate webhook URLs. Enables use of non-FQDNs."
253
253
  },
254
+ {
255
+ name: 'tunnel',
256
+ type: Boolean,
257
+ description: "Expose a tunnel to your EASY API session - this is for testing and it is unsecured."
258
+ },
254
259
  {
255
260
  name: 'help',
256
261
  description: 'Print this usage guide.'
@@ -4,8 +4,8 @@ declare const puppeteerConfig: {
4
4
  height: number;
5
5
  chromiumArgs: string[];
6
6
  };
7
- export declare const useragent = "WhatsApp/2.2108.8 Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36";
8
7
  export declare const createUserAgent: (waVersion: string) => string;
8
+ export declare const useragent: string;
9
9
  export { puppeteerConfig };
10
10
  export declare const width: number;
11
11
  export declare const height: number;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.height = exports.width = exports.puppeteerConfig = exports.createUserAgent = exports.useragent = void 0;
3
+ exports.height = exports.width = exports.puppeteerConfig = exports.useragent = exports.createUserAgent = void 0;
4
4
  const puppeteerConfig = {
5
5
  WAUrl: 'https://web.whatsapp.com',
6
6
  width: 1440,
@@ -52,8 +52,8 @@ const puppeteerConfig = {
52
52
  ]
53
53
  };
54
54
  exports.puppeteerConfig = puppeteerConfig;
55
- exports.useragent = 'WhatsApp/2.2108.8 Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36';
56
- const createUserAgent = (waVersion) => `WhatsApp/${waVersion} Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36`;
55
+ const createUserAgent = (waVersion) => `WhatsApp/${waVersion} Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36`;
57
56
  exports.createUserAgent = createUserAgent;
57
+ exports.useragent = exports.createUserAgent('2.2144.11');
58
58
  exports.width = puppeteerConfig.width;
59
59
  exports.height = puppeteerConfig.height;
@@ -157,11 +157,11 @@ function create(config = {}) {
157
157
  /**
158
158
  * Check if the IGNORE folder exists, therefore, assume that the session is MD.
159
159
  */
160
- // const mdDir = config["userDataDir"] || `${config?.inDocker ? '/sessions' : config?.sessionDataPath || '.' }/_IGNORE_${config?.sessionId || 'session'}`
161
- // if(fs.existsSync(mdDir) && !config?.multiDevice) {
162
- // spinner.info(`Multi-Device directory detected. multiDevice set to true.`);
163
- // config.multiDevice = true;
164
- // }
160
+ const mdDir = config["userDataDir"] || `${(config === null || config === void 0 ? void 0 : config.inDocker) ? '/sessions' : (config === null || config === void 0 ? void 0 : config.sessionDataPath) || '.'}/_IGNORE_${(config === null || config === void 0 ? void 0 : config.sessionId) || 'session'}`;
161
+ if (process.env.AUTO_MD && fs.existsSync(mdDir) && !(config === null || config === void 0 ? void 0 : config.multiDevice)) {
162
+ spinner.info(`Multi-Device directory detected. multiDevice set to true.`);
163
+ config.multiDevice = true;
164
+ }
165
165
  if ((config === null || config === void 0 ? void 0 : config.multiDevice) && (config === null || config === void 0 ? void 0 : config.chromiumArgs))
166
166
  spinner.info(`Using custom chromium args with multi device will cause issues! Please remove themm`);
167
167
  if ((config === null || config === void 0 ? void 0 : config.multiDevice) && !(config === null || config === void 0 ? void 0 : config.useChrome))
@@ -269,7 +269,10 @@ function create(config = {}) {
269
269
  const race = [];
270
270
  race.push(auth_1.smartQr(waPage, config, spinner));
271
271
  if ((config === null || config === void 0 ? void 0 : config.qrTimeout) !== 0) {
272
- race.push(timeout(((config === null || config === void 0 ? void 0 : config.qrTimeout) || 60) * 1000));
272
+ let to = ((config === null || config === void 0 ? void 0 : config.qrTimeout) || 60) * 1000;
273
+ if (config === null || config === void 0 ? void 0 : config.multiDevice)
274
+ to = to * 2;
275
+ race.push(timeout(to));
273
276
  }
274
277
  const result = yield Promise.race(race);
275
278
  if (result === "MULTI_DEVICE_DETECTED" && !(config === null || config === void 0 ? void 0 : config.multiDevice)) {
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@open-wa/wa-automate",
3
- "version": "4.23.18",
3
+ "version": "4.24.0",
4
4
  "licenseCheckUrl": "https://openwa.dev/license-check",
5
5
  "brokenMethodReportUrl": "https://openwa.dev/report-bm",
6
- "patches": "https://cdn.openwa.dev/patches.json",
6
+ "patches": "http://127.0.0.1:5503/functions/patches.json",
7
7
  "stickerUrl": "https://sticker-api.openwa.dev",
8
8
  "description": " 💬 🤖 The most reliable NodeJS whatsapp library for chatbots with advanced features.",
9
9
  "main": "dist/index.js",
@@ -69,6 +69,7 @@
69
69
  "@types/express": "^4.17.11",
70
70
  "@types/fs-extra": "^9.0.11",
71
71
  "@types/line-reader": "0.0.34",
72
+ "@types/localtunnel": "^2.0.1",
72
73
  "@types/marked": "^3.0.0",
73
74
  "@types/mime-types": "^2.1.0",
74
75
  "@types/node": "^16.0.0",
@@ -120,11 +121,11 @@
120
121
  "find-up": "^5.0.0",
121
122
  "fs-extra": "^10.0.0",
122
123
  "get-port": "^5.1.1",
123
- "glob-promise": "^4.2.2",
124
124
  "hasha": "^5.2.0",
125
125
  "image-type": "^4.1.0",
126
126
  "is-url-superb": "^5.0.0",
127
127
  "json5": "^2.2.0",
128
+ "localtunnel": "^2.0.2",
128
129
  "lodash.uniq": "^4.5.0",
129
130
  "meow": "^9.0.0",
130
131
  "node-persist": "^3.1.0",
@@ -154,6 +155,7 @@
154
155
  "swagger-ui-express": "^4.1.4",
155
156
  "tcp-port-used": "^1.0.1",
156
157
  "terminal-link": "^2.1.1",
158
+ "tiny-glob": "^0.2.9",
157
159
  "tree-kill": "^1.2.2",
158
160
  "ts-json-schema-generator": "^0.95.0",
159
161
  "ts-morph": "^12.0.0",