Installations
npm install @agility/content-sync
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
16.20.2
NPM Version
8.19.4
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
agility
Download Statistics
Total Downloads
254,456
Last Day
273
Last Week
1,922
Last Month
9,400
Last Year
95,794
GitHub Statistics
3 Stars
70 Commits
3 Forks
5 Watching
15 Branches
7 Contributors
Bundle Size
68.90 kB
Minified
17.22 kB
Minified + Gzipped
Package Meta Information
Latest Version
1.1.8
Package Id
@agility/content-sync@1.1.8
Unpacked Size
222.76 kB
Size
46.46 kB
File Count
23
NPM Version
8.19.4
Node Version
16.20.2
Publised On
13 Dec 2024
Total Downloads
Cumulative downloads
Total Downloads
254,456
Last day
4.6%
273
Compared to previous day
Last week
-13.1%
1,922
Compared to previous week
Last month
-5.5%
9,400
Compared to previous month
Last year
92.2%
95,794
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Agility CMS Sync SDK
The Agility CMS Sync SDK provides an interface to sync, store and access content locally.
By keeping a local cache of your content, your web app can access content faster.
Benefits
- Access your content quickly, and locally in your web or mobile app
- Use your own persistent storage, such as Gatsby GraphQL, a Database, or Local Storage
- Simplify syncing content
Use Cases
- You want to reduce the amount of REST API calls made to your Agility CMS instance.
- You have a client-side Single Page Application, and want to cache content in local storage in the browser.
- You want so synchronize content from the CMS to another system such Redis Cache
- You are running a Server-Side Rendered (SSR) web app and you want to cache your content locally, reducing latency for retrieving content.
- You are using a Static Site Generator (SSG) and you don't want to have to re-source all of your content on each build.
- You have a client-side Single Page Application, and want to cache content in local storage in the browser.
How it Works
This Sync SDK uses the Sync API getSyncPages
and getSyncContent
found in our Agility CMS Content Fetch JS SDK and aims to abstract some of the complexities involved in managing synced content.
It Calls the Sync API and returns content that has not yet been synced. The first call will pull everything and save it to your local store. Subsequent calls will only refresh content that has changed since the last time the Sync API was called.
This SDK:
- Calls the API
- Manages your
syncToken
for you - Stores content in the filesystem (by default)
- Provides ability to extend and store/access content in other places
Setup
Install @agility/content-sync
:
npm install @agility/content-sync
Sync to Filesystem (using Defaults)
-
Create a sync client:
1import agilitySync from '@agility/content-sync' 2const syncClient = agilitySync.getSyncClient({ 3 //your 'guid' from Agility CMS 4 guid: 'some-guid', 5 //your 'apiKey' from Agility CMS 6 apiKey: 'some-api-key', 7 //the language(s) of content you want to source 8 languages: ['en-us'], 9 //your channel(s) for the pages you want to source 10 channels: ['website'], 11 //whether you are using the preview key or not 12 isPreview: false 13});
-
Run the
runSync
command to synchronize your Agility CMS content (Content and Pages) to your local filesystem1await syncClient.runSync();
runSync()
will pull down all your Sitemap, Pages, and Content and store them in your local filesystem under the default path.agility-files
.
Accessing Content
Once content is in your sync store, you can easily access it as you need it:
1import agilitySync from '@agility/constent-sync' 2const syncClient = agilitySync.getSyncClient({ 3 //your 'guid' from Agility CMS 4 guid: 'some-guid', 5 //your 'apiKey' from Agility CMS 6 apiKey: 'some-api-key', 7 //the language(s) of content you want to source 8 languages: ['en-us'], 9 //your channel(s) for the pages you want to source 10 channels: ['website'] 11}); 12 13//start the sync process 14await syncClient.runSync(); 15 16//query and retrieve your content 17const contentItem = await syncClient.store.getContentItem({ 18 contentID: 21, 19 languageCode: languageCode 20}) 21 22const contentList = await syncClient.store.getContentList({ 23 referenceName: 'posts', 24 languageCode: languageCode 25})
Clearing out the Sync Content
To clear out the locally synced content, run the clearSync command.
1await syncClient.clearSync();
How to Create your Own Sync Store
While this SDK provides a filesystem sync interface by default, you can change this and use another one or create your own.
- Create a new
.js
file which exports the following methods:
1/** 2 * The function to handle saving/updating an item to your storage. This could be a Content Item, Page, Url Redirections, Sync State (state), or Sitemap. 3 * @param {Object} params - The parameters object 4 * @param {Object} params.options - A flexible object that can contain any properties specifically related to this interface 5 * @param {Object} params.item - The object representing the Content Item, Page, Url Redirections, Sync State (state), or Sitemap that needs to be saved/updated 6 * @param {String} params.itemType - The type of item being saved/updated, expected values are `item`, `page`, `sitemap`, `nestedsitemap`, `state`, `urlredirections` 7 * @param {String} params.languageCode - The locale code associated to the item being saved/updated 8 * @param {(String|Number)} params.itemID - The ID of the item being saved/updated - this could be a string or number depending on the itemType 9 * @returns {Void} 10 */ 11const saveItem = async ({ options, item, itemType, languageCode, itemID }) => { 12 console.log(`Console Interface: saveItem has been called`); 13 return null; 14} 15/** 16 * The function to handle deleting an item to your storage. This could be a Content Item, Page, Url Redirections, Sync State (state), or Sitemap. 17 * @param {Object} params - The parameters object 18 * @param {Object} params.options - A flexible object that can contain any properties specifically related to this interface 19 * @param {String} params.itemType - The type of item being deleted, expected values are `item`, `page`, `sitemap`, `nestedsitemap`, `state`, `urlredirections` 20 * @param {String} params.languageCode - The locale code associated to the item being saved/updated 21 * @param {(String|Number)} params.itemID - The ID of the item being deleted - this could be a string or number depending on the itemType 22 * @returns {Void} 23 */ 24const deleteItem = async ({ options, itemType, languageCode, itemID }) => { 25 console.log(`Console Interface: deleteItem has been called`); 26 return null; 27} 28/** 29 * The function to handle updating and placing a Content Item into a "list" so that you can handle querying a collection of items. 30 * @param {Object} params - The parameters object 31 * @param {Object} params.options - A flexible object that can contain any properties specifically related to this interface 32 * @param {Object} params.item - The object representing the Content Item 33 * @param {String} params.languageCode - The locale code associated to the item being saved/updated 34 * @param {(String|Number)} params.itemID - The ID of the item being updated - this could be a string or number depending on the itemType 35 * @param {String} params.referenceName - The reference name of the Content List that this Content Item should be added to 36 * @param {String} params.definitionName - The Model name that the Content Item is based on 37 * @returns {Void} 38 */ 39const mergeItemToList = async ({ options, item, languageCode, itemID, referenceName, definitionName }) => { 40 console.log(`Console Interface: mergeItemToList has been called`); 41 return null; 42} 43/** 44 * The function to handle retrieving a Content Item, Page, Url Redirections, Sync State (state), or Sitemap 45 * @param {Object} params - The parameters object 46 * @param {Object} params.options - A flexible object that can contain any properties specifically related to this interface 47 * @param {String} params.itemType - The type of item being accessed, expected values are `item`, `list`, `page`, `sitemap`, `nestedsitemap`, `state`, `urlredirections` 48 * @param {String} params.languageCode - The locale code associated to the item being accessed 49 * @param {(String|Number)} params.itemID - The ID of the item being accessed - this could be a string or number depending on the itemType 50 * @returns {Object} 51 */ 52const getItem = async ({ options, itemType, languageCode, itemID }) => { 53 console.log(`Console Interface: getItem has been called`) 54 return null; 55} 56/** 57 * The function to handle clearing the cache of synchronized data from the CMS 58 * @param {Object} params - The parameters object 59 * @param {Object} params.options - A flexible object that can contain any properties specifically related to this interface 60 * @returns {Void} 61 */ 62const clearItems = async ({ options }) => { 63 console.log(`Console Interface: clearItem has been called`) 64 return null; 65} 66 67module.exports = { 68 saveItem, 69 deleteItem, 70 mergeItemToList, 71 getItem, 72 clearItems 73}
- Register the
syncClient
to use your Sync Store
1import agilitySync from '@agility/constent-sync' 2import sampleSyncConsoleInterface from './store-interface-console' 3const syncClient = agilitySync.getSyncClient({ 4 //your 'guid' from Agility CMS 5 guid: 'some-guid', 6 //your 'apiKey' from Agility CMS 7 apiKey: 'some-api-key', 8 //the language(s) of content you want to source 9 languages: ['en-us'], 10 //your channel(s) for the pages you want to source 11 channels: ['website'], 12 //your custom storage/access interface 13 store: { 14 //must be the interface used to store and access content 15 interface: sampleSyncConsoleInterface, 16 //any options/config that you want to pass along to your interface as an argument 'options' 17 options: {} 18 } 19}); 20//start the sync process 21syncClient.runSync();
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
Found 6/16 approved changesets -- score normalized to 3
Reason
3 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 2
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
license file not detected
Details
- Warn: project does not have a license file
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 24 are checked with a SAST tool
Reason
24 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-x9w5-v3q2-3rhw
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-434g-2637-qmqr
- Warn: Project is vulnerable to: GHSA-49q7-c7j4-3p7m
- Warn: Project is vulnerable to: GHSA-977x-g7h5-7qgw
- Warn: Project is vulnerable to: GHSA-f7q4-pwc6-w24p
- Warn: Project is vulnerable to: GHSA-fc9h-whq2-v747
- Warn: Project is vulnerable to: GHSA-4q6p-r6v2-jvc5
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-76p3-8jx3-jpfq
- Warn: Project is vulnerable to: GHSA-3rfm-jhwj-7488
- Warn: Project is vulnerable to: GHSA-hhq3-ff78-jv3g
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-qrpm-p2h7-hrv2
- Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-mxhp-79qh-mcx6
- Warn: Project is vulnerable to: GHSA-4wf5-vphf-c2xc
Score
2
/10
Last Scanned on 2025-01-13
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More