strapi-utils
Advanced tools
Comparing version 3.1.5 to 3.2.0-beta.0
@@ -153,2 +153,22 @@ const { convertRestQueryParams } = require('../convert-rest-query-params'); | ||
describe('Publication State param', () => { | ||
test.each([ | ||
{ _publicationState: 'foobar' }, | ||
{ _publicationState: undefined }, | ||
{ _publicationState: null }, | ||
])('Throws on invalid params (%#)', params => { | ||
expect(() => convertRestQueryParams(params)).toThrow(); | ||
}); | ||
test.each([ | ||
['Live Mode', { _publicationState: 'live' }], | ||
['Preview Mode', { _publicationState: 'preview' }, []], | ||
])('%s', (name, params) => { | ||
const result = convertRestQueryParams(params); | ||
expect(result._publicationState).toBeUndefined(); | ||
expect(result.publicationState).toBe(params._publicationState); | ||
}); | ||
}); | ||
describe('Filters', () => { | ||
@@ -155,0 +175,0 @@ test('Can combine filters', () => { |
@@ -7,2 +7,5 @@ /** | ||
const _ = require('lodash'); | ||
const { | ||
constants: { DP_PUB_STATES }, | ||
} = require('./content-types'); | ||
@@ -39,3 +42,7 @@ /** | ||
const whereParams = _.omit(params, ['_sort', '_start', '_limit', '_where']); | ||
if (_.has(params, '_publicationState')) { | ||
Object.assign(finalParams, convertPublicationStateParams(params._publicationState)); | ||
} | ||
const whereParams = _.omit(params, ['_sort', '_start', '_limit', '_where', '_publicationState']); | ||
const whereClauses = []; | ||
@@ -119,2 +126,18 @@ | ||
/** | ||
* publicationState query parser | ||
* @param {string} publicationState - eg: 'live', 'preview' | ||
*/ | ||
const convertPublicationStateParams = publicationState => { | ||
if (!DP_PUB_STATES.includes(publicationState)) { | ||
throw new Error( | ||
`convertPublicationStateParams expected a value from: ${DP_PUB_STATES.join( | ||
', ' | ||
)}. Got ${publicationState} instead` | ||
); | ||
} | ||
return { publicationState }; | ||
}; | ||
// List of all the possible filters | ||
@@ -121,0 +144,0 @@ const VALID_REST_OPERATORS = [ |
@@ -28,2 +28,4 @@ 'use strict'; | ||
const { generateTimestampCode } = require('./code-generator'); | ||
const contentTypes = require('./content-types'); | ||
const webhook = require('./webhook'); | ||
@@ -56,2 +58,4 @@ module.exports = { | ||
stringEquals, | ||
contentTypes, | ||
webhook, | ||
}; |
'use strict'; | ||
const _ = require('lodash'); | ||
const { constants } = require('./content-types'); | ||
const { | ||
ID_ATTRIBUTE, | ||
PUBLISHED_AT_ATTRIBUTE, | ||
CREATED_BY_ATTRIBUTE, | ||
UPDATED_BY_ATTRIBUTE, | ||
} = constants; | ||
@@ -93,5 +100,4 @@ const sanitizeEntity = (dataSource, options) => { | ||
const CREATOR_FIELDS = ['created_by', 'updated_by']; | ||
const COMPONENT_FIELDS = ['__component']; | ||
const STATIC_FIELDS = ['id', '__v']; | ||
const STATIC_FIELDS = [ID_ATTRIBUTE, '__v']; | ||
@@ -106,3 +112,11 @@ const getAllowedFields = ({ includeFields, model, isOutput }) => { | ||
...(isOutput | ||
? [primaryKey, timestamps, STATIC_FIELDS, COMPONENT_FIELDS, CREATOR_FIELDS] | ||
? [ | ||
primaryKey, | ||
timestamps, | ||
STATIC_FIELDS, | ||
COMPONENT_FIELDS, | ||
CREATED_BY_ATTRIBUTE, | ||
UPDATED_BY_ATTRIBUTE, | ||
PUBLISHED_AT_ATTRIBUTE, | ||
] | ||
: [primaryKey, STATIC_FIELDS, COMPONENT_FIELDS]) | ||
@@ -109,0 +123,0 @@ ); |
@@ -19,4 +19,4 @@ 'use strict'; | ||
function arrayRequiredAllowEmpty(message) { | ||
return this.test('field is required', message || '', value => _.isArray(value)); | ||
function arrayRequiredAllowEmpty(message = '${path} is required') { | ||
return this.test('field is required', message, value => _.isArray(value)); | ||
} | ||
@@ -23,0 +23,0 @@ |
{ | ||
"name": "strapi-utils", | ||
"version": "3.1.5", | ||
"version": "3.2.0-beta.0", | ||
"description": "Shared utilities for the Strapi packages", | ||
@@ -22,3 +22,3 @@ "homepage": "http://strapi.io", | ||
"pluralize": "^8.0.0", | ||
"yup": "0.28.1" | ||
"yup": "0.29.3" | ||
}, | ||
@@ -45,7 +45,7 @@ "author": { | ||
"engines": { | ||
"node": ">=10.10.0 <13", | ||
"node": ">=10.16.0 <13", | ||
"npm": ">=6.0.0" | ||
}, | ||
"license": "SEE LICENSE IN LICENSE", | ||
"gitHead": "736a580001cd6f0d94ff2d5a930554f6d42e0477" | ||
"gitHead": "90761175f6a0f3a36d9742f3e169cc0cc8068972" | ||
} |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
0
1
84788
31
2552
1
+ Addedfn-name@3.0.0(transitive)
+ Addedproperty-expr@2.0.6(transitive)
+ Addedyup@0.29.3(transitive)
- Removedfn-name@2.0.1(transitive)
- Removedproperty-expr@1.5.1(transitive)
- Removedyup@0.28.1(transitive)
Updatedyup@0.29.3