@open-wa/wa-automate 4.34.3 → 4.35.1

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/bin/server.js CHANGED
@@ -1,3 +1,40 @@
1
1
  #! /usr/bin/env node
2
- // require('./index.js');
3
- require('../dist/cli');
2
+ const pm2Index = process.argv.findIndex(arg => arg === "--pm2");
3
+ const sIdIndex = process.argv.findIndex(arg => arg === "--session-id");
4
+ const nameIndex = process.argv.findIndex(arg => arg === "--name");
5
+ const getVal = (index) => index !== -1 && process.argv[index + 1]
6
+ const getBool = (index) => !((index !== -1 && process.argv[index + 1]) === false)
7
+ const procName = getVal(sIdIndex || nameIndex) || "@OPEN-WA EASY API";
8
+ const CLI = '../dist/cli'
9
+ async function start() {
10
+ if (getBool(pm2Index)) {
11
+ const { spawn } = require("child_process");
12
+ try {
13
+ const pm2 = spawn('pm2');
14
+ await new Promise((resolve, reject) => {
15
+ pm2.on('error', reject);
16
+ pm2.stdout.on('data', () => resolve(true));
17
+ })
18
+ const pm2Flags = (getVal(pm2Index) || "").split(" ");
19
+ const cliFlags = (process.argv.slice(2) || []);
20
+ spawn("pm2", [
21
+ "start",
22
+ require.resolve(CLI),
23
+ '--name',
24
+ procName,
25
+ ...pm2Flags,
26
+ '--',
27
+ ...cliFlags.filter(x=>!pm2Flags.includes(x))
28
+ ], {
29
+ stdio: "inherit",
30
+ detached: true
31
+ })
32
+ } catch (error) {
33
+ if (error.errorno === -2) console.error("pm2 not found. Please install with the following command: npm install -g pm2");
34
+ }
35
+ } else {
36
+ require(CLI);
37
+ }
38
+ }
39
+
40
+ start()
@@ -234,6 +234,12 @@ exports.optionList = [{
234
234
  type: Boolean,
235
235
  description: "Expose a tunnel to your EASY API session - this is for testing and it is unsecured."
236
236
  },
237
+ {
238
+ name: 'pm2',
239
+ type: Boolean,
240
+ typeLabel: '{yellow {underline "--max-memory-restart 300M"}}',
241
+ description: "Offload the EASY API to local instance of pm2. You can add pm2 specific arguments also if you want."
242
+ },
237
243
  {
238
244
  name: 'help',
239
245
  description: 'Print this usage guide.'
package/dist/cli/index.js CHANGED
@@ -183,7 +183,7 @@ function start() {
183
183
  spinner.succeed(`Port ${PORT} is now free.`);
184
184
  server_1.server.listen(PORT, () => __awaiter(this, void 0, void 0, function* () {
185
185
  spinner.succeed(`\n• Listening on port ${PORT}!`);
186
- yield (0, index_1.processSendData)({ port: PORT });
186
+ (0, index_1.processSendData)({ port: PORT });
187
187
  yield ready(Object.assign(Object.assign(Object.assign(Object.assign({}, cliConfig), createConfig), client.getSessionInfo()), { hostAccountNumber: yield client.getHostNumber() }));
188
188
  }));
189
189
  process.on('message', function (data) {
@@ -191,7 +191,7 @@ function start() {
191
191
  return __awaiter(this, void 0, void 0, function* () {
192
192
  if (((_a = data === null || data === void 0 ? void 0 : data.data) === null || _a === void 0 ? void 0 : _a.command) === "port_report") {
193
193
  const response = { port: PORT };
194
- yield (0, index_1.processSendData)(response);
194
+ (0, index_1.processSendData)(response);
195
195
  return response;
196
196
  }
197
197
  });
@@ -490,7 +490,7 @@ function getWAPage(browser) {
490
490
  * @internal
491
491
  */
492
492
  const kill = (p, b, exit, pid, reason = "LAUNCH_KILL") => __awaiter(void 0, void 0, void 0, function* () {
493
- yield (0, tools_1.processSendData)({
493
+ (0, tools_1.processSendData)({
494
494
  reason
495
495
  });
496
496
  (0, tools_1.timeout)(3000);
@@ -314,7 +314,12 @@ function create(config = {}) {
314
314
  yield (0, exports.timeout)(5000);
315
315
  }
316
316
  //@ts-ignore
317
- const VALID_SESSION = yield waPage.waitForFunction(`window.Store && window.Store.Msg ? true : false`, { timeout: 9000, polling: 200 }).catch(e => false);
317
+ const VALID_SESSION = yield waPage.waitForFunction(`window.Store && window.Store.Msg ? true : false`, { timeout: 9000, polling: 200 }).catch((e) => __awaiter(this, void 0, void 0, function* () {
318
+ logging_1.log.error("Valid session check failed", e);
319
+ const storeKeys = yield waPage.evaluate(`Object.keys(window.Store || {})`);
320
+ logging_1.log.info("Store keys", storeKeys);
321
+ return false;
322
+ }));
318
323
  if (VALID_SESSION) {
319
324
  /**
320
325
  * Session is valid, attempt to preload patches
@@ -111,7 +111,7 @@ function popup(config) {
111
111
  });
112
112
  });
113
113
  server.listen(PORT);
114
- yield (0, tools_1.processSendData)({ port: PORT });
114
+ (0, tools_1.processSendData)({ port: PORT });
115
115
  const os = (0, os_name_1.default)();
116
116
  const appName = os.includes('macOS') ? 'google chrome' : os.includes('Windows') ? 'chrome' : 'google-chrome';
117
117
  const hasChrome = yield (0, command_exists_1.default)(appName).then(() => true).catch(() => false);
@@ -67,7 +67,7 @@ export declare function timePromise(fn: () => Promise<any>): Promise<string>;
67
67
  * @param {any} data - The data to be sent to the parent process.
68
68
  * @returns Nothing.
69
69
  */
70
- export declare const processSendData: (data?: any) => Promise<unknown>;
70
+ export declare const processSendData: (data?: any) => boolean;
71
71
  /**
72
72
  * It generates a link to the GitHub issue template for the current session
73
73
  * @param {ConfigObject} config - the config object
@@ -211,21 +211,20 @@ exports.timePromise = timePromise;
211
211
  * @param {any} data - The data to be sent to the parent process.
212
212
  * @returns Nothing.
213
213
  */
214
- const processSendData = (data = {}) => __awaiter(void 0, void 0, void 0, function* () {
215
- const sd = (resolve, reject) => process.send({
214
+ const processSendData = (data = {}) => {
215
+ const sd = () => process.send({
216
216
  type: 'process:msg',
217
217
  data
218
218
  }, (error) => {
219
219
  if (error) {
220
220
  console.error(error);
221
- reject(error);
222
221
  }
223
- resolve(true);
224
222
  });
225
- return yield new Promise((resolve, reject) => {
226
- sd(resolve, reject);
227
- });
228
- });
223
+ return sd();
224
+ // return await new Promise((resolve, reject)=>{
225
+ // sd(resolve,reject)
226
+ // })
227
+ };
229
228
  exports.processSendData = processSendData;
230
229
  /**
231
230
  * It generates a link to the GitHub issue template for the current session
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-wa/wa-automate",
3
- "version": "4.34.3",
3
+ "version": "4.35.1",
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",