chrome-webstore-upload 3.0.2 → 3.1.0
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/index.js +38 -7
- package/package.json +1 -1
- package/readme.md +2 -1
package/index.js
CHANGED
|
@@ -6,13 +6,30 @@ const rootURI = 'https://www.googleapis.com';
|
|
|
6
6
|
export const refreshTokenURI = 'https://www.googleapis.com/oauth2/v4/token';
|
|
7
7
|
const uploadExistingURI = id =>
|
|
8
8
|
`${rootURI}/upload/chromewebstore/v1.1/items/${id}`;
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
|
|
10
|
+
const publishURI = ({ extensionId, target = 'default', deployPercentage }) => {
|
|
11
|
+
const url = new URL(`${rootURI}/chromewebstore/v1.1/items/${extensionId}/publish`);
|
|
12
|
+
url.searchParams.set('publishTarget', target);
|
|
13
|
+
if (deployPercentage) {
|
|
14
|
+
url.searchParams.set('deployPercentage', deployPercentage);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return url.href;
|
|
18
|
+
};
|
|
19
|
+
|
|
11
20
|
const getURI = (id, projection) =>
|
|
12
21
|
`${rootURI}/chromewebstore/v1.1/items/${id}?projection=${projection}`;
|
|
13
22
|
|
|
14
23
|
const requiredFields = ['extensionId', 'clientId', 'refreshToken'];
|
|
15
24
|
|
|
25
|
+
function throwIfNotOk(request, response) {
|
|
26
|
+
if (!request.ok) {
|
|
27
|
+
const error = new Error(request.statusText ?? 'Unknown error');
|
|
28
|
+
error.response = response;
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
16
33
|
class APIClient {
|
|
17
34
|
constructor(options) {
|
|
18
35
|
if (typeof fetch !== 'function') {
|
|
@@ -46,18 +63,26 @@ class APIClient {
|
|
|
46
63
|
body: readStream,
|
|
47
64
|
});
|
|
48
65
|
|
|
49
|
-
|
|
66
|
+
const response = await request.json();
|
|
67
|
+
|
|
68
|
+
throwIfNotOk(request, response);
|
|
69
|
+
|
|
70
|
+
return response;
|
|
50
71
|
}
|
|
51
72
|
|
|
52
|
-
async publish(target = 'default', token = this.fetchToken()) {
|
|
73
|
+
async publish(target = 'default', token = this.fetchToken(), deployPercentage) {
|
|
53
74
|
const { extensionId } = this;
|
|
54
75
|
|
|
55
|
-
const request = await fetch(publishURI(extensionId, target), {
|
|
76
|
+
const request = await fetch(publishURI({ extensionId, target, deployPercentage }), {
|
|
56
77
|
method: 'POST',
|
|
57
78
|
headers: this._headers(await token),
|
|
58
79
|
});
|
|
59
80
|
|
|
60
|
-
|
|
81
|
+
const response = await request.json();
|
|
82
|
+
|
|
83
|
+
throwIfNotOk(request, response);
|
|
84
|
+
|
|
85
|
+
return response;
|
|
61
86
|
}
|
|
62
87
|
|
|
63
88
|
async get(projection = 'DRAFT', token = this.fetchToken()) {
|
|
@@ -68,7 +93,11 @@ class APIClient {
|
|
|
68
93
|
headers: this._headers(await token),
|
|
69
94
|
});
|
|
70
95
|
|
|
71
|
-
|
|
96
|
+
const response = await request.json();
|
|
97
|
+
|
|
98
|
+
throwIfNotOk(request, response);
|
|
99
|
+
|
|
100
|
+
return response;
|
|
72
101
|
}
|
|
73
102
|
|
|
74
103
|
async fetchToken() {
|
|
@@ -91,6 +120,8 @@ class APIClient {
|
|
|
91
120
|
},
|
|
92
121
|
});
|
|
93
122
|
|
|
123
|
+
await throwIfNotOk(request);
|
|
124
|
+
|
|
94
125
|
const response = await request.json();
|
|
95
126
|
|
|
96
127
|
return response.access_token;
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -49,7 +49,8 @@ store.uploadExisting(myZipFile, token).then(res => {
|
|
|
49
49
|
```javascript
|
|
50
50
|
const target = 'default'; // optional. Can also be 'trustedTesters'
|
|
51
51
|
const token = 'xxxx'; // optional. One will be fetched if not provided
|
|
52
|
-
|
|
52
|
+
const deployPercentage = 25; // optional. Will default to 100%.
|
|
53
|
+
store.publish(target, token, deployPercentage).then(res => {
|
|
53
54
|
// Response is documented here:
|
|
54
55
|
// https://developer.chrome.com/webstore/webstore_api/items/publish
|
|
55
56
|
});
|