node_modules ignore

This commit is contained in:
2025-05-08 23:43:47 +02:00
parent e19d52f172
commit 4574544c9f
65041 changed files with 10593536 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
export { default as throwPassword } from './throw-password';
export { default as throwPrivate } from './throw-private';
export { default as throwRestrictedRelations } from './throw-restricted-relations';
export { default as throwMorphToRelations } from './throw-morph-to-relations';
export { default as throwDynamicZones } from './throw-dynamic-zones';
export { default as throwDisallowedFields } from './throw-disallowed-fields';
export { default as throwRestrictedFields } from './throw-restricted-fields';
export { default as throwUnrecognizedFields } from './throw-unrecognized-fields';
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/validate/visitors/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAE,OAAO,IAAI,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACnF,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAC9E,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAC7E,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAC7E,OAAO,EAAE,OAAO,IAAI,uBAAuB,EAAE,MAAM,6BAA6B,CAAC"}

View File

@@ -0,0 +1,22 @@
'use strict';
var throwPassword = require('./throw-password.js');
var throwPrivate = require('./throw-private.js');
var throwRestrictedRelations = require('./throw-restricted-relations.js');
var throwMorphToRelations = require('./throw-morph-to-relations.js');
var throwDynamicZones = require('./throw-dynamic-zones.js');
var throwDisallowedFields = require('./throw-disallowed-fields.js');
var throwRestrictedFields = require('./throw-restricted-fields.js');
var throwUnrecognizedFields = require('./throw-unrecognized-fields.js');
exports.throwPassword = throwPassword;
exports.throwPrivate = throwPrivate;
exports.throwRestrictedRelations = throwRestrictedRelations;
exports.throwMorphToRelations = throwMorphToRelations;
exports.throwDynamicZones = throwDynamicZones;
exports.throwDisallowedFields = throwDisallowedFields;
exports.throwRestrictedFields = throwRestrictedFields;
exports.throwUnrecognizedFields = throwUnrecognizedFields;
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;"}

View File

@@ -0,0 +1,9 @@
export { default as throwPassword } from './throw-password.mjs';
export { default as throwPrivate } from './throw-private.mjs';
export { default as throwRestrictedRelations } from './throw-restricted-relations.mjs';
export { default as throwMorphToRelations } from './throw-morph-to-relations.mjs';
export { default as throwDynamicZones } from './throw-dynamic-zones.mjs';
export { default as throwDisallowedFields } from './throw-disallowed-fields.mjs';
export { default as throwRestrictedFields } from './throw-restricted-fields.mjs';
export { default as throwUnrecognizedFields } from './throw-unrecognized-fields.mjs';
//# sourceMappingURL=index.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}

View File

@@ -0,0 +1,4 @@
import type { Visitor } from '../../traverse/factory';
declare const _default: (allowedFields?: string[] | null) => Visitor;
export default _default;
//# sourceMappingURL=throw-disallowed-fields.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"throw-disallowed-fields.d.ts","sourceRoot":"","sources":["../../../src/validate/visitors/throw-disallowed-fields.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;yCAGvB,MAAM,EAAE,GAAG,IAAI,KAAU,OAAO;AAA/D,wBAoEI"}

View File

@@ -0,0 +1,91 @@
'use strict';
var fp = require('lodash/fp');
var utils = require('../utils.js');
var throwDisallowedFields = ((allowedFields = null)=>({ key, path: { attribute: path } })=>{
// All fields are allowed
if (allowedFields === null) {
return;
}
// Throw on invalid formats
if (!(fp.isArray(allowedFields) && allowedFields.every(fp.isString))) {
throw new TypeError(`Expected array of strings for allowedFields but got "${typeof allowedFields}"`);
}
if (fp.isNil(path)) {
return;
}
const containedPaths = getContainedPaths(path);
/**
* Tells if the current path should be kept or not based
* on the success of the check functions for any of the allowed paths.
*
* The check functions are defined as follow:
*
* `containedPaths.includes(p)`
* @example
* ```js
* const path = 'foo.bar.field';
* const p = 'foo.bar';
* // it should match
*
* const path = 'foo.bar.field';
* const p = 'bar.foo';
* // it shouldn't match
*
* const path = 'foo.bar';
* const p = 'foo.bar.field';
* // it should match but isn't handled by this check
* ```
*
* `p.startsWith(`${path}.`)`
* @example
* ```js
* const path = 'foo.bar';
* const p = 'foo.bar.field';
* // it should match
*
* const path = 'foo.bar.field';
* const p = 'bar.foo';
* // it shouldn't match
*
* const path = 'foo.bar.field';
* const p = 'foo.bar';
* // it should match but isn't handled by this check
* ```
*/ const isPathAllowed = allowedFields.some((p)=>containedPaths.includes(p) || p.startsWith(`${path}.`));
if (isPathAllowed) {
return;
}
// throw otherwise
utils.throwInvalidKey({
key,
path
});
});
/**
* Retrieve the list of allowed paths based on the given path
*
* @example
* ```js
* const containedPaths = getContainedPaths('foo');
* // ['foo']
*
* * const containedPaths = getContainedPaths('foo.bar');
* // ['foo', 'foo.bar']
*
* * const containedPaths = getContainedPaths('foo.bar.field');
* // ['foo', 'foo.bar', 'foo.bar.field']
* ```
*/ const getContainedPaths = (path)=>{
const parts = fp.toPath(path);
return parts.reduce((acc, value, index, list)=>{
return [
...acc,
list.slice(0, index + 1).join('.')
];
}, []);
};
module.exports = throwDisallowedFields;
//# sourceMappingURL=throw-disallowed-fields.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"throw-disallowed-fields.js","sources":["../../../src/validate/visitors/throw-disallowed-fields.ts"],"sourcesContent":["import { isArray, isNil, isString, toPath } from 'lodash/fp';\nimport type { Visitor } from '../../traverse/factory';\nimport { throwInvalidKey } from '../utils';\n\nexport default (allowedFields: string[] | null = null): Visitor =>\n ({ key, path: { attribute: path } }) => {\n // All fields are allowed\n if (allowedFields === null) {\n return;\n }\n\n // Throw on invalid formats\n if (!(isArray(allowedFields) && allowedFields.every(isString))) {\n throw new TypeError(\n `Expected array of strings for allowedFields but got \"${typeof allowedFields}\"`\n );\n }\n\n if (isNil(path)) {\n return;\n }\n\n const containedPaths = getContainedPaths(path);\n\n /**\n * Tells if the current path should be kept or not based\n * on the success of the check functions for any of the allowed paths.\n *\n * The check functions are defined as follow:\n *\n * `containedPaths.includes(p)`\n * @example\n * ```js\n * const path = 'foo.bar.field';\n * const p = 'foo.bar';\n * // it should match\n *\n * const path = 'foo.bar.field';\n * const p = 'bar.foo';\n * // it shouldn't match\n *\n * const path = 'foo.bar';\n * const p = 'foo.bar.field';\n * // it should match but isn't handled by this check\n * ```\n *\n * `p.startsWith(`${path}.`)`\n * @example\n * ```js\n * const path = 'foo.bar';\n * const p = 'foo.bar.field';\n * // it should match\n *\n * const path = 'foo.bar.field';\n * const p = 'bar.foo';\n * // it shouldn't match\n *\n * const path = 'foo.bar.field';\n * const p = 'foo.bar';\n * // it should match but isn't handled by this check\n * ```\n */\n const isPathAllowed = allowedFields.some(\n (p) => containedPaths.includes(p) || p.startsWith(`${path}.`)\n );\n\n if (isPathAllowed) {\n return;\n }\n\n // throw otherwise\n throwInvalidKey({ key, path });\n };\n\n/**\n * Retrieve the list of allowed paths based on the given path\n *\n * @example\n * ```js\n * const containedPaths = getContainedPaths('foo');\n * // ['foo']\n *\n * * const containedPaths = getContainedPaths('foo.bar');\n * // ['foo', 'foo.bar']\n *\n * * const containedPaths = getContainedPaths('foo.bar.field');\n * // ['foo', 'foo.bar', 'foo.bar.field']\n * ```\n */\nconst getContainedPaths = (path: string) => {\n const parts = toPath(path);\n\n return parts.reduce((acc, value, index, list) => {\n return [...acc, list.slice(0, index + 1).join('.')];\n }, [] as string[]);\n};\n"],"names":["allowedFields","key","path","attribute","isArray","every","isString","TypeError","isNil","containedPaths","getContainedPaths","isPathAllowed","some","p","includes","startsWith","throwInvalidKey","parts","toPath","reduce","acc","value","index","list","slice","join"],"mappings":";;;;;AAIA,4BAAe,CAAA,CAACA,aAAiC,GAAA,IAAI,GACnD,CAAC,EAAEC,GAAG,EAAEC,IAAM,EAAA,EAAEC,SAAWD,EAAAA,IAAI,EAAE,EAAE,GAAA;;AAEjC,QAAA,IAAIF,kBAAkB,IAAM,EAAA;AAC1B,YAAA;AACF;;QAGA,IAAI,EAAEI,UAAQJ,CAAAA,aAAAA,CAAAA,IAAkBA,cAAcK,KAAK,CAACC,YAAQ,CAAI,EAAA;YAC9D,MAAM,IAAIC,UACR,CAAC,qDAAqD,EAAE,OAAOP,aAAAA,CAAc,CAAC,CAAC,CAAA;AAEnF;AAEA,QAAA,IAAIQ,SAAMN,IAAO,CAAA,EAAA;AACf,YAAA;AACF;AAEA,QAAA,MAAMO,iBAAiBC,iBAAkBR,CAAAA,IAAAA,CAAAA;AAEzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCC,QACD,MAAMS,aAAgBX,GAAAA,aAAAA,CAAcY,IAAI,CACtC,CAACC,IAAMJ,cAAeK,CAAAA,QAAQ,CAACD,CAAAA,CAAAA,IAAMA,EAAEE,UAAU,CAAC,CAAC,EAAEb,IAAAA,CAAK,CAAC,CAAC,CAAA,CAAA;AAG9D,QAAA,IAAIS,aAAe,EAAA;AACjB,YAAA;AACF;;QAGAK,qBAAgB,CAAA;AAAEf,YAAAA,GAAAA;AAAKC,YAAAA;AAAK,SAAA,CAAA;AAC9B,KAAA;AAEF;;;;;;;;;;;;;;IAeA,MAAMQ,oBAAoB,CAACR,IAAAA,GAAAA;AACzB,IAAA,MAAMe,QAAQC,SAAOhB,CAAAA,IAAAA,CAAAA;AAErB,IAAA,OAAOe,MAAME,MAAM,CAAC,CAACC,GAAAA,EAAKC,OAAOC,KAAOC,EAAAA,IAAAA,GAAAA;QACtC,OAAO;AAAIH,YAAAA,GAAAA,GAAAA;AAAKG,YAAAA,IAAAA,CAAKC,KAAK,CAAC,CAAA,EAAGF,KAAQ,GAAA,CAAA,CAAA,CAAGG,IAAI,CAAC,GAAA;AAAK,SAAA;AACrD,KAAA,EAAG,EAAE,CAAA;AACP,CAAA;;;;"}

