chrome-webstore-upload 3.0.1 → 3.0.3

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.
Files changed (2) hide show
  1. package/index.js +29 -3
  2. package/package.json +10 -3
package/index.js CHANGED
@@ -13,8 +13,20 @@ const getURI = (id, projection) =>
13
13
 
14
14
  const requiredFields = ['extensionId', 'clientId', 'refreshToken'];
15
15
 
16
+ function throwIfNotOk(request, response) {
17
+ if (!request.ok) {
18
+ const error = new Error(request.statusText ?? 'Unknown error');
19
+ error.response = response;
20
+ throw error;
21
+ }
22
+ }
23
+
16
24
  class APIClient {
17
25
  constructor(options) {
26
+ if (typeof fetch !== 'function') {
27
+ throw new TypeError('`chrome-webstore-upload` requires Node.js 18.0 or newer because it relies on the global `fetch` function.');
28
+ }
29
+
18
30
  for (const field of requiredFields) {
19
31
  if (!options[field]) {
20
32
  throw new Error(`Option "${field}" is required`);
@@ -42,7 +54,11 @@ class APIClient {
42
54
  body: readStream,
43
55
  });
44
56
 
45
- return request.json();
57
+ const response = await request.json();
58
+
59
+ throwIfNotOk(request, response);
60
+
61
+ return response;
46
62
  }
47
63
 
48
64
  async publish(target = 'default', token = this.fetchToken()) {
@@ -53,7 +69,11 @@ class APIClient {
53
69
  headers: this._headers(await token),
54
70
  });
55
71
 
56
- return request.json();
72
+ const response = await request.json();
73
+
74
+ throwIfNotOk(request, response);
75
+
76
+ return response;
57
77
  }
58
78
 
59
79
  async get(projection = 'DRAFT', token = this.fetchToken()) {
@@ -64,7 +84,11 @@ class APIClient {
64
84
  headers: this._headers(await token),
65
85
  });
66
86
 
67
- return request.json();
87
+ const response = await request.json();
88
+
89
+ throwIfNotOk(request, response);
90
+
91
+ return response;
68
92
  }
69
93
 
70
94
  async fetchToken() {
@@ -87,6 +111,8 @@ class APIClient {
87
111
  },
88
112
  });
89
113
 
114
+ await throwIfNotOk(request);
115
+
90
116
  const response = await request.json();
91
117
 
92
118
  return response.access_token;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chrome-webstore-upload",
3
- "version": "3.0.1",
3
+ "version": "3.0.3",
4
4
  "description": "Upload Chrome Extensions to the Chrome Web Store",
5
5
  "keywords": [
6
6
  "chrome",
@@ -25,7 +25,12 @@
25
25
  "index.js"
26
26
  ],
27
27
  "scripts": {
28
- "test": "xo && vitest"
28
+ "test": "xo && vitest run",
29
+ "upload": "npm run bundle && npm run test:upload",
30
+ "prebundle": "dot-json test/extension/manifest.json version $(utc-version)",
31
+ "bundle": "web-ext build --filename live-test.zip --overwrite-dest",
32
+ "postbundle": "git restore test/extension/manifest.json",
33
+ "test:upload": "eval $(cat .env) node test/live-test.js"
29
34
  },
30
35
  "xo": {
31
36
  "rules": {
@@ -38,8 +43,10 @@
38
43
  "space": 4
39
44
  },
40
45
  "devDependencies": {
46
+ "dot-json": "^1.3.0",
41
47
  "fetch-mock": "^9.11.0",
42
48
  "node-fetch": "^2.7.0",
49
+ "utc-version": "^2.0.2",
43
50
  "vitest": "^1.0.4",
44
51
  "xo": "^0.56.0"
45
52
  },
@@ -47,6 +54,6 @@
47
54
  "node": ">=18"
48
55
  },
49
56
  "webExt": {
50
- "sourceDir": "live-test"
57
+ "sourceDir": "test/extension"
51
58
  }
52
59
  }