Socket
Socket
Sign inDemoInstall

@akemona-org/strapi-utils

Package Overview
Dependencies
42
Maintainers
2
Versions
37
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.7.0 to 3.7.1

12

lib/build-query.js

@@ -28,3 +28,3 @@ 'use strict';

const assoc = tmpModel.associations.find(ast => ast.alias === part);
const assoc = tmpModel.associations.find((ast) => ast.alias === part);

@@ -63,3 +63,3 @@ if (assoc) {

return Array.isArray(value)
? value.map(val => castValue({ type, operator, value: val }))
? value.map((val) => castValue({ type, operator, value: val }))
: castValue({ type, operator, value: value });

@@ -89,5 +89,3 @@ };

return _.last(fieldPath) === 'id'
? _.initial(fieldPath)
.concat(model.primaryKey)
.join('.')
? _.initial(fieldPath).concat(model.primaryKey).join('.')
: fieldPath.join('.');

@@ -106,3 +104,3 @@ };

if (BOOLEAN_OPERATORS.includes(operator)) {
return value.some(clauses => hasDeepFilters({ where: clauses }));
return value.some((clauses) => hasDeepFilters({ where: clauses }));
}

@@ -132,3 +130,3 @@

operator,
value: value.map(clauses => normalizeWhereClauses(clauses, { model })),
value: value.map((clauses) => normalizeWhereClauses(clauses, { model })),
};

@@ -135,0 +133,0 @@ }

@@ -5,3 +5,3 @@ 'use strict';

