@adobe/helix-onedrive-support 11.0.0 → 11.0.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/.eslintrc.cjs +1 -1
- package/CHANGELOG.md +14 -0
- package/package.json +7 -7
- package/src/OneDrive.js +44 -26
package/.eslintrc.cjs
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [11.0.2](https://github.com/adobe/helix-onedrive-support/compare/v11.0.1...v11.0.2) (2023-10-20)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **deps:** update dependency @adobe/helix-shared-tokencache to v1.3.12 ([f4ffa5f](https://github.com/adobe/helix-onedrive-support/commit/f4ffa5f89bf3857d0e6a9e233a95962f9af36994))
|
|
7
|
+
|
|
8
|
+
## [11.0.1](https://github.com/adobe/helix-onedrive-support/compare/v11.0.0...v11.0.1) (2023-10-18)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* log errors once ([#453](https://github.com/adobe/helix-onedrive-support/issues/453)) ([018c1c2](https://github.com/adobe/helix-onedrive-support/commit/018c1c22a3257805fa126b56ad8e59afd7e1fc0f))
|
|
14
|
+
|
|
1
15
|
# [11.0.0](https://github.com/adobe/helix-onedrive-support/compare/v10.8.5...v11.0.0) (2023-10-14)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/helix-onedrive-support",
|
|
3
|
-
"version": "11.0.
|
|
3
|
+
"version": "11.0.2",
|
|
4
4
|
"description": "Helix OneDrive Support",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -28,15 +28,15 @@
|
|
|
28
28
|
"homepage": "https://github.com/adobe/helix-onedrive-support#readme",
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@adobe/fetch": "4.1.0",
|
|
31
|
-
"@adobe/helix-shared-tokencache": "1.3.
|
|
31
|
+
"@adobe/helix-shared-tokencache": "1.3.12",
|
|
32
32
|
"@azure/msal-node": "2.2.0",
|
|
33
|
-
"jose": "4.15.
|
|
33
|
+
"jose": "4.15.4"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@adobe/eslint-config-helix": "2.0.3",
|
|
37
37
|
"@semantic-release/changelog": "6.0.3",
|
|
38
38
|
"@semantic-release/git": "10.0.1",
|
|
39
|
-
"@aws-sdk/client-s3": "3.
|
|
39
|
+
"@aws-sdk/client-s3": "3.428.0",
|
|
40
40
|
"ajv": "8.12.0",
|
|
41
41
|
"c8": "8.0.1",
|
|
42
42
|
"codecov": "3.8.3",
|
|
@@ -48,11 +48,11 @@
|
|
|
48
48
|
"install": "0.13.0",
|
|
49
49
|
"jsdoc-to-markdown": "8.0.0",
|
|
50
50
|
"jsdoc-tsimport-plugin": "1.0.5",
|
|
51
|
-
"junit-report-builder": "3.0
|
|
52
|
-
"lint-staged": "
|
|
51
|
+
"junit-report-builder": "3.1.0",
|
|
52
|
+
"lint-staged": "15.0.1",
|
|
53
53
|
"mocha": "10.2.0",
|
|
54
54
|
"mocha-multi-reporters": "1.5.1",
|
|
55
|
-
"nock": "13.3.
|
|
55
|
+
"nock": "13.3.4",
|
|
56
56
|
"npm": "10.2.0",
|
|
57
57
|
"semantic-release": "22.0.5"
|
|
58
58
|
},
|
package/src/OneDrive.js
CHANGED
|
@@ -116,6 +116,32 @@ export class OneDrive {
|
|
|
116
116
|
return this._log;
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
+
async #handleBadResponse(resp, rateLimit) {
|
|
120
|
+
const { log } = this;
|
|
121
|
+
|
|
122
|
+
let text;
|
|
123
|
+
let err;
|
|
124
|
+
|
|
125
|
+
try {
|
|
126
|
+
text = await resp.text();
|
|
127
|
+
/* c8 ignore next 4 */
|
|
128
|
+
} catch (e) {
|
|
129
|
+
log.warn(`Unable to fetch response text: ${e.message}`);
|
|
130
|
+
throw StatusCodeError.fromError(e);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
try {
|
|
134
|
+
err = StatusCodeError.fromErrorResponse(JSON.parse(text), resp.status, rateLimit);
|
|
135
|
+
} catch (e) {
|
|
136
|
+
if (text.startsWith('<!DOCTYPE html>')) {
|
|
137
|
+
log.warn('Graph API returned html response', text);
|
|
138
|
+
text = 'Something went wrong: HTML error from graph api.';
|
|
139
|
+
}
|
|
140
|
+
err = new StatusCodeError(text, resp.status, null, rateLimit);
|
|
141
|
+
}
|
|
142
|
+
throw err;
|
|
143
|
+
}
|
|
144
|
+
|
|
119
145
|
/**
|
|
120
146
|
*/
|
|
121
147
|
async doFetch(relUrl, rawResponseBody = false, options = {}) {
|
|
@@ -129,45 +155,37 @@ export class OneDrive {
|
|
|
129
155
|
const { log, auth: { logFields, tenant } } = this;
|
|
130
156
|
const url = `https://graph.microsoft.com/v1.0${relUrl}`;
|
|
131
157
|
const method = opts.method || 'GET';
|
|
158
|
+
let resp;
|
|
132
159
|
|
|
133
160
|
try {
|
|
134
161
|
const { fetch } = this.fetchContext;
|
|
135
|
-
|
|
162
|
+
resp = await fetch(url, opts);
|
|
136
163
|
log.info(`OneDrive API [tenant:${tenant}] ${logFields}: ${method} ${relUrl} ${resp.status}`);
|
|
164
|
+
} catch (e) {
|
|
165
|
+
log.info(`OneDrive API [tenant:${tenant}] ${logFields}: ${method} ${relUrl} ${e.message}`);
|
|
166
|
+
throw StatusCodeError.fromError(e);
|
|
167
|
+
}
|
|
137
168
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
169
|
+
const rateLimit = RateLimit.fromHeaders(resp.headers);
|
|
170
|
+
if (rateLimit) {
|
|
171
|
+
log.warn({ sharepointRateLimit: { tenant, ...rateLimit.toJSON() } });
|
|
172
|
+
}
|
|
142
173
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
err = StatusCodeError.fromErrorResponse(JSON.parse(text), resp.status, rateLimit);
|
|
149
|
-
} catch {
|
|
150
|
-
if (text.startsWith('<!DOCTYPE html>')) {
|
|
151
|
-
log.warn('onedrive returned html response', text);
|
|
152
|
-
text = 'Something went wrong: HTML error from graph api.';
|
|
153
|
-
}
|
|
154
|
-
err = new StatusCodeError(text, resp.status, null, rateLimit);
|
|
155
|
-
}
|
|
156
|
-
throw err;
|
|
157
|
-
}
|
|
174
|
+
if (!resp.ok) {
|
|
175
|
+
return this.#handleBadResponse(resp, rateLimit);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
try {
|
|
158
179
|
// check content type before trying to parse a response body as JSON
|
|
159
180
|
const contentType = resp.headers.get('content-type');
|
|
160
181
|
const json = contentType && contentType.startsWith('application/json');
|
|
161
182
|
|
|
162
183
|
// await result in order to be able to catch any error
|
|
163
184
|
return await (rawResponseBody || !json ? resp.buffer() : resp.json());
|
|
185
|
+
/* c8 ignore next 4 */
|
|
164
186
|
} catch (e) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
err = StatusCodeError.fromError(e);
|
|
168
|
-
}
|
|
169
|
-
log.info(`OneDrive API [tenant:${tenant}] ${logFields}: ${method} ${relUrl} ${e.statusCode}`);
|
|
170
|
-
throw err;
|
|
187
|
+
log.warn(`Unable to fetch response buffer or json: ${e.message}`);
|
|
188
|
+
throw StatusCodeError.fromError(e);
|
|
171
189
|
}
|
|
172
190
|
}
|
|
173
191
|
|