sanka-baileyss 2.3.2 → 2.3.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 (158) hide show
  1. package/WAProto/BotMetadata/BotMetadata.d.ts +594 -1
  2. package/WAProto/BotMetadata/BotMetadata.js +1910 -148
  3. package/WAProto/BotMetadata/BotMetadata.proto +36 -0
  4. package/WAProto/E2E/E2E.d.ts +570 -6
  5. package/WAProto/E2E/E2E.js +1591 -26
  6. package/WAProto/E2E/E2E.proto +10 -1
  7. package/WAProto/HistorySync/HistorySync.d.ts +806 -6
  8. package/WAProto/HistorySync/HistorySync.js +2193 -29
  9. package/WAProto/HistorySync/HistorySync.proto +2 -1
  10. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.d.ts +570 -6
  11. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.js +1591 -26
  12. package/WAProto/StatusAttributions/StatusAttributions.d.ts +2 -1
  13. package/WAProto/StatusAttributions/StatusAttributions.js +7 -0
  14. package/WAProto/StatusAttributions/StatusAttributions.proto +1 -0
  15. package/WAProto/SyncAction/SyncAction.d.ts +230 -0
  16. package/WAProto/SyncAction/SyncAction.js +578 -2
  17. package/WAProto/SyncAction/SyncAction.proto +13 -1
  18. package/WAProto/Web/Web.d.ts +570 -6
  19. package/WAProto/Web/Web.js +1591 -26
  20. package/lib/Defaults/baileys-version.json +2 -2
  21. package/lib/Defaults/index.d.ts +42 -25
  22. package/lib/Defaults/index.js +6 -2
  23. package/lib/Signal/libsignal.d.ts +1 -0
  24. package/lib/Socket/Client/index.js +13 -9
  25. package/lib/Socket/Client/types.d.ts +11 -10
  26. package/lib/Socket/Client/types.js +11 -7
  27. package/lib/Socket/Client/websocket.d.ts +9 -8
  28. package/lib/Socket/Client/websocket.js +52 -47
  29. package/lib/Socket/business.d.ts +185 -182
  30. package/lib/Socket/business.js +258 -249
  31. package/lib/Socket/chats.d.ts +90 -87
  32. package/lib/Socket/chats.js +1095 -888
  33. package/lib/Socket/community.d.ts +131 -0
  34. package/lib/Socket/community.js +369 -0
  35. package/lib/Socket/groups.d.ts +50 -41
  36. package/lib/Socket/groups.js +10 -3
  37. package/lib/Socket/index.d.ts +5 -1
  38. package/lib/Socket/index.js +19 -5
  39. package/lib/Socket/messages-recv.d.ts +6 -2
  40. package/lib/Socket/messages-recv.js +31 -8
  41. package/lib/Socket/messages-send.d.ts +5 -1
  42. package/lib/Socket/messages-send.js +1293 -1351
  43. package/lib/Socket/newsletter.d.ts +142 -135
  44. package/lib/Socket/newsletter.js +274 -230
  45. package/lib/Socket/socket.d.ts +37 -35
  46. package/lib/Socket/usync.d.ts +31 -30
  47. package/lib/Socket/usync.js +74 -62
  48. package/lib/Types/Auth.d.ts +89 -72
  49. package/lib/Types/Auth.js +1 -0
  50. package/lib/Types/Call.d.ts +11 -10
  51. package/lib/Types/Call.js +1 -0
  52. package/lib/Types/Chat.d.ts +85 -62
  53. package/lib/Types/Chat.js +4 -1
  54. package/lib/Types/Contact.js +1 -0
  55. package/lib/Types/Events.d.ts +209 -191
  56. package/lib/Types/Events.js +1 -0
  57. package/lib/Types/GroupMetadata.d.ts +12 -27
  58. package/lib/Types/GroupMetadata.js +1 -0
  59. package/lib/Types/Label.d.ts +41 -39
  60. package/lib/Types/Label.js +24 -21
  61. package/lib/Types/LabelAssociation.d.ts +18 -12
  62. package/lib/Types/LabelAssociation.js +6 -3
  63. package/lib/Types/Message.d.ts +3 -2
  64. package/lib/Types/Message.js +7 -3
  65. package/lib/Types/MexUpdates.d.ts +9 -0
  66. package/lib/Types/MexUpdates.js +18 -0
  67. package/lib/Types/Newsletter.d.ts +84 -67
  68. package/lib/Types/Newsletter.js +30 -23
  69. package/lib/Types/Product.d.ts +70 -56
  70. package/lib/Types/Product.js +1 -0
  71. package/lib/Types/Signal.d.ts +46 -35
  72. package/lib/Types/Signal.js +1 -0
  73. package/lib/Types/Socket.d.ts +105 -101
  74. package/lib/Types/Socket.js +1 -0
  75. package/lib/Types/State.d.ts +37 -23
  76. package/lib/Types/State.js +13 -1
  77. package/lib/Types/USync.d.ts +21 -20
  78. package/lib/Types/USync.js +1 -0
  79. package/lib/Types/index.d.ts +51 -42
  80. package/lib/Types/index.js +25 -19
  81. package/lib/Utils/auth-utils.d.ts +14 -11
  82. package/lib/Utils/auth-utils.js +189 -182
  83. package/lib/Utils/baileys-event-stream.d.ts +12 -10
  84. package/lib/Utils/baileys-event-stream.js +52 -46
  85. package/lib/Utils/business.d.ts +15 -8
  86. package/lib/Utils/business.js +229 -217
  87. package/lib/Utils/chat-utils.d.ts +22 -12
  88. package/lib/Utils/chat-utils.js +57 -27
  89. package/lib/Utils/crypto.d.ts +31 -15
  90. package/lib/Utils/crypto.js +136 -107
  91. package/lib/Utils/decode-wa-message.d.ts +34 -245
  92. package/lib/Utils/decode-wa-message.js +205 -217
  93. package/lib/Utils/event-buffer.d.ts +30 -26
  94. package/lib/Utils/event-buffer.js +519 -515
  95. package/lib/Utils/history.d.ts +2 -8
  96. package/lib/Utils/index.js +13 -9
  97. package/lib/Utils/link-preview.d.ts +16 -14
  98. package/lib/Utils/link-preview.js +100 -92
  99. package/lib/Utils/logger.d.ts +9 -7
  100. package/lib/Utils/logger.js +1 -1
  101. package/lib/Utils/lt-hash.d.ts +10 -8
  102. package/lib/Utils/lt-hash.js +49 -44
  103. package/lib/Utils/make-mutex.d.ts +4 -2
  104. package/lib/Utils/make-mutex.js +43 -39
  105. package/lib/Utils/messages-media.d.ts +75 -50
  106. package/lib/Utils/messages.d.ts +60 -35
  107. package/lib/Utils/messages.js +87 -8
  108. package/lib/Utils/noise-handler.d.ts +13 -12
  109. package/lib/Utils/noise-handler.js +143 -138
  110. package/lib/Utils/process-message.d.ts +32 -24
  111. package/lib/Utils/process-message.js +387 -367
  112. package/lib/Utils/signal.d.ts +24 -15
  113. package/lib/Utils/signal.js +143 -131
  114. package/lib/Utils/use-mongo-file-auth-state.d.ts +3 -2
  115. package/lib/Utils/use-mongo-file-auth-state.js +72 -63
  116. package/lib/Utils/use-multi-file-auth-state.d.ts +9 -8
  117. package/lib/Utils/use-multi-file-auth-state.js +110 -102
  118. package/lib/Utils/use-single-file-auth-state.d.ts +8 -7
  119. package/lib/Utils/use-single-file-auth-state.js +66 -61
  120. package/lib/Utils/validate-connection.d.ts +5 -2
  121. package/lib/Utils/validate-connection.js +7 -6
  122. package/lib/WABinary/constants.d.ts +24 -21
  123. package/lib/WABinary/constants.js +1302 -31
  124. package/lib/WABinary/decode.d.ts +4 -1
  125. package/lib/WABinary/decode.js +267 -234
  126. package/lib/WABinary/encode.d.ts +1 -0
  127. package/lib/WABinary/encode.js +248 -226
  128. package/lib/WABinary/generic-utils.d.ts +13 -1
  129. package/lib/WABinary/generic-utils.js +113 -96
  130. package/lib/WABinary/index.js +13 -9
  131. package/lib/WABinary/jid-utils.d.ts +23 -4
  132. package/lib/WABinary/jid-utils.js +58 -39
  133. package/lib/WABinary/types.d.ts +15 -11
  134. package/lib/WABinary/types.js +1 -0
  135. package/lib/WAM/BinaryInfo.d.ts +14 -14
  136. package/lib/WAM/BinaryInfo.js +11 -8
  137. package/lib/WAM/constants.d.ts +34 -26
  138. package/lib/WAM/constants.js +15358 -15349
  139. package/lib/WAM/encode.d.ts +1 -0
  140. package/lib/WAM/encode.js +153 -144
  141. package/lib/WAM/index.js +13 -9
  142. package/lib/index.js +11 -11
  143. package/package.json +1 -2
  144. package/WASignalGroup/GroupProtocol.js +0 -1771
  145. package/WASignalGroup/ciphertext_message.js +0 -10
  146. package/WASignalGroup/group_cipher.js +0 -103
  147. package/WASignalGroup/group_session_builder.js +0 -39
  148. package/WASignalGroup/index.js +0 -5
  149. package/WASignalGroup/keyhelper.js +0 -17
  150. package/WASignalGroup/protobufs.js +0 -2
  151. package/WASignalGroup/queue_job.js +0 -64
  152. package/WASignalGroup/sender_chain_key.js +0 -38
  153. package/WASignalGroup/sender_key_distribution_message.js +0 -68
  154. package/WASignalGroup/sender_key_message.js +0 -79
  155. package/WASignalGroup/sender_key_name.js +0 -59
  156. package/WASignalGroup/sender_key_record.js +0 -47
  157. package/WASignalGroup/sender_key_state.js +0 -110
  158. package/WASignalGroup/sender_message_key.js +0 -30
