@open-wa/wa-automate 4.76.0 → 5.0.0-alpha.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.
Files changed (125) hide show
  1. package/README.md +14 -165
  2. package/dist/cli-runtime-B7_3MM0c.cjs +798 -0
  3. package/dist/cli-runtime-B7_3MM0c.cjs.map +1 -0
  4. package/dist/cli-runtime-CmpYxFCk.d.cts +31 -0
  5. package/dist/cli-runtime-CmpYxFCk.d.cts.map +1 -0
  6. package/dist/cli.cjs +17 -0
  7. package/dist/cli.cjs.map +1 -0
  8. package/dist/cli.d.cts +2 -0
  9. package/dist/index.cjs +224 -0
  10. package/dist/index.cjs.map +1 -0
  11. package/dist/index.d.cts +81 -0
  12. package/dist/index.d.cts.map +1 -0
  13. package/package.json +34 -177
  14. package/CNAME +0 -1
  15. package/_tsconfig.docs.json +0 -140
  16. package/bin/config-schema.json +0 -1
  17. package/bin/oas-type-schemas.json +0 -1
  18. package/bin/server.js +0 -45
  19. package/build/build-config-json-for-bin.ts +0 -56
  20. package/build/generate-oas-types.ts +0 -31
  21. package/dist/api/Client.d.ts +0 -2255
  22. package/dist/api/Client.js +0 -4358
  23. package/dist/api/functions/exposed.enum.d.ts +0 -7
  24. package/dist/api/functions/exposed.enum.js +0 -11
  25. package/dist/api/model/aliases.d.ts +0 -110
  26. package/dist/api/model/aliases.js +0 -3
  27. package/dist/api/model/button.d.ts +0 -24
  28. package/dist/api/model/button.js +0 -2
  29. package/dist/api/model/call.d.ts +0 -51
  30. package/dist/api/model/call.js +0 -18
  31. package/dist/api/model/chat.d.ts +0 -221
  32. package/dist/api/model/chat.js +0 -52
  33. package/dist/api/model/config.d.ts +0 -836
  34. package/dist/api/model/config.js +0 -111
  35. package/dist/api/model/contact.d.ts +0 -143
  36. package/dist/api/model/contact.js +0 -2
  37. package/dist/api/model/errors.d.ts +0 -90
  38. package/dist/api/model/errors.js +0 -117
  39. package/dist/api/model/events.d.ts +0 -120
  40. package/dist/api/model/events.js +0 -127
  41. package/dist/api/model/group-metadata.d.ts +0 -124
  42. package/dist/api/model/group-metadata.js +0 -25
  43. package/dist/api/model/id.d.ts +0 -5
  44. package/dist/api/model/id.js +0 -2
  45. package/dist/api/model/index.d.ts +0 -110
  46. package/dist/api/model/index.js +0 -128
  47. package/dist/api/model/label.d.ts +0 -24
  48. package/dist/api/model/label.js +0 -2
  49. package/dist/api/model/media.d.ts +0 -93
  50. package/dist/api/model/media.js +0 -12
  51. package/dist/api/model/message.d.ts +0 -422
  52. package/dist/api/model/message.js +0 -40
  53. package/dist/api/model/product.d.ts +0 -141
  54. package/dist/api/model/product.js +0 -2
  55. package/dist/api/model/reactions.d.ts +0 -76
  56. package/dist/api/model/reactions.js +0 -2
  57. package/dist/api/model/sessionInfo.d.ts +0 -77
  58. package/dist/api/model/sessionInfo.js +0 -2
  59. package/dist/build/build-postman.d.ts +0 -1
  60. package/dist/build/build-postman.js +0 -262
  61. package/dist/cli/cli-options.d.ts +0 -9
  62. package/dist/cli/cli-options.js +0 -289
  63. package/dist/cli/collections.d.ts +0 -2
  64. package/dist/cli/collections.js +0 -251
  65. package/dist/cli/file-utils.d.ts +0 -1
  66. package/dist/cli/file-utils.js +0 -71
  67. package/dist/cli/index.d.ts +0 -1
  68. package/dist/cli/index.js +0 -231
  69. package/dist/cli/integrations/chatwoot.d.ts +0 -49
  70. package/dist/cli/integrations/chatwoot.js +0 -672
  71. package/dist/cli/integrations/cloudflare.d.ts +0 -6
  72. package/dist/cli/integrations/cloudflare.js +0 -76
  73. package/dist/cli/logo.d.ts +0 -1
  74. package/dist/cli/logo.js +0 -49
  75. package/dist/cli/server.d.ts +0 -24
  76. package/dist/cli/server.js +0 -540
  77. package/dist/cli/setup.d.ts +0 -30
  78. package/dist/cli/setup.js +0 -308
  79. package/dist/config/puppeteer.config.d.ts +0 -11
  80. package/dist/config/puppeteer.config.js +0 -65
  81. package/dist/controllers/auth.d.ts +0 -36
  82. package/dist/controllers/auth.js +0 -322
  83. package/dist/controllers/browser.d.ts +0 -17
  84. package/dist/controllers/browser.js +0 -603
  85. package/dist/controllers/events.d.ts +0 -82
  86. package/dist/controllers/events.js +0 -173
  87. package/dist/controllers/init_patch.d.ts +0 -13
  88. package/dist/controllers/init_patch.js +0 -42
  89. package/dist/controllers/initializer.d.ts +0 -22
  90. package/dist/controllers/initializer.js +0 -511
  91. package/dist/controllers/launch_checks.d.ts +0 -8
  92. package/dist/controllers/launch_checks.js +0 -130
  93. package/dist/controllers/patch_manager.d.ts +0 -37
  94. package/dist/controllers/patch_manager.js +0 -231
  95. package/dist/controllers/popup/index.d.ts +0 -3
  96. package/dist/controllers/popup/index.html +0 -168
  97. package/dist/controllers/popup/index.js +0 -148
  98. package/dist/controllers/script_preloader.d.ts +0 -17
  99. package/dist/controllers/script_preloader.js +0 -88
  100. package/dist/index.d.ts +0 -13
  101. package/dist/index.js +0 -36
  102. package/dist/lib/README.md +0 -5
  103. package/dist/lib/base64.js +0 -1
  104. package/dist/lib/hash.js +0 -1
  105. package/dist/lib/jsSha.min.js +0 -1
  106. package/dist/lib/launch.js +0 -1
  107. package/dist/lib/qr.min.js +0 -1
  108. package/dist/lib/wapi.js +0 -2163
  109. package/dist/logging/custom_transport.d.ts +0 -9
  110. package/dist/logging/custom_transport.js +0 -35
  111. package/dist/logging/logging.d.ts +0 -50
  112. package/dist/logging/logging.js +0 -196
  113. package/dist/structures/Collector.d.ts +0 -202
  114. package/dist/structures/Collector.js +0 -391
  115. package/dist/structures/Dialog.d.ts +0 -55
  116. package/dist/structures/Dialog.js +0 -21
  117. package/dist/structures/MessageCollector.d.ts +0 -78
  118. package/dist/structures/MessageCollector.js +0 -145
  119. package/dist/structures/preProcessors.d.ts +0 -58
  120. package/dist/structures/preProcessors.js +0 -181
  121. package/dist/utils/pid_utils.d.ts +0 -1
  122. package/dist/utils/pid_utils.js +0 -26
  123. package/dist/utils/tools.d.ts +0 -152
  124. package/dist/utils/tools.js +0 -494
  125. package/tos.md +0 -77
