@adobe/helix-onedrive-support 7.1.4 → 8.0.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.
Files changed (41) hide show
  1. package/.eslintrc.cjs +33 -0
  2. package/.husky/pre-commit +4 -0
  3. package/.jsdoc.json +4 -2
  4. package/.nycrc.json +4 -3
  5. package/.releaserc.cjs +16 -0
  6. package/CHANGELOG.md +21 -0
  7. package/docs/API.md +106 -341
  8. package/package.json +17 -17
  9. package/src/OneDrive.d.ts +4 -72
  10. package/src/OneDrive.js +62 -326
  11. package/src/OneDriveAuth.d.ts +98 -0
  12. package/src/OneDriveAuth.js +310 -0
  13. package/src/OneDriveMock.js +19 -12
  14. package/src/SharePointSite.js +5 -7
  15. package/src/StatusCodeError.js +2 -4
  16. package/src/cache/FSCacheManager.d.ts +28 -0
  17. package/src/cache/FSCacheManager.js +77 -0
  18. package/src/cache/FSCachePlugin.d.ts +29 -0
  19. package/src/cache/FSCachePlugin.js +70 -0
  20. package/src/cache/MemCachePlugin.d.ts +34 -0
  21. package/src/cache/MemCachePlugin.js +88 -0
  22. package/src/cache/S3CacheManager.d.ts +40 -0
  23. package/src/cache/S3CacheManager.js +107 -0
  24. package/src/cache/S3CachePlugin.d.ts +49 -0
  25. package/src/cache/S3CachePlugin.js +116 -0
  26. package/src/cache/encrypt.js +70 -0
  27. package/src/{NamedItem.d.ts → excel/NamedItem.d.ts} +0 -0
  28. package/src/{NamedItemContainer.js → excel/NamedItemContainer.js} +3 -5
  29. package/src/{Range.d.ts → excel/Range.d.ts} +2 -2
  30. package/src/{Range.js → excel/Range.js} +3 -5
  31. package/src/{Table.d.ts → excel/Table.d.ts} +2 -2
  32. package/src/{Table.js → excel/Table.js} +3 -5
  33. package/src/{Workbook.d.ts → excel/Workbook.d.ts} +2 -2
  34. package/src/{Workbook.js → excel/Workbook.js} +5 -10
  35. package/src/{Worksheet.d.ts → excel/Worksheet.d.ts} +4 -4
  36. package/src/{Worksheet.js → excel/Worksheet.js} +5 -10
  37. package/src/index.d.ts +14 -5
  38. package/src/index.js +9 -7
  39. package/src/package.cjs +12 -0
  40. package/src/utils.js +95 -45
  41. package/src/fuzzy-helper.js +0 -89
package/.eslintrc.cjs ADDED
@@ -0,0 +1,33 @@
1
+ /*
2
+ * Copyright 2019 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ module.exports = {
14
+ root: true,
15
+ extends: '@adobe/helix',
16
+ env: {
17
+ node: true,
18
+ es6: true,
19
+ },
20
+ parserOptions: {
21
+ sourceType: 'module',
22
+ ecmaVersion: 2020,
23
+ },
24
+ rules: {
25
+ 'import/extensions': [2, 'ignorePackages'],
26
+ 'import/prefer-default-export': 0,
27
+ 'no-param-reassign': ['error', { props: false }],
28
+ },
29
+ globals: {
30
+ __rootdir: true,
31
+ __testdir: true,
32
+ },
33
+ };
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+ . "$(dirname "$0")/_/husky.sh"
3
+
4
+ npx lint-staged
package/.jsdoc.json CHANGED
@@ -1,5 +1,7 @@
1
1
  {
2
- "plugins": [],
2
+ "plugins": [
3
+ "node_modules/jsdoc-tsimport-plugin/index.js"
4
+ ],
3
5
  "recurseDepth": 10,
4
6
  "source": {
5
7
  "includePattern": ".+\\.js(doc|x)?$",
@@ -14,4 +16,4 @@
14
16
  "cleverLinks": false,
15
17
  "monospaceLinks": false
16
18
  }
17
- }
19
+ }
package/.nycrc.json CHANGED
@@ -4,7 +4,8 @@
4
4
  "text"
5
5
  ],
6
6
  "check-coverage": true,
7
- "lines": 83,
8
- "branches": 77,
9
- "statements": 83
7
+ "statements": 87,
8
+ "branches": 80,
9
+ "functions": 87,
10
+ "lines": 87
10
11
  }
package/.releaserc.cjs ADDED
@@ -0,0 +1,16 @@
1
+ module.exports = {
2
+ plugins: [
3
+ "@semantic-release/commit-analyzer",
4
+ "@semantic-release/release-notes-generator",
5
+ ["@semantic-release/changelog", {
6
+ "changelogFile": "CHANGELOG.md",
7
+ }],
8
+ "@semantic-release/npm",
9
+ ["@semantic-release/git", {
10
+ "assets": ["package.json", "CHANGELOG.md"],
11
+ "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
12
+ }],
13
+ ["@semantic-release/github", {}]
14
+ ],
15
+ branches: ['main']
16
+ };
package/CHANGELOG.md CHANGED
@@ -1,3 +1,24 @@
1
+ # [8.0.0](https://github.com/adobe/helix-onedrive-support/compare/v7.1.4...v8.0.0) (2022-05-03)
2
+
3
+
4
+ ### Features
5
+
6
+ * use msal-node ([a6dca62](https://github.com/adobe/helix-onedrive-support/commit/a6dca6215af57d9ea5ad830003d0192a67b91bff)), closes [#180](https://github.com/adobe/helix-onedrive-support/issues/180)
7
+
8
+
9
+ ### BREAKING CHANGES
10
+
11
+ * Major refactoring
12
+ - ESM only
13
+ - new OneDriveAuth class handling all authentication
14
+ - OneDrive no longer takes auth specific options; use OneDriveAuth instead
15
+ - username/password authentication no longer supported
16
+
17
+ Feature:
18
+
19
+ - Authentication cache (store) is now pluggable
20
+ - Memory, Filesystem and S3 based cache plugins available
21
+
1
22
  ## [7.1.4](https://github.com/adobe/helix-onedrive-support/compare/v7.1.3...v7.1.4) (2022-04-30)
2
23
 
3
24
 
package/docs/API.md CHANGED
@@ -4,18 +4,38 @@
4
4
  <dt><a href="#OneDrive">OneDrive</a></dt>
5
5
  <dd><p>Helper class that facilitates accessing one drive.</p>
6
6
  </dd>
7
+ <dt><a href="#OneDriveAuth">OneDriveAuth</a></dt>
8
+ <dd><p>Helper class that facilitates accessing one drive.</p>
9
+ </dd>
7
10
  <dt><a href="#OneDriveMock">OneDriveMock</a></dt>
8
11
  <dd><p>Mock OneDrive client that supports some of the operations the <code>OneDrive</code> class does.</p>
9
12
  </dd>
13
+ <dt><a href="#SharePointSite">SharePointSite</a></dt>
14
+ <dd><p>Helper class accessing folders and files using the SharePoint V1 API.</p>
15
+ </dd>
16
+ </dl>
17
+
18
+ ## Constants
19
+
20
+ <dl>
21
+ <dt><a href="#globalTenantCache">globalTenantCache</a> : <code>Map.&lt;string, string&gt;</code></dt>
22
+ <dd><p>map that caches the tenant ids</p>
23
+ </dd>
10
24
  </dl>
11
25
 
12
26
  ## Functions
13
27
 
14
28
  <dl>
29
+ <dt><a href="#handleNamedItems">handleNamedItems(sheet, segs, method, body)</a> ⇒ <code>object</code></dt>
30
+ <dd><p>Handle the <code>namedItems</code> operation on a workbook / worksheet</p>
31
+ </dd>
32
+ <dt><a href="#handleTable">handleTable(sheet, segs, method, body)</a> ⇒ <code>object</code></dt>
33
+ <dd><p>Handle the <code>table</code> operation on a workbook / worksheet</p>
34
+ </dd>
15
35
  <dt><a href="#splitByExtension">splitByExtension(name)</a> ⇒ <code>Array.&lt;string&gt;</code></dt>
16
36
  <dd><p>Splits the given name at the last &#39;.&#39;, returning the extension and the base name.</p>
17
37
  </dd>
18
- <dt><a href="#sanitize">sanitize(name)</a> ⇒ <code>string</code></dt>
38
+ <dt><a href="#sanitizeName">sanitizeName(name)</a> ⇒ <code>string</code></dt>
19
39
  <dd><p>Sanitizes the given string by :</p>
20
40
  <ul>
21
41
  <li>convert to lower case</li>
@@ -25,320 +45,77 @@
25
45
  <li>remove all leading and trailing dashes</li>
26
46
  </ul>
27
47
  </dd>
48
+ <dt><a href="#sanitizePath">sanitizePath(filepath, opts)</a> ⇒ <code>string</code></dt>
49
+ <dd><p>Sanitizes the file path by:</p>
50
+ <ul>
51
+ <li>convert to lower case</li>
52
+ <li>normalize all unicode characters</li>
53
+ <li>replace all non-alphanumeric characters with a dash</li>
54
+ <li>remove all consecutive dashes</li>
55
+ <li>remove all leading and trailing dashes</li>
56
+ </ul>
57
+ <p>Note that only the basename of the file path is sanitized. i.e. The ancestor path and the
58
+ extension is not affected.</p>
59
+ </dd>
28
60
  <dt><a href="#editDistance">editDistance(s0, s1)</a> ⇒ <code>number</code> | <code>*</code></dt>
29
61
  <dd><p>Compute the edit distance using a recursive algorithm. since we only expect to have relative
30
62
  short filenames, the algorithm shouldn&#39;t be too expensive.</p>
31
63
  </dd>
32
- <dt><a href="#handleNamedItems">handleNamedItems(sheet, segs, method, body)</a> ⇒ <code>object</code></dt>
33
- <dd><p>Handle the <code>namedItems</code> operation on a workbook / worksheet</p>
34
- </dd>
35
- <dt><a href="#handleTable">handleTable(sheet, segs, method, body)</a> ⇒ <code>object</code></dt>
36
- <dd><p>Handle the <code>table</code> operation on a workbook / worksheet</p>
37
- </dd>
38
- <dt><a href="#driveItemToURL">driveItemToURL(driveItem)</a> <code>URL</code></dt>
39
- <dd><p>Returns a onedrive uri for the given drive item. the uri has the format:
40
- <code>onedrive:/drives/&lt;driveId&gt;/items/&lt;itemId&gt;</code></p>
41
- </dd>
42
- <dt><a href="#driveItemFromURL">driveItemFromURL(url)</a> ⇒ <code>DriveItem</code></dt>
43
- <dd><p>Returns a partial drive item from the given url. The urls needs to have the format:
44
- <code>onedrive:/drives/&lt;driveId&gt;/items/&lt;itemId&gt;</code>. if the url does not start with the correct
45
- protocol, {@code null} is returned.</p>
64
+ <dt><a href="#superTrim">superTrim(str)</a> ⇒ <code>string</code></dt>
65
+ <dd><p>Trims the string at both ends and removes the zero width unicode chars:</p>
66
+ <ul>
67
+ <li>U+200B zero width space</li>
68
+ <li>U+200C zero width non-joiner Unicode code point</li>
69
+ <li>U+200D zero width joiner Unicode code point</li>
70
+ <li>U+FEFF zero width no-break space Unicode code point</li>
71
+ </ul>
46
72
  </dd>
47
73
  </dl>
48
74
 
49
- <a name="OneDrive"></a>
50
-
51
- ## OneDrive
52
- Helper class that facilitates accessing one drive.
53
-
54
- **Kind**: global class
55
-
56
- * [OneDrive](#OneDrive)
57
- * [new OneDrive(opts)](#new_OneDrive_new)
58
- * _instance_
59
- * [.log](#OneDrive+log)
60
- * [.authenticated](#OneDrive+authenticated) ⇒ <code>boolean</code>
61
- * [.dispose()](#OneDrive+dispose)
62
- * [.loadTokenCache(entries)](#OneDrive+loadTokenCache) ⇒
63
- * [.login()](#OneDrive+login) ⇒ <code>Promise.&lt;TokenResponse&gt;</code>
64
- * [.getAccessToken()](#OneDrive+getAccessToken)
65
- * [.createLoginUrl()](#OneDrive+createLoginUrl)
66
- * [.acquireToken()](#OneDrive+acquireToken)
67
- * [.doFetch()](#OneDrive+doFetch)
68
- * [.resolveShareLink()](#OneDrive+resolveShareLink)
69
- * [.getDriveRootItem()](#OneDrive+getDriveRootItem)
70
- * [.getDriveItemFromShareLink()](#OneDrive+getDriveItemFromShareLink)
71
- * [.listChildren()](#OneDrive+listChildren)
72
- * [.fuzzyGetDriveItem(folderItem, relPath)](#OneDrive+fuzzyGetDriveItem) ⇒ <code>Promise.&lt;Array.&lt;DriveItem&gt;&gt;</code>
73
- * [.getDriveItem()](#OneDrive+getDriveItem)
74
- * [.downloadDriveItem()](#OneDrive+downloadDriveItem)
75
- * [.uploadDriveItem()](#OneDrive+uploadDriveItem)
76
- * [.getWorkbook()](#OneDrive+getWorkbook)
77
- * [.listSubscriptions()](#OneDrive+listSubscriptions)
78
- * [.createSubscription()](#OneDrive+createSubscription)
79
- * [.refreshSubscription()](#OneDrive+refreshSubscription)
80
- * [.deleteSubscription()](#OneDrive+deleteSubscription)
81
- * [.fetchChanges(resource, [token])](#OneDrive+fetchChanges) ⇒ <code>Promise.&lt;Array&gt;</code>
82
- * _static_
83
- * [.MAX_SUBSCRIPTION_EXPIRATION_TIME](#OneDrive.MAX_SUBSCRIPTION_EXPIRATION_TIME)
84
- * [.encodeSharingUrl(sharingUrl)](#OneDrive.encodeSharingUrl) ⇒ <code>string</code>
85
-
86
- <a name="new_OneDrive_new"></a>
87
-
88
- ### new OneDrive(opts)
89
-
90
- | Param | Type | Description |
91
- | --- | --- | --- |
92
- | opts | <code>OneDriveOptions</code> | Options |
93
- | opts.clientId | <code>string</code> | The client id of the app |
94
- | [opts.clientSecret] | <code>string</code> | The client secret of the app |
95
- | [opts.refreshToken] | <code>string</code> | The refresh token. |
96
- | [opts.accessToken] | <code>string</code> | The access token. |
97
- | [opts.username] | <code>string</code> | Username for username/password authentication. |
98
- | [opts.password] | <code>string</code> | Password for username/password authentication. |
99
- | [opts.expiresOn] | <code>number</code> | Expiration time. |
100
- | [opts.log] | <code>Logger</code> | A logger. |
101
-
102
- <a name="OneDrive+log"></a>
103
-
104
- ### oneDrive.log
105
- **Kind**: instance property of [<code>OneDrive</code>](#OneDrive)
106
- <a name="OneDrive+authenticated"></a>
107
-
108
- ### oneDrive.authenticated ⇒ <code>boolean</code>
109
- **Kind**: instance property of [<code>OneDrive</code>](#OneDrive)
110
- <a name="OneDrive+dispose"></a>
111
-
112
- ### oneDrive.dispose()
113
- **Kind**: instance method of [<code>OneDrive</code>](#OneDrive)
114
- <a name="OneDrive+loadTokenCache"></a>
115
-
116
- ### oneDrive.loadTokenCache(entries) ⇒
117
- Adds entries to the token cache
118
-
119
- **Kind**: instance method of [<code>OneDrive</code>](#OneDrive)
120
- **Returns**: this;
121
-
122
- | Param | Type |
123
- | --- | --- |
124
- | entries | <code>Array.&lt;TokenResponse&gt;</code> |
125
-
126
- <a name="OneDrive+login"></a>
127
-
128
- ### oneDrive.login() ⇒ <code>Promise.&lt;TokenResponse&gt;</code>
129
- Performs a login using an interactive flow which prompts the user to open a browser window and
130
- enter the authorization code.
131
-
132
- **Kind**: instance method of [<code>OneDrive</code>](#OneDrive)
133
- **Params**: <code>function</code> [onCode] - optional function that gets invoked after code was retrieved.
134
- <a name="OneDrive+getAccessToken"></a>
135
-
136
- ### oneDrive.getAccessToken()
137
- **Kind**: instance method of [<code>OneDrive</code>](#OneDrive)
138
- <a name="OneDrive+createLoginUrl"></a>
139
-
140
- ### oneDrive.createLoginUrl()
141
- **Kind**: instance method of [<code>OneDrive</code>](#OneDrive)
142
- <a name="OneDrive+acquireToken"></a>
143
-
144
- ### oneDrive.acquireToken()
145
- **Kind**: instance method of [<code>OneDrive</code>](#OneDrive)
146
- <a name="OneDrive+doFetch"></a>
147
-
148
- ### oneDrive.doFetch()
149
- **Kind**: instance method of [<code>OneDrive</code>](#OneDrive)
150
- <a name="OneDrive+resolveShareLink"></a>
151
-
152
- ### oneDrive.resolveShareLink()
153
- **Kind**: instance method of [<code>OneDrive</code>](#OneDrive)
154
- <a name="OneDrive+getDriveRootItem"></a>
155
-
156
- ### oneDrive.getDriveRootItem()
157
- **Kind**: instance method of [<code>OneDrive</code>](#OneDrive)
158
- <a name="OneDrive+getDriveItemFromShareLink"></a>
159
-
160
- ### oneDrive.getDriveItemFromShareLink()
161
- **Kind**: instance method of [<code>OneDrive</code>](#OneDrive)
162
- <a name="OneDrive+listChildren"></a>
163
-
164
- ### oneDrive.listChildren()
165
- **Kind**: instance method of [<code>OneDrive</code>](#OneDrive)
166
- <a name="OneDrive+fuzzyGetDriveItem"></a>
167
-
168
- ### oneDrive.fuzzyGetDriveItem(folderItem, relPath) ⇒ <code>Promise.&lt;Array.&lt;DriveItem&gt;&gt;</code>
169
- Tries to get the drive items for the given folder and relative path, by loading the files of
170
- the respective directory and returning the item with the best matching filename. Please note,
171
- that only the files are matched 'fuzzily' but not the folders. The rules for transforming the
172
- filenames to the name segment of the `relPath` are:
173
- - convert to lower case
174
- - replace all non-alphanumeric characters with a dash
175
- - remove all consecutive dashes
176
- - extensions are ignored, if the given path doesn't have one
177
-
178
- The result is an array of drive items that match the given path. They are ordered by the edit
179
- distance to the original name and then alphanumerically.
180
-
181
- **Kind**: instance method of [<code>OneDrive</code>](#OneDrive)
182
-
183
- | Param | Type |
184
- | --- | --- |
185
- | folderItem | <code>DriveItem</code> |
186
- | relPath | <code>string</code> |
187
-
188
- <a name="OneDrive+getDriveItem"></a>
189
-
190
- ### oneDrive.getDriveItem()
191
- **Kind**: instance method of [<code>OneDrive</code>](#OneDrive)
192
- <a name="OneDrive+downloadDriveItem"></a>
193
-
194
- ### oneDrive.downloadDriveItem()
195
- **Kind**: instance method of [<code>OneDrive</code>](#OneDrive)
196
- <a name="OneDrive+uploadDriveItem"></a>
197
-
198
- ### oneDrive.uploadDriveItem()
199
- **Kind**: instance method of [<code>OneDrive</code>](#OneDrive)
200
- **See**: https://docs.microsoft.com/en-us/graph/api/driveitem-put-content?view=graph-rest-1.0&tabs=http
201
- <a name="OneDrive+getWorkbook"></a>
202
-
203
- ### oneDrive.getWorkbook()
204
- **Kind**: instance method of [<code>OneDrive</code>](#OneDrive)
205
- <a name="OneDrive+listSubscriptions"></a>
206
-
207
- ### oneDrive.listSubscriptions()
208
- **Kind**: instance method of [<code>OneDrive</code>](#OneDrive)
209
- <a name="OneDrive+createSubscription"></a>
210
-
211
- ### oneDrive.createSubscription()
212
- **Kind**: instance method of [<code>OneDrive</code>](#OneDrive)
213
- <a name="OneDrive+refreshSubscription"></a>
214
-
215
- ### oneDrive.refreshSubscription()
216
- **Kind**: instance method of [<code>OneDrive</code>](#OneDrive)
217
- <a name="OneDrive+deleteSubscription"></a>
218
-
219
- ### oneDrive.deleteSubscription()
220
- **Kind**: instance method of [<code>OneDrive</code>](#OneDrive)
221
- <a name="OneDrive+fetchChanges"></a>
222
-
223
- ### oneDrive.fetchChanges(resource, [token]) ⇒ <code>Promise.&lt;Array&gt;</code>
224
- Fetches the changes from the respective resource using the provided delta token.
225
- Use an empty token to fetch the initial state or `latest` to fetch the latest state.
226
-
227
- **Kind**: instance method of [<code>OneDrive</code>](#OneDrive)
228
- **Returns**: <code>Promise.&lt;Array&gt;</code> - An object with an array of changes and a delta token.
229
-
230
- | Param | Type | Description |
231
- | --- | --- | --- |
232
- | resource | <code>string</code> | OneDrive resource path. |
233
- | [token] | <code>string</code> | Delta token. |
234
-
235
- <a name="OneDrive.MAX_SUBSCRIPTION_EXPIRATION_TIME"></a>
236
-
237
- ### OneDrive.MAX\_SUBSCRIPTION\_EXPIRATION\_TIME
238
- the maximum subscription time in milliseconds
239
-
240
- **Kind**: static constant of [<code>OneDrive</code>](#OneDrive)
241
- **See**: https://docs.microsoft.com/en-us/graph/api/resources/subscription?view=graph-rest-1.0#maximum-length-of-subscription-per-resource-type
242
- <a name="OneDrive.encodeSharingUrl"></a>
243
-
244
- ### OneDrive.encodeSharingUrl(sharingUrl) ⇒ <code>string</code>
245
- Encodes the sharing url into a token that can be used to access drive items.
246
-
247
- **Kind**: static method of [<code>OneDrive</code>](#OneDrive)
248
- **Returns**: <code>string</code> - an id for a shared item.
249
- **See**: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/shares_get?view=odsp-graph-online#encoding-sharing-urls
250
-
251
- | Param | Type | Description |
252
- | --- | --- | --- |
253
- | sharingUrl | <code>string</code> | A sharing URL from OneDrive |
75
+ ## Typedefs
254
76
 
255
- <a name="OneDriveMock"></a>
256
-
257
- ## OneDriveMock
258
- Mock OneDrive client that supports some of the operations the `OneDrive` class does.
259
-
260
- **Kind**: global class
261
-
262
- * [OneDriveMock](#OneDriveMock)
263
- * [.registerWorkbook(driveId, itemId, data)](#OneDriveMock+registerWorkbook) ⇒ [<code>OneDriveMock</code>](#OneDriveMock)
264
- * [.registerDriveItem(driveId, itemId, data)](#OneDriveMock+registerDriveItem) ⇒ [<code>OneDriveMock</code>](#OneDriveMock)
265
- * [.registerDriveItemChildren(driveId, itemId, data)](#OneDriveMock+registerDriveItemChildren) ⇒ [<code>OneDriveMock</code>](#OneDriveMock)
266
- * [.registerShareLink(uri, driveId, itemId)](#OneDriveMock+registerShareLink) ⇒ [<code>OneDriveMock</code>](#OneDriveMock)
267
- * [.getDriveItemFromShareLink()](#OneDriveMock+getDriveItemFromShareLink)
268
- * [.getWorkbook()](#OneDriveMock+getWorkbook)
269
- * [.doFetch()](#OneDriveMock+doFetch)
270
-
271
- <a name="OneDriveMock+registerWorkbook"></a>
272
-
273
- ### oneDriveMock.registerWorkbook(driveId, itemId, data) ⇒ [<code>OneDriveMock</code>](#OneDriveMock)
274
- Register a mock workbook.
275
-
276
- **Kind**: instance method of [<code>OneDriveMock</code>](#OneDriveMock)
277
- **Returns**: [<code>OneDriveMock</code>](#OneDriveMock) - this
278
-
279
- | Param | Type | Description |
280
- | --- | --- | --- |
281
- | driveId | <code>string</code> | The drive id |
282
- | itemId | <code>string</code> | the item id |
283
- | data | <code>object</code> | Mock workbook data |
284
-
285
- <a name="OneDriveMock+registerDriveItem"></a>
286
-
287
- ### oneDriveMock.registerDriveItem(driveId, itemId, data) ⇒ [<code>OneDriveMock</code>](#OneDriveMock)
288
- Registers a mock drive item
77
+ <dl>
78
+ <dt><a href="#AuthenticationResult">AuthenticationResult</a> : <code>module:@azure/msal-node~AuthenticationResult</code></dt>
79
+ <dd><p>aliases</p>
80
+ </dd>
81
+ </dl>
289
82
 
290
- **Kind**: instance method of [<code>OneDriveMock</code>](#OneDriveMock)
291
- **Returns**: [<code>OneDriveMock</code>](#OneDriveMock) - this
83
+ <a name="globalTenantCache"></a>
292
84
 
293
- | Param | Type | Description |
294
- | --- | --- | --- |
295
- | driveId | <code>string</code> | The drive id |
296
- | itemId | <code>string</code> | the item id |
297
- | data | <code>object</code> | Mock item data |
85
+ ## globalTenantCache : <code>Map.&lt;string, string&gt;</code>
86
+ map that caches the tenant ids
298
87
 
299
- <a name="OneDriveMock+registerDriveItemChildren"></a>
88
+ **Kind**: global constant
89
+ <a name="handleNamedItems"></a>
300
90
 
301
- ### oneDriveMock.registerDriveItemChildren(driveId, itemId, data) ⇒ [<code>OneDriveMock</code>](#OneDriveMock)
302
- Registers a mock drive item child list
91
+ ## handleNamedItems(sheet, segs, method, body) ⇒ <code>object</code>
92
+ Handle the `namedItems` operation on a workbook / worksheet
303
93
 
304
- **Kind**: instance method of [<code>OneDriveMock</code>](#OneDriveMock)
305
- **Returns**: [<code>OneDriveMock</code>](#OneDriveMock) - this
94
+ **Kind**: global function
95
+ **Returns**: <code>object</code> - The response value
306
96
 
307
97
  | Param | Type | Description |
308
98
  | --- | --- | --- |
309
- | driveId | <code>string</code> | The drive id |
310
- | itemId | <code>string</code> | the item id |
311
- | data | <code>object</code> | Mock item data |
99
+ | sheet | <code>object</code> | The mock data |
100
+ | segs | <code>Array.&lt;string&gt;</code> | Array of path segments |
101
+ | method | <code>string</code> | Request method |
102
+ | body | <code>object</code> | Request body |
312
103
 
313
- <a name="OneDriveMock+registerShareLink"></a>
104
+ <a name="handleTable"></a>
314
105
 
315
- ### oneDriveMock.registerShareLink(uri, driveId, itemId) ⇒ [<code>OneDriveMock</code>](#OneDriveMock)
316
- Register a mock sharelink.
106
+ ## handleTable(sheet, segs, method, body) ⇒ <code>object</code>
107
+ Handle the `table` operation on a workbook / worksheet
317
108
 
318
- **Kind**: instance method of [<code>OneDriveMock</code>](#OneDriveMock)
319
- **Returns**: [<code>OneDriveMock</code>](#OneDriveMock) - this;
109
+ **Kind**: global function
110
+ **Returns**: <code>object</code> - The response value
320
111
 
321
112
  | Param | Type | Description |
322
113
  | --- | --- | --- |
323
- | uri | <code>string</code> | The sharelink uri |
324
- | driveId | <code>string</code> | The drive id |
325
- | itemId | <code>string</code> | The the item id |
326
-
327
- <a name="OneDriveMock+getDriveItemFromShareLink"></a>
328
-
329
- ### oneDriveMock.getDriveItemFromShareLink()
330
- **Kind**: instance method of [<code>OneDriveMock</code>](#OneDriveMock)
331
- **See**: OneDrive#getDriveItemFromShareLink
332
- <a name="OneDriveMock+getWorkbook"></a>
333
-
334
- ### oneDriveMock.getWorkbook()
335
- **Kind**: instance method of [<code>OneDriveMock</code>](#OneDriveMock)
336
- **See**: OneDrive#getWorkbook
337
- <a name="OneDriveMock+doFetch"></a>
114
+ | sheet | <code>object</code> | The mock data |
115
+ | segs | <code>Array.&lt;string&gt;</code> | Array of path segments |
116
+ | method | <code>string</code> | Request method |
117
+ | body | <code>object</code> | Request body |
338
118
 
339
- ### oneDriveMock.doFetch()
340
- **Kind**: instance method of [<code>OneDriveMock</code>](#OneDriveMock)
341
- **See**: OneDrive#doFetch
342
119
  <a name="splitByExtension"></a>
343
120
 
344
121
  ## splitByExtension(name) ⇒ <code>Array.&lt;string&gt;</code>
@@ -351,9 +128,9 @@ Splits the given name at the last '.', returning the extension and the base name
351
128
  | --- | --- | --- |
352
129
  | name | <code>string</code> | Filename |
353
130
 
354
- <a name="sanitize"></a>
131
+ <a name="sanitizeName"></a>
355
132
 
356
- ## sanitize(name) ⇒ <code>string</code>
133
+ ## sanitizeName(name) ⇒ <code>string</code>
357
134
  Sanitizes the given string by :
358
135
  - convert to lower case
359
136
  - normalize all unicode characters
@@ -368,73 +145,61 @@ Sanitizes the given string by :
368
145
  | --- | --- |
369
146
  | name | <code>string</code> |
370
147
 
371
- <a name="editDistance"></a>
372
-
373
- ## editDistance(s0, s1) ⇒ <code>number</code> \| <code>\*</code>
374
- Compute the edit distance using a recursive algorithm. since we only expect to have relative
375
- short filenames, the algorithm shouldn't be too expensive.
376
-
377
- **Kind**: global function
148
+ <a name="sanitizePath"></a>
378
149
 
379
- | Param | Type | Description |
380
- | --- | --- | --- |
381
- | s0 | <code>string</code> | Input string |
382
- | s1 | <code>string</code> | Input string |
383
-
384
- <a name="handleNamedItems"></a>
150
+ ## sanitizePath(filepath, opts) <code>string</code>
151
+ Sanitizes the file path by:
152
+ - convert to lower case
153
+ - normalize all unicode characters
154
+ - replace all non-alphanumeric characters with a dash
155
+ - remove all consecutive dashes
156
+ - remove all leading and trailing dashes
385
157
 
386
- ## handleNamedItems(sheet, segs, method, body) <code>object</code>
387
- Handle the `namedItems` operation on a workbook / worksheet
158
+ Note that only the basename of the file path is sanitized. i.e. The ancestor path and the
159
+ extension is not affected.
388
160
 
389
161
  **Kind**: global function
390
- **Returns**: <code>object</code> - The response value
162
+ **Returns**: <code>string</code> - sanitized file path
391
163
 
392
164
  | Param | Type | Description |
393
165
  | --- | --- | --- |
394
- | sheet | <code>object</code> | The mock data |
395
- | segs | <code>Array.&lt;string&gt;</code> | Array of path segments |
396
- | method | <code>string</code> | Request method |
397
- | body | <code>object</code> | Request body |
166
+ | filepath | <code>string</code> | the file path |
167
+ | opts | <code>object</code> | Options |
168
+ | [opts.ignoreExtension] | <code>boolean</code> | if {@code true} ignores the extension |
398
169
 
399
- <a name="handleTable"></a>
170
+ <a name="editDistance"></a>
400
171
 
401
- ## handleTable(sheet, segs, method, body) ⇒ <code>object</code>
402
- Handle the `table` operation on a workbook / worksheet
172
+ ## editDistance(s0, s1) ⇒ <code>number</code> \| <code>\*</code>
173
+ Compute the edit distance using a recursive algorithm. since we only expect to have relative
174
+ short filenames, the algorithm shouldn't be too expensive.
403
175
 
404
176
  **Kind**: global function
405
- **Returns**: <code>object</code> - The response value
406
177
 
407
178
  | Param | Type | Description |
408
179
  | --- | --- | --- |
409
- | sheet | <code>object</code> | The mock data |
410
- | segs | <code>Array.&lt;string&gt;</code> | Array of path segments |
411
- | method | <code>string</code> | Request method |
412
- | body | <code>object</code> | Request body |
413
-
414
- <a name="driveItemToURL"></a>
415
-
416
- ## driveItemToURL(driveItem) ⇒ <code>URL</code>
417
- Returns a onedrive uri for the given drive item. the uri has the format:
418
- `onedrive:/drives/<driveId>/items/<itemId>`
419
-
420
- **Kind**: global function
421
- **Returns**: <code>URL</code> - An url representing the drive item
180
+ | s0 | <code>string</code> | Input string |
181
+ | s1 | <code>string</code> | Input string |
422
182
 
423
- | Param | Type |
424
- | --- | --- |
425
- | driveItem | <code>DriveItem</code> |
183
+ <a name="superTrim"></a>
426
184
 
427
- <a name="driveItemFromURL"></a>
185
+ ## superTrim(str) ⇒ <code>string</code>
186
+ Trims the string at both ends and removes the zero width unicode chars:
428
187
 
429
- ## driveItemFromURL(url) <code>DriveItem</code>
430
- Returns a partial drive item from the given url. The urls needs to have the format:
431
- `onedrive:/drives/<driveId>/items/<itemId>`. if the url does not start with the correct
432
- protocol, {@code null} is returned.
188
+ - U+200B zero width space
189
+ - U+200C zero width non-joiner Unicode code point
190
+ - U+200D zero width joiner Unicode code point
191
+ - U+FEFF zero width no-break space Unicode code point
433
192
 
434
193
  **Kind**: global function
435
- **Returns**: <code>DriveItem</code> - A (partial) drive item.
194
+ **Returns**: <code>string</code> - trimmed and stripped string
436
195
 
437
196
  | Param | Type | Description |
438
197
  | --- | --- | --- |
439
- | url | <code>URL</code> \| <code>string</code> | The url of the drive item. |
198
+ | str | <code>string</code> | input string |
199
+
200
+ <a name="AuthenticationResult"></a>
201
+
202
+ ## AuthenticationResult : <code>module:@azure/msal-node~AuthenticationResult</code>
203
+ aliases
440
204
 
205
+ **Kind**: global typedef