@sanity/personalization-plugin 2.4.0 → 2.5.0-launch-darkly.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 +38 -3
- package/dist/growthbook/index.js.map +1 -1
- package/dist/growthbook/index.mjs.map +1 -1
- package/dist/index.js +637 -66
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +637 -66
- 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 +8 -3
- package/src/fieldExperiments.tsx +17 -0
- package/src/launchDarkly/components/LaunchDarklyContext.tsx +36 -0
- package/src/launchDarkly/components/Secrets.tsx +46 -0
- package/src/launchDarkly/index.ts +52 -0
- package/src/launchDarkly/launchdarkly.md +76 -0
- package/src/launchDarkly/types.ts +193 -0
- package/src/launchDarkly/utils.ts +54 -0
|
@@ -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 | string | number
|
|
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
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {SanityClient} from 'sanity'
|
|
2
|
+
|
|
3
|
+
import {ExperimentType} from '../types'
|
|
4
|
+
import {LaunchDarklyFieldLevelConfig, LaunchDarklyFlagItem} from './types'
|
|
5
|
+
|
|
6
|
+
export const getExperiments = async ({
|
|
7
|
+
client,
|
|
8
|
+
projectKey,
|
|
9
|
+
tags,
|
|
10
|
+
}: Omit<LaunchDarklyFieldLevelConfig, 'fields'> & {client: SanityClient}): Promise<
|
|
11
|
+
ExperimentType[]
|
|
12
|
+
> => {
|
|
13
|
+
const query = `*[_id == 'secrets.launchdarkly'][0].secrets.apiKey`
|
|
14
|
+
|
|
15
|
+
const secret = await client.fetch(query) // secret is stored in the content lake using @sanity/studio-secrets
|
|
16
|
+
if (!secret) return []
|
|
17
|
+
|
|
18
|
+
const url = new URL(`https://app.launchdarkly.com/api/v2/flags/${projectKey}`)
|
|
19
|
+
|
|
20
|
+
if (tags) {
|
|
21
|
+
url.searchParams.set('filter', `tags:${tags.join('+')}`)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const featureExperiments: ExperimentType[] = []
|
|
25
|
+
let hasMore = true
|
|
26
|
+
const offset = 0
|
|
27
|
+
const limit = 10
|
|
28
|
+
|
|
29
|
+
while (hasMore) {
|
|
30
|
+
url.searchParams.set('offset', offset.toString())
|
|
31
|
+
url.searchParams.set('limit', limit.toString())
|
|
32
|
+
const responseFlags = await fetch(url, {
|
|
33
|
+
headers: {
|
|
34
|
+
Authorization: secret,
|
|
35
|
+
},
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
const {items} = await responseFlags.json()
|
|
39
|
+
const experiments = items.map((flag: LaunchDarklyFlagItem) => ({
|
|
40
|
+
id: flag.key,
|
|
41
|
+
label: flag.name,
|
|
42
|
+
variants: flag.variations.map((variation) => ({
|
|
43
|
+
id: variation.value.toString(),
|
|
44
|
+
label: variation.name ?? variation.value.toString(),
|
|
45
|
+
})),
|
|
46
|
+
}))
|
|
47
|
+
featureExperiments.push(...experiments)
|
|
48
|
+
if (items.length !== limit) {
|
|
49
|
+
hasMore = false
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return featureExperiments
|
|
54
|
+
}
|