nodejs-insta-private-api-mqt 1.3.79 → 1.3.80
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.
|
@@ -114,8 +114,13 @@ class AccountRepository extends Repository {
|
|
|
114
114
|
'X-FB-Connection-Type': 'MOBILE.LTE',
|
|
115
115
|
'X-FB-Network-Properties': 'VPN;Metered;Validated;LocalAddrs=/10.0.0.2,;',
|
|
116
116
|
'X-FB-Conn-UUID-Client': crypto.randomBytes(16).toString('hex'),
|
|
117
|
+
'X-IG-Bandwidth-Speed-KBPS': (Math.random() * 1500 + 1500).toFixed(3),
|
|
118
|
+
'X-IG-Bandwidth-TotalBytes-B': '0',
|
|
119
|
+
'X-IG-Bandwidth-TotalTime-MS': '0',
|
|
120
|
+
'X-IG-Connection-Type': 'MOBILE(LTE)',
|
|
121
|
+
'X-IG-Capabilities': '3brTv10=',
|
|
117
122
|
'Accept-Encoding': 'gzip, deflate',
|
|
118
|
-
'X-FB-HTTP-Engine': '
|
|
123
|
+
'X-FB-HTTP-Engine': 'MNS/TCP',
|
|
119
124
|
};
|
|
120
125
|
|
|
121
126
|
const response = await this.client.request.send({
|
|
@@ -184,52 +189,132 @@ class AccountRepository extends Repository {
|
|
|
184
189
|
throw err;
|
|
185
190
|
}
|
|
186
191
|
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
192
|
+
const bearerPatterns = [
|
|
193
|
+
/Bearer IGT:2:[A-Za-z0-9+\/=]+/,
|
|
194
|
+
/Bearer\s+IGT:2:[A-Za-z0-9+\/=]+/,
|
|
195
|
+
/\\?"Bearer IGT:2:([A-Za-z0-9+\/=]+)\\?"/,
|
|
196
|
+
/ig-set-authorization[\\"\s:]*Bearer IGT:2:([A-Za-z0-9+\/=]+)/i,
|
|
197
|
+
];
|
|
198
|
+
for (const pattern of bearerPatterns) {
|
|
199
|
+
const bearerMatch = layoutStr.match(pattern);
|
|
200
|
+
if (bearerMatch) {
|
|
201
|
+
const token = bearerMatch[0].includes('Bearer IGT:2:')
|
|
202
|
+
? bearerMatch[0].replace(/^.*?(Bearer IGT:2:[A-Za-z0-9+\/=]+).*$/, '$1')
|
|
203
|
+
: `Bearer IGT:2:${bearerMatch[1]}`;
|
|
204
|
+
this.client.state.authorization = token.replace(/\\?"/g, '').trim();
|
|
205
|
+
this.client.state.updateAuthorization();
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
191
208
|
}
|
|
192
209
|
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
|
|
210
|
+
const pkPatterns = [
|
|
211
|
+
/\\"pk\\":\s*(\d+)/,
|
|
212
|
+
/"pk":\s*(\d+)/,
|
|
213
|
+
/\\"pk_id\\":\s*\\"(\d+)\\"/,
|
|
214
|
+
/"pk_id":\s*"(\d+)"/,
|
|
215
|
+
/logged_in_user.*?"pk":\s*(\d+)/,
|
|
216
|
+
/logged_in_user.*?\\"pk\\":\s*(\d+)/,
|
|
217
|
+
];
|
|
218
|
+
let extractedPk = null;
|
|
219
|
+
for (const pattern of pkPatterns) {
|
|
220
|
+
const pkMatch = layoutStr.match(pattern);
|
|
221
|
+
if (pkMatch) {
|
|
222
|
+
extractedPk = pkMatch[1];
|
|
223
|
+
this.client.state.cookieUserId = extractedPk;
|
|
224
|
+
this.client.state._userId = extractedPk;
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
196
227
|
}
|
|
197
228
|
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
|
|
229
|
+
const wwwClaimPatterns = [
|
|
230
|
+
/IG-Set-WWW-Claim[\\"\s:]+([a-f0-9]+)/i,
|
|
231
|
+
/ig-set-www-claim[\\"\s:]+([a-f0-9]+)/i,
|
|
232
|
+
/www.claim[\\"\s:]+([a-f0-9]+)/i,
|
|
233
|
+
/x-ig-set-www-claim[\\"\s:]+([a-f0-9]+)/i,
|
|
234
|
+
];
|
|
235
|
+
for (const pattern of wwwClaimPatterns) {
|
|
236
|
+
const wwwClaimMatch = layoutStr.match(pattern);
|
|
237
|
+
if (wwwClaimMatch) {
|
|
238
|
+
this.client.state.igWWWClaim = wwwClaimMatch[1];
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
201
241
|
}
|
|
202
242
|
|
|
203
|
-
const encKeyIdMatch = layoutStr.match(/IG-Set-Password-Encryption-Key-Id[\\"\s:]+(\d+)/i)
|
|
243
|
+
const encKeyIdMatch = layoutStr.match(/IG-Set-Password-Encryption-Key-Id[\\"\s:]+(\d+)/i) ||
|
|
244
|
+
layoutStr.match(/password.encryption.key.id[\\"\s:]+(\d+)/i);
|
|
204
245
|
if (encKeyIdMatch) {
|
|
205
246
|
this.client.state.passwordEncryptionKeyId = parseInt(encKeyIdMatch[1]);
|
|
206
247
|
}
|
|
207
248
|
|
|
208
|
-
const encPubKeyMatch = layoutStr.match(/IG-Set-Password-Encryption-Pub-Key[\\"\s:]+([A-Za-z0-9+\/=]+)/i)
|
|
249
|
+
const encPubKeyMatch = layoutStr.match(/IG-Set-Password-Encryption-Pub-Key[\\"\s:]+([A-Za-z0-9+\/=]+)/i) ||
|
|
250
|
+
layoutStr.match(/password.encryption.pub.key[\\"\s:]+([A-Za-z0-9+\/=]+)/i);
|
|
209
251
|
if (encPubKeyMatch) {
|
|
210
252
|
this.client.state.passwordEncryptionPubKey = encPubKeyMatch[1];
|
|
211
253
|
}
|
|
212
254
|
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
255
|
+
const midMatch = layoutStr.match(/ig-set-x-mid[\\"\s:]+([A-Za-z0-9+\/=_-]+)/i) ||
|
|
256
|
+
layoutStr.match(/\\"x-mid\\"[\\"\s:]+([A-Za-z0-9+\/=_-]+)/i);
|
|
257
|
+
if (midMatch) {
|
|
258
|
+
this.client.state.mid = midMatch[1];
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const loginResponsePatterns = [
|
|
262
|
+
/\\"logged_in_user\\":\{[^}]*\\"pk\\":(\d+)[^}]*\\"username\\":\\"([^"\\]+)\\"/,
|
|
263
|
+
/"logged_in_user":\{[^}]*"pk":(\d+)[^}]*"username":"([^"]+)"/,
|
|
264
|
+
/\\"logged_in_user\\".*?\\"pk\\":\s*(\d+).*?\\"username\\":\s*\\"([^"\\]+)\\"/s,
|
|
265
|
+
];
|
|
266
|
+
for (const pattern of loginResponsePatterns) {
|
|
267
|
+
const loginResponseMatch = layoutStr.match(pattern);
|
|
268
|
+
if (loginResponseMatch) {
|
|
269
|
+
this.client.state.cookieUserId = loginResponseMatch[1];
|
|
270
|
+
this.client.state._userId = loginResponseMatch[1];
|
|
271
|
+
return {
|
|
272
|
+
pk: parseInt(loginResponseMatch[1]),
|
|
273
|
+
pk_id: loginResponseMatch[1],
|
|
274
|
+
username: loginResponseMatch[2],
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (extractedPk && this.client.state.authorization) {
|
|
280
|
+
try {
|
|
281
|
+
const userInfo = await this.currentUser();
|
|
282
|
+
const user = userInfo.user || userInfo;
|
|
283
|
+
if (user && user.pk) {
|
|
284
|
+
this.client.state.cookieUserId = String(user.pk);
|
|
285
|
+
this.client.state._userId = String(user.pk);
|
|
286
|
+
}
|
|
287
|
+
return user;
|
|
288
|
+
} catch (e) {
|
|
289
|
+
return { pk: parseInt(extractedPk), pk_id: extractedPk };
|
|
290
|
+
}
|
|
220
291
|
}
|
|
221
292
|
}
|
|
222
293
|
|
|
223
294
|
if (body.logged_in_user) {
|
|
224
|
-
|
|
295
|
+
const lu = body.logged_in_user;
|
|
296
|
+
if (lu.pk) {
|
|
297
|
+
this.client.state.cookieUserId = String(lu.pk);
|
|
298
|
+
this.client.state._userId = String(lu.pk);
|
|
299
|
+
}
|
|
300
|
+
return lu;
|
|
225
301
|
}
|
|
226
302
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
303
|
+
if (this.client.state.authorization) {
|
|
304
|
+
try {
|
|
305
|
+
const userInfo = await this.currentUser();
|
|
306
|
+
const user = userInfo.user || userInfo;
|
|
307
|
+
if (user && user.pk) {
|
|
308
|
+
this.client.state.cookieUserId = String(user.pk);
|
|
309
|
+
this.client.state._userId = String(user.pk);
|
|
310
|
+
}
|
|
311
|
+
return user;
|
|
312
|
+
} catch (e) {
|
|
313
|
+
return body;
|
|
314
|
+
}
|
|
232
315
|
}
|
|
316
|
+
|
|
317
|
+
return body;
|
|
233
318
|
});
|
|
234
319
|
}
|
|
235
320
|
|
|
@@ -12,10 +12,31 @@ class DirectRepository extends Repository {
|
|
|
12
12
|
const result = await requestFn();
|
|
13
13
|
return result;
|
|
14
14
|
} catch (error) {
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
const errorCode = error.data?.content?.error_code || error.data?.error_code;
|
|
16
|
+
const errorType = error.data?.error_type;
|
|
17
|
+
const statusCode = error.status || error.data?.status_code;
|
|
18
|
+
|
|
19
|
+
const isPromptContribution = errorCode === 4415001;
|
|
20
|
+
const isAuthIssue = statusCode === 400 && isPromptContribution;
|
|
21
|
+
const isServerError = errorType === 'server_error';
|
|
22
|
+
const isRateLimited = errorType === 'rate_limited';
|
|
23
|
+
const isLoginRequired = error.data?.message === 'login_required' || errorType === 'login_required';
|
|
24
|
+
|
|
25
|
+
if ((isAuthIssue || isLoginRequired) && retries < this.maxRetries) {
|
|
26
|
+
try {
|
|
27
|
+
if (this.client.state.authorization) {
|
|
28
|
+
this.client.state.updateAuthorization();
|
|
29
|
+
}
|
|
30
|
+
if (this.client.account && typeof this.client.account.syncPostLoginExperiments === 'function') {
|
|
31
|
+
await this.client.account.syncPostLoginExperiments().catch(() => {});
|
|
32
|
+
}
|
|
33
|
+
} catch (syncErr) {}
|
|
34
|
+
const delay = 2000 * (retries + 1);
|
|
35
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
|
36
|
+
return this.requestWithRetry(requestFn, retries + 1);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const shouldRetry = (isServerError || isRateLimited) && retries < this.maxRetries;
|
|
19
40
|
if (shouldRetry) {
|
|
20
41
|
const delay = 1000 * (retries + 1);
|
|
21
42
|
await new Promise(resolve => setTimeout(resolve, delay));
|
|
@@ -159,6 +180,19 @@ class DirectRepository extends Repository {
|
|
|
159
180
|
}
|
|
160
181
|
|
|
161
182
|
async getInbox(cursor = null, limit = 20) {
|
|
183
|
+
if (!this.client.state.authorization) {
|
|
184
|
+
throw new Error('Not authenticated. Please login first before accessing inbox.');
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const userId = this.client.state.cookieUserId || this.client.state._userId;
|
|
188
|
+
if (!userId || userId === '0' || userId === 0) {
|
|
189
|
+
this.client.state.updateAuthorization();
|
|
190
|
+
if (this.client.state.parsedAuthorization && this.client.state.parsedAuthorization.ds_user_id) {
|
|
191
|
+
this.client.state._userId = this.client.state.parsedAuthorization.ds_user_id;
|
|
192
|
+
this.client.state.cookieUserId = this.client.state.parsedAuthorization.ds_user_id;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
162
196
|
return this.requestWithRetry(async () => {
|
|
163
197
|
const qs = { persistentBadging: true, limit };
|
|
164
198
|
if (cursor) qs.cursor = cursor;
|
package/package.json
CHANGED