View File

@@ -0,0 +1,89 @@
import { isArray, isString, isNil, toPath } from 'lodash/fp';
import { throwInvalidKey } from '../utils.mjs';
var throwDisallowedFields = ((allowedFields = null)=>({ key, path: { attribute: path } })=>{
// All fields are allowed
if (allowedFields === null) {
return;
}
// Throw on invalid formats
if (!(isArray(allowedFields) && allowedFields.every(isString))) {
throw new TypeError(`Expected array of strings for allowedFields but got "${typeof allowedFields}"`);
}
if (isNil(path)) {
return;
}
const containedPaths = getContainedPaths(path);
/**
* Tells if the current path should be kept or not based
* on the success of the check functions for any of the allowed paths.
*
* The check functions are defined as follow:
*
* `containedPaths.includes(p)`
* @example
* ```js
* const path = 'foo.bar.field';
* const p = 'foo.bar';
* // it should match
*
* const path = 'foo.bar.field';
* const p = 'bar.foo';
* // it shouldn't match
*
* const path = 'foo.bar';
* const p = 'foo.bar.field';
* // it should match but isn't handled by this check
* ```
*
* `p.startsWith(`${path}.`)`
* @example
* ```js
* const path = 'foo.bar';
* const p = 'foo.bar.field';
* // it should match
*
* const path = 'foo.bar.field';
* const p = 'bar.foo';
* // it shouldn't match
*
* const path = 'foo.bar.field';
* const p = 'foo.bar';
* // it should match but isn't handled by this check
* ```
*/ const isPathAllowed = allowedFields.some((p)=>containedPaths.includes(p) || p.startsWith(`${path}.`));
if (isPathAllowed) {
return;
}
// throw otherwise
throwInvalidKey({
key,
path
});
});
/**
* Retrieve the list of allowed paths based on the given path
*
* @example
* ```js
* const containedPaths = getContainedPaths('foo');
* // ['foo']
*
* * const containedPaths = getContainedPaths('foo.bar');
* // ['foo', 'foo.bar']
*
* * const containedPaths = getContainedPaths('foo.bar.field');
* // ['foo', 'foo.bar', 'foo.bar.field']
* ```
*/ const getContainedPaths = (path)=>{
const parts = toPath(path);
return parts.reduce((acc, value, index, list)=>{
return [
...acc,
list.slice(0, index + 1).join('.')
];
}, []);
};
export { throwDisallowedFields as default };
//# sourceMappingURL=throw-disallowed-fields.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"throw-disallowed-fields.mjs","sources":["../../../src/validate/visitors/throw-disallowed-fields.ts"],"sourcesContent":["import { isArray, isNil, isString, toPath } from 'lodash/fp';\nimport type { Visitor } from '../../traverse/factory';\nimport { throwInvalidKey } from '../utils';\n\nexport default (allowedFields: string[] | null = null): Visitor =>\n ({ key, path: { attribute: path } }) => {\n // All fields are allowed\n if (allowedFields === null) {\n return;\n }\n\n // Throw on invalid formats\n if (!(isArray(allowedFields) && allowedFields.every(isString))) {\n throw new TypeError(\n `Expected array of strings for allowedFields but got \"${typeof allowedFields}\"`\n );\n }\n\n if (isNil(path)) {\n return;\n }\n\n const containedPaths = getContainedPaths(path);\n\n /**\n * Tells if the current path should be kept or not based\n * on the success of the check functions for any of the allowed paths.\n *\n * The check functions are defined as follow:\n *\n * `containedPaths.includes(p)`\n * @example\n * ```js\n * const path = 'foo.bar.field';\n * const p = 'foo.bar';\n * // it should match\n *\n * const path = 'foo.bar.field';\n * const p = 'bar.foo';\n * // it shouldn't match\n *\n * const path = 'foo.bar';\n * const p = 'foo.bar.field';\n * // it should match but isn't handled by this check\n * ```\n *\n * `p.startsWith(`${path}.`)`\n * @example\n * ```js\n * const path = 'foo.bar';\n * const p = 'foo.bar.field';\n * // it should match\n *\n * const path = 'foo.bar.field';\n * const p = 'bar.foo';\n * // it shouldn't match\n *\n * const path = 'foo.bar.field';\n * const p = 'foo.bar';\n * // it should match but isn't handled by this check\n * ```\n */\n const isPathAllowed = allowedFields.some(\n (p) => containedPaths.includes(p) || p.startsWith(`${path}.`)\n );\n\n if (isPathAllowed) {\n return;\n }\n\n // throw otherwise\n throwInvalidKey({ key, path });\n };\n\n/**\n * Retrieve the list of allowed paths based on the given path\n *\n * @example\n * ```js\n * const containedPaths = getContainedPaths('foo');\n * // ['foo']\n *\n * * const containedPaths = getContainedPaths('foo.bar');\n * // ['foo', 'foo.bar']\n *\n * * const containedPaths = getContainedPaths('foo.bar.field');\n * // ['foo', 'foo.bar', 'foo.bar.field']\n * ```\n */\nconst getContainedPaths = (path: string) => {\n const parts = toPath(path);\n\n return parts.reduce((acc, value, index, list) => {\n return [...acc, list.slice(0, index + 1).join('.')];\n }, [] as string[]);\n};\n"],"names":["allowedFields","key","path","attribute","isArray","every","isString","TypeError","isNil","containedPaths","getContainedPaths","isPathAllowed","some","p","includes","startsWith","throwInvalidKey","parts","toPath","reduce","acc","value","index","list","slice","join"],"mappings":";;;AAIA,4BAAe,CAAA,CAACA,aAAiC,GAAA,IAAI,GACnD,CAAC,EAAEC,GAAG,EAAEC,IAAM,EAAA,EAAEC,SAAWD,EAAAA,IAAI,EAAE,EAAE,GAAA;;AAEjC,QAAA,IAAIF,kBAAkB,IAAM,EAAA;AAC1B,YAAA;AACF;;QAGA,IAAI,EAAEI,OAAQJ,CAAAA,aAAAA,CAAAA,IAAkBA,cAAcK,KAAK,CAACC,SAAQ,CAAI,EAAA;YAC9D,MAAM,IAAIC,UACR,CAAC,qDAAqD,EAAE,OAAOP,aAAAA,CAAc,CAAC,CAAC,CAAA;AAEnF;AAEA,QAAA,IAAIQ,MAAMN,IAAO,CAAA,EAAA;AACf,YAAA;AACF;AAEA,QAAA,MAAMO,iBAAiBC,iBAAkBR,CAAAA,IAAAA,CAAAA;AAEzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqCC,QACD,MAAMS,aAAgBX,GAAAA,aAAAA,CAAcY,IAAI,CACtC,CAACC,IAAMJ,cAAeK,CAAAA,QAAQ,CAACD,CAAAA,CAAAA,IAAMA,EAAEE,UAAU,CAAC,CAAC,EAAEb,IAAAA,CAAK,CAAC,CAAC,CAAA,CAAA;AAG9D,QAAA,IAAIS,aAAe,EAAA;AACjB,YAAA;AACF;;QAGAK,eAAgB,CAAA;AAAEf,YAAAA,GAAAA;AAAKC,YAAAA;AAAK,SAAA,CAAA;AAC9B,KAAA;AAEF;;;;;;;;;;;;;;IAeA,MAAMQ,oBAAoB,CAACR,IAAAA,GAAAA;AACzB,IAAA,MAAMe,QAAQC,MAAOhB,CAAAA,IAAAA,CAAAA;AAErB,IAAA,OAAOe,MAAME,MAAM,CAAC,CAACC,GAAAA,EAAKC,OAAOC,KAAOC,EAAAA,IAAAA,GAAAA;QACtC,OAAO;AAAIH,YAAAA,GAAAA,GAAAA;AAAKG,YAAAA,IAAAA,CAAKC,KAAK,CAAC,CAAA,EAAGF,KAAQ,GAAA,CAAA,CAAA,CAAGG,IAAI,CAAC,GAAA;AAAK,SAAA;AACrD,KAAA,EAAG,EAAE,CAAA;AACP,CAAA;;;;"}

View File

@@ -0,0 +1,4 @@
import type { Visitor } from '../../traverse/factory';
declare const visitor: Visitor;
export default visitor;
//# sourceMappingURL=throw-dynamic-zones.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"throw-dynamic-zones.d.ts","sourceRoot":"","sources":["../../../src/validate/visitors/throw-dynamic-zones.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEtD,QAAA,MAAM,OAAO,EAAE,OAId,CAAC;AAEF,eAAe,OAAO,CAAC"}

View File

@@ -0,0 +1,16 @@
'use strict';
var contentTypes = require('../../content-types.js');
var utils = require('../utils.js');
const visitor = ({ key, attribute, path })=>{
if (contentTypes.isDynamicZoneAttribute(attribute)) {
utils.throwInvalidKey({
key,
path: path.attribute
});
}
};
module.exports = visitor;
//# sourceMappingURL=throw-dynamic-zones.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"throw-dynamic-zones.js","sources":["../../../src/validate/visitors/throw-dynamic-zones.ts"],"sourcesContent":["import { isDynamicZoneAttribute } from '../../content-types';\nimport { throwInvalidKey } from '../utils';\nimport type { Visitor } from '../../traverse/factory';\n\nconst visitor: Visitor = ({ key, attribute, path }) => {\n if (isDynamicZoneAttribute(attribute)) {\n throwInvalidKey({ key, path: path.attribute });\n }\n};\n\nexport default visitor;\n"],"names":["visitor","key","attribute","path","isDynamicZoneAttribute","throwInvalidKey"],"mappings":";;;;;AAIMA,MAAAA,OAAAA,GAAmB,CAAC,EAAEC,GAAG,EAAEC,SAAS,EAAEC,IAAI,EAAE,GAAA;AAChD,IAAA,IAAIC,oCAAuBF,SAAY,CAAA,EAAA;QACrCG,qBAAgB,CAAA;AAAEJ,YAAAA,GAAAA;AAAKE,YAAAA,IAAAA,EAAMA,KAAKD;AAAU,SAAA,CAAA;AAC9C;AACF;;;;"}

View File

@@ -0,0 +1,14 @@
import { isDynamicZoneAttribute } from '../../content-types.mjs';
import { throwInvalidKey } from '../utils.mjs';
const visitor = ({ key, attribute, path })=>{
if (isDynamicZoneAttribute(attribute)) {
throwInvalidKey({
key,
path: path.attribute
});
}
};
export { visitor as default };
//# sourceMappingURL=throw-dynamic-zones.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"throw-dynamic-zones.mjs","sources":["../../../src/validate/visitors/throw-dynamic-zones.ts"],"sourcesContent":["import { isDynamicZoneAttribute } from '../../content-types';\nimport { throwInvalidKey } from '../utils';\nimport type { Visitor } from '../../traverse/factory';\n\nconst visitor: Visitor = ({ key, attribute, path }) => {\n if (isDynamicZoneAttribute(attribute)) {\n throwInvalidKey({ key, path: path.attribute });\n }\n};\n\nexport default visitor;\n"],"names":["visitor","key","attribute","path","isDynamicZoneAttribute","throwInvalidKey"],"mappings":";;;AAIMA,MAAAA,OAAAA,GAAmB,CAAC,EAAEC,GAAG,EAAEC,SAAS,EAAEC,IAAI,EAAE,GAAA;AAChD,IAAA,IAAIC,uBAAuBF,SAAY,CAAA,EAAA;QACrCG,eAAgB,CAAA;AAAEJ,YAAAA,GAAAA;AAAKE,YAAAA,IAAAA,EAAMA,KAAKD;AAAU,SAAA,CAAA;AAC9C;AACF;;;;"}

View File

@@ -0,0 +1,4 @@
import type { Visitor } from '../../traverse/factory';
declare const visitor: Visitor;
export default visitor;
//# sourceMappingURL=throw-morph-to-relations.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"throw-morph-to-relations.d.ts","sourceRoot":"","sources":["../../../src/validate/visitors/throw-morph-to-relations.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEtD,QAAA,MAAM,OAAO,EAAE,OAId,CAAC;AAEF,eAAe,OAAO,CAAC"}

View File

@@ -0,0 +1,16 @@
'use strict';
var contentTypes = require('../../content-types.js');
var utils = require('../utils.js');
const visitor = ({ key, attribute, path })=>{
if (contentTypes.isMorphToRelationalAttribute(attribute)) {
utils.throwInvalidKey({
key,
path: path.attribute
});
}
};
module.exports = visitor;
//# sourceMappingURL=throw-morph-to-relations.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"throw-morph-to-relations.js","sources":["../../../src/validate/visitors/throw-morph-to-relations.ts"],"sourcesContent":["import { isMorphToRelationalAttribute } from '../../content-types';\nimport { throwInvalidKey } from '../utils';\nimport type { Visitor } from '../../traverse/factory';\n\nconst visitor: Visitor = ({ key, attribute, path }) => {\n if (isMorphToRelationalAttribute(attribute)) {\n throwInvalidKey({ key, path: path.attribute });\n }\n};\n\nexport default visitor;\n"],"names":["visitor","key","attribute","path","isMorphToRelationalAttribute","throwInvalidKey"],"mappings":";;;;;AAIMA,MAAAA,OAAAA,GAAmB,CAAC,EAAEC,GAAG,EAAEC,SAAS,EAAEC,IAAI,EAAE,GAAA;AAChD,IAAA,IAAIC,0CAA6BF,SAAY,CAAA,EAAA;QAC3CG,qBAAgB,CAAA;AAAEJ,YAAAA,GAAAA;AAAKE,YAAAA,IAAAA,EAAMA,KAAKD;AAAU,SAAA,CAAA;AAC9C;AACF;;;;"}

View File

