@sovovs/bycli 2.1.53 → 2.1.54

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.
@@ -204,6 +204,12 @@ export const USER_INFO_EXTRACT_SCRIPT = `(() => {
204
204
  }
205
205
  return cleanValueText(node);
206
206
  };
207
+ const textWithout = (node, selector) => {
208
+ if (!node) return null;
209
+ const copy = node.cloneNode(true);
210
+ copy.querySelectorAll(selector).forEach(item => item.remove());
211
+ return compact(copy.textContent);
212
+ };
207
213
  const switchValue = row => {
208
214
  const node = firstVisible(row, [
209
215
  'input[type="checkbox"]',
@@ -263,6 +269,45 @@ export const USER_INFO_EXTRACT_SCRIPT = `(() => {
263
269
  const label = compact(heading && heading.textContent)
264
270
  || compact(sectionNode.getAttribute('aria-label'))
265
271
  || '其他信息';
272
+ const authorizationTable = Array.from(sectionNode.querySelectorAll('table'))
273
+ .filter(visible)
274
+ .find(table => {
275
+ const headers = Array.from(table.querySelectorAll('thead th, tr > th'))
276
+ .filter(visible)
277
+ .map(node => compact(node.textContent));
278
+ return headers.includes('第三方平台名称')
279
+ && headers.includes('已授权权限')
280
+ && headers.includes('授权时间');
281
+ }) || null;
282
+ const records = authorizationTable === null ? null : Array.from(
283
+ authorizationTable.querySelectorAll('tbody > tr, tr'),
284
+ ).filter(visible).flatMap(row => {
285
+ const cells = Array.from(row.querySelectorAll(':scope > td')).filter(visible);
286
+ if (cells.length < 3 || row.querySelector('.empty_tips')) return [];
287
+ const nameNode = firstVisible(cells[0], [
288
+ '.plugin_info h4',
289
+ '.plugin_info .name',
290
+ 'h4',
291
+ ]);
292
+ const name = compact(nameNode && nameNode.textContent);
293
+ if (!name) return [];
294
+ const descriptionNode = firstVisible(cells[0], [
295
+ '.plugin_info .desc',
296
+ '.plugin_info p',
297
+ ]);
298
+ const permissions = Array.from(cells[1].querySelectorAll('.privilege'))
299
+ .filter(visible)
300
+ .flatMap(node => {
301
+ const permission = textWithout(node, '.dot');
302
+ return permission ? [permission] : [];
303
+ });
304
+ return [{
305
+ name,
306
+ description: compact(descriptionNode && descriptionNode.textContent),
307
+ permissions,
308
+ authorized_at: cleanValueText(cells[2]),
309
+ }];
310
+ });
266
311
  let rows = Array.from(sectionNode.querySelectorAll(rowSelector)).filter(visible);
267
312
  rows = rows.filter(node => !rows.some(other => other !== node && other.contains(node)));
268
313
  const fields = [];
@@ -339,7 +384,10 @@ export const USER_INFO_EXTRACT_SCRIPT = `(() => {
339
384
  }
340
385
  }
341
386
 
342
- if (fields.length > 0) return [{ label, fields }];
387
+ if (fields.length > 0 || (records && records.length > 0)) {
388
+ return [{ label, fields, ...(records === null ? {} : { records }) }];
389
+ }
390
+ if (records !== null) return [{ label, fields, records, empty: true }];
343
391
  const empty = Boolean(sectionNode.querySelector('table thead th, table tr > th'));
344
392
  return empty ? [{ label, fields, empty: true }] : [];
345
393
  });
@@ -361,6 +409,25 @@ function normalizeField(field, tabLabel, sectionIndex, fieldIndex) {
361
409
  };
362
410
  }
363
411
 
412
+ function normalizeAuthorizationRecord(record, tabLabel, sectionIndex, recordIndex) {
413
+ const prefix = `WeChat ${tabLabel} returned an invalid authorization record at section ${sectionIndex} index ${recordIndex}`;
414
+ execution(object(record), prefix);
415
+ const name = text(record.name);
416
+ const authorizedAt = text(record.authorized_at);
417
+ execution(name && authorizedAt && Array.isArray(record.permissions), prefix);
418
+ const permissions = record.permissions.map((permission, permissionIndex) => {
419
+ const normalized = text(permission);
420
+ execution(normalized, `${prefix} permission ${permissionIndex}`);
421
+ return normalized;
422
+ });
423
+ return {
424
+ name,
425
+ description: text(record.description),
426
+ permissions,
427
+ authorized_at: authorizedAt,
428
+ };
429
+ }
430
+
364
431
  export function normalizeUserInfoTab(tabId, payload) {
365
432
  const definition = TAB_DEFINITIONS.find(tab => tab.id === tabId);
366
433
  execution(definition, `WeChat account settings returned an unknown tab: ${String(tabId)}`);
@@ -381,8 +448,14 @@ export function normalizeUserInfoTab(tabId, payload) {
381
448
  const fields = rawFields.map((field, fieldIndex) => (
382
449
  normalizeField(field, definition.label, sectionIndex, fieldIndex)
383
450
  ));
384
- return fields.length > 0 || section.empty === true
385
- ? [{ label, fields }]
451
+ const hasRecords = Object.prototype.hasOwnProperty.call(section, 'records');
452
+ const rawRecords = hasRecords ? section.records : [];
453
+ execution(Array.isArray(rawRecords), prefix);
454
+ const records = rawRecords.map((record, recordIndex) => (
455
+ normalizeAuthorizationRecord(record, definition.label, sectionIndex, recordIndex)
456
+ ));
457
+ return fields.length > 0 || records.length > 0 || section.empty === true
458
+ ? [{ label, fields, ...(hasRecords ? { records } : {}) }]
386
459
  : [];
387
460
  });
388
461
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sovovs/bycli",
3
- "version": "2.1.53",
3
+ "version": "2.1.54",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },