kage-baileys 3.0.6 → 3.2.4
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/Example/connection.cjs +4 -0
- package/README.MD +4726 -48
- package/README.md +5941 -0
- package/WAProto/WAProto.proto +3395 -415
- package/WAProto/compat.cjs +12 -0
- package/WAProto/index.d.ts +47104 -19888
- package/WAProto/index.js +131979 -57361
- package/lib/Addon/http-error.js +43 -0
- package/lib/Addon/index.js +32 -0
- package/lib/Addon/keyed-db.js +250 -0
- package/lib/Addon/link-preview.js +82 -0
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/connection.js +110 -0
- package/lib/Defaults/constants.js +156 -0
- package/lib/Defaults/history.js +46 -0
- package/lib/Defaults/index.js +230 -0
- package/lib/Defaults/media.js +104 -0
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Defaults/prefix.js +44 -0
- package/lib/Extensions/business-advanced.js +382 -0
- package/lib/Extensions/business.js +159 -0
- package/lib/Extensions/chats-advanced.js +1106 -0
- package/lib/Extensions/chats.js +349 -0
- package/lib/Extensions/communities-advanced.js +430 -0
- package/lib/Extensions/community.js +94 -0
- package/lib/Extensions/groups-advanced.js +343 -0
- package/lib/Extensions/index.js +30 -0
- package/lib/Extensions/messages-recv-advanced.js +1690 -0
- package/lib/Extensions/messages-send-advanced.js +622 -0
- package/lib/Extensions/messages-send.js +1380 -0
- package/lib/Extensions/newsletter-advanced.js +228 -0
- package/lib/Extensions/newsletter.js +72 -0
- package/lib/Extensions/socket.js +389 -0
- package/lib/Modded/message_builder.js +2084 -4
- package/lib/Signal/Group/ciphertext-message.js +54 -0
- package/lib/Signal/Group/group-session-builder.js +124 -0
- package/lib/Signal/Group/group_cipher.js +216 -0
- package/lib/Signal/Group/index.js +124 -0
- package/lib/Signal/Group/keyhelper.js +108 -0
- package/lib/Signal/Group/sender-chain-key.js +83 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +157 -0
- package/lib/Signal/Group/sender-key-message.js +166 -0
- package/lib/Signal/Group/sender-key-name.js +130 -0
- package/lib/Signal/Group/sender-key-record.js +113 -0
- package/lib/Signal/Group/sender-key-state.js +208 -0
- package/lib/Signal/Group/sender-message-key.js +82 -0
- package/lib/Signal/libsignal.js +935 -0
- package/lib/Signal/lid-mapping.js +545 -1
- package/lib/Socket/Client/index.js +60 -0
- package/lib/Socket/Client/types.js +51 -0
- package/lib/Socket/Client/websocket.js +152 -0
- package/lib/Socket/business.js +831 -0
- package/lib/Socket/chats.js +2535 -49
- package/lib/Socket/communities.js +450 -1
- package/lib/Socket/community.js +1022 -0
- package/lib/Socket/dugong.js +1 -1
- package/lib/Socket/groups.js +747 -0
- package/lib/Socket/index.js +60 -2
- package/lib/Socket/messages-recv.js +3450 -5
- package/lib/Socket/messages-send.js +3123 -0
- package/lib/Socket/mex.js +126 -1
- package/lib/Socket/newsletter.js +465 -0
- package/lib/Socket/socket.js +2217 -1
- package/lib/Store/index.js +79 -0
- package/lib/Store/make-cache-manager-store.js +186 -0
- package/lib/Store/make-in-memory-store.js +878 -0
- package/lib/Store/make-ordered-dictionary.js +187 -0
- package/lib/Store/object-repository.js +78 -0
- package/lib/Types/Auth.js +25 -0
- package/lib/Types/Bussines.js +25 -1
- package/lib/Types/Call.js +25 -0
- package/lib/Types/Chat.js +39 -0
- package/lib/Types/Contact.js +25 -0
- package/lib/Types/Events.js +25 -0
- package/lib/Types/GroupMetadata.js +25 -0
- package/lib/Types/Label.js +76 -0
- package/lib/Types/LabelAssociation.js +40 -0
- package/lib/Types/Message.js +57 -0
- package/lib/Types/Mex.js +56 -1
- package/lib/Types/MexUpdates.js +46 -0
- package/lib/Types/Newsletter.js +56 -0
- package/lib/Types/Product.js +25 -0
- package/lib/Types/RichType.js +23 -0
- package/lib/Types/Signal.js +25 -0
- package/lib/Types/Socket.js +25 -0
- package/lib/Types/State.js +92 -0
- package/lib/Types/USync.js +25 -0
- package/lib/Types/index.js +133 -0
- package/lib/Utils/auth-utils.js +703 -0
- package/lib/Utils/automation-tools.js +51 -16
- package/lib/Utils/baileys-event-stream.js +146 -0
- package/lib/Utils/browser-utils.js +95 -0
- package/lib/Utils/business.js +525 -0
- package/lib/Utils/chat-utils.js +1861 -0
- package/lib/Utils/companion-reg-client-utils.js +55 -1
- package/lib/Utils/crypto.js +355 -0
- package/lib/Utils/decode-wa-message.js +709 -0
- package/lib/Utils/event-buffer.js +1323 -8
- package/lib/Utils/generics.js +945 -1
- package/lib/Utils/history.js +266 -0
- package/lib/Utils/identity-change-handler.js +62 -1
- package/lib/Utils/index.js +114 -0
- package/lib/Utils/link-preview.js +179 -0
- package/lib/Utils/logger.js +42 -0
- package/lib/Utils/lt-hash.js +73 -0
- package/lib/Utils/make-mutex.js +104 -0
- package/lib/Utils/message-inspector.js +110 -0
- package/lib/Utils/message-retry-manager.js +507 -2
- package/lib/Utils/messages-media.js +1931 -1
- package/lib/Utils/messages.js +3748 -0
- package/lib/Utils/noise-handler.js +423 -0
- package/lib/Utils/offline-node-processor.js +53 -1
- package/lib/Utils/pre-key-manager.js +255 -1
- package/lib/Utils/process-message.js +1592 -0
- package/lib/Utils/reporting-utils.js +272 -1
- package/lib/Utils/rich-message-utils.js +377 -0
- package/lib/Utils/rich-messages.js +1 -1
- package/lib/Utils/signal.js +437 -0
- package/lib/Utils/stanza-ack.js +51 -1
- package/lib/Utils/status-refresh.js +37 -0
- package/lib/Utils/status-tools.js +4 -2
- package/lib/Utils/sync-action-utils.js +63 -1
- package/lib/Utils/tc-token-utils.js +185 -1
- package/lib/Utils/terminal-banner.js +31 -0
- package/lib/Utils/use-multi-file-auth-state.js +271 -0
- package/lib/Utils/use-single-file-auth-state.js +108 -0
- package/lib/Utils/use-sqlite-auth-state.js +142 -0
- package/lib/Utils/validate-connection.js +497 -1
- package/lib/Utils/view-once-compat.js +13 -5
- package/lib/VoIP/audio-feeder.js +150 -0
- package/lib/VoIP/index.js +289 -0
- package/lib/VoIP/relay-transport.js +608 -0
- package/lib/VoIP/signaling.js +583 -0
- package/lib/VoIP/types.js +30 -0
- package/lib/VoIP/wasm-engine.js +1261 -2
- package/lib/VoIP/worker-bootstrap.js +1090 -2
- package/lib/WABinary/constants.js +2805 -0
- package/lib/WABinary/decode.js +649 -2
- package/lib/WABinary/encode.js +564 -2
- package/lib/WABinary/generic-utils.js +401 -0
- package/lib/WABinary/index.js +82 -0
- package/lib/WABinary/jid-utils.js +290 -0
- package/lib/WABinary/types.js +25 -0
- package/lib/WAM/BinaryInfo.js +50 -0
- package/lib/WAM/constants.js +45747 -0
- package/lib/WAM/encode.js +393 -0
- package/lib/WAM/index.js +78 -0
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +135 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +110 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +142 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +85 -0
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +69 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +107 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +38 -1
- package/lib/WAUSync/Protocols/index.js +83 -0
- package/lib/WAUSync/USyncQuery.js +241 -2
- package/lib/WAUSync/USyncUser.js +86 -0
- package/lib/WAUSync/index.js +78 -0
- package/lib/assets/wasm/loader.js +1875 -1
- package/lib/assets/wasm/worker-modules.js +11047 -1
- package/lib/index.d.ts +126 -0
- package/lib/index.js +53 -21
- package/lib/index.mjs +437 -0
- package/licenses/upstream-MIT.txt +22 -0
- package/maintenance/api-coverage.json +1642 -0
- package/maintenance/archivos-sha256.json +207 -0
- package/maintenance/consumer-validation.log +3 -0
- package/maintenance/dependency-audit.json +4 -4
- package/maintenance/extension-inventory.json +57 -0
- package/maintenance/protocol-update.json +1101 -0
- package/maintenance/protocol-wire-audit.json +4 -0
- package/maintenance/reference-socket-surface.json +209 -0
- package/maintenance/resumen-validacion.json +50 -0
- package/maintenance/validation.log +2725 -0
- package/maintenance/verification.json +566 -0
- package/package.json +107 -9
- package/scripts/check-imports.cjs +10 -0
- package/scripts/check-package.cjs +40 -0
- package/scripts/check-syntax.cjs +1 -1
- package/scripts/generate-protobuf.cjs +6 -1
- package/scripts/generate-public-types.cjs +9 -0
- package/scripts/kage-base64-fix.cjs +45 -0
- package/scripts/maintenance.cjs +10 -0
- package/test/advanced.test.cjs +24 -0
- package/test/base64-fix.test.cjs +49 -0
- package/test/maintenance.test.cjs +1 -1
- package/test/npm-publication.test.cjs +141 -0
- package/test/recepcion-reparada.test.cjs +98 -0
- package/test/resilience-binary.test.cjs +69 -0
- package/test/resilience-transport.test.cjs +34 -0
- package/test/types.test.ts +5 -0
- package/test/upgrade.test.cjs +104 -0
- package/tsconfig.json +20 -0
- package/WAProto/p.html +0 -1
- package/lib/KageExtra/Modded/message_builder.js +0 -2330
- package/lib/KageExtra/VoIP/audio-feeder.js +0 -136
- package/lib/KageExtra/VoIP/index.js +0 -282
- package/lib/KageExtra/VoIP/relay-transport.js +0 -559
- package/lib/KageExtra/VoIP/signaling.js +0 -603
- package/lib/KageExtra/VoIP/types.js +0 -17
- package/lib/KageExtra/VoIP/wasm-engine.js +0 -1214
- package/lib/KageExtra/VoIP/worker-bootstrap.js +0 -1042
- package/lib/KageExtra/assets/wasm/loader.js +0 -5
- package/lib/KageExtra/assets/wasm/whatsapp.wasm +0 -0
- package/lib/KageExtra/assets/wasm/worker-modules.js +0 -273
- package/lib/KageExtra/index.js +0 -3
- package/lib/KageExtra/package.json +0 -1
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -53
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +0 -24
- package/maintenance/revision-full-check.txt +0 -1097
- package/maintenance/revision-library-tests.tap +0 -1088
- package/maintenance/revision-protobuf.txt +0 -5
- package/maintenance/revision-syntax.txt +0 -5
- package/maintenance/schema-coverage.json +0 -23
- package/maintenance/schema-merge.json +0 -30
- package/maintenance/validation-node20.txt +0 -191
- package/maintenance/validation-node22.txt +0 -237
package/lib/Utils/business.js
CHANGED
|
@@ -232,3 +232,528 @@ const parseStatusInfo = (mediaNode) => {
|
|
|
232
232
|
canAppeal: (0, WABinary_1.getBinaryNodeChildString)(node, 'can_appeal') === 'true',
|
|
233
233
|
};
|
|
234
234
|
};
|
|
235
|
+
|
|
236
|
+
// Kage: compatibilidad de API.
|
|
237
|
+
const __kageModule60 = (() => {
|
|
238
|
+
const module = { exports: {} }; const exports = module.exports;
|
|
239
|
+
"use strict"
|
|
240
|
+
|
|
241
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
242
|
+
|
|
243
|
+
const { Boom } = require("@hapi/boom")
|
|
244
|
+
const { createHash } = require("crypto")
|
|
245
|
+
const { join } = require("path")
|
|
246
|
+
const { tmpdir } = require("os")
|
|
247
|
+
const {
|
|
248
|
+
promises,
|
|
249
|
+
createWriteStream
|
|
250
|
+
} = require("fs")
|
|
251
|
+
const {
|
|
252
|
+
getBinaryNodeChild,
|
|
253
|
+
getBinaryNodeChildren,
|
|
254
|
+
getBinaryNodeChildString
|
|
255
|
+
} = require("../WABinary")
|
|
256
|
+
const {
|
|
257
|
+
getStream,
|
|
258
|
+
getUrlFromDirectPath
|
|
259
|
+
} = require("./messages-media")
|
|
260
|
+
const { generateMessageID } = require("./generics")
|
|
261
|
+
|
|
262
|
+
const parseCatalogNode = (node) => {
|
|
263
|
+
const catalogNode = getBinaryNodeChild(node, 'product_catalog')
|
|
264
|
+
const products = getBinaryNodeChildren(catalogNode, 'product').map(parseProductNode)
|
|
265
|
+
const paging = getBinaryNodeChild(catalogNode, 'paging')
|
|
266
|
+
return {
|
|
267
|
+
products,
|
|
268
|
+
nextPageCursor: paging
|
|
269
|
+
? getBinaryNodeChildString(paging, 'after')
|
|
270
|
+
: undefined
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const parseCollectionsNode = (node) => {
|
|
275
|
+
const collectionsNode = getBinaryNodeChild(node, 'collections')
|
|
276
|
+
const collections = getBinaryNodeChildren(collectionsNode, 'collection').map(collectionNode => {
|
|
277
|
+
const id = getBinaryNodeChildString(collectionNode, 'id')
|
|
278
|
+
const name = getBinaryNodeChildString(collectionNode, 'name')
|
|
279
|
+
const products = getBinaryNodeChildren(collectionNode, 'product').map(parseProductNode)
|
|
280
|
+
return {
|
|
281
|
+
id,
|
|
282
|
+
name,
|
|
283
|
+
products,
|
|
284
|
+
status: parseStatusInfo(collectionNode)
|
|
285
|
+
}
|
|
286
|
+
})
|
|
287
|
+
return {
|
|
288
|
+
collections
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
const parseOrderDetailsNode = (node) => {
|
|
293
|
+
const orderNode = getBinaryNodeChild(node, 'order')
|
|
294
|
+
const products = getBinaryNodeChildren(orderNode, 'product').map(productNode => {
|
|
295
|
+
const imageNode = getBinaryNodeChild(productNode, 'image')
|
|
296
|
+
return {
|
|
297
|
+
id: getBinaryNodeChildString(productNode, 'id'),
|
|
298
|
+
name: getBinaryNodeChildString(productNode, 'name'),
|
|
299
|
+
imageUrl: getBinaryNodeChildString(imageNode, 'url'),
|
|
300
|
+
price: +getBinaryNodeChildString(productNode, 'price'),
|
|
301
|
+
currency: getBinaryNodeChildString(productNode, 'currency'),
|
|
302
|
+
quantity: +getBinaryNodeChildString(productNode, 'quantity')
|
|
303
|
+
}
|
|
304
|
+
})
|
|
305
|
+
const priceNode = getBinaryNodeChild(orderNode, 'price')
|
|
306
|
+
const orderDetails = {
|
|
307
|
+
price: {
|
|
308
|
+
total: +getBinaryNodeChildString(priceNode, 'total'),
|
|
309
|
+
currency: getBinaryNodeChildString(priceNode, 'currency'),
|
|
310
|
+
},
|
|
311
|
+
products
|
|
312
|
+
}
|
|
313
|
+
return orderDetails
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
const toProductNode = (productId, product) => {
|
|
317
|
+
const attrs = {}
|
|
318
|
+
const content = []
|
|
319
|
+
if (typeof productId !== 'undefined') {
|
|
320
|
+
content.push({
|
|
321
|
+
tag: 'id',
|
|
322
|
+
attrs: {},
|
|
323
|
+
content: Buffer.from(productId)
|
|
324
|
+
})
|
|
325
|
+
}
|
|
326
|
+
if (typeof product.name !== 'undefined') {
|
|
327
|
+
content.push({
|
|
328
|
+
tag: 'name',
|
|
329
|
+
attrs: {},
|
|
330
|
+
content: Buffer.from(product.name)
|
|
331
|
+
})
|
|
332
|
+
}
|
|
333
|
+
if (typeof product.description !== 'undefined') {
|
|
334
|
+
content.push({
|
|
335
|
+
tag: 'description',
|
|
336
|
+
attrs: {},
|
|
337
|
+
content: Buffer.from(product.description)
|
|
338
|
+
})
|
|
339
|
+
}
|
|
340
|
+
if (typeof product.retailerId !== 'undefined') {
|
|
341
|
+
content.push({
|
|
342
|
+
tag: 'retailer_id',
|
|
343
|
+
attrs: {},
|
|
344
|
+
content: Buffer.from(product.retailerId)
|
|
345
|
+
})
|
|
346
|
+
}
|
|
347
|
+
if (product.images.length) {
|
|
348
|
+
content.push({
|
|
349
|
+
tag: 'media',
|
|
350
|
+
attrs: {},
|
|
351
|
+
content: product.images.map(img => {
|
|
352
|
+
if (!('url' in img)) {
|
|
353
|
+
throw new Boom('Expected img for product to already be uploaded', { statusCode: 400 })
|
|
354
|
+
}
|
|
355
|
+
return {
|
|
356
|
+
tag: 'image',
|
|
357
|
+
attrs: {},
|
|
358
|
+
content: [
|
|
359
|
+
{
|
|
360
|
+
tag: 'url',
|
|
361
|
+
attrs: {},
|
|
362
|
+
content: Buffer.from(img.url.toString())
|
|
363
|
+
}
|
|
364
|
+
]
|
|
365
|
+
}
|
|
366
|
+
})
|
|
367
|
+
})
|
|
368
|
+
}
|
|
369
|
+
if (typeof product.price !== 'undefined') {
|
|
370
|
+
content.push({
|
|
371
|
+
tag: 'price',
|
|
372
|
+
attrs: {},
|
|
373
|
+
content: Buffer.from(product.price.toString())
|
|
374
|
+
})
|
|
375
|
+
}
|
|
376
|
+
if (typeof product.currency !== 'undefined') {
|
|
377
|
+
content.push({
|
|
378
|
+
tag: 'currency',
|
|
379
|
+
attrs: {},
|
|
380
|
+
content: Buffer.from(product.currency)
|
|
381
|
+
})
|
|
382
|
+
}
|
|
383
|
+
if ('originCountryCode' in product) {
|
|
384
|
+
if (typeof product.originCountryCode === 'undefined') {
|
|
385
|
+
attrs['compliance_category'] = 'COUNTRY_ORIGIN_EXEMPT'
|
|
386
|
+
}
|
|
387
|
+
else {
|
|
388
|
+
content.push({
|
|
389
|
+
tag: 'compliance_info',
|
|
390
|
+
attrs: {},
|
|
391
|
+
content: [
|
|
392
|
+
{
|
|
393
|
+
tag: 'country_code_origin',
|
|
394
|
+
attrs: {},
|
|
395
|
+
content: Buffer.from(product.originCountryCode)
|
|
396
|
+
}
|
|
397
|
+
]
|
|
398
|
+
})
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
if (typeof product.isHidden !== 'undefined') {
|
|
402
|
+
attrs['is_hidden'] = product.isHidden.toString()
|
|
403
|
+
}
|
|
404
|
+
const node = {
|
|
405
|
+
tag: 'product',
|
|
406
|
+
attrs,
|
|
407
|
+
content
|
|
408
|
+
}
|
|
409
|
+
return node
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
const parseProductNode = (productNode) => {
|
|
413
|
+
const isHidden = productNode.attrs.is_hidden === 'true'
|
|
414
|
+
const id = getBinaryNodeChildString(productNode, 'id')
|
|
415
|
+
const mediaNode = getBinaryNodeChild(productNode, 'media')
|
|
416
|
+
const statusInfoNode = getBinaryNodeChild(productNode, 'status_info')
|
|
417
|
+
const product = {
|
|
418
|
+
id,
|
|
419
|
+
imageUrls: parseImageUrls(mediaNode),
|
|
420
|
+
reviewStatus: {
|
|
421
|
+
whatsapp: getBinaryNodeChildString(statusInfoNode, 'status'),
|
|
422
|
+
},
|
|
423
|
+
availability: 'in stock',
|
|
424
|
+
name: getBinaryNodeChildString(productNode, 'name'),
|
|
425
|
+
retailerId: getBinaryNodeChildString(productNode, 'retailer_id'),
|
|
426
|
+
url: getBinaryNodeChildString(productNode, 'url'),
|
|
427
|
+
description: getBinaryNodeChildString(productNode, 'description'),
|
|
428
|
+
price: +getBinaryNodeChildString(productNode, 'price'),
|
|
429
|
+
currency: getBinaryNodeChildString(productNode, 'currency'),
|
|
430
|
+
isHidden
|
|
431
|
+
}
|
|
432
|
+
return product
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* Uploads images not already uploaded to WA's servers
|
|
437
|
+
*/
|
|
438
|
+
async function uploadingNecessaryImagesOfProduct(product, waUploadToServer, timeoutMs = 30000) {
|
|
439
|
+
product = {
|
|
440
|
+
...product,
|
|
441
|
+
images: product.images ? await uploadingNecessaryImages(product.images, waUploadToServer, timeoutMs) : product.images
|
|
442
|
+
}
|
|
443
|
+
return product
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
/**
|
|
447
|
+
* Uploads images not already uploaded to WA's servers
|
|
448
|
+
*/
|
|
449
|
+
const uploadingNecessaryImages = async (images, waUploadToServer, timeoutMs = 30000) => {
|
|
450
|
+
const results = await Promise.all(images.map(async (img) => {
|
|
451
|
+
if ('url' in img) {
|
|
452
|
+
const url = img.url.toString()
|
|
453
|
+
if (url.includes('.whatsapp.net')) {
|
|
454
|
+
return { url }
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
const { stream } = await getStream(img)
|
|
458
|
+
const hasher = createHash('sha256')
|
|
459
|
+
const filePath = join(tmpdir(), 'img' + generateMessageID())
|
|
460
|
+
const encFileWriteStream = createWriteStream(filePath)
|
|
461
|
+
for await (const block of stream) {
|
|
462
|
+
hasher.update(block)
|
|
463
|
+
encFileWriteStream.write(block)
|
|
464
|
+
}
|
|
465
|
+
const sha = hasher.digest('base64')
|
|
466
|
+
const { directPath } = await waUploadToServer(filePath, {
|
|
467
|
+
mediaType: 'product-catalog-image',
|
|
468
|
+
fileEncSha256B64: sha,
|
|
469
|
+
timeoutMs
|
|
470
|
+
})
|
|
471
|
+
await promises
|
|
472
|
+
.unlink(filePath)
|
|
473
|
+
.catch(err => console.log('Error deleting temp file ', err))
|
|
474
|
+
return { url: getUrlFromDirectPath(directPath) }
|
|
475
|
+
}))
|
|
476
|
+
return results
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
const parseImageUrls = (mediaNode) => {
|
|
480
|
+
const imgNode = getBinaryNodeChild(mediaNode, 'image')
|
|
481
|
+
return {
|
|
482
|
+
requested: getBinaryNodeChildString(imgNode, 'request_image_url'),
|
|
483
|
+
original: getBinaryNodeChildString(imgNode, 'original_image_url')
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
const parseStatusInfo = (mediaNode) => {
|
|
488
|
+
const node = getBinaryNodeChild(mediaNode, 'status_info')
|
|
489
|
+
return {
|
|
490
|
+
status: getBinaryNodeChildString(node, 'status'),
|
|
491
|
+
canAppeal: getBinaryNodeChildString(node, 'can_appeal') === 'true',
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
module.exports = {
|
|
496
|
+
parseCatalogNode,
|
|
497
|
+
parseCollectionsNode,
|
|
498
|
+
parseOrderDetailsNode,
|
|
499
|
+
toProductNode,
|
|
500
|
+
parseProductNode,
|
|
501
|
+
uploadingNecessaryImagesOfProduct,
|
|
502
|
+
uploadingNecessaryImages
|
|
503
|
+
}
|
|
504
|
+
return module.exports;
|
|
505
|
+
})();
|
|
506
|
+
for (const key of Object.keys(__kageModule60)) {
|
|
507
|
+
if (key !== '__esModule' && !Object.prototype.hasOwnProperty.call(exports,key)) Object.defineProperty(exports,key,{enumerable:true,configurable:true,get:()=>__kageModule60[key]});
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// Kage: funciones avanzadas.
|
|
511
|
+
const __kageModule163 = (() => {
|
|
512
|
+
const module = { exports: {} }; const exports = module.exports;
|
|
513
|
+
"use strict";
|
|
514
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
515
|
+
exports.uploadingNecessaryImages = exports.parseProductNode = exports.toProductNode = exports.parseOrderDetailsNode = exports.parseCollectionsNode = exports.parseCatalogNode = void 0;
|
|
516
|
+
exports.uploadingNecessaryImagesOfProduct = uploadingNecessaryImagesOfProduct;
|
|
517
|
+
const crypto_1 = require("crypto");
|
|
518
|
+
const fs_1 = require("fs");
|
|
519
|
+
const os_1 = require("os");
|
|
520
|
+
const path_1 = require("path");
|
|
521
|
+
const index_js_1 = require("../Addon/index.js");
|
|
522
|
+
const index_js_2 = require("../WABinary/index.js");
|
|
523
|
+
const generics_js_1 = require("./generics.js");
|
|
524
|
+
const messages_media_js_1 = require("./messages-media.js");
|
|
525
|
+
const parseCatalogNode = (node) => {
|
|
526
|
+
const catalogNode = (0, index_js_2.getBinaryNodeChild)(node, 'product_catalog');
|
|
527
|
+
const products = (0, index_js_2.getBinaryNodeChildren)(catalogNode, 'product').map(exports.parseProductNode);
|
|
528
|
+
const paging = (0, index_js_2.getBinaryNodeChild)(catalogNode, 'paging');
|
|
529
|
+
return {
|
|
530
|
+
products,
|
|
531
|
+
nextPageCursor: paging ? (0, index_js_2.getBinaryNodeChildString)(paging, 'after') : undefined
|
|
532
|
+
};
|
|
533
|
+
};
|
|
534
|
+
exports.parseCatalogNode = parseCatalogNode;
|
|
535
|
+
const parseCollectionsNode = (node) => {
|
|
536
|
+
const collectionsNode = (0, index_js_2.getBinaryNodeChild)(node, 'collections');
|
|
537
|
+
const collections = (0, index_js_2.getBinaryNodeChildren)(collectionsNode, 'collection').map(collectionNode => {
|
|
538
|
+
const id = (0, index_js_2.getBinaryNodeChildString)(collectionNode, 'id');
|
|
539
|
+
const name = (0, index_js_2.getBinaryNodeChildString)(collectionNode, 'name');
|
|
540
|
+
const products = (0, index_js_2.getBinaryNodeChildren)(collectionNode, 'product').map(exports.parseProductNode);
|
|
541
|
+
return {
|
|
542
|
+
id,
|
|
543
|
+
name,
|
|
544
|
+
products,
|
|
545
|
+
status: parseStatusInfo(collectionNode)
|
|
546
|
+
};
|
|
547
|
+
});
|
|
548
|
+
return {
|
|
549
|
+
collections
|
|
550
|
+
};
|
|
551
|
+
};
|
|
552
|
+
exports.parseCollectionsNode = parseCollectionsNode;
|
|
553
|
+
const parseOrderDetailsNode = (node) => {
|
|
554
|
+
const orderNode = (0, index_js_2.getBinaryNodeChild)(node, 'order');
|
|
555
|
+
const products = (0, index_js_2.getBinaryNodeChildren)(orderNode, 'product').map(productNode => {
|
|
556
|
+
const imageNode = (0, index_js_2.getBinaryNodeChild)(productNode, 'image');
|
|
557
|
+
return {
|
|
558
|
+
id: (0, index_js_2.getBinaryNodeChildString)(productNode, 'id'),
|
|
559
|
+
name: (0, index_js_2.getBinaryNodeChildString)(productNode, 'name'),
|
|
560
|
+
imageUrl: (0, index_js_2.getBinaryNodeChildString)(imageNode, 'url'),
|
|
561
|
+
price: +(0, index_js_2.getBinaryNodeChildString)(productNode, 'price'),
|
|
562
|
+
currency: (0, index_js_2.getBinaryNodeChildString)(productNode, 'currency'),
|
|
563
|
+
quantity: +(0, index_js_2.getBinaryNodeChildString)(productNode, 'quantity')
|
|
564
|
+
};
|
|
565
|
+
});
|
|
566
|
+
const priceNode = (0, index_js_2.getBinaryNodeChild)(orderNode, 'price');
|
|
567
|
+
const orderDetails = {
|
|
568
|
+
price: {
|
|
569
|
+
total: +(0, index_js_2.getBinaryNodeChildString)(priceNode, 'total'),
|
|
570
|
+
currency: (0, index_js_2.getBinaryNodeChildString)(priceNode, 'currency')
|
|
571
|
+
},
|
|
572
|
+
products
|
|
573
|
+
};
|
|
574
|
+
return orderDetails;
|
|
575
|
+
};
|
|
576
|
+
exports.parseOrderDetailsNode = parseOrderDetailsNode;
|
|
577
|
+
const toProductNode = (productId, product) => {
|
|
578
|
+
const attrs = {};
|
|
579
|
+
const content = [];
|
|
580
|
+
if (typeof productId !== 'undefined') {
|
|
581
|
+
content.push({
|
|
582
|
+
tag: 'id',
|
|
583
|
+
attrs: {},
|
|
584
|
+
content: Buffer.from(productId)
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
if (typeof product.name !== 'undefined') {
|
|
588
|
+
content.push({
|
|
589
|
+
tag: 'name',
|
|
590
|
+
attrs: {},
|
|
591
|
+
content: Buffer.from(product.name)
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
if (typeof product.description !== 'undefined') {
|
|
595
|
+
content.push({
|
|
596
|
+
tag: 'description',
|
|
597
|
+
attrs: {},
|
|
598
|
+
content: Buffer.from(product.description)
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
if (typeof product.retailerId !== 'undefined') {
|
|
602
|
+
content.push({
|
|
603
|
+
tag: 'retailer_id',
|
|
604
|
+
attrs: {},
|
|
605
|
+
content: Buffer.from(product.retailerId)
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
if (product.images.length) {
|
|
609
|
+
content.push({
|
|
610
|
+
tag: 'media',
|
|
611
|
+
attrs: {},
|
|
612
|
+
content: product.images.map(img => {
|
|
613
|
+
if (!('url' in img)) {
|
|
614
|
+
throw new index_js_1.HttpError('Expected img for product to already be uploaded', { statusCode: 400 });
|
|
615
|
+
}
|
|
616
|
+
return {
|
|
617
|
+
tag: 'image',
|
|
618
|
+
attrs: {},
|
|
619
|
+
content: [
|
|
620
|
+
{
|
|
621
|
+
tag: 'url',
|
|
622
|
+
attrs: {},
|
|
623
|
+
content: Buffer.from(img.url.toString())
|
|
624
|
+
}
|
|
625
|
+
]
|
|
626
|
+
};
|
|
627
|
+
})
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
if (typeof product.price !== 'undefined') {
|
|
631
|
+
content.push({
|
|
632
|
+
tag: 'price',
|
|
633
|
+
attrs: {},
|
|
634
|
+
content: Buffer.from(product.price.toString())
|
|
635
|
+
});
|
|
636
|
+
}
|
|
637
|
+
if (typeof product.currency !== 'undefined') {
|
|
638
|
+
content.push({
|
|
639
|
+
tag: 'currency',
|
|
640
|
+
attrs: {},
|
|
641
|
+
content: Buffer.from(product.currency)
|
|
642
|
+
});
|
|
643
|
+
}
|
|
644
|
+
if ('originCountryCode' in product) {
|
|
645
|
+
if (typeof product.originCountryCode === 'undefined') {
|
|
646
|
+
attrs['compliance_category'] = 'COUNTRY_ORIGIN_EXEMPT';
|
|
647
|
+
}
|
|
648
|
+
else {
|
|
649
|
+
content.push({
|
|
650
|
+
tag: 'compliance_info',
|
|
651
|
+
attrs: {},
|
|
652
|
+
content: [
|
|
653
|
+
{
|
|
654
|
+
tag: 'country_code_origin',
|
|
655
|
+
attrs: {},
|
|
656
|
+
content: Buffer.from(product.originCountryCode)
|
|
657
|
+
}
|
|
658
|
+
]
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
if (typeof product.isHidden !== 'undefined') {
|
|
663
|
+
attrs['is_hidden'] = product.isHidden.toString();
|
|
664
|
+
}
|
|
665
|
+
const node = {
|
|
666
|
+
tag: 'product',
|
|
667
|
+
attrs,
|
|
668
|
+
content
|
|
669
|
+
};
|
|
670
|
+
return node;
|
|
671
|
+
};
|
|
672
|
+
exports.toProductNode = toProductNode;
|
|
673
|
+
const parseProductNode = (productNode) => {
|
|
674
|
+
const isHidden = productNode.attrs.is_hidden === 'true';
|
|
675
|
+
const id = (0, index_js_2.getBinaryNodeChildString)(productNode, 'id');
|
|
676
|
+
const mediaNode = (0, index_js_2.getBinaryNodeChild)(productNode, 'media');
|
|
677
|
+
const statusInfoNode = (0, index_js_2.getBinaryNodeChild)(productNode, 'status_info');
|
|
678
|
+
const product = {
|
|
679
|
+
id,
|
|
680
|
+
imageUrls: parseImageUrls(mediaNode),
|
|
681
|
+
reviewStatus: {
|
|
682
|
+
whatsapp: (0, index_js_2.getBinaryNodeChildString)(statusInfoNode, 'status')
|
|
683
|
+
},
|
|
684
|
+
availability: 'in stock',
|
|
685
|
+
name: (0, index_js_2.getBinaryNodeChildString)(productNode, 'name'),
|
|
686
|
+
retailerId: (0, index_js_2.getBinaryNodeChildString)(productNode, 'retailer_id'),
|
|
687
|
+
url: (0, index_js_2.getBinaryNodeChildString)(productNode, 'url'),
|
|
688
|
+
description: (0, index_js_2.getBinaryNodeChildString)(productNode, 'description'),
|
|
689
|
+
price: +(0, index_js_2.getBinaryNodeChildString)(productNode, 'price'),
|
|
690
|
+
currency: (0, index_js_2.getBinaryNodeChildString)(productNode, 'currency'),
|
|
691
|
+
isHidden
|
|
692
|
+
};
|
|
693
|
+
return product;
|
|
694
|
+
};
|
|
695
|
+
exports.parseProductNode = parseProductNode;
|
|
696
|
+
/**
|
|
697
|
+
* Uploads images not already uploaded to WA's servers
|
|
698
|
+
*/
|
|
699
|
+
async function uploadingNecessaryImagesOfProduct(product, waUploadToServer, timeoutMs = 30000) {
|
|
700
|
+
product = {
|
|
701
|
+
...product,
|
|
702
|
+
images: product.images
|
|
703
|
+
? await (0, exports.uploadingNecessaryImages)(product.images, waUploadToServer, timeoutMs)
|
|
704
|
+
: product.images
|
|
705
|
+
};
|
|
706
|
+
return product;
|
|
707
|
+
}
|
|
708
|
+
/**
|
|
709
|
+
* Uploads images not already uploaded to WA's servers
|
|
710
|
+
*/
|
|
711
|
+
const uploadingNecessaryImages = async (images, waUploadToServer, timeoutMs = 30000) => {
|
|
712
|
+
const results = await Promise.all(images.map(async (img) => {
|
|
713
|
+
if ('url' in img) {
|
|
714
|
+
const url = img.url.toString();
|
|
715
|
+
if (url.includes('.whatsapp.net')) {
|
|
716
|
+
return { url };
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
const { stream } = await (0, messages_media_js_1.getStream)(img);
|
|
720
|
+
const hasher = (0, crypto_1.createHash)('sha256');
|
|
721
|
+
const filePath = (0, path_1.join)((0, os_1.tmpdir)(), 'img' + (0, generics_js_1.generateMessageIDV2)());
|
|
722
|
+
const encFileWriteStream = (0, fs_1.createWriteStream)(filePath);
|
|
723
|
+
for await (const block of stream) {
|
|
724
|
+
hasher.update(block);
|
|
725
|
+
encFileWriteStream.write(block);
|
|
726
|
+
}
|
|
727
|
+
const sha = hasher.digest('base64');
|
|
728
|
+
const { directPath } = await waUploadToServer(filePath, {
|
|
729
|
+
mediaType: 'product-catalog-image',
|
|
730
|
+
fileEncSha256B64: sha,
|
|
731
|
+
timeoutMs
|
|
732
|
+
});
|
|
733
|
+
await fs_1.promises.unlink(filePath).catch(err => console.log('Error deleting temp file ', err));
|
|
734
|
+
return { url: (0, messages_media_js_1.getUrlFromDirectPath)(directPath) };
|
|
735
|
+
}));
|
|
736
|
+
return results;
|
|
737
|
+
};
|
|
738
|
+
exports.uploadingNecessaryImages = uploadingNecessaryImages;
|
|
739
|
+
const parseImageUrls = (mediaNode) => {
|
|
740
|
+
const imgNode = (0, index_js_2.getBinaryNodeChild)(mediaNode, 'image');
|
|
741
|
+
return {
|
|
742
|
+
requested: (0, index_js_2.getBinaryNodeChildString)(imgNode, 'request_image_url'),
|
|
743
|
+
original: (0, index_js_2.getBinaryNodeChildString)(imgNode, 'original_image_url')
|
|
744
|
+
};
|
|
745
|
+
};
|
|
746
|
+
const parseStatusInfo = (mediaNode) => {
|
|
747
|
+
const node = (0, index_js_2.getBinaryNodeChild)(mediaNode, 'status_info');
|
|
748
|
+
return {
|
|
749
|
+
status: (0, index_js_2.getBinaryNodeChildString)(node, 'status'),
|
|
750
|
+
canAppeal: (0, index_js_2.getBinaryNodeChildString)(node, 'can_appeal') === 'true'
|
|
751
|
+
};
|
|
752
|
+
};
|
|
753
|
+
|
|
754
|
+
return module.exports;
|
|
755
|
+
})();
|
|
756
|
+
for (const key of Object.keys(__kageModule163)) {
|
|
757
|
+
if (key !== '__esModule' && !Object.prototype.hasOwnProperty.call(exports,key)) Object.defineProperty(exports,key,{enumerable:true,configurable:true,get:()=>__kageModule163[key]});
|
|
758
|
+
}
|
|
759
|
+
Object.defineProperty(exports, Symbol.for('kage.advanced'), {value:__kageModule163, configurable:true});
|