nodejs-insta-private-api-mqt 1.4.8 → 1.4.9
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/dist/dist/core/client.js +0 -9
- package/dist/dist/core/state.js +0 -9
- package/dist/dist/core/utils.js +2 -6
- package/dist/dist/realtime/commands/direct.commands.js +5 -5
- package/dist/dist/realtime/commands/enhanced.direct.commands.js +5 -5
- package/dist/dist/realtime/features/persistent-logger.js +0 -4
- package/dist/dist/realtime/mixins/message-sync.mixin.js +0 -2
- package/dist/dist/realtime/realtime.client.js +1 -1
- package/dist/dist/realtime/realtime.service.js +0 -12
- package/dist/dist/repositories/direct-thread.repository.js +2 -4
- package/dist/dist/useMultiFileAuthState.js +0 -5
- package/dist/dist/utils/index.js +0 -1
- package/dist/dist/utils/insta-mqtt-helper.js +5 -5
- package/package.json +1 -1
package/dist/dist/core/client.js
CHANGED
|
@@ -128,7 +128,6 @@ class IgApiClient extends EventEmitter {
|
|
|
128
128
|
*/
|
|
129
129
|
async simulateAndroidBehavior() {
|
|
130
130
|
if (this.state.verbose)
|
|
131
|
-
console.log('[Anti-Bot] Simulating Android-specific background behaviors...');
|
|
132
131
|
// 0. Pre-login notification suppression / Trust signal
|
|
133
132
|
try {
|
|
134
133
|
await this.request.send({
|
|
@@ -209,7 +208,6 @@ class IgApiClient extends EventEmitter {
|
|
|
209
208
|
// -------------------------------
|
|
210
209
|
async preLoginFlow() {
|
|
211
210
|
if (this.state.verbose)
|
|
212
|
-
console.log('[Pre-Login] Starting pre-login flow (sync_launcher)...');
|
|
213
211
|
try {
|
|
214
212
|
await this.request.send({
|
|
215
213
|
url: '/api/v1/launcher/sync/',
|
|
@@ -220,7 +218,6 @@ class IgApiClient extends EventEmitter {
|
|
|
220
218
|
}),
|
|
221
219
|
});
|
|
222
220
|
if (this.state.verbose)
|
|
223
|
-
console.log('[Pre-Login] Launcher Sync: OK');
|
|
224
221
|
}
|
|
225
222
|
catch (e) {
|
|
226
223
|
if (this.state.verbose)
|
|
@@ -230,7 +227,6 @@ class IgApiClient extends EventEmitter {
|
|
|
230
227
|
}
|
|
231
228
|
async postLoginFlow() {
|
|
232
229
|
if (this.state.verbose)
|
|
233
|
-
console.log('[Post-Login] Starting post-login flow...');
|
|
234
230
|
try {
|
|
235
231
|
await this.request.send({
|
|
236
232
|
url: '/api/v1/feed/reels_tray/',
|
|
@@ -247,7 +243,6 @@ class IgApiClient extends EventEmitter {
|
|
|
247
243
|
}),
|
|
248
244
|
});
|
|
249
245
|
if (this.state.verbose)
|
|
250
|
-
console.log('[Post-Login] Reels tray: OK');
|
|
251
246
|
}
|
|
252
247
|
catch (e) {
|
|
253
248
|
if (this.state.verbose)
|
|
@@ -284,7 +279,6 @@ class IgApiClient extends EventEmitter {
|
|
|
284
279
|
},
|
|
285
280
|
});
|
|
286
281
|
if (this.state.verbose)
|
|
287
|
-
console.log('[Post-Login] Timeline feed: OK');
|
|
288
282
|
}
|
|
289
283
|
catch (e) {
|
|
290
284
|
if (this.state.verbose)
|
|
@@ -315,7 +309,6 @@ class IgApiClient extends EventEmitter {
|
|
|
315
309
|
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
316
310
|
try {
|
|
317
311
|
if (this.state.verbose) {
|
|
318
|
-
console.log(`[Retry] attempt ${attempt + 1}/${retries + 1}`);
|
|
319
312
|
}
|
|
320
313
|
const res = await fn();
|
|
321
314
|
return res;
|
|
@@ -361,7 +354,6 @@ class IgApiClient extends EventEmitter {
|
|
|
361
354
|
const json = typeof data === 'string' ? data : JSON.stringify(data, null, 2);
|
|
362
355
|
await fs.promises.writeFile(p, json, { mode: 0o600 });
|
|
363
356
|
if (this.state.verbose)
|
|
364
|
-
console.log('[Session] Saved session to', p);
|
|
365
357
|
return p;
|
|
366
358
|
}
|
|
367
359
|
/**
|
|
@@ -386,7 +378,6 @@ class IgApiClient extends EventEmitter {
|
|
|
386
378
|
}
|
|
387
379
|
await this.loadSession(sessionObj);
|
|
388
380
|
if (this.state.verbose)
|
|
389
|
-
console.log('[Session] Loaded session from', p);
|
|
390
381
|
return true;
|
|
391
382
|
}
|
|
392
383
|
/**
|
package/dist/dist/core/state.js
CHANGED
|
@@ -953,7 +953,6 @@ class State {
|
|
|
953
953
|
: this.cookieJar.getCookies(this.constants.HOST);
|
|
954
954
|
if (Array.isArray(cookies)) {
|
|
955
955
|
for (const c of cookies) {
|
|
956
|
-
console.log(`- ${c.key}=${c.value}`);
|
|
957
956
|
}
|
|
958
957
|
return cookies;
|
|
959
958
|
}
|
|
@@ -964,14 +963,6 @@ class State {
|
|
|
964
963
|
}
|
|
965
964
|
}
|
|
966
965
|
logStateSummary() {
|
|
967
|
-
console.log('--- State Summary ---');
|
|
968
|
-
console.log(`Device ID: ${this.deviceId}`);
|
|
969
|
-
console.log(`UUID: ${this.uuid}`);
|
|
970
|
-
console.log(`User Agent: ${this.appUserAgent}`);
|
|
971
|
-
console.log(`Language: ${this.language}`);
|
|
972
|
-
console.log(`Timezone Offset: ${this.timezoneOffset}`);
|
|
973
|
-
console.log(`Authorization: ${this.authorization ? 'Present' : 'Missing'}`);
|
|
974
|
-
console.log('----------------------');
|
|
975
966
|
}
|
|
976
967
|
//
|
|
977
968
|
// === NEW UTILITIES ADDED BELOW (non-destructive; keep backwards compat)
|
package/dist/dist/core/utils.js
CHANGED
|
@@ -645,12 +645,8 @@ class Utils {
|
|
|
645
645
|
};
|
|
646
646
|
return (codes[color] || codes.reset) + text + codes.reset;
|
|
647
647
|
}
|
|
648
|
-
static logRed(...args) {
|
|
649
|
-
|
|
650
|
-
}
|
|
651
|
-
static logGreen(...args) {
|
|
652
|
-
console.log(this.colorize(args.map(String).join(' '), 'green'));
|
|
653
|
-
}
|
|
648
|
+
static logRed(...args) {}
|
|
649
|
+
static logGreen(...args) {}
|
|
654
650
|
/* -------------------------
|
|
655
651
|
System / environment helpers
|
|
656
652
|
------------------------- */
|
|
@@ -7,9 +7,9 @@ const Chance = require("chance");
|
|
|
7
7
|
const thrift_1 = require("../../thrift");
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* SerialQueue —
|
|
11
|
-
*
|
|
12
|
-
* race conditions
|
|
10
|
+
* SerialQueue — Strictly serial queue with retry and exponential backoff.
|
|
11
|
+
* Used per-thread to serialize MQTT operations and prevent
|
|
12
|
+
* race conditions and lost messages on reconnect.
|
|
13
13
|
*/
|
|
14
14
|
class SerialQueue {
|
|
15
15
|
constructor(name) {
|
|
@@ -70,9 +70,9 @@ class DirectCommands {
|
|
|
70
70
|
];
|
|
71
71
|
this.client = client;
|
|
72
72
|
this.chance = new Chance();
|
|
73
|
-
//
|
|
73
|
+
// Per-thread queue for MQTT operations
|
|
74
74
|
this._threadQueues = new Map();
|
|
75
|
-
//
|
|
75
|
+
// Global queue for non-thread operations (e.g. foreground state)
|
|
76
76
|
this._globalQueue = new SerialQueue('direct:global');
|
|
77
77
|
}
|
|
78
78
|
|
|
@@ -7,9 +7,9 @@ const constants_1 = require("../../constants");
|
|
|
7
7
|
const thrift_1 = require("../../thrift");
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* SerialQueue —
|
|
11
|
-
*
|
|
12
|
-
* race conditions
|
|
10
|
+
* SerialQueue — Strictly serial queue with retry and exponential backoff.
|
|
11
|
+
* Used per-thread to serialize MQTT operations and prevent
|
|
12
|
+
* race conditions and lost messages on reconnect.
|
|
13
13
|
*/
|
|
14
14
|
class SerialQueue {
|
|
15
15
|
constructor(name) {
|
|
@@ -81,9 +81,9 @@ class EnhancedDirectCommands {
|
|
|
81
81
|
thrift_1.ThriftDescriptors.listOfBinary('unsubscribeGenericTopics', 7),
|
|
82
82
|
thrift_1.ThriftDescriptors.int64('requestId', 8),
|
|
83
83
|
];
|
|
84
|
-
//
|
|
84
|
+
// Per-thread queue for MQTT operations
|
|
85
85
|
this._threadQueues = new Map();
|
|
86
|
-
//
|
|
86
|
+
// Global queue for non-thread operations (e.g. foreground state)
|
|
87
87
|
this._globalQueue = new SerialQueue('enhanced:global');
|
|
88
88
|
}
|
|
89
89
|
/** Returnează (sau creează) coada pentru un threadId specific */
|
|
@@ -67,10 +67,6 @@ class PersistentLogger {
|
|
|
67
67
|
return String(a);
|
|
68
68
|
}).join(' ');
|
|
69
69
|
const line = `[${timestamp}] [${level.toUpperCase()}] ${message}`;
|
|
70
|
-
if (this.logToConsole) {
|
|
71
|
-
const consoleFn = level === 'error' ? console.error : (level === 'warn' ? console.warn : console.log);
|
|
72
|
-
consoleFn(line);
|
|
73
|
-
}
|
|
74
70
|
this._buffer.push(line);
|
|
75
71
|
this._totalLines++;
|
|
76
72
|
if (this._buffer.length >= 50) {
|
|
@@ -523,12 +523,10 @@ class MessageSyncMixin extends mixin_1.Mixin {
|
|
|
523
523
|
}
|
|
524
524
|
}
|
|
525
525
|
catch (inner) {
|
|
526
|
-
console.log(`[MESSAGE_SYNC] element handling error: ${inner?.message || inner}`);
|
|
527
526
|
}
|
|
528
527
|
}
|
|
529
528
|
}
|
|
530
529
|
catch (outer) {
|
|
531
|
-
console.log(`[MESSAGE_SYNC] item error: ${outer?.message || outer}`);
|
|
532
530
|
}
|
|
533
531
|
}
|
|
534
532
|
}
|
|
@@ -72,9 +72,6 @@ class RealtimeService extends EventEmitter {
|
|
|
72
72
|
// Broker URL
|
|
73
73
|
const brokerUrl = `${this.protocol}://${this.broker}:${this.port}`;
|
|
74
74
|
if (this.client.state.verbose) {
|
|
75
|
-
console.log(`[Realtime] Connecting to MQTT broker: ${brokerUrl}`);
|
|
76
|
-
console.log(`[Realtime] Client ID: ${this.clientId}`);
|
|
77
|
-
console.log(`[Realtime] Username: ${this.username}`);
|
|
78
75
|
}
|
|
79
76
|
// Create MQTT connection
|
|
80
77
|
this.mqttClient = mqtt.connect(brokerUrl, mqttOptions);
|
|
@@ -117,7 +114,6 @@ class RealtimeService extends EventEmitter {
|
|
|
117
114
|
disconnect() {
|
|
118
115
|
if (this.mqttClient && this.isConnected) {
|
|
119
116
|
if (this.client.state.verbose) {
|
|
120
|
-
console.log('[Realtime] Disconnecting from MQTT broker...');
|
|
121
117
|
}
|
|
122
118
|
this.mqttClient.end();
|
|
123
119
|
this.isConnected = false;
|
|
@@ -137,7 +133,6 @@ class RealtimeService extends EventEmitter {
|
|
|
137
133
|
ping() {
|
|
138
134
|
if (this.isRealtimeConnected()) {
|
|
139
135
|
if (this.client.state.verbose) {
|
|
140
|
-
console.log('[Realtime] Sending ping...');
|
|
141
136
|
}
|
|
142
137
|
// MQTT client handles ping automatically through keepalive
|
|
143
138
|
// But we can emit an event for debugging
|
|
@@ -176,7 +171,6 @@ class RealtimeService extends EventEmitter {
|
|
|
176
171
|
this.isConnected = true;
|
|
177
172
|
this.reconnectAttempts = 0;
|
|
178
173
|
if (this.client.state.verbose) {
|
|
179
|
-
console.log('[Realtime] Connected to MQTT broker');
|
|
180
174
|
}
|
|
181
175
|
// Subscribe to all topics
|
|
182
176
|
this._subscribeToTopics();
|
|
@@ -191,7 +185,6 @@ class RealtimeService extends EventEmitter {
|
|
|
191
185
|
try {
|
|
192
186
|
const message = payload.toString();
|
|
193
187
|
if (this.client.state.verbose) {
|
|
194
|
-
console.log(`[Realtime] Received message on ${topic}: ${message}`);
|
|
195
188
|
}
|
|
196
189
|
// Find the topic configuration
|
|
197
190
|
const topicConfig = this._findTopicByPath(topic);
|
|
@@ -294,7 +287,6 @@ class RealtimeService extends EventEmitter {
|
|
|
294
287
|
_onClose() {
|
|
295
288
|
this.isConnected = false;
|
|
296
289
|
if (this.client.state.verbose) {
|
|
297
|
-
console.log('[Realtime] MQTT connection closed');
|
|
298
290
|
}
|
|
299
291
|
this.emit('disconnected');
|
|
300
292
|
// Try reconnection if not manually disconnected
|
|
@@ -309,7 +301,6 @@ class RealtimeService extends EventEmitter {
|
|
|
309
301
|
_onOffline() {
|
|
310
302
|
this.isConnected = false;
|
|
311
303
|
if (this.client.state.verbose) {
|
|
312
|
-
console.log('[Realtime] MQTT client offline');
|
|
313
304
|
}
|
|
314
305
|
this.emit('offline');
|
|
315
306
|
}
|
|
@@ -319,7 +310,6 @@ class RealtimeService extends EventEmitter {
|
|
|
319
310
|
*/
|
|
320
311
|
_onReconnect() {
|
|
321
312
|
if (this.client.state.verbose) {
|
|
322
|
-
console.log('[Realtime] MQTT client reconnecting...');
|
|
323
313
|
}
|
|
324
314
|
this.emit('reconnecting');
|
|
325
315
|
}
|
|
@@ -340,7 +330,6 @@ class RealtimeService extends EventEmitter {
|
|
|
340
330
|
}
|
|
341
331
|
else {
|
|
342
332
|
if (this.client.state.verbose) {
|
|
343
|
-
console.log(`[Realtime] Subscribed to ${topic.path}`);
|
|
344
333
|
}
|
|
345
334
|
}
|
|
346
335
|
});
|
|
@@ -357,7 +346,6 @@ class RealtimeService extends EventEmitter {
|
|
|
357
346
|
this.reconnectAttempts++;
|
|
358
347
|
const delay = this.reconnectDelay * Math.pow(2, this.reconnectAttempts - 1); // Exponential backoff
|
|
359
348
|
if (this.client.state.verbose) {
|
|
360
|
-
console.log(`[Realtime] Scheduling reconnect in ${delay}ms (attempt ${this.reconnectAttempts}/${this.maxReconnectAttempts})`);
|
|
361
349
|
}
|
|
362
350
|
setTimeout(() => {
|
|
363
351
|
if (this.reconnectAttempts <= this.maxReconnectAttempts) {
|
|
@@ -12,8 +12,7 @@ class DirectThreadRepository extends Repository {
|
|
|
12
12
|
*/
|
|
13
13
|
async requestWithRetry(requestFn, retries = 0) {
|
|
14
14
|
try {
|
|
15
|
-
if (process.env.DEBUG)
|
|
16
|
-
console.log(`[DEBUG] Attempt #${retries + 1}`);
|
|
15
|
+
if (process.env.DEBUG) {}
|
|
17
16
|
const result = await requestFn();
|
|
18
17
|
return result;
|
|
19
18
|
}
|
|
@@ -26,8 +25,7 @@ class DirectThreadRepository extends Repository {
|
|
|
26
25
|
retries < this.maxRetries;
|
|
27
26
|
if (shouldRetry) {
|
|
28
27
|
const delay = 1000 * (retries + 1);
|
|
29
|
-
if (process.env.DEBUG)
|
|
30
|
-
console.log(`[DEBUG] Retrying after ${delay}ms due to ${error.data?.error_type || error.message || error.name || error.status}`);
|
|
28
|
+
if (process.env.DEBUG) {}
|
|
31
29
|
await new Promise(resolve => setTimeout(resolve, delay));
|
|
32
30
|
return this.requestWithRetry(requestFn, retries + 1);
|
|
33
31
|
}
|
|
@@ -1514,7 +1514,6 @@ async function useMultiFileAuthState(folder) {
|
|
|
1514
1514
|
authState._debouncedSave(['creds']);
|
|
1515
1515
|
}
|
|
1516
1516
|
catch (e) { }
|
|
1517
|
-
console.log('[useMultiFileAuthState] Credentials saved to', folder);
|
|
1518
1517
|
};
|
|
1519
1518
|
const saveMqttSession = async (realtimeClient) => {
|
|
1520
1519
|
if (!realtimeClient) {
|
|
@@ -1612,7 +1611,6 @@ async function useMultiFileAuthState(folder) {
|
|
|
1612
1611
|
// Increment stats
|
|
1613
1612
|
authState.incrementStat('mqttMessages');
|
|
1614
1613
|
await authState.saveMqttState();
|
|
1615
|
-
console.log('[useMultiFileAuthState] MQTT session saved to', folder);
|
|
1616
1614
|
};
|
|
1617
1615
|
const loadCreds = async (igClient) => {
|
|
1618
1616
|
if (!igClient || !igClient.state) {
|
|
@@ -1620,11 +1618,9 @@ async function useMultiFileAuthState(folder) {
|
|
|
1620
1618
|
return false;
|
|
1621
1619
|
}
|
|
1622
1620
|
if (!authState.hasValidSession()) {
|
|
1623
|
-
console.log('[useMultiFileAuthState] No valid session found');
|
|
1624
1621
|
return false;
|
|
1625
1622
|
}
|
|
1626
1623
|
await applyStateData(igClient.state, authState);
|
|
1627
|
-
console.log('[useMultiFileAuthState] Credentials loaded from', folder);
|
|
1628
1624
|
return true;
|
|
1629
1625
|
};
|
|
1630
1626
|
const getMqttConnectOptions = () => {
|
|
@@ -1655,7 +1651,6 @@ async function useMultiFileAuthState(folder) {
|
|
|
1655
1651
|
};
|
|
1656
1652
|
const clearSession = async () => {
|
|
1657
1653
|
await authState.clearAll();
|
|
1658
|
-
console.log('[useMultiFileAuthState] Session cleared');
|
|
1659
1654
|
};
|
|
1660
1655
|
const isSessionValid = async (igClient) => {
|
|
1661
1656
|
if (!authState.hasValidSession())
|
package/dist/dist/utils/index.js
CHANGED
|
@@ -9,15 +9,15 @@ const async_mutex_1 = require("async-mutex");
|
|
|
9
9
|
const p_queue_1 = __importDefault(require("p-queue"));
|
|
10
10
|
// Logger stub if not provided
|
|
11
11
|
const defaultLogger = {
|
|
12
|
-
trace: (
|
|
13
|
-
debug: (
|
|
14
|
-
info: (
|
|
12
|
+
trace: () => {},
|
|
13
|
+
debug: () => {},
|
|
14
|
+
info: () => {},
|
|
15
15
|
warn: (obj, msg) => console.warn('[WARN]', msg, obj),
|
|
16
16
|
error: (obj, msg) => console.error('[ERROR]', msg, obj),
|
|
17
17
|
};
|
|
18
18
|
/**
|
|
19
19
|
* Adds transaction capability and sequential processing to the Instagram Realtime Client
|
|
20
|
-
* ensuring messages are sent in order (e.g. "
|
|
20
|
+
* ensuring messages are sent in order (e.g. "Hello" before "How are you").
|
|
21
21
|
*
|
|
22
22
|
* @param client The RealtimeClient instance from nodejs-insta-private-api-mqt
|
|
23
23
|
* @param logger Optional logger
|
|
@@ -26,7 +26,7 @@ const defaultLogger = {
|
|
|
26
26
|
const addTransactionCapability = (client, logger = defaultLogger) => {
|
|
27
27
|
const txStorage = new async_hooks_1.AsyncLocalStorage();
|
|
28
28
|
// Global queue for all direct thread operations to ensure sequence
|
|
29
|
-
// concurrency: 1 is CRITICAL for ensuring messages arrive in
|
|
29
|
+
// concurrency: 1 is CRITICAL for ensuring messages arrive in the correct sequential order
|
|
30
30
|
const globalQueue = new p_queue_1.default({ concurrency: 1 });
|
|
31
31
|
// Per-thread queues if we want parallelism across different threads but serial within a thread
|
|
32
32
|
const threadQueues = new Map();
|