@sanity/personalization-plugin 2.2.0 → 2.3.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 +2 -0
- package/dist/growthbook/index.d.mts +15 -0
- package/dist/growthbook/index.d.ts +15 -0
- package/dist/growthbook/index.js +118 -0
- package/dist/growthbook/index.js.map +1 -0
- package/dist/growthbook/index.mjs +122 -0
- package/dist/growthbook/index.mjs.map +1 -0
- package/dist/index.d.mts +191 -1
- package/dist/index.d.ts +191 -1
- package/dist/index.js +37 -22
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +37 -22
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -1
- package/src/components/ExperimentField.tsx +56 -32
- package/src/components/ExperimentInput.tsx +2 -2
- package/src/fieldExperiments.tsx +1 -0
- package/src/growthbook/Components/GrowthbookContext.tsx +38 -0
- package/src/growthbook/Components/Secrets.tsx +47 -0
- package/src/growthbook/index.ts +52 -0
- package/src/growthbook/types.ts +15 -0
- package/src/growthbook/utils.ts +94 -0
- package/src/types.ts +179 -1
package/dist/index.d.ts
CHANGED
|
@@ -42,7 +42,9 @@ export declare const fieldLevelExperiments: Plugin_2<FieldPluginConfig>
|
|
|
42
42
|
|
|
43
43
|
export declare type FieldPluginConfig = {
|
|
44
44
|
fields: (string | FieldDefinition)[]
|
|
45
|
-
experiments:
|
|
45
|
+
experiments:
|
|
46
|
+
| ExperimentType[]
|
|
47
|
+
| ((client: SanityClient, secret?: string) => Promise<ExperimentType[]>)
|
|
46
48
|
apiVersion?: string
|
|
47
49
|
experimentNameOverride?: string
|
|
48
50
|
variantNameOverride?: string
|
|
@@ -56,6 +58,194 @@ export declare type FieldPluginConfig = {
|
|
|
56
58
|
*/
|
|
57
59
|
export declare function flattenSchemaType(schemaType: SchemaType): ObjectFieldWithPath[]
|
|
58
60
|
|
|
61
|
+
export declare type GrowthbookExperiment = {
|
|
62
|
+
id: string
|
|
63
|
+
dateCreated: string
|
|
64
|
+
dateUpdated: string
|
|
65
|
+
name: string
|
|
66
|
+
project: string
|
|
67
|
+
hypothesis: string
|
|
68
|
+
description: string
|
|
69
|
+
tags: [string]
|
|
70
|
+
owner: string
|
|
71
|
+
archived: boolean
|
|
72
|
+
status: string
|
|
73
|
+
autoRefresh: boolean
|
|
74
|
+
hashAttribute: string
|
|
75
|
+
fallbackAttribute: string
|
|
76
|
+
hashVersion: number
|
|
77
|
+
disableStickyBucketing: boolean
|
|
78
|
+
bucketVersion: number
|
|
79
|
+
minBucketVersion: number
|
|
80
|
+
variations: [
|
|
81
|
+
{
|
|
82
|
+
variationId: string
|
|
83
|
+
key: string
|
|
84
|
+
name: string
|
|
85
|
+
description: string
|
|
86
|
+
screenshots: [string]
|
|
87
|
+
},
|
|
88
|
+
]
|
|
89
|
+
phases: [
|
|
90
|
+
{
|
|
91
|
+
name: string
|
|
92
|
+
dateStarted: string
|
|
93
|
+
dateEnded: string
|
|
94
|
+
reasonForStopping: string
|
|
95
|
+
seed: string
|
|
96
|
+
coverage: 0
|
|
97
|
+
trafficSplit: [
|
|
98
|
+
{
|
|
99
|
+
variationId: string
|
|
100
|
+
weight: 0
|
|
101
|
+
},
|
|
102
|
+
]
|
|
103
|
+
namespace: {
|
|
104
|
+
namespaceId: string
|
|
105
|
+
range: []
|
|
106
|
+
}
|
|
107
|
+
targetingCondition: string
|
|
108
|
+
savedGroupTargeting: [
|
|
109
|
+
{
|
|
110
|
+
matchType: string
|
|
111
|
+
savedGroups: [string]
|
|
112
|
+
},
|
|
113
|
+
]
|
|
114
|
+
},
|
|
115
|
+
]
|
|
116
|
+
settings: {
|
|
117
|
+
datasourceId: string
|
|
118
|
+
assignmentQueryId: string
|
|
119
|
+
experimentId: string
|
|
120
|
+
segmentId: string
|
|
121
|
+
queryFilter: string
|
|
122
|
+
inProgressConversions: string
|
|
123
|
+
attributionModel: string
|
|
124
|
+
statsEngine: string
|
|
125
|
+
regressionAdjustmentEnabled: boolean
|
|
126
|
+
goals: [
|
|
127
|
+
{
|
|
128
|
+
metricId: string
|
|
129
|
+
overrides: {
|
|
130
|
+
delayHours: 0
|
|
131
|
+
windowHours: 0
|
|
132
|
+
window: string
|
|
133
|
+
winRiskThreshold: 0
|
|
134
|
+
loseRiskThreshold: 0
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
]
|
|
138
|
+
secondaryMetrics: [
|
|
139
|
+
{
|
|
140
|
+
metricId: string
|
|
141
|
+
overrides: {
|
|
142
|
+
delayHours: 0
|
|
143
|
+
windowHours: 0
|
|
144
|
+
window: string
|
|
145
|
+
winRiskThreshold: 0
|
|
146
|
+
loseRiskThreshold: 0
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
]
|
|
150
|
+
guardrails: [
|
|
151
|
+
{
|
|
152
|
+
metricId: string
|
|
153
|
+
overrides: {
|
|
154
|
+
delayHours: 0
|
|
155
|
+
windowHours: 0
|
|
156
|
+
window: string
|
|
157
|
+
winRiskThreshold: 0
|
|
158
|
+
loseRiskThreshold: 0
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
]
|
|
162
|
+
activationMetric: {
|
|
163
|
+
metricId: string
|
|
164
|
+
overrides: {
|
|
165
|
+
delayHours: 0
|
|
166
|
+
windowHours: 0
|
|
167
|
+
window: string
|
|
168
|
+
winRiskThreshold: 0
|
|
169
|
+
loseRiskThreshold: 0
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
resultSummary: {
|
|
174
|
+
status: string
|
|
175
|
+
winner: string
|
|
176
|
+
conclusions: string
|
|
177
|
+
releasedVariationId: string
|
|
178
|
+
excludeFromPayload: boolean
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export declare type GrowthbookFeature = {
|
|
183
|
+
id: string
|
|
184
|
+
dateCreated: string
|
|
185
|
+
dateUpdated: string
|
|
186
|
+
archived: boolean
|
|
187
|
+
description: string
|
|
188
|
+
owner: string
|
|
189
|
+
project: string
|
|
190
|
+
valueType: string
|
|
191
|
+
defaultValue: string
|
|
192
|
+
tags: string[]
|
|
193
|
+
environments: {
|
|
194
|
+
[key: string]: {
|
|
195
|
+
enabled: boolean
|
|
196
|
+
defaultValue: string
|
|
197
|
+
rules: {
|
|
198
|
+
description: string
|
|
199
|
+
condition: string
|
|
200
|
+
savedGroupTargeting: {
|
|
201
|
+
matchType: string
|
|
202
|
+
savedGroups: string[]
|
|
203
|
+
}[]
|
|
204
|
+
id: string
|
|
205
|
+
enabled: boolean
|
|
206
|
+
type: string
|
|
207
|
+
value: string
|
|
208
|
+
variations: {
|
|
209
|
+
value: string
|
|
210
|
+
variationId: string
|
|
211
|
+
}[]
|
|
212
|
+
}[]
|
|
213
|
+
definition: string
|
|
214
|
+
draft: {
|
|
215
|
+
enabled: boolean
|
|
216
|
+
defaultValue: string
|
|
217
|
+
rules: {
|
|
218
|
+
description: string
|
|
219
|
+
condition: string
|
|
220
|
+
savedGroupTargeting: {
|
|
221
|
+
matchType: string
|
|
222
|
+
savedGroups: string[]
|
|
223
|
+
}[]
|
|
224
|
+
id: string
|
|
225
|
+
enabled: boolean
|
|
226
|
+
type: string
|
|
227
|
+
value: string
|
|
228
|
+
variations: {
|
|
229
|
+
value: string
|
|
230
|
+
variationId: string
|
|
231
|
+
}[]
|
|
232
|
+
}[]
|
|
233
|
+
definition: string
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
prerequisites: {
|
|
238
|
+
parentId: string
|
|
239
|
+
parentCondition: string
|
|
240
|
+
}[]
|
|
241
|
+
revision: {
|
|
242
|
+
version: number
|
|
243
|
+
comment: string
|
|
244
|
+
date: string
|
|
245
|
+
publishedBy: string
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
59
249
|
export declare type ObjectFieldWithPath = ObjectField<SchemaType> & {
|
|
60
250
|
path: Path
|
|
61
251
|
}
|
package/dist/index.js
CHANGED
|
@@ -6405,9 +6405,9 @@ const icons = {
|
|
|
6405
6405
|
});
|
|
6406
6406
|
Icon.displayName = "ForwardRef(Icon)";
|
|
6407
6407
|
const useAddExperimentAction = (props) => {
|
|
6408
|
-
const { onChange, experimentNameOverride } = props, handleAddAction = () => {
|
|
6409
|
-
onChange([sanity.set(!
|
|
6410
|
-
};
|
|
6408
|
+
const { onChange, active, experimentNameOverride } = props, handleAddAction = react.useCallback(() => {
|
|
6409
|
+
onChange([sanity.set(!active, ["active"])]);
|
|
6410
|
+
}, [onChange, active]);
|
|
6411
6411
|
return {
|
|
6412
6412
|
title: `Add ${experimentNameOverride}`,
|
|
6413
6413
|
type: "action",
|
|
@@ -6416,13 +6416,10 @@ const useAddExperimentAction = (props) => {
|
|
|
6416
6416
|
renderAsButton: !0
|
|
6417
6417
|
};
|
|
6418
6418
|
}, useRemoveExperimentAction = (props) => {
|
|
6419
|
-
const { onChange, experimentId, experimentNameOverride } = props,
|
|
6420
|
-
const experiment = [experimentId], variants = [
|
|
6421
|
-
|
|
6422
|
-
},
|
|
6423
|
-
const clearEvents = patchClearEvent(), activeEvent = patchActiveFalseEvent();
|
|
6424
|
-
onChange([activeEvent, ...clearEvents]);
|
|
6425
|
-
};
|
|
6419
|
+
const { onChange, active, experimentId, experimentNameOverride, variantNameOverride } = props, handleClearAction = react.useCallback(() => {
|
|
6420
|
+
const activeId = ["active"], experiment = [experimentId], variants = [`${variantNameOverride}s`];
|
|
6421
|
+
onChange([sanity.set(!active, activeId), sanity.unset(experiment), sanity.unset(variants)]);
|
|
6422
|
+
}, [onChange, active, experimentId, variantNameOverride]);
|
|
6426
6423
|
return {
|
|
6427
6424
|
title: `Remove ${experimentNameOverride}`,
|
|
6428
6425
|
type: "action",
|
|
@@ -6430,36 +6427,53 @@ const useAddExperimentAction = (props) => {
|
|
|
6430
6427
|
onAction: handleClearAction,
|
|
6431
6428
|
renderAsButton: !0
|
|
6432
6429
|
};
|
|
6433
|
-
},
|
|
6430
|
+
}, createActions = ({
|
|
6434
6431
|
onChange,
|
|
6435
6432
|
inputId,
|
|
6436
6433
|
active,
|
|
6437
6434
|
experimentNameOverride,
|
|
6438
|
-
experimentId
|
|
6435
|
+
experimentId,
|
|
6436
|
+
variantNameOverride
|
|
6439
6437
|
}) => {
|
|
6440
6438
|
const removeAction = sanity.defineDocumentFieldAction({
|
|
6441
6439
|
name: `Remove ${experimentNameOverride}`,
|
|
6442
6440
|
useAction: (props) => useRemoveExperimentAction({
|
|
6441
|
+
active: !0,
|
|
6443
6442
|
onChange,
|
|
6444
6443
|
experimentNameOverride,
|
|
6445
|
-
experimentId
|
|
6444
|
+
experimentId,
|
|
6445
|
+
variantNameOverride
|
|
6446
6446
|
})
|
|
6447
6447
|
}), addAction = sanity.defineDocumentFieldAction({
|
|
6448
6448
|
name: `Add ${experimentNameOverride}`,
|
|
6449
6449
|
useAction: (props) => useAddExperimentAction({
|
|
6450
|
+
active: !1,
|
|
6450
6451
|
onChange,
|
|
6451
6452
|
experimentNameOverride
|
|
6452
6453
|
})
|
|
6453
6454
|
});
|
|
6454
6455
|
return active ? removeAction : addAction;
|
|
6455
6456
|
}, ExperimentField = (props) => {
|
|
6456
|
-
const { onChange } = props.inputProps, { inputId, experimentNameOverride, experimentId } = props, active = props.value?.active,
|
|
6457
|
-
|
|
6458
|
-
|
|
6459
|
-
|
|
6460
|
-
|
|
6461
|
-
|
|
6462
|
-
|
|
6457
|
+
const { onChange } = props.inputProps, { inputId, experimentNameOverride, experimentId, variantNameOverride } = props, active = props.value?.active, actionProps = react.useMemo(
|
|
6458
|
+
() => ({
|
|
6459
|
+
onChange,
|
|
6460
|
+
inputId,
|
|
6461
|
+
active,
|
|
6462
|
+
experimentNameOverride,
|
|
6463
|
+
experimentId,
|
|
6464
|
+
variantNameOverride
|
|
6465
|
+
}),
|
|
6466
|
+
[onChange, inputId, active, experimentNameOverride, experimentId, variantNameOverride]
|
|
6467
|
+
), memoizedActions = react.useMemo(() => {
|
|
6468
|
+
const oldActions = props.actions || [];
|
|
6469
|
+
return [createActions(actionProps), ...oldActions];
|
|
6470
|
+
}, [actionProps, props.actions]), withActionProps = react.useMemo(
|
|
6471
|
+
() => ({
|
|
6472
|
+
...props,
|
|
6473
|
+
actions: memoizedActions
|
|
6474
|
+
}),
|
|
6475
|
+
[props, memoizedActions]
|
|
6476
|
+
);
|
|
6463
6477
|
return props.renderDefault(withActionProps);
|
|
6464
6478
|
}, Select = (props) => {
|
|
6465
6479
|
const {
|
|
@@ -6491,7 +6505,7 @@ const useAddExperimentAction = (props) => {
|
|
|
6491
6505
|
value: experiment.id
|
|
6492
6506
|
})), ExperimentInput = (props) => {
|
|
6493
6507
|
const { experiments } = useExperimentContext(), id = sanity.useFormValue(["_id"]), aditionalChangePath = react.useMemo(
|
|
6494
|
-
() => [...props.path.slice(0, -1), props.variantNameOverride],
|
|
6508
|
+
() => [...props.path.slice(0, -1), `${props.variantNameOverride}s`],
|
|
6495
6509
|
[props.variantNameOverride, props.path]
|
|
6496
6510
|
), subValues = sanity.useFormValue(aditionalChangePath), { patch } = sanity.useDocumentOperation(id.replace("drafts.", ""), props.schemaType.name), handleChange = react.useCallback(
|
|
6497
6511
|
(event, onChange) => {
|
|
@@ -6583,7 +6597,8 @@ const createExperimentType = ({
|
|
|
6583
6597
|
{
|
|
6584
6598
|
...props,
|
|
6585
6599
|
experimentId,
|
|
6586
|
-
experimentNameOverride
|
|
6600
|
+
experimentNameOverride,
|
|
6601
|
+
variantNameOverride
|
|
6587
6602
|
}
|
|
6588
6603
|
)
|
|
6589
6604
|
},
|