@adobe/helix-onedrive-support 10.6.4 → 10.7.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 +14 -0
- package/package.json +2 -2
- package/src/OneDrive.js +11 -0
- package/src/OneDriveMock.js +13 -2
- package/src/excel/Table.d.ts +2 -1
- package/src/excel/Table.js +4 -4
- package/src/excel/Workbook.d.ts +21 -0
- package/src/excel/Workbook.js +41 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# [10.7.0](https://github.com/adobe/helix-onedrive-support/compare/v10.6.5...v10.7.0) (2023-09-14)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* add row at index and workbook session upport ([bba1aab](https://github.com/adobe/helix-onedrive-support/commit/bba1aab486ed1f12bc08de43c66e44d08e521a05))
|
|
7
|
+
|
|
8
|
+
## [10.6.5](https://github.com/adobe/helix-onedrive-support/compare/v10.6.4...v10.6.5) (2023-09-13)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* **deps:** update dependency @adobe/fetch to v4.1.0 ([a2237b4](https://github.com/adobe/helix-onedrive-support/commit/a2237b43f769b494ff50e65bb0c755532c698863))
|
|
14
|
+
|
|
1
15
|
## [10.6.4](https://github.com/adobe/helix-onedrive-support/compare/v10.6.3...v10.6.4) (2023-09-09)
|
|
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
|
+
"version": "10.7.0",
|
|
4
4
|
"description": "Helix OneDrive Support",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"homepage": "https://github.com/adobe/helix-onedrive-support#readme",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@adobe/fetch": "4.0
|
|
30
|
+
"@adobe/fetch": "4.1.0",
|
|
31
31
|
"@adobe/helix-shared-tokencache": "1.3.7",
|
|
32
32
|
"@azure/msal-node": "2.1.0",
|
|
33
33
|
"jose": "4.14.6"
|
package/src/OneDrive.js
CHANGED
|
@@ -116,6 +116,14 @@ export class OneDrive {
|
|
|
116
116
|
return this._log;
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
+
get workbookSessionId() {
|
|
120
|
+
return this._sessionId;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
setWorkbookSessionId(workbookSessionId) {
|
|
124
|
+
this._sessionId = workbookSessionId;
|
|
125
|
+
}
|
|
126
|
+
|
|
119
127
|
/**
|
|
120
128
|
*/
|
|
121
129
|
async doFetch(relUrl, rawResponseBody = false, options = {}) {
|
|
@@ -126,6 +134,9 @@ export class OneDrive {
|
|
|
126
134
|
}
|
|
127
135
|
opts.headers.authorization = `Bearer ${accessToken}`;
|
|
128
136
|
|
|
137
|
+
if (this._sessionId) {
|
|
138
|
+
opts.headers['Workbook-Session-Id'] = this._sessionId;
|
|
139
|
+
}
|
|
129
140
|
const { log, auth: { logFields, tenant } } = this;
|
|
130
141
|
const url = `https://graph.microsoft.com/v1.0${relUrl}`;
|
|
131
142
|
const method = opts.method || 'GET';
|
package/src/OneDriveMock.js
CHANGED
|
@@ -111,8 +111,13 @@ function handleTable(container, segs, method, body) {
|
|
|
111
111
|
}
|
|
112
112
|
const subCommand = segs.shift();
|
|
113
113
|
if (subCommand === 'add') {
|
|
114
|
-
|
|
115
|
-
|
|
114
|
+
if (body.index && body.index >= 0) {
|
|
115
|
+
table.rows.splice(body.index, 0, ...body.values);
|
|
116
|
+
return { index: body.index };
|
|
117
|
+
} else {
|
|
118
|
+
table.rows.push(...body.values);
|
|
119
|
+
return { index: table.rows.length - 1 };
|
|
120
|
+
}
|
|
116
121
|
}
|
|
117
122
|
index = parseInt(subCommand.replace(/itemAt\(index=([0-9]+)\)/, '$1'), 10);
|
|
118
123
|
if (index < 0 || index >= table.rows.length) {
|
|
@@ -375,6 +380,12 @@ export class OneDriveMock extends OneDrive {
|
|
|
375
380
|
} else {
|
|
376
381
|
return { value: data.sheets.map((st) => ({ name: st.name })) };
|
|
377
382
|
}
|
|
383
|
+
} else if (segs[0] === 'createSession') {
|
|
384
|
+
return {
|
|
385
|
+
id: 'test-session-id',
|
|
386
|
+
};
|
|
387
|
+
} else if (segs[0] === 'refreshSession' || segs[0] === 'closeSession') {
|
|
388
|
+
return {};
|
|
378
389
|
}
|
|
379
390
|
|
|
380
391
|
// handle the operations on the workbook / worksheet
|
package/src/excel/Table.d.ts
CHANGED
|
@@ -56,9 +56,10 @@ export declare interface Table {
|
|
|
56
56
|
/**
|
|
57
57
|
* Add a row to the table
|
|
58
58
|
* @param values values for new row
|
|
59
|
+
* @param index zero-based index or missing to add at end
|
|
59
60
|
* @returns zero-based index of new row
|
|
60
61
|
*/
|
|
61
|
-
addRow(values: string[]): Promise<number>;
|
|
62
|
+
addRow(values: string[], index?: number): Promise<number>;
|
|
62
63
|
|
|
63
64
|
/**
|
|
64
65
|
* Replace a row in the table
|
package/src/excel/Table.js
CHANGED
|
@@ -71,16 +71,16 @@ export class Table {
|
|
|
71
71
|
return result.values[0];
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
async addRow(values) {
|
|
75
|
-
const result = await this.addRows([values]);
|
|
74
|
+
async addRow(values, index = null) {
|
|
75
|
+
const result = await this.addRows([values], index);
|
|
76
76
|
return result;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
async addRows(values) {
|
|
79
|
+
async addRows(values, index = null) {
|
|
80
80
|
const result = await this._oneDrive.doFetch(`${this.uri}/rows/add`, false, {
|
|
81
81
|
method: 'POST',
|
|
82
82
|
body: {
|
|
83
|
-
index
|
|
83
|
+
index,
|
|
84
84
|
values,
|
|
85
85
|
},
|
|
86
86
|
});
|
package/src/excel/Workbook.d.ts
CHANGED
|
@@ -93,4 +93,25 @@ export declare interface Workbook {
|
|
|
93
93
|
* @param name name
|
|
94
94
|
*/
|
|
95
95
|
deleteNamedItem(name: string): Promise<void>;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* creates a new session
|
|
99
|
+
*/
|
|
100
|
+
createSession(): Promise<string>;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* closes the session
|
|
104
|
+
*/
|
|
105
|
+
closeSession(): Promise<void>;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* refreshes the session
|
|
109
|
+
*/
|
|
110
|
+
refreshSession(): Promise<void>;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Sets the sessionId of the workbook
|
|
114
|
+
* @param sessionId
|
|
115
|
+
*/
|
|
116
|
+
setSessionId(sessionId: string): void;
|
|
96
117
|
}
|
package/src/excel/Workbook.js
CHANGED
|
@@ -38,6 +38,47 @@ export class Workbook extends NamedItemContainer {
|
|
|
38
38
|
return new Worksheet(this._oneDrive, `${this._uri}/worksheets`, name, this._log);
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
async createSession() {
|
|
42
|
+
const sessionId = this._oneDrive.workbookSessionId;
|
|
43
|
+
if (sessionId) {
|
|
44
|
+
return sessionId;
|
|
45
|
+
} else {
|
|
46
|
+
const uri = `${this.uri}/createSession`;
|
|
47
|
+
const result = await this._oneDrive.doFetch(uri, false, {
|
|
48
|
+
method: 'POST',
|
|
49
|
+
});
|
|
50
|
+
this._oneDrive.setWorkbookSessionId(result.id);
|
|
51
|
+
return result.id;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async closeSession() {
|
|
56
|
+
if (this._oneDrive.workbookSessionId) {
|
|
57
|
+
const uri = `${this.uri}/closeSession`;
|
|
58
|
+
await this._oneDrive.doFetch(uri, false, {
|
|
59
|
+
method: 'POST',
|
|
60
|
+
});
|
|
61
|
+
this._oneDrive.setWorkbookSessionId(null);
|
|
62
|
+
} else {
|
|
63
|
+
throw new StatusCodeError('Please create a session first!', 400);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async refreshSession() {
|
|
68
|
+
if (this._oneDrive.workbookSessionId) {
|
|
69
|
+
const uri = `${this.uri}/refreshSession`;
|
|
70
|
+
await this._oneDrive.doFetch(uri, false, {
|
|
71
|
+
method: 'POST',
|
|
72
|
+
});
|
|
73
|
+
} else {
|
|
74
|
+
throw new StatusCodeError('Please create a session first!', 400);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
setSessionId(sessionId) {
|
|
79
|
+
this._oneDrive.setWorkbookSessionId(sessionId);
|
|
80
|
+
}
|
|
81
|
+
|
|
41
82
|
async createWorksheet(sheetName) {
|
|
42
83
|
const uri = `${this.uri}/worksheets`;
|
|
43
84
|
await this._oneDrive.doFetch(uri, false, {
|