@@ -1,198 +1,205 @@
1
1
  "use strict"
2
+
2
3
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod }
4
+ return (mod && mod.__esModule) ? mod : { "default": mod }
4
5
  }
6
+
5
7
  Object.defineProperty(exports, "__esModule", { value: true })
8
+
6
9
  const crypto_1 = require("crypto")
7
10
  const node_cache_1 = __importDefault(require("@cacheable/node-cache"))
8
11
  const Defaults_1 = require("../Defaults")
9
12
  const crypto_2 = require("./crypto")
10
13
  const generics_1 = require("./generics")
14
+
11
15
  /**
12
- * Adds caching capability to a SignalKeyStore
13
- * @param store the store to add caching to
14
- * @param logger to log trace events
15
- * @param _cache cache store to use
16
- */
16
+ * Adds caching capability to a SignalKeyStore
17
+ * @param store the store to add caching to
18
+ * @param logger to log trace events
19
+ * @param _cache cache store to use
20
+ */
17
21
  function makeCacheableSignalKeyStore(store, logger, _cache) {
18
- const cache = _cache || new node_cache_1.default({
19
- stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.SIGNAL_STORE,
20
- useClones: false,
21
- deleteOnExpire: true,
22
- })
23
- function getUniqueId(type, id) {
24
- return `${type}.${id}`
25
- }
26
- return {
27
- async get(type, ids) {
28
- const data = {}
29
- const idsToFetch = []
30
- for (const id of ids) {
31
- const item = cache.get(getUniqueId(type, id))
32
- if (typeof item !== 'undefined') {
33
- data[id] = item
34
- }
35
- else {
36
- idsToFetch.push(id)
37
- }
38
- }
39
- if (idsToFetch.length) {
40
- logger?.trace({ items: idsToFetch.length }, 'loading from store')
41
- const fetched = await store.get(type, idsToFetch)
42
- for (const id of idsToFetch) {
43
- const item = fetched[id]
44
- if (item) {
45
- data[id] = item
46
- cache.set(getUniqueId(type, id), item)
47
- }
48
- }
49
- }
50
- return data
51
- },
52
- async set(data) {
53
- let keys = 0
54
- for (const type in data) {
55
- for (const id in data[type]) {
56
- cache.set(getUniqueId(type, id), data[type][id])
57
- keys += 1
58
- }
59
- }
60
- logger?.trace({ keys }, 'updated cache')
61
- await store.set(data)
62
- },
63
- async clear() {
64
- cache.flushAll()
65
- await store.clear?.call(store)
66
- }
67
- }
68
- }
22
+ const cache = _cache || new node_cache_1.default({
23
+ stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.SIGNAL_STORE,
24
+ useClones: false,
25
+ deleteOnExpire: true,
26
+ })
27
+ function getUniqueId(type, id) {
28
+ return `${type}.${id}`
29
+ }
30
+ return {
31
+ async get(type, ids) {
32
+ const data = {}
33
+ const idsToFetch = []
34
+ for (const id of ids) {
35
+ const item = cache.get(getUniqueId(type, id))
36
+ if (typeof item !== 'undefined') {
37
+ data[id] = item
38
+ }
39
+ else {
40
+ idsToFetch.push(id)
41
+ }
42
+ }
43
+ if (idsToFetch.length) {
44
+ logger?.trace({ items: idsToFetch.length }, 'loading from store')
45
+ const fetched = await store.get(type, idsToFetch)
46
+ for (const id of idsToFetch) {
47
+ const item = fetched[id]
48
+ if (item) {
49
+ data[id] = item
50
+ cache.set(getUniqueId(type, id), item)
51
+ }
52
+ }
53
+ }
54
+ return data
55
+ },
56
+ async set(data) {
57
+ let keys = 0
58
+ for (const type in data) {
59
+ for (const id in data[type]) {
60
+ cache.set(getUniqueId(type, id), data[type][id])
61
+ keys += 1
62
+ }
63
+ }
64
+ logger?.trace({ keys }, 'updated cache')
65
+ await store.set(data)
66
+ },
67
+ async clear() {
68
+ cache.flushAll()
69
+ await store.clear?.call(store)
70
+ }
71
+ }
72
+ }
73
+
69
74
  /**
70
- * Adds DB like transaction capability (https://en.wikipedia.org/wiki/Database_transaction) to the SignalKeyStore,
71
- * this allows batch read & write operations & improves the performance of the lib
72
- * @param state the key store to apply this capability to
73
- * @param logger logger to log events
74
- * @returns SignalKeyStore with transaction capability
75
- */
75
+ * Adds DB like transaction capability (https://en.wikipedia.org/wiki/Database_transaction) to the SignalKeyStore,
76
+ * this allows batch read & write operations & improves the performance of the lib
77
+ * @param state the key store to apply this capability to
78
+ * @param logger logger to log events
79
+ * @returns SignalKeyStore with transaction capability
80
+ */
76
81
  const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetweenTriesMs }) => {
77
- // number of queries made to the DB during the transaction
78
- // only there for logging purposes
79
- let dbQueriesInTransaction = 0
80
- let transactionCache = {}
81
- let mutations = {}
82
- let transactionsInProgress = 0
83
- return {
84
- get: async (type, ids) => {
85
- if (isInTransaction()) {
86
- const dict = transactionCache[type]
87
- const idsRequiringFetch = dict
88
- ? ids.filter(item => typeof dict[item] === 'undefined')
89
- : ids
90
- // only fetch if there are any items to fetch
91
- if (idsRequiringFetch.length) {
92
- dbQueriesInTransaction += 1
93
- const result = await state.get(type, idsRequiringFetch)
94
- transactionCache[type] || (transactionCache[type] = {})
95
- Object.assign(transactionCache[type], result)
96
- }
97
- return ids.reduce((dict, id) => {
98
- const value = transactionCache[type]?.[id]
99
- if (value) {
100
- dict[id] = value
101
- }
102
- return dict
103
- }, {})
104
- }
105
- else {
106
- return state.get(type, ids)
107
- }
108
- },
109
- set: data => {
110
- if (isInTransaction()) {
111
- logger.trace({ types: Object.keys(data) }, 'caching in transaction')
112
- for (const key in data) {
113
- transactionCache[key] = transactionCache[key] || {}
114
- Object.assign(transactionCache[key], data[key])
115
- mutations[key] = mutations[key] || {}
116
- Object.assign(mutations[key], data[key])
117
- }
118
- }
119
- else {
120
- return state.set(data)
121
- }
122
- },
123
- isInTransaction,
124
- async transaction(work) {
125
- let result
126
- transactionsInProgress += 1
127
- if (transactionsInProgress === 1) {
128
- logger.trace('entering transaction')
129
- }
130
- try {
131
- result = await work()
132
- // commit if this is the outermost transaction
133
- if (transactionsInProgress === 1) {
134
- if (Object.keys(mutations).length) {
135
- logger.trace('committing transaction')
136
- // retry mechanism to ensure we've some recovery
137
- // in case a transaction fails in the first attempt
138
- let tries = maxCommitRetries
139
- while (tries) {
140
- tries -= 1
141
- try {
142
- await state.set(mutations)
143
- logger.trace({ dbQueriesInTransaction }, 'committed transaction')
144
- break
145
- }
146
- catch (error) {
147
- logger.warn(`failed to commit ${Object.keys(mutations).length} mutations, tries left=${tries}`)
148
- await generics_1.delay(delayBetweenTriesMs)
149
- }
150
- }
151
- }
152
- else {
153
- logger.trace('no mutations in transaction')
154
- }
155
- }
156
- }
157
- finally {
158
- transactionsInProgress -= 1
159
- if (transactionsInProgress === 0) {
160
- transactionCache = {}
161
- mutations = {}
162
- dbQueriesInTransaction = 0
163
- }
164
- }
165
- return result
166
- }
167
- }
168
- function isInTransaction() {
169
- return transactionsInProgress > 0
170
- }
171
- }
82
+ // number of queries made to the DB during the transaction
83
+ // only there for logging purposes
84
+ let dbQueriesInTransaction = 0
85
+ let transactionCache = {}
86
+ let mutations = {}
87
+ let transactionsInProgress = 0
88
+ return {
89
+ get: async (type, ids) => {
90
+ if (isInTransaction()) {
91
+ const dict = transactionCache[type]
92
+ const idsRequiringFetch = dict
93
+ ? ids.filter(item => typeof dict[item] === 'undefined')
94
+ : ids
95
+ // only fetch if there are any items to fetch
96
+ if (idsRequiringFetch.length) {
97
+ dbQueriesInTransaction += 1
98
+ const result = await state.get(type, idsRequiringFetch)
99
+ transactionCache[type] || (transactionCache[type] = {})
100
+ Object.assign(transactionCache[type], result)
101
+ }
102
+ return ids.reduce((dict, id) => {
103
+ const value = transactionCache[type]?.[id]
104
+ if (value) {
105
+ dict[id] = value
106
+ }
107
+ return dict
108
+ }, {})
109
+ }
110
+ else {
111
+ return state.get(type, ids)
112
+ }
113
+ },
114
+ set: data => {
115
+ if (isInTransaction()) {
116
+ logger.trace({ types: Object.keys(data) }, 'caching in transaction')
117
+ for (const key in data) {
118
+ transactionCache[key] = transactionCache[key] || {}
119
+ Object.assign(transactionCache[key], data[key])
120
+ mutations[key] = mutations[key] || {}
121
+ Object.assign(mutations[key], data[key])
122
+ }
123
+ }
124
+ else {
125
+ return state.set(data)
126
+ }
127
+ },
128
+ isInTransaction,
129
+ async transaction(work) {
130
+ let result
131
+ transactionsInProgress += 1
132
+ if (transactionsInProgress === 1) {
133
+ logger.trace('entering transaction')
134
+ }
135
+ try {
136
+ result = await work()
137
+ // commit if this is the outermost transaction
138
+ if (transactionsInProgress === 1) {
139
+ if (Object.keys(mutations).length) {
140
+ logger.trace('committing transaction')
141
+ // retry mechanism to ensure we've some recovery
142
+ // in case a transaction fails in the first attempt
143
+ let tries = maxCommitRetries
144
+ while (tries) {
145
+ tries -= 1
146
+ try {
147
+ await state.set(mutations)
148
+ logger.trace({ dbQueriesInTransaction }, 'committed transaction')
149
+ break
150
+ }
151
+ catch (error) {
152
+ logger.warn(`failed to commit ${Object.keys(mutations).length} mutations, tries left=${tries}`)
153
+ await generics_1.delay(delayBetweenTriesMs)
154
+ }
155
+ }
156
+ }
157
+ else {
158
+ logger.trace('no mutations in transaction')
159
+ }
160
+ }
161
+ }
162
+ finally {
163
+ transactionsInProgress -= 1
164
+ if (transactionsInProgress === 0) {
165
+ transactionCache = {}
166
+ mutations = {}
167
+ dbQueriesInTransaction = 0
168
+ }
169
+ }
170
+ return result
171
+ }
172
+ }
173
+ function isInTransaction() {
174
+ return transactionsInProgress > 0
175
+ }
176
+ }
177
+
172
178
  const initAuthCreds = () => {
173
- const identityKey = crypto_2.Curve.generateKeyPair()
174
- return {
175
- noiseKey: crypto_2.Curve.generateKeyPair(),
176
- pairingEphemeralKeyPair: crypto_2.Curve.generateKeyPair(),
177
- signedIdentityKey: identityKey,
178
- signedPreKey: crypto_2.signedKeyPair(identityKey, 1),
179
- registrationId: generics_1.generateRegistrationId(),
180
- advSecretKey: crypto_1.randomBytes(32).toString('base64'),
181
- processedHistoryMessages: [],
182
- nextPreKeyId: 1,
183
- firstUnuploadedPreKeyId: 1,
184
- accountSyncCounter: 0,
185
- accountSettings: {
186
- unarchiveChats: false
187
- },
188
- registered: false,
189
- pairingCode: undefined,
190
- lastPropHash: undefined,
191
- routingInfo: undefined
192
- }
193
- }
179
+ const identityKey = crypto_2.Curve.generateKeyPair()
180
+ return {
181
+ noiseKey: crypto_2.Curve.generateKeyPair(),
182
+ pairingEphemeralKeyPair: crypto_2.Curve.generateKeyPair(),
183
+ signedIdentityKey: identityKey,
184
+ signedPreKey: crypto_2.signedKeyPair(identityKey, 1),
185
+ registrationId: generics_1.generateRegistrationId(),
186
+ advSecretKey: crypto_1.randomBytes(32).toString('base64'),
187
+ processedHistoryMessages: [],
188
+ nextPreKeyId: 1,
189
+ firstUnuploadedPreKeyId: 1,
190
+ accountSyncCounter: 0,
191
+ accountSettings: {
192
+ unarchiveChats: false
193
+ },
194
+ registered: false,
195
+ pairingCode: undefined,
196
+ lastPropHash: undefined,
197
+ routingInfo: undefined
198
+ }
199
+ }
200
+
194
201
  module.exports = {
195
- makeCacheableSignalKeyStore,
196
- addTransactionCapability,
197
- initAuthCreds
202
+ makeCacheableSignalKeyStore,
203
+ addTransactionCapability,
204
+ initAuthCreds
198
205
  }
@@ -1,16 +1,18 @@
1
1
  import type { BaileysEventEmitter } from '../Types'
2
+
2
3
  /**
3
- * Captures events from a baileys event emitter & stores them in a file
4
- * @param ev The event emitter to read events from
5
- * @param filename File to save to
6
- */
4
+ * Captures events from a baileys event emitter & stores them in a file
5
+ * @param ev The event emitter to read events from
6
+ * @param filename File to save to
7
+ */
7
8
  export declare const captureEventStream: (ev: BaileysEventEmitter, filename: string) => void
9
+
8
10
  /**
9
- * Read event file and emit events from there
10
- * @param filename filename containing event data
11
- * @param delayIntervalMs delay between each event emit
12
- */
11
+ * Read event file and emit events from there
12
+ * @param filename filename containing event data
13
+ * @param delayIntervalMs delay between each event emit
14
+ */
13
15
  export declare const readAndEmitEventStream: (filename: string, delayIntervalMs?: number) => {
14
- ev: BaileysEventEmitter
15
- task: Promise<void>
16
+ ev: BaileysEventEmitter
17
+ task: Promise<void>
16
18
  }
@@ -1,64 +1,70 @@
1
1
  "use strict"
2
+
2
3
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod }
4
+ return (mod && mod.__esModule) ? mod : { "default": mod }
4
5
  }
6
+
5
7
  Object.defineProperty(exports, "__esModule", { value: true })
8
+
6
9
  const events_1 = __importDefault(require("events"))
7
10
  const fs_1 = require("fs")
8
11
  const promises_1 = require("fs/promises")
9
12
  const readline_1 = require("readline")
10
13
  const generics_1 = require("./generics")
11
14
  const make_mutex_1 = require("./make-mutex")
15
+
12
16
  /**
13
- * Captures events from a baileys event emitter & stores them in a file
14
- * @param ev The event emitter to read events from
15
- * @param filename File to save to
16
- */
17
+ * Captures events from a baileys event emitter & stores them in a file
18
+ * @param ev The event emitter to read events from
19
+ * @param filename File to save to
20
+ */
17
21
  const captureEventStream = (ev, filename) => {
18
- const oldEmit = ev.emit
19
- // write mutex so data is appended in order
20
- const writeMutex = make_mutex_1.makeMutex()
21
- // monkey patch eventemitter to capture all events
22
- ev.emit = function (...args) {
23
- const content = JSON.stringify({ timestamp: Date.now(), event: args[0], data: args[1] }) + '\n'
24
- const result = oldEmit.apply(ev, args)
25
- writeMutex.mutex(async () => {
26
- await promises_1.writeFile(filename, content, { flag: 'a' })
27
- })
28
- return result
29
- }
22
+ const oldEmit = ev.emit
23
+ // write mutex so data is appended in order
24
+ const writeMutex = make_mutex_1.makeMutex()
25
+ // monkey patch eventemitter to capture all events
26
+ ev.emit = function (...args) {
27
+ const content = JSON.stringify({ timestamp: Date.now(), event: args[0], data: args[1] }) + '\n'
28
+ const result = oldEmit.apply(ev, args)
29
+ writeMutex.mutex(async () => {
30
+ await promises_1.writeFile(filename, content, { flag: 'a' })
31
+ })
32
+ return result
33
+ }
30
34
  }
