payload 0.16.4 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +18 -22
  3. package/components/utilities.ts +3 -0
  4. package/dist/admin/components/Routes.js +2 -7
  5. package/dist/admin/components/elements/Autosave/index.js +1 -1
  6. package/dist/admin/components/elements/DeleteDocument/index.js +1 -1
  7. package/dist/admin/components/elements/DuplicateDocument/index.js +1 -1
  8. package/dist/admin/components/elements/FileDetails/Meta/index.js +1 -1
  9. package/dist/admin/components/elements/Localizer/index.js +1 -1
  10. package/dist/admin/components/elements/Nav/index.js +2 -1
  11. package/dist/admin/components/elements/PreviewButton/index.js +1 -1
  12. package/dist/admin/components/elements/SaveDraft/index.js +1 -1
  13. package/dist/admin/components/elements/Status/index.js +1 -1
  14. package/dist/admin/components/elements/VersionsCount/index.js +1 -1
  15. package/dist/admin/components/elements/WhereBuilder/Condition/Relationship/index.js +1 -1
  16. package/dist/admin/components/forms/DraggableSection/PositionPanel/index.js +5 -4
  17. package/dist/admin/components/forms/DraggableSection/PositionPanel/types.d.ts +1 -0
  18. package/dist/admin/components/forms/DraggableSection/index.js +1 -1
  19. package/dist/admin/components/forms/Form/index.js +1 -1
  20. package/dist/admin/components/forms/field-types/Array/Array.js +1 -1
  21. package/dist/admin/components/forms/field-types/Blocks/Blocks.js +1 -1
  22. package/dist/admin/components/forms/field-types/Relationship/index.js +2 -1
  23. package/dist/admin/components/forms/field-types/RichText/elements/relationship/Button/Fields/index.js +2 -1
  24. package/dist/admin/components/forms/field-types/RichText/elements/relationship/Button/index.js +1 -1
  25. package/dist/admin/components/forms/field-types/RichText/elements/relationship/Element/index.js +1 -1
  26. package/dist/admin/components/forms/field-types/RichText/elements/upload/Button/index.js +1 -1
  27. package/dist/admin/components/forms/field-types/RichText/elements/upload/Element/EditModal/index.js +1 -1
  28. package/dist/admin/components/forms/field-types/RichText/elements/upload/Element/SwapUploadModal/index.js +1 -1
  29. package/dist/admin/components/forms/field-types/RichText/elements/upload/Element/index.js +1 -1
  30. package/dist/admin/components/forms/field-types/Upload/Add/index.js +2 -1
  31. package/dist/admin/components/forms/field-types/Upload/SelectExisting/index.js +2 -1
  32. package/dist/admin/components/forms/field-types/Upload/index.js +1 -1
  33. package/dist/admin/components/forms/useField/index.js +1 -1
  34. package/dist/admin/components/graphics/Icon/index.js +1 -1
  35. package/dist/admin/components/graphics/Logo/index.js +1 -1
  36. package/dist/admin/components/modals/LeaveWithoutSaving/index.js +1 -1
  37. package/dist/admin/components/modals/StayLoggedIn/index.js +1 -1
  38. package/dist/admin/components/templates/Default/index.js +1 -1
  39. package/dist/admin/components/utilities/Auth/index.d.ts +6 -0
  40. package/dist/admin/components/utilities/Auth/index.js +124 -0
  41. package/dist/admin/components/utilities/Auth/types.d.ts +9 -0
  42. package/dist/admin/components/utilities/Auth/types.js +1 -0
  43. package/dist/admin/components/utilities/Config/index.d.ts +7 -0
  44. package/dist/admin/components/utilities/Config/index.js +4 -0
  45. package/dist/admin/components/utilities/CustomProvider/index.js +1 -1
  46. package/dist/admin/components/utilities/DocumentInfo/index.js +1 -1
  47. package/dist/admin/components/utilities/Locale/index.js +2 -1
  48. package/dist/admin/components/utilities/Meta/index.js +1 -1
  49. package/dist/admin/components/utilities/Preferences/index.js +2 -1
  50. package/dist/admin/components/utilities/RenderCustomComponent/index.js +3 -1
  51. package/dist/admin/components/views/Account/Default.js +1 -1
  52. package/dist/admin/components/views/Account/index.js +2 -1
  53. package/dist/admin/components/views/CreateFirstUser/index.js +2 -1
  54. package/dist/admin/components/views/Dashboard/Default.js +1 -1
  55. package/dist/admin/components/views/Dashboard/index.js +2 -1
  56. package/dist/admin/components/views/ForgotPassword/index.js +2 -1
  57. package/dist/admin/components/views/Global/Default.js +1 -1
  58. package/dist/admin/components/views/Global/index.js +2 -1
  59. package/dist/admin/components/views/Login/index.js +2 -1
  60. package/dist/admin/components/views/Logout/index.js +2 -1
  61. package/dist/admin/components/views/NotFound/index.js +1 -1
  62. package/dist/admin/components/views/ResetPassword/index.js +2 -1
  63. package/dist/admin/components/views/Unauthorized/index.js +1 -1
  64. package/dist/admin/components/views/Verify/index.js +2 -1
  65. package/dist/admin/components/views/Version/Compare/index.js +1 -1
  66. package/dist/admin/components/views/Version/RenderFieldsToDiff/fields/Relationship/index.js +1 -1
  67. package/dist/admin/components/views/Version/Restore/index.js +1 -1
  68. package/dist/admin/components/views/Version/Version.js +2 -1
  69. package/dist/admin/components/views/Versions/columns.js +1 -1
  70. package/dist/admin/components/views/Versions/index.js +1 -1
  71. package/dist/admin/components/views/collections/Edit/Auth/index.js +1 -1
  72. package/dist/admin/components/views/collections/Edit/Default.js +1 -1
  73. package/dist/admin/components/views/collections/Edit/index.js +2 -1
  74. package/dist/admin/components/views/collections/List/Cell/cellTypes.spec.js +1 -1
  75. package/dist/admin/components/views/collections/List/Cell/field-types/Date/index.js +1 -1
  76. package/dist/admin/components/views/collections/List/Cell/field-types/Relationship/index.js +1 -1
  77. package/dist/admin/components/views/collections/List/Cell/index.js +1 -1
  78. package/dist/admin/components/views/collections/List/Default.js +1 -1
  79. package/dist/admin/components/views/collections/List/index.js +2 -1
  80. package/dist/admin/hooks/useThumbnail.js +1 -1
  81. package/dist/admin/index.js +2 -1
  82. package/dist/auth/operations/access.js +1 -3
  83. package/dist/auth/types.d.ts +0 -1
  84. package/dist/auth/types.js +1 -1
  85. package/dist/config/types.d.ts +0 -1
  86. package/dist/index.d.ts +0 -1
  87. package/dist/index.js +1 -2
  88. package/dist/mongoose/connect.js +2 -2
  89. package/docs/admin/components.mdx +74 -3
  90. package/docs/admin/overview.mdx +0 -4
  91. package/docs/authentication/operations.mdx +0 -1
  92. package/docs/email/overview.mdx +2 -1
  93. package/docs/getting-started/installation.mdx +0 -4
  94. package/license.md +22 -238
  95. package/package.json +3 -3
  96. package/dist/admin/components/views/UnauthorizedUser/index.d.ts +0 -4
  97. package/dist/admin/components/views/UnauthorizedUser/index.js +0 -30
  98. package/dist/admin/components/views/UnauthorizedUser/index.scss +0 -15
  99. package/dist/admin/components/views/Unlicensed/index.d.ts +0 -3
  100. package/dist/admin/components/views/Unlicensed/index.js +0 -19
  101. package/docs/production/licensing.mdx +0 -84
package/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ # [0.17.0](https://github.com/payloadcms/payload/compare/v0.16.4...v0.17.0) (2022-05-16)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * apply field condition to custom components ([#560](https://github.com/payloadcms/payload/issues/560)) ([1dfe2b8](https://github.com/payloadcms/payload/commit/1dfe2b892947411ff5295f5818befe28c4972915))
7
+ * prevent changing order of readOnly arrays ([#563](https://github.com/payloadcms/payload/issues/563)) ([16b7edb](https://github.com/payloadcms/payload/commit/16b7edbc9782dcfb3bef77f1ff312e041d66922c))
8
+
1
9
  ## [0.16.4](https://github.com/payloadcms/payload/compare/v0.16.3...v0.16.4) (2022-05-06)
2
10
 
3
11
 
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <h1 align="center">Payload</h1>
2
- <p align="center">A self-hosted, TypeScript / JavaScript headless CMS & application framework built with Express, MongoDB and React.</p>
2
+ <p align="center">A free and open-source TypeScript headless CMS & application framework built with Express, MongoDB and React.</p>
3
3
  <p align="center">
4
4
  <a href="https://github.com/payloadcms/payload/actions">
5
5
  <img src="https://github.com/payloadcms/payload/workflows/build/badge.svg" />
@@ -21,25 +21,15 @@
21
21
  <img src="https://payloadcms.com/images/og-image.jpg" alt="Payload headless CMS Admin panel built with React" />
22
22
  </a>
23
23
 
24
- ### Quick Start
25
-
26
- ```
27
- npx create-payload-app
28
- ```
29
-
30
- Alternatively, it only takes about five minutes to [create an app from scratch](https://payloadcms.com/docs/getting-started/installation#from-scratch).
31
-
32
- ### Documentation
33
-
34
- Check out the [Payload website](https://payloadcms.com/docs/getting-started/what-is-payload) to find in-depth documentation for everything that Payload offers.
35
-
36
24
  ### Features
37
25
 
26
+ - Completely free and open-source
38
27
  - [GraphQL](https://payloadcms.com/docs/graphql/overview), [REST](https://payloadcms.com/docs/rest-api/overview), and [Local](https://payloadcms.com/docs/local-api/overview) APIs
39
28
  - [Easily customizable ReactJS Admin](https://payloadcms.com/docs/admin/overview)
40
29
  - [Fully self-hosted](https://payloadcms.com/docs/production/deployment)
41
30
  - [Extensible Authentication](https://payloadcms.com/docs/authentication/overview)
42
31
  - [Local file storage & upload](https://payloadcms.com/docs/upload/overview)
32
+ - [Version History and Drafts](https://payloadcms.com/docs/versions/overview)
43
33
  - [Field-based Localization](https://payloadcms.com/docs/configuration/localization)
44
34
  - [Block-based Layout Builder](https://payloadcms.com/docs/fields/blocks)
45
35
  - [Extensible SlateJS rich text editor](https://payloadcms.com/docs/fields/rich-text)
@@ -53,18 +43,14 @@ Check out the [Payload website](https://payloadcms.com/docs/getting-started/what
53
43
 
54
44
  ### Code-first
55
45
 
56
- If you know JavaScript, you know Payload. Payload is a _code-first_ CMS, which allows us to do a lot of things right:
46
+ Payload is a CMS that has been designed for developers from the ground up to deliver them what they need to build great digital products. If you know JavaScript, you know Payload. It's a _code-first_ CMS, which allows us to do a lot of things right:
57
47
 
58
48
  - Payload gives you everything you need, but then steps back and lets you build what you want in JavaScript or TypeScript - with no unnecessary complexity brought by GUIs. You'll understand how your CMS works, because you will have written it exactly how you want it.
59
49
  - Bring your own Express server and do whatever you need on top of Payload. Payload doesn't impose anything on you or your app.
60
50
  - Completely control the Admin panel by using your own React components. Swap out fields or even entire views with ease.
61
51
  - Use your data however and wherever you need thanks to auto-generated, yet fully extensible REST, GraphQL and Local Node APIs.
62
52
 
63
- ### Free forever for personal use and small projects
64
-
65
- Payload is 100% free for personal projects or small use cases where only one admin user is required. You can also get started without an account whatsoever while running on `localhost`.
66
-
67
- ## Installation
53
+ ### Quick Start
68
54
 
69
55
  Before beginning to work with Payload, make sure you have all of the [required software](https://payloadcms.com/docs/getting-started/installation).
70
56
 
@@ -74,8 +60,18 @@ From there, the easiest way to get started with Payload is to use the `create-pa
74
60
  npx create-payload-app
75
61
  ```
76
62
 
77
- Alternatively, it only takes about five minutes to [write out your own app from scratch](https://payloadcms.com/docs/getting-started/installation#from-scratch).
63
+ Alternatively, it only takes about five minutes to [create an app from scratch](https://payloadcms.com/docs/getting-started/installation#from-scratch).
64
+
65
+ ### Documentation
66
+
67
+ Check out the [Payload website](https://payloadcms.com/docs/getting-started/what-is-payload) to find in-depth documentation for everything that Payload offers.
68
+
69
+ ### Other Resources
70
+
71
+ ##### Discussions
72
+
73
+ There are lots of good conversations and resources in our [GitHub Discussions board](https://github.com/payloadcms/payload/discussions). If you're struggling with something, chances are, someone's already solved what you're up against. Searching Discussions will often provide very helpful tips and tricks.
78
74
 
79
- ## License
75
+ ##### Discord
80
76
 
81
- Find the Payload license [here](https://github.com/payloadcms/payload/blob/master/license.md).
77
+ Join [Payload's Discord channel](https://discord.com/invite/r6sCXqVk3v) to interact with Payload developers in realtime.
@@ -1,2 +1,5 @@
1
1
  export { default as Meta } from '../dist/admin/components/utilities/Meta';
2
2
  export { useLocale } from '../dist/admin/components/utilities/Locale';
3
+ export { useDocumentInfo } from '../dist/admin/components/utilities/DocumentInfo';
4
+ export { useConfig } from '../dist/admin/components/utilities/Config';
5
+ export { useAuth } from '../dist/admin/components/utilities/Auth';
@@ -1,12 +1,12 @@
1
1
  import React, { Suspense, lazy, useState, useEffect } from 'react';
2
2
  import { Route, Switch, withRouter, Redirect, } from 'react-router-dom';
3
- import { useConfig, useAuth } from '@payloadcms/config-provider';
3
+ import { useAuth } from './utilities/Auth';
4
+ import { useConfig } from './utilities/Config';
4
5
  import List from './views/collections/List';
5
6
  import DefaultTemplate from './templates/Default';
6
7
  import { requests } from '../api';
7
8
  import Loading from './elements/Loading';
8
9
  import StayLoggedIn from './modals/StayLoggedIn';
9
- import Unlicensed from './views/Unlicensed';
10
10
  import Versions from './views/Versions';
11
11
  import Version from './views/Version';
12
12
  import { DocumentInfoProvider } from './utilities/DocumentInfo';
@@ -21,7 +21,6 @@ const Edit = lazy(() => import('./views/collections/Edit'));
21
21
  const EditGlobal = lazy(() => import('./views/Global'));
22
22
  const ResetPassword = lazy(() => import('./views/ResetPassword'));
23
23
  const Unauthorized = lazy(() => import('./views/Unauthorized'));
24
- const UnauthorizedUser = lazy(() => import('./views/UnauthorizedUser'));
25
24
  const Account = lazy(() => import('./views/Account'));
26
25
  const Routes = () => {
27
26
  const [initialized, setInitialized] = useState(null);
@@ -61,10 +60,6 @@ const Routes = () => {
61
60
  React.createElement(ForgotPassword, null)),
62
61
  React.createElement(Route, { path: `${match.url}/reset/:token` },
63
62
  React.createElement(ResetPassword, null)),
64
- React.createElement(Route, { path: `${match.url}/unlicensed-domain` },
65
- React.createElement(Unlicensed, null)),
66
- React.createElement(Route, { path: `${match.url}/unauthorized-user` },
67
- React.createElement(UnauthorizedUser, null)),
68
63
  collections.map((collection) => {
69
64
  var _a;
70
65
  if ((_a = collection === null || collection === void 0 ? void 0 : collection.auth) === null || _a === void 0 ? void 0 : _a.verify) {
@@ -1,8 +1,8 @@
1
- import { useConfig } from '@payloadcms/config-provider';
2
1
  import { formatDistance } from 'date-fns';
3
2
  import { useHistory } from 'react-router-dom';
4
3
  import { toast } from 'react-toastify';
5
4
  import React, { useCallback, useEffect, useRef, useState } from 'react';
5
+ import { useConfig } from '../../utilities/Config';
6
6
  import { useWatchForm, useFormModified } from '../../forms/Form/context';
7
7
  import { useLocale } from '../../utilities/Locale';
8
8
  import reduceFieldsToValues from '../../forms/Form/reduceFieldsToValues';
@@ -2,7 +2,7 @@ import React, { useState, useCallback } from 'react';
2
2
  import { toast } from 'react-toastify';
3
3
  import { useHistory } from 'react-router-dom';
4
4
  import { Modal, useModal } from '@faceless-ui/modal';
5
- import { useConfig } from '@payloadcms/config-provider';
5
+ import { useConfig } from '../../utilities/Config';
6
6
  import Button from '../Button';
7
7
  import MinimalTemplate from '../../templates/Minimal';
8
8
  import { useForm } from '../../forms/Form/context';
@@ -1,6 +1,6 @@
1
1
  import React, { useCallback } from 'react';
2
2
  import { useHistory } from 'react-router-dom';
3
- import { useConfig } from '@payloadcms/config-provider';
3
+ import { useConfig } from '../../utilities/Config';
4
4
  import Button from '../Button';
5
5
  import { useForm } from '../../forms/Form/context';
6
6
  import './index.scss';
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { useConfig } from '@payloadcms/config-provider';
2
+ import { useConfig } from '../../../utilities/Config';
3
3
  import CopyToClipboard from '../../CopyToClipboard';
4
4
  import formatFilesize from '../../../../../uploads/formatFilesize';
5
5
  import './index.scss';
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { Link } from 'react-router-dom';
3
3
  import qs from 'qs';
4
- import { useConfig } from '@payloadcms/config-provider';
4
+ import { useConfig } from '../../utilities/Config';
5
5
  import { useLocale } from '../../utilities/Locale';
6
6
  import { useSearchParams } from '../../utilities/SearchParams';
7
7
  import Popup from '../Popup';
@@ -1,6 +1,7 @@
1
1
  import React, { useState, useEffect } from 'react';
2
2
  import { NavLink, Link, useHistory } from 'react-router-dom';
3
- import { useConfig, useAuth } from '@payloadcms/config-provider';
3
+ import { useConfig } from '../../utilities/Config';
4
+ import { useAuth } from '../../utilities/Auth';
4
5
  import RenderCustomComponent from '../../utilities/RenderCustomComponent';
5
6
  import Chevron from '../../icons/Chevron';
6
7
  import LogOut from '../../icons/LogOut';
@@ -1,5 +1,5 @@
1
1
  import React, { useEffect, useState } from 'react';
2
- import { useAuth } from '@payloadcms/config-provider';
2
+ import { useAuth } from '../../utilities/Auth';
3
3
  import Button from '../Button';
4
4
  import { useLocale } from '../../utilities/Locale';
5
5
  import './index.scss';
@@ -1,5 +1,5 @@
1
1
  import React, { useCallback } from 'react';
2
- import { useConfig } from '@payloadcms/config-provider';
2
+ import { useConfig } from '../../utilities/Config';
3
3
  import FormSubmit from '../../forms/Submit';
4
4
  import { useForm, useFormModified } from '../../forms/Form/context';
5
5
  import { useDocumentInfo } from '../../utilities/DocumentInfo';
@@ -1,7 +1,7 @@
1
1
  import React, { useCallback, useState } from 'react';
2
- import { useConfig } from '@payloadcms/config-provider';
3
2
  import { toast } from 'react-toastify';
4
3
  import { Modal, useModal } from '@faceless-ui/modal';
4
+ import { useConfig } from '../../utilities/Config';
5
5
  import { useDocumentInfo } from '../../utilities/DocumentInfo';
6
6
  import Button from '../Button';
7
7
  import { MinimalTemplate } from '../..';
@@ -1,5 +1,5 @@
1
- import { useConfig } from '@payloadcms/config-provider';
2
1
  import React from 'react';
2
+ import { useConfig } from '../../utilities/Config';
3
3
  import Button from '../Button';
4
4
  import { useDocumentInfo } from '../../utilities/DocumentInfo';
5
5
  import { shouldIncrementVersionCount } from '../../../../versions/shouldIncrementVersionCount';
@@ -1,5 +1,5 @@
1
1
  import React, { useReducer, useState, useCallback, useEffect } from 'react';
2
- import { useConfig } from '@payloadcms/config-provider';
2
+ import { useConfig } from '../../../../utilities/Config';
3
3
  import optionsReducer from './optionsReducer';
4
4
  import useDebounce from '../../../../../hooks/useDebounce';
5
5
  import ReactSelect from '../../../ReactSelect';
@@ -3,15 +3,16 @@ import Button from '../../../elements/Button';
3
3
  import './index.scss';
4
4
  const baseClass = 'position-panel';
5
5
  const PositionPanel = (props) => {
6
- const { moveRow, positionIndex, rowCount } = props;
6
+ const { moveRow, positionIndex, rowCount, readOnly } = props;
7
7
  const adjustedIndex = positionIndex + 1;
8
8
  const classes = [
9
9
  baseClass,
10
+ `${baseClass}__${readOnly ? 'read-only' : ''}`,
10
11
  ].filter(Boolean).join(' ');
11
12
  return (React.createElement("div", { className: classes },
12
- React.createElement(Button, { className: `${baseClass}__move-backward ${positionIndex === 0 ? 'first-row' : ''}`, buttonStyle: "none", icon: "chevron", round: true, onClick: () => moveRow(positionIndex, positionIndex - 1) }),
13
+ !readOnly && (React.createElement(Button, { className: `${baseClass}__move-backward ${positionIndex === 0 ? 'first-row' : ''}`, buttonStyle: "none", icon: "chevron", round: true, onClick: () => moveRow(positionIndex, positionIndex - 1) })),
13
14
  (adjustedIndex && typeof positionIndex === 'number')
14
- && React.createElement("div", { className: `${baseClass}__current-position` }, adjustedIndex >= 10 ? adjustedIndex : `0${adjustedIndex}`),
15
- React.createElement(Button, { className: `${baseClass}__move-forward ${(positionIndex === rowCount - 1) ? 'last-row' : ''}`, buttonStyle: "none", icon: "chevron", round: true, onClick: () => moveRow(positionIndex, positionIndex + 1) })));
15
+ && (React.createElement("div", { className: `${baseClass}__current-position` }, adjustedIndex >= 10 ? adjustedIndex : `0${adjustedIndex}`)),
16
+ !readOnly && (React.createElement(Button, { className: `${baseClass}__move-forward ${(positionIndex === rowCount - 1) ? 'last-row' : ''}`, buttonStyle: "none", icon: "chevron", round: true, onClick: () => moveRow(positionIndex, positionIndex + 1) }))));
16
17
  };
17
18
  export default PositionPanel;
@@ -2,4 +2,5 @@ export declare type Props = {
2
2
  moveRow: (fromIndex: number, toIndex: number) => void;
3
3
  positionIndex: number;
4
4
  rowCount: number;
5
+ readOnly: boolean;
5
6
  };
@@ -23,7 +23,7 @@ const DraggableSection = (props) => {
23
23
  return (React.createElement(Draggable, { draggableId: id, index: rowIndex, isDragDisabled: readOnly }, (providedDrag) => (React.createElement("div", { ref: providedDrag.innerRef, className: classes, onMouseLeave: () => setIsHovered(false), onMouseOver: () => setIsHovered(true), onFocus: () => setIsHovered(true), ...providedDrag.draggableProps },
24
24
  React.createElement("div", { className: `${baseClass}__content-wrapper` },
25
25
  React.createElement(FieldTypeGutter, { variant: "left", dragHandleProps: providedDrag.dragHandleProps },
26
- React.createElement(PositionPanel, { moveRow: moveRow, rowCount: rowCount, positionIndex: rowIndex })),
26
+ React.createElement(PositionPanel, { moveRow: moveRow, rowCount: rowCount, positionIndex: rowIndex, readOnly: readOnly })),
27
27
  React.createElement("div", { className: `${baseClass}__render-fields-wrapper` },
28
28
  blockType === 'blocks' && (React.createElement("div", { className: `${baseClass}__section-header` },
29
29
  React.createElement(HiddenInput, { name: `${parentPath}.${rowIndex}.id`, value: id }),
@@ -4,7 +4,7 @@ import isDeepEqual from 'deep-equal';
4
4
  import { serialize } from 'object-to-formdata';
5
5
  import { useHistory } from 'react-router-dom';
6
6
  import { toast } from 'react-toastify';
7
- import { useAuth } from '@payloadcms/config-provider';
7
+ import { useAuth } from '../../utilities/Auth';
8
8
  import { useLocale } from '../../utilities/Locale';
9
9
  import { useDocumentInfo } from '../../utilities/DocumentInfo';
10
10
  import { requests } from '../../../api';
@@ -1,6 +1,6 @@
1
1
  import React, { useCallback, useEffect, useReducer, useState } from 'react';
2
2
  import { DragDropContext, Droppable } from 'react-beautiful-dnd';
3
- import { useAuth } from '@payloadcms/config-provider';
3
+ import { useAuth } from '../../../utilities/Auth';
4
4
  import withCondition from '../../withCondition';
5
5
  import Button from '../../../elements/Button';
6
6
  import DraggableSection from '../../DraggableSection';
@@ -1,6 +1,6 @@
1
1
  import React, { useCallback, useEffect, useReducer, useState } from 'react';
2
2
  import { DragDropContext, Droppable } from 'react-beautiful-dnd';
3
- import { useAuth } from '@payloadcms/config-provider';
3
+ import { useAuth } from '../../../utilities/Auth';
4
4
  import { usePreferences } from '../../../utilities/Preferences';
5
5
  import { useLocale } from '../../../utilities/Locale';
6
6
  import withCondition from '../../withCondition';
@@ -1,7 +1,8 @@
1
1
  import React, { useCallback, useEffect, useState, useReducer, } from 'react';
2
2
  import equal from 'deep-equal';
3
- import { useAuth, useConfig } from '@payloadcms/config-provider';
4
3
  import qs from 'qs';
4
+ import { useConfig } from '../../../utilities/Config';
5
+ import { useAuth } from '../../../utilities/Auth';
5
6
  import withCondition from '../../withCondition';
6
7
  import ReactSelect from '../../../elements/ReactSelect';
7
8
  import useField from '../../useField';
@@ -1,5 +1,6 @@
1
1
  import React, { Fragment, useState, useEffect } from 'react';
2
- import { useConfig, useAuth } from '@payloadcms/config-provider';
2
+ import { useConfig } from '../../../../../../../utilities/Config';
3
+ import { useAuth } from '../../../../../../../utilities/Auth';
3
4
  import { useWatchForm } from '../../../../../../Form/context';
4
5
  import Relationship from '../../../../../Relationship';
5
6
  import Select from '../../../../../Select';
@@ -2,7 +2,7 @@ import React, { Fragment, useCallback, useEffect, useState } from 'react';
2
2
  import { Modal, useModal } from '@faceless-ui/modal';
3
3
  import { Transforms } from 'slate';
4
4
  import { ReactEditor, useSlate } from 'slate-react';
5
- import { useConfig } from '@payloadcms/config-provider';
5
+ import { useConfig } from '../../../../../../utilities/Config';
6
6
  import ElementButton from '../../Button';
7
7
  import RelationshipIcon from '../../../../../../icons/Relationship';
8
8
  import Form from '../../../../../Form';
@@ -1,6 +1,6 @@
1
1
  import React, { useState } from 'react';
2
2
  import { useFocused, useSelected } from 'slate-react';
3
- import { useConfig } from '@payloadcms/config-provider';
3
+ import { useConfig } from '../../../../../../utilities/Config';
4
4
  import RelationshipIcon from '../../../../../../icons/Relationship';
5
5
  import usePayloadAPI from '../../../../../../../hooks/usePayloadAPI';
6
6
  import './index.scss';
@@ -2,7 +2,7 @@ import React, { Fragment, useEffect, useState } from 'react';
2
2
  import { Modal, useModal } from '@faceless-ui/modal';
3
3
  import { Transforms } from 'slate';
4
4
  import { ReactEditor, useSlate } from 'slate-react';
5
- import { useConfig } from '@payloadcms/config-provider';
5
+ import { useConfig } from '../../../../../../utilities/Config';
6
6
  import ElementButton from '../../Button';
7
7
  import UploadIcon from '../../../../../../icons/Upload';
8
8
  import usePayloadAPI from '../../../../../../../hooks/usePayloadAPI';
@@ -2,7 +2,7 @@ import React, { useCallback, useEffect, useState } from 'react';
2
2
  import { Transforms } from 'slate';
3
3
  import { ReactEditor, useSlateStatic } from 'slate-react';
4
4
  import { Modal } from '@faceless-ui/modal';
5
- import { useAuth } from '@payloadcms/config-provider';
5
+ import { useAuth } from '../../../../../../../utilities/Auth';
6
6
  import buildStateFromSchema from '../../../../../../Form/buildStateFromSchema';
7
7
  import MinimalTemplate from '../../../../../../../templates/Minimal';
8
8
  import Button from '../../../../../../../elements/Button';
@@ -1,8 +1,8 @@
1
1
  import * as React from 'react';
2
2
  import { Modal } from '@faceless-ui/modal';
3
- import { useConfig } from '@payloadcms/config-provider';
4
3
  import { Transforms } from 'slate';
5
4
  import { ReactEditor, useSlateStatic } from 'slate-react';
5
+ import { useConfig } from '../../../../../../../utilities/Config';
6
6
  import usePayloadAPI from '../../../../../../../../hooks/usePayloadAPI';
7
7
  import MinimalTemplate from '../../../../../../../templates/Minimal';
8
8
  import Button from '../../../../../../../elements/Button';
@@ -2,7 +2,7 @@ import React, { useState, useEffect, useCallback } from 'react';
2
2
  import { useModal } from '@faceless-ui/modal';
3
3
  import { Transforms } from 'slate';
4
4
  import { ReactEditor, useSlateStatic, useFocused, useSelected } from 'slate-react';
5
- import { useConfig } from '@payloadcms/config-provider';
5
+ import { useConfig } from '../../../../../../utilities/Config';
6
6
  import usePayloadAPI from '../../../../../../../hooks/usePayloadAPI';
7
7
  import FileGraphic from '../../../../../../graphics/File';
8
8
  import useThumbnail from '../../../../../../../hooks/useThumbnail';
@@ -1,6 +1,7 @@
1
1
  import React, { useCallback } from 'react';
2
2
  import { Modal, useModal } from '@faceless-ui/modal';
3
- import { useConfig, useAuth } from '@payloadcms/config-provider';
3
+ import { useConfig } from '../../../../utilities/Config';
4
+ import { useAuth } from '../../../../utilities/Auth';
4
5
  import MinimalTemplate from '../../../../templates/Minimal';
5
6
  import Form from '../../../Form';
6
7
  import Button from '../../../../elements/Button';
@@ -1,7 +1,8 @@
1
1
  import React, { Fragment, useState, useEffect } from 'react';
2
2
  import equal from 'deep-equal';
3
3
  import { Modal, useModal } from '@faceless-ui/modal';
4
- import { useAuth, useConfig } from '@payloadcms/config-provider';
4
+ import { useConfig } from '../../../../utilities/Config';
5
+ import { useAuth } from '../../../../utilities/Auth';
5
6
  import MinimalTemplate from '../../../../templates/Minimal';
6
7
  import Button from '../../../../elements/Button';
7
8
  import usePayloadAPI from '../../../../../hooks/usePayloadAPI';
@@ -1,5 +1,5 @@
1
1
  import React, { useCallback } from 'react';
2
- import { useConfig } from '@payloadcms/config-provider';
2
+ import { useConfig } from '../../../utilities/Config';
3
3
  import useField from '../../useField';
4
4
  import withCondition from '../../withCondition';
5
5
  import { upload } from '../../../../../fields/validations';
@@ -1,5 +1,5 @@
1
1
  import { useCallback, useEffect, useState, } from 'react';
2
- import { useAuth } from '@payloadcms/config-provider';
2
+ import { useAuth } from '../../utilities/Auth';
3
3
  import { useFormProcessing, useFormSubmitted, useFormModified, useForm } from '../Form/context';
4
4
  import useDebounce from '../../../hooks/useDebounce';
5
5
  import { useDocumentInfo } from '../../utilities/DocumentInfo';
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { useConfig } from '@payloadcms/config-provider';
2
+ import { useConfig } from '../../utilities/Config';
3
3
  import RenderCustomComponent from '../../utilities/RenderCustomComponent';
4
4
  const PayloadIcon = () => (React.createElement("svg", { width: "25", height: "25", viewBox: "0 0 25 25", xmlns: "http://www.w3.org/2000/svg" },
5
5
  React.createElement("path", { d: "M11.5293 0L23 6.90096V19.9978L14.3608 25V11.9032L2.88452 5.00777L11.5293 0Z", fill: "#333333" }),
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { useConfig } from '@payloadcms/config-provider';
2
+ import { useConfig } from '../../utilities/Config';
3
3
  import RenderCustomComponent from '../../utilities/RenderCustomComponent';
4
4
  const PayloadLogo = () => (React.createElement("svg", { width: "180", height: "50", viewBox: "0 0 180 50", fill: "none", xmlns: "http://www.w3.org/2000/svg", className: "logo" },
5
5
  React.createElement("path", { d: "M65.922 13.8685C71.1075 13.8685 77.0257 14.6014 77.0257 22.2185C77.0257 28.6587 71.8736 30.2243 66.0664 30.2243H62.2689V39.0961H57.2944V13.8685H65.922ZM62.2689 17.7659V26.3602H66.3773C69.4752 26.3602 71.9069 25.594 71.9069 22.2518C71.9069 18.1101 68.7424 17.7659 66.022 17.7659H62.2689Z", fill: "#333333" }),
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import NavigationPrompt from 'react-router-navigation-prompt';
3
- import { useAuth } from '@payloadcms/config-provider';
3
+ import { useAuth } from '../../utilities/Auth';
4
4
  import { useFormModified } from '../../forms/Form/context';
5
5
  import MinimalTemplate from '../../templates/Minimal';
6
6
  import Button from '../../elements/Button';
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { useHistory } from 'react-router-dom';
3
3
  import { useModal, Modal } from '@faceless-ui/modal';
4
- import { useConfig } from '@payloadcms/config-provider';
4
+ import { useConfig } from '../../utilities/Config';
5
5
  import MinimalTemplate from '../../templates/Minimal';
6
6
  import Button from '../../elements/Button';
7
7
  import './index.scss';
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { useConfig } from '@payloadcms/config-provider';
2
+ import { useConfig } from '../../utilities/Config';
3
3
  import DefaultNav from '../../elements/Nav';
4
4
  import RenderCustomComponent from '../../utilities/RenderCustomComponent';
5
5
  import Meta from '../../utilities/Meta';
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ import { AuthContext } from './types';
3
+ export declare const AuthProvider: React.FC<{
4
+ children: React.ReactNode;
5
+ }>;
6
+ export declare const useAuth: () => AuthContext;
@@ -0,0 +1,124 @@
1
+ import React, { useState, createContext, useContext, useEffect, useCallback, } from 'react';
2
+ import jwtDecode from 'jwt-decode';
3
+ import { useLocation, useHistory } from 'react-router-dom';
4
+ import { useModal } from '@faceless-ui/modal';
5
+ import { useConfig } from '../Config';
6
+ import { requests } from '../../../api';
7
+ import useDebounce from '../../../hooks/useDebounce';
8
+ const Context = createContext({});
9
+ export const AuthProvider = ({ children }) => {
10
+ const [user, setUser] = useState();
11
+ const [tokenInMemory, setTokenInMemory] = useState();
12
+ const { pathname } = useLocation();
13
+ const { push } = useHistory();
14
+ const config = useConfig();
15
+ const { admin: { user: userSlug, }, serverURL, routes: { admin, api, }, } = config;
16
+ const exp = user === null || user === void 0 ? void 0 : user.exp;
17
+ const [permissions, setPermissions] = useState();
18
+ const { open: openModal, closeAll: closeAllModals } = useModal();
19
+ const [lastLocationChange, setLastLocationChange] = useState(0);
20
+ const debouncedLocationChange = useDebounce(lastLocationChange, 10000);
21
+ const email = user === null || user === void 0 ? void 0 : user.email;
22
+ const refreshCookie = useCallback(() => {
23
+ const now = Math.round((new Date()).getTime() / 1000);
24
+ const remainingTime = (exp || 0) - now;
25
+ if (exp && remainingTime < 120) {
26
+ setTimeout(async () => {
27
+ const request = await requests.post(`${serverURL}${api}/${userSlug}/refresh-token`);
28
+ if (request.status === 200) {
29
+ const json = await request.json();
30
+ setUser(json.user);
31
+ }
32
+ else {
33
+ setUser(null);
34
+ push(`${admin}/logout-inactivity`);
35
+ }
36
+ }, 1000);
37
+ }
38
+ }, [setUser, push, exp, admin, api, serverURL, userSlug]);
39
+ const setToken = useCallback((token) => {
40
+ const decoded = jwtDecode(token);
41
+ setUser(decoded);
42
+ setTokenInMemory(token);
43
+ }, []);
44
+ const logOut = () => {
45
+ setUser(null);
46
+ setTokenInMemory(undefined);
47
+ requests.post(`${serverURL}${api}/${userSlug}/logout`);
48
+ };
49
+ // On mount, get user and set
50
+ useEffect(() => {
51
+ const fetchMe = async () => {
52
+ const request = await requests.get(`${serverURL}${api}/${userSlug}/me`);
53
+ if (request.status === 200) {
54
+ const json = await request.json();
55
+ setUser((json === null || json === void 0 ? void 0 : json.user) || null);
56
+ if (json === null || json === void 0 ? void 0 : json.token) {
57
+ setToken(json.token);
58
+ }
59
+ }
60
+ };
61
+ fetchMe();
62
+ }, [setToken, api, serverURL, userSlug]);
63
+ // When location changes, refresh cookie
64
+ useEffect(() => {
65
+ if (email) {
66
+ refreshCookie();
67
+ }
68
+ }, [debouncedLocationChange, refreshCookie, email]);
69
+ useEffect(() => {
70
+ setLastLocationChange(Date.now());
71
+ }, [pathname]);
72
+ // When user changes, get new access
73
+ useEffect(() => {
74
+ async function getPermissions() {
75
+ const request = await requests.get(`${serverURL}${api}/access`);
76
+ if (request.status === 200) {
77
+ const json = await request.json();
78
+ setPermissions(json);
79
+ }
80
+ }
81
+ if (email) {
82
+ getPermissions();
83
+ }
84
+ }, [email, api, serverURL]);
85
+ useEffect(() => {
86
+ let reminder;
87
+ const now = Math.round((new Date()).getTime() / 1000);
88
+ const remainingTime = exp - now;
89
+ if (remainingTime > 0) {
90
+ reminder = setTimeout(() => {
91
+ openModal('stay-logged-in');
92
+ }, ((remainingTime - 60) * 1000));
93
+ }
94
+ return () => {
95
+ if (reminder)
96
+ clearTimeout(reminder);
97
+ };
98
+ }, [exp, openModal]);
99
+ useEffect(() => {
100
+ let forceLogOut;
101
+ const now = Math.round((new Date()).getTime() / 1000);
102
+ const remainingTime = exp - now;
103
+ if (remainingTime > 0) {
104
+ forceLogOut = setTimeout(() => {
105
+ setUser(null);
106
+ push(`${admin}/logout-inactivity`);
107
+ closeAllModals();
108
+ }, remainingTime * 1000);
109
+ }
110
+ return () => {
111
+ if (forceLogOut)
112
+ clearTimeout(forceLogOut);
113
+ };
114
+ }, [exp, push, closeAllModals, admin]);
115
+ return (React.createElement(Context.Provider, { value: {
116
+ user,
117
+ logOut,
118
+ refreshCookie,
119
+ permissions,
120
+ setToken,
121
+ token: tokenInMemory,
122
+ } }, children));
123
+ };
124
+ export const useAuth = () => useContext(Context);
@@ -0,0 +1,9 @@
1
+ import { User, Permissions } from '../../../../auth/types';
2
+ export declare type AuthContext = {
3
+ user?: User | null;
4
+ logOut: () => void;
5
+ refreshCookie: () => void;
6
+ setToken: (token: string) => void;
7
+ token?: string;
8
+ permissions?: Permissions;
9
+ };
@@ -0,0 +1 @@
1
+ export {};