@barekey/sdk 0.4.4 → 0.6.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/README.md +84 -7
- package/dist/client.d.ts +4 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +61 -15
- package/dist/handle.d.ts +1 -1
- package/dist/handle.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/internal/config.d.ts +5 -0
- package/dist/internal/config.d.ts.map +1 -0
- package/dist/internal/config.js +26 -0
- package/dist/internal/node-runtime.d.ts +11 -0
- package/dist/internal/node-runtime.d.ts.map +1 -1
- package/dist/internal/node-runtime.js +2 -1
- package/dist/internal/public-runtime.d.ts.map +1 -1
- package/dist/internal/public-runtime.js +17 -3
- package/dist/internal/runtime.d.ts +15 -1
- package/dist/internal/runtime.d.ts.map +1 -1
- package/dist/internal/runtime.js +49 -7
- package/dist/internal/singleton.d.ts.map +1 -1
- package/dist/internal/singleton.js +14 -0
- package/dist/internal/standalone.d.ts +10 -0
- package/dist/internal/standalone.d.ts.map +1 -0
- package/dist/internal/standalone.js +246 -0
- package/dist/internal/typegen.d.ts +6 -3
- package/dist/internal/typegen.d.ts.map +1 -1
- package/dist/internal/typegen.js +45 -13
- package/dist/key-types.typecheck.d.ts +5 -5
- package/dist/key-types.typecheck.d.ts.map +1 -1
- package/dist/public-client.d.ts +4 -0
- package/dist/public-client.d.ts.map +1 -1
- package/dist/public-types.d.ts +1 -1
- package/dist/public-types.d.ts.map +1 -1
- package/dist/public.d.ts +1 -1
- package/dist/public.d.ts.map +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/types.d.ts +34 -5
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +86 -15
- package/src/handle.ts +1 -1
- package/src/index.ts +2 -0
- package/src/internal/config.ts +34 -0
- package/src/internal/node-runtime.ts +4 -2
- package/src/internal/public-runtime.ts +25 -4
- package/src/internal/runtime.ts +91 -7
- package/src/internal/singleton.ts +37 -4
- package/src/internal/standalone.ts +309 -0
- package/src/internal/typegen.ts +68 -15
- package/src/key-types.typecheck.ts +20 -4
- package/src/public-client.ts +4 -0
- package/src/public-types.ts +1 -0
- package/src/public.ts +2 -0
- package/src/server.ts +2 -0
- package/src/types.ts +81 -8
package/README.md
CHANGED
|
@@ -1,27 +1,104 @@
|
|
|
1
1
|
# @barekey/sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
TypeScript SDK for Barekey.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
|
|
8
|
+
npm install @barekey/sdk
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Entrypoints
|
|
12
|
+
|
|
13
|
+
- `@barekey/sdk/server`: server reads, CLI-session auth, standalone `.env` mode, and typegen
|
|
14
|
+
- `@barekey/sdk/public`: public-variable reads
|
|
15
|
+
- `@barekey/sdk`: root export
|
|
16
|
+
|
|
17
|
+
## Server quickstart
|
|
18
|
+
|
|
19
|
+
Create `barekey.json`:
|
|
20
|
+
|
|
21
|
+
```json
|
|
22
|
+
{
|
|
23
|
+
"organization": "acme",
|
|
24
|
+
"project": "web",
|
|
25
|
+
"environment": "development"
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Log in locally:
|
|
12
30
|
|
|
13
31
|
```bash
|
|
14
|
-
|
|
32
|
+
barekey auth login
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Use the SDK:
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { BarekeyClient } from "@barekey/sdk/server";
|
|
39
|
+
|
|
40
|
+
const barekey = new BarekeyClient();
|
|
41
|
+
|
|
42
|
+
const databaseUrl = await barekey.get("DATABASE_URL");
|
|
43
|
+
const details = await barekey.get("DATABASE_URL").inspect();
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Auth resolution
|
|
47
|
+
|
|
48
|
+
In centralized mode the server client uses:
|
|
49
|
+
|
|
50
|
+
1. `BAREKEY_ACCESS_TOKEN`
|
|
51
|
+
2. a stored CLI session from `barekey auth login`
|
|
52
|
+
|
|
53
|
+
Optional:
|
|
54
|
+
|
|
55
|
+
- `BAREKEY_API_URL` overrides the API base URL
|
|
56
|
+
|
|
57
|
+
## `barekey.json`
|
|
58
|
+
|
|
59
|
+
Supported keys:
|
|
60
|
+
|
|
61
|
+
- `organization` or `org`
|
|
62
|
+
- `project`
|
|
63
|
+
- `environment` or `stage`
|
|
64
|
+
- `config.mode`: `"centralized"` or `"standalone"`
|
|
65
|
+
- `config.typegen`: `"semantic"` or `"minimal"`
|
|
66
|
+
|
|
67
|
+
## Typegen
|
|
68
|
+
|
|
69
|
+
Generate SDK types into the installed package:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
barekey typegen
|
|
15
73
|
```
|
|
16
74
|
|
|
17
|
-
|
|
75
|
+
Watch mode:
|
|
18
76
|
|
|
19
77
|
```bash
|
|
20
|
-
|
|
78
|
+
barekey typegen --watch
|
|
21
79
|
```
|
|
22
80
|
|
|
23
|
-
|
|
81
|
+
`semantic` typegen keeps Barekey metadata in the generated `Env<...>` wrapper, including `Kind`, `Visibility`, and `Rollout`. `minimal` only emits the resolved value type.
|
|
82
|
+
|
|
83
|
+
## Public client
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
import { PublicBarekeyClient } from "@barekey/sdk/public";
|
|
87
|
+
|
|
88
|
+
const publicBarekey = new PublicBarekeyClient({
|
|
89
|
+
organization: "acme",
|
|
90
|
+
project: "web",
|
|
91
|
+
environment: "production",
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const title = await publicBarekey.get("PUBLIC_TITLE");
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Development
|
|
24
98
|
|
|
25
99
|
```bash
|
|
100
|
+
bun install
|
|
101
|
+
bun run build
|
|
102
|
+
bun run typecheck
|
|
26
103
|
bun test
|
|
27
104
|
```
|
package/dist/client.d.ts
CHANGED
|
@@ -9,6 +9,10 @@ export declare class BarekeyClient {
|
|
|
9
9
|
private requirementsPromise;
|
|
10
10
|
private typegenWatcherStarted;
|
|
11
11
|
constructor();
|
|
12
|
+
constructor(options: {
|
|
13
|
+
requirements?: BarekeyClientOptions["requirements"];
|
|
14
|
+
typegen?: BarekeyClientOptions["typegen"];
|
|
15
|
+
});
|
|
12
16
|
constructor(options: {
|
|
13
17
|
organization: string;
|
|
14
18
|
project: string;
|
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,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAuBtE,OAAO,KAAK,EACV,oBAAoB,EAEpB,2BAA2B,EAC3B,6BAA6B,EAC7B,iBAAiB,EACjB,iBAAiB,EACjB,UAAU,EACV,oBAAoB,EAErB,MAAM,YAAY,CAAC;AAyGpB,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAwB;IAChD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA2B;IACnD,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,CAAC,EAAE,oBAAoB,CAAC,cAAc,CAAC,CAAC;QACpD,OAAO,CAAC,EAAE,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{ validateRequirements } from "./internal/requirements.js";
|
|
6
6
|
import { resolveRuntimeContext } from "./internal/runtime.js";
|
|
7
7
|
import { createBarekeyClientSingletonKey } from "./internal/singleton.js";
|
|
8
|
+
import { buildStandaloneTypegenManifest, loadStandaloneDefinitions, } from "./internal/standalone.js";
|
|
8
9
|
import { MemoryCache } from "./internal/cache.js";
|
|
9
10
|
import { DEFAULT_TYPEGEN_TTL_MS, resolveTtlMilliseconds } from "./internal/ttl.js";
|
|
10
11
|
import { hasFreshInstalledSdkTypegen, resolveInstalledSdkGeneratedTypesPath, writeInstalledSdkGeneratedTypes, } from "./internal/typegen.js";
|
|
@@ -55,6 +56,17 @@ function resolveEvaluatedResponse(evaluated) {
|
|
|
55
56
|
selectedArm: inferSelectedArmFromDecision(evaluated.decision),
|
|
56
57
|
};
|
|
57
58
|
}
|
|
59
|
+
function createTypegenIdentity(context) {
|
|
60
|
+
return {
|
|
61
|
+
baseUrl: context.baseUrl,
|
|
62
|
+
orgSlug: context.organization,
|
|
63
|
+
projectSlug: context.project,
|
|
64
|
+
stageSlug: context.environment,
|
|
65
|
+
typegenMode: context.typegenMode,
|
|
66
|
+
runtimeMode: context.mode,
|
|
67
|
+
localEnvRoot: context.localEnvRoot,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
58
70
|
export class BarekeyClient {
|
|
59
71
|
options;
|
|
60
72
|
fetchFn;
|
|
@@ -87,13 +99,15 @@ export class BarekeyClient {
|
|
|
87
99
|
message: "Barekey could not update generated SDK types because filesystem access is unavailable.",
|
|
88
100
|
});
|
|
89
101
|
}
|
|
90
|
-
const manifest =
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
102
|
+
const manifest = context.mode === "standalone"
|
|
103
|
+
? await buildStandaloneTypegenManifest({
|
|
104
|
+
rootDirectory: context.localEnvRoot,
|
|
105
|
+
organization: context.organization,
|
|
106
|
+
project: context.project,
|
|
107
|
+
environment: context.environment,
|
|
108
|
+
})
|
|
109
|
+
: await this.fetchTypegenManifest(context);
|
|
110
|
+
return await writeInstalledSdkGeneratedTypes(manifest, createTypegenIdentity(context));
|
|
97
111
|
}
|
|
98
112
|
async getRuntimeContext() {
|
|
99
113
|
if (this.runtimeContextPromise === null) {
|
|
@@ -109,6 +123,14 @@ export class BarekeyClient {
|
|
|
109
123
|
}
|
|
110
124
|
async fetchTypegenManifest(context) {
|
|
111
125
|
const resolvedContext = context ?? (await this.getRuntimeContext());
|
|
126
|
+
if (resolvedContext.mode !== "centralized") {
|
|
127
|
+
return await buildStandaloneTypegenManifest({
|
|
128
|
+
rootDirectory: resolvedContext.localEnvRoot,
|
|
129
|
+
organization: resolvedContext.organization,
|
|
130
|
+
project: resolvedContext.project,
|
|
131
|
+
environment: resolvedContext.environment,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
112
134
|
return await getJson({
|
|
113
135
|
fetchFn: this.fetchFn,
|
|
114
136
|
baseUrl: resolvedContext.baseUrl,
|
|
@@ -138,10 +160,13 @@ export class BarekeyClient {
|
|
|
138
160
|
}
|
|
139
161
|
const intervalMs = this.getTypegenIntervalMs();
|
|
140
162
|
const watcherKey = [
|
|
141
|
-
context.baseUrl,
|
|
163
|
+
context.baseUrl ?? "",
|
|
142
164
|
context.organization,
|
|
143
165
|
context.project,
|
|
144
166
|
context.environment,
|
|
167
|
+
context.mode,
|
|
168
|
+
context.localEnvRoot ?? "",
|
|
169
|
+
context.typegenMode,
|
|
145
170
|
generatedTypesPath,
|
|
146
171
|
].join("|");
|
|
147
172
|
const runWatcher = async (watcher) => {
|
|
@@ -187,10 +212,7 @@ export class BarekeyClient {
|
|
|
187
212
|
};
|
|
188
213
|
sharedTypegenWatchers.set(watcherKey, watcher);
|
|
189
214
|
if (!(await hasFreshInstalledSdkTypegen(intervalMs, {
|
|
190
|
-
|
|
191
|
-
orgSlug: context.organization,
|
|
192
|
-
projectSlug: context.project,
|
|
193
|
-
stageSlug: context.environment,
|
|
215
|
+
...createTypegenIdentity(context),
|
|
194
216
|
}))) {
|
|
195
217
|
void runWatcher(watcher);
|
|
196
218
|
}
|
|
@@ -205,16 +227,25 @@ export class BarekeyClient {
|
|
|
205
227
|
});
|
|
206
228
|
}
|
|
207
229
|
buildDefinitionCacheKey(context, name) {
|
|
208
|
-
return [
|
|
230
|
+
return [
|
|
231
|
+
context.mode,
|
|
232
|
+
context.localEnvRoot ?? "",
|
|
233
|
+
context.organization,
|
|
234
|
+
context.project,
|
|
235
|
+
context.environment,
|
|
236
|
+
name,
|
|
237
|
+
].join("|");
|
|
209
238
|
}
|
|
210
239
|
buildEvaluationCacheKey(context, name, options) {
|
|
211
240
|
return [
|
|
241
|
+
context.mode,
|
|
242
|
+
context.localEnvRoot ?? "",
|
|
212
243
|
context.organization,
|
|
213
244
|
context.project,
|
|
214
245
|
context.environment,
|
|
215
246
|
name,
|
|
216
|
-
options?.seed ?? "",
|
|
217
|
-
options?.key ?? "",
|
|
247
|
+
context.mode === "standalone" ? "" : options?.seed ?? "",
|
|
248
|
+
context.mode === "standalone" ? "" : options?.key ?? "",
|
|
218
249
|
].join("|");
|
|
219
250
|
}
|
|
220
251
|
async fetchDefinitions(names) {
|
|
@@ -222,6 +253,16 @@ export class BarekeyClient {
|
|
|
222
253
|
return [];
|
|
223
254
|
}
|
|
224
255
|
const context = await this.getRuntimeContext();
|
|
256
|
+
if (context.mode === "standalone") {
|
|
257
|
+
const definitions = await loadStandaloneDefinitions(context.localEnvRoot);
|
|
258
|
+
for (const definition of definitions) {
|
|
259
|
+
this.definitionCache.set(this.buildDefinitionCacheKey(context, definition.name), definition);
|
|
260
|
+
}
|
|
261
|
+
if (names === undefined) {
|
|
262
|
+
return definitions;
|
|
263
|
+
}
|
|
264
|
+
return mapValuesToRequestedOrder(names, definitions);
|
|
265
|
+
}
|
|
225
266
|
const response = await postJson({
|
|
226
267
|
fetchFn: this.fetchFn,
|
|
227
268
|
baseUrl: context.baseUrl,
|
|
@@ -308,6 +349,11 @@ export class BarekeyClient {
|
|
|
308
349
|
return await Promise.all(definitions.map(async (definition) => await evaluateDefinition(definition, options)));
|
|
309
350
|
}
|
|
310
351
|
async fetchDynamicValues(names, context, options) {
|
|
352
|
+
if (context.mode === "standalone") {
|
|
353
|
+
const definitions = await loadStandaloneDefinitions(context.localEnvRoot);
|
|
354
|
+
const resolvedDefinitions = mapValuesToRequestedOrder(names, definitions);
|
|
355
|
+
return await Promise.all(resolvedDefinitions.map(async (definition) => await evaluateDefinition(definition)));
|
|
356
|
+
}
|
|
311
357
|
try {
|
|
312
358
|
if (names.length === 1) {
|
|
313
359
|
const evaluated = await postJson({
|
package/dist/handle.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { BarekeyCoerceTarget, BarekeyEvaluatedValue, BarekeyResolvedRecord, BarekeyResolvedRecords } from "./types.js";
|
|
2
2
|
type BarekeyCoercibleEnvMarker = {
|
|
3
3
|
readonly __barekey?: {
|
|
4
|
-
readonly
|
|
4
|
+
readonly kind: "ab_roll" | "rollout";
|
|
5
5
|
};
|
|
6
6
|
};
|
|
7
7
|
export declare class BarekeyEnvHandle<TValue = unknown> implements PromiseLike<TValue> {
|
package/dist/handle.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handle.d.ts","sourceRoot":"","sources":["../src/handle.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,mBAAmB,EACnB,qBAAqB,EACrB,qBAAqB,EACrB,sBAAsB,EACvB,MAAM,YAAY,CAAC;AAEpB,KAAK,yBAAyB,GAAG;IAC/B,QAAQ,CAAC,SAAS,CAAC,EAAE;QACnB,QAAQ,CAAC,IAAI,EAAE,
|
|
1
|
+
{"version":3,"file":"handle.d.ts","sourceRoot":"","sources":["../src/handle.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,mBAAmB,EACnB,qBAAqB,EACrB,qBAAqB,EACrB,sBAAsB,EACvB,MAAM,YAAY,CAAC;AAEpB,KAAK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IAAI,CAAC,GAAG,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC;CAG3D"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,6 @@ export { BarekeyClient } from "./client.js";
|
|
|
2
2
|
export { PublicBarekeyClient } from "./public-client.js";
|
|
3
3
|
export { BarekeyEnvBatchHandle, BarekeyEnvHandle } from "./handle.js";
|
|
4
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";
|
|
5
|
-
export type { AB, BarekeyClientOptions, BarekeyCoerceTarget, BarekeyDeclaredType, BarekeyErrorCode, BarekeyEnvDescriptor, BarekeyEvaluatedValue, BarekeyGeneratedTypeMap, BarekeyGeneratedValueForKey, BarekeyGeneratedValuesForKeys, BarekeyGetOptions, BarekeyJsonConfig, BarekeyKey, BarekeyLiteralString, BarekeyKnownKey, BarekeyResolvedRecord, BarekeyResolvedRecords, BarekeyResolvedKind, BarekeyRolloutMilestone, BarekeyStandardSchemaV1, BarekeyTemporalInstant, BarekeyTemporalInstantLike, BarekeyTtlInput, BarekeyTypegenResult, BarekeyValueForGeneratedMap, BarekeyValuesForGeneratedMap, Env, Linear, Secret, BarekeyVisibility, } from "./types.js";
|
|
5
|
+
export type { AB, BarekeyClientOptions, BarekeyCoerceTarget, BarekeyDeclaredType, BarekeyErrorCode, BarekeyEnvDescriptor, BarekeyEvaluatedValue, BarekeyGeneratedTypeMap, BarekeyGeneratedValueForKey, BarekeyGeneratedValuesForKeys, BarekeyGetOptions, BarekeyJsonConfig, BarekeyKey, BarekeyLiteralString, BarekeyMode, BarekeyKnownKey, BarekeyResolvedRecord, BarekeyResolvedRecords, BarekeyResolvedKind, BarekeyRolloutMilestone, BarekeyStandardSchemaV1, BarekeyTemporalInstant, BarekeyTemporalInstantLike, BarekeyTypegenMode, BarekeyTtlInput, BarekeyTypegenResult, BarekeyValueForGeneratedMap, BarekeyValuesForGeneratedMap, Env, Linear, Secret, BarekeyVisibility, } from "./types.js";
|
|
6
6
|
export type { BarekeyPublicGeneratedTypeMap, BarekeyPublicKey, BarekeyPublicKnownKey, BarekeyPublicValueForKey, BarekeyPublicValuesForKeys, PublicBarekeyClientOptions, } from "./public-types.js";
|
|
7
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,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACtE,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,oBAAoB,EACpB,qBAAqB,EACrB,uBAAuB,EACvB,2BAA2B,EAC3B,6BAA6B,EAC7B,iBAAiB,EACjB,iBAAiB,EACjB,UAAU,EACV,oBAAoB,EACpB,eAAe,EACf,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,EACnB,uBAAuB,EACvB,uBAAuB,EACvB,sBAAsB,EACtB,0BAA0B,EAC1B,eAAe,EACf,oBAAoB,EACpB,2BAA2B,EAC3B,4BAA4B,EAC5B,GAAG,EACH,MAAM,EACN,MAAM,EACN,iBAAiB,GAClB,MAAM,YAAY,CAAC;AAEpB,YAAY,EACV,6BAA6B,EAC7B,gBAAgB,EAChB,qBAAqB,EACrB,wBAAwB,EACxB,0BAA0B,EAC1B,0BAA0B,GAC3B,MAAM,mBAAmB,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,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACtE,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,oBAAoB,EACpB,qBAAqB,EACrB,uBAAuB,EACvB,2BAA2B,EAC3B,6BAA6B,EAC7B,iBAAiB,EACjB,iBAAiB,EACjB,UAAU,EACV,oBAAoB,EACpB,WAAW,EACX,eAAe,EACf,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,EACnB,uBAAuB,EACvB,uBAAuB,EACvB,sBAAsB,EACtB,0BAA0B,EAC1B,kBAAkB,EAClB,eAAe,EACf,oBAAoB,EACpB,2BAA2B,EAC3B,4BAA4B,EAC5B,GAAG,EACH,MAAM,EACN,MAAM,EACN,iBAAiB,GAClB,MAAM,YAAY,CAAC;AAEpB,YAAY,EACV,6BAA6B,EAC7B,gBAAgB,EAChB,qBAAqB,EACrB,wBAAwB,EACxB,0BAA0B,EAC1B,0BAA0B,GAC3B,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { BarekeyMode, BarekeyTypegenMode } from "../types.js";
|
|
2
|
+
export declare function readConfigString(value: unknown): string | undefined;
|
|
3
|
+
export declare function normalizeTypegenMode(value: unknown, source: string): BarekeyTypegenMode;
|
|
4
|
+
export declare function normalizeMode(value: unknown, source: string): BarekeyMode;
|
|
5
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/internal/config.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEnE,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAEnE;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,kBAAkB,CAYvF;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW,CAYzE"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { InvalidConfigurationProvidedError } from "../errors.js";
|
|
2
|
+
export function readConfigString(value) {
|
|
3
|
+
return typeof value === "string" ? value.trim() : undefined;
|
|
4
|
+
}
|
|
5
|
+
export function normalizeTypegenMode(value, source) {
|
|
6
|
+
if (value === undefined) {
|
|
7
|
+
return "semantic";
|
|
8
|
+
}
|
|
9
|
+
if (value === "semantic" || value === "minimal") {
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
throw new InvalidConfigurationProvidedError({
|
|
13
|
+
message: `${source} must provide config.typegen as "semantic" or "minimal" when set.`,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
export function normalizeMode(value, source) {
|
|
17
|
+
if (value === undefined) {
|
|
18
|
+
return "centralized";
|
|
19
|
+
}
|
|
20
|
+
if (value === "centralized" || value === "standalone") {
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
throw new InvalidConfigurationProvidedError({
|
|
24
|
+
message: `${source} must provide config.mode as "centralized" or "standalone" when set.`,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
@@ -1,6 +1,17 @@
|
|
|
1
|
+
export type NodeRuntimeModules = {
|
|
2
|
+
childProcess: typeof import("node:child_process");
|
|
3
|
+
fs: typeof import("node:fs/promises");
|
|
4
|
+
moduleApi: {
|
|
5
|
+
createRequire(path: string | URL): NodeRequire;
|
|
6
|
+
};
|
|
7
|
+
os: typeof import("node:os");
|
|
8
|
+
path: typeof import("node:path");
|
|
9
|
+
};
|
|
10
|
+
export declare function loadNodeRuntime(): Promise<NodeRuntimeModules | null>;
|
|
1
11
|
export declare function isFilesystemAvailable(): Promise<boolean>;
|
|
2
12
|
export declare function loadBarekeyJsonConfig(): Promise<{
|
|
3
13
|
path: string;
|
|
14
|
+
directory: string;
|
|
4
15
|
json: Record<string, unknown>;
|
|
5
16
|
} | null>;
|
|
6
17
|
export declare function loadCliSessionAuthResolver(fetchFn: typeof globalThis.fetch): Promise<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-runtime.d.ts","sourceRoot":"","sources":["../../src/internal/node-runtime.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"node-runtime.d.ts","sourceRoot":"","sources":["../../src/internal/node-runtime.ts"],"names":[],"mappings":"AAWA,MAAM,MAAM,kBAAkB,GAAG;IAC/B,YAAY,EAAE,cAAc,oBAAoB,CAAC,CAAC;IAClD,EAAE,EAAE,cAAc,kBAAkB,CAAC,CAAC;IACtC,SAAS,EAAE;QACT,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,GAAG,WAAW,CAAC;KAChD,CAAC;IACF,EAAE,EAAE,cAAc,SAAS,CAAC,CAAC;IAC7B,IAAI,EAAE,cAAc,WAAW,CAAC,CAAC;CAClC,CAAC;AAwCF,wBAAsB,eAAe,IAAI,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,CAwB1E;AAyQD,wBAAsB,qBAAqB,IAAI,OAAO,CAAC,OAAO,CAAC,CAE9D;AAED,wBAAsB,qBAAqB,IAAI,OAAO,CAAC;IACrD,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B,GAAG,IAAI,CAAC,CAyCR;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"}
|
|
@@ -7,7 +7,7 @@ function isNodeRuntime() {
|
|
|
7
7
|
process.versions !== null &&
|
|
8
8
|
typeof process.versions.node === "string");
|
|
9
9
|
}
|
|
10
|
-
async function loadNodeRuntime() {
|
|
10
|
+
export async function loadNodeRuntime() {
|
|
11
11
|
if (!isNodeRuntime()) {
|
|
12
12
|
return null;
|
|
13
13
|
}
|
|
@@ -241,6 +241,7 @@ export async function loadBarekeyJsonConfig() {
|
|
|
241
241
|
try {
|
|
242
242
|
return {
|
|
243
243
|
path: candidate,
|
|
244
|
+
directory: current,
|
|
244
245
|
json: JSON.parse(raw),
|
|
245
246
|
};
|
|
246
247
|
}
|
|
@@ -1 +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;
|
|
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;AAO9E,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;AAyHF,wBAAsB,2BAA2B,CAC/C,OAAO,EAAE,0BAA0B,GAClC,OAAO,CAAC,2BAA2B,CAAC,CAOtC"}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { FsNotAvailableError, InvalidConfigurationProvidedError, NoConfigurationProvidedError, } from "../errors.js";
|
|
2
|
+
import { normalizeMode, normalizeTypegenMode, readConfigString } from "./config.js";
|
|
2
3
|
import { normalizeBaseUrl } from "./http.js";
|
|
3
4
|
import { isFilesystemAvailable, loadBarekeyJsonConfig } from "./node-runtime.js";
|
|
4
5
|
const DEFAULT_BAREKEY_API_URL = "https://api.barekey.dev";
|
|
5
|
-
function readConfigString(value) {
|
|
6
|
-
return typeof value === "string" ? value.trim() : undefined;
|
|
7
|
-
}
|
|
8
6
|
function normalizeScope(input) {
|
|
9
7
|
const organization = readConfigString(input.organization) ?? "";
|
|
10
8
|
const project = readConfigString(input.project) ?? "";
|
|
@@ -20,7 +18,23 @@ function normalizeScope(input) {
|
|
|
20
18
|
environment,
|
|
21
19
|
};
|
|
22
20
|
}
|
|
21
|
+
function createStandaloneUnsupportedError(source) {
|
|
22
|
+
return new InvalidConfigurationProvidedError({
|
|
23
|
+
message: [
|
|
24
|
+
`${source} sets config.mode to "standalone".`,
|
|
25
|
+
"PublicBarekeyClient does not support standalone local env mode because it relies on a server filesystem to read .env files.",
|
|
26
|
+
"Use BarekeyClient on the server instead, or switch barekey.json config.mode back to \"centralized\" for browser/public usage.",
|
|
27
|
+
].join(" "),
|
|
28
|
+
});
|
|
29
|
+
}
|
|
23
30
|
function normalizeJsonConfig(input, source) {
|
|
31
|
+
const config = "config" in input && typeof input.config === "object" && input.config !== null
|
|
32
|
+
? input.config
|
|
33
|
+
: undefined;
|
|
34
|
+
normalizeTypegenMode(config?.typegen ?? ("typegen" in input ? input.typegen : undefined), source);
|
|
35
|
+
if (normalizeMode(config?.mode, source) === "standalone") {
|
|
36
|
+
throw createStandaloneUnsupportedError(source);
|
|
37
|
+
}
|
|
24
38
|
return normalizeScope({
|
|
25
39
|
organization: input.organization ?? input.org,
|
|
26
40
|
project: input.project,
|
|
@@ -1,15 +1,29 @@
|
|
|
1
1
|
import type { BarekeyClientOptions, BarekeyStandardSchemaV1 } from "../types.js";
|
|
2
|
+
import type { BarekeyMode, BarekeyTypegenMode } from "../types.js";
|
|
2
3
|
import { type InternalAuthResolver } from "./http.js";
|
|
3
4
|
type BarekeyResolvedScope = {
|
|
4
5
|
organization: string;
|
|
5
6
|
project: string;
|
|
6
7
|
environment: string;
|
|
8
|
+
typegenMode: BarekeyTypegenMode;
|
|
9
|
+
mode: BarekeyMode;
|
|
10
|
+
localEnvRoot: string | null;
|
|
7
11
|
};
|
|
8
|
-
|
|
12
|
+
type BarekeyCentralizedRuntimeContext = BarekeyResolvedScope & {
|
|
13
|
+
mode: "centralized";
|
|
14
|
+
localEnvRoot: null;
|
|
9
15
|
baseUrl: string;
|
|
10
16
|
auth: InternalAuthResolver;
|
|
11
17
|
requirements?: BarekeyStandardSchemaV1;
|
|
12
18
|
};
|
|
19
|
+
type BarekeyStandaloneRuntimeContext = BarekeyResolvedScope & {
|
|
20
|
+
mode: "standalone";
|
|
21
|
+
localEnvRoot: string;
|
|
22
|
+
baseUrl: null;
|
|
23
|
+
auth: null;
|
|
24
|
+
requirements?: BarekeyStandardSchemaV1;
|
|
25
|
+
};
|
|
26
|
+
export type BarekeyRuntimeContext = BarekeyCentralizedRuntimeContext | BarekeyStandaloneRuntimeContext;
|
|
13
27
|
export declare function resolveRuntimeContext(options: BarekeyClientOptions, fetchFn: typeof globalThis.fetch): Promise<BarekeyRuntimeContext>;
|
|
14
28
|
export {};
|
|
15
29
|
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/internal/runtime.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/internal/runtime.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,oBAAoB,EAEpB,uBAAuB,EACxB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEnE,OAAO,EAAE,KAAK,oBAAoB,EAAoB,MAAM,WAAW,CAAC;AASxE,KAAK,oBAAoB,GAAG;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,kBAAkB,CAAC;IAChC,IAAI,EAAE,WAAW,CAAC;IAClB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B,CAAC;AAEF,KAAK,gCAAgC,GAAG,oBAAoB,GAAG;IAC7D,IAAI,EAAE,aAAa,CAAC;IACpB,YAAY,EAAE,IAAI,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,oBAAoB,CAAC;IAC3B,YAAY,CAAC,EAAE,uBAAuB,CAAC;CACxC,CAAC;AAEF,KAAK,+BAA+B,GAAG,oBAAoB,GAAG;IAC5D,IAAI,EAAE,YAAY,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,IAAI,CAAC;IACd,IAAI,EAAE,IAAI,CAAC;IACX,YAAY,CAAC,EAAE,uBAAuB,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAC7B,gCAAgC,GAChC,+BAA+B,CAAC;AAuMpC,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,oBAAoB,EAC7B,OAAO,EAAE,OAAO,UAAU,CAAC,KAAK,GAC/B,OAAO,CAAC,qBAAqB,CAAC,CA4BhC"}
|
package/dist/internal/runtime.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { FsNotAvailableError, InvalidConfigurationProvidedError, InvalidCredentialsProvidedError, InvalidRefreshTokenError, NoConfigurationProvidedError, NoCredentialsProvidedError, UnauthorizedError, } from "../errors.js";
|
|
2
|
+
import { normalizeMode, normalizeTypegenMode, readConfigString } from "./config.js";
|
|
2
3
|
import { normalizeBaseUrl } from "./http.js";
|
|
3
4
|
import { isFilesystemAvailable, loadBarekeyJsonConfig, loadCliSessionAuthResolver, } from "./node-runtime.js";
|
|
4
5
|
const DEFAULT_BAREKEY_API_URL = "https://api.barekey.dev";
|
|
@@ -9,29 +10,49 @@ function readProcessEnv(key) {
|
|
|
9
10
|
const value = process.env[key];
|
|
10
11
|
return typeof value === "string" ? value : undefined;
|
|
11
12
|
}
|
|
12
|
-
function
|
|
13
|
-
|
|
13
|
+
function safeCurrentWorkingDirectory() {
|
|
14
|
+
if (typeof process === "undefined" || typeof process.cwd !== "function") {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
return process.cwd();
|
|
14
18
|
}
|
|
15
19
|
function normalizeScope(input) {
|
|
20
|
+
const mode = input.mode ?? "centralized";
|
|
16
21
|
const organization = readConfigString(input.organization) ?? "";
|
|
17
22
|
const project = readConfigString(input.project) ?? "";
|
|
18
23
|
const environment = readConfigString(input.environment) ?? "";
|
|
19
|
-
if (
|
|
24
|
+
if (mode !== "standalone" &&
|
|
25
|
+
(organization.length === 0 || project.length === 0 || environment.length === 0)) {
|
|
20
26
|
throw new InvalidConfigurationProvidedError({
|
|
21
27
|
message: `${input.source} must provide organization, project, and environment.`,
|
|
22
28
|
});
|
|
23
29
|
}
|
|
30
|
+
const localEnvRoot = mode === "standalone" ? input.localEnvRoot ?? safeCurrentWorkingDirectory() : null;
|
|
31
|
+
if (mode === "standalone" && (!localEnvRoot || localEnvRoot.trim().length === 0)) {
|
|
32
|
+
throw new FsNotAvailableError({
|
|
33
|
+
message: "Barekey standalone mode requires filesystem access and a working directory.",
|
|
34
|
+
});
|
|
35
|
+
}
|
|
24
36
|
return {
|
|
25
37
|
organization,
|
|
26
38
|
project,
|
|
27
39
|
environment,
|
|
40
|
+
typegenMode: mode === "standalone" ? "minimal" : (input.typegenMode ?? "semantic"),
|
|
41
|
+
mode,
|
|
42
|
+
localEnvRoot: mode === "standalone" ? localEnvRoot : null,
|
|
28
43
|
};
|
|
29
44
|
}
|
|
30
|
-
function normalizeJsonConfig(input, source) {
|
|
45
|
+
function normalizeJsonConfig(input, source, localEnvRoot) {
|
|
46
|
+
const config = "config" in input && typeof input.config === "object" && input.config !== null
|
|
47
|
+
? input.config
|
|
48
|
+
: undefined;
|
|
31
49
|
return normalizeScope({
|
|
32
50
|
organization: input.organization ?? input.org,
|
|
33
51
|
project: input.project,
|
|
34
52
|
environment: input.environment ?? input.stage,
|
|
53
|
+
typegenMode: normalizeTypegenMode(config?.typegen ?? ("typegen" in input ? input.typegen : undefined), source),
|
|
54
|
+
mode: normalizeMode(config?.mode, source),
|
|
55
|
+
localEnvRoot,
|
|
35
56
|
source,
|
|
36
57
|
});
|
|
37
58
|
}
|
|
@@ -54,13 +75,16 @@ async function resolveScope(options) {
|
|
|
54
75
|
});
|
|
55
76
|
}
|
|
56
77
|
if (explicitJson !== undefined) {
|
|
57
|
-
return normalizeJsonConfig(explicitJson, "The provided json configuration");
|
|
78
|
+
return normalizeJsonConfig(explicitJson, "The provided json configuration", safeCurrentWorkingDirectory());
|
|
58
79
|
}
|
|
59
80
|
if (explicitCount === 3) {
|
|
60
81
|
return normalizeScope({
|
|
61
82
|
organization: explicitOrganization,
|
|
62
83
|
project: explicitProject,
|
|
63
84
|
environment: explicitEnvironment,
|
|
85
|
+
typegenMode: "semantic",
|
|
86
|
+
mode: "centralized",
|
|
87
|
+
localEnvRoot: null,
|
|
64
88
|
source: "The provided Barekey configuration",
|
|
65
89
|
});
|
|
66
90
|
}
|
|
@@ -73,7 +97,7 @@ async function resolveScope(options) {
|
|
|
73
97
|
message: "No Barekey configuration was found and no barekey.json file could be loaded.",
|
|
74
98
|
});
|
|
75
99
|
}
|
|
76
|
-
return normalizeJsonConfig(loadedConfig.json, `The barekey.json file at ${loadedConfig.path}
|
|
100
|
+
return normalizeJsonConfig(loadedConfig.json, `The barekey.json file at ${loadedConfig.path}`, loadedConfig.directory);
|
|
77
101
|
}
|
|
78
102
|
async function resolveAuth(fetchFn) {
|
|
79
103
|
const envToken = readProcessEnv("BAREKEY_ACCESS_TOKEN");
|
|
@@ -125,9 +149,27 @@ async function resolveAuth(fetchFn) {
|
|
|
125
149
|
};
|
|
126
150
|
}
|
|
127
151
|
export async function resolveRuntimeContext(options, fetchFn) {
|
|
128
|
-
const
|
|
152
|
+
const scope = await resolveScope(options);
|
|
153
|
+
if (scope.mode === "standalone") {
|
|
154
|
+
if (!(await isFilesystemAvailable())) {
|
|
155
|
+
throw new FsNotAvailableError({
|
|
156
|
+
message: "Barekey standalone mode requires a local filesystem to read .env files.",
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
return {
|
|
160
|
+
...scope,
|
|
161
|
+
mode: "standalone",
|
|
162
|
+
localEnvRoot: scope.localEnvRoot ?? safeCurrentWorkingDirectory() ?? "",
|
|
163
|
+
baseUrl: null,
|
|
164
|
+
auth: null,
|
|
165
|
+
requirements: options.requirements,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
const auth = await resolveAuth(fetchFn);
|
|
129
169
|
return {
|
|
130
170
|
...scope,
|
|
171
|
+
mode: "centralized",
|
|
172
|
+
localEnvRoot: null,
|
|
131
173
|
baseUrl: auth.baseUrl,
|
|
132
174
|
auth: auth.auth,
|
|
133
175
|
requirements: options.requirements,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"singleton.d.ts","sourceRoot":"","sources":["../../src/internal/singleton.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,KAAK,EACV,oBAAoB,EAIrB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"singleton.d.ts","sourceRoot":"","sources":["../../src/internal/singleton.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,KAAK,EACV,oBAAoB,EAIrB,MAAM,aAAa,CAAC;AA0LrB,wBAAgB,+BAA+B,CAAC,OAAO,EAAE,oBAAoB,GAAG,MAAM,CAYrF;AAED,wBAAgB,qCAAqC,CACnD,OAAO,EAAE,0BAA0B,GAClC,MAAM,CAOR"}
|
|
@@ -28,10 +28,21 @@ function normalizeJsonScope(value) {
|
|
|
28
28
|
if (value === undefined) {
|
|
29
29
|
return null;
|
|
30
30
|
}
|
|
31
|
+
const config = typeof value.config === "object" && value.config !== null
|
|
32
|
+
? value.config
|
|
33
|
+
: undefined;
|
|
34
|
+
const runtimeMode = config?.mode === "standalone" ? "standalone" : "centralized";
|
|
31
35
|
return {
|
|
32
36
|
organization: readConfigString(value.organization ?? value.org),
|
|
33
37
|
project: readConfigString(value.project),
|
|
34
38
|
environment: readConfigString(value.environment ?? value.stage),
|
|
39
|
+
typegenMode: runtimeMode === "standalone"
|
|
40
|
+
? "minimal"
|
|
41
|
+
: config?.typegen === "minimal"
|
|
42
|
+
? "minimal"
|
|
43
|
+
: "semantic",
|
|
44
|
+
runtimeMode,
|
|
45
|
+
localEnvRoot: runtimeMode === "standalone" ? safeCurrentWorkingDirectory() : null,
|
|
35
46
|
};
|
|
36
47
|
}
|
|
37
48
|
function normalizeScopeKey(options) {
|
|
@@ -47,6 +58,9 @@ function normalizeScopeKey(options) {
|
|
|
47
58
|
organization,
|
|
48
59
|
project,
|
|
49
60
|
environment,
|
|
61
|
+
typegenMode: "semantic",
|
|
62
|
+
runtimeMode: "centralized",
|
|
63
|
+
localEnvRoot: null,
|
|
50
64
|
};
|
|
51
65
|
}
|
|
52
66
|
return {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { BarekeyVariableDefinition } from "../types.js";
|
|
2
|
+
import type { TypegenManifest } from "./typegen.js";
|
|
3
|
+
export declare function loadStandaloneDefinitions(rootDirectory: string): Promise<Array<BarekeyVariableDefinition>>;
|
|
4
|
+
export declare function buildStandaloneTypegenManifest(input: {
|
|
5
|
+
rootDirectory: string;
|
|
6
|
+
organization: string;
|
|
7
|
+
project: string;
|
|
8
|
+
environment: string;
|
|
9
|
+
}): Promise<TypegenManifest>;
|
|
10
|
+
//# sourceMappingURL=standalone.d.ts.map
|