@adobe/spacecat-shared-content-client 1.1.6 → 1.1.8
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/README.md +23 -0
- package/package.json +2 -1
- package/src/clients/content-client.js +4 -4
- package/src/clients/index.d.ts +31 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# [@adobe/spacecat-shared-content-client-v1.1.8](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-content-client-v1.1.7...@adobe/spacecat-shared-content-client-v1.1.8) (2024-10-02)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* docs for content client ([0978c2d](https://github.com/adobe/spacecat-shared/commit/0978c2d84636f03b7ebdf22e9888740d9518b989))
|
|
7
|
+
|
|
8
|
+
# [@adobe/spacecat-shared-content-client-v1.1.7](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-content-client-v1.1.6...@adobe/spacecat-shared-content-client-v1.1.7) (2024-10-02)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* content client should use the hlxConfig ([8e74827](https://github.com/adobe/spacecat-shared/commit/8e74827613421828eaef29cf1372d329433526cc))
|
|
14
|
+
|
|
1
15
|
# [@adobe/spacecat-shared-content-client-v1.1.6](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-content-client-v1.1.5...@adobe/spacecat-shared-content-client-v1.1.6) (2024-10-01)
|
|
2
16
|
|
|
3
17
|
|
package/README.md
CHANGED
|
@@ -20,7 +20,30 @@ To remove `node_modules` and `package-lock.json`:
|
|
|
20
20
|
```bash
|
|
21
21
|
npm run clean
|
|
22
22
|
```
|
|
23
|
+
## Usage
|
|
23
24
|
|
|
25
|
+
### Google Drive
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
import { ContentClient } from '../src/index.js';
|
|
29
|
+
|
|
30
|
+
const context = {}; // Your AWS Lambda context object
|
|
31
|
+
const gdriveclient = await ContentClient.createFrom(context, { url: 'GOOGLE_DRIVE_URL', type: 'drive.google' });
|
|
32
|
+
const results = await client.getPageMetadata('/path1');
|
|
33
|
+
console.log(results);
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Microsoft Sharepoint Drive
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
import { ContentClient } from '../src/index.js';
|
|
40
|
+
|
|
41
|
+
const context = {}; // Your AWS Lambda context object
|
|
42
|
+
const onedriveclient = await ContentClient.createFrom(context, { url: 'ONEDRIVE_URL', type: 'onedrive' });
|
|
43
|
+
|
|
44
|
+
const results = await client.getPageMetadata('/path1');
|
|
45
|
+
console.log(results);
|
|
46
|
+
```
|
|
24
47
|
## Additional Information
|
|
25
48
|
|
|
26
49
|
- **Repository**: [GitHub](https://github.com/adobe/spacecat-shared.git)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/spacecat-shared-content-client",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.8",
|
|
4
4
|
"description": "Shared modules of the Spacecat Services - Content Client",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"graph-data-structure": "4.0.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
+
"@adobe/spacecat-shared-data-access": "1.45.5",
|
|
43
44
|
"chai": "5.1.1",
|
|
44
45
|
"chai-as-promised": "8.0.0",
|
|
45
46
|
"esmock": "2.6.7",
|
|
@@ -58,7 +58,7 @@ const validateSite = (site) => {
|
|
|
58
58
|
throw new Error('Site is required');
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
const contentSource = site.
|
|
61
|
+
const contentSource = site.getHlxConfig()?.content?.source;
|
|
62
62
|
if (!isObject(contentSource)) {
|
|
63
63
|
throw new Error('Site must have a valid content source');
|
|
64
64
|
}
|
|
@@ -181,7 +181,7 @@ export default class ContentClient {
|
|
|
181
181
|
const { log = console, env } = context;
|
|
182
182
|
|
|
183
183
|
const config = {};
|
|
184
|
-
const contentSourceType = site.
|
|
184
|
+
const contentSourceType = site.getHlxConfig()?.content?.source?.type;
|
|
185
185
|
const envMapping = SUPPORTED_CONTENT_SOURCES.get(contentSourceType);
|
|
186
186
|
|
|
187
187
|
if (envMapping) {
|
|
@@ -195,11 +195,11 @@ export default class ContentClient {
|
|
|
195
195
|
|
|
196
196
|
constructor(config, site, log) {
|
|
197
197
|
validateSite(site);
|
|
198
|
-
validateConfiguration(config, site.
|
|
198
|
+
validateConfiguration(config, site.getHlxConfig()?.content.source?.type);
|
|
199
199
|
|
|
200
200
|
this.log = log;
|
|
201
201
|
this.config = config;
|
|
202
|
-
this.contentSource = site.
|
|
202
|
+
this.contentSource = site.getHlxConfig()?.content?.source;
|
|
203
203
|
this.site = site;
|
|
204
204
|
this.rawClient = null;
|
|
205
205
|
}
|
package/src/clients/index.d.ts
CHANGED
|
@@ -36,10 +36,11 @@ export class ContentClient {
|
|
|
36
36
|
* Example: "/path/to/page" (from the full URL: "https://www.example.com/path/to/page").
|
|
37
37
|
*
|
|
38
38
|
* @param {string} path The path to the page.
|
|
39
|
-
* @returns {Map<string, string
|
|
39
|
+
* @returns {Promise<Map<string, { value: string, type: string }>>} A promise that
|
|
40
|
+
* resolves to the page's metadata.
|
|
40
41
|
* @throws {Error} If the path is not a string, empty or does not start with a "/"
|
|
41
42
|
*/
|
|
42
|
-
getPageMetadata(path: string): Map<string, string
|
|
43
|
+
getPageMetadata(path: string): Promise<Map<string, { value: string, type: string }>>;
|
|
43
44
|
|
|
44
45
|
/**
|
|
45
46
|
* Updates the metadata for the given page path. The document backing the path
|
|
@@ -53,17 +54,41 @@ export class ContentClient {
|
|
|
53
54
|
* overwrites the existing metadata.
|
|
54
55
|
*
|
|
55
56
|
* @param {string} path The path to the page.
|
|
56
|
-
* @param {Map<string, string>} metadata The metadata to update.
|
|
57
|
+
* @param {Map<string, { value: string, type: string }>} metadata The metadata to update.
|
|
57
58
|
* @param {Object} [options] The options to use for updating the metadata.
|
|
58
59
|
* @param {Object} [options.overwrite] Whether to overwrite the existing metadata.
|
|
59
|
-
* @returns {Map<string, string
|
|
60
|
+
* @returns {Promise<Map<string, { value: string, type: string }>>} A promise that resolves to
|
|
61
|
+
* the page's merged metadata.
|
|
60
62
|
* @throws {Error} If the metadata is not a Map or empty
|
|
61
63
|
* @throws {Error} If any of the metadata keys or values are not a string
|
|
62
64
|
* @throws {Error} If the path is not a string, empty or does not start with a "/"
|
|
63
65
|
*/
|
|
64
66
|
updatePageMetadata(
|
|
65
67
|
path: string,
|
|
66
|
-
metadata: Map<string, string>,
|
|
68
|
+
metadata: Map<string, { value: string, type: string }>,
|
|
67
69
|
options: object,
|
|
68
|
-
): Map<string, string
|
|
70
|
+
): Promise<Map<string, { value: string, type: string }>>;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Retrieves the current redirects for the site from the redirects.xlsx file.
|
|
74
|
+
*
|
|
75
|
+
* @returns {Promise<Array<{ from: string, to: string }>>} A promise that resolves to
|
|
76
|
+
* an array of redirect objects.
|
|
77
|
+
* @throws {Error} If there is an issue retrieving the redirects.
|
|
78
|
+
*/
|
|
79
|
+
getRedirects(): Promise<Array<{ from: string, to: string }>>
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Updates the redirects for the site with the valid array of redirects.
|
|
83
|
+
* The redirects are validated before updating the redirects.
|
|
84
|
+
* The duplicate redirects are removed.
|
|
85
|
+
* The redundant redirects are removed.
|
|
86
|
+
* The valid redirects are appended at the end of the redirects.xlsx file.
|
|
87
|
+
*
|
|
88
|
+
* @param {Array<{ from: string, to: string }>} redirects The array of redirect objects to update.
|
|
89
|
+
* @returns {Promise<void>} A promise that resolves when the redirects have been updated.
|
|
90
|
+
* @throws {Error} If the redirects array is not valid or if there
|
|
91
|
+
* is an issue updating the redirects.
|
|
92
|
+
*/
|
|
93
|
+
updateRedirects(redirects: Array<{ from: string, to: string }>): Promise<void>
|
|
69
94
|
}
|