@@ -0,0 +1,14 @@
import { isMorphToRelationalAttribute } from '../../content-types.mjs';
import { throwInvalidKey } from '../utils.mjs';
const visitor = ({ key, attribute, path })=>{
if (isMorphToRelationalAttribute(attribute)) {
throwInvalidKey({
key,
path: path.attribute
});
}
};
export { visitor as default };
//# sourceMappingURL=throw-morph-to-relations.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"throw-morph-to-relations.mjs","sources":["../../../src/validate/visitors/throw-morph-to-relations.ts"],"sourcesContent":["import { isMorphToRelationalAttribute } from '../../content-types';\nimport { throwInvalidKey } from '../utils';\nimport type { Visitor } from '../../traverse/factory';\n\nconst visitor: Visitor = ({ key, attribute, path }) => {\n if (isMorphToRelationalAttribute(attribute)) {\n throwInvalidKey({ key, path: path.attribute });\n }\n};\n\nexport default visitor;\n"],"names":["visitor","key","attribute","path","isMorphToRelationalAttribute","throwInvalidKey"],"mappings":";;;AAIMA,MAAAA,OAAAA,GAAmB,CAAC,EAAEC,GAAG,EAAEC,SAAS,EAAEC,IAAI,EAAE,GAAA;AAChD,IAAA,IAAIC,6BAA6BF,SAAY,CAAA,EAAA;QAC3CG,eAAgB,CAAA;AAAEJ,YAAAA,GAAAA;AAAKE,YAAAA,IAAAA,EAAMA,KAAKD;AAAU,SAAA,CAAA;AAC9C;AACF;;;;"}

View File

@@ -0,0 +1,4 @@
import type { Visitor } from '../../traverse/factory';
declare const visitor: Visitor;
export default visitor;
//# sourceMappingURL=throw-password.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"throw-password.d.ts","sourceRoot":"","sources":["../../../src/validate/visitors/throw-password.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEtD,QAAA,MAAM,OAAO,EAAE,OAId,CAAC;AAEF,eAAe,OAAO,CAAC"}

View File

@@ -0,0 +1,15 @@
'use strict';
var utils = require('../utils.js');
const visitor = ({ key, attribute, path })=>{
if (attribute?.type === 'password') {
utils.throwInvalidKey({
key,
path: path.attribute
});
}
};
module.exports = visitor;
//# sourceMappingURL=throw-password.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"throw-password.js","sources":["../../../src/validate/visitors/throw-password.ts"],"sourcesContent":["import { throwInvalidKey } from '../utils';\nimport type { Visitor } from '../../traverse/factory';\n\nconst visitor: Visitor = ({ key, attribute, path }) => {\n if (attribute?.type === 'password') {\n throwInvalidKey({ key, path: path.attribute });\n }\n};\n\nexport default visitor;\n"],"names":["visitor","key","attribute","path","type","throwInvalidKey"],"mappings":";;;;AAGMA,MAAAA,OAAAA,GAAmB,CAAC,EAAEC,GAAG,EAAEC,SAAS,EAAEC,IAAI,EAAE,GAAA;IAChD,IAAID,SAAAA,EAAWE,SAAS,UAAY,EAAA;QAClCC,qBAAgB,CAAA;AAAEJ,YAAAA,GAAAA;AAAKE,YAAAA,IAAAA,EAAMA,KAAKD;AAAU,SAAA,CAAA;AAC9C;AACF;;;;"}

View File

@@ -0,0 +1,13 @@
import { throwInvalidKey } from '../utils.mjs';
const visitor = ({ key, attribute, path })=>{
if (attribute?.type === 'password') {
throwInvalidKey({
key,
path: path.attribute
});
}
};
export { visitor as default };
//# sourceMappingURL=throw-password.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"throw-password.mjs","sources":["../../../src/validate/visitors/throw-password.ts"],"sourcesContent":["import { throwInvalidKey } from '../utils';\nimport type { Visitor } from '../../traverse/factory';\n\nconst visitor: Visitor = ({ key, attribute, path }) => {\n if (attribute?.type === 'password') {\n throwInvalidKey({ key, path: path.attribute });\n }\n};\n\nexport default visitor;\n"],"names":["visitor","key","attribute","path","type","throwInvalidKey"],"mappings":";;AAGMA,MAAAA,OAAAA,GAAmB,CAAC,EAAEC,GAAG,EAAEC,SAAS,EAAEC,IAAI,EAAE,GAAA;IAChD,IAAID,SAAAA,EAAWE,SAAS,UAAY,EAAA;QAClCC,eAAgB,CAAA;AAAEJ,YAAAA,GAAAA;AAAKE,YAAAA,IAAAA,EAAMA,KAAKD;AAAU,SAAA,CAAA;AAC9C;AACF;;;;"}

View File

@@ -0,0 +1,4 @@
import type { Visitor } from '../../traverse/factory';
declare const visitor: Visitor;
export default visitor;
//# sourceMappingURL=throw-private.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"throw-private.d.ts","sourceRoot":"","sources":["../../../src/validate/visitors/throw-private.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAEtD,QAAA,MAAM,OAAO,EAAE,OAUd,CAAC;AAEF,eAAe,OAAO,CAAC"}

View File

@@ -0,0 +1,20 @@
'use strict';
var contentTypes = require('../../content-types.js');
var utils = require('../utils.js');
const visitor = ({ schema, key, attribute, path })=>{
if (!attribute) {
return;
}
const isPrivate = attribute.private === true || contentTypes.isPrivateAttribute(schema, key);
if (isPrivate) {
utils.throwInvalidKey({
key,
path: path.attribute
});
}
};
module.exports = visitor;
//# sourceMappingURL=throw-private.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"throw-private.js","sources":["../../../src/validate/visitors/throw-private.ts"],"sourcesContent":["import { isPrivateAttribute } from '../../content-types';\nimport { throwInvalidKey } from '../utils';\nimport type { Visitor } from '../../traverse/factory';\n\nconst visitor: Visitor = ({ schema, key, attribute, path }) => {\n if (!attribute) {\n return;\n }\n\n const isPrivate = attribute.private === true || isPrivateAttribute(schema, key);\n\n if (isPrivate) {\n throwInvalidKey({ key, path: path.attribute });\n }\n};\n\nexport default visitor;\n"],"names":["visitor","schema","key","attribute","path","isPrivate","private","isPrivateAttribute","throwInvalidKey"],"mappings":";;;;;AAIMA,MAAAA,OAAAA,GAAmB,CAAC,EAAEC,MAAM,EAAEC,GAAG,EAAEC,SAAS,EAAEC,IAAI,EAAE,GAAA;AACxD,IAAA,IAAI,CAACD,SAAW,EAAA;AACd,QAAA;AACF;AAEA,IAAA,MAAME,YAAYF,SAAUG,CAAAA,OAAO,KAAK,IAAA,IAAQC,gCAAmBN,MAAQC,EAAAA,GAAAA,CAAAA;AAE3E,IAAA,IAAIG,SAAW,EAAA;QACbG,qBAAgB,CAAA;AAAEN,YAAAA,GAAAA;AAAKE,YAAAA,IAAAA,EAAMA,KAAKD;AAAU,SAAA,CAAA;AAC9C;AACF;;;;"}

View File

@@ -0,0 +1,18 @@
import { isPrivateAttribute } from '../../content-types.mjs';
import { throwInvalidKey } from '../utils.mjs';
const visitor = ({ schema, key, attribute, path })=>{
if (!attribute) {
return;
}
const isPrivate = attribute.private === true || isPrivateAttribute(schema, key);
if (isPrivate) {
throwInvalidKey({
key,
path: path.attribute
});
}
};
export { visitor as default };
//# sourceMappingURL=throw-private.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"throw-private.mjs","sources":["../../../src/validate/visitors/throw-private.ts"],"sourcesContent":["import { isPrivateAttribute } from '../../content-types';\nimport { throwInvalidKey } from '../utils';\nimport type { Visitor } from '../../traverse/factory';\n\nconst visitor: Visitor = ({ schema, key, attribute, path }) => {\n if (!attribute) {\n return;\n }\n\n const isPrivate = attribute.private === true || isPrivateAttribute(schema, key);\n\n if (isPrivate) {\n throwInvalidKey({ key, path: path.attribute });\n }\n};\n\nexport default visitor;\n"],"names":["visitor","schema","key","attribute","path","isPrivate","private","isPrivateAttribute","throwInvalidKey"],"mappings":";;;AAIMA,MAAAA,OAAAA,GAAmB,CAAC,EAAEC,MAAM,EAAEC,GAAG,EAAEC,SAAS,EAAEC,IAAI,EAAE,GAAA;AACxD,IAAA,IAAI,CAACD,SAAW,EAAA;AACd,QAAA;AACF;AAEA,IAAA,MAAME,YAAYF,SAAUG,CAAAA,OAAO,KAAK,IAAA,IAAQC,mBAAmBN,MAAQC,EAAAA,GAAAA,CAAAA;AAE3E,IAAA,IAAIG,SAAW,EAAA;QACbG,eAAgB,CAAA;AAAEN,YAAAA,GAAAA;AAAKE,YAAAA,IAAAA,EAAMA,KAAKD;AAAU,SAAA,CAAA;AAC9C;AACF;;;;"}

