@ainsleydev/payload-helper 0.0.2 → 0.0.3
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.
- package/package.json +5 -4
- package/src/collections/Media.ts +27 -22
- package/src/collections/Redirects.ts +40 -42
- package/src/common/SEO.ts +1 -1
- package/src/endpoints/slug.ts +8 -6
- package/src/globals/Navigation.ts +4 -4
- package/src/globals/Settings.ts +6 -6
- package/src/util/validation.ts +2 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ainsleydev/payload-helper",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Payload CMS utilities, collections and global types for ainsley.dev builds",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -20,14 +20,15 @@
|
|
|
20
20
|
"url": "https://ainsley.dev"
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
23
|
-
"
|
|
23
|
+
"release": "npm publish --access public",
|
|
24
24
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@nouance/payload-better-fields-plugin": "^1.4.1",
|
|
28
|
-
"@payloadcms/richtext-slate": "
|
|
28
|
+
"@payloadcms/richtext-slate": "beta",
|
|
29
|
+
"@payloadcms/richtext-lexical": "beta",
|
|
29
30
|
"json-schema": "^0.4.0",
|
|
30
|
-
"payload": "
|
|
31
|
+
"payload": "beta",
|
|
31
32
|
"pluralize": "^8.0.0"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
package/src/collections/Media.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
1
|
+
import type { CollectionConfig, Field } from 'payload';
|
|
2
|
+
import { lexicalEditor } from '@payloadcms/richtext-lexical';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Media Collection Configuration
|
|
@@ -9,12 +9,34 @@ import type { CollectionConfig, Field } from 'payload/types';
|
|
|
9
9
|
* @param additionalFields
|
|
10
10
|
* @constructor
|
|
11
11
|
*/
|
|
12
|
-
export const Media = (
|
|
12
|
+
export const Media = (additionalFields?: Field[]): CollectionConfig => {
|
|
13
13
|
return {
|
|
14
14
|
slug: 'media',
|
|
15
|
+
access: {
|
|
16
|
+
read: () => true,
|
|
17
|
+
},
|
|
18
|
+
fields: [
|
|
19
|
+
{
|
|
20
|
+
name: 'alt',
|
|
21
|
+
type: 'text',
|
|
22
|
+
required: true,
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: 'caption',
|
|
26
|
+
type: 'richText',
|
|
27
|
+
required: false,
|
|
28
|
+
editor: lexicalEditor({
|
|
29
|
+
features: ({ defaultFeatures }) => {
|
|
30
|
+
return defaultFeatures.filter((feature) => {
|
|
31
|
+
return feature.key === 'paragraph' || feature.key === 'link';
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
}),
|
|
35
|
+
},
|
|
36
|
+
...(additionalFields ? additionalFields : []),
|
|
37
|
+
],
|
|
15
38
|
upload: {
|
|
16
|
-
|
|
17
|
-
staticDir: filePath,
|
|
39
|
+
staticDir: 'media',
|
|
18
40
|
imageSizes: [
|
|
19
41
|
// Original Size (for WebP & Avif)
|
|
20
42
|
{
|
|
@@ -128,22 +150,5 @@ export const Media = (filePath: string, additionalFields?: Field[]): CollectionC
|
|
|
128
150
|
},
|
|
129
151
|
],
|
|
130
152
|
},
|
|
131
|
-
fields: [
|
|
132
|
-
{
|
|
133
|
-
name: 'alt',
|
|
134
|
-
type: 'text',
|
|
135
|
-
required: true,
|
|
136
|
-
},
|
|
137
|
-
{
|
|
138
|
-
name: 'caption',
|
|
139
|
-
type: 'richText',
|
|
140
|
-
// editor: slateEditor({
|
|
141
|
-
// admin: {
|
|
142
|
-
// elements: ['link'],
|
|
143
|
-
// },
|
|
144
|
-
// }),
|
|
145
|
-
},
|
|
146
|
-
...(additionalFields ? additionalFields : []),
|
|
147
|
-
],
|
|
148
153
|
};
|
|
149
154
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CollectionConfig } from 'payload
|
|
1
|
+
import type { CollectionConfig } from 'payload';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Redirects Collection Configuration
|
|
@@ -10,49 +10,47 @@ import type { CollectionConfig } from 'payload/types';
|
|
|
10
10
|
*/
|
|
11
11
|
export const Redirects = (overrides?: Partial<CollectionConfig>): CollectionConfig => {
|
|
12
12
|
return {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
description: 'The URL you want to redirect from, ensure it starts with a /',
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
name: 'to',
|
|
31
|
-
type: 'text',
|
|
32
|
-
label: 'Destination URL',
|
|
33
|
-
required: true,
|
|
34
|
-
admin: {
|
|
35
|
-
description:
|
|
36
|
-
'The URL you want to redirect to, can be a relative or absolute URL',
|
|
37
|
-
},
|
|
13
|
+
slug: 'redirects',
|
|
14
|
+
admin: {
|
|
15
|
+
useAsTitle: 'from',
|
|
16
|
+
},
|
|
17
|
+
fields: [
|
|
18
|
+
{
|
|
19
|
+
name: 'from',
|
|
20
|
+
type: 'text',
|
|
21
|
+
label: 'From URL',
|
|
22
|
+
required: true,
|
|
23
|
+
index: true,
|
|
24
|
+
admin: {
|
|
25
|
+
description: 'The URL you want to redirect from, ensure it starts with a /',
|
|
38
26
|
},
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
{ label: '307 - Temporary Redirect', value: '307' },
|
|
49
|
-
{ label: '308 - Permanent Redirect', value: '308' },
|
|
50
|
-
{ label: '410 - Content Deleted', value: '410' },
|
|
51
|
-
{ label: '451 - Unavailable For Legal Reasons', value: '451' },
|
|
52
|
-
],
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: 'to',
|
|
30
|
+
type: 'text',
|
|
31
|
+
label: 'Destination URL',
|
|
32
|
+
required: true,
|
|
33
|
+
admin: {
|
|
34
|
+
description:
|
|
35
|
+
'The URL you want to redirect to, can be a relative or absolute URL',
|
|
53
36
|
},
|
|
54
|
-
|
|
55
|
-
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: 'code',
|
|
40
|
+
type: 'select',
|
|
41
|
+
label: 'Redirect Code',
|
|
42
|
+
required: true,
|
|
43
|
+
defaultValue: '301',
|
|
44
|
+
options: [
|
|
45
|
+
{ label: '301 - Permanent', value: '301' },
|
|
46
|
+
{ label: '302 - Temporary', value: '302' },
|
|
47
|
+
{ label: '307 - Temporary Redirect', value: '307' },
|
|
48
|
+
{ label: '308 - Permanent Redirect', value: '308' },
|
|
49
|
+
{ label: '410 - Content Deleted', value: '410' },
|
|
50
|
+
{ label: '451 - Unavailable For Legal Reasons', value: '451' },
|
|
51
|
+
],
|
|
52
|
+
},
|
|
53
|
+
],
|
|
56
54
|
...(overrides ? overrides : {}),
|
|
57
55
|
};
|
|
58
56
|
};
|
package/src/common/SEO.ts
CHANGED
package/src/endpoints/slug.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PayloadHandler } from 'payload
|
|
1
|
+
import { PayloadHandler, PayloadRequest } from 'payload';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Find a document in the given collection by its slug.
|
|
@@ -6,25 +6,27 @@ import { PayloadHandler } from 'payload/config';
|
|
|
6
6
|
* @param collection
|
|
7
7
|
*/
|
|
8
8
|
export const findBySlug = (collection: string): PayloadHandler => {
|
|
9
|
-
return async (req
|
|
9
|
+
return async (req: PayloadRequest): Promise<Response> => {
|
|
10
10
|
try {
|
|
11
11
|
const data = await req.payload.find({
|
|
12
12
|
collection,
|
|
13
13
|
where: {
|
|
14
14
|
slug: {
|
|
15
|
-
equals: req.
|
|
15
|
+
equals: req.routeParams.slug,
|
|
16
16
|
},
|
|
17
17
|
},
|
|
18
18
|
limit: 1,
|
|
19
19
|
});
|
|
20
20
|
if (data.docs.length === 0) {
|
|
21
|
-
|
|
21
|
+
return new Response(JSON.stringify({ error: 'not found' }), { status: 404 });
|
|
22
22
|
} else {
|
|
23
|
-
|
|
23
|
+
return new Response(JSON.stringify(data.docs[0]), { status: 200 });
|
|
24
24
|
}
|
|
25
25
|
} catch (error) {
|
|
26
26
|
console.error('Error occurred while fetching document:', error);
|
|
27
|
-
|
|
27
|
+
return new Response(JSON.stringify({ error: 'Internal server error' }), {
|
|
28
|
+
status: 500,
|
|
29
|
+
});
|
|
28
30
|
}
|
|
29
31
|
};
|
|
30
32
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { GlobalConfig, Tab, Field, ArrayField } from 'payload';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Navigation Configuration for the header and footer
|
|
@@ -111,7 +111,7 @@ export const Navigation = (config?: NavigationConfig): GlobalConfig => {
|
|
|
111
111
|
],
|
|
112
112
|
},
|
|
113
113
|
],
|
|
114
|
-
},
|
|
114
|
+
} as ArrayField,
|
|
115
115
|
];
|
|
116
116
|
|
|
117
117
|
if (config?.includeFooter) {
|
|
@@ -141,7 +141,7 @@ export const Navigation = (config?: NavigationConfig): GlobalConfig => {
|
|
|
141
141
|
],
|
|
142
142
|
},
|
|
143
143
|
],
|
|
144
|
-
});
|
|
144
|
+
} as ArrayField);
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
return {
|
|
@@ -158,7 +158,7 @@ export const Navigation = (config?: NavigationConfig): GlobalConfig => {
|
|
|
158
158
|
fields: [
|
|
159
159
|
{
|
|
160
160
|
type: 'tabs',
|
|
161
|
-
tabs: [...tabs, ...(config
|
|
161
|
+
tabs: [...tabs, ...(config?.additionalTabs ? config.additionalTabs : [])],
|
|
162
162
|
},
|
|
163
163
|
],
|
|
164
164
|
};
|
package/src/globals/Settings.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { GlobalConfig, Tab } from 'payload
|
|
1
|
+
import type { GlobalConfig, GroupField, Tab, UploadField } from 'payload';
|
|
2
2
|
import { validatePostcode, validateURL } from '../util/validation';
|
|
3
3
|
import { languages } from './locales';
|
|
4
4
|
import { countries } from './countries';
|
|
@@ -10,7 +10,7 @@ import { countries } from './countries';
|
|
|
10
10
|
* @param additionalTabs
|
|
11
11
|
* @constructor
|
|
12
12
|
*/
|
|
13
|
-
export const Settings = (additionalTabs
|
|
13
|
+
export const Settings = (additionalTabs: Tab[]): GlobalConfig => {
|
|
14
14
|
return {
|
|
15
15
|
slug: 'settings',
|
|
16
16
|
typescript: {
|
|
@@ -83,7 +83,7 @@ export const Settings = (additionalTabs?: Tab[]): GlobalConfig => {
|
|
|
83
83
|
description:
|
|
84
84
|
'Add a logo for the website that will be displayed in the header & across the website.',
|
|
85
85
|
},
|
|
86
|
-
},
|
|
86
|
+
} as UploadField,
|
|
87
87
|
{
|
|
88
88
|
name: 'robots',
|
|
89
89
|
type: 'textarea',
|
|
@@ -164,7 +164,7 @@ export const Settings = (additionalTabs?: Tab[]): GlobalConfig => {
|
|
|
164
164
|
],
|
|
165
165
|
},
|
|
166
166
|
],
|
|
167
|
-
},
|
|
167
|
+
} as GroupField,
|
|
168
168
|
{
|
|
169
169
|
type: 'group',
|
|
170
170
|
name: 'address',
|
|
@@ -236,7 +236,7 @@ export const Settings = (additionalTabs?: Tab[]): GlobalConfig => {
|
|
|
236
236
|
],
|
|
237
237
|
},
|
|
238
238
|
],
|
|
239
|
-
},
|
|
239
|
+
} as GroupField,
|
|
240
240
|
{
|
|
241
241
|
type: 'group',
|
|
242
242
|
name: 'social',
|
|
@@ -307,7 +307,7 @@ export const Settings = (additionalTabs?: Tab[]): GlobalConfig => {
|
|
|
307
307
|
],
|
|
308
308
|
},
|
|
309
309
|
],
|
|
310
|
-
},
|
|
310
|
+
} as GroupField,
|
|
311
311
|
],
|
|
312
312
|
},
|
|
313
313
|
{
|
package/src/util/validation.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export const validateURL: Validate<string> = async (value) => {
|
|
1
|
+
export const validateURL = async (value) => {
|
|
4
2
|
if (!value) {
|
|
5
3
|
return true;
|
|
6
4
|
}
|
|
@@ -12,7 +10,7 @@ export const validateURL: Validate<string> = async (value) => {
|
|
|
12
10
|
}
|
|
13
11
|
};
|
|
14
12
|
|
|
15
|
-
export const validatePostcode
|
|
13
|
+
export const validatePostcode = async (value) => {
|
|
16
14
|
if (!value) {
|
|
17
15
|
return true;
|
|
18
16
|
}
|