@badzz88/baileys 8.5.4 → 8.5.6
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 +2 -2
- package/WAProto/fix-imports.js +69 -79
- package/WAProto/index.d.ts +15305 -87935
- package/WAProto/index.js +41109 -194076
- package/engine-requirements.js +15 -8
- package/package.json +23 -19
- package/src/Defaults/index.js +186 -0
- package/src/Signal/Group/ciphertext-message.js +15 -0
- package/src/Signal/Group/group-session-builder.js +86 -0
- package/src/Signal/Group/group_cipher.js +82 -0
- package/src/Signal/Group/index.js +140 -0
- package/src/Signal/Group/keyhelper.js +77 -0
- package/src/Signal/Group/sender-chain-key.js +29 -0
- package/src/Signal/Group/sender-key-distribution-message.js +66 -0
- package/src/Signal/Group/sender-key-message.js +69 -0
- package/src/Signal/Group/sender-key-name.js +51 -0
- package/src/Signal/Group/sender-key-record.js +44 -0
- package/src/Signal/Group/sender-key-state.js +87 -0
- package/src/Signal/Group/sender-message-key.js +29 -0
- package/src/Signal/libsignal.js +455 -0
- package/src/Signal/lid-mapping.js +273 -0
- package/src/Socket/Client/index.js +31 -0
- package/src/Socket/Client/types.js +13 -0
- package/src/Socket/Client/websocket.js +61 -0
- package/src/Socket/aigroups.js +221 -0
- package/src/Socket/business.js +411 -0
- package/src/Socket/chats.js +1449 -0
- package/src/Socket/communities.js +463 -0
- package/src/Socket/graphql.js +523 -0
- package/src/Socket/groups.js +516 -0
- package/src/Socket/index.js +31 -0
- package/src/Socket/interactive-handler.js +527 -0
- package/src/Socket/interop.js +339 -0
- package/src/Socket/luxu.js +349 -0
- package/src/Socket/managed-account.js +98 -0
- package/src/Socket/messages-recv.js +2685 -0
- package/src/Socket/messages-send.js +2047 -0
- package/src/Socket/mex.js +57 -0
- package/src/Socket/newsletter.js +455 -0
- package/src/Socket/privacy.js +125 -0
- package/src/Socket/registration.js +236 -0
- package/src/Socket/socket.js +983 -0
- package/src/Socket/text-router.js +65 -0
- package/src/Socket/username.js +130 -0
- package/src/Store/index.js +33 -0
- package/src/Store/keyed-db.js +118 -0
- package/src/Store/make-cache-manager-store.js +84 -0
- package/src/Store/make-in-memory-store.js +551 -0
- package/src/Store/make-ordered-dictionary.js +81 -0
- package/src/Store/object-repository.js +26 -0
- package/src/Types/Auth.js +31 -0
- package/src/Types/Bussines.js +2 -0
- package/src/Types/Call.js +2 -0
- package/src/Types/Chat.js +4 -0
- package/src/Types/Contact.js +2 -0
- package/src/Types/Events.js +2 -0
- package/src/Types/GroupMetadata.js +2 -0
- package/src/Types/Label.js +26 -0
- package/src/Types/LabelAssociation.js +8 -0
- package/src/Types/Message.js +93 -0
- package/src/Types/Mex.js +112 -0
- package/src/Types/Newsletter.js +109 -0
- package/src/Types/Product.js +2 -0
- package/src/Types/Signal.js +2 -0
- package/src/Types/Socket.js +2 -0
- package/src/Types/State.js +62 -0
- package/src/Types/USync.js +2 -0
- package/src/Types/index.js +56 -0
- package/src/Utils/auth-utils.js +254 -0
- package/src/Utils/browser-utils.js +112 -0
- package/src/Utils/business.js +240 -0
- package/src/Utils/chat-utils.js +1230 -0
- package/src/Utils/command-loader.d.ts +27 -0
- package/src/Utils/command-loader.js +89 -0
- package/src/Utils/companion-reg-client-utils.js +40 -0
- package/src/Utils/consumer-application.js +105 -0
- package/src/Utils/crypto.js +118 -0
- package/src/Utils/curve25519-js.js +242 -0
- package/src/Utils/decode-wa-message.js +529 -0
- package/src/Utils/event-buffer.js +580 -0
- package/src/Utils/generics.js +483 -0
- package/src/Utils/group-history.js +44 -0
- package/src/Utils/history.js +232 -0
- package/src/Utils/identity-change-handler.js +52 -0
- package/src/Utils/index.js +58 -0
- package/src/Utils/jid-display-normalization.js +195 -0
- package/src/Utils/link-preview.js +135 -0
- package/src/Utils/logger.js +8 -0
- package/src/Utils/lt-hash.js +25 -0
- package/src/Utils/make-mutex.js +36 -0
- package/src/Utils/message-composer.js +471 -0
- package/src/Utils/message-retry-manager.js +217 -0
- package/src/Utils/messages-media.js +843 -0
- package/src/Utils/messages.js +2817 -0
- package/src/Utils/meta-ai-msmsg.js +222 -0
- package/src/Utils/native-bridge.js +68 -0
- package/src/Utils/noise-handler.js +169 -0
- package/src/Utils/offline-node-processor.js +34 -0
- package/src/Utils/pre-key-manager.js +90 -0
- package/src/Utils/process-message.js +950 -0
- package/src/Utils/reporting-utils.js +261 -0
- package/src/Utils/session-pool.d.ts +14 -0
- package/src/Utils/session-pool.js +70 -0
- package/src/Utils/signal.js +217 -0
- package/src/Utils/stanza-ack.js +30 -0
- package/src/Utils/sticker.d.ts +13 -0
- package/src/Utils/sticker.js +123 -0
- package/src/Utils/sync-action-utils.js +45 -0
- package/src/Utils/tc-token-utils.js +158 -0
- package/src/Utils/use-multi-file-auth-state.js +111 -0
- package/src/Utils/validate-connection.js +209 -0
- package/src/Utils/view-once-cache.d.ts +12 -0
- package/src/Utils/view-once-cache.js +63 -0
- package/src/Utils/voip-rekey.js +22 -0
- package/src/WABinary/constants.js +1304 -0
- package/src/WABinary/decode.js +342 -0
- package/src/WABinary/encode.js +225 -0
- package/src/WABinary/generic-utils.js +238 -0
- package/src/WABinary/index.js +34 -0
- package/src/WABinary/jid-utils.js +351 -0
- package/src/WABinary/types.js +2 -0
- package/src/WAM/BinaryInfo.js +13 -0
- package/src/WAM/constants.js +39484 -0
- package/src/WAM/encode.js +149 -0
- package/src/WAM/index.js +32 -0
- package/src/WAUSync/Protocols/USyncBotProfileProtocol.js +53 -0
- package/src/WAUSync/Protocols/USyncBusinessProtocol.js +44 -0
- package/src/WAUSync/Protocols/USyncContactProtocol.js +55 -0
- package/src/WAUSync/Protocols/USyncDeviceProtocol.js +55 -0
- package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.js +31 -0
- package/src/WAUSync/Protocols/USyncFeatureProtocol.js +54 -0
- package/src/WAUSync/Protocols/USyncLIDProtocol.js +32 -0
- package/src/WAUSync/Protocols/USyncNewsletterProtocol.js +473 -0
- package/src/WAUSync/Protocols/USyncPictureProtocol.js +34 -0
- package/src/WAUSync/Protocols/USyncSidelistProtocol.js +29 -0
- package/src/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
- package/src/WAUSync/Protocols/USyncTextStatusProtocol.js +38 -0
- package/src/WAUSync/Protocols/USyncUsernameProtocol.js +28 -0
- package/src/WAUSync/Protocols/index.js +40 -0
- package/src/WAUSync/USyncQuery.js +126 -0
- package/src/WAUSync/USyncUser.js +50 -0
- package/src/WAUSync/index.js +32 -0
- package/src/antiban.js +4152 -0
- package/{lib → src}/index.js +51 -49
- package/lib/Defaults/index.js +0 -195
- package/lib/Signal/Group/ciphertext-message.js +0 -15
- package/lib/Signal/Group/group-session-builder.js +0 -92
- package/lib/Signal/Group/group_cipher.js +0 -89
- package/lib/Signal/Group/index.js +0 -136
- package/lib/Signal/Group/keyhelper.js +0 -73
- package/lib/Signal/Group/sender-chain-key.js +0 -32
- package/lib/Signal/Group/sender-key-distribution-message.js +0 -66
- package/lib/Signal/Group/sender-key-message.js +0 -69
- package/lib/Signal/Group/sender-key-name.js +0 -50
- package/lib/Signal/Group/sender-key-record.js +0 -44
- package/lib/Signal/Group/sender-key-state.js +0 -97
- package/lib/Signal/Group/sender-message-key.js +0 -30
- package/lib/Signal/libsignal.js +0 -470
- package/lib/Signal/lid-mapping.js +0 -280
- package/lib/Socket/Client/index.js +0 -30
- package/lib/Socket/Client/types.js +0 -13
- package/lib/Socket/Client/websocket.js +0 -62
- package/lib/Socket/aigroups.js +0 -240
- package/lib/Socket/business.js +0 -414
- package/lib/Socket/chats.js +0 -2165
- package/lib/Socket/communities.js +0 -545
- package/lib/Socket/graphql.js +0 -863
- package/lib/Socket/groups.js +0 -685
- package/lib/Socket/index.js +0 -41
- package/lib/Socket/interactive-handler.js +0 -579
- package/lib/Socket/interop.js +0 -430
- package/lib/Socket/managed-account.js +0 -214
- package/lib/Socket/messages-recv.js +0 -3000
- package/lib/Socket/messages-send.js +0 -2155
- package/lib/Socket/mex.js +0 -47
- package/lib/Socket/newsletter.js +0 -814
- package/lib/Socket/privacy.js +0 -261
- package/lib/Socket/registration.js +0 -434
- package/lib/Socket/socket.js +0 -1074
- package/lib/Socket/username.js +0 -160
- package/lib/Store/index.js +0 -36
- package/lib/Store/make-cache-manager-store.js +0 -90
- package/lib/Store/make-in-memory-store.js +0 -488
- package/lib/Store/make-ordered-dictionary.js +0 -81
- package/lib/Store/object-repository.js +0 -29
- package/lib/Types/Auth.js +0 -38
- package/lib/Types/Bussines.js +0 -2
- package/lib/Types/Call.js +0 -2
- package/lib/Types/Chat.js +0 -4
- package/lib/Types/Contact.js +0 -2
- package/lib/Types/Events.js +0 -2
- package/lib/Types/GroupMetadata.js +0 -2
- package/lib/Types/Label.js +0 -27
- package/lib/Types/LabelAssociation.js +0 -9
- package/lib/Types/Message.js +0 -95
- package/lib/Types/Newsletter.js +0 -152
- package/lib/Types/Product.js +0 -2
- package/lib/Types/Signal.js +0 -2
- package/lib/Types/Socket.js +0 -2
- package/lib/Types/State.js +0 -70
- package/lib/Types/USync.js +0 -2
- package/lib/Types/index.js +0 -55
- package/lib/Utils/auth-utils.js +0 -301
- package/lib/Utils/browser-utils.js +0 -114
- package/lib/Utils/business.js +0 -243
- package/lib/Utils/chat-utils.js +0 -1272
- package/lib/Utils/consumer-application.js +0 -107
- package/lib/Utils/crypto.js +0 -125
- package/lib/Utils/decode-wa-message.js +0 -793
- package/lib/Utils/event-buffer.js +0 -583
- package/lib/Utils/generics.js +0 -617
- package/lib/Utils/group-history.js +0 -51
- package/lib/Utils/history.js +0 -244
- package/lib/Utils/identity-change-handler.js +0 -52
- package/lib/Utils/index.js +0 -53
- package/lib/Utils/jid-display-normalization.js +0 -218
- package/lib/Utils/link-preview.js +0 -138
- package/lib/Utils/logger.js +0 -9
- package/lib/Utils/lt-hash.js +0 -6
- package/lib/Utils/make-mutex.js +0 -36
- package/lib/Utils/message-composer.js +0 -479
- package/lib/Utils/message-inspect.js +0 -393
- package/lib/Utils/message-retry-manager.js +0 -205
- package/lib/Utils/messages-media.js +0 -925
- package/lib/Utils/messages.js +0 -2482
- package/lib/Utils/meta-ai-msmsg.js +0 -122
- package/lib/Utils/noise-handler.js +0 -194
- package/lib/Utils/offline-node-processor.js +0 -37
- package/lib/Utils/pre-key-manager.js +0 -97
- package/lib/Utils/process-message.js +0 -1139
- package/lib/Utils/reporting-utils.js +0 -262
- package/lib/Utils/signal.js +0 -189
- package/lib/Utils/stanza-ack.js +0 -67
- package/lib/Utils/sync-action-utils.js +0 -51
- package/lib/Utils/tc-token-utils.js +0 -156
- package/lib/Utils/use-multi-file-auth-state.js +0 -137
- package/lib/Utils/validate-connection.js +0 -259
- package/lib/Utils/voip-rekey.js +0 -22
- package/lib/WABinary/constants.js +0 -1304
- package/lib/WABinary/decode.js +0 -377
- package/lib/WABinary/encode.js +0 -58
- package/lib/WABinary/generic-utils.js +0 -150
- package/lib/WABinary/index.js +0 -33
- package/lib/WABinary/jid-utils.js +0 -374
- package/lib/WABinary/types.js +0 -2
- package/lib/WAM/BinaryInfo.js +0 -13
- package/lib/WAM/constants.js +0 -39486
- package/lib/WAM/encode.js +0 -142
- package/lib/WAM/index.js +0 -31
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +0 -55
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +0 -100
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +0 -60
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +0 -65
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -27
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +0 -72
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -31
- package/lib/WAUSync/Protocols/USyncNewsletterProtocol.js +0 -865
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +0 -32
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +0 -29
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +0 -44
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +0 -38
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +0 -28
- package/lib/WAUSync/Protocols/index.js +0 -40
- package/lib/WAUSync/USyncBackoff.js +0 -26
- package/lib/WAUSync/USyncQuery.js +0 -204
- package/lib/WAUSync/USyncUser.js +0 -58
- package/lib/WAUSync/index.js +0 -32
- package/lib/antiban.js +0 -4391
- /package/{lib → src}/Defaults/phonenumber-mcc.json +0 -0
package/lib/Utils/auth-utils.js
DELETED
|
@@ -1,301 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
var __importDefault =
|
|
3
|
-
(this && this.__importDefault) ||
|
|
4
|
-
function (mod) {
|
|
5
|
-
return mod && mod.__esModule ? mod : { default: mod }
|
|
6
|
-
}
|
|
7
|
-
Object.defineProperty(exports, '__esModule', { value: true })
|
|
8
|
-
exports.initAuthCreds = exports.addTransactionCapability = void 0
|
|
9
|
-
exports.makeCacheableSignalKeyStore = makeCacheableSignalKeyStore
|
|
10
|
-
const node_cache_1 = __importDefault(require('@cacheable/node-cache'))
|
|
11
|
-
const async_hooks_1 = require('async_hooks')
|
|
12
|
-
const async_mutex_1 = require('async-mutex')
|
|
13
|
-
const crypto_1 = require('crypto')
|
|
14
|
-
const p_queue_1 = __importDefault(require('p-queue'))
|
|
15
|
-
const Defaults_1 = require('../Defaults')
|
|
16
|
-
const crypto_2 = require('./crypto')
|
|
17
|
-
const generics_1 = require('./generics')
|
|
18
|
-
const pre_key_manager_1 = require('./pre-key-manager')
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const sharedTxStorage = new async_hooks_1.AsyncLocalStorage()
|
|
28
|
-
|
|
29
|
-
function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
30
|
-
const cache =
|
|
31
|
-
_cache ||
|
|
32
|
-
new node_cache_1.default({
|
|
33
|
-
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.SIGNAL_STORE,
|
|
34
|
-
useClones: false,
|
|
35
|
-
deleteOnExpire: true
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
const cacheMutex = new async_mutex_1.Mutex()
|
|
39
|
-
function getUniqueId(type, id) {
|
|
40
|
-
return `${type}.${id}`
|
|
41
|
-
}
|
|
42
|
-
return {
|
|
43
|
-
async get(type, ids) {
|
|
44
|
-
return cacheMutex.runExclusive(async () => {
|
|
45
|
-
const data = {}
|
|
46
|
-
const idsToFetch = []
|
|
47
|
-
for (const id of ids) {
|
|
48
|
-
const item = await cache.get(getUniqueId(type, id))
|
|
49
|
-
if (typeof item !== 'undefined') {
|
|
50
|
-
data[id] = item
|
|
51
|
-
} else {
|
|
52
|
-
idsToFetch.push(id)
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
if (idsToFetch.length) {
|
|
56
|
-
logger?.trace({ items: idsToFetch.length }, 'loading from store')
|
|
57
|
-
const fetched = await store.get(type, idsToFetch)
|
|
58
|
-
for (const id of idsToFetch) {
|
|
59
|
-
const item = fetched[id]
|
|
60
|
-
if (item) {
|
|
61
|
-
data[id] = item
|
|
62
|
-
|
|
63
|
-
await cache.set(getUniqueId(type, id), item)
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return data
|
|
68
|
-
})
|
|
69
|
-
},
|
|
70
|
-
async set(data) {
|
|
71
|
-
return cacheMutex.runExclusive(async () => {
|
|
72
|
-
let keys = 0
|
|
73
|
-
for (const type in data) {
|
|
74
|
-
for (const id in data[type]) {
|
|
75
|
-
await cache.set(getUniqueId(type, id), data[type][id])
|
|
76
|
-
keys += 1
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
logger?.trace({ keys }, 'updated cache')
|
|
80
|
-
await store.set(data)
|
|
81
|
-
})
|
|
82
|
-
},
|
|
83
|
-
async clear() {
|
|
84
|
-
await cache.flushAll()
|
|
85
|
-
await store.clear?.()
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetweenTriesMs }) => {
|
|
91
|
-
const txStorage = sharedTxStorage
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const storeToken = Symbol('addTransactionCapability')
|
|
96
|
-
const getOwnStore = () => {
|
|
97
|
-
const ctx = txStorage.getStore()
|
|
98
|
-
return ctx && ctx.token === storeToken ? ctx : undefined
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const keyQueues = new Map()
|
|
102
|
-
|
|
103
|
-
const txMutexes = new Map()
|
|
104
|
-
const txMutexRefCounts = new Map()
|
|
105
|
-
|
|
106
|
-
const preKeyManager = new pre_key_manager_1.PreKeyManager(state, logger)
|
|
107
|
-
|
|
108
|
-
function getQueue(key) {
|
|
109
|
-
if (!keyQueues.has(key)) {
|
|
110
|
-
keyQueues.set(key, new p_queue_1.default({ concurrency: 1 }))
|
|
111
|
-
}
|
|
112
|
-
return keyQueues.get(key)
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function getTxMutex(key) {
|
|
116
|
-
if (!txMutexes.has(key)) {
|
|
117
|
-
txMutexes.set(key, new async_mutex_1.Mutex())
|
|
118
|
-
txMutexRefCounts.set(key, 0)
|
|
119
|
-
}
|
|
120
|
-
return txMutexes.get(key)
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function acquireTxMutexRef(key) {
|
|
124
|
-
const count = txMutexRefCounts.get(key) ?? 0
|
|
125
|
-
txMutexRefCounts.set(key, count + 1)
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function releaseTxMutexRef(key) {
|
|
129
|
-
const count = (txMutexRefCounts.get(key) ?? 1) - 1
|
|
130
|
-
txMutexRefCounts.set(key, count)
|
|
131
|
-
|
|
132
|
-
if (count <= 0) {
|
|
133
|
-
const mutex = txMutexes.get(key)
|
|
134
|
-
if (mutex && !mutex.isLocked()) {
|
|
135
|
-
txMutexes.delete(key)
|
|
136
|
-
txMutexRefCounts.delete(key)
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
function isInTransaction() {
|
|
142
|
-
return !!getOwnStore()
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
async function commitWithRetry(mutations) {
|
|
146
|
-
if (Object.keys(mutations).length === 0) {
|
|
147
|
-
logger.trace('no mutations in transaction')
|
|
148
|
-
return
|
|
149
|
-
}
|
|
150
|
-
logger.trace('committing transaction')
|
|
151
|
-
for (let attempt = 0; attempt < maxCommitRetries; attempt++) {
|
|
152
|
-
try {
|
|
153
|
-
await state.set(mutations)
|
|
154
|
-
logger.trace({ mutationCount: Object.keys(mutations).length }, 'committed transaction')
|
|
155
|
-
return
|
|
156
|
-
} catch (error) {
|
|
157
|
-
const retriesLeft = maxCommitRetries - attempt - 1
|
|
158
|
-
logger.warn(`failed to commit mutations, retries left=${retriesLeft}`)
|
|
159
|
-
if (retriesLeft === 0) {
|
|
160
|
-
throw error
|
|
161
|
-
}
|
|
162
|
-
await (0, generics_1.delay)(delayBetweenTriesMs)
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
return {
|
|
167
|
-
get: async (type, ids) => {
|
|
168
|
-
const ctx = getOwnStore()
|
|
169
|
-
if (!ctx) {
|
|
170
|
-
|
|
171
|
-
return state.get(type, ids)
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
const cached = ctx.cache[type] || {}
|
|
175
|
-
const missing = ids.filter(id => !(id in cached))
|
|
176
|
-
if (missing.length > 0) {
|
|
177
|
-
ctx.dbQueries++
|
|
178
|
-
logger.trace({ type, count: missing.length }, 'fetching missing keys in transaction')
|
|
179
|
-
const fetched = await getTxMutex(type).runExclusive(() => state.get(type, missing))
|
|
180
|
-
|
|
181
|
-
ctx.cache[type] = ctx.cache[type] || {}
|
|
182
|
-
Object.assign(ctx.cache[type], fetched)
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
const result = {}
|
|
186
|
-
for (const id of ids) {
|
|
187
|
-
const value = ctx.cache[type]?.[id]
|
|
188
|
-
if (value !== undefined && value !== null) {
|
|
189
|
-
result[id] = value
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
return result
|
|
193
|
-
},
|
|
194
|
-
set: async data => {
|
|
195
|
-
const ctx = getOwnStore()
|
|
196
|
-
if (!ctx) {
|
|
197
|
-
|
|
198
|
-
const types = Object.keys(data)
|
|
199
|
-
|
|
200
|
-
for (const type_ of types) {
|
|
201
|
-
const type = type_
|
|
202
|
-
if (type === 'pre-key') {
|
|
203
|
-
await preKeyManager.validateDeletions(data, type)
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
await Promise.all(
|
|
208
|
-
types.map(type =>
|
|
209
|
-
getQueue(type).add(async () => {
|
|
210
|
-
const typeData = { [type]: data[type] }
|
|
211
|
-
await state.set(typeData)
|
|
212
|
-
})
|
|
213
|
-
)
|
|
214
|
-
)
|
|
215
|
-
return
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
logger.trace({ types: Object.keys(data) }, 'caching in transaction')
|
|
219
|
-
for (const key_ in data) {
|
|
220
|
-
const key = key_
|
|
221
|
-
|
|
222
|
-
ctx.cache[key] = ctx.cache[key] || {}
|
|
223
|
-
ctx.mutations[key] = ctx.mutations[key] || {}
|
|
224
|
-
|
|
225
|
-
if (key === 'pre-key') {
|
|
226
|
-
await preKeyManager.processOperations(data, key, ctx.cache, ctx.mutations, true)
|
|
227
|
-
} else {
|
|
228
|
-
|
|
229
|
-
Object.assign(ctx.cache[key], data[key])
|
|
230
|
-
Object.assign(ctx.mutations[key], data[key])
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
},
|
|
234
|
-
isInTransaction,
|
|
235
|
-
transaction: async (work, key) => {
|
|
236
|
-
const existing = getOwnStore()
|
|
237
|
-
|
|
238
|
-
if (existing) {
|
|
239
|
-
logger.trace('reusing existing transaction context')
|
|
240
|
-
return work()
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
const mutex = getTxMutex(key)
|
|
244
|
-
acquireTxMutexRef(key)
|
|
245
|
-
try {
|
|
246
|
-
return await mutex.runExclusive(async () => {
|
|
247
|
-
const ctx = {
|
|
248
|
-
token: storeToken,
|
|
249
|
-
cache: {},
|
|
250
|
-
mutations: {},
|
|
251
|
-
dbQueries: 0
|
|
252
|
-
}
|
|
253
|
-
logger.trace('entering transaction')
|
|
254
|
-
try {
|
|
255
|
-
const result = await txStorage.run(ctx, work)
|
|
256
|
-
|
|
257
|
-
await commitWithRetry(ctx.mutations)
|
|
258
|
-
logger.trace({ dbQueries: ctx.dbQueries }, 'transaction completed')
|
|
259
|
-
return result
|
|
260
|
-
} catch (error) {
|
|
261
|
-
logger.error({ error }, 'transaction failed, rolling back')
|
|
262
|
-
throw error
|
|
263
|
-
}
|
|
264
|
-
})
|
|
265
|
-
} finally {
|
|
266
|
-
releaseTxMutexRef(key)
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
exports.addTransactionCapability = addTransactionCapability
|
|
272
|
-
const initAuthCreds = () => {
|
|
273
|
-
const identityKey = crypto_2.Curve.generateKeyPair()
|
|
274
|
-
return {
|
|
275
|
-
noiseKey: crypto_2.Curve.generateKeyPair(),
|
|
276
|
-
pairingEphemeralKeyPair: crypto_2.Curve.generateKeyPair(),
|
|
277
|
-
signedIdentityKey: identityKey,
|
|
278
|
-
signedPreKey: (0, crypto_2.signedKeyPair)(identityKey, 1),
|
|
279
|
-
registrationId: (0, generics_1.generateRegistrationId)(),
|
|
280
|
-
advSecretKey: (0, crypto_1.randomBytes)(32).toString('base64'),
|
|
281
|
-
processedHistoryMessages: [],
|
|
282
|
-
initialFullSyncDone: false,
|
|
283
|
-
nextPreKeyId: 1,
|
|
284
|
-
firstUnuploadedPreKeyId: 1,
|
|
285
|
-
accountSyncCounter: 0,
|
|
286
|
-
accountSettings: {
|
|
287
|
-
unarchiveChats: false
|
|
288
|
-
},
|
|
289
|
-
deviceId: Buffer.from((0, crypto_1.randomUUID)().replace(/-/g, ''), 'hex').toString('base64url'),
|
|
290
|
-
phoneId: (0, crypto_1.randomUUID)(),
|
|
291
|
-
identityId: (0, crypto_1.randomBytes)(20),
|
|
292
|
-
backupToken: (0, crypto_1.randomBytes)(20),
|
|
293
|
-
registration: {},
|
|
294
|
-
registered: false,
|
|
295
|
-
pairingCode: undefined,
|
|
296
|
-
lastPropHash: undefined,
|
|
297
|
-
routingInfo: undefined,
|
|
298
|
-
additionalData: undefined
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
exports.initAuthCreds = initAuthCreds
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
|
-
exports.getPlatformId = exports.Browsers = void 0
|
|
4
|
-
const os_1 = require('os')
|
|
5
|
-
const index_js_1 = require('../../WAProto/index.js')
|
|
6
|
-
const COMPANION_PLATFORM_MAP = {
|
|
7
|
-
Chrome: '49',
|
|
8
|
-
Edge: '50',
|
|
9
|
-
Firefox: '51',
|
|
10
|
-
Opera: '53',
|
|
11
|
-
Safari: '54',
|
|
12
|
-
Brave: '1.79.112',
|
|
13
|
-
Vivaldi: '6.2.3105.58',
|
|
14
|
-
Tor: '12.5.3',
|
|
15
|
-
Yandex: '23.7.1',
|
|
16
|
-
Falkon: '22.08.3',
|
|
17
|
-
Epiphany: '44.2'
|
|
18
|
-
}
|
|
19
|
-
const PLATFORM_MAP = {
|
|
20
|
-
aix: 'AIX',
|
|
21
|
-
darwin: 'Mac OS',
|
|
22
|
-
win32: 'Windows',
|
|
23
|
-
android: 'Android',
|
|
24
|
-
freebsd: 'FreeBSD',
|
|
25
|
-
openbsd: 'OpenBSD',
|
|
26
|
-
sunos: 'Solaris',
|
|
27
|
-
linux: 'Linux',
|
|
28
|
-
ubuntu: 'Ubuntu',
|
|
29
|
-
ios: 'iOS',
|
|
30
|
-
baileys: 'Baileys',
|
|
31
|
-
chromeos: 'Chrome OS',
|
|
32
|
-
tizen: 'Tizen',
|
|
33
|
-
watchos: 'watchOS',
|
|
34
|
-
wearos: 'Wear OS',
|
|
35
|
-
harmonyos: 'HarmonyOS',
|
|
36
|
-
kaios: 'KaiOS',
|
|
37
|
-
smarttv: 'Smart TV',
|
|
38
|
-
raspberrypi: 'Raspberry Pi OS',
|
|
39
|
-
symbian: 'Symbian',
|
|
40
|
-
blackberry: 'Blackberry OS',
|
|
41
|
-
windowsphone: 'Windows Phone',
|
|
42
|
-
safari: 'Safari'
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const PLATFORM_VERSIONS = {
|
|
46
|
-
ubuntu: '22.04.4',
|
|
47
|
-
darwin: '18.5',
|
|
48
|
-
win32: '10.0.22631',
|
|
49
|
-
android: '14.0.0',
|
|
50
|
-
freebsd: '13.2',
|
|
51
|
-
openbsd: '7.3',
|
|
52
|
-
sunos: '11',
|
|
53
|
-
linux: '6.5',
|
|
54
|
-
ios: '18.2',
|
|
55
|
-
baileys: '6.5.0',
|
|
56
|
-
chromeos: '117.0.5938.132',
|
|
57
|
-
tizen: '6.5',
|
|
58
|
-
watchos: '10.1',
|
|
59
|
-
wearos: '4.1',
|
|
60
|
-
harmonyos: '4.0.0',
|
|
61
|
-
kaios: '3.1',
|
|
62
|
-
smarttv: '23.3.1',
|
|
63
|
-
raspberrypi: '11 (Bullseye)',
|
|
64
|
-
symbian: '3',
|
|
65
|
-
blackberry: '10.3.3',
|
|
66
|
-
windowsphone: '8.1'
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
exports.Browsers = {
|
|
70
|
-
ubuntu: browser => {
|
|
71
|
-
return [PLATFORM_MAP['ubuntu'], browser, PLATFORM_VERSIONS['ubuntu']]
|
|
72
|
-
},
|
|
73
|
-
macOS: browser => {
|
|
74
|
-
return [PLATFORM_MAP['darwin'], browser, PLATFORM_VERSIONS['darwin']]
|
|
75
|
-
},
|
|
76
|
-
windows: browser => {
|
|
77
|
-
return [PLATFORM_MAP['win32'], browser, PLATFORM_VERSIONS['win32']]
|
|
78
|
-
},
|
|
79
|
-
linux: browser => {
|
|
80
|
-
return [PLATFORM_MAP['linux'], browser, PLATFORM_VERSIONS['linux']]
|
|
81
|
-
},
|
|
82
|
-
solaris: browser => {
|
|
83
|
-
return [PLATFORM_MAP['sunos'], browser, PLATFORM_VERSIONS['sunos']]
|
|
84
|
-
},
|
|
85
|
-
baileys: browser => {
|
|
86
|
-
return [PLATFORM_MAP['baileys'], browser, PLATFORM_VERSIONS['baileys']]
|
|
87
|
-
},
|
|
88
|
-
android: browser => {
|
|
89
|
-
return [PLATFORM_MAP['android'], browser, PLATFORM_VERSIONS['android']]
|
|
90
|
-
},
|
|
91
|
-
iOS: browser => {
|
|
92
|
-
return [PLATFORM_MAP['ios'], browser, PLATFORM_VERSIONS['ios']]
|
|
93
|
-
},
|
|
94
|
-
kaiOS: browser => {
|
|
95
|
-
return [PLATFORM_MAP['kaios'], browser, PLATFORM_VERSIONS['kaios']]
|
|
96
|
-
},
|
|
97
|
-
chromeOS: browser => {
|
|
98
|
-
return [PLATFORM_MAP['chromeos'], browser, PLATFORM_VERSIONS['chromeos']]
|
|
99
|
-
},
|
|
100
|
-
appropriate: browser => {
|
|
101
|
-
const platform = os_1.platform()
|
|
102
|
-
const platformName = PLATFORM_MAP[platform] || 'Unknown OS'
|
|
103
|
-
return [platformName, browser, PLATFORM_VERSIONS[platform] || 'latest']
|
|
104
|
-
},
|
|
105
|
-
custom: (platform, browser, version) => {
|
|
106
|
-
const platformName = PLATFORM_MAP[platform.toLowerCase()] || platform
|
|
107
|
-
return [platformName, browser, version || PLATFORM_VERSIONS[platform] || 'latest']
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
const getPlatformId = browser => {
|
|
111
|
-
const platformType = index_js_1.proto.DeviceProps.PlatformType[browser.toUpperCase()]
|
|
112
|
-
return platformType ? platformType.toString() : '1'
|
|
113
|
-
}
|
|
114
|
-
exports.getPlatformId = getPlatformId
|
package/lib/Utils/business.js
DELETED
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
|
-
exports.uploadingNecessaryImages =
|
|
4
|
-
exports.parseProductNode =
|
|
5
|
-
exports.toProductNode =
|
|
6
|
-
exports.parseOrderDetailsNode =
|
|
7
|
-
exports.parseCollectionsNode =
|
|
8
|
-
exports.parseCatalogNode =
|
|
9
|
-
void 0
|
|
10
|
-
exports.uploadingNecessaryImagesOfProduct = uploadingNecessaryImagesOfProduct
|
|
11
|
-
const boom_1 = require('@hapi/boom')
|
|
12
|
-
const crypto_1 = require('crypto')
|
|
13
|
-
const fs_1 = require('fs')
|
|
14
|
-
const os_1 = require('os')
|
|
15
|
-
const path_1 = require('path')
|
|
16
|
-
const WABinary_1 = require('../WABinary')
|
|
17
|
-
const generics_1 = require('./generics')
|
|
18
|
-
const messages_media_1 = require('./messages-media')
|
|
19
|
-
const parseCatalogNode = node => {
|
|
20
|
-
const catalogNode = (0, WABinary_1.getBinaryNodeChild)(node, 'product_catalog')
|
|
21
|
-
const products = (0, WABinary_1.getBinaryNodeChildren)(catalogNode, 'product').map(exports.parseProductNode)
|
|
22
|
-
const paging = (0, WABinary_1.getBinaryNodeChild)(catalogNode, 'paging')
|
|
23
|
-
return {
|
|
24
|
-
products,
|
|
25
|
-
nextPageCursor: paging ? (0, WABinary_1.getBinaryNodeChildString)(paging, 'after') : undefined
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
exports.parseCatalogNode = parseCatalogNode
|
|
29
|
-
const parseCollectionsNode = node => {
|
|
30
|
-
const collectionsNode = (0, WABinary_1.getBinaryNodeChild)(node, 'collections')
|
|
31
|
-
const collections = (0, WABinary_1.getBinaryNodeChildren)(collectionsNode, 'collection').map(collectionNode => {
|
|
32
|
-
const id = (0, WABinary_1.getBinaryNodeChildString)(collectionNode, 'id')
|
|
33
|
-
const name = (0, WABinary_1.getBinaryNodeChildString)(collectionNode, 'name')
|
|
34
|
-
const products = (0, WABinary_1.getBinaryNodeChildren)(collectionNode, 'product').map(exports.parseProductNode)
|
|
35
|
-
return {
|
|
36
|
-
id,
|
|
37
|
-
name,
|
|
38
|
-
products,
|
|
39
|
-
status: parseStatusInfo(collectionNode)
|
|
40
|
-
}
|
|
41
|
-
})
|
|
42
|
-
return {
|
|
43
|
-
collections
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
exports.parseCollectionsNode = parseCollectionsNode
|
|
47
|
-
const parseOrderDetailsNode = node => {
|
|
48
|
-
const orderNode = (0, WABinary_1.getBinaryNodeChild)(node, 'order')
|
|
49
|
-
const products = (0, WABinary_1.getBinaryNodeChildren)(orderNode, 'product').map(productNode => {
|
|
50
|
-
const imageNode = (0, WABinary_1.getBinaryNodeChild)(productNode, 'image')
|
|
51
|
-
return {
|
|
52
|
-
id: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'id'),
|
|
53
|
-
name: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'name'),
|
|
54
|
-
imageUrl: (0, WABinary_1.getBinaryNodeChildString)(imageNode, 'url'),
|
|
55
|
-
price: +(0, WABinary_1.getBinaryNodeChildString)(productNode, 'price'),
|
|
56
|
-
currency: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'currency'),
|
|
57
|
-
quantity: +(0, WABinary_1.getBinaryNodeChildString)(productNode, 'quantity')
|
|
58
|
-
}
|
|
59
|
-
})
|
|
60
|
-
const priceNode = (0, WABinary_1.getBinaryNodeChild)(orderNode, 'price')
|
|
61
|
-
const orderDetails = {
|
|
62
|
-
price: {
|
|
63
|
-
total: +(0, WABinary_1.getBinaryNodeChildString)(priceNode, 'total'),
|
|
64
|
-
currency: (0, WABinary_1.getBinaryNodeChildString)(priceNode, 'currency')
|
|
65
|
-
},
|
|
66
|
-
products
|
|
67
|
-
}
|
|
68
|
-
return orderDetails
|
|
69
|
-
}
|
|
70
|
-
exports.parseOrderDetailsNode = parseOrderDetailsNode
|
|
71
|
-
const toProductNode = (productId, product) => {
|
|
72
|
-
const attrs = {}
|
|
73
|
-
const content = []
|
|
74
|
-
if (typeof productId !== 'undefined') {
|
|
75
|
-
content.push({
|
|
76
|
-
tag: 'id',
|
|
77
|
-
attrs: {},
|
|
78
|
-
content: Buffer.from(productId)
|
|
79
|
-
})
|
|
80
|
-
}
|
|
81
|
-
if (typeof product.name !== 'undefined') {
|
|
82
|
-
content.push({
|
|
83
|
-
tag: 'name',
|
|
84
|
-
attrs: {},
|
|
85
|
-
content: Buffer.from(product.name)
|
|
86
|
-
})
|
|
87
|
-
}
|
|
88
|
-
if (typeof product.description !== 'undefined') {
|
|
89
|
-
content.push({
|
|
90
|
-
tag: 'description',
|
|
91
|
-
attrs: {},
|
|
92
|
-
content: Buffer.from(product.description)
|
|
93
|
-
})
|
|
94
|
-
}
|
|
95
|
-
if (typeof product.retailerId !== 'undefined') {
|
|
96
|
-
content.push({
|
|
97
|
-
tag: 'retailer_id',
|
|
98
|
-
attrs: {},
|
|
99
|
-
content: Buffer.from(product.retailerId)
|
|
100
|
-
})
|
|
101
|
-
}
|
|
102
|
-
if (product.images.length) {
|
|
103
|
-
content.push({
|
|
104
|
-
tag: 'media',
|
|
105
|
-
attrs: {},
|
|
106
|
-
content: product.images.map(img => {
|
|
107
|
-
if (!('url' in img)) {
|
|
108
|
-
throw new boom_1.Boom('Expected img for product to already be uploaded', { statusCode: 400 })
|
|
109
|
-
}
|
|
110
|
-
return {
|
|
111
|
-
tag: 'image',
|
|
112
|
-
attrs: {},
|
|
113
|
-
content: [
|
|
114
|
-
{
|
|
115
|
-
tag: 'url',
|
|
116
|
-
attrs: {},
|
|
117
|
-
content: Buffer.from(img.url.toString())
|
|
118
|
-
}
|
|
119
|
-
]
|
|
120
|
-
}
|
|
121
|
-
})
|
|
122
|
-
})
|
|
123
|
-
}
|
|
124
|
-
if (typeof product.price !== 'undefined') {
|
|
125
|
-
content.push({
|
|
126
|
-
tag: 'price',
|
|
127
|
-
attrs: {},
|
|
128
|
-
content: Buffer.from(product.price.toString())
|
|
129
|
-
})
|
|
130
|
-
}
|
|
131
|
-
if (typeof product.currency !== 'undefined') {
|
|
132
|
-
content.push({
|
|
133
|
-
tag: 'currency',
|
|
134
|
-
attrs: {},
|
|
135
|
-
content: Buffer.from(product.currency)
|
|
136
|
-
})
|
|
137
|
-
}
|
|
138
|
-
if ('originCountryCode' in product) {
|
|
139
|
-
if (typeof product.originCountryCode === 'undefined') {
|
|
140
|
-
attrs['compliance_category'] = 'COUNTRY_ORIGIN_EXEMPT'
|
|
141
|
-
} else {
|
|
142
|
-
content.push({
|
|
143
|
-
tag: 'compliance_info',
|
|
144
|
-
attrs: {},
|
|
145
|
-
content: [
|
|
146
|
-
{
|
|
147
|
-
tag: 'country_code_origin',
|
|
148
|
-
attrs: {},
|
|
149
|
-
content: Buffer.from(product.originCountryCode)
|
|
150
|
-
}
|
|
151
|
-
]
|
|
152
|
-
})
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
if (typeof product.isHidden !== 'undefined') {
|
|
156
|
-
attrs['is_hidden'] = product.isHidden.toString()
|
|
157
|
-
}
|
|
158
|
-
const node = {
|
|
159
|
-
tag: 'product',
|
|
160
|
-
attrs,
|
|
161
|
-
content
|
|
162
|
-
}
|
|
163
|
-
return node
|
|
164
|
-
}
|
|
165
|
-
exports.toProductNode = toProductNode
|
|
166
|
-
const parseProductNode = productNode => {
|
|
167
|
-
const isHidden = productNode.attrs.is_hidden === 'true'
|
|
168
|
-
const id = (0, WABinary_1.getBinaryNodeChildString)(productNode, 'id')
|
|
169
|
-
const mediaNode = (0, WABinary_1.getBinaryNodeChild)(productNode, 'media')
|
|
170
|
-
const statusInfoNode = (0, WABinary_1.getBinaryNodeChild)(productNode, 'status_info')
|
|
171
|
-
const product = {
|
|
172
|
-
id,
|
|
173
|
-
imageUrls: parseImageUrls(mediaNode),
|
|
174
|
-
reviewStatus: {
|
|
175
|
-
whatsapp: (0, WABinary_1.getBinaryNodeChildString)(statusInfoNode, 'status')
|
|
176
|
-
},
|
|
177
|
-
availability: 'in stock',
|
|
178
|
-
name: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'name'),
|
|
179
|
-
retailerId: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'retailer_id'),
|
|
180
|
-
url: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'url'),
|
|
181
|
-
description: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'description'),
|
|
182
|
-
price: +(0, WABinary_1.getBinaryNodeChildString)(productNode, 'price'),
|
|
183
|
-
currency: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'currency'),
|
|
184
|
-
isHidden
|
|
185
|
-
}
|
|
186
|
-
return product
|
|
187
|
-
}
|
|
188
|
-
exports.parseProductNode = parseProductNode
|
|
189
|
-
|
|
190
|
-
async function uploadingNecessaryImagesOfProduct(product, waUploadToServer, timeoutMs = 30000) {
|
|
191
|
-
product = {
|
|
192
|
-
...product,
|
|
193
|
-
images: product.images
|
|
194
|
-
? await (0, exports.uploadingNecessaryImages)(product.images, waUploadToServer, timeoutMs)
|
|
195
|
-
: product.images
|
|
196
|
-
}
|
|
197
|
-
return product
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
const uploadingNecessaryImages = async (images, waUploadToServer, timeoutMs = 30000) => {
|
|
201
|
-
const results = await Promise.all(
|
|
202
|
-
images.map(async img => {
|
|
203
|
-
if ('url' in img) {
|
|
204
|
-
const url = img.url.toString()
|
|
205
|
-
if (url.includes('.whatsapp.net')) {
|
|
206
|
-
return { url }
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
const { stream } = await (0, messages_media_1.getStream)(img)
|
|
210
|
-
const hasher = (0, crypto_1.createHash)('sha256')
|
|
211
|
-
const filePath = (0, path_1.join)((0, os_1.tmpdir)(), 'img' + (0, generics_1.generateMessageIDV2)())
|
|
212
|
-
const encFileWriteStream = (0, fs_1.createWriteStream)(filePath)
|
|
213
|
-
for await (const block of stream) {
|
|
214
|
-
hasher.update(block)
|
|
215
|
-
encFileWriteStream.write(block)
|
|
216
|
-
}
|
|
217
|
-
const sha = hasher.digest('base64')
|
|
218
|
-
const { directPath } = await waUploadToServer(filePath, {
|
|
219
|
-
mediaType: 'product-catalog-image',
|
|
220
|
-
fileEncSha256B64: sha,
|
|
221
|
-
timeoutMs
|
|
222
|
-
})
|
|
223
|
-
await fs_1.promises.unlink(filePath).catch(() => {})
|
|
224
|
-
return { url: (0, messages_media_1.getUrlFromDirectPath)(directPath) }
|
|
225
|
-
})
|
|
226
|
-
)
|
|
227
|
-
return results
|
|
228
|
-
}
|
|
229
|
-
exports.uploadingNecessaryImages = uploadingNecessaryImages
|
|
230
|
-
const parseImageUrls = mediaNode => {
|
|
231
|
-
const imgNode = (0, WABinary_1.getBinaryNodeChild)(mediaNode, 'image')
|
|
232
|
-
return {
|
|
233
|
-
requested: (0, WABinary_1.getBinaryNodeChildString)(imgNode, 'request_image_url'),
|
|
234
|
-
original: (0, WABinary_1.getBinaryNodeChildString)(imgNode, 'original_image_url')
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
const parseStatusInfo = mediaNode => {
|
|
238
|
-
const node = (0, WABinary_1.getBinaryNodeChild)(mediaNode, 'status_info')
|
|
239
|
-
return {
|
|
240
|
-
status: (0, WABinary_1.getBinaryNodeChildString)(node, 'status'),
|
|
241
|
-
canAppeal: (0, WABinary_1.getBinaryNodeChildString)(node, 'can_appeal') === 'true'
|
|
242
|
-
}
|
|
243
|
-
}
|