@@ -1,494 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- var __rest = (this && this.__rest) || function (s, e) {
35
- var t = {};
36
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
37
- t[p] = s[p];
38
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
39
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
40
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
41
- t[p[i]] = s[p[i]];
42
- }
43
- return t;
44
- };
45
- var __importDefault = (this && this.__importDefault) || function (mod) {
46
- return (mod && mod.__esModule) ? mod : { "default": mod };
47
- };
48
- Object.defineProperty(exports, "__esModule", { value: true });
49
- exports.sanitizeAccentedChars = exports.fixPath = exports.pathExists = exports.assertFile = exports.rmFileAsync = exports.FileOutputTypes = exports.FileInputTypes = exports.ensureDUrl = exports.generateGHIssueLink = exports.processSendData = exports.timePromise = exports.now = exports.perf = exports.processSend = exports.base64MimeType = exports.getDUrl = exports.getBufferFromUrl = exports.isDataURL = exports.isBase64 = exports.camelize = exports.without = exports.getConfigFromProcessEnv = exports.smartUserAgent = exports.timeout = void 0;
50
- const crypto_1 = __importDefault(require("crypto"));
51
- const fs = __importStar(require("fs"));
52
- const fsp = __importStar(require("fs/promises"));
53
- const path = __importStar(require("path"));
54
- const datauri_1 = __importDefault(require("datauri"));
55
- const is_url_superb_1 = __importDefault(require("is-url-superb"));
56
- const model_1 = require("../api/model");
57
- const axios_1 = __importDefault(require("axios"));
58
- const child_process_1 = require("child_process");
59
- const os_1 = require("os");
60
- const perf_hooks_1 = require("perf_hooks");
61
- const mime_1 = __importDefault(require("mime"));
62
- const os_2 = require("os");
63
- const stream_1 = require("stream");
64
- const logging_1 = require("../logging/logging");
65
- const import_1 = require("@brillout/import");
66
- const fsconstants = fsp.constants || {
67
- F_OK: 0,
68
- R_OK: 4,
69
- W_OK: 2,
70
- X_OK: 1
71
- };
72
- const IGNORE_FILE_EXTS = [
73
- 'mpga'
74
- ];
75
- let _ft = null;
76
- const ft = () => __awaiter(void 0, void 0, void 0, function* () {
77
- if (!_ft) {
78
- const x = yield (0, import_1.import_)('file-type');
79
- _ft = x;
80
- }
81
- return _ft;
82
- });
83
- //@ts-ignore
84
- process.send = process.send || function () { };
85
- const timeout = ms => new Promise(resolve => setTimeout(resolve, ms, 'timeout'));
86
- exports.timeout = timeout;
87
- /**
88
- * Use this to generate a more likely valid user agent. It makes sure it has the WA part and replaces any windows or linux os info with mac.
89
- * @param useragent Your custom user agent
90
- * @param v The WA version from the debug info. This is optional. default is 2.2117.5
91
- */
92
- const smartUserAgent = (useragent, v = '2.2117.5') => {
93
- useragent = useragent.replace(useragent
94
- .match(/\(([^()]*)\)/g)
95
- .find((x) => x.toLowerCase().includes('linux') ||
96
- x.toLowerCase().includes('windows')), '(Macintosh; Intel Mac OS X 10_15_2)');
97
- if (!useragent.includes('WhatsApp'))
98
- return `WhatsApp/${v} ${useragent}`;
99
- return useragent.replace(useragent
100
- .match(/WhatsApp\/([.\d])*/g)[0]
101
- .match(/[.\d]*/g)
102
- .find((x) => x), v);
103
- };
104
- exports.smartUserAgent = smartUserAgent;
105
- const getConfigFromProcessEnv = (json) => {
106
- const output = {};
107
- json.forEach(({ env, key }) => {
108
- if (process.env[env])
109
- output[key] = process.env[env];
110
- if (process.env[env] === 'true' || process.env[env] === 'false')
111
- output[key] = Boolean(process.env[env]);
112
- });
113
- return output;
114
- };
115
- exports.getConfigFromProcessEnv = getConfigFromProcessEnv;
116
- /**
117
- * Remove the key from the object and return the rest of the object.
118
- * @param {JsonObject} obj - The object to be filtered.
119
- * @param {string} key - The key to discard.
120
- * @returns The object without the key.
121
- */
122
- const without = (obj, key) => {
123
- const _a = obj,
124
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
125
- _b = key,
126
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
127
- discard = _a[_b], rest = __rest(_a, [typeof _b === "symbol" ? _b : _b + ""]);
128
- return rest;
129
- };
130
- exports.without = without;
131
- const camelize = (str) => {
132
- const arr = str.split('-');
133
- const capital = arr.map((item, index) => index
134
- ? item.charAt(0).toUpperCase() + item.slice(1).toLowerCase()
135
- : item.toLowerCase());
136
- // ^-- change here.
137
- const capitalString = capital.join('');
138
- return capitalString;
139
- };
140
- exports.camelize = camelize;
141
- /**
142
- * Check if a string is Base64
143
- * @param str string
144
- * @returns
145
- */
146
- const isBase64 = (str) => {
147
- const len = str.length;
148
- if (!len || len % 4 !== 0 || /[^A-Z0-9+/=]/i.test(str)) {
149
- return false;
150
- }
151
- const firstPaddingChar = str.indexOf('=');
152
- return (firstPaddingChar === -1 ||
153
- firstPaddingChar === len - 1 ||
154
- (firstPaddingChar === len - 2 && str[len - 1] === '='));
155
- };
156
- exports.isBase64 = isBase64;
157
- /**
158
- * Check if a string is a DataURL
159
- * @param s string
160
- * @returns
161
- */
162
- const isDataURL = (s) => !!s.match(/^data:((?:\w+\/(?:(?!;).)+)?)((?:;[\w\W]*?[^;])*),(.+)$/g);
163
- exports.isDataURL = isDataURL;
164
- /**
165
- * @internal
166
- * A convinience method to download the buffer of a downloaded file
167
- * @param url The url
168
- * @param optionsOverride You can use this to override the [axios request config](https://github.com/axios/axios#request-config)
169
- */
170
- const getBufferFromUrl = (url, optionsOverride = {}) => __awaiter(void 0, void 0, void 0, function* () {
171
- // eslint-disable-next-line no-useless-catch
172
- try {
173
- const res = yield (0, axios_1.default)(Object.assign(Object.assign({ method: 'get', url, headers: {
174
- DNT: 1,
175
- 'Upgrade-Insecure-Requests': 1,
176
- } }, optionsOverride), { responseType: 'arraybuffer' }));
177
- return [Buffer.from(res.data, 'binary'), res.headers];
178
- }
179
- catch (error) {
180
- throw error;
181
- }
182
- });
183
- exports.getBufferFromUrl = getBufferFromUrl;
184
- /**
185
- * @internal
186
- * A convinience method to download the [[DataURL]] of a file
187
- * @param url The url
188
- * @param optionsOverride You can use this to override the [axios request config](https://github.com/axios/axios#request-config)
189
- */
190
- const getDUrl = (url, optionsOverride = {}) => __awaiter(void 0, void 0, void 0, function* () {
191
- // eslint-disable-next-line no-useless-catch
192
- try {
193
- const [buff, headers] = yield (0, exports.getBufferFromUrl)(url, optionsOverride);
194
- const dUrl = `data:${headers['content-type']};base64,${buff.toString('base64')}`;
195
- return dUrl;
196
- }
197
- catch (error) {
198
- throw error;
199
- }
200
- });
201
- exports.getDUrl = getDUrl;
202
- /**
203
- * @internal
204
- * Use this to extract the mime type from a [[DataURL]]
205
- */
206
- const base64MimeType = (dUrl) => {
207
- let result = null;
208
- if (typeof dUrl !== 'string') {
209
- return result;
210
- }
211
- const mime = dUrl.match(/data:([a-zA-Z0-9]+\/[a-zA-Z0-9-.+]+).*,.*/);
212
- if (mime && mime.length) {
213
- result = mime[1];
214
- }
215
- return result;
216
- };
217
- exports.base64MimeType = base64MimeType;
218
- /**
219
- * If process.send is defined, send the message three times
220
- * @param {string} message - The message to send to the parent process.
221
- * @returns Nothing.
222
- */
223
- const processSend = (message) => {
224
- if (process.send) {
225
- process.send(message);
226
- process.send(message);
227
- process.send(message);
228
- }
229
- return;
230
- };
231
- exports.processSend = processSend;
232
- /**
233
- * Return the performance object if it is available, otherwise return the Date object
234
- */
235
- const perf = () => perf_hooks_1.performance || Date;
236
- exports.perf = perf;
237
- /**
238
- * Return the current time in milliseconds
239
- */
240
- const now = () => (0, exports.perf)().now();
241
- exports.now = now;
242
- /**
243
- * `timePromise` returns a promise that resolves to the time it took to run the function passed to it
244
- * @param fn - the function to be timed.
245
- * @returns A string.
246
- */
247
- function timePromise(fn) {
248
- return __awaiter(this, void 0, void 0, function* () {
249
- const start = (0, exports.now)();
250
- yield fn();
251
- return ((0, exports.now)() - start).toFixed(0);
252
- });
253
- }
254
- exports.timePromise = timePromise;
255
- /**
256
- * It sends a message to the parent process.
257
- * @param {any} data - The data to be sent to the parent process.
258
- * @returns Nothing.
259
- */
260
- const processSendData = (data = {}) => {
261
- const sd = () => process.send({
262
- type: 'process:msg',
263
- data
264
- }, (error) => {
265
- if (error) {
266
- console.error(error);
267
- }
268
- });
269
- return sd();
270
- // return await new Promise((resolve, reject)=>{
271
- // sd(resolve,reject)
272
- // })
273
- };
274
- exports.processSendData = processSendData;
275
- /**
276
- * It generates a link to the GitHub issue template for the current session
277
- * @param {ConfigObject} config - the config object
278
- * @param {SessionInfo} sessionInfo - The sessionInfo object from the CLI
279
- * @param {any} extras - any
280
- * @returns A link to the issue tracker for the current session.
281
- */
282
- const generateGHIssueLink = (config, sessionInfo, extras = {}) => {
283
- const npm_ver = (0, child_process_1.execSync)('npm -v');
284
- const labels = [];
285
- if (sessionInfo.CLI)
286
- labels.push('CLI');
287
- if (!sessionInfo.LATEST_VERSION)
288
- labels.push('NCV');
289
- labels.push(config.multiDevice ? 'MD' : 'Legacy');
290
- if (sessionInfo.ACC_TYPE === 'BUSINESS')
291
- labels.push('BHA');
292
- if (sessionInfo.ACC_TYPE === 'PERSONAL')
293
- labels.push('PHA');
294
- const qp = Object.assign({ "template": "bug_report.yaml",
295
- //@ts-ignore
296
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
297
- "d_info": `${encodeURI(JSON.stringify(((_a) => {
298
- var { OS, purged, PAGE_UA, OW_KEY, NUM, NUM_HASH } = _a, o = __rest(_a, ["OS", "purged", "PAGE_UA", "OW_KEY", "NUM", "NUM_HASH"]);
299
- return o;
300
- })(sessionInfo), null, 2))}`, "enviro": `${`-%20OS:%20${encodeURI(sessionInfo.OS)}%0A-%20Node:%20${encodeURI(process.versions.node)}%0A-%20npm:%20${(String(npm_ver)).replace(/\s/g, '')}`}`, "labels": labels.join(',') }, extras);
301
- return `https://github.com/open-wa/wa-automate-nodejs/issues/new?${Object.keys(qp).map(k => `${k}=${qp[k]}`).join('&')}`;
302
- };
303
- exports.generateGHIssueLink = generateGHIssueLink;
304
- /**
305
- * If the file is a DataURL, return it. If it's a file, convert it to a DataURL. If it's a URL,
306
- * download it and convert it to a DataURL. If Base64, returns it.
307
- * @param {string} file - The file to be converted to a DataURL.
308
- * @param {AxiosRequestConfig} requestConfig - AxiosRequestConfig = {}
309
- * @param {string} filename - Filename with an extension so a datauri mimetype can be inferred.
310
- * @returns A DataURL
311
- */
312
- const ensureDUrl = (file, requestConfig = {}, filename) => __awaiter(void 0, void 0, void 0, function* () {
313
- if (Buffer.isBuffer(file)) {
314
- if (!filename) {
315
- const { ext } = yield (yield ft()).fileTypeFromBuffer(file);
316
- filename = `file.${ext}`;
317
- }
318
- return `data:${mime_1.default.getType(filename)};base64,${file.toString('base64').split(',')[1]}`;
319
- }
320
- else if (!(0, exports.isDataURL)(file) && !(0, exports.isBase64)(file)) {
321
- //must be a file then
322
- const relativePath = path.join(path.resolve(process.cwd(), file || ''));
323
- if (fs.existsSync(file) || fs.existsSync(relativePath)) {
324
- file = yield (0, datauri_1.default)(fs.existsSync(file) ? file : relativePath);
325
- }
326
- else if ((0, is_url_superb_1.default)(file)) {
327
- file = yield (0, exports.getDUrl)(file, requestConfig);
328
- }
329
- else
330
- 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');
331
- }
332
- if (!filename) {
333
- const { ext } = yield (yield ft()).fileTypeFromBuffer(Buffer.from(file.split(',')[1], 'base64'));
334
- filename = `file.${ext}`;
335
- }
336
- if (file.includes("data:") && file.includes("undefined") || file.includes("application/octet-stream") && filename && mime_1.default.getType(filename)) {
337
- file = `data:${mime_1.default.getType(filename)};base64,${file.split(',')[1]}`;
338
- }
339
- return file;
340
- });
341
- exports.ensureDUrl = ensureDUrl;
342
- exports.FileInputTypes = {
343
- "VALIDATED_FILE_PATH": "VALIDATED_FILE_PATH",
344
- "URL": "URL",
345
- "DATA_URL": "DATA_URL",
346
- "BASE_64": "BASE_64",
347
- "BUFFER": "BUFFER",
348
- "READ_STREAM": "READ_STREAM",
349
- };
350
- exports.FileOutputTypes = Object.assign(Object.assign({}, exports.FileInputTypes), { "TEMP_FILE_PATH": "TEMP_FILE_PATH" });
351
- /**
352
- * Remove file asynchronously
353
- * @param file Filepath
354
- * @returns
355
- */
356
- function rmFileAsync(file) {
357
- return new Promise((resolve, reject) => {
358
- fs.unlink(file, (err) => {
359
- if (err) {
360
- reject(err);
361
- }
362
- else {
363
- resolve(true);
364
- }
365
- });
366
- });
367
- }
368
- exports.rmFileAsync = rmFileAsync;
369
- /**
370
- * Takes a file parameter and consistently returns the desired type of file.
371
- * @param file The file path, URL, base64 or DataURL string of the file
372
- * @param outfileName The ouput filename of the file
373
- * @param desiredOutputType The type of file output required from this function
374
- * @param requestConfig optional axios config if file parameter is a url
375
- */
376
- const assertFile = (file, outfileName, desiredOutputType, requestConfig) => __awaiter(void 0, void 0, void 0, function* () {
377
- let inputType;
378
- outfileName = (0, exports.sanitizeAccentedChars)(outfileName);
379
- if (typeof file == 'string') {
380
- if ((0, exports.isDataURL)(file))
381
- inputType = exports.FileInputTypes.DATA_URL;
382
- else if ((0, exports.isBase64)(file))
383
- inputType = exports.FileInputTypes.BASE_64;
384
- /**
385
- * Check if it is a path
386
- */
387
- else {
388
- const relativePath = path.join(path.resolve(process.cwd(), file || ''));
389
- if (fs.existsSync(file) || fs.existsSync(relativePath)) {
390
- // file = await datauri(fs.existsSync(file) ? file : relativePath);
391
- inputType = exports.FileInputTypes.VALIDATED_FILE_PATH;
392
- }
393
- else if ((0, is_url_superb_1.default)(file))
394
- inputType = exports.FileInputTypes.URL;
395
- /**
396
- * If not file type is determined by now then it is some sort of unidentifiable string. Throw an error.
397
- */
398
- if (!inputType)
399
- 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: ${file.slice(0, 25)}`);
400
- }
401
- }
402
- else {
403
- if (Buffer.isBuffer(file))
404
- inputType = exports.FileInputTypes.BUFFER;
405
- /**
406
- * Leave space to determine if incoming file parameter is any other type of object (maybe one day people will submit a path object as a param?)
407
- */
408
- }
409
- if (inputType === desiredOutputType)
410
- return file;
411
- switch (desiredOutputType) {
412
- case exports.FileOutputTypes.DATA_URL:
413
- case exports.FileOutputTypes.BASE_64:
414
- return yield (0, exports.ensureDUrl)(file, requestConfig, outfileName);
415
- break;
416
- case exports.FileOutputTypes.TEMP_FILE_PATH: {
417
- /**
418
- * Create a temp file in tempdir, return the tempfile.
419
- */
420
- let tfn = `${crypto_1.default.randomBytes(6).readUIntLE(0, 6).toString(36)}.${outfileName}`;
421
- if (inputType != exports.FileInputTypes.BUFFER) {
422
- file = yield (0, exports.ensureDUrl)(file, requestConfig, outfileName);
423
- const ext = mime_1.default.getExtension(file.match(/[^:]\w+\/[\w-+\d.]+(?=;|,)/)[0]);
424
- if (ext && !IGNORE_FILE_EXTS.includes(ext) && !tfn.endsWith(ext))
425
- tfn = `${tfn}.${ext}`;
426
- file = Buffer.from(file.split(',')[1], 'base64');
427
- }
428
- const tempFilePath = path.join((0, os_2.tmpdir)(), tfn);
429
- yield fs.writeFileSync(tempFilePath, file);
430
- logging_1.log.info(`Saved temporary file to ${tempFilePath}`);
431
- return tempFilePath;
432
- break;
433
- }
434
- case exports.FileOutputTypes.BUFFER:
435
- return Buffer.from((yield (0, exports.ensureDUrl)(file, requestConfig, outfileName)).split(',')[1], 'base64');
436
- break;
437
- case exports.FileOutputTypes.READ_STREAM: {
438
- if (inputType === exports.FileInputTypes.VALIDATED_FILE_PATH)
439
- return fs.createReadStream(file);
440
- else if (inputType != exports.FileInputTypes.BUFFER)
441
- file = Buffer.from((yield (0, exports.ensureDUrl)(file, requestConfig, outfileName)).split(',')[1], 'base64');
442
- return stream_1.Readable.from(file);
443
- break;
444
- }
445
- }
446
- return file;
447
- });
448
- exports.assertFile = assertFile;
449
- /**
450
- * Checks if a given path exists.
451
- *
452
- * If exists, returns the resolved absolute path. Otherwise returns false.
453
- *
454
- * @param _path a relative, absolute or homedir path to a folder or a file
455
- * @param failSilent If you're expecting for the file to not exist and just want the `false` response then set this to true to prevent false-positive error messages in the logs.
456
- * @returns string | false
457
- */
458
- const pathExists = (_path, failSilent) => __awaiter(void 0, void 0, void 0, function* () {
459
- _path = (0, exports.fixPath)(_path);
460
- try {
461
- yield fsp.access(_path, fsconstants.R_OK | fsconstants.W_OK);
462
- return _path;
463
- }
464
- catch (error) {
465
- if (!failSilent)
466
- logging_1.log.error('Given check path threw an error', error);
467
- return false;
468
- }
469
- });
470
- exports.pathExists = pathExists;
471
- /**
472
- * Returns an absolute file path reference
473
- * @param _path a relative, absolute or homedir path to a folder or a file
474
- * @returns string
475
- */
476
- const fixPath = (_path) => {
477
- _path = _path.replace("~", (0, os_1.homedir)());
478
- _path = _path.includes('./') ? path.join(process.cwd(), _path) : _path;
479
- return _path;
480
- };
481
- exports.fixPath = fixPath;
482
- /**
483
- *
484
- * Accented filenames break file sending in docker containers. This is used to replace accented chars in strings to prevent file sending failures.
485
- *
486
- * @param input The raw string
487
- * @returns A sanitized string with all accented chars removed
488
- */
489
- const sanitizeAccentedChars = (input) => {
490
- return input
491
- .normalize('NFD')
492
- .replace(/[\u0300-\u036f]/g, '');
493
- };
494
- exports.sanitizeAccentedChars = sanitizeAccentedChars;
package/tos.md DELETED
@@ -1,77 +0,0 @@
1
- # open-wa Project Terms of Service (ToS.md)
2
-
3
- ## 1. Acceptance of Terms
4
-
5
- By accessing, using, contemplating, or in any way interacting with the open-wa project, its websites, repositories, or any adjacent or non-adjacent internet properties, you, the user, visitor, or contemplator, hereby agree to these Terms of Service (ToS), both in their current form and as they may be amended, modified, expanded, or shrunk in the future, with or without notice.
6
-
7
- ## 2. Definitions:
8
-
9
- 'User': Any individual or entity that interacts with the open-wa project in any capacity.
10
-
11
- 'Project': The open-wa project and any of its associated or non-associated services, features, or components.
12
-
13
- 'Maintainers': Individuals, both associated and non-associated, contributing to or overseeing the open-wa project, on GitHub or elsewhere.
14
-
15
- ## 3. Limitation of Liability:
16
-
17
- **3.1** The Project and its Maintainers shall not be liable for any actions, claims, damages, or any consequences arising from the use of the Project by Users.
18
-
19
- ## 4. Usage According to License:
20
-
21
- **4.1** Users of the Project agree to use it strictly in accordance with its license. Failure to do so will result in penalties akin to those outlined in the anti-spam document, including but not limited to financial remuneration and existential cessation.
22
-
23
- ## 5. Indemnification:
24
-
25
- **5.1** By accessing or reading this ToS, or any material related to the open-wa project, Users completely indemnify the Project and its Maintainers from any previous agreements, obligations, or understandings.
26
-
27
- ## 6. Disclaimer of Affiliation:
28
-
29
- **6.1** The open-wa Project is not affiliated with WhatsApp, Meta, or any other company, it is community project owned by no one person, although may be guided by temporary stewardships.
30
-
31
- ## 7. Support for Causes:
32
-
33
- **7.1** By using the Project, Users explicitly express their support for the liberation of Palestine, from the river to the sea.
34
-
35
- ## 8. Continuation of Agreement:
36
-
37
- **8.1** Continuation of existence as a sentient being, human or otherwise, is considered as acceptance of these ToS. Ceasing to exist is the only method to rescind this agreement.
38
-
39
-
40
- ## 9. Universality of Terms:
41
-
42
- **9.1** These ToS are binding legally, morally, universally, spiritually, religiously, and in all other conceivable manners, until the heat death of the universe.
43
-
44
- ## 10. Modification of Terms:
45
-
46
- **10.1** The Project and its Maintainers reserve the right to modify these ToS at any time, with or without notice.
47
-
48
- ## 11. Severability:
49
-
50
- **11.1** If any part of these ToS is found to be invalid or unenforceable, the remaining parts will continue to be in full effect.
51
-
52
- ## 12. Agreement to Contact Terms:
53
-
54
- **12.1** Contacting info@openwa.dev to rescind acceptance constitutes an agreement to these ToS.
55
-
56
- ## 13. Governing Law and Jurisdiction:
57
-
58
- **13.1** These ToS are governed by the whims, fancies, and current mood of the Project Maintainers and are subject to the laws of every jurisdiction, dimension, and reality.
59
-
60
- ## 14. Clarification of Project Nomenclature:
61
-
62
- **14.1** For the purpose of clarity and avoidance of any potential misunderstanding, it is hereby explicitly stated and codified within these Terms that the term 'wa' as utilized in the naming convention of the 'open-wa' project is an abbreviation denoting the term 'walrus'. This definition is established irrespective of any possible semantic associations or perceived affiliations with other entities, trademarks, or intellectual properties.
63
-
64
- ## 15. Legal Protections for the Project:
65
-
66
- **15.1** Protection under Van Buren v. United States: Users acknowledge that the Project is protected against any claims under the Computer Fraud and Abuse Act (CFAA), as interpreted by the United States Supreme Court in Van Buren v. United States. This ruling clarifies the extent of authorized access, and as such, the Project's actions and operations fall within the scope of permissible use under this interpretation.
67
-
68
- **15.2** Directive 2009/24/EC of the European Parliament and of the Council: In compliance with Directive 2009/24/EC, the Project asserts its right to engage in the lawful use of computer programs necessary for its functionality, including any actions deemed necessary for correcting errors.
69
-
70
- **15.3** EU Digital Markets Act Compliance: Given the designation of WhatsApp as a 'gatekeeper' under the EU Digital Markets Act, the Project operates under the regulations and stipulations set forth in this act, particularly concerning digital services and their interoperability within the EU market.
71
-
72
- **15.4** Digital Right of Interoperability and Deshittification: The Project asserts its digital right to interoperability, both adversarial and cooperative, under the principles of digital freedom and improvement of digital services ('deshittification'). This assertion is in line with the growing recognition of interoperability as a fundamental digital right, facilitating better user experiences and fostering competitive digital environments.
73
-
74
- ___
75
-
76
- By continuing to access, use, contemplate, or exist in the same universe as the open-wa project, you hereby acknowledge and agree to these Terms of Service.
77
-