nodejs-insta-private-api-mqt 1.3.85 → 1.3.87

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 (464) hide show
  1. package/dist/dist/constants/constants.d.ts +1 -0
  2. package/dist/dist/constants/index.d.ts +25 -0
  3. package/dist/dist/core/client.d.ts +106 -0
  4. package/dist/dist/core/nav-chain.d.ts +77 -0
  5. package/dist/dist/core/repository.d.ts +3 -0
  6. package/dist/dist/core/request.d.ts +76 -0
  7. package/dist/dist/core/state.d.ts +605 -0
  8. package/dist/dist/core/utils.d.ts +129 -0
  9. package/dist/dist/downloadMedia.d.ts +106 -0
  10. package/{dist-ts → dist}/dist/downloadMedia.js +19 -20
  11. package/dist/dist/errors/index.d.ts +18 -0
  12. package/dist/dist/extend.d.ts +20 -0
  13. package/dist/dist/fbns/fbns.client.d.ts +43 -0
  14. package/dist/dist/fbns/fbns.client.events.d.ts +0 -0
  15. package/{dist-ts → dist}/dist/fbns/fbns.client.js +4 -5
  16. package/dist/dist/fbns/fbns.device-auth.d.ts +9 -0
  17. package/{src-ts/dist/fbns/fbns.device-auth.ts → dist/dist/fbns/fbns.device-auth.js} +6 -3
  18. package/dist/dist/fbns/fbns.types.d.ts +0 -0
  19. package/dist/dist/fbns/fbns.utilities.d.ts +4 -0
  20. package/dist/dist/fbns/index.d.ts +2 -0
  21. package/dist/dist/index.d.ts +49 -0
  22. package/dist/dist/mqtt-shim.d.ts +1 -0
  23. package/dist/dist/mqttot/index.d.ts +2 -0
  24. package/dist/dist/mqttot/mqttot.client.d.ts +77 -0
  25. package/{dist-ts → dist}/dist/mqttot/mqttot.client.js +10 -10
  26. package/dist/dist/mqttot/mqttot.connect.request.packet.d.ts +1 -0
  27. package/dist/dist/mqttot/mqttot.connect.response.packet.d.ts +5 -0
  28. package/dist/dist/mqttot/mqttot.connection.d.ts +6 -0
  29. package/dist/dist/realtime/commands/commands.d.ts +19 -0
  30. package/dist/dist/realtime/commands/direct.commands.d.ts +142 -0
  31. package/dist/dist/realtime/commands/enhanced.direct.commands.d.ts +425 -0
  32. package/{dist-ts → dist}/dist/realtime/commands/enhanced.direct.commands.js +8 -10
  33. package/dist/dist/realtime/commands/index.d.ts +2 -0
  34. package/dist/dist/realtime/delta-sync.manager.d.ts +82 -0
  35. package/{dist-ts → dist}/dist/realtime/delta-sync.manager.js +7 -10
  36. package/dist/dist/realtime/features/dm-sender.d.ts +20 -0
  37. package/{src-ts/dist/realtime/features/dm-sender.ts → dist/dist/realtime/features/dm-sender.js} +6 -3
  38. package/dist/dist/realtime/features/error-handler.d.ts +33 -0
  39. package/{dist-ts → dist}/dist/realtime/features/error-handler.js +4 -4
  40. package/dist/dist/realtime/features/gap-handler.d.ts +19 -0
  41. package/dist/dist/realtime/features/persistent-logger.d.ts +28 -0
  42. package/{dist-ts → dist}/dist/realtime/features/persistent-logger.js +3 -3
  43. package/dist/dist/realtime/features/presence.manager.d.ts +24 -0
  44. package/{src-ts/dist/realtime/features/presence.manager.ts → dist/dist/realtime/features/presence.manager.js} +2 -1
  45. package/dist/dist/realtime/features/session-health-monitor.d.ts +93 -0
  46. package/{src-ts/dist/realtime/features/session-health-monitor.ts → dist/dist/realtime/features/session-health-monitor.js} +45 -65
  47. package/dist/dist/realtime/index.d.ts +9 -0
  48. package/dist/dist/realtime/messages/app-presence.event.d.ts +0 -0
  49. package/dist/dist/realtime/messages/index.d.ts +2 -0
  50. package/dist/dist/realtime/messages/message-sync.message.d.ts +1 -0
  51. package/dist/dist/realtime/messages/realtime-sub.direct.data.d.ts +0 -0
  52. package/dist/dist/realtime/messages/thread-update.message.d.ts +0 -0
  53. package/dist/dist/realtime/mixins/index.d.ts +2 -0
  54. package/dist/dist/realtime/mixins/message-sync.mixin.d.ts +38 -0
  55. package/{dist-ts → dist}/dist/realtime/mixins/message-sync.mixin.js +16 -18
  56. package/dist/dist/realtime/mixins/mixin.d.ts +4 -0
  57. package/dist/dist/realtime/mixins/presence-typing.mixin.d.ts +9 -0
  58. package/dist/dist/realtime/mixins/realtime-sub.mixin.d.ts +37 -0
  59. package/{dist-ts → dist}/dist/realtime/mixins/realtime-sub.mixin.js +4 -5
  60. package/dist/dist/realtime/parsers/graphql-parser.d.ts +18 -0
  61. package/dist/dist/realtime/parsers/graphql.parser.d.ts +10 -0
  62. package/{src-ts/dist/realtime/parsers/graphql.parser.ts → dist/dist/realtime/parsers/graphql.parser.js} +0 -1
  63. package/dist/dist/realtime/parsers/index.d.ts +2 -0
  64. package/dist/dist/realtime/parsers/iris-parser.d.ts +18 -0
  65. package/dist/dist/realtime/parsers/iris.parser.d.ts +3 -0
  66. package/dist/dist/realtime/parsers/json-parser.d.ts +18 -0
  67. package/dist/dist/realtime/parsers/json.parser.d.ts +6 -0
  68. package/dist/dist/realtime/parsers/parser.d.ts +0 -0
  69. package/dist/dist/realtime/parsers/region-hint-parser.d.ts +18 -0
  70. package/dist/dist/realtime/parsers/region-hint.parser.d.ts +4 -0
  71. package/dist/dist/realtime/parsers/skywalker-parser.d.ts +18 -0
  72. package/dist/dist/realtime/parsers/skywalker.parser.d.ts +7 -0
  73. package/dist/dist/realtime/parsers-advanced.d.ts +93 -0
  74. package/{dist-ts → dist}/dist/realtime/parsers-advanced.js +5 -8
  75. package/dist/dist/realtime/proto-parser.d.ts +27 -0
  76. package/{dist-ts → dist}/dist/realtime/proto-parser.js +1 -2
  77. package/dist/dist/realtime/protocols/iris.handshake.d.ts +41 -0
  78. package/dist/dist/realtime/protocols/proto-definitions.d.ts +0 -0
  79. package/dist/dist/realtime/protocols/skywalker.protocol.d.ts +20 -0
  80. package/{src-ts/dist/realtime/protocols/skywalker.protocol.ts → dist/dist/realtime/protocols/skywalker.protocol.js} +8 -5
  81. package/dist/dist/realtime/realtime.client.d.ts +169 -0
  82. package/dist/dist/realtime/realtime.client.events.d.ts +0 -0
  83. package/{dist-ts → dist}/dist/realtime/realtime.client.js +75 -86
  84. package/dist/dist/realtime/realtime.service.d.ts +109 -0
  85. package/dist/dist/realtime/reconnect.manager.d.ts +15 -0
  86. package/dist/dist/realtime/session.manager.d.ts +25 -0
  87. package/dist/dist/realtime/subscriptions/graphql.subscription.d.ts +4 -0
  88. package/dist/dist/realtime/subscriptions/index.d.ts +2 -0
  89. package/dist/dist/realtime/subscriptions/skywalker.subscription.d.ts +4 -0
  90. package/dist/dist/realtime/topic-map.d.ts +97 -0
  91. package/dist/dist/realtime/topic.d.ts +71 -0
  92. package/dist/dist/repositories/account.repository.d.ts +72 -0
  93. package/{dist-ts → dist}/dist/repositories/account.repository.js +828 -214
  94. package/dist/dist/repositories/bloks.repository.d.ts +6 -0
  95. package/dist/dist/repositories/captcha.repository.d.ts +6 -0
  96. package/dist/dist/repositories/challenge.repository.d.ts +12 -0
  97. package/{dist-ts → dist}/dist/repositories/challenge.repository.js +1 -2
  98. package/dist/dist/repositories/clip.repository.d.ts +10 -0
  99. package/dist/dist/repositories/close-friends.repository.d.ts +8 -0
  100. package/dist/dist/repositories/collection.repository.d.ts +8 -0
  101. package/dist/dist/repositories/direct-thread.repository.d.ts +88 -0
  102. package/{dist-ts → dist}/dist/repositories/direct-thread.repository.js +7 -9
  103. package/dist/dist/repositories/direct.repository.d.ts +22 -0
  104. package/{dist-ts → dist}/dist/repositories/direct.repository.js +4 -5
  105. package/dist/dist/repositories/explore.repository.d.ts +7 -0
  106. package/dist/dist/repositories/fbsearch.repository.d.ts +14 -0
  107. package/dist/dist/repositories/feed.repository.d.ts +19 -0
  108. package/dist/dist/repositories/friendship.repository.d.ts +26 -0
  109. package/dist/dist/repositories/fundraiser.repository.d.ts +6 -0
  110. package/dist/dist/repositories/hashtag.repository.d.ts +11 -0
  111. package/dist/dist/repositories/highlights.repository.d.ts +11 -0
  112. package/dist/dist/repositories/insights.repository.d.ts +8 -0
  113. package/dist/dist/repositories/location.repository.d.ts +9 -0
  114. package/dist/dist/repositories/media.repository.d.ts +41 -0
  115. package/{dist-ts → dist}/dist/repositories/media.repository.js +1 -2
  116. package/dist/dist/repositories/multiple-accounts.repository.d.ts +7 -0
  117. package/dist/dist/repositories/news.repository.d.ts +6 -0
  118. package/dist/dist/repositories/note.repository.d.ts +8 -0
  119. package/dist/dist/repositories/notification.repository.d.ts +33 -0
  120. package/{dist-ts → dist}/dist/repositories/notification.repository.js +1 -1
  121. package/dist/dist/repositories/share.repository.d.ts +12 -0
  122. package/dist/dist/repositories/signup.repository.d.ts +19 -0
  123. package/dist/dist/repositories/story.repository.d.ts +23 -0
  124. package/{dist-ts → dist}/dist/repositories/story.repository.js +1 -2
  125. package/dist/dist/repositories/timeline.repository.d.ts +7 -0
  126. package/dist/dist/repositories/totp.repository.d.ts +14 -0
  127. package/dist/dist/repositories/track.repository.d.ts +7 -0
  128. package/{dist-ts → dist}/dist/repositories/track.repository.js +1 -2
  129. package/dist/dist/repositories/upload.repository.d.ts +30 -0
  130. package/{dist-ts → dist}/dist/repositories/upload.repository.js +4 -5
  131. package/dist/dist/repositories/user.repository.d.ts +52 -0
  132. package/dist/dist/sendmedia/index.d.ts +12 -0
  133. package/dist/dist/sendmedia/sendFile.d.ts +8 -0
  134. package/dist/dist/sendmedia/sendPhoto.d.ts +26 -0
  135. package/dist/dist/sendmedia/sendRavenPhoto.d.ts +14 -0
  136. package/{dist-ts → dist}/dist/sendmedia/sendRavenPhoto.js +4 -5
  137. package/dist/dist/sendmedia/sendRavenVideo.d.ts +15 -0
  138. package/{dist-ts → dist}/dist/sendmedia/sendRavenVideo.js +4 -5
  139. package/dist/dist/sendmedia/uploadPhoto.d.ts +8 -0
  140. package/dist/dist/sendmedia/uploadfFile.d.ts +13 -0
  141. package/{dist-ts → dist}/dist/sendmedia/uploadfFile.js +3 -4
  142. package/dist/dist/services/live.service.d.ts +13 -0
  143. package/dist/dist/services/search.service.d.ts +11 -0
  144. package/dist/dist/shared/index.d.ts +4 -0
  145. package/{src-ts/dist/shared/index.ts → dist/dist/shared/index.js} +14 -13
  146. package/dist/dist/shared/shared.d.ts +15 -0
  147. package/dist/dist/thrift/index.d.ts +2 -0
  148. package/dist/dist/thrift/thrift.d.ts +11 -0
  149. package/dist/dist/thrift/thrift.reading.d.ts +49 -0
  150. package/{dist-ts → dist}/dist/thrift/thrift.reading.js +3 -5
  151. package/dist/dist/thrift/thrift.writing.d.ts +49 -0
  152. package/{dist-ts → dist}/dist/thrift/thrift.writing.js +2 -4
  153. package/dist/dist/types/index.d.ts +28 -0
  154. package/dist/dist/useMultiFileAuthState.d.ts +267 -0
  155. package/{dist-ts → dist}/dist/useMultiFileAuthState.js +47 -61
  156. package/dist/dist/utils/helper-1.d.ts +0 -0
  157. package/dist/dist/utils/helper-10.d.ts +0 -0
  158. package/dist/dist/utils/helper-11.d.ts +0 -0
  159. package/dist/dist/utils/helper-12.d.ts +0 -0
  160. package/dist/dist/utils/helper-13.d.ts +0 -0
  161. package/dist/dist/utils/helper-14.d.ts +0 -0
  162. package/dist/dist/utils/helper-15.d.ts +0 -0
  163. package/dist/dist/utils/helper-16.d.ts +0 -0
  164. package/dist/dist/utils/helper-17.d.ts +0 -0
  165. package/dist/dist/utils/helper-18.d.ts +0 -0
  166. package/dist/dist/utils/helper-19.d.ts +0 -0
  167. package/dist/dist/utils/helper-2.d.ts +0 -0
  168. package/dist/dist/utils/helper-20.d.ts +0 -0
  169. package/dist/dist/utils/helper-21.d.ts +0 -0
  170. package/dist/dist/utils/helper-22.d.ts +0 -0
  171. package/dist/dist/utils/helper-23.d.ts +0 -0
  172. package/dist/dist/utils/helper-24.d.ts +0 -0
  173. package/dist/dist/utils/helper-25.d.ts +0 -0
  174. package/dist/dist/utils/helper-26.d.ts +0 -0
  175. package/dist/dist/utils/helper-27.d.ts +0 -0
  176. package/dist/dist/utils/helper-28.d.ts +0 -0
  177. package/dist/dist/utils/helper-29.d.ts +0 -0
  178. package/dist/dist/utils/helper-3.d.ts +0 -0
  179. package/dist/dist/utils/helper-30.d.ts +0 -0
  180. package/dist/dist/utils/helper-4.d.ts +0 -0
  181. package/dist/dist/utils/helper-5.d.ts +0 -0
  182. package/dist/dist/utils/helper-6.d.ts +0 -0
  183. package/dist/dist/utils/helper-7.d.ts +0 -0
  184. package/dist/dist/utils/helper-8.d.ts +0 -0
  185. package/dist/dist/utils/helper-9.d.ts +0 -0
  186. package/dist/dist/utils/index.d.ts +56 -0
  187. package/{dist-ts → dist}/dist/utils/index.js +1 -2
  188. package/dist/dist/utils/insta-mqtt-helper.d.ts +30 -0
  189. package/dist/examples/listen-to-messages.d.ts +4 -0
  190. package/{dist-ts → dist}/examples/listen-to-messages.js +1 -2
  191. package/package.json +37 -42
  192. package/dist-ts/dist/fbns/fbns.device-auth.js +0 -59
  193. package/dist-ts/dist/realtime/features/dm-sender.js +0 -94
  194. package/dist-ts/dist/realtime/features/presence.manager.js +0 -68
  195. package/dist-ts/dist/realtime/features/session-health-monitor.js +0 -327
  196. package/dist-ts/dist/realtime/parsers/graphql.parser.js +0 -22
  197. package/dist-ts/dist/realtime/protocols/skywalker.protocol.js +0 -96
  198. package/dist-ts/dist/shared/index.js +0 -98
  199. package/examples/listen-to-messages.js +0 -86
  200. package/src-ts/dist/constants/constants.ts +0 -342
  201. package/src-ts/dist/constants/index.ts +0 -58
  202. package/src-ts/dist/core/client.ts +0 -419
  203. package/src-ts/dist/core/nav-chain.ts +0 -282
  204. package/src-ts/dist/core/repository.ts +0 -7
  205. package/src-ts/dist/core/request.ts +0 -395
  206. package/src-ts/dist/core/state.ts +0 -1484
  207. package/src-ts/dist/core/utils.ts +0 -786
  208. package/src-ts/dist/downloadMedia.ts +0 -381
  209. package/src-ts/dist/errors/index.ts +0 -38
  210. package/src-ts/dist/extend.ts +0 -167
  211. package/src-ts/dist/fbns/fbns.client.events.ts +0 -3
  212. package/src-ts/dist/fbns/fbns.client.ts +0 -252
  213. package/src-ts/dist/fbns/fbns.types.ts +0 -3
  214. package/src-ts/dist/fbns/fbns.utilities.ts +0 -79
  215. package/src-ts/dist/fbns/index.ts +0 -21
  216. package/src-ts/dist/index.ts +0 -139
  217. package/src-ts/dist/mqtt-shim.ts +0 -15
  218. package/src-ts/dist/mqttot/index.ts +0 -21
  219. package/src-ts/dist/mqttot/mqttot.client.ts +0 -318
  220. package/src-ts/dist/mqttot/mqttot.connect.request.packet.ts +0 -9
  221. package/src-ts/dist/mqttot/mqttot.connect.response.packet.ts +0 -24
  222. package/src-ts/dist/mqttot/mqttot.connection.ts +0 -77
  223. package/src-ts/dist/realtime/commands/commands.ts +0 -71
  224. package/src-ts/dist/realtime/commands/direct.commands.ts +0 -417
  225. package/src-ts/dist/realtime/commands/enhanced.direct.commands.ts +0 -1731
  226. package/src-ts/dist/realtime/commands/index.ts +0 -20
  227. package/src-ts/dist/realtime/delta-sync.manager.ts +0 -293
  228. package/src-ts/dist/realtime/features/error-handler.ts +0 -185
  229. package/src-ts/dist/realtime/features/gap-handler.ts +0 -61
  230. package/src-ts/dist/realtime/features/persistent-logger.ts +0 -186
  231. package/src-ts/dist/realtime/index.ts +0 -30
  232. package/src-ts/dist/realtime/messages/app-presence.event.ts +0 -3
  233. package/src-ts/dist/realtime/messages/index.ts +0 -20
  234. package/src-ts/dist/realtime/messages/message-sync.message.ts +0 -43
  235. package/src-ts/dist/realtime/messages/realtime-sub.direct.data.ts +0 -3
  236. package/src-ts/dist/realtime/messages/thread-update.message.ts +0 -3
  237. package/src-ts/dist/realtime/mixins/index.ts +0 -20
  238. package/src-ts/dist/realtime/mixins/message-sync.mixin.ts +0 -596
  239. package/src-ts/dist/realtime/mixins/mixin.ts +0 -41
  240. package/src-ts/dist/realtime/mixins/presence-typing.mixin.ts +0 -33
  241. package/src-ts/dist/realtime/mixins/realtime-sub.mixin.ts +0 -181
  242. package/src-ts/dist/realtime/parsers/graphql-parser.ts +0 -43
  243. package/src-ts/dist/realtime/parsers/index.ts +0 -23
  244. package/src-ts/dist/realtime/parsers/iris-parser.ts +0 -43
  245. package/src-ts/dist/realtime/parsers/iris.parser.ts +0 -10
  246. package/src-ts/dist/realtime/parsers/json-parser.ts +0 -43
  247. package/src-ts/dist/realtime/parsers/json.parser.ts +0 -10
  248. package/src-ts/dist/realtime/parsers/parser.ts +0 -3
  249. package/src-ts/dist/realtime/parsers/region-hint-parser.ts +0 -43
  250. package/src-ts/dist/realtime/parsers/region-hint.parser.ts +0 -15
  251. package/src-ts/dist/realtime/parsers/skywalker-parser.ts +0 -43
  252. package/src-ts/dist/realtime/parsers/skywalker.parser.ts +0 -15
  253. package/src-ts/dist/realtime/parsers-advanced.ts +0 -158
  254. package/src-ts/dist/realtime/proto-parser.ts +0 -195
  255. package/src-ts/dist/realtime/protocols/iris.handshake.ts +0 -74
  256. package/src-ts/dist/realtime/protocols/proto-definitions.ts +0 -80
  257. package/src-ts/dist/realtime/realtime.client.events.ts +0 -3
  258. package/src-ts/dist/realtime/realtime.client.ts +0 -1996
  259. package/src-ts/dist/realtime/realtime.service.ts +0 -462
  260. package/src-ts/dist/realtime/reconnect.manager.ts +0 -88
  261. package/src-ts/dist/realtime/session.manager.ts +0 -121
  262. package/src-ts/dist/realtime/subscriptions/graphql.subscription.ts +0 -99
  263. package/src-ts/dist/realtime/subscriptions/index.ts +0 -19
  264. package/src-ts/dist/realtime/subscriptions/skywalker.subscription.ts +0 -13
  265. package/src-ts/dist/realtime/topic-map.ts +0 -71
  266. package/src-ts/dist/realtime/topic.ts +0 -80
  267. package/src-ts/dist/repositories/account.repository.ts +0 -1384
  268. package/src-ts/dist/repositories/bloks.repository.ts +0 -70
  269. package/src-ts/dist/repositories/captcha.repository.ts +0 -44
  270. package/src-ts/dist/repositories/challenge.repository.ts +0 -120
  271. package/src-ts/dist/repositories/clip.repository.ts +0 -165
  272. package/src-ts/dist/repositories/close-friends.repository.ts +0 -46
  273. package/src-ts/dist/repositories/collection.repository.ts +0 -68
  274. package/src-ts/dist/repositories/direct-thread.repository.ts +0 -446
  275. package/src-ts/dist/repositories/direct.repository.ts +0 -266
  276. package/src-ts/dist/repositories/explore.repository.ts +0 -70
  277. package/src-ts/dist/repositories/fbsearch.repository.ts +0 -140
  278. package/src-ts/dist/repositories/feed.repository.ts +0 -245
  279. package/src-ts/dist/repositories/friendship.repository.ts +0 -296
  280. package/src-ts/dist/repositories/fundraiser.repository.ts +0 -49
  281. package/src-ts/dist/repositories/hashtag.repository.ts +0 -99
  282. package/src-ts/dist/repositories/highlights.repository.ts +0 -121
  283. package/src-ts/dist/repositories/insights.repository.ts +0 -82
  284. package/src-ts/dist/repositories/location.repository.ts +0 -84
  285. package/src-ts/dist/repositories/media.repository.ts +0 -395
  286. package/src-ts/dist/repositories/multiple-accounts.repository.ts +0 -41
  287. package/src-ts/dist/repositories/news.repository.ts +0 -35
  288. package/src-ts/dist/repositories/note.repository.ts +0 -57
  289. package/src-ts/dist/repositories/notification.repository.ts +0 -79
  290. package/src-ts/dist/repositories/share.repository.ts +0 -35
  291. package/src-ts/dist/repositories/signup.repository.ts +0 -218
  292. package/src-ts/dist/repositories/story.repository.ts +0 -290
  293. package/src-ts/dist/repositories/timeline.repository.ts +0 -60
  294. package/src-ts/dist/repositories/totp.repository.ts +0 -139
  295. package/src-ts/dist/repositories/track.repository.ts +0 -53
  296. package/src-ts/dist/repositories/upload.repository.ts +0 -204
  297. package/src-ts/dist/repositories/user.repository.ts +0 -360
  298. package/src-ts/dist/sendmedia/index.ts +0 -27
  299. package/src-ts/dist/sendmedia/sendFile.ts +0 -72
  300. package/src-ts/dist/sendmedia/sendPhoto.ts +0 -142
  301. package/src-ts/dist/sendmedia/sendRavenPhoto.ts +0 -153
  302. package/src-ts/dist/sendmedia/sendRavenVideo.ts +0 -158
  303. package/src-ts/dist/sendmedia/uploadPhoto.ts +0 -107
  304. package/src-ts/dist/sendmedia/uploadfFile.ts +0 -130
  305. package/src-ts/dist/services/live.service.ts +0 -139
  306. package/src-ts/dist/services/search.service.ts +0 -115
  307. package/src-ts/dist/shared/shared.ts +0 -86
  308. package/src-ts/dist/thrift/index.ts +0 -20
  309. package/src-ts/dist/thrift/thrift.reading.ts +0 -368
  310. package/src-ts/dist/thrift/thrift.ts +0 -111
  311. package/src-ts/dist/thrift/thrift.writing.ts +0 -396
  312. package/src-ts/dist/types/index.ts +0 -285
  313. package/src-ts/dist/useMultiFileAuthState.ts +0 -1800
  314. package/src-ts/dist/utils/helper-1.ts +0 -1
  315. package/src-ts/dist/utils/helper-10.ts +0 -1
  316. package/src-ts/dist/utils/helper-11.ts +0 -1
  317. package/src-ts/dist/utils/helper-12.ts +0 -1
  318. package/src-ts/dist/utils/helper-13.ts +0 -1
  319. package/src-ts/dist/utils/helper-14.ts +0 -1
  320. package/src-ts/dist/utils/helper-15.ts +0 -1
  321. package/src-ts/dist/utils/helper-16.ts +0 -1
  322. package/src-ts/dist/utils/helper-17.ts +0 -1
  323. package/src-ts/dist/utils/helper-18.ts +0 -1
  324. package/src-ts/dist/utils/helper-19.ts +0 -1
  325. package/src-ts/dist/utils/helper-2.ts +0 -1
  326. package/src-ts/dist/utils/helper-20.ts +0 -1
  327. package/src-ts/dist/utils/helper-21.ts +0 -1
  328. package/src-ts/dist/utils/helper-22.ts +0 -1
  329. package/src-ts/dist/utils/helper-23.ts +0 -1
  330. package/src-ts/dist/utils/helper-24.ts +0 -1
  331. package/src-ts/dist/utils/helper-25.ts +0 -1
  332. package/src-ts/dist/utils/helper-26.ts +0 -1
  333. package/src-ts/dist/utils/helper-27.ts +0 -1
  334. package/src-ts/dist/utils/helper-28.ts +0 -1
  335. package/src-ts/dist/utils/helper-29.ts +0 -1
  336. package/src-ts/dist/utils/helper-3.ts +0 -1
  337. package/src-ts/dist/utils/helper-30.ts +0 -1
  338. package/src-ts/dist/utils/helper-4.ts +0 -1
  339. package/src-ts/dist/utils/helper-5.ts +0 -1
  340. package/src-ts/dist/utils/helper-6.ts +0 -1
  341. package/src-ts/dist/utils/helper-7.ts +0 -1
  342. package/src-ts/dist/utils/helper-8.ts +0 -1
  343. package/src-ts/dist/utils/helper-9.ts +0 -1
  344. package/src-ts/dist/utils/index.ts +0 -280
  345. package/src-ts/dist/utils/insta-mqtt-helper.ts +0 -128
  346. package/src-ts/examples/listen-to-messages.ts +0 -86
  347. /package/{dist-ts → dist}/dist/constants/constants.js +0 -0
  348. /package/{dist-ts → dist}/dist/constants/index.js +0 -0
  349. /package/{dist-ts → dist}/dist/core/client.js +0 -0
  350. /package/{dist-ts → dist}/dist/core/nav-chain.js +0 -0
  351. /package/{dist-ts → dist}/dist/core/repository.js +0 -0
  352. /package/{dist-ts → dist}/dist/core/request.js +0 -0
  353. /package/{dist-ts → dist}/dist/core/state.js +0 -0
  354. /package/{dist-ts → dist}/dist/core/utils.js +0 -0
  355. /package/{dist-ts → dist}/dist/errors/index.js +0 -0
  356. /package/{dist-ts → dist}/dist/extend.js +0 -0
  357. /package/{dist-ts → dist}/dist/fbns/fbns.client.events.js +0 -0
  358. /package/{dist-ts → dist}/dist/fbns/fbns.types.js +0 -0
  359. /package/{dist-ts → dist}/dist/fbns/fbns.utilities.js +0 -0
  360. /package/{dist-ts → dist}/dist/fbns/index.js +0 -0
  361. /package/{dist-ts → dist}/dist/index.js +0 -0
  362. /package/{dist-ts → dist}/dist/mqtt-shim.js +0 -0
  363. /package/{dist-ts → dist}/dist/mqttot/index.js +0 -0
  364. /package/{dist-ts → dist}/dist/mqttot/mqttot.connect.request.packet.js +0 -0
  365. /package/{dist-ts → dist}/dist/mqttot/mqttot.connect.response.packet.js +0 -0
  366. /package/{dist-ts → dist}/dist/mqttot/mqttot.connection.js +0 -0
  367. /package/{dist-ts → dist}/dist/realtime/commands/commands.js +0 -0
  368. /package/{dist-ts → dist}/dist/realtime/commands/direct.commands.js +0 -0
  369. /package/{dist-ts → dist}/dist/realtime/commands/index.js +0 -0
  370. /package/{dist-ts → dist}/dist/realtime/features/gap-handler.js +0 -0
  371. /package/{dist-ts → dist}/dist/realtime/index.js +0 -0
  372. /package/{dist-ts → dist}/dist/realtime/messages/app-presence.event.js +0 -0
  373. /package/{dist-ts → dist}/dist/realtime/messages/index.js +0 -0
  374. /package/{dist-ts → dist}/dist/realtime/messages/message-sync.message.js +0 -0
  375. /package/{dist-ts → dist}/dist/realtime/messages/realtime-sub.direct.data.js +0 -0
  376. /package/{dist-ts → dist}/dist/realtime/messages/thread-update.message.js +0 -0
  377. /package/{dist-ts → dist}/dist/realtime/mixins/index.js +0 -0
  378. /package/{dist-ts → dist}/dist/realtime/mixins/mixin.js +0 -0
  379. /package/{dist-ts → dist}/dist/realtime/mixins/presence-typing.mixin.js +0 -0
  380. /package/{dist-ts → dist}/dist/realtime/parsers/graphql-parser.js +0 -0
  381. /package/{dist-ts → dist}/dist/realtime/parsers/index.js +0 -0
  382. /package/{dist-ts → dist}/dist/realtime/parsers/iris-parser.js +0 -0
  383. /package/{dist-ts → dist}/dist/realtime/parsers/iris.parser.js +0 -0
  384. /package/{dist-ts → dist}/dist/realtime/parsers/json-parser.js +0 -0
  385. /package/{dist-ts → dist}/dist/realtime/parsers/json.parser.js +0 -0
  386. /package/{dist-ts → dist}/dist/realtime/parsers/parser.js +0 -0
  387. /package/{dist-ts → dist}/dist/realtime/parsers/region-hint-parser.js +0 -0
  388. /package/{dist-ts → dist}/dist/realtime/parsers/region-hint.parser.js +0 -0
  389. /package/{dist-ts → dist}/dist/realtime/parsers/skywalker-parser.js +0 -0
  390. /package/{dist-ts → dist}/dist/realtime/parsers/skywalker.parser.js +0 -0
  391. /package/{dist-ts → dist}/dist/realtime/protocols/iris.handshake.js +0 -0
  392. /package/{dist-ts → dist}/dist/realtime/protocols/proto-definitions.js +0 -0
  393. /package/{dist-ts → dist}/dist/realtime/realtime.client.events.js +0 -0
  394. /package/{dist-ts → dist}/dist/realtime/realtime.service.js +0 -0
  395. /package/{dist-ts → dist}/dist/realtime/reconnect.manager.js +0 -0
  396. /package/{dist-ts → dist}/dist/realtime/session.manager.js +0 -0
  397. /package/{dist-ts → dist}/dist/realtime/subscriptions/graphql.subscription.js +0 -0
  398. /package/{dist-ts → dist}/dist/realtime/subscriptions/index.js +0 -0
  399. /package/{dist-ts → dist}/dist/realtime/subscriptions/skywalker.subscription.js +0 -0
  400. /package/{dist-ts → dist}/dist/realtime/topic-map.js +0 -0
  401. /package/{dist-ts → dist}/dist/realtime/topic.js +0 -0
  402. /package/{dist-ts → dist}/dist/repositories/bloks.repository.js +0 -0
  403. /package/{dist-ts → dist}/dist/repositories/captcha.repository.js +0 -0
  404. /package/{dist-ts → dist}/dist/repositories/clip.repository.js +0 -0
  405. /package/{dist-ts → dist}/dist/repositories/close-friends.repository.js +0 -0
  406. /package/{dist-ts → dist}/dist/repositories/collection.repository.js +0 -0
  407. /package/{dist-ts → dist}/dist/repositories/explore.repository.js +0 -0
  408. /package/{dist-ts → dist}/dist/repositories/fbsearch.repository.js +0 -0
  409. /package/{dist-ts → dist}/dist/repositories/feed.repository.js +0 -0
  410. /package/{dist-ts → dist}/dist/repositories/friendship.repository.js +0 -0
  411. /package/{dist-ts → dist}/dist/repositories/fundraiser.repository.js +0 -0
  412. /package/{dist-ts → dist}/dist/repositories/hashtag.repository.js +0 -0
  413. /package/{dist-ts → dist}/dist/repositories/highlights.repository.js +0 -0
  414. /package/{dist-ts → dist}/dist/repositories/insights.repository.js +0 -0
  415. /package/{dist-ts → dist}/dist/repositories/location.repository.js +0 -0
  416. /package/{dist-ts → dist}/dist/repositories/multiple-accounts.repository.js +0 -0
  417. /package/{dist-ts → dist}/dist/repositories/news.repository.js +0 -0
  418. /package/{dist-ts → dist}/dist/repositories/note.repository.js +0 -0
  419. /package/{dist-ts → dist}/dist/repositories/share.repository.js +0 -0
  420. /package/{dist-ts → dist}/dist/repositories/signup.repository.js +0 -0
  421. /package/{dist-ts → dist}/dist/repositories/timeline.repository.js +0 -0
  422. /package/{dist-ts → dist}/dist/repositories/totp.repository.js +0 -0
  423. /package/{dist-ts → dist}/dist/repositories/user.repository.js +0 -0
  424. /package/{dist-ts → dist}/dist/sendmedia/index.js +0 -0
  425. /package/{dist-ts → dist}/dist/sendmedia/sendFile.js +0 -0
  426. /package/{dist-ts → dist}/dist/sendmedia/sendPhoto.js +0 -0
  427. /package/{dist-ts → dist}/dist/sendmedia/uploadPhoto.js +0 -0
  428. /package/{dist-ts → dist}/dist/services/live.service.js +0 -0
  429. /package/{dist-ts → dist}/dist/services/search.service.js +0 -0
  430. /package/{dist-ts → dist}/dist/shared/shared.js +0 -0
  431. /package/{dist-ts → dist}/dist/thrift/index.js +0 -0
  432. /package/{dist-ts → dist}/dist/thrift/thrift.js +0 -0
  433. /package/{dist-ts → dist}/dist/types/index.js +0 -0
  434. /package/{dist-ts → dist}/dist/utils/helper-1.js +0 -0
  435. /package/{dist-ts → dist}/dist/utils/helper-10.js +0 -0
  436. /package/{dist-ts → dist}/dist/utils/helper-11.js +0 -0
  437. /package/{dist-ts → dist}/dist/utils/helper-12.js +0 -0
  438. /package/{dist-ts → dist}/dist/utils/helper-13.js +0 -0
  439. /package/{dist-ts → dist}/dist/utils/helper-14.js +0 -0
  440. /package/{dist-ts → dist}/dist/utils/helper-15.js +0 -0
  441. /package/{dist-ts → dist}/dist/utils/helper-16.js +0 -0
  442. /package/{dist-ts → dist}/dist/utils/helper-17.js +0 -0
  443. /package/{dist-ts → dist}/dist/utils/helper-18.js +0 -0
  444. /package/{dist-ts → dist}/dist/utils/helper-19.js +0 -0
  445. /package/{dist-ts → dist}/dist/utils/helper-2.js +0 -0
  446. /package/{dist-ts → dist}/dist/utils/helper-20.js +0 -0
  447. /package/{dist-ts → dist}/dist/utils/helper-21.js +0 -0
  448. /package/{dist-ts → dist}/dist/utils/helper-22.js +0 -0
  449. /package/{dist-ts → dist}/dist/utils/helper-23.js +0 -0
  450. /package/{dist-ts → dist}/dist/utils/helper-24.js +0 -0
  451. /package/{dist-ts → dist}/dist/utils/helper-25.js +0 -0
  452. /package/{dist-ts → dist}/dist/utils/helper-26.js +0 -0
  453. /package/{dist-ts → dist}/dist/utils/helper-27.js +0 -0
  454. /package/{dist-ts → dist}/dist/utils/helper-28.js +0 -0
  455. /package/{dist-ts → dist}/dist/utils/helper-29.js +0 -0
  456. /package/{dist-ts → dist}/dist/utils/helper-3.js +0 -0
  457. /package/{dist-ts → dist}/dist/utils/helper-30.js +0 -0
  458. /package/{dist-ts → dist}/dist/utils/helper-4.js +0 -0
  459. /package/{dist-ts → dist}/dist/utils/helper-5.js +0 -0
  460. /package/{dist-ts → dist}/dist/utils/helper-6.js +0 -0
  461. /package/{dist-ts → dist}/dist/utils/helper-7.js +0 -0
  462. /package/{dist-ts → dist}/dist/utils/helper-8.js +0 -0
  463. /package/{dist-ts → dist}/dist/utils/helper-9.js +0 -0
  464. /package/{dist-ts → dist}/dist/utils/insta-mqtt-helper.js +0 -0
@@ -1,1384 +0,0 @@
1
- const Repository = require('../core/repository');
2
- const crypto = require('crypto');
3
-
4
- class AccountRepository extends Repository {
5
- constructor(client) {
6
- super(client);
7
- this.maxRetries = 3;
8
- }
9
-
10
- async requestWithRetry(requestFn, retries = 0) {
11
- try {
12
- const result = await requestFn();
13
- return result;
14
- } catch (error) {
15
- const shouldRetry =
16
- (error.data?.error_type === 'server_error' ||
17
- error.data?.error_type === 'rate_limited') &&
18
- retries < this.maxRetries;
19
- if (shouldRetry) {
20
- const delay = 1000 * (retries + 1);
21
- await new Promise(resolve => setTimeout(resolve, delay));
22
- return this.requestWithRetry(requestFn, retries + 1);
23
- }
24
- throw error;
25
- }
26
- }
27
-
28
- /**
29
- * Helper: try to extract an IGT bearer token from various sources:
30
- * - response.headers (IG-Set-Authorization or ig-set-authorization)
31
- * - response.body top-level fields
32
- * - body.layout (stringified layout)
33
- * - any embedded login_response.headers JSON inside layout or body
34
- *
35
- * When found, sets this.client.state.authorization and calls updateAuthorization().
36
- */
37
- _extractAndSaveAuthorization(response) {
38
- if (!response) return null;
39
-
40
- // Normalize headers (case-insensitive)
41
- const headers = {};
42
- if (response.headers && typeof response.headers === 'object') {
43
- for (const k of Object.keys(response.headers)) {
44
- headers[k.toLowerCase()] = response.headers[k];
45
- }
46
- }
47
-
48
- // Simpler: look for any header that contains ig-set-authorization
49
- for (const key of Object.keys(headers)) {
50
- const val = headers[key];
51
- if (!val) continue;
52
- if (key.includes('ig-set-authorization')) {
53
- const token = this._normalizeTokenString(val);
54
- if (token) {
55
- this.client.state.authorization = token;
56
- try { this.client.state.updateAuthorization(); } catch (e) {}
57
- return token;
58
- }
59
- }
60
- // Some servers include the header value inside a JSON-like string in other headers
61
- if (typeof val === 'string' && val.includes('Bearer IGT:2:')) {
62
- const token = this._findBearerInString(val);
63
- if (token) {
64
- this.client.state.authorization = token;
65
- try { this.client.state.updateAuthorization(); } catch (e) {}
66
- return token;
67
- }
68
- }
69
- }
70
-
71
- // Extract IG-U headers (user id, region, claim) when present
72
- const dsUserIdHeader =
73
- headers['ig-set-ig-u-ds-user-id'] ||
74
- headers['ig-u-ds-user-id'] ||
75
- headers['x-ig-set-ig-u-ds-user-id'];
76
- if (dsUserIdHeader) {
77
- const m = String(dsUserIdHeader).match(/(\d{3,})/);
78
- if (m) {
79
- const uid = m[1];
80
- this.client.state.cookieUserId = uid;
81
- this.client.state._userId = uid;
82
- }
83
- }
84
-
85
- const rurHeader =
86
- headers['ig-set-ig-u-rur'] ||
87
- headers['ig-u-rur'] ||
88
- headers['x-ig-set-ig-u-rur'];
89
- if (rurHeader) {
90
- const rur = String(rurHeader).trim().replace(/^"|"$/g, '');
91
- if (rur) {
92
- this.client.state.igURur = rur;
93
- }
94
- }
95
-
96
- const wwwClaimHeader =
97
- headers['x-ig-set-www-claim'] ||
98
- headers['ig-set-www-claim'] ||
99
- headers['ig-u-www-claim'];
100
- if (wwwClaimHeader) {
101
- const claim = String(wwwClaimHeader).trim().replace(/^"|"$/g, '');
102
- if (claim) {
103
- this.client.state.igWWWClaim = claim;
104
- }
105
- }
106
-
107
- const midHeader =
108
- headers['ig-set-x-mid'] ||
109
- headers['x-mid'] ||
110
- headers['ig-set-mid'];
111
- if (midHeader) {
112
- const mid = String(midHeader).trim().replace(/^"|"$/g, '');
113
- if (mid) {
114
- this.client.state.mid = mid;
115
- }
116
- }
117
-
118
- // 2) Check response.body for common fields
119
- const body = response.body;
120
- if (body) {
121
- // If body has headers string (some responses embed headers JSON as a string)
122
- if (body.headers && typeof body.headers === 'string') {
123
- const token = this._findBearerInString(body.headers);
124
- if (token) {
125
- this.client.state.authorization = token;
126
- try { this.client.state.updateAuthorization(); } catch (e) {}
127
- return token;
128
- }
129
- }
130
-
131
- // If body contains a layout object or string, stringify and search it
132
- try {
133
- let layoutStr = null;
134
- if (body.layout) {
135
- layoutStr = typeof body.layout === 'string' ? body.layout : JSON.stringify(body.layout);
136
- } else if (body?.layout?.bloks_payload) {
137
- layoutStr = JSON.stringify(body.layout.bloks_payload);
138
- } else if (body?.bloks_payload) {
139
- layoutStr = JSON.stringify(body.bloks_payload);
140
- }
141
-
142
- if (!layoutStr && typeof body === 'string') {
143
- layoutStr = body;
144
- }
145
-
146
- if (layoutStr) {
147
- const token = this._findBearerInString(layoutStr);
148
- if (token) {
149
- this.client.state.authorization = token;
150
- try { this.client.state.updateAuthorization(); } catch (e) {}
151
- return token;
152
- }
153
-
154
- // Some responses embed a login_response JSON string inside layout; try to extract it
155
- const loginResponseMatch = layoutStr.match(/"login_response"\s*:\s*"(\\?{.*?\\?})"/s);
156
- if (loginResponseMatch) {
157
- // Unescape JSON string
158
- let jsonStr = loginResponseMatch[1];
159
- try {
160
- jsonStr = jsonStr.replace(/\\"/g, '"').replace(/\\n/g, '');
161
- const parsed = JSON.parse(jsonStr);
162
- if (parsed && parsed.headers) {
163
- const token = this._findBearerInString(parsed.headers);
164
- if (token) {
165
- this.client.state.authorization = token;
166
- try { this.client.state.updateAuthorization(); } catch (e) {}
167
- return token;
168
- }
169
- }
170
- } catch (e) {
171
- // ignore parse errors
172
- }
173
- }
174
-
175
- // Also try to find IG-Set-Password-Encryption headers (not token but useful)
176
- const encKeyIdMatch = layoutStr.match(/IG-Set-Password-Encryption-Key-Id[\\"\s:]+(\d+)/i) ||
177
- layoutStr.match(/password.encryption.key.id[\\"\s:]+(\d+)/i);
178
- if (encKeyIdMatch) {
179
- this.client.state.passwordEncryptionKeyId = parseInt(encKeyIdMatch[1]);
180
- }
181
- const encPubKeyMatch = layoutStr.match(/IG-Set-Password-Encryption-Pub-Key[\\"\s:]+([A-Za-z0-9+\/=]+)/i) ||
182
- layoutStr.match(/password.encryption.pub.key[\\"\s:]+([A-Za-z0-9+\/=]+)/i);
183
- if (encPubKeyMatch) {
184
- this.client.state.passwordEncryptionPubKey = encPubKeyMatch[1];
185
- }
186
-
187
- // Extract user/account identifiers from layout string
188
- const dsIdMatch =
189
- layoutStr.match(/ig-set-ig-u-ds-user-id[\\"\s:]+(\d+)/i) ||
190
- layoutStr.match(/ig-u-ds-user-id[\\"\s:]+(\d+)/i) ||
191
- layoutStr.match(/"strong_id__"\s*:\s*"(\d+)"/i) ||
192
- layoutStr.match(/"pk_id"\s*:\s*"(\d+)"/i) ||
193
- layoutStr.match(/"pk"\s*:\s*(\d+)/i);
194
- if (dsIdMatch) {
195
- const uid = String(dsIdMatch[1]);
196
- this.client.state.cookieUserId = uid;
197
- this.client.state._userId = uid;
198
- }
199
-
200
- const rurMatch =
201
- layoutStr.match(/ig-set-ig-u-rur[\\"\s:]+"([^"\\]+)/i) ||
202
- layoutStr.match(/ig-u-rur[\\"\s:]+"([^"\\]+)/i);
203
- if (rurMatch) {
204
- this.client.state.igURur = rurMatch[1];
205
- }
206
-
207
- const wwwClaimMatch = layoutStr.match(/x-ig-set-www-claim[\\"\s:]+"([^"\\]+)/i);
208
- if (wwwClaimMatch) {
209
- this.client.state.igWWWClaim = wwwClaimMatch[1];
210
- }
211
-
212
- const midMatch = layoutStr.match(/"mid"\s*:\s*"([^"\\]+)"/i);
213
- if (midMatch) {
214
- this.client.state.mid = midMatch[1];
215
- }
216
- }
217
- } catch (e) {
218
- // ignore
219
- }
220
-
221
- // 3) If body.logged_in_user exists and we have authorization already, return it
222
- if (body.logged_in_user && this.client.state.authorization) {
223
- return this.client.state.authorization;
224
- }
225
- }
226
-
227
- return null;
228
- }
229
-
230
- // Normalize token string: accept either raw token or "Bearer IGT:2:..." and return trimmed token string
231
- _normalizeTokenString(val) {
232
- if (!val || typeof val !== 'string') return null;
233
- // If header already contains "Bearer IGT:2:..."
234
- const bearer = this._findBearerInString(val);
235
- if (bearer) return bearer;
236
- // If header contains JSON with IG-Set-Authorization field
237
- try {
238
- const maybeJson = JSON.parse(val);
239
- if (maybeJson['IG-Set-Authorization']) {
240
- return this._findBearerInString(maybeJson['IG-Set-Authorization']);
241
- }
242
- } catch (e) {
243
- // not JSON
244
- }
245
- // fallback: return trimmed value
246
- return val.trim();
247
- }
248
-
249
- // Find bearer token in arbitrary string using multiple patterns
250
- _findBearerInString(str) {
251
- if (!str || typeof str !== 'string') return null;
252
- // Patterns to match the Bearer token in many possible encodings/escapes
253
- const bearerPatterns = [
254
- /Bearer IGT:2:[A-Za-z0-9+\/=]+/,
255
- /Bearer\s+IGT:2:[A-Za-z0-9+\/=]+/,
256
- /\?"Bearer IGT:2:([A-Za-z0-9+\/=]+)\?"/,
257
- /ig-set-authorization[\\"\s:]*Bearer IGT:2:([A-Za-z0-9+\/=]+)/i,
258
- /"IG-Set-Authorization"\s*:\s*"(Bearer IGT:2:[A-Za-z0-9+\/=]+)"/i,
259
- /IG-Set-Authorization[\s:]+(Bearer IGT:2:[A-Za-z0-9+\/=]+)/i,
260
- /Bearer IGT:2:([A-Za-z0-9+\/=]+)/,
261
- ];
262
-
263
- for (const pattern of bearerPatterns) {
264
- const m = str.match(pattern);
265
- if (m) {
266
- // If capturing group present, prefer it
267
- if (m[1]) {
268
- const token = m[1].includes('Bearer IGT:2:') ? m[1] : `Bearer IGT:2:${m[1]}`;
269
- return token.replace(/\?"/g, '').trim();
270
- }
271
- // Otherwise m[0] contains the full token
272
- return m[0].replace(/\?"/g, '').trim();
273
- }
274
- }
275
-
276
- return null;
277
- }
278
-
279
- // Ensure we have a valid csrftoken cookie (and mid) before sensitive endpoints.
280
- // Instagram typically sets csrftoken via /api/v1/si/fetch_headers/.
281
- async ensureCsrfToken() {
282
- const cookieToken = this.client.state.cookieCsrfToken;
283
- if (cookieToken && cookieToken !== 'missing' && cookieToken !== 'pending') {
284
- try { this.client.state.csrfToken = cookieToken; } catch {}
285
- return cookieToken;
286
- }
287
-
288
- // Warmup endpoint that returns/set cookies (csrftoken, mid, etc.)
289
- try {
290
- await this.client.request.send({
291
- method: 'GET',
292
- url: `/api/v1/si/fetch_headers/?challenge_type=signup&guid=${this.client.state.uuid}`,
293
- });
294
- } catch (e) {
295
- // ignore warmup failures
296
- }
297
-
298
- const token = this.client.state.cookieCsrfToken;
299
- if (token && token !== 'missing' && token !== 'pending') {
300
- try { this.client.state.csrfToken = token; } catch {}
301
- return token;
302
- }
303
- return null;
304
- }
305
-
306
- async login(credentialsOrUsername, passwordArg) {
307
- let username, password;
308
- if (typeof credentialsOrUsername === 'object' && credentialsOrUsername !== null) {
309
- username = credentialsOrUsername.username;
310
- password = credentialsOrUsername.password;
311
- } else {
312
- username = credentialsOrUsername;
313
- password = passwordArg;
314
- }
315
- if (!username || !password) {
316
- throw new Error('Username and password are required');
317
- }
318
-
319
- if (!this.client.state.passwordEncryptionPubKey) {
320
- await this.syncLoginExperiments();
321
- }
322
-
323
- const { encrypted, time } = this.encryptPassword(password);
324
-
325
- // optional CSRF warmup (like app does before login)
326
- await this.ensureCsrfToken();
327
-
328
- return this.requestWithRetry(async () => {
329
- // ====== client_input_params (oglindă după traficul real) ======
330
- const nowSec = Math.floor(Date.now() / 1000);
331
- const aacInitTimestamp = nowSec - Math.floor(Math.random() * 50);
332
- const aacjid = crypto.randomUUID ? crypto.randomUUID() : require('uuid').v4();
333
- const aaccs = crypto.randomBytes(32).toString('base64').replace(/=/g, '');
334
-
335
- const androidDeviceId =
336
- this.client.state.androidDeviceId ||
337
- this.client.state.deviceId ||
338
- `android-${crypto.randomBytes(8).toString('hex')}`;
339
-
340
- const machineId =
341
- this.client.state.mid ||
342
- this.client.state.machineId ||
343
- `aZ${crypto.randomBytes(8).toString('hex')}`;
344
-
345
- const familyDeviceId =
346
- this.client.state.phoneId ||
347
- this.client.state.familyDeviceId ||
348
- crypto.randomUUID
349
- ? crypto.randomUUID()
350
- : require('uuid').v4();
351
-
352
- const qeDeviceId =
353
- this.client.state.deviceId ||
354
- this.client.state.qeDeviceId ||
355
- crypto.randomUUID
356
- ? crypto.randomUUID()
357
- : require('uuid').v4();
358
-
359
- const accountsList = this.client.state.accountsList || [];
360
-
361
- const flashCallPermissionStatus = {
362
- READ_PHONE_STATE: 'GRANTED',
363
- READ_CALL_LOG: 'GRANTED',
364
- ANSWER_PHONE_CALLS: 'GRANTED',
365
- };
366
-
367
- const clientInputParams = {
368
- aac: JSON.stringify({
369
- aac_init_timestamp: aacInitTimestamp,
370
- aacjid,
371
- aaccs,
372
- }),
373
- sim_phones: [],
374
- aymh_accounts: [],
375
- network_bssid: null,
376
- secure_family_device_id: '',
377
- has_granted_read_contacts_permissions: 0,
378
- auth_secure_device_id: '',
379
- has_whatsapp_installed: 1,
380
- password: `#PWD_INSTAGRAM:4:${time}:${encrypted}`,
381
- sso_token_map_json_string: JSON.stringify({
382
- [this.client.state.cookieUserId || '0']: [],
383
- }),
384
- block_store_machine_id: '',
385
- ig_vetted_device_nonces: JSON.stringify({}),
386
- cloud_trust_token: null,
387
- event_flow: 'login_manual',
388
- password_contains_non_ascii: 'false',
389
- client_known_key_hash: '',
390
- encrypted_msisdn: '',
391
- has_granted_read_phone_permissions: 0,
392
- app_manager_id: '',
393
- should_show_nested_nta_from_aymh: 0,
394
- device_id: androidDeviceId,
395
- zero_balance_state: '',
396
- login_attempt_count: 1,
397
- machine_id: machineId,
398
- flash_call_permission_status: flashCallPermissionStatus,
399
- accounts_list: accountsList,
400
- gms_incoming_call_retriever_eligibility: 'client_not_supported',
401
- family_device_id: familyDeviceId,
402
- fb_ig_device_id: [],
403
- device_emails: [],
404
- try_num: 1,
405
- lois_settings: { lois_token: '' },
406
- event_step: 'home_page',
407
- headers_infra_flow_id: '',
408
- openid_tokens: {},
409
- contact_point: username,
410
- };
411
-
412
- // ====== server_params (oglindă după traficul real) ======
413
- const waterfallId = crypto.randomUUID ? crypto.randomUUID() : require('uuid').v4();
414
- const latencyMarkerId = 36707139;
415
- const latencyInstanceId = Number(`${Date.now()}${Math.floor(Math.random() * 1000)}`);
416
-
417
- const serverParams = {
418
- should_trigger_override_login_2fa_action: 0,
419
- is_vanilla_password_page_empty_password: 0,
420
- is_from_logged_out: 0,
421
- should_trigger_override_login_success_action: 0,
422
- login_credential_type: 'none',
423
- server_login_source: 'login',
424
- waterfall_id: waterfallId,
425
- two_step_login_type: 'one_step_login',
426
- login_source: 'Login',
427
- is_platform_login: 0,
428
- INTERNAL__latency_qpl_marker_id: latencyMarkerId,
429
- is_from_aymh: 0,
430
- offline_experiment_group: 'caa_iteration_v3_perf_ig_4',
431
- is_from_landing_page: 0,
432
- left_nav_button_action: 'NONE',
433
- password_text_input_id: 'z0jejq:194',
434
- is_from_empty_password: 0,
435
- is_from_msplit_fallback: 0,
436
- ar_event_source: 'login_home_page',
437
- qe_device_id: qeDeviceId,
438
- username_text_input_id: 'z0jejq:193',
439
- layered_homepage_experiment_group: null,
440
- device_id: androidDeviceId,
441
- login_surface: 'switcher',
442
- INTERNAL__latency_qpl_instance_id: latencyInstanceId,
443
- reg_flow_source: 'login_home_native_integration_point',
444
- is_caa_perf_enabled: 1,
445
- credential_type: 'password',
446
- is_from_password_entry_page: 0,
447
- caller: 'gslr',
448
- family_device_id: familyDeviceId,
449
- is_from_assistive_id: 0,
450
- access_flow_version: 'pre_mt_behavior',
451
- is_from_logged_in_switcher: 1,
452
- };
453
-
454
- const paramsJson = JSON.stringify({
455
- client_input_params: clientInputParams,
456
- server_params: serverParams,
457
- });
458
-
459
- const attestParams = AccountRepository.generateAttestParams(this.client.state);
460
-
461
- const bkClientContext = JSON.stringify({
462
- bloks_version: this.client.state.bloksVersionId,
463
- styles_id: 'instagram',
464
- });
465
-
466
- // ====== HEADERS – modelate după request_i.instagram.com_mlwzj8x1.txt ======
467
- const lang = (this.client.state.language || 'ro_RO');
468
- const acceptLanguage = `${lang.replace('_', '-')}, en-US`;
469
-
470
- const userAgent =
471
- this.client.state.userAgent ||
472
- 'Instagram 371.0.0.0.23 Android (30/11; 320dpi; 720x1449; Xiaomi/Redmi; M2006C3MNG; angelican; mt6765; ro_RO; 703217507)';
473
-
474
- const bloksHeaders = {
475
- 'accept-language': acceptLanguage,
476
- 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
477
- 'ig-intended-user-id': '0',
478
- 'priority': 'u=3',
479
-
480
- 'x-bloks-is-layout-rtl': 'false',
481
- 'x-bloks-prism-ax-base-colors-enabled': 'false',
482
- 'x-bloks-prism-button-version': 'CONTROL',
483
- 'x-bloks-prism-colors-enabled': 'true',
484
- 'x-bloks-prism-font-enabled': 'false',
485
- 'x-bloks-prism-indigo-link-version': '0',
486
- 'x-bloks-version-id': this.client.state.bloksVersionId,
487
-
488
- 'x-fb-client-ip': 'True',
489
- 'x-fb-connection-type': 'WIFI',
490
- 'x-fb-friendly-name': 'IgApi: bloks/async_action/com.bloks.www.bloks.caa.login.async.send_login_request/',
491
- 'x-fb-network-properties': 'VPN;Validated;LocalAddrs=/10.0.0.2,;',
492
- 'x-fb-request-analytics-tags': JSON.stringify({
493
- network_tags: {
494
- product: String(this.client.state.fbAnalyticsApplicationId || '567067343352427'),
495
- purpose: 'fetch',
496
- surface: 'undefined',
497
- request_category: 'api',
498
- retry_attempt: '0',
499
- },
500
- }),
501
- 'x-fb-server-cluster': 'True',
502
-
503
- 'x-ig-android-id': androidDeviceId,
504
- 'x-ig-app-id': String(this.client.state.fbAnalyticsApplicationId || '567067343352427'),
505
- 'x-ig-app-locale': lang,
506
- 'x-ig-attest-params': JSON.stringify(attestParams),
507
- 'x-ig-bandwidth-speed-kbps': (Math.random() * 1500 + 800).toFixed(3),
508
- 'x-ig-bandwidth-totalbytes-b': '0',
509
- 'x-ig-bandwidth-totaltime-ms': '0',
510
- 'x-ig-client-endpoint': 'com.bloks.www.caa.login.aymh_single_profile_screen_entry',
511
- 'x-ig-capabilities': '3brTv10=',
512
- 'x-ig-connection-type': 'WIFI',
513
- 'x-ig-device-id': qeDeviceId,
514
- 'x-ig-device-locale': lang,
515
- 'x-ig-family-device-id': familyDeviceId,
516
- 'x-ig-mapped-locale': lang,
517
- 'x-ig-nav-chain':
518
- 'LockoutFragment:dogfooding_lockout:1:cold_start:...,' +
519
- 'com.bloks.www.caa.login.aymh_single_profile_screen_entry:com.bloks.www.caa.login.aymh_single_profile_screen_entry:14:button:0:::0',
520
- 'x-ig-timezone-offset': String(
521
- typeof this.client.state.timezoneOffset === 'number'
522
- ? this.client.state.timezoneOffset
523
- : 7200
524
- ),
525
- 'x-ig-www-claim': this.client.state.igWWWClaim || '0',
526
-
527
- 'x-mid': machineId,
528
- 'x-pigeon-rawclienttime': `${nowSec}.${Math.floor(Math.random() * 1000)
529
- .toString()
530
- .padStart(3, '0')}`,
531
- 'x-pigeon-session-id':
532
- this.client.state.pigeonSessionId ||
533
- `UFS-${crypto.randomBytes(16).toString('hex')}-1`,
534
- 'x-tigon-is-retry': 'False',
535
-
536
- // ...
537
- 'accept-encoding': 'gzip, deflate, br',
538
- // ...
539
- 'user-agent': userAgent,
540
- 'x-fb-conn-uuid-client': crypto.randomBytes(16).toString('hex'),
541
- 'x-fb-http-engine': 'MNS/TCP',
542
- 'x-fb-rmd': 'state=URL_ELIGIBLE',
543
- };
544
-
545
- const response = await this.client.request.send({
546
- method: 'POST',
547
- url: '/api/v1/bloks/async_action/com.bloks.www.bloks.caa.login.async.send_login_request/',
548
- form: {
549
- params: paramsJson,
550
- bk_client_context: bkClientContext,
551
- bloks_versioning_id: this.client.state.bloksVersionId,
552
- },
553
- headers: bloksHeaders,
554
- });
555
-
556
- // === DEBUG LOGIN: salvăm răspunsul pentru analiză ===
557
- try {
558
- const fs = require('fs');
559
- const path = require('path');
560
-
561
- const debugDir = path.join(process.cwd(), 'authinfo_instagram');
562
- const debugFile = path.join(debugDir, 'login-debug.json');
563
-
564
- try {
565
- fs.mkdirSync(debugDir, { recursive: true });
566
- } catch (e) {}
567
-
568
- const debugPayload = {
569
- at: new Date().toISOString(),
570
- statusCode: response.statusCode || response.status || null,
571
- headers: response.headers || null,
572
- body: response.body || null,
573
- };
574
-
575
- fs.writeFileSync(debugFile, JSON.stringify(debugPayload, null, 2), 'utf8');
576
- } catch (e) {
577
- // nu stricăm login-ul dacă nu merge debug-ul
578
- }
579
- // === SFÂRȘIT DEBUG LOGIN ===
580
-
581
- const body = response.body;
582
-
583
- // Immediately attempt to extract and save authorization token from the response
584
- this._extractAndSaveAuthorization(response);
585
-
586
- if (body && body.two_factor_required) {
587
- const err = new Error('Two factor authentication required');
588
- err.name = 'IgLoginTwoFactorRequiredError';
589
- err.twoFactorInfo = body.two_factor_info;
590
- throw err;
591
- }
592
- if (body && body.error_type === 'bad_password') {
593
- const err = new Error('Bad password');
594
- err.name = 'IgLoginBadPasswordError';
595
- throw err;
596
- }
597
- if (body && body.error_type === 'invalid_user') {
598
- const err = new Error('Invalid user');
599
- err.name = 'IgLoginInvalidUserError';
600
- throw err;
601
- }
602
- if (body && body.message === 'challenge_required') {
603
- const err = new Error('Challenge required');
604
- err.name = 'IgCheckpointError';
605
- err.challengeInfo = body.challenge;
606
- throw err;
607
- }
608
-
609
- if (body && body.layout) {
610
- const layoutStr = typeof body.layout === 'string' ? body.layout : JSON.stringify(body.layout);
611
-
612
- // If layout contains two-factor markers, parse and throw
613
- if (layoutStr.includes('two_factor_required') || layoutStr.includes('"two_factor_info"')) {
614
- let twoFactorInfo = null;
615
- try {
616
- const match = layoutStr.match(/"two_factor_info"\s*:\s*(\{[^}]+\})/);
617
- if (match) twoFactorInfo = JSON.parse(match[1]);
618
- } catch (e) {}
619
- const err = new Error('Two factor authentication required');
620
- err.name = 'IgLoginTwoFactorRequiredError';
621
- err.twoFactorInfo = twoFactorInfo;
622
- throw err;
623
- }
624
-
625
- if (layoutStr.includes('bad_password') || layoutStr.includes('incorrect_password')) {
626
- const err = new Error('Bad password');
627
- err.name = 'IgLoginBadPasswordError';
628
- throw err;
629
- }
630
-
631
- if (layoutStr.includes('invalid_user') || layoutStr.includes('user_not_found')) {
632
- const err = new Error('Invalid user');
633
- err.name = 'IgLoginInvalidUserError';
634
- throw err;
635
- }
636
-
637
- if (layoutStr.includes('challenge_required')) {
638
- const err = new Error('Challenge required');
639
- err.name = 'IgCheckpointError';
640
- err.challengeInfo = body.challenge || null;
641
- throw err;
642
- }
643
-
644
- // Additional attempt to extract token from layout string (redundant but robust)
645
- const tokenFromLayout = this._findBearerInString(layoutStr);
646
- if (tokenFromLayout) {
647
- this.client.state.authorization = tokenFromLayout;
648
- try { this.client.state.updateAuthorization(); } catch (e) {}
649
- }
650
-
651
- // Extract pk (user id) from layout if present
652
- const pkPatterns = [
653
- /\\"pk\\":\s*(\d+)/,
654
- /"pk":\s*(\d+)/,
655
- /\\"pk_id\\":\s*\\"(\d+)\\"/,
656
- /"pk_id":\s*"(\d+)"/,
657
- /logged_in_user.*?"pk":\s*(\d+)/,
658
- /logged_in_user.*?\\"pk\\":\s*(\d+)/,
659
- ];
660
- let extractedPk = null;
661
- for (const pattern of pkPatterns) {
662
- const pkMatch = layoutStr.match(pattern);
663
- if (pkMatch) {
664
- extractedPk = pkMatch[1];
665
- this.client.state.cookieUserId = extractedPk;
666
- this.client.state._userId = extractedPk;
667
- break;
668
- }
669
- }
670
-
671
- // Extract IG-Set-WWW-Claim if present
672
- const wwwClaimPatterns = [
673
- /IG-Set-WWW-Claim[\\"\s:]+([a-f0-9]+)/i,
674
- /ig-set-www-claim[\\"\s:]+([a-f0-9]+)/i,
675
- /www.claim[\\"\s:]+([a-f0-9]+)/i,
676
- /x-ig-set-www-claim[\\"\s:]+([a-f0-9]+)/i,
677
- ];
678
- for (const pattern of wwwClaimPatterns) {
679
- const wwwClaimMatch = layoutStr.match(pattern);
680
- if (wwwClaimMatch) {
681
- this.client.state.igWWWClaim = wwwClaimMatch[1];
682
- break;
683
- }
684
- }
685
-
686
- // Extract encryption key id and pub key (already attempted earlier in _extractAndSaveAuthorization)
687
- const encKeyIdMatch = layoutStr.match(/IG-Set-Password-Encryption-Key-Id[\\"\s:]+(\d+)/i) ||
688
- layoutStr.match(/password.encryption.key.id[\\"\s:]+(\d+)/i);
689
- if (encKeyIdMatch) {
690
- this.client.state.passwordEncryptionKeyId = parseInt(encKeyIdMatch[1]);
691
- }
692
-
693
- const encPubKeyMatch = layoutStr.match(/IG-Set-Password-Encryption-Pub-Key[\\"\s:]+([A-Za-z0-9+\/=]+)/i) ||
694
- layoutStr.match(/password.encryption.pub.key[\\"\s:]+([A-Za-z0-9+\/=]+)/i);
695
- if (encPubKeyMatch) {
696
- this.client.state.passwordEncryptionPubKey = encPubKeyMatch[1];
697
- }
698
-
699
- const midMatch = layoutStr.match(/ig-set-x-mid[\\"\s:]+([A-Za-z0-9+\/=_-]+)/i) ||
700
- layoutStr.match(/\\"x-mid\\"[\\"\s:]+([A-Za-z0-9+\/=_-]+)/i);
701
- if (midMatch) {
702
- this.client.state.mid = midMatch[1];
703
- }
704
-
705
- // If layout contains a direct logged_in_user JSON, extract and return it
706
- const loginResponsePatterns = [
707
- /\\"logged_in_user\\":\{[^}]*\\"pk\\":(\d+)[^}]*\\"username\\":\\"([^"\\]+)\\"/,
708
- /"logged_in_user":\{[^}]*"pk":(\d+)[^}]*"username":"([^"]+)"/,
709
- /\\"logged_in_user\\".*?\\"pk\\":\s*(\d+).*?\\"username\\":\s*\\"([^"\\]+)\\"/s,
710
- ];
711
- for (const pattern of loginResponsePatterns) {
712
- const loginResponseMatch = layoutStr.match(pattern);
713
- if (loginResponseMatch) {
714
- this.client.state.cookieUserId = loginResponseMatch[1];
715
- this.client.state._userId = loginResponseMatch[1];
716
- return {
717
- pk: parseInt(loginResponseMatch[1]),
718
- pk_id: loginResponseMatch[1],
719
- username: loginResponseMatch[2],
720
- };
721
- }
722
- }
723
-
724
- // If we have extracted a pk and we also have authorization, try to fetch current user
725
- if (extractedPk && this.client.state.authorization) {
726
- try {
727
- const userInfo = await this.currentUser();
728
- const user = userInfo.user || userInfo;
729
- if (user && user.pk) {
730
- this.client.state.cookieUserId = String(user.pk);
731
- this.client.state._userId = String(user.pk);
732
- }
733
- return user;
734
- } catch (e) {
735
- return { pk: parseInt(extractedPk), pk_id: extractedPk };
736
- }
737
- }
738
- }
739
-
740
- // If server returned logged_in_user directly in body
741
- if (body && body.logged_in_user) {
742
- const lu = body.logged_in_user;
743
- if (lu.pk) {
744
- this.client.state.cookieUserId = String(lu.pk);
745
- this.client.state._userId = String(lu.pk);
746
- }
747
- // Ensure authorization is saved if present in response headers
748
- this._extractAndSaveAuthorization(response);
749
- return lu;
750
- }
751
-
752
- // If we already have authorization, try to fetch current user to populate state
753
- if (this.client.state.authorization) {
754
- try {
755
- const userInfo = await this.currentUser();
756
- const user = userInfo.user || userInfo;
757
- if (user && user.pk) {
758
- this.client.state.cookieUserId = String(user.pk);
759
- this.client.state._userId = String(user.pk);
760
- }
761
- return user;
762
- } catch (e) {
763
- // fallback: return raw body
764
- return body;
765
- }
766
- }
767
-
768
- return body;
769
- });
770
- }
771
-
772
- async twoFactorLogin(username, verificationCode, twoFactorIdentifier, verificationMethod = '1') {
773
- return this.requestWithRetry(async () => {
774
- const response = await this.client.request.send({
775
- method: 'POST',
776
- url: '/api/v1/accounts/two_factor_login/',
777
- form: this.client.request.sign({
778
- username,
779
- verification_code: verificationCode,
780
- two_factor_identifier: twoFactorIdentifier,
781
- verification_method: verificationMethod,
782
- trust_this_device: '1',
783
- guid: this.client.state.uuid,
784
- device_id: this.client.state.deviceId,
785
- phone_id: this.client.state.phoneId,
786
- }),
787
- });
788
- // Save authorization if present in two-factor response
789
- this._extractAndSaveAuthorization(response);
790
- return response.body;
791
- });
792
- }
793
-
794
- async logout() {
795
- return this.requestWithRetry(async () => {
796
- const response = await this.client.request.send({
797
- method: 'POST',
798
- url: '/api/v1/accounts/logout/',
799
- form: this.client.request.sign({
800
- _uuid: this.client.state.uuid,
801
- }),
802
- });
803
- return response.body;
804
- });
805
- }
806
-
807
- async currentUser() {
808
- return this.requestWithRetry(async () => {
809
- const response = await this.client.request.send({
810
- method: 'GET',
811
- url: '/api/v1/accounts/current_user/',
812
- qs: { edit: true },
813
- });
814
- return response.body;
815
- });
816
- }
817
-
818
- async accountInfo() {
819
- return this.currentUser();
820
- }
821
-
822
- async editProfile({ externalUrl, phoneNumber, username, fullName, biography, email } = {}) {
823
- return this.requestWithRetry(async () => {
824
- const current = await this.currentUser();
825
- const user = current.user || current;
826
- const response = await this.client.request.send({
827
- method: 'POST',
828
- url: '/api/v1/accounts/edit_profile/',
829
- form: this.client.request.sign({
830
- _uuid: this.client.state.uuid,
831
- external_url: externalUrl !== undefined ? externalUrl : (user.external_url || ''),
832
- phone_number: phoneNumber !== undefined ? phoneNumber : (user.phone_number || ''),
833
- username: username !== undefined ? username : user.username,
834
- full_name: fullName !== undefined ? fullName : (user.full_name || ''),
835
- biography: biography !== undefined ? biography : (user.biography || ''),
836
- email: email !== undefined ? email : (user.email || ''),
837
- }),
838
- });
839
- return response.body;
840
- });
841
- }
842
-
843
- async setBiography(biography) {
844
- return this.editProfile({ biography });
845
- }
846
-
847
- async setExternalUrl(url) {
848
- return this.editProfile({ externalUrl: url });
849
- }
850
-
851
- async removeBioLinks() {
852
- return this.editProfile({ externalUrl: '' });
853
- }
854
-
855
- async setGender(gender) {
856
- return this.requestWithRetry(async () => {
857
- const response = await this.client.request.send({
858
- method: 'POST',
859
- url: '/api/v1/accounts/set_gender/',
860
- form: this.client.request.sign({
861
- _uuid: this.client.state.uuid,
862
- gender,
863
- }),
864
- });
865
- return response.body;
866
- });
867
- }
868
-
869
- async setPrivate() {
870
- return this.requestWithRetry(async () => {
871
- const response = await this.client.request.send({
872
- method: 'POST',
873
- url: '/api/v1/accounts/set_private/',
874
- form: this.client.request.sign({
875
- _uuid: this.client.state.uuid,
876
- }),
877
- });
878
- return response.body;
879
- });
880
- }
881
-
882
- async setPublic() {
883
- return this.requestWithRetry(async () => {
884
- const response = await this.client.request.send({
885
- method: 'POST',
886
- url: '/api/v1/accounts/set_public/',
887
- form: this.client.request.sign({
888
- _uuid: this.client.state.uuid,
889
- }),
890
- });
891
- return response.body;
892
- });
893
- }
894
-
895
- async changePassword(oldPassword, newPassword) {
896
- const oldEnc = this.encryptPassword(oldPassword);
897
- const newEnc = this.encryptPassword(newPassword);
898
- return this.requestWithRetry(async () => {
899
- const response = await this.client.request.send({
900
- method: 'POST',
901
- url: '/api/v1/accounts/change_password/',
902
- form: this.client.request.sign({
903
- _uuid: this.client.state.uuid,
904
- enc_old_password: `#PWD_INSTAGRAM:4:${oldEnc.time}:${oldEnc.encrypted}`,
905
- enc_new_password1: `#PWD_INSTAGRAM:4:${newEnc.time}:${newEnc.encrypted}`,
906
- enc_new_password2: `#PWD_INSTAGRAM:4:${newEnc.time}:${newEnc.encrypted}`,
907
- }),
908
- });
909
- return response.body;
910
- });
911
- }
912
-
913
- async sendConfirmEmail() {
914
- return this.requestWithRetry(async () => {
915
- const response = await this.client.request.send({
916
- method: 'POST',
917
- url: '/api/v1/accounts/send_confirm_email/',
918
- form: this.client.request.sign({
919
- _uuid: this.client.state.uuid,
920
- send_source: 'edit_profile',
921
- }),
922
- });
923
- return response.body;
924
- });
925
- }
926
-
927
- async sendConfirmPhoneNumber(phoneNumber) {
928
- return this.requestWithRetry(async () => {
929
- const response = await this.client.request.send({
930
- method: 'POST',
931
- url: '/api/v1/accounts/send_confirm_phone_number/',
932
- form: this.client.request.sign({
933
- _uuid: this.client.state.uuid,
934
- phone_number: phoneNumber,
935
- }),
936
- });
937
- return response.body;
938
- });
939
- }
940
-
941
- async profilePictureChange(uploadId) {
942
- return this.requestWithRetry(async () => {
943
- const response = await this.client.request.send({
944
- method: 'POST',
945
- url: '/api/v1/accounts/change_profile_picture/',
946
- form: this.client.request.sign({
947
- _uuid: this.client.state.uuid,
948
- use_fbuploader: 'true',
949
- upload_id: uploadId,
950
- }),
951
- });
952
- return response.body;
953
- });
954
- }
955
-
956
- async profilePictureRemove() {
957
- return this.requestWithRetry(async () => {
958
- const response = await this.client.request.send({
959
- method: 'POST',
960
- url: '/api/v1/accounts/remove_profile_picture/',
961
- form: this.client.request.sign({
962
- _uuid: this.client.state.uuid,
963
- }),
964
- });
965
- return response.body;
966
- });
967
- }
968
-
969
- async newsInbox() {
970
- return this.requestWithRetry(async () => {
971
- const response = await this.client.request.send({
972
- method: 'GET',
973
- url: '/api/v1/news/inbox/',
974
- });
975
- return response.body;
976
- });
977
- }
978
-
979
- async syncLoginExperiments() {
980
- return this.requestWithRetry(async () => {
981
- const response = await this.client.request.send({
982
- method: 'POST',
983
- url: '/api/v1/qe/sync/',
984
- form: this.client.request.sign({
985
- id: this.client.state.uuid,
986
- server_config_retrieval: '1',
987
- experiments: this.client.state.constants.LOGIN_EXPERIMENTS,
988
- }),
989
- });
990
- return response.body;
991
- });
992
- }
993
-
994
- async syncPostLoginExperiments() {
995
- let userId;
996
- try { userId = this.client.state.cookieUserId; } catch { userId = '0'; }
997
- return this.requestWithRetry(async () => {
998
- const response = await this.client.request.send({
999
- method: 'POST',
1000
- url: '/api/v1/qe/sync/',
1001
- form: this.client.request.sign({
1002
- id: userId,
1003
- _uid: userId,
1004
- _uuid: this.client.state.uuid,
1005
- server_config_retrieval: '1',
1006
- experiments: this.client.state.constants.EXPERIMENTS,
1007
- }),
1008
- });
1009
- return response.body;
1010
- });
1011
- }
1012
-
1013
- async syncLauncher(preLogin = true) {
1014
- const data = {
1015
- id: this.client.state.uuid,
1016
- server_config_retrieval: '1',
1017
- };
1018
- if (!preLogin) {
1019
- try {
1020
- data._uid = this.client.state.cookieUserId;
1021
- data._uuid = this.client.state.uuid;
1022
- } catch {}
1023
- }
1024
- return this.requestWithRetry(async () => {
1025
- const response = await this.client.request.send({
1026
- method: 'POST',
1027
- url: '/api/v1/launcher/sync/',
1028
- form: this.client.request.sign(data),
1029
- });
1030
- return response.body;
1031
- });
1032
- }
1033
-
1034
- async syncDeviceFeatures() {
1035
- return this.requestWithRetry(async () => {
1036
- const response = await this.client.request.send({
1037
- method: 'POST',
1038
- url: '/api/v1/devices/sync/',
1039
- form: this.client.request.sign({
1040
- id: this.client.state.uuid,
1041
- server_config_retrieval: '1',
1042
- }),
1043
- });
1044
- return response.body;
1045
- });
1046
- }
1047
-
1048
- async getPrefillCandidates() {
1049
- return this.requestWithRetry(async () => {
1050
- const response = await this.client.request.send({
1051
- method: 'POST',
1052
- url: '/api/v1/accounts/get_prefill_candidates/',
1053
- form: this.client.request.sign({
1054
- android_device_id: this.client.state.deviceId,
1055
- phone_id: this.client.state.phoneId,
1056
- usages: '["account_recovery_omnibox"]',
1057
- device_id: this.client.state.uuid,
1058
- }),
1059
- });
1060
- return response.body;
1061
- });
1062
- }
1063
-
1064
- async contactPointPrefill(usage = 'prefill') {
1065
- return this.requestWithRetry(async () => {
1066
- const response = await this.client.request.send({
1067
- method: 'POST',
1068
- url: '/api/v1/accounts/contact_point_prefill/',
1069
- form: this.client.request.sign({
1070
- phone_id: this.client.state.phoneId,
1071
- usage,
1072
- }),
1073
- });
1074
- return response.body;
1075
- });
1076
- }
1077
-
1078
- async getZrToken(params = {}) {
1079
- return this.requestWithRetry(async () => {
1080
- const response = await this.client.request.send({
1081
- method: 'GET',
1082
- url: '/api/v1/zr/token/result/',
1083
- qs: {
1084
- device_id: this.client.state.deviceId,
1085
- custom_device_id: this.client.state.uuid,
1086
- fetch_reason: 'token_expired',
1087
- token_hash: '',
1088
- ...params,
1089
- },
1090
- });
1091
- return response.body;
1092
- });
1093
- }
1094
-
1095
- async getConsentSignupConfig() {
1096
- return this.requestWithRetry(async () => {
1097
- const response = await this.client.request.send({
1098
- method: 'GET',
1099
- url: '/api/v1/consent/get_signup_config/',
1100
- qs: {
1101
- guid: this.client.state.uuid,
1102
- main_account_selected: false,
1103
- },
1104
- });
1105
- return response.body;
1106
- });
1107
- }
1108
-
1109
- async sendRecoveryFlowEmail(query) {
1110
- return this.requestWithRetry(async () => {
1111
- const response = await this.client.request.send({
1112
- url: '/api/v1/accounts/send_recovery_flow_email/',
1113
- method: 'POST',
1114
- form: this.client.request.sign({
1115
- adid: '',
1116
- guid: this.client.state.uuid,
1117
- device_id: this.client.state.deviceId,
1118
- query,
1119
- }),
1120
- });
1121
- return response.body;
1122
- });
1123
- }
1124
-
1125
- async sendRecoveryFlowSms(query) {
1126
- return this.requestWithRetry(async () => {
1127
- const response = await this.client.request.send({
1128
- url: '/api/v1/accounts/send_recovery_flow_sms/',
1129
- method: 'POST',
1130
- form: this.client.request.sign({
1131
- adid: '',
1132
- guid: this.client.state.uuid,
1133
- device_id: this.client.state.deviceId,
1134
- query,
1135
- }),
1136
- });
1137
- return response.body;
1138
- });
1139
- }
1140
-
1141
- static generateAttestParams(state) {
1142
- // Emulate Instagram's keystore attestation as closely as possible:
1143
- // - version: 2
1144
- // - type: "keystore"
1145
- // - errors: [0]
1146
- // - challenge_nonce: random base64url
1147
- // - signed_nonce: ECDSA signature over the nonce
1148
- // - key_hash: sha256(spki(publicKey))
1149
- // - certificate_chain: 4 PEM certificates concatenated (leaf + 2 intermediates + root)
1150
- //
1151
- // NOTE: This is *not* a real hardware-backed attestation chain, but it mirrors
1152
- // the structure of the official app very closely so the server sees the same
1153
- // shape: a single attestation object with a 4‑certificate chain.
1154
- const challengeNonce = crypto.randomBytes(24).toString('base64url');
1155
-
1156
- const { privateKey, publicKey } = crypto.generateKeyPairSync('ec', {
1157
- namedCurve: 'prime256v1',
1158
- });
1159
-
1160
- // Sign the challenge nonce with the private key (simulating TEE signing).
1161
- const signedData = crypto.sign(null, Buffer.from(challengeNonce), privateKey);
1162
- const signedNonce = signedData.toString('base64');
1163
-
1164
- const publicKeyDer = publicKey.export({ type: 'spki', format: 'der' });
1165
- const keyHash = crypto.createHash('sha256').update(publicKeyDer).digest('hex');
1166
-
1167
- // Build a 4‑certificate chain (leaf + 2 intermediates + root), just like
1168
- // what we saw in the captured traffic from the real Instagram app.
1169
- const leafCertPem = AccountRepository._generateSelfSignedCert(
1170
- privateKey,
1171
- publicKey,
1172
- 'Android Keystore Key'
1173
- );
1174
- const intermediate1Pem = AccountRepository._generateSelfSignedCert(
1175
- privateKey,
1176
- publicKey,
1177
- 'Android Keystore Key Attestation'
1178
- );
1179
- const intermediate2Pem = AccountRepository._generateSelfSignedCert(
1180
- privateKey,
1181
- publicKey,
1182
- 'Android Hardware Keystore'
1183
- );
1184
- const rootCertPem = AccountRepository._generateSelfSignedCert(
1185
- privateKey,
1186
- publicKey,
1187
- 'Android Keystore Root'
1188
- );
1189
-
1190
- const certificateChain = [
1191
- leafCertPem,
1192
- intermediate1Pem,
1193
- intermediate2Pem,
1194
- rootCertPem,
1195
- ].join('\n');
1196
-
1197
- return {
1198
- attestation: [
1199
- {
1200
- version: 2,
1201
- type: 'keystore',
1202
- errors: [0],
1203
- challenge_nonce: challengeNonce,
1204
- signed_nonce: signedNonce,
1205
- key_hash: keyHash,
1206
- certificate_chain: certificateChain,
1207
- },
1208
- ],
1209
- };
1210
- }
1211
-
1212
- static _generateSelfSignedCert(privateKey, publicKey, cn) {
1213
- const publicKeyDer = publicKey.export({ type: 'spki', format: 'der' });
1214
- const serialNumber = crypto.randomBytes(8);
1215
- const now = new Date();
1216
- const notBefore = new Date(now.getTime() - 365 * 24 * 60 * 60 * 1000);
1217
- const notAfter = new Date(now.getTime() + 10 * 365 * 24 * 60 * 60 * 1000);
1218
-
1219
- const cnBytes = Buffer.from(cn, 'utf8');
1220
- const cnSeq = Buffer.concat([
1221
- Buffer.from([0x30, cnBytes.length + 13]),
1222
- Buffer.from([0x31, cnBytes.length + 11]),
1223
- Buffer.from([0x30, cnBytes.length + 9]),
1224
- Buffer.from([0x06, 0x03, 0x55, 0x04, 0x03]),
1225
- Buffer.from([0x0c, cnBytes.length]),
1226
- cnBytes,
1227
- ]);
1228
-
1229
- function encodeTime(date) {
1230
- const str = date.toISOString().replace(/[-:T]/g, '').slice(2, 14) + 'Z';
1231
- return Buffer.concat([Buffer.from([0x17, str.length]), Buffer.from(str)]);
1232
- }
1233
-
1234
- const validityBuf = Buffer.concat([
1235
- encodeTime(notBefore),
1236
- encodeTime(notAfter),
1237
- ]);
1238
- const validity = Buffer.concat([Buffer.from([0x30, validityBuf.length]), validityBuf]);
1239
-
1240
- const tbs = Buffer.concat([
1241
- Buffer.from([0xa0, 0x03, 0x02, 0x01, 0x02]),
1242
- Buffer.from([0x02, serialNumber.length]), serialNumber,
1243
- Buffer.from([0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02]),
1244
- cnSeq,
1245
- validity,
1246
- cnSeq,
1247
- publicKeyDer,
1248
- ]);
1249
-
1250
- const tbsSeq = Buffer.concat([Buffer.from([0x30, 0x82]), Buffer.alloc(2), tbs]);
1251
- tbsSeq.writeUInt16BE(tbs.length, 2);
1252
-
1253
- const signature = crypto.sign(null, tbsSeq, privateKey);
1254
-
1255
- const sigBitString = Buffer.concat([
1256
- Buffer.from([0x03, signature.length + 1, 0x00]),
1257
- signature,
1258
- ]);
1259
-
1260
- const algId = Buffer.from([0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02]);
1261
-
1262
- const certBody = Buffer.concat([tbsSeq, algId, sigBitString]);
1263
- const cert = Buffer.concat([Buffer.from([0x30, 0x82]), Buffer.alloc(2), certBody]);
1264
- cert.writeUInt16BE(certBody.length, 2);
1265
-
1266
- const b64 = cert.toString('base64');
1267
- const lines = b64.match(/.{1,76}/g) || [b64];
1268
- return '-----BEGIN CERTIFICATE-----\n' + lines.join('\n') + '\n-----END CERTIFICATE-----';
1269
- }
1270
-
1271
- static createJazoest(input) {
1272
- const buf = Buffer.from(input || '', 'ascii');
1273
- let sum = 0;
1274
- for (let i = 0; i < buf.byteLength; i++) {
1275
- sum += buf.readUInt8(i);
1276
- }
1277
- return `2${sum}`;
1278
- }
1279
-
1280
- encryptPassword(password) {
1281
- if (!this.client.state.passwordEncryptionPubKey) {
1282
- return { time: Math.floor(Date.now() / 1000).toString(), encrypted: password };
1283
- }
1284
-
1285
- const randKey = crypto.randomBytes(32);
1286
- const iv = crypto.randomBytes(12);
1287
-
1288
- const rsaEncrypted = crypto.publicEncrypt({
1289
- key: Buffer.from(this.client.state.passwordEncryptionPubKey, 'base64').toString(),
1290
- padding: crypto.constants.RSA_PKCS1_PADDING,
1291
- }, randKey);
1292
-
1293
- const cipher = crypto.createCipheriv('aes-256-gcm', randKey, iv);
1294
- const time = Math.floor(Date.now() / 1000).toString();
1295
- cipher.setAAD(Buffer.from(time));
1296
-
1297
- const aesEncrypted = Buffer.concat([cipher.update(password, 'utf8'), cipher.final()]);
1298
- const sizeBuffer = Buffer.alloc(2, 0);
1299
- sizeBuffer.writeInt16LE(rsaEncrypted.byteLength, 0);
1300
- const authTag = cipher.getAuthTag();
1301
-
1302
- return {
1303
- time,
1304
- encrypted: Buffer.concat([
1305
- Buffer.from([1, this.client.state.passwordEncryptionKeyId || 0]),
1306
- iv,
1307
- sizeBuffer,
1308
- rsaEncrypted,
1309
- authTag,
1310
- aesEncrypted
1311
- ]).toString('base64')
1312
- };
1313
- }
1314
-
1315
- async passwordPublicKeys() {
1316
- const response = await this.client.request.send({
1317
- method: 'GET',
1318
- url: '/api/v1/qe/sync/',
1319
- });
1320
- const headers = response.headers || {};
1321
- const keyId = parseInt(headers['ig-set-password-encryption-key-id'] || '0');
1322
- const pubKey = headers['ig-set-password-encryption-pub-key'] || '';
1323
- return { keyId, pubKey };
1324
- }
1325
-
1326
- async setPresenceDisabled(disabled = true) {
1327
- return this.requestWithRetry(async () => {
1328
- const response = await this.client.request.send({
1329
- method: 'POST',
1330
- url: '/api/v1/accounts/set_presence_disabled/',
1331
- form: this.client.request.sign({
1332
- _uuid: this.client.state.uuid,
1333
- disabled: disabled ? '1' : '0',
1334
- }),
1335
- });
1336
- return response.body;
1337
- });
1338
- }
1339
-
1340
- async getCommentFilter() {
1341
- return this.requestWithRetry(async () => {
1342
- const response = await this.client.request.send({
1343
- method: 'GET',
1344
- url: '/api/v1/accounts/get_comment_filter/',
1345
- });
1346
- return response.body;
1347
- });
1348
- }
1349
-
1350
- async setCommentFilter(configValue = 0) {
1351
- return this.requestWithRetry(async () => {
1352
- const response = await this.client.request.send({
1353
- method: 'POST',
1354
- url: '/api/v1/accounts/set_comment_filter/',
1355
- form: this.client.request.sign({
1356
- _uuid: this.client.state.uuid,
1357
- config_value: String(configValue),
1358
- }),
1359
- });
1360
- return response.body;
1361
- });
1362
- }
1363
-
1364
- async pushPreferences(preferences = 'default') {
1365
- return this.requestWithRetry(async () => {
1366
- const response = await this.client.request.send({
1367
- method: 'POST',
1368
- url: '/api/v1/push/register/',
1369
- form: this.client.request.sign({
1370
- _uuid: this.client.state.uuid,
1371
- device_type: 'android_mqtt',
1372
- is_main_push_channel: 'true',
1373
- phone_id: this.client.state.phoneId,
1374
- device_token: '',
1375
- guid: this.client.state.uuid,
1376
- users: preferences,
1377
- }),
1378
- });
1379
- return response.body;
1380
- });
1381
- }
1382
- }
1383
-
1384
- module.exports = AccountRepository;