@ainsleydev/payload-helper 0.0.3 → 0.0.4
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/bin.js +7 -0
- package/dist/cli/bin.d.ts +2 -0
- package/dist/cli/bin.js +17 -0
- package/dist/cli/bin.js.map +1 -0
- package/dist/cli/types.d.ts +4 -0
- package/dist/cli/types.js +35 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/collections/Media.js +156 -0
- package/dist/collections/Media.js.map +1 -0
- package/dist/collections/Redirects.js +72 -0
- package/dist/collections/Redirects.js.map +1 -0
- package/dist/common/SEO.js +45 -0
- package/dist/common/SEO.js.map +1 -0
- package/dist/endpoints/slug.js +39 -0
- package/dist/endpoints/slug.js.map +1 -0
- package/dist/globals/Navigation.js +138 -0
- package/dist/globals/Navigation.js.map +1 -0
- package/dist/globals/Settings.js +346 -0
- package/dist/globals/Settings.js.map +1 -0
- package/dist/globals/countries.js +198 -0
- package/dist/globals/countries.js.map +1 -0
- package/dist/globals/locales.js +2664 -0
- package/dist/globals/locales.js.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin/schema.js +239 -0
- package/dist/plugin/schema.js.map +1 -0
- package/dist/util/env.js +75 -0
- package/dist/util/env.js.map +1 -0
- package/dist/util/fields.js +12 -0
- package/dist/util/fields.js.map +1 -0
- package/dist/util/validation.js +23 -0
- package/dist/util/validation.js.map +1 -0
- package/package.json +42 -10
- package/eslint.config.mjs +0 -4
- package/src/collections/Media.ts +0 -154
- package/src/collections/Redirects.ts +0 -56
- package/src/common/SEO.ts +0 -45
- package/src/endpoints/slug.ts +0 -32
- package/src/gen/schema.ts +0 -584
- package/src/globals/Navigation.ts +0 -165
- package/src/globals/Settings.ts +0 -356
- package/src/globals/countries.ts +0 -196
- package/src/globals/locales.ts +0 -2668
- package/src/scripts/.gitkeep +0 -0
- package/src/seed/.gitkeep +0 -0
- package/src/util/env.ts +0 -96
- package/src/util/validation.ts +0 -22
- package/tsconfig.json +0 -19
package/package.json
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ainsleydev/payload-helper",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Payload CMS utilities, collections and global types for ainsley.dev builds",
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
6
7
|
"keywords": [
|
|
7
8
|
"payload",
|
|
8
|
-
"payloadcms",
|
|
9
9
|
"cms",
|
|
10
|
-
"
|
|
10
|
+
"plugin",
|
|
11
|
+
"typescript",
|
|
12
|
+
"react"
|
|
11
13
|
],
|
|
12
14
|
"repository": {
|
|
13
15
|
"type": "git",
|
|
@@ -19,20 +21,50 @@
|
|
|
19
21
|
"email": "hello@ainsley.dev",
|
|
20
22
|
"url": "https://ainsley.dev"
|
|
21
23
|
},
|
|
24
|
+
"main": "./src/index.ts",
|
|
25
|
+
"types": "./src/index.ts",
|
|
22
26
|
"scripts": {
|
|
27
|
+
"build": "pnpm run clean && pnpm build:types && pnpm build:swc",
|
|
28
|
+
"build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths",
|
|
29
|
+
"build:types": "tsc --emitDeclarationOnly --outDir dist",
|
|
30
|
+
"format": "biome format --write .",
|
|
31
|
+
"lint": "biome lint --write .",
|
|
23
32
|
"release": "npm publish --access public",
|
|
24
|
-
"
|
|
33
|
+
"clean": "rimraf {dist,*.tsbuildinfo}",
|
|
34
|
+
"test": "jest"
|
|
25
35
|
},
|
|
36
|
+
"bin": {
|
|
37
|
+
"payload-helper": "bin.js"
|
|
38
|
+
},
|
|
39
|
+
"files": [
|
|
40
|
+
"dist",
|
|
41
|
+
"bin.js"
|
|
42
|
+
],
|
|
26
43
|
"dependencies": {
|
|
44
|
+
"@lexical/headless": "^0.16.1",
|
|
45
|
+
"@lexical/html": "^0.16.1",
|
|
27
46
|
"@nouance/payload-better-fields-plugin": "^1.4.1",
|
|
28
|
-
"@payloadcms/richtext-
|
|
29
|
-
"@
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
47
|
+
"@payloadcms/richtext-lexical": "3.0.0-beta.67",
|
|
48
|
+
"@types/json-schema": "^7.0.15",
|
|
49
|
+
"chalk": "^5.3.0",
|
|
50
|
+
"commander": "^12.1.0",
|
|
51
|
+
"jsdom": "^24.1.1",
|
|
52
|
+
"lexical": "^0.16.1",
|
|
53
|
+
"payload": "3.0.0-beta.67"
|
|
33
54
|
},
|
|
34
55
|
"devDependencies": {
|
|
35
|
-
"@ainsleydev/eslint-config": "workspace:*"
|
|
56
|
+
"@ainsleydev/eslint-config": "workspace:*",
|
|
57
|
+
"@jest/globals": "^29.7.0",
|
|
58
|
+
"@swc/cli": "^0.4.0",
|
|
59
|
+
"@swc/core": "^1.7.2",
|
|
60
|
+
"@types/jest": "^29.5.12",
|
|
61
|
+
"@types/jsdom": "^21.1.7",
|
|
62
|
+
"jest": "^29.7.0",
|
|
63
|
+
"json-schema": "^0.4.0",
|
|
64
|
+
"rimraf": "3.0.2",
|
|
65
|
+
"ts-jest": "^29.2.3",
|
|
66
|
+
"ts-node": "^10.9.2",
|
|
67
|
+
"typescript": "^5.5.4"
|
|
36
68
|
},
|
|
37
69
|
"engines": {
|
|
38
70
|
"node": ">=18",
|
package/eslint.config.mjs
DELETED
package/src/collections/Media.ts
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import type { CollectionConfig, Field } from 'payload';
|
|
2
|
-
import { lexicalEditor } from '@payloadcms/richtext-lexical';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Media Collection Configuration
|
|
6
|
-
* Additional fields will be appended to the media collection.
|
|
7
|
-
*
|
|
8
|
-
* @param filePath
|
|
9
|
-
* @param additionalFields
|
|
10
|
-
* @constructor
|
|
11
|
-
*/
|
|
12
|
-
export const Media = (additionalFields?: Field[]): CollectionConfig => {
|
|
13
|
-
return {
|
|
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
|
-
],
|
|
38
|
-
upload: {
|
|
39
|
-
staticDir: 'media',
|
|
40
|
-
imageSizes: [
|
|
41
|
-
// Original Size (for WebP & Avif)
|
|
42
|
-
{
|
|
43
|
-
name: 'webp',
|
|
44
|
-
width: undefined,
|
|
45
|
-
height: undefined,
|
|
46
|
-
formatOptions: {
|
|
47
|
-
format: 'webp',
|
|
48
|
-
options: {
|
|
49
|
-
quality: 80,
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
name: 'avif',
|
|
55
|
-
width: undefined,
|
|
56
|
-
height: undefined,
|
|
57
|
-
formatOptions: {
|
|
58
|
-
format: 'avif',
|
|
59
|
-
options: {
|
|
60
|
-
quality: 80,
|
|
61
|
-
},
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
// Thumbnail Sizes
|
|
65
|
-
{
|
|
66
|
-
name: 'thumbnail',
|
|
67
|
-
width: 400,
|
|
68
|
-
height: 300,
|
|
69
|
-
position: 'centre',
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
name: 'thumbnail_webp',
|
|
73
|
-
width: 400,
|
|
74
|
-
height: 300,
|
|
75
|
-
position: 'centre',
|
|
76
|
-
formatOptions: {
|
|
77
|
-
format: 'webp',
|
|
78
|
-
options: {
|
|
79
|
-
quality: 80,
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
name: 'thumbnail_avif',
|
|
85
|
-
width: 400,
|
|
86
|
-
height: 300,
|
|
87
|
-
position: 'centre',
|
|
88
|
-
formatOptions: {
|
|
89
|
-
format: 'avif',
|
|
90
|
-
options: {
|
|
91
|
-
quality: 80,
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
// Mobile Sizes
|
|
96
|
-
{
|
|
97
|
-
name: 'mobile',
|
|
98
|
-
width: 768,
|
|
99
|
-
height: undefined,
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
name: 'mobile_webp',
|
|
103
|
-
width: 768,
|
|
104
|
-
height: undefined,
|
|
105
|
-
formatOptions: {
|
|
106
|
-
format: 'webp',
|
|
107
|
-
options: {
|
|
108
|
-
quality: 80,
|
|
109
|
-
},
|
|
110
|
-
},
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
name: 'mobile_avif',
|
|
114
|
-
width: 768,
|
|
115
|
-
height: undefined,
|
|
116
|
-
formatOptions: {
|
|
117
|
-
format: 'avif',
|
|
118
|
-
options: {
|
|
119
|
-
quality: 80,
|
|
120
|
-
},
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
|
-
// Tablet Sizes
|
|
124
|
-
{
|
|
125
|
-
name: 'tablet',
|
|
126
|
-
width: 1024,
|
|
127
|
-
height: undefined,
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
name: 'tablet_webp',
|
|
131
|
-
width: 1024,
|
|
132
|
-
height: undefined,
|
|
133
|
-
formatOptions: {
|
|
134
|
-
format: 'webp',
|
|
135
|
-
options: {
|
|
136
|
-
quality: 80,
|
|
137
|
-
},
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
{
|
|
141
|
-
name: 'tablet_avif',
|
|
142
|
-
width: 1024,
|
|
143
|
-
height: undefined,
|
|
144
|
-
formatOptions: {
|
|
145
|
-
format: 'avif',
|
|
146
|
-
options: {
|
|
147
|
-
quality: 80,
|
|
148
|
-
},
|
|
149
|
-
},
|
|
150
|
-
},
|
|
151
|
-
],
|
|
152
|
-
},
|
|
153
|
-
};
|
|
154
|
-
};
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import type { CollectionConfig } from 'payload';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Redirects Collection Configuration
|
|
5
|
-
* In favour of the native plugin for more granular control.
|
|
6
|
-
*
|
|
7
|
-
* TODO: Potential to add regex redirects here, i.e product-category/(.*)$ => /category/$1
|
|
8
|
-
*
|
|
9
|
-
* @constructor
|
|
10
|
-
*/
|
|
11
|
-
export const Redirects = (overrides?: Partial<CollectionConfig>): CollectionConfig => {
|
|
12
|
-
return {
|
|
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 /',
|
|
26
|
-
},
|
|
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',
|
|
36
|
-
},
|
|
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
|
-
],
|
|
54
|
-
...(overrides ? overrides : {}),
|
|
55
|
-
};
|
|
56
|
-
};
|
package/src/common/SEO.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { Field } from 'payload';
|
|
2
|
-
import { validateURL } from '../util/validation';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* SEO Fields define the additional fields that appear
|
|
6
|
-
* within the Payload SEO plugin.
|
|
7
|
-
*/
|
|
8
|
-
export const SEOFields: Field[] = [
|
|
9
|
-
{
|
|
10
|
-
type: 'row',
|
|
11
|
-
fields: [
|
|
12
|
-
{
|
|
13
|
-
name: 'private',
|
|
14
|
-
type: 'checkbox',
|
|
15
|
-
label: 'Private',
|
|
16
|
-
defaultValue: false,
|
|
17
|
-
admin: {
|
|
18
|
-
width: '50%',
|
|
19
|
-
description:
|
|
20
|
-
'Enable private mode to prevent robots from crawling the page or website. When enabled it will output <meta name="robots" content="noindex" /> on the frontend.',
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
name: 'canonicalURL',
|
|
25
|
-
type: 'text',
|
|
26
|
-
label: 'Canonical',
|
|
27
|
-
admin: {
|
|
28
|
-
width: '50%',
|
|
29
|
-
description:
|
|
30
|
-
'A canonical URL is the version of a webpage chosen by search engines like Google as the main version when there are duplicates.',
|
|
31
|
-
},
|
|
32
|
-
validate: validateURL,
|
|
33
|
-
},
|
|
34
|
-
],
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
name: 'structuredData',
|
|
38
|
-
type: 'json',
|
|
39
|
-
label: 'Structured Data',
|
|
40
|
-
admin: {
|
|
41
|
-
description:
|
|
42
|
-
'Structured data is a standardized format for providing information about a page and classifying the page content. The site Schema.org contains a standardised list of markup that the major search engines — Google, Bing, Yahoo and Yandex — have collectively agreed to support.',
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
];
|
package/src/endpoints/slug.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { PayloadHandler, PayloadRequest } from 'payload';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Find a document in the given collection by its slug.
|
|
5
|
-
*
|
|
6
|
-
* @param collection
|
|
7
|
-
*/
|
|
8
|
-
export const findBySlug = (collection: string): PayloadHandler => {
|
|
9
|
-
return async (req: PayloadRequest): Promise<Response> => {
|
|
10
|
-
try {
|
|
11
|
-
const data = await req.payload.find({
|
|
12
|
-
collection,
|
|
13
|
-
where: {
|
|
14
|
-
slug: {
|
|
15
|
-
equals: req.routeParams.slug,
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
limit: 1,
|
|
19
|
-
});
|
|
20
|
-
if (data.docs.length === 0) {
|
|
21
|
-
return new Response(JSON.stringify({ error: 'not found' }), { status: 404 });
|
|
22
|
-
} else {
|
|
23
|
-
return new Response(JSON.stringify(data.docs[0]), { status: 200 });
|
|
24
|
-
}
|
|
25
|
-
} catch (error) {
|
|
26
|
-
console.error('Error occurred while fetching document:', error);
|
|
27
|
-
return new Response(JSON.stringify({ error: 'Internal server error' }), {
|
|
28
|
-
status: 500,
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
};
|