Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

oc

Package Overview
Dependencies
Maintainers
1
Versions
472
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

oc - npm Package Compare versions

Comparing version 0.0.6 to 0.0.7

3

cli/facade/init.js

@@ -6,2 +6,3 @@ 'use strict';

var strings = require('../../resources/index');
var validator = require('../../registry/domain/validator');

@@ -17,3 +18,3 @@ module.exports = function(dependencies){

if(componentName.trim() === ''){
if(!validator.validateComponentName(componentName)){
return logger.log(format(errors.INIT_FAIL, errors.NAME_NOT_VALID).red);

@@ -20,0 +21,0 @@ }

{
"name": "oc",
"version": "0.0.6",
"version": "0.0.7",
"description": "An experimental framework to develop and distribute html components",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -9,2 +9,3 @@ 'use strict';

var strings = require('../../resources');
var validator = require('./validator');
var versionHandler = require('./version-handler');

@@ -149,2 +150,9 @@ var _ = require('underscore');

if(!validator.validateComponentName(componentName)){
return callback({
code: strings.errors.registry.COMPONENT_NAME_NOT_VALID_CODE,
msg: strings.errors.regitry.COMPONENT_NAME_NOT_VALID
});
}
this.getComponentVersions(componentName, function(err, componentVersions){

@@ -151,0 +159,0 @@

@@ -33,60 +33,5 @@ 'use strict';

module.exports = {
registryConfiguration: function(conf){
var response = { isValid: true };
var returnError = function(message){
response.isValid = false;
response.message = message || 'registry configuration is not valid';
return response;
};
if(!conf || !_.isObject(conf) || _.keys(conf).length === 0){
return returnError(strings.errors.registry.CONFIGURATION_EMPTY);
}
var prefix = conf.prefix;
if(!!prefix){
if(prefix.substr(0, 1) !== '/'){
return returnError(strings.errors.registry.CONFIGURATION_PREFIX_DOES_NOT_START_WITH_SLASH);
}
if(prefix.substr(prefix.length - 1) !== '/'){
return returnError(strings.errors.registry.CONFIGURATION_PREFIX_DOES_NOT_END_WITH_SLASH);
}
}
return response;
validateComponentName: function(componentName){
return !/[^a-zA-Z0-9\-\_]/.test(componentName);
},
validatePackage: function(input){
var response = {
isValid: true
};
var returnError = function(message){
response.isValid = false;
response.message = message || 'uploaded package is not valid';
return response;
};
if(!input || !_.isObject(input) || _.keys(input).length === 0){
return returnError('empty');
}
if(_.keys(input).length !== 1){
return returnError('not_valid');
}
var file = input[_.keys(input)[0]];
if(file.mimetype !== 'application/octet-stream' || !!file.truncated || file.extension !== 'gz' || file.path.indexOf('.tar.gz') < 0){
return returnError('not_valid');
}
return response;
},
validateVersion: function(version){
return { isValid: !!semver.valid(version) };
},
validateComponentParameters: function(requestParameters, expectedParameters){

@@ -157,3 +102,61 @@

return result;
},
registryConfiguration: function(conf){
var response = { isValid: true };
var returnError = function(message){
response.isValid = false;
response.message = message || 'registry configuration is not valid';
return response;
};
if(!conf || !_.isObject(conf) || _.keys(conf).length === 0){
return returnError(strings.errors.registry.CONFIGURATION_EMPTY);
}
var prefix = conf.prefix;
if(!!prefix){
if(prefix.substr(0, 1) !== '/'){
return returnError(strings.errors.registry.CONFIGURATION_PREFIX_DOES_NOT_START_WITH_SLASH);
}
if(prefix.substr(prefix.length - 1) !== '/'){
return returnError(strings.errors.registry.CONFIGURATION_PREFIX_DOES_NOT_END_WITH_SLASH);
}
}
return response;
},
validatePackage: function(input){
var response = {
isValid: true
};
var returnError = function(message){
response.isValid = false;
response.message = message || 'uploaded package is not valid';
return response;
};
if(!input || !_.isObject(input) || _.keys(input).length === 0){
return returnError('empty');
}
if(_.keys(input).length !== 1){
return returnError('not_valid');
}
var file = input[_.keys(input)[0]];
if(file.mimetype !== 'application/octet-stream' || !!file.truncated || file.extension !== 'gz' || file.path.indexOf('.tar.gz') < 0){
return returnError('not_valid');
}
return response;
},
validateVersion: function(version){
return { isValid: !!semver.valid(version) };
}
};

@@ -6,2 +6,4 @@ 'use strict';

registry: {
COMPONENT_NAME_NOT_VALID: 'The component\'s name contains invalid characters. Allowed are alphanumeric, _, -',
COMPONENT_NAME_NOT_VALID_CODE: 'name_not_valid',
COMPONENT_NOT_FOUND: 'Component "{0}" not found on {1}',

@@ -30,3 +32,3 @@ COMPONENT_VERSION_NOT_FOUND: 'Component "{0}" with version "{1}" not found on {2}',

INIT_FAIL: 'An error happened when initialising the component: {0}',
NAME_NOT_VALID: 'the name is not valid',
NAME_NOT_VALID: 'the name is not valid. Allowed characters are alphanumeric, _, -',
PACKAGING_FAIL: 'An error happened when creating the package: {0}',

@@ -33,0 +35,0 @@ PUBLISHING_FAIL: 'An error happened when publishing the component: {0}',

@@ -31,6 +31,17 @@ 'use strict';

it('should show an error', function(){
expect(logs[0]).to.equal('An error happened when initialising the component: the name is not valid'.red);
expect(logs[0]).to.equal('An error happened when initialising the component: the name is not valid. Allowed characters are alphanumeric, _, -'.red);
});
});
describe('when the component has a non valid name', function(){
beforeEach(function(){
execute('hello-asd$qwe:11');
});
it('should show an error', function(){
expect(logs[0]).to.equal('An error happened when initialising the component: the name is not valid. Allowed characters are alphanumeric, _, -'.red);
});
});
describe('when an error happens', function(){

@@ -37,0 +48,0 @@

@@ -319,2 +319,32 @@ 'use strict';

describe('when validating component name for new candidate', function(){
var validate = function(a){ return validator.validateComponentName(a); };
describe('when name has spaces', function(){
var name = 'hello ha';
it('should not be valid', function(){
expect(validate(name)).to.be.false;
});
});
describe('when name has not allowed characters', function(){
var name = 'name@ha';
it('should not be valid', function(){
expect(validate(name)).to.be.false;
});
});
describe('when name has alphanumeric characters, _ or -', function(){
var name = 'hello-world_haha23';
it('should be valid', function(){
expect(validate(name)).to.be.true;
});
});
});
describe('when validating component version for new candidate', function(){

@@ -321,0 +351,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc