-
Notifications
You must be signed in to change notification settings - Fork 0
/
payload.config.ts
116 lines (113 loc) · 4.23 KB
/
payload.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import { announcements, media, pages, sessions, users } from '@/payload/collections'
import { COLLECTION_SLUG_MEDIA, COLLECTION_SLUG_PAGE, COLLECTION_SLUG_PRODUCTS } from '@/payload/collections/config'
import { siteSettings } from '@/payload/globals/site-settings'
import generateBreadcrumbsUrl from '@/payload/utils/generateBreadcrumbsUrl'
import { resendAdapter } from '@payloadcms/email-resend'
import { formBuilderPlugin } from '@payloadcms/plugin-form-builder'
import { seoPlugin } from '@payloadcms/plugin-seo'
import { nestedDocsPlugin } from '@payloadcms/plugin-nested-docs'
import { stripePlugin } from '@payloadcms/plugin-stripe'
import { FixedToolbarFeature, lexicalEditor } from '@payloadcms/richtext-lexical'
import { vercelBlobStorage } from '@payloadcms/storage-vercel-blob'
import { prices, products, subscriptions } from '@/payload/collections/stripe'
import { priceUpsert, subscriptionDeleted, subscriptionUpsert } from '@/payload/stripe/webhooks'
import path from 'path'
import { buildConfig } from 'payload/config'
import { en } from 'payload/i18n/en'
import sharp from 'sharp'
import { fileURLToPath } from 'url'
import _get from 'lodash/get'
import {postgresAdapter} from "@payloadcms/db-postgres";
const filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(filename)
export default buildConfig({
globals: [siteSettings],
collections: [announcements, users, pages, media, sessions, products, prices, subscriptions],
admin: {
livePreview: {
url: ({ data, locale }) => `${process.env.NEXT_PUBLIC_SITE_URL}/preview${data.path}${locale ? `?locale=${locale.code}` : ''}`,
collections: [COLLECTION_SLUG_PAGE]
}
},
cors: ['https://checkout.stripe.com', `${process.env.NEXT_PUBLIC_SITE_URL}` || ''],
csrf: ['https://checkout.stripe.com', process.env.NEXT_PUBLIC_SITE_URL || ''],
editor: lexicalEditor({
features: ({ defaultFeatures }) => [...defaultFeatures, FixedToolbarFeature()]
}),
secret: process.env.AUTH_SECRET || '',
db: postgresAdapter({
pool: {
connectionString: process.env.POSTGRES_URL,
},
}),
serverURL: process.env.NEXT_PUBLIC_SITE_URL,
email:
process.env.RESEND_DEFAULT_EMAIL && process.env.AUTH_RESEND_KEY
? resendAdapter({
defaultFromAddress: process.env.RESEND_DEFAULT_EMAIL,
defaultFromName: 'Payload Admin',
apiKey: process.env.AUTH_RESEND_KEY || ''
})
: undefined,
i18n: {
supportedLanguages: { en }
},
plugins: [
nestedDocsPlugin({
collections: [COLLECTION_SLUG_PAGE],
generateURL: generateBreadcrumbsUrl,
breadcrumbsFieldSlug: 'breadcrumbs'
}),
vercelBlobStorage({
collections: {
[media.slug]: true,
},
token: process.env.BLOB_READ_WRITE_TOKEN || '',
}),
formBuilderPlugin({
redirectRelationships: [COLLECTION_SLUG_PAGE],
fields: {
state: false
}
}),
stripePlugin({
isTestKey: Boolean(process.env.NEXT_PUBLIC_STRIPE_IS_TEST_KEY),
rest: false,
stripeSecretKey: process.env.STRIPE_SECRET_KEY || '',
stripeWebhooksEndpointSecret: process.env.STRIPE_WEBHOOKS_SIGNING_SECRET,
webhooks: {
'price.updated': priceUpsert,
'price.created': priceUpsert,
'customer.subscription.created': subscriptionUpsert,
'customer.subscription.updated': subscriptionUpsert,
'customer.subscription.deleted': subscriptionDeleted
},
sync: [
{
collection: COLLECTION_SLUG_PRODUCTS,
stripeResourceType: 'products',
stripeResourceTypeSingular: 'product',
fields: [
{ fieldPath: 'active', stripeProperty: 'active' },
{ fieldPath: 'name', stripeProperty: 'name' },
{ fieldPath: 'description', stripeProperty: 'description' },
{ fieldPath: 'image', stripeProperty: 'images.0' }
]
}
]
}),
seoPlugin({
collections: [COLLECTION_SLUG_PAGE],
uploadsCollection: COLLECTION_SLUG_MEDIA,
generateURL: ({ doc }) => {
const path = _get(doc, 'path.value', null)
return `${process.env.NEXT_PUBLIC_SITE_URL || ''}${path}`
},
tabbedUI: true
})
],
typescript: {
outputFile: path.resolve(dirname, 'payload-types.ts')
},
sharp
})