@whotracksme/reporting 5.2.1 β†’ 5.2.2

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/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ # v5.2.2 (Wed Jan 15 2025)
2
+
3
+ #### πŸ› Bug Fix
4
+
5
+ - Better error handling if fetching public keys fails [#146](https://github.com/whotracksme/webextension-packages/pull/146) ([@philipp-classen](https://github.com/philipp-classen))
6
+
7
+ #### Authors: 1
8
+
9
+ - Philipp Claßen ([@philipp-classen](https://github.com/philipp-classen))
10
+
11
+ ---
12
+
1
13
  # v5.2.1 (Tue Dec 10 2024)
2
14
 
3
15
  #### πŸ› Bug Fix
@@ -20,8 +20,8 @@
20
20
  * in the code (e.g. configuration errors, incorrect use of the API).
21
21
  */
22
22
  class ExtendableError extends Error {
23
- constructor(message) {
24
- super(message);
23
+ constructor(message, options) {
24
+ super(message, options);
25
25
  this.name = this.constructor.name;
26
26
  if (typeof Error.captureStackTrace === 'function') {
27
27
  Error.captureStackTrace(this, this.constructor);
@@ -55,8 +55,8 @@ class ExtendableError extends Error {
55
55
  * retried at a later point, or replaced by updated messages.
56
56
  */
57
57
  class RecoverableError extends ExtendableError {
58
- constructor(message) {
59
- super(message);
58
+ constructor(message, options) {
59
+ super(message, options);
60
60
  this.isRecoverableError = true;
61
61
  this.isPermanentError = false;
62
62
  }
@@ -70,15 +70,26 @@ class RecoverableError extends ExtendableError {
70
70
  * trying to send it again will again trigger the identical error.
71
71
  */
72
72
  class PermanentError extends ExtendableError {
73
- constructor(message) {
74
- super(message);
73
+ constructor(message, options) {
74
+ super(message, options);
75
75
  this.isRecoverableError = false;
76
76
  this.isPermanentError = true;
77
77
  }
78
78
  }
79
79
 
80
+ /**
81
+ * The message size exceeded the limit of 32K.
82
+ */
80
83
  export class TooBigMsgError extends PermanentError {}
84
+
81
85
  export class TransportError extends RecoverableError {}
82
86
  export class ProtocolError extends PermanentError {}
83
87
  export class InvalidMessageError extends PermanentError {}
84
88
  export class ClockOutOfSync extends RecoverableError {}
89
+
90
+ /**
91
+ * Thrown when the client failed to fetch public keys. Without
92
+ * current keys, it cannot setup the end-to-end encryption
93
+ * needed to communicate with the server.
94
+ */
95
+ export class FailedToFetchPublicKeys extends RecoverableError {}
@@ -12,6 +12,7 @@
12
12
  import logger from './logger.js';
13
13
  import { getTimeAsYYYYMMDD } from './timestamps.js';
14
14
  import { fromBase64 } from './encoding.js';
15
+ import { FailedToFetchPublicKeys } from './errors.js';
15
16
 
16
17
  function isYYYYMMDD(date) {
17
18
  return typeof date === 'string' && /^[0-9]{8}$/.test(date);
@@ -72,21 +73,7 @@ export default class ServerPublicKeyAccessor {
72
73
 
73
74
  // not found on disk or outdated -> fetch from server
74
75
  if (!knownKeys) {
75
- const url = `${this.collectorUrl}/config?fields=pubKeys`;
76
- logger.info('Fetching new server public keys from', url);
77
- const response = await fetch(url, {
78
- method: 'GET',
79
- credentials: 'omit',
80
- redirect: 'manual',
81
- });
82
- if (!response.ok) {
83
- throw new Error(
84
- `Failed to get config (${response.statusText}) from url=${url}`,
85
- );
86
- }
87
- const { pubKeys } = await response.json();
88
- logger.info('Fetched server public keys:', pubKeys);
89
-
76
+ const pubKeys = await this._fetchPublicKeys();
90
77
  const allKeys = Object.keys(pubKeys)
91
78
  .filter(isYYYYMMDD)
92
79
  .map((date) => [date, fromBase64(pubKeys[date])]);
@@ -104,6 +91,31 @@ export default class ServerPublicKeyAccessor {
104
91
  this._knownKeys = knownKeys;
105
92
  }
106
93
 
94
+ async _fetchPublicKeys() {
95
+ const url = `${this.collectorUrl}/config?fields=pubKeys`;
96
+ logger.info('Fetching new server public keys from', url);
97
+ try {
98
+ const response = await fetch(url, {
99
+ method: 'GET',
100
+ credentials: 'omit',
101
+ redirect: 'manual',
102
+ });
103
+ if (!response.ok) {
104
+ throw new Error(
105
+ `Failed to get config (${response.statusText}) from '${url}'`,
106
+ );
107
+ }
108
+ const { pubKeys } = await response.json();
109
+ logger.info('Fetched server public keys:', pubKeys);
110
+ return pubKeys;
111
+ } catch (e) {
112
+ throw new FailedToFetchPublicKeys(
113
+ `Failed to fetch public keys from '${url}'`,
114
+ { cause: e },
115
+ );
116
+ }
117
+ }
118
+
107
119
  async importAndVerifyPubKeys(allKeys) {
108
120
  return new Map(
109
121
  await Promise.all(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whotracksme/reporting",
3
- "version": "5.2.1",
3
+ "version": "5.2.2",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "scripts": {