@open-wa/wa-automate 4.27.8 → 4.28.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.
- package/README.md +1 -1
- package/bin/config-schema.json +1 -1
- package/dist/api/Client.d.ts +0 -1
- package/dist/api/Client.js +71 -78
- package/dist/api/model/config.d.ts +7 -0
- package/dist/build/build-postman.js +3 -3
- package/dist/cli/collections.js +8 -7
- package/dist/cli/index.js +22 -22
- package/dist/cli/integrations/chatwoot.js +1 -1
- package/dist/cli/server.js +11 -11
- package/dist/cli/setup.js +21 -15
- package/dist/config/puppeteer.config.js +1 -1
- package/dist/connect/socket.js +2 -2
- package/dist/controllers/auth.js +20 -11
- package/dist/controllers/browser.js +25 -19
- package/dist/controllers/events.js +17 -1
- package/dist/controllers/initializer.js +60 -40
- package/dist/controllers/launch_checks.js +2 -2
- package/dist/controllers/patch_manager.js +4 -4
- package/dist/controllers/popup/index.js +5 -5
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/logging/custom_transport.d.ts +9 -0
- package/dist/logging/custom_transport.js +35 -0
- package/dist/logging/logging.d.ts +50 -0
- package/dist/logging/logging.js +172 -0
- package/dist/structures/preProcessors.js +3 -3
- package/dist/utils/configSchema.js +2 -2
- package/dist/utils/tools.js +1 -1
- package/package.json +12 -9
@@ -97,7 +97,7 @@ const generatePostmanJson = (setup = {}) => __awaiter(void 0, void 0, void 0, fu
|
|
97
97
|
noCase = (yield Promise.resolve().then(() => __importStar(require("change-case")))).noCase;
|
98
98
|
if (setup === null || setup === void 0 ? void 0 : setup.apiHost) {
|
99
99
|
if (setup.apiHost.includes(setup.sessionId)) {
|
100
|
-
const parsed = parse_url_1.default(setup.apiHost);
|
100
|
+
const parsed = (0, parse_url_1.default)(setup.apiHost);
|
101
101
|
setup.host = parsed.resource;
|
102
102
|
setup.port = parsed.port;
|
103
103
|
}
|
@@ -132,7 +132,7 @@ const postmanRequestGeneratorGenerator = setup => method => {
|
|
132
132
|
method.parameters.forEach(function (param) {
|
133
133
|
args[param.name] = aliasExamples[param.type] ? aliasExamples[param.type] : paramNameExamples[param.name] ? paramNameExamples[param.name] : primatives.includes(param.type) ? param.type : 'Check documentation in description';
|
134
134
|
});
|
135
|
-
const hostpath = setup.apiHost ? parse_url_1.default(setup.apiHost).pathname.substring(1) : false;
|
135
|
+
const hostpath = setup.apiHost ? (0, parse_url_1.default)(setup.apiHost).pathname.substring(1) : false;
|
136
136
|
const url = {
|
137
137
|
"raw": setup.apiHost ? `{{address}}:{{port}}${hostpath ? `/${hostpath}` : ''}/${method.name}` : (setup === null || setup === void 0 ? void 0 : setup.useSessionIdInPath) ? "{{address}}:{{port}}/{{sessionId}}/" + method.name : "{{address}}:{{port}}/" + method.name,
|
138
138
|
"host": [
|
@@ -140,7 +140,7 @@ const postmanRequestGeneratorGenerator = setup => method => {
|
|
140
140
|
],
|
141
141
|
"port": "{{port}}",
|
142
142
|
"path": (setup === null || setup === void 0 ? void 0 : setup.apiHost) ? [
|
143
|
-
parse_url_1.default(setup.apiHost).pathname.substring(1),
|
143
|
+
(0, parse_url_1.default)(setup.apiHost).pathname.substring(1),
|
144
144
|
"" + method.name
|
145
145
|
].filter(x => x) : (setup === null || setup === void 0 ? void 0 : setup.useSessionIdInPath) ? [
|
146
146
|
"{{sessionId}}",
|
package/dist/cli/collections.js
CHANGED
@@ -43,11 +43,11 @@ exports.collections = {};
|
|
43
43
|
const generateCollections = (config, spinner) => __awaiter(void 0, void 0, void 0, function* () {
|
44
44
|
let swCol = null;
|
45
45
|
let pmCol = null;
|
46
|
-
const _types = yield exports.getTypeSchemas();
|
46
|
+
const _types = yield (0, exports.getTypeSchemas)();
|
47
47
|
spinner.info('Generating Swagger Spec');
|
48
|
-
pmCol = yield __1.generatePostmanJson(config);
|
48
|
+
pmCol = yield (0, __1.generatePostmanJson)(config);
|
49
49
|
spinner.succeed(`Postman collection generated: open-wa-${config.sessionId}.postman_collection.json`);
|
50
|
-
swCol = postman_2_swagger_1.default(pmCol);
|
50
|
+
swCol = (0, postman_2_swagger_1.default)(pmCol);
|
51
51
|
/**
|
52
52
|
* Fix swagger docs by removing the content type as a required paramater
|
53
53
|
*/
|
@@ -106,7 +106,8 @@ const generateCollections = (config, spinner) => __awaiter(void 0, void 0, void
|
|
106
106
|
const x = {};
|
107
107
|
Object.keys(swCol.paths).sort().map(k => x[k] = swCol.paths[k]);
|
108
108
|
swCol.paths = x;
|
109
|
-
|
109
|
+
if (!(config === null || config === void 0 ? void 0 : config.skipSavePostmanCollection))
|
110
|
+
(0, fs_extra_1.writeJsonSync)("./open-wa-" + config.sessionId + ".sw_col.json", swCol);
|
110
111
|
exports.collections['postman'] = pmCol;
|
111
112
|
exports.collections['swagger'] = swCol;
|
112
113
|
spinner.succeed('API collections (swagger + postman) generated successfully');
|
@@ -114,9 +115,9 @@ const generateCollections = (config, spinner) => __awaiter(void 0, void 0, void
|
|
114
115
|
});
|
115
116
|
exports.generateCollections = generateCollections;
|
116
117
|
const getTypeSchemas = () => __awaiter(void 0, void 0, void 0, function* () {
|
117
|
-
const reader = typeconv_1.getTypeScriptReader();
|
118
|
-
const writer = typeconv_1.getOpenApiWriter({ format: 'json', title: 'My API', version: 'v3.0.3' });
|
119
|
-
const { convert } = typeconv_1.makeConverter(reader, writer, {
|
118
|
+
const reader = (0, typeconv_1.getTypeScriptReader)();
|
119
|
+
const writer = (0, typeconv_1.getOpenApiWriter)({ format: 'json', title: 'My API', version: 'v3.0.3' });
|
120
|
+
const { convert } = (0, typeconv_1.makeConverter)(reader, writer, {
|
120
121
|
simplify: true
|
121
122
|
});
|
122
123
|
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'));
|
package/dist/cli/index.js
CHANGED
@@ -21,11 +21,11 @@ const setup_1 = require("./setup");
|
|
21
21
|
const collections_1 = require("./collections");
|
22
22
|
const server_1 = require("./server");
|
23
23
|
const localtunnel_1 = __importDefault(require("localtunnel"));
|
24
|
-
let checkUrl = (s) => (typeof s === "string") && is_url_superb_1.default(s);
|
24
|
+
let checkUrl = (s) => (typeof s === "string") && (0, is_url_superb_1.default)(s);
|
25
25
|
const ready = (config) => __awaiter(void 0, void 0, void 0, function* () {
|
26
|
-
index_1.processSend('ready');
|
26
|
+
(0, index_1.processSend)('ready');
|
27
27
|
if (config.readyWebhook)
|
28
|
-
yield axios_1.default({
|
28
|
+
yield (0, axios_1.default)({
|
29
29
|
method: 'post',
|
30
30
|
url: config.readyWebhook,
|
31
31
|
data: {
|
@@ -38,11 +38,11 @@ const ready = (config) => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
38
|
});
|
39
39
|
function start() {
|
40
40
|
return __awaiter(this, void 0, void 0, function* () {
|
41
|
-
const { cliConfig, createConfig, PORT, spinner } = setup_1.cli();
|
41
|
+
const { cliConfig, createConfig, PORT, spinner } = (0, setup_1.cli)();
|
42
42
|
spinner.start("Launching EASY API");
|
43
|
-
server_1.setUpExpressApp();
|
43
|
+
(0, server_1.setUpExpressApp)();
|
44
44
|
if (cliConfig.cors)
|
45
|
-
yield server_1.enableCORSRequests();
|
45
|
+
yield (0, server_1.enableCORSRequests)();
|
46
46
|
try {
|
47
47
|
const { status, data } = yield axios_1.default.post(`http://localhost:${PORT}/getConnectionState`);
|
48
48
|
if (status === 200 && data.response === "CONNECTED") {
|
@@ -79,7 +79,7 @@ function start() {
|
|
79
79
|
}
|
80
80
|
if (!cliConfig.allowSessionDataWebhook && (namespace == "sessionData" || namespace == "sessionDataBase64"))
|
81
81
|
return;
|
82
|
-
yield axios_1.default({
|
82
|
+
yield (0, axios_1.default)({
|
83
83
|
method: 'post',
|
84
84
|
url: cliConfig.ev,
|
85
85
|
data: {
|
@@ -93,10 +93,10 @@ function start() {
|
|
93
93
|
}
|
94
94
|
//These things can be done before the client is created
|
95
95
|
if ((cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.generateApiDocs) || (cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.stats)) {
|
96
|
-
yield collections_1.generateCollections(Object.assign(Object.assign({}, createConfig), cliConfig), spinner);
|
96
|
+
yield (0, collections_1.generateCollections)(Object.assign(Object.assign({}, createConfig), cliConfig), spinner);
|
97
97
|
}
|
98
98
|
try {
|
99
|
-
const client = yield index_1.create(Object.assign({}, createConfig));
|
99
|
+
const client = yield (0, index_1.create)(Object.assign({}, createConfig));
|
100
100
|
if (cliConfig.autoReject) {
|
101
101
|
yield client.autoReject(cliConfig.onCall);
|
102
102
|
}
|
@@ -115,12 +115,12 @@ function start() {
|
|
115
115
|
}));
|
116
116
|
if (cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.botPressUrl) {
|
117
117
|
spinner.info('Setting Up Botpress handler');
|
118
|
-
server_1.setupBotPressHandler(cliConfig, client);
|
118
|
+
(0, server_1.setupBotPressHandler)(cliConfig, client);
|
119
119
|
spinner.succeed('Botpress handler set up successfully');
|
120
120
|
}
|
121
121
|
if (cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.twilioWebhook) {
|
122
122
|
spinner.info('Setting Up Twilio Compaitible Webhook');
|
123
|
-
server_1.setupTwilioCompatibleWebhook(cliConfig, client);
|
123
|
+
(0, server_1.setupTwilioCompatibleWebhook)(cliConfig, client);
|
124
124
|
spinner.succeed('Twilio Compaitible Webhook set up successfully');
|
125
125
|
}
|
126
126
|
if (cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.webhook) {
|
@@ -142,32 +142,32 @@ function start() {
|
|
142
142
|
if (cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.key) {
|
143
143
|
spinner.info(`Please see machine logs to see the API key`);
|
144
144
|
console.log(`Please use the following api key for requests as a header:\napi_key: ${cliConfig.key}`);
|
145
|
-
server_1.setupAuthenticationLayer(cliConfig);
|
145
|
+
(0, server_1.setupAuthenticationLayer)(cliConfig);
|
146
146
|
}
|
147
147
|
if (cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.chatwootUrl) {
|
148
148
|
spinner.info('Setting Up Chatwoot handler');
|
149
149
|
spinner.info(`Make sure to set up the Chatwoot inbox webhook to the following path on this process: /chatwoot${cliConfig.key ? `?api_key=YOUR-API-KEY` : ''}`);
|
150
|
-
yield server_1.setupChatwoot(cliConfig, client);
|
150
|
+
yield (0, server_1.setupChatwoot)(cliConfig, client);
|
151
151
|
spinner.succeed('Chatwoot handler set up successfully');
|
152
152
|
}
|
153
|
-
server_1.setupRefocusDisengageMiddleware(cliConfig);
|
153
|
+
(0, server_1.setupRefocusDisengageMiddleware)(cliConfig);
|
154
154
|
if (cliConfig && cliConfig.generateApiDocs && collections_1.collections["swagger"]) {
|
155
155
|
spinner.info('Setting Up API Explorer');
|
156
|
-
server_1.setupApiDocs(cliConfig);
|
156
|
+
(0, server_1.setupApiDocs)(cliConfig);
|
157
157
|
spinner.succeed('API Explorer set up successfully');
|
158
158
|
}
|
159
159
|
if ((cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.stats) && collections_1.collections["swagger"]) {
|
160
160
|
spinner.info('Setting Up API Stats');
|
161
|
-
server_1.setupSwaggerStatsMiddleware(cliConfig);
|
161
|
+
(0, server_1.setupSwaggerStatsMiddleware)(cliConfig);
|
162
162
|
spinner.info('API Stats set up successfully');
|
163
163
|
}
|
164
164
|
if (createConfig.messagePreprocessor === "AUTO_DECRYPT_SAVE") {
|
165
|
-
server_1.setupMediaMiddleware();
|
165
|
+
(0, server_1.setupMediaMiddleware)();
|
166
166
|
}
|
167
167
|
server_1.app.use(client.middleware((cliConfig && cliConfig.useSessionIdInPath)));
|
168
168
|
if (cliConfig.socket) {
|
169
169
|
spinner.info("Setting up socket");
|
170
|
-
yield server_1.setupSocketServer(cliConfig, client);
|
170
|
+
yield (0, server_1.setupSocketServer)(cliConfig, client);
|
171
171
|
spinner.succeed("Socket ready for connection");
|
172
172
|
}
|
173
173
|
spinner.info(`...waiting for port ${PORT} to be free`);
|
@@ -182,16 +182,16 @@ function start() {
|
|
182
182
|
}));
|
183
183
|
if (cliConfig.tunnel) {
|
184
184
|
spinner.info(`\n• Setting up external tunnel`);
|
185
|
-
const tunnel = yield localtunnel_1.default({ port: PORT });
|
186
|
-
spinner.succeed(`\n\t${terminal_link_1.default('External address', tunnel.url)}`);
|
185
|
+
const tunnel = yield (0, localtunnel_1.default)({ port: PORT });
|
186
|
+
spinner.succeed(`\n\t${(0, terminal_link_1.default)('External address', tunnel.url)}`);
|
187
187
|
}
|
188
188
|
const apiDocsUrl = cliConfig.apiHost ? `${cliConfig.apiHost}/api-docs/ ` : `${cliConfig.host.includes('http') ? '' : 'http://'}${cliConfig.host}:${PORT}/api-docs/ `;
|
189
|
-
const link = terminal_link_1.default('API Explorer', apiDocsUrl);
|
189
|
+
const link = (0, terminal_link_1.default)('API Explorer', apiDocsUrl);
|
190
190
|
if (cliConfig && cliConfig.generateApiDocs)
|
191
191
|
spinner.succeed(`\n\t${link}`);
|
192
192
|
if (cliConfig && cliConfig.generateApiDocs && cliConfig.stats) {
|
193
193
|
const swaggerStatsUrl = cliConfig.apiHost ? `${cliConfig.apiHost}/swagger-stats/ ` : `${cliConfig.host.includes('http') ? '' : 'http://'}${cliConfig.host}:${PORT}/swagger-stats/ `;
|
194
|
-
const statsLink = terminal_link_1.default('API Stats', swaggerStatsUrl);
|
194
|
+
const statsLink = (0, terminal_link_1.default)('API Stats', swaggerStatsUrl);
|
195
195
|
spinner.succeed(`\n\t${statsLink}`);
|
196
196
|
}
|
197
197
|
}
|
@@ -90,7 +90,7 @@ const setupChatwootOutgoingMessageHandler = (cliConfig, client) => __awaiter(voi
|
|
90
90
|
const cwReq = (path, method, data, _headers) => {
|
91
91
|
const url = `${origin}/api/v1/accounts/${accountId}/${path}`.replace('app.bentonow.com', 'chat.bentonow.com');
|
92
92
|
// console.log(url,method,data)
|
93
|
-
return axios_1.default({
|
93
|
+
return (0, axios_1.default)({
|
94
94
|
method,
|
95
95
|
data,
|
96
96
|
url,
|
package/dist/cli/server.js
CHANGED
@@ -44,7 +44,7 @@ const __1 = require("..");
|
|
44
44
|
const qs_1 = __importDefault(require("qs"));
|
45
45
|
const xmlbuilder2_1 = require("xmlbuilder2");
|
46
46
|
const chatwoot_1 = require("./integrations/chatwoot");
|
47
|
-
exports.app = express_1.default();
|
47
|
+
exports.app = (0, express_1.default)();
|
48
48
|
exports.server = http_1.default.createServer(exports.app);
|
49
49
|
const trimChatId = (chatId) => chatId.replace("@c.us", "").replace("@g.us", "");
|
50
50
|
const socketListenerCallbacks = {};
|
@@ -52,7 +52,7 @@ const socketListenerCallbacks = {};
|
|
52
52
|
const existingListeners = [];
|
53
53
|
const getCallbacks = (listener) => Object.keys(socketListenerCallbacks).flatMap(k => socketListenerCallbacks[k]).map(o => o[listener]).filter(x => x);
|
54
54
|
const setUpExpressApp = () => {
|
55
|
-
exports.app.use(express_robots_txt_1.default({ UserAgent: '*', Disallow: '/' }));
|
55
|
+
exports.app.use((0, express_robots_txt_1.default)({ UserAgent: '*', Disallow: '/' }));
|
56
56
|
//@ts-ignore
|
57
57
|
exports.app.use(express_1.default.json({ limit: '99mb' })); //add the limit option so we can send base64 data through the api
|
58
58
|
setupMetaMiddleware();
|
@@ -154,8 +154,8 @@ const setupMetaMiddleware = () => {
|
|
154
154
|
/**
|
155
155
|
* Basic
|
156
156
|
*/
|
157
|
-
exports.app.get("/meta/basic/commands", (_, res) => res.send(exports.getCommands()));
|
158
|
-
exports.app.get("/meta/basic/listeners", (_, res) => res.send(exports.listListeners()));
|
157
|
+
exports.app.get("/meta/basic/commands", (_, res) => res.send((0, exports.getCommands)()));
|
158
|
+
exports.app.get("/meta/basic/listeners", (_, res) => res.send((0, exports.listListeners)()));
|
159
159
|
/**
|
160
160
|
* If you want to list the list of all languages GET https://codegen.openwa.dev/api/gen/clients
|
161
161
|
*
|
@@ -216,13 +216,13 @@ const setupTwilioCompatibleWebhook = (cliConfig, client) => {
|
|
216
216
|
fd["Longitude"] = message.lng || "";
|
217
217
|
}
|
218
218
|
try {
|
219
|
-
const { data } = yield axios_1.default({
|
219
|
+
const { data } = yield (0, axios_1.default)({
|
220
220
|
method: 'post',
|
221
221
|
url,
|
222
222
|
data: qs_1.default.stringify(fd),
|
223
223
|
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
224
224
|
});
|
225
|
-
const obj = xmlbuilder2_1.convert(data, { format: "object" });
|
225
|
+
const obj = (0, xmlbuilder2_1.convert)(data, { format: "object" });
|
226
226
|
const msg = obj.Response.Message;
|
227
227
|
// const toId : string = msg['@to'].match(/\d*/g).filter(x=>x).join("-");
|
228
228
|
// const to = `${toId}@${toId.includes("-") ? 'g' : 'c'}.us` as ChatId
|
@@ -238,8 +238,8 @@ const setupTwilioCompatibleWebhook = (cliConfig, client) => {
|
|
238
238
|
};
|
239
239
|
exports.setupTwilioCompatibleWebhook = setupTwilioCompatibleWebhook;
|
240
240
|
const setupChatwoot = (cliConfig, client) => __awaiter(void 0, void 0, void 0, function* () {
|
241
|
-
exports.app.post('/chatwoot', chatwoot_1.chatwootMiddleware(cliConfig, client));
|
242
|
-
yield chatwoot_1.setupChatwootOutgoingMessageHandler(cliConfig, client);
|
241
|
+
exports.app.post('/chatwoot', (0, chatwoot_1.chatwootMiddleware)(cliConfig, client));
|
242
|
+
yield (0, chatwoot_1.setupChatwootOutgoingMessageHandler)(cliConfig, client);
|
243
243
|
});
|
244
244
|
exports.setupChatwoot = setupChatwoot;
|
245
245
|
const setupBotPressHandler = (cliConfig, client) => {
|
@@ -340,10 +340,10 @@ const setupSocketServer = (cliConfig, client) => __awaiter(void 0, void 0, void
|
|
340
340
|
if (m === "node_red_init_call") {
|
341
341
|
if (!collections_1.collections['swagger'])
|
342
342
|
return callbacks[0]();
|
343
|
-
return callbacks[0](exports.getCommands());
|
343
|
+
return callbacks[0]((0, exports.getCommands)());
|
344
344
|
}
|
345
345
|
if (m === "node_red_init_listen") {
|
346
|
-
return callbacks[0](exports.listListeners());
|
346
|
+
return callbacks[0]((0, exports.listListeners)());
|
347
347
|
}
|
348
348
|
if (client[m]) {
|
349
349
|
if (m.startsWith("on") && callbacks[0]) {
|
@@ -362,7 +362,7 @@ const setupSocketServer = (cliConfig, client) => __awaiter(void 0, void 0, void
|
|
362
362
|
else {
|
363
363
|
let { args } = objs[0];
|
364
364
|
if (args && !Array.isArray(args))
|
365
|
-
args = parse_function_1.default().parse(client[m]).args.map(argName => args[argName]);
|
365
|
+
args = (0, parse_function_1.default)().parse(client[m]).args.map(argName => args[argName]);
|
366
366
|
else if (!args)
|
367
367
|
args = [];
|
368
368
|
const data = yield client[m](...args);
|
package/dist/cli/setup.js
CHANGED
@@ -43,8 +43,9 @@ const uuid_apikey_1 = __importDefault(require("uuid-apikey"));
|
|
43
43
|
const events_1 = require("../controllers/events");
|
44
44
|
const is_url_superb_1 = __importDefault(require("is-url-superb"));
|
45
45
|
const path = __importStar(require("path"));
|
46
|
-
|
47
|
-
|
46
|
+
const logging_1 = require("../logging/logging");
|
47
|
+
let checkUrl = url => typeof url === 'string' ? (0, is_url_superb_1.default)(url) : false;
|
48
|
+
const configWithCases = (0, fs_extra_1.readJsonSync)(path.join(__dirname, '../../bin/config-schema.json'));
|
48
49
|
const optionList = [{
|
49
50
|
name: 'no-api',
|
50
51
|
default: false,
|
@@ -271,8 +272,8 @@ const optionList = [{
|
|
271
272
|
description: 'Print this usage guide.'
|
272
273
|
}
|
273
274
|
];
|
274
|
-
exports.optionKeys = optionList.map(({ name }) => tools_1.camelize(name));
|
275
|
-
exports.optionKeysWithDefalts = optionList.filter(o => o.hasOwnProperty('default')).map(({ name }) => tools_1.camelize(name));
|
275
|
+
exports.optionKeys = optionList.map(({ name }) => (0, tools_1.camelize)(name));
|
276
|
+
exports.optionKeysWithDefalts = [...optionList.filter(o => o.hasOwnProperty('default')).map(({ name }) => (0, tools_1.camelize)(name)), 'popup'];
|
276
277
|
exports.PrimitiveConverter = {
|
277
278
|
Number: 1,
|
278
279
|
Boolean: true,
|
@@ -281,7 +282,7 @@ exports.PrimitiveConverter = {
|
|
281
282
|
exports.cliOptionNames = optionList.reduce((acc, c) => {
|
282
283
|
if (!c.type)
|
283
284
|
return acc;
|
284
|
-
acc[tools_1.camelize(c.name)] = typeof exports.PrimitiveConverter[c.type.name];
|
285
|
+
acc[(0, tools_1.camelize)(c.name)] = typeof exports.PrimitiveConverter[c.type.name];
|
285
286
|
return acc;
|
286
287
|
}, {});
|
287
288
|
const meowFlags = () => {
|
@@ -300,14 +301,14 @@ const meowFlags = () => {
|
|
300
301
|
const res = {};
|
301
302
|
optionList.map(option => {
|
302
303
|
var _a, _b;
|
303
|
-
res[tools_1.camelize(option.name)] = Object.assign(Object.assign({}, option), {
|
304
|
+
res[(0, tools_1.camelize)(option.name)] = Object.assign(Object.assign({}, option), {
|
304
305
|
//@ts-ignore
|
305
306
|
type: (_b = (_a = option.type) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.toLowerCase() });
|
306
307
|
});
|
307
308
|
return Object.assign(Object.assign({}, res), extraFlags);
|
308
309
|
};
|
309
310
|
exports.meowFlags = meowFlags;
|
310
|
-
exports.helptext = command_line_usage_1.default([{
|
311
|
+
exports.helptext = (0, command_line_usage_1.default)([{
|
311
312
|
content: logo_1.HELP_HEADER,
|
312
313
|
raw: true,
|
313
314
|
},
|
@@ -351,24 +352,24 @@ const configFile = (config) => {
|
|
351
352
|
let confFile = {};
|
352
353
|
const conf = config || process.env.WA_CLI_CONFIG;
|
353
354
|
if (conf) {
|
354
|
-
if (tools_1.isBase64(conf)) {
|
355
|
+
if ((0, tools_1.isBase64)(conf)) {
|
355
356
|
confFile = JSON.parse(Buffer.from(conf, 'base64').toString('ascii'));
|
356
357
|
}
|
357
358
|
else {
|
358
|
-
confFile = file_utils_1.tryOpenFileAsObject(conf || `cli.config.json`);
|
359
|
+
confFile = (0, file_utils_1.tryOpenFileAsObject)(conf || `cli.config.json`);
|
359
360
|
if (!confFile)
|
360
361
|
console.error(`Unable to read config file json: ${conf}`);
|
361
362
|
}
|
362
363
|
}
|
363
364
|
else {
|
364
|
-
confFile = file_utils_1.tryOpenFileAsObject(`cli.config.json`);
|
365
|
+
confFile = (0, file_utils_1.tryOpenFileAsObject)(`cli.config.json`);
|
365
366
|
}
|
366
367
|
return confFile;
|
367
368
|
};
|
368
369
|
exports.configFile = configFile;
|
369
370
|
const cli = () => {
|
370
|
-
const _cli = meow_1.default(exports.helptext, {
|
371
|
-
flags: Object.assign(Object.assign({}, exports.meowFlags()), { popup: {
|
371
|
+
const _cli = (0, meow_1.default)(exports.helptext, {
|
372
|
+
flags: Object.assign(Object.assign({}, (0, exports.meowFlags)()), { popup: {
|
372
373
|
type: 'boolean',
|
373
374
|
default: false
|
374
375
|
} }),
|
@@ -381,9 +382,14 @@ const cli = () => {
|
|
381
382
|
* 2. Config file
|
382
383
|
* 3. CLI flags
|
383
384
|
*/
|
384
|
-
const nonCliConfigs = Object.assign(Object.assign({}, exports.envArgs()), (exports.configFile(_cli.flags.config) || {}));
|
385
|
+
const nonCliConfigs = Object.assign(Object.assign({}, (0, exports.envArgs)()), ((0, exports.configFile)(_cli.flags.config) || {}));
|
385
386
|
optionList.filter(option => option.default);
|
386
387
|
const cliConfig = Object.assign(Object.assign(Object.assign({ sessionId: "session" }, nonCliConfigs), _cli.flags), exports.optionKeysWithDefalts.reduce((p, c) => nonCliConfigs.hasOwnProperty(c) ? Object.assign(Object.assign({}, p), { [c]: nonCliConfigs[c] }) : p, {}));
|
388
|
+
//firstly set up logger
|
389
|
+
if (cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.logging) {
|
390
|
+
if (Array.isArray(cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.logging))
|
391
|
+
cliConfig.logging = (0, logging_1.setupLogging)(cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.logging, `easy-api-${(cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.sessionId) || 'session'}`);
|
392
|
+
}
|
387
393
|
const PORT = Number(cliConfig.port || process.env.PORT || 8080);
|
388
394
|
const spinner = new events_1.Spin(cliConfig.sessionId, 'STARTUP', cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.disableSpins);
|
389
395
|
const createConfig = Object.assign({}, cliConfig);
|
@@ -414,7 +420,7 @@ const cli = () => {
|
|
414
420
|
}
|
415
421
|
if (cliConfig.sessionDataOnly) {
|
416
422
|
events_1.ev.on(`sessionData.**`, (sessionData, sessionId) => __awaiter(void 0, void 0, void 0, function* () {
|
417
|
-
fs_extra_1.writeFile(`${sessionId}.data.json`, JSON.stringify(sessionData), (err) => {
|
423
|
+
(0, fs_extra_1.writeFile)(`${sessionId}.data.json`, JSON.stringify(sessionData), (err) => {
|
418
424
|
if (err) {
|
419
425
|
spinner.fail(err.message);
|
420
426
|
return;
|
@@ -434,7 +440,7 @@ const cli = () => {
|
|
434
440
|
else {
|
435
441
|
if (cliConfig.webhook == '')
|
436
442
|
cliConfig.webhook = 'webhooks.json';
|
437
|
-
cliConfig.webhook = file_utils_1.tryOpenFileAsObject(cliConfig.webhook, true);
|
443
|
+
cliConfig.webhook = (0, file_utils_1.tryOpenFileAsObject)(cliConfig.webhook, true);
|
438
444
|
if (!checkUrl(cliConfig.webhook)) {
|
439
445
|
cliConfig.webhook = undefined;
|
440
446
|
}
|
@@ -58,6 +58,6 @@ const puppeteerConfig = {
|
|
58
58
|
exports.puppeteerConfig = puppeteerConfig;
|
59
59
|
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`;
|
60
60
|
exports.createUserAgent = createUserAgent;
|
61
|
-
exports.useragent = exports.createUserAgent('2.
|
61
|
+
exports.useragent = (0, exports.createUserAgent)('2.2147.16');
|
62
62
|
exports.width = puppeteerConfig.width;
|
63
63
|
exports.height = puppeteerConfig.height;
|
package/dist/connect/socket.js
CHANGED
@@ -65,7 +65,7 @@ class SocketClient {
|
|
65
65
|
this.apiKey = apiKey;
|
66
66
|
const _url = new URL(url);
|
67
67
|
const _path = _url.pathname.replace(/\/$/, "");
|
68
|
-
this.socket = socket_io_client_1.io(_url.origin, {
|
68
|
+
this.socket = (0, socket_io_client_1.io)(_url.origin, {
|
69
69
|
autoConnect: true,
|
70
70
|
auth: {
|
71
71
|
apiKey
|
@@ -168,7 +168,7 @@ class SocketClient {
|
|
168
168
|
listen(listener, callback) {
|
169
169
|
return __awaiter(this, void 0, void 0, function* () {
|
170
170
|
// if (!this.socket.connected) throw new Error("Socket not connected!")
|
171
|
-
const id = uuid_1.v4();
|
171
|
+
const id = (0, uuid_1.v4)();
|
172
172
|
if (!this.listeners[listener]) {
|
173
173
|
this.listeners[listener] = {};
|
174
174
|
yield this.ask(listener);
|
package/dist/controllers/auth.js
CHANGED
@@ -39,16 +39,17 @@ const initializer_1 = require("./initializer");
|
|
39
39
|
const tools_1 = require("../utils/tools");
|
40
40
|
const browser_1 = require("./browser");
|
41
41
|
const axios_1 = __importDefault(require("axios"));
|
42
|
+
const logging_1 = require("../logging/logging");
|
42
43
|
const timeout = ms => new Promise(resolve => setTimeout(resolve, ms, 'timeout'));
|
43
44
|
/**
|
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) => rxjs_1.race(exports.needsToScan(waPage), exports.isInsideChat(waPage), exports.sessionDataInvalid(waPage)).toPromise();
|
49
|
+
const isAuthenticated = (waPage) => (0, rxjs_1.race)((0, exports.needsToScan)(waPage), (0, exports.isInsideChat)(waPage), (0, exports.sessionDataInvalid)(waPage)).toPromise();
|
49
50
|
exports.isAuthenticated = isAuthenticated;
|
50
51
|
const needsToScan = (waPage) => {
|
51
|
-
return rxjs_1.from(new Promise((resolve) => __awaiter(void 0, void 0, void 0, function* () {
|
52
|
+
return (0, rxjs_1.from)(new Promise((resolve) => __awaiter(void 0, void 0, void 0, function* () {
|
52
53
|
try {
|
53
54
|
yield Promise.race([
|
54
55
|
waPage.waitForFunction('checkQrRefresh()', { timeout: 0, polling: 1000 }).catch(() => { }),
|
@@ -62,12 +63,13 @@ const needsToScan = (waPage) => {
|
|
62
63
|
}
|
63
64
|
catch (error) {
|
64
65
|
console.log("needsToScan -> error", error);
|
66
|
+
logging_1.log.error("needsToScan -> error", error);
|
65
67
|
}
|
66
68
|
})));
|
67
69
|
};
|
68
70
|
exports.needsToScan = needsToScan;
|
69
71
|
const isInsideChat = (waPage) => {
|
70
|
-
return rxjs_1.from(waPage
|
72
|
+
return (0, rxjs_1.from)(waPage
|
71
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 })
|
72
74
|
.then(() => true));
|
73
75
|
};
|
@@ -85,7 +87,7 @@ exports.waitForRipeSession = waitForRipeSession;
|
|
85
87
|
const sessionDataInvalid = (waPage) => __awaiter(void 0, void 0, void 0, function* () {
|
86
88
|
yield waPage
|
87
89
|
.waitForFunction('!window.getQrPng', { timeout: 0, polling: 'mutation' });
|
88
|
-
yield browser_1.injectApi(waPage);
|
90
|
+
yield (0, browser_1.injectApi)(waPage);
|
89
91
|
yield waPage
|
90
92
|
.waitForFunction('!window.getQrPng', { timeout: 0, polling: 'mutation' });
|
91
93
|
//if the code reaches here it means the browser was refreshed. Nuke the session data and restart `create`
|
@@ -105,10 +107,11 @@ function smartQr(waPage, config, spinner) {
|
|
105
107
|
const evalResult = yield waPage.evaluate("window.Store && window.Store.State");
|
106
108
|
if (evalResult === false) {
|
107
109
|
console.log('Seems as though you have been TOS_BLOCKed, unable to refresh QR Code. Please see https://github.com/open-wa/wa-automate-nodejs#best-practice for information on how to prevent this from happeing. You will most likely not get a QR Code');
|
110
|
+
logging_1.log.warn('Seems as though you have been TOS_BLOCKed, unable to refresh QR Code. Please see https://github.com/open-wa/wa-automate-nodejs#best-practice for information on how to prevent this from happeing. You will most likely not get a QR Code');
|
108
111
|
if (config.throwErrorOnTosBlock)
|
109
112
|
throw new Error('TOSBLOCK');
|
110
113
|
}
|
111
|
-
const isAuthed = yield exports.isAuthenticated(waPage);
|
114
|
+
const isAuthed = yield (0, exports.isAuthenticated)(waPage);
|
112
115
|
if (isAuthed)
|
113
116
|
return true;
|
114
117
|
let hash = 'START';
|
@@ -116,18 +119,20 @@ function smartQr(waPage, config, spinner) {
|
|
116
119
|
if (qrData) {
|
117
120
|
if (!config.qrLogSkip)
|
118
121
|
qrcode.generate(qrData, { small: true });
|
119
|
-
else
|
122
|
+
else {
|
120
123
|
console.log(`New QR Code generated. Not printing in console because qrLogSkip is set to true`);
|
124
|
+
logging_1.log.info(`New QR Code generated. Not printing in console because qrLogSkip is set to true`);
|
125
|
+
}
|
121
126
|
}
|
122
127
|
try {
|
123
128
|
const qrPng = yield waPage.evaluate(`window.getQrPng()`);
|
124
129
|
if (qrPng) {
|
125
130
|
qrEv.emit(qrPng);
|
126
131
|
qrNum++;
|
127
|
-
tools_1.processSend('ready');
|
132
|
+
(0, tools_1.processSend)('ready');
|
128
133
|
if (config.qrMax && qrNum >= config.qrMax) {
|
129
134
|
spinner.info('QR Code limit reached, exiting');
|
130
|
-
yield browser_1.kill(waPage, null, true);
|
135
|
+
yield (0, browser_1.kill)(waPage, null, true);
|
131
136
|
}
|
132
137
|
if (config.ezqr || config.inDocker) {
|
133
138
|
const host = 'https://qr.openwa.cloud/';
|
@@ -139,6 +144,7 @@ function smartQr(waPage, config, spinner) {
|
|
139
144
|
const qrUrl = `${host}${data}`;
|
140
145
|
qrEv.emit(qrUrl, `qrUrl`);
|
141
146
|
console.log(`Scan the qr code at ${qrUrl}`);
|
147
|
+
logging_1.log.info(`Scan the qr code at ${qrUrl}`);
|
142
148
|
}
|
143
149
|
hash = data;
|
144
150
|
}).catch(e => {
|
@@ -152,7 +158,9 @@ function smartQr(waPage, config, spinner) {
|
|
152
158
|
}
|
153
159
|
catch (error) {
|
154
160
|
//@ts-ignore
|
155
|
-
|
161
|
+
const lr = yield waPage.evaluate("window.launchres");
|
162
|
+
console.log(lr);
|
163
|
+
logging_1.log.info('smartQr -> error', { lr });
|
156
164
|
spinner.info(`Something went wrong while retreiving new the QR code but it should not affect the session launch procedure: ${error.message}`);
|
157
165
|
}
|
158
166
|
});
|
@@ -174,7 +182,7 @@ function smartQr(waPage, config, spinner) {
|
|
174
182
|
if (!gotResult && (qrData === 'QR_CODE_SUCCESS' || qrData === md)) {
|
175
183
|
gotResult = true;
|
176
184
|
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...");
|
177
|
-
return resolve(yield exports.isInsideChat(waPage).toPromise());
|
185
|
+
return resolve(yield (0, exports.isInsideChat)(waPage).toPromise());
|
178
186
|
}
|
179
187
|
if (!gotResult)
|
180
188
|
grabAndEmit(qrData);
|
@@ -185,8 +193,9 @@ function smartQr(waPage, config, spinner) {
|
|
185
193
|
}, { funcName });
|
186
194
|
yield waPage.exposeFunction(funcName, (obj) => fn(obj)).then(set).catch((e) => __awaiter(this, void 0, void 0, function* () {
|
187
195
|
//if an error occurs during the qr launcher then take a screenshot.
|
188
|
-
yield initializer_1.screenshot(waPage);
|
196
|
+
yield (0, initializer_1.screenshot)(waPage);
|
189
197
|
console.log("qr -> e", e);
|
198
|
+
logging_1.log.error("qr -> e", e);
|
190
199
|
}));
|
191
200
|
const firstQr = yield waPage.evaluate(`document.querySelector("canvas[aria-label='Scan me!']")?document.querySelector("canvas[aria-label='Scan me!']").parentElement.getAttribute("data-ref"):false`);
|
192
201
|
yield grabAndEmit(firstQr);
|