@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
package/README.md
CHANGED
|
@@ -5,17 +5,23 @@ Barekey TypeScript SDK.
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
|
|
8
|
+
bun add @barekey/sdk
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Build
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
|
-
|
|
14
|
+
bun run build
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
## Typecheck
|
|
18
18
|
|
|
19
19
|
```bash
|
|
20
|
-
|
|
20
|
+
bun run typecheck
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Test
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
bun test
|
|
21
27
|
```
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAkB/C,OAAO,KAAK,EACV,oBAAoB,EAEpB,uBAAuB,EACvB,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,oBAAoB,EAErB,MAAM,YAAY,CAAC;AAiDpB,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAuB;IAC/C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA0B;IAClD,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAgD;IAChF,OAAO,CAAC,QAAQ,CAAC,eAAe,CAA4C;IAC5E,OAAO,CAAC,qBAAqB,CAA+C;IAC5E,OAAO,CAAC,mBAAmB,CAA8B;IACzD,OAAO,CAAC,qBAAqB,CAAS;;gBAG1B,OAAO,EAAE;QACnB,YAAY,EAAE,MAAM,CAAC;QACrB,OAAO,EAAE,MAAM,CAAC;QAChB,WAAW,EAAE,MAAM,CAAC;QACpB,YAAY,CAAC,EAAE,oBAAoB,CAAC,cAAc,CAAC,CAAC;QACpD,OAAO,CAAC,EAAE,oBAAoB,CAAC,SAAS,CAAC,CAAC;KAC3C;gBACW,OAAO,EAAE;QACnB,IAAI,EAAE,iBAAiB,CAAC;QACxB,YAAY,CAAC,EAAE,oBAAoB,CAAC,cAAc,CAAC,CAAC;QACpD,OAAO,CAAC,EAAE,oBAAoB,CAAC,SAAS,CAAC,CAAC;KAC3C;IAMD,GAAG,CAAC,IAAI,SAAS,eAAe,EAC9B,IAAI,EAAE,IAAI,EACV,OAAO,CAAC,EAAE,iBAAiB,GAC1B,gBAAgB,CAAC,uBAAuB,CAAC,IAAI,CAAC,CAAC;IAClD,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,gBAAgB,CAAC,OAAO,CAAC;IAOnE,OAAO,IAAI,OAAO,CAAC,oBAAoB,CAAC;YAkBhC,iBAAiB;YAajB,oBAAoB;IAclC,OAAO,CAAC,oBAAoB;YAWd,mBAAmB;IA6EjC,OAAO,CAAC,oBAAoB;IAW5B,OAAO,CAAC,uBAAuB;IAI/B,OAAO,CAAC,uBAAuB;YAejB,gBAAgB;YAsBhB,2BAA2B;YA4B3B,mBAAmB;YAiBnB,kBAAkB;YAQlB,mBAAmB;YAkEnB,qBAAqB;CAYpC"}
|
package/dist/client.js
CHANGED
|
@@ -6,7 +6,7 @@ import { validateRequirements } from "./internal/requirements.js";
|
|
|
6
6
|
import { resolveRuntimeContext } from "./internal/runtime.js";
|
|
7
7
|
import { MemoryCache } from "./internal/cache.js";
|
|
8
8
|
import { DEFAULT_TYPEGEN_TTL_MS, resolveTtlMilliseconds } from "./internal/ttl.js";
|
|
9
|
-
import { resolveInstalledSdkGeneratedTypesPath, writeInstalledSdkGeneratedTypes, } from "./internal/typegen.js";
|
|
9
|
+
import { hasFreshInstalledSdkTypegen, resolveInstalledSdkGeneratedTypesPath, writeInstalledSdkGeneratedTypes, } from "./internal/typegen.js";
|
|
10
10
|
const sharedTypegenWatchers = new Map();
|
|
11
11
|
function createDefaultFetch() {
|
|
12
12
|
if (typeof globalThis.fetch === "function") {
|
|
@@ -53,7 +53,12 @@ export class BarekeyClient {
|
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
55
|
const manifest = await this.fetchTypegenManifest(context);
|
|
56
|
-
return await writeInstalledSdkGeneratedTypes(manifest
|
|
56
|
+
return await writeInstalledSdkGeneratedTypes(manifest, {
|
|
57
|
+
baseUrl: context.baseUrl,
|
|
58
|
+
orgSlug: context.organization,
|
|
59
|
+
projectSlug: context.project,
|
|
60
|
+
stageSlug: context.environment,
|
|
61
|
+
});
|
|
57
62
|
}
|
|
58
63
|
async getRuntimeContext() {
|
|
59
64
|
if (this.runtimeContextPromise === null) {
|
|
@@ -146,7 +151,14 @@ export class BarekeyClient {
|
|
|
146
151
|
}, intervalMs),
|
|
147
152
|
};
|
|
148
153
|
sharedTypegenWatchers.set(watcherKey, watcher);
|
|
149
|
-
|
|
154
|
+
if (!(await hasFreshInstalledSdkTypegen(intervalMs, {
|
|
155
|
+
baseUrl: context.baseUrl,
|
|
156
|
+
orgSlug: context.organization,
|
|
157
|
+
projectSlug: context.project,
|
|
158
|
+
stageSlug: context.environment,
|
|
159
|
+
}))) {
|
|
160
|
+
void runWatcher(watcher);
|
|
161
|
+
}
|
|
150
162
|
}
|
|
151
163
|
ensureTypegenWatcher(context) {
|
|
152
164
|
if (this.typegenWatcherStarted || this.options.typegen === false || context.environment !== "development") {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export { BarekeyClient } from "./client.js";
|
|
2
|
+
export { PublicBarekeyClient } from "./public-client.js";
|
|
2
3
|
export { BarekeyEnvHandle } from "./handle.js";
|
|
3
4
|
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
5
|
export type { AB, BarekeyClientOptions, BarekeyCoerceTarget, BarekeyDeclaredType, BarekeyErrorCode, BarekeyGeneratedTypeMap, BarekeyGetOptions, BarekeyJsonConfig, BarekeyKnownKey, BarekeyResolvedKind, BarekeyRolloutMilestone, BarekeyStandardSchemaV1, BarekeyTemporalInstant, BarekeyTemporalInstantLike, BarekeyTtlInput, BarekeyTypegenResult, Env, Linear, Secret, } from "./types.js";
|
|
6
|
+
export type { BarekeyPublicGeneratedTypeMap, BarekeyPublicKnownKey, PublicBarekeyClientOptions, } from "./public-types.js";
|
|
5
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.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"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,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,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;AAEpB,YAAY,EACV,6BAA6B,EAC7B,qBAAqB,EACrB,0BAA0B,GAC3B,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { BarekeyClient } from "./client.js";
|
|
2
|
+
export { PublicBarekeyClient } from "./public-client.js";
|
|
2
3
|
export { BarekeyEnvHandle } from "./handle.js";
|
|
3
4
|
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";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluate.d.ts","sourceRoot":"","sources":["../../src/internal/evaluate.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,mBAAmB,EACnB,mBAAmB,EACnB,eAAe,EACf,qBAAqB,EACrB,iBAAiB,
|
|
1
|
+
{"version":3,"file":"evaluate.d.ts","sourceRoot":"","sources":["../../src/internal/evaluate.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,mBAAmB,EACnB,mBAAmB,EACnB,eAAe,EACf,qBAAqB,EACrB,iBAAiB,EAIjB,yBAAyB,EAC1B,MAAM,aAAa,CAAC;AAgDrB,wBAAgB,sBAAsB,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,IAAI,CAKxE;AAqHD,wBAAsB,kBAAkB,CACtC,UAAU,EAAE,yBAAyB,EACrC,OAAO,CAAC,EAAE,IAAI,CAAC,iBAAiB,EAAE,MAAM,GAAG,KAAK,CAAC,GAChD,OAAO,CAAC,qBAAqB,CAAC,CAuDhC;AAED,wBAAgB,4BAA4B,CAAC,QAAQ,CAAC,EAAE,eAAe,GAAG,GAAG,GAAG,GAAG,GAAG,SAAS,CAQ9F;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,mBAAmB,GAAG,OAAO,CAiB5F;AAED,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,qBAAqB,EAC/B,MAAM,EAAE,mBAAmB,GAC1B,OAAO,CA0BT"}
|
|
@@ -50,13 +50,51 @@ async function deterministicBucket(input) {
|
|
|
50
50
|
return (value >>> 0) / 4294967296;
|
|
51
51
|
}
|
|
52
52
|
function resolveLinearRolloutChance(input) {
|
|
53
|
+
return resolveRolloutChance({
|
|
54
|
+
function: "linear",
|
|
55
|
+
milestones: input.milestones,
|
|
56
|
+
nowMs: input.nowMs,
|
|
57
|
+
}).chance;
|
|
58
|
+
}
|
|
59
|
+
function smoothstep(progress) {
|
|
60
|
+
return progress * progress * (3 - 2 * progress);
|
|
61
|
+
}
|
|
62
|
+
function resolveSegmentPercentage(input) {
|
|
63
|
+
if (input.function === "step") {
|
|
64
|
+
return input.currentPercentage;
|
|
65
|
+
}
|
|
66
|
+
if (input.function === "ease_in_out") {
|
|
67
|
+
const easedProgress = smoothstep(input.progress);
|
|
68
|
+
return (input.currentPercentage +
|
|
69
|
+
(input.nextPercentage - input.currentPercentage) * easedProgress);
|
|
70
|
+
}
|
|
71
|
+
return (input.currentPercentage +
|
|
72
|
+
(input.nextPercentage - input.currentPercentage) * input.progress);
|
|
73
|
+
}
|
|
74
|
+
function matchedRuleForRolloutFunction(value) {
|
|
75
|
+
if (value === "step") {
|
|
76
|
+
return "step_rollout";
|
|
77
|
+
}
|
|
78
|
+
if (value === "ease_in_out") {
|
|
79
|
+
return "ease_in_out_rollout";
|
|
80
|
+
}
|
|
81
|
+
return "linear_rollout";
|
|
82
|
+
}
|
|
83
|
+
function resolveRolloutChance(input) {
|
|
53
84
|
const milestones = normalizeRolloutMilestones(input.milestones);
|
|
85
|
+
const matchedRule = matchedRuleForRolloutFunction(input.function);
|
|
54
86
|
const first = milestones[0];
|
|
55
87
|
if (first === undefined) {
|
|
56
|
-
return
|
|
88
|
+
return {
|
|
89
|
+
chance: 0,
|
|
90
|
+
matchedRule,
|
|
91
|
+
};
|
|
57
92
|
}
|
|
58
93
|
if (input.nowMs < parseRolloutInstant(first.at)) {
|
|
59
|
-
return
|
|
94
|
+
return {
|
|
95
|
+
chance: 0,
|
|
96
|
+
matchedRule,
|
|
97
|
+
};
|
|
60
98
|
}
|
|
61
99
|
for (let index = 0; index < milestones.length - 1; index += 1) {
|
|
62
100
|
const current = milestones[index];
|
|
@@ -68,12 +106,23 @@ function resolveLinearRolloutChance(input) {
|
|
|
68
106
|
const nextAtMs = parseRolloutInstant(next.at);
|
|
69
107
|
if (input.nowMs >= currentAtMs && input.nowMs < nextAtMs) {
|
|
70
108
|
const progress = (input.nowMs - currentAtMs) / (nextAtMs - currentAtMs);
|
|
71
|
-
const percentage =
|
|
72
|
-
|
|
109
|
+
const percentage = resolveSegmentPercentage({
|
|
110
|
+
function: input.function,
|
|
111
|
+
currentPercentage: current.percentage,
|
|
112
|
+
nextPercentage: next.percentage,
|
|
113
|
+
progress,
|
|
114
|
+
});
|
|
115
|
+
return {
|
|
116
|
+
chance: percentage / 100,
|
|
117
|
+
matchedRule,
|
|
118
|
+
};
|
|
73
119
|
}
|
|
74
120
|
}
|
|
75
121
|
const last = milestones[milestones.length - 1];
|
|
76
|
-
return
|
|
122
|
+
return {
|
|
123
|
+
chance: last === undefined ? 0 : last.percentage / 100,
|
|
124
|
+
matchedRule,
|
|
125
|
+
};
|
|
77
126
|
}
|
|
78
127
|
export async function evaluateDefinition(definition, options) {
|
|
79
128
|
if (definition.kind === "secret") {
|
|
@@ -106,7 +155,8 @@ export async function evaluateDefinition(definition, options) {
|
|
|
106
155
|
},
|
|
107
156
|
};
|
|
108
157
|
}
|
|
109
|
-
const chance =
|
|
158
|
+
const { chance, matchedRule } = resolveRolloutChance({
|
|
159
|
+
function: definition.rolloutFunction,
|
|
110
160
|
milestones: definition.rolloutMilestones,
|
|
111
161
|
nowMs: Date.now(),
|
|
112
162
|
});
|
|
@@ -122,7 +172,7 @@ export async function evaluateDefinition(definition, options) {
|
|
|
122
172
|
chance,
|
|
123
173
|
seed: seed.length > 0 ? seed : undefined,
|
|
124
174
|
key: key.length > 0 ? key : undefined,
|
|
125
|
-
matchedRule
|
|
175
|
+
matchedRule,
|
|
126
176
|
},
|
|
127
177
|
};
|
|
128
178
|
}
|
|
@@ -10,7 +10,9 @@ export declare function loadCliSessionAuthResolver(fetchFn: typeof globalThis.fe
|
|
|
10
10
|
} | null>;
|
|
11
11
|
type InstalledSdkTypegenTarget = {
|
|
12
12
|
packageRoot: string;
|
|
13
|
-
|
|
13
|
+
serverGeneratedTypesPath: string;
|
|
14
|
+
publicGeneratedTypesPath: string;
|
|
15
|
+
typegenMetadataPath: string;
|
|
14
16
|
};
|
|
15
17
|
export declare function resolveInstalledSdkTypegenTarget(): Promise<InstalledSdkTypegenTarget | null>;
|
|
16
18
|
export declare function readTextFile(filePath: string): Promise<string | null>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-runtime.d.ts","sourceRoot":"","sources":["../../src/internal/node-runtime.ts"],"names":[],"mappings":"AA4VA,wBAAsB,qBAAqB,IAAI,OAAO,CAAC,OAAO,CAAC,CAE9D;AAED,wBAAsB,qBAAqB,IAAI,OAAO,CAAC;IACrD,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B,GAAG,IAAI,CAAC,CAwCR;AAED,wBAAsB,0BAA0B,CAAC,OAAO,EAAE,OAAO,UAAU,CAAC,KAAK,GAAG,OAAO,CAAC;IAC1F,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAClC,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACjC,GAAG,IAAI,CAAC,CAoER;AAOD,KAAK,yBAAyB,GAAG;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,
|
|
1
|
+
{"version":3,"file":"node-runtime.d.ts","sourceRoot":"","sources":["../../src/internal/node-runtime.ts"],"names":[],"mappings":"AA4VA,wBAAsB,qBAAqB,IAAI,OAAO,CAAC,OAAO,CAAC,CAE9D;AAED,wBAAsB,qBAAqB,IAAI,OAAO,CAAC;IACrD,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B,GAAG,IAAI,CAAC,CAwCR;AAED,wBAAsB,0BAA0B,CAAC,OAAO,EAAE,OAAO,UAAU,CAAC,KAAK,GAAG,OAAO,CAAC;IAC1F,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAClC,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACjC,GAAG,IAAI,CAAC,CAoER;AAOD,KAAK,yBAAyB,GAAG;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,wBAAwB,EAAE,MAAM,CAAC;IACjC,wBAAwB,EAAE,MAAM,CAAC;IACjC,mBAAmB,EAAE,MAAM,CAAC;CAC7B,CAAC;AAEF,wBAAsB,gCAAgC,IAAI,OAAO,CAAC,yBAAyB,GAAG,IAAI,CAAC,CA0DlG;AAED,wBAAsB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAkB3E;AAED,wBAAsB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAuBxF"}
|
|
@@ -351,19 +351,23 @@ export async function resolveInstalledSdkTypegenTarget() {
|
|
|
351
351
|
const candidatePackageJson = runtime.path.join(current, "package.json");
|
|
352
352
|
const rawPackageJson = await readJsonFile(runtime, candidatePackageJson);
|
|
353
353
|
if (rawPackageJson !== null && rawPackageJson.name === "@barekey/sdk") {
|
|
354
|
-
const
|
|
354
|
+
const serverGeneratedTypesPath = runtime.path.join(current, "generated.server.d.ts");
|
|
355
|
+
const publicGeneratedTypesPath = runtime.path.join(current, "generated.public.d.ts");
|
|
355
356
|
try {
|
|
356
|
-
await runtime.fs.access(
|
|
357
|
+
await runtime.fs.access(serverGeneratedTypesPath);
|
|
358
|
+
await runtime.fs.access(publicGeneratedTypesPath);
|
|
357
359
|
}
|
|
358
360
|
catch (error) {
|
|
359
361
|
throw new TypegenUnsupportedSdkError({
|
|
360
|
-
message: `The installed @barekey/sdk module at ${current} does not include generated.d.ts.`,
|
|
362
|
+
message: `The installed @barekey/sdk module at ${current} does not include generated.server.d.ts and generated.public.d.ts.`,
|
|
361
363
|
cause: error,
|
|
362
364
|
});
|
|
363
365
|
}
|
|
364
366
|
return {
|
|
365
367
|
packageRoot: current,
|
|
366
|
-
|
|
368
|
+
serverGeneratedTypesPath,
|
|
369
|
+
publicGeneratedTypesPath,
|
|
370
|
+
typegenMetadataPath: runtime.path.join(current, "typegen.json"),
|
|
367
371
|
};
|
|
368
372
|
}
|
|
369
373
|
const parent = runtime.path.dirname(current);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { PublicBarekeyClientOptions } from "../public-types.js";
|
|
2
|
+
import type { BarekeyStandardSchemaV1 } from "../types.js";
|
|
3
|
+
type BarekeyResolvedScope = {
|
|
4
|
+
organization: string;
|
|
5
|
+
project: string;
|
|
6
|
+
environment: string;
|
|
7
|
+
};
|
|
8
|
+
export type BarekeyPublicRuntimeContext = BarekeyResolvedScope & {
|
|
9
|
+
baseUrl: string;
|
|
10
|
+
requirements?: BarekeyStandardSchemaV1;
|
|
11
|
+
};
|
|
12
|
+
export declare function resolvePublicRuntimeContext(options: PublicBarekeyClientOptions): Promise<BarekeyPublicRuntimeContext>;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=public-runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public-runtime.d.ts","sourceRoot":"","sources":["../../src/internal/public-runtime.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,KAAK,EAAqB,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAM9E,KAAK,oBAAoB,GAAG;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,2BAA2B,GAAG,oBAAoB,GAAG;IAC/D,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,uBAAuB,CAAC;CACxC,CAAC;AA4FF,wBAAsB,2BAA2B,CAC/C,OAAO,EAAE,0BAA0B,GAClC,OAAO,CAAC,2BAA2B,CAAC,CAOtC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { FsNotAvailableError, InvalidConfigurationProvidedError, NoConfigurationProvidedError, } from "../errors.js";
|
|
2
|
+
import { normalizeBaseUrl } from "./http.js";
|
|
3
|
+
import { isFilesystemAvailable, loadBarekeyJsonConfig } from "./node-runtime.js";
|
|
4
|
+
const DEFAULT_BAREKEY_API_URL = "https://api.barekey.dev";
|
|
5
|
+
function readConfigString(value) {
|
|
6
|
+
return typeof value === "string" ? value.trim() : undefined;
|
|
7
|
+
}
|
|
8
|
+
function normalizeScope(input) {
|
|
9
|
+
const organization = readConfigString(input.organization) ?? "";
|
|
10
|
+
const project = readConfigString(input.project) ?? "";
|
|
11
|
+
const environment = readConfigString(input.environment) ?? "";
|
|
12
|
+
if (organization.length === 0 || project.length === 0 || environment.length === 0) {
|
|
13
|
+
throw new InvalidConfigurationProvidedError({
|
|
14
|
+
message: `${input.source} must provide organization, project, and environment.`,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
organization,
|
|
19
|
+
project,
|
|
20
|
+
environment,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function normalizeJsonConfig(input, source) {
|
|
24
|
+
return normalizeScope({
|
|
25
|
+
organization: input.organization ?? input.org,
|
|
26
|
+
project: input.project,
|
|
27
|
+
environment: input.environment ?? input.stage,
|
|
28
|
+
source,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
async function resolveScope(options) {
|
|
32
|
+
const explicitOrganization = "organization" in options ? options.organization : undefined;
|
|
33
|
+
const explicitProject = "project" in options ? options.project : undefined;
|
|
34
|
+
const explicitEnvironment = "environment" in options ? options.environment : undefined;
|
|
35
|
+
const explicitJson = "json" in options ? options.json : undefined;
|
|
36
|
+
const explicitCount = Number(explicitOrganization !== undefined) +
|
|
37
|
+
Number(explicitProject !== undefined) +
|
|
38
|
+
Number(explicitEnvironment !== undefined);
|
|
39
|
+
if (explicitJson !== undefined && explicitCount > 0) {
|
|
40
|
+
throw new InvalidConfigurationProvidedError({
|
|
41
|
+
message: "Pass either json or organization/project/environment, not both.",
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
if (explicitCount > 0 && explicitCount < 3) {
|
|
45
|
+
throw new InvalidConfigurationProvidedError({
|
|
46
|
+
message: "organization, project, and environment must be provided together.",
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
if (explicitJson !== undefined) {
|
|
50
|
+
return normalizeJsonConfig(explicitJson, "The provided json configuration");
|
|
51
|
+
}
|
|
52
|
+
if (explicitCount === 3) {
|
|
53
|
+
return normalizeScope({
|
|
54
|
+
organization: explicitOrganization,
|
|
55
|
+
project: explicitProject,
|
|
56
|
+
environment: explicitEnvironment,
|
|
57
|
+
source: "The provided Barekey configuration",
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
const loadedConfig = await loadBarekeyJsonConfig();
|
|
61
|
+
if (loadedConfig === null) {
|
|
62
|
+
if (!(await isFilesystemAvailable())) {
|
|
63
|
+
throw new FsNotAvailableError();
|
|
64
|
+
}
|
|
65
|
+
throw new NoConfigurationProvidedError({
|
|
66
|
+
message: "No Barekey configuration was found and no barekey.json file could be loaded.",
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return normalizeJsonConfig(loadedConfig.json, `The barekey.json file at ${loadedConfig.path}`);
|
|
70
|
+
}
|
|
71
|
+
export async function resolvePublicRuntimeContext(options) {
|
|
72
|
+
const scope = await resolveScope(options);
|
|
73
|
+
return {
|
|
74
|
+
...scope,
|
|
75
|
+
baseUrl: normalizeBaseUrl(options.baseUrl?.trim() || DEFAULT_BAREKEY_API_URL),
|
|
76
|
+
requirements: options.requirements,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { BarekeyRolloutMilestone, BarekeyTypegenResult } from "../types.js";
|
|
1
|
+
import type { BarekeyRolloutFunction, BarekeyRolloutMilestone, BarekeyTypegenResult } from "../types.js";
|
|
2
2
|
export type TypegenManifestVariable = {
|
|
3
3
|
name: string;
|
|
4
|
+
visibility: "private" | "public";
|
|
4
5
|
kind: "secret" | "ab_roll" | "rollout";
|
|
5
6
|
declaredType: "string" | "boolean" | "int64" | "float" | "date" | "json";
|
|
6
7
|
required: boolean;
|
|
@@ -8,7 +9,7 @@ export type TypegenManifestVariable = {
|
|
|
8
9
|
typeScriptType: string;
|
|
9
10
|
valueATypeScriptType: string | null;
|
|
10
11
|
valueBTypeScriptType: string | null;
|
|
11
|
-
rolloutFunction:
|
|
12
|
+
rolloutFunction: BarekeyRolloutFunction | null;
|
|
12
13
|
rolloutMilestones: Array<BarekeyRolloutMilestone> | null;
|
|
13
14
|
};
|
|
14
15
|
export type TypegenManifest = {
|
|
@@ -20,6 +21,18 @@ export type TypegenManifest = {
|
|
|
20
21
|
manifestVersion: string;
|
|
21
22
|
variables: Array<TypegenManifestVariable>;
|
|
22
23
|
};
|
|
24
|
+
type TypegenMetadataIdentity = {
|
|
25
|
+
baseUrl: string;
|
|
26
|
+
orgSlug: string;
|
|
27
|
+
projectSlug: string;
|
|
28
|
+
stageSlug: string;
|
|
29
|
+
};
|
|
23
30
|
export declare function resolveInstalledSdkGeneratedTypesPath(): Promise<string | null>;
|
|
24
|
-
export declare function
|
|
31
|
+
export declare function renderGeneratedTypesForManifest(manifest: TypegenManifest): {
|
|
32
|
+
serverContents: string;
|
|
33
|
+
publicContents: string;
|
|
34
|
+
};
|
|
35
|
+
export declare function hasFreshInstalledSdkTypegen(intervalMs: number, identity: TypegenMetadataIdentity): Promise<boolean>;
|
|
36
|
+
export declare function writeInstalledSdkGeneratedTypes(manifest: TypegenManifest, identity: TypegenMetadataIdentity): Promise<BarekeyTypegenResult>;
|
|
37
|
+
export {};
|
|
25
38
|
//# sourceMappingURL=typegen.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typegen.d.ts","sourceRoot":"","sources":["../../src/internal/typegen.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"typegen.d.ts","sourceRoot":"","sources":["../../src/internal/typegen.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,sBAAsB,EACtB,uBAAuB,EACvB,oBAAoB,EACrB,MAAM,aAAa,CAAC;AAErB,MAAM,MAAM,uBAAuB,GAAG;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,SAAS,GAAG,QAAQ,CAAC;IACjC,IAAI,EAAE,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;IACvC,YAAY,EAAE,QAAQ,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;IACzE,QAAQ,EAAE,OAAO,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,oBAAoB,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,eAAe,EAAE,sBAAsB,GAAG,IAAI,CAAC;IAC/C,iBAAiB,EAAE,KAAK,CAAC,uBAAuB,CAAC,GAAG,IAAI,CAAC;CAC1D,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,KAAK,CAAC,uBAAuB,CAAC,CAAC;CAC3C,CAAC;AAcF,KAAK,uBAAuB,GAAG;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAqJF,wBAAsB,qCAAqC,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAGpF;AAED,wBAAgB,+BAA+B,CAAC,QAAQ,EAAE,eAAe,GAAG;IAC1E,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;CACxB,CAeA;AAED,wBAAsB,2BAA2B,CAC/C,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,uBAAuB,GAChC,OAAO,CAAC,OAAO,CAAC,CAqBlB;AAED,wBAAsB,+BAA+B,CACnD,QAAQ,EAAE,eAAe,EACzB,QAAQ,EAAE,uBAAuB,GAChC,OAAO,CAAC,oBAAoB,CAAC,CAwD/B"}
|
package/dist/internal/typegen.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { readTextFile, resolveInstalledSdkTypegenTarget, writeTextFileAtomic, } from "./node-runtime.js";
|
|
2
2
|
const MANIFEST_VERSION_PATTERN = /\/\* barekey-manifest-version: ([^\n]+) \*\//;
|
|
3
|
+
const TYPEGEN_METADATA_VERSION = 1;
|
|
3
4
|
function renderLinearMilestones(milestones) {
|
|
4
5
|
if (milestones.length === 0) {
|
|
5
6
|
return "readonly []";
|
|
@@ -8,6 +9,16 @@ function renderLinearMilestones(milestones) {
|
|
|
8
9
|
.map((milestone) => `readonly [${JSON.stringify(milestone.at)}, ${String(milestone.percentage)}]`)
|
|
9
10
|
.join(", ")}]`;
|
|
10
11
|
}
|
|
12
|
+
function renderRolloutMetadataType(row) {
|
|
13
|
+
const renderedMilestones = renderLinearMilestones(row.rolloutMilestones ?? []);
|
|
14
|
+
if (row.rolloutFunction === "step") {
|
|
15
|
+
return `Step<${renderedMilestones}>`;
|
|
16
|
+
}
|
|
17
|
+
if (row.rolloutFunction === "ease_in_out") {
|
|
18
|
+
return `EaseInOut<${renderedMilestones}>`;
|
|
19
|
+
}
|
|
20
|
+
return `Linear<${renderedMilestones}>`;
|
|
21
|
+
}
|
|
11
22
|
function renderVariableType(row) {
|
|
12
23
|
if (row.kind === "secret") {
|
|
13
24
|
return `Env<Secret, ${row.typeScriptType}>`;
|
|
@@ -15,11 +26,12 @@ function renderVariableType(row) {
|
|
|
15
26
|
if (row.kind === "ab_roll") {
|
|
16
27
|
return `Env<AB, ${row.typeScriptType}>`;
|
|
17
28
|
}
|
|
18
|
-
return `Env<AB, ${row.typeScriptType},
|
|
29
|
+
return `Env<AB, ${row.typeScriptType}, ${renderRolloutMetadataType(row)}>`;
|
|
19
30
|
}
|
|
20
|
-
function buildGeneratedTypesContents(manifest) {
|
|
31
|
+
function buildGeneratedTypesContents(manifest, input) {
|
|
21
32
|
const mapLines = manifest.variables
|
|
22
33
|
.slice()
|
|
34
|
+
.filter(input.include)
|
|
23
35
|
.sort((left, right) => left.name.localeCompare(right.name))
|
|
24
36
|
.map((row) => ` ${JSON.stringify(row.name)}: ${renderVariableType(row)};`)
|
|
25
37
|
.join("\n");
|
|
@@ -27,10 +39,10 @@ function buildGeneratedTypesContents(manifest) {
|
|
|
27
39
|
/* This file is generated by barekey typegen. */
|
|
28
40
|
/* barekey-manifest-version: ${manifest.manifestVersion} */
|
|
29
41
|
|
|
30
|
-
import type { AB, Env, Linear, Secret } from "
|
|
42
|
+
import type { AB, EaseInOut, Env, Linear, Secret, Step } from "${input.typeModulePath}";
|
|
31
43
|
|
|
32
|
-
declare module "
|
|
33
|
-
interface
|
|
44
|
+
declare module "${input.declaredModulePath}" {
|
|
45
|
+
interface ${input.interfaceName} {
|
|
34
46
|
${mapLines.length > 0 ? mapLines : ""}
|
|
35
47
|
}
|
|
36
48
|
}
|
|
@@ -45,31 +57,130 @@ function readManifestVersion(contents) {
|
|
|
45
57
|
const match = contents.match(MANIFEST_VERSION_PATTERN);
|
|
46
58
|
return match?.[1]?.trim() ?? null;
|
|
47
59
|
}
|
|
60
|
+
function parseTypegenMetadata(contents) {
|
|
61
|
+
if (contents === null) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
const parsed = JSON.parse(contents);
|
|
66
|
+
if (typeof parsed !== "object" || parsed === null) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
const candidate = parsed;
|
|
70
|
+
if (candidate.version !== TYPEGEN_METADATA_VERSION ||
|
|
71
|
+
typeof candidate.last !== "string" ||
|
|
72
|
+
(candidate.baseUrl !== undefined &&
|
|
73
|
+
candidate.baseUrl !== null &&
|
|
74
|
+
typeof candidate.baseUrl !== "string") ||
|
|
75
|
+
(candidate.orgSlug !== undefined &&
|
|
76
|
+
candidate.orgSlug !== null &&
|
|
77
|
+
typeof candidate.orgSlug !== "string") ||
|
|
78
|
+
(candidate.projectSlug !== undefined &&
|
|
79
|
+
candidate.projectSlug !== null &&
|
|
80
|
+
typeof candidate.projectSlug !== "string") ||
|
|
81
|
+
(candidate.stageSlug !== undefined &&
|
|
82
|
+
candidate.stageSlug !== null &&
|
|
83
|
+
typeof candidate.stageSlug !== "string") ||
|
|
84
|
+
!Number.isFinite(Date.parse(candidate.last))) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
version: TYPEGEN_METADATA_VERSION,
|
|
89
|
+
last: candidate.last,
|
|
90
|
+
baseUrl: candidate.baseUrl ?? null,
|
|
91
|
+
orgSlug: candidate.orgSlug ?? null,
|
|
92
|
+
projectSlug: candidate.projectSlug ?? null,
|
|
93
|
+
stageSlug: candidate.stageSlug ?? null,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function buildTypegenMetadataContents(lastGeneratedAt, identity) {
|
|
101
|
+
return `${JSON.stringify({
|
|
102
|
+
version: TYPEGEN_METADATA_VERSION,
|
|
103
|
+
last: lastGeneratedAt.toISOString(),
|
|
104
|
+
baseUrl: identity.baseUrl,
|
|
105
|
+
orgSlug: identity.orgSlug,
|
|
106
|
+
projectSlug: identity.projectSlug,
|
|
107
|
+
stageSlug: identity.stageSlug,
|
|
108
|
+
}, null, 2)}\n`;
|
|
109
|
+
}
|
|
48
110
|
export async function resolveInstalledSdkGeneratedTypesPath() {
|
|
49
111
|
const target = await resolveInstalledSdkTypegenTarget();
|
|
50
|
-
return target?.
|
|
112
|
+
return target?.serverGeneratedTypesPath ?? null;
|
|
113
|
+
}
|
|
114
|
+
export function renderGeneratedTypesForManifest(manifest) {
|
|
115
|
+
return {
|
|
116
|
+
serverContents: buildGeneratedTypesContents(manifest, {
|
|
117
|
+
typeModulePath: "./dist/types.js",
|
|
118
|
+
declaredModulePath: "./dist/types.js",
|
|
119
|
+
interfaceName: "BarekeyGeneratedTypeMap",
|
|
120
|
+
include: () => true,
|
|
121
|
+
}),
|
|
122
|
+
publicContents: buildGeneratedTypesContents(manifest, {
|
|
123
|
+
typeModulePath: "./dist/public-types.js",
|
|
124
|
+
declaredModulePath: "./dist/public-types.js",
|
|
125
|
+
interfaceName: "BarekeyPublicGeneratedTypeMap",
|
|
126
|
+
include: (row) => row.visibility === "public",
|
|
127
|
+
}),
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
export async function hasFreshInstalledSdkTypegen(intervalMs, identity) {
|
|
131
|
+
const target = await resolveInstalledSdkTypegenTarget();
|
|
132
|
+
if (target === null) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
const metadata = parseTypegenMetadata(await readTextFile(target.typegenMetadataPath));
|
|
136
|
+
if (metadata === null) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
if (metadata.baseUrl !== identity.baseUrl ||
|
|
140
|
+
metadata.orgSlug !== identity.orgSlug ||
|
|
141
|
+
metadata.projectSlug !== identity.projectSlug ||
|
|
142
|
+
metadata.stageSlug !== identity.stageSlug) {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
return Date.now() - Date.parse(metadata.last) < intervalMs;
|
|
51
146
|
}
|
|
52
|
-
export async function writeInstalledSdkGeneratedTypes(manifest) {
|
|
147
|
+
export async function writeInstalledSdkGeneratedTypes(manifest, identity) {
|
|
53
148
|
const target = await resolveInstalledSdkTypegenTarget();
|
|
54
149
|
if (target === null) {
|
|
55
150
|
return {
|
|
56
151
|
written: false,
|
|
57
152
|
path: "",
|
|
153
|
+
serverPath: "",
|
|
154
|
+
publicPath: "",
|
|
58
155
|
manifestVersion: manifest.manifestVersion,
|
|
59
156
|
};
|
|
60
157
|
}
|
|
61
|
-
const
|
|
62
|
-
|
|
158
|
+
const [existingServerContents, existingPublicContents] = await Promise.all([
|
|
159
|
+
readTextFile(target.serverGeneratedTypesPath),
|
|
160
|
+
readTextFile(target.publicGeneratedTypesPath),
|
|
161
|
+
]);
|
|
162
|
+
if (readManifestVersion(existingServerContents) === manifest.manifestVersion &&
|
|
163
|
+
readManifestVersion(existingPublicContents) === manifest.manifestVersion) {
|
|
164
|
+
await writeTextFileAtomic(target.typegenMetadataPath, buildTypegenMetadataContents(new Date(), identity));
|
|
63
165
|
return {
|
|
64
166
|
written: false,
|
|
65
|
-
path: target.
|
|
167
|
+
path: target.serverGeneratedTypesPath,
|
|
168
|
+
serverPath: target.serverGeneratedTypesPath,
|
|
169
|
+
publicPath: target.publicGeneratedTypesPath,
|
|
66
170
|
manifestVersion: manifest.manifestVersion,
|
|
67
171
|
};
|
|
68
172
|
}
|
|
69
|
-
|
|
173
|
+
const rendered = renderGeneratedTypesForManifest(manifest);
|
|
174
|
+
await Promise.all([
|
|
175
|
+
writeTextFileAtomic(target.serverGeneratedTypesPath, rendered.serverContents),
|
|
176
|
+
writeTextFileAtomic(target.publicGeneratedTypesPath, rendered.publicContents),
|
|
177
|
+
]);
|
|
178
|
+
await writeTextFileAtomic(target.typegenMetadataPath, buildTypegenMetadataContents(new Date(), identity));
|
|
70
179
|
return {
|
|
71
180
|
written: true,
|
|
72
|
-
path: target.
|
|
181
|
+
path: target.serverGeneratedTypesPath,
|
|
182
|
+
serverPath: target.serverGeneratedTypesPath,
|
|
183
|
+
publicPath: target.publicGeneratedTypesPath,
|
|
73
184
|
manifestVersion: manifest.manifestVersion,
|
|
74
185
|
};
|
|
75
186
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { BarekeyEnvHandle } from "./handle.js";
|
|
2
|
+
import type { BarekeyPublicGeneratedTypeMap, BarekeyPublicKnownKey, PublicBarekeyClientOptions } from "./public-types.js";
|
|
3
|
+
import type { BarekeyGetOptions, BarekeyJsonConfig } from "./types.js";
|
|
4
|
+
export declare class PublicBarekeyClient {
|
|
5
|
+
private readonly options;
|
|
6
|
+
private readonly fetchFn;
|
|
7
|
+
private readonly definitionCache;
|
|
8
|
+
private readonly evaluationCache;
|
|
9
|
+
private runtimeContextPromise;
|
|
10
|
+
private requirementsPromise;
|
|
11
|
+
constructor();
|
|
12
|
+
constructor(options: {
|
|
13
|
+
organization: string;
|
|
14
|
+
project: string;
|
|
15
|
+
environment: string;
|
|
16
|
+
requirements?: PublicBarekeyClientOptions["requirements"];
|
|
17
|
+
baseUrl?: string;
|
|
18
|
+
});
|
|
19
|
+
constructor(options: {
|
|
20
|
+
json: BarekeyJsonConfig;
|
|
21
|
+
requirements?: PublicBarekeyClientOptions["requirements"];
|
|
22
|
+
baseUrl?: string;
|
|
23
|
+
});
|
|
24
|
+
get<TKey extends BarekeyPublicKnownKey>(name: TKey, options?: BarekeyGetOptions): BarekeyEnvHandle<BarekeyPublicGeneratedTypeMap[TKey]>;
|
|
25
|
+
get(name: string, options?: BarekeyGetOptions): BarekeyEnvHandle<unknown>;
|
|
26
|
+
private getRuntimeContext;
|
|
27
|
+
private buildDefinitionCacheKey;
|
|
28
|
+
private buildEvaluationCacheKey;
|
|
29
|
+
private fetchDefinitions;
|
|
30
|
+
private ensureRequirementsValidated;
|
|
31
|
+
private getStaticDefinition;
|
|
32
|
+
private resolveStaticValue;
|
|
33
|
+
private resolveDynamicValue;
|
|
34
|
+
private resolveEvaluatedValue;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=public-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public-client.d.ts","sourceRoot":"","sources":["../src/public-client.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAc/C,OAAO,KAAK,EACV,6BAA6B,EAC7B,qBAAqB,EACrB,0BAA0B,EAC3B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAEV,iBAAiB,EACjB,iBAAiB,EAElB,MAAM,YAAY,CAAC;AAgBpB,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA6B;IACrD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA0B;IAClD,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAgD;IAChF,OAAO,CAAC,QAAQ,CAAC,eAAe,CAA4C;IAC5E,OAAO,CAAC,qBAAqB,CAAqD;IAClF,OAAO,CAAC,mBAAmB,CAA8B;;gBAG7C,OAAO,EAAE;QACnB,YAAY,EAAE,MAAM,CAAC;QACrB,OAAO,EAAE,MAAM,CAAC;QAChB,WAAW,EAAE,MAAM,CAAC;QACpB,YAAY,CAAC,EAAE,0BAA0B,CAAC,cAAc,CAAC,CAAC;QAC1D,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB;gBACW,OAAO,EAAE;QACnB,IAAI,EAAE,iBAAiB,CAAC;QACxB,YAAY,CAAC,EAAE,0BAA0B,CAAC,cAAc,CAAC,CAAC;QAC1D,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB;IAMD,GAAG,CAAC,IAAI,SAAS,qBAAqB,EACpC,IAAI,EAAE,IAAI,EACV,OAAO,CAAC,EAAE,iBAAiB,GAC1B,gBAAgB,CAAC,6BAA6B,CAAC,IAAI,CAAC,CAAC;IACxD,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,gBAAgB,CAAC,OAAO,CAAC;YAO3D,iBAAiB;IAa/B,OAAO,CAAC,uBAAuB;IAI/B,OAAO,CAAC,uBAAuB;YAejB,gBAAgB;YAqBhB,2BAA2B;YA4B3B,mBAAmB;YAiBnB,kBAAkB;YAQlB,mBAAmB;YAkCnB,qBAAqB;CAUpC"}
|