@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
@@ -0,0 +1,50 @@
|
|
1
|
+
import * as winston from 'winston';
|
2
|
+
/**
|
3
|
+
* You can access the log in your code and add your own custom transports
|
4
|
+
* https://github.com/winstonjs/winston#transports
|
5
|
+
* see [Logger](https://github.com/winstonjs/winston#transports) for more details.
|
6
|
+
*
|
7
|
+
* Here is an example of adding the GCP stackdriver transport:
|
8
|
+
*
|
9
|
+
* ```
|
10
|
+
* import { log } from '@open-wa/wa-automate'
|
11
|
+
* import { LoggingWinston } from '@google-cloud/logging-winston';
|
12
|
+
*
|
13
|
+
* const gcpTransport = new LoggingWinston({
|
14
|
+
* projectId: 'your-project-id',
|
15
|
+
* keyFilename: '/path/to/keyfile.json'
|
16
|
+
* });
|
17
|
+
*
|
18
|
+
* ...
|
19
|
+
* log.add(
|
20
|
+
* gcpTransport
|
21
|
+
* )
|
22
|
+
*
|
23
|
+
* //Congrats! Now all of your session logs will also go to GCP Stackdriver
|
24
|
+
* ```
|
25
|
+
*/
|
26
|
+
export declare const log: winston.Logger;
|
27
|
+
export declare const addRotateFileLogTransport: (options?: any) => void;
|
28
|
+
/**
|
29
|
+
* @private
|
30
|
+
*/
|
31
|
+
export declare const addSysLogTransport: (options?: any) => void;
|
32
|
+
export declare type ConfigLogTransport = {
|
33
|
+
/**
|
34
|
+
* The type of winston transport. At the moment only `file`, `console`, `ev` and `syslog` are supported.
|
35
|
+
*/
|
36
|
+
type: 'syslog' | 'console' | 'file' | 'ev';
|
37
|
+
/**
|
38
|
+
* The options for the transport. Generally only required for syslog but you can use this to override default options for other types of transports.
|
39
|
+
*/
|
40
|
+
options?: any;
|
41
|
+
/**
|
42
|
+
* If the transport has already been added to the logger. The logging set up command handles this for you.
|
43
|
+
* @readonly
|
44
|
+
*/
|
45
|
+
done?: boolean;
|
46
|
+
};
|
47
|
+
/**
|
48
|
+
* @private
|
49
|
+
*/
|
50
|
+
export declare const setupLogging: (logging: ConfigLogTransport[], sessionId?: string) => ConfigLogTransport[];
|
@@ -0,0 +1,172 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
5
|
+
}) : (function(o, m, k, k2) {
|
6
|
+
if (k2 === undefined) k2 = k;
|
7
|
+
o[k2] = m[k];
|
8
|
+
}));
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
11
|
+
}) : function(o, v) {
|
12
|
+
o["default"] = v;
|
13
|
+
});
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
15
|
+
if (mod && mod.__esModule) return mod;
|
16
|
+
var result = {};
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
18
|
+
__setModuleDefault(result, mod);
|
19
|
+
return result;
|
20
|
+
};
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
23
|
+
};
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
25
|
+
exports.setupLogging = exports.addSysLogTransport = exports.addRotateFileLogTransport = exports.log = void 0;
|
26
|
+
const os_1 = __importDefault(require("os"));
|
27
|
+
const winston = __importStar(require("winston"));
|
28
|
+
const winston_daily_rotate_file_1 = __importDefault(require("winston-daily-rotate-file"));
|
29
|
+
const winston_syslog_1 = require("winston-syslog");
|
30
|
+
const custom_transport_1 = require("./custom_transport");
|
31
|
+
const { combine, timestamp } = winston.format;
|
32
|
+
const traverse_1 = __importDefault(require("traverse"));
|
33
|
+
const full_1 = require("klona/full");
|
34
|
+
const truncateLength = 200;
|
35
|
+
let _evSet = false, _consoleSet = false, d = Date.now();
|
36
|
+
const sensitiveKeys = [
|
37
|
+
/cookie/i,
|
38
|
+
/sessionData/i,
|
39
|
+
/passw(or)?d/i,
|
40
|
+
/^pw$/,
|
41
|
+
/^pass$/i,
|
42
|
+
/secret/i,
|
43
|
+
/token/i,
|
44
|
+
/api[-._]?key/i,
|
45
|
+
];
|
46
|
+
function isSensitiveKey(keyStr) {
|
47
|
+
if (keyStr) {
|
48
|
+
return sensitiveKeys.some(regex => regex.test(keyStr));
|
49
|
+
}
|
50
|
+
}
|
51
|
+
function redactObject(obj) {
|
52
|
+
(0, traverse_1.default)(obj).forEach(function redactor() {
|
53
|
+
if (isSensitiveKey(this.key)) {
|
54
|
+
this.update("[REDACTED]");
|
55
|
+
}
|
56
|
+
else if (typeof this.node === 'string' && this.node.length > truncateLength) {
|
57
|
+
this.update(truncate(this.node, truncateLength));
|
58
|
+
}
|
59
|
+
});
|
60
|
+
}
|
61
|
+
function redact(obj) {
|
62
|
+
const copy = (0, full_1.klona)(obj); // Making a deep copy to prevent side effects
|
63
|
+
redactObject(copy);
|
64
|
+
const splat = copy[Symbol.for("splat")];
|
65
|
+
redactObject(splat); // Specifically redact splat Symbol
|
66
|
+
return copy;
|
67
|
+
}
|
68
|
+
function truncate(str, n) {
|
69
|
+
return str.length > n ? str.substr(0, n - 1) + '...[TRUNCATED]...' : str;
|
70
|
+
}
|
71
|
+
const formatRedact = winston.format(redact);
|
72
|
+
const stringSaver = winston.format((info) => {
|
73
|
+
const copy = (0, full_1.klona)(info);
|
74
|
+
const splat = copy[Symbol.for("splat")];
|
75
|
+
if (splat) {
|
76
|
+
copy.message = `${copy.message} ${splat.filter((x) => typeof x !== 'object').join(' ')}`;
|
77
|
+
copy[Symbol.for("splat")] = splat.filter((x) => typeof x == 'object');
|
78
|
+
return copy;
|
79
|
+
}
|
80
|
+
return info;
|
81
|
+
});
|
82
|
+
/**
|
83
|
+
* To prevent "Attempt to write logs with no transports" error
|
84
|
+
*/
|
85
|
+
const placeholderTransport = new custom_transport_1.NoOpTransport();
|
86
|
+
const makeLogger = () => winston.createLogger({
|
87
|
+
format: combine(stringSaver(), timestamp(), winston.format.json(), formatRedact(), winston.format.splat(), winston.format.simple()),
|
88
|
+
levels: winston.config.syslog.levels,
|
89
|
+
transports: [placeholderTransport]
|
90
|
+
});
|
91
|
+
/**
|
92
|
+
* You can access the log in your code and add your own custom transports
|
93
|
+
* https://github.com/winstonjs/winston#transports
|
94
|
+
* see [Logger](https://github.com/winstonjs/winston#transports) for more details.
|
95
|
+
*
|
96
|
+
* Here is an example of adding the GCP stackdriver transport:
|
97
|
+
*
|
98
|
+
* ```
|
99
|
+
* import { log } from '@open-wa/wa-automate'
|
100
|
+
* import { LoggingWinston } from '@google-cloud/logging-winston';
|
101
|
+
*
|
102
|
+
* const gcpTransport = new LoggingWinston({
|
103
|
+
* projectId: 'your-project-id',
|
104
|
+
* keyFilename: '/path/to/keyfile.json'
|
105
|
+
* });
|
106
|
+
*
|
107
|
+
* ...
|
108
|
+
* log.add(
|
109
|
+
* gcpTransport
|
110
|
+
* )
|
111
|
+
*
|
112
|
+
* //Congrats! Now all of your session logs will also go to GCP Stackdriver
|
113
|
+
* ```
|
114
|
+
*/
|
115
|
+
exports.log = makeLogger();
|
116
|
+
if (exports.log.warning && !exports.log.warn)
|
117
|
+
exports.log.warn = exports.log.warning;
|
118
|
+
if (exports.log.alert && !exports.log.help)
|
119
|
+
exports.log.help = exports.log.alert;
|
120
|
+
const addRotateFileLogTransport = (options = {}) => {
|
121
|
+
exports.log.add(new winston_daily_rotate_file_1.default(Object.assign({ filename: 'application-%DATE%.log', datePattern: 'YYYY-MM-DD-HH', zippedArchive: true, maxSize: '2m', maxFiles: '14d' }, options)));
|
122
|
+
};
|
123
|
+
exports.addRotateFileLogTransport = addRotateFileLogTransport;
|
124
|
+
/**
|
125
|
+
* @private
|
126
|
+
*/
|
127
|
+
const addSysLogTransport = (options = {}) => {
|
128
|
+
exports.log.add(new winston_syslog_1.Syslog(Object.assign({ localhost: os_1.default.hostname() }, options)));
|
129
|
+
};
|
130
|
+
exports.addSysLogTransport = addSysLogTransport;
|
131
|
+
const enableConsoleLogger = (options = {}) => {
|
132
|
+
if (_consoleSet)
|
133
|
+
return;
|
134
|
+
exports.log.add(new winston.transports.Console(Object.assign({ level: 'debug', timestamp: timestamp() }, options)));
|
135
|
+
_consoleSet = true;
|
136
|
+
};
|
137
|
+
function enableLogToEv(options = {}) {
|
138
|
+
if (_evSet)
|
139
|
+
return;
|
140
|
+
exports.log.add(new custom_transport_1.LogToEvTransport(Object.assign({ format: winston.format.json() }, options)));
|
141
|
+
_evSet = true;
|
142
|
+
}
|
143
|
+
/**
|
144
|
+
* @private
|
145
|
+
*/
|
146
|
+
const setupLogging = (logging, sessionId = "session") => {
|
147
|
+
const currentlySetup = [];
|
148
|
+
const _logging = logging.map((l) => {
|
149
|
+
if (l.done)
|
150
|
+
return l;
|
151
|
+
if (l.type === 'console') {
|
152
|
+
enableConsoleLogger(Object.assign({}, (l.options || {})));
|
153
|
+
}
|
154
|
+
else if (l.type === 'ev') {
|
155
|
+
enableLogToEv(Object.assign({}, (l.options || {})));
|
156
|
+
}
|
157
|
+
else if (l.type === 'file') {
|
158
|
+
(0, exports.addRotateFileLogTransport)(Object.assign({}, (l.options || {})));
|
159
|
+
}
|
160
|
+
else if (l.type === 'syslog') {
|
161
|
+
(0, exports.addSysLogTransport)(Object.assign(Object.assign({}, (l.options || {})), { appName: `owa-${sessionId}-${d}` }));
|
162
|
+
}
|
163
|
+
currentlySetup.push(l);
|
164
|
+
return Object.assign(Object.assign({}, l), { done: true });
|
165
|
+
});
|
166
|
+
currentlySetup.map((l) => {
|
167
|
+
exports.log.info(`Set up logging for ${l.type}`, l.options);
|
168
|
+
return l;
|
169
|
+
});
|
170
|
+
return _logging;
|
171
|
+
};
|
172
|
+
exports.setupLogging = setupLogging;
|
@@ -41,7 +41,7 @@ const AUTO_DECRYPT_SAVE = (message, client) => __awaiter(void 0, void 0, void 0,
|
|
41
41
|
const mediaData = yield client.decryptMedia(message);
|
42
42
|
const filePath = `media/${filename}`;
|
43
43
|
try {
|
44
|
-
fs_extra_1.outputFileSync(filePath, Buffer.from(mediaData.split(",")[1], "base64"));
|
44
|
+
(0, fs_extra_1.outputFileSync)(filePath, Buffer.from(mediaData.split(",")[1], "base64"));
|
45
45
|
}
|
46
46
|
catch (error) {
|
47
47
|
console.error(error);
|
@@ -111,11 +111,11 @@ const UPLOAD_CLOUD = (message, client) => __awaiter(void 0, void 0, void 0, func
|
|
111
111
|
console.error("UPLOAD ERROR: No provider provided. If you're using the CLI, set env var OW_CLOUD_PROVIDER");
|
112
112
|
return message;
|
113
113
|
}
|
114
|
-
const url = pico_s3_1.getCloudUrl(opts);
|
114
|
+
const url = (0, pico_s3_1.getCloudUrl)(opts);
|
115
115
|
if (!processedFiles[filename]) {
|
116
116
|
processedFiles[filename] = true;
|
117
117
|
try {
|
118
|
-
yield uploadQueue.add(() => pico_s3_1.upload(opts).catch(() => { }));
|
118
|
+
yield uploadQueue.add(() => (0, pico_s3_1.upload)(opts).catch(() => { }));
|
119
119
|
}
|
120
120
|
catch (error) {
|
121
121
|
console.error(error);
|
@@ -11,7 +11,7 @@ const defaultConfig = {
|
|
11
11
|
const getConfigWithCase = (config) => {
|
12
12
|
if (!config)
|
13
13
|
config = defaultConfig;
|
14
|
-
const schema = ts_json_schema_generator_1.createGenerator(config).createSchema(config.type);
|
14
|
+
const schema = (0, ts_json_schema_generator_1.createGenerator)(config).createSchema(config.type);
|
15
15
|
const ignoredConfigs = [
|
16
16
|
'useStealth',
|
17
17
|
'chromiumArgs',
|
@@ -40,7 +40,7 @@ const getConfigWithCase = (config) => {
|
|
40
40
|
}
|
41
41
|
return Object.assign(Object.assign({}, entry), { key });
|
42
42
|
}).filter(({ type, key }) => type && !ignoredConfigs.includes(key));
|
43
|
-
const configWithCases = configs.map(o => (Object.assign({ env: `WA_${change_case_1.constantCase(o.key)}`, p: change_case_1.paramCase(o.key) }, o)));
|
43
|
+
const configWithCases = configs.map(o => (Object.assign({ env: `WA_${(0, change_case_1.constantCase)(o.key)}`, p: (0, change_case_1.paramCase)(o.key) }, o)));
|
44
44
|
return configWithCases;
|
45
45
|
};
|
46
46
|
exports.getConfigWithCase = getConfigWithCase;
|
package/dist/utils/tools.js
CHANGED
@@ -96,7 +96,7 @@ exports.isDataURL = isDataURL;
|
|
96
96
|
const getDUrl = (url, optionsOverride = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
97
97
|
// eslint-disable-next-line no-useless-catch
|
98
98
|
try {
|
99
|
-
const res = yield axios_1.default(Object.assign(Object.assign({ method: 'get', url, headers: {
|
99
|
+
const res = yield (0, axios_1.default)(Object.assign(Object.assign({ method: 'get', url, headers: {
|
100
100
|
DNT: 1,
|
101
101
|
'Upgrade-Insecure-Requests': 1,
|
102
102
|
} }, optionsOverride), { responseType: 'arraybuffer' }));
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@open-wa/wa-automate",
|
3
|
-
"version": "4.
|
3
|
+
"version": "4.28.2",
|
4
4
|
"licenseCheckUrl": "https://openwa.dev/license-check",
|
5
5
|
"brokenMethodReportUrl": "https://openwa.dev/report-bm",
|
6
6
|
"patches": "https://cdn.openwa.dev/patches.json",
|
@@ -67,17 +67,16 @@
|
|
67
67
|
"@types/cross-spawn": "^6.0.2",
|
68
68
|
"@types/death": "^1.1.1",
|
69
69
|
"@types/express": "^4.17.11",
|
70
|
-
"@types/form-data": "^2.5.0",
|
71
70
|
"@types/fs-extra": "^9.0.11",
|
72
71
|
"@types/line-reader": "0.0.34",
|
73
72
|
"@types/localtunnel": "^2.0.1",
|
74
73
|
"@types/marked": "^3.0.0",
|
75
74
|
"@types/mime-types": "^2.1.0",
|
76
75
|
"@types/node": "^16.0.0",
|
77
|
-
"@types/pino": "^6.3.8",
|
78
76
|
"@types/puppeteer": "^5.4.0",
|
79
77
|
"@types/shelljs": "^0.8.5",
|
80
|
-
"@
|
78
|
+
"@types/winston-syslog": "^2.4.0",
|
79
|
+
"@typescript-eslint/eslint-plugin": "^5.8.0",
|
81
80
|
"@typescript-eslint/parser": "^4.15.2",
|
82
81
|
"auto-changelog": "^2.0.0",
|
83
82
|
"ava": "^3.13.0",
|
@@ -95,7 +94,7 @@
|
|
95
94
|
"shelljs": "^0.8.3",
|
96
95
|
"ts-node": "^10.0.0",
|
97
96
|
"tsc-watch": "^4.0.0",
|
98
|
-
"typedoc": "^0.21.
|
97
|
+
"typedoc": "^0.21.6",
|
99
98
|
"typedoc-plugin-pages": "^1.0.1",
|
100
99
|
"typescript": "^4.2.4"
|
101
100
|
},
|
@@ -116,7 +115,7 @@
|
|
116
115
|
"cross-spawn": "^7.0.3",
|
117
116
|
"datauri": "^4.0.1",
|
118
117
|
"death": "^1.1.0",
|
119
|
-
"eventemitter2": "^6.
|
118
|
+
"eventemitter2": "^6.4.4",
|
120
119
|
"express": "^4.17.1",
|
121
120
|
"express-robots-txt": "^1.0.0",
|
122
121
|
"find-up": "^5.0.0",
|
@@ -127,6 +126,7 @@
|
|
127
126
|
"image-type": "^4.1.0",
|
128
127
|
"is-url-superb": "^5.0.0",
|
129
128
|
"json5": "^2.2.0",
|
129
|
+
"klona": "^2.0.5",
|
130
130
|
"localtunnel": "^2.0.2",
|
131
131
|
"lodash.uniq": "^4.5.0",
|
132
132
|
"meow": "^9.0.0",
|
@@ -138,7 +138,6 @@
|
|
138
138
|
"parse-url": "^5.0.2",
|
139
139
|
"patch-package": "^6.2.2",
|
140
140
|
"pico-s3": "^1.0.1",
|
141
|
-
"pino": "^6.11.1",
|
142
141
|
"postman-2-swagger": "^0.5.0",
|
143
142
|
"puppeteer": "^13.0.0",
|
144
143
|
"puppeteer-extra": "^3.2.3",
|
@@ -153,11 +152,12 @@
|
|
153
152
|
"socket.io-client": "^4.1.1",
|
154
153
|
"spinnies": "^0.5.1",
|
155
154
|
"swagger-stats": "^0.99.1",
|
156
|
-
"swagger-ui-dist": "^
|
155
|
+
"swagger-ui-dist": "^4.1.3",
|
157
156
|
"swagger-ui-express": "^4.1.4",
|
158
157
|
"tcp-port-used": "^1.0.1",
|
159
158
|
"terminal-link": "^2.1.1",
|
160
159
|
"tiny-glob": "^0.2.9",
|
160
|
+
"traverse": "^0.6.6",
|
161
161
|
"tree-kill": "^1.2.2",
|
162
162
|
"ts-json-schema-generator": "^0.95.0",
|
163
163
|
"ts-morph": "^12.0.0",
|
@@ -165,7 +165,10 @@
|
|
165
165
|
"typeconv": "^1.7.0",
|
166
166
|
"update-notifier": "^5.0.0",
|
167
167
|
"uuid": "^8.3.2",
|
168
|
-
"uuid-apikey": "^1.
|
168
|
+
"uuid-apikey": "^1.5.3",
|
169
|
+
"winston": "^3.3.3",
|
170
|
+
"winston-daily-rotate-file": "^4.5.5",
|
171
|
+
"winston-syslog": "^2.4.4",
|
169
172
|
"xmlbuilder2": "^3.0.2"
|
170
173
|
}
|
171
174
|
}
|