@neelegirl/baileys 2.0.2 → 2.0.3

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.
@@ -0,0 +1,3 @@
1
+ yarn pbjs -t static-module --no-beautify -w es6 --no-bundle --no-delimited --no-verify --no-comments -o ./index.js ./WAProto.proto;
2
+ yarn pbjs -t static-module --no-beautify -w es6 --no-bundle --no-delimited --no-verify ./WAProto.proto | yarn pbts --no-comments -o ./index.d.ts -;
3
+ node ./fix-imports.js
@@ -0,0 +1,81 @@
1
+ import { readFileSync, writeFileSync } from 'fs';
2
+ import { exit } from 'process';
3
+
4
+ const filePath = './index.js'
5
+
6
+ try {
7
+ let content = readFileSync(filePath, 'utf8')
8
+
9
+ content = content.replace(/import \* as (\$protobuf) from/g, 'import $1 from')
10
+ content = content.replace(/(['"])protobufjs\/minimal(['"])/g, '$1protobufjs/minimal.js$2')
11
+
12
+ const marker = 'const $root = $protobuf.roots["default"] || ($protobuf.roots["default"] = {});\n\n'
13
+ const longToStringHelper =
14
+ 'function longToString(value, unsigned) {\n' +
15
+ '\tif (typeof value === "string") {\n' +
16
+ '\t\treturn value;\n' +
17
+ '\t}\n' +
18
+ '\tif (typeof value === "number") {\n' +
19
+ '\t\treturn String(value);\n' +
20
+ '\t}\n' +
21
+ '\tif (!$util.Long) {\n' +
22
+ '\t\treturn String(value);\n' +
23
+ '\t}\n' +
24
+ '\tconst normalized = $util.Long.fromValue(value);\n' +
25
+ '\tconst prepared = unsigned && normalized && typeof normalized.toUnsigned === "function"\n' +
26
+ '\t\t? normalized.toUnsigned()\n' +
27
+ '\t\t: normalized;\n' +
28
+ '\treturn prepared.toString();\n' +
29
+ '}\n\n'
30
+ const longToNumberHelper =
31
+ 'function longToNumber(value, unsigned) {\n' +
32
+ '\tif (typeof value === "number") {\n' +
33
+ '\t\treturn value;\n' +
34
+ '\t}\n' +
35
+ '\tif (typeof value === "string") {\n' +
36
+ '\t\tconst numeric = Number(value);\n' +
37
+ '\t\treturn numeric;\n' +
38
+ '\t}\n' +
39
+ '\tif (!$util.Long) {\n' +
40
+ '\t\treturn Number(value);\n' +
41
+ '\t}\n' +
42
+ '\tconst normalized = $util.Long.fromValue(value);\n' +
43
+ '\tconst prepared = unsigned && normalized && typeof normalized.toUnsigned === "function"\n' +
44
+ '\t\t? normalized.toUnsigned()\n' +
45
+ '\t\t: typeof normalized.toSigned === "function"\n' +
46
+ '\t\t\t? normalized.toSigned()\n' +
47
+ '\t\t\t: normalized;\n' +
48
+ '\treturn prepared.toNumber();\n' +
49
+ '}\n\n'
50
+
51
+ if (!content.includes('function longToString(')) {
52
+ const markerIndex = content.indexOf(marker)
53
+ if (markerIndex === -1) {
54
+ throw new Error('Unable to inject Long helpers: marker not found in WAProto index output')
55
+ }
56
+
57
+ content = content.replace(marker, `${marker}${longToStringHelper}${longToNumberHelper}`)
58
+ } else {
59
+ const longToStringRegex = /function longToString\(value, unsigned\) {\n[\s\S]*?\n}\n\n/
60
+ const longToNumberRegex = /function longToNumber\(value, unsigned\) {\n[\s\S]*?\n}\n\n/
61
+
62
+ if (!longToStringRegex.test(content) || !longToNumberRegex.test(content)) {
63
+ throw new Error('Unable to update Long helpers: existing definitions not found')
64
+ }
65
+
66
+ content = content.replace(longToStringRegex, longToStringHelper)
67
+ content = content.replace(longToNumberRegex, longToNumberHelper)
68
+ }
69
+
70
+ const longPattern = /([ \t]+d\.(\w+) = )o\.longs === String \? \$util\.Long\.prototype\.toString\.call\(m\.\2\) : o\.longs === Number \? new \$util\.LongBits\(m\.\2\.low >>> 0, m\.\2\.high >>> 0\)\.toNumber\((true)?\) : m\.\2;/g
71
+ content = content.replace(longPattern, (_match, prefix, field, unsignedFlag) => {
72
+ const unsignedArg = unsignedFlag ? ', true' : ''
73
+ return `${prefix}o.longs === String ? longToString(m.${field}${unsignedArg}) : o.longs === Number ? longToNumber(m.${field}${unsignedArg}) : m.${field};`
74
+ })
75
+
76
+ writeFileSync(filePath, content, 'utf8')
77
+ console.log(`✅ Fixed imports in ${filePath}`)
78
+ } catch (error) {
79
+ console.error(`❌ Error fixing imports: ${error.message}`)
80
+ exit(1)
81
+ }
@@ -208,7 +208,7 @@ const uploadingNecessaryImages = async (images, waUploadToServer, timeoutMs = 30
208
208
  }
209
209
  const { stream } = await messages_media_1.getStream(img)
210
210
  const hasher = crypto_1.createHash('sha256')
211
- const filePath = path_1.join(os_1.tmpdir(), 'img' + generics_1.generateMessageID())
211
+ const filePath = path_1.join(process.cwd(), 'tmp', 'img' + generics_1.generateMessageID())
212
212
  const encFileWriteStream = fs_1.createWriteStream(filePath)
213
213
  for await (const block of stream) {
214
214
  hasher.update(block)
@@ -348,7 +348,7 @@ const prepareStream = async (media, mediaType, { logger, saveOriginalFileIfRequi
348
348
  const { stream, type } = await getStream(media, opts)
349
349
  logger?.debug('fetched media stream')
350
350
 
351
- const encFilePath = path_1.join(os_1.tmpdir(), mediaType + generics_1.generateMessageID() + '-plain')
351
+ const encFilePath = path_1.join(process.cwd(), 'tmp', mediaType + generics_1.generateMessageID() + '-plain')
352
352
  const encFileWriteStream = fs_1.createWriteStream(encFilePath)
353
353
 
354
354
  let originalFilePath
@@ -357,7 +357,7 @@ const prepareStream = async (media, mediaType, { logger, saveOriginalFileIfRequi
357
357
  if (type === 'file') {
358
358
  originalFilePath = media.url.toString()
359
359
  } else if (saveOriginalFileIfRequired) {
360
- originalFilePath = path_1.join(os_1.tmpdir(), mediaType + generics_1.generateMessageID() + '-original')
360
+ originalFilePath = path_1.join(process.cwd(), 'tmp', mediaType + generics_1.generateMessageID() + '-original')
361
361
  originalFileStream = fs_1.createWriteStream(originalFilePath)
362
362
  }
363
363
 
@@ -423,12 +423,12 @@ const encryptedStream = async (media, mediaType, { logger, saveOriginalFileIfReq
423
423
  logger?.debug('fetched media stream')
424
424
  const mediaKey = Crypto.randomBytes(32)
425
425
  const { cipherKey, iv, macKey } = await getMediaKeys(mediaKey, mediaType)
426
- const encFilePath = path_1.join(os_1.tmpdir(), mediaType + generics_1.generateMessageID() + '-enc')
426
+ const encFilePath = path_1.join(process.cwd(), 'tmp', mediaType + generics_1.generateMessageID() + '-enc')
427
427
  const encFileWriteStream = fs_1.createWriteStream(encFilePath)
428
428
  let originalFileStream
429
429
  let originalFilePath
430
430
  if (saveOriginalFileIfRequired) {
431
- originalFilePath = path_1.join(os_1.tmpdir(), mediaType + generics_1.generateMessageID() + '-original')
431
+ originalFilePath = path_1.join(process.cwd(), 'tmp', mediaType + generics_1.generateMessageID() + '-original')
432
432
  originalFileStream = fs_1.createWriteStream(originalFilePath)
433
433
  }
434
434
  let fileLength = 0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neelegirl/baileys",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "description": "WhatsApp API for wa-api, a multi-device WhatsApp Web API client",
5
5
  "keywords": [
6
6
  "whatsapp",