@barekey/sdk 0.1.0
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/LICENSE +28 -0
- package/README.md +21 -0
- package/dist/client.d.ts +41 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +302 -0
- package/dist/errors.d.ts +461 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +343 -0
- package/dist/handle.d.ts +20 -0
- package/dist/handle.d.ts.map +1 -0
- package/dist/handle.js +35 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/internal/cache.d.ts +13 -0
- package/dist/internal/cache.d.ts.map +1 -0
- package/dist/internal/cache.js +24 -0
- package/dist/internal/evaluate.d.ts +7 -0
- package/dist/internal/evaluate.d.ts.map +1 -0
- package/dist/internal/evaluate.js +176 -0
- package/dist/internal/http.d.ts +19 -0
- package/dist/internal/http.d.ts.map +1 -0
- package/dist/internal/http.js +92 -0
- package/dist/internal/node-runtime.d.ts +19 -0
- package/dist/internal/node-runtime.d.ts.map +1 -0
- package/dist/internal/node-runtime.js +422 -0
- package/dist/internal/requirements.d.ts +3 -0
- package/dist/internal/requirements.d.ts.map +1 -0
- package/dist/internal/requirements.js +40 -0
- package/dist/internal/runtime.d.ts +15 -0
- package/dist/internal/runtime.d.ts.map +1 -0
- package/dist/internal/runtime.js +135 -0
- package/dist/internal/ttl.d.ts +4 -0
- package/dist/internal/ttl.d.ts.map +1 -0
- package/dist/internal/ttl.js +30 -0
- package/dist/internal/typegen.d.ts +25 -0
- package/dist/internal/typegen.d.ts.map +1 -0
- package/dist/internal/typegen.js +75 -0
- package/dist/types.d.ts +130 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/generated.d.ts +16 -0
- package/index.d.ts +2 -0
- package/package.json +42 -0
- package/src/client.ts +422 -0
- package/src/errors.ts +420 -0
- package/src/handle.ts +67 -0
- package/src/index.ts +60 -0
- package/src/internal/cache.ts +33 -0
- package/src/internal/evaluate.ts +232 -0
- package/src/internal/http.ts +134 -0
- package/src/internal/node-runtime.ts +581 -0
- package/src/internal/requirements.ts +57 -0
- package/src/internal/runtime.ts +199 -0
- package/src/internal/ttl.ts +41 -0
- package/src/internal/typegen.ts +124 -0
- package/src/types.ts +189 -0
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FsNotAvailableError,
|
|
3
|
+
InvalidConfigurationProvidedError,
|
|
4
|
+
InvalidCredentialsProvidedError,
|
|
5
|
+
InvalidRefreshTokenError,
|
|
6
|
+
NoConfigurationProvidedError,
|
|
7
|
+
NoCredentialsProvidedError,
|
|
8
|
+
UnauthorizedError,
|
|
9
|
+
} from "../errors.js";
|
|
10
|
+
import type { BarekeyClientOptions, BarekeyJsonConfig, BarekeyStandardSchemaV1 } from "../types.js";
|
|
11
|
+
import { type InternalAuthResolver, normalizeBaseUrl } from "./http.js";
|
|
12
|
+
import {
|
|
13
|
+
isFilesystemAvailable,
|
|
14
|
+
loadBarekeyJsonConfig,
|
|
15
|
+
loadCliSessionAuthResolver,
|
|
16
|
+
} from "./node-runtime.js";
|
|
17
|
+
|
|
18
|
+
const DEFAULT_BAREKEY_API_URL = "https://api.barekey.dev";
|
|
19
|
+
|
|
20
|
+
type BarekeyResolvedScope = {
|
|
21
|
+
organization: string;
|
|
22
|
+
project: string;
|
|
23
|
+
environment: string;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type BarekeyRuntimeContext = BarekeyResolvedScope & {
|
|
27
|
+
baseUrl: string;
|
|
28
|
+
auth: InternalAuthResolver;
|
|
29
|
+
requirements?: BarekeyStandardSchemaV1;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
function readProcessEnv(key: string): string | undefined {
|
|
33
|
+
if (typeof process === "undefined" || typeof process.env !== "object" || process.env === null) {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const value = process.env[key];
|
|
38
|
+
return typeof value === "string" ? value : undefined;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function readConfigString(value: unknown): string | undefined {
|
|
42
|
+
return typeof value === "string" ? value.trim() : undefined;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function normalizeScope(input: {
|
|
46
|
+
organization?: unknown;
|
|
47
|
+
project?: unknown;
|
|
48
|
+
environment?: unknown;
|
|
49
|
+
source: string;
|
|
50
|
+
}): BarekeyResolvedScope {
|
|
51
|
+
const organization = readConfigString(input.organization) ?? "";
|
|
52
|
+
const project = readConfigString(input.project) ?? "";
|
|
53
|
+
const environment = readConfigString(input.environment) ?? "";
|
|
54
|
+
if (organization.length === 0 || project.length === 0 || environment.length === 0) {
|
|
55
|
+
throw new InvalidConfigurationProvidedError({
|
|
56
|
+
message: `${input.source} must provide organization, project, and environment.`,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
organization,
|
|
62
|
+
project,
|
|
63
|
+
environment,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function normalizeJsonConfig(
|
|
68
|
+
input: BarekeyJsonConfig | Record<string, unknown>,
|
|
69
|
+
source: string,
|
|
70
|
+
): BarekeyResolvedScope {
|
|
71
|
+
return normalizeScope({
|
|
72
|
+
organization: input.organization ?? input.org,
|
|
73
|
+
project: input.project,
|
|
74
|
+
environment: input.environment ?? input.stage,
|
|
75
|
+
source,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async function resolveScope(options: BarekeyClientOptions): Promise<BarekeyResolvedScope> {
|
|
80
|
+
const explicitOrganization = "organization" in options ? options.organization : undefined;
|
|
81
|
+
const explicitProject = "project" in options ? options.project : undefined;
|
|
82
|
+
const explicitEnvironment = "environment" in options ? options.environment : undefined;
|
|
83
|
+
const explicitJson = "json" in options ? options.json : undefined;
|
|
84
|
+
|
|
85
|
+
const explicitCount =
|
|
86
|
+
Number(explicitOrganization !== undefined) +
|
|
87
|
+
Number(explicitProject !== undefined) +
|
|
88
|
+
Number(explicitEnvironment !== undefined);
|
|
89
|
+
|
|
90
|
+
if (explicitJson !== undefined && explicitCount > 0) {
|
|
91
|
+
throw new InvalidConfigurationProvidedError({
|
|
92
|
+
message: "Pass either json or organization/project/environment, not both.",
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (explicitCount > 0 && explicitCount < 3) {
|
|
97
|
+
throw new InvalidConfigurationProvidedError({
|
|
98
|
+
message: "organization, project, and environment must be provided together.",
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (explicitJson !== undefined) {
|
|
103
|
+
return normalizeJsonConfig(explicitJson, "The provided json configuration");
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (explicitCount === 3) {
|
|
107
|
+
return normalizeScope({
|
|
108
|
+
organization: explicitOrganization,
|
|
109
|
+
project: explicitProject,
|
|
110
|
+
environment: explicitEnvironment,
|
|
111
|
+
source: "The provided Barekey configuration",
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const loadedConfig = await loadBarekeyJsonConfig();
|
|
116
|
+
if (loadedConfig === null) {
|
|
117
|
+
if (!(await isFilesystemAvailable())) {
|
|
118
|
+
throw new FsNotAvailableError();
|
|
119
|
+
}
|
|
120
|
+
throw new NoConfigurationProvidedError({
|
|
121
|
+
message: "No Barekey configuration was found and no barekey.json file could be loaded.",
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return normalizeJsonConfig(
|
|
126
|
+
loadedConfig.json,
|
|
127
|
+
`The barekey.json file at ${loadedConfig.path}`,
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async function resolveAuth(fetchFn: typeof globalThis.fetch): Promise<{
|
|
132
|
+
baseUrl: string;
|
|
133
|
+
auth: InternalAuthResolver;
|
|
134
|
+
}> {
|
|
135
|
+
const envToken = readProcessEnv("BAREKEY_ACCESS_TOKEN");
|
|
136
|
+
if (envToken !== undefined) {
|
|
137
|
+
const normalizedToken = envToken.trim();
|
|
138
|
+
if (normalizedToken.length === 0) {
|
|
139
|
+
throw new InvalidCredentialsProvidedError({
|
|
140
|
+
message: "BAREKEY_ACCESS_TOKEN was provided but is empty.",
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const envBaseUrl = readProcessEnv("BAREKEY_API_URL")?.trim();
|
|
145
|
+
return {
|
|
146
|
+
baseUrl: normalizeBaseUrl(
|
|
147
|
+
envBaseUrl && envBaseUrl.length > 0 ? envBaseUrl : DEFAULT_BAREKEY_API_URL,
|
|
148
|
+
),
|
|
149
|
+
auth: {
|
|
150
|
+
async getAccessToken(): Promise<string> {
|
|
151
|
+
return normalizedToken;
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const cliSession = await loadCliSessionAuthResolver(fetchFn);
|
|
158
|
+
if (cliSession === null) {
|
|
159
|
+
if (!(await isFilesystemAvailable())) {
|
|
160
|
+
throw new FsNotAvailableError();
|
|
161
|
+
}
|
|
162
|
+
throw new NoCredentialsProvidedError();
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return {
|
|
166
|
+
baseUrl: normalizeBaseUrl(cliSession.baseUrl),
|
|
167
|
+
auth: {
|
|
168
|
+
async getAccessToken(): Promise<string> {
|
|
169
|
+
try {
|
|
170
|
+
return await cliSession.getAccessToken();
|
|
171
|
+
} catch (error: unknown) {
|
|
172
|
+
if (error instanceof InvalidRefreshTokenError || error instanceof UnauthorizedError) {
|
|
173
|
+
throw new InvalidCredentialsProvidedError({
|
|
174
|
+
message: "Stored Barekey CLI credentials are no longer valid.",
|
|
175
|
+
cause: error,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
throw error;
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
async onUnauthorized(): Promise<void> {
|
|
182
|
+
await cliSession.onUnauthorized();
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export async function resolveRuntimeContext(
|
|
189
|
+
options: BarekeyClientOptions,
|
|
190
|
+
fetchFn: typeof globalThis.fetch,
|
|
191
|
+
): Promise<BarekeyRuntimeContext> {
|
|
192
|
+
const [scope, auth] = await Promise.all([resolveScope(options), resolveAuth(fetchFn)]);
|
|
193
|
+
return {
|
|
194
|
+
...scope,
|
|
195
|
+
baseUrl: auth.baseUrl,
|
|
196
|
+
auth: auth.auth,
|
|
197
|
+
requirements: options.requirements,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { InvalidDynamicOptionsError } from "../errors.js";
|
|
2
|
+
import type { BarekeyTemporalInstantLike, BarekeyTtlInput } from "../types.js";
|
|
3
|
+
|
|
4
|
+
export const DEFAULT_TYPEGEN_TTL_MS = 30_000;
|
|
5
|
+
|
|
6
|
+
function buildTtlError(label: string) {
|
|
7
|
+
return new InvalidDynamicOptionsError({
|
|
8
|
+
message: `${label} must be a positive integer number of milliseconds, a future Date, or a future Temporal instant.`,
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function isTemporalInstantLike(value: unknown): value is BarekeyTemporalInstantLike {
|
|
13
|
+
return (
|
|
14
|
+
typeof value === "object" &&
|
|
15
|
+
value !== null &&
|
|
16
|
+
typeof (value as { epochMilliseconds?: unknown }).epochMilliseconds === "number"
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function normalizePositiveMilliseconds(value: number, label: string): number {
|
|
21
|
+
if (!Number.isFinite(value) || value <= 0 || !Number.isInteger(value)) {
|
|
22
|
+
throw buildTtlError(label);
|
|
23
|
+
}
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function resolveTtlMilliseconds(value: BarekeyTtlInput, label: string): number {
|
|
28
|
+
if (typeof value === "number") {
|
|
29
|
+
return normalizePositiveMilliseconds(value, label);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (value instanceof Date) {
|
|
33
|
+
return normalizePositiveMilliseconds(value.getTime() - Date.now(), label);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (isTemporalInstantLike(value)) {
|
|
37
|
+
return normalizePositiveMilliseconds(value.epochMilliseconds - Date.now(), label);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
throw buildTtlError(label);
|
|
41
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import {
|
|
2
|
+
readTextFile,
|
|
3
|
+
resolveInstalledSdkTypegenTarget,
|
|
4
|
+
writeTextFileAtomic,
|
|
5
|
+
} from "./node-runtime.js";
|
|
6
|
+
import type { BarekeyRolloutMilestone, BarekeyTypegenResult } from "../types.js";
|
|
7
|
+
|
|
8
|
+
export type TypegenManifestVariable = {
|
|
9
|
+
name: string;
|
|
10
|
+
kind: "secret" | "ab_roll" | "rollout";
|
|
11
|
+
declaredType: "string" | "boolean" | "int64" | "float" | "date" | "json";
|
|
12
|
+
required: boolean;
|
|
13
|
+
updatedAtMs: number;
|
|
14
|
+
typeScriptType: string;
|
|
15
|
+
valueATypeScriptType: string | null;
|
|
16
|
+
valueBTypeScriptType: string | null;
|
|
17
|
+
rolloutFunction: "linear" | null;
|
|
18
|
+
rolloutMilestones: Array<BarekeyRolloutMilestone> | null;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type TypegenManifest = {
|
|
22
|
+
orgId: string;
|
|
23
|
+
orgSlug: string;
|
|
24
|
+
projectSlug: string;
|
|
25
|
+
stageSlug: string;
|
|
26
|
+
generatedAtMs: number;
|
|
27
|
+
manifestVersion: string;
|
|
28
|
+
variables: Array<TypegenManifestVariable>;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const MANIFEST_VERSION_PATTERN = /\/\* barekey-manifest-version: ([^\n]+) \*\//;
|
|
32
|
+
|
|
33
|
+
function renderLinearMilestones(milestones: Array<BarekeyRolloutMilestone>): string {
|
|
34
|
+
if (milestones.length === 0) {
|
|
35
|
+
return "readonly []";
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return `readonly [${milestones
|
|
39
|
+
.map(
|
|
40
|
+
(milestone) =>
|
|
41
|
+
`readonly [${JSON.stringify(milestone.at)}, ${String(milestone.percentage)}]`,
|
|
42
|
+
)
|
|
43
|
+
.join(", ")}]`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function renderVariableType(row: TypegenManifestVariable): string {
|
|
47
|
+
if (row.kind === "secret") {
|
|
48
|
+
return `Env<Secret, ${row.typeScriptType}>`;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (row.kind === "ab_roll") {
|
|
52
|
+
return `Env<AB, ${row.typeScriptType}>`;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return `Env<AB, ${row.typeScriptType}, Linear<${renderLinearMilestones(
|
|
56
|
+
row.rolloutMilestones ?? [],
|
|
57
|
+
)}>>`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function buildGeneratedTypesContents(manifest: TypegenManifest): string {
|
|
61
|
+
const mapLines = manifest.variables
|
|
62
|
+
.slice()
|
|
63
|
+
.sort((left, right) => left.name.localeCompare(right.name))
|
|
64
|
+
.map((row) => ` ${JSON.stringify(row.name)}: ${renderVariableType(row)};`)
|
|
65
|
+
.join("\n");
|
|
66
|
+
|
|
67
|
+
return `/* eslint-disable */
|
|
68
|
+
/* This file is generated by barekey typegen. */
|
|
69
|
+
/* barekey-manifest-version: ${manifest.manifestVersion} */
|
|
70
|
+
|
|
71
|
+
import type { AB, Env, Linear, Secret } from "./dist/types.js";
|
|
72
|
+
|
|
73
|
+
declare module "./dist/types.js" {
|
|
74
|
+
interface BarekeyGeneratedTypeMap {
|
|
75
|
+
${mapLines.length > 0 ? mapLines : ""}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export {};
|
|
80
|
+
`;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function readManifestVersion(contents: string | null): string | null {
|
|
84
|
+
if (contents === null) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const match = contents.match(MANIFEST_VERSION_PATTERN);
|
|
89
|
+
return match?.[1]?.trim() ?? null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export async function resolveInstalledSdkGeneratedTypesPath(): Promise<string | null> {
|
|
93
|
+
const target = await resolveInstalledSdkTypegenTarget();
|
|
94
|
+
return target?.generatedTypesPath ?? null;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export async function writeInstalledSdkGeneratedTypes(
|
|
98
|
+
manifest: TypegenManifest,
|
|
99
|
+
): Promise<BarekeyTypegenResult> {
|
|
100
|
+
const target = await resolveInstalledSdkTypegenTarget();
|
|
101
|
+
if (target === null) {
|
|
102
|
+
return {
|
|
103
|
+
written: false,
|
|
104
|
+
path: "",
|
|
105
|
+
manifestVersion: manifest.manifestVersion,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const existingContents = await readTextFile(target.generatedTypesPath);
|
|
110
|
+
if (readManifestVersion(existingContents) === manifest.manifestVersion) {
|
|
111
|
+
return {
|
|
112
|
+
written: false,
|
|
113
|
+
path: target.generatedTypesPath,
|
|
114
|
+
manifestVersion: manifest.manifestVersion,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
await writeTextFileAtomic(target.generatedTypesPath, buildGeneratedTypesContents(manifest));
|
|
119
|
+
return {
|
|
120
|
+
written: true,
|
|
121
|
+
path: target.generatedTypesPath,
|
|
122
|
+
manifestVersion: manifest.manifestVersion,
|
|
123
|
+
};
|
|
124
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
export type BarekeyResolvedKind = "secret" | "ab_roll" | "rollout";
|
|
2
|
+
|
|
3
|
+
export type BarekeyDeclaredType = "string" | "boolean" | "int64" | "float" | "date" | "json";
|
|
4
|
+
|
|
5
|
+
export type BarekeyTemporalInstant = {
|
|
6
|
+
readonly epochMilliseconds: number;
|
|
7
|
+
toJSON(): string;
|
|
8
|
+
toString(): string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type BarekeyTemporalInstantLike = {
|
|
12
|
+
readonly epochMilliseconds: number;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type BarekeyTtlInput = number | Date | BarekeyTemporalInstantLike;
|
|
16
|
+
|
|
17
|
+
export type Secret = "secret";
|
|
18
|
+
|
|
19
|
+
export type AB = "ab";
|
|
20
|
+
|
|
21
|
+
export type Linear<
|
|
22
|
+
TMilestones extends ReadonlyArray<readonly [string, number]> = ReadonlyArray<
|
|
23
|
+
readonly [string, number]
|
|
24
|
+
>,
|
|
25
|
+
> = {
|
|
26
|
+
readonly kind: "linear";
|
|
27
|
+
readonly milestones: TMilestones;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export type Env<TMode, TValue, TFunction = never> = TValue & {
|
|
31
|
+
readonly __barekey?: {
|
|
32
|
+
readonly mode: TMode;
|
|
33
|
+
readonly function: TFunction;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type BarekeyCoerceTarget = "string" | "boolean" | "int64" | "float" | "date" | "json";
|
|
38
|
+
|
|
39
|
+
export interface BarekeyGeneratedTypeMap {}
|
|
40
|
+
|
|
41
|
+
export type BarekeyKnownKey = Extract<keyof BarekeyGeneratedTypeMap, string>;
|
|
42
|
+
|
|
43
|
+
export type BarekeyRolloutMilestone = {
|
|
44
|
+
at: string;
|
|
45
|
+
percentage: number;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export type BarekeyDecision = {
|
|
49
|
+
bucket: number;
|
|
50
|
+
chance: number;
|
|
51
|
+
seed?: string;
|
|
52
|
+
key?: string;
|
|
53
|
+
matchedRule: "ab_roll" | "linear_rollout";
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export type BarekeyEvaluatedValue = {
|
|
57
|
+
name: string;
|
|
58
|
+
kind: BarekeyResolvedKind;
|
|
59
|
+
declaredType: BarekeyDeclaredType;
|
|
60
|
+
value: string;
|
|
61
|
+
decision?: BarekeyDecision;
|
|
62
|
+
selectedArm?: "A" | "B";
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export type BarekeyVariableDefinition =
|
|
66
|
+
| {
|
|
67
|
+
name: string;
|
|
68
|
+
kind: "secret";
|
|
69
|
+
declaredType: BarekeyDeclaredType;
|
|
70
|
+
value: string;
|
|
71
|
+
}
|
|
72
|
+
| {
|
|
73
|
+
name: string;
|
|
74
|
+
kind: "ab_roll";
|
|
75
|
+
declaredType: BarekeyDeclaredType;
|
|
76
|
+
valueA: string;
|
|
77
|
+
valueB: string;
|
|
78
|
+
chance: number;
|
|
79
|
+
}
|
|
80
|
+
| {
|
|
81
|
+
name: string;
|
|
82
|
+
kind: "rollout";
|
|
83
|
+
declaredType: BarekeyDeclaredType;
|
|
84
|
+
valueA: string;
|
|
85
|
+
valueB: string;
|
|
86
|
+
rolloutFunction: "linear";
|
|
87
|
+
rolloutMilestones: Array<BarekeyRolloutMilestone>;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export type BarekeyGetOptions = {
|
|
91
|
+
dynamic?: true | { ttl: BarekeyTtlInput };
|
|
92
|
+
seed?: string;
|
|
93
|
+
key?: string;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export type BarekeyJsonConfig = {
|
|
97
|
+
organization?: string;
|
|
98
|
+
project?: string;
|
|
99
|
+
environment?: string;
|
|
100
|
+
org?: string;
|
|
101
|
+
stage?: string;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export type BarekeyStandardSchemaResult =
|
|
105
|
+
| {
|
|
106
|
+
value: unknown;
|
|
107
|
+
issues?: undefined;
|
|
108
|
+
}
|
|
109
|
+
| {
|
|
110
|
+
issues: ReadonlyArray<{
|
|
111
|
+
message?: string;
|
|
112
|
+
path?: ReadonlyArray<BarekeyStandardSchemaPathSegment>;
|
|
113
|
+
}>;
|
|
114
|
+
value?: undefined;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export type BarekeyStandardSchemaPathSegment =
|
|
118
|
+
| PropertyKey
|
|
119
|
+
| {
|
|
120
|
+
key: PropertyKey;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
export type BarekeyStandardSchemaV1 = {
|
|
124
|
+
readonly ["~standard"]?: {
|
|
125
|
+
readonly version?: number;
|
|
126
|
+
validate(value: unknown): BarekeyStandardSchemaResult | Promise<BarekeyStandardSchemaResult>;
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
type BarekeyBaseClientOptions = {
|
|
131
|
+
requirements?: BarekeyStandardSchemaV1;
|
|
132
|
+
typegen?: false | { ttl?: BarekeyTtlInput };
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
export type BarekeyTypegenResult = {
|
|
136
|
+
written: boolean;
|
|
137
|
+
path: string;
|
|
138
|
+
manifestVersion: string;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export type BarekeyClientOptions =
|
|
142
|
+
| (BarekeyBaseClientOptions & {
|
|
143
|
+
organization: string;
|
|
144
|
+
project: string;
|
|
145
|
+
environment: string;
|
|
146
|
+
json?: never;
|
|
147
|
+
})
|
|
148
|
+
| (BarekeyBaseClientOptions & {
|
|
149
|
+
json: BarekeyJsonConfig;
|
|
150
|
+
organization?: never;
|
|
151
|
+
project?: never;
|
|
152
|
+
environment?: never;
|
|
153
|
+
})
|
|
154
|
+
| (BarekeyBaseClientOptions & {
|
|
155
|
+
organization?: never;
|
|
156
|
+
project?: never;
|
|
157
|
+
environment?: never;
|
|
158
|
+
json?: never;
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
export type BarekeyErrorCode =
|
|
162
|
+
| "FS_NOT_AVAILABLE"
|
|
163
|
+
| "NO_CONFIGURATION_PROVIDED"
|
|
164
|
+
| "INVALID_CONFIGURATION_PROVIDED"
|
|
165
|
+
| "NO_CREDENTIALS_PROVIDED"
|
|
166
|
+
| "INVALID_CREDENTIALS_PROVIDED"
|
|
167
|
+
| "INVALID_DYNAMIC_OPTIONS"
|
|
168
|
+
| "REQUIREMENTS_VALIDATION_FAILED"
|
|
169
|
+
| "NETWORK_ERROR"
|
|
170
|
+
| "COERCE_FAILED"
|
|
171
|
+
| "TEMPORAL_NOT_AVAILABLE"
|
|
172
|
+
| "SDK_MODULE_NOT_FOUND"
|
|
173
|
+
| "TYPEGEN_UNSUPPORTED_SDK"
|
|
174
|
+
| "TYPEGEN_READ_FAILED"
|
|
175
|
+
| "TYPEGEN_WRITE_FAILED"
|
|
176
|
+
| "UNAUTHORIZED"
|
|
177
|
+
| "INVALID_ORG_SCOPE"
|
|
178
|
+
| "ORG_SCOPE_INVALID"
|
|
179
|
+
| "INVALID_JSON"
|
|
180
|
+
| "INVALID_REQUEST"
|
|
181
|
+
| "VARIABLE_NOT_FOUND"
|
|
182
|
+
| "EVALUATION_FAILED"
|
|
183
|
+
| "USAGE_LIMIT_EXCEEDED"
|
|
184
|
+
| "BILLING_UNAVAILABLE"
|
|
185
|
+
| "DEVICE_CODE_NOT_FOUND"
|
|
186
|
+
| "DEVICE_CODE_EXPIRED"
|
|
187
|
+
| "USER_CODE_INVALID"
|
|
188
|
+
| "INVALID_REFRESH_TOKEN"
|
|
189
|
+
| "UNKNOWN_ERROR";
|