@open-wa/wa-automate 4.39.0 → 4.40.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.
@@ -98,7 +98,8 @@ export declare enum LicenseType {
|
|
98
98
|
TEXT_STORY = "Text Story License Key",
|
99
99
|
IMAGE_STORY = "Image Story License Key",
|
100
100
|
VIDEO_STORY = "Video Story License Key",
|
101
|
-
PREMIUM = "Premium License Key"
|
101
|
+
PREMIUM = "Premium License Key",
|
102
|
+
NONE = "NONE"
|
102
103
|
}
|
103
104
|
export interface SessionData {
|
104
105
|
WABrowserId?: string;
|
package/dist/api/model/config.js
CHANGED
@@ -104,4 +104,5 @@ var LicenseType;
|
|
104
104
|
LicenseType["IMAGE_STORY"] = "Image Story License Key";
|
105
105
|
LicenseType["VIDEO_STORY"] = "Video Story License Key";
|
106
106
|
LicenseType["PREMIUM"] = "Premium License Key";
|
107
|
+
LicenseType["NONE"] = "NONE";
|
107
108
|
})(LicenseType = exports.LicenseType || (exports.LicenseType = {}));
|
package/dist/cli/file-utils.js
CHANGED
@@ -26,13 +26,18 @@ exports.tryOpenFileAsObject = void 0;
|
|
26
26
|
const path = __importStar(require("path"));
|
27
27
|
const fs = __importStar(require("fs"));
|
28
28
|
const json5_1 = __importDefault(require("json5"));
|
29
|
+
const logging_1 = require("../logging/logging");
|
29
30
|
const tryOpenFileAsObject = (fileLocation, needArray = false) => {
|
30
31
|
let res = undefined;
|
32
|
+
let fp = undefined;
|
31
33
|
const relativePath = path.join(path.resolve(process.cwd(), fileLocation || ''));
|
34
|
+
const isJs = fileLocation.endsWith(".js");
|
35
|
+
logging_1.log.info(`Checking exists: ${fileLocation || relativePath}`);
|
32
36
|
if (fs.existsSync(fileLocation) || fs.existsSync(relativePath)) {
|
33
|
-
|
37
|
+
fp = isJs ? fs.existsSync(relativePath) && relativePath : fs.existsSync(fileLocation) ? fileLocation : relativePath;
|
38
|
+
logging_1.log.info("Attempting to open: " + fp);
|
34
39
|
try {
|
35
|
-
const data = json5_1.default.parse(fs.readFileSync(fp, 'utf8'));
|
40
|
+
const data = isJs ? (require(fp) || {}).default : json5_1.default.parse(fs.readFileSync(fp, 'utf8'));
|
36
41
|
if (data && (Array.isArray(data) == needArray))
|
37
42
|
res = data;
|
38
43
|
}
|
@@ -40,6 +45,9 @@ const tryOpenFileAsObject = (fileLocation, needArray = false) => {
|
|
40
45
|
throw `Unable to parse config file as JSON. Please make sure ${fp} is a valid JSON config file`;
|
41
46
|
}
|
42
47
|
}
|
43
|
-
|
48
|
+
else
|
49
|
+
return;
|
50
|
+
logging_1.log.info(`${fp} is ${res ? 'valid' : 'invalid'}`);
|
51
|
+
return res && Object.assign(Object.assign({}, (res || {})), { confPath: fp });
|
44
52
|
};
|
45
53
|
exports.tryOpenFileAsObject = tryOpenFileAsObject;
|
package/dist/cli/setup.d.ts
CHANGED
@@ -19,7 +19,7 @@ export declare const cliOptionNames: import("type-fest").Simplify<import("type-f
|
|
19
19
|
export declare const meowFlags: () => AnyFlags;
|
20
20
|
export declare const helptext: string;
|
21
21
|
export declare const envArgs: () => JsonObject;
|
22
|
-
export declare const configFile: (config
|
22
|
+
export declare const configFile: (config?: string) => JsonObject;
|
23
23
|
export declare const cli: () => {
|
24
24
|
createConfig: ConfigObject;
|
25
25
|
cliConfig: Merge<ConfigObject, {
|
package/dist/cli/setup.js
CHANGED
@@ -126,23 +126,42 @@ exports.envArgs = envArgs;
|
|
126
126
|
const configFile = (config) => {
|
127
127
|
let confFile = {};
|
128
128
|
const conf = config || process.env.WA_CLI_CONFIG;
|
129
|
+
const backup = () => {
|
130
|
+
if (!confFile)
|
131
|
+
confFile = (0, file_utils_1.tryOpenFileAsObject)(`cli.config.json`);
|
132
|
+
if (!confFile)
|
133
|
+
confFile = (0, file_utils_1.tryOpenFileAsObject)(`cli.config.js`);
|
134
|
+
};
|
135
|
+
const attempt = (firstAttempt) => {
|
136
|
+
try {
|
137
|
+
confFile = (0, file_utils_1.tryOpenFileAsObject)(firstAttempt || `cli.config.json`);
|
138
|
+
backup();
|
139
|
+
}
|
140
|
+
catch (error) {
|
141
|
+
logging_1.log.error(error);
|
142
|
+
logging_1.log.error("Trying cli.config.js");
|
143
|
+
backup();
|
144
|
+
}
|
145
|
+
};
|
129
146
|
if (conf) {
|
130
147
|
if ((0, tools_1.isBase64)(conf)) {
|
131
148
|
confFile = JSON.parse(Buffer.from(conf, 'base64').toString('ascii'));
|
132
149
|
}
|
133
150
|
else {
|
134
|
-
|
151
|
+
attempt(conf);
|
135
152
|
if (!confFile)
|
136
153
|
console.error(`Unable to read config file json: ${conf}`);
|
137
154
|
}
|
138
155
|
}
|
139
156
|
else {
|
140
|
-
|
157
|
+
attempt();
|
141
158
|
}
|
159
|
+
logging_1.log.info(`Using config file: ${confFile.confPath || "???"}`);
|
142
160
|
return confFile;
|
143
161
|
};
|
144
162
|
exports.configFile = configFile;
|
145
163
|
const cli = () => {
|
164
|
+
let loggingSetup = false;
|
146
165
|
const _cli = (0, meow_1.default)(exports.helptext, {
|
147
166
|
flags: Object.assign(Object.assign({}, (0, exports.meowFlags)()), { popup: {
|
148
167
|
type: 'boolean',
|
@@ -150,6 +169,21 @@ const cli = () => {
|
|
150
169
|
} }),
|
151
170
|
booleanDefault: undefined
|
152
171
|
});
|
172
|
+
const _setupLogging = (_config) => {
|
173
|
+
if (loggingSetup)
|
174
|
+
return;
|
175
|
+
//firstly set up logger
|
176
|
+
if ((_config === null || _config === void 0 ? void 0 : _config.logging) || (_config === null || _config === void 0 ? void 0 : _config.verbose)) {
|
177
|
+
if (!(_config === null || _config === void 0 ? void 0 : _config.logging) && (_config === null || _config === void 0 ? void 0 : _config.verbose))
|
178
|
+
_config.logging = [];
|
179
|
+
if ((_config === null || _config === void 0 ? void 0 : _config.logging) && !((_config === null || _config === void 0 ? void 0 : _config.logging) || []).find(transport => transport.type === "console"))
|
180
|
+
_config.logging.push({ type: 'console' });
|
181
|
+
if (Array.isArray(_config === null || _config === void 0 ? void 0 : _config.logging))
|
182
|
+
_config.logging = (0, logging_1.setupLogging)(_config === null || _config === void 0 ? void 0 : _config.logging, `easy-api-${(_config === null || _config === void 0 ? void 0 : _config.sessionId) || 'session'}`);
|
183
|
+
loggingSetup = true;
|
184
|
+
}
|
185
|
+
};
|
186
|
+
_setupLogging(_cli.flags);
|
153
187
|
/**
|
154
188
|
* Config order should follow airmanship rules. Least maneuverable to most maneuverable.
|
155
189
|
*
|
@@ -161,14 +195,7 @@ const cli = () => {
|
|
161
195
|
cli_options_1.optionList.filter(option => option.default);
|
162
196
|
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, {}));
|
163
197
|
//firstly set up logger
|
164
|
-
|
165
|
-
if (!(cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.logging) && (cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.verbose))
|
166
|
-
cliConfig.logging = [];
|
167
|
-
if ((cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.logging) && !((cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.logging) || []).find(transport => transport.type === "console"))
|
168
|
-
cliConfig.logging.push({ type: 'console' });
|
169
|
-
if (Array.isArray(cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.logging))
|
170
|
-
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'}`);
|
171
|
-
}
|
198
|
+
_setupLogging(cliConfig);
|
172
199
|
const PORT = Number((typeof cliConfig.forcePort === "boolean" && cliConfig.forcePort ? process.env.PORT : cliConfig.forcePort) || cliConfig.port || process.env.PORT || 8080);
|
173
200
|
const spinner = new events_1.Spin(cliConfig.sessionId, 'STARTUP', cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.disableSpins);
|
174
201
|
const createConfig = Object.assign({}, cliConfig);
|
@@ -149,6 +149,15 @@ function getLicense(config, me, debugInfo, spinner) {
|
|
149
149
|
const hasSpin = !!spinner;
|
150
150
|
if (!spinner)
|
151
151
|
spinner = new events_1.Spin(config.sessionId || "session", "FETCH_LICENSE", config.disableSpins, true);
|
152
|
+
if (typeof config.licenseKey === "function") {
|
153
|
+
//run the funciton to get the key
|
154
|
+
config.licenseKey = yield config.licenseKey(config.sessionId, me._serialized);
|
155
|
+
}
|
156
|
+
if (typeof config.licenseKey === "object") {
|
157
|
+
//attempt to get the key from the object
|
158
|
+
config.licenseKey = config.licenseKey[me._serialized] || config.licenseKey[config.sessionId];
|
159
|
+
}
|
160
|
+
//asume by now the key is a string
|
152
161
|
spinner === null || spinner === void 0 ? void 0 : spinner.start(`Fetching License: ${Array.isArray(config.licenseKey) ? config.licenseKey : typeof config.licenseKey === "string" ? config.licenseKey.indexOf("-") == -1 ? config.licenseKey.slice(-4) : config.licenseKey.split("-").slice(-1)[0] : config.licenseKey}`, hasSpin ? undefined : 2);
|
153
162
|
try {
|
154
163
|
const START = Date.now();
|
package/package.json
CHANGED