changes access permissions structure to be more typescript-friendly
This commit is contained in:
@@ -32,7 +32,7 @@ module.exports = {
|
|||||||
2,
|
2,
|
||||||
{
|
{
|
||||||
ignore: [
|
ignore: [
|
||||||
'payload/unsanitizedConfig',
|
'payload/config',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"author": "Payload CMS LLC",
|
"author": "Payload CMS LLC",
|
||||||
"main": "./dist/src/index.js",
|
"main": "./dist/src/index.js",
|
||||||
|
"typings": "./dist/src/index.d.ts",
|
||||||
"sideEffects": false,
|
"sideEffects": false,
|
||||||
"bin": {
|
"bin": {
|
||||||
"payload": "./dist/src/bin/index.js"
|
"payload": "./dist/src/bin/index.js"
|
||||||
@@ -94,7 +95,7 @@
|
|||||||
"passport-local-mongoose": "^6.0.1",
|
"passport-local-mongoose": "^6.0.1",
|
||||||
"path-browserify": "^1.0.1",
|
"path-browserify": "^1.0.1",
|
||||||
"pino": "^6.4.1",
|
"pino": "^6.4.1",
|
||||||
"pino-pretty": "^4.1.0",
|
"pino-pretty": "^4.3.0",
|
||||||
"pluralize": "^8.0.0",
|
"pluralize": "^8.0.0",
|
||||||
"postcss-loader": "^4.1.0",
|
"postcss-loader": "^4.1.0",
|
||||||
"postcss-preset-env": "^6.7.0",
|
"postcss-preset-env": "^6.7.0",
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ const Routes = () => {
|
|||||||
path={`${match.url}/collections/${collection.slug}`}
|
path={`${match.url}/collections/${collection.slug}`}
|
||||||
exact
|
exact
|
||||||
render={(routeProps) => {
|
render={(routeProps) => {
|
||||||
if (permissions?.[collection.slug]?.read?.permission) {
|
if (permissions?.collections?.[collection.slug]?.read?.permission) {
|
||||||
return (
|
return (
|
||||||
<List
|
<List
|
||||||
{...routeProps}
|
{...routeProps}
|
||||||
@@ -141,7 +141,7 @@ const Routes = () => {
|
|||||||
path={`${match.url}/collections/${collection.slug}/create`}
|
path={`${match.url}/collections/${collection.slug}/create`}
|
||||||
exact
|
exact
|
||||||
render={(routeProps) => {
|
render={(routeProps) => {
|
||||||
if (permissions?.[collection.slug]?.create?.permission) {
|
if (permissions?.collections?.[collection.slug]?.create?.permission) {
|
||||||
return (
|
return (
|
||||||
<Edit
|
<Edit
|
||||||
{...routeProps}
|
{...routeProps}
|
||||||
@@ -161,7 +161,7 @@ const Routes = () => {
|
|||||||
path={`${match.url}/collections/${collection.slug}/:id`}
|
path={`${match.url}/collections/${collection.slug}/:id`}
|
||||||
exact
|
exact
|
||||||
render={(routeProps) => {
|
render={(routeProps) => {
|
||||||
if (permissions?.[collection.slug]?.read?.permission) {
|
if (permissions?.collections?.[collection.slug]?.read?.permission) {
|
||||||
return (
|
return (
|
||||||
<Edit
|
<Edit
|
||||||
isEditing
|
isEditing
|
||||||
@@ -182,7 +182,7 @@ const Routes = () => {
|
|||||||
path={`${match.url}/globals/${global.slug}`}
|
path={`${match.url}/globals/${global.slug}`}
|
||||||
exact
|
exact
|
||||||
render={(routeProps) => {
|
render={(routeProps) => {
|
||||||
if (permissions?.[global.slug]?.read?.permission) {
|
if (permissions?.globals?.[global.slug]?.read?.permission) {
|
||||||
return (
|
return (
|
||||||
<EditGlobal
|
<EditGlobal
|
||||||
{...routeProps}
|
{...routeProps}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { NavLink, Link, useHistory } from 'react-router-dom';
|
import { NavLink, Link, useHistory } from 'react-router-dom';
|
||||||
import { useConfig } from '@payloadcms/config-provider';
|
import { useConfig, useAuth } from '@payloadcms/config-provider';
|
||||||
import { useAuth } from '@payloadcms/config-provider';
|
|
||||||
import RenderCustomComponent from '../../utilities/RenderCustomComponent';
|
import RenderCustomComponent from '../../utilities/RenderCustomComponent';
|
||||||
import Chevron from '../../icons/Chevron';
|
import Chevron from '../../icons/Chevron';
|
||||||
import LogOut from '../../icons/LogOut';
|
import LogOut from '../../icons/LogOut';
|
||||||
@@ -65,7 +65,7 @@ const DefaultNav = () => {
|
|||||||
{collections && collections.map((collection, i) => {
|
{collections && collections.map((collection, i) => {
|
||||||
const href = `${admin}/collections/${collection.slug}`;
|
const href = `${admin}/collections/${collection.slug}`;
|
||||||
|
|
||||||
if (permissions?.[collection.slug]?.read.permission) {
|
if (permissions?.collections?.[collection.slug]?.read.permission) {
|
||||||
return (
|
return (
|
||||||
<NavLink
|
<NavLink
|
||||||
activeClassName="active"
|
activeClassName="active"
|
||||||
@@ -88,7 +88,7 @@ const DefaultNav = () => {
|
|||||||
{globals.map((global, i) => {
|
{globals.map((global, i) => {
|
||||||
const href = `${admin}/globals/${global.slug}`;
|
const href = `${admin}/globals/${global.slug}`;
|
||||||
|
|
||||||
if (permissions?.[global.slug].read.permission) {
|
if (permissions?.globals?.[global.slug].read.permission) {
|
||||||
return (
|
return (
|
||||||
<NavLink
|
<NavLink
|
||||||
activeClassName="active"
|
activeClassName="active"
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import Select from '../../../../../Select';
|
|||||||
|
|
||||||
|
|
||||||
const createOptions = (collections, permissions) => collections.reduce((options, collection) => {
|
const createOptions = (collections, permissions) => collections.reduce((options, collection) => {
|
||||||
if (permissions[collection.slug]?.read?.permission && collection?.admin?.enableRichTextRelationship) {
|
if (permissions?.collections?.[collection.slug]?.read?.permission && collection?.admin?.enableRichTextRelationship) {
|
||||||
return [
|
return [
|
||||||
...options,
|
...options,
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { useLocation } from 'react-router-dom';
|
import { useLocation } from 'react-router-dom';
|
||||||
import { useConfig } from '@payloadcms/config-provider';
|
import { useConfig, useAuth } from '@payloadcms/config-provider';
|
||||||
import { useStepNav } from '../../elements/StepNav';
|
import { useStepNav } from '../../elements/StepNav';
|
||||||
import { useAuth } from '@payloadcms/config-provider';
|
|
||||||
import usePayloadAPI from '../../../hooks/usePayloadAPI';
|
import usePayloadAPI from '../../../hooks/usePayloadAPI';
|
||||||
import { useLocale } from '../../utilities/Locale';
|
import { useLocale } from '../../utilities/Locale';
|
||||||
import DefaultAccount from './Default';
|
import DefaultAccount from './Default';
|
||||||
@@ -31,7 +31,7 @@ const AccountView = () => {
|
|||||||
|
|
||||||
const { fields } = collection;
|
const { fields } = collection;
|
||||||
|
|
||||||
const collectionPermissions = permissions?.[user?.collection];
|
const collectionPermissions = permissions?.collections?.[user?.collection];
|
||||||
|
|
||||||
const [{ data, isLoading }] = usePayloadAPI(
|
const [{ data, isLoading }] = usePayloadAPI(
|
||||||
`${serverURL}${api}/${collection?.slug}/${user?.id}?depth=0`,
|
`${serverURL}${api}/${collection?.slug}/${user?.id}?depth=0`,
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ const Dashboard = (props) => {
|
|||||||
<h3 className={`${baseClass}__label`}>Collections</h3>
|
<h3 className={`${baseClass}__label`}>Collections</h3>
|
||||||
<ul className={`${baseClass}__card-list`}>
|
<ul className={`${baseClass}__card-list`}>
|
||||||
{collections.map((collection) => {
|
{collections.map((collection) => {
|
||||||
const hasCreatePermission = permissions?.[collection.slug]?.create?.permission;
|
const hasCreatePermission = permissions?.collections?.[collection.slug]?.create?.permission;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<li key={collection.slug}>
|
<li key={collection.slug}>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { useConfig } from '@payloadcms/config-provider';
|
import { useConfig, useAuth } from '@payloadcms/config-provider';
|
||||||
import { useAuth } from '@payloadcms/config-provider';
|
|
||||||
import { useStepNav } from '../../elements/StepNav';
|
import { useStepNav } from '../../elements/StepNav';
|
||||||
import RenderCustomComponent from '../../utilities/RenderCustomComponent';
|
import RenderCustomComponent from '../../utilities/RenderCustomComponent';
|
||||||
import DefaultDashboard from './Default';
|
import DefaultDashboard from './Default';
|
||||||
@@ -22,7 +22,7 @@ const Dashboard = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setFilteredGlobals(
|
setFilteredGlobals(
|
||||||
globals.filter((global) => permissions?.[global.slug]?.read?.permission),
|
globals.filter((global) => permissions?.globals?.[global.slug]?.read?.permission),
|
||||||
);
|
);
|
||||||
}, [permissions, globals]);
|
}, [permissions, globals]);
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ const Dashboard = () => {
|
|||||||
CustomComponent={CustomDashboard}
|
CustomComponent={CustomDashboard}
|
||||||
componentProps={{
|
componentProps={{
|
||||||
globals: filteredGlobals,
|
globals: filteredGlobals,
|
||||||
collections: collections.filter((collection) => permissions?.[collection.slug]?.read?.permission),
|
collections: collections.filter((collection) => permissions?.collections?.[collection.slug]?.read?.permission),
|
||||||
permissions,
|
permissions,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { useHistory, useLocation } from 'react-router-dom';
|
import { useHistory, useLocation } from 'react-router-dom';
|
||||||
import { useConfig } from '@payloadcms/config-provider';
|
import { useConfig, useAuth } from '@payloadcms/config-provider';
|
||||||
import { useStepNav } from '../../elements/StepNav';
|
import { useStepNav } from '../../elements/StepNav';
|
||||||
import usePayloadAPI from '../../../hooks/usePayloadAPI';
|
import usePayloadAPI from '../../../hooks/usePayloadAPI';
|
||||||
import { useAuth } from '@payloadcms/config-provider';
|
|
||||||
import { useLocale } from '../../utilities/Locale';
|
import { useLocale } from '../../utilities/Locale';
|
||||||
|
|
||||||
import RenderCustomComponent from '../../utilities/RenderCustomComponent';
|
import RenderCustomComponent from '../../utilities/RenderCustomComponent';
|
||||||
@@ -77,7 +77,7 @@ const GlobalView = (props) => {
|
|||||||
awaitInitialState();
|
awaitInitialState();
|
||||||
}, [dataToRender, fields]);
|
}, [dataToRender, fields]);
|
||||||
|
|
||||||
const globalPermissions = permissions?.[slug];
|
const globalPermissions = permissions?.globals?.[slug];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<NegativeFieldGutterProvider allow>
|
<NegativeFieldGutterProvider allow>
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { Redirect, useRouteMatch, useHistory, useLocation } from 'react-router-dom';
|
import { Redirect, useRouteMatch, useHistory, useLocation } from 'react-router-dom';
|
||||||
import { useConfig } from '@payloadcms/config-provider';
|
import { useConfig, useAuth } from '@payloadcms/config-provider';
|
||||||
import { useStepNav } from '../../../elements/StepNav';
|
import { useStepNav } from '../../../elements/StepNav';
|
||||||
import usePayloadAPI from '../../../../hooks/usePayloadAPI';
|
import usePayloadAPI from '../../../../hooks/usePayloadAPI';
|
||||||
import { useAuth } from '@payloadcms/config-provider';
|
|
||||||
|
|
||||||
import RenderCustomComponent from '../../../utilities/RenderCustomComponent';
|
import RenderCustomComponent from '../../../utilities/RenderCustomComponent';
|
||||||
import DefaultEdit from './Default';
|
import DefaultEdit from './Default';
|
||||||
@@ -91,7 +91,7 @@ const EditView = (props) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const collectionPermissions = permissions?.[slug];
|
const collectionPermissions = permissions?.collections?.[slug];
|
||||||
|
|
||||||
const apiURL = `${serverURL}${api}/${slug}/${id}`;
|
const apiURL = `${serverURL}${api}/${slug}/${id}`;
|
||||||
const action = `${serverURL}${api}/${slug}${isEditing ? `/${id}` : ''}?locale=${locale}&depth=0`;
|
const action = `${serverURL}${api}/${slug}${isEditing ? `/${id}` : ''}?locale=${locale}&depth=0`;
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import React, { useEffect, useState } from 'react';
|
|||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import queryString from 'qs';
|
import queryString from 'qs';
|
||||||
import { useLocation } from 'react-router-dom';
|
import { useLocation } from 'react-router-dom';
|
||||||
import { useConfig } from '@payloadcms/config-provider';
|
import { useConfig, useAuth } from '@payloadcms/config-provider';
|
||||||
import { useAuth } from '@payloadcms/config-provider';
|
|
||||||
import usePayloadAPI from '../../../../hooks/usePayloadAPI';
|
import usePayloadAPI from '../../../../hooks/usePayloadAPI';
|
||||||
import DefaultList from './Default';
|
import DefaultList from './Default';
|
||||||
import RenderCustomComponent from '../../../utilities/RenderCustomComponent';
|
import RenderCustomComponent from '../../../utilities/RenderCustomComponent';
|
||||||
@@ -37,7 +37,7 @@ const ListView = (props) => {
|
|||||||
const [columns, setColumns] = useState([]);
|
const [columns, setColumns] = useState([]);
|
||||||
const [sort, setSort] = useState(null);
|
const [sort, setSort] = useState(null);
|
||||||
|
|
||||||
const collectionPermissions = permissions?.[slug];
|
const collectionPermissions = permissions?.collections?.[slug];
|
||||||
const hasCreatePermission = collectionPermissions?.create?.permission;
|
const hasCreatePermission = collectionPermissions?.create?.permission;
|
||||||
|
|
||||||
const { page } = queryString.parse(location.search, { ignoreQueryPrefix: true });
|
const { page } = queryString.parse(location.search, { ignoreQueryPrefix: true });
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
|
// @ts-ignore - need to do this because this file doesn't actually exist
|
||||||
|
import config from 'payload/config';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { render } from 'react-dom';
|
import { render } from 'react-dom';
|
||||||
import { BrowserRouter as Router } from 'react-router-dom';
|
import { BrowserRouter as Router } from 'react-router-dom';
|
||||||
@@ -6,7 +9,6 @@ import { WindowInfoProvider } from '@faceless-ui/window-info';
|
|||||||
import { ModalProvider, ModalContainer } from '@faceless-ui/modal';
|
import { ModalProvider, ModalContainer } from '@faceless-ui/modal';
|
||||||
import { ToastContainer, Slide } from 'react-toastify';
|
import { ToastContainer, Slide } from 'react-toastify';
|
||||||
import { ConfigProvider, AuthProvider } from '@payloadcms/config-provider';
|
import { ConfigProvider, AuthProvider } from '@payloadcms/config-provider';
|
||||||
import unsanitizedConfig from 'payload/unsanitizedConfig';
|
|
||||||
import { SearchParamsProvider } from './components/utilities/SearchParams';
|
import { SearchParamsProvider } from './components/utilities/SearchParams';
|
||||||
import { LocaleProvider } from './components/utilities/Locale';
|
import { LocaleProvider } from './components/utilities/Locale';
|
||||||
import Routes from './components/Routes';
|
import Routes from './components/Routes';
|
||||||
@@ -16,7 +18,7 @@ import './scss/app.scss';
|
|||||||
|
|
||||||
const Index = () => (
|
const Index = () => (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<ConfigProvider config={unsanitizedConfig}>
|
<ConfigProvider config={config}>
|
||||||
<WindowInfoProvider breakpoints={{
|
<WindowInfoProvider breakpoints={{
|
||||||
xs: parseInt(getCSSVariable('breakpoint-xs-width').replace('px', ''), 10),
|
xs: parseInt(getCSSVariable('breakpoint-xs-width').replace('px', ''), 10),
|
||||||
s: parseInt(getCSSVariable('breakpoint-s-width').replace('px', ''), 10),
|
s: parseInt(getCSSVariable('breakpoint-s-width').replace('px', ''), 10),
|
||||||
|
|||||||
@@ -67,18 +67,20 @@ async function accessOperation(args) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const executeEntityPolicies = (entity, operations) => {
|
const executeEntityPolicies = (entity, operations, type) => {
|
||||||
results[entity.slug] = {
|
if (!results[type]) results[type] = {};
|
||||||
|
|
||||||
|
results[type][entity.slug] = {
|
||||||
fields: {},
|
fields: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
operations.forEach((operation) => {
|
operations.forEach((operation) => {
|
||||||
executeFieldPolicies(results[entity.slug].fields, entity.fields, operation);
|
executeFieldPolicies(results[type][entity.slug].fields, entity.fields, operation);
|
||||||
|
|
||||||
if (typeof entity.access[operation] === 'function') {
|
if (typeof entity.access[operation] === 'function') {
|
||||||
promises.push(createAccessPromise(results[entity.slug], entity.access[operation], operation));
|
promises.push(createAccessPromise(results[type][entity.slug], entity.access[operation], operation));
|
||||||
} else {
|
} else {
|
||||||
results[entity.slug][operation] = {
|
results[type][entity.slug][operation] = {
|
||||||
permission: isLoggedIn,
|
permission: isLoggedIn,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -87,17 +89,17 @@ async function accessOperation(args) {
|
|||||||
|
|
||||||
if (userCollectionConfig) {
|
if (userCollectionConfig) {
|
||||||
results.canAccessAdmin = userCollectionConfig.access.admin ? userCollectionConfig.access.admin(args) : isLoggedIn;
|
results.canAccessAdmin = userCollectionConfig.access.admin ? userCollectionConfig.access.admin(args) : isLoggedIn;
|
||||||
if (results.canAccessAdmin) results.license = config.license;
|
if (results.canAccessAdmin) results.license = this.license;
|
||||||
} else {
|
} else {
|
||||||
results.canAccessAdmin = false;
|
results.canAccessAdmin = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
config.collections.forEach((collection) => {
|
config.collections.forEach((collection) => {
|
||||||
executeEntityPolicies(collection, allOperations);
|
executeEntityPolicies(collection, allOperations, 'collection');
|
||||||
});
|
});
|
||||||
|
|
||||||
config.globals.forEach((global) => {
|
config.globals.forEach((global) => {
|
||||||
executeEntityPolicies(global, ['read', 'update']);
|
executeEntityPolicies(global, ['read', 'update'], 'global');
|
||||||
});
|
});
|
||||||
|
|
||||||
await Promise.all(promises);
|
await Promise.all(promises);
|
||||||
|
|||||||
@@ -3,31 +3,51 @@ export type Permission = {
|
|||||||
where?: Record<string, unknown>
|
where?: Record<string, unknown>
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Permissions = {
|
export type CollectionPermission = {
|
||||||
[key: string]: boolean | {
|
create: Permission
|
||||||
create: Permission
|
read: Permission
|
||||||
read: Permission
|
update: Permission
|
||||||
update: Permission
|
delete: Permission
|
||||||
delete: Permission
|
fields: {
|
||||||
fields: {
|
[field: string]: {
|
||||||
[field: string]: {
|
create: {
|
||||||
create: {
|
permission: boolean
|
||||||
permission: boolean
|
}
|
||||||
}
|
read: {
|
||||||
read: {
|
permission: boolean
|
||||||
permission: boolean
|
}
|
||||||
}
|
update: {
|
||||||
update: {
|
permission: boolean
|
||||||
permission: boolean
|
}
|
||||||
}
|
delete: {
|
||||||
delete: {
|
permission: boolean
|
||||||
permission: boolean
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type GlobalPermission = {
|
||||||
|
read: Permission
|
||||||
|
update: Permission
|
||||||
|
fields: {
|
||||||
|
[field: string]: {
|
||||||
|
read: {
|
||||||
|
permission: boolean
|
||||||
|
}
|
||||||
|
update: {
|
||||||
|
permission: boolean
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export type Permissions = {
|
||||||
|
canAccessAdmin: boolean
|
||||||
|
license?: string
|
||||||
|
collections: CollectionPermission[]
|
||||||
|
globals?: GlobalPermission[]
|
||||||
|
}
|
||||||
|
|
||||||
export type User = {
|
export type User = {
|
||||||
id: string
|
id: string
|
||||||
email: string
|
email: string
|
||||||
|
|||||||
@@ -66,7 +66,6 @@ const sanitizeConfig = (config: Config): Config => {
|
|||||||
|
|
||||||
sanitizedConfig.components = { ...(config.components || {}) };
|
sanitizedConfig.components = { ...(config.components || {}) };
|
||||||
sanitizedConfig.hooks = { ...(config.hooks || {}) };
|
sanitizedConfig.hooks = { ...(config.hooks || {}) };
|
||||||
sanitizedConfig.admin = { ...(config.admin || {}) };
|
|
||||||
|
|
||||||
return sanitizedConfig as DeepRequired<Config>;
|
return sanitizedConfig as DeepRequired<Config>;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ import { Response, NextFunction } from 'express';
|
|||||||
import formatErrorResponse from '../responses/formatError';
|
import formatErrorResponse from '../responses/formatError';
|
||||||
import { PayloadRequest } from '../types/payloadRequest';
|
import { PayloadRequest } from '../types/payloadRequest';
|
||||||
|
|
||||||
const errorHandler = (config, logger) => async (err, req: PayloadRequest, res: Response): Promise<void> => {
|
// NextFunction must be passed for Express to use this middleware as error handler
|
||||||
|
const errorHandler = (config, logger) => async (err, req: PayloadRequest, res: Response, next: NextFunction): Promise<void> => {
|
||||||
const data = formatErrorResponse(err);
|
const data = formatErrorResponse(err);
|
||||||
let response;
|
let response;
|
||||||
let status = err.status || httpStatus.INTERNAL_SERVER_ERROR;
|
let status = err.status || httpStatus.INTERNAL_SERVER_ERROR;
|
||||||
|
|||||||
@@ -318,4 +318,7 @@ export class Payload {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = new Payload();
|
const payload = new Payload();
|
||||||
|
|
||||||
|
export default payload;
|
||||||
|
module.exports = payload;
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ export default (config: Config): Configuration => {
|
|||||||
},
|
},
|
||||||
modules: ['node_modules', path.resolve(__dirname, '../../node_modules')],
|
modules: ['node_modules', path.resolve(__dirname, '../../node_modules')],
|
||||||
alias: {
|
alias: {
|
||||||
'payload/unsanitizedConfig': config.paths.config,
|
'payload/config': config.paths.config,
|
||||||
'@payloadcms/payload$': mockModulePath,
|
'@payloadcms/payload$': mockModulePath,
|
||||||
},
|
},
|
||||||
extensions: ['.ts', '.tsx', '.js', '.json'],
|
extensions: ['.ts', '.tsx', '.js', '.json'],
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ export default (config: Config): Configuration => {
|
|||||||
},
|
},
|
||||||
modules: ['node_modules', path.resolve(__dirname, '../../node_modules')],
|
modules: ['node_modules', path.resolve(__dirname, '../../node_modules')],
|
||||||
alias: {
|
alias: {
|
||||||
'payload/unsanitizedConfig': config.paths.config,
|
'payload/config': config.paths.config,
|
||||||
'@payloadcms/payload$': mockModulePath,
|
'@payloadcms/payload$': mockModulePath,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,60 +1,27 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
"target": "esnext",
|
||||||
/* Basic Options */
|
"module": "commonjs",
|
||||||
// "incremental": true, /* Enable incremental compilation */
|
|
||||||
"target": "esnext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
|
|
||||||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
|
|
||||||
// "lib": [], /* Specify library files to be included in the compilation. */
|
|
||||||
"allowJs": true, /* Allow javascript files to be compiled. */
|
"allowJs": true, /* Allow javascript files to be compiled. */
|
||||||
"checkJs": false, /* Report errors in .js files. */
|
"checkJs": false, /* Report errors in .js files. */
|
||||||
"jsx": "react", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
"jsx": "react", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
||||||
"declaration": true, /* Generates corresponding '.d.ts' file. */
|
"declaration": true, /* Generates corresponding '.d.ts' file. */
|
||||||
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
/* Concatenate and emit output to single file. */
|
||||||
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
|
||||||
// "outFile": "./", /* Concatenate and emit output to single file. */
|
|
||||||
"outDir": "./dist", /* Redirect output structure to the directory. */
|
"outDir": "./dist", /* Redirect output structure to the directory. */
|
||||||
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||||
// "composite": true, /* Enable project compilation */
|
/* Do not emit comments to output. */
|
||||||
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
|
||||||
// "removeComments": true, /* Do not emit comments to output. */
|
|
||||||
"noEmit": false, /* Do not emit outputs. */
|
"noEmit": false, /* Do not emit outputs. */
|
||||||
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
|
||||||
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
|
||||||
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
|
||||||
/* Strict Type-Checking Options */
|
|
||||||
"strict": false, /* Enable all strict type-checking options. */
|
"strict": false, /* Enable all strict type-checking options. */
|
||||||
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
|
||||||
// "strictNullChecks": true, /* Enable strict null checks. */
|
|
||||||
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
|
||||||
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
|
||||||
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
|
||||||
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
|
||||||
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
|
||||||
/* Additional Checks */
|
|
||||||
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
|
||||||
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
|
||||||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
|
||||||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
|
||||||
/* Module Resolution Options */
|
|
||||||
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
||||||
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
"baseUrl": "",
|
||||||
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
"paths": {
|
||||||
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
"payload/config": [
|
||||||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
"src/admin/types/config" // Webpack alias to user config
|
||||||
|
],
|
||||||
|
},
|
||||||
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
|
||||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
/* Source Map Options */
|
|
||||||
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
|
||||||
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
||||||
"inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
"inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
||||||
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
|
||||||
/* Experimental Options */
|
|
||||||
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
|
||||||
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
|
||||||
/* Advanced Options */
|
|
||||||
"skipLibCheck": true, /* Skip type checking of declaration files. */
|
"skipLibCheck": true, /* Skip type checking of declaration files. */
|
||||||
"forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */
|
"forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */
|
||||||
},
|
},
|
||||||
|
|||||||
37
yarn.lock
37
yarn.lock
@@ -2150,9 +2150,9 @@
|
|||||||
loglevel "^1.6.2"
|
loglevel "^1.6.2"
|
||||||
|
|
||||||
"@types/webpack-env@^1.15.3":
|
"@types/webpack-env@^1.15.3":
|
||||||
version "1.15.3"
|
version "1.16.0"
|
||||||
resolved "https://registry.yarnpkg.com/@types/webpack-env/-/webpack-env-1.15.3.tgz#fb602cd4c2f0b7c0fb857e922075fdf677d25d84"
|
resolved "https://registry.yarnpkg.com/@types/webpack-env/-/webpack-env-1.16.0.tgz#8c0a9435dfa7b3b1be76562f3070efb3f92637b4"
|
||||||
integrity sha512-5oiXqR7kwDGZ6+gmzIO2lTC+QsriNuQXZDWNYRV3l2XRN/zmPgnC21DLSx2D05zvD8vnXW6qUg7JnXZ4I6qLVQ==
|
integrity sha512-Fx+NpfOO0CpeYX2g9bkvX8O5qh9wrU1sOF4g8sft4Mu7z+qfe387YlyY8w8daDyDsKY5vUxM0yxkAYnbkRbZEw==
|
||||||
|
|
||||||
"@types/webpack-hot-middleware@^2.25.3":
|
"@types/webpack-hot-middleware@^2.25.3":
|
||||||
version "2.25.3"
|
version "2.25.3"
|
||||||
@@ -3427,9 +3427,9 @@ caniuse-api@^3.0.0:
|
|||||||
lodash.uniq "^4.5.0"
|
lodash.uniq "^4.5.0"
|
||||||
|
|
||||||
caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001157:
|
caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001157:
|
||||||
version "1.0.30001159"
|
version "1.0.30001161"
|
||||||
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001159.tgz#bebde28f893fa9594dadcaa7d6b8e2aa0299df20"
|
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001161.tgz#64f7ffe79ee780b8c92843ff34feb36cea4651e0"
|
||||||
integrity sha512-w9Ph56jOsS8RL20K9cLND3u/+5WASWdhC/PPrf+V3/HsM3uHOavWOR1Xzakbv4Puo/srmPHudkmCRWM7Aq+/UA==
|
integrity sha512-JharrCDxOqPLBULF9/SPa6yMcBRTjZARJ6sc3cuKrPfyIk64JN6kuMINWqA99Xc8uElMFcROliwtz0n9pYej+g==
|
||||||
|
|
||||||
capture-exit@^2.0.0:
|
capture-exit@^2.0.0:
|
||||||
version "2.0.0"
|
version "2.0.0"
|
||||||
@@ -4646,9 +4646,9 @@ ejs@^2.6.1:
|
|||||||
integrity sha512-7vmuyh5+kuUyJKePhQfRQBhXV5Ce+RnaeeQArKu1EAMpL3WbgMt5WG6uQZpEVvYSSsxMXRKOewtDk9RaTKXRlA==
|
integrity sha512-7vmuyh5+kuUyJKePhQfRQBhXV5Ce+RnaeeQArKu1EAMpL3WbgMt5WG6uQZpEVvYSSsxMXRKOewtDk9RaTKXRlA==
|
||||||
|
|
||||||
electron-to-chromium@^1.3.591:
|
electron-to-chromium@^1.3.591:
|
||||||
version "1.3.604"
|
version "1.3.606"
|
||||||
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.604.tgz#285da30e38a71e2b9d28ce3a792ec60235c63b7c"
|
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.606.tgz#6ef2655d9a7c1b447dfdd6344657d00461a65e26"
|
||||||
integrity sha512-Mk5ODhvz+ZaQpVFXbu51wGW94P3CnkJIDkEQGxXMl6Ix6R0PG4IFWz83WbqFEZjN1UksoTsmmzKY5SmUrEvNJQ==
|
integrity sha512-+/2yPHwtNf6NWKpaYt0KoqdSZ6Qddt6nDfH/pnhcrHq9hSb23e5LFy06Mlf0vF2ykXvj7avJ597psqcbKnG5YQ==
|
||||||
|
|
||||||
emittery@^0.7.1:
|
emittery@^0.7.1:
|
||||||
version "0.7.2"
|
version "0.7.2"
|
||||||
@@ -4850,11 +4850,12 @@ eslint-plugin-import@^2.20.0:
|
|||||||
tsconfig-paths "^3.9.0"
|
tsconfig-paths "^3.9.0"
|
||||||
|
|
||||||
eslint-plugin-jest-dom@^3.0.1:
|
eslint-plugin-jest-dom@^3.0.1:
|
||||||
version "3.2.4"
|
version "3.3.0"
|
||||||
resolved "https://registry.yarnpkg.com/eslint-plugin-jest-dom/-/eslint-plugin-jest-dom-3.2.4.tgz#78e95c48755240a4d1e9d6c3bdcd87ea4af242b9"
|
resolved "https://registry.yarnpkg.com/eslint-plugin-jest-dom/-/eslint-plugin-jest-dom-3.3.0.tgz#5be14f8c303b7e8551b426bc7ac8a152d01736ae"
|
||||||
integrity sha512-CRR5rMMJgLKjxHHuio/oy4tt5gnUohgGNMzLM0p0THoyRYewzV/PE+8qUUHSyTO+iexCvgnHukdRfckdyi+5tg==
|
integrity sha512-/7LqlMPiZh4SHy8YXSHilcx/zy7m5Fb7rl4AlzjIY8+amsGP2nZq9WIbMv0JYYVeq20p5+44GmWO6dCZcdLj4A==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@babel/runtime" "^7.9.6"
|
"@babel/runtime" "^7.9.6"
|
||||||
|
"@testing-library/dom" "^7.28.1"
|
||||||
requireindex "^1.2.0"
|
requireindex "^1.2.0"
|
||||||
|
|
||||||
eslint-plugin-jest@^23.16.0:
|
eslint-plugin-jest@^23.16.0:
|
||||||
@@ -6479,9 +6480,9 @@ is-hexadecimal@^1.0.0:
|
|||||||
integrity sha512-gyPJuv83bHMpocVYoqof5VDiZveEoGoFL8m3BXNb2VW8Xs+rz9kqO8LOQ5DH6EsuvilT1ApazU0pyl+ytbPtlw==
|
integrity sha512-gyPJuv83bHMpocVYoqof5VDiZveEoGoFL8m3BXNb2VW8Xs+rz9kqO8LOQ5DH6EsuvilT1ApazU0pyl+ytbPtlw==
|
||||||
|
|
||||||
is-hotkey@^0.1.6:
|
is-hotkey@^0.1.6:
|
||||||
version "0.1.7"
|
version "0.1.8"
|
||||||
resolved "https://registry.yarnpkg.com/is-hotkey/-/is-hotkey-0.1.7.tgz#15b89a80c71df0a7367bafa8629a187196586522"
|
resolved "https://registry.yarnpkg.com/is-hotkey/-/is-hotkey-0.1.8.tgz#6b1f4b2d0e5639934e20c05ed24d623a21d36d25"
|
||||||
integrity sha512-fOzQF4+oex9Alhn4vDxzukeO5kwpn825U8CjACFD5MtPs52/0RnkYNYmhSDD6sPfRngCr/c6+VGyF3Wc7Jv+iw==
|
integrity sha512-qs3NZ1INIS+H+yeo7cD9pDfwYV/jqRh1JG9S9zYrNudkoUQg7OL7ziXqRKu+InFjUIDoP2o6HIkLYMh1pcWgyQ==
|
||||||
|
|
||||||
is-installed-globally@^0.1.0:
|
is-installed-globally@^0.1.0:
|
||||||
version "0.1.0"
|
version "0.1.0"
|
||||||
@@ -8821,7 +8822,7 @@ pinkie@^2.0.0:
|
|||||||
resolved "https://registry.yarnpkg.com/pinkie/-/pinkie-2.0.4.tgz#72556b80cfa0d48a974e80e77248e80ed4f7f870"
|
resolved "https://registry.yarnpkg.com/pinkie/-/pinkie-2.0.4.tgz#72556b80cfa0d48a974e80e77248e80ed4f7f870"
|
||||||
integrity sha1-clVrgM+g1IqXToDnckjoDtT3+HA=
|
integrity sha1-clVrgM+g1IqXToDnckjoDtT3+HA=
|
||||||
|
|
||||||
pino-pretty@^4.1.0:
|
pino-pretty@^4.3.0:
|
||||||
version "4.3.0"
|
version "4.3.0"
|
||||||
resolved "https://registry.yarnpkg.com/pino-pretty/-/pino-pretty-4.3.0.tgz#18695606fd4f1e21cd1585d18999cd84d429e1d8"
|
resolved "https://registry.yarnpkg.com/pino-pretty/-/pino-pretty-4.3.0.tgz#18695606fd4f1e21cd1585d18999cd84d429e1d8"
|
||||||
integrity sha512-uEc9SUCCGVEs0goZvyznKXBHtI1PNjGgqHviJHxOCEFEWZN6Z/IQKv5pO9gSdm/b+WfX+/dfheWhtZUyScqjlQ==
|
integrity sha512-uEc9SUCCGVEs0goZvyznKXBHtI1PNjGgqHviJHxOCEFEWZN6Z/IQKv5pO9gSdm/b+WfX+/dfheWhtZUyScqjlQ==
|
||||||
@@ -11738,12 +11739,11 @@ ts-easing@^0.2.0:
|
|||||||
resolved "https://registry.yarnpkg.com/ts-easing/-/ts-easing-0.2.0.tgz#c8a8a35025105566588d87dbda05dd7fbfa5a4ec"
|
resolved "https://registry.yarnpkg.com/ts-easing/-/ts-easing-0.2.0.tgz#c8a8a35025105566588d87dbda05dd7fbfa5a4ec"
|
||||||
integrity sha512-Z86EW+fFFh/IFB1fqQ3/+7Zpf9t2ebOAxNI/V6Wo7r5gqiqtxmgTlQ1qbqQcjLKYeSHPTsEmvlJUDg/EuL0uHQ==
|
integrity sha512-Z86EW+fFFh/IFB1fqQ3/+7Zpf9t2ebOAxNI/V6Wo7r5gqiqtxmgTlQ1qbqQcjLKYeSHPTsEmvlJUDg/EuL0uHQ==
|
||||||
|
|
||||||
<<<<<<< HEAD
|
|
||||||
ts-essentials@^7.0.1:
|
ts-essentials@^7.0.1:
|
||||||
version "7.0.1"
|
version "7.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/ts-essentials/-/ts-essentials-7.0.1.tgz#d205508cae0cdadfb73c89503140cf2228389e2d"
|
resolved "https://registry.yarnpkg.com/ts-essentials/-/ts-essentials-7.0.1.tgz#d205508cae0cdadfb73c89503140cf2228389e2d"
|
||||||
integrity sha512-8lwh3QJtIc1UWhkQtr9XuksXu3O0YQdEE5g79guDfhCaU1FWTDIEDZ1ZSx4HTHUmlJZ8L812j3BZQ4a0aOUkSA==
|
integrity sha512-8lwh3QJtIc1UWhkQtr9XuksXu3O0YQdEE5g79guDfhCaU1FWTDIEDZ1ZSx4HTHUmlJZ8L812j3BZQ4a0aOUkSA==
|
||||||
=======
|
|
||||||
tsc-silent@^1.2.1:
|
tsc-silent@^1.2.1:
|
||||||
version "1.2.1"
|
version "1.2.1"
|
||||||
resolved "https://registry.yarnpkg.com/tsc-silent/-/tsc-silent-1.2.1.tgz#c219789b7b1ab8e475fe3069d061d5ab49167d3f"
|
resolved "https://registry.yarnpkg.com/tsc-silent/-/tsc-silent-1.2.1.tgz#c219789b7b1ab8e475fe3069d061d5ab49167d3f"
|
||||||
@@ -11751,7 +11751,6 @@ tsc-silent@^1.2.1:
|
|||||||
dependencies:
|
dependencies:
|
||||||
"@types/node" "10.12.7"
|
"@types/node" "10.12.7"
|
||||||
yargs "12 - 15"
|
yargs "12 - 15"
|
||||||
>>>>>>> 062771e0a720fc1684a4754e42b14b95c9cc2c73
|
|
||||||
|
|
||||||
tsconfig-paths@^3.9.0:
|
tsconfig-paths@^3.9.0:
|
||||||
version "3.9.0"
|
version "3.9.0"
|
||||||
|
|||||||
Reference in New Issue
Block a user