@pontalabs/baileys 1.0.11 → 1.1.0
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 +96 -85
- package/lib/Defaults/connection.js +39 -0
- package/lib/Defaults/constants.js +50 -0
- package/lib/Defaults/history.js +13 -0
- package/lib/Defaults/index.js +36 -151
- package/lib/Defaults/media.js +43 -0
- package/lib/Defaults/phonenumber-mcc.json +221 -221
- package/lib/Defaults/prefix.js +12 -0
- package/lib/Defaults/vialeys-version.json +7 -0
- package/lib/Signal/Group/ciphertext-message.js +10 -15
- package/lib/Signal/Group/group-session-builder.js +34 -60
- package/lib/Signal/Group/group_cipher.js +69 -76
- package/lib/Signal/Group/index.js +41 -60
- package/lib/Signal/Group/keyhelper.js +12 -57
- package/lib/Signal/Group/sender-chain-key.js +20 -33
- package/lib/Signal/Group/sender-key-distribution-message.js +43 -48
- package/lib/Signal/Group/sender-key-message.js +58 -53
- package/lib/Signal/Group/sender-key-name.js +21 -31
- package/lib/Signal/Group/sender-key-record.js +21 -34
- package/lib/Signal/Group/sender-key-state.js +59 -106
- package/lib/Signal/Group/sender-message-key.js +16 -21
- package/lib/Signal/libsignal.js +282 -203
- package/lib/Signal/lid-mapping.js +164 -184
- package/lib/Socket/Client/index.js +31 -22
- package/lib/Socket/Client/types.js +9 -15
- package/lib/Socket/Client/websocket.js +42 -37
- package/lib/Socket/business.js +212 -336
- package/lib/Socket/chats.js +696 -940
- package/lib/Socket/community.js +454 -369
- package/lib/Socket/groups.js +278 -280
- package/lib/Socket/index.js +9 -21
- package/lib/Socket/messages-recv.js +1027 -1570
- package/lib/Socket/messages-send.js +1180 -1136
- package/lib/Socket/mex.js +59 -0
- package/lib/Socket/newsletter.js +193 -251
- package/lib/Socket/socket.js +758 -898
- package/lib/Store/index.js +35 -24
- package/lib/Store/make-cache-manager-store.js +53 -66
- package/lib/Store/make-in-memory-store.js +319 -325
- package/lib/Store/make-ordered-dictionary.js +49 -57
- package/lib/Store/object-repository.js +10 -15
- package/lib/Types/Auth.js +2 -3
- package/lib/Types/Bussines.js +2 -3
- package/lib/Types/Call.js +2 -3
- package/lib/Types/Chat.js +10 -9
- package/lib/Types/Contact.js +2 -3
- package/lib/Types/Events.js +2 -3
- package/lib/Types/GroupMetadata.js +2 -3
- package/lib/Types/Label.js +6 -12
- package/lib/Types/LabelAssociation.js +4 -13
- package/lib/Types/Message.js +10 -18
- package/lib/Types/MexUpdates.js +15 -18
- package/lib/Types/Newsletter.js +26 -34
- package/lib/Types/Product.js +2 -3
- package/lib/Types/Signal.js +2 -3
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.js +8 -13
- package/lib/Types/USync.js +2 -3
- package/lib/Types/index.js +49 -40
- package/lib/Utils/auth-utils.js +190 -495
- package/lib/Utils/browser-utils.js +29 -0
- package/lib/Utils/business.js +177 -199
- package/lib/Utils/chat-utils.js +711 -624
- package/lib/Utils/crypto.js +116 -161
- package/lib/Utils/decode-wa-message.js +225 -321
- package/lib/Utils/event-buffer.js +363 -405
- package/lib/Utils/generics.js +318 -472
- package/lib/Utils/history.js +72 -76
- package/lib/Utils/index.js +49 -41
- package/lib/Utils/link-preview.js +59 -103
- package/lib/Utils/logger.js +4 -7
- package/lib/Utils/lt-hash.js +29 -42
- package/lib/Utils/make-mutex.js +26 -42
- package/lib/Utils/message-retry-manager.js +134 -160
- package/lib/Utils/messages-media.js +665 -731
- package/lib/Utils/messages.js +518 -1
- package/lib/Utils/noise-handler.js +127 -125
- package/lib/Utils/pre-key-manager.js +86 -0
- package/lib/Utils/process-message.js +739 -351
- package/lib/Utils/signal.js +146 -129
- package/lib/Utils/use-multi-file-auth-state.js +68 -135
- package/lib/Utils/validate-connection.js +183 -142
- package/lib/Utils/vialeys-event-stream.js +41 -0
- package/lib/WABinary/constants.js +1281 -1289
- package/lib/WABinary/decode.js +145 -200
- package/lib/WABinary/encode.js +149 -202
- package/lib/WABinary/generic-utils.js +79 -97
- package/lib/WABinary/index.js +36 -25
- package/lib/WABinary/jid-utils.js +91 -123
- package/lib/WABinary/types.js +2 -3
- package/lib/WAM/BinaryInfo.js +8 -13
- package/lib/WAM/constants.js +16584 -11464
- package/lib/WAM/encode.js +117 -133
- package/lib/WAM/index.js +34 -23
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +62 -69
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +11 -25
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +32 -44
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +13 -23
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +24 -38
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +17 -31
- package/lib/WAUSync/Protocols/index.js +37 -26
- package/lib/WAUSync/USyncQuery.js +66 -66
- package/lib/WAUSync/USyncUser.js +13 -18
- package/lib/WAUSync/index.js +34 -23
- package/lib/index.js +95 -28
- package/package.json +2 -1
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Signal/Group/queue-job.d.ts +0 -1
- package/lib/Signal/Group/queue-job.js +0 -57
- package/lib/Socket/usync.d.ts +0 -37
- package/lib/Socket/usync.js +0 -83
- package/lib/Utils/baileys-event-stream.d.ts +0 -18
- package/lib/Utils/baileys-event-stream.js +0 -70
- package/lib/Utils/signal-housekeeping.d.ts +0 -19
- package/lib/Utils/signal-housekeeping.js +0 -73
- package/lib/Utils/use-mongo-file-auth-state.d.ts +0 -6
- package/lib/Utils/use-mongo-file-auth-state.js +0 -84
- package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
- package/lib/Utils/use-single-file-auth-state.js +0 -80
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const { platform: platform, release: release } = require("os");
|
|
4
|
+
const { proto: proto } = require("../../WAProto");
|
|
5
|
+
const PLATFORM_MAP = {
|
|
6
|
+
aix: "AIX",
|
|
7
|
+
darwin: "Mac OS",
|
|
8
|
+
win32: "Windows",
|
|
9
|
+
android: "Android",
|
|
10
|
+
freebsd: "FreeBSD",
|
|
11
|
+
openbsd: "OpenBSD",
|
|
12
|
+
sunos: "Solaris",
|
|
13
|
+
linux: undefined,
|
|
14
|
+
haiku: undefined,
|
|
15
|
+
cygwin: undefined,
|
|
16
|
+
netbsd: undefined,
|
|
17
|
+
};
|
|
18
|
+
const Browsers = {
|
|
19
|
+
ubuntu: (browser) => ["Ubuntu", browser, "22.04.4"],
|
|
20
|
+
macOS: (browser) => ["Mac OS", browser, "14.4.1"],
|
|
21
|
+
baileys: (browser) => ["Baileys", browser, "6.5.0"],
|
|
22
|
+
windows: (browser) => ["Windows", browser, "10.0.22631"],
|
|
23
|
+
appropriate: (browser) => [PLATFORM_MAP[platform()] || "Ubuntu", browser, release()],
|
|
24
|
+
};
|
|
25
|
+
const getPlatformId = (browser) => {
|
|
26
|
+
const platformType = proto.DeviceProps.PlatformType[browser.toUpperCase()];
|
|
27
|
+
return platformType ? platformType.toString() : "1";
|
|
28
|
+
};
|
|
29
|
+
module.exports = { Browsers: Browsers, getPlatformId: getPlatformId };
|
package/lib/Utils/business.js
CHANGED
|
@@ -1,255 +1,233 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const { Boom: Boom } = require("@hapi/boom");
|
|
4
|
+
const { createHash: createHash } = require("crypto");
|
|
5
|
+
const { join: join } = require("path");
|
|
6
|
+
const { tmpdir: tmpdir } = require("os");
|
|
7
|
+
const { promises: promises, createWriteStream: createWriteStream } = require("fs");
|
|
8
|
+
const {
|
|
9
|
+
getBinaryNodeChild: getBinaryNodeChild,
|
|
10
|
+
getBinaryNodeChildren: getBinaryNodeChildren,
|
|
11
|
+
getBinaryNodeChildString: getBinaryNodeChildString,
|
|
12
|
+
} = require("../WABinary");
|
|
13
|
+
const {
|
|
14
|
+
getStream: getStream,
|
|
15
|
+
getUrlFromDirectPath: getUrlFromDirectPath,
|
|
16
|
+
} = require("./messages-media");
|
|
17
|
+
const { generateMessageID: generateMessageID } = require("./generics");
|
|
14
18
|
const parseCatalogNode = (node) => {
|
|
15
|
-
const catalogNode =
|
|
16
|
-
const products =
|
|
17
|
-
const paging =
|
|
19
|
+
const catalogNode = getBinaryNodeChild(node, "product_catalog");
|
|
20
|
+
const products = getBinaryNodeChildren(catalogNode, "product").map(parseProductNode);
|
|
21
|
+
const paging = getBinaryNodeChild(catalogNode, "paging");
|
|
18
22
|
return {
|
|
19
|
-
products,
|
|
20
|
-
nextPageCursor: paging
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
23
|
+
products: products,
|
|
24
|
+
nextPageCursor: paging ? getBinaryNodeChildString(paging, "after") : undefined,
|
|
25
|
+
};
|
|
26
|
+
};
|
|
26
27
|
const parseCollectionsNode = (node) => {
|
|
27
|
-
const collectionsNode =
|
|
28
|
-
const collections =
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
28
|
+
const collectionsNode = getBinaryNodeChild(node, "collections");
|
|
29
|
+
const collections = getBinaryNodeChildren(collectionsNode, "collection").map(
|
|
30
|
+
(collectionNode) => {
|
|
31
|
+
const id = getBinaryNodeChildString(collectionNode, "id");
|
|
32
|
+
const name = getBinaryNodeChildString(collectionNode, "name");
|
|
33
|
+
const products = getBinaryNodeChildren(collectionNode, "product").map(parseProductNode);
|
|
34
|
+
return {
|
|
35
|
+
id: id,
|
|
36
|
+
name: name,
|
|
37
|
+
products: products,
|
|
38
|
+
status: parseStatusInfo(collectionNode),
|
|
39
|
+
};
|
|
37
40
|
}
|
|
38
|
-
|
|
39
|
-
return {
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
41
|
+
);
|
|
42
|
+
return { collections: collections };
|
|
43
|
+
};
|
|
44
44
|
const parseOrderDetailsNode = (node) => {
|
|
45
|
-
const orderNode =
|
|
46
|
-
const products =
|
|
47
|
-
const imageNode =
|
|
45
|
+
const orderNode = getBinaryNodeChild(node, "order");
|
|
46
|
+
const products = getBinaryNodeChildren(orderNode, "product").map((productNode) => {
|
|
47
|
+
const imageNode = getBinaryNodeChild(productNode, "image");
|
|
48
48
|
return {
|
|
49
|
-
id:
|
|
50
|
-
name:
|
|
51
|
-
imageUrl:
|
|
52
|
-
price: +
|
|
53
|
-
currency:
|
|
54
|
-
quantity: +
|
|
55
|
-
}
|
|
56
|
-
})
|
|
57
|
-
const priceNode =
|
|
49
|
+
id: getBinaryNodeChildString(productNode, "id"),
|
|
50
|
+
name: getBinaryNodeChildString(productNode, "name"),
|
|
51
|
+
imageUrl: getBinaryNodeChildString(imageNode, "url"),
|
|
52
|
+
price: +getBinaryNodeChildString(productNode, "price"),
|
|
53
|
+
currency: getBinaryNodeChildString(productNode, "currency"),
|
|
54
|
+
quantity: +getBinaryNodeChildString(productNode, "quantity"),
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
const priceNode = getBinaryNodeChild(orderNode, "price");
|
|
58
58
|
const orderDetails = {
|
|
59
59
|
price: {
|
|
60
|
-
total: +
|
|
61
|
-
currency:
|
|
60
|
+
total: +getBinaryNodeChildString(priceNode, "total"),
|
|
61
|
+
currency: getBinaryNodeChildString(priceNode, "currency"),
|
|
62
62
|
},
|
|
63
|
-
products
|
|
64
|
-
}
|
|
65
|
-
return orderDetails
|
|
66
|
-
}
|
|
67
|
-
|
|
63
|
+
products: products,
|
|
64
|
+
};
|
|
65
|
+
return orderDetails;
|
|
66
|
+
};
|
|
68
67
|
const toProductNode = (productId, product) => {
|
|
69
|
-
const attrs = {}
|
|
70
|
-
const content = []
|
|
71
|
-
if (typeof productId !==
|
|
72
|
-
content.push({
|
|
73
|
-
tag: 'id',
|
|
74
|
-
attrs: {},
|
|
75
|
-
content: Buffer.from(productId)
|
|
76
|
-
})
|
|
68
|
+
const attrs = {};
|
|
69
|
+
const content = [];
|
|
70
|
+
if (typeof productId !== "undefined") {
|
|
71
|
+
content.push({ tag: "id", attrs: {}, content: Buffer.from(productId) });
|
|
77
72
|
}
|
|
78
|
-
if (typeof product.name !==
|
|
73
|
+
if (typeof product.name !== "undefined") {
|
|
79
74
|
content.push({
|
|
80
|
-
tag:
|
|
75
|
+
tag: "name",
|
|
81
76
|
attrs: {},
|
|
82
|
-
content: Buffer.from(product.name)
|
|
83
|
-
})
|
|
77
|
+
content: Buffer.from(product.name),
|
|
78
|
+
});
|
|
84
79
|
}
|
|
85
|
-
if (typeof product.description !==
|
|
80
|
+
if (typeof product.description !== "undefined") {
|
|
86
81
|
content.push({
|
|
87
|
-
tag:
|
|
82
|
+
tag: "description",
|
|
88
83
|
attrs: {},
|
|
89
|
-
content: Buffer.from(product.description)
|
|
90
|
-
})
|
|
84
|
+
content: Buffer.from(product.description),
|
|
85
|
+
});
|
|
91
86
|
}
|
|
92
|
-
if (typeof product.retailerId !==
|
|
87
|
+
if (typeof product.retailerId !== "undefined") {
|
|
93
88
|
content.push({
|
|
94
|
-
tag:
|
|
89
|
+
tag: "retailer_id",
|
|
95
90
|
attrs: {},
|
|
96
|
-
content: Buffer.from(product.retailerId)
|
|
97
|
-
})
|
|
91
|
+
content: Buffer.from(product.retailerId),
|
|
92
|
+
});
|
|
98
93
|
}
|
|
99
94
|
if (product.images.length) {
|
|
100
95
|
content.push({
|
|
101
|
-
tag:
|
|
96
|
+
tag: "media",
|
|
102
97
|
attrs: {},
|
|
103
|
-
content: product.images.map(img => {
|
|
104
|
-
if (!(
|
|
105
|
-
throw new
|
|
98
|
+
content: product.images.map((img) => {
|
|
99
|
+
if (!("url" in img)) {
|
|
100
|
+
throw new Boom("Expected img for product to already be uploaded", {
|
|
101
|
+
statusCode: 400,
|
|
102
|
+
});
|
|
106
103
|
}
|
|
107
104
|
return {
|
|
108
|
-
tag:
|
|
105
|
+
tag: "image",
|
|
109
106
|
attrs: {},
|
|
110
|
-
content: [
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
content: Buffer.from(img.url.toString())
|
|
115
|
-
}
|
|
116
|
-
]
|
|
117
|
-
}
|
|
118
|
-
})
|
|
119
|
-
})
|
|
107
|
+
content: [{ tag: "url", attrs: {}, content: Buffer.from(img.url.toString()) }],
|
|
108
|
+
};
|
|
109
|
+
}),
|
|
110
|
+
});
|
|
120
111
|
}
|
|
121
|
-
if (typeof product.price !==
|
|
112
|
+
if (typeof product.price !== "undefined") {
|
|
122
113
|
content.push({
|
|
123
|
-
tag:
|
|
114
|
+
tag: "price",
|
|
124
115
|
attrs: {},
|
|
125
|
-
content: Buffer.from(product.price.toString())
|
|
126
|
-
})
|
|
116
|
+
content: Buffer.from(product.price.toString()),
|
|
117
|
+
});
|
|
127
118
|
}
|
|
128
|
-
if (typeof product.currency !==
|
|
119
|
+
if (typeof product.currency !== "undefined") {
|
|
129
120
|
content.push({
|
|
130
|
-
tag:
|
|
121
|
+
tag: "currency",
|
|
131
122
|
attrs: {},
|
|
132
|
-
content: Buffer.from(product.currency)
|
|
133
|
-
})
|
|
123
|
+
content: Buffer.from(product.currency),
|
|
124
|
+
});
|
|
134
125
|
}
|
|
135
|
-
if (
|
|
136
|
-
if (typeof product.originCountryCode ===
|
|
137
|
-
attrs[
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
126
|
+
if ("originCountryCode" in product) {
|
|
127
|
+
if (typeof product.originCountryCode === "undefined") {
|
|
128
|
+
attrs["compliance_category"] = "COUNTRY_ORIGIN_EXEMPT";
|
|
129
|
+
} else {
|
|
140
130
|
content.push({
|
|
141
|
-
tag:
|
|
131
|
+
tag: "compliance_info",
|
|
142
132
|
attrs: {},
|
|
143
133
|
content: [
|
|
144
134
|
{
|
|
145
|
-
tag:
|
|
135
|
+
tag: "country_code_origin",
|
|
146
136
|
attrs: {},
|
|
147
|
-
content: Buffer.from(product.originCountryCode)
|
|
148
|
-
}
|
|
149
|
-
]
|
|
150
|
-
})
|
|
137
|
+
content: Buffer.from(product.originCountryCode),
|
|
138
|
+
},
|
|
139
|
+
],
|
|
140
|
+
});
|
|
151
141
|
}
|
|
152
142
|
}
|
|
153
|
-
if (typeof product.isHidden !==
|
|
154
|
-
attrs[
|
|
143
|
+
if (typeof product.isHidden !== "undefined") {
|
|
144
|
+
attrs["is_hidden"] = product.isHidden.toString();
|
|
155
145
|
}
|
|
156
|
-
const node = {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
content
|
|
160
|
-
}
|
|
161
|
-
return node
|
|
162
|
-
}
|
|
163
|
-
|
|
146
|
+
const node = { tag: "product", attrs: attrs, content: content };
|
|
147
|
+
return node;
|
|
148
|
+
};
|
|
164
149
|
const parseProductNode = (productNode) => {
|
|
165
|
-
const isHidden = productNode.attrs.is_hidden ===
|
|
166
|
-
const id =
|
|
167
|
-
const mediaNode =
|
|
168
|
-
const statusInfoNode =
|
|
150
|
+
const isHidden = productNode.attrs.is_hidden === "true";
|
|
151
|
+
const id = getBinaryNodeChildString(productNode, "id");
|
|
152
|
+
const mediaNode = getBinaryNodeChild(productNode, "media");
|
|
153
|
+
const statusInfoNode = getBinaryNodeChild(productNode, "status_info");
|
|
169
154
|
const product = {
|
|
170
|
-
id,
|
|
155
|
+
id: id,
|
|
171
156
|
imageUrls: parseImageUrls(mediaNode),
|
|
172
157
|
reviewStatus: {
|
|
173
|
-
whatsapp:
|
|
158
|
+
whatsapp: getBinaryNodeChildString(statusInfoNode, "status"),
|
|
174
159
|
},
|
|
175
|
-
availability:
|
|
176
|
-
name:
|
|
177
|
-
retailerId:
|
|
178
|
-
url:
|
|
179
|
-
description:
|
|
180
|
-
price: +
|
|
181
|
-
currency:
|
|
182
|
-
isHidden,
|
|
183
|
-
}
|
|
184
|
-
return product
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Uploads images not already uploaded to WA's servers
|
|
189
|
-
*/
|
|
190
|
-
async function uploadingNecessaryImagesOfProduct(product, waUploadToServer, timeoutMs = 30000) {
|
|
160
|
+
availability: "in stock",
|
|
161
|
+
name: getBinaryNodeChildString(productNode, "name"),
|
|
162
|
+
retailerId: getBinaryNodeChildString(productNode, "retailer_id"),
|
|
163
|
+
url: getBinaryNodeChildString(productNode, "url"),
|
|
164
|
+
description: getBinaryNodeChildString(productNode, "description"),
|
|
165
|
+
price: +getBinaryNodeChildString(productNode, "price"),
|
|
166
|
+
currency: getBinaryNodeChildString(productNode, "currency"),
|
|
167
|
+
isHidden: isHidden,
|
|
168
|
+
};
|
|
169
|
+
return product;
|
|
170
|
+
};
|
|
171
|
+
async function uploadingNecessaryImagesOfProduct(product, waUploadToServer, timeoutMs = 3e4) {
|
|
191
172
|
product = {
|
|
192
173
|
...product,
|
|
193
|
-
images: product.images
|
|
194
|
-
|
|
195
|
-
|
|
174
|
+
images: product.images
|
|
175
|
+
? await uploadingNecessaryImages(product.images, waUploadToServer, timeoutMs)
|
|
176
|
+
: product.images,
|
|
177
|
+
};
|
|
178
|
+
return product;
|
|
196
179
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
const
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
if (url.includes('.whatsapp.net')) {
|
|
206
|
-
return { url }
|
|
180
|
+
const uploadingNecessaryImages = async (images, waUploadToServer, timeoutMs = 3e4) => {
|
|
181
|
+
const results = await Promise.all(
|
|
182
|
+
images.map(async (img) => {
|
|
183
|
+
if ("url" in img) {
|
|
184
|
+
const url = img.url.toString();
|
|
185
|
+
if (url.includes(".whatsapp.net")) {
|
|
186
|
+
return { url: url };
|
|
187
|
+
}
|
|
207
188
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
189
|
+
const { stream: stream } = await getStream(img);
|
|
190
|
+
const hasher = createHash("sha256");
|
|
191
|
+
const filePath = join(tmpdir(), "img" + generateMessageID());
|
|
192
|
+
const encFileWriteStream = createWriteStream(filePath);
|
|
193
|
+
for await (const block of stream) {
|
|
194
|
+
hasher.update(block);
|
|
195
|
+
encFileWriteStream.write(block);
|
|
196
|
+
}
|
|
197
|
+
const sha = hasher.digest("base64");
|
|
198
|
+
const { directPath: directPath } = await waUploadToServer(filePath, {
|
|
199
|
+
mediaType: "product-catalog-image",
|
|
200
|
+
fileEncSha256B64: sha,
|
|
201
|
+
timeoutMs: timeoutMs,
|
|
202
|
+
});
|
|
203
|
+
await promises
|
|
204
|
+
.unlink(filePath)
|
|
205
|
+
.catch((err) => console.log("Error deleting temp file ", err));
|
|
206
|
+
return { url: getUrlFromDirectPath(directPath) };
|
|
222
207
|
})
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
return { url: messages_media_1.getUrlFromDirectPath(directPath) }
|
|
227
|
-
}))
|
|
228
|
-
return results
|
|
229
|
-
}
|
|
230
|
-
|
|
208
|
+
);
|
|
209
|
+
return results;
|
|
210
|
+
};
|
|
231
211
|
const parseImageUrls = (mediaNode) => {
|
|
232
|
-
const imgNode =
|
|
212
|
+
const imgNode = getBinaryNodeChild(mediaNode, "image");
|
|
233
213
|
return {
|
|
234
|
-
requested:
|
|
235
|
-
original:
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
214
|
+
requested: getBinaryNodeChildString(imgNode, "request_image_url"),
|
|
215
|
+
original: getBinaryNodeChildString(imgNode, "original_image_url"),
|
|
216
|
+
};
|
|
217
|
+
};
|
|
239
218
|
const parseStatusInfo = (mediaNode) => {
|
|
240
|
-
const node =
|
|
219
|
+
const node = getBinaryNodeChild(mediaNode, "status_info");
|
|
241
220
|
return {
|
|
242
|
-
status:
|
|
243
|
-
canAppeal:
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
|
|
221
|
+
status: getBinaryNodeChildString(node, "status"),
|
|
222
|
+
canAppeal: getBinaryNodeChildString(node, "can_appeal") === "true",
|
|
223
|
+
};
|
|
224
|
+
};
|
|
247
225
|
module.exports = {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
}
|
|
226
|
+
parseCatalogNode: parseCatalogNode,
|
|
227
|
+
parseCollectionsNode: parseCollectionsNode,
|
|
228
|
+
parseOrderDetailsNode: parseOrderDetailsNode,
|
|
229
|
+
toProductNode: toProductNode,
|
|
230
|
+
parseProductNode: parseProductNode,
|
|
231
|
+
uploadingNecessaryImagesOfProduct: uploadingNecessaryImagesOfProduct,
|
|
232
|
+
uploadingNecessaryImages: uploadingNecessaryImages,
|
|
233
|
+
};
|