@sanity/personalization-plugin 2.3.0-launch-darkly.1 → 2.3.0-launch-darkly.2
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/dist/index.d.mts +0 -194
- package/dist/index.d.ts +0 -194
- package/dist/index.js +43 -103
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +45 -106
- package/dist/index.mjs.map +1 -1
- package/dist/launchDarkly/index.d.mts +12 -0
- package/dist/launchDarkly/index.d.ts +12 -0
- package/dist/launchDarkly/index.js +103 -0
- package/dist/launchDarkly/index.js.map +1 -0
- package/dist/launchDarkly/index.mjs +107 -0
- package/dist/launchDarkly/index.mjs.map +1 -0
- package/package.json +6 -1
- package/src/components/ExperimentContext.tsx +4 -7
- package/src/components/ExperimentField.tsx +54 -28
- package/src/components/ExperimentInput.tsx +2 -2
- package/src/fieldExperiments.tsx +1 -0
- package/src/index.ts +0 -1
- package/src/launchDarkly/components/LaunchDarklyContext.tsx +36 -0
- package/src/{components → launchDarkly/components}/Secrets.tsx +4 -3
- package/src/launchDarkly/index.ts +52 -0
- package/src/launchDarkly/types.ts +193 -0
- package/src/{utils/launchDarkly.ts → launchDarkly/utils.ts} +2 -2
- package/src/types.ts +0 -185
- package/src/launchDarklyExperiments.tsx +0 -48
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import {FieldDefinition} from 'sanity'
|
|
2
|
+
|
|
3
|
+
export type LaunchDarklyFieldLevelConfig = {
|
|
4
|
+
fields: (string | FieldDefinition)[]
|
|
5
|
+
projectKey: string
|
|
6
|
+
tags?: string[]
|
|
7
|
+
}
|
|
8
|
+
export type LaunchDarklyContextProps = {
|
|
9
|
+
setSecret: (secret: string | undefined) => void
|
|
10
|
+
secret: string | undefined
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type LaunchDarklyFlagItem = {
|
|
14
|
+
name: string
|
|
15
|
+
kind: string
|
|
16
|
+
key: string
|
|
17
|
+
_version: number
|
|
18
|
+
creationDate: number
|
|
19
|
+
variations: Array<{
|
|
20
|
+
value: boolean
|
|
21
|
+
_id: string
|
|
22
|
+
name: string
|
|
23
|
+
}>
|
|
24
|
+
temporary: boolean
|
|
25
|
+
tags: string[]
|
|
26
|
+
_links: {
|
|
27
|
+
parent: {
|
|
28
|
+
href: string
|
|
29
|
+
type: string
|
|
30
|
+
}
|
|
31
|
+
self: {
|
|
32
|
+
href: string
|
|
33
|
+
type: string
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
experiments: {
|
|
37
|
+
baselineIdx: number
|
|
38
|
+
items: Array<{
|
|
39
|
+
metricKey: string
|
|
40
|
+
_metric: {
|
|
41
|
+
_id: string
|
|
42
|
+
_versionId: string
|
|
43
|
+
key: string
|
|
44
|
+
name: string
|
|
45
|
+
kind: string
|
|
46
|
+
_links: {
|
|
47
|
+
parent: {
|
|
48
|
+
href: string
|
|
49
|
+
type: string
|
|
50
|
+
}
|
|
51
|
+
self: {
|
|
52
|
+
href: string
|
|
53
|
+
type: string
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
tags: string[]
|
|
57
|
+
_creationDate: number
|
|
58
|
+
experimentCount: number
|
|
59
|
+
metricGroupCount: number
|
|
60
|
+
_attachedFlagCount: number
|
|
61
|
+
maintainerId: string
|
|
62
|
+
_maintainer: {
|
|
63
|
+
_links: {
|
|
64
|
+
self: {
|
|
65
|
+
href: string
|
|
66
|
+
type: string
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
_id: string
|
|
70
|
+
role: string
|
|
71
|
+
email: string
|
|
72
|
+
firstName: string
|
|
73
|
+
lastName: string
|
|
74
|
+
}
|
|
75
|
+
category: string
|
|
76
|
+
isNumeric: boolean
|
|
77
|
+
percentileValue: number
|
|
78
|
+
}
|
|
79
|
+
}>
|
|
80
|
+
}
|
|
81
|
+
customProperties: {
|
|
82
|
+
key: {
|
|
83
|
+
name: string
|
|
84
|
+
value: string[]
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
archived: boolean
|
|
88
|
+
description: string
|
|
89
|
+
maintainerId: string
|
|
90
|
+
_maintainer: {
|
|
91
|
+
_links: {
|
|
92
|
+
self: {
|
|
93
|
+
href: string
|
|
94
|
+
type: string
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
_id: string
|
|
98
|
+
role: string
|
|
99
|
+
email: string
|
|
100
|
+
firstName: string
|
|
101
|
+
lastName: string
|
|
102
|
+
}
|
|
103
|
+
maintainerTeamKey: string
|
|
104
|
+
_maintainerTeam: {
|
|
105
|
+
key: string
|
|
106
|
+
name: string
|
|
107
|
+
_links: {
|
|
108
|
+
parent: {
|
|
109
|
+
href: string
|
|
110
|
+
type: string
|
|
111
|
+
}
|
|
112
|
+
roles: {
|
|
113
|
+
href: string
|
|
114
|
+
type: string
|
|
115
|
+
}
|
|
116
|
+
self: {
|
|
117
|
+
href: string
|
|
118
|
+
type: string
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
archivedDate: number
|
|
123
|
+
deprecated: boolean
|
|
124
|
+
deprecatedDate: number
|
|
125
|
+
defaults: {
|
|
126
|
+
onVariation: number
|
|
127
|
+
offVariation: number
|
|
128
|
+
}
|
|
129
|
+
_purpose: string
|
|
130
|
+
migrationSettings: {
|
|
131
|
+
contextKind: string
|
|
132
|
+
stageCount: number
|
|
133
|
+
}
|
|
134
|
+
environments: {
|
|
135
|
+
[key: string]: {
|
|
136
|
+
on: boolean
|
|
137
|
+
archived: boolean
|
|
138
|
+
salt: string
|
|
139
|
+
sel: string
|
|
140
|
+
lastModified: number
|
|
141
|
+
version: number
|
|
142
|
+
_site: {
|
|
143
|
+
href: string
|
|
144
|
+
type: string
|
|
145
|
+
}
|
|
146
|
+
_environmentName: string
|
|
147
|
+
trackEvents: boolean
|
|
148
|
+
trackEventsFallthrough: boolean
|
|
149
|
+
targets: Array<{
|
|
150
|
+
values: string[]
|
|
151
|
+
variation: number
|
|
152
|
+
contextKind: string
|
|
153
|
+
}>
|
|
154
|
+
contextTargets: Array<{
|
|
155
|
+
values: string[]
|
|
156
|
+
variation: number
|
|
157
|
+
contextKind: string
|
|
158
|
+
}>
|
|
159
|
+
rules: Array<{
|
|
160
|
+
clauses: Array<{
|
|
161
|
+
attribute: string
|
|
162
|
+
op: string
|
|
163
|
+
values: unknown[]
|
|
164
|
+
negate: boolean
|
|
165
|
+
}>
|
|
166
|
+
trackEvents: boolean
|
|
167
|
+
}>
|
|
168
|
+
fallthrough: {
|
|
169
|
+
variation: number
|
|
170
|
+
}
|
|
171
|
+
offVariation: number
|
|
172
|
+
prerequisites: Array<{
|
|
173
|
+
key: string
|
|
174
|
+
variation: number
|
|
175
|
+
}>
|
|
176
|
+
_summary: {
|
|
177
|
+
variations: {
|
|
178
|
+
[key: string]: {
|
|
179
|
+
rules: number
|
|
180
|
+
nullRules: number
|
|
181
|
+
targets: number
|
|
182
|
+
contextTargets: number
|
|
183
|
+
isFallthrough?: boolean
|
|
184
|
+
isOff?: boolean
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
prerequisites: number
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
includeInSnippet: boolean
|
|
192
|
+
goalIds: string[]
|
|
193
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {SanityClient} from 'sanity'
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import {ExperimentType} from '../types'
|
|
4
|
+
import {LaunchDarklyFieldLevelConfig, LaunchDarklyFlagItem} from './types'
|
|
5
5
|
|
|
6
6
|
export const getExperiments = async ({
|
|
7
7
|
client,
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import {Dispatch, SetStateAction} from 'react'
|
|
2
1
|
import {
|
|
3
2
|
ArrayOfObjectsInputProps,
|
|
4
3
|
FieldDefinition,
|
|
@@ -38,8 +37,6 @@ export type VariantPreviewProps = Omit<PreviewProps, 'SchemaType'> & {
|
|
|
38
37
|
|
|
39
38
|
export type ExperimentContextProps = Required<FieldPluginConfig> & {
|
|
40
39
|
experiments: ExperimentType[]
|
|
41
|
-
setSecret: Dispatch<SetStateAction<string | undefined>>
|
|
42
|
-
secret: string | undefined
|
|
43
40
|
}
|
|
44
41
|
|
|
45
42
|
export type ArrayInputProps = ArrayOfObjectsInputProps & {
|
|
@@ -70,185 +67,3 @@ export type ExperimentGeneric<T> = {
|
|
|
70
67
|
| T
|
|
71
68
|
| undefined
|
|
72
69
|
}
|
|
73
|
-
|
|
74
|
-
export type LaunchDarklyFlagItem = {
|
|
75
|
-
name: string
|
|
76
|
-
kind: string
|
|
77
|
-
key: string
|
|
78
|
-
_version: number
|
|
79
|
-
creationDate: number
|
|
80
|
-
variations: Array<{
|
|
81
|
-
value: boolean
|
|
82
|
-
_id: string
|
|
83
|
-
name: string
|
|
84
|
-
}>
|
|
85
|
-
temporary: boolean
|
|
86
|
-
tags: string[]
|
|
87
|
-
_links: {
|
|
88
|
-
parent: {
|
|
89
|
-
href: string
|
|
90
|
-
type: string
|
|
91
|
-
}
|
|
92
|
-
self: {
|
|
93
|
-
href: string
|
|
94
|
-
type: string
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
experiments: {
|
|
98
|
-
baselineIdx: number
|
|
99
|
-
items: Array<{
|
|
100
|
-
metricKey: string
|
|
101
|
-
_metric: {
|
|
102
|
-
_id: string
|
|
103
|
-
_versionId: string
|
|
104
|
-
key: string
|
|
105
|
-
name: string
|
|
106
|
-
kind: string
|
|
107
|
-
_links: {
|
|
108
|
-
parent: {
|
|
109
|
-
href: string
|
|
110
|
-
type: string
|
|
111
|
-
}
|
|
112
|
-
self: {
|
|
113
|
-
href: string
|
|
114
|
-
type: string
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
tags: string[]
|
|
118
|
-
_creationDate: number
|
|
119
|
-
experimentCount: number
|
|
120
|
-
metricGroupCount: number
|
|
121
|
-
_attachedFlagCount: number
|
|
122
|
-
maintainerId: string
|
|
123
|
-
_maintainer: {
|
|
124
|
-
_links: {
|
|
125
|
-
self: {
|
|
126
|
-
href: string
|
|
127
|
-
type: string
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
_id: string
|
|
131
|
-
role: string
|
|
132
|
-
email: string
|
|
133
|
-
firstName: string
|
|
134
|
-
lastName: string
|
|
135
|
-
}
|
|
136
|
-
category: string
|
|
137
|
-
isNumeric: boolean
|
|
138
|
-
percentileValue: number
|
|
139
|
-
}
|
|
140
|
-
}>
|
|
141
|
-
}
|
|
142
|
-
customProperties: {
|
|
143
|
-
key: {
|
|
144
|
-
name: string
|
|
145
|
-
value: string[]
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
archived: boolean
|
|
149
|
-
description: string
|
|
150
|
-
maintainerId: string
|
|
151
|
-
_maintainer: {
|
|
152
|
-
_links: {
|
|
153
|
-
self: {
|
|
154
|
-
href: string
|
|
155
|
-
type: string
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
_id: string
|
|
159
|
-
role: string
|
|
160
|
-
email: string
|
|
161
|
-
firstName: string
|
|
162
|
-
lastName: string
|
|
163
|
-
}
|
|
164
|
-
maintainerTeamKey: string
|
|
165
|
-
_maintainerTeam: {
|
|
166
|
-
key: string
|
|
167
|
-
name: string
|
|
168
|
-
_links: {
|
|
169
|
-
parent: {
|
|
170
|
-
href: string
|
|
171
|
-
type: string
|
|
172
|
-
}
|
|
173
|
-
roles: {
|
|
174
|
-
href: string
|
|
175
|
-
type: string
|
|
176
|
-
}
|
|
177
|
-
self: {
|
|
178
|
-
href: string
|
|
179
|
-
type: string
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
archivedDate: number
|
|
184
|
-
deprecated: boolean
|
|
185
|
-
deprecatedDate: number
|
|
186
|
-
defaults: {
|
|
187
|
-
onVariation: number
|
|
188
|
-
offVariation: number
|
|
189
|
-
}
|
|
190
|
-
_purpose: string
|
|
191
|
-
migrationSettings: {
|
|
192
|
-
contextKind: string
|
|
193
|
-
stageCount: number
|
|
194
|
-
}
|
|
195
|
-
environments: {
|
|
196
|
-
[key: string]: {
|
|
197
|
-
on: boolean
|
|
198
|
-
archived: boolean
|
|
199
|
-
salt: string
|
|
200
|
-
sel: string
|
|
201
|
-
lastModified: number
|
|
202
|
-
version: number
|
|
203
|
-
_site: {
|
|
204
|
-
href: string
|
|
205
|
-
type: string
|
|
206
|
-
}
|
|
207
|
-
_environmentName: string
|
|
208
|
-
trackEvents: boolean
|
|
209
|
-
trackEventsFallthrough: boolean
|
|
210
|
-
targets: Array<{
|
|
211
|
-
values: string[]
|
|
212
|
-
variation: number
|
|
213
|
-
contextKind: string
|
|
214
|
-
}>
|
|
215
|
-
contextTargets: Array<{
|
|
216
|
-
values: string[]
|
|
217
|
-
variation: number
|
|
218
|
-
contextKind: string
|
|
219
|
-
}>
|
|
220
|
-
rules: Array<{
|
|
221
|
-
clauses: Array<{
|
|
222
|
-
attribute: string
|
|
223
|
-
op: string
|
|
224
|
-
values: unknown[]
|
|
225
|
-
negate: boolean
|
|
226
|
-
}>
|
|
227
|
-
trackEvents: boolean
|
|
228
|
-
}>
|
|
229
|
-
fallthrough: {
|
|
230
|
-
variation: number
|
|
231
|
-
}
|
|
232
|
-
offVariation: number
|
|
233
|
-
prerequisites: Array<{
|
|
234
|
-
key: string
|
|
235
|
-
variation: number
|
|
236
|
-
}>
|
|
237
|
-
_summary: {
|
|
238
|
-
variations: {
|
|
239
|
-
[key: string]: {
|
|
240
|
-
rules: number
|
|
241
|
-
nullRules: number
|
|
242
|
-
targets: number
|
|
243
|
-
contextTargets: number
|
|
244
|
-
isFallthrough?: boolean
|
|
245
|
-
isOff?: boolean
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
prerequisites: number
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
includeInSnippet: boolean
|
|
253
|
-
goalIds: string[]
|
|
254
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import {definePlugin, FieldDefinition, isObjectInputProps} from 'sanity'
|
|
2
|
-
|
|
3
|
-
import {Secrets} from './components/Secrets'
|
|
4
|
-
import {fieldLevelExperiments} from './fieldExperiments'
|
|
5
|
-
import {flattenSchemaType} from './utils/flattenSchemaType'
|
|
6
|
-
import {getExperiments} from './utils/launchDarkly'
|
|
7
|
-
|
|
8
|
-
export type LaunchDarklyFieldLevelConfig = {
|
|
9
|
-
fields: (string | FieldDefinition)[]
|
|
10
|
-
projectKey: string
|
|
11
|
-
tags?: string[]
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export const launchDarklyFieldLevel = definePlugin<LaunchDarklyFieldLevelConfig>((config) => {
|
|
15
|
-
const {fields, projectKey, tags} = config
|
|
16
|
-
return {
|
|
17
|
-
name: 'sanity-growthbook-personalistaion-plugin-field-level-experiments',
|
|
18
|
-
plugins: [
|
|
19
|
-
fieldLevelExperiments({
|
|
20
|
-
fields,
|
|
21
|
-
experiments: (client) => getExperiments({client, projectKey, tags}),
|
|
22
|
-
}),
|
|
23
|
-
],
|
|
24
|
-
|
|
25
|
-
form: {
|
|
26
|
-
components: {
|
|
27
|
-
input: (props) => {
|
|
28
|
-
const isRootInput = props.id === 'root' && isObjectInputProps(props)
|
|
29
|
-
|
|
30
|
-
if (!isRootInput) {
|
|
31
|
-
return props.renderDefault(props)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const flatFieldTypeNames = flattenSchemaType(props.schemaType).map(
|
|
35
|
-
(field) => field.type.name,
|
|
36
|
-
)
|
|
37
|
-
|
|
38
|
-
const hasExperiment = flatFieldTypeNames.some((name) => name.startsWith('experiment'))
|
|
39
|
-
|
|
40
|
-
if (!hasExperiment) {
|
|
41
|
-
return props.renderDefault(props)
|
|
42
|
-
}
|
|
43
|
-
return Secrets(props, 'launchdarkly')
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
}
|
|
48
|
-
})
|