View File

@@ -0,0 +1,4 @@
import type { Visitor } from '../../traverse/factory';
declare const _default: (restrictedFields?: string[] | null) => Visitor;
export default _default;
//# sourceMappingURL=throw-restricted-fields.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"throw-restricted-fields.d.ts","sourceRoot":"","sources":["../../../src/validate/visitors/throw-restricted-fields.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;4CAGpB,MAAM,EAAE,GAAG,IAAI,KAAU,OAAO;AAAlE,wBA0BI"}

View File

@@ -0,0 +1,36 @@
'use strict';
var fp = require('lodash/fp');
var utils = require('../utils.js');
var throwRestrictedFields = ((restrictedFields = null)=>({ key, path: { attribute: path } })=>{
// all fields
if (restrictedFields === null) {
utils.throwInvalidKey({
key,
path
});
}
// Throw on invalid formats
if (!(fp.isArray(restrictedFields) && restrictedFields.every(fp.isString))) {
throw new TypeError(`Expected array of strings for restrictedFields but got "${typeof restrictedFields}"`);
}
// if an exact match was found
if (restrictedFields.includes(path)) {
utils.throwInvalidKey({
key,
path
});
}
// nested matches
const isRestrictedNested = restrictedFields.some((allowedPath)=>path?.toString().startsWith(`${allowedPath}.`));
if (isRestrictedNested) {
utils.throwInvalidKey({
key,
path
});
}
});
module.exports = throwRestrictedFields;
//# sourceMappingURL=throw-restricted-fields.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"throw-restricted-fields.js","sources":["../../../src/validate/visitors/throw-restricted-fields.ts"],"sourcesContent":["import { isArray, isString } from 'lodash/fp';\nimport type { Visitor } from '../../traverse/factory';\nimport { throwInvalidKey } from '../utils';\n\nexport default (restrictedFields: string[] | null = null): Visitor =>\n ({ key, path: { attribute: path } }) => {\n // all fields\n if (restrictedFields === null) {\n throwInvalidKey({ key, path });\n }\n\n // Throw on invalid formats\n if (!(isArray(restrictedFields) && restrictedFields.every(isString))) {\n throw new TypeError(\n `Expected array of strings for restrictedFields but got \"${typeof restrictedFields}\"`\n );\n }\n\n // if an exact match was found\n if (restrictedFields.includes(path as string)) {\n throwInvalidKey({ key, path });\n }\n\n // nested matches\n const isRestrictedNested = restrictedFields.some((allowedPath) =>\n path?.toString().startsWith(`${allowedPath}.`)\n );\n if (isRestrictedNested) {\n throwInvalidKey({ key, path });\n }\n };\n"],"names":["restrictedFields","key","path","attribute","throwInvalidKey","isArray","every","isString","TypeError","includes","isRestrictedNested","some","allowedPath","toString","startsWith"],"mappings":";;;;;AAIA,4BAAe,CAAA,CAACA,gBAAoC,GAAA,IAAI,GACtD,CAAC,EAAEC,GAAG,EAAEC,IAAM,EAAA,EAAEC,SAAWD,EAAAA,IAAI,EAAE,EAAE,GAAA;;AAEjC,QAAA,IAAIF,qBAAqB,IAAM,EAAA;YAC7BI,qBAAgB,CAAA;AAAEH,gBAAAA,GAAAA;AAAKC,gBAAAA;AAAK,aAAA,CAAA;AAC9B;;QAGA,IAAI,EAAEG,UAAQL,CAAAA,gBAAAA,CAAAA,IAAqBA,iBAAiBM,KAAK,CAACC,YAAQ,CAAI,EAAA;YACpE,MAAM,IAAIC,UACR,CAAC,wDAAwD,EAAE,OAAOR,gBAAAA,CAAiB,CAAC,CAAC,CAAA;AAEzF;;QAGA,IAAIA,gBAAAA,CAAiBS,QAAQ,CAACP,IAAiB,CAAA,EAAA;YAC7CE,qBAAgB,CAAA;AAAEH,gBAAAA,GAAAA;AAAKC,gBAAAA;AAAK,aAAA,CAAA;AAC9B;;AAGA,QAAA,MAAMQ,kBAAqBV,GAAAA,gBAAAA,CAAiBW,IAAI,CAAC,CAACC,WAAAA,GAChDV,IAAMW,EAAAA,QAAAA,EAAAA,CAAWC,UAAW,CAAA,CAAC,EAAEF,WAAAA,CAAY,CAAC,CAAC,CAAA,CAAA;AAE/C,QAAA,IAAIF,kBAAoB,EAAA;YACtBN,qBAAgB,CAAA;AAAEH,gBAAAA,GAAAA;AAAKC,gBAAAA;AAAK,aAAA,CAAA;AAC9B;AACF,KAAA;;;;"}

View File

@@ -0,0 +1,34 @@
import { isArray, isString } from 'lodash/fp';
import { throwInvalidKey } from '../utils.mjs';
var throwRestrictedFields = ((restrictedFields = null)=>({ key, path: { attribute: path } })=>{
// all fields
if (restrictedFields === null) {
throwInvalidKey({
key,
path
});
}
// Throw on invalid formats
if (!(isArray(restrictedFields) && restrictedFields.every(isString))) {
throw new TypeError(`Expected array of strings for restrictedFields but got "${typeof restrictedFields}"`);
}
// if an exact match was found
if (restrictedFields.includes(path)) {
throwInvalidKey({
key,
path
});
}
// nested matches
const isRestrictedNested = restrictedFields.some((allowedPath)=>path?.toString().startsWith(`${allowedPath}.`));
if (isRestrictedNested) {
throwInvalidKey({
key,
path
});
}
});
export { throwRestrictedFields as default };
//# sourceMappingURL=throw-restricted-fields.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"throw-restricted-fields.mjs","sources":["../../../src/validate/visitors/throw-restricted-fields.ts"],"sourcesContent":["import { isArray, isString } from 'lodash/fp';\nimport type { Visitor } from '../../traverse/factory';\nimport { throwInvalidKey } from '../utils';\n\nexport default (restrictedFields: string[] | null = null): Visitor =>\n ({ key, path: { attribute: path } }) => {\n // all fields\n if (restrictedFields === null) {\n throwInvalidKey({ key, path });\n }\n\n // Throw on invalid formats\n if (!(isArray(restrictedFields) && restrictedFields.every(isString))) {\n throw new TypeError(\n `Expected array of strings for restrictedFields but got \"${typeof restrictedFields}\"`\n );\n }\n\n // if an exact match was found\n if (restrictedFields.includes(path as string)) {\n throwInvalidKey({ key, path });\n }\n\n // nested matches\n const isRestrictedNested = restrictedFields.some((allowedPath) =>\n path?.toString().startsWith(`${allowedPath}.`)\n );\n if (isRestrictedNested) {\n throwInvalidKey({ key, path });\n }\n };\n"],"names":["restrictedFields","key","path","attribute","throwInvalidKey","isArray","every","isString","TypeError","includes","isRestrictedNested","some","allowedPath","toString","startsWith"],"mappings":";;;AAIA,4BAAe,CAAA,CAACA,gBAAoC,GAAA,IAAI,GACtD,CAAC,EAAEC,GAAG,EAAEC,IAAM,EAAA,EAAEC,SAAWD,EAAAA,IAAI,EAAE,EAAE,GAAA;;AAEjC,QAAA,IAAIF,qBAAqB,IAAM,EAAA;YAC7BI,eAAgB,CAAA;AAAEH,gBAAAA,GAAAA;AAAKC,gBAAAA;AAAK,aAAA,CAAA;AAC9B;;QAGA,IAAI,EAAEG,OAAQL,CAAAA,gBAAAA,CAAAA,IAAqBA,iBAAiBM,KAAK,CAACC,SAAQ,CAAI,EAAA;YACpE,MAAM,IAAIC,UACR,CAAC,wDAAwD,EAAE,OAAOR,gBAAAA,CAAiB,CAAC,CAAC,CAAA;AAEzF;;QAGA,IAAIA,gBAAAA,CAAiBS,QAAQ,CAACP,IAAiB,CAAA,EAAA;YAC7CE,eAAgB,CAAA;AAAEH,gBAAAA,GAAAA;AAAKC,gBAAAA;AAAK,aAAA,CAAA;AAC9B;;AAGA,QAAA,MAAMQ,kBAAqBV,GAAAA,gBAAAA,CAAiBW,IAAI,CAAC,CAACC,WAAAA,GAChDV,IAAMW,EAAAA,QAAAA,EAAAA,CAAWC,UAAW,CAAA,CAAC,EAAEF,WAAAA,CAAY,CAAC,CAAC,CAAA,CAAA;AAE/C,QAAA,IAAIF,kBAAoB,EAAA;YACtBN,eAAgB,CAAA;AAAEH,gBAAAA,GAAAA;AAAKC,gBAAAA;AAAK,aAAA,CAAA;AAC9B;AACF,KAAA;;;;"}

