@adobe/helix-onedrive-support 7.1.4 → 8.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.
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 +35 -0
  7. package/docs/API.md +106 -341
  8. package/package.json +19 -19
  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 +15 -6
  39. package/src/package.cjs +12 -0
  40. package/src/utils.js +95 -45
  41. package/src/fuzzy-helper.js +0 -89
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright 2019 Adobe. All rights reserved.
2
+ * Copyright 2022 Adobe. All rights reserved.
3
3
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
4
  * you may not use this file except in compliance with the License. You may obtain a copy
5
5
  * of the License at http://www.apache.org/licenses/LICENSE-2.0
@@ -11,7 +11,7 @@
11
11
  */
12
12
  import { Table } from './Table';
13
13
  import { Worksheet } from './Worksheet';
14
- import { GraphResult } from './OneDrive';
14
+ import { GraphResult } from '../OneDrive';
15
15
  import { NamedItem } from './NamedItem';
16
16
 
17
17
  /**
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright 2020 Adobe. All rights reserved.
2
+ * Copyright 2022 Adobe. All rights reserved.
3
3
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
4
  * you may not use this file except in compliance with the License. You may obtain a copy
5
5
  * of the License at http://www.apache.org/licenses/LICENSE-2.0
@@ -9,14 +9,11 @@
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
+ import { NamedItemContainer } from './NamedItemContainer.js';
13
+ import { Table } from './Table.js';
14
+ import { Worksheet } from './Worksheet.js';
12
15
 
13
- 'use strict';
14
-
15
- const NamedItemContainer = require('./NamedItemContainer.js');
16
- const Table = require('./Table.js');
17
- const Worksheet = require('./Worksheet.js');
18
-
19
- class Workbook extends NamedItemContainer {
16
+ export class Workbook extends NamedItemContainer {
20
17
  constructor(oneDrive, uri, log) {
21
18
  super(oneDrive);
22
19
 
@@ -58,5 +55,3 @@ class Workbook extends NamedItemContainer {
58
55
  return this._log;
59
56
  }
60
57
  }
61
-
62
- module.exports = Workbook;
@@ -1,16 +1,16 @@
1
1
  /*
2
- * Copyright 2019 Adobe. All rights reserved.
3
- * This file is licensed to you under the Apache License, Version 2.0 (the 'License');
2
+ * Copyright 2022 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
4
  * you may not use this file except in compliance with the License. You may obtain a copy
5
5
  * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
6
  *
7
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
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
  import { NamedItem } from './NamedItem';
13
- import { GraphResult } from './OneDrive';
13
+ import { GraphResult } from '../OneDrive';
14
14
  import { Table } from './Table';
15
15
  import { Range } from './Range';
16
16
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright 2019 Adobe. All rights reserved.
2
+ * Copyright 2022 Adobe. All rights reserved.
3
3
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
4
  * you may not use this file except in compliance with the License. You may obtain a copy
5
5
  * of the License at http://www.apache.org/licenses/LICENSE-2.0
@@ -9,14 +9,11 @@
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
+ import { NamedItemContainer } from './NamedItemContainer.js';
13
+ import { Table } from './Table.js';
14
+ import { Range } from './Range.js';
12
15
 
13
- 'use strict';
14
-
15
- const NamedItemContainer = require('./NamedItemContainer.js');
16
- const Table = require('./Table.js');
17
- const Range = require('./Range.js');
18
-
19
- class Worksheet extends NamedItemContainer {
16
+ export class Worksheet extends NamedItemContainer {
20
17
  constructor(oneDrive, prefix, name, log) {
21
18
  super(oneDrive);
22
19
 
@@ -57,5 +54,3 @@ class Worksheet extends NamedItemContainer {
57
54
  return new Range(this._oneDrive, `${this._uri}/range(address='${address}')`, this._log);
58
55
  }
59
56
  }
60
-
61
- module.exports = Worksheet;
package/src/index.d.ts CHANGED
@@ -10,8 +10,17 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
  export * from './OneDrive';
13
- export * from './Workbook';
14
- export * from './Worksheet';
15
- export * from './NamedItem';
16
- export * from './Table';
17
- export * from './Range';
13
+ export * from './OneDriveAuth';
14
+ export * from './OneDriveMock';
15
+ export * from './StatusCodeError';
16
+ export * from './excel/Workbook';
17
+ export * from './excel/Worksheet';
18
+ export * from './excel/NamedItem';
19
+ export * from './excel/Table';
20
+ export * from './excel/Range';
21
+
22
+ export * from './cache/FSCacheManager';
23
+ export * from './cache/FSCachePlugin';
24
+ export * from './cache/MemCachePlugin';
25
+ export * from './cache/S3CacheManager';
26
+ export * from './cache/S3CachePlugin';
package/src/index.js CHANGED
@@ -9,10 +9,19 @@
9
9
  * OF ANY KIND, either express or implied. See the License for the specific language
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
- const OneDrive = require('./OneDrive.js');
13
- const OneDriveMock = require('./OneDriveMock.js');
12
+ export { OneDrive } from './OneDrive.js';
13
+ export { OneDriveAuth } from './OneDriveAuth.js';
14
14
 
15
- module.exports = {
16
- OneDrive,
17
- OneDriveMock,
18
- };
15
+ export { FSCachePlugin } from './cache/FSCachePlugin.js';
16
+ export { FSCacheManager } from './cache/FSCacheManager.js';
17
+ export { MemCachePlugin } from './cache/MemCachePlugin.js';
18
+ export { S3CachePlugin } from './cache/S3CachePlugin.js';
19
+ export { S3CacheManager } from './cache/S3CacheManager.js';
20
+ export { OneDriveMock } from './OneDriveMock.js';
21
+ export { StatusCodeError } from './StatusCodeError.js';
22
+
23
+ export { NamedItemContainer } from './excel/NamedItemContainer.js';
24
+ export { Range } from './excel/Range.js';
25
+ export { Table } from './excel/Table.js';
26
+ export { Workbook } from './excel/Workbook.js';
27
+ export { Worksheet } from './excel/Worksheet.js';
@@ -0,0 +1,12 @@
1
+ /*
2
+ * Copyright 2021 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
+ module.exports = require('../package.json');
package/src/utils.js CHANGED
@@ -11,66 +11,116 @@
11
11
  */
12
12
 
13
13
  /**
14
- * Trims the string at both ends and removes the zero width unicode chars:
15
- *
16
- * - U+200B zero width space
17
- * - U+200C zero width non-joiner Unicode code point
18
- * - U+200D zero width joiner Unicode code point
19
- * - U+FEFF zero width no-break space Unicode code point
14
+ * Splits the given name at the last '.', returning the extension and the base name.
15
+ * @param {string} name Filename
16
+ * @returns {string[]} Returns an array containing the base name and extension.
17
+ */
18
+ export function splitByExtension(name) {
19
+ const idx = name.lastIndexOf('.');
20
+ const baseName = idx > 0 && idx < name.length - 1 ? name.substring(0, idx) : name;
21
+ const ext = idx > 0 && idx < name.length - 1 ? name.substring(idx + 1).toLowerCase() : '';
22
+ return [baseName, ext];
23
+ }
24
+
25
+ /**
26
+ * Sanitizes the given string by :
27
+ * - convert to lower case
28
+ * - normalize all unicode characters
29
+ * - replace all non-alphanumeric characters with a dash
30
+ * - remove all consecutive dashes
31
+ * - remove all leading and trailing dashes
20
32
  *
21
- * @param {string} str input string
22
- * @return {string} trimmed and stripped string
33
+ * @param {string} name
34
+ * @returns {string} sanitized name
23
35
  */
24
- function superTrim(str) {
25
- return String(str)
26
- .replace(/[\u200B-\u200D\uFEFF]/g, '')
27
- .trim();
36
+ export function sanitizeName(name) {
37
+ return name
38
+ .toLowerCase()
39
+ .normalize('NFD')
40
+ .replace(/[\u0300-\u036f]/g, '')
41
+ .replace(/[^a-z0-9]+/g, '-')
42
+ .replace(/^-|-$/g, '');
28
43
  }
29
44
 
30
45
  /**
31
- * Returns a onedrive uri for the given drive item. the uri has the format:
32
- * `onedrive:/drives/<driveId>/items/<itemId>`
46
+ * Sanitizes the file path by:
47
+ * - convert to lower case
48
+ * - normalize all unicode characters
49
+ * - replace all non-alphanumeric characters with a dash
50
+ * - remove all consecutive dashes
51
+ * - remove all leading and trailing dashes
33
52
  *
34
- * @param {DriveItem} driveItem
35
- * @returns {URL} An url representing the drive item
53
+ * Note that only the basename of the file path is sanitized. i.e. The ancestor path and the
54
+ * extension is not affected.
55
+ *
56
+ * @param {string} filepath the file path
57
+ * @param {object} opts Options
58
+ * @param {boolean} [opts.ignoreExtension] if {@code true} ignores the extension
59
+ * @returns {string} sanitized file path
36
60
  */
37
- function driveItemToURL(driveItem) {
38
- return new URL(`onedrive:/drives/${driveItem.parentReference.driveId}/items/${driveItem.id}`);
61
+ export function sanitizePath(filepath, opts = {}) {
62
+ const idx = filepath.lastIndexOf('/') + 1;
63
+ const extIdx = opts.ignoreExtension ? -1 : filepath.lastIndexOf('.');
64
+ const pfx = filepath.substring(0, idx);
65
+ const basename = extIdx < idx ? filepath.substring(idx) : filepath.substring(idx, extIdx);
66
+ const ext = extIdx < idx ? '' : filepath.substring(extIdx);
67
+ const name = sanitizeName(basename);
68
+ return `${pfx}${name}${ext}`;
39
69
  }
40
70
 
41
71
  /**
42
- * Returns a partial drive item from the given url. The urls needs to have the format:
43
- * `onedrive:/drives/<driveId>/items/<itemId>`. if the url does not start with the correct
44
- * protocol, {@code null} is returned.
72
+ * Compute the edit distance using a recursive algorithm. since we only expect to have relative
73
+ * short filenames, the algorithm shouldn't be too expensive.
45
74
  *
46
- * @param {URL|string} url The url of the drive item.
47
- * @return {DriveItem} A (partial) drive item.
75
+ * @param {string} s0 Input string
76
+ * @param {string} s1 Input string
77
+ * @returns {number|*}
48
78
  */
49
- function driveItemFromURL(url) {
50
- if (!(url instanceof URL)) {
79
+ export function editDistance(s0, s1) {
80
+ // make sure that s0 length is greater than s1 length
81
+ if (s0.length < s1.length) {
82
+ const t = s1;
51
83
  // eslint-disable-next-line no-param-reassign
52
- url = new URL(String(url));
53
- }
54
- if (url.protocol !== 'onedrive:') {
55
- return null;
84
+ s1 = s0;
85
+ // eslint-disable-next-line no-param-reassign
86
+ s0 = t;
56
87
  }
57
- const [drives, driveId, items, itemId] = url.pathname.split('/').filter((s) => !!s);
58
- if (drives !== 'drives') {
59
- throw new Error(`URI not supported (missing 'drives' segment): ${url}`);
88
+ const l0 = s0.length;
89
+ const l1 = s1.length;
90
+
91
+ // init first row
92
+ const resultMatrix = [[]];
93
+ for (let c = 0; c < l1 + 1; c += 1) {
94
+ resultMatrix[0][c] = c;
60
95
  }
61
- if (items !== 'items') {
62
- throw new Error(`URI not supported (missing 'items' segment): ${url}`);
96
+ // fill out the distance matrix and find the best path
97
+ for (let i = 1; i < l0 + 1; i += 1) {
98
+ resultMatrix[i] = [i];
99
+ for (let j = 1; j < l1 + 1; j += 1) {
100
+ const replaceCost = (s0.charAt(i - 1) === s1.charAt(j - 1)) ? 0 : 1;
101
+ resultMatrix[i][j] = Math.min(
102
+ resultMatrix[i - 1][j] + 1, // insert
103
+ resultMatrix[i][j - 1] + 1, // remove
104
+ resultMatrix[i - 1][j - 1] + replaceCost,
105
+ );
106
+ }
63
107
  }
64
- return {
65
- id: itemId,
66
- parentReference: {
67
- driveId,
68
- },
69
- };
108
+ return resultMatrix[l0][l1];
70
109
  }
71
110
 
72
- module.exports = {
73
- driveItemFromURL,
74
- driveItemToURL,
75
- superTrim,
76
- };
111
+ /**
112
+ * Trims the string at both ends and removes the zero width unicode chars:
113
+ *
114
+ * - U+200B zero width space
115
+ * - U+200C zero width non-joiner Unicode code point
116
+ * - U+200D zero width joiner Unicode code point
117
+ * - U+FEFF zero width no-break space Unicode code point
118
+ *
119
+ * @param {string} str input string
120
+ * @return {string} trimmed and stripped string
121
+ */
122
+ export function superTrim(str) {
123
+ return String(str)
124
+ .replace(/[\u200B-\u200D\uFEFF]/g, '')
125
+ .trim();
126
+ }
@@ -1,89 +0,0 @@
1
- /*
2
- * Copyright 2020 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
- /**
14
- * Splits the given name at the last '.', returning the extension and the base name.
15
- * @param {string} name Filename
16
- * @returns {string[]} Returns an array containing the base name and extension.
17
- */
18
- function splitByExtension(name) {
19
- const idx = name.lastIndexOf('.');
20
- const baseName = idx > 0 && idx < name.length - 1 ? name.substring(0, idx) : name;
21
- const ext = idx > 0 && idx < name.length - 1 ? name.substring(idx + 1).toLowerCase() : '';
22
- return [baseName, ext];
23
- }
24
-
25
- /**
26
- * Sanitizes the given string by :
27
- * - convert to lower case
28
- * - normalize all unicode characters
29
- * - replace all non-alphanumeric characters with a dash
30
- * - remove all consecutive dashes
31
- * - remove all leading and trailing dashes
32
- *
33
- * @param {string} name
34
- * @returns {string} sanitized name
35
- */
36
- function sanitize(name) {
37
- return name
38
- .toLowerCase()
39
- .normalize('NFD')
40
- .replace(/[\u0300-\u036f]/g, '')
41
- .replace(/[^a-z0-9]+/g, '-')
42
- .replace(/^-|-$/g, '');
43
- }
44
-
45
- /**
46
- * Compute the edit distance using a recursive algorithm. since we only expect to have relative
47
- * short filenames, the algorithm shouldn't be too expensive.
48
- *
49
- * @param {string} s0 Input string
50
- * @param {string} s1 Input string
51
- * @returns {number|*}
52
- */
53
- function editDistance(s0, s1) {
54
- // make sure that s0 length is greater than s1 length
55
- if (s0.length < s1.length) {
56
- const t = s1;
57
- // eslint-disable-next-line no-param-reassign
58
- s1 = s0;
59
- // eslint-disable-next-line no-param-reassign
60
- s0 = t;
61
- }
62
- const l0 = s0.length;
63
- const l1 = s1.length;
64
-
65
- // init first row
66
- const resultMatrix = [[]];
67
- for (let c = 0; c < l1 + 1; c += 1) {
68
- resultMatrix[0][c] = c;
69
- }
70
- // fill out the distance matrix and find the best path
71
- for (let i = 1; i < l0 + 1; i += 1) {
72
- resultMatrix[i] = [i];
73
- for (let j = 1; j < l1 + 1; j += 1) {
74
- const replaceCost = (s0.charAt(i - 1) === s1.charAt(j - 1)) ? 0 : 1;
75
- resultMatrix[i][j] = Math.min(
76
- resultMatrix[i - 1][j] + 1, // insert
77
- resultMatrix[i][j - 1] + 1, // remove
78
- resultMatrix[i - 1][j - 1] + replaceCost,
79
- );
80
- }
81
- }
82
- return resultMatrix[l0][l1];
83
- }
84
-
85
- module.exports = {
86
- splitByExtension,
87
- sanitize,
88
- editDistance,
89
- };