mirror of
https://github.com/xtr-dev/payload-feature-flags.git
synced 2025-12-11 11:23:24 +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",
|
"name": "payload-feature-flags",
|
||||||
"version": "1.0.0",
|
"version": "0.0.17",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "payload-feature-flags",
|
"name": "payload-feature-flags",
|
||||||
"version": "1.0.0",
|
"version": "0.0.17",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/eslintrc": "^3.2.0",
|
"@eslint/eslintrc": "^3.2.0",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@xtr-dev/payload-feature-flags",
|
"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",
|
"description": "Feature flags plugin for Payload CMS - manage feature toggles, A/B tests, and gradual rollouts",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|||||||
@@ -21,23 +21,31 @@ export interface FeatureFlagOptions {
|
|||||||
|
|
||||||
// Helper to get config from options or defaults
|
// Helper to get config from options or defaults
|
||||||
function getConfig(options?: FeatureFlagOptions) {
|
function getConfig(options?: FeatureFlagOptions) {
|
||||||
// In server-side environments, serverURL must be explicitly provided
|
// Check if serverURL is explicitly provided
|
||||||
const serverURL = options?.serverURL ||
|
if (options?.serverURL) {
|
||||||
(typeof window !== 'undefined' ? window.location.origin : undefined)
|
return {
|
||||||
|
serverURL: options.serverURL,
|
||||||
if (!serverURL) {
|
apiPath: options.apiPath || '/api',
|
||||||
console.warn(
|
collectionSlug: options.collectionSlug || 'feature-flags'
|
||||||
'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' }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const apiPath = options?.apiPath || '/api'
|
// In browser environment, use window.location.origin
|
||||||
const collectionSlug = options?.collectionSlug || 'feature-flags'
|
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
|
* Override collection configuration
|
||||||
*/
|
*/
|
||||||
collectionOverrides?: CollectionOverrides
|
collectionOverrides?: CollectionOverrides
|
||||||
|
/**
|
||||||
|
* Enable custom list view for feature flags
|
||||||
|
* @default false
|
||||||
|
*/
|
||||||
|
enableCustomListView?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export const payloadFeatureFlags =
|
export const payloadFeatureFlags =
|
||||||
@@ -44,6 +49,7 @@ export const payloadFeatureFlags =
|
|||||||
defaultValue = false,
|
defaultValue = false,
|
||||||
enableRollouts = true,
|
enableRollouts = true,
|
||||||
enableVariants = true,
|
enableVariants = true,
|
||||||
|
enableCustomListView = false,
|
||||||
collectionOverrides,
|
collectionOverrides,
|
||||||
} = pluginOptions
|
} = pluginOptions
|
||||||
|
|
||||||
@@ -163,6 +169,15 @@ export const payloadFeatureFlags =
|
|||||||
useAsTitle: 'name',
|
useAsTitle: 'name',
|
||||||
group: 'Configuration',
|
group: 'Configuration',
|
||||||
description: 'Manage feature flags for your application',
|
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 || {}),
|
...(collectionOverrides?.admin || {}),
|
||||||
},
|
},
|
||||||
fields,
|
fields,
|
||||||
|
|||||||
Reference in New Issue
Block a user