View File

@@ -0,0 +1,4 @@
import type { Visitor } from '../../traverse/factory';
declare const _default: (auth: unknown) => Visitor;
export default _default;
//# sourceMappingURL=throw-restricted-relations.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"throw-restricted-relations.d.ts","sourceRoot":"","sources":["../../../src/validate/visitors/throw-restricted-relations.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;+BAQhC,OAAO,KAAG,OAAO;AAAvC,wBAkGI"}

View File

@@ -0,0 +1,125 @@
'use strict';
var fp = require('lodash/fp');
var contentTypes = require('../../content-types.js');
var utils = require('../utils.js');
var relations = require('../../relations.js');
const ACTIONS_TO_VERIFY = [
'find'
];
const { CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE } = contentTypes.constants;
var throwRestrictedRelations = ((auth)=>async ({ data, key, attribute, schema, path })=>{
if (!attribute) {
return;
}
const isRelation = attribute.type === 'relation';
if (!isRelation) {
return;
}
const handleMorphRelation = async ()=>{
const elements = data[key];
if ('connect' in elements || 'set' in elements || 'disconnect' in elements || 'options' in elements) {
await handleMorphElements(elements.connect || []);
await handleMorphElements(elements.set || []);
await handleMorphElements(elements.disconnect || []);
// TODO: this should technically be in its own visitor to check morph options, but for now we'll handle it here
if ('options' in elements) {
if (elements.options === null || elements.options === undefined) {
return;
}
if (typeof elements.options !== 'object') {
utils.throwInvalidKey({
key,
path: path.attribute
});
}
const optionKeys = Object.keys(elements.options);
// Validate each key based on its validator function
for (const key of optionKeys){
if (!(key in relations.VALID_RELATION_ORDERING_KEYS)) {
utils.throwInvalidKey({
key,
path: path.attribute
});
}
if (!relations.VALID_RELATION_ORDERING_KEYS[key](elements.options[key])) {
utils.throwInvalidKey({
key,
path: path.attribute
});
}
}
}
} else {
await handleMorphElements(elements);
}
};
const handleMorphElements = async (elements)=>{
if (!fp.isArray(elements)) {
utils.throwInvalidKey({
key,
path: path.attribute
});
}
for (const element of elements){
if (!fp.isObject(element) || !('__type' in element)) {
utils.throwInvalidKey({
key,
path: path.attribute
});
}
const scopes = ACTIONS_TO_VERIFY.map((action)=>`${element.__type}.${action}`);
const isAllowed = await hasAccessToSomeScopes(scopes, auth);
if (!isAllowed) {
utils.throwInvalidKey({
key,
path: path.attribute
});
}
}
};
const handleRegularRelation = async ()=>{
const scopes = ACTIONS_TO_VERIFY.map((action)=>`${attribute.target}.${action}`);
const isAllowed = await hasAccessToSomeScopes(scopes, auth);
// If the authenticated user don't have access to any of the scopes
if (!isAllowed) {
utils.throwInvalidKey({
key,
path: path.attribute
});
}
};
const isCreatorRelation = [
CREATED_BY_ATTRIBUTE,
UPDATED_BY_ATTRIBUTE
].includes(key);
// Polymorphic relations
if (contentTypes.isMorphToRelationalAttribute(attribute)) {
await handleMorphRelation();
return;
}
// Creator relations
if (isCreatorRelation && schema.options?.populateCreatorFields) {
// do nothing
return;
}
// Regular relations
await handleRegularRelation();
});
const hasAccessToSomeScopes = async (scopes, auth)=>{
for (const scope of scopes){
try {
await strapi.auth.verify(auth, {
scope
});
return true;
} catch {
continue;
}
}
return false;
};
module.exports = throwRestrictedRelations;
//# sourceMappingURL=throw-restricted-relations.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,123 @@
import { isArray, isObject } from 'lodash/fp';
import { isMorphToRelationalAttribute, constants } from '../../content-types.mjs';
import { throwInvalidKey } from '../utils.mjs';
import { VALID_RELATION_ORDERING_KEYS } from '../../relations.mjs';
const ACTIONS_TO_VERIFY = [
'find'
];
const { CREATED_BY_ATTRIBUTE, UPDATED_BY_ATTRIBUTE } = constants;
var throwRestrictedRelations = ((auth)=>async ({ data, key, attribute, schema, path })=>{
if (!attribute) {
return;
}
const isRelation = attribute.type === 'relation';
if (!isRelation) {
return;
}
const handleMorphRelation = async ()=>{
const elements = data[key];
if ('connect' in elements || 'set' in elements || 'disconnect' in elements || 'options' in elements) {
await handleMorphElements(elements.connect || []);
await handleMorphElements(elements.set || []);
await handleMorphElements(elements.disconnect || []);
// TODO: this should technically be in its own visitor to check morph options, but for now we'll handle it here
if ('options' in elements) {
if (elements.options === null || elements.options === undefined) {
return;
}
if (typeof elements.options !== 'object') {
throwInvalidKey({
key,
path: path.attribute
});
}
const optionKeys = Object.keys(elements.options);
// Validate each key based on its validator function
for (const key of optionKeys){
if (!(key in VALID_RELATION_ORDERING_KEYS)) {
throwInvalidKey({
key,
path: path.attribute
});
}
if (!VALID_RELATION_ORDERING_KEYS[key](elements.options[key])) {
throwInvalidKey({
key,
path: path.attribute
});
}
}
}
} else {
await handleMorphElements(elements);
}
};
const handleMorphElements = async (elements)=>{
if (!isArray(elements)) {
throwInvalidKey({
key,
path: path.attribute
});
}
for (const element of elements){
if (!isObject(element) || !('__type' in element)) {
throwInvalidKey({
key,
path: path.attribute
});
}
const scopes = ACTIONS_TO_VERIFY.map((action)=>`${element.__type}.${action}`);
const isAllowed = await hasAccessToSomeScopes(scopes, auth);
if (!isAllowed) {
throwInvalidKey({
key,
path: path.attribute
});
}
}
};
const handleRegularRelation = async ()=>{
const scopes = ACTIONS_TO_VERIFY.map((action)=>`${attribute.target}.${action}`);
const isAllowed = await hasAccessToSomeScopes(scopes, auth);
// If the authenticated user don't have access to any of the scopes
if (!isAllowed) {
throwInvalidKey({
key,
path: path.attribute
});
}
};
const isCreatorRelation = [
CREATED_BY_ATTRIBUTE,
UPDATED_BY_ATTRIBUTE
].includes(key);
// Polymorphic relations
if (isMorphToRelationalAttribute(attribute)) {
await handleMorphRelation();
return;
}
// Creator relations
if (isCreatorRelation && schema.options?.populateCreatorFields) {
// do nothing
return;
}
// Regular relations
await handleRegularRelation();
});
const hasAccessToSomeScopes = async (scopes, auth)=>{
for (const scope of scopes){
try {
await strapi.auth.verify(auth, {
scope
});
return true;
} catch {
continue;
}
}
return false;
};
export { throwRestrictedRelations as default };
//# sourceMappingURL=throw-restricted-relations.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,4 @@
import type { Visitor } from '../../traverse-entity';
declare const throwUnrecognizedFields: Visitor;
export default throwUnrecognizedFields;
//# sourceMappingURL=throw-unrecognized-fields.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"throw-unrecognized-fields.d.ts","sourceRoot":"","sources":["../../../src/validate/visitors/throw-unrecognized-fields.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAUrD,QAAA,MAAM,uBAAuB,EAAE,OA0C9B,CAAC;AAEF,eAAe,uBAAuB,CAAC"}

View File

