wileys 0.4.4 → 0.4.6

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.
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": [2, 3000, 1027934701]
2
+ "version": [2, 3000, 1033105955]
3
3
  }
@@ -389,7 +389,7 @@ const makeSocket = (config) => {
389
389
  end(new boom_1.Boom(msg || 'Intentional Logout', { statusCode: Types_1.DisconnectReason.loggedOut }));
390
390
  };
391
391
  const requestPairingCode = async (phoneNumber, pairKey) => {
392
- await waitForSocketOpen();
392
+ var _a, _b;
393
393
  const pairingCode = pairKey || (0, Utils_1.bytesToCrockford)((0, crypto_1.randomBytes)(5));
394
394
  if (pairKey && pairKey.length !== 8) {
395
395
  throw new Error('Custom pairing code must be exactly 8 chars');
@@ -400,53 +400,69 @@ const makeSocket = (config) => {
400
400
  name: '~'
401
401
  };
402
402
  ev.emit('creds.update', authState.creds);
403
- await sendNode({
404
- tag: 'iq',
405
- attrs: {
406
- to: WABinary_1.S_WHATSAPP_NET,
407
- type: 'set',
408
- id: generateMessageTag(),
409
- xmlns: 'md'
410
- },
411
- content: [
412
- {
413
- tag: 'link_code_companion_reg',
403
+ const maxRetries = 2;
404
+ for (let attempt = 1; attempt <= maxRetries; attempt++) {
405
+ try {
406
+ await waitForSocketOpen();
407
+ await sendNode({
408
+ tag: 'iq',
414
409
  attrs: {
415
- jid: authState.creds.me.id,
416
- stage: 'companion_hello',
417
- // eslint-disable-next-line camelcase
418
- should_show_push_notification: 'true'
410
+ to: WABinary_1.S_WHATSAPP_NET,
411
+ type: 'set',
412
+ id: generateMessageTag(),
413
+ xmlns: 'md'
419
414
  },
420
415
  content: [
421
416
  {
422
- tag: 'link_code_pairing_wrapped_companion_ephemeral_pub',
423
- attrs: {},
424
- content: await generatePairingKey()
425
- },
426
- {
427
- tag: 'companion_server_auth_key_pub',
428
- attrs: {},
429
- content: authState.creds.noiseKey.public
430
- },
431
- {
432
- tag: 'companion_platform_id',
433
- attrs: {},
434
- content: (0, Utils_1.getPlatformId)(browser[1])
435
- },
436
- {
437
- tag: 'companion_platform_display',
438
- attrs: {},
439
- content: `${browser[1]} (${browser[0]})`
440
- },
441
- {
442
- tag: 'link_code_pairing_nonce',
443
- attrs: {},
444
- content: '0'
417
+ tag: 'link_code_companion_reg',
418
+ attrs: {
419
+ jid: authState.creds.me.id,
420
+ stage: 'companion_hello',
421
+ // eslint-disable-next-line camelcase
422
+ should_show_push_notification: 'true'
423
+ },
424
+ content: [
425
+ {
426
+ tag: 'link_code_pairing_wrapped_companion_ephemeral_pub',
427
+ attrs: {},
428
+ content: await generatePairingKey()
429
+ },
430
+ {
431
+ tag: 'companion_server_auth_key_pub',
432
+ attrs: {},
433
+ content: authState.creds.noiseKey.public
434
+ },
435
+ {
436
+ tag: 'companion_platform_id',
437
+ attrs: {},
438
+ content: (0, Utils_1.getPlatformId)(browser[1])
439
+ },
440
+ {
441
+ tag: 'companion_platform_display',
442
+ attrs: {},
443
+ content: `${browser[1]} (${browser[0]})`
444
+ },
445
+ {
446
+ tag: 'link_code_pairing_nonce',
447
+ attrs: {},
448
+ content: '0'
449
+ }
450
+ ]
445
451
  }
446
452
  ]
453
+ });
454
+ break;
455
+ }
456
+ catch (error) {
457
+ const statusCode = ((_b = (_a = error === null || error === void 0 ? void 0 : error.output) === null || _a === void 0 ? void 0 : _a.payload) === null || _b === void 0 ? void 0 : _b.statusCode) || (error === null || error === void 0 ? void 0 : error.statusCode);
458
+ const canRetry = statusCode === 428 || statusCode === Types_1.DisconnectReason.connectionClosed || statusCode === Types_1.DisconnectReason.connectionLost;
459
+ if (!canRetry || attempt >= maxRetries) {
460
+ throw error;
447
461
  }
448
- ]
449
- });
462
+ logger.warn({ attempt, statusCode, trace: error === null || error === void 0 ? void 0 : error.stack }, 'pairing code request failed, retrying');
463
+ await (0, Utils_1.delay)(500 * attempt);
464
+ }
465
+ }
450
466
  return authState.creds.pairingCode;
451
467
  };
452
468
  async function generatePairingKey() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wileys",
3
- "version": "0.4.4",
3
+ "version": "0.4.6",
4
4
  "description": "WhatsApp Web API Library",
5
5
  "keywords": [
6
6
  "wileys",