@ainsleydev/payload-helper 0.1.0 → 0.1.1
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/README.md +151 -0
- package/dist/collections/index.d.ts +3 -0
- package/dist/collections/index.js +4 -0
- package/dist/collections/index.js.map +1 -0
- package/dist/common/index.d.ts +1 -0
- package/dist/common/index.js +3 -0
- package/dist/common/index.js.map +1 -0
- package/dist/endpoints/index.d.ts +1 -0
- package/dist/endpoints/index.js +3 -0
- package/dist/endpoints/index.js.map +1 -0
- package/dist/globals/index.d.ts +5 -0
- package/dist/globals/index.js +6 -0
- package/dist/globals/index.js.map +1 -0
- package/dist/index.d.ts +13 -13
- package/dist/index.js +12 -77
- package/dist/index.js.map +1 -1
- package/dist/plugin.d.ts +9 -0
- package/dist/plugin.js +78 -0
- package/dist/plugin.js.map +1 -0
- package/dist/util/index.d.ts +4 -0
- package/dist/util/index.js +6 -0
- package/dist/util/index.js.map +1 -0
- package/package.json +21 -1
package/README.md
CHANGED
|
@@ -48,6 +48,157 @@ export default buildConfig({
|
|
|
48
48
|
})
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
+
## Available Exports
|
|
52
|
+
|
|
53
|
+
The payload-helper package exports a variety of utilities, collections, globals, and components that you can use directly in your Payload projects.
|
|
54
|
+
|
|
55
|
+
### Collections
|
|
56
|
+
|
|
57
|
+
Pre-built Payload collections ready to use:
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
import { Media, Redirects, imageSizes, imageSizesWithAvif } from '@ainsleydev/payload-helper'
|
|
61
|
+
|
|
62
|
+
// Use in your Payload config
|
|
63
|
+
export default buildConfig({
|
|
64
|
+
collections: [
|
|
65
|
+
Media({ includeAvif: true, additionalFields: [...] }),
|
|
66
|
+
Redirects(),
|
|
67
|
+
],
|
|
68
|
+
})
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
**Subpath imports** (optional):
|
|
72
|
+
```typescript
|
|
73
|
+
import { Media, Redirects } from '@ainsleydev/payload-helper/collections'
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Globals
|
|
77
|
+
|
|
78
|
+
Pre-configured global types for common website needs:
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
import { Settings, Navigation, countries, languages } from '@ainsleydev/payload-helper'
|
|
82
|
+
|
|
83
|
+
export default buildConfig({
|
|
84
|
+
globals: [
|
|
85
|
+
Settings({ additionalTabs: [...] }),
|
|
86
|
+
Navigation({ includeFooter: true }),
|
|
87
|
+
],
|
|
88
|
+
})
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
**Subpath imports** (optional):
|
|
92
|
+
```typescript
|
|
93
|
+
import { Settings, Navigation } from '@ainsleydev/payload-helper/globals'
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Utilities
|
|
97
|
+
|
|
98
|
+
Helpful utility functions for validation, field operations, and Lexical conversion:
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
import {
|
|
102
|
+
env,
|
|
103
|
+
fieldHasName,
|
|
104
|
+
validateURL,
|
|
105
|
+
validatePostcode,
|
|
106
|
+
htmlToLexical,
|
|
107
|
+
lexicalToHtml,
|
|
108
|
+
} from '@ainsleydev/payload-helper'
|
|
109
|
+
|
|
110
|
+
// Use in field validation
|
|
111
|
+
{
|
|
112
|
+
name: 'website',
|
|
113
|
+
type: 'text',
|
|
114
|
+
validate: validateURL,
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Convert HTML to Lexical format
|
|
118
|
+
const lexicalData = await htmlToLexical('<p>Hello world</p>')
|
|
119
|
+
|
|
120
|
+
// Convert Lexical to HTML
|
|
121
|
+
const html = await lexicalToHtml(lexicalData)
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**Subpath imports** (optional):
|
|
125
|
+
```typescript
|
|
126
|
+
import { validateURL, htmlToLexical } from '@ainsleydev/payload-helper/util'
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Common/Reusable Fields
|
|
130
|
+
|
|
131
|
+
Reusable field definitions:
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
import { SEOFields } from '@ainsleydev/payload-helper'
|
|
135
|
+
import { seoPlugin } from '@payloadcms/plugin-seo'
|
|
136
|
+
|
|
137
|
+
export default buildConfig({
|
|
138
|
+
plugins: [
|
|
139
|
+
seoPlugin({
|
|
140
|
+
collections: ['pages'],
|
|
141
|
+
fields: SEOFields,
|
|
142
|
+
}),
|
|
143
|
+
],
|
|
144
|
+
})
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
**Subpath imports** (optional):
|
|
148
|
+
```typescript
|
|
149
|
+
import { SEOFields } from '@ainsleydev/payload-helper/common'
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Endpoints
|
|
153
|
+
|
|
154
|
+
Custom API endpoints:
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
import { findBySlug } from '@ainsleydev/payload-helper'
|
|
158
|
+
|
|
159
|
+
// Use in your collection config
|
|
160
|
+
export const Pages: CollectionConfig = {
|
|
161
|
+
slug: 'pages',
|
|
162
|
+
endpoints: [findBySlug],
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
**Subpath imports** (optional):
|
|
167
|
+
```typescript
|
|
168
|
+
import { findBySlug } from '@ainsleydev/payload-helper/endpoints'
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Email Components
|
|
172
|
+
|
|
173
|
+
Customizable email templates for authentication flows:
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
import { ForgotPasswordEmail, VerifyAccountEmail } from '@ainsleydev/payload-helper'
|
|
177
|
+
import type { ForgotPasswordEmailProps, VerifyAccountEmailProps } from '@ainsleydev/payload-helper'
|
|
178
|
+
|
|
179
|
+
// Use directly in custom email handlers
|
|
180
|
+
const emailHtml = ForgotPasswordEmail({
|
|
181
|
+
resetPasswordToken: 'token123',
|
|
182
|
+
frontEndUrl: 'https://yoursite.com',
|
|
183
|
+
// ...other props
|
|
184
|
+
})
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### Schema Utilities
|
|
188
|
+
|
|
189
|
+
For projects that need JSON schema generation (e.g., Go type generation):
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
import { fieldMapper, schemas, addGoJSONSchema } from '@ainsleydev/payload-helper'
|
|
193
|
+
import type { SchemaOptions } from '@ainsleydev/payload-helper'
|
|
194
|
+
|
|
195
|
+
// Apply Go schema mappings
|
|
196
|
+
const config = fieldMapper(sanitizedConfig, {
|
|
197
|
+
useWebKitMedia: true,
|
|
198
|
+
assignRelationships: true,
|
|
199
|
+
})
|
|
200
|
+
```
|
|
201
|
+
|
|
51
202
|
## Configuration
|
|
52
203
|
|
|
53
204
|
### Admin configuration
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/collections/index.ts"],"sourcesContent":["export { Media, imageSizes, imageSizesWithAvif } from './Media.js';\nexport type { MediaArgs } from './Media.js';\nexport { Redirects } from './Redirects.js';\n"],"names":["Media","imageSizes","imageSizesWithAvif","Redirects"],"mappings":"AAAA,SAASA,KAAK,EAAEC,UAAU,EAAEC,kBAAkB,QAAQ,aAAa;AAEnE,SAASC,SAAS,QAAQ,iBAAiB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SEOFields } from './SEO.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/common/index.ts"],"sourcesContent":["export { SEOFields } from './SEO.js';\n"],"names":["SEOFields"],"mappings":"AAAA,SAASA,SAAS,QAAQ,WAAW"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { findBySlug } from './slug.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/endpoints/index.ts"],"sourcesContent":["export { findBySlug } from './slug.js';\n"],"names":["findBySlug"],"mappings":"AAAA,SAASA,UAAU,QAAQ,YAAY"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/globals/index.ts"],"sourcesContent":["export { Settings } from './Settings.js';\nexport type { SettingsArgs } from './Settings.js';\nexport { Navigation } from './Navigation.js';\nexport { countries } from './countries.js';\nexport { languages } from './locales.js';\n"],"names":["Settings","Navigation","countries","languages"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,gBAAgB;AAEzC,SAASC,UAAU,QAAQ,kBAAkB;AAC7C,SAASC,SAAS,QAAQ,iBAAiB;AAC3C,SAASC,SAAS,QAAQ,eAAe"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* @param pluginOptions
|
|
8
|
-
*/
|
|
9
|
-
export declare const payloadHelper: (pluginOptions: PayloadHelperPluginConfig) => (incomingConfig: Config) => Config;
|
|
10
|
-
export type { IconProps } from './admin/components/Icon.js';
|
|
11
|
-
export type { LogoProps } from './admin/components/Logo.js';
|
|
1
|
+
export { payloadHelper } from './plugin.js';
|
|
2
|
+
export type { PayloadHelperPluginConfig, AdminConfig, AdminIconConfig, AdminLogoConfig, EmailConfig, EmailContentOverrides, SettingsConfig, WebServerConfig, } from './types.js';
|
|
3
|
+
export type { MediaArgs } from './collections/Media.js';
|
|
4
|
+
export { Media, imageSizes, imageSizesWithAvif, Redirects } from './collections/index.js';
|
|
5
|
+
export type { SettingsArgs } from './globals/Settings.js';
|
|
6
|
+
export { Settings, Navigation, countries, languages } from './globals/index.js';
|
|
12
7
|
export { ForgotPasswordEmail } from './email/ForgotPasswordEmail.js';
|
|
13
8
|
export type { ForgotPasswordEmailProps } from './email/ForgotPasswordEmail.js';
|
|
14
9
|
export { VerifyAccountEmail } from './email/VerifyAccountEmail.js';
|
|
15
10
|
export type { VerifyAccountEmailProps } from './email/VerifyAccountEmail.js';
|
|
16
|
-
export {
|
|
17
|
-
export type {
|
|
11
|
+
export type { IconProps } from './admin/components/Icon.js';
|
|
12
|
+
export type { LogoProps } from './admin/components/Logo.js';
|
|
13
|
+
export { env, fieldHasName, validateURL, validatePostcode, htmlToLexical, lexicalToHtml, } from './util/index.js';
|
|
14
|
+
export { SEOFields } from './common/index.js';
|
|
15
|
+
export { findBySlug } from './endpoints/index.js';
|
|
16
|
+
export type { SchemaOptions } from './plugin/schema.js';
|
|
17
|
+
export { fieldMapper, schemas, addGoJSONSchema } from './plugin/schema.js';
|
package/dist/index.js
CHANGED
|
@@ -1,81 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
* @constructor
|
|
8
|
-
* @param pluginOptions
|
|
9
|
-
*/ export const payloadHelper = (pluginOptions)=>(incomingConfig)=>{
|
|
10
|
-
// TODO: Validate Config
|
|
11
|
-
let config = incomingConfig;
|
|
12
|
-
// Update typescript generation file
|
|
13
|
-
config.typescript = config.typescript || {};
|
|
14
|
-
config.typescript.outputFile = './src/types/payload.ts';
|
|
15
|
-
// Inject admin Logo component if logo config is provided
|
|
16
|
-
if (pluginOptions.admin?.logo) {
|
|
17
|
-
config = injectAdminLogo(config, pluginOptions.admin.logo, pluginOptions.siteName);
|
|
18
|
-
}
|
|
19
|
-
// Inject admin Icon component if icon config is provided
|
|
20
|
-
if (pluginOptions.admin?.icon) {
|
|
21
|
-
config = injectAdminIcon(config, pluginOptions.admin.icon, pluginOptions.siteName);
|
|
22
|
-
}
|
|
23
|
-
// Inject email templates for auth-enabled collections if email config is provided
|
|
24
|
-
if (pluginOptions.email) {
|
|
25
|
-
config = injectEmailTemplates(config, pluginOptions.email);
|
|
26
|
-
}
|
|
27
|
-
// Map collections & add hooks
|
|
28
|
-
config.collections = (config.collections || []).map((collection)=>{
|
|
29
|
-
if (collection.upload !== undefined && collection.upload !== true) {
|
|
30
|
-
return collection;
|
|
31
|
-
}
|
|
32
|
-
const hooks = collection.hooks || {};
|
|
33
|
-
// Add afterChange hook only if webServer is defined
|
|
34
|
-
if (pluginOptions.webServer) {
|
|
35
|
-
hooks.afterChange = [
|
|
36
|
-
...hooks.afterChange || [],
|
|
37
|
-
cacheHookCollections({
|
|
38
|
-
server: pluginOptions.webServer,
|
|
39
|
-
slug: collection.slug,
|
|
40
|
-
fields: collection.fields,
|
|
41
|
-
isCollection: true
|
|
42
|
-
})
|
|
43
|
-
];
|
|
44
|
-
}
|
|
45
|
-
return {
|
|
46
|
-
...collection,
|
|
47
|
-
hooks
|
|
48
|
-
};
|
|
49
|
-
});
|
|
50
|
-
// Map globals & add hooks
|
|
51
|
-
config.globals = (config.globals || []).map((global)=>{
|
|
52
|
-
const hooks = global.hooks || {};
|
|
53
|
-
// Add afterChange hook only if webServer is defined
|
|
54
|
-
if (pluginOptions.webServer) {
|
|
55
|
-
hooks.afterChange = [
|
|
56
|
-
...hooks.afterChange || [],
|
|
57
|
-
cacheHookGlobals({
|
|
58
|
-
server: pluginOptions.webServer,
|
|
59
|
-
slug: global.slug,
|
|
60
|
-
fields: global.fields,
|
|
61
|
-
isCollection: true
|
|
62
|
-
})
|
|
63
|
-
];
|
|
64
|
-
}
|
|
65
|
-
return {
|
|
66
|
-
...global,
|
|
67
|
-
hooks
|
|
68
|
-
};
|
|
69
|
-
});
|
|
70
|
-
// Store plugin options in config.custom for CLI access (e.g., preview-emails command)
|
|
71
|
-
config.custom = {
|
|
72
|
-
...config.custom,
|
|
73
|
-
payloadHelperOptions: pluginOptions
|
|
74
|
-
};
|
|
75
|
-
return config;
|
|
76
|
-
};
|
|
1
|
+
// Main plugin
|
|
2
|
+
export { payloadHelper } from './plugin.js';
|
|
3
|
+
export { Media, imageSizes, imageSizesWithAvif, Redirects } from './collections/index.js';
|
|
4
|
+
export { Settings, Navigation, countries, languages } from './globals/index.js';
|
|
5
|
+
// Email Components
|
|
77
6
|
export { ForgotPasswordEmail } from './email/ForgotPasswordEmail.js';
|
|
78
7
|
export { VerifyAccountEmail } from './email/VerifyAccountEmail.js';
|
|
79
|
-
|
|
8
|
+
// Utilities
|
|
9
|
+
export { env, fieldHasName, validateURL, validatePostcode, htmlToLexical, lexicalToHtml } from './util/index.js';
|
|
10
|
+
// Common/Reusable
|
|
11
|
+
export { SEOFields } from './common/index.js';
|
|
12
|
+
// Endpoints
|
|
13
|
+
export { findBySlug } from './endpoints/index.js';
|
|
14
|
+
export { fieldMapper, schemas, addGoJSONSchema } from './plugin/schema.js';
|
|
80
15
|
|
|
81
16
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// Main plugin\nexport { payloadHelper } from './plugin.js';\n\n// Types\nexport type {\n\tPayloadHelperPluginConfig,\n\tAdminConfig,\n\tAdminIconConfig,\n\tAdminLogoConfig,\n\tEmailConfig,\n\tEmailContentOverrides,\n\tSettingsConfig,\n\tWebServerConfig,\n} from './types.js';\n\n// Collections\nexport type { MediaArgs } from './collections/Media.js';\nexport { Media, imageSizes, imageSizesWithAvif, Redirects } from './collections/index.js';\n\n// Globals\nexport type { SettingsArgs } from './globals/Settings.js';\nexport { Settings, Navigation, countries, languages } from './globals/index.js';\n\n// Email Components\nexport { ForgotPasswordEmail } from './email/ForgotPasswordEmail.js';\nexport type { ForgotPasswordEmailProps } from './email/ForgotPasswordEmail.js';\nexport { VerifyAccountEmail } from './email/VerifyAccountEmail.js';\nexport type { VerifyAccountEmailProps } from './email/VerifyAccountEmail.js';\n\n// Admin Components\nexport type { IconProps } from './admin/components/Icon.js';\nexport type { LogoProps } from './admin/components/Logo.js';\n\n// Utilities\nexport {\n\tenv,\n\tfieldHasName,\n\tvalidateURL,\n\tvalidatePostcode,\n\thtmlToLexical,\n\tlexicalToHtml,\n} from './util/index.js';\n\n// Common/Reusable\nexport { SEOFields } from './common/index.js';\n\n// Endpoints\nexport { findBySlug } from './endpoints/index.js';\n\n// Schema utilities\nexport type { SchemaOptions } from './plugin/schema.js';\nexport { fieldMapper, schemas, addGoJSONSchema } from './plugin/schema.js';\n"],"names":["payloadHelper","Media","imageSizes","imageSizesWithAvif","Redirects","Settings","Navigation","countries","languages","ForgotPasswordEmail","VerifyAccountEmail","env","fieldHasName","validateURL","validatePostcode","htmlToLexical","lexicalToHtml","SEOFields","findBySlug","fieldMapper","schemas","addGoJSONSchema"],"mappings":"AAAA,cAAc;AACd,SAASA,aAAa,QAAQ,cAAc;AAgB5C,SAASC,KAAK,EAAEC,UAAU,EAAEC,kBAAkB,EAAEC,SAAS,QAAQ,yBAAyB;AAI1F,SAASC,QAAQ,EAAEC,UAAU,EAAEC,SAAS,EAAEC,SAAS,QAAQ,qBAAqB;AAEhF,mBAAmB;AACnB,SAASC,mBAAmB,QAAQ,iCAAiC;AAErE,SAASC,kBAAkB,QAAQ,gCAAgC;AAOnE,YAAY;AACZ,SACCC,GAAG,EACHC,YAAY,EACZC,WAAW,EACXC,gBAAgB,EAChBC,aAAa,EACbC,aAAa,QACP,kBAAkB;AAEzB,kBAAkB;AAClB,SAASC,SAAS,QAAQ,oBAAoB;AAE9C,YAAY;AACZ,SAASC,UAAU,QAAQ,uBAAuB;AAIlD,SAASC,WAAW,EAAEC,OAAO,EAAEC,eAAe,QAAQ,qBAAqB"}
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Config } from 'payload';
|
|
2
|
+
import type { PayloadHelperPluginConfig } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Payload Helper Plugin for websites at ainsley.dev
|
|
5
|
+
*
|
|
6
|
+
* @constructor
|
|
7
|
+
* @param pluginOptions
|
|
8
|
+
*/
|
|
9
|
+
export declare const payloadHelper: (pluginOptions: PayloadHelperPluginConfig) => (incomingConfig: Config) => Config;
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { injectAdminIcon, injectAdminLogo } from './plugin/admin.js';
|
|
2
|
+
import { injectEmailTemplates } from './plugin/email.js';
|
|
3
|
+
import { cacheHookCollections, cacheHookGlobals } from './plugin/hooks.js';
|
|
4
|
+
/**
|
|
5
|
+
* Payload Helper Plugin for websites at ainsley.dev
|
|
6
|
+
*
|
|
7
|
+
* @constructor
|
|
8
|
+
* @param pluginOptions
|
|
9
|
+
*/ export const payloadHelper = (pluginOptions)=>(incomingConfig)=>{
|
|
10
|
+
// TODO: Validate Config
|
|
11
|
+
let config = incomingConfig;
|
|
12
|
+
// Update typescript generation file
|
|
13
|
+
config.typescript = config.typescript || {};
|
|
14
|
+
config.typescript.outputFile = './src/types/payload.ts';
|
|
15
|
+
// Inject admin Logo component if logo config is provided
|
|
16
|
+
if (pluginOptions.admin?.logo) {
|
|
17
|
+
config = injectAdminLogo(config, pluginOptions.admin.logo, pluginOptions.siteName);
|
|
18
|
+
}
|
|
19
|
+
// Inject admin Icon component if icon config is provided
|
|
20
|
+
if (pluginOptions.admin?.icon) {
|
|
21
|
+
config = injectAdminIcon(config, pluginOptions.admin.icon, pluginOptions.siteName);
|
|
22
|
+
}
|
|
23
|
+
// Inject email templates for auth-enabled collections if email config is provided
|
|
24
|
+
if (pluginOptions.email) {
|
|
25
|
+
config = injectEmailTemplates(config, pluginOptions.email);
|
|
26
|
+
}
|
|
27
|
+
// Map collections & add hooks
|
|
28
|
+
config.collections = (config.collections || []).map((collection)=>{
|
|
29
|
+
if (collection.upload !== undefined && collection.upload !== true) {
|
|
30
|
+
return collection;
|
|
31
|
+
}
|
|
32
|
+
const hooks = collection.hooks || {};
|
|
33
|
+
// Add afterChange hook only if webServer is defined
|
|
34
|
+
if (pluginOptions.webServer) {
|
|
35
|
+
hooks.afterChange = [
|
|
36
|
+
...hooks.afterChange || [],
|
|
37
|
+
cacheHookCollections({
|
|
38
|
+
server: pluginOptions.webServer,
|
|
39
|
+
slug: collection.slug,
|
|
40
|
+
fields: collection.fields,
|
|
41
|
+
isCollection: true
|
|
42
|
+
})
|
|
43
|
+
];
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
...collection,
|
|
47
|
+
hooks
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
// Map globals & add hooks
|
|
51
|
+
config.globals = (config.globals || []).map((global)=>{
|
|
52
|
+
const hooks = global.hooks || {};
|
|
53
|
+
// Add afterChange hook only if webServer is defined
|
|
54
|
+
if (pluginOptions.webServer) {
|
|
55
|
+
hooks.afterChange = [
|
|
56
|
+
...hooks.afterChange || [],
|
|
57
|
+
cacheHookGlobals({
|
|
58
|
+
server: pluginOptions.webServer,
|
|
59
|
+
slug: global.slug,
|
|
60
|
+
fields: global.fields,
|
|
61
|
+
isCollection: true
|
|
62
|
+
})
|
|
63
|
+
];
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
...global,
|
|
67
|
+
hooks
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
// Store plugin options in config.custom for CLI access (e.g., preview-emails command)
|
|
71
|
+
config.custom = {
|
|
72
|
+
...config.custom,
|
|
73
|
+
payloadHelperOptions: pluginOptions
|
|
74
|
+
};
|
|
75
|
+
return config;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/plugin.ts"],"sourcesContent":["import type { CollectionConfig, Config } from 'payload';\nimport { injectAdminIcon, injectAdminLogo } from './plugin/admin.js';\nimport { injectEmailTemplates } from './plugin/email.js';\nimport { cacheHookCollections, cacheHookGlobals } from './plugin/hooks.js';\nimport type { PayloadHelperPluginConfig } from './types.js';\n\n/**\n * Payload Helper Plugin for websites at ainsley.dev\n *\n * @constructor\n * @param pluginOptions\n */\nexport const payloadHelper =\n\t(pluginOptions: PayloadHelperPluginConfig) =>\n\t(incomingConfig: Config): Config => {\n\t\t// TODO: Validate Config\n\n\t\tlet config = incomingConfig;\n\n\t\t// Update typescript generation file\n\t\tconfig.typescript = config.typescript || {};\n\t\tconfig.typescript.outputFile = './src/types/payload.ts';\n\n\t\t// Inject admin Logo component if logo config is provided\n\t\tif (pluginOptions.admin?.logo) {\n\t\t\tconfig = injectAdminLogo(config, pluginOptions.admin.logo, pluginOptions.siteName);\n\t\t}\n\n\t\t// Inject admin Icon component if icon config is provided\n\t\tif (pluginOptions.admin?.icon) {\n\t\t\tconfig = injectAdminIcon(config, pluginOptions.admin.icon, pluginOptions.siteName);\n\t\t}\n\n\t\t// Inject email templates for auth-enabled collections if email config is provided\n\t\tif (pluginOptions.email) {\n\t\t\tconfig = injectEmailTemplates(config, pluginOptions.email);\n\t\t}\n\n\t\t// Map collections & add hooks\n\t\tconfig.collections = (config.collections || []).map((collection): CollectionConfig => {\n\t\t\tif (collection.upload !== undefined && collection.upload !== true) {\n\t\t\t\treturn collection;\n\t\t\t}\n\n\t\t\tconst hooks = collection.hooks || {};\n\n\t\t\t// Add afterChange hook only if webServer is defined\n\t\t\tif (pluginOptions.webServer) {\n\t\t\t\thooks.afterChange = [\n\t\t\t\t\t...(hooks.afterChange || []),\n\t\t\t\t\tcacheHookCollections({\n\t\t\t\t\t\tserver: pluginOptions.webServer,\n\t\t\t\t\t\tslug: collection.slug,\n\t\t\t\t\t\tfields: collection.fields,\n\t\t\t\t\t\tisCollection: true,\n\t\t\t\t\t}),\n\t\t\t\t];\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\t...collection,\n\t\t\t\thooks,\n\t\t\t};\n\t\t});\n\n\t\t// Map globals & add hooks\n\t\tconfig.globals = (config.globals || []).map((global) => {\n\t\t\tconst hooks = global.hooks || {};\n\n\t\t\t// Add afterChange hook only if webServer is defined\n\t\t\tif (pluginOptions.webServer) {\n\t\t\t\thooks.afterChange = [\n\t\t\t\t\t...(hooks.afterChange || []),\n\t\t\t\t\tcacheHookGlobals({\n\t\t\t\t\t\tserver: pluginOptions.webServer,\n\t\t\t\t\t\tslug: global.slug,\n\t\t\t\t\t\tfields: global.fields,\n\t\t\t\t\t\tisCollection: true,\n\t\t\t\t\t}),\n\t\t\t\t];\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\t...global,\n\t\t\t\thooks,\n\t\t\t};\n\t\t});\n\n\t\t// Store plugin options in config.custom for CLI access (e.g., preview-emails command)\n\t\tconfig.custom = {\n\t\t\t...config.custom,\n\t\t\tpayloadHelperOptions: pluginOptions,\n\t\t};\n\n\t\treturn config;\n\t};\n"],"names":["injectAdminIcon","injectAdminLogo","injectEmailTemplates","cacheHookCollections","cacheHookGlobals","payloadHelper","pluginOptions","incomingConfig","config","typescript","outputFile","admin","logo","siteName","icon","email","collections","map","collection","upload","undefined","hooks","webServer","afterChange","server","slug","fields","isCollection","globals","global","custom","payloadHelperOptions"],"mappings":"AACA,SAASA,eAAe,EAAEC,eAAe,QAAQ,oBAAoB;AACrE,SAASC,oBAAoB,QAAQ,oBAAoB;AACzD,SAASC,oBAAoB,EAAEC,gBAAgB,QAAQ,oBAAoB;AAG3E;;;;;CAKC,GACD,OAAO,MAAMC,gBACZ,CAACC,gBACD,CAACC;QACA,wBAAwB;QAExB,IAAIC,SAASD;QAEb,oCAAoC;QACpCC,OAAOC,UAAU,GAAGD,OAAOC,UAAU,IAAI,CAAC;QAC1CD,OAAOC,UAAU,CAACC,UAAU,GAAG;QAE/B,yDAAyD;QACzD,IAAIJ,cAAcK,KAAK,EAAEC,MAAM;YAC9BJ,SAASP,gBAAgBO,QAAQF,cAAcK,KAAK,CAACC,IAAI,EAAEN,cAAcO,QAAQ;QAClF;QAEA,yDAAyD;QACzD,IAAIP,cAAcK,KAAK,EAAEG,MAAM;YAC9BN,SAASR,gBAAgBQ,QAAQF,cAAcK,KAAK,CAACG,IAAI,EAAER,cAAcO,QAAQ;QAClF;QAEA,kFAAkF;QAClF,IAAIP,cAAcS,KAAK,EAAE;YACxBP,SAASN,qBAAqBM,QAAQF,cAAcS,KAAK;QAC1D;QAEA,8BAA8B;QAC9BP,OAAOQ,WAAW,GAAG,AAACR,CAAAA,OAAOQ,WAAW,IAAI,EAAE,AAAD,EAAGC,GAAG,CAAC,CAACC;YACpD,IAAIA,WAAWC,MAAM,KAAKC,aAAaF,WAAWC,MAAM,KAAK,MAAM;gBAClE,OAAOD;YACR;YAEA,MAAMG,QAAQH,WAAWG,KAAK,IAAI,CAAC;YAEnC,oDAAoD;YACpD,IAAIf,cAAcgB,SAAS,EAAE;gBAC5BD,MAAME,WAAW,GAAG;uBACfF,MAAME,WAAW,IAAI,EAAE;oBAC3BpB,qBAAqB;wBACpBqB,QAAQlB,cAAcgB,SAAS;wBAC/BG,MAAMP,WAAWO,IAAI;wBACrBC,QAAQR,WAAWQ,MAAM;wBACzBC,cAAc;oBACf;iBACA;YACF;YAEA,OAAO;gBACN,GAAGT,UAAU;gBACbG;YACD;QACD;QAEA,0BAA0B;QAC1Bb,OAAOoB,OAAO,GAAG,AAACpB,CAAAA,OAAOoB,OAAO,IAAI,EAAE,AAAD,EAAGX,GAAG,CAAC,CAACY;YAC5C,MAAMR,QAAQQ,OAAOR,KAAK,IAAI,CAAC;YAE/B,oDAAoD;YACpD,IAAIf,cAAcgB,SAAS,EAAE;gBAC5BD,MAAME,WAAW,GAAG;uBACfF,MAAME,WAAW,IAAI,EAAE;oBAC3BnB,iBAAiB;wBAChBoB,QAAQlB,cAAcgB,SAAS;wBAC/BG,MAAMI,OAAOJ,IAAI;wBACjBC,QAAQG,OAAOH,MAAM;wBACrBC,cAAc;oBACf;iBACA;YACF;YAEA,OAAO;gBACN,GAAGE,MAAM;gBACTR;YACD;QACD;QAEA,sFAAsF;QACtFb,OAAOsB,MAAM,GAAG;YACf,GAAGtB,OAAOsB,MAAM;YAChBC,sBAAsBzB;QACvB;QAEA,OAAOE;IACR,EAAE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/util/index.ts"],"sourcesContent":["export { default as env } from './env.js';\nexport { fieldHasName } from './fields.js';\nexport { validateURL, validatePostcode } from './validation.js';\nexport { htmlToLexical, lexicalToHtml } from './lexical.js';\n"],"names":["default","env","fieldHasName","validateURL","validatePostcode","htmlToLexical","lexicalToHtml"],"mappings":"AAAA,SAASA,WAAWC,GAAG,QAAQ,WAAW;AAC1C,SAASC,YAAY,QAAQ,cAAc;AAC3C,SAASC,WAAW,EAAEC,gBAAgB,QAAQ,kBAAkB;AAChE,SAASC,aAAa,EAAEC,aAAa,QAAQ,eAAe"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ainsleydev/payload-helper",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Payload CMS utilities, collections and global types for ainsley.dev builds",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -29,6 +29,26 @@
|
|
|
29
29
|
"import": "./dist/index.js",
|
|
30
30
|
"default": "./dist/index.js"
|
|
31
31
|
},
|
|
32
|
+
"./collections": {
|
|
33
|
+
"types": "./dist/collections/index.d.ts",
|
|
34
|
+
"import": "./dist/collections/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./globals": {
|
|
37
|
+
"types": "./dist/globals/index.d.ts",
|
|
38
|
+
"import": "./dist/globals/index.js"
|
|
39
|
+
},
|
|
40
|
+
"./util": {
|
|
41
|
+
"types": "./dist/util/index.d.ts",
|
|
42
|
+
"import": "./dist/util/index.js"
|
|
43
|
+
},
|
|
44
|
+
"./common": {
|
|
45
|
+
"types": "./dist/common/index.d.ts",
|
|
46
|
+
"import": "./dist/common/index.js"
|
|
47
|
+
},
|
|
48
|
+
"./endpoints": {
|
|
49
|
+
"types": "./dist/endpoints/index.d.ts",
|
|
50
|
+
"import": "./dist/endpoints/index.js"
|
|
51
|
+
},
|
|
32
52
|
"./dist/admin/components/*": {
|
|
33
53
|
"types": "./dist/admin/components/*.d.ts",
|
|
34
54
|
"import": "./dist/admin/components/*.js",
|