@open-wa/wa-automate 4.33.4 → 4.33.7
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/dist/api/Client.d.ts +1 -1
- package/dist/api/Client.js +4 -1
- package/dist/structures/preProcessors.js +1 -1
- package/dist/utils/tools.d.ts +52 -0
- package/dist/utils/tools.js +92 -1
- package/package.json +1 -1
package/dist/api/Client.d.ts
CHANGED
@@ -1023,7 +1023,7 @@ export declare class Client {
|
|
1023
1023
|
* @param {boolean} isHidden Whether or not the product is shown publicly in your catalog
|
1024
1024
|
* @returns product object
|
1025
1025
|
*/
|
1026
|
-
createNewProduct(name: string, price: number, currency: string, images:
|
1026
|
+
createNewProduct(name: string, price: number, currency: string, images: string[], description: string, url?: string, internalId?: string, isHidden?: boolean): Promise<Product>;
|
1027
1027
|
/**
|
1028
1028
|
* [REQUIRES AN INSIDERS LICENSE-KEY](https://gum.co/open-wa?tier=Insiders%20Program)
|
1029
1029
|
*
|
package/dist/api/Client.js
CHANGED
@@ -2227,6 +2227,9 @@ class Client {
|
|
2227
2227
|
*/
|
2228
2228
|
createNewProduct(name, price, currency, images, description, url, internalId, isHidden) {
|
2229
2229
|
return __awaiter(this, void 0, void 0, function* () {
|
2230
|
+
if (!Array.isArray(images))
|
2231
|
+
images = [images];
|
2232
|
+
images = yield Promise.all(images.map(image => (0, tools_1.ensureDUrl)(image)));
|
2230
2233
|
return yield this.pup(({ name, price, currency, images, description, url, internalId, isHidden }) => WAPI.createNewProduct(name, price, currency, images, description, url, internalId, isHidden), { name, price, currency, images, description, url, internalId, isHidden });
|
2231
2234
|
});
|
2232
2235
|
}
|
@@ -3167,7 +3170,7 @@ class Client {
|
|
3167
3170
|
height: 512,
|
3168
3171
|
animated,
|
3169
3172
|
};
|
3170
|
-
webpBase64 = webpBase64.replace(/^data:image\/(png|gif|jpeg|webp);base64,/, '');
|
3173
|
+
webpBase64 = webpBase64.replace(/^data:image\/(png|gif|jpeg|webp|octet-stream);base64,/, '');
|
3171
3174
|
return yield this.pup(({ webpBase64, to, metadata }) => WAPI.sendImageAsSticker(webpBase64, to, metadata), { webpBase64, to, metadata });
|
3172
3175
|
});
|
3173
3176
|
}
|
@@ -59,7 +59,7 @@ const UPLOAD_CLOUD = (message, client) => __awaiter(void 0, void 0, void 0, func
|
|
59
59
|
if (!uploadQueue) {
|
60
60
|
uploadQueue = new p_queue_1.default({ concurrency: 2, interval: 1000, carryoverConcurrencyCount: true, intervalCap: 2 });
|
61
61
|
}
|
62
|
-
const filename = `${message.id.split("_").
|
62
|
+
const filename = `${message.id.split("_").find(x => !x.includes("@") && x.length > 6) || `${Date.now()}`}.${mime_1.default.extension(message.mimetype)}`;
|
63
63
|
const mediaData = yield client.decryptMedia(message);
|
64
64
|
if (!cloudUploadOptions)
|
65
65
|
return message;
|
package/dist/utils/tools.d.ts
CHANGED
@@ -10,9 +10,25 @@ export declare const timeout: (ms: any) => Promise<unknown>;
|
|
10
10
|
*/
|
11
11
|
export declare const smartUserAgent: (ua: string, version?: string) => string;
|
12
12
|
export declare const getConfigFromProcessEnv: any;
|
13
|
+
/**
|
14
|
+
* Remove the key from the object and return the rest of the object.
|
15
|
+
* @param {JsonObject} obj - The object to be filtered.
|
16
|
+
* @param {string} key - The key to discard.
|
17
|
+
* @returns The object without the key.
|
18
|
+
*/
|
13
19
|
export declare const without: any;
|
14
20
|
export declare const camelize: (str: string) => string;
|
21
|
+
/**
|
22
|
+
* Check if a string is Base64
|
23
|
+
* @param str string
|
24
|
+
* @returns
|
25
|
+
*/
|
15
26
|
export declare const isBase64: (str: string) => boolean;
|
27
|
+
/**
|
28
|
+
* Check if a string is a DataURL
|
29
|
+
* @param s string
|
30
|
+
* @returns
|
31
|
+
*/
|
16
32
|
export declare const isDataURL: (s: string) => boolean;
|
17
33
|
/**
|
18
34
|
* @internal
|
@@ -26,9 +42,45 @@ export declare const getDUrl: (url: string, optionsOverride?: AxiosRequestConfig
|
|
26
42
|
* Use this to extract the mime type from a [[DataURL]]
|
27
43
|
*/
|
28
44
|
export declare const base64MimeType: (dUrl: DataURL) => string;
|
45
|
+
/**
|
46
|
+
* If process.send is defined, send the message three times
|
47
|
+
* @param {string} message - The message to send to the parent process.
|
48
|
+
* @returns Nothing.
|
49
|
+
*/
|
29
50
|
export declare const processSend: (message: string) => void;
|
51
|
+
/**
|
52
|
+
* Return the performance object if it is available, otherwise return the Date object
|
53
|
+
*/
|
30
54
|
export declare const perf: () => DateConstructor | import("perf_hooks").Performance;
|
55
|
+
/**
|
56
|
+
* Return the current time in milliseconds
|
57
|
+
*/
|
31
58
|
export declare const now: () => number;
|
59
|
+
/**
|
60
|
+
* `timePromise` returns a promise that resolves to the time it took to run the function passed to it
|
61
|
+
* @param fn - the function to be timed.
|
62
|
+
* @returns A string.
|
63
|
+
*/
|
32
64
|
export declare function timePromise(fn: () => Promise<any>): Promise<string>;
|
65
|
+
/**
|
66
|
+
* It sends a message to the parent process.
|
67
|
+
* @param {any} data - The data to be sent to the parent process.
|
68
|
+
* @returns Nothing.
|
69
|
+
*/
|
33
70
|
export declare const processSendData: (data?: any) => void;
|
71
|
+
/**
|
72
|
+
* It generates a link to the GitHub issue template for the current session
|
73
|
+
* @param {ConfigObject} config - the config object
|
74
|
+
* @param {SessionInfo} sessionInfo - The sessionInfo object from the CLI
|
75
|
+
* @param {any} extras - any
|
76
|
+
* @returns A link to the issue tracker for the current session.
|
77
|
+
*/
|
34
78
|
export declare const generateGHIssueLink: (config: ConfigObject, sessionInfo: SessionInfo, extras?: any) => string;
|
79
|
+
/**
|
80
|
+
* If the file is a DataURL, return it. If it's a file, convert it to a DataURL. If it's a URL,
|
81
|
+
* download it and convert it to a DataURL. If Base64, returns it.
|
82
|
+
* @param {string} file - The file to be converted to a DataURL.
|
83
|
+
* @param {AxiosRequestConfig} requestConfig - AxiosRequestConfig = {}
|
84
|
+
* @returns A DataURL
|
85
|
+
*/
|
86
|
+
export declare const ensureDUrl: (file: string, requestConfig?: AxiosRequestConfig) => Promise<string>;
|
package/dist/utils/tools.js
CHANGED
@@ -1,4 +1,23 @@
|
|
1
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
|
+
};
|
2
21
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
22
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
23
|
return new (P || (P = Promise))(function (resolve, reject) {
|
@@ -23,7 +42,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
42
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
24
43
|
};
|
25
44
|
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
-
exports.generateGHIssueLink = exports.processSendData = exports.timePromise = exports.now = exports.perf = exports.processSend = exports.base64MimeType = exports.getDUrl = exports.isDataURL = exports.isBase64 = exports.camelize = exports.without = exports.getConfigFromProcessEnv = exports.smartUserAgent = exports.timeout = void 0;
|
45
|
+
exports.ensureDUrl = exports.generateGHIssueLink = exports.processSendData = exports.timePromise = exports.now = exports.perf = exports.processSend = exports.base64MimeType = exports.getDUrl = exports.isDataURL = exports.isBase64 = exports.camelize = exports.without = exports.getConfigFromProcessEnv = exports.smartUserAgent = exports.timeout = void 0;
|
46
|
+
const fs = __importStar(require("fs"));
|
47
|
+
const path = __importStar(require("path"));
|
48
|
+
const datauri_1 = __importDefault(require("datauri"));
|
49
|
+
const is_url_superb_1 = __importDefault(require("is-url-superb"));
|
50
|
+
const model_1 = require("../api/model");
|
27
51
|
const axios_1 = __importDefault(require("axios"));
|
28
52
|
const child_process_1 = require("child_process");
|
29
53
|
const perf_hooks_1 = require("perf_hooks");
|
@@ -60,6 +84,12 @@ const getConfigFromProcessEnv = (json) => {
|
|
60
84
|
return output;
|
61
85
|
};
|
62
86
|
exports.getConfigFromProcessEnv = getConfigFromProcessEnv;
|
87
|
+
/**
|
88
|
+
* Remove the key from the object and return the rest of the object.
|
89
|
+
* @param {JsonObject} obj - The object to be filtered.
|
90
|
+
* @param {string} key - The key to discard.
|
91
|
+
* @returns The object without the key.
|
92
|
+
*/
|
63
93
|
const without = (obj, key) => {
|
64
94
|
const _a = obj,
|
65
95
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
@@ -79,6 +109,11 @@ const camelize = (str) => {
|
|
79
109
|
return capitalString;
|
80
110
|
};
|
81
111
|
exports.camelize = camelize;
|
112
|
+
/**
|
113
|
+
* Check if a string is Base64
|
114
|
+
* @param str string
|
115
|
+
* @returns
|
116
|
+
*/
|
82
117
|
const isBase64 = (str) => {
|
83
118
|
const len = str.length;
|
84
119
|
if (!len || len % 4 !== 0 || /[^A-Z0-9+/=]/i.test(str)) {
|
@@ -90,6 +125,11 @@ const isBase64 = (str) => {
|
|
90
125
|
(firstPaddingChar === len - 2 && str[len - 1] === '='));
|
91
126
|
};
|
92
127
|
exports.isBase64 = isBase64;
|
128
|
+
/**
|
129
|
+
* Check if a string is a DataURL
|
130
|
+
* @param s string
|
131
|
+
* @returns
|
132
|
+
*/
|
93
133
|
const isDataURL = (s) => !!s.match(/^data:((?:\w+\/(?:(?!;).)+)?)((?:;[\w\W]*?[^;])*),(.+)$/g);
|
94
134
|
exports.isDataURL = isDataURL;
|
95
135
|
/**
|
@@ -129,6 +169,11 @@ const base64MimeType = (dUrl) => {
|
|
129
169
|
return result;
|
130
170
|
};
|
131
171
|
exports.base64MimeType = base64MimeType;
|
172
|
+
/**
|
173
|
+
* If process.send is defined, send the message three times
|
174
|
+
* @param {string} message - The message to send to the parent process.
|
175
|
+
* @returns Nothing.
|
176
|
+
*/
|
132
177
|
const processSend = (message) => {
|
133
178
|
if (process.send) {
|
134
179
|
process.send(message);
|
@@ -138,10 +183,21 @@ const processSend = (message) => {
|
|
138
183
|
return;
|
139
184
|
};
|
140
185
|
exports.processSend = processSend;
|
186
|
+
/**
|
187
|
+
* Return the performance object if it is available, otherwise return the Date object
|
188
|
+
*/
|
141
189
|
const perf = () => perf_hooks_1.performance || Date;
|
142
190
|
exports.perf = perf;
|
191
|
+
/**
|
192
|
+
* Return the current time in milliseconds
|
193
|
+
*/
|
143
194
|
const now = () => (0, exports.perf)().now();
|
144
195
|
exports.now = now;
|
196
|
+
/**
|
197
|
+
* `timePromise` returns a promise that resolves to the time it took to run the function passed to it
|
198
|
+
* @param fn - the function to be timed.
|
199
|
+
* @returns A string.
|
200
|
+
*/
|
145
201
|
function timePromise(fn) {
|
146
202
|
return __awaiter(this, void 0, void 0, function* () {
|
147
203
|
const start = (0, exports.now)();
|
@@ -150,6 +206,11 @@ function timePromise(fn) {
|
|
150
206
|
});
|
151
207
|
}
|
152
208
|
exports.timePromise = timePromise;
|
209
|
+
/**
|
210
|
+
* It sends a message to the parent process.
|
211
|
+
* @param {any} data - The data to be sent to the parent process.
|
212
|
+
* @returns Nothing.
|
213
|
+
*/
|
153
214
|
const processSendData = (data = {}) => {
|
154
215
|
process.send({
|
155
216
|
type: 'process:msg',
|
@@ -158,6 +219,13 @@ const processSendData = (data = {}) => {
|
|
158
219
|
return;
|
159
220
|
};
|
160
221
|
exports.processSendData = processSendData;
|
222
|
+
/**
|
223
|
+
* It generates a link to the GitHub issue template for the current session
|
224
|
+
* @param {ConfigObject} config - the config object
|
225
|
+
* @param {SessionInfo} sessionInfo - The sessionInfo object from the CLI
|
226
|
+
* @param {any} extras - any
|
227
|
+
* @returns A link to the issue tracker for the current session.
|
228
|
+
*/
|
161
229
|
const generateGHIssueLink = (config, sessionInfo, extras = {}) => {
|
162
230
|
const npm_ver = (0, child_process_1.execSync)('npm -v');
|
163
231
|
const labels = [];
|
@@ -180,3 +248,26 @@ const generateGHIssueLink = (config, sessionInfo, extras = {}) => {
|
|
180
248
|
return `https://github.com/open-wa/wa-automate-nodejs/issues/new?${Object.keys(qp).map(k => `${k}=${qp[k]}`).join('&')}`;
|
181
249
|
};
|
182
250
|
exports.generateGHIssueLink = generateGHIssueLink;
|
251
|
+
/**
|
252
|
+
* If the file is a DataURL, return it. If it's a file, convert it to a DataURL. If it's a URL,
|
253
|
+
* download it and convert it to a DataURL. If Base64, returns it.
|
254
|
+
* @param {string} file - The file to be converted to a DataURL.
|
255
|
+
* @param {AxiosRequestConfig} requestConfig - AxiosRequestConfig = {}
|
256
|
+
* @returns A DataURL
|
257
|
+
*/
|
258
|
+
const ensureDUrl = (file, requestConfig = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
259
|
+
if (!(0, exports.isDataURL)(file) && !(0, exports.isBase64)(file)) {
|
260
|
+
//must be a file then
|
261
|
+
const relativePath = path.join(path.resolve(process.cwd(), file || ''));
|
262
|
+
if (fs.existsSync(file) || fs.existsSync(relativePath)) {
|
263
|
+
file = yield (0, datauri_1.default)(fs.existsSync(file) ? file : relativePath);
|
264
|
+
}
|
265
|
+
else if ((0, is_url_superb_1.default)(file)) {
|
266
|
+
file = yield (0, exports.getDUrl)(file, requestConfig);
|
267
|
+
}
|
268
|
+
else
|
269
|
+
throw new model_1.CustomError(model_1.ERROR_NAME.FILE_NOT_FOUND, 'Cannot find file. Make sure the file reference is relative, a valid URL or a valid DataURL');
|
270
|
+
}
|
271
|
+
return file;
|
272
|
+
});
|
273
|
+
exports.ensureDUrl = ensureDUrl;
|
package/package.json
CHANGED