@adobe/helix-onedrive-support 10.3.7 → 10.5.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/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ # [10.5.0](https://github.com/adobe/helix-onedrive-support/compare/v10.4.0...v10.5.0) (2023-09-01)
2
+
3
+
4
+ ### Features
5
+
6
+ * added excel workbook functionalities ([8782e56](https://github.com/adobe/helix-onedrive-support/commit/8782e560593b02e56dcb33595256089ffaa35132))
7
+
8
+ # [10.4.0](https://github.com/adobe/helix-onedrive-support/compare/v10.3.7...v10.4.0) (2023-08-28)
9
+
10
+
11
+ ### Features
12
+
13
+ * add log fields for API call logging ([#425](https://github.com/adobe/helix-onedrive-support/issues/425)) ([36f88db](https://github.com/adobe/helix-onedrive-support/commit/36f88db697db73a7fc24da062f66d66aeab32bc0))
14
+
1
15
  ## [10.3.7](https://github.com/adobe/helix-onedrive-support/compare/v10.3.6...v10.3.7) (2023-08-21)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-onedrive-support",
3
- "version": "10.3.7",
3
+ "version": "10.5.0",
4
4
  "description": "Helix OneDrive Support",
5
5
  "main": "src/index.js",
6
6
  "exports": {
@@ -36,12 +36,12 @@
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.395.0",
39
+ "@aws-sdk/client-s3": "3.400.0",
40
40
  "ajv": "8.12.0",
41
41
  "c8": "8.0.1",
42
42
  "codecov": "3.8.3",
43
43
  "dotenv": "16.3.1",
44
- "eslint": "8.47.0",
44
+ "eslint": "8.48.0",
45
45
  "eslint-plugin-header": "3.1.1",
46
46
  "eslint-plugin-import": "2.28.1",
47
47
  "husky": "8.0.3",
@@ -49,12 +49,12 @@
49
49
  "jsdoc-to-markdown": "8.0.0",
50
50
  "jsdoc-tsimport-plugin": "1.0.5",
51
51
  "junit-report-builder": "3.0.1",
52
- "lint-staged": "14.0.0",
52
+ "lint-staged": "14.0.1",
53
53
  "mocha": "10.2.0",
54
54
  "mocha-multi-reporters": "1.5.1",
55
55
  "nock": "13.3.3",
56
56
  "npm": "9.8.1",
57
- "semantic-release": "21.0.7"
57
+ "semantic-release": "21.1.1"
58
58
  },
59
59
  "lint-staged": {
60
60
  "*.js": "eslint"
package/src/OneDrive.d.ts CHANGED
@@ -149,6 +149,14 @@ export declare class OneDrive extends EventEmitter {
149
149
  */
150
150
  getDriveItem(folderItem: DriveItem, relPath?: string, download?: boolean): Promise<GraphResult>;
151
151
 
152
+
153
+ /**
154
+ * Returns the parentdrive item for the given driveItem
155
+ *
156
+ * @param {DriveItem} driveItem Drive Item.
157
+ */
158
+ getParentDriveItem(driveItem: DriveItemn): Promise<GraphResult>;
159
+
152
160
  /**
153
161
  * Tries to get the drive items for the given folder and relative path, by loading the files of
154
162
  * the respective directory and returning the item with the best matching filename. Please note,
package/src/OneDrive.js CHANGED
@@ -125,14 +125,19 @@ export class OneDrive {
125
125
  opts.headers = {};
126
126
  }
127
127
  opts.headers.authorization = `Bearer ${accessToken}`;
128
+
129
+ const { log, auth: { logFields, tenant } } = this;
128
130
  const url = `https://graph.microsoft.com/v1.0${relUrl}`;
131
+ const method = opts.method || 'GET';
132
+
129
133
  try {
130
134
  const { fetch } = this.fetchContext;
131
135
  const resp = await fetch(url, opts);
132
- const rateLimit = RateLimit.fromHeaders(resp.headers);
136
+ log.info(`OneDrive API [tenant:${tenant}] ${logFields}: ${method} ${relUrl} ${resp.status}`);
133
137
 
138
+ const rateLimit = RateLimit.fromHeaders(resp.headers);
134
139
  if (rateLimit) {
135
- this.log.warn({ sharepointRateLimit: { tenant: this.auth.tenant, ...rateLimit.toJSON() } });
140
+ log.warn({ sharepointRateLimit: { tenant, ...rateLimit.toJSON() } });
136
141
  }
137
142
 
138
143
  if (!resp.ok) {
@@ -157,6 +162,7 @@ export class OneDrive {
157
162
  if (!(e instanceof StatusCodeError)) {
158
163
  err = StatusCodeError.fromError(e);
159
164
  }
165
+ log.info(`OneDrive API [tenant:${tenant}] ${logFields}: ${method} ${relUrl} ${e.statusCode}`);
160
166
  throw err;
161
167
  }
162
168
  }
@@ -347,6 +353,13 @@ export class OneDrive {
347
353
  return download ? this.doFetch(`${uri}:/content`, true) : this.doFetch(uri);
348
354
  }
349
355
 
356
+ /**
357
+ */
358
+ async getParentDriveItem(driveItem) {
359
+ const parentURI = `/drives/${driveItem.parentReference.driveId}/items/${driveItem.parentReference.id}`;
360
+ return this.doFetch(parentURI, false);
361
+ }
362
+
350
363
  /**
351
364
  */
352
365
  async downloadDriveItem(driveItem) {
@@ -28,6 +28,11 @@ export declare interface OneDriveAuthOptions {
28
28
  acquireMethod?: AcquireMethod;
29
29
  accessToken?: string;
30
30
 
31
+ /**
32
+ * Optional log fields, as key-value object.
33
+ */
34
+ logFields?: object;
35
+
31
36
  /**
32
37
  * use cache plugin instead for default (global) token cache.
33
38
  */
@@ -76,6 +76,8 @@ export class OneDriveAuth {
76
76
  this.scopes = opts.scopes || DEFAULT_SCOPES;
77
77
  this.onCode = opts.onCode;
78
78
  this.acquireMethod = opts.acquireMethod || '';
79
+ this.logFields = Object.entries(opts.logFields || {})
80
+ .map(([key, value]) => `[${key}:${value}]`).join(' ');
79
81
 
80
82
  const validAcquireMethods = Array.from(Object.values(AcquireMethod));
81
83
  if (this.acquireMethod && !validAcquireMethods.includes(this.acquireMethod)) {
@@ -355,6 +355,10 @@ export class OneDriveMock extends OneDrive {
355
355
  segs.shift();
356
356
  if (segs[0]) {
357
357
  const sheetName = segs.shift();
358
+ if (method === 'DELETE' && segs.length === 0) {
359
+ data.sheets = data.sheets.filter((s) => (s.name !== sheetName));
360
+ return data.sheets;
361
+ }
358
362
  sheet = data.sheets.find((s) => (s.name === sheetName));
359
363
  if (!sheet) {
360
364
  throw new StatusCodeError(sheetName, 404);
@@ -363,6 +367,11 @@ export class OneDriveMock extends OneDrive {
363
367
  // if no more segments, return the sheet data
364
368
  return { value: sheet };
365
369
  }
370
+ } else if (method === 'POST') {
371
+ data.sheets.push({
372
+ name: body.name,
373
+ });
374
+ return { value: data.sheets.map((st) => ({ name: st.name })) };
366
375
  } else {
367
376
  return { value: data.sheets.map((st) => ({ name: st.name })) };
368
377
  }
@@ -24,6 +24,20 @@ export declare interface Workbook {
24
24
  */
25
25
  getWorksheetNames(): Promise<string[]>;
26
26
 
27
+ /**
28
+ * Create the worksheet with given name in the workbook.
29
+ * @param {string} sheetName sheet name
30
+ * @returns Worksheet
31
+ *
32
+ */
33
+ createWorksheet(sheetName: string): Worksheet;
34
+
35
+ /**
36
+ * Delete the worksheet with given name in the workbook.
37
+ * @param {string} sheetName sheet name
38
+ */
39
+ deleteWorksheet(sheetName: string): Promise<void>;
40
+
27
41
  /**
28
42
  * Return a new `Worksheet` instance given its name
29
43
  * @param name work sheet name
@@ -38,6 +38,24 @@ export class Workbook extends NamedItemContainer {
38
38
  return new Worksheet(this._oneDrive, `${this._uri}/worksheets`, name, this._log);
39
39
  }
40
40
 
41
+ async createWorksheet(sheetName) {
42
+ const uri = `${this.uri}/worksheets`;
43
+ await this._oneDrive.doFetch(uri, false, {
44
+ method: 'POST',
45
+ body: { name: sheetName },
46
+ headers: { 'content-type': 'application/json' },
47
+ });
48
+ return this.worksheet(sheetName);
49
+ }
50
+
51
+ async deleteWorksheet(sheetName) {
52
+ const uri = `${this.uri}/worksheets/${sheetName}`;
53
+ await this._oneDrive.doFetch(uri, false, {
54
+ method: 'DELETE',
55
+ headers: { 'content-type': 'application/json' },
56
+ });
57
+ }
58
+
41
59
  async getTableNames() {
42
60
  this.log.debug(`get table names from ${this._uri}/tables`);
43
61
  const result = await this._oneDrive.doFetch(`${this._uri}/tables`);