@barekey/sdk 0.1.0 → 0.1.3
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 +9 -3
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +15 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/internal/evaluate.d.ts.map +1 -1
- package/dist/internal/evaluate.js +57 -7
- package/dist/internal/node-runtime.d.ts +3 -1
- package/dist/internal/node-runtime.d.ts.map +1 -1
- package/dist/internal/node-runtime.js +8 -4
- package/dist/internal/public-runtime.d.ts +14 -0
- package/dist/internal/public-runtime.d.ts.map +1 -0
- package/dist/internal/public-runtime.js +78 -0
- package/dist/internal/typegen.d.ts +16 -3
- package/dist/internal/typegen.d.ts.map +1 -1
- package/dist/internal/typegen.js +123 -12
- package/dist/public-client.d.ts +36 -0
- package/dist/public-client.d.ts.map +1 -0
- package/dist/public-client.js +150 -0
- package/dist/public-types.d.ts +26 -0
- package/dist/public-types.d.ts.map +1 -0
- package/dist/public-types.js +1 -0
- package/dist/public.d.ts +6 -0
- package/dist/public.d.ts.map +1 -0
- package/dist/public.js +3 -0
- package/dist/server.d.ts +5 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +3 -0
- package/dist/types.d.ts +14 -2
- package/dist/types.d.ts.map +1 -1
- package/generated.public.d.ts +8 -0
- package/{generated.d.ts → generated.server.d.ts} +8 -2
- package/index.d.ts +0 -1
- package/package.json +18 -3
- package/public.d.ts +2 -0
- package/server.d.ts +2 -0
- package/src/client.ts +17 -2
- package/src/index.ts +7 -0
- package/src/internal/evaluate.ts +83 -7
- package/src/internal/node-runtime.ts +11 -5
- package/src/internal/public-runtime.ts +123 -0
- package/src/internal/typegen.ts +203 -15
- package/src/public-client.ts +229 -0
- package/src/public-types.ts +57 -0
- package/src/public.ts +69 -0
- package/src/server.ts +60 -0
- package/src/types.ts +29 -2
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { VariableNotFoundError } from "./errors.js";
|
|
2
|
+
import { BarekeyEnvHandle } from "./handle.js";
|
|
3
|
+
import { evaluateDefinition, parseDeclaredValue, validateDynamicOptions, } from "./internal/evaluate.js";
|
|
4
|
+
import { postJson } from "./internal/http.js";
|
|
5
|
+
import { MemoryCache } from "./internal/cache.js";
|
|
6
|
+
import { validateRequirements } from "./internal/requirements.js";
|
|
7
|
+
import { resolvePublicRuntimeContext, } from "./internal/public-runtime.js";
|
|
8
|
+
import { resolveTtlMilliseconds } from "./internal/ttl.js";
|
|
9
|
+
function createDefaultFetch() {
|
|
10
|
+
if (typeof globalThis.fetch === "function") {
|
|
11
|
+
return globalThis.fetch.bind(globalThis);
|
|
12
|
+
}
|
|
13
|
+
return (async () => {
|
|
14
|
+
throw new Error("fetch is not available in this runtime.");
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
export class PublicBarekeyClient {
|
|
18
|
+
options;
|
|
19
|
+
fetchFn;
|
|
20
|
+
definitionCache = new MemoryCache();
|
|
21
|
+
evaluationCache = new MemoryCache();
|
|
22
|
+
runtimeContextPromise = null;
|
|
23
|
+
requirementsPromise = null;
|
|
24
|
+
constructor(options = {}) {
|
|
25
|
+
this.options = options;
|
|
26
|
+
this.fetchFn = createDefaultFetch();
|
|
27
|
+
}
|
|
28
|
+
get(name, options) {
|
|
29
|
+
return new BarekeyEnvHandle(async () => await this.resolveEvaluatedValue(name, options));
|
|
30
|
+
}
|
|
31
|
+
async getRuntimeContext() {
|
|
32
|
+
if (this.runtimeContextPromise === null) {
|
|
33
|
+
const runtimeContextPromise = resolvePublicRuntimeContext(this.options);
|
|
34
|
+
runtimeContextPromise.catch(() => {
|
|
35
|
+
if (this.runtimeContextPromise === runtimeContextPromise) {
|
|
36
|
+
this.runtimeContextPromise = null;
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
this.runtimeContextPromise = runtimeContextPromise;
|
|
40
|
+
}
|
|
41
|
+
return await this.runtimeContextPromise;
|
|
42
|
+
}
|
|
43
|
+
buildDefinitionCacheKey(context, name) {
|
|
44
|
+
return [context.organization, context.project, context.environment, name].join("|");
|
|
45
|
+
}
|
|
46
|
+
buildEvaluationCacheKey(context, name, options) {
|
|
47
|
+
return [
|
|
48
|
+
context.organization,
|
|
49
|
+
context.project,
|
|
50
|
+
context.environment,
|
|
51
|
+
name,
|
|
52
|
+
options?.seed ?? "",
|
|
53
|
+
options?.key ?? "",
|
|
54
|
+
].join("|");
|
|
55
|
+
}
|
|
56
|
+
async fetchDefinitions(names) {
|
|
57
|
+
const context = await this.getRuntimeContext();
|
|
58
|
+
const response = await postJson({
|
|
59
|
+
fetchFn: this.fetchFn,
|
|
60
|
+
baseUrl: context.baseUrl,
|
|
61
|
+
path: "/v1/public/env/definitions",
|
|
62
|
+
payload: {
|
|
63
|
+
orgSlug: context.organization,
|
|
64
|
+
projectSlug: context.project,
|
|
65
|
+
stageSlug: context.environment,
|
|
66
|
+
...(names === undefined ? {} : { names }),
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
for (const definition of response.definitions) {
|
|
70
|
+
this.definitionCache.set(this.buildDefinitionCacheKey(context, definition.name), definition);
|
|
71
|
+
}
|
|
72
|
+
return response.definitions;
|
|
73
|
+
}
|
|
74
|
+
async ensureRequirementsValidated() {
|
|
75
|
+
const context = await this.getRuntimeContext();
|
|
76
|
+
const requirements = context.requirements;
|
|
77
|
+
if (requirements === undefined) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (this.requirementsPromise === null) {
|
|
81
|
+
const requirementsPromise = (async () => {
|
|
82
|
+
const definitions = await this.fetchDefinitions();
|
|
83
|
+
const values = {};
|
|
84
|
+
for (const definition of definitions) {
|
|
85
|
+
const evaluated = await evaluateDefinition(definition);
|
|
86
|
+
values[definition.name] = parseDeclaredValue(evaluated.value, evaluated.declaredType);
|
|
87
|
+
}
|
|
88
|
+
await validateRequirements(requirements, values);
|
|
89
|
+
})();
|
|
90
|
+
requirementsPromise.catch(() => {
|
|
91
|
+
if (this.requirementsPromise === requirementsPromise) {
|
|
92
|
+
this.requirementsPromise = null;
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
this.requirementsPromise = requirementsPromise;
|
|
96
|
+
}
|
|
97
|
+
await this.requirementsPromise;
|
|
98
|
+
}
|
|
99
|
+
async getStaticDefinition(name) {
|
|
100
|
+
await this.ensureRequirementsValidated();
|
|
101
|
+
const context = await this.getRuntimeContext();
|
|
102
|
+
const cacheKey = this.buildDefinitionCacheKey(context, name);
|
|
103
|
+
const cached = this.definitionCache.get(cacheKey);
|
|
104
|
+
if (cached !== null) {
|
|
105
|
+
return cached;
|
|
106
|
+
}
|
|
107
|
+
const definitions = await this.fetchDefinitions([name]);
|
|
108
|
+
const resolved = definitions[0];
|
|
109
|
+
if (resolved === undefined) {
|
|
110
|
+
throw new VariableNotFoundError();
|
|
111
|
+
}
|
|
112
|
+
return resolved;
|
|
113
|
+
}
|
|
114
|
+
async resolveStaticValue(name, options) {
|
|
115
|
+
const definition = await this.getStaticDefinition(name);
|
|
116
|
+
return await evaluateDefinition(definition, options);
|
|
117
|
+
}
|
|
118
|
+
async resolveDynamicValue(name, options) {
|
|
119
|
+
await this.ensureRequirementsValidated();
|
|
120
|
+
const context = await this.getRuntimeContext();
|
|
121
|
+
const cacheKey = this.buildEvaluationCacheKey(context, name, options);
|
|
122
|
+
const dynamic = options?.dynamic;
|
|
123
|
+
const dynamicTtlMs = dynamic !== undefined && dynamic !== true
|
|
124
|
+
? resolveTtlMilliseconds(dynamic.ttl, "dynamic.ttl")
|
|
125
|
+
: null;
|
|
126
|
+
if (dynamic !== true) {
|
|
127
|
+
const cached = this.evaluationCache.getRecord(cacheKey);
|
|
128
|
+
if (cached !== null && dynamicTtlMs !== null && Date.now() - cached.storedAtMs <= dynamicTtlMs) {
|
|
129
|
+
return cached.value;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
const freshDefinitions = await this.fetchDefinitions([name]);
|
|
133
|
+
const freshDefinition = freshDefinitions[0];
|
|
134
|
+
if (freshDefinition === undefined) {
|
|
135
|
+
throw new VariableNotFoundError();
|
|
136
|
+
}
|
|
137
|
+
const resolved = await evaluateDefinition(freshDefinition, options);
|
|
138
|
+
if (dynamicTtlMs !== null) {
|
|
139
|
+
this.evaluationCache.set(cacheKey, resolved);
|
|
140
|
+
}
|
|
141
|
+
return resolved;
|
|
142
|
+
}
|
|
143
|
+
async resolveEvaluatedValue(name, options) {
|
|
144
|
+
validateDynamicOptions(options);
|
|
145
|
+
if (options?.dynamic === undefined) {
|
|
146
|
+
return await this.resolveStaticValue(name, options);
|
|
147
|
+
}
|
|
148
|
+
return await this.resolveDynamicValue(name, options);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export type { AB, BarekeyCoerceTarget, BarekeyDeclaredType, BarekeyDecision, BarekeyErrorCode, BarekeyEvaluatedValue, BarekeyGetOptions, BarekeyJsonConfig, BarekeyResolvedKind, BarekeyRolloutFunction, BarekeyRolloutMatchedRule, BarekeyRolloutMilestone, BarekeyStandardSchemaPathSegment, BarekeyStandardSchemaResult, BarekeyStandardSchemaV1, BarekeyTemporalInstant, BarekeyTemporalInstantLike, BarekeyTtlInput, BarekeyTypegenResult, BarekeyVariableDefinition, EaseInOut, Env, Linear, Secret, Step, } from "./types.js";
|
|
2
|
+
import type { BarekeyJsonConfig, BarekeyStandardSchemaV1 } from "./types.js";
|
|
3
|
+
export interface BarekeyPublicGeneratedTypeMap {
|
|
4
|
+
}
|
|
5
|
+
export type BarekeyPublicKnownKey = Extract<keyof BarekeyPublicGeneratedTypeMap, string>;
|
|
6
|
+
type BarekeyPublicBaseClientOptions = {
|
|
7
|
+
requirements?: BarekeyStandardSchemaV1;
|
|
8
|
+
baseUrl?: string;
|
|
9
|
+
};
|
|
10
|
+
export type PublicBarekeyClientOptions = (BarekeyPublicBaseClientOptions & {
|
|
11
|
+
organization: string;
|
|
12
|
+
project: string;
|
|
13
|
+
environment: string;
|
|
14
|
+
json?: never;
|
|
15
|
+
}) | (BarekeyPublicBaseClientOptions & {
|
|
16
|
+
json: BarekeyJsonConfig;
|
|
17
|
+
organization?: never;
|
|
18
|
+
project?: never;
|
|
19
|
+
environment?: never;
|
|
20
|
+
}) | (BarekeyPublicBaseClientOptions & {
|
|
21
|
+
organization?: never;
|
|
22
|
+
project?: never;
|
|
23
|
+
environment?: never;
|
|
24
|
+
json?: never;
|
|
25
|
+
});
|
|
26
|
+
//# sourceMappingURL=public-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public-types.d.ts","sourceRoot":"","sources":["../src/public-types.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,EAAE,EACF,mBAAmB,EACnB,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,sBAAsB,EACtB,yBAAyB,EACzB,uBAAuB,EACvB,gCAAgC,EAChC,2BAA2B,EAC3B,uBAAuB,EACvB,sBAAsB,EACtB,0BAA0B,EAC1B,eAAe,EACf,oBAAoB,EACpB,yBAAyB,EACzB,SAAS,EACT,GAAG,EACH,MAAM,EACN,MAAM,EACN,IAAI,GACL,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAE7E,MAAM,WAAW,6BAA6B;CAAG;AAEjD,MAAM,MAAM,qBAAqB,GAAG,OAAO,CAAC,MAAM,6BAA6B,EAAE,MAAM,CAAC,CAAC;AAEzF,KAAK,8BAA8B,GAAG;IACpC,YAAY,CAAC,EAAE,uBAAuB,CAAC;IACvC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAClC,CAAC,8BAA8B,GAAG;IAChC,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,KAAK,CAAC;CACd,CAAC,GACF,CAAC,8BAA8B,GAAG;IAChC,IAAI,EAAE,iBAAiB,CAAC;IACxB,YAAY,CAAC,EAAE,KAAK,CAAC;IACrB,OAAO,CAAC,EAAE,KAAK,CAAC;IAChB,WAAW,CAAC,EAAE,KAAK,CAAC;CACrB,CAAC,GACF,CAAC,8BAA8B,GAAG;IAChC,YAAY,CAAC,EAAE,KAAK,CAAC;IACrB,OAAO,CAAC,EAAE,KAAK,CAAC;IAChB,WAAW,CAAC,EAAE,KAAK,CAAC;IACpB,IAAI,CAAC,EAAE,KAAK,CAAC;CACd,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/public.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { PublicBarekeyClient } from "./public-client.js";
|
|
2
|
+
export { BarekeyEnvHandle } from "./handle.js";
|
|
3
|
+
export { BarekeyError, BillingUnavailableError, CoerceFailedError, DeviceCodeExpiredError, DeviceCodeNotFoundError, EvaluationFailedError, FsNotAvailableError, InvalidConfigurationProvidedError, InvalidCredentialsProvidedError, InvalidDynamicOptionsError, InvalidJsonError, InvalidOrgScopeError, InvalidRefreshTokenError, InvalidRequestError, NetworkError, NoConfigurationProvidedError, NoCredentialsProvidedError, OrgScopeInvalidError, RequirementsValidationFailedError, SdkModuleNotFoundError, TemporalNotAvailableError, TypegenReadFailedError, TypegenUnsupportedSdkError, TypegenWriteFailedError, UnauthorizedError, UnknownError, UsageLimitExceededError, UserCodeInvalidError, VariableNotFoundError, createBarekeyErrorFromCode, docsUrlForErrorCode, formatBarekeyErrorMessage, isBarekeyErrorCode, normalizeErrorCode, } from "./errors.js";
|
|
4
|
+
export type { AB, BarekeyCoerceTarget, BarekeyDeclaredType, BarekeyDecision, BarekeyErrorCode, BarekeyEvaluatedValue, BarekeyGetOptions, BarekeyJsonConfig, BarekeyResolvedKind, BarekeyRolloutFunction, BarekeyRolloutMatchedRule, BarekeyRolloutMilestone, BarekeyStandardSchemaV1, BarekeyTemporalInstant, BarekeyTemporalInstantLike, BarekeyTtlInput, BarekeyVariableDefinition, EaseInOut, Env, Linear, Secret, Step, } from "./types.js";
|
|
5
|
+
export type { BarekeyPublicGeneratedTypeMap, BarekeyPublicKnownKey, PublicBarekeyClientOptions, } from "./public-types.js";
|
|
6
|
+
//# sourceMappingURL=public.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public.d.ts","sourceRoot":"","sources":["../src/public.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EACL,YAAY,EACZ,uBAAuB,EACvB,iBAAiB,EACjB,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,EACrB,mBAAmB,EACnB,iCAAiC,EACjC,+BAA+B,EAC/B,0BAA0B,EAC1B,gBAAgB,EAChB,oBAAoB,EACpB,wBAAwB,EACxB,mBAAmB,EACnB,YAAY,EACZ,4BAA4B,EAC5B,0BAA0B,EAC1B,oBAAoB,EACpB,iCAAiC,EACjC,sBAAsB,EACtB,yBAAyB,EACzB,sBAAsB,EACtB,0BAA0B,EAC1B,uBAAuB,EACvB,iBAAiB,EACjB,YAAY,EACZ,uBAAuB,EACvB,oBAAoB,EACpB,qBAAqB,EACrB,0BAA0B,EAC1B,mBAAmB,EACnB,yBAAyB,EACzB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,aAAa,CAAC;AAErB,YAAY,EACV,EAAE,EACF,mBAAmB,EACnB,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,sBAAsB,EACtB,yBAAyB,EACzB,uBAAuB,EACvB,uBAAuB,EACvB,sBAAsB,EACtB,0BAA0B,EAC1B,eAAe,EACf,yBAAyB,EACzB,SAAS,EACT,GAAG,EACH,MAAM,EACN,MAAM,EACN,IAAI,GACL,MAAM,YAAY,CAAC;AAEpB,YAAY,EACV,6BAA6B,EAC7B,qBAAqB,EACrB,0BAA0B,GAC3B,MAAM,mBAAmB,CAAC"}
|
package/dist/public.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { PublicBarekeyClient } from "./public-client.js";
|
|
2
|
+
export { BarekeyEnvHandle } from "./handle.js";
|
|
3
|
+
export { BarekeyError, BillingUnavailableError, CoerceFailedError, DeviceCodeExpiredError, DeviceCodeNotFoundError, EvaluationFailedError, FsNotAvailableError, InvalidConfigurationProvidedError, InvalidCredentialsProvidedError, InvalidDynamicOptionsError, InvalidJsonError, InvalidOrgScopeError, InvalidRefreshTokenError, InvalidRequestError, NetworkError, NoConfigurationProvidedError, NoCredentialsProvidedError, OrgScopeInvalidError, RequirementsValidationFailedError, SdkModuleNotFoundError, TemporalNotAvailableError, TypegenReadFailedError, TypegenUnsupportedSdkError, TypegenWriteFailedError, UnauthorizedError, UnknownError, UsageLimitExceededError, UserCodeInvalidError, VariableNotFoundError, createBarekeyErrorFromCode, docsUrlForErrorCode, formatBarekeyErrorMessage, isBarekeyErrorCode, normalizeErrorCode, } from "./errors.js";
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { BarekeyClient } from "./client.js";
|
|
2
|
+
export { BarekeyEnvHandle } from "./handle.js";
|
|
3
|
+
export { BarekeyError, BillingUnavailableError, CoerceFailedError, DeviceCodeExpiredError, DeviceCodeNotFoundError, EvaluationFailedError, FsNotAvailableError, InvalidConfigurationProvidedError, InvalidCredentialsProvidedError, InvalidDynamicOptionsError, InvalidJsonError, InvalidOrgScopeError, InvalidRefreshTokenError, InvalidRequestError, NetworkError, NoConfigurationProvidedError, NoCredentialsProvidedError, OrgScopeInvalidError, RequirementsValidationFailedError, SdkModuleNotFoundError, TemporalNotAvailableError, TypegenReadFailedError, TypegenUnsupportedSdkError, TypegenWriteFailedError, UnauthorizedError, UnknownError, UsageLimitExceededError, UserCodeInvalidError, VariableNotFoundError, createBarekeyErrorFromCode, docsUrlForErrorCode, formatBarekeyErrorMessage, isBarekeyErrorCode, normalizeErrorCode, } from "./errors.js";
|
|
4
|
+
export type { AB, BarekeyClientOptions, BarekeyCoerceTarget, BarekeyDeclaredType, BarekeyErrorCode, BarekeyGeneratedTypeMap, BarekeyGetOptions, BarekeyJsonConfig, BarekeyKnownKey, BarekeyResolvedKind, BarekeyRolloutMilestone, BarekeyStandardSchemaV1, BarekeyTemporalInstant, BarekeyTemporalInstantLike, BarekeyTtlInput, BarekeyTypegenResult, Env, Linear, Secret, } from "./types.js";
|
|
5
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EACL,YAAY,EACZ,uBAAuB,EACvB,iBAAiB,EACjB,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,EACrB,mBAAmB,EACnB,iCAAiC,EACjC,+BAA+B,EAC/B,0BAA0B,EAC1B,gBAAgB,EAChB,oBAAoB,EACpB,wBAAwB,EACxB,mBAAmB,EACnB,YAAY,EACZ,4BAA4B,EAC5B,0BAA0B,EAC1B,oBAAoB,EACpB,iCAAiC,EACjC,sBAAsB,EACtB,yBAAyB,EACzB,sBAAsB,EACtB,0BAA0B,EAC1B,uBAAuB,EACvB,iBAAiB,EACjB,YAAY,EACZ,uBAAuB,EACvB,oBAAoB,EACpB,qBAAqB,EACrB,0BAA0B,EAC1B,mBAAmB,EACnB,yBAAyB,EACzB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,aAAa,CAAC;AAErB,YAAY,EACV,EAAE,EACF,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,EAChB,uBAAuB,EACvB,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,mBAAmB,EACnB,uBAAuB,EACvB,uBAAuB,EACvB,sBAAsB,EACtB,0BAA0B,EAC1B,eAAe,EACf,oBAAoB,EACpB,GAAG,EACH,MAAM,EACN,MAAM,GACP,MAAM,YAAY,CAAC"}
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { BarekeyClient } from "./client.js";
|
|
2
|
+
export { BarekeyEnvHandle } from "./handle.js";
|
|
3
|
+
export { BarekeyError, BillingUnavailableError, CoerceFailedError, DeviceCodeExpiredError, DeviceCodeNotFoundError, EvaluationFailedError, FsNotAvailableError, InvalidConfigurationProvidedError, InvalidCredentialsProvidedError, InvalidDynamicOptionsError, InvalidJsonError, InvalidOrgScopeError, InvalidRefreshTokenError, InvalidRequestError, NetworkError, NoConfigurationProvidedError, NoCredentialsProvidedError, OrgScopeInvalidError, RequirementsValidationFailedError, SdkModuleNotFoundError, TemporalNotAvailableError, TypegenReadFailedError, TypegenUnsupportedSdkError, TypegenWriteFailedError, UnauthorizedError, UnknownError, UsageLimitExceededError, UserCodeInvalidError, VariableNotFoundError, createBarekeyErrorFromCode, docsUrlForErrorCode, formatBarekeyErrorMessage, isBarekeyErrorCode, normalizeErrorCode, } from "./errors.js";
|
package/dist/types.d.ts
CHANGED
|
@@ -15,6 +15,14 @@ export type Linear<TMilestones extends ReadonlyArray<readonly [string, number]>
|
|
|
15
15
|
readonly kind: "linear";
|
|
16
16
|
readonly milestones: TMilestones;
|
|
17
17
|
};
|
|
18
|
+
export type Step<TMilestones extends ReadonlyArray<readonly [string, number]> = ReadonlyArray<readonly [string, number]>> = {
|
|
19
|
+
readonly kind: "step";
|
|
20
|
+
readonly milestones: TMilestones;
|
|
21
|
+
};
|
|
22
|
+
export type EaseInOut<TMilestones extends ReadonlyArray<readonly [string, number]> = ReadonlyArray<readonly [string, number]>> = {
|
|
23
|
+
readonly kind: "ease_in_out";
|
|
24
|
+
readonly milestones: TMilestones;
|
|
25
|
+
};
|
|
18
26
|
export type Env<TMode, TValue, TFunction = never> = TValue & {
|
|
19
27
|
readonly __barekey?: {
|
|
20
28
|
readonly mode: TMode;
|
|
@@ -29,12 +37,14 @@ export type BarekeyRolloutMilestone = {
|
|
|
29
37
|
at: string;
|
|
30
38
|
percentage: number;
|
|
31
39
|
};
|
|
40
|
+
export type BarekeyRolloutFunction = "linear" | "step" | "ease_in_out";
|
|
41
|
+
export type BarekeyRolloutMatchedRule = "linear_rollout" | "step_rollout" | "ease_in_out_rollout";
|
|
32
42
|
export type BarekeyDecision = {
|
|
33
43
|
bucket: number;
|
|
34
44
|
chance: number;
|
|
35
45
|
seed?: string;
|
|
36
46
|
key?: string;
|
|
37
|
-
matchedRule: "ab_roll" |
|
|
47
|
+
matchedRule: "ab_roll" | BarekeyRolloutMatchedRule;
|
|
38
48
|
};
|
|
39
49
|
export type BarekeyEvaluatedValue = {
|
|
40
50
|
name: string;
|
|
@@ -62,7 +72,7 @@ export type BarekeyVariableDefinition = {
|
|
|
62
72
|
declaredType: BarekeyDeclaredType;
|
|
63
73
|
valueA: string;
|
|
64
74
|
valueB: string;
|
|
65
|
-
rolloutFunction:
|
|
75
|
+
rolloutFunction: BarekeyRolloutFunction;
|
|
66
76
|
rolloutMilestones: Array<BarekeyRolloutMilestone>;
|
|
67
77
|
};
|
|
68
78
|
export type BarekeyGetOptions = {
|
|
@@ -107,6 +117,8 @@ type BarekeyBaseClientOptions = {
|
|
|
107
117
|
export type BarekeyTypegenResult = {
|
|
108
118
|
written: boolean;
|
|
109
119
|
path: string;
|
|
120
|
+
serverPath: string;
|
|
121
|
+
publicPath: string;
|
|
110
122
|
manifestVersion: string;
|
|
111
123
|
};
|
|
112
124
|
export type BarekeyClientOptions = (BarekeyBaseClientOptions & {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en. */
|
|
3
|
-
/* barekey-manifest-version: REnQvc_83Zn-Xs-tvl2fA375JUy3Jp1IOIoYFB8y-74 */
|
|
4
3
|
|
|
5
4
|
import type { AB, Env, Linear, Secret } from "./dist/types.js";
|
|
6
5
|
|
|
@@ -9,7 +8,14 @@ declare module "./dist/types.js" {
|
|
|
9
8
|
"CODEX_TEST_SECRET": Env<Secret, string>;
|
|
10
9
|
"DATABASE_URL": Env<Secret, string>;
|
|
11
10
|
"foo": Env<Secret, string>;
|
|
12
|
-
"JSON_DEEP": Env<
|
|
11
|
+
"JSON_DEEP": Env<
|
|
12
|
+
Secret,
|
|
13
|
+
{
|
|
14
|
+
bar: boolean;
|
|
15
|
+
foo: string;
|
|
16
|
+
nested: { count: number; flags: Array<boolean>; meta: { label: string } };
|
|
17
|
+
}
|
|
18
|
+
>;
|
|
13
19
|
}
|
|
14
20
|
}
|
|
15
21
|
|
package/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@barekey/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Barekey TypeScript SDK",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -11,18 +11,33 @@
|
|
|
11
11
|
"import": "./dist/index.js",
|
|
12
12
|
"default": "./dist/index.js"
|
|
13
13
|
},
|
|
14
|
+
"./public": {
|
|
15
|
+
"types": "./public.d.ts",
|
|
16
|
+
"import": "./dist/public.js",
|
|
17
|
+
"default": "./dist/public.js"
|
|
18
|
+
},
|
|
19
|
+
"./server": {
|
|
20
|
+
"types": "./server.d.ts",
|
|
21
|
+
"import": "./dist/server.js",
|
|
22
|
+
"default": "./dist/server.js"
|
|
23
|
+
},
|
|
14
24
|
"./package.json": "./package.json"
|
|
15
25
|
},
|
|
16
26
|
"files": [
|
|
17
27
|
"dist",
|
|
18
|
-
"generated.d.ts",
|
|
28
|
+
"generated.public.d.ts",
|
|
29
|
+
"generated.server.d.ts",
|
|
19
30
|
"index.d.ts",
|
|
31
|
+
"public.d.ts",
|
|
32
|
+
"server.d.ts",
|
|
20
33
|
"src"
|
|
21
34
|
],
|
|
22
35
|
"scripts": {
|
|
23
36
|
"build": "tsc -p tsconfig.json",
|
|
24
|
-
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
37
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
38
|
+
"test": "bun test test"
|
|
25
39
|
},
|
|
40
|
+
"packageManager": "bun@1.2.22",
|
|
26
41
|
"devDependencies": {
|
|
27
42
|
"@types/node": "^24.10.1",
|
|
28
43
|
"typescript": "^5.9.3"
|
package/public.d.ts
ADDED
package/server.d.ts
ADDED
package/src/client.ts
CHANGED
|
@@ -17,6 +17,7 @@ import { resolveRuntimeContext, type BarekeyRuntimeContext } from "./internal/ru
|
|
|
17
17
|
import { MemoryCache } from "./internal/cache.js";
|
|
18
18
|
import { DEFAULT_TYPEGEN_TTL_MS, resolveTtlMilliseconds } from "./internal/ttl.js";
|
|
19
19
|
import {
|
|
20
|
+
hasFreshInstalledSdkTypegen,
|
|
20
21
|
resolveInstalledSdkGeneratedTypesPath,
|
|
21
22
|
type TypegenManifest,
|
|
22
23
|
writeInstalledSdkGeneratedTypes,
|
|
@@ -127,7 +128,12 @@ export class BarekeyClient {
|
|
|
127
128
|
}
|
|
128
129
|
|
|
129
130
|
const manifest = await this.fetchTypegenManifest(context);
|
|
130
|
-
return await writeInstalledSdkGeneratedTypes(manifest
|
|
131
|
+
return await writeInstalledSdkGeneratedTypes(manifest, {
|
|
132
|
+
baseUrl: context.baseUrl,
|
|
133
|
+
orgSlug: context.organization,
|
|
134
|
+
projectSlug: context.project,
|
|
135
|
+
stageSlug: context.environment,
|
|
136
|
+
});
|
|
131
137
|
}
|
|
132
138
|
|
|
133
139
|
private async getRuntimeContext(): Promise<BarekeyRuntimeContext> {
|
|
@@ -233,7 +239,16 @@ export class BarekeyClient {
|
|
|
233
239
|
}, intervalMs),
|
|
234
240
|
};
|
|
235
241
|
sharedTypegenWatchers.set(watcherKey, watcher);
|
|
236
|
-
|
|
242
|
+
if (
|
|
243
|
+
!(await hasFreshInstalledSdkTypegen(intervalMs, {
|
|
244
|
+
baseUrl: context.baseUrl,
|
|
245
|
+
orgSlug: context.organization,
|
|
246
|
+
projectSlug: context.project,
|
|
247
|
+
stageSlug: context.environment,
|
|
248
|
+
}))
|
|
249
|
+
) {
|
|
250
|
+
void runWatcher(watcher);
|
|
251
|
+
}
|
|
237
252
|
}
|
|
238
253
|
|
|
239
254
|
private ensureTypegenWatcher(context: BarekeyRuntimeContext): void {
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { BarekeyClient } from "./client.js";
|
|
2
|
+
export { PublicBarekeyClient } from "./public-client.js";
|
|
2
3
|
export { BarekeyEnvHandle } from "./handle.js";
|
|
3
4
|
export {
|
|
4
5
|
BarekeyError,
|
|
@@ -58,3 +59,9 @@ export type {
|
|
|
58
59
|
Linear,
|
|
59
60
|
Secret,
|
|
60
61
|
} from "./types.js";
|
|
62
|
+
|
|
63
|
+
export type {
|
|
64
|
+
BarekeyPublicGeneratedTypeMap,
|
|
65
|
+
BarekeyPublicKnownKey,
|
|
66
|
+
PublicBarekeyClientOptions,
|
|
67
|
+
} from "./public-types.js";
|
package/src/internal/evaluate.ts
CHANGED
|
@@ -13,6 +13,8 @@ import type {
|
|
|
13
13
|
BarekeyDecision,
|
|
14
14
|
BarekeyEvaluatedValue,
|
|
15
15
|
BarekeyGetOptions,
|
|
16
|
+
BarekeyRolloutFunction,
|
|
17
|
+
BarekeyRolloutMatchedRule,
|
|
16
18
|
BarekeyRolloutMilestone,
|
|
17
19
|
BarekeyVariableDefinition,
|
|
18
20
|
} from "../types.js";
|
|
@@ -82,14 +84,76 @@ function resolveLinearRolloutChance(input: {
|
|
|
82
84
|
milestones: Array<BarekeyRolloutMilestone>;
|
|
83
85
|
nowMs: number;
|
|
84
86
|
}): number {
|
|
87
|
+
return resolveRolloutChance({
|
|
88
|
+
function: "linear",
|
|
89
|
+
milestones: input.milestones,
|
|
90
|
+
nowMs: input.nowMs,
|
|
91
|
+
}).chance;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function smoothstep(progress: number): number {
|
|
95
|
+
return progress * progress * (3 - 2 * progress);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function resolveSegmentPercentage(input: {
|
|
99
|
+
function: BarekeyRolloutFunction;
|
|
100
|
+
currentPercentage: number;
|
|
101
|
+
nextPercentage: number;
|
|
102
|
+
progress: number;
|
|
103
|
+
}): number {
|
|
104
|
+
if (input.function === "step") {
|
|
105
|
+
return input.currentPercentage;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (input.function === "ease_in_out") {
|
|
109
|
+
const easedProgress = smoothstep(input.progress);
|
|
110
|
+
return (
|
|
111
|
+
input.currentPercentage +
|
|
112
|
+
(input.nextPercentage - input.currentPercentage) * easedProgress
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return (
|
|
117
|
+
input.currentPercentage +
|
|
118
|
+
(input.nextPercentage - input.currentPercentage) * input.progress
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function matchedRuleForRolloutFunction(
|
|
123
|
+
value: BarekeyRolloutFunction,
|
|
124
|
+
): BarekeyRolloutMatchedRule {
|
|
125
|
+
if (value === "step") {
|
|
126
|
+
return "step_rollout";
|
|
127
|
+
}
|
|
128
|
+
if (value === "ease_in_out") {
|
|
129
|
+
return "ease_in_out_rollout";
|
|
130
|
+
}
|
|
131
|
+
return "linear_rollout";
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function resolveRolloutChance(input: {
|
|
135
|
+
function: BarekeyRolloutFunction;
|
|
136
|
+
milestones: Array<BarekeyRolloutMilestone>;
|
|
137
|
+
nowMs: number;
|
|
138
|
+
}): {
|
|
139
|
+
chance: number;
|
|
140
|
+
matchedRule: BarekeyRolloutMatchedRule;
|
|
141
|
+
} {
|
|
85
142
|
const milestones = normalizeRolloutMilestones(input.milestones);
|
|
143
|
+
const matchedRule = matchedRuleForRolloutFunction(input.function);
|
|
86
144
|
const first = milestones[0];
|
|
87
145
|
if (first === undefined) {
|
|
88
|
-
return
|
|
146
|
+
return {
|
|
147
|
+
chance: 0,
|
|
148
|
+
matchedRule,
|
|
149
|
+
};
|
|
89
150
|
}
|
|
90
151
|
|
|
91
152
|
if (input.nowMs < parseRolloutInstant(first.at)) {
|
|
92
|
-
return
|
|
153
|
+
return {
|
|
154
|
+
chance: 0,
|
|
155
|
+
matchedRule,
|
|
156
|
+
};
|
|
93
157
|
}
|
|
94
158
|
|
|
95
159
|
for (let index = 0; index < milestones.length - 1; index += 1) {
|
|
@@ -103,13 +167,24 @@ function resolveLinearRolloutChance(input: {
|
|
|
103
167
|
const nextAtMs = parseRolloutInstant(next.at);
|
|
104
168
|
if (input.nowMs >= currentAtMs && input.nowMs < nextAtMs) {
|
|
105
169
|
const progress = (input.nowMs - currentAtMs) / (nextAtMs - currentAtMs);
|
|
106
|
-
const percentage =
|
|
107
|
-
|
|
170
|
+
const percentage = resolveSegmentPercentage({
|
|
171
|
+
function: input.function,
|
|
172
|
+
currentPercentage: current.percentage,
|
|
173
|
+
nextPercentage: next.percentage,
|
|
174
|
+
progress,
|
|
175
|
+
});
|
|
176
|
+
return {
|
|
177
|
+
chance: percentage / 100,
|
|
178
|
+
matchedRule,
|
|
179
|
+
};
|
|
108
180
|
}
|
|
109
181
|
}
|
|
110
182
|
|
|
111
183
|
const last = milestones[milestones.length - 1];
|
|
112
|
-
return
|
|
184
|
+
return {
|
|
185
|
+
chance: last === undefined ? 0 : last.percentage / 100,
|
|
186
|
+
matchedRule,
|
|
187
|
+
};
|
|
113
188
|
}
|
|
114
189
|
|
|
115
190
|
export async function evaluateDefinition(
|
|
@@ -150,7 +225,8 @@ export async function evaluateDefinition(
|
|
|
150
225
|
};
|
|
151
226
|
}
|
|
152
227
|
|
|
153
|
-
const chance =
|
|
228
|
+
const { chance, matchedRule } = resolveRolloutChance({
|
|
229
|
+
function: definition.rolloutFunction,
|
|
154
230
|
milestones: definition.rolloutMilestones,
|
|
155
231
|
nowMs: Date.now(),
|
|
156
232
|
});
|
|
@@ -166,7 +242,7 @@ export async function evaluateDefinition(
|
|
|
166
242
|
chance,
|
|
167
243
|
seed: seed.length > 0 ? seed : undefined,
|
|
168
244
|
key: key.length > 0 ? key : undefined,
|
|
169
|
-
matchedRule
|
|
245
|
+
matchedRule,
|
|
170
246
|
},
|
|
171
247
|
};
|
|
172
248
|
}
|
|
@@ -476,7 +476,9 @@ function isMissingModuleError(error: unknown): boolean {
|
|
|
476
476
|
|
|
477
477
|
type InstalledSdkTypegenTarget = {
|
|
478
478
|
packageRoot: string;
|
|
479
|
-
|
|
479
|
+
serverGeneratedTypesPath: string;
|
|
480
|
+
publicGeneratedTypesPath: string;
|
|
481
|
+
typegenMetadataPath: string;
|
|
480
482
|
};
|
|
481
483
|
|
|
482
484
|
export async function resolveInstalledSdkTypegenTarget(): Promise<InstalledSdkTypegenTarget | null> {
|
|
@@ -507,19 +509,23 @@ export async function resolveInstalledSdkTypegenTarget(): Promise<InstalledSdkTy
|
|
|
507
509
|
const candidatePackageJson = runtime.path.join(current, "package.json");
|
|
508
510
|
const rawPackageJson = await readJsonFile<Record<string, unknown>>(runtime, candidatePackageJson);
|
|
509
511
|
if (rawPackageJson !== null && rawPackageJson.name === "@barekey/sdk") {
|
|
510
|
-
const
|
|
512
|
+
const serverGeneratedTypesPath = runtime.path.join(current, "generated.server.d.ts");
|
|
513
|
+
const publicGeneratedTypesPath = runtime.path.join(current, "generated.public.d.ts");
|
|
511
514
|
try {
|
|
512
|
-
await runtime.fs.access(
|
|
515
|
+
await runtime.fs.access(serverGeneratedTypesPath);
|
|
516
|
+
await runtime.fs.access(publicGeneratedTypesPath);
|
|
513
517
|
} catch (error: unknown) {
|
|
514
518
|
throw new TypegenUnsupportedSdkError({
|
|
515
|
-
message: `The installed @barekey/sdk module at ${current} does not include generated.d.ts.`,
|
|
519
|
+
message: `The installed @barekey/sdk module at ${current} does not include generated.server.d.ts and generated.public.d.ts.`,
|
|
516
520
|
cause: error,
|
|
517
521
|
});
|
|
518
522
|
}
|
|
519
523
|
|
|
520
524
|
return {
|
|
521
525
|
packageRoot: current,
|
|
522
|
-
|
|
526
|
+
serverGeneratedTypesPath,
|
|
527
|
+
publicGeneratedTypesPath,
|
|
528
|
+
typegenMetadataPath: runtime.path.join(current, "typegen.json"),
|
|
523
529
|
};
|
|
524
530
|
}
|
|
525
531
|
|