@@ -0,0 +1,66 @@
'use strict';
var contentTypes = require('../../content-types.js');
var utils = require('../utils.js');
// TODO these should all be centralized somewhere instead of maintaining a list
const ID_FIELDS = [
contentTypes.constants.DOC_ID_ATTRIBUTE,
contentTypes.constants.DOC_ID_ATTRIBUTE
];
const ALLOWED_ROOT_LEVEL_FIELDS = [
...ID_FIELDS
];
const MORPH_TO_ALLOWED_FIELDS = [
'__type'
];
const DYNAMIC_ZONE_ALLOWED_FIELDS = [
'__component'
];
const RELATION_REORDERING_FIELDS = [
'connect',
'disconnect',
'set',
'options'
];
const throwUnrecognizedFields = ({ key, attribute, path, schema, parent })=>{
// We only look at properties that are not attributes
if (attribute) {
return;
}
// At root level (path.attribute === null), only accept allowed fields
if (path.attribute === null) {
if (ALLOWED_ROOT_LEVEL_FIELDS.includes(key)) {
return;
}
return utils.throwInvalidKey({
key,
path: attribute
});
}
// allow special morphTo keys
if (contentTypes.isMorphToRelationalAttribute(parent?.attribute) && MORPH_TO_ALLOWED_FIELDS.includes(key)) {
return;
}
// allow special dz keys
if (contentTypes.isComponentSchema(schema) && contentTypes.isDynamicZoneAttribute(parent?.attribute) && DYNAMIC_ZONE_ALLOWED_FIELDS.includes(key)) {
return;
}
// allow special relation reordering keys in manyToX and XtoMany relations
if (contentTypes.hasRelationReordering(parent?.attribute) && RELATION_REORDERING_FIELDS.includes(key)) {
return;
}
// allow id fields where it is needed for setting a relational id rather than trying to create with a given id
const canUseID = contentTypes.isRelationalAttribute(parent?.attribute) || contentTypes.isMediaAttribute(parent?.attribute);
if (canUseID && !ID_FIELDS.includes(key)) {
return;
}
// if we couldn't find any reason for it to be here, throw
utils.throwInvalidKey({
key,
path: attribute
});
};
module.exports = throwUnrecognizedFields;
//# sourceMappingURL=throw-unrecognized-fields.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"throw-unrecognized-fields.js","sources":["../../../src/validate/visitors/throw-unrecognized-fields.ts"],"sourcesContent":["import {\n isDynamicZoneAttribute,\n isMorphToRelationalAttribute,\n isRelationalAttribute,\n constants,\n isComponentSchema,\n isMediaAttribute,\n hasRelationReordering,\n} from '../../content-types';\nimport type { Visitor } from '../../traverse-entity';\nimport { throwInvalidKey } from '../utils';\n\n// TODO these should all be centralized somewhere instead of maintaining a list\nconst ID_FIELDS = [constants.DOC_ID_ATTRIBUTE, constants.DOC_ID_ATTRIBUTE];\nconst ALLOWED_ROOT_LEVEL_FIELDS = [...ID_FIELDS];\nconst MORPH_TO_ALLOWED_FIELDS = ['__type'];\nconst DYNAMIC_ZONE_ALLOWED_FIELDS = ['__component'];\nconst RELATION_REORDERING_FIELDS = ['connect', 'disconnect', 'set', 'options'];\n\nconst throwUnrecognizedFields: Visitor = ({ key, attribute, path, schema, parent }) => {\n // We only look at properties that are not attributes\n if (attribute) {\n return;\n }\n\n // At root level (path.attribute === null), only accept allowed fields\n if (path.attribute === null) {\n if (ALLOWED_ROOT_LEVEL_FIELDS.includes(key)) {\n return;\n }\n\n return throwInvalidKey({ key, path: attribute });\n }\n\n // allow special morphTo keys\n if (isMorphToRelationalAttribute(parent?.attribute) && MORPH_TO_ALLOWED_FIELDS.includes(key)) {\n return;\n }\n\n // allow special dz keys\n if (\n isComponentSchema(schema) &&\n isDynamicZoneAttribute(parent?.attribute) &&\n DYNAMIC_ZONE_ALLOWED_FIELDS.includes(key)\n ) {\n return;\n }\n\n // allow special relation reordering keys in manyToX and XtoMany relations\n if (hasRelationReordering(parent?.attribute) && RELATION_REORDERING_FIELDS.includes(key)) {\n return;\n }\n\n // allow id fields where it is needed for setting a relational id rather than trying to create with a given id\n const canUseID = isRelationalAttribute(parent?.attribute) || isMediaAttribute(parent?.attribute);\n if (canUseID && !ID_FIELDS.includes(key)) {\n return;\n }\n\n // if we couldn't find any reason for it to be here, throw\n throwInvalidKey({ key, path: attribute });\n};\n\nexport default throwUnrecognizedFields;\n"],"names":["ID_FIELDS","constants","DOC_ID_ATTRIBUTE","ALLOWED_ROOT_LEVEL_FIELDS","MORPH_TO_ALLOWED_FIELDS","DYNAMIC_ZONE_ALLOWED_FIELDS","RELATION_REORDERING_FIELDS","throwUnrecognizedFields","key","attribute","path","schema","parent","includes","throwInvalidKey","isMorphToRelationalAttribute","isComponentSchema","isDynamicZoneAttribute","hasRelationReordering","canUseID","isRelationalAttribute","isMediaAttribute"],"mappings":";;;;;AAYA;AACA,MAAMA,SAAY,GAAA;AAACC,IAAAA,sBAAAA,CAAUC,gBAAgB;AAAED,IAAAA,sBAAAA,CAAUC;AAAiB,CAAA;AAC1E,MAAMC,yBAA4B,GAAA;AAAIH,IAAAA,GAAAA;AAAU,CAAA;AAChD,MAAMI,uBAA0B,GAAA;AAAC,IAAA;AAAS,CAAA;AAC1C,MAAMC,2BAA8B,GAAA;AAAC,IAAA;AAAc,CAAA;AACnD,MAAMC,0BAA6B,GAAA;AAAC,IAAA,SAAA;AAAW,IAAA,YAAA;AAAc,IAAA,KAAA;AAAO,IAAA;AAAU,CAAA;AAE9E,MAAMC,uBAAmC,GAAA,CAAC,EAAEC,GAAG,EAAEC,SAAS,EAAEC,IAAI,EAAEC,MAAM,EAAEC,MAAM,EAAE,GAAA;;AAEhF,IAAA,IAAIH,SAAW,EAAA;AACb,QAAA;AACF;;IAGA,IAAIC,IAAAA,CAAKD,SAAS,KAAK,IAAM,EAAA;QAC3B,IAAIN,yBAAAA,CAA0BU,QAAQ,CAACL,GAAM,CAAA,EAAA;AAC3C,YAAA;AACF;AAEA,QAAA,OAAOM,qBAAgB,CAAA;AAAEN,YAAAA,GAAAA;YAAKE,IAAMD,EAAAA;AAAU,SAAA,CAAA;AAChD;;AAGA,IAAA,IAAIM,0CAA6BH,MAAQH,EAAAA,SAAAA,CAAAA,IAAcL,uBAAwBS,CAAAA,QAAQ,CAACL,GAAM,CAAA,EAAA;AAC5F,QAAA;AACF;;IAGA,IACEQ,8BAAAA,CAAkBL,WAClBM,mCAAuBL,CAAAA,MAAAA,EAAQH,cAC/BJ,2BAA4BQ,CAAAA,QAAQ,CAACL,GACrC,CAAA,EAAA;AACA,QAAA;AACF;;AAGA,IAAA,IAAIU,mCAAsBN,MAAQH,EAAAA,SAAAA,CAAAA,IAAcH,0BAA2BO,CAAAA,QAAQ,CAACL,GAAM,CAAA,EAAA;AACxF,QAAA;AACF;;AAGA,IAAA,MAAMW,QAAWC,GAAAA,kCAAAA,CAAsBR,MAAQH,EAAAA,SAAAA,CAAAA,IAAcY,8BAAiBT,MAAQH,EAAAA,SAAAA,CAAAA;AACtF,IAAA,IAAIU,QAAY,IAAA,CAACnB,SAAUa,CAAAA,QAAQ,CAACL,GAAM,CAAA,EAAA;AACxC,QAAA;AACF;;IAGAM,qBAAgB,CAAA;AAAEN,QAAAA,GAAAA;QAAKE,IAAMD,EAAAA;AAAU,KAAA,CAAA;AACzC;;;;"}

View File

