Socket
Socket
Sign inDemoInstall

@verdaccio/utils

Package Overview
Dependencies
Maintainers
4
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@verdaccio/utils - npm Package Compare versions

Comparing version 6.0.0-6-next.8 to 6.0.0-6-next.9

2

build/matcher.d.ts

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

import { PackageList, PackageAccess } from '@verdaccio/types';
import { PackageAccess, PackageList } from '@verdaccio/types';
export declare function getMatchedPackagesSpec(pkgName: string, packages: PackageList): PackageAccess | void;

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

import { Package, Version, Author } from '@verdaccio/types';
import { Author, Package, Version } from '@verdaccio/types';
export declare type AuthorAvatar = Author & {
avatar?: string;
};
/**

@@ -70,1 +73,9 @@ * From normalize-package-data/lib/fixer.js

export declare function isVersionValid(packageMeta: any, packageVersion: any): boolean;
export declare function addGravatarSupport(pkgInfo: Package, online?: boolean): AuthorAvatar;
export declare const GENERIC_AVATAR: string;
/**
* Generate gravatar url from email address
*/
export declare function generateGravatarUrl(email?: string | void, online?: boolean): string;
export declare function normalizeContributors(contributors: Author[]): Author[];
export declare function deleteProperties(propertiesToDelete: string[], objectItem: any): any;

@@ -6,4 +6,8 @@ "use strict";

});
exports.GENERIC_AVATAR = void 0;
exports.addGravatarSupport = addGravatarSupport;
exports.buildToken = buildToken;
exports.deleteProperties = deleteProperties;
exports.formatAuthor = formatAuthor;
exports.generateGravatarUrl = generateGravatarUrl;
exports.getLatestVersion = getLatestVersion;

@@ -15,2 +19,3 @@ exports.getVersion = getVersion;

exports.mask = mask;
exports.normalizeContributors = normalizeContributors;
exports.normalizeDistTags = normalizeDistTags;

@@ -31,2 +36,4 @@ exports.pad = pad;

var _cryptoUtils = require("./crypto-utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -295,2 +302,97 @@

}
function addGravatarSupport(pkgInfo, online = true) {
const pkgInfoCopy = _objectSpread({}, pkgInfo);
const author = _lodash.default.get(pkgInfo, 'latest.author', null);
const contributors = normalizeContributors(_lodash.default.get(pkgInfo, 'latest.contributors', []));
const maintainers = _lodash.default.get(pkgInfo, 'latest.maintainers', []); // for author.
if (author && _lodash.default.isObject(author)) {
const {
email
} = author;
pkgInfoCopy.latest.author.avatar = generateGravatarUrl(email, online);
}
if (author && _lodash.default.isString(author)) {
pkgInfoCopy.latest.author = {
avatar: GENERIC_AVATAR,
email: '',
author
};
} // for contributors
if (_lodash.default.isEmpty(contributors) === false) {
pkgInfoCopy.latest.contributors = contributors.map(contributor => {
if (isObject(contributor)) {
contributor.avatar = generateGravatarUrl(contributor.email, online);
} else if (_lodash.default.isString(contributor)) {
contributor = {
avatar: GENERIC_AVATAR,
email: contributor,
name: contributor
};
}
return contributor;
});
} // for maintainers
if (_lodash.default.isEmpty(maintainers) === false) {
pkgInfoCopy.latest.maintainers = maintainers.map(maintainer => {
maintainer.avatar = generateGravatarUrl(maintainer.email, online);
return maintainer;
});
}
return pkgInfoCopy;
}
const AVATAR_PROVIDER = 'https://www.gravatar.com/avatar/';
const GENERIC_AVATAR = 'data:image/svg+xml;utf8,' + encodeURIComponent('<svg height="100" viewBox="-27 24 100 100" width="100" xmlns="http://www.w3.org/' + '2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><defs><circle cx="23" cy="7' + '4" id="a" r="50"/></defs><use fill="#F5EEE5" overflow="visible" xlink:href="#a"/' + '><clipPath id="b"><use overflow="visible" xlink:href="#a"/></clipPath><g clip-pa' + 'th="url(#b)"><defs><path d="M36 95.9c0 4 4.7 5.2 7.1 5.8 7.6 2 22.8 5.9 22.8 5.9' + ' 3.2 1.1 5.7 3.5 7.1 6.6v9.8H-27v-9.8c1.3-3.1 3.9-5.5 7.1-6.6 0 0 15.2-3.9 22.8-' + '5.9 2.4-.6 7.1-1.8 7.1-5.8V85h26v10.9z" id="c"/></defs><use fill="#E6C19C" overf' + 'low="visible" xlink:href="#c"/><clipPath id="d"><use overflow="visible" xlink:hr' + 'ef="#c"/></clipPath><path clip-path="url(#d)" d="M23.2 35h.2c3.3 0 8.2.2 11.4 2 ' + '3.3 1.9 7.3 5.6 8.5 12.1 2.4 13.7-2.1 35.4-6.3 42.4-4 6.7-9.8 9.2-13.5 9.4H23h-.' + '1c-3.7-.2-9.5-2.7-13.5-9.4-4.2-7-8.7-28.7-6.3-42.4 1.2-6.5 5.2-10.2 8.5-12.1 3.2' + '-1.8 8.1-2 11.4-2h.2z" fill="#D4B08C"/></g><path d="M22.6 40c19.1 0 20.7 13.8 20' + '.8 15.1 1.1 11.9-3 28.1-6.8 33.7-4 5.9-9.8 8.1-13.5 8.3h-.5c-3.8-.3-9.6-2.5-13.6' + '-8.4-3.8-5.6-7.9-21.8-6.8-33.8C2.3 53.7 3.5 40 22.6 40z" fill="#F2CEA5"/></svg>');
/**
* Generate gravatar url from email address
*/
exports.GENERIC_AVATAR = GENERIC_AVATAR;
function generateGravatarUrl(email = '', online = true) {
if (online && _lodash.default.isString(email) && _lodash.default.size(email) > 0) {
email = email.trim().toLocaleLowerCase();
const emailMD5 = (0, _cryptoUtils.stringToMD5)(email);
return `${AVATAR_PROVIDER}${emailMD5}`;
}
return GENERIC_AVATAR;
}
function normalizeContributors(contributors) {
if (_lodash.default.isNil(contributors)) {
return [];
} else if (contributors && _lodash.default.isArray(contributors) === false) {
// FIXME: this branch is clearly no an array, still tsc complains
// @ts-ignore
return [contributors];
} else if (_lodash.default.isString(contributors)) {
return [{
name: contributors
}];
}
return contributors;
}
function deleteProperties(propertiesToDelete, objectItem) {
_lodash.default.forEach(propertiesToDelete, property => {
delete objectItem[property];
});
return objectItem;
}
//# sourceMappingURL=utils.js.map
# @verdaccio/utils
## 6.0.0-6-next.9
### Minor Changes
- f86c31ed: feat: migrate web sidebar endpoint to fastify
reuse utils methods between packages
## 6.0.0-6-next.8