// + converting timestamp to base 36 for better readibility
const generateTimestampCode = date => {
const generateTimestampCode = (date) => {
const referDate = date || new Date();

@@ -8,0 +8,0 @@

@@ -62,17 +62,19 @@ 'use strict';

const getAbsoluteUrl = adminOrServer => (config, forAdminBuild = false) => {
const { serverUrl, adminUrl } = getConfigUrls(config.server, forAdminBuild);
let url = adminOrServer === 'server' ? serverUrl : adminUrl;
const getAbsoluteUrl =
(adminOrServer) =>
(config, forAdminBuild = false) => {
const { serverUrl, adminUrl } = getConfigUrls(config.server, forAdminBuild);
let url = adminOrServer === 'server' ? serverUrl : adminUrl;
if (url.startsWith('http')) {
return url;
}
if (url.startsWith('http')) {
return url;
}
let hostname =
config.environment === 'development' && ['127.0.0.1', '0.0.0.0'].includes(config.server.host)
? 'localhost'
: config.server.host;
let hostname =
config.environment === 'development' && ['127.0.0.1', '0.0.0.0'].includes(config.server.host)
? 'localhost'
: config.server.host;
return `http://${hostname}:${config.server.port}${url}`;
};
return `http://${hostname}:${config.server.port}${url}`;
};

@@ -79,0 +81,0 @@ module.exports = {

@@ -29,3 +29,3 @@ 'use strict';

const getTimestamps = model => {
const getTimestamps = (model) => {
const timestamps = _.get(model, 'options.timestamps', []);

@@ -40,3 +40,3 @@

const getTimestampsAttributes = model => {
const getTimestampsAttributes = (model) => {
const timestamps = getTimestamps(model);

@@ -76,3 +76,3 @@

const getNonVisibleAttributes = model => {
const getNonVisibleAttributes = (model) => {
const nonVisibleAttributes = _.reduce(

@@ -87,3 +87,3 @@ model.attributes,

const getVisibleAttributes = model => {
const getVisibleAttributes = (model) => {
return _.difference(_.keys(model.attributes), getNonVisibleAttributes(model));

@@ -96,3 +96,3 @@ };

const hasDraftAndPublish = model => _.get(model, 'options.draftAndPublish', false) === true;
const hasDraftAndPublish = (model) => _.get(model, 'options.draftAndPublish', false) === true;

@@ -104,3 +104,3 @@ const isDraft = (data, model) =>

const isCollectionType = ({ kind = COLLECTION_TYPE }) => kind === COLLECTION_TYPE;
const isKind = kind => model => model.kind === kind;
const isKind = (kind) => (model) => model.kind === kind;

@@ -111,3 +111,3 @@ const getPrivateAttributes = (model = {}) => {

_.get(model, 'options.privateAttributes', []),
_.keys(_.pickBy(model.attributes, attr => !!attr.private))
_.keys(_.pickBy(model.attributes, (attr) => !!attr.private))
);

@@ -120,3 +120,3 @@ };

const isScalarAttribute = attribute => {
const isScalarAttribute = (attribute) => {
return (

@@ -130,9 +130,9 @@ !attribute.collection &&

const isMediaAttribute = attr => {
const isMediaAttribute = (attr) => {
return (attr.collection || attr.model) === 'file' && attr.plugin === 'upload';
};
const getKind = obj => obj.kind || 'collectionType';
const getKind = (obj) => obj.kind || 'collectionType';
const pickSchema = model => {
const pickSchema = (model) => {
const schema = _.cloneDeep(

@@ -200,3 +200,3 @@ _.pick(model, [

const isRelationalAttribute = attribute =>
const isRelationalAttribute = (attribute) =>
_.has(attribute, 'model') || _.has(attribute, 'collection');

@@ -218,3 +218,3 @@

*/
const getContentTypeRoutePrefix = contentType => {
const getContentTypeRoutePrefix = (contentType) => {
return isSingleType(contentType)

@@ -221,0 +221,0 @@ ? _.kebabCase(contentType.modelName)

@@ -75,3 +75,3 @@ 'use strict';

*/
const convertExtraRootParams = params => {
const convertExtraRootParams = (params) => {
return Object.entries(params).reduce((acc, [key, value]) => {

@@ -92,3 +92,3 @@ if (_.startsWith(key, '_') && !QUERY_OPERATORS.includes(key)) {

*/
const convertSortQueryParams = sortQuery => {
const convertSortQueryParams = (sortQuery) => {
if (typeof sortQuery !== 'string') {

@@ -100,3 +100,3 @@ throw new Error(`convertSortQueryParams expected a string, got ${typeof sortQuery}`);

sortQuery.split(',').forEach(part => {
sortQuery.split(',').forEach((part) => {
// split field and order param with default order to ascending

@@ -125,3 +125,3 @@ const [field, order = 'asc'] = part.split(':');

*/
const convertStartQueryParams = startQuery => {
const convertStartQueryParams = (startQuery) => {
const startAsANumber = _.toNumber(startQuery);

@@ -142,3 +142,3 @@

*/
const convertLimitQueryParams = limitQuery => {
const convertLimitQueryParams = (limitQuery) => {
const limitAsANumber = _.toNumber(limitQuery);

@@ -159,3 +159,3 @@

*/
const convertPublicationStateParams = publicationState => {
const convertPublicationStateParams = (publicationState) => {
if (!DP_PUB_STATES.includes(publicationState)) {

@@ -192,3 +192,3 @@ throw new Error(

*/
const convertWhereParams = whereParams => {
const convertWhereParams = (whereParams) => {
let finalWhere = [];

@@ -202,7 +202,8 @@

Object.keys(whereParams).forEach(whereClause => {
const { field, operator = 'eq', value } = convertWhereClause(
whereClause,
whereParams[whereClause]
);
Object.keys(whereParams).forEach((whereClause) => {
const {
field,
operator = 'eq',
value,
} = convertWhereClause(whereClause, whereParams[whereClause]);

@@ -209,0 +210,0 @@ finalWhere.push({

@@ -61,3 +61,3 @@ 'use strict';

return value.split(',').map(v => {
return value.split(',').map((v) => {
return _.trim(_.trim(v, ' '), '"');

@@ -64,0 +64,0 @@ });

@@ -26,3 +26,3 @@ 'use strict';

const where = _.findKey(api, o => {
const where = _.findKey(api, (o) => {
return _.get(o, `controllers.${controller}`);

@@ -29,0 +29,0 @@ });

@@ -27,7 +27,7 @@ 'use strict';

register: handler => {
register: (handler) => {
state.handlers.push(handler);
},
delete: handler => {
delete: (handler) => {
state.handlers = remove(eq(handler), state.handlers);

@@ -85,3 +85,3 @@ },

call(context) {
const promises = this.handlers.map(handler => handler(cloneDeep(context)));
const promises = this.handlers.map((handler) => handler(cloneDeep(context)));

@@ -88,0 +88,0 @@ return Promise.all(promises);

@@ -19,3 +19,3 @@ 'use strict';

initialize: cb => {
initialize: (cb) => {
cb();

@@ -61,4 +61,4 @@ },

// We have to find if they are a model linked to this key
_.forEach(allModels, model => {
_.forIn(model.attributes, attribute => {
_.forEach(allModels, (model) => {
_.forIn(model.attributes, (attribute) => {
if (_.has(attribute, 'via') && attribute.via === attributeName) {

@@ -177,4 +177,4 @@ if (_.has(attribute, 'collection') && attribute.collection === modelName) {

// We have to find if they are a model linked to this attributeName
_.forIn(models, model => {
_.forIn(model.attributes, attribute => {
_.forIn(models, (model) => {
_.forIn(model.attributes, (attribute) => {
if (_.has(attribute, 'via') && attribute.via === attributeName) {

@@ -199,4 +199,4 @@ if (_.has(attribute, 'collection') && attribute.collection === modelName) {

// We have to find if they are a model linked to this attributeName
_.forIn(models, model => {
_.forIn(model.attributes, attribute => {
_.forIn(models, (model) => {
_.forIn(model.attributes, (attribute) => {
if (_.has(attribute, 'via') && attribute.via === attributeName) {

@@ -347,3 +347,3 @@ if (_.has(attribute, 'collection') && attribute.collection === modelName) {

})
.map(table =>
.map((table) =>
_.snakeCase(`${pluralize.plural(table.collection)} ${pluralize.plural(table.via)}`)

@@ -358,3 +358,3 @@ )

defineAssociations: function(model, definition, association, key) {
defineAssociations: function (model, definition, association, key) {
try {

@@ -437,4 +437,4 @@ // Initialize associations object

const pluginsModels = Object.keys(strapi.plugins).reduce((acc, current) => {
Object.keys(strapi.plugins[current].models).forEach(entity => {
Object.keys(strapi.plugins[current].models[entity].attributes).forEach(attribute => {
Object.keys(strapi.plugins[current].models).forEach((entity) => {
Object.keys(strapi.plugins[current].models[entity].attributes).forEach((attribute) => {
const attr = strapi.plugins[current].models[entity].attributes[attribute];

@@ -452,3 +452,3 @@

const appModels = Object.keys(strapi.models).reduce((acc, entity) => {
Object.keys(strapi.models[entity].attributes).forEach(attribute => {
Object.keys(strapi.models[entity].attributes).forEach((attribute) => {
const attr = strapi.models[entity].attributes[attribute];

@@ -465,3 +465,3 @@

const componentModels = Object.keys(strapi.components).reduce((acc, entity) => {
Object.keys(strapi.components[entity].attributes).forEach(attribute => {
Object.keys(strapi.components[entity].attributes).forEach((attribute) => {
const attr = strapi.components[entity].attributes[attribute];

@@ -468,0 +468,0 @@

@@ -5,3 +5,3 @@ 'use strict';

const removeUndefined = obj => _.pickBy(obj, value => typeof value !== 'undefined');
const removeUndefined = (obj) => _.pickBy(obj, (value) => typeof value !== 'undefined');

@@ -8,0 +8,0 @@ module.exports = {

@@ -5,3 +5,3 @@ 'use strict';

module.exports = ctx => {
module.exports = (ctx) => {
const { body = {}, files = {} } = ctx.request;

@@ -8,0 +8,0 @@

@@ -6,7 +6,5 @@ 'use strict';

const timeRegex = new RegExp(
'^(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(.[0-9]{1,3})?$'
);
const timeRegex = new RegExp('^(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(.[0-9]{1,3})?$');
const parseTime = value => {
const parseTime = (value) => {
if (dates.isDate(value)) return dates.format(value, 'HH:mm:ss.SSS');

@@ -29,3 +27,3 @@

const parseDate = value => {
const parseDate = (value) => {
if (dates.isDate(value)) return dates.format(value, 'yyyy-MM-dd');

@@ -43,3 +41,3 @@ try {

const parseDateTimeOrTimestamp = value => {
const parseDateTimeOrTimestamp = (value) => {
if (dates.isDate(value)) return value;

@@ -78,5 +76,3 @@ try {

throw new Error(
'Invalid boolean input. Expected "t","1","true","false","0","f"'
);
throw new Error('Invalid boolean input. Expected "t","1","true","false","0","f"');
}

@@ -83,0 +79,0 @@ case 'integer':

@@ -24,9 +24,9 @@ /**

const resolveHandler = policy => (_.isFunction(policy) ? policy : policy.handler);
const resolveHandler = (policy) => (_.isFunction(policy) ? policy : policy.handler);
const parsePolicy = policy =>
const parsePolicy = (policy) =>
isPolicyFactory(policy) ? createPolicy(...policy) : createPolicy(policy);
const resolvePolicy = policyName => {
const resolver = policyResolvers.find(resolver => resolver.exists(policyName));
const resolvePolicy = (policyName) => {
const resolver = policyResolvers.find((resolver) => resolver.exists(policyName));

@@ -82,3 +82,3 @@ return resolver ? resolveHandler(resolver.get)(policyName) : undefined;

},
get: policy => {
get: (policy) => {
const [, policyWithoutPrefix] = policy.split('::');

@@ -97,3 +97,3 @@ const [api = '', policyName = ''] = policyWithoutPrefix.split('.');

},
get: policy => {
get: (policy) => {
return getPolicyIn(_.get(strapi, 'admin'), stripPolicy(policy, ADMIN_PREFIX));

@@ -100,0 +100,0 @@ },

@@ -99,3 +99,3 @@ 'use strict';

return items.filter(item => {
return items.filter((item) => {
return filtersEntries.every(([key, value]) => item[key] === value);

@@ -102,0 +102,0 @@ });

@@ -8,4 +8,4 @@ 'use strict';

const getRelationalFields = modelDef => {
return modelDef.associations.filter(a => RF_RELATIONS.includes(a.nature)).map(prop('alias'));
const getRelationalFields = (modelDef) => {
return modelDef.associations.filter((a) => RF_RELATIONS.includes(a.nature)).map(prop('alias'));
};

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

@@ -34,3 +34,3 @@ 'use strict';

if (_.isArray(data)) {
return data.map(entity => sanitizeEntity(entity, options));
return data.map((entity) => sanitizeEntity(entity, options));
}

@@ -81,3 +81,3 @@

if (relation === '*') {
sanitizeFn = entity => {
sanitizeFn = (entity) => {
if (_.isNil(entity) || !_.has(entity, '__contentType')) {

@@ -93,3 +93,3 @@ return entity;

} else {
sanitizeFn = entity =>
sanitizeFn = (entity) =>
sanitizeEntity(entity, {

@@ -110,3 +110,3 @@ model: strapi.getModel(relation, attribute.plugin),

if (attribute && attribute.type === 'dynamiczone' && value !== null && isAllowedField) {
const nextVal = value.map(elem =>
const nextVal = value.map((elem) =>
sanitizeEntity(elem, {

@@ -133,3 +133,3 @@ model: strapi.getModel(elem.__component),

const parseOriginalData = data => (_.isFunction(data.toJSON) ? data.toJSON() : data);
const parseOriginalData = (data) => (_.isFunction(data.toJSON) ? data.toJSON() : data);

@@ -169,4 +169,4 @@ const COMPONENT_FIELDS = ['__component'];

const transformedFields = (fields || [])
.filter(field => field.startsWith(searchStr))
.map(field => field.replace(searchStr, ''));
.filter((field) => field.startsWith(searchStr))
.map((field) => field.replace(searchStr, ''));

@@ -173,0 +173,0 @@ const isAllowed = allowedFieldsHasKey || transformedFields.length > 0;

@@ -6,11 +6,13 @@ 'use strict';

module.exports = ({ user, isEdition = false }) => data => {
if (isEdition) {
return assoc(UPDATED_BY_ATTRIBUTE, user.id, data);
}
module.exports =
({ user, isEdition = false }) =>
(data) => {
if (isEdition) {
return assoc(UPDATED_BY_ATTRIBUTE, user.id, data);
}
return assign(data, {
[CREATED_BY_ATTRIBUTE]: user.id,
[UPDATED_BY_ATTRIBUTE]: user.id,
});
};
return assign(data, {
[CREATED_BY_ATTRIBUTE]: user.id,
[UPDATED_BY_ATTRIBUTE]: user.id,
});
};

@@ -7,14 +7,15 @@ 'use strict';

const nameToCollectionName = name => slugify(name, { separator: '_' });
const nameToCollectionName = (name) => slugify(name, { separator: '_' });
const getCommonBeginning = (...strings) => _.takeWhile(
strings[0],
(char, index) => strings.every(string => string[index] === char)
).join('');
const getCommonBeginning = (...strings) =>
_.takeWhile(strings[0], (char, index) => strings.every((string) => string[index] === char)).join(
''
);
const getCommonPath = (...paths) => {
const [segments, ...otherSegments] = paths.map(it => _.split(it, '/'));
const [segments, ...otherSegments] = paths.map((it) => _.split(it, '/'));
return _.join(
_.takeWhile(segments, (str, index) => otherSegments.every(it => it[index] === str))
, '/');
_.takeWhile(segments, (str, index) => otherSegments.every((it) => it[index] === str)),
'/'
);
};

@@ -21,0 +22,0 @@

@@ -8,3 +8,3 @@ 'use strict';

const isNotNilTest = value => !_.isNil(value);
const isNotNilTest = (value) => !_.isNil(value);

@@ -15,3 +15,3 @@ function isNotNill(msg = '${path} must be defined.') {

const isNotNullTest = value => !_.isNull(value);
const isNotNullTest = (value) => !_.isNull(value);
function isNotNull(msg = '${path} cannot be null.') {

@@ -40,3 +40,3 @@ return this.test('defined', msg, isNotNullTest);

*/
const formatYupErrors = validationError => {
const formatYupErrors = (validationError) => {
if (!validationError.inner) {

@@ -43,0 +43,0 @@ throw new Error('invalid.input');

@@ -6,3 +6,3 @@ {

},
"version": "3.7.0",
"version": "3.7.1",
"description": "Shared utilities for the Strapi packages",

@@ -52,3 +52,3 @@ "homepage": "https://strapi.akemona.com",

"license": "SEE LICENSE IN LICENSE",
"gitHead": "129a8d6191b55810fd66448dcc47fee829df986c"
"gitHead": "5545ca033e2fb1aa3afbd546c370972426058525"
}
SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc