-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathfeature-flags.ts
More file actions
80 lines (69 loc) · 2.26 KB
/
feature-flags.ts
File metadata and controls
80 lines (69 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { AutoPaginatable } from '../common/utils/pagination';
import { WorkOS } from '../workos';
import {
AddFlagTargetOptions,
FeatureFlag,
FeatureFlagResponse,
ListFeatureFlagsOptions,
RemoveFlagTargetOptions,
RuntimeClientOptions,
} from './interfaces';
import { deserializeFeatureFlag } from './serializers';
import { fetchAndDeserialize } from '../common/utils/fetch-and-deserialize';
import { FeatureFlagsRuntimeClient } from './runtime-client';
export class FeatureFlags {
constructor(private readonly workos: WorkOS) {}
async listFeatureFlags(
options?: ListFeatureFlagsOptions,
): Promise<AutoPaginatable<FeatureFlag>> {
return new AutoPaginatable(
await fetchAndDeserialize<FeatureFlagResponse, FeatureFlag>(
this.workos,
'/feature-flags',
deserializeFeatureFlag,
options,
),
(params) =>
fetchAndDeserialize<FeatureFlagResponse, FeatureFlag>(
this.workos,
'/feature-flags',
deserializeFeatureFlag,
params,
),
options,
);
}
async getFeatureFlag(slug: string): Promise<FeatureFlag> {
const { data } = await this.workos.get<FeatureFlagResponse>(
`/feature-flags/${slug}`,
);
return deserializeFeatureFlag(data);
}
async enableFeatureFlag(slug: string): Promise<FeatureFlag> {
const { data } = await this.workos.put<FeatureFlagResponse>(
`/feature-flags/${slug}/enable`,
{},
);
return deserializeFeatureFlag(data);
}
async disableFeatureFlag(slug: string): Promise<FeatureFlag> {
const { data } = await this.workos.put<FeatureFlagResponse>(
`/feature-flags/${slug}/disable`,
{},
);
return deserializeFeatureFlag(data);
}
async addFlagTarget(options: AddFlagTargetOptions): Promise<void> {
const { slug, targetId } = options;
await this.workos.post(`/feature-flags/${slug}/targets/${targetId}`, {});
}
async removeFlagTarget(options: RemoveFlagTargetOptions): Promise<void> {
const { slug, targetId } = options;
await this.workos.delete(`/feature-flags/${slug}/targets/${targetId}`);
}
createRuntimeClient(
options?: RuntimeClientOptions,
): FeatureFlagsRuntimeClient {
return new FeatureFlagsRuntimeClient(this.workos, options);
}
}