@@ -0,0 +1,64 @@
import { constants, isMorphToRelationalAttribute, isComponentSchema, isDynamicZoneAttribute, hasRelationReordering, isRelationalAttribute, isMediaAttribute } from '../../content-types.mjs';
import { throwInvalidKey } from '../utils.mjs';
// TODO these should all be centralized somewhere instead of maintaining a list
const ID_FIELDS = [
constants.DOC_ID_ATTRIBUTE,
constants.DOC_ID_ATTRIBUTE
];
const ALLOWED_ROOT_LEVEL_FIELDS = [
...ID_FIELDS
];
const MORPH_TO_ALLOWED_FIELDS = [
'__type'
];
const DYNAMIC_ZONE_ALLOWED_FIELDS = [
'__component'
];
const RELATION_REORDERING_FIELDS = [
'connect',
'disconnect',
'set',
'options'
];
const throwUnrecognizedFields = ({ key, attribute, path, schema, parent })=>{
// We only look at properties that are not attributes
if (attribute) {
return;
}
// At root level (path.attribute === null), only accept allowed fields
if (path.attribute === null) {
if (ALLOWED_ROOT_LEVEL_FIELDS.includes(key)) {
return;
}
return throwInvalidKey({
key,
path: attribute
});
}
// allow special morphTo keys
if (isMorphToRelationalAttribute(parent?.attribute) && MORPH_TO_ALLOWED_FIELDS.includes(key)) {
return;
}
// allow special dz keys
if (isComponentSchema(schema) && isDynamicZoneAttribute(parent?.attribute) && DYNAMIC_ZONE_ALLOWED_FIELDS.includes(key)) {
return;
}
// allow special relation reordering keys in manyToX and XtoMany relations
if (hasRelationReordering(parent?.attribute) && RELATION_REORDERING_FIELDS.includes(key)) {
return;
}
// allow id fields where it is needed for setting a relational id rather than trying to create with a given id
const canUseID = isRelationalAttribute(parent?.attribute) || isMediaAttribute(parent?.attribute);
if (canUseID && !ID_FIELDS.includes(key)) {
return;
}
// if we couldn't find any reason for it to be here, throw
throwInvalidKey({
key,
path: attribute
});
};
export { throwUnrecognizedFields as default };
//# sourceMappingURL=throw-unrecognized-fields.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"throw-unrecognized-fields.mjs","sources":["../../../src/validate/visitors/throw-unrecognized-fields.ts"],"sourcesContent":["import {\n isDynamicZoneAttribute,\n isMorphToRelationalAttribute,\n isRelationalAttribute,\n constants,\n isComponentSchema,\n isMediaAttribute,\n hasRelationReordering,\n} from '../../content-types';\nimport type { Visitor } from '../../traverse-entity';\nimport { throwInvalidKey } from '../utils';\n\n// TODO these should all be centralized somewhere instead of maintaining a list\nconst ID_FIELDS = [constants.DOC_ID_ATTRIBUTE, constants.DOC_ID_ATTRIBUTE];\nconst ALLOWED_ROOT_LEVEL_FIELDS = [...ID_FIELDS];\nconst MORPH_TO_ALLOWED_FIELDS = ['__type'];\nconst DYNAMIC_ZONE_ALLOWED_FIELDS = ['__component'];\nconst RELATION_REORDERING_FIELDS = ['connect', 'disconnect', 'set', 'options'];\n\nconst throwUnrecognizedFields: Visitor = ({ key, attribute, path, schema, parent }) => {\n // We only look at properties that are not attributes\n if (attribute) {\n return;\n }\n\n // At root level (path.attribute === null), only accept allowed fields\n if (path.attribute === null) {\n if (ALLOWED_ROOT_LEVEL_FIELDS.includes(key)) {\n return;\n }\n\n return throwInvalidKey({ key, path: attribute });\n }\n\n // allow special morphTo keys\n if (isMorphToRelationalAttribute(parent?.attribute) && MORPH_TO_ALLOWED_FIELDS.includes(key)) {\n return;\n }\n\n // allow special dz keys\n if (\n isComponentSchema(schema) &&\n isDynamicZoneAttribute(parent?.attribute) &&\n DYNAMIC_ZONE_ALLOWED_FIELDS.includes(key)\n ) {\n return;\n }\n\n // allow special relation reordering keys in manyToX and XtoMany relations\n if (hasRelationReordering(parent?.attribute) && RELATION_REORDERING_FIELDS.includes(key)) {\n return;\n }\n\n // allow id fields where it is needed for setting a relational id rather than trying to create with a given id\n const canUseID = isRelationalAttribute(parent?.attribute) || isMediaAttribute(parent?.attribute);\n if (canUseID && !ID_FIELDS.includes(key)) {\n return;\n }\n\n // if we couldn't find any reason for it to be here, throw\n throwInvalidKey({ key, path: attribute });\n};\n\nexport default throwUnrecognizedFields;\n"],"names":["ID_FIELDS","constants","DOC_ID_ATTRIBUTE","ALLOWED_ROOT_LEVEL_FIELDS","MORPH_TO_ALLOWED_FIELDS","DYNAMIC_ZONE_ALLOWED_FIELDS","RELATION_REORDERING_FIELDS","throwUnrecognizedFields","key","attribute","path","schema","parent","includes","throwInvalidKey","isMorphToRelationalAttribute","isComponentSchema","isDynamicZoneAttribute","hasRelationReordering","canUseID","isRelationalAttribute","isMediaAttribute"],"mappings":";;;AAYA;AACA,MAAMA,SAAY,GAAA;AAACC,IAAAA,SAAAA,CAAUC,gBAAgB;AAAED,IAAAA,SAAAA,CAAUC;AAAiB,CAAA;AAC1E,MAAMC,yBAA4B,GAAA;AAAIH,IAAAA,GAAAA;AAAU,CAAA;AAChD,MAAMI,uBAA0B,GAAA;AAAC,IAAA;AAAS,CAAA;AAC1C,MAAMC,2BAA8B,GAAA;AAAC,IAAA;AAAc,CAAA;AACnD,MAAMC,0BAA6B,GAAA;AAAC,IAAA,SAAA;AAAW,IAAA,YAAA;AAAc,IAAA,KAAA;AAAO,IAAA;AAAU,CAAA;AAE9E,MAAMC,uBAAmC,GAAA,CAAC,EAAEC,GAAG,EAAEC,SAAS,EAAEC,IAAI,EAAEC,MAAM,EAAEC,MAAM,EAAE,GAAA;;AAEhF,IAAA,IAAIH,SAAW,EAAA;AACb,QAAA;AACF;;IAGA,IAAIC,IAAAA,CAAKD,SAAS,KAAK,IAAM,EAAA;QAC3B,IAAIN,yBAAAA,CAA0BU,QAAQ,CAACL,GAAM,CAAA,EAAA;AAC3C,YAAA;AACF;AAEA,QAAA,OAAOM,eAAgB,CAAA;AAAEN,YAAAA,GAAAA;YAAKE,IAAMD,EAAAA;AAAU,SAAA,CAAA;AAChD;;AAGA,IAAA,IAAIM,6BAA6BH,MAAQH,EAAAA,SAAAA,CAAAA,IAAcL,uBAAwBS,CAAAA,QAAQ,CAACL,GAAM,CAAA,EAAA;AAC5F,QAAA;AACF;;IAGA,IACEQ,iBAAAA,CAAkBL,WAClBM,sBAAuBL,CAAAA,MAAAA,EAAQH,cAC/BJ,2BAA4BQ,CAAAA,QAAQ,CAACL,GACrC,CAAA,EAAA;AACA,QAAA;AACF;;AAGA,IAAA,IAAIU,sBAAsBN,MAAQH,EAAAA,SAAAA,CAAAA,IAAcH,0BAA2BO,CAAAA,QAAQ,CAACL,GAAM,CAAA,EAAA;AACxF,QAAA;AACF;;AAGA,IAAA,MAAMW,QAAWC,GAAAA,qBAAAA,CAAsBR,MAAQH,EAAAA,SAAAA,CAAAA,IAAcY,iBAAiBT,MAAQH,EAAAA,SAAAA,CAAAA;AACtF,IAAA,IAAIU,QAAY,IAAA,CAACnB,SAAUa,CAAAA,QAAQ,CAACL,GAAM,CAAA,EAAA;AACxC,QAAA;AACF;;IAGAM,eAAgB,CAAA;AAAEN,QAAAA,GAAAA;QAAKE,IAAMD,EAAAA;AAAU,KAAA,CAAA;AACzC;;;;"}