nodejs-insta-private-api-mqtt 1.0.0

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 (210) hide show
  1. package/README.md +1650 -0
  2. package/dist/constants/constants.js +280 -0
  3. package/dist/constants/index.js +41 -0
  4. package/dist/core/client.js +243 -0
  5. package/dist/core/repository.js +7 -0
  6. package/dist/core/request.js +212 -0
  7. package/dist/core/state.js +1456 -0
  8. package/dist/core/utils.js +786 -0
  9. package/dist/downloadMedia.js +381 -0
  10. package/dist/errors/index.d.ts +16 -0
  11. package/dist/errors/index.js +30 -0
  12. package/dist/errors/index.js.map +1 -0
  13. package/dist/fbns/fbns.client.d.ts +32 -0
  14. package/dist/fbns/fbns.client.events.d.ts +41 -0
  15. package/dist/fbns/fbns.client.events.js +3 -0
  16. package/dist/fbns/fbns.client.events.js.map +1 -0
  17. package/dist/fbns/fbns.client.js +179 -0
  18. package/dist/fbns/fbns.client.js.map +1 -0
  19. package/dist/fbns/fbns.device-auth.d.ts +17 -0
  20. package/dist/fbns/fbns.device-auth.js +54 -0
  21. package/dist/fbns/fbns.device-auth.js.map +1 -0
  22. package/dist/fbns/fbns.types.d.ts +83 -0
  23. package/dist/fbns/fbns.types.js +3 -0
  24. package/dist/fbns/fbns.types.js.map +1 -0
  25. package/dist/fbns/fbns.utilities.d.ts +2 -0
  26. package/dist/fbns/fbns.utilities.js +79 -0
  27. package/dist/fbns/fbns.utilities.js.map +1 -0
  28. package/dist/fbns/index.d.ts +4 -0
  29. package/dist/fbns/index.js +21 -0
  30. package/dist/fbns/index.js.map +1 -0
  31. package/dist/index.js +39 -0
  32. package/dist/mqttot/index.d.ts +4 -0
  33. package/dist/mqttot/index.js +21 -0
  34. package/dist/mqttot/index.js.map +1 -0
  35. package/dist/mqttot/mqttot.client.d.ts +39 -0
  36. package/dist/mqttot/mqttot.client.js +120 -0
  37. package/dist/mqttot/mqttot.client.js.map +1 -0
  38. package/dist/mqttot/mqttot.connect.request.packet.d.ts +7 -0
  39. package/dist/mqttot/mqttot.connect.request.packet.js +9 -0
  40. package/dist/mqttot/mqttot.connect.request.packet.js.map +1 -0
  41. package/dist/mqttot/mqttot.connect.response.packet.d.ts +7 -0
  42. package/dist/mqttot/mqttot.connect.response.packet.js +24 -0
  43. package/dist/mqttot/mqttot.connect.response.packet.js.map +1 -0
  44. package/dist/mqttot/mqttot.connection.d.ts +57 -0
  45. package/dist/mqttot/mqttot.connection.js +56 -0
  46. package/dist/mqttot/mqttot.connection.js.map +1 -0
  47. package/dist/package.json +59 -0
  48. package/dist/realtime/commands/commands.d.ts +15 -0
  49. package/dist/realtime/commands/commands.js +21 -0
  50. package/dist/realtime/commands/commands.js.map +1 -0
  51. package/dist/realtime/commands/direct.commands.d.ts +75 -0
  52. package/dist/realtime/commands/direct.commands.js +186 -0
  53. package/dist/realtime/commands/direct.commands.js.map +1 -0
  54. package/dist/realtime/commands/enhanced.direct.commands.js +987 -0
  55. package/dist/realtime/commands/index.d.ts +2 -0
  56. package/dist/realtime/commands/index.js +19 -0
  57. package/dist/realtime/commands/index.js.map +1 -0
  58. package/dist/realtime/delta-sync.manager.js +293 -0
  59. package/dist/realtime/features/dm-sender.js +88 -0
  60. package/dist/realtime/features/error-handler.js +73 -0
  61. package/dist/realtime/features/gap-handler.js +61 -0
  62. package/dist/realtime/features/presence.manager.js +66 -0
  63. package/dist/realtime/index.js +30 -0
  64. package/dist/realtime/messages/app-presence.event.d.ts +9 -0
  65. package/dist/realtime/messages/app-presence.event.js +3 -0
  66. package/dist/realtime/messages/app-presence.event.js.map +1 -0
  67. package/dist/realtime/messages/index.d.ts +3 -0
  68. package/dist/realtime/messages/index.js +20 -0
  69. package/dist/realtime/messages/index.js.map +1 -0
  70. package/dist/realtime/messages/message-sync.message.d.ts +222 -0
  71. package/dist/realtime/messages/message-sync.message.js +43 -0
  72. package/dist/realtime/messages/message-sync.message.js.map +1 -0
  73. package/dist/realtime/messages/realtime-sub.direct.data.d.ts +11 -0
  74. package/dist/realtime/messages/realtime-sub.direct.data.js +3 -0
  75. package/dist/realtime/messages/realtime-sub.direct.data.js.map +1 -0
  76. package/dist/realtime/messages/thread-update.message.d.ts +68 -0
  77. package/dist/realtime/messages/thread-update.message.js +3 -0
  78. package/dist/realtime/messages/thread-update.message.js.map +1 -0
  79. package/dist/realtime/mixins/index.d.ts +3 -0
  80. package/dist/realtime/mixins/index.js +20 -0
  81. package/dist/realtime/mixins/index.js.map +1 -0
  82. package/dist/realtime/mixins/message-sync.mixin.d.ts +8 -0
  83. package/dist/realtime/mixins/message-sync.mixin.js +381 -0
  84. package/dist/realtime/mixins/message-sync.mixin.js.map +1 -0
  85. package/dist/realtime/mixins/mixin.d.ts +19 -0
  86. package/dist/realtime/mixins/mixin.js +41 -0
  87. package/dist/realtime/mixins/mixin.js.map +1 -0
  88. package/dist/realtime/mixins/presence-typing.mixin.js +33 -0
  89. package/dist/realtime/mixins/realtime-sub.mixin.d.ts +8 -0
  90. package/dist/realtime/mixins/realtime-sub.mixin.js +55 -0
  91. package/dist/realtime/mixins/realtime-sub.mixin.js.map +1 -0
  92. package/dist/realtime/parsers/graphql-parser.js +43 -0
  93. package/dist/realtime/parsers/graphql.parser.d.ts +15 -0
  94. package/dist/realtime/parsers/graphql.parser.js +22 -0
  95. package/dist/realtime/parsers/graphql.parser.js.map +1 -0
  96. package/dist/realtime/parsers/index.d.ts +6 -0
  97. package/dist/realtime/parsers/index.js +23 -0
  98. package/dist/realtime/parsers/index.js.map +1 -0
  99. package/dist/realtime/parsers/iris-parser.js +43 -0
  100. package/dist/realtime/parsers/iris.parser.d.ts +17 -0
  101. package/dist/realtime/parsers/iris.parser.js +10 -0
  102. package/dist/realtime/parsers/iris.parser.js.map +1 -0
  103. package/dist/realtime/parsers/json-parser.js +43 -0
  104. package/dist/realtime/parsers/json.parser.d.ts +6 -0
  105. package/dist/realtime/parsers/json.parser.js +10 -0
  106. package/dist/realtime/parsers/json.parser.js.map +1 -0
  107. package/dist/realtime/parsers/parser.d.ts +9 -0
  108. package/dist/realtime/parsers/parser.js +3 -0
  109. package/dist/realtime/parsers/parser.js.map +1 -0
  110. package/dist/realtime/parsers/region-hint-parser.js +43 -0
  111. package/dist/realtime/parsers/region-hint.parser.d.ts +12 -0
  112. package/dist/realtime/parsers/region-hint.parser.js +15 -0
  113. package/dist/realtime/parsers/region-hint.parser.js.map +1 -0
  114. package/dist/realtime/parsers/skywalker-parser.js +43 -0
  115. package/dist/realtime/parsers/skywalker.parser.d.ts +12 -0
  116. package/dist/realtime/parsers/skywalker.parser.js +15 -0
  117. package/dist/realtime/parsers/skywalker.parser.js.map +1 -0
  118. package/dist/realtime/parsers-advanced.js +158 -0
  119. package/dist/realtime/proto/common.proto +38 -0
  120. package/dist/realtime/proto/direct.proto +65 -0
  121. package/dist/realtime/proto/ig-messages.proto +83 -0
  122. package/dist/realtime/proto/iris.proto +188 -0
  123. package/dist/realtime/proto-parser.js +195 -0
  124. package/dist/realtime/protocols/iris.handshake.js +74 -0
  125. package/dist/realtime/protocols/proto-definitions.js +80 -0
  126. package/dist/realtime/protocols/skywalker.protocol.js +91 -0
  127. package/dist/realtime/realtime.client.events.js +3 -0
  128. package/dist/realtime/realtime.client.js +449 -0
  129. package/dist/realtime/realtime.service.js +462 -0
  130. package/dist/realtime/reconnect.manager.js +94 -0
  131. package/dist/realtime/session.manager.js +121 -0
  132. package/dist/realtime/subscriptions/graphql.subscription.d.ts +47 -0
  133. package/dist/realtime/subscriptions/graphql.subscription.js +99 -0
  134. package/dist/realtime/subscriptions/graphql.subscription.js.map +1 -0
  135. package/dist/realtime/subscriptions/index.d.ts +2 -0
  136. package/dist/realtime/subscriptions/index.js +19 -0
  137. package/dist/realtime/subscriptions/index.js.map +1 -0
  138. package/dist/realtime/subscriptions/skywalker.subscription.d.ts +4 -0
  139. package/dist/realtime/subscriptions/skywalker.subscription.js +13 -0
  140. package/dist/realtime/subscriptions/skywalker.subscription.js.map +1 -0
  141. package/dist/realtime/topic-map.js +71 -0
  142. package/dist/realtime/topic.js +80 -0
  143. package/dist/repositories/account.repository.js +261 -0
  144. package/dist/repositories/direct-thread.repository.js +247 -0
  145. package/dist/repositories/direct.repository.js +153 -0
  146. package/dist/repositories/feed.repository.js +233 -0
  147. package/dist/repositories/friendship.repository.js +190 -0
  148. package/dist/repositories/hashtag.repository.js +101 -0
  149. package/dist/repositories/highlights.repository.js +127 -0
  150. package/dist/repositories/location.repository.js +84 -0
  151. package/dist/repositories/media.repository.js +165 -0
  152. package/dist/repositories/story.repository.js +156 -0
  153. package/dist/repositories/upload.repository.js +167 -0
  154. package/dist/repositories/user.repository.js +94 -0
  155. package/dist/sendmedia/index.js +11 -0
  156. package/dist/sendmedia/sendFile.js +154 -0
  157. package/dist/sendmedia/sendPhoto.js +145 -0
  158. package/dist/sendmedia/uploadPhoto.js +175 -0
  159. package/dist/sendmedia/uploadfFile.js +264 -0
  160. package/dist/services/live.service.js +147 -0
  161. package/dist/services/search.service.js +116 -0
  162. package/dist/shared/index.js +35 -0
  163. package/dist/shared/shared.js +86 -0
  164. package/dist/thrift/index.d.ts +3 -0
  165. package/dist/thrift/index.js +20 -0
  166. package/dist/thrift/index.js.map +1 -0
  167. package/dist/thrift/thrift.d.ts +59 -0
  168. package/dist/thrift/thrift.js +101 -0
  169. package/dist/thrift/thrift.js.map +1 -0
  170. package/dist/thrift/thrift.reading.d.ts +41 -0
  171. package/dist/thrift/thrift.reading.js +327 -0
  172. package/dist/thrift/thrift.reading.js.map +1 -0
  173. package/dist/thrift/thrift.writing.d.ts +44 -0
  174. package/dist/thrift/thrift.writing.js +342 -0
  175. package/dist/thrift/thrift.writing.js.map +1 -0
  176. package/dist/types/index.js +285 -0
  177. package/dist/useMultiFileAuthState.js +437 -0
  178. package/dist/utils/helper-1.js +1 -0
  179. package/dist/utils/helper-10.js +1 -0
  180. package/dist/utils/helper-11.js +1 -0
  181. package/dist/utils/helper-12.js +1 -0
  182. package/dist/utils/helper-13.js +1 -0
  183. package/dist/utils/helper-14.js +1 -0
  184. package/dist/utils/helper-15.js +1 -0
  185. package/dist/utils/helper-16.js +1 -0
  186. package/dist/utils/helper-17.js +1 -0
  187. package/dist/utils/helper-18.js +1 -0
  188. package/dist/utils/helper-19.js +1 -0
  189. package/dist/utils/helper-2.js +1 -0
  190. package/dist/utils/helper-20.js +1 -0
  191. package/dist/utils/helper-21.js +1 -0
  192. package/dist/utils/helper-22.js +1 -0
  193. package/dist/utils/helper-23.js +1 -0
  194. package/dist/utils/helper-24.js +1 -0
  195. package/dist/utils/helper-25.js +1 -0
  196. package/dist/utils/helper-26.js +1 -0
  197. package/dist/utils/helper-27.js +1 -0
  198. package/dist/utils/helper-28.js +1 -0
  199. package/dist/utils/helper-29.js +1 -0
  200. package/dist/utils/helper-3.js +1 -0
  201. package/dist/utils/helper-30.js +1 -0
  202. package/dist/utils/helper-4.js +1 -0
  203. package/dist/utils/helper-5.js +1 -0
  204. package/dist/utils/helper-6.js +1 -0
  205. package/dist/utils/helper-7.js +1 -0
  206. package/dist/utils/helper-8.js +1 -0
  207. package/dist/utils/helper-9.js +1 -0
  208. package/dist/utils/index.js +280 -0
  209. package/examples/listen-to-messages.js +86 -0
  210. package/package.json +79 -0
@@ -0,0 +1,47 @@
1
+ export declare const QueryIDs: {
2
+ appPresence: string;
3
+ asyncAdSub: string;
4
+ clientConfigUpdate: string;
5
+ directStatus: string;
6
+ directTyping: string;
7
+ liveWave: string;
8
+ interactivityActivateQuestion: string;
9
+ interactivityRealtimeQuestionSubmissionsStatus: string;
10
+ interactivitySub: string;
11
+ liveRealtimeComments: string;
12
+ liveTypingIndicator: string;
13
+ mediaFeedback: string;
14
+ reactNativeOTA: string;
15
+ videoCallCoWatchControl: string;
16
+ videoCallInAlert: string;
17
+ videoCallPrototypePublish: string;
18
+ zeroProvision: string;
19
+ };
20
+ export interface GraphQLSubscription {
21
+ subscriptionQueryId: string;
22
+ inputParams: Record<string, any>;
23
+ }
24
+ export interface GraphQLSubBaseOptions {
25
+ subscriptionId?: string;
26
+ clientLogged?: boolean;
27
+ }
28
+ export declare class GraphQLSubscriptions {
29
+ private static formatSubscriptionString;
30
+ static getAppPresenceSubscription: (options?: GraphQLSubBaseOptions) => string;
31
+ static getAsyncAdSubscription: (userId: string, options?: GraphQLSubBaseOptions) => string;
32
+ static getClientConfigUpdateSubscription: (options?: GraphQLSubBaseOptions) => string;
33
+ static getDirectStatusSubscription: (options?: GraphQLSubBaseOptions) => string;
34
+ static getDirectTypingSubscription: (userId: string, clientLogged?: boolean) => string;
35
+ static getIgLiveWaveSubscription: (broadcastId: string, receiverId: string, options?: GraphQLSubBaseOptions) => string;
36
+ static getInteractivityActivateQuestionSubscription: (broadcastId: string, options?: GraphQLSubBaseOptions) => string;
37
+ static getInteractivityRealtimeQuestionSubmissionsStatusSubscription: (broadcastId: string, options?: GraphQLSubBaseOptions) => string;
38
+ static getInteractivitySubscription: (broadcastId: string, options?: GraphQLSubBaseOptions) => string;
39
+ static getLiveRealtimeCommentsSubscription: (broadcastId: string, options?: GraphQLSubBaseOptions) => string;
40
+ static getLiveTypingIndicatorSubscription: (broadcastId: string, options?: GraphQLSubBaseOptions) => string;
41
+ static getMediaFeedbackSubscription: (feedbackId: string, options?: GraphQLSubBaseOptions) => string;
42
+ static getReactNativeOTAUpdateSubscription: (buildNumber: string, options?: GraphQLSubBaseOptions) => string;
43
+ static getVideoCallCoWatchControlSubscription: (videoCallId: string, options?: GraphQLSubBaseOptions) => string;
44
+ static getVideoCallInCallAlertSubscription: (videoCallId: string, options?: GraphQLSubBaseOptions) => string;
45
+ static getVideoCallPrototypePublishSubscription: (videoCallId: string, options?: GraphQLSubBaseOptions) => string;
46
+ static getZeroProvisionSubscription: (deviceId: string, options?: GraphQLSubBaseOptions) => string;
47
+ }
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GraphQLSubscriptions = exports.QueryIDs = void 0;
4
+ const Chance = require("chance");
5
+ // src: com.instagram.realtimeclient.RealtimeSubscription
6
+ exports.QueryIDs = {
7
+ appPresence: '17846944882223835',
8
+ asyncAdSub: '17911191835112000',
9
+ clientConfigUpdate: '17849856529644700',
10
+ directStatus: '17854499065530643',
11
+ directTyping: '17867973967082385',
12
+ liveWave: '17882305414154951',
13
+ interactivityActivateQuestion: '18005526940184517',
14
+ interactivityRealtimeQuestionSubmissionsStatus: '18027779584026952',
15
+ interactivitySub: '17907616480241689',
16
+ liveRealtimeComments: '17855344750227125',
17
+ liveTypingIndicator: '17926314067024917',
18
+ mediaFeedback: '17877917527113814',
19
+ reactNativeOTA: '17861494672288167',
20
+ videoCallCoWatchControl: '17878679623388956',
21
+ videoCallInAlert: '17878679623388956',
22
+ videoCallPrototypePublish: '18031704190010162',
23
+ zeroProvision: '17913953740109069',
24
+ };
25
+ class GraphQLSubscriptions {
26
+ static formatSubscriptionString(queryId, inputParams, clientLogged) {
27
+ return `1/graphqlsubscriptions/${queryId}/${JSON.stringify({
28
+ input_data: inputParams,
29
+ ...(clientLogged ? { '%options': { client_logged: clientLogged } } : {}),
30
+ })}`;
31
+ }
32
+ }
33
+ exports.GraphQLSubscriptions = GraphQLSubscriptions;
34
+ GraphQLSubscriptions.getAppPresenceSubscription = (options = {}) => GraphQLSubscriptions.formatSubscriptionString(exports.QueryIDs.appPresence, {
35
+ client_subscription_id: options.subscriptionId || new Chance().guid({ version: 4 }),
36
+ }, options.clientLogged);
37
+ GraphQLSubscriptions.getAsyncAdSubscription = (userId, options = {}) => GraphQLSubscriptions.formatSubscriptionString(exports.QueryIDs.asyncAdSub, {
38
+ client_subscription_id: options.subscriptionId || new Chance().guid({ version: 4 }),
39
+ user_id: userId,
40
+ }, options.clientLogged);
41
+ GraphQLSubscriptions.getClientConfigUpdateSubscription = (options = {}) => GraphQLSubscriptions.formatSubscriptionString(exports.QueryIDs.clientConfigUpdate, {
42
+ client_subscription_id: options.subscriptionId || new Chance().guid({ version: 4 }),
43
+ }, options.clientLogged);
44
+ GraphQLSubscriptions.getDirectStatusSubscription = (options = {}) => GraphQLSubscriptions.formatSubscriptionString(exports.QueryIDs.directStatus, {
45
+ client_subscription_id: options.subscriptionId || new Chance().guid({ version: 4 }),
46
+ }, options.clientLogged);
47
+ GraphQLSubscriptions.getDirectTypingSubscription = (userId, clientLogged) => GraphQLSubscriptions.formatSubscriptionString(exports.QueryIDs.directTyping, {
48
+ user_id: userId,
49
+ }, clientLogged);
50
+ GraphQLSubscriptions.getIgLiveWaveSubscription = (broadcastId, receiverId, options = {}) => GraphQLSubscriptions.formatSubscriptionString(exports.QueryIDs.liveWave, {
51
+ client_subscription_id: options.subscriptionId || new Chance().guid({ version: 4 }),
52
+ broadcast_id: broadcastId,
53
+ receiver_id: receiverId,
54
+ }, options.clientLogged);
55
+ GraphQLSubscriptions.getInteractivityActivateQuestionSubscription = (broadcastId, options = {}) => GraphQLSubscriptions.formatSubscriptionString(exports.QueryIDs.interactivityActivateQuestion, {
56
+ client_subscription_id: options.subscriptionId || new Chance().guid({ version: 4 }),
57
+ broadcast_id: broadcastId,
58
+ }, options.clientLogged);
59
+ GraphQLSubscriptions.getInteractivityRealtimeQuestionSubmissionsStatusSubscription = (broadcastId, options = {}) => GraphQLSubscriptions.formatSubscriptionString(exports.QueryIDs.interactivityRealtimeQuestionSubmissionsStatus, {
60
+ client_subscription_id: options.subscriptionId || new Chance().guid({ version: 4 }),
61
+ broadcast_id: broadcastId,
62
+ }, options.clientLogged);
63
+ GraphQLSubscriptions.getInteractivitySubscription = (broadcastId, options = {}) => GraphQLSubscriptions.formatSubscriptionString(exports.QueryIDs.interactivitySub, {
64
+ client_subscription_id: options.subscriptionId || new Chance().guid({ version: 4 }),
65
+ broadcast_id: broadcastId,
66
+ }, options.clientLogged);
67
+ GraphQLSubscriptions.getLiveRealtimeCommentsSubscription = (broadcastId, options = {}) => GraphQLSubscriptions.formatSubscriptionString(exports.QueryIDs.liveRealtimeComments, {
68
+ client_subscription_id: options.subscriptionId || new Chance().guid({ version: 4 }),
69
+ broadcast_id: broadcastId,
70
+ }, options.clientLogged);
71
+ GraphQLSubscriptions.getLiveTypingIndicatorSubscription = (broadcastId, options = {}) => GraphQLSubscriptions.formatSubscriptionString(exports.QueryIDs.liveTypingIndicator, {
72
+ client_subscription_id: options.subscriptionId || new Chance().guid({ version: 4 }),
73
+ broadcast_id: broadcastId,
74
+ }, options.clientLogged);
75
+ GraphQLSubscriptions.getMediaFeedbackSubscription = (feedbackId, options = {}) => GraphQLSubscriptions.formatSubscriptionString(exports.QueryIDs.mediaFeedback, {
76
+ client_subscription_id: options.subscriptionId || new Chance().guid({ version: 4 }),
77
+ feedback_id: feedbackId,
78
+ }, options.clientLogged);
79
+ GraphQLSubscriptions.getReactNativeOTAUpdateSubscription = (buildNumber, options = {}) => GraphQLSubscriptions.formatSubscriptionString(exports.QueryIDs.reactNativeOTA, {
80
+ client_subscription_id: options.subscriptionId || new Chance().guid({ version: 4 }),
81
+ build_number: buildNumber,
82
+ }, options.clientLogged);
83
+ GraphQLSubscriptions.getVideoCallCoWatchControlSubscription = (videoCallId, options = {}) => GraphQLSubscriptions.formatSubscriptionString(exports.QueryIDs.videoCallCoWatchControl, {
84
+ client_subscription_id: options.subscriptionId || new Chance().guid({ version: 4 }),
85
+ video_call_id: videoCallId,
86
+ }, options.clientLogged);
87
+ GraphQLSubscriptions.getVideoCallInCallAlertSubscription = (videoCallId, options = {}) => GraphQLSubscriptions.formatSubscriptionString(exports.QueryIDs.videoCallInAlert, {
88
+ client_subscription_id: options.subscriptionId || new Chance().guid({ version: 4 }),
89
+ video_call_id: videoCallId,
90
+ }, options.clientLogged);
91
+ GraphQLSubscriptions.getVideoCallPrototypePublishSubscription = (videoCallId, options = {}) => GraphQLSubscriptions.formatSubscriptionString(exports.QueryIDs.videoCallPrototypePublish, {
92
+ client_subscription_id: options.subscriptionId || new Chance().guid({ version: 4 }),
93
+ video_call_id: videoCallId,
94
+ }, options.clientLogged);
95
+ GraphQLSubscriptions.getZeroProvisionSubscription = (deviceId, options = {}) => GraphQLSubscriptions.formatSubscriptionString(exports.QueryIDs.zeroProvision, {
96
+ client_subscription_id: options.subscriptionId || new Chance().guid({ version: 4 }),
97
+ device_id: deviceId,
98
+ }, options.clientLogged);
99
+ //# sourceMappingURL=graphql.subscription.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphql.subscription.js","sourceRoot":"","sources":["../../../src/realtime/subscriptions/graphql.subscription.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AAEjC,yDAAyD;AAC5C,QAAA,QAAQ,GAAG;IACrB,WAAW,EAAE,mBAAmB;IAChC,UAAU,EAAE,mBAAmB;IAC/B,kBAAkB,EAAE,mBAAmB;IACvC,YAAY,EAAE,mBAAmB;IACjC,YAAY,EAAE,mBAAmB;IACjC,QAAQ,EAAE,mBAAmB;IAC7B,6BAA6B,EAAE,mBAAmB;IAClD,8CAA8C,EAAE,mBAAmB;IACnE,gBAAgB,EAAE,mBAAmB;IACrC,oBAAoB,EAAE,mBAAmB;IACzC,mBAAmB,EAAE,mBAAmB;IACxC,aAAa,EAAE,mBAAmB;IAClC,cAAc,EAAE,mBAAmB;IACnC,uBAAuB,EAAE,mBAAmB;IAC5C,gBAAgB,EAAE,mBAAmB;IACrC,yBAAyB,EAAE,mBAAmB;IAC9C,aAAa,EAAE,mBAAmB;CACpC,CAAC;AAYF,MAAa,oBAAoB;IACtB,MAAM,CAAC,wBAAwB,CAAC,OAAe,EAAE,WAAgB,EAAE,YAAsB;QAC9F,OAAO,0BAA0B,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC;YACxD,UAAU,EAAE,WAAW;YACvB,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,EAAE,aAAa,EAAE,YAAY,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC1E,CAAC,EAAE,CAAC;IACR,CAAC;;AANJ,oDA2LC;AAnLgB,+CAA0B,GAAG,CAAC,UAAiC,EAAE,EAAE,EAA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C;IACnF,SAAS,EAAE,QAAQ;CACrB,EACD,OAAO,CAAC,YAAY,CACtB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './graphql.subscription';
2
+ export * from './skywalker.subscription';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./graphql.subscription"), exports);
18
+ __exportStar(require("./skywalker.subscription"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/realtime/subscriptions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yDAAuC;AACvC,2DAAyC"}
@@ -0,0 +1,4 @@
1
+ export declare class SkywalkerSubscriptions {
2
+ static directSub(userId: string | number | bigint): string;
3
+ static liveSub(userId: string | number | bigint): string;
4
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SkywalkerSubscriptions = void 0;
4
+ class SkywalkerSubscriptions {
5
+ static directSub(userId) {
6
+ return `ig/u/v1/${userId}`;
7
+ }
8
+ static liveSub(userId) {
9
+ return `ig/live_notification_subscribe/${userId}`;
10
+ }
11
+ }
12
+ exports.SkywalkerSubscriptions = SkywalkerSubscriptions;
13
+ //# sourceMappingURL=skywalker.subscription.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skywalker.subscription.js","sourceRoot":"","sources":["../../../src/realtime/subscriptions/skywalker.subscription.ts"],"names":[],"mappings":";;;AAAA,MAAa,sBAAsB;IACzB,MAAM,CAAC,SAAS,CAAC,MAAgC;QACrD,OAAO,WAAW,MAAM,EAAE,CAAC;IAC9B,CAAC;IACM,MAAM,CAAC,OAAO,CAAC,MAAgC;QACnD,OAAO,kCAAkC,MAAM,EAAE,CAAC;IACrD,CAAC;CACH;AAPD,wDAOC"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Topic Mapping - Maps Instagram MQTT topics to handlers
3
+ * Topic IDs from Instagram MQTT broker
4
+ */
5
+
6
+ const TOPICS = {
7
+ // Direct Messages
8
+ IRIS: { id: 88, path: '/ig/u/v1', type: 'iris', qos: 1 },
9
+
10
+ // Typing Indicators & Presence
11
+ GRAPHQL: { id: 135, path: '/ig/gqls', type: 'graphql', qos: 1 },
12
+
13
+ // Message Sync Deltas
14
+ MESSAGE_SYNC: { id: 149, path: '/ig/s/delta', type: 'delta', qos: 1 },
15
+
16
+ // Presence Status
17
+ PRESENCE: { id: 150, path: '/ig/s/presence', type: 'presence', qos: 1 },
18
+
19
+ // Feed Updates
20
+ FEED: { id: 133, path: '/ig/s/feed', type: 'feed', qos: 1 },
21
+
22
+ // Live Events
23
+ LIVE: { id: 146, path: '/ig/s/live', type: 'live', qos: 1 },
24
+
25
+ // Region Hint
26
+ REGION_HINT: { id: 202, path: '/t_region_hint', type: 'region', qos: 0 }
27
+ };
28
+
29
+ // For quick ID lookup
30
+ const ID_TO_TOPIC = {};
31
+ Object.values(TOPICS).forEach(topic => {
32
+ ID_TO_TOPIC[topic.id] = topic;
33
+ });
34
+
35
+ // Parser mapping
36
+ const TOPIC_PARSERS = {
37
+ iris: 'parseIris',
38
+ graphql: 'parseGraphQL',
39
+ delta: 'parseDelta',
40
+ presence: 'parsePresence',
41
+ feed: 'parseFeed',
42
+ live: 'parseLive',
43
+ region: 'parseRegionHint'
44
+ };
45
+
46
+ function getTopicById(id) {
47
+ return ID_TO_TOPIC[id];
48
+ }
49
+
50
+ function getTopicByPath(path) {
51
+ return Object.values(TOPICS).find(t => t.path === path);
52
+ }
53
+
54
+ function getParserForTopic(topicType) {
55
+ return TOPIC_PARSERS[topicType] || null;
56
+ }
57
+
58
+ function getSubscriptionList() {
59
+ // Return IDs for MQTT subscription
60
+ return Object.values(TOPICS).map(t => t.id);
61
+ }
62
+
63
+ module.exports = {
64
+ TOPICS,
65
+ ID_TO_TOPIC,
66
+ TOPIC_PARSERS,
67
+ getTopicById,
68
+ getTopicByPath,
69
+ getParserForTopic,
70
+ getSubscriptionList
71
+ };
@@ -0,0 +1,80 @@
1
+ const { RegionHintParser, GraphqlParser, IrisParser, JsonParser, SkywalkerParser } = require('./parsers');
2
+
3
+ /**
4
+ * Instagram Realtime Topics Configuration
5
+ *
6
+ * Defines all available topics for Instagram's realtime MQTT system
7
+ * using the correct endpoint: edge-mqtt.facebook.com
8
+ */
9
+ const Topics = {
10
+ GRAPHQL: {
11
+ id: '9',
12
+ path: '/graphql',
13
+ parser: new GraphqlParser()
14
+ },
15
+ PUBSUB: {
16
+ id: '88',
17
+ path: '/pubsub',
18
+ parser: new SkywalkerParser()
19
+ },
20
+ SEND_MESSAGE_RESPONSE: {
21
+ id: '133',
22
+ path: '/ig_send_message_response',
23
+ parser: new JsonParser()
24
+ },
25
+ IRIS_SUB: {
26
+ id: '134',
27
+ path: '/ig_sub_iris',
28
+ parser: null
29
+ },
30
+ IRIS_SUB_RESPONSE: {
31
+ id: '135',
32
+ path: '/ig_sub_iris_response',
33
+ parser: new JsonParser()
34
+ },
35
+ MESSAGE_SYNC: {
36
+ id: '146',
37
+ path: '/ig_message_sync',
38
+ parser: new IrisParser(),
39
+ noParse: true
40
+ },
41
+ REALTIME_SUB: {
42
+ id: '149',
43
+ path: '/ig_realtime_sub',
44
+ parser: new GraphqlParser(),
45
+ noParse: true
46
+ },
47
+ REGION_HINT: {
48
+ id: '150',
49
+ path: '/t_region_hint',
50
+ parser: new RegionHintParser()
51
+ },
52
+ FOREGROUND_STATE: {
53
+ id: '102',
54
+ path: '/t_fs',
55
+ parser: null
56
+ },
57
+ SEND_MESSAGE: {
58
+ id: '132',
59
+ path: '/ig_send_message',
60
+ parser: null
61
+ }
62
+ };
63
+
64
+ /**
65
+ * Array of all topics for easy iteration
66
+ */
67
+ const RealtimeTopicsArray = Object.values(Topics);
68
+
69
+ /**
70
+ * Realtime configuration
71
+ */
72
+ const REALTIME = {
73
+ HOST_NAME_V6: 'edge-mqtt.facebook.com' // Main realtime endpoint
74
+ };
75
+
76
+ module.exports = {
77
+ Topics,
78
+ RealtimeTopicsArray,
79
+ REALTIME
80
+ };
@@ -0,0 +1,261 @@
1
+ const Repository = require('../core/repository');
2
+ const crypto = require('crypto');
3
+
4
+ class AccountRepository extends Repository {
5
+ constructor(client) {
6
+ super(client);
7
+ // Default max retries for any request
8
+ this.maxRetries = 3;
9
+ }
10
+
11
+ /**
12
+ * Generic request wrapper with retry and debug logging
13
+ * @param {Function} requestFn - async function performing request
14
+ * @param {number} retries - current retry count
15
+ */
16
+ async requestWithRetry(requestFn, retries = 0) {
17
+ try {
18
+ if (process.env.DEBUG) console.log(`[DEBUG] Attempt #${retries + 1}`);
19
+ const result = await requestFn();
20
+ return result;
21
+ } catch (error) {
22
+ const shouldRetry =
23
+ (error.data?.error_type === 'server_error' ||
24
+ error.data?.error_type === 'rate_limited') &&
25
+ retries < this.maxRetries;
26
+
27
+ if (shouldRetry) {
28
+ const delay = 1000 * (retries + 1);
29
+ if (process.env.DEBUG) console.log(`[DEBUG] Retrying after ${delay}ms due to ${error.data?.error_type}`);
30
+ await new Promise(resolve => setTimeout(resolve, delay));
31
+ return this.requestWithRetry(requestFn, retries + 1);
32
+ }
33
+
34
+ throw error;
35
+ }
36
+ }
37
+
38
+ /**
39
+ * Login with username/password
40
+ * @param {Object|string} credentialsOrUsername - { username, password } or username string
41
+ * @param {string} passwordArg - password (if first arg is username string)
42
+ */
43
+ async login(credentialsOrUsername, passwordArg) {
44
+ let username, password;
45
+
46
+ // Support both object and separate parameters
47
+ if (typeof credentialsOrUsername === 'object' && credentialsOrUsername !== null) {
48
+ username = credentialsOrUsername.username;
49
+ password = credentialsOrUsername.password;
50
+ } else {
51
+ username = credentialsOrUsername;
52
+ password = passwordArg;
53
+ }
54
+
55
+ if (!username || !password) {
56
+ throw new Error('Username and password are required');
57
+ }
58
+
59
+ // Ensure encryption keys are ready
60
+ if (!this.client.state.passwordEncryptionPubKey) {
61
+ await this.syncLoginExperiments();
62
+ }
63
+
64
+ const { encrypted, time } = this.encryptPassword(password);
65
+
66
+ if (process.env.DEBUG) {
67
+ console.log(`[DEBUG] Logging in user: ${username}, encrypted password length: ${encrypted.length}`);
68
+ }
69
+
70
+ return this.requestWithRetry(async () => {
71
+ const response = await this.client.request.send({
72
+ method: 'POST',
73
+ url: '/api/v1/accounts/login/',
74
+ form: this.client.request.sign({
75
+ username,
76
+ enc_password: `#PWD_INSTAGRAM:4:${time}:${encrypted}`,
77
+ guid: this.client.state.uuid,
78
+ phone_id: this.client.state.phoneId,
79
+ _csrftoken: this.client.state.cookieCsrfToken,
80
+ device_id: this.client.state.deviceId,
81
+ adid: this.client.state.adid,
82
+ google_tokens: '[]',
83
+ login_attempt_count: 0,
84
+ country_codes: JSON.stringify([{ country_code: '1', source: 'default' }]),
85
+ jazoest: AccountRepository.createJazoest(this.client.state.phoneId),
86
+ }),
87
+ });
88
+
89
+ // Handle common login errors
90
+ const body = response.body;
91
+ if (body.two_factor_required) {
92
+ const err = new Error('Two factor authentication required');
93
+ err.name = 'IgLoginTwoFactorRequiredError';
94
+ throw err;
95
+ }
96
+ if (body.error_type === 'bad_password') {
97
+ const err = new Error('Bad password');
98
+ err.name = 'IgLoginBadPasswordError';
99
+ throw err;
100
+ }
101
+ if (body.error_type === 'invalid_user') {
102
+ const err = new Error('Invalid user');
103
+ err.name = 'IgLoginInvalidUserError';
104
+ throw err;
105
+ }
106
+
107
+ return body.logged_in_user;
108
+ });
109
+ }
110
+
111
+ /**
112
+ * Logout user
113
+ */
114
+ async logout() {
115
+ return this.requestWithRetry(async () => {
116
+ const response = await this.client.request.send({
117
+ method: 'POST',
118
+ url: '/api/v1/accounts/logout/',
119
+ form: this.client.request.sign({
120
+ _csrftoken: this.client.state.cookieCsrfToken,
121
+ _uuid: this.client.state.uuid,
122
+ }),
123
+ });
124
+ return response.body;
125
+ });
126
+ }
127
+
128
+ /**
129
+ * Get current user
130
+ */
131
+ async currentUser() {
132
+ return this.requestWithRetry(async () => {
133
+ const response = await this.client.request.send({
134
+ method: 'GET',
135
+ url: '/api/v1/accounts/current_user/',
136
+ qs: { edit: true },
137
+ });
138
+ return response.body;
139
+ });
140
+ }
141
+
142
+ /**
143
+ * Sync login experiments (required for encryption keys)
144
+ */
145
+ async syncLoginExperiments() {
146
+ return this.requestWithRetry(async () => {
147
+ const response = await this.client.request.send({
148
+ method: 'POST',
149
+ url: '/api/v1/qe/sync/',
150
+ form: this.client.request.sign({
151
+ _csrftoken: this.client.state.cookieCsrfToken,
152
+ id: this.client.state.uuid,
153
+ server_config_retrieval: '1',
154
+ experiments: this.client.state.constants.LOGIN_EXPERIMENTS,
155
+ }),
156
+ });
157
+ return response.body;
158
+ });
159
+ }
160
+
161
+ /**
162
+ * Create jazoest string from input
163
+ * @param {string} input
164
+ */
165
+ static createJazoest(input) {
166
+ const buf = Buffer.from(input, 'ascii');
167
+ let sum = 0;
168
+ for (let i = 0; i < buf.byteLength; i++) {
169
+ sum += buf.readUInt8(i);
170
+ }
171
+ return `2${sum}`;
172
+ }
173
+
174
+ /**
175
+ * Encrypt password using Instagram's password encryption
176
+ * @param {string} password
177
+ */
178
+ encryptPassword(password) {
179
+ if (!this.client.state.passwordEncryptionPubKey) {
180
+ console.warn('[WARN] Password encryption key missing. Using plaintext password.');
181
+ return { time: Math.floor(Date.now() / 1000).toString(), encrypted: password };
182
+ }
183
+
184
+ const randKey = crypto.randomBytes(32);
185
+ const iv = crypto.randomBytes(12);
186
+
187
+ const rsaEncrypted = crypto.publicEncrypt({
188
+ key: Buffer.from(this.client.state.passwordEncryptionPubKey, 'base64').toString(),
189
+ padding: crypto.constants.RSA_PKCS1_PADDING,
190
+ }, randKey);
191
+
192
+ const cipher = crypto.createCipheriv('aes-256-gcm', randKey, iv);
193
+ const time = Math.floor(Date.now() / 1000).toString();
194
+ cipher.setAAD(Buffer.from(time));
195
+
196
+ const aesEncrypted = Buffer.concat([cipher.update(password, 'utf8'), cipher.final()]);
197
+ const sizeBuffer = Buffer.alloc(2, 0);
198
+ sizeBuffer.writeInt16LE(rsaEncrypted.byteLength, 0);
199
+ const authTag = cipher.getAuthTag();
200
+
201
+ if (process.env.DEBUG) {
202
+ console.log(`[DEBUG] AES length: ${aesEncrypted.length}, RSA length: ${rsaEncrypted.length}`);
203
+ }
204
+
205
+ return {
206
+ time,
207
+ encrypted: Buffer.concat([
208
+ Buffer.from([1, this.client.state.passwordEncryptionKeyId || 0]),
209
+ iv,
210
+ sizeBuffer,
211
+ rsaEncrypted,
212
+ authTag,
213
+ aesEncrypted
214
+ ]).toString('base64')
215
+ };
216
+ }
217
+
218
+ /**
219
+ * Send password recovery request to Instagram via email
220
+ * @param {string} query - Username, email, or phone number
221
+ */
222
+ async sendRecoveryFlowEmail(query) {
223
+ return this.requestWithRetry(async () => {
224
+ const response = await this.client.request.send({
225
+ url: '/api/v1/accounts/send_recovery_flow_email/',
226
+ method: 'POST',
227
+ form: this.client.request.sign({
228
+ _csrftoken: this.client.state.cookieCsrfToken,
229
+ adid: '',
230
+ guid: this.client.state.uuid,
231
+ device_id: this.client.state.deviceId,
232
+ query,
233
+ }),
234
+ });
235
+ return response.body;
236
+ });
237
+ }
238
+
239
+ /**
240
+ * Send password recovery request to Instagram via SMS
241
+ * @param {string} query - Username, email, or phone number
242
+ */
243
+ async sendRecoveryFlowSms(query) {
244
+ return this.requestWithRetry(async () => {
245
+ const response = await this.client.request.send({
246
+ url: '/api/v1/accounts/send_recovery_flow_sms/',
247
+ method: 'POST',
248
+ form: this.client.request.sign({
249
+ _csrftoken: this.client.state.cookieCsrfToken,
250
+ adid: '',
251
+ guid: this.client.state.uuid,
252
+ device_id: this.client.state.deviceId,
253
+ query,
254
+ }),
255
+ });
256
+ return response.body;
257
+ });
258
+ }
259
+ }
260
+
261
+ module.exports = AccountRepository;