@dilxzcode/bails 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +200 -0
  3. package/WAProto/index.js +169661 -0
  4. package/engine-requirements.js +10 -0
  5. package/lib/Defaults/baileys-version.json +3 -0
  6. package/lib/Defaults/index.js +147 -0
  7. package/lib/Defaults/phonenumber-mcc.json +223 -0
  8. package/lib/Signal/Group/ciphertext-message.js +15 -0
  9. package/lib/Signal/Group/group-session-builder.js +64 -0
  10. package/lib/Signal/Group/group_cipher.js +96 -0
  11. package/lib/Signal/Group/index.js +57 -0
  12. package/lib/Signal/Group/keyhelper.js +55 -0
  13. package/lib/Signal/Group/queue-job.js +57 -0
  14. package/lib/Signal/Group/sender-chain-key.js +34 -0
  15. package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
  16. package/lib/Signal/Group/sender-key-message.js +69 -0
  17. package/lib/Signal/Group/sender-key-name.js +51 -0
  18. package/lib/Signal/Group/sender-key-record.js +53 -0
  19. package/lib/Signal/Group/sender-key-state.js +99 -0
  20. package/lib/Signal/Group/sender-message-key.js +29 -0
  21. package/lib/Signal/libsignal.js +174 -0
  22. package/lib/Socket/Client/abstract-socket-client.js +13 -0
  23. package/lib/Socket/Client/index.js +19 -0
  24. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  25. package/lib/Socket/Client/web-socket-client.js +62 -0
  26. package/lib/Socket/business.js +260 -0
  27. package/lib/Socket/chats.js +1002 -0
  28. package/lib/Socket/groups.js +317 -0
  29. package/lib/Socket/handel.js +637 -0
  30. package/lib/Socket/index.js +11 -0
  31. package/lib/Socket/messages-recv.js +1110 -0
  32. package/lib/Socket/messages-send.js +831 -0
  33. package/lib/Socket/newsletter.js +434 -0
  34. package/lib/Socket/registration.js +166 -0
  35. package/lib/Socket/socket.js +665 -0
  36. package/lib/Socket/usync.js +70 -0
  37. package/lib/Store/index.js +10 -0
  38. package/lib/Store/make-cache-manager-store.js +83 -0
  39. package/lib/Store/make-in-memory-store.js +427 -0
  40. package/lib/Store/make-ordered-dictionary.js +81 -0
  41. package/lib/Store/object-repository.js +27 -0
  42. package/lib/Types/Auth.js +2 -0
  43. package/lib/Types/Call.js +2 -0
  44. package/lib/Types/Chat.js +4 -0
  45. package/lib/Types/Contact.js +2 -0
  46. package/lib/Types/Events.js +2 -0
  47. package/lib/Types/GroupMetadata.js +2 -0
  48. package/lib/Types/Label.js +27 -0
  49. package/lib/Types/LabelAssociation.js +9 -0
  50. package/lib/Types/Message.js +9 -0
  51. package/lib/Types/Newsletter.js +38 -0
  52. package/lib/Types/Product.js +2 -0
  53. package/lib/Types/Signal.js +2 -0
  54. package/lib/Types/Socket.js +2 -0
  55. package/lib/Types/State.js +2 -0
  56. package/lib/Types/USync.js +2 -0
  57. package/lib/Types/index.js +42 -0
  58. package/lib/Utils/auth-utils.js +206 -0
  59. package/lib/Utils/baileys-event-stream.js +63 -0
  60. package/lib/Utils/business.js +234 -0
  61. package/lib/Utils/chat-utils.js +729 -0
  62. package/lib/Utils/crypto.js +151 -0
  63. package/lib/Utils/decode-wa-message.js +198 -0
  64. package/lib/Utils/event-buffer.js +514 -0
  65. package/lib/Utils/generics.js +498 -0
  66. package/lib/Utils/history.js +96 -0
  67. package/lib/Utils/index.js +33 -0
  68. package/lib/Utils/link-preview.js +93 -0
  69. package/lib/Utils/logger.js +7 -0
  70. package/lib/Utils/lt-hash.js +51 -0
  71. package/lib/Utils/make-mutex.js +43 -0
  72. package/lib/Utils/messages-media.js +819 -0
  73. package/lib/Utils/messages.js +819 -0
  74. package/lib/Utils/noise-handler.js +155 -0
  75. package/lib/Utils/process-message.js +321 -0
  76. package/lib/Utils/signal.js +153 -0
  77. package/lib/Utils/use-multi-file-auth-state.js +119 -0
  78. package/lib/Utils/validate-connection.js +229 -0
  79. package/lib/WABinary/constants.js +40 -0
  80. package/lib/WABinary/decode.js +252 -0
  81. package/lib/WABinary/encode.js +265 -0
  82. package/lib/WABinary/generic-utils.js +198 -0
  83. package/lib/WABinary/index.js +21 -0
  84. package/lib/WABinary/jid-utils.js +62 -0
  85. package/lib/WABinary/types.js +2 -0
  86. package/lib/WAM/BinaryInfo.js +13 -0
  87. package/lib/WAM/constants.js +15350 -0
  88. package/lib/WAM/encode.js +155 -0
  89. package/lib/WAM/index.js +19 -0
  90. package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
  91. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
  92. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
  93. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  94. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
  95. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
  96. package/lib/WAUSync/Protocols/index.js +20 -0
  97. package/lib/WAUSync/USyncQuery.js +89 -0
  98. package/lib/WAUSync/USyncUser.js +26 -0
  99. package/lib/WAUSync/index.js +19 -0
  100. package/lib/index.js +40 -0
  101. package/package.json +112 -0
@@ -0,0 +1,234 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.uploadingNecessaryImages = exports.uploadingNecessaryImagesOfProduct = exports.parseProductNode = exports.toProductNode = exports.parseOrderDetailsNode = exports.parseCollectionsNode = exports.parseCatalogNode = void 0;
4
+ const boom_1 = require("@hapi/boom");
5
+ const crypto_1 = require("crypto");
6
+ const WABinary_1 = require("../WABinary");
7
+ const messages_media_1 = require("./messages-media");
8
+ const parseCatalogNode = (node) => {
9
+ const catalogNode = (0, WABinary_1.getBinaryNodeChild)(node, 'product_catalog');
10
+ const products = (0, WABinary_1.getBinaryNodeChildren)(catalogNode, 'product').map(exports.parseProductNode);
11
+ const paging = (0, WABinary_1.getBinaryNodeChild)(catalogNode, 'paging');
12
+ return {
13
+ products,
14
+ nextPageCursor: paging
15
+ ? (0, WABinary_1.getBinaryNodeChildString)(paging, 'after')
16
+ : undefined
17
+ };
18
+ };
19
+ exports.parseCatalogNode = parseCatalogNode;
20
+ const parseCollectionsNode = (node) => {
21
+ const collectionsNode = (0, WABinary_1.getBinaryNodeChild)(node, 'collections');
22
+ const collections = (0, WABinary_1.getBinaryNodeChildren)(collectionsNode, 'collection').map(collectionNode => {
23
+ const id = (0, WABinary_1.getBinaryNodeChildString)(collectionNode, 'id');
24
+ const name = (0, WABinary_1.getBinaryNodeChildString)(collectionNode, 'name');
25
+ const products = (0, WABinary_1.getBinaryNodeChildren)(collectionNode, 'product').map(exports.parseProductNode);
26
+ return {
27
+ id,
28
+ name,
29
+ products,
30
+ status: parseStatusInfo(collectionNode)
31
+ };
32
+ });
33
+ return {
34
+ collections
35
+ };
36
+ };
37
+ exports.parseCollectionsNode = parseCollectionsNode;
38
+ const parseOrderDetailsNode = (node) => {
39
+ const orderNode = (0, WABinary_1.getBinaryNodeChild)(node, 'order');
40
+ const products = (0, WABinary_1.getBinaryNodeChildren)(orderNode, 'product').map(productNode => {
41
+ const imageNode = (0, WABinary_1.getBinaryNodeChild)(productNode, 'image');
42
+ return {
43
+ id: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'id'),
44
+ name: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'name'),
45
+ imageUrl: (0, WABinary_1.getBinaryNodeChildString)(imageNode, 'url'),
46
+ price: +(0, WABinary_1.getBinaryNodeChildString)(productNode, 'price'),
47
+ currency: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'currency'),
48
+ quantity: +(0, WABinary_1.getBinaryNodeChildString)(productNode, 'quantity')
49
+ };
50
+ });
51
+ const priceNode = (0, WABinary_1.getBinaryNodeChild)(orderNode, 'price');
52
+ const orderDetails = {
53
+ price: {
54
+ total: +(0, WABinary_1.getBinaryNodeChildString)(priceNode, 'total'),
55
+ currency: (0, WABinary_1.getBinaryNodeChildString)(priceNode, 'currency'),
56
+ },
57
+ products
58
+ };
59
+ return orderDetails;
60
+ };
61
+ exports.parseOrderDetailsNode = parseOrderDetailsNode;
62
+ const toProductNode = (productId, product) => {
63
+ const attrs = {};
64
+ const content = [];
65
+ if (typeof productId !== 'undefined') {
66
+ content.push({
67
+ tag: 'id',
68
+ attrs: {},
69
+ content: Buffer.from(productId)
70
+ });
71
+ }
72
+ if (typeof product.name !== 'undefined') {
73
+ content.push({
74
+ tag: 'name',
75
+ attrs: {},
76
+ content: Buffer.from(product.name)
77
+ });
78
+ }
79
+ if (typeof product.description !== 'undefined') {
80
+ content.push({
81
+ tag: 'description',
82
+ attrs: {},
83
+ content: Buffer.from(product.description)
84
+ });
85
+ }
86
+ if (typeof product.retailerId !== 'undefined') {
87
+ content.push({
88
+ tag: 'retailer_id',
89
+ attrs: {},
90
+ content: Buffer.from(product.retailerId)
91
+ });
92
+ }
93
+ if (product.images.length) {
94
+ content.push({
95
+ tag: 'media',
96
+ attrs: {},
97
+ content: product.images.map(img => {
98
+ if (!('url' in img)) {
99
+ throw new boom_1.Boom('Expected img for product to already be uploaded', { statusCode: 400 });
100
+ }
101
+ return {
102
+ tag: 'image',
103
+ attrs: {},
104
+ content: [
105
+ {
106
+ tag: 'url',
107
+ attrs: {},
108
+ content: Buffer.from(img.url.toString())
109
+ }
110
+ ]
111
+ };
112
+ })
113
+ });
114
+ }
115
+ if (typeof product.price !== 'undefined') {
116
+ content.push({
117
+ tag: 'price',
118
+ attrs: {},
119
+ content: Buffer.from(product.price.toString())
120
+ });
121
+ }
122
+ if (typeof product.currency !== 'undefined') {
123
+ content.push({
124
+ tag: 'currency',
125
+ attrs: {},
126
+ content: Buffer.from(product.currency)
127
+ });
128
+ }
129
+ if ('originCountryCode' in product) {
130
+ if (typeof product.originCountryCode === 'undefined') {
131
+ attrs['compliance_category'] = 'COUNTRY_ORIGIN_EXEMPT';
132
+ }
133
+ else {
134
+ content.push({
135
+ tag: 'compliance_info',
136
+ attrs: {},
137
+ content: [
138
+ {
139
+ tag: 'country_code_origin',
140
+ attrs: {},
141
+ content: Buffer.from(product.originCountryCode)
142
+ }
143
+ ]
144
+ });
145
+ }
146
+ }
147
+ if (typeof product.isHidden !== 'undefined') {
148
+ attrs['is_hidden'] = product.isHidden.toString();
149
+ }
150
+ const node = {
151
+ tag: 'product',
152
+ attrs,
153
+ content
154
+ };
155
+ return node;
156
+ };
157
+ exports.toProductNode = toProductNode;
158
+ const parseProductNode = (productNode) => {
159
+ const isHidden = productNode.attrs.is_hidden === 'true';
160
+ const id = (0, WABinary_1.getBinaryNodeChildString)(productNode, 'id');
161
+ const mediaNode = (0, WABinary_1.getBinaryNodeChild)(productNode, 'media');
162
+ const statusInfoNode = (0, WABinary_1.getBinaryNodeChild)(productNode, 'status_info');
163
+ const product = {
164
+ id,
165
+ imageUrls: parseImageUrls(mediaNode),
166
+ reviewStatus: {
167
+ whatsapp: (0, WABinary_1.getBinaryNodeChildString)(statusInfoNode, 'status'),
168
+ },
169
+ availability: 'in stock',
170
+ name: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'name'),
171
+ retailerId: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'retailer_id'),
172
+ url: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'url'),
173
+ description: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'description'),
174
+ price: +(0, WABinary_1.getBinaryNodeChildString)(productNode, 'price'),
175
+ currency: (0, WABinary_1.getBinaryNodeChildString)(productNode, 'currency'),
176
+ isHidden,
177
+ };
178
+ return product;
179
+ };
180
+ exports.parseProductNode = parseProductNode;
181
+ /**
182
+ * Uploads images not already uploaded to WA's servers
183
+ */
184
+ async function uploadingNecessaryImagesOfProduct(product, waUploadToServer, timeoutMs = 30000) {
185
+ product = {
186
+ ...product,
187
+ images: product.images ? await (0, exports.uploadingNecessaryImages)(product.images, waUploadToServer, timeoutMs) : product.images
188
+ };
189
+ return product;
190
+ }
191
+ exports.uploadingNecessaryImagesOfProduct = uploadingNecessaryImagesOfProduct;
192
+ /**
193
+ * Uploads images not already uploaded to WA's servers
194
+ */
195
+ const uploadingNecessaryImages = async (images, waUploadToServer, timeoutMs = 30000) => {
196
+ const results = await Promise.all(images.map(async (img) => {
197
+ if ('url' in img) {
198
+ const url = img.url.toString();
199
+ if (url.includes('.whatsapp.net')) {
200
+ return { url };
201
+ }
202
+ }
203
+ const { stream } = await (0, messages_media_1.getStream)(img);
204
+ const hasher = (0, crypto_1.createHash)('sha256');
205
+ const contentBlocks = [];
206
+ for await (const block of stream) {
207
+ hasher.update(block);
208
+ contentBlocks.push(block);
209
+ }
210
+ const sha = hasher.digest('base64');
211
+ const { directPath } = await waUploadToServer((0, messages_media_1.toReadable)(Buffer.concat(contentBlocks)), {
212
+ mediaType: 'product-catalog-image',
213
+ fileEncSha256B64: sha,
214
+ timeoutMs
215
+ });
216
+ return { url: (0, messages_media_1.getUrlFromDirectPath)(directPath) };
217
+ }));
218
+ return results;
219
+ };
220
+ exports.uploadingNecessaryImages = uploadingNecessaryImages;
221
+ const parseImageUrls = (mediaNode) => {
222
+ const imgNode = (0, WABinary_1.getBinaryNodeChild)(mediaNode, 'image');
223
+ return {
224
+ requested: (0, WABinary_1.getBinaryNodeChildString)(imgNode, 'request_image_url'),
225
+ original: (0, WABinary_1.getBinaryNodeChildString)(imgNode, 'original_image_url')
226
+ };
227
+ };
228
+ const parseStatusInfo = (mediaNode) => {
229
+ const node = (0, WABinary_1.getBinaryNodeChild)(mediaNode, 'status_info');
230
+ return {
231
+ status: (0, WABinary_1.getBinaryNodeChildString)(node, 'status'),
232
+ canAppeal: (0, WABinary_1.getBinaryNodeChildString)(node, 'can_appeal') === 'true',
233
+ };
234
+ };