nodejs-insta-private-api-mqtt 1.3.11 → 1.3.12

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.
@@ -12,7 +12,7 @@ const mqtts_1 = require("mqtts");
12
12
  * Changes applied:
13
13
  * - tolerant parsing for e.value (string / object / already-parsed)
14
14
  * - support for several path shapes when extracting thread id
15
- * - safer timestamp parsing (accepts seconds or milliseconds)
15
+ * - safer timestamp parsing (accepts seconds, milliseconds, microseconds, nanoseconds)
16
16
  * - username fetch uses a pending map + small backoff to reduce rush/rate-limit risk
17
17
  * - defensive try/catch around JSON.parse and all external calls
18
18
  * - keeps original API: apply(client) registers post-connect hook and emits same events
@@ -20,6 +20,8 @@ const mqtts_1 = require("mqtts");
20
20
  * Additional change requested:
21
21
  * - set message status to 'received' for incoming messages and 'sent' for messages authored by the logged-in account,
22
22
  * instead of the previous 'good'.
23
+ *
24
+ * Note: No rate-limiting code is included.
23
25
  */
24
26
 
25
27
  class MessageSyncMixin extends mixin_1.Mixin {
@@ -305,12 +307,22 @@ class MessageSyncMixin extends mixin_1.Mixin {
305
307
 
306
308
  formatMessageForConsole(msgData) {
307
309
  const separator = '----------------------------------------';
308
- // robust timestamp formatting
310
+ // robust timestamp formatting into readable date+time in Europe/Bucharest
309
311
  let ts = 'N/A';
310
312
  try {
311
- if (msgData.timestamp) {
312
- const t = this.parseTimestamp(msgData.timestamp);
313
- if (t) ts = new Date(t).toISOString();
313
+ const parsed = this.parseTimestamp(msgData.timestamp);
314
+ if (parsed) {
315
+ const d = new Date(parsed);
316
+ ts = d.toLocaleString('ro-RO', {
317
+ year: 'numeric',
318
+ month: '2-digit',
319
+ day: '2-digit',
320
+ hour: '2-digit',
321
+ minute: '2-digit',
322
+ second: '2-digit',
323
+ hour12: false,
324
+ timeZone: 'Europe/Bucharest'
325
+ });
314
326
  }
315
327
  } catch (e) {
316
328
  ts = 'N/A';
@@ -334,17 +346,55 @@ class MessageSyncMixin extends mixin_1.Mixin {
334
346
  return lines.join('\n');
335
347
  }
336
348
 
349
+ /**
350
+ * parseTimestamp
351
+ * - accepts numeric strings or numbers in seconds, milliseconds, microseconds, nanoseconds
352
+ * - normalizes to milliseconds
353
+ * - sanity-checks to avoid absurd future dates; returns Date.now() fallback if out of range
354
+ */
337
355
  parseTimestamp(ts) {
338
- // Accept numeric seconds or milliseconds, or numeric-like string
339
356
  try {
340
357
  if (ts === undefined || ts === null) return null;
341
- const n = Number(ts);
342
- if (isNaN(n)) return null;
343
- // heuristics: if > 10^12 -> already ms; if between 10^9 .. 10^12 -> probably seconds -> convert
344
- if (n > 1e12) return n; // ms
345
- if (n > 1e9) return n * 1000; // sec -> ms
346
- if (n > 1e6) return n * 1000; // fallback seconds-ish
347
- // otherwise treat as ms fallback
358
+ // if object with .ms or similar, try common fields
359
+ if (typeof ts === 'object') {
360
+ if (ts.ms) return Number(ts.ms);
361
+ if (ts.seconds) return Number(ts.seconds) * 1000;
362
+ if (ts.nano) return Math.floor(Number(ts.nano) / 1e6);
363
+ // fallback to toString
364
+ ts = String(ts);
365
+ }
366
+ let n = Number(ts);
367
+ if (!Number.isFinite(n)) return null;
368
+
369
+ // Heuristics:
370
+ // nanoseconds ~ 1e18+, microseconds ~ 1e15+, milliseconds ~ 1e12, seconds ~ 1e9
371
+ if (n > 1e17) {
372
+ // nanoseconds -> ms
373
+ n = Math.floor(n / 1e6);
374
+ } else if (n > 1e14) {
375
+ // microseconds -> ms
376
+ n = Math.floor(n / 1e3);
377
+ } else if (n > 1e12) {
378
+ // likely already ms (leave)
379
+ n = Math.floor(n);
380
+ } else if (n > 1e9) {
381
+ // seconds -> ms
382
+ n = Math.floor(n * 1000);
383
+ } else if (n > 1e6) {
384
+ // ambiguous (older formats) -> treat as seconds -> ms
385
+ n = Math.floor(n * 1000);
386
+ } else {
387
+ // too small -> invalid
388
+ return null;
389
+ }
390
+
391
+ // sanity range: allow roughly 2010-2036 (ms)
392
+ const min = 1262304000000; // 2010-01-01
393
+ const max = 2114380800000; // 2037-01-01 (safe future upper bound)
394
+ if (!Number.isFinite(n) || n < min || n > max) {
395
+ // fallback to now to avoid huge future years displayed
396
+ return Date.now();
397
+ }
348
398
  return n;
349
399
  } catch (e) {
350
400
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodejs-insta-private-api-mqtt",
3
- "version": "1.3.11",
3
+ "version": "1.3.12",
4
4
  "description": "Complete Instagram MQTT protocol with FULL iOS + Android support. 33 device presets (21 iOS + 12 Android). iPhone 16/15/14/13/12, iPad Pro, Samsung, Pixel, Huawei. Real-time DM messaging, view-once media extraction, sub-500ms latency.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {