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.
- package/README.md +1650 -0
- package/dist/constants/constants.js +280 -0
- package/dist/constants/index.js +41 -0
- package/dist/core/client.js +243 -0
- package/dist/core/repository.js +7 -0
- package/dist/core/request.js +212 -0
- package/dist/core/state.js +1456 -0
- package/dist/core/utils.js +786 -0
- package/dist/downloadMedia.js +381 -0
- package/dist/errors/index.d.ts +16 -0
- package/dist/errors/index.js +30 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/fbns/fbns.client.d.ts +32 -0
- package/dist/fbns/fbns.client.events.d.ts +41 -0
- package/dist/fbns/fbns.client.events.js +3 -0
- package/dist/fbns/fbns.client.events.js.map +1 -0
- package/dist/fbns/fbns.client.js +179 -0
- package/dist/fbns/fbns.client.js.map +1 -0
- package/dist/fbns/fbns.device-auth.d.ts +17 -0
- package/dist/fbns/fbns.device-auth.js +54 -0
- package/dist/fbns/fbns.device-auth.js.map +1 -0
- package/dist/fbns/fbns.types.d.ts +83 -0
- package/dist/fbns/fbns.types.js +3 -0
- package/dist/fbns/fbns.types.js.map +1 -0
- package/dist/fbns/fbns.utilities.d.ts +2 -0
- package/dist/fbns/fbns.utilities.js +79 -0
- package/dist/fbns/fbns.utilities.js.map +1 -0
- package/dist/fbns/index.d.ts +4 -0
- package/dist/fbns/index.js +21 -0
- package/dist/fbns/index.js.map +1 -0
- package/dist/index.js +39 -0
- package/dist/mqttot/index.d.ts +4 -0
- package/dist/mqttot/index.js +21 -0
- package/dist/mqttot/index.js.map +1 -0
- package/dist/mqttot/mqttot.client.d.ts +39 -0
- package/dist/mqttot/mqttot.client.js +120 -0
- package/dist/mqttot/mqttot.client.js.map +1 -0
- package/dist/mqttot/mqttot.connect.request.packet.d.ts +7 -0
- package/dist/mqttot/mqttot.connect.request.packet.js +9 -0
- package/dist/mqttot/mqttot.connect.request.packet.js.map +1 -0
- package/dist/mqttot/mqttot.connect.response.packet.d.ts +7 -0
- package/dist/mqttot/mqttot.connect.response.packet.js +24 -0
- package/dist/mqttot/mqttot.connect.response.packet.js.map +1 -0
- package/dist/mqttot/mqttot.connection.d.ts +57 -0
- package/dist/mqttot/mqttot.connection.js +56 -0
- package/dist/mqttot/mqttot.connection.js.map +1 -0
- package/dist/package.json +59 -0
- package/dist/realtime/commands/commands.d.ts +15 -0
- package/dist/realtime/commands/commands.js +21 -0
- package/dist/realtime/commands/commands.js.map +1 -0
- package/dist/realtime/commands/direct.commands.d.ts +75 -0
- package/dist/realtime/commands/direct.commands.js +186 -0
- package/dist/realtime/commands/direct.commands.js.map +1 -0
- package/dist/realtime/commands/enhanced.direct.commands.js +987 -0
- package/dist/realtime/commands/index.d.ts +2 -0
- package/dist/realtime/commands/index.js +19 -0
- package/dist/realtime/commands/index.js.map +1 -0
- package/dist/realtime/delta-sync.manager.js +293 -0
- package/dist/realtime/features/dm-sender.js +88 -0
- package/dist/realtime/features/error-handler.js +73 -0
- package/dist/realtime/features/gap-handler.js +61 -0
- package/dist/realtime/features/presence.manager.js +66 -0
- package/dist/realtime/index.js +30 -0
- package/dist/realtime/messages/app-presence.event.d.ts +9 -0
- package/dist/realtime/messages/app-presence.event.js +3 -0
- package/dist/realtime/messages/app-presence.event.js.map +1 -0
- package/dist/realtime/messages/index.d.ts +3 -0
- package/dist/realtime/messages/index.js +20 -0
- package/dist/realtime/messages/index.js.map +1 -0
- package/dist/realtime/messages/message-sync.message.d.ts +222 -0
- package/dist/realtime/messages/message-sync.message.js +43 -0
- package/dist/realtime/messages/message-sync.message.js.map +1 -0
- package/dist/realtime/messages/realtime-sub.direct.data.d.ts +11 -0
- package/dist/realtime/messages/realtime-sub.direct.data.js +3 -0
- package/dist/realtime/messages/realtime-sub.direct.data.js.map +1 -0
- package/dist/realtime/messages/thread-update.message.d.ts +68 -0
- package/dist/realtime/messages/thread-update.message.js +3 -0
- package/dist/realtime/messages/thread-update.message.js.map +1 -0
- package/dist/realtime/mixins/index.d.ts +3 -0
- package/dist/realtime/mixins/index.js +20 -0
- package/dist/realtime/mixins/index.js.map +1 -0
- package/dist/realtime/mixins/message-sync.mixin.d.ts +8 -0
- package/dist/realtime/mixins/message-sync.mixin.js +381 -0
- package/dist/realtime/mixins/message-sync.mixin.js.map +1 -0
- package/dist/realtime/mixins/mixin.d.ts +19 -0
- package/dist/realtime/mixins/mixin.js +41 -0
- package/dist/realtime/mixins/mixin.js.map +1 -0
- package/dist/realtime/mixins/presence-typing.mixin.js +33 -0
- package/dist/realtime/mixins/realtime-sub.mixin.d.ts +8 -0
- package/dist/realtime/mixins/realtime-sub.mixin.js +55 -0
- package/dist/realtime/mixins/realtime-sub.mixin.js.map +1 -0
- package/dist/realtime/parsers/graphql-parser.js +43 -0
- package/dist/realtime/parsers/graphql.parser.d.ts +15 -0
- package/dist/realtime/parsers/graphql.parser.js +22 -0
- package/dist/realtime/parsers/graphql.parser.js.map +1 -0
- package/dist/realtime/parsers/index.d.ts +6 -0
- package/dist/realtime/parsers/index.js +23 -0
- package/dist/realtime/parsers/index.js.map +1 -0
- package/dist/realtime/parsers/iris-parser.js +43 -0
- package/dist/realtime/parsers/iris.parser.d.ts +17 -0
- package/dist/realtime/parsers/iris.parser.js +10 -0
- package/dist/realtime/parsers/iris.parser.js.map +1 -0
- package/dist/realtime/parsers/json-parser.js +43 -0
- package/dist/realtime/parsers/json.parser.d.ts +6 -0
- package/dist/realtime/parsers/json.parser.js +10 -0
- package/dist/realtime/parsers/json.parser.js.map +1 -0
- package/dist/realtime/parsers/parser.d.ts +9 -0
- package/dist/realtime/parsers/parser.js +3 -0
- package/dist/realtime/parsers/parser.js.map +1 -0
- package/dist/realtime/parsers/region-hint-parser.js +43 -0
- package/dist/realtime/parsers/region-hint.parser.d.ts +12 -0
- package/dist/realtime/parsers/region-hint.parser.js +15 -0
- package/dist/realtime/parsers/region-hint.parser.js.map +1 -0
- package/dist/realtime/parsers/skywalker-parser.js +43 -0
- package/dist/realtime/parsers/skywalker.parser.d.ts +12 -0
- package/dist/realtime/parsers/skywalker.parser.js +15 -0
- package/dist/realtime/parsers/skywalker.parser.js.map +1 -0
- package/dist/realtime/parsers-advanced.js +158 -0
- package/dist/realtime/proto/common.proto +38 -0
- package/dist/realtime/proto/direct.proto +65 -0
- package/dist/realtime/proto/ig-messages.proto +83 -0
- package/dist/realtime/proto/iris.proto +188 -0
- package/dist/realtime/proto-parser.js +195 -0
- package/dist/realtime/protocols/iris.handshake.js +74 -0
- package/dist/realtime/protocols/proto-definitions.js +80 -0
- package/dist/realtime/protocols/skywalker.protocol.js +91 -0
- package/dist/realtime/realtime.client.events.js +3 -0
- package/dist/realtime/realtime.client.js +449 -0
- package/dist/realtime/realtime.service.js +462 -0
- package/dist/realtime/reconnect.manager.js +94 -0
- package/dist/realtime/session.manager.js +121 -0
- package/dist/realtime/subscriptions/graphql.subscription.d.ts +47 -0
- package/dist/realtime/subscriptions/graphql.subscription.js +99 -0
- package/dist/realtime/subscriptions/graphql.subscription.js.map +1 -0
- package/dist/realtime/subscriptions/index.d.ts +2 -0
- package/dist/realtime/subscriptions/index.js +19 -0
- package/dist/realtime/subscriptions/index.js.map +1 -0
- package/dist/realtime/subscriptions/skywalker.subscription.d.ts +4 -0
- package/dist/realtime/subscriptions/skywalker.subscription.js +13 -0
- package/dist/realtime/subscriptions/skywalker.subscription.js.map +1 -0
- package/dist/realtime/topic-map.js +71 -0
- package/dist/realtime/topic.js +80 -0
- package/dist/repositories/account.repository.js +261 -0
- package/dist/repositories/direct-thread.repository.js +247 -0
- package/dist/repositories/direct.repository.js +153 -0
- package/dist/repositories/feed.repository.js +233 -0
- package/dist/repositories/friendship.repository.js +190 -0
- package/dist/repositories/hashtag.repository.js +101 -0
- package/dist/repositories/highlights.repository.js +127 -0
- package/dist/repositories/location.repository.js +84 -0
- package/dist/repositories/media.repository.js +165 -0
- package/dist/repositories/story.repository.js +156 -0
- package/dist/repositories/upload.repository.js +167 -0
- package/dist/repositories/user.repository.js +94 -0
- package/dist/sendmedia/index.js +11 -0
- package/dist/sendmedia/sendFile.js +154 -0
- package/dist/sendmedia/sendPhoto.js +145 -0
- package/dist/sendmedia/uploadPhoto.js +175 -0
- package/dist/sendmedia/uploadfFile.js +264 -0
- package/dist/services/live.service.js +147 -0
- package/dist/services/search.service.js +116 -0
- package/dist/shared/index.js +35 -0
- package/dist/shared/shared.js +86 -0
- package/dist/thrift/index.d.ts +3 -0
- package/dist/thrift/index.js +20 -0
- package/dist/thrift/index.js.map +1 -0
- package/dist/thrift/thrift.d.ts +59 -0
- package/dist/thrift/thrift.js +101 -0
- package/dist/thrift/thrift.js.map +1 -0
- package/dist/thrift/thrift.reading.d.ts +41 -0
- package/dist/thrift/thrift.reading.js +327 -0
- package/dist/thrift/thrift.reading.js.map +1 -0
- package/dist/thrift/thrift.writing.d.ts +44 -0
- package/dist/thrift/thrift.writing.js +342 -0
- package/dist/thrift/thrift.writing.js.map +1 -0
- package/dist/types/index.js +285 -0
- package/dist/useMultiFileAuthState.js +437 -0
- package/dist/utils/helper-1.js +1 -0
- package/dist/utils/helper-10.js +1 -0
- package/dist/utils/helper-11.js +1 -0
- package/dist/utils/helper-12.js +1 -0
- package/dist/utils/helper-13.js +1 -0
- package/dist/utils/helper-14.js +1 -0
- package/dist/utils/helper-15.js +1 -0
- package/dist/utils/helper-16.js +1 -0
- package/dist/utils/helper-17.js +1 -0
- package/dist/utils/helper-18.js +1 -0
- package/dist/utils/helper-19.js +1 -0
- package/dist/utils/helper-2.js +1 -0
- package/dist/utils/helper-20.js +1 -0
- package/dist/utils/helper-21.js +1 -0
- package/dist/utils/helper-22.js +1 -0
- package/dist/utils/helper-23.js +1 -0
- package/dist/utils/helper-24.js +1 -0
- package/dist/utils/helper-25.js +1 -0
- package/dist/utils/helper-26.js +1 -0
- package/dist/utils/helper-27.js +1 -0
- package/dist/utils/helper-28.js +1 -0
- package/dist/utils/helper-29.js +1 -0
- package/dist/utils/helper-3.js +1 -0
- package/dist/utils/helper-30.js +1 -0
- package/dist/utils/helper-4.js +1 -0
- package/dist/utils/helper-5.js +1 -0
- package/dist/utils/helper-6.js +1 -0
- package/dist/utils/helper-7.js +1 -0
- package/dist/utils/helper-8.js +1 -0
- package/dist/utils/helper-9.js +1 -0
- package/dist/utils/index.js +280 -0
- package/examples/listen-to-messages.js +86 -0
- package/package.json +79 -0
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const { CookieJar } = require('tough-cookie');
|
|
6
|
+
const util = require('util');
|
|
7
|
+
const EventEmitter = require('events');
|
|
8
|
+
|
|
9
|
+
const FILE_NAMES = {
|
|
10
|
+
creds: 'creds.json',
|
|
11
|
+
device: 'device.json',
|
|
12
|
+
cookies: 'cookies.json',
|
|
13
|
+
mqttSession: 'mqtt-session.json',
|
|
14
|
+
subscriptions: 'subscriptions.json',
|
|
15
|
+
seqIds: 'seq-ids.json',
|
|
16
|
+
appState: 'app-state.json'
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
class MultiFileAuthState extends EventEmitter {
|
|
20
|
+
constructor(folder) {
|
|
21
|
+
super();
|
|
22
|
+
this.folder = folder;
|
|
23
|
+
this._saveDebounceTimer = null;
|
|
24
|
+
this._saveDebounceMs = 500;
|
|
25
|
+
this._dirty = new Set();
|
|
26
|
+
|
|
27
|
+
this.data = {
|
|
28
|
+
creds: null,
|
|
29
|
+
device: null,
|
|
30
|
+
cookies: null,
|
|
31
|
+
mqttSession: null,
|
|
32
|
+
subscriptions: null,
|
|
33
|
+
seqIds: null,
|
|
34
|
+
appState: null
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
_getFilePath(key) {
|
|
39
|
+
return path.join(this.folder, FILE_NAMES[key]);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
_ensureFolder() {
|
|
43
|
+
if (!fs.existsSync(this.folder)) {
|
|
44
|
+
fs.mkdirSync(this.folder, { recursive: true, mode: 0o700 });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async _writeFileAtomic(filePath, data) {
|
|
49
|
+
const tempPath = filePath + '.tmp';
|
|
50
|
+
const jsonData = JSON.stringify(data, null, 2);
|
|
51
|
+
await fs.promises.writeFile(tempPath, jsonData, { mode: 0o600 });
|
|
52
|
+
await fs.promises.rename(tempPath, filePath);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async _readFile(key) {
|
|
56
|
+
const filePath = this._getFilePath(key);
|
|
57
|
+
try {
|
|
58
|
+
if (fs.existsSync(filePath)) {
|
|
59
|
+
const raw = await fs.promises.readFile(filePath, 'utf8');
|
|
60
|
+
return JSON.parse(raw);
|
|
61
|
+
}
|
|
62
|
+
} catch (e) {
|
|
63
|
+
console.warn(`[MultiFileAuthState] Error reading ${key}:`, e.message);
|
|
64
|
+
}
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async _writeFile(key, data) {
|
|
69
|
+
this._ensureFolder();
|
|
70
|
+
const filePath = this._getFilePath(key);
|
|
71
|
+
try {
|
|
72
|
+
await this._writeFileAtomic(filePath, data);
|
|
73
|
+
return true;
|
|
74
|
+
} catch (e) {
|
|
75
|
+
console.error(`[MultiFileAuthState] Error writing ${key}:`, e.message);
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async loadAll() {
|
|
81
|
+
this._ensureFolder();
|
|
82
|
+
|
|
83
|
+
const loadPromises = Object.keys(FILE_NAMES).map(async (key) => {
|
|
84
|
+
this.data[key] = await this._readFile(key);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
await Promise.all(loadPromises);
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
creds: this.data.creds,
|
|
91
|
+
device: this.data.device,
|
|
92
|
+
cookies: this.data.cookies,
|
|
93
|
+
mqttSession: this.data.mqttSession,
|
|
94
|
+
subscriptions: this.data.subscriptions,
|
|
95
|
+
seqIds: this.data.seqIds,
|
|
96
|
+
appState: this.data.appState,
|
|
97
|
+
hasSession: !!(this.data.creds && this.data.cookies)
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async saveAll() {
|
|
102
|
+
const savePromises = Object.keys(FILE_NAMES).map(async (key) => {
|
|
103
|
+
if (this.data[key] !== null && this.data[key] !== undefined) {
|
|
104
|
+
await this._writeFile(key, this.data[key]);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
await Promise.all(savePromises);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async saveCreds() {
|
|
111
|
+
const promises = [];
|
|
112
|
+
if (this.data.creds) promises.push(this._writeFile('creds', this.data.creds));
|
|
113
|
+
if (this.data.device) promises.push(this._writeFile('device', this.data.device));
|
|
114
|
+
if (this.data.cookies) promises.push(this._writeFile('cookies', this.data.cookies));
|
|
115
|
+
await Promise.all(promises);
|
|
116
|
+
this.emit('creds-saved');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async saveMqttState() {
|
|
120
|
+
const promises = [];
|
|
121
|
+
if (this.data.mqttSession) promises.push(this._writeFile('mqttSession', this.data.mqttSession));
|
|
122
|
+
if (this.data.subscriptions) promises.push(this._writeFile('subscriptions', this.data.subscriptions));
|
|
123
|
+
if (this.data.seqIds) promises.push(this._writeFile('seqIds', this.data.seqIds));
|
|
124
|
+
await Promise.all(promises);
|
|
125
|
+
this.emit('mqtt-state-saved');
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async saveAppState() {
|
|
129
|
+
if (this.data.appState) {
|
|
130
|
+
await this._writeFile('appState', this.data.appState);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
_debouncedSave(keys) {
|
|
135
|
+
keys.forEach(k => this._dirty.add(k));
|
|
136
|
+
|
|
137
|
+
if (this._saveDebounceTimer) {
|
|
138
|
+
clearTimeout(this._saveDebounceTimer);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
this._saveDebounceTimer = setTimeout(async () => {
|
|
142
|
+
const toSave = Array.from(this._dirty);
|
|
143
|
+
this._dirty.clear();
|
|
144
|
+
|
|
145
|
+
for (const key of toSave) {
|
|
146
|
+
if (this.data[key] !== null && this.data[key] !== undefined) {
|
|
147
|
+
await this._writeFile(key, this.data[key]);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}, this._saveDebounceMs);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
setCreds(creds) {
|
|
154
|
+
this.data.creds = creds;
|
|
155
|
+
this._debouncedSave(['creds']);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
setDevice(device) {
|
|
159
|
+
this.data.device = device;
|
|
160
|
+
this._debouncedSave(['device']);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
setCookies(cookies) {
|
|
164
|
+
this.data.cookies = cookies;
|
|
165
|
+
this._debouncedSave(['cookies']);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
setMqttSession(session) {
|
|
169
|
+
this.data.mqttSession = session;
|
|
170
|
+
this._debouncedSave(['mqttSession']);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
setSubscriptions(subs) {
|
|
174
|
+
this.data.subscriptions = subs;
|
|
175
|
+
this._debouncedSave(['subscriptions']);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
setSeqIds(seqIds) {
|
|
179
|
+
this.data.seqIds = seqIds;
|
|
180
|
+
this._debouncedSave(['seqIds']);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
setAppState(state) {
|
|
184
|
+
this.data.appState = state;
|
|
185
|
+
this._debouncedSave(['appState']);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
getCreds() { return this.data.creds; }
|
|
189
|
+
getDevice() { return this.data.device; }
|
|
190
|
+
getCookies() { return this.data.cookies; }
|
|
191
|
+
getMqttSession() { return this.data.mqttSession; }
|
|
192
|
+
getSubscriptions() { return this.data.subscriptions; }
|
|
193
|
+
getSeqIds() { return this.data.seqIds; }
|
|
194
|
+
getAppState() { return this.data.appState; }
|
|
195
|
+
|
|
196
|
+
hasValidSession() {
|
|
197
|
+
return !!(this.data.creds && this.data.cookies && this.data.creds.authorization);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
hasMqttSession() {
|
|
201
|
+
return !!(this.data.mqttSession && this.data.mqttSession.sessionId);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
async clearAll() {
|
|
205
|
+
for (const key of Object.keys(FILE_NAMES)) {
|
|
206
|
+
const filePath = this._getFilePath(key);
|
|
207
|
+
try {
|
|
208
|
+
if (fs.existsSync(filePath)) {
|
|
209
|
+
await fs.promises.unlink(filePath);
|
|
210
|
+
}
|
|
211
|
+
} catch (e) {}
|
|
212
|
+
this.data[key] = null;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
async function extractStateData(igState) {
|
|
218
|
+
const creds = {
|
|
219
|
+
authorization: igState.authorization || null,
|
|
220
|
+
igWWWClaim: igState.igWWWClaim || null,
|
|
221
|
+
passwordEncryptionKeyId: igState.passwordEncryptionKeyId || null,
|
|
222
|
+
passwordEncryptionPubKey: igState.passwordEncryptionPubKey || null
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
const device = {
|
|
226
|
+
deviceString: igState.deviceString || null,
|
|
227
|
+
deviceId: igState.deviceId || null,
|
|
228
|
+
uuid: igState.uuid || null,
|
|
229
|
+
phoneId: igState.phoneId || null,
|
|
230
|
+
adid: igState.adid || null,
|
|
231
|
+
build: igState.build || null
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
let cookies = null;
|
|
235
|
+
try {
|
|
236
|
+
if (igState.cookieJar && typeof igState.serializeCookieJar === 'function') {
|
|
237
|
+
cookies = await igState.serializeCookieJar();
|
|
238
|
+
}
|
|
239
|
+
} catch (e) {
|
|
240
|
+
console.warn('[MultiFileAuthState] Could not serialize cookies:', e.message);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const appState = {
|
|
244
|
+
language: igState.language || 'en_US',
|
|
245
|
+
timezoneOffset: igState.timezoneOffset || null,
|
|
246
|
+
connectionTypeHeader: igState.connectionTypeHeader || 'WIFI',
|
|
247
|
+
capabilitiesHeader: igState.capabilitiesHeader || null,
|
|
248
|
+
checkpoint: igState.checkpoint || null,
|
|
249
|
+
challenge: igState.challenge || null
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
return { creds, device, cookies, appState };
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
async function applyStateData(igState, authState) {
|
|
256
|
+
const { creds, device, cookies, appState } = authState.data;
|
|
257
|
+
|
|
258
|
+
if (creds) {
|
|
259
|
+
if (creds.authorization) igState.authorization = creds.authorization;
|
|
260
|
+
if (creds.igWWWClaim) igState.igWWWClaim = creds.igWWWClaim;
|
|
261
|
+
if (creds.passwordEncryptionKeyId) igState.passwordEncryptionKeyId = creds.passwordEncryptionKeyId;
|
|
262
|
+
if (creds.passwordEncryptionPubKey) igState.passwordEncryptionPubKey = creds.passwordEncryptionPubKey;
|
|
263
|
+
igState.updateAuthorization();
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (device) {
|
|
267
|
+
if (device.deviceString) igState.deviceString = device.deviceString;
|
|
268
|
+
if (device.deviceId) igState.deviceId = device.deviceId;
|
|
269
|
+
if (device.uuid) igState.uuid = device.uuid;
|
|
270
|
+
if (device.phoneId) igState.phoneId = device.phoneId;
|
|
271
|
+
if (device.adid) igState.adid = device.adid;
|
|
272
|
+
if (device.build) igState.build = device.build;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (cookies) {
|
|
276
|
+
try {
|
|
277
|
+
await igState.deserializeCookieJar(cookies);
|
|
278
|
+
} catch (e) {
|
|
279
|
+
console.warn('[MultiFileAuthState] Could not deserialize cookies:', e.message);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
if (appState) {
|
|
284
|
+
if (appState.language) igState.language = appState.language;
|
|
285
|
+
if (appState.timezoneOffset) igState.timezoneOffset = appState.timezoneOffset;
|
|
286
|
+
if (appState.connectionTypeHeader) igState.connectionTypeHeader = appState.connectionTypeHeader;
|
|
287
|
+
if (appState.capabilitiesHeader) igState.capabilitiesHeader = appState.capabilitiesHeader;
|
|
288
|
+
if (appState.checkpoint) igState.checkpoint = appState.checkpoint;
|
|
289
|
+
if (appState.challenge) igState.challenge = appState.challenge;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
async function useMultiFileAuthState(folder) {
|
|
294
|
+
const authState = new MultiFileAuthState(folder);
|
|
295
|
+
await authState.loadAll();
|
|
296
|
+
|
|
297
|
+
const saveCreds = async (igClient) => {
|
|
298
|
+
if (!igClient || !igClient.state) {
|
|
299
|
+
console.warn('[useMultiFileAuthState] No igClient provided to saveCreds');
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const { creds, device, cookies, appState } = await extractStateData(igClient.state);
|
|
304
|
+
|
|
305
|
+
authState.data.creds = creds;
|
|
306
|
+
authState.data.device = device;
|
|
307
|
+
authState.data.cookies = cookies;
|
|
308
|
+
authState.data.appState = appState;
|
|
309
|
+
|
|
310
|
+
await authState.saveCreds();
|
|
311
|
+
await authState.saveAppState();
|
|
312
|
+
|
|
313
|
+
console.log('[useMultiFileAuthState] Credentials saved to', folder);
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
const saveMqttSession = async (realtimeClient) => {
|
|
317
|
+
if (!realtimeClient) {
|
|
318
|
+
console.warn('[useMultiFileAuthState] No realtimeClient provided');
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
const mqttSession = {
|
|
323
|
+
sessionId: null,
|
|
324
|
+
mqttSessionId: null,
|
|
325
|
+
lastConnected: new Date().toISOString(),
|
|
326
|
+
userId: null
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
try {
|
|
330
|
+
if (realtimeClient.ig && realtimeClient.ig.state) {
|
|
331
|
+
mqttSession.userId = realtimeClient.ig.state.cookieUserId;
|
|
332
|
+
mqttSession.sessionId = realtimeClient.extractSessionIdFromJWT?.() || null;
|
|
333
|
+
}
|
|
334
|
+
if (realtimeClient.connection) {
|
|
335
|
+
mqttSession.mqttSessionId = realtimeClient.connection?.clientInfo?.clientMqttSessionId?.toString() || null;
|
|
336
|
+
}
|
|
337
|
+
} catch (e) {}
|
|
338
|
+
|
|
339
|
+
const subscriptions = {
|
|
340
|
+
graphQlSubs: realtimeClient.initOptions?.graphQlSubs || [],
|
|
341
|
+
skywalkerSubs: realtimeClient.initOptions?.skywalkerSubs || [],
|
|
342
|
+
subscribedAt: new Date().toISOString()
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
const seqIds = {};
|
|
346
|
+
if (realtimeClient.initOptions?.irisData) {
|
|
347
|
+
seqIds.seq_id = realtimeClient.initOptions.irisData.seq_id || null;
|
|
348
|
+
seqIds.snapshot_at_ms = realtimeClient.initOptions.irisData.snapshot_at_ms || null;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
authState.data.mqttSession = mqttSession;
|
|
352
|
+
authState.data.subscriptions = subscriptions;
|
|
353
|
+
authState.data.seqIds = seqIds;
|
|
354
|
+
|
|
355
|
+
await authState.saveMqttState();
|
|
356
|
+
console.log('[useMultiFileAuthState] MQTT session saved to', folder);
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
const loadCreds = async (igClient) => {
|
|
360
|
+
if (!igClient || !igClient.state) {
|
|
361
|
+
console.warn('[useMultiFileAuthState] No igClient provided to loadCreds');
|
|
362
|
+
return false;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
if (!authState.hasValidSession()) {
|
|
366
|
+
console.log('[useMultiFileAuthState] No valid session found');
|
|
367
|
+
return false;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
await applyStateData(igClient.state, authState);
|
|
371
|
+
console.log('[useMultiFileAuthState] Credentials loaded from', folder);
|
|
372
|
+
return true;
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
const getMqttConnectOptions = () => {
|
|
376
|
+
if (!authState.hasMqttSession()) {
|
|
377
|
+
return null;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
const subs = authState.getSubscriptions() || {};
|
|
381
|
+
const seqIds = authState.getSeqIds() || {};
|
|
382
|
+
|
|
383
|
+
return {
|
|
384
|
+
graphQlSubs: subs.graphQlSubs || ['ig_sub_direct', 'ig_sub_direct_v2_message_sync'],
|
|
385
|
+
skywalkerSubs: subs.skywalkerSubs || ['presence_subscribe', 'typing_subscribe'],
|
|
386
|
+
irisData: seqIds.seq_id ? {
|
|
387
|
+
seq_id: seqIds.seq_id,
|
|
388
|
+
snapshot_at_ms: seqIds.snapshot_at_ms
|
|
389
|
+
} : null
|
|
390
|
+
};
|
|
391
|
+
};
|
|
392
|
+
|
|
393
|
+
const clearSession = async () => {
|
|
394
|
+
await authState.clearAll();
|
|
395
|
+
console.log('[useMultiFileAuthState] Session cleared');
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
const isSessionValid = async (igClient) => {
|
|
399
|
+
if (!authState.hasValidSession()) return false;
|
|
400
|
+
if (!igClient) return true;
|
|
401
|
+
|
|
402
|
+
try {
|
|
403
|
+
await igClient.account.currentUser();
|
|
404
|
+
return true;
|
|
405
|
+
} catch (e) {
|
|
406
|
+
console.warn('[useMultiFileAuthState] Session validation failed:', e.message);
|
|
407
|
+
return false;
|
|
408
|
+
}
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
return {
|
|
412
|
+
state: authState,
|
|
413
|
+
|
|
414
|
+
saveCreds,
|
|
415
|
+
loadCreds,
|
|
416
|
+
|
|
417
|
+
saveMqttSession,
|
|
418
|
+
getMqttConnectOptions,
|
|
419
|
+
|
|
420
|
+
clearSession,
|
|
421
|
+
isSessionValid,
|
|
422
|
+
|
|
423
|
+
hasSession: () => authState.hasValidSession(),
|
|
424
|
+
hasMqttSession: () => authState.hasMqttSession(),
|
|
425
|
+
|
|
426
|
+
folder,
|
|
427
|
+
|
|
428
|
+
getData: () => authState.data
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
module.exports = {
|
|
433
|
+
useMultiFileAuthState,
|
|
434
|
+
MultiFileAuthState,
|
|
435
|
+
extractStateData,
|
|
436
|
+
applyStateData
|
|
437
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// Helper utility file 1
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// Helper utility file 10
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// Helper utility file 11
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// Helper utility file 12
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// Helper utility file 13
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// Helper utility file 14
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// Helper utility file 15
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// Helper utility file 16
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// Helper utility file 17
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// Helper utility file 18
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// Helper utility file 19
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// Helper utility file 2
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// Helper utility file 20
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// Helper utility file 21
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// Helper utility file 22
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// Helper utility file 23
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// Helper utility file 24
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// Helper utility file 25
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// Helper utility file 26
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// Helper utility file 27
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// Helper utility file 28
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// Helper utility file 29
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// Helper utility file 3
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// Helper utility file 30
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// Helper utility file 4
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// Helper utility file 5
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// Helper utility file 6
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// Helper utility file 7
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// Helper utility file 8
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// Helper utility file 9
|