@@ -4,0 +12,0 @@

{
"name": "@verdaccio/utils",
"version": "6.0.0-6-next.8",
"version": "6.0.0-6-next.9",
"description": "verdaccio utilities",

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

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

import { createHash, pseudoRandomBytes, Hash } from 'crypto';
import { Hash, createHash, pseudoRandomBytes } from 'crypto';

@@ -3,0 +3,0 @@ export const defaultTarballHashAlgorithm = 'sha1';

@@ -1,4 +0,5 @@

import { PackageList, PackageAccess } from '@verdaccio/types';
import minimatch from 'minimatch';
import { PackageAccess, PackageList } from '@verdaccio/types';
export function getMatchedPackagesSpec(

@@ -5,0 +6,0 @@ pkgName: string,

import assert from 'assert';
import _ from 'lodash';
import semver from 'semver';
import { Package, Version, Author } from '@verdaccio/types';
import { DIST_TAGS, DEFAULT_USER } from '@verdaccio/core';
import { DEFAULT_USER, DIST_TAGS } from '@verdaccio/core';
import { Author, Package, Version } from '@verdaccio/types';
import { stringToMD5 } from './crypto-utils';
export type AuthorAvatar = Author & { avatar?: string };
/**

@@ -255,1 +259,109 @@ * From normalize-package-data/lib/fixer.js

}
export function addGravatarSupport(pkgInfo: Package, online = true): AuthorAvatar {
const pkgInfoCopy = { ...pkgInfo } as any;
const author: any = _.get(pkgInfo, 'latest.author', null) as any;
const contributors: AuthorAvatar[] = normalizeContributors(
_.get(pkgInfo, 'latest.contributors', [])
);
const maintainers = _.get(pkgInfo, 'latest.maintainers', []);
// for author.
if (author && _.isObject(author)) {
const { email } = author as Author;
pkgInfoCopy.latest.author.avatar = generateGravatarUrl(email, online);
}
if (author && _.isString(author)) {
pkgInfoCopy.latest.author = {
avatar: GENERIC_AVATAR,
email: '',
author,
};
}
// for contributors
if (_.isEmpty(contributors) === false) {
pkgInfoCopy.latest.contributors = contributors.map((contributor): AuthorAvatar => {
if (isObject(contributor)) {
contributor.avatar = generateGravatarUrl(contributor.email, online);
} else if (_.isString(contributor)) {
contributor = {
avatar: GENERIC_AVATAR,
email: contributor,
name: contributor,
};
}
return contributor;
});
}
// for maintainers
if (_.isEmpty(maintainers) === false) {
pkgInfoCopy.latest.maintainers = maintainers.map((maintainer): void => {
maintainer.avatar = generateGravatarUrl(maintainer.email, online);
return maintainer;
});
}
return pkgInfoCopy;
}
const AVATAR_PROVIDER = 'https://www.gravatar.com/avatar/';
export const GENERIC_AVATAR =
'data:image/svg+xml;utf8,' +
encodeURIComponent(
'<svg height="100" viewBox="-27 24 100 100" width="100" xmlns="http://www.w3.org/' +
'2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><defs><circle cx="23" cy="7' +
'4" id="a" r="50"/></defs><use fill="#F5EEE5" overflow="visible" xlink:href="#a"/' +
'><clipPath id="b"><use overflow="visible" xlink:href="#a"/></clipPath><g clip-pa' +
'th="url(#b)"><defs><path d="M36 95.9c0 4 4.7 5.2 7.1 5.8 7.6 2 22.8 5.9 22.8 5.9' +
' 3.2 1.1 5.7 3.5 7.1 6.6v9.8H-27v-9.8c1.3-3.1 3.9-5.5 7.1-6.6 0 0 15.2-3.9 22.8-' +
'5.9 2.4-.6 7.1-1.8 7.1-5.8V85h26v10.9z" id="c"/></defs><use fill="#E6C19C" overf' +
'low="visible" xlink:href="#c"/><clipPath id="d"><use overflow="visible" xlink:hr' +
'ef="#c"/></clipPath><path clip-path="url(#d)" d="M23.2 35h.2c3.3 0 8.2.2 11.4 2 ' +
'3.3 1.9 7.3 5.6 8.5 12.1 2.4 13.7-2.1 35.4-6.3 42.4-4 6.7-9.8 9.2-13.5 9.4H23h-.' +
'1c-3.7-.2-9.5-2.7-13.5-9.4-4.2-7-8.7-28.7-6.3-42.4 1.2-6.5 5.2-10.2 8.5-12.1 3.2' +
'-1.8 8.1-2 11.4-2h.2z" fill="#D4B08C"/></g><path d="M22.6 40c19.1 0 20.7 13.8 20' +
'.8 15.1 1.1 11.9-3 28.1-6.8 33.7-4 5.9-9.8 8.1-13.5 8.3h-.5c-3.8-.3-9.6-2.5-13.6' +
'-8.4-3.8-5.6-7.9-21.8-6.8-33.8C2.3 53.7 3.5 40 22.6 40z" fill="#F2CEA5"/></svg>'
);
/**
* Generate gravatar url from email address
*/
export function generateGravatarUrl(email: string | void = '', online: boolean = true): string {
if (online && _.isString(email) && _.size(email) > 0) {
email = email.trim().toLocaleLowerCase();
const emailMD5 = stringToMD5(email);
return `${AVATAR_PROVIDER}${emailMD5}`;
}
return GENERIC_AVATAR;
}
export function normalizeContributors(contributors: Author[]): Author[] {
if (_.isNil(contributors)) {
return [];
} else if (contributors && _.isArray(contributors) === false) {
// FIXME: this branch is clearly no an array, still tsc complains
// @ts-ignore
return [contributors];
} else if (_.isString(contributors)) {
return [
{
name: contributors,
},
];
}
return contributors;
}
export function deleteProperties(propertiesToDelete: string[], objectItem: any): any {
_.forEach(propertiesToDelete, (property): any => {
delete objectItem[property];
});
return objectItem;
}

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

import { validatePassword, createSessionToken, getAuthenticatedMessage } from '../src';
import { createSessionToken, getAuthenticatedMessage, validatePassword } from '../src';

@@ -3,0 +3,0 @@ describe('Auth Utilities', () => {

@@ -1,4 +0,13 @@

import { DIST_TAGS, DEFAULT_USER } from '@verdaccio/core';
import { validateMetadata, getVersion, normalizeDistTags, formatAuthor } from '../src/index';
import { DEFAULT_USER, DIST_TAGS } from '@verdaccio/core';
import {
GENERIC_AVATAR,
addGravatarSupport,
formatAuthor,
generateGravatarUrl,
getVersion,
normalizeDistTags,
validateMetadata,
} from '../src/index';
describe('Utilities', () => {

@@ -133,3 +142,210 @@ const metadata: any = {

});
describe('User utilities', () => {
test('should generate gravatar url with email', () => {
const gravatarUrl: string = generateGravatarUrl('user@verdaccio.org');
expect(gravatarUrl).toMatch('https://www.gravatar.com/avatar/');
expect(gravatarUrl).not.toMatch('000000000');
});
test('should generate generic gravatar url', () => {
const gravatarUrl: string = generateGravatarUrl();
expect(gravatarUrl).toMatch(GENERIC_AVATAR);
});
});
describe('addGravatarSupport', () => {
test('check for blank object', () => {
// @ts-ignore
expect(addGravatarSupport({})).toEqual({});
});
test('author, contributors and maintainers fields are not present', () => {
const packageInfo = {
latest: {},
};
// @ts-ignore
expect(addGravatarSupport(packageInfo)).toEqual(packageInfo);
});
test('author field is a blank object', () => {
const packageInfo = { latest: { author: {} } };
// @ts-ignore
expect(addGravatarSupport(packageInfo)).toEqual(packageInfo);
});
test('author field is a string type', () => {
const packageInfo = {
latest: { author: 'user@verdccio.org' },
};
const result = {
latest: {
author: {
author: 'user@verdccio.org',
avatar: GENERIC_AVATAR,
email: '',
},
},
};
// @ts-ignore
expect(addGravatarSupport(packageInfo)).toEqual(result);
});
test('author field is an object type with author information', () => {
const packageInfo = {
latest: { author: { name: 'verdaccio', email: 'user@verdccio.org' } },
};
const result = {
latest: {
author: {
avatar: 'https://www.gravatar.com/avatar/794d7f6ef93d0689437de3c3e48fadc7',
email: 'user@verdccio.org',
name: 'verdaccio',
},
},
};
// @ts-ignore
expect(addGravatarSupport(packageInfo)).toEqual(result);
});
test('contributor field is a blank array', () => {
const packageInfo = {
latest: {
contributors: [],
},
};
// @ts-ignore
expect(addGravatarSupport(packageInfo)).toEqual(packageInfo);
});
describe('contributors', () => {
test('contributors field has contributors', () => {
const packageInfo = {
latest: {
contributors: [
{ name: 'user', email: 'user@verdccio.org' },
{ name: 'user1', email: 'user1@verdccio.org' },
],
},
};
const result = {
latest: {
contributors: [
{
avatar: 'https://www.gravatar.com/avatar/794d7f6ef93d0689437de3c3e48fadc7',
email: 'user@verdccio.org',
name: 'user',
},
{
avatar: 'https://www.gravatar.com/avatar/51105a49ce4a9c2bfabf0f6a2cba3762',
email: 'user1@verdccio.org',
name: 'user1',
},
],
},
};
// @ts-ignore
expect(addGravatarSupport(packageInfo)).toEqual(result);
});
test('contributors field is an object', () => {
const packageInfo = {
latest: {
contributors: { name: 'user', email: 'user@verdccio.org' },
},
};
const result = {
latest: {
contributors: [
{
avatar: 'https://www.gravatar.com/avatar/794d7f6ef93d0689437de3c3e48fadc7',
email: 'user@verdccio.org',
name: 'user',
},
],
},
};
// @ts-ignore
expect(addGravatarSupport(packageInfo)).toEqual(result);
});
test('contributors field is a string', () => {
const contributor = 'Barney Rubble <b@rubble.com> (http://barnyrubble.tumblr.com/)';
const packageInfo = {
latest: {
contributors: contributor,
},
};
const result = {
latest: {
contributors: [
{
avatar: GENERIC_AVATAR,
email: contributor,
name: contributor,
},
],
},
};
// @ts-ignore
expect(addGravatarSupport(packageInfo)).toEqual(result);
});
});
test('maintainers field is a blank array', () => {
const packageInfo = {
latest: {
maintainers: [],
},
};
// @ts-ignore
expect(addGravatarSupport(packageInfo)).toEqual(packageInfo);
});
test('maintainers field has maintainers', () => {
const packageInfo = {
latest: {
maintainers: [
{ name: 'user', email: 'user@verdccio.org' },
{ name: 'user1', email: 'user1@verdccio.org' },
],
},
};
const result = {
latest: {
maintainers: [
{
avatar: 'https://www.gravatar.com/avatar/794d7f6ef93d0689437de3c3e48fadc7',
email: 'user@verdccio.org',
name: 'user',
},
{
avatar: 'https://www.gravatar.com/avatar/51105a49ce4a9c2bfabf0f6a2cba3762',
email: 'user1@verdccio.org',
name: 'user1',
},
],
},
};
// @ts-ignore
expect(addGravatarSupport(packageInfo)).toEqual(result);
});
});
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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