mirror of
https://github.com/xtr-dev/payload-feature-flags.git
synced 2025-12-10 19:03:25 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
14a5acd222 | ||
| d3b8a8446e | |||
| 7dc17bc80a | |||
| b642b653d0 | |||
|
|
1db434e701 | ||
| 7fd6194712 | |||
| 259599ddcc |
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "payload-feature-flags",
|
||||
"version": "1.0.0",
|
||||
"version": "0.0.17",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "payload-feature-flags",
|
||||
"version": "1.0.0",
|
||||
"version": "0.0.17",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@eslint/eslintrc": "^3.2.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@xtr-dev/payload-feature-flags",
|
||||
"version": "0.0.14",
|
||||
"version": "0.0.17",
|
||||
"description": "Feature flags plugin for Payload CMS - manage feature toggles, A/B tests, and gradual rollouts",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
|
||||
@@ -21,23 +21,31 @@ export interface FeatureFlagOptions {
|
||||
|
||||
// Helper to get config from options or defaults
|
||||
function getConfig(options?: FeatureFlagOptions) {
|
||||
// In server-side environments, serverURL must be explicitly provided
|
||||
const serverURL = options?.serverURL ||
|
||||
(typeof window !== 'undefined' ? window.location.origin : undefined)
|
||||
|
||||
if (!serverURL) {
|
||||
console.warn(
|
||||
'FeatureFlags: serverURL must be provided when using hooks in server-side environment. ' +
|
||||
'Falling back to relative URL which may not work correctly.'
|
||||
)
|
||||
// Use relative URL as fallback - will work if API is on same domain
|
||||
return { serverURL: '', apiPath: options?.apiPath || '/api', collectionSlug: options?.collectionSlug || 'feature-flags' }
|
||||
// Check if serverURL is explicitly provided
|
||||
if (options?.serverURL) {
|
||||
return {
|
||||
serverURL: options.serverURL,
|
||||
apiPath: options.apiPath || '/api',
|
||||
collectionSlug: options.collectionSlug || 'feature-flags'
|
||||
}
|
||||
}
|
||||
|
||||
const apiPath = options?.apiPath || '/api'
|
||||
const collectionSlug = options?.collectionSlug || 'feature-flags'
|
||||
// In browser environment, use window.location.origin
|
||||
if (typeof window !== 'undefined') {
|
||||
return {
|
||||
serverURL: window.location.origin,
|
||||
apiPath: options?.apiPath || '/api',
|
||||
collectionSlug: options?.collectionSlug || 'feature-flags'
|
||||
}
|
||||
}
|
||||
|
||||
return { serverURL, apiPath, collectionSlug }
|
||||
// During SSR or in non-browser environments, use relative URL
|
||||
// This will work for same-origin requests
|
||||
return {
|
||||
serverURL: '',
|
||||
apiPath: options?.apiPath || '/api',
|
||||
collectionSlug: options?.collectionSlug || 'feature-flags'
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
15
src/index.ts
15
src/index.ts
@@ -34,6 +34,11 @@ export type PayloadFeatureFlagsConfig = {
|
||||
* Override collection configuration
|
||||
*/
|
||||
collectionOverrides?: CollectionOverrides
|
||||
/**
|
||||
* Enable custom list view for feature flags
|
||||
* @default false
|
||||
*/
|
||||
enableCustomListView?: boolean
|
||||
}
|
||||
|
||||
export const payloadFeatureFlags =
|
||||
@@ -44,6 +49,7 @@ export const payloadFeatureFlags =
|
||||
defaultValue = false,
|
||||
enableRollouts = true,
|
||||
enableVariants = true,
|
||||
enableCustomListView = false,
|
||||
collectionOverrides,
|
||||
} = pluginOptions
|
||||
|
||||
@@ -163,6 +169,15 @@ export const payloadFeatureFlags =
|
||||
useAsTitle: 'name',
|
||||
group: 'Configuration',
|
||||
description: 'Manage feature flags for your application',
|
||||
components: enableCustomListView ? {
|
||||
...collectionOverrides?.admin?.components,
|
||||
views: {
|
||||
...collectionOverrides?.admin?.components?.views,
|
||||
list: {
|
||||
Component: '@xtr-dev/payload-feature-flags/views#FeatureFlagsView'
|
||||
}
|
||||
}
|
||||
} : collectionOverrides?.admin?.components || {},
|
||||
...(collectionOverrides?.admin || {}),
|
||||
},
|
||||
fields,
|
||||
|
||||
Reference in New Issue
Block a user