nrx-bails 0.0.1
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/LICENSE +21 -0
- package/README.md +1541 -0
- package/WAProto/GenerateStatics.sh +4 -0
- package/WAProto/WAProto.proto +4775 -0
- package/WAProto/index.d.ts +2 -0
- package/WAProto/index.js +169661 -0
- package/lib/Defaults/index.d.ts +113 -0
- package/lib/Defaults/index.js +156 -0
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Defaults/ye-bail-version.json +3 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
- package/lib/Signal/Group/ciphertext-message.js +41 -0
- package/lib/Signal/Group/group-session-builder.d.ts +8 -0
- package/lib/Signal/Group/group-session-builder.js +90 -0
- package/lib/Signal/Group/group_cipher.d.ts +12 -0
- package/lib/Signal/Group/group_cipher.js +122 -0
- package/lib/Signal/Group/index.d.ts +22 -0
- package/lib/Signal/Group/index.js +83 -0
- package/lib/Signal/Group/keyhelper.d.ts +7 -0
- package/lib/Signal/Group/keyhelper.js +81 -0
- package/lib/Signal/Group/queue-job.d.ts +3 -0
- package/lib/Signal/Group/queue-job.js +83 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-chain-key.js +60 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +92 -0
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-message.js +95 -0
- package/lib/Signal/Group/sender-key-name.d.ts +12 -0
- package/lib/Signal/Group/sender-key-name.js +77 -0
- package/lib/Signal/Group/sender-key-record.d.ts +13 -0
- package/lib/Signal/Group/sender-key-record.js +79 -0
- package/lib/Signal/Group/sender-key-state.d.ts +17 -0
- package/lib/Signal/Group/sender-key-state.js +125 -0
- package/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/lib/Signal/Group/sender-message-key.js +55 -0
- package/lib/Signal/libsignal.d.ts +37 -0
- package/lib/Signal/libsignal.js +200 -0
- package/lib/Socket/Client/index.d.ts +1 -0
- package/lib/Socket/Client/index.js +44 -0
- package/lib/Socket/Client/types.d.ts +7 -0
- package/lib/Socket/Client/types.js +39 -0
- package/lib/Socket/Client/websocket.d.ts +19 -0
- package/lib/Socket/Client/websocket.js +137 -0
- package/lib/Socket/business.d.ts +329 -0
- package/lib/Socket/business.js +286 -0
- package/lib/Socket/chats.d.ts +84 -0
- package/lib/Socket/chats.js +1022 -0
- package/lib/Socket/groups.d.ts +216 -0
- package/lib/Socket/groups.js +358 -0
- package/lib/Socket/index.d.ts +330 -0
- package/lib/Socket/index.js +36 -0
- package/lib/Socket/messages-recv.d.ts +271 -0
- package/lib/Socket/messages-recv.js +1079 -0
- package/lib/Socket/messages-send.d.ts +258 -0
- package/lib/Socket/messages-send.js +1190 -0
- package/lib/Socket/newsletter.d.ts +253 -0
- package/lib/Socket/newsletter.js +362 -0
- package/lib/Socket/registration.d.ts +361 -0
- package/lib/Socket/registration.js +179 -0
- package/lib/Socket/socket.d.ts +33 -0
- package/lib/Socket/socket.js +699 -0
- package/lib/Socket/usync.d.ts +27 -0
- package/lib/Socket/usync.js +96 -0
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/index.js +36 -0
- package/lib/Store/make-cache-manager-auth-state.d.ts +16 -0
- package/lib/Store/make-cache-manager-auth-state.js +118 -0
- package/lib/Store/make-in-memory-store.d.ts +64 -0
- package/lib/Store/make-in-memory-store.js +465 -0
- package/lib/Store/make-ordered-dictionary.d.ts +14 -0
- package/lib/Store/make-ordered-dictionary.js +107 -0
- package/lib/Store/object-repository.d.ts +11 -0
- package/lib/Store/object-repository.js +53 -0
- package/lib/Types/Auth.d.ts +1 -0
- package/lib/Types/Auth.js +28 -0
- package/lib/Types/Call.d.ts +1 -0
- package/lib/Types/Call.js +28 -0
- package/lib/Types/Chat.d.ts +2 -0
- package/lib/Types/Chat.js +30 -0
- package/lib/Types/Contact.d.ts +1 -0
- package/lib/Types/Contact.js +28 -0
- package/lib/Types/Events.d.ts +1 -0
- package/lib/Types/Events.js +28 -0
- package/lib/Types/GroupMetadata.d.ts +1 -0
- package/lib/Types/GroupMetadata.js +28 -0
- package/lib/Types/Label.d.ts +2 -0
- package/lib/Types/Label.js +53 -0
- package/lib/Types/LabelAssociation.d.ts +2 -0
- package/lib/Types/LabelAssociation.js +35 -0
- package/lib/Types/Message.d.ts +2 -0
- package/lib/Types/Message.js +33 -0
- package/lib/Types/Newsletter.d.ts +4 -0
- package/lib/Types/Newsletter.js +62 -0
- package/lib/Types/Product.d.ts +1 -0
- package/lib/Types/Product.js +28 -0
- package/lib/Types/Signal.d.ts +1 -0
- package/lib/Types/Signal.js +28 -0
- package/lib/Types/Socket.d.ts +1 -0
- package/lib/Types/Socket.js +28 -0
- package/lib/Types/State.d.ts +1 -0
- package/lib/Types/State.js +28 -0
- package/lib/Types/USync.d.ts +1 -0
- package/lib/Types/USync.js +28 -0
- package/lib/Types/index.d.ts +2 -0
- package/lib/Types/index.js +68 -0
- package/lib/Utils/auth-utils.d.ts +63 -0
- package/lib/Utils/auth-utils.js +248 -0
- package/lib/Utils/browser-utils.d.ts +3 -0
- package/lib/Utils/browser-utils.js +61 -0
- package/lib/Utils/business.d.ts +53 -0
- package/lib/Utils/business.js +260 -0
- package/lib/Utils/chat-utils.d.ts +253 -0
- package/lib/Utils/chat-utils.js +756 -0
- package/lib/Utils/crypto.d.ts +43 -0
- package/lib/Utils/crypto.js +219 -0
- package/lib/Utils/decode-wa-message.d.ts +61 -0
- package/lib/Utils/decode-wa-message.js +233 -0
- package/lib/Utils/event-buffer.d.ts +17 -0
- package/lib/Utils/event-buffer.js +544 -0
- package/lib/Utils/generics.d.ts +89 -0
- package/lib/Utils/generics.js +471 -0
- package/lib/Utils/history.d.ts +59 -0
- package/lib/Utils/history.js +120 -0
- package/lib/Utils/index.d.ts +1 -0
- package/lib/Utils/index.js +61 -0
- package/lib/Utils/link-preview.d.ts +19 -0
- package/lib/Utils/link-preview.js +152 -0
- package/lib/Utils/logger.d.ts +3 -0
- package/lib/Utils/logger.js +33 -0
- package/lib/Utils/lt-hash.d.ts +13 -0
- package/lib/Utils/lt-hash.js +77 -0
- package/lib/Utils/make-mutex.d.ts +7 -0
- package/lib/Utils/make-mutex.js +69 -0
- package/lib/Utils/message-retry-manager.d.ts +34 -0
- package/lib/Utils/message-retry-manager.js +154 -0
- package/lib/Utils/messages-media.d.ts +137 -0
- package/lib/Utils/messages-media.js +1024 -0
- package/lib/Utils/messages.d.ts +66 -0
- package/lib/Utils/messages.js +1407 -0
- package/lib/Utils/noise-handler.d.ts +21 -0
- package/lib/Utils/noise-handler.js +176 -0
- package/lib/Utils/pre-key-manager.d.ts +13 -0
- package/lib/Utils/pre-key-manager.js +93 -0
- package/lib/Utils/process-message.d.ts +40 -0
- package/lib/Utils/process-message.js +430 -0
- package/lib/Utils/signal.d.ts +72 -0
- package/lib/Utils/signal.js +179 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +18 -0
- package/lib/Utils/use-multi-file-auth-state.js +151 -0
- package/lib/Utils/validate-connection.d.ts +43 -0
- package/lib/Utils/validate-connection.js +255 -0
- package/lib/Utils/ye-bail-event-stream.d.ts +16 -0
- package/lib/Utils/ye-bail-event-stream.js +89 -0
- package/lib/WABinary/constants.d.ts +23 -0
- package/lib/WABinary/constants.js +1328 -0
- package/lib/WABinary/decode.d.ts +10 -0
- package/lib/WABinary/decode.js +291 -0
- package/lib/WABinary/encode.d.ts +2 -0
- package/lib/WABinary/encode.js +276 -0
- package/lib/WABinary/generic-utils.d.ts +16 -0
- package/lib/WABinary/generic-utils.js +155 -0
- package/lib/WABinary/index.d.ts +1 -0
- package/lib/WABinary/index.js +47 -0
- package/lib/WABinary/jid-utils.d.ts +34 -0
- package/lib/WABinary/jid-utils.js +111 -0
- package/lib/WABinary/types.d.ts +1 -0
- package/lib/WABinary/types.js +28 -0
- package/lib/WAM/BinaryInfo.d.ts +8 -0
- package/lib/WAM/BinaryInfo.js +39 -0
- package/lib/WAM/constants.d.ts +35374 -0
- package/lib/WAM/constants.js +15376 -0
- package/lib/WAM/encode.d.ts +2 -0
- package/lib/WAM/encode.js +181 -0
- package/lib/WAM/index.d.ts +1 -0
- package/lib/WAM/index.js +45 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +14 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +58 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +83 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +56 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +68 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +39 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +79 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +50 -0
- package/lib/WAUSync/Protocols/index.d.ts +1 -0
- package/lib/WAUSync/Protocols/index.js +46 -0
- package/lib/WAUSync/USyncQuery.d.ts +20 -0
- package/lib/WAUSync/USyncQuery.js +115 -0
- package/lib/WAUSync/USyncUser.d.ts +13 -0
- package/lib/WAUSync/USyncUser.js +52 -0
- package/lib/WAUSync/index.d.ts +1 -0
- package/lib/WAUSync/index.js +45 -0
- package/lib/index.js +81 -0
- package/package.json +113 -0
- package/requirements.js +32 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export const __esModule: boolean;
|
|
2
|
+
/**
|
|
3
|
+
* Adds caching capability to a SignalKeyStore
|
|
4
|
+
* @param store the store to add caching to
|
|
5
|
+
* @param logger to log trace events
|
|
6
|
+
* @param _cache cache store to use
|
|
7
|
+
*/
|
|
8
|
+
export function makeCacheableSignalKeyStore(store: any, logger: any, _cache: any): {
|
|
9
|
+
get(type: any, ids: any): Promise<{}>;
|
|
10
|
+
set(data: any): Promise<void>;
|
|
11
|
+
clear(): Promise<void>;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Adds DB like transaction capability (https://en.wikipedia.org/wiki/Database_transaction) to the SignalKeyStore,
|
|
15
|
+
* this allows batch read & write operations & improves the performance of the lib
|
|
16
|
+
* @param state the key store to apply this capability to
|
|
17
|
+
* @param logger logger to log events
|
|
18
|
+
* @returns SignalKeyStore with transaction capability
|
|
19
|
+
*/
|
|
20
|
+
export function addTransactionCapability(state: any, logger: any, { maxCommitRetries, delayBetweenTriesMs }: {
|
|
21
|
+
maxCommitRetries: any;
|
|
22
|
+
delayBetweenTriesMs: any;
|
|
23
|
+
}): {
|
|
24
|
+
get: (type: any, ids: any) => Promise<any>;
|
|
25
|
+
set: (data: any) => Promise<void>;
|
|
26
|
+
isInTransaction: () => boolean;
|
|
27
|
+
transaction(work: any, key: any): Promise<any>;
|
|
28
|
+
};
|
|
29
|
+
export function initAuthCreds(): {
|
|
30
|
+
noiseKey: {
|
|
31
|
+
private: Buffer<any>;
|
|
32
|
+
public: Buffer<any>;
|
|
33
|
+
};
|
|
34
|
+
pairingEphemeralKeyPair: {
|
|
35
|
+
private: Buffer<any>;
|
|
36
|
+
public: Buffer<any>;
|
|
37
|
+
};
|
|
38
|
+
signedIdentityKey: {
|
|
39
|
+
private: Buffer<any>;
|
|
40
|
+
public: Buffer<any>;
|
|
41
|
+
};
|
|
42
|
+
signedPreKey: {
|
|
43
|
+
keyPair: {
|
|
44
|
+
private: Buffer<any>;
|
|
45
|
+
public: Buffer<any>;
|
|
46
|
+
};
|
|
47
|
+
signature: any;
|
|
48
|
+
keyId: any;
|
|
49
|
+
};
|
|
50
|
+
registrationId: number;
|
|
51
|
+
advSecretKey: string;
|
|
52
|
+
processedHistoryMessages: any[];
|
|
53
|
+
nextPreKeyId: number;
|
|
54
|
+
firstUnuploadedPreKeyId: number;
|
|
55
|
+
accountSyncCounter: number;
|
|
56
|
+
accountSettings: {
|
|
57
|
+
unarchiveChats: boolean;
|
|
58
|
+
};
|
|
59
|
+
registered: boolean;
|
|
60
|
+
pairingCode: any;
|
|
61
|
+
lastPropHash: any;
|
|
62
|
+
routingInfo: any;
|
|
63
|
+
};
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ╔═══════════════════════════════════════════════════════════╗
|
|
3
|
+
* ║ NEROX - WhatsApp API Library ║
|
|
4
|
+
* ║ Premium Edition ║
|
|
5
|
+
* ╚═══════════════════════════════════════════════════════════╝
|
|
6
|
+
*
|
|
7
|
+
* @package nerox-bails
|
|
8
|
+
* @version 0.1.0
|
|
9
|
+
* @author NEROX Development Team
|
|
10
|
+
* @copyright Copyright (c) 2025 NEROX. All rights reserved.
|
|
11
|
+
* @license MIT License
|
|
12
|
+
*
|
|
13
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
14
|
+
* a copy of this software and associated documentation files (the "Software"),
|
|
15
|
+
* to deal in the Software without restriction, including without limitation
|
|
16
|
+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
17
|
+
* and/or sell copies of the Software, and to permit persons to whom the
|
|
18
|
+
* Software is furnished to do so, subject to the following conditions:
|
|
19
|
+
*
|
|
20
|
+
* The above copyright notice and this permission notice shall be included
|
|
21
|
+
* in all copies or substantial portions of the Software.
|
|
22
|
+
*
|
|
23
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
24
|
+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
26
|
+
*/
|
|
27
|
+
"use strict";
|
|
28
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
29
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
30
|
+
};
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
exports.initAuthCreds = exports.addTransactionCapability = void 0;
|
|
33
|
+
exports.makeCacheableSignalKeyStore = makeCacheableSignalKeyStore;
|
|
34
|
+
const crypto_1 = require("crypto");
|
|
35
|
+
const async_hooks_1 = require("async_hooks");
|
|
36
|
+
const async_mutex_1 = require("async-mutex");
|
|
37
|
+
const p_queue_1 = __importDefault(require("p-queue"));
|
|
38
|
+
const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
|
|
39
|
+
const Defaults_1 = require("../Defaults");
|
|
40
|
+
const crypto_2 = require("./crypto");
|
|
41
|
+
const generics_1 = require("./generics");
|
|
42
|
+
const pre_key_manager_1 = require("./pre-key-manager");
|
|
43
|
+
/**
|
|
44
|
+
* Adds caching capability to a SignalKeyStore
|
|
45
|
+
* @param store the store to add caching to
|
|
46
|
+
* @param logger to log trace events
|
|
47
|
+
* @param _cache cache store to use
|
|
48
|
+
*/
|
|
49
|
+
function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
50
|
+
const cache = _cache || new node_cache_1.default({
|
|
51
|
+
stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.SIGNAL_STORE,
|
|
52
|
+
useClones: false,
|
|
53
|
+
deleteOnExpire: true,
|
|
54
|
+
});
|
|
55
|
+
function getUniqueId(type, id) {
|
|
56
|
+
return `${type}.${id}`;
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
async get(type, ids) {
|
|
60
|
+
const data = {};
|
|
61
|
+
const idsToFetch = [];
|
|
62
|
+
for (const id of ids) {
|
|
63
|
+
const item = cache.get(getUniqueId(type, id));
|
|
64
|
+
if (typeof item !== 'undefined') {
|
|
65
|
+
data[id] = item;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
idsToFetch.push(id);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (idsToFetch.length) {
|
|
72
|
+
logger === null || logger === void 0 ? void 0 : logger.trace({ items: idsToFetch.length }, 'loading from store');
|
|
73
|
+
const fetched = await store.get(type, idsToFetch);
|
|
74
|
+
for (const id of idsToFetch) {
|
|
75
|
+
const item = fetched[id];
|
|
76
|
+
if (item) {
|
|
77
|
+
data[id] = item;
|
|
78
|
+
cache.set(getUniqueId(type, id), item);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return data;
|
|
83
|
+
},
|
|
84
|
+
async set(data) {
|
|
85
|
+
let keys = 0;
|
|
86
|
+
for (const type in data) {
|
|
87
|
+
for (const id in data[type]) {
|
|
88
|
+
cache.set(getUniqueId(type, id), data[type][id]);
|
|
89
|
+
keys += 1;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
logger === null || logger === void 0 ? void 0 : logger.trace({ keys }, 'updated cache');
|
|
93
|
+
await store.set(data);
|
|
94
|
+
},
|
|
95
|
+
async clear() {
|
|
96
|
+
var _a;
|
|
97
|
+
cache.flushAll();
|
|
98
|
+
await ((_a = store.clear) === null || _a === void 0 ? void 0 : _a.call(store));
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetweenTriesMs }) => {
|
|
103
|
+
const txStorage = new async_hooks_1.AsyncLocalStorage();
|
|
104
|
+
const keyQueues = new Map();
|
|
105
|
+
const txMutexes = new Map();
|
|
106
|
+
const preKeyManager = new pre_key_manager_1.PreKeyManager(state, logger);
|
|
107
|
+
function getQueue(key) {
|
|
108
|
+
if (!keyQueues.has(key)) {
|
|
109
|
+
keyQueues.set(key, new p_queue_1.default({ concurrency: 1 }));
|
|
110
|
+
}
|
|
111
|
+
return keyQueues.get(key);
|
|
112
|
+
}
|
|
113
|
+
function getTxMutex(key) {
|
|
114
|
+
if (!txMutexes.has(key)) {
|
|
115
|
+
txMutexes.set(key, new async_mutex_1.Mutex());
|
|
116
|
+
}
|
|
117
|
+
return txMutexes.get(key);
|
|
118
|
+
}
|
|
119
|
+
function isInTransaction() {
|
|
120
|
+
return !!txStorage.getStore();
|
|
121
|
+
}
|
|
122
|
+
async function commitWithRetry(mutationSet) {
|
|
123
|
+
if (Object.keys(mutationSet).length === 0) {
|
|
124
|
+
logger === null || logger === void 0 ? void 0 : logger.trace('no mutations in transaction');
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
logger === null || logger === void 0 ? void 0 : logger.trace('committing transaction');
|
|
128
|
+
for (let attempt = 0; attempt < maxCommitRetries; attempt++) {
|
|
129
|
+
try {
|
|
130
|
+
await state.set(mutationSet);
|
|
131
|
+
logger === null || logger === void 0 ? void 0 : logger.trace({ mutationCount: Object.keys(mutationSet).length }, 'committed transaction');
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
const retriesLeft = maxCommitRetries - attempt - 1;
|
|
136
|
+
logger === null || logger === void 0 ? void 0 : logger.warn(`failed to commit mutations, retries left=${retriesLeft}`);
|
|
137
|
+
if (retriesLeft === 0) {
|
|
138
|
+
throw error;
|
|
139
|
+
}
|
|
140
|
+
await (0, generics_1.delay)(delayBetweenTriesMs);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return {
|
|
145
|
+
get: async (type, ids) => {
|
|
146
|
+
const ctx = txStorage.getStore();
|
|
147
|
+
if (!ctx) {
|
|
148
|
+
return state.get(type, ids);
|
|
149
|
+
}
|
|
150
|
+
const cached = ctx.cache[type] || {};
|
|
151
|
+
const missing = ids.filter(id => !(id in cached));
|
|
152
|
+
if (missing.length > 0) {
|
|
153
|
+
ctx.dbQueries += 1;
|
|
154
|
+
logger === null || logger === void 0 ? void 0 : logger.trace({ type, count: missing.length }, 'fetching missing keys in transaction');
|
|
155
|
+
const fetched = await getTxMutex(type).runExclusive(() => state.get(type, missing));
|
|
156
|
+
ctx.cache[type] = ctx.cache[type] || {};
|
|
157
|
+
Object.assign(ctx.cache[type], fetched);
|
|
158
|
+
}
|
|
159
|
+
const result = {};
|
|
160
|
+
for (const id of ids) {
|
|
161
|
+
var _a;
|
|
162
|
+
const value = (_a = ctx.cache[type]) === null || _a === void 0 ? void 0 : _a[id];
|
|
163
|
+
if (value !== undefined && value !== null) {
|
|
164
|
+
result[id] = value;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return result;
|
|
168
|
+
},
|
|
169
|
+
set: async data => {
|
|
170
|
+
const ctx = txStorage.getStore();
|
|
171
|
+
if (!ctx) {
|
|
172
|
+
const types = Object.keys(data);
|
|
173
|
+
for (const type of types) {
|
|
174
|
+
if (type === 'pre-key') {
|
|
175
|
+
await preKeyManager.validateDeletions(data, type);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
await Promise.all(types.map(type => getQueue(type).add(async () => {
|
|
179
|
+
const typeData = { [type]: data[type] };
|
|
180
|
+
await state.set(typeData);
|
|
181
|
+
})));
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
logger === null || logger === void 0 ? void 0 : logger.trace({ types: Object.keys(data) }, 'caching in transaction');
|
|
185
|
+
for (const key in data) {
|
|
186
|
+
ctx.cache[key] = ctx.cache[key] || {};
|
|
187
|
+
ctx.mutations[key] = ctx.mutations[key] || {};
|
|
188
|
+
if (key === 'pre-key') {
|
|
189
|
+
await preKeyManager.processOperations(data, key, ctx.cache, ctx.mutations, true);
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
Object.assign(ctx.cache[key], data[key]);
|
|
193
|
+
Object.assign(ctx.mutations[key], data[key]);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
isInTransaction,
|
|
198
|
+
transaction: async (work, key) => {
|
|
199
|
+
const existing = txStorage.getStore();
|
|
200
|
+
if (existing) {
|
|
201
|
+
logger === null || logger === void 0 ? void 0 : logger.trace('reusing existing transaction context');
|
|
202
|
+
return work();
|
|
203
|
+
}
|
|
204
|
+
return getTxMutex(key).runExclusive(async () => {
|
|
205
|
+
const ctx = {
|
|
206
|
+
cache: {},
|
|
207
|
+
mutations: {},
|
|
208
|
+
dbQueries: 0
|
|
209
|
+
};
|
|
210
|
+
logger === null || logger === void 0 ? void 0 : logger.trace('entering transaction');
|
|
211
|
+
try {
|
|
212
|
+
const result = await txStorage.run(ctx, work);
|
|
213
|
+
await commitWithRetry(ctx.mutations);
|
|
214
|
+
logger === null || logger === void 0 ? void 0 : logger.trace({ dbQueries: ctx.dbQueries }, 'transaction completed');
|
|
215
|
+
return result;
|
|
216
|
+
}
|
|
217
|
+
catch (error) {
|
|
218
|
+
logger === null || logger === void 0 ? void 0 : logger.error({ error }, 'transaction failed, rolling back');
|
|
219
|
+
throw error;
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
};
|
|
225
|
+
exports.addTransactionCapability = addTransactionCapability;
|
|
226
|
+
const initAuthCreds = () => {
|
|
227
|
+
const identityKey = crypto_2.Curve.generateKeyPair();
|
|
228
|
+
return {
|
|
229
|
+
noiseKey: crypto_2.Curve.generateKeyPair(),
|
|
230
|
+
pairingEphemeralKeyPair: crypto_2.Curve.generateKeyPair(),
|
|
231
|
+
signedIdentityKey: identityKey,
|
|
232
|
+
signedPreKey: (0, crypto_2.signedKeyPair)(identityKey, 1),
|
|
233
|
+
registrationId: (0, generics_1.generateRegistrationId)(),
|
|
234
|
+
advSecretKey: (0, crypto_1.randomBytes)(32).toString('base64'),
|
|
235
|
+
processedHistoryMessages: [],
|
|
236
|
+
nextPreKeyId: 1,
|
|
237
|
+
firstUnuploadedPreKeyId: 1,
|
|
238
|
+
accountSyncCounter: 0,
|
|
239
|
+
accountSettings: {
|
|
240
|
+
unarchiveChats: false
|
|
241
|
+
},
|
|
242
|
+
registered: false,
|
|
243
|
+
pairingCode: undefined,
|
|
244
|
+
lastPropHash: undefined,
|
|
245
|
+
routingInfo: undefined,
|
|
246
|
+
};
|
|
247
|
+
};
|
|
248
|
+
exports.initAuthCreds = initAuthCreds;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ╔═══════════════════════════════════════════════════════════╗
|
|
3
|
+
* ║ NEROX - WhatsApp API Library ║
|
|
4
|
+
* ║ Premium Edition ║
|
|
5
|
+
* ╚═══════════════════════════════════════════════════════════╝
|
|
6
|
+
*
|
|
7
|
+
* @package nerox-bails
|
|
8
|
+
* @version 0.1.0
|
|
9
|
+
* @author NEROX Development Team
|
|
10
|
+
* @copyright Copyright (c) 2025 NEROX. All rights reserved.
|
|
11
|
+
* @license MIT License
|
|
12
|
+
*
|
|
13
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
14
|
+
* a copy of this software and associated documentation files (the "Software"),
|
|
15
|
+
* to deal in the Software without restriction, including without limitation
|
|
16
|
+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
17
|
+
* and/or sell copies of the Software, and to permit persons to whom the
|
|
18
|
+
* Software is furnished to do so, subject to the following conditions:
|
|
19
|
+
*
|
|
20
|
+
* The above copyright notice and this permission notice shall be included
|
|
21
|
+
* in all copies or substantial portions of the Software.
|
|
22
|
+
*
|
|
23
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
24
|
+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
26
|
+
*/
|
|
27
|
+
"use strict";
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.getPlatformId = exports.Browsers = void 0;
|
|
30
|
+
|
|
31
|
+
const os = require("os");
|
|
32
|
+
const { proto } = require("../../WAProto/index.js");
|
|
33
|
+
|
|
34
|
+
const PLATFORM_MAP = {
|
|
35
|
+
'aix': 'AIX',
|
|
36
|
+
'darwin': 'Mac OS',
|
|
37
|
+
'win32': 'Windows',
|
|
38
|
+
'android': 'Android',
|
|
39
|
+
'freebsd': 'FreeBSD',
|
|
40
|
+
'openbsd': 'OpenBSD',
|
|
41
|
+
'sunos': 'Solaris',
|
|
42
|
+
'linux': undefined,
|
|
43
|
+
'haiku': undefined,
|
|
44
|
+
'cygwin': undefined,
|
|
45
|
+
'netbsd': undefined
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
exports.Browsers = (browser) => {
|
|
51
|
+
const osName = PLATFORM_MAP[os.platform()] || 'Ubuntu';
|
|
52
|
+
const osRelease = os.release();
|
|
53
|
+
return [osName, browser, osRelease];
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const getPlatformId = (browser) => {
|
|
57
|
+
const platformType = proto.DeviceProps.PlatformType[browser.toUpperCase()];
|
|
58
|
+
return platformType ? platformType.toString() : '1';
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
exports.getPlatformId = getPlatformId;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export const __esModule: boolean;
|
|
2
|
+
/**
|
|
3
|
+
* Uploads images not already uploaded to WA's servers
|
|
4
|
+
*/
|
|
5
|
+
export function uploadingNecessaryImagesOfProduct(product: any, waUploadToServer: any, timeoutMs?: number): Promise<any>;
|
|
6
|
+
export function parseCatalogNode(node: any): {
|
|
7
|
+
products: any;
|
|
8
|
+
nextPageCursor: any;
|
|
9
|
+
};
|
|
10
|
+
export function parseCollectionsNode(node: any): {
|
|
11
|
+
collections: any;
|
|
12
|
+
};
|
|
13
|
+
export function parseOrderDetailsNode(node: any): {
|
|
14
|
+
price: {
|
|
15
|
+
total: number;
|
|
16
|
+
currency: any;
|
|
17
|
+
};
|
|
18
|
+
products: any;
|
|
19
|
+
};
|
|
20
|
+
export function toProductNode(productId: any, product: any): {
|
|
21
|
+
tag: string;
|
|
22
|
+
attrs: {
|
|
23
|
+
compliance_category: string;
|
|
24
|
+
is_hidden: any;
|
|
25
|
+
};
|
|
26
|
+
content: {
|
|
27
|
+
tag: string;
|
|
28
|
+
attrs: {};
|
|
29
|
+
content: any;
|
|
30
|
+
}[];
|
|
31
|
+
};
|
|
32
|
+
export function parseProductNode(productNode: any): {
|
|
33
|
+
id: any;
|
|
34
|
+
imageUrls: {
|
|
35
|
+
requested: any;
|
|
36
|
+
original: any;
|
|
37
|
+
};
|
|
38
|
+
reviewStatus: {
|
|
39
|
+
whatsapp: any;
|
|
40
|
+
};
|
|
41
|
+
availability: string;
|
|
42
|
+
name: any;
|
|
43
|
+
retailerId: any;
|
|
44
|
+
url: any;
|
|
45
|
+
description: any;
|
|
46
|
+
price: number;
|
|
47
|
+
currency: any;
|
|
48
|
+
isHidden: boolean;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Uploads images not already uploaded to WA's servers
|
|
52
|
+
*/
|
|
53
|
+
export function uploadingNecessaryImages(images: any, waUploadToServer: any, timeoutMs?: number): Promise<any[]>;
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ╔═══════════════════════════════════════════════════════════╗
|
|
3
|
+
* ║ NEROX - WhatsApp API Library ║
|
|
4
|
+
* ║ Premium Edition ║
|
|
5
|
+
* ╚═══════════════════════════════════════════════════════════╝
|
|
6
|
+
*
|
|
7
|
+
* @package nerox-bails
|
|
8
|
+
* @version 0.1.0
|
|
9
|
+
* @author NEROX Development Team
|
|
10
|
+
* @copyright Copyright (c) 2025 NEROX. All rights reserved.
|
|
11
|
+
* @license MIT License
|
|
12
|
+
*
|
|
13
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
14
|
+
* a copy of this software and associated documentation files (the "Software"),
|
|
15
|
+
* to deal in the Software without restriction, including without limitation
|
|
16
|
+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
17
|
+
* and/or sell copies of the Software, and to permit persons to whom the
|
|
18
|
+
* Software is furnished to do so, subject to the following conditions:
|
|
19
|
+
*
|
|
20
|
+
* The above copyright notice and this permission notice shall be included
|
|
21
|
+
* in all copies or substantial portions of the Software.
|
|
22
|
+
*
|
|
23
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
24
|
+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
26
|
+
*/
|
|
27
|
+
"use strict";
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.uploadingNecessaryImages = exports.parseProductNode = exports.toProductNode = exports.parseOrderDetailsNode = exports.parseCollectionsNode = exports.parseCatalogNode = void 0;
|
|
30
|
+
exports.uploadingNecessaryImagesOfProduct = uploadingNecessaryImagesOfProduct;
|
|
31
|
+
const boom_1 = require("@hapi/boom");
|
|
32
|
+
const crypto_1 = require("crypto");
|
|
33
|
+
const WABinary_1 = require("../WABinary");
|
|
34
|
+
const messages_media_1 = require("./messages-media");
|
|
35
|
+
const parseCatalogNode = (node) => {
|
|
36
|
+
const catalogNode = (0, WABinary_1.getBinaryNodeChild)(node, 'product_catalog');
|
|
37
|
+
const products = (0, WABinary_1.getBinaryNodeChildren)(catalogNode, 'product').map(exports.parseProductNode);
|
|
38
|
+
const paging = (0, WABinary_1.getBinaryNodeChild)(catalogNode, 'paging');
|
|
39
|
+
return {
|
|
40
|
+
products,
|
|
41
|
+
nextPageCursor: paging
|
|
42
|
+
? (0, WABinary_1.getBinaryNodeChildString)(paging, 'after')
|
|
43
|
+
: undefined
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
exports.parseCatalogNode = parseCatalogNode;
|
|
47
|
+
const parseCollectionsNode = (node) => {
|
|
48
|
+
const collectionsNode = (0, WABinary_1.getBinaryNodeChild)(node, 'collections');
|
|
49
|
+
const collections = (0, WABinary_1.getBinaryNodeChildren)(collectionsNode, 'collection').map(collectionNode => {
|
|
50
|
+
const id = (0, WABinary_1.getBinaryNodeChildString)(collectionNode, 'id');
|
|
51
|
+
const name = (0, WABinary_1.getBinaryNodeChildString)(collectionNode, 'name');
|
|
52
|
+
const products = (0, WABinary_1.getBinaryNodeChildren)(collectionNode, 'product').map(exports.parseProductNode);
|
|
53
|
+
return {
|
|
54
|
+
id,
|
|
55
|
+
name,
|
|
56
|
+
products,
|
|
57
|
+
status: parseStatusInfo(collectionNode)
|
|
58
|
+
};
|
|
59
|
+
});
|
|
60
|
+
return {
|
|
61
|
+
collections
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
exports.parseCollectionsNode = parseCollectionsNode;
|
|
65
|
+
const parseOrderDetailsNode = (node) => {
|
|
66
|
+
const orderNode = (0, WABinary_1.getBinaryNodeChild)(node, 'order');
|
|
67
|
+
const products = (0, WABinary_1.getBinaryNodeChildren)(orderNode, 'product').map(productNode => {
|
|
68
|
+
const imageNode = (0, WABinary_1.getBinaryNodeChild)(productNode, 'image');
|
|
69
|
+
return {
|
|
70
|
+
id: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'id'),
|
|
71
|
+
name: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'name'),
|
|
72
|
+
imageUrl: (0, WABinary_1.getBinaryNodeChildString)(imageNode, 'url'),
|
|
73
|
+
price: +(0, WABinary_1.getBinaryNodeChildString)(productNode, 'price'),
|
|
74
|
+
currency: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'currency'),
|
|
75
|
+
quantity: +(0, WABinary_1.getBinaryNodeChildString)(productNode, 'quantity')
|
|
76
|
+
};
|
|
77
|
+
});
|
|
78
|
+
const priceNode = (0, WABinary_1.getBinaryNodeChild)(orderNode, 'price');
|
|
79
|
+
const orderDetails = {
|
|
80
|
+
price: {
|
|
81
|
+
total: +(0, WABinary_1.getBinaryNodeChildString)(priceNode, 'total'),
|
|
82
|
+
currency: (0, WABinary_1.getBinaryNodeChildString)(priceNode, 'currency'),
|
|
83
|
+
},
|
|
84
|
+
products
|
|
85
|
+
};
|
|
86
|
+
return orderDetails;
|
|
87
|
+
};
|
|
88
|
+
exports.parseOrderDetailsNode = parseOrderDetailsNode;
|
|
89
|
+
const toProductNode = (productId, product) => {
|
|
90
|
+
const attrs = {};
|
|
91
|
+
const content = [];
|
|
92
|
+
if (typeof productId !== 'undefined') {
|
|
93
|
+
content.push({
|
|
94
|
+
tag: 'id',
|
|
95
|
+
attrs: {},
|
|
96
|
+
content: Buffer.from(productId)
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
if (typeof product.name !== 'undefined') {
|
|
100
|
+
content.push({
|
|
101
|
+
tag: 'name',
|
|
102
|
+
attrs: {},
|
|
103
|
+
content: Buffer.from(product.name)
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
if (typeof product.description !== 'undefined') {
|
|
107
|
+
content.push({
|
|
108
|
+
tag: 'description',
|
|
109
|
+
attrs: {},
|
|
110
|
+
content: Buffer.from(product.description)
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
if (typeof product.retailerId !== 'undefined') {
|
|
114
|
+
content.push({
|
|
115
|
+
tag: 'retailer_id',
|
|
116
|
+
attrs: {},
|
|
117
|
+
content: Buffer.from(product.retailerId)
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
if (product.images.length) {
|
|
121
|
+
content.push({
|
|
122
|
+
tag: 'media',
|
|
123
|
+
attrs: {},
|
|
124
|
+
content: product.images.map(img => {
|
|
125
|
+
if (!('url' in img)) {
|
|
126
|
+
throw new boom_1.Boom('Expected img for product to already be uploaded', { statusCode: 400 });
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
tag: 'image',
|
|
130
|
+
attrs: {},
|
|
131
|
+
content: [
|
|
132
|
+
{
|
|
133
|
+
tag: 'url',
|
|
134
|
+
attrs: {},
|
|
135
|
+
content: Buffer.from(img.url.toString())
|
|
136
|
+
}
|
|
137
|
+
]
|
|
138
|
+
};
|
|
139
|
+
})
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
if (typeof product.price !== 'undefined') {
|
|
143
|
+
content.push({
|
|
144
|
+
tag: 'price',
|
|
145
|
+
attrs: {},
|
|
146
|
+
content: Buffer.from(product.price.toString())
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
if (typeof product.currency !== 'undefined') {
|
|
150
|
+
content.push({
|
|
151
|
+
tag: 'currency',
|
|
152
|
+
attrs: {},
|
|
153
|
+
content: Buffer.from(product.currency)
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
if ('originCountryCode' in product) {
|
|
157
|
+
if (typeof product.originCountryCode === 'undefined') {
|
|
158
|
+
attrs['compliance_category'] = 'COUNTRY_ORIGIN_EXEMPT';
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
content.push({
|
|
162
|
+
tag: 'compliance_info',
|
|
163
|
+
attrs: {},
|
|
164
|
+
content: [
|
|
165
|
+
{
|
|
166
|
+
tag: 'country_code_origin',
|
|
167
|
+
attrs: {},
|
|
168
|
+
content: Buffer.from(product.originCountryCode)
|
|
169
|
+
}
|
|
170
|
+
]
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (typeof product.isHidden !== 'undefined') {
|
|
175
|
+
attrs['is_hidden'] = product.isHidden.toString();
|
|
176
|
+
}
|
|
177
|
+
const node = {
|
|
178
|
+
tag: 'product',
|
|
179
|
+
attrs,
|
|
180
|
+
content
|
|
181
|
+
};
|
|
182
|
+
return node;
|
|
183
|
+
};
|
|
184
|
+
exports.toProductNode = toProductNode;
|
|
185
|
+
const parseProductNode = (productNode) => {
|
|
186
|
+
const isHidden = productNode.attrs.is_hidden === 'true';
|
|
187
|
+
const id = (0, WABinary_1.getBinaryNodeChildString)(productNode, 'id');
|
|
188
|
+
const mediaNode = (0, WABinary_1.getBinaryNodeChild)(productNode, 'media');
|
|
189
|
+
const statusInfoNode = (0, WABinary_1.getBinaryNodeChild)(productNode, 'status_info');
|
|
190
|
+
const product = {
|
|
191
|
+
id,
|
|
192
|
+
imageUrls: parseImageUrls(mediaNode),
|
|
193
|
+
reviewStatus: {
|
|
194
|
+
whatsapp: (0, WABinary_1.getBinaryNodeChildString)(statusInfoNode, 'status'),
|
|
195
|
+
},
|
|
196
|
+
availability: 'in stock',
|
|
197
|
+
name: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'name'),
|
|
198
|
+
retailerId: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'retailer_id'),
|
|
199
|
+
url: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'url'),
|
|
200
|
+
description: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'description'),
|
|
201
|
+
price: +(0, WABinary_1.getBinaryNodeChildString)(productNode, 'price'),
|
|
202
|
+
currency: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'currency'),
|
|
203
|
+
isHidden,
|
|
204
|
+
};
|
|
205
|
+
return product;
|
|
206
|
+
};
|
|
207
|
+
exports.parseProductNode = parseProductNode;
|
|
208
|
+
/**
|
|
209
|
+
* Uploads images not already uploaded to WA's servers
|
|
210
|
+
*/
|
|
211
|
+
async function uploadingNecessaryImagesOfProduct(product, waUploadToServer, timeoutMs = 30000) {
|
|
212
|
+
product = {
|
|
213
|
+
...product,
|
|
214
|
+
images: product.images ? await (0, exports.uploadingNecessaryImages)(product.images, waUploadToServer, timeoutMs) : product.images
|
|
215
|
+
};
|
|
216
|
+
return product;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Uploads images not already uploaded to WA's servers
|
|
220
|
+
*/
|
|
221
|
+
const uploadingNecessaryImages = async (images, waUploadToServer, timeoutMs = 30000) => {
|
|
222
|
+
const results = await Promise.all(images.map(async (img) => {
|
|
223
|
+
if ('url' in img) {
|
|
224
|
+
const url = img.url.toString();
|
|
225
|
+
if (url.includes('.whatsapp.net')) {
|
|
226
|
+
return { url };
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
const { stream } = await (0, messages_media_1.getStream)(img);
|
|
230
|
+
const hasher = (0, crypto_1.createHash)('sha256');
|
|
231
|
+
const contentBlocks = [];
|
|
232
|
+
for await (const block of stream) {
|
|
233
|
+
hasher.update(block);
|
|
234
|
+
contentBlocks.push(block);
|
|
235
|
+
}
|
|
236
|
+
const sha = hasher.digest('base64');
|
|
237
|
+
const { directPath } = await waUploadToServer((0, messages_media_1.toReadable)(Buffer.concat(contentBlocks)), {
|
|
238
|
+
mediaType: 'product-catalog-image',
|
|
239
|
+
fileEncSha256B64: sha,
|
|
240
|
+
timeoutMs
|
|
241
|
+
});
|
|
242
|
+
return { url: (0, messages_media_1.getUrlFromDirectPath)(directPath) };
|
|
243
|
+
}));
|
|
244
|
+
return results;
|
|
245
|
+
};
|
|
246
|
+
exports.uploadingNecessaryImages = uploadingNecessaryImages;
|
|
247
|
+
const parseImageUrls = (mediaNode) => {
|
|
248
|
+
const imgNode = (0, WABinary_1.getBinaryNodeChild)(mediaNode, 'image');
|
|
249
|
+
return {
|
|
250
|
+
requested: (0, WABinary_1.getBinaryNodeChildString)(imgNode, 'request_image_url'),
|
|
251
|
+
original: (0, WABinary_1.getBinaryNodeChildString)(imgNode, 'original_image_url')
|
|
252
|
+
};
|
|
253
|
+
};
|
|
254
|
+
const parseStatusInfo = (mediaNode) => {
|
|
255
|
+
const node = (0, WABinary_1.getBinaryNodeChild)(mediaNode, 'status_info');
|
|
256
|
+
return {
|
|
257
|
+
status: (0, WABinary_1.getBinaryNodeChildString)(node, 'status'),
|
|
258
|
+
canAppeal: (0, WABinary_1.getBinaryNodeChildString)(node, 'can_appeal') === 'true',
|
|
259
|
+
};
|
|
260
|
+
};
|