@barekey/sdk 0.4.3 → 0.5.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.
Files changed (45) hide show
  1. package/dist/client.d.ts +4 -0
  2. package/dist/client.d.ts.map +1 -1
  3. package/dist/client.js +61 -15
  4. package/dist/index.d.ts +1 -1
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/internal/node-runtime.d.ts +11 -0
  7. package/dist/internal/node-runtime.d.ts.map +1 -1
  8. package/dist/internal/node-runtime.js +2 -1
  9. package/dist/internal/public-runtime.d.ts.map +1 -1
  10. package/dist/internal/public-runtime.js +38 -0
  11. package/dist/internal/runtime.d.ts +15 -2
  12. package/dist/internal/runtime.d.ts.map +1 -1
  13. package/dist/internal/runtime.js +71 -5
  14. package/dist/internal/singleton.d.ts.map +1 -1
  15. package/dist/internal/singleton.js +14 -0
  16. package/dist/internal/standalone.d.ts +10 -0
  17. package/dist/internal/standalone.d.ts.map +1 -0
  18. package/dist/internal/standalone.js +246 -0
  19. package/dist/internal/typegen.d.ts +6 -3
  20. package/dist/internal/typegen.d.ts.map +1 -1
  21. package/dist/internal/typegen.js +41 -9
  22. package/dist/public-client.d.ts +4 -0
  23. package/dist/public-client.d.ts.map +1 -1
  24. package/dist/public-types.d.ts +1 -1
  25. package/dist/public-types.d.ts.map +1 -1
  26. package/dist/public.d.ts +1 -1
  27. package/dist/public.d.ts.map +1 -1
  28. package/dist/server.d.ts +1 -1
  29. package/dist/server.d.ts.map +1 -1
  30. package/dist/types.d.ts +7 -3
  31. package/dist/types.d.ts.map +1 -1
  32. package/package.json +1 -1
  33. package/src/client.ts +86 -15
  34. package/src/index.ts +2 -0
  35. package/src/internal/node-runtime.ts +4 -2
  36. package/src/internal/public-runtime.ts +58 -1
  37. package/src/internal/runtime.ts +121 -5
  38. package/src/internal/singleton.ts +37 -4
  39. package/src/internal/standalone.ts +309 -0
  40. package/src/internal/typegen.ts +63 -10
  41. package/src/public-client.ts +4 -0
  42. package/src/public-types.ts +1 -0
  43. package/src/public.ts +2 -0
  44. package/src/server.ts +2 -0
  45. package/src/types.ts +14 -8
package/src/client.ts CHANGED
@@ -15,6 +15,10 @@ import { getJson, postJson } from "./internal/http.js";
15
15
  import { validateRequirements } from "./internal/requirements.js";
16
16
  import { resolveRuntimeContext, type BarekeyRuntimeContext } from "./internal/runtime.js";
17
17
  import { createBarekeyClientSingletonKey } from "./internal/singleton.js";
18
+ import {
19
+ buildStandaloneTypegenManifest,
20
+ loadStandaloneDefinitions,
21
+ } from "./internal/standalone.js";
18
22
  import { MemoryCache } from "./internal/cache.js";
19
23
  import { DEFAULT_TYPEGEN_TTL_MS, resolveTtlMilliseconds } from "./internal/ttl.js";
20
24
  import {
@@ -118,6 +122,26 @@ function resolveEvaluatedResponse(evaluated: EvaluateResponse): BarekeyEvaluated
118
122
  };
119
123
  }
120
124
 
125
+ function createTypegenIdentity(context: BarekeyRuntimeContext): {
126
+ baseUrl: string | null;
127
+ orgSlug: string;
128
+ projectSlug: string;
129
+ stageSlug: string;
130
+ typegenMode: BarekeyRuntimeContext["typegenMode"];
131
+ runtimeMode: BarekeyRuntimeContext["mode"];
132
+ localEnvRoot: string | null;
133
+ } {
134
+ return {
135
+ baseUrl: context.baseUrl,
136
+ orgSlug: context.organization,
137
+ projectSlug: context.project,
138
+ stageSlug: context.environment,
139
+ typegenMode: context.typegenMode,
140
+ runtimeMode: context.mode,
141
+ localEnvRoot: context.localEnvRoot,
142
+ };
143
+ }
144
+
121
145
  export class BarekeyClient {
122
146
  private readonly options!: BarekeyClientOptions;
123
147
  private readonly fetchFn!: typeof globalThis.fetch;
@@ -128,6 +152,10 @@ export class BarekeyClient {
128
152
  private typegenWatcherStarted = false;
129
153
 
130
154
  constructor();
155
+ constructor(options: {
156
+ requirements?: BarekeyClientOptions["requirements"];
157
+ typegen?: BarekeyClientOptions["typegen"];
158
+ });
131
159
  constructor(options: {
132
160
  organization: string;
133
161
  project: string;
@@ -184,13 +212,17 @@ export class BarekeyClient {
184
212
  });
185
213
  }
186
214
 
187
- const manifest = await this.fetchTypegenManifest(context);
188
- return await writeInstalledSdkGeneratedTypes(manifest, {
189
- baseUrl: context.baseUrl,
190
- orgSlug: context.organization,
191
- projectSlug: context.project,
192
- stageSlug: context.environment,
193
- });
215
+ const manifest =
216
+ context.mode === "standalone"
217
+ ? await buildStandaloneTypegenManifest({
218
+ rootDirectory: context.localEnvRoot,
219
+ organization: context.organization,
220
+ project: context.project,
221
+ environment: context.environment,
222
+ })
223
+ : await this.fetchTypegenManifest(context);
224
+
225
+ return await writeInstalledSdkGeneratedTypes(manifest, createTypegenIdentity(context));
194
226
  }
195
227
 
196
228
  private async getRuntimeContext(): Promise<BarekeyRuntimeContext> {
@@ -208,6 +240,15 @@ export class BarekeyClient {
208
240
 
209
241
  private async fetchTypegenManifest(context?: BarekeyRuntimeContext): Promise<TypegenManifest> {
210
242
  const resolvedContext = context ?? (await this.getRuntimeContext());
243
+ if (resolvedContext.mode !== "centralized") {
244
+ return await buildStandaloneTypegenManifest({
245
+ rootDirectory: resolvedContext.localEnvRoot,
246
+ organization: resolvedContext.organization,
247
+ project: resolvedContext.project,
248
+ environment: resolvedContext.environment,
249
+ });
250
+ }
251
+
211
252
  return await getJson<TypegenManifest>({
212
253
  fetchFn: this.fetchFn,
213
254
  baseUrl: resolvedContext.baseUrl,
@@ -245,10 +286,13 @@ export class BarekeyClient {
245
286
 
246
287
  const intervalMs = this.getTypegenIntervalMs();
247
288
  const watcherKey = [
248
- context.baseUrl,
289
+ context.baseUrl ?? "",
249
290
  context.organization,
250
291
  context.project,
251
292
  context.environment,
293
+ context.mode,
294
+ context.localEnvRoot ?? "",
295
+ context.typegenMode,
252
296
  generatedTypesPath,
253
297
  ].join("|");
254
298
 
@@ -298,10 +342,7 @@ export class BarekeyClient {
298
342
  sharedTypegenWatchers.set(watcherKey, watcher);
299
343
  if (
300
344
  !(await hasFreshInstalledSdkTypegen(intervalMs, {
301
- baseUrl: context.baseUrl,
302
- orgSlug: context.organization,
303
- projectSlug: context.project,
304
- stageSlug: context.environment,
345
+ ...createTypegenIdentity(context),
305
346
  }))
306
347
  ) {
307
348
  void runWatcher(watcher);
@@ -320,7 +361,14 @@ export class BarekeyClient {
320
361
  }
321
362
 
322
363
  private buildDefinitionCacheKey(context: BarekeyRuntimeContext, name: string): string {
323
- return [context.organization, context.project, context.environment, name].join("|");
364
+ return [
365
+ context.mode,
366
+ context.localEnvRoot ?? "",
367
+ context.organization,
368
+ context.project,
369
+ context.environment,
370
+ name,
371
+ ].join("|");
324
372
  }
325
373
 
326
374
  private buildEvaluationCacheKey(
@@ -329,12 +377,14 @@ export class BarekeyClient {
329
377
  options?: BarekeyGetOptions,
330
378
  ): string {
331
379
  return [
380
+ context.mode,
381
+ context.localEnvRoot ?? "",
332
382
  context.organization,
333
383
  context.project,
334
384
  context.environment,
335
385
  name,
336
- options?.seed ?? "",
337
- options?.key ?? "",
386
+ context.mode === "standalone" ? "" : options?.seed ?? "",
387
+ context.mode === "standalone" ? "" : options?.key ?? "",
338
388
  ].join("|");
339
389
  }
340
390
 
@@ -344,6 +394,19 @@ export class BarekeyClient {
344
394
  }
345
395
 
346
396
  const context = await this.getRuntimeContext();
397
+ if (context.mode === "standalone") {
398
+ const definitions = await loadStandaloneDefinitions(context.localEnvRoot);
399
+ for (const definition of definitions) {
400
+ this.definitionCache.set(this.buildDefinitionCacheKey(context, definition.name), definition);
401
+ }
402
+
403
+ if (names === undefined) {
404
+ return definitions;
405
+ }
406
+
407
+ return mapValuesToRequestedOrder(names, definitions);
408
+ }
409
+
347
410
  const response = await postJson<DefinitionsResponse>({
348
411
  fetchFn: this.fetchFn,
349
412
  baseUrl: context.baseUrl,
@@ -458,6 +521,14 @@ export class BarekeyClient {
458
521
  context: BarekeyRuntimeContext,
459
522
  options?: BarekeyGetOptions,
460
523
  ): Promise<Array<BarekeyEvaluatedValue>> {
524
+ if (context.mode === "standalone") {
525
+ const definitions = await loadStandaloneDefinitions(context.localEnvRoot);
526
+ const resolvedDefinitions = mapValuesToRequestedOrder(names, definitions);
527
+ return await Promise.all(
528
+ resolvedDefinitions.map(async (definition) => await evaluateDefinition(definition)),
529
+ );
530
+ }
531
+
461
532
  try {
462
533
  if (names.length === 1) {
463
534
  const evaluated = await postJson<EvaluateResponse>({
package/src/index.ts CHANGED
@@ -53,6 +53,7 @@ export type {
53
53
  BarekeyJsonConfig,
54
54
  BarekeyKey,
55
55
  BarekeyLiteralString,
56
+ BarekeyMode,
56
57
  BarekeyKnownKey,
57
58
  BarekeyResolvedRecord,
58
59
  BarekeyResolvedRecords,
@@ -61,6 +62,7 @@ export type {
61
62
  BarekeyStandardSchemaV1,
62
63
  BarekeyTemporalInstant,
63
64
  BarekeyTemporalInstantLike,
65
+ BarekeyTypegenMode,
64
66
  BarekeyTtlInput,
65
67
  BarekeyTypegenResult,
66
68
  BarekeyValueForGeneratedMap,
@@ -9,7 +9,7 @@ import {
9
9
  } from "../errors.js";
10
10
  import { postJson } from "./http.js";
11
11
 
12
- type NodeRuntimeModules = {
12
+ export type NodeRuntimeModules = {
13
13
  childProcess: typeof import("node:child_process");
14
14
  fs: typeof import("node:fs/promises");
15
15
  moduleApi: {
@@ -57,7 +57,7 @@ function isNodeRuntime(): boolean {
57
57
  );
58
58
  }
59
59
 
60
- async function loadNodeRuntime(): Promise<NodeRuntimeModules | null> {
60
+ export async function loadNodeRuntime(): Promise<NodeRuntimeModules | null> {
61
61
  if (!isNodeRuntime()) {
62
62
  return null;
63
63
  }
@@ -352,6 +352,7 @@ export async function isFilesystemAvailable(): Promise<boolean> {
352
352
 
353
353
  export async function loadBarekeyJsonConfig(): Promise<{
354
354
  path: string;
355
+ directory: string;
355
356
  json: Record<string, unknown>;
356
357
  } | null> {
357
358
  const runtime = await loadNodeRuntime();
@@ -367,6 +368,7 @@ export async function loadBarekeyJsonConfig(): Promise<{
367
368
  try {
368
369
  return {
369
370
  path: candidate,
371
+ directory: current,
370
372
  json: JSON.parse(raw) as Record<string, unknown>,
371
373
  };
372
374
  } catch (error: unknown) {
@@ -4,7 +4,12 @@ import {
4
4
  NoConfigurationProvidedError,
5
5
  } from "../errors.js";
6
6
  import type { PublicBarekeyClientOptions } from "../public-types.js";
7
- import type { BarekeyJsonConfig, BarekeyStandardSchemaV1 } from "../types.js";
7
+ import type {
8
+ BarekeyJsonConfig,
9
+ BarekeyMode,
10
+ BarekeyStandardSchemaV1,
11
+ BarekeyTypegenMode,
12
+ } from "../types.js";
8
13
  import { normalizeBaseUrl } from "./http.js";
9
14
  import { isFilesystemAvailable, loadBarekeyJsonConfig } from "./node-runtime.js";
10
15
 
@@ -47,10 +52,62 @@ function normalizeScope(input: {
47
52
  };
48
53
  }
49
54
 
55
+ function normalizeTypegenMode(value: unknown, source: string): BarekeyTypegenMode {
56
+ if (value === undefined) {
57
+ return "semantic";
58
+ }
59
+
60
+ if (value === "semantic" || value === "minimal") {
61
+ return value;
62
+ }
63
+
64
+ throw new InvalidConfigurationProvidedError({
65
+ message: `${source} must provide config.typegen as "semantic" or "minimal" when set.`,
66
+ });
67
+ }
68
+
69
+ function normalizeMode(value: unknown, source: string): BarekeyMode {
70
+ if (value === undefined) {
71
+ return "centralized";
72
+ }
73
+
74
+ if (value === "centralized" || value === "standalone") {
75
+ return value;
76
+ }
77
+
78
+ throw new InvalidConfigurationProvidedError({
79
+ message: `${source} must provide config.mode as "centralized" or "standalone" when set.`,
80
+ });
81
+ }
82
+
83
+ function createStandaloneUnsupportedError(source: string): Error {
84
+ return new InvalidConfigurationProvidedError({
85
+ message: [
86
+ `${source} sets config.mode to "standalone".`,
87
+ "PublicBarekeyClient does not support standalone local env mode because it relies on a server filesystem to read .env files.",
88
+ "Use BarekeyClient on the server instead, or switch barekey.json config.mode back to \"centralized\" for browser/public usage.",
89
+ ].join(" "),
90
+ });
91
+ }
92
+
50
93
  function normalizeJsonConfig(
51
94
  input: BarekeyJsonConfig | Record<string, unknown>,
52
95
  source: string,
53
96
  ): BarekeyResolvedScope {
97
+ const config =
98
+ "config" in input && typeof input.config === "object" && input.config !== null
99
+ ? (input.config as Record<string, unknown>)
100
+ : undefined;
101
+
102
+ normalizeTypegenMode(
103
+ config?.typegen ?? ("typegen" in input ? input.typegen : undefined),
104
+ source,
105
+ );
106
+
107
+ if (normalizeMode(config?.mode, source) === "standalone") {
108
+ throw createStandaloneUnsupportedError(source);
109
+ }
110
+
54
111
  return normalizeScope({
55
112
  organization: input.organization ?? input.org,
56
113
  project: input.project,
@@ -7,7 +7,13 @@ import {
7
7
  NoCredentialsProvidedError,
8
8
  UnauthorizedError,
9
9
  } from "../errors.js";
10
- import type { BarekeyClientOptions, BarekeyJsonConfig, BarekeyStandardSchemaV1 } from "../types.js";
10
+ import type {
11
+ BarekeyClientOptions,
12
+ BarekeyJsonConfig,
13
+ BarekeyMode,
14
+ BarekeyStandardSchemaV1,
15
+ BarekeyTypegenMode,
16
+ } from "../types.js";
11
17
  import { type InternalAuthResolver, normalizeBaseUrl } from "./http.js";
12
18
  import {
13
19
  isFilesystemAvailable,
@@ -21,14 +27,31 @@ type BarekeyResolvedScope = {
21
27
  organization: string;
22
28
  project: string;
23
29
  environment: string;
30
+ typegenMode: BarekeyTypegenMode;
31
+ mode: BarekeyMode;
32
+ localEnvRoot: string | null;
24
33
  };
25
34
 
26
- export type BarekeyRuntimeContext = BarekeyResolvedScope & {
35
+ type BarekeyCentralizedRuntimeContext = BarekeyResolvedScope & {
36
+ mode: "centralized";
37
+ localEnvRoot: null;
27
38
  baseUrl: string;
28
39
  auth: InternalAuthResolver;
29
40
  requirements?: BarekeyStandardSchemaV1;
30
41
  };
31
42
 
43
+ type BarekeyStandaloneRuntimeContext = BarekeyResolvedScope & {
44
+ mode: "standalone";
45
+ localEnvRoot: string;
46
+ baseUrl: null;
47
+ auth: null;
48
+ requirements?: BarekeyStandardSchemaV1;
49
+ };
50
+
51
+ export type BarekeyRuntimeContext =
52
+ | BarekeyCentralizedRuntimeContext
53
+ | BarekeyStandaloneRuntimeContext;
54
+
32
55
  function readProcessEnv(key: string): string | undefined {
33
56
  if (typeof process === "undefined" || typeof process.env !== "object" || process.env === null) {
34
57
  return undefined;
@@ -42,36 +65,101 @@ function readConfigString(value: unknown): string | undefined {
42
65
  return typeof value === "string" ? value.trim() : undefined;
43
66
  }
44
67
 
68
+ function safeCurrentWorkingDirectory(): string | null {
69
+ if (typeof process === "undefined" || typeof process.cwd !== "function") {
70
+ return null;
71
+ }
72
+
73
+ return process.cwd();
74
+ }
75
+
76
+ function normalizeTypegenMode(value: unknown, source: string): BarekeyTypegenMode {
77
+ if (value === undefined) {
78
+ return "semantic";
79
+ }
80
+
81
+ if (value === "semantic" || value === "minimal") {
82
+ return value;
83
+ }
84
+
85
+ throw new InvalidConfigurationProvidedError({
86
+ message: `${source} must provide config.typegen as "semantic" or "minimal" when set.`,
87
+ });
88
+ }
89
+
90
+ function normalizeMode(value: unknown, source: string): BarekeyMode {
91
+ if (value === undefined) {
92
+ return "centralized";
93
+ }
94
+
95
+ if (value === "centralized" || value === "standalone") {
96
+ return value;
97
+ }
98
+
99
+ throw new InvalidConfigurationProvidedError({
100
+ message: `${source} must provide config.mode as "centralized" or "standalone" when set.`,
101
+ });
102
+ }
103
+
45
104
  function normalizeScope(input: {
46
105
  organization?: unknown;
47
106
  project?: unknown;
48
107
  environment?: unknown;
108
+ typegenMode?: BarekeyTypegenMode;
109
+ mode?: BarekeyMode;
110
+ localEnvRoot?: string | null;
49
111
  source: string;
50
112
  }): BarekeyResolvedScope {
113
+ const mode = input.mode ?? "centralized";
51
114
  const organization = readConfigString(input.organization) ?? "";
52
115
  const project = readConfigString(input.project) ?? "";
53
116
  const environment = readConfigString(input.environment) ?? "";
54
- if (organization.length === 0 || project.length === 0 || environment.length === 0) {
117
+ if (
118
+ mode !== "standalone" &&
119
+ (organization.length === 0 || project.length === 0 || environment.length === 0)
120
+ ) {
55
121
  throw new InvalidConfigurationProvidedError({
56
122
  message: `${input.source} must provide organization, project, and environment.`,
57
123
  });
58
124
  }
59
125
 
126
+ const localEnvRoot = mode === "standalone" ? input.localEnvRoot ?? safeCurrentWorkingDirectory() : null;
127
+ if (mode === "standalone" && (!localEnvRoot || localEnvRoot.trim().length === 0)) {
128
+ throw new FsNotAvailableError({
129
+ message: "Barekey standalone mode requires filesystem access and a working directory.",
130
+ });
131
+ }
132
+
60
133
  return {
61
134
  organization,
62
135
  project,
63
136
  environment,
137
+ typegenMode: mode === "standalone" ? "minimal" : (input.typegenMode ?? "semantic"),
138
+ mode,
139
+ localEnvRoot: mode === "standalone" ? localEnvRoot : null,
64
140
  };
65
141
  }
66
142
 
67
143
  function normalizeJsonConfig(
68
144
  input: BarekeyJsonConfig | Record<string, unknown>,
69
145
  source: string,
146
+ localEnvRoot: string | null,
70
147
  ): BarekeyResolvedScope {
148
+ const config =
149
+ "config" in input && typeof input.config === "object" && input.config !== null
150
+ ? (input.config as Record<string, unknown>)
151
+ : undefined;
152
+
71
153
  return normalizeScope({
72
154
  organization: input.organization ?? input.org,
73
155
  project: input.project,
74
156
  environment: input.environment ?? input.stage,
157
+ typegenMode: normalizeTypegenMode(
158
+ config?.typegen ?? ("typegen" in input ? input.typegen : undefined),
159
+ source,
160
+ ),
161
+ mode: normalizeMode(config?.mode, source),
162
+ localEnvRoot,
75
163
  source,
76
164
  });
77
165
  }
@@ -100,7 +188,11 @@ async function resolveScope(options: BarekeyClientOptions): Promise<BarekeyResol
100
188
  }
101
189
 
102
190
  if (explicitJson !== undefined) {
103
- return normalizeJsonConfig(explicitJson, "The provided json configuration");
191
+ return normalizeJsonConfig(
192
+ explicitJson,
193
+ "The provided json configuration",
194
+ safeCurrentWorkingDirectory(),
195
+ );
104
196
  }
105
197
 
106
198
  if (explicitCount === 3) {
@@ -108,6 +200,9 @@ async function resolveScope(options: BarekeyClientOptions): Promise<BarekeyResol
108
200
  organization: explicitOrganization,
109
201
  project: explicitProject,
110
202
  environment: explicitEnvironment,
203
+ typegenMode: "semantic",
204
+ mode: "centralized",
205
+ localEnvRoot: null,
111
206
  source: "The provided Barekey configuration",
112
207
  });
113
208
  }
@@ -125,6 +220,7 @@ async function resolveScope(options: BarekeyClientOptions): Promise<BarekeyResol
125
220
  return normalizeJsonConfig(
126
221
  loadedConfig.json,
127
222
  `The barekey.json file at ${loadedConfig.path}`,
223
+ loadedConfig.directory,
128
224
  );
129
225
  }
130
226
 
@@ -189,9 +285,29 @@ export async function resolveRuntimeContext(
189
285
  options: BarekeyClientOptions,
190
286
  fetchFn: typeof globalThis.fetch,
191
287
  ): Promise<BarekeyRuntimeContext> {
192
- const [scope, auth] = await Promise.all([resolveScope(options), resolveAuth(fetchFn)]);
288
+ const scope = await resolveScope(options);
289
+ if (scope.mode === "standalone") {
290
+ if (!(await isFilesystemAvailable())) {
291
+ throw new FsNotAvailableError({
292
+ message: "Barekey standalone mode requires a local filesystem to read .env files.",
293
+ });
294
+ }
295
+
296
+ return {
297
+ ...scope,
298
+ mode: "standalone",
299
+ localEnvRoot: scope.localEnvRoot ?? safeCurrentWorkingDirectory() ?? "",
300
+ baseUrl: null,
301
+ auth: null,
302
+ requirements: options.requirements,
303
+ };
304
+ }
305
+
306
+ const auth = await resolveAuth(fetchFn);
193
307
  return {
194
308
  ...scope,
309
+ mode: "centralized",
310
+ localEnvRoot: null,
195
311
  baseUrl: auth.baseUrl,
196
312
  auth: auth.auth,
197
313
  requirements: options.requirements,
@@ -42,15 +42,36 @@ function safeCurrentWorkingDirectory(): string {
42
42
 
43
43
  function normalizeJsonScope(
44
44
  value: BarekeyJsonConfig | undefined,
45
- ): { organization: string | null; project: string | null; environment: string | null } | null {
45
+ ): {
46
+ organization: string | null;
47
+ project: string | null;
48
+ environment: string | null;
49
+ typegenMode: string | null;
50
+ runtimeMode: string | null;
51
+ localEnvRoot: string | null;
52
+ } | null {
46
53
  if (value === undefined) {
47
54
  return null;
48
55
  }
49
56
 
57
+ const config =
58
+ typeof value.config === "object" && value.config !== null
59
+ ? (value.config as { typegen?: unknown; mode?: unknown })
60
+ : undefined;
61
+ const runtimeMode = config?.mode === "standalone" ? "standalone" : "centralized";
62
+
50
63
  return {
51
64
  organization: readConfigString(value.organization ?? value.org),
52
65
  project: readConfigString(value.project),
53
66
  environment: readConfigString(value.environment ?? value.stage),
67
+ typegenMode:
68
+ runtimeMode === "standalone"
69
+ ? "minimal"
70
+ : config?.typegen === "minimal"
71
+ ? "minimal"
72
+ : "semantic",
73
+ runtimeMode,
74
+ localEnvRoot: runtimeMode === "standalone" ? safeCurrentWorkingDirectory() : null,
54
75
  };
55
76
  }
56
77
 
@@ -58,9 +79,18 @@ function normalizeScopeKey(
58
79
  options:
59
80
  | BarekeyClientOptions
60
81
  | PublicBarekeyClientOptions,
61
- ): { organization: string | null; project: string | null; environment: string | null } | {
62
- cwd: string;
63
- } {
82
+ ):
83
+ | {
84
+ organization: string | null;
85
+ project: string | null;
86
+ environment: string | null;
87
+ typegenMode: string | null;
88
+ runtimeMode: string | null;
89
+ localEnvRoot: string | null;
90
+ }
91
+ | {
92
+ cwd: string;
93
+ } {
64
94
  const jsonScope = normalizeJsonScope("json" in options ? options.json : undefined);
65
95
  if (jsonScope !== null) {
66
96
  return jsonScope;
@@ -74,6 +104,9 @@ function normalizeScopeKey(
74
104
  organization,
75
105
  project,
76
106
  environment,
107
+ typegenMode: "semantic",
108
+ runtimeMode: "centralized",
109
+ localEnvRoot: null,
77
110
  };
78
111
  }
79
112