@sanity/personalization-plugin 2.5.0-launch-darkly.1 → 2.5.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/personalization-plugin",
3
- "version": "2.5.0-launch-darkly.1",
3
+ "version": "2.5.0",
4
4
  "description": "Plugin to help with personalization, a/b testing when using Sanity",
5
5
  "keywords": [
6
6
  "sanity",
@@ -54,43 +54,43 @@
54
54
  "prepare": "husky"
55
55
  },
56
56
  "dependencies": {
57
- "@sanity/incompatible-plugin": "^1.0.4",
58
- "@sanity/studio-secrets": "^3.0.1",
59
- "@sanity/ui": "^2.8.19",
57
+ "@sanity/incompatible-plugin": "^1.0.5",
58
+ "@sanity/studio-secrets": "^3.0.2",
59
+ "@sanity/ui": "^2.16.12",
60
60
  "@sanity/uuid": "^3.0.2",
61
61
  "fast-deep-equal": "^3.1.3",
62
- "react-icons": "^5.4.0",
62
+ "react-icons": "^5.5.0",
63
63
  "suspend-react": "^0.1.3"
64
64
  },
65
65
  "devDependencies": {
66
- "@commitlint/cli": "^19.7.1",
67
- "@commitlint/config-conventional": "^19.7.1",
66
+ "@commitlint/cli": "^19.8.1",
67
+ "@commitlint/config-conventional": "^19.8.1",
68
68
  "@sanity/pkg-utils": "^6.13.4",
69
69
  "@sanity/plugin-kit": "^4.0.19",
70
70
  "@sanity/semantic-release-preset": "^5.0.0",
71
- "@types/react": "^18.3.18",
72
- "@typescript-eslint/eslint-plugin": "^8.23.0",
73
- "@typescript-eslint/parser": "^8.23.0",
71
+ "@types/react": "^18.3.23",
72
+ "@typescript-eslint/eslint-plugin": "^8.39.1",
73
+ "@typescript-eslint/parser": "^8.39.1",
74
74
  "eslint": "^8.57.1",
75
- "eslint-config-prettier": "^9.1.0",
75
+ "eslint-config-prettier": "^9.1.2",
76
76
  "eslint-config-sanity": "^7.1.4",
77
- "eslint-plugin-prettier": "^5.2.3",
78
- "eslint-plugin-react": "^7.37.4",
79
- "eslint-plugin-react-hooks": "^5.1.0",
77
+ "eslint-plugin-prettier": "^5.5.4",
78
+ "eslint-plugin-react": "^7.37.5",
79
+ "eslint-plugin-react-hooks": "^5.2.0",
80
80
  "husky": "^9.1.7",
81
81
  "lint-staged": "^15.2.10",
82
- "prettier": "^3.4.2",
83
- "prettier-plugin-packagejson": "^2.5.8",
84
- "react": "^18.3.1",
85
- "react-dom": "^18.3.1",
86
- "sanity": "^3.74.1",
87
- "semantic-release": "^24.2.1",
88
- "styled-components": "^6.1.15",
89
- "typescript": "^5.7.3"
82
+ "prettier": "^3.6.2",
83
+ "prettier-plugin-packagejson": "^2.5.19",
84
+ "react": "^19.2.3",
85
+ "react-dom": "^19.2.3",
86
+ "sanity": "^5.0.1",
87
+ "semantic-release": "^24.2.7",
88
+ "styled-components": "^6.1.19",
89
+ "typescript": "^5.9.2"
90
90
  },
91
91
  "peerDependencies": {
92
92
  "react": "^18 || ^19",
93
- "sanity": "^3 || ^4.0.0-0"
93
+ "sanity": "^3 || ^4.0.0-0 || ^5.0.0"
94
94
  },
95
95
  "engines": {
96
96
  "node": ">=18"
@@ -0,0 +1,10 @@
1
+ import {ObjectItem, ObjectItemProps, set} from 'sanity'
2
+
3
+ export const ExperimentItem = (props: ObjectItemProps) => {
4
+ const {active} = props.value as ObjectItem & {active: boolean}
5
+ if (!active) {
6
+ props.inputProps.onChange(set(true, ['active']))
7
+ }
8
+
9
+ return props.renderDefault(props)
10
+ }
@@ -2,7 +2,8 @@ import {Button, Inline, Stack} from '@sanity/ui'
2
2
  import {ObjectInputProps, set, useFormValue} from 'sanity'
3
3
 
4
4
  export const VariantInput = (props: ObjectInputProps) => {
5
- const defaultValue = useFormValue([props.path[0], 'default'])
5
+ const experimentPath = props.path.slice(0, -2)
6
+ const defaultValue = useFormValue([...experimentPath, 'default'])
6
7
  const handleClick = () => {
7
8
  props.onChange(set(defaultValue, ['value']))
8
9
  }
@@ -11,6 +11,7 @@ import {ArrayInput} from './components/Array'
11
11
  import {CONFIG_DEFAULT, ExperimentProvider} from './components/ExperimentContext'
12
12
  import {ExperimentField} from './components/ExperimentField'
13
13
  import {ExperimentInput} from './components/ExperimentInput'
14
+ import {ExperimentItem} from './components/ExperimentItem'
14
15
  import {VariantInput} from './components/VariantInput'
15
16
  import {VariantPreview} from './components/VariantPreview'
16
17
  import {FieldPluginConfig} from './types'
@@ -47,6 +48,7 @@ const createExperimentType = ({
47
48
  variantNameOverride={variantNameOverride}
48
49
  />
49
50
  ),
51
+ item: ExperimentItem,
50
52
  },
51
53
  fields: [
52
54
  typeof field === `string`
@@ -112,7 +114,7 @@ const createExperimentType = ({
112
114
  experiment: experimentId,
113
115
  },
114
116
  prepare: ({base, experiment}) => {
115
- const title = base?.title || base?.name || ''
117
+ const title = base?.title || base?.name || typeof base === 'string' ? base : ''
116
118
  const experimentTitle = experiment ? `Experiment: ${experiment}` : ''
117
119
  const media = base?.image || base?.photo || base?.media || ''
118
120
  return {
@@ -1,76 +0,0 @@
1
- # @sanity/personalization-plugin - launchDarklyFieldLevel
2
-
3
- ## Previously know as @sanity/personalisation-plugin
4
-
5
- > This is a **Sanity Studio v3** plugin.
6
-
7
- This plugin allows users to add a/b/n testing experiments to individual fields connecting to the [LaunchDarkly](https://launchdarkly.com//) A/B testing service.
8
-
9
- - [@sanity/personalization-plugin - launchDarklyFieldLevel](#sanitypersonalization-plugin---launchDarklyFieldLevel)
10
- - [Installation](#installation)
11
- - [Usage](#usage)
12
- - [Loading Experiments](#loading-experiments)
13
-
14
- This plugin is built on top of the `fieldLevelExperiments` export so see the main readme for details of:
15
-
16
- - [Using complex field configurations](/#using-complex-field-configurations)
17
- - [Validation of individual array items](/#validation-of-individual-array-items)
18
- - [Shape of stored data](/#shape-of-stored-data)
19
- - [Querying data](/#querying-data)
20
- - [License](#license)
21
- - [Develop \& test](#develop--test)
22
- - [Release new version](#release-new-version)
23
- - [License](#license-1)
24
-
25
- ## Installation
26
-
27
- ```sh
28
- npm install @sanity/personalization-plugin
29
- ```
30
-
31
- ## Usage
32
-
33
- Add it as a plugin in `sanity.config.ts` (or .js):
34
-
35
- ```ts
36
- import {defineConfig} from 'sanity'
37
- import {fieldLevelExperiments} from '@sanity/personalization-plugin/launchDarkly'
38
-
39
- export default defineConfig({
40
- //...
41
- plugins: [
42
- //...
43
- launchDarklyFieldLevel({
44
- fields: ['string'],
45
- projectKey: 'string', // required filter parameter for fetching features/variants
46
- tags: ['string'] //optional parameter that filters the list to flags that have all of the tags in the list
47
- }),
48
- ],
49
- })
50
- ```
51
-
52
- This will register two new fields to the schema., based on the setting passed into `fields:`
53
-
54
- - `flagString` an Object field with `string` field called `default`, a `string` field called `flagId` and an array field of type:
55
- - `variantsString` an object field with a `string` field called `value`, a string field called `variantId`, a `string` field called `flagId`.
56
-
57
- Use the flag field in your schema like this:
58
-
59
- ```ts
60
- //for Example in post.ts
61
-
62
- fields: [
63
- defineField({
64
- name: 'title',
65
- type: 'flagString',
66
- }),
67
- ]
68
- ```
69
-
70
- ## Loading Experiments
71
-
72
- This plugin uses [@sanity/studio-secrets](https://www.npmjs.com/package/@sanity/studio-secrets) for storing your Launch Darkly API key. The first time you open a document that has an experiment you will be asked to provide your API key. This is stored in a private document on the dataset.
73
-
74
- Once you have entered you API key the plugin will fetch feature flags and variants flags. If features/variants are updated on LaunchDarkly you will need to refresh the page.
75
-
76
- The values stored for an flag will be the Feature Key amd the variants will stored the variation value.