aws-s3-facia-tool
v2.0.1
Published
API on top of facia tool storage
Downloads
9
Readme
aws-s3-facia-tool
API on top of facia tool storage
Dependencies
This package has a peer dependency on aws-sdk
version 2.x
.
Installation
npm install aws-s3-facia-tool --save
Usage
const facia = require('aws-s3-facia-tool');
const client = new facia.Client({
'bucket': 'bucket-used-by-fronts-tool',
'env': 'CODE',
'configKey': 'where/config.json/lives',
'configHistoryPrefix': 'path/containing/config/history',
'collectionHistoryPrefix': 'path/containing/collections/history',
'collectionsPrefix': 'path/containing/collection.json',
'pressedPrefix': 'path/containing/pressed.json',
'maxParallelRequests': 6,
'maxDaysHistory': 7
});
Config
const facia = require('aws-s3-facia-tool');
const client = new facia.Client({});
facia.Config(client).fetch()
.then(config => {
// use the config here
})
Config.fetch()
- Fetch the config JSON from the bucket, returns aConfig
classConfig.head()
- Performs ahead
action, the resulting promise is resolved with the config metadata (e.g.ETag
,LastModified
)Config.get()
- Returns theConfig
class using in memory cache, it reads from the bucket only when the cache is empty.Config.json()
- Returns the config JSON instead of the utility class. It uses the cacheConfig.fetchAt(key)
- Returns aConfig
class reading fromkey
instead of the internal configuration
Config class
Instances of Config
class have the following methods
hasFront(front)
- Boolean, whether afront
existshasCollection(id)
- Boolean, whether a collection withid
existslistFrontsIds(priority)
- List of all front id. Optionally filter by prioritylistCollectionsIds()
- List of all collection idfront(path)
- Return aFront
class for the given pathcollection
- Return aCollection
class for the given idfronts.find(query)
- Return a list ofFront
classes for all paths that match thequery
collections.find(query)
- Return a list ofCollection
classes for all paths that match thequery
Collection
const facia = require('aws-s3-facia-tool');
const client = new facia.Client({});
facia.Collection(client).fetch()
.then(collection => {
// use the collection here
})
fetch (id, config)
- Fetch a collectionid
.config
is optional if you're just interested in the collection content, otherwise pass aconfig
objectfetchAt (id, key, config)
- Fetch a collection withid
at a specifiedkey
list()
- List all collections in the bucket (including the ones that have been removed from fronts)
Collection class
Instances of Front
class have the following methods
forEachArticle(action)
- Perform anaction
for each item in the collection.action
receives(stage, article)
wherestage
islive
/draft
/treats
setContent(json)
- Set the content of the collectionsetKey(key)
- Set the key storing the collection contenttoJSON()
- Return the collection as JSON. The result object containsconfig
: the collection configcollection
: the collection content
trails(stage)
- Return the list of trail instage
(live
/draft
/treats
)lastUpdated()
- Return the last updated dateisBackfilled()
- Whether the collection has a backfillhasMetadata(type)
- Whether the collection has metadata oftype
(e.g. collection tags)layout()
- Return the collection layoutvisibleStories(scope)
- Number of visible stories (above show more) on desktop and mobile
Front
const facia = require('aws-s3-facia-tool');
const client = new facia.Client({});
facia.Front(client).fetch()
.then(front => {
// use the front here
})
fetch (path, config)
- Fetch a front withpath
.config
is optional, the tool will get it from S3 if not specified
Front class
Instances of Front
class have the following methods
toJSON()
- Return the front a JSON. The result object containsconfig
: the front configurationcollections
: the collections configurationcollectionsFull
: the collections content
setCollection(id, collection)
- Set the content a collectioncollection(id)
- Return aCollection
class for the collection withid
lastUpdated()
- Return the last updated datepriority()
- Return the explicit prioritylistCollectionsIds()
- List all collection id
Press
const facia = require('aws-s3-facia-tool');
const client = new facia.Client({});
facia.Press(client).getLastModified('front-path', 'live')
.then(lastModified => {
// date
})
getLastModified(path, location)
- Get the last modified date of a front in eitherlive
ordraft