35
+
31
36
  /**
32
- * Read event file and emit events from there
33
- * @param filename filename containing event data
34
- * @param delayIntervalMs delay between each event emit
35
- */
37
+ * Read event file and emit events from there
38
+ * @param filename filename containing event data
39
+ * @param delayIntervalMs delay between each event emit
40
+ */
36
41
  const readAndEmitEventStream = (filename, delayIntervalMs = 0) => {
37
- const ev = new events_1.default()
38
- const fireEvents = async () => {
39
- // from: https://stackoverflow.com/questions/6156501/read-a-file-one-line-at-a-time-in-node-js
40
- const fileStream = fs_1.createReadStream(filename)
41
- const rl = readline_1.createInterface({
42
- input: fileStream,
43
- crlfDelay: Infinity
44
- })
45
- // Note: we use the crlfDelay option to recognize all instances of CR LF
46
- // ('\r\n') in input.txt as a single line break.
47
- for await (const line of rl) {
48
- if (line) {
49
- const { event, data } = JSON.parse(line)
50
- ev.emit(event, data)
51
- delayIntervalMs && await generics_1.delay(delayIntervalMs)
52
- }
53
- }
54
- fileStream.close()
55
- }
56
- return {
57
- ev,
58
- task: fireEvents()
59
- }
42
+ const ev = new events_1.default()
43
+ const fireEvents = async () => {
44
+ // from: https://stackoverflow.com/questions/6156501/read-a-file-one-line-at-a-time-in-node-js
45
+ const fileStream = fs_1.createReadStream(filename)
46
+ const rl = readline_1.createInterface({
47
+ input: fileStream,
48
+ crlfDelay: Infinity
49
+ })
50
+ // Note: we use the crlfDelay option to recognize all instances of CR LF
51
+ // ('\r\n') in input.txt as a single line break.
52
+ for await (const line of rl) {
53
+ if (line) {
54
+ const { event, data } = JSON.parse(line)
55
+ ev.emit(event, data)
56
+ delayIntervalMs && await generics_1.delay(delayIntervalMs)
57
+ }
58
+ }
59
+ fileStream.close()
60
+ }
61
+ return {
62
+ ev,
63
+ task: fireEvents()
64
+ }
60
65
  }
66
+
61
67
  module.exports = {
62
- captureEventStream,
63
- readAndEmitEventStream
68
+ captureEventStream,
69
+ readAndEmitEventStream
64
70
  }
@@ -1,22 +1,29 @@
1
1
  import { CatalogCollection, OrderDetails, Product, ProductCreate, ProductUpdate, WAMediaUpload, WAMediaUploadFunction } from '../Types'
2
2
  import { BinaryNode } from '../WABinary'
3
+
3
4
  export declare const parseCatalogNode: (node: BinaryNode) => {
4
- products: Product[]
5
- nextPageCursor: string | undefined
5
+ products: Product[]
6
+ nextPageCursor: string | undefined
6
7
  }
8
+
7
9
  export declare const parseCollectionsNode: (node: BinaryNode) => {
8
- collections: CatalogCollection[]
10
+ collections: CatalogCollection[]
9
11
  }
12
+
10
13
  export declare const parseOrderDetailsNode: (node: BinaryNode) => OrderDetails
14
+
11
15
  export declare const toProductNode: (productId: string | undefined, product: ProductCreate | ProductUpdate) => BinaryNode
16
+
12
17
  export declare const parseProductNode: (productNode: BinaryNode) => Product
18
+
13
19
  /**
14
- * Uploads images not already uploaded to WA's servers
15
- */
20
+ * Uploads images not already uploaded to WA's servers
21
+ */
16
22
  export declare function uploadingNecessaryImagesOfProduct<T extends ProductUpdate | ProductCreate>(product: T, waUploadToServer: WAMediaUploadFunction, timeoutMs?: number): Promise<T>
23
+
17
24
  /**
18
- * Uploads images not already uploaded to WA's servers
19
- */
25
+ * Uploads images not already uploaded to WA's servers
26
+ */
20
27
  export declare const uploadingNecessaryImages: (images: WAMediaUpload[], waUploadToServer: WAMediaUploadFunction, timeoutMs?: number) => Promise<{
21
- url: string
28
+ url: string
22
29
  }[]>