gologin 1.0.53 → 1.0.55

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.
@@ -177,41 +177,6 @@ class ExtensionsManager extends UserExtensionsManager {
177
177
  this.#useCookiesExt = useCookiesExt;
178
178
  }
179
179
 
180
- async getExtensionsStrToIncludeAsOrbitaParam(profileExtensions = []) {
181
- if (!(Array.isArray(profileExtensions) && profileExtensions.length)) {
182
- return [];
183
- }
184
-
185
- const folders = await Promise.all([
186
- readdir(CHROME_EXTENSIONS_PATH).then(folderNames => folderNames.map(folderName => path.join(CHROME_EXTENSIONS_PATH, folderName))),
187
- readdir(USER_EXTENSIONS_PATH).then(folderNames => folderNames.map(folderName => path.join(USER_EXTENSIONS_PATH, folderName))),
188
- ]);
189
-
190
- const chromeExtList = [].concat.apply([], folders).filter(Boolean);
191
-
192
- if (!chromeExtList.length) {
193
- return [];
194
- }
195
-
196
- const formattedIdsList = chromeExtList.map((el) => {
197
- const [folderName] = el.split(path.sep).reverse();
198
- const [originalId] = folderName.split('@');
199
- return {
200
- originalId,
201
- path: el,
202
- };
203
- });
204
-
205
- return profileExtensions.map((el) => {
206
- const extExisted = formattedIdsList.find(chromeExtPathElem => chromeExtPathElem.originalId === el);
207
- if (!extExisted) {
208
- return '';
209
- }
210
-
211
- return extExisted.path;
212
- }).filter(Boolean);
213
- }
214
-
215
180
  async updateExtensions() {
216
181
  const fileList = await readdir(CHROME_EXTENSIONS_PATH).catch(() => []);
217
182
  if (!fileList.length) {
package/gologin.js CHANGED
@@ -426,15 +426,19 @@ class GoLogin {
426
426
  console.log('checkChromeExtensions error: ', e);
427
427
  return { profileExtensionsCheckRes: [] };
428
428
  }),
429
- ExtensionsManagerInst.checkLocalUserChromeExtensions().catch((error) => {
430
- console.log('checkUserChromeExtensions error: ', error);
431
- return null;
432
- }),
429
+ ExtensionsManagerInst.checkLocalUserChromeExtensions(userChromeExtensions)
430
+ .then(res => ({ profileUserExtensionsCheckRes: res }))
431
+ .catch((error) => {
432
+ console.log('checkUserChromeExtensions error: ', error);
433
+ return null;
434
+ }),
433
435
  ];
434
436
  const extensionsResult = await Promise.all(promises);
435
437
 
436
- const profileExtensionsPathRes = extensionsResult.find(el => 'profileExtensionsCheckRes' in el) || {};
437
- profileExtensionsCheckRes = profileExtensionsPathRes.profileExtensionsCheckRes;
438
+ const profileExtensionPathRes = extensionsResult.find(el => 'profileExtensionsCheckRes' in el) || {};
439
+ const profileUserExtensionPathRes = extensionsResult.find(el => 'profileUserExtensionsCheckRes' in el);
440
+ profileExtensionsCheckRes =
441
+ (profileExtensionPathRes?.profileExtensionsCheckRes || []).concat(profileUserExtensionPathRes?.profileUserExtensionsCheckRes || []);
438
442
  }
439
443
 
440
444
  let extSettings;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gologin",
3
- "version": "1.0.53",
3
+ "version": "1.0.55",
4
4
  "description": "A high-level API to control Orbita browser over GoLogin API",
5
5
  "main": "./gologin.js",
6
6
  "repository": {
@@ -194,7 +194,11 @@ class UserExtensionsManager {
194
194
  }
195
195
  }
196
196
 
197
- checkLocalUserChromeExtensions = async () => {
197
+ checkLocalUserChromeExtensions = async (userChromeExtensions) => {
198
+ if (!userChromeExtensions.length) {
199
+ return;
200
+ }
201
+
198
202
  const extensionsToDownloadPaths = await request.post(`${this.#API_BASE_URL}/extensions/user_chrome_extensions_paths`, {
199
203
  json: true,
200
204
  fullResponse: false,
@@ -208,11 +212,14 @@ class UserExtensionsManager {
208
212
  }
209
213
  }) || [];
210
214
 
211
- if (!extensionsToDownloadPaths.length) {
212
- return;
215
+ const extensionsToDownloadPathsFiltered =
216
+ extensionsToDownloadPaths.filter(extPath => userChromeExtensions.some(extId => extPath.includes(extId)));
217
+
218
+ if (!extensionsToDownloadPathsFiltered.length) {
219
+ return this.getExtensionsStrToIncludeAsOrbitaParam(userChromeExtensions, USER_EXTENSIONS_PATH);
213
220
  }
214
221
 
215
- const promises = extensionsToDownloadPaths.map(async awsPath => {
222
+ const promises = extensionsToDownloadPathsFiltered.map(async awsPath => {
216
223
  const [basePath] = awsPath.split('?');
217
224
  const [extId] = basePath.split('/').reverse();
218
225
  const zipPath = `${path.join(USER_EXTENSIONS_PATH, extId)}.zip`;
@@ -230,7 +237,7 @@ class UserExtensionsManager {
230
237
  const zipPaths = await Promise.all(promises).catch(() => []);
231
238
 
232
239
  if (!zipPaths) {
233
- return;
240
+ return this.getExtensionsStrToIncludeAsOrbitaParam(userChromeExtensions, USER_EXTENSIONS_PATH);
234
241
  }
235
242
 
236
243
  const extractionPromises = composeExtractionPromises(zipPaths, USER_EXTENSIONS_PATH);
@@ -240,6 +247,39 @@ class UserExtensionsManager {
240
247
  const [downloadedFolders] = zipPaths.map(archivePath => archivePath.split(path.sep).reverse());
241
248
  this.#existedUserExtensions = [...this.#existedUserExtensions, ...downloadedFolders];
242
249
  }
250
+
251
+ return this.getExtensionsStrToIncludeAsOrbitaParam(userChromeExtensions, USER_EXTENSIONS_PATH);
252
+ }
253
+
254
+ async getExtensionsStrToIncludeAsOrbitaParam(profileExtensions = [], folderPath = CHROME_EXTENSIONS_PATH) {
255
+ if (!(Array.isArray(profileExtensions) && profileExtensions.length)) {
256
+ return [];
257
+ }
258
+
259
+ const folders = await readdir(folderPath).then(folderNames => folderNames.map(folderName => path.join(folderPath, folderName)));
260
+
261
+ if (!folders.length) {
262
+ return [];
263
+ }
264
+
265
+ const formattedIdsList = folders.map((el) => {
266
+ const [folderName] = el.split(path.sep).reverse();
267
+ const [originalId] = folderName.split('@');
268
+ return {
269
+ originalId,
270
+ path: el,
271
+ };
272
+ });
273
+
274
+ return profileExtensions.map((el) => {
275
+ const extExisted = formattedIdsList.find(chromeExtPathElem => chromeExtPathElem.originalId === el);
276
+
277
+ if (!extExisted) {
278
+ return '';
279
+ }
280
+
281
+ return extExisted.path;
282
+ }).filter(Boolean);
243
283
  }
244
284
 
245
285
  async getExtensionsNameAndImage(extensionsIds, pathToExtensions) {