@sanity/personalization-plugin 2.1.0-field-names.1 → 2.1.0-growthbook.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 CHANGED
@@ -25,6 +25,8 @@ Once configured you can query the values using the ids of the experiment and var
25
25
  - [Release new version](#release-new-version)
26
26
  - [License](#license-1)
27
27
 
28
+ For Specific information about the growthbookFieldLevel export see its [readme](/growthbook.md)
29
+
28
30
  ## Installation
29
31
 
30
32
  ```sh
@@ -143,23 +145,21 @@ experiments: async () => {
143
145
  const response = await fetch('https://example.com/experiments')
144
146
  const {externalExperiments} = await response.json()
145
147
 
146
- const experiments: ExperimentType[] = externalExperiments?.map(
147
- (experiment) => {
148
- const experimentId = experiment.id
149
- const experimentLabel = experiment.name
150
- const variants = experiment.variations?.map((variant) => {
151
- return {
152
- id: variant.variationId,
153
- label: variant.name,
154
- }
155
- })
148
+ const experiments: ExperimentType[] = externalExperiments?.map((experiment) => {
149
+ const experimentId = experiment.id
150
+ const experimentLabel = experiment.name
151
+ const variants = experiment.variations?.map((variant) => {
156
152
  return {
157
- id: experimentId,
158
- label: experimentLabel,
159
- variants,
153
+ id: variant.variationId,
154
+ label: variant.name,
160
155
  }
161
- },
162
- )
156
+ })
157
+ return {
158
+ id: experimentId,
159
+ label: experimentLabel,
160
+ variants,
161
+ }
162
+ })
163
163
  return experiments
164
164
  }
165
165
  ```
package/dist/index.d.mts CHANGED
@@ -1,4 +1,5 @@
1
1
  import {ArrayOfObjectsInputProps} from 'sanity'
2
+ import {Dispatch} from 'react'
2
3
  import {FieldDefinition} from 'sanity'
3
4
  import {ObjectField} from 'sanity'
4
5
  import {Path} from 'sanity'
@@ -6,30 +7,27 @@ import {Plugin as Plugin_2} from 'sanity'
6
7
  import {PreviewProps} from 'sanity'
7
8
  import {SanityClient} from 'sanity'
8
9
  import {SchemaType} from 'sanity'
10
+ import {SetStateAction} from 'react'
9
11
 
10
12
  export declare type ArrayInputProps = ArrayOfObjectsInputProps & {
11
- variantName: string
12
- variantId: string
13
- experimentId: string
13
+ objectName: string
14
14
  }
15
15
 
16
16
  export declare type ExperimentContextProps = Required<FieldPluginConfig> & {
17
17
  experiments: ExperimentType[]
18
+ setSecret: Dispatch<SetStateAction<string | undefined>>
19
+ secret: string | undefined
18
20
  }
19
21
 
20
22
  export declare type ExperimentGeneric<T> = {
21
23
  _type: string
22
24
  default?: T
23
25
  experimentValue?: string
24
- [key: string]:
25
- | Array<
26
- {
27
- _key: string
28
- } & VariantGeneric<T>
29
- >
30
- | string
31
- | T
32
- | undefined
26
+ variants?: Array<
27
+ {
28
+ _key: string
29
+ } & VariantGeneric<T>
30
+ >
33
31
  }
34
32
 
35
33
  export declare type ExperimentType = {
@@ -42,13 +40,10 @@ export declare const fieldLevelExperiments: Plugin_2<FieldPluginConfig>
42
40
 
43
41
  export declare type FieldPluginConfig = {
44
42
  fields: (string | FieldDefinition)[]
45
- experiments: ExperimentType[] | ((client: SanityClient) => Promise<ExperimentType[]>)
43
+ experiments:
44
+ | ExperimentType[]
45
+ | ((client: SanityClient, secret?: string) => Promise<ExperimentType[]>)
46
46
  apiVersion?: string
47
- experimentNameOverride?: string
48
- variantNameOverride?: string
49
- variantId?: string
50
- variantArrayName?: string
51
- experimentId?: string
52
47
  }
53
48
 
54
49
  /**
@@ -56,18 +51,218 @@ export declare type FieldPluginConfig = {
56
51
  */
57
52
  export declare function flattenSchemaType(schemaType: SchemaType): ObjectFieldWithPath[]
58
53
 
54
+ export declare type GrowthbookABConfig = {
55
+ fields: (string | FieldDefinition)[]
56
+ environment: string
57
+ baseUrl?: string
58
+ project?: string
59
+ convertBooleans?: boolean
60
+ }
61
+
62
+ export declare type GrowthbookExperiment = {
63
+ id: string
64
+ dateCreated: string
65
+ dateUpdated: string
66
+ name: string
67
+ project: string
68
+ hypothesis: string
69
+ description: string
70
+ tags: [string]
71
+ owner: string
72
+ archived: boolean
73
+ status: string
74
+ autoRefresh: boolean
75
+ hashAttribute: string
76
+ fallbackAttribute: string
77
+ hashVersion: number
78
+ disableStickyBucketing: boolean
79
+ bucketVersion: number
80
+ minBucketVersion: number
81
+ variations: [
82
+ {
83
+ variationId: string
84
+ key: string
85
+ name: string
86
+ description: string
87
+ screenshots: [string]
88
+ },
89
+ ]
90
+ phases: [
91
+ {
92
+ name: string
93
+ dateStarted: string
94
+ dateEnded: string
95
+ reasonForStopping: string
96
+ seed: string
97
+ coverage: 0
98
+ trafficSplit: [
99
+ {
100
+ variationId: string
101
+ weight: 0
102
+ },
103
+ ]
104
+ namespace: {
105
+ namespaceId: string
106
+ range: []
107
+ }
108
+ targetingCondition: string
109
+ savedGroupTargeting: [
110
+ {
111
+ matchType: string
112
+ savedGroups: [string]
113
+ },
114
+ ]
115
+ },
116
+ ]
117
+ settings: {
118
+ datasourceId: string
119
+ assignmentQueryId: string
120
+ experimentId: string
121
+ segmentId: string
122
+ queryFilter: string
123
+ inProgressConversions: string
124
+ attributionModel: string
125
+ statsEngine: string
126
+ regressionAdjustmentEnabled: boolean
127
+ goals: [
128
+ {
129
+ metricId: string
130
+ overrides: {
131
+ delayHours: 0
132
+ windowHours: 0
133
+ window: string
134
+ winRiskThreshold: 0
135
+ loseRiskThreshold: 0
136
+ }
137
+ },
138
+ ]
139
+ secondaryMetrics: [
140
+ {
141
+ metricId: string
142
+ overrides: {
143
+ delayHours: 0
144
+ windowHours: 0
145
+ window: string
146
+ winRiskThreshold: 0
147
+ loseRiskThreshold: 0
148
+ }
149
+ },
150
+ ]
151
+ guardrails: [
152
+ {
153
+ metricId: string
154
+ overrides: {
155
+ delayHours: 0
156
+ windowHours: 0
157
+ window: string
158
+ winRiskThreshold: 0
159
+ loseRiskThreshold: 0
160
+ }
161
+ },
162
+ ]
163
+ activationMetric: {
164
+ metricId: string
165
+ overrides: {
166
+ delayHours: 0
167
+ windowHours: 0
168
+ window: string
169
+ winRiskThreshold: 0
170
+ loseRiskThreshold: 0
171
+ }
172
+ }
173
+ }
174
+ resultSummary: {
175
+ status: string
176
+ winner: string
177
+ conclusions: string
178
+ releasedVariationId: string
179
+ excludeFromPayload: boolean
180
+ }
181
+ }
182
+
183
+ export declare type GrowthbookFeature = {
184
+ id: string
185
+ dateCreated: string
186
+ dateUpdated: string
187
+ archived: boolean
188
+ description: string
189
+ owner: string
190
+ project: string
191
+ valueType: string
192
+ defaultValue: string
193
+ tags: string[]
194
+ environments: {
195
+ [key: string]: {
196
+ enabled: boolean
197
+ defaultValue: string
198
+ rules: {
199
+ description: string
200
+ condition: string
201
+ savedGroupTargeting: {
202
+ matchType: string
203
+ savedGroups: string[]
204
+ }[]
205
+ id: string
206
+ enabled: boolean
207
+ type: string
208
+ value: string
209
+ variations: {
210
+ value: string
211
+ variationId: string
212
+ }[]
213
+ }[]
214
+ definition: string
215
+ draft: {
216
+ enabled: boolean
217
+ defaultValue: string
218
+ rules: {
219
+ description: string
220
+ condition: string
221
+ savedGroupTargeting: {
222
+ matchType: string
223
+ savedGroups: string[]
224
+ }[]
225
+ id: string
226
+ enabled: boolean
227
+ type: string
228
+ value: string
229
+ variations: {
230
+ value: string
231
+ variationId: string
232
+ }[]
233
+ }[]
234
+ definition: string
235
+ }
236
+ }
237
+ }
238
+ prerequisites: {
239
+ parentId: string
240
+ parentCondition: string
241
+ }[]
242
+ revision: {
243
+ version: number
244
+ comment: string
245
+ date: string
246
+ publishedBy: string
247
+ }
248
+ }
249
+
250
+ export declare const growthbookFieldLevel: Plugin_2<GrowthbookABConfig>
251
+
59
252
  export declare type ObjectFieldWithPath = ObjectField<SchemaType> & {
60
253
  path: Path
61
254
  }
62
255
 
63
256
  export declare type VariantGeneric<T> = {
64
- [key: string]: string | T | undefined
65
257
  _type: string
258
+ variantId?: string
259
+ experimentId?: string
66
260
  value?: T
67
261
  }
68
262
 
69
263
  export declare type VariantPreviewProps = Omit<PreviewProps, 'SchemaType'> & {
70
- [key: string]: string
264
+ experiment: string
265
+ variant: string
71
266
  value: any
72
267
  }
73
268
 
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import {ArrayOfObjectsInputProps} from 'sanity'
2
+ import {Dispatch} from 'react'
2
3
  import {FieldDefinition} from 'sanity'
3
4
  import {ObjectField} from 'sanity'
4
5
  import {Path} from 'sanity'
@@ -6,30 +7,27 @@ import {Plugin as Plugin_2} from 'sanity'
6
7
  import {PreviewProps} from 'sanity'
7
8
  import {SanityClient} from 'sanity'
8
9
  import {SchemaType} from 'sanity'
10
+ import {SetStateAction} from 'react'
9
11
 
10
12
  export declare type ArrayInputProps = ArrayOfObjectsInputProps & {
11
- variantName: string
12
- variantId: string
13
- experimentId: string
13
+ objectName: string
14
14
  }
15
15
 
16
16
  export declare type ExperimentContextProps = Required<FieldPluginConfig> & {
17
17
  experiments: ExperimentType[]
18
+ setSecret: Dispatch<SetStateAction<string | undefined>>
19
+ secret: string | undefined
18
20
  }
19
21
 
20
22
  export declare type ExperimentGeneric<T> = {
21
23
  _type: string
22
24
  default?: T
23
25
  experimentValue?: string
24
- [key: string]:
25
- | Array<
26
- {
27
- _key: string
28
- } & VariantGeneric<T>
29
- >
30
- | string
31
- | T
32
- | undefined
26
+ variants?: Array<
27
+ {
28
+ _key: string
29
+ } & VariantGeneric<T>
30
+ >
33
31
  }
34
32
 
35
33
  export declare type ExperimentType = {
@@ -42,13 +40,10 @@ export declare const fieldLevelExperiments: Plugin_2<FieldPluginConfig>
42
40
 
43
41
  export declare type FieldPluginConfig = {
44
42
  fields: (string | FieldDefinition)[]
45
- experiments: ExperimentType[] | ((client: SanityClient) => Promise<ExperimentType[]>)
43
+ experiments:
44
+ | ExperimentType[]
45
+ | ((client: SanityClient, secret?: string) => Promise<ExperimentType[]>)
46
46
  apiVersion?: string
47
- experimentNameOverride?: string
48
- variantNameOverride?: string
49
- variantId?: string
50
- variantArrayName?: string
51
- experimentId?: string
52
47
  }
53
48
 
54
49
  /**
@@ -56,18 +51,218 @@ export declare type FieldPluginConfig = {
56
51
  */
57
52
  export declare function flattenSchemaType(schemaType: SchemaType): ObjectFieldWithPath[]
58
53
 
54
+ export declare type GrowthbookABConfig = {
55
+ fields: (string | FieldDefinition)[]
56
+ environment: string
57
+ baseUrl?: string
58
+ project?: string
59
+ convertBooleans?: boolean
60
+ }
61
+
62
+ export declare type GrowthbookExperiment = {
63
+ id: string
64
+ dateCreated: string
65
+ dateUpdated: string
66
+ name: string
67
+ project: string
68
+ hypothesis: string
69
+ description: string
70
+ tags: [string]
71
+ owner: string
72
+ archived: boolean
73
+ status: string
74
+ autoRefresh: boolean
75
+ hashAttribute: string
76
+ fallbackAttribute: string
77
+ hashVersion: number
78
+ disableStickyBucketing: boolean
79
+ bucketVersion: number
80
+ minBucketVersion: number
81
+ variations: [
82
+ {
83
+ variationId: string
84
+ key: string
85
+ name: string
86
+ description: string
87
+ screenshots: [string]
88
+ },
89
+ ]
90
+ phases: [
91
+ {
92
+ name: string
93
+ dateStarted: string
94
+ dateEnded: string
95
+ reasonForStopping: string
96
+ seed: string
97
+ coverage: 0
98
+ trafficSplit: [
99
+ {
100
+ variationId: string
101
+ weight: 0
102
+ },
103
+ ]
104
+ namespace: {
105
+ namespaceId: string
106
+ range: []
107
+ }
108
+ targetingCondition: string
109
+ savedGroupTargeting: [
110
+ {
111
+ matchType: string
112
+ savedGroups: [string]
113
+ },
114
+ ]
115
+ },
116
+ ]
117
+ settings: {
118
+ datasourceId: string
119
+ assignmentQueryId: string
120
+ experimentId: string
121
+ segmentId: string
122
+ queryFilter: string
123
+ inProgressConversions: string
124
+ attributionModel: string
125
+ statsEngine: string
126
+ regressionAdjustmentEnabled: boolean
127
+ goals: [
128
+ {
129
+ metricId: string
130
+ overrides: {
131
+ delayHours: 0
132
+ windowHours: 0
133
+ window: string
134
+ winRiskThreshold: 0
135
+ loseRiskThreshold: 0
136
+ }
137
+ },
138
+ ]
139
+ secondaryMetrics: [
140
+ {
141
+ metricId: string
142
+ overrides: {
143
+ delayHours: 0
144
+ windowHours: 0
145
+ window: string
146
+ winRiskThreshold: 0
147
+ loseRiskThreshold: 0
148
+ }
149
+ },
150
+ ]
151
+ guardrails: [
152
+ {
153
+ metricId: string
154
+ overrides: {
155
+ delayHours: 0
156
+ windowHours: 0
157
+ window: string
158
+ winRiskThreshold: 0
159
+ loseRiskThreshold: 0
160
+ }
161
+ },
162
+ ]
163
+ activationMetric: {
164
+ metricId: string
165
+ overrides: {
166
+ delayHours: 0
167
+ windowHours: 0
168
+ window: string
169
+ winRiskThreshold: 0
170
+ loseRiskThreshold: 0
171
+ }
172
+ }
173
+ }
174
+ resultSummary: {
175
+ status: string
176
+ winner: string
177
+ conclusions: string
178
+ releasedVariationId: string
179
+ excludeFromPayload: boolean
180
+ }
181
+ }
182
+
183
+ export declare type GrowthbookFeature = {
184
+ id: string
185
+ dateCreated: string
186
+ dateUpdated: string
187
+ archived: boolean
188
+ description: string
189
+ owner: string
190
+ project: string
191
+ valueType: string
192
+ defaultValue: string
193
+ tags: string[]
194
+ environments: {
195
+ [key: string]: {
196
+ enabled: boolean
197
+ defaultValue: string
198
+ rules: {
199
+ description: string
200
+ condition: string
201
+ savedGroupTargeting: {
202
+ matchType: string
203
+ savedGroups: string[]
204
+ }[]
205
+ id: string
206
+ enabled: boolean
207
+ type: string
208
+ value: string
209
+ variations: {
210
+ value: string
211
+ variationId: string
212
+ }[]
213
+ }[]
214
+ definition: string
215
+ draft: {
216
+ enabled: boolean
217
+ defaultValue: string
218
+ rules: {
219
+ description: string
220
+ condition: string
221
+ savedGroupTargeting: {
222
+ matchType: string
223
+ savedGroups: string[]
224
+ }[]
225
+ id: string
226
+ enabled: boolean
227
+ type: string
228
+ value: string
229
+ variations: {
230
+ value: string
231
+ variationId: string
232
+ }[]
233
+ }[]
234
+ definition: string
235
+ }
236
+ }
237
+ }
238
+ prerequisites: {
239
+ parentId: string
240
+ parentCondition: string
241
+ }[]
242
+ revision: {
243
+ version: number
244
+ comment: string
245
+ date: string
246
+ publishedBy: string
247
+ }
248
+ }
249
+
250
+ export declare const growthbookFieldLevel: Plugin_2<GrowthbookABConfig>
251
+
59
252
  export declare type ObjectFieldWithPath = ObjectField<SchemaType> & {
60
253
  path: Path
61
254
  }
62
255
 
63
256
  export declare type VariantGeneric<T> = {
64
- [key: string]: string | T | undefined
65
257
  _type: string
258
+ variantId?: string
259
+ experimentId?: string
66
260
  value?: T
67
261
  }
68
262
 
69
263
  export declare type VariantPreviewProps = Omit<PreviewProps, 'SchemaType'> & {
70
- [key: string]: string
264
+ experiment: string
265
+ variant: string
71
266
  value: any
72
267
  }
73
268