@adobe/spacecat-shared-content-client 1.1.22 → 1.2.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 +7 -0
- package/README.md +20 -1
- package/package.json +2 -2
- package/src/clients/content-client.js +29 -1
- package/src/clients/index.d.ts +12 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [@adobe/spacecat-shared-content-client-v1.2.0](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-content-client-v1.1.22...@adobe/spacecat-shared-content-client-v1.2.0) (2024-11-12)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* create content client directly from domain ([17aec10](https://github.com/adobe/spacecat-shared/commit/17aec10cabb7b50d35588054587a96032b52ef73))
|
|
7
|
+
|
|
1
8
|
# [@adobe/spacecat-shared-content-client-v1.1.22](https://github.com/adobe/spacecat-shared/compare/@adobe/spacecat-shared-content-client-v1.1.21...@adobe/spacecat-shared-content-client-v1.1.22) (2024-11-11)
|
|
2
9
|
|
|
3
10
|
|
package/README.md
CHANGED
|
@@ -29,6 +29,15 @@ import { ContentClient } from '../src/index.js';
|
|
|
29
29
|
|
|
30
30
|
const context = {}; // Your AWS Lambda context object
|
|
31
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
|
+
```js
|
|
36
|
+
import { ContentClient } from '../src/index.js';
|
|
37
|
+
|
|
38
|
+
const env = {}; // Your env variables to connect to spacecat apis and google drive
|
|
39
|
+
const onedriveclient = await ContentClient.createFromDomain('example.com', env, log);
|
|
40
|
+
|
|
32
41
|
const results = await client.getPageMetadata('/path1');
|
|
33
42
|
console.log(results);
|
|
34
43
|
```
|
|
@@ -38,9 +47,19 @@ console.log(results);
|
|
|
38
47
|
```js
|
|
39
48
|
import { ContentClient } from '../src/index.js';
|
|
40
49
|
|
|
41
|
-
const context = {}; // Your
|
|
50
|
+
const context = {}; // Your env variables to connect to spacecat apis and onedrive
|
|
42
51
|
const onedriveclient = await ContentClient.createFrom(context, { url: 'ONEDRIVE_URL', type: 'onedrive' });
|
|
43
52
|
|
|
53
|
+
const results = await client.getPageMetadata('/path1');
|
|
54
|
+
console.log(results);
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
```js
|
|
58
|
+
import { ContentClient } from '../src/index.js';
|
|
59
|
+
|
|
60
|
+
const env = {}; // Your AWS Lambda context object
|
|
61
|
+
const onedriveclient = await ContentClient.createFromDomain('example.com', env, log);
|
|
62
|
+
|
|
44
63
|
const results = await client.getPageMetadata('/path1');
|
|
45
64
|
console.log(results);
|
|
46
65
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/spacecat-shared-content-client",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Shared modules of the Spacecat Services - Content Client",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -35,12 +35,12 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@adobe/helix-universal": "5.0.6",
|
|
38
|
+
"@adobe/spacecat-shared-data-access": "1.50.0",
|
|
38
39
|
"@adobe/spacecat-helix-content-sdk": "1.2.7",
|
|
39
40
|
"@adobe/spacecat-shared-utils": "1.22.4",
|
|
40
41
|
"graph-data-structure": "4.1.0"
|
|
41
42
|
},
|
|
42
43
|
"devDependencies": {
|
|
43
|
-
"@adobe/spacecat-shared-data-access": "1.50.0",
|
|
44
44
|
"chai": "5.1.2",
|
|
45
45
|
"chai-as-promised": "8.0.0",
|
|
46
46
|
"esmock": "2.6.9",
|
|
@@ -11,8 +11,11 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import { createFrom as createContentSDKClient } from '@adobe/spacecat-helix-content-sdk';
|
|
14
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
composeBaseURL, hasText, isObject, tracingFetch,
|
|
16
|
+
} from '@adobe/spacecat-shared-utils';
|
|
15
17
|
import { Graph, hasCycle } from 'graph-data-structure';
|
|
18
|
+
import { SiteDto } from '@adobe/spacecat-shared-data-access/src/dto/site.js';
|
|
16
19
|
|
|
17
20
|
const CONTENT_SOURCE_TYPE_DRIVE_GOOGLE = 'drive.google';
|
|
18
21
|
const CONTENT_SOURCE_TYPE_ONEDRIVE = 'onedrive';
|
|
@@ -193,6 +196,31 @@ export default class ContentClient {
|
|
|
193
196
|
return new ContentClient(config, site, log);
|
|
194
197
|
}
|
|
195
198
|
|
|
199
|
+
static async createFromDomain(domain, env, log = console) {
|
|
200
|
+
const baseUrl = composeBaseURL(domain);
|
|
201
|
+
const siteBaseUrlEncoded = Buffer.from(baseUrl).toString('base64');
|
|
202
|
+
let site;
|
|
203
|
+
const sitesApiEndpoint = `${env.SPACECAT_API_ENDPOINT}/sites/by-base-url`;
|
|
204
|
+
try {
|
|
205
|
+
const response = await tracingFetch(`${sitesApiEndpoint}/${siteBaseUrlEncoded}`, {
|
|
206
|
+
method: 'GET',
|
|
207
|
+
headers: {
|
|
208
|
+
'x-api-key': env.SPACECAT_API_KEY,
|
|
209
|
+
'Content-Type': 'application/json',
|
|
210
|
+
},
|
|
211
|
+
});
|
|
212
|
+
if (!response.ok) {
|
|
213
|
+
throw new Error(`Failed to fetch ${domain}`);
|
|
214
|
+
}
|
|
215
|
+
site = await response.json();
|
|
216
|
+
const siteDto = SiteDto.fromDynamoItem(site);
|
|
217
|
+
return ContentClient.createFrom({ log, env }, siteDto);
|
|
218
|
+
} catch (e) {
|
|
219
|
+
log.error(`Failed to fetch ${domain}: ${e.message}`);
|
|
220
|
+
throw new Error(`Failed to fetch ${domain}`);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
196
224
|
constructor(config, site, log) {
|
|
197
225
|
validateSite(site);
|
|
198
226
|
validateConfiguration(config, site.getHlxConfig()?.content.source?.type);
|
package/src/clients/index.d.ts
CHANGED
|
@@ -26,6 +26,18 @@ export class ContentClient {
|
|
|
26
26
|
*/
|
|
27
27
|
static createFrom(context: UniversalContext, site: object): ContentClient;
|
|
28
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Creates a new ContentClient instance from the given domain and environment.
|
|
31
|
+
*
|
|
32
|
+
* @param {string} domain The domain of the site to create the ContentClient for.
|
|
33
|
+
* @param {Object} env The environment object that contains the required configuration
|
|
34
|
+
* for the site's content source type.
|
|
35
|
+
* @returns {Promise<ContentClient>} A promise that resolves to the ContentClient instance.
|
|
36
|
+
* @throws {Error} If the domain is not a string or empty.
|
|
37
|
+
* @throws {Error} If the env is not an object or does not contain the required configuration.
|
|
38
|
+
*/
|
|
39
|
+
static createFromDomain(domain: string, env: object,): Promise<ContentClient>;
|
|
40
|
+
|
|
29
41
|
/**
|
|
30
42
|
* Returns the metadata for the given page path. The document backing the path
|
|
31
43
|
* is resolved and the metadata is extracted from it. The metadata is a Map where the entries
|