xible-registry-wrapper
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -47,4 +47,5 @@ module.exports = (XIBLE_REGISTRY_WRAPPER) => { | ||
static publish(obj, userToken) { | ||
return new OoHttpRequest('POST', `${XIBLE_REGISTRY_WRAPPER.url}/flows?token=${encodeURIComponent(userToken)}`) | ||
.toJson(obj); | ||
const req = new OoHttpRequest('POST', `${XIBLE_REGISTRY_WRAPPER.url}/flows`); | ||
req.headers['x-auth-token'] = encodeURIComponent(userToken); | ||
return req.toJson(obj); | ||
} | ||
@@ -51,0 +52,0 @@ |
@@ -1,3 +0,2 @@ | ||
module.exports = function(XIBLE_REGISTRY_WRAPPER) { | ||
module.exports = (XIBLE_REGISTRY_WRAPPER) => { | ||
const OoHttpRequest = require('oohttp').Request; | ||
@@ -8,3 +7,2 @@ | ||
constructor(obj) { | ||
if (obj) { | ||
@@ -14,7 +12,5 @@ Object.assign(this, obj); | ||
this.registryData = null; | ||
} | ||
getRegistryData() { | ||
if (this.registryData) { | ||
@@ -26,7 +22,5 @@ return Promise.resolve(this.registryData); | ||
return req.toJson(); | ||
} | ||
getTarballUrl() { | ||
return this.getRegistryData().then((json) => { | ||
@@ -44,7 +38,5 @@ | ||
}); | ||
} | ||
static mapHash(nodePacks) { | ||
Object.keys(nodePacks).forEach((nodePackName) => { | ||
@@ -55,14 +47,10 @@ nodePacks[nodePackName] = new NodePack(nodePacks[nodePackName]); | ||
return nodePacks; | ||
} | ||
static getAll() { | ||
let req = new OoHttpRequest('GET', `${XIBLE_REGISTRY_WRAPPER.url}/nodepacks`); | ||
return req.toJson().then(this.mapHash); | ||
} | ||
static getByName(nodePackName) { | ||
if (typeof nodePackName !== 'string') { | ||
@@ -75,3 +63,2 @@ return Promise.reject(`name argument must be a string`); | ||
.catch((err) => { | ||
if (err.statusCode === 404) { | ||
@@ -83,7 +70,5 @@ return Promise.resolve(null); | ||
}); | ||
} | ||
static search(searchString) { | ||
if (typeof searchString !== 'string') { | ||
@@ -93,12 +78,11 @@ return Promise.reject(`searchString argument must be a string`); | ||
let req = new OoHttpRequest('GET', `${XIBLE_REGISTRY_WRAPPER.url}/nodepacks?search=${encodeURIComponent(searchString)}`); | ||
return req.toJson().then(this.mapHash); | ||
const req = new OoHttpRequest('GET', `${XIBLE_REGISTRY_WRAPPER.url}/nodepacks?search=${encodeURIComponent(searchString)}`); | ||
return req.toJson() | ||
.then(this.mapHash); | ||
} | ||
static publish(obj, userToken) { | ||
let req = new OoHttpRequest('POST', `${XIBLE_REGISTRY_WRAPPER.url}/nodepacks?token=${encodeURIComponent(userToken)}`); | ||
const req = new OoHttpRequest('POST', `${XIBLE_REGISTRY_WRAPPER.url}/nodepacks`); | ||
req.headers['x-auth-token'] = encodeURIComponent(userToken); | ||
return req.toJson(obj); | ||
} | ||
@@ -109,3 +93,2 @@ | ||
return NodePack; | ||
}; |
{ | ||
"name": "xible-registry-wrapper", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "nodejs wrapper for a xible registry", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
27
User.js
@@ -1,3 +0,2 @@ | ||
module.exports = function(XIBLE_REGISTRY_WRAPPER) { | ||
module.exports = (XIBLE_REGISTRY_WRAPPER) => { | ||
const OoHttpRequest = require('oohttp').Request; | ||
@@ -8,29 +7,25 @@ | ||
constructor(obj) { | ||
if (obj) { | ||
Object.assign(this, obj); | ||
} | ||
} | ||
/** | ||
* adds a user to the registry. rejects if the user already exists | ||
* @param {User} user the user to add | ||
* @returns {Promise} a promise that resolves with a token | ||
* Adds a user to the registry. Rejects if the user already exists. | ||
* @param {User} user The user to add. | ||
* @returns {Promise} A promise that resolves with a token. | ||
*/ | ||
static add(user) { | ||
let req = new OoHttpRequest('POST', `${XIBLE_REGISTRY_WRAPPER.url}/users`); | ||
return req.toJson(user); | ||
} | ||
/** | ||
* resolves a user for a token, or null if the token can't be matched | ||
* @param {String} token the authentication token belonging to the user | ||
* @returns {Promise} a promise that resolves with the found user or null | ||
* Resolves a user for a token, or null if the token can't be matched. | ||
* @param {String} token The authentication token belonging to the user. | ||
* @returns {Promise.<User>} A promise that resolves with the found user or null. | ||
*/ | ||
static getByToken(token) { | ||
let req = new OoHttpRequest('GET', `${XIBLE_REGISTRY_WRAPPER.url}/users?token=${encodeURIComponent(token)}`); | ||
const req = new OoHttpRequest('GET', `${XIBLE_REGISTRY_WRAPPER.url}/users`); | ||
req.headers['x-auth-token'] = encodeURIComponent(token); | ||
return req.toObject(User) | ||
@@ -44,3 +39,2 @@ .catch((err) => { | ||
}); | ||
} | ||
@@ -53,3 +47,2 @@ | ||
getToken() { | ||
if (!this.password) { | ||
@@ -65,3 +58,2 @@ return Promise.reject(`No "password" set.`); | ||
return req.toJson(this); | ||
} | ||
@@ -72,3 +64,2 @@ | ||
return User; | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5980
177
6