@adobe/helix-onedrive-support 10.4.0 → 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,10 @@
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
+
1
8
  # [10.4.0](https://github.com/adobe/helix-onedrive-support/compare/v10.3.7...v10.4.0) (2023-08-28)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-onedrive-support",
3
- "version": "10.4.0",
3
+ "version": "10.5.0",
4
4
  "description": "Helix OneDrive Support",
5
5
  "main": "src/index.js",
6
6
  "exports": {
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
@@ -353,6 +353,13 @@ export class OneDrive {
353
353
  return download ? this.doFetch(`${uri}:/content`, true) : this.doFetch(uri);
354
354
  }
355
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
+
356
363
  /**
357
364
  */
358
365
  async downloadDriveItem(driveItem) {
@@ -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`);