New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@bowtie/houndstooth-sdk

Package Overview
Dependencies
Maintainers
5
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bowtie/houndstooth-sdk - npm Package Compare versions

Comparing version

to
0.0.4

.jsdoc.json

24

package.json
{
"name": "@bowtie/houndstooth-sdk",
"version": "0.0.2",
"version": "0.0.4",
"description": "SDK for Houndstooth Editor",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"doc": "jsdoc --configure .jsdoc.json --verbose",
"doc:commit": "npm run doc && git add docs && git commit -m 'Generated Docs'",
"lint": "standard",
"lint:fix": "standard --fix",
"test": "npm run lint && nyc mocha test/**/*.spec.js && npm run nyc:report",
"test:watch": "mocha test/**/*.spec.js --watch",
"preversion": "npm test && npm run doc:commit",
"postversion": "git push --follow-tags",
"nyc:check": "nyc check-coverage --lines 95 --functions 95 --branches 95",
"nyc:report": "nyc report --reporter=lcov"
},

@@ -26,2 +35,7 @@ "repository": {

},
"standard": {
"ignore": [
"docs/*"
]
},
"homepage": "https://github.com/bowtie-co/node-houndstooth-sdk#readme",

@@ -39,5 +53,11 @@ "dependencies": {

"devDependencies": {
"chai": "^4.2.0",
"dirty-chai": "^2.0.1",
"dotenv": "^6.2.0",
"jsdoc": "^3.5.5",
"minami": "^1.2.3",
"mocha": "^6.0.2",
"nyc": "^13.3.0",
"standard": "^12.0.1"
}
}

@@ -0,2 +1,5 @@

[![Maintainability](https://api.codeclimate.com/v1/badges/e3b3b00e62464050aa24/maintainability)](https://codeclimate.com/github/bowtie-co/node-houndstooth-sdk/maintainability)
[![Test Coverage](https://api.codeclimate.com/v1/badges/e3b3b00e62464050aa24/test_coverage)](https://codeclimate.com/github/bowtie-co/node-houndstooth-sdk/test_coverage)
# node-houndstooth-sdk
NodeJS SDK for Houndstooth Editor

28

src/logger.js
// const winston = require('winston')
const { createLogger, format, transports } = require('winston');
const { combine, timestamp, label, printf } = format;
const { createLogger, format, transports } = require('winston')
const { combine, timestamp, label, printf } = format
const myFormat = printf(({ level, message, label, timestamp }) => {
return `${timestamp} [${label}] ${level}: ${message}`;
});
return `${timestamp} [${label}] ${level}: ${message}`
})

@@ -25,14 +25,14 @@ const logger = createLogger({

transports: [new transports.Console()]
});
})
// const logger = winston.createLogger({
// level: 'info',
// levels: {
// error: 0,
// warn: 1,
// info: 2,
// verbose: 3,
// debug: 4,
// silly: 5
// },
// level: 'info',
// levels: {
// error: 0,
// warn: 1,
// info: 2,
// verbose: 3,
// debug: 4,
// silly: 5
// },
// transports: [new winston.transports.Console({

@@ -39,0 +39,0 @@ // format: winston.format.simple()

const logger = require('../logger')
/**
* Base class for shared logic
*/
class Base {
constructor(options = {}) {
/**
* Constructor for a Base object
*
* @constructor
* @param {Object} [options] - Options for this object, copied onto itself
*/
constructor (options = {}) {
this.logger = logger

@@ -12,12 +21,27 @@ this.cached = {}

_params() {
/**
* Construct params object, starting with this.defaultParams
*
* @returns {Object} - Returns any params given merged ontop of defaultParams
*/
_params () {
return Object.assign({}, this.defaultParams, ...arguments)
}
_isCached(key, params = {}) {
return this.cached[key]
/**
* Check if a given key is cached
*
* @param {String} key - Key to check for in the cache
*/
_isCached (key) {
return typeof this.cached[key] !== 'undefined'
}
_cached(key, params = {}) {
if (typeof this.cached[key] !== 'undefined') {
/**
* Get cached value for a given key
*
* @param {String} key - Key to return value for from cache
*/
_cached (key) {
if (this._isCached(key)) {
this.logger.info(`Loading cached key: ${key}`)

@@ -29,3 +53,9 @@ }

_cache(key, value, params = {}) {
/**
* Cache a new key/value pair
*
* @param {String} key - Key to be cached
* @param {*} value - Value to be cached
*/
_cache (key, value) {
this.cached[key] = value

@@ -36,3 +66,8 @@

clearCache(key) {
/**
* Clear key (or all keys) from cache
*
* @param {String} [key] - Optional key to clear from cache, otherwise clear all
*/
clearCache (key) {
if (key && this.cached[key]) {

@@ -39,0 +74,0 @@ delete this.cached[key]

const yaml = require('js-yaml')
const { verifySchema, verifyRequired } = require('@bowtie/utils')
const { verifyRequired } = require('@bowtie/utils')

@@ -7,4 +7,16 @@ const Base = require('./Base')

/**
* Collection class
*/
class Collection extends Base {
constructor(options = {}) {
/**
* Create a Collection object
*
* @constructor
* @param {Object} options - Options for collection
* @param {Object} options.jekyll - The Jekyll instance for this collection
* @param {String} options.name - The name of this collection
* @param {String} options.path - The path to this collection
*/
constructor (options = {}) {
super(options)

@@ -20,3 +32,10 @@

parsePath(path, params = {}) {
/**
* Parse Jekyll file path
*
* @param {String} path - Path to be parsed (for Jekyll front matter + markdown content)
* @param {Object} [params] - Additional params (sent to github)
* @returns {Promise<Object>} - Returns promise with parsed data
*/
parsePath (path, params = {}) {
return new Promise(

@@ -62,2 +81,8 @@ (resolve, reject) => {

/**
* Get defaults for a collection (from "_fields.md" file in collection dir)
*
* @param {Object} [params] - Additional params (sent to github)
* @returns {Promise<Object>} - Returns promise with parsed data
*/
defaults (params = {}) {

@@ -67,3 +92,10 @@ return this.parsePath(`${this.path}/_fields.md`, params)

defaultsKey(key, params = {}) {
/**
* Load a single key from resolved defaults (fields or content)
*
* @param {String} key - Key to be loaded from defaults
* @param {Object} [params] - Additional params (sent to github)
* @returns {Promise<Object>} - Returns promise with parsed data for specified key
*/
defaultsKey (key, params = {}) {
return this.defaults(params).then(defaults => {

@@ -74,2 +106,8 @@ return Promise.resolve(defaults[key])

/**
* Get content for this collection (using defaultsKey method)
*
* @param {Object} [params] - Additional params (sent to github)
* @returns {Promise<String>} - Returns promise with parsed content
*/
content (params = {}) {

@@ -79,2 +117,8 @@ return this.defaultsKey('content', params)

/**
* Get fields for this collection (using defaultsKey method)
*
* @param {Object} [params] - Additional params (sent to github)
* @returns {Promise<Object>} - Returns promise with parsed fields
*/
fields (params = {}) {

@@ -84,2 +128,8 @@ return this.defaultsKey('fields', params)

/**
* Load items for this collection
*
* @param {Object} [params] - Additional params (sent to github)
* @returns {Promise<Array>} - Returns promise with array of CollectionItem objects
*/
items (params = {}) {

@@ -115,2 +165,11 @@ return new Promise(

/**
* Create a new item in this collection
*
* @param {Object} data - Data for new collection item
* @param {String} data.name - Name for new collection item
* @param {Object} [data.fields] - Fields for new collection item
* @param {String} [data.content] - Content for new collection item
* @param {Object} [params] - Additional params (sent to github)
*/
createItem (data, params = {}) {

@@ -117,0 +176,0 @@ verifyRequired(data, [ 'name' ])

const yaml = require('js-yaml')
const { verifySchema, verifyRequired } = require('@bowtie/utils')
const { verifyRequired } = require('@bowtie/utils')

@@ -7,3 +7,3 @@ const Base = require('./Base')

class CollectionItem extends Base {
constructor(options = {}) {
constructor (options = {}) {
verifyRequired(options, [ 'collection', 'name', 'path' ])

@@ -54,3 +54,3 @@

defaultsKey(key, params = {}) {
defaultsKey (key, params = {}) {
return this.defaults(params).then(defaults => {

@@ -57,0 +57,0 @@ return Promise.resolve(defaults[key])

const async = require('async')
const parse = require('parse-link-header')
const Octokit = require('@octokit/rest')
const { verifySchema, verifyRequired } = require('@bowtie/utils')
const { verifyRequired } = require('@bowtie/utils')

@@ -10,3 +10,3 @@ const Base = require('./Base')

class GitHub extends Base {
constructor(options = {}) {
constructor (options = {}) {
super(options)

@@ -72,3 +72,3 @@

auth(token) {
auth (token) {
if (token) {

@@ -75,0 +75,0 @@ this.octokit = new Octokit({ auth: `token ${token}` })

const toml = require('toml')
const yaml = require('js-yaml')
const { verifySchema, verifyRequired } = require('@bowtie/utils')
const { verifyRequired } = require('@bowtie/utils')
const Base = require('./Base')
const Collection = require('./Collection')
const GitHub = require('./GitHub')
class Jekyll extends Base {
constructor(options = {}) {
constructor (options = {}) {
verifyRequired(options, [ 'github', 'owner', 'repo' ])

@@ -22,3 +21,3 @@

config(params = {}) {
config (params = {}) {
return new Promise(

@@ -56,3 +55,3 @@ (resolve, reject) => {

collections(params = {}) {
collections (params = {}) {
return new Promise(

@@ -95,3 +94,3 @@ (resolve, reject) => {

collection(name, params = {}) {
collection (name, params = {}) {
return this.collections(params).then(collections => {

@@ -98,0 +97,0 @@ return Promise.resolve(collections.find(coll => coll.name === name))

@@ -1,2 +0,2 @@

const { verifySchema, verifyRequired } = require('@bowtie/utils')
const { verifyRequired } = require('@bowtie/utils')

@@ -6,3 +6,3 @@ const Base = require('./Base')

class Repo extends Base {
constructor(options = {}) {
constructor (options = {}) {
verifyRequired(options, [ 'github', 'owner', 'repo' ])

@@ -9,0 +9,0 @@

@@ -54,3 +54,3 @@ require('dotenv').config()

if (items.length > 4) {
items[items.length-1].delete({ message: 'Delete an item from sdk' }).then(item => {
items[items.length - 1].delete({ message: 'Delete an item from sdk' }).then(item => {
console.log('deleted item', item.name)

@@ -90,3 +90,2 @@ })

// const { user } = await github.user()

@@ -93,0 +92,0 @@ // console.log(user.login)