@agility/content-fetch 2.0.11 → 2.0.13
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/.github/workflows/npm-publish.yml +46 -0
- package/.github/workflows/pr-tests.yml +28 -0
- package/.jsdoc.json +28 -28
- package/LICENSE +21 -21
- package/README.md +118 -102
- package/build.js +24 -24
- package/dist/browser.js +92 -85
- package/dist/index.d.ts +2 -1
- package/dist/node.js +92 -85
- package/dist/types/Config.d.ts +7 -4
- package/dist/types/Page.d.ts +3 -0
- package/dist/types/PageScripts.d.ts +13 -0
- package/dist/utils.d.ts +17 -3
- package/jest.config.js +5 -5
- package/package.json +53 -53
- package/tsconfig.json +14 -14
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
name: Publish to npm
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*"
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
publish:
|
|
10
|
+
name: Build and publish to npm
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
permissions:
|
|
13
|
+
contents: read
|
|
14
|
+
id-token: write
|
|
15
|
+
|
|
16
|
+
steps:
|
|
17
|
+
- name: Checkout
|
|
18
|
+
uses: actions/checkout@v4
|
|
19
|
+
with:
|
|
20
|
+
fetch-depth: 0
|
|
21
|
+
|
|
22
|
+
- name: Verify tag matches package.json version
|
|
23
|
+
run: |
|
|
24
|
+
TAG_VERSION="${GITHUB_REF_NAME#v}"
|
|
25
|
+
PKG_VERSION=$(node -p "require('./package.json').version")
|
|
26
|
+
if [ "$TAG_VERSION" != "$PKG_VERSION" ]; then
|
|
27
|
+
echo "Tag ($TAG_VERSION) does not match package.json version ($PKG_VERSION)."
|
|
28
|
+
exit 1
|
|
29
|
+
fi
|
|
30
|
+
|
|
31
|
+
- name: Set up Node.js
|
|
32
|
+
uses: actions/setup-node@v4
|
|
33
|
+
with:
|
|
34
|
+
node-version: "24"
|
|
35
|
+
registry-url: "https://registry.npmjs.org"
|
|
36
|
+
|
|
37
|
+
- name: Install dependencies
|
|
38
|
+
run: npm ci
|
|
39
|
+
|
|
40
|
+
- name: Build
|
|
41
|
+
run: npm run build
|
|
42
|
+
|
|
43
|
+
# Always publish under the beta dist-tag. Promote to latest manually:
|
|
44
|
+
# npm dist-tag add @agility/content-fetch@<version> latest
|
|
45
|
+
- name: Publish
|
|
46
|
+
run: npm publish --access public --tag beta
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
name: Run tests on PR
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
branches:
|
|
6
|
+
- master
|
|
7
|
+
- dev # add whichever branches you want PRs against
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
|
|
13
|
+
steps:
|
|
14
|
+
- name: Checkout repository
|
|
15
|
+
uses: actions/checkout@v4
|
|
16
|
+
|
|
17
|
+
- name: Set up Node.js
|
|
18
|
+
uses: actions/setup-node@v4
|
|
19
|
+
with:
|
|
20
|
+
node-version: "24"
|
|
21
|
+
cache: "npm"
|
|
22
|
+
|
|
23
|
+
- name: Install dependencies
|
|
24
|
+
run: npm ci
|
|
25
|
+
|
|
26
|
+
- name: Run tests
|
|
27
|
+
run: npm test
|
|
28
|
+
|
package/.jsdoc.json
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
{
|
|
2
|
-
"source": {
|
|
3
|
-
"include": ["src", "README.md", "package.json"],
|
|
4
|
-
"includePattern": ".js$",
|
|
5
|
-
"excludePattern": "(node_modules/|docs)"
|
|
6
|
-
},
|
|
7
|
-
"plugins": [
|
|
8
|
-
"plugins/markdown"
|
|
9
|
-
],
|
|
10
|
-
"recurse": 10,
|
|
11
|
-
"templates": {
|
|
12
|
-
"cleverLinks": false,
|
|
13
|
-
"monospaceLinks": true,
|
|
14
|
-
"useLongnameInNav": true,
|
|
15
|
-
"showInheritedInNav": true
|
|
16
|
-
},
|
|
17
|
-
"tags": {
|
|
18
|
-
"allowUnknownTags": true,
|
|
19
|
-
"dictionaries": ["jsdoc"]
|
|
20
|
-
},
|
|
21
|
-
"source-type": "module",
|
|
22
|
-
"opts": {
|
|
23
|
-
"destination": "./docs/",
|
|
24
|
-
"encoding": "utf8",
|
|
25
|
-
"private": false,
|
|
26
|
-
"recurse": true,
|
|
27
|
-
"template": "./node_modules/agility-jsdoc-template"
|
|
28
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"source": {
|
|
3
|
+
"include": ["src", "README.md", "package.json"],
|
|
4
|
+
"includePattern": ".js$",
|
|
5
|
+
"excludePattern": "(node_modules/|docs)"
|
|
6
|
+
},
|
|
7
|
+
"plugins": [
|
|
8
|
+
"plugins/markdown"
|
|
9
|
+
],
|
|
10
|
+
"recurse": 10,
|
|
11
|
+
"templates": {
|
|
12
|
+
"cleverLinks": false,
|
|
13
|
+
"monospaceLinks": true,
|
|
14
|
+
"useLongnameInNav": true,
|
|
15
|
+
"showInheritedInNav": true
|
|
16
|
+
},
|
|
17
|
+
"tags": {
|
|
18
|
+
"allowUnknownTags": true,
|
|
19
|
+
"dictionaries": ["jsdoc"]
|
|
20
|
+
},
|
|
21
|
+
"source-type": "module",
|
|
22
|
+
"opts": {
|
|
23
|
+
"destination": "./docs/",
|
|
24
|
+
"encoding": "utf8",
|
|
25
|
+
"private": false,
|
|
26
|
+
"recurse": true,
|
|
27
|
+
"template": "./node_modules/agility-jsdoc-template"
|
|
28
|
+
}
|
|
29
29
|
}
|
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2019 Agility
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Agility
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,102 +1,118 @@
|
|
|
1
|
-
[](https://agility.visualstudio.com/Agility%20CMS/_build/latest?definitionId=59&branchName=master)
|
|
2
|
-
[](https://app.netlify.com/sites/agilitydocs/deploys)
|
|
3
|
-
|
|
4
|
-
# Agility Content Fetch JS SDK
|
|
5
|
-
|
|
6
|
-
This is the official JavaScript/TypeScript library for accessing live and preview content from your [Agility CMS](https://agilitycms.com) instance.
|
|
7
|
-
|
|
8
|
-
You can use this in both
|
|
9
|
-
|
|
10
|
-
Don't have an Agility CMS instance? Sign up for [Free Trial](https://agilitycms.com/free) today!
|
|
11
|
-
|
|
12
|
-
## Features
|
|
13
|
-
|
|
14
|
-
-
|
|
15
|
-
- Get a sitemap for a given channel
|
|
16
|
-
- Get a page, including its content zones, modules, and their content
|
|
17
|
-
- Get a content item
|
|
18
|
-
- Query a content list using a filter syntax
|
|
19
|
-
- Get the details of a media gallery
|
|
20
|
-
- Keep track of syncing content to your app
|
|
21
|
-
|
|
22
|
-
## Getting Started
|
|
23
|
-
|
|
24
|
-
In order to use this
|
|
25
|
-
|
|
26
|
-
### Prerequisites
|
|
27
|
-
|
|
28
|
-
You must have access to an Agility instance to retrieve the _guid_ and generate your _apiKey_. Or, you must have these values provided to you.
|
|
29
|
-
|
|
30
|
-
### Installation
|
|
31
|
-
|
|
32
|
-
**npm**
|
|
33
|
-
|
|
34
|
-
```
|
|
35
|
-
npm install @agility/content-fetch
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
**yarn**
|
|
39
|
-
|
|
40
|
-
```
|
|
41
|
-
yarn add @agility/content-fetch
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
### Making a Request
|
|
45
|
-
|
|
46
|
-
```javascript
|
|
47
|
-
import agility from "@agility/content-fetch"
|
|
48
|
-
|
|
49
|
-
//initialize the api client
|
|
50
|
-
const api = agility.getApi({
|
|
51
|
-
guid: "[guid]",
|
|
52
|
-
apiKey: "[your-api-key]",
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
//make the request: get a content item with the ID 22 in locale 'en-us'
|
|
56
|
-
const contentItems = await api.getContentItem({
|
|
57
|
-
contentID: 22,
|
|
58
|
-
locale: "en-us",
|
|
59
|
-
})
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
## Documentation
|
|
63
|
-
|
|
64
|
-
Full documentation for this SDK can be found in our [Agility Fetch JS SDK Reference Doc](https://
|
|
65
|
-
|
|
66
|
-
For docs & help around Agility CMS, please see [Agility CMS Documentation](https://
|
|
67
|
-
|
|
68
|
-
## Tutorials
|
|
69
|
-
|
|
70
|
-
[About the Content Fetch API](https://
|
|
71
|
-
|
|
72
|
-
[
|
|
73
|
-
|
|
74
|
-
[
|
|
75
|
-
|
|
76
|
-
[
|
|
77
|
-
|
|
78
|
-
[
|
|
79
|
-
|
|
80
|
-
[
|
|
81
|
-
|
|
82
|
-
[
|
|
83
|
-
|
|
84
|
-
[Creating a
|
|
85
|
-
|
|
86
|
-
[
|
|
87
|
-
|
|
88
|
-
[
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
|
|
1
|
+
[](https://agility.visualstudio.com/Agility%20CMS/_build/latest?definitionId=59&branchName=master)
|
|
2
|
+
[](https://app.netlify.com/sites/agilitydocs/deploys)
|
|
3
|
+
|
|
4
|
+
# Agility Content Fetch JS SDK
|
|
5
|
+
|
|
6
|
+
This is the official JavaScript/TypeScript library for accessing live and preview content from your [Agility CMS](https://agilitycms.com) instance.
|
|
7
|
+
|
|
8
|
+
You can use this in both Node.js and browser-based JavaScript apps.
|
|
9
|
+
|
|
10
|
+
Don't have an Agility CMS instance? Sign up for [Free Trial](https://agilitycms.com/free) today!
|
|
11
|
+
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
- Query the high-availability, CDN-backed Agility Fetch REST API
|
|
15
|
+
- Get a sitemap for a given channel
|
|
16
|
+
- Get a page, including its content zones, modules, and their content
|
|
17
|
+
- Get a content item
|
|
18
|
+
- Query a content list using a filter syntax
|
|
19
|
+
- Get the details of a media gallery
|
|
20
|
+
- Keep track of syncing content to your app
|
|
21
|
+
|
|
22
|
+
## Getting Started
|
|
23
|
+
|
|
24
|
+
In order to use this SDK, you'll need to install the `@agility/content-fetch` package and you'll also need to authenticate your requests.
|
|
25
|
+
|
|
26
|
+
### Prerequisites
|
|
27
|
+
|
|
28
|
+
You must have access to an Agility instance to retrieve the _guid_ and generate your _apiKey_. Or, you must have these values provided to you.
|
|
29
|
+
|
|
30
|
+
### Installation
|
|
31
|
+
|
|
32
|
+
**npm**
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
npm install @agility/content-fetch
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
**yarn**
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
yarn add @agility/content-fetch
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Making a Request
|
|
45
|
+
|
|
46
|
+
```javascript
|
|
47
|
+
import agility from "@agility/content-fetch"
|
|
48
|
+
|
|
49
|
+
//initialize the api client
|
|
50
|
+
const api = agility.getApi({
|
|
51
|
+
guid: "[guid]",
|
|
52
|
+
apiKey: "[your-api-key]",
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
//make the request: get a content item with the ID 22 in locale 'en-us'
|
|
56
|
+
const contentItems = await api.getContentItem({
|
|
57
|
+
contentID: 22,
|
|
58
|
+
locale: "en-us",
|
|
59
|
+
})
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Documentation
|
|
63
|
+
|
|
64
|
+
Full documentation for this SDK can be found in our [Agility Fetch JS SDK Reference Doc](https://agilitycms.com/docs/javascript/content-fetch-js-sdk).
|
|
65
|
+
|
|
66
|
+
For docs & help around Agility CMS, please see [Agility CMS Documentation](https://agilitycms.com/docs)
|
|
67
|
+
|
|
68
|
+
## Tutorials
|
|
69
|
+
|
|
70
|
+
[About using the Content Fetch API and authenticating API calls](https://agilitycms.com/docs/developers/content-fetch-api)
|
|
71
|
+
|
|
72
|
+
[Retrieving your API Key(s), Guid, and API URL](https://agilitycms.com/docs/training-guide/admin-api-keys)
|
|
73
|
+
|
|
74
|
+
[Making your First Call with the Content Fetch API](https://agilitycms.com/docs/training-guide/developer-api-basics)
|
|
75
|
+
|
|
76
|
+
[Calilng the Content Fetch API using the Javascript SDK](https://agilitycms.com/docs/javascript/content-fetch-js-sdk)
|
|
77
|
+
|
|
78
|
+
[Page Management in a Headless CMS](https://agilitycms.com/docs/developers/page-management-in-a-headless-cms)
|
|
79
|
+
|
|
80
|
+
[Using Agility CMS with Next.js](https://agilitycms.com/docs/nextjs)
|
|
81
|
+
|
|
82
|
+
[Creating a Next.js component in Agility CMS](https://agilitycms.com/docs/training-guide/developer-component-development)
|
|
83
|
+
|
|
84
|
+
[Creating a page model in Agility CMS](https://agilitycms.com/docs/developers/page-models)
|
|
85
|
+
|
|
86
|
+
[Deploying your Agility CMS Next.js app to Vercel](https://agilitycms.com/docs/nextjs/deploying-next-js-to-vercel)
|
|
87
|
+
|
|
88
|
+
[Webhooks](https://agilitycms.com/docs/developers/webhooks)
|
|
89
|
+
|
|
90
|
+
## Contributing
|
|
91
|
+
|
|
92
|
+
If you would like to contribute to this SDK, you can fork the repository and submit a pull request. We'd love to include your updates.
|
|
93
|
+
|
|
94
|
+
### Running the Tests
|
|
95
|
+
|
|
96
|
+
An essential part of contributing to this SDK is adding and running unit tests to ensure the stability of the project.
|
|
97
|
+
|
|
98
|
+
```
|
|
99
|
+
> npm run test
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Publishing a New Release
|
|
103
|
+
|
|
104
|
+
Releases are published to npm automatically by [`.github/workflows/npm-publish.yml`](.github/workflows/npm-publish.yml) whenever a `v*` tag is pushed to the repo. To cut a release:
|
|
105
|
+
|
|
106
|
+
1. Bump the `version` field in `package.json` (following [semver](https://semver.org)) and merge that change into `master`.
|
|
107
|
+
2. Tag the merge commit and push the tag:
|
|
108
|
+
```
|
|
109
|
+
git tag v2.0.12
|
|
110
|
+
git push origin v2.0.12
|
|
111
|
+
```
|
|
112
|
+
3. The workflow verifies the tag matches `package.json`'s version, builds the package, and publishes it to npm under the `beta` dist-tag.
|
|
113
|
+
4. Once you've verified the `beta` release, promote it to `latest`:
|
|
114
|
+
```
|
|
115
|
+
npm dist-tag add @agility/content-fetch@2.0.12 latest
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Publishing uses npm's [Trusted Publishing](https://docs.npmjs.com/trusted-publishers) (OIDC) — no `NPM_TOKEN` secret is stored in this repo.
|
package/build.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
const esbuild = require('esbuild');
|
|
2
|
-
const { execSync } = require('child_process');
|
|
3
|
-
const path = require('path');
|
|
4
|
-
|
|
5
|
-
console.log("Building...", path.resolve(__dirname, "src/index.ts"))
|
|
6
|
-
console.log("Building...", path.resolve(__dirname, "dist/browser.js"))
|
|
7
|
-
|
|
8
|
-
execSync('tsc --emitDeclarationOnly');
|
|
9
|
-
|
|
10
|
-
// Build for browser
|
|
11
|
-
esbuild.build({
|
|
12
|
-
entryPoints: ['./src/index.ts'],
|
|
13
|
-
bundle: true,
|
|
14
|
-
outfile: './dist/browser.js',
|
|
15
|
-
platform: 'browser',
|
|
16
|
-
}).catch(() => process.exit(1));
|
|
17
|
-
|
|
18
|
-
// Build for Node.js
|
|
19
|
-
esbuild.build({
|
|
20
|
-
entryPoints: ['./src/index.ts'],
|
|
21
|
-
bundle: true,
|
|
22
|
-
outfile: './dist/node.js',
|
|
23
|
-
platform: 'node',
|
|
24
|
-
}).catch(() => process.exit(1));
|
|
1
|
+
const esbuild = require('esbuild');
|
|
2
|
+
const { execSync } = require('child_process');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
|
|
5
|
+
console.log("Building...", path.resolve(__dirname, "src/index.ts"))
|
|
6
|
+
console.log("Building...", path.resolve(__dirname, "dist/browser.js"))
|
|
7
|
+
|
|
8
|
+
execSync('tsc --emitDeclarationOnly');
|
|
9
|
+
|
|
10
|
+
// Build for browser
|
|
11
|
+
esbuild.build({
|
|
12
|
+
entryPoints: ['./src/index.ts'],
|
|
13
|
+
bundle: true,
|
|
14
|
+
outfile: './dist/browser.js',
|
|
15
|
+
platform: 'browser',
|
|
16
|
+
}).catch(() => process.exit(1));
|
|
17
|
+
|
|
18
|
+
// Build for Node.js
|
|
19
|
+
esbuild.build({
|
|
20
|
+
entryPoints: ['./src/index.ts'],
|
|
21
|
+
bundle: true,
|
|
22
|
+
outfile: './dist/node.js',
|
|
23
|
+
platform: 'node',
|
|
24
|
+
}).catch(() => process.exit(1));
|
package/dist/browser.js
CHANGED
|
@@ -21,37 +21,42 @@
|
|
|
21
21
|
return;
|
|
22
22
|
console.error("\x1B[41m%s\x1B[0m", message);
|
|
23
23
|
}
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
var SENSITIVE_HEADERS = ["apikey", "authorization", "x-api-key"];
|
|
25
|
+
function headersToObject(headers) {
|
|
26
|
+
const obj = {};
|
|
26
27
|
if (headers instanceof Headers) {
|
|
27
28
|
headers.forEach((value, key) => {
|
|
28
|
-
|
|
29
|
-
sanitized[key] = "***REDACTED***";
|
|
30
|
-
} else {
|
|
31
|
-
sanitized[key] = value;
|
|
32
|
-
}
|
|
29
|
+
obj[key] = value;
|
|
33
30
|
});
|
|
34
31
|
} else {
|
|
35
32
|
Object.keys(headers).forEach((key) => {
|
|
36
|
-
|
|
37
|
-
sanitized[key] = "***REDACTED***";
|
|
38
|
-
} else {
|
|
39
|
-
sanitized[key] = headers[key];
|
|
40
|
-
}
|
|
33
|
+
obj[key] = headers[key];
|
|
41
34
|
});
|
|
42
35
|
}
|
|
36
|
+
return obj;
|
|
37
|
+
}
|
|
38
|
+
function sanitizeHeaders(headers) {
|
|
39
|
+
const sanitized = headersToObject(headers);
|
|
40
|
+
Object.keys(sanitized).forEach((key) => {
|
|
41
|
+
if (SENSITIVE_HEADERS.includes(key.toLowerCase())) {
|
|
42
|
+
sanitized[key] = "***REDACTED***";
|
|
43
|
+
}
|
|
44
|
+
});
|
|
43
45
|
return sanitized;
|
|
44
46
|
}
|
|
45
47
|
function logDebugDetails({ config, details }) {
|
|
46
|
-
if (!config.debug)
|
|
48
|
+
if (!config.debug && config.logLevel !== "debug")
|
|
47
49
|
return;
|
|
48
50
|
const sanitizedDetails = {
|
|
49
51
|
...details,
|
|
50
|
-
|
|
52
|
+
requestHeaders: details.requestHeaders ? sanitizeHeaders(details.requestHeaders) : void 0,
|
|
53
|
+
responseHeaders: details.responseHeaders ? sanitizeHeaders(details.responseHeaders) : void 0
|
|
51
54
|
};
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
const banner = `=== AgilityCMS Fetch API Debug [${details.type.toUpperCase()}] ===`;
|
|
56
|
+
const log = details.type === "error" ? console.error : console.log;
|
|
57
|
+
log("\x1B[36m%s\x1B[0m", banner);
|
|
58
|
+
log(JSON.stringify(sanitizedDetails, null, 2));
|
|
59
|
+
log("\x1B[36m%s\x1B[0m", "=".repeat(banner.length));
|
|
55
60
|
}
|
|
56
61
|
function buildRequestUrlPath(config, locale) {
|
|
57
62
|
let apiFetchOrPreview = "";
|
|
@@ -604,10 +609,11 @@
|
|
|
604
609
|
//the function that actually makes ALL our requests
|
|
605
610
|
async makeRequest(reqConfig) {
|
|
606
611
|
const isPreview = !!this.config.isPreview;
|
|
612
|
+
const apiType = isPreview ? "preview" : "fetch";
|
|
607
613
|
const startTime = Date.now();
|
|
608
|
-
|
|
614
|
+
const fullUrl = `${reqConfig.baseURL}${reqConfig.url}`;
|
|
615
|
+
logDebug({ config: this.config, message: `AgilityCMS Fetch API LOG: ${fullUrl}` });
|
|
609
616
|
try {
|
|
610
|
-
const fullUrl = `${reqConfig.baseURL}${reqConfig.url}`;
|
|
611
617
|
let init = {
|
|
612
618
|
...this.config.fetchConfig,
|
|
613
619
|
method: "GET",
|
|
@@ -621,92 +627,93 @@
|
|
|
621
627
|
init.cache = "no-store";
|
|
622
628
|
delete init.next;
|
|
623
629
|
}
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
}
|
|
635
|
-
}
|
|
630
|
+
logDebugDetails({
|
|
631
|
+
config: this.config,
|
|
632
|
+
details: {
|
|
633
|
+
type: "request",
|
|
634
|
+
url: fullUrl,
|
|
635
|
+
method: init.method,
|
|
636
|
+
guid: this.config.guid,
|
|
637
|
+
apiType,
|
|
638
|
+
requestHeaders: init.headers,
|
|
639
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
640
|
+
}
|
|
641
|
+
});
|
|
636
642
|
const response = await fetch(fullUrl, init);
|
|
637
643
|
const duration = Date.now() - startTime;
|
|
638
644
|
if (!response.ok) {
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
response.
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
let errorBody = "";
|
|
645
|
-
try {
|
|
646
|
-
errorBody = await response.text();
|
|
647
|
-
} catch (e) {
|
|
648
|
-
errorBody = "Unable to read error response body";
|
|
649
|
-
}
|
|
650
|
-
logDebugDetails({
|
|
651
|
-
config: this.config,
|
|
652
|
-
details: {
|
|
653
|
-
type: "error",
|
|
654
|
-
url: fullUrl,
|
|
655
|
-
method: init.method,
|
|
656
|
-
statusCode: response.status,
|
|
657
|
-
statusText: response.statusText,
|
|
658
|
-
headers: responseHeaders,
|
|
659
|
-
responsePreview: errorBody.substring(0, 500),
|
|
660
|
-
// First 500 chars
|
|
661
|
-
duration,
|
|
662
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
663
|
-
}
|
|
664
|
-
});
|
|
665
|
-
}
|
|
666
|
-
if (response.status === 404) {
|
|
667
|
-
logInfo({ config: this.config, message: `AgilityCMS Fetch API: Request returned a ${response.status} response for ${reqConfig.baseURL}${reqConfig.url}. ${response.statusText}` });
|
|
668
|
-
return;
|
|
645
|
+
let errorBody = "";
|
|
646
|
+
try {
|
|
647
|
+
errorBody = await response.text();
|
|
648
|
+
} catch (e) {
|
|
649
|
+
errorBody = "Unable to read error response body";
|
|
669
650
|
}
|
|
670
|
-
logError({ config: this.config, message: `AgilityCMS Fetch API ERROR: Request returned a ${response.status} response for ${reqConfig.baseURL}${reqConfig.url}. ${response.statusText}` });
|
|
671
|
-
return;
|
|
672
|
-
}
|
|
673
|
-
let data = await response.json();
|
|
674
|
-
if (this.config.debug) {
|
|
675
|
-
const responseHeaders = {};
|
|
676
|
-
response.headers.forEach((value, key) => {
|
|
677
|
-
responseHeaders[key] = value;
|
|
678
|
-
});
|
|
679
651
|
logDebugDetails({
|
|
680
652
|
config: this.config,
|
|
681
653
|
details: {
|
|
682
|
-
type: "
|
|
654
|
+
type: "error",
|
|
683
655
|
url: fullUrl,
|
|
684
656
|
method: init.method,
|
|
657
|
+
guid: this.config.guid,
|
|
658
|
+
apiType,
|
|
685
659
|
statusCode: response.status,
|
|
686
660
|
statusText: response.statusText,
|
|
687
|
-
|
|
661
|
+
requestHeaders: init.headers,
|
|
662
|
+
responseHeaders: headersToObject(response.headers),
|
|
663
|
+
responsePreview: errorBody.substring(0, 2e3),
|
|
664
|
+
responsePreviewTruncated: errorBody.length > 2e3,
|
|
688
665
|
duration,
|
|
689
666
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
690
667
|
}
|
|
691
668
|
});
|
|
669
|
+
const bodySnippet = errorBody ? ` Response body: ${errorBody.substring(0, 500)}` : "";
|
|
670
|
+
if (response.status === 404) {
|
|
671
|
+
logInfo({ config: this.config, message: `AgilityCMS Fetch API: Request returned a ${response.status} response for ${fullUrl}. ${response.statusText}.${bodySnippet}` });
|
|
672
|
+
return;
|
|
673
|
+
}
|
|
674
|
+
logError({ config: this.config, message: `AgilityCMS Fetch API ERROR: Request returned a ${response.status} (${response.statusText}) response for ${fullUrl}. Duration: ${duration}ms.${bodySnippet}` });
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
let data = await response.json();
|
|
678
|
+
logDebugDetails({
|
|
679
|
+
config: this.config,
|
|
680
|
+
details: {
|
|
681
|
+
type: "response",
|
|
682
|
+
url: fullUrl,
|
|
683
|
+
method: init.method,
|
|
684
|
+
guid: this.config.guid,
|
|
685
|
+
apiType,
|
|
686
|
+
statusCode: response.status,
|
|
687
|
+
statusText: response.statusText,
|
|
688
|
+
responseHeaders: headersToObject(response.headers),
|
|
689
|
+
contentType: response.headers.get("content-type") ?? void 0,
|
|
690
|
+
contentLength: response.headers.get("content-length") ?? void 0,
|
|
691
|
+
duration,
|
|
692
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
693
|
+
}
|
|
694
|
+
});
|
|
695
|
+
if (this.config.debug) {
|
|
692
696
|
data["agilityResponseHeaders"] = response.headers;
|
|
693
697
|
}
|
|
694
698
|
return data;
|
|
695
699
|
} catch (error) {
|
|
696
700
|
const duration = Date.now() - startTime;
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
701
|
+
logDebugDetails({
|
|
702
|
+
config: this.config,
|
|
703
|
+
details: {
|
|
704
|
+
type: "error",
|
|
705
|
+
url: fullUrl,
|
|
706
|
+
method: "GET",
|
|
707
|
+
guid: this.config.guid,
|
|
708
|
+
apiType,
|
|
709
|
+
errorName: error instanceof Error ? error.name : void 0,
|
|
710
|
+
errorMessage: error instanceof Error ? error.message : String(error),
|
|
711
|
+
errorStack: error instanceof Error ? error.stack : void 0,
|
|
712
|
+
duration,
|
|
713
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
714
|
+
}
|
|
715
|
+
});
|
|
716
|
+
logError({ config: this.config, message: `AgilityCMS Fetch API ERROR: Request failed for ${fullUrl} after ${duration}ms ... ${error}` });
|
|
710
717
|
}
|
|
711
718
|
}
|
|
712
719
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,8 @@ import { ContentList } from "./types/ContentList";
|
|
|
4
4
|
import { Filter } from "./types/Filter";
|
|
5
5
|
import { Gallery } from "./types/Gallery";
|
|
6
6
|
import { Page } from "./types/Page";
|
|
7
|
+
import { PageScripts } from "./types/PageScripts";
|
|
7
8
|
import { ApiClientInstance, getApi } from "./api-client";
|
|
8
9
|
import { ContentReference } from "./types/ContentReference";
|
|
9
|
-
export type { ApiClientInstance, Config, ContentItem, ContentList, ContentReference, Filter, Gallery, Page };
|
|
10
|
+
export type { ApiClientInstance, Config, ContentItem, ContentList, ContentReference, Filter, Gallery, Page, PageScripts };
|
|
10
11
|
export { getApi };
|
package/dist/node.js
CHANGED
|
@@ -39,37 +39,42 @@ function logError({ config, message }) {
|
|
|
39
39
|
return;
|
|
40
40
|
console.error("\x1B[41m%s\x1B[0m", message);
|
|
41
41
|
}
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
var SENSITIVE_HEADERS = ["apikey", "authorization", "x-api-key"];
|
|
43
|
+
function headersToObject(headers) {
|
|
44
|
+
const obj = {};
|
|
44
45
|
if (headers instanceof Headers) {
|
|
45
46
|
headers.forEach((value, key) => {
|
|
46
|
-
|
|
47
|
-
sanitized[key] = "***REDACTED***";
|
|
48
|
-
} else {
|
|
49
|
-
sanitized[key] = value;
|
|
50
|
-
}
|
|
47
|
+
obj[key] = value;
|
|
51
48
|
});
|
|
52
49
|
} else {
|
|
53
50
|
Object.keys(headers).forEach((key) => {
|
|
54
|
-
|
|
55
|
-
sanitized[key] = "***REDACTED***";
|
|
56
|
-
} else {
|
|
57
|
-
sanitized[key] = headers[key];
|
|
58
|
-
}
|
|
51
|
+
obj[key] = headers[key];
|
|
59
52
|
});
|
|
60
53
|
}
|
|
54
|
+
return obj;
|
|
55
|
+
}
|
|
56
|
+
function sanitizeHeaders(headers) {
|
|
57
|
+
const sanitized = headersToObject(headers);
|
|
58
|
+
Object.keys(sanitized).forEach((key) => {
|
|
59
|
+
if (SENSITIVE_HEADERS.includes(key.toLowerCase())) {
|
|
60
|
+
sanitized[key] = "***REDACTED***";
|
|
61
|
+
}
|
|
62
|
+
});
|
|
61
63
|
return sanitized;
|
|
62
64
|
}
|
|
63
65
|
function logDebugDetails({ config, details }) {
|
|
64
|
-
if (!config.debug)
|
|
66
|
+
if (!config.debug && config.logLevel !== "debug")
|
|
65
67
|
return;
|
|
66
68
|
const sanitizedDetails = {
|
|
67
69
|
...details,
|
|
68
|
-
|
|
70
|
+
requestHeaders: details.requestHeaders ? sanitizeHeaders(details.requestHeaders) : void 0,
|
|
71
|
+
responseHeaders: details.responseHeaders ? sanitizeHeaders(details.responseHeaders) : void 0
|
|
69
72
|
};
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
+
const banner = `=== AgilityCMS Fetch API Debug [${details.type.toUpperCase()}] ===`;
|
|
74
|
+
const log = details.type === "error" ? console.error : console.log;
|
|
75
|
+
log("\x1B[36m%s\x1B[0m", banner);
|
|
76
|
+
log(JSON.stringify(sanitizedDetails, null, 2));
|
|
77
|
+
log("\x1B[36m%s\x1B[0m", "=".repeat(banner.length));
|
|
73
78
|
}
|
|
74
79
|
function buildRequestUrlPath(config, locale) {
|
|
75
80
|
let apiFetchOrPreview = "";
|
|
@@ -622,10 +627,11 @@ var ApiClient = class {
|
|
|
622
627
|
//the function that actually makes ALL our requests
|
|
623
628
|
async makeRequest(reqConfig) {
|
|
624
629
|
const isPreview = !!this.config.isPreview;
|
|
630
|
+
const apiType = isPreview ? "preview" : "fetch";
|
|
625
631
|
const startTime = Date.now();
|
|
626
|
-
|
|
632
|
+
const fullUrl = `${reqConfig.baseURL}${reqConfig.url}`;
|
|
633
|
+
logDebug({ config: this.config, message: `AgilityCMS Fetch API LOG: ${fullUrl}` });
|
|
627
634
|
try {
|
|
628
|
-
const fullUrl = `${reqConfig.baseURL}${reqConfig.url}`;
|
|
629
635
|
let init = {
|
|
630
636
|
...this.config.fetchConfig,
|
|
631
637
|
method: "GET",
|
|
@@ -639,92 +645,93 @@ var ApiClient = class {
|
|
|
639
645
|
init.cache = "no-store";
|
|
640
646
|
delete init.next;
|
|
641
647
|
}
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
}
|
|
653
|
-
}
|
|
648
|
+
logDebugDetails({
|
|
649
|
+
config: this.config,
|
|
650
|
+
details: {
|
|
651
|
+
type: "request",
|
|
652
|
+
url: fullUrl,
|
|
653
|
+
method: init.method,
|
|
654
|
+
guid: this.config.guid,
|
|
655
|
+
apiType,
|
|
656
|
+
requestHeaders: init.headers,
|
|
657
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
658
|
+
}
|
|
659
|
+
});
|
|
654
660
|
const response = await fetch(fullUrl, init);
|
|
655
661
|
const duration = Date.now() - startTime;
|
|
656
662
|
if (!response.ok) {
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
response.
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
let errorBody = "";
|
|
663
|
-
try {
|
|
664
|
-
errorBody = await response.text();
|
|
665
|
-
} catch (e) {
|
|
666
|
-
errorBody = "Unable to read error response body";
|
|
667
|
-
}
|
|
668
|
-
logDebugDetails({
|
|
669
|
-
config: this.config,
|
|
670
|
-
details: {
|
|
671
|
-
type: "error",
|
|
672
|
-
url: fullUrl,
|
|
673
|
-
method: init.method,
|
|
674
|
-
statusCode: response.status,
|
|
675
|
-
statusText: response.statusText,
|
|
676
|
-
headers: responseHeaders,
|
|
677
|
-
responsePreview: errorBody.substring(0, 500),
|
|
678
|
-
// First 500 chars
|
|
679
|
-
duration,
|
|
680
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
681
|
-
}
|
|
682
|
-
});
|
|
683
|
-
}
|
|
684
|
-
if (response.status === 404) {
|
|
685
|
-
logInfo({ config: this.config, message: `AgilityCMS Fetch API: Request returned a ${response.status} response for ${reqConfig.baseURL}${reqConfig.url}. ${response.statusText}` });
|
|
686
|
-
return;
|
|
663
|
+
let errorBody = "";
|
|
664
|
+
try {
|
|
665
|
+
errorBody = await response.text();
|
|
666
|
+
} catch (e) {
|
|
667
|
+
errorBody = "Unable to read error response body";
|
|
687
668
|
}
|
|
688
|
-
logError({ config: this.config, message: `AgilityCMS Fetch API ERROR: Request returned a ${response.status} response for ${reqConfig.baseURL}${reqConfig.url}. ${response.statusText}` });
|
|
689
|
-
return;
|
|
690
|
-
}
|
|
691
|
-
let data = await response.json();
|
|
692
|
-
if (this.config.debug) {
|
|
693
|
-
const responseHeaders = {};
|
|
694
|
-
response.headers.forEach((value, key) => {
|
|
695
|
-
responseHeaders[key] = value;
|
|
696
|
-
});
|
|
697
669
|
logDebugDetails({
|
|
698
670
|
config: this.config,
|
|
699
671
|
details: {
|
|
700
|
-
type: "
|
|
672
|
+
type: "error",
|
|
701
673
|
url: fullUrl,
|
|
702
674
|
method: init.method,
|
|
675
|
+
guid: this.config.guid,
|
|
676
|
+
apiType,
|
|
703
677
|
statusCode: response.status,
|
|
704
678
|
statusText: response.statusText,
|
|
705
|
-
|
|
679
|
+
requestHeaders: init.headers,
|
|
680
|
+
responseHeaders: headersToObject(response.headers),
|
|
681
|
+
responsePreview: errorBody.substring(0, 2e3),
|
|
682
|
+
responsePreviewTruncated: errorBody.length > 2e3,
|
|
706
683
|
duration,
|
|
707
684
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
708
685
|
}
|
|
709
686
|
});
|
|
687
|
+
const bodySnippet = errorBody ? ` Response body: ${errorBody.substring(0, 500)}` : "";
|
|
688
|
+
if (response.status === 404) {
|
|
689
|
+
logInfo({ config: this.config, message: `AgilityCMS Fetch API: Request returned a ${response.status} response for ${fullUrl}. ${response.statusText}.${bodySnippet}` });
|
|
690
|
+
return;
|
|
691
|
+
}
|
|
692
|
+
logError({ config: this.config, message: `AgilityCMS Fetch API ERROR: Request returned a ${response.status} (${response.statusText}) response for ${fullUrl}. Duration: ${duration}ms.${bodySnippet}` });
|
|
693
|
+
return;
|
|
694
|
+
}
|
|
695
|
+
let data = await response.json();
|
|
696
|
+
logDebugDetails({
|
|
697
|
+
config: this.config,
|
|
698
|
+
details: {
|
|
699
|
+
type: "response",
|
|
700
|
+
url: fullUrl,
|
|
701
|
+
method: init.method,
|
|
702
|
+
guid: this.config.guid,
|
|
703
|
+
apiType,
|
|
704
|
+
statusCode: response.status,
|
|
705
|
+
statusText: response.statusText,
|
|
706
|
+
responseHeaders: headersToObject(response.headers),
|
|
707
|
+
contentType: response.headers.get("content-type") ?? void 0,
|
|
708
|
+
contentLength: response.headers.get("content-length") ?? void 0,
|
|
709
|
+
duration,
|
|
710
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
711
|
+
}
|
|
712
|
+
});
|
|
713
|
+
if (this.config.debug) {
|
|
710
714
|
data["agilityResponseHeaders"] = response.headers;
|
|
711
715
|
}
|
|
712
716
|
return data;
|
|
713
717
|
} catch (error) {
|
|
714
718
|
const duration = Date.now() - startTime;
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
719
|
+
logDebugDetails({
|
|
720
|
+
config: this.config,
|
|
721
|
+
details: {
|
|
722
|
+
type: "error",
|
|
723
|
+
url: fullUrl,
|
|
724
|
+
method: "GET",
|
|
725
|
+
guid: this.config.guid,
|
|
726
|
+
apiType,
|
|
727
|
+
errorName: error instanceof Error ? error.name : void 0,
|
|
728
|
+
errorMessage: error instanceof Error ? error.message : String(error),
|
|
729
|
+
errorStack: error instanceof Error ? error.stack : void 0,
|
|
730
|
+
duration,
|
|
731
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
732
|
+
}
|
|
733
|
+
});
|
|
734
|
+
logError({ config: this.config, message: `AgilityCMS Fetch API ERROR: Request failed for ${fullUrl} after ${duration}ms ... ${error}` });
|
|
728
735
|
}
|
|
729
736
|
}
|
|
730
737
|
};
|
package/dist/types/Config.d.ts
CHANGED
|
@@ -31,11 +31,14 @@ export interface Config {
|
|
|
31
31
|
logLevel?: 'debug' | 'info' | 'warn' | 'error' | 'silent';
|
|
32
32
|
/**
|
|
33
33
|
* Enable debug mode for detailed logging. Default is false.
|
|
34
|
+
* Detailed logging is also enabled when logLevel is set to 'debug'.
|
|
34
35
|
* When enabled:
|
|
35
|
-
* - Adds comprehensive request/response logging with timing information
|
|
36
|
-
*
|
|
37
|
-
* - Logs error details including status codes, headers,
|
|
38
|
-
*
|
|
36
|
+
* - Adds comprehensive structured request/response/error logging with timing information,
|
|
37
|
+
* instance guid, api type (fetch/preview), and request/response headers
|
|
38
|
+
* - Logs error details including status codes, headers, response body previews,
|
|
39
|
+
* and exception name/message/stack
|
|
40
|
+
* - Sanitizes sensitive data (API keys, auth tokens) in debug output
|
|
41
|
+
* - When debug is true, also includes response headers in the returned data as 'agilityResponseHeaders'
|
|
39
42
|
*/
|
|
40
43
|
debug?: boolean;
|
|
41
44
|
/**
|
package/dist/types/Page.d.ts
CHANGED
|
@@ -15,11 +15,13 @@
|
|
|
15
15
|
* @property {string} [redirectUrl] - If this page is a *link*, then this property will show the intended destination redirect.
|
|
16
16
|
* @property {number} [dynamicItemContentID] - If this page is a dynamic page, then this property will show the associated contentID of the dynamic content item.
|
|
17
17
|
* @property {AgilityFetch.Types.SitemapVisibility} visible - Object that contains properties pertaining to the intended visibility of this page for seo and menus.
|
|
18
|
+
* @property {AgilityFetch.Types.PageScripts} [scripts] - The page's custom head/body scripts, and whether it opts out of the instance's global scripts.
|
|
18
19
|
*/
|
|
19
20
|
import { ContentZone } from "./ContentZone";
|
|
20
21
|
import { SystemProperties } from "./SystemProperties";
|
|
21
22
|
import { SitemapVisibility } from "./SitemapVisibility";
|
|
22
23
|
import { SEOProperties } from "./SEO";
|
|
24
|
+
import { PageScripts } from "./PageScripts";
|
|
23
25
|
export interface Page {
|
|
24
26
|
pageID: number;
|
|
25
27
|
name: string;
|
|
@@ -37,4 +39,5 @@ export interface Page {
|
|
|
37
39
|
dynamicItemContentID?: number;
|
|
38
40
|
visible: SitemapVisibility;
|
|
39
41
|
seo?: SEOProperties;
|
|
42
|
+
scripts?: PageScripts | null;
|
|
40
43
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines the custom scripts configured on a **Page** in the CMS.
|
|
3
|
+
* @interface PageScripts
|
|
4
|
+
* @memberof AgilityFetch.Types
|
|
5
|
+
* @property {boolean} excludedFromGlobal - Whether this page opts out of the instance's global scripts. When `true`, the global head and body scripts should not be rendered on this page.
|
|
6
|
+
* @property {string | null} top - The page's custom head scripts (HTML to render inside `<head>`), or `null` if none are set.
|
|
7
|
+
* @property {string | null} bottom - The page's custom body scripts (HTML to render at the end of `<body>`), or `null` if none are set.
|
|
8
|
+
*/
|
|
9
|
+
export interface PageScripts {
|
|
10
|
+
excludedFromGlobal: boolean;
|
|
11
|
+
top: string | null;
|
|
12
|
+
bottom: string | null;
|
|
13
|
+
}
|
package/dist/utils.d.ts
CHANGED
|
@@ -11,16 +11,29 @@ interface DebugDetails {
|
|
|
11
11
|
type: 'request' | 'response' | 'error';
|
|
12
12
|
url?: string;
|
|
13
13
|
method?: string;
|
|
14
|
-
|
|
14
|
+
guid?: string | null;
|
|
15
|
+
apiType?: 'fetch' | 'preview';
|
|
16
|
+
requestHeaders?: Record<string, any>;
|
|
17
|
+
responseHeaders?: Record<string, any>;
|
|
15
18
|
statusCode?: number;
|
|
16
19
|
statusText?: string;
|
|
20
|
+
contentType?: string;
|
|
21
|
+
contentLength?: string;
|
|
17
22
|
duration?: number;
|
|
18
23
|
timestamp?: string;
|
|
24
|
+
errorName?: string;
|
|
19
25
|
errorMessage?: string;
|
|
26
|
+
errorStack?: string;
|
|
20
27
|
responsePreview?: string;
|
|
28
|
+
responsePreviewTruncated?: boolean;
|
|
21
29
|
}
|
|
22
30
|
/**
|
|
23
|
-
*
|
|
31
|
+
* Converts a fetch Headers instance (or plain object) to a plain object
|
|
32
|
+
*/
|
|
33
|
+
declare function headersToObject(headers: Record<string, any> | Headers): Record<string, any>;
|
|
34
|
+
/**
|
|
35
|
+
* Logs detailed debug information about requests, responses, and errors
|
|
36
|
+
* in a uniform structured format. Enabled by config.debug or logLevel 'debug'.
|
|
24
37
|
*/
|
|
25
38
|
declare function logDebugDetails({ config, details }: {
|
|
26
39
|
config: Config;
|
|
@@ -30,4 +43,5 @@ declare function buildRequestUrlPath(config: any, locale: any): string;
|
|
|
30
43
|
declare function buildPathUrl(contentType: any, referenceName: any, skip: any, take: any, sort: any, direction: any, filters: any, filtersLogicOperator: any, filterString: any, contentLinkDepth: any, expandAllContentLinks: any): string;
|
|
31
44
|
declare function buildAuthHeader(config: any): any;
|
|
32
45
|
declare function isHttps(url: any): boolean;
|
|
33
|
-
export { buildPathUrl, buildAuthHeader, buildRequestUrlPath, isHttps, logError, logDebug, logInfo, logWarning, logDebugDetails };
|
|
46
|
+
export { buildPathUrl, buildAuthHeader, buildRequestUrlPath, isHttps, logError, logDebug, logInfo, logWarning, logDebugDetails, headersToObject };
|
|
47
|
+
export type { DebugDetails };
|
package/jest.config.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
preset: "ts-jest",
|
|
3
|
-
testEnvironment: "node",
|
|
4
|
-
testMatch: ["<rootDir>/test/**/*.tests.ts"],
|
|
5
|
-
};
|
|
1
|
+
module.exports = {
|
|
2
|
+
preset: "ts-jest",
|
|
3
|
+
testEnvironment: "node",
|
|
4
|
+
testMatch: ["<rootDir>/test/**/*.tests.ts"],
|
|
5
|
+
};
|
|
6
6
|
|
package/package.json
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@agility/content-fetch",
|
|
3
|
-
"version": "2.0.
|
|
4
|
-
"description": "JS/TS library for the Agility Fetch API",
|
|
5
|
-
"repository": {
|
|
6
|
-
"type": "git",
|
|
7
|
-
"url": "https://github.com/agility/agility-content-fetch-js-sdk.git"
|
|
8
|
-
},
|
|
9
|
-
"bugs": {
|
|
10
|
-
"url": "https://github.com/agility/agility-content-fetch-js-sdk.git/issues"
|
|
11
|
-
},
|
|
12
|
-
"homepage": "https://github.com/agility/agility-content-fetch-js-sdk.git#readme",
|
|
13
|
-
"main": "./dist/node.js",
|
|
14
|
-
"browser": "./dist/browser.js",
|
|
15
|
-
"module": "./dist/browser.js",
|
|
16
|
-
"types": "./dist/index.d.ts",
|
|
17
|
-
"engines": {
|
|
18
|
-
"node": ">= 18.0.0"
|
|
19
|
-
},
|
|
20
|
-
"scripts": {
|
|
21
|
-
"clean": "rimraf dist",
|
|
22
|
-
"build": "node build.js",
|
|
23
|
-
"prepare": "
|
|
24
|
-
"test": "jest",
|
|
25
|
-
"generate-docs": "node_modules/.bin/jsdoc --configure .jsdoc.json --verbose"
|
|
26
|
-
},
|
|
27
|
-
"keywords": [
|
|
28
|
-
"typescript",
|
|
29
|
-
"agility",
|
|
30
|
-
"cms",
|
|
31
|
-
"headlesscms",
|
|
32
|
-
"fetch-sdk"
|
|
33
|
-
],
|
|
34
|
-
"author": "Agility CMS",
|
|
35
|
-
"contributors": [
|
|
36
|
-
"Kevin Tran",
|
|
37
|
-
"Joel Varty",
|
|
38
|
-
"Aaron Taylor"
|
|
39
|
-
],
|
|
40
|
-
"license": "MIT",
|
|
41
|
-
"dependencies": {},
|
|
42
|
-
"devDependencies": {
|
|
43
|
-
"@types/jest": "^29.5.3",
|
|
44
|
-
"@types/node": "^18.11.9",
|
|
45
|
-
"agility-jsdoc-template": "1.0.3",
|
|
46
|
-
"esbuild": "^0.19.0",
|
|
47
|
-
"jest": "^29.6.2",
|
|
48
|
-
"npm-dts": "^1.3.12",
|
|
49
|
-
"rimraf": "^5.0.1",
|
|
50
|
-
"ts-jest": "^29.1.1",
|
|
51
|
-
"typescript": "^5.1.6"
|
|
52
|
-
}
|
|
53
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@agility/content-fetch",
|
|
3
|
+
"version": "2.0.13",
|
|
4
|
+
"description": "JS/TS library for the Agility Fetch API",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/agility/agility-content-fetch-js-sdk.git"
|
|
8
|
+
},
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/agility/agility-content-fetch-js-sdk.git/issues"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/agility/agility-content-fetch-js-sdk.git#readme",
|
|
13
|
+
"main": "./dist/node.js",
|
|
14
|
+
"browser": "./dist/browser.js",
|
|
15
|
+
"module": "./dist/browser.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">= 18.0.0"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"clean": "rimraf dist",
|
|
22
|
+
"build": "node build.js",
|
|
23
|
+
"prepare": "npm run build",
|
|
24
|
+
"test": "jest",
|
|
25
|
+
"generate-docs": "node_modules/.bin/jsdoc --configure .jsdoc.json --verbose"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"typescript",
|
|
29
|
+
"agility",
|
|
30
|
+
"cms",
|
|
31
|
+
"headlesscms",
|
|
32
|
+
"fetch-sdk"
|
|
33
|
+
],
|
|
34
|
+
"author": "Agility CMS",
|
|
35
|
+
"contributors": [
|
|
36
|
+
"Kevin Tran",
|
|
37
|
+
"Joel Varty",
|
|
38
|
+
"Aaron Taylor"
|
|
39
|
+
],
|
|
40
|
+
"license": "MIT",
|
|
41
|
+
"dependencies": {},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/jest": "^29.5.3",
|
|
44
|
+
"@types/node": "^18.11.9",
|
|
45
|
+
"agility-jsdoc-template": "1.0.3",
|
|
46
|
+
"esbuild": "^0.19.0",
|
|
47
|
+
"jest": "^29.6.2",
|
|
48
|
+
"npm-dts": "^1.3.12",
|
|
49
|
+
"rimraf": "^5.0.1",
|
|
50
|
+
"ts-jest": "^29.1.1",
|
|
51
|
+
"typescript": "^5.1.6"
|
|
52
|
+
}
|
|
53
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"module" : "commonjs",
|
|
4
|
-
"allowJs": true,
|
|
5
|
-
"declaration": true,
|
|
6
|
-
"jsx": "react-jsx",
|
|
7
|
-
"target": "es5",
|
|
8
|
-
"outDir": "./dist/",
|
|
9
|
-
"lib": ["es2016", "dom"],
|
|
10
|
-
"esModuleInterop": true,
|
|
11
|
-
"skipLibCheck": true,
|
|
12
|
-
"allowSyntheticDefaultImports": true
|
|
13
|
-
},
|
|
14
|
-
"include": ["src", "src/api-client.ts"]
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module" : "commonjs",
|
|
4
|
+
"allowJs": true,
|
|
5
|
+
"declaration": true,
|
|
6
|
+
"jsx": "react-jsx",
|
|
7
|
+
"target": "es5",
|
|
8
|
+
"outDir": "./dist/",
|
|
9
|
+
"lib": ["es2016", "dom"],
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"allowSyntheticDefaultImports": true
|
|
13
|
+
},
|
|
14
|
+
"include": ["src", "src/api-client.ts"]
|
|
15
15
|
}
|