@barekey/sdk 0.1.2 → 0.2.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 (50) hide show
  1. package/README.md +9 -3
  2. package/dist/client.d.ts +2 -3
  3. package/dist/client.d.ts.map +1 -1
  4. package/dist/index.d.ts +3 -1
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +1 -0
  7. package/dist/internal/node-runtime.d.ts +2 -1
  8. package/dist/internal/node-runtime.d.ts.map +1 -1
  9. package/dist/internal/node-runtime.js +7 -4
  10. package/dist/internal/public-runtime.d.ts +14 -0
  11. package/dist/internal/public-runtime.d.ts.map +1 -0
  12. package/dist/internal/public-runtime.js +78 -0
  13. package/dist/internal/typegen.d.ts +5 -0
  14. package/dist/internal/typegen.d.ts.map +1 -1
  15. package/dist/internal/typegen.js +44 -13
  16. package/dist/key-types.typecheck.d.ts +13 -0
  17. package/dist/key-types.typecheck.d.ts.map +1 -0
  18. package/dist/key-types.typecheck.js +5 -0
  19. package/dist/public-client.d.ts +35 -0
  20. package/dist/public-client.d.ts.map +1 -0
  21. package/dist/public-client.js +150 -0
  22. package/dist/public-types.d.ts +27 -0
  23. package/dist/public-types.d.ts.map +1 -0
  24. package/dist/public-types.js +1 -0
  25. package/dist/public.d.ts +6 -0
  26. package/dist/public.d.ts.map +1 -0
  27. package/dist/public.js +3 -0
  28. package/dist/server.d.ts +5 -0
  29. package/dist/server.d.ts.map +1 -0
  30. package/dist/server.js +3 -0
  31. package/dist/types.d.ts +6 -1
  32. package/dist/types.d.ts.map +1 -1
  33. package/generated.public.d.ts +8 -0
  34. package/generated.server.d.ts +8 -0
  35. package/index.d.ts +0 -1
  36. package/package.json +18 -3
  37. package/public.d.ts +2 -0
  38. package/server.d.ts +2 -0
  39. package/src/client.ts +3 -3
  40. package/src/index.ts +10 -0
  41. package/src/internal/node-runtime.ts +9 -5
  42. package/src/internal/public-runtime.ts +123 -0
  43. package/src/internal/typegen.ts +68 -13
  44. package/src/key-types.typecheck.ts +68 -0
  45. package/src/public-client.ts +231 -0
  46. package/src/public-types.ts +63 -0
  47. package/src/public.ts +71 -0
  48. package/src/server.ts +62 -0
  49. package/src/types.ts +8 -1
  50. package/generated.d.ts +0 -16
package/README.md CHANGED
@@ -5,17 +5,23 @@ Barekey TypeScript SDK.
5
5
  ## Install
6
6
 
7
7
  ```bash
8
- npm install @barekey/sdk
8
+ bun add @barekey/sdk
9
9
  ```
10
10
 
11
11
  ## Build
12
12
 
13
13
  ```bash
14
- npm run build
14
+ bun run build
15
15
  ```
16
16
 
17
17
  ## Typecheck
18
18
 
19
19
  ```bash
20
- npm run typecheck
20
+ bun run typecheck
21
+ ```
22
+
23
+ ## Test
24
+
25
+ ```bash
26
+ bun test
21
27
  ```
package/dist/client.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { BarekeyEnvHandle } from "./handle.js";
2
- import type { BarekeyClientOptions, BarekeyGeneratedTypeMap, BarekeyGetOptions, BarekeyJsonConfig, BarekeyKnownKey, BarekeyTypegenResult } from "./types.js";
2
+ import type { BarekeyClientOptions, BarekeyGeneratedTypeMap, BarekeyGetOptions, BarekeyJsonConfig, BarekeyKey, BarekeyKnownKey, BarekeyTypegenResult } from "./types.js";
3
3
  export declare class BarekeyClient {
4
4
  private readonly options;
5
5
  private readonly fetchFn;
@@ -21,8 +21,7 @@ export declare class BarekeyClient {
21
21
  requirements?: BarekeyClientOptions["requirements"];
22
22
  typegen?: BarekeyClientOptions["typegen"];
23
23
  });
24
- get<TKey extends BarekeyKnownKey>(name: TKey, options?: BarekeyGetOptions): BarekeyEnvHandle<BarekeyGeneratedTypeMap[TKey]>;
25
- get(name: string, options?: BarekeyGetOptions): BarekeyEnvHandle<unknown>;
24
+ get<TKey extends BarekeyKey>(name: TKey, options?: BarekeyGetOptions): BarekeyEnvHandle<TKey extends BarekeyKnownKey ? BarekeyGeneratedTypeMap[TKey] : unknown>;
26
25
  typegen(): Promise<BarekeyTypegenResult>;
27
26
  private getRuntimeContext;
28
27
  private fetchTypegenManifest;
@@ -1 +1 @@
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,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QACpD,OAAO,CAAC,EAAE,oBAAoB,CAAC,SAAS,CAAC,CAAC;KAC3C;IAMD,GAAG,CAAC,IAAI,SAAS,UAAU,EACzB,IAAI,EAAE,IAAI,EACV,OAAO,CAAC,EAAE,iBAAiB,GAC1B,gBAAgB,CAAC,IAAI,SAAS,eAAe,GAAG,uBAAuB,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC;IAOrF,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/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
- export type { AB, BarekeyClientOptions, BarekeyCoerceTarget, BarekeyDeclaredType, BarekeyErrorCode, BarekeyGeneratedTypeMap, BarekeyGetOptions, BarekeyJsonConfig, BarekeyKnownKey, BarekeyResolvedKind, BarekeyRolloutMilestone, BarekeyStandardSchemaV1, BarekeyTemporalInstant, BarekeyTemporalInstantLike, BarekeyTtlInput, BarekeyTypegenResult, Env, Linear, Secret, } from "./types.js";
5
+ export type { AB, BarekeyClientOptions, BarekeyCoerceTarget, BarekeyDeclaredType, BarekeyErrorCode, BarekeyGeneratedTypeMap, BarekeyGetOptions, BarekeyJsonConfig, BarekeyKey, BarekeyLiteralString, BarekeyKnownKey, BarekeyResolvedKind, BarekeyRolloutMilestone, BarekeyStandardSchemaV1, BarekeyTemporalInstant, BarekeyTemporalInstantLike, BarekeyTtlInput, BarekeyTypegenResult, Env, Linear, Secret, } from "./types.js";
6
+ export type { BarekeyPublicGeneratedTypeMap, BarekeyPublicKey, BarekeyPublicKnownKey, PublicBarekeyClientOptions, } from "./public-types.js";
5
7
  //# sourceMappingURL=index.d.ts.map
@@ -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,UAAU,EACV,oBAAoB,EACpB,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,gBAAgB,EAChB,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";
@@ -10,7 +10,8 @@ export declare function loadCliSessionAuthResolver(fetchFn: typeof globalThis.fe
10
10
  } | null>;
11
11
  type InstalledSdkTypegenTarget = {
12
12
  packageRoot: string;
13
- generatedTypesPath: string;
13
+ serverGeneratedTypesPath: string;
14
+ publicGeneratedTypesPath: string;
14
15
  typegenMetadataPath: string;
15
16
  };
16
17
  export declare function resolveInstalledSdkTypegenTarget(): Promise<InstalledSdkTypegenTarget | 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,kBAAkB,EAAE,MAAM,CAAC;IAC3B,mBAAmB,EAAE,MAAM,CAAC;CAC7B,CAAC;AAEF,wBAAsB,gCAAgC,IAAI,OAAO,CAAC,yBAAyB,GAAG,IAAI,CAAC,CAuDlG;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"}
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,22 @@ 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 generatedTypesPath = runtime.path.join(current, "generated.d.ts");
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(generatedTypesPath);
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
- generatedTypesPath,
368
+ serverGeneratedTypesPath,
369
+ publicGeneratedTypesPath,
367
370
  typegenMetadataPath: runtime.path.join(current, "typegen.json"),
368
371
  };
369
372
  }
@@ -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
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;
@@ -27,6 +28,10 @@ type TypegenMetadataIdentity = {
27
28
  stageSlug: string;
28
29
  };
29
30
  export declare function resolveInstalledSdkGeneratedTypesPath(): Promise<string | null>;
31
+ export declare function renderGeneratedTypesForManifest(manifest: TypegenManifest): {
32
+ serverContents: string;
33
+ publicContents: string;
34
+ };
30
35
  export declare function hasFreshInstalledSdkTypegen(intervalMs: number, identity: TypegenMetadataIdentity): Promise<boolean>;
31
36
  export declare function writeInstalledSdkGeneratedTypes(manifest: TypegenManifest, identity: TypegenMetadataIdentity): Promise<BarekeyTypegenResult>;
32
37
  export {};
@@ -1 +1 @@
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,GAA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,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"}
@@ -21,16 +21,17 @@ function renderRolloutMetadataType(row) {
21
21
  }
22
22
  function renderVariableType(row) {
23
23
  if (row.kind === "secret") {
24
- return `Env<Secret, ${row.typeScriptType}>`;
24
+ return `Env<Secret, ${row.typeScriptType}, never, ${JSON.stringify(row.visibility)}>`;
25
25
  }
26
26
  if (row.kind === "ab_roll") {
27
- return `Env<AB, ${row.typeScriptType}>`;
27
+ return `Env<AB, ${row.typeScriptType}, never, ${JSON.stringify(row.visibility)}>`;
28
28
  }
29
- return `Env<AB, ${row.typeScriptType}, ${renderRolloutMetadataType(row)}>`;
29
+ return `Env<AB, ${row.typeScriptType}, ${renderRolloutMetadataType(row)}, ${JSON.stringify(row.visibility)}>`;
30
30
  }
31
- function buildGeneratedTypesContents(manifest) {
31
+ function buildGeneratedTypesContents(manifest, input) {
32
32
  const mapLines = manifest.variables
33
33
  .slice()
34
+ .filter(input.include)
34
35
  .sort((left, right) => left.name.localeCompare(right.name))
35
36
  .map((row) => ` ${JSON.stringify(row.name)}: ${renderVariableType(row)};`)
36
37
  .join("\n");
@@ -38,10 +39,10 @@ function buildGeneratedTypesContents(manifest) {
38
39
  /* This file is generated by barekey typegen. */
39
40
  /* barekey-manifest-version: ${manifest.manifestVersion} */
40
41
 
41
- import type { AB, EaseInOut, Env, Linear, Secret, Step } from "./dist/types.js";
42
+ import type { AB, EaseInOut, Env, Linear, Secret, Step } from "${input.typeModulePath}";
42
43
 
43
- declare module "./dist/types.js" {
44
- interface BarekeyGeneratedTypeMap {
44
+ declare module "${input.declaredModulePath}" {
45
+ interface ${input.interfaceName} {
45
46
  ${mapLines.length > 0 ? mapLines : ""}
46
47
  }
47
48
  }
@@ -108,7 +109,23 @@ function buildTypegenMetadataContents(lastGeneratedAt, identity) {
108
109
  }
109
110
  export async function resolveInstalledSdkGeneratedTypesPath() {
110
111
  const target = await resolveInstalledSdkTypegenTarget();
111
- return target?.generatedTypesPath ?? null;
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
+ };
112
129
  }
113
130
  export async function hasFreshInstalledSdkTypegen(intervalMs, identity) {
114
131
  const target = await resolveInstalledSdkTypegenTarget();
@@ -133,23 +150,37 @@ export async function writeInstalledSdkGeneratedTypes(manifest, identity) {
133
150
  return {
134
151
  written: false,
135
152
  path: "",
153
+ serverPath: "",
154
+ publicPath: "",
136
155
  manifestVersion: manifest.manifestVersion,
137
156
  };
138
157
  }
139
- const existingContents = await readTextFile(target.generatedTypesPath);
140
- if (readManifestVersion(existingContents) === manifest.manifestVersion) {
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) {
141
164
  await writeTextFileAtomic(target.typegenMetadataPath, buildTypegenMetadataContents(new Date(), identity));
142
165
  return {
143
166
  written: false,
144
- path: target.generatedTypesPath,
167
+ path: target.serverGeneratedTypesPath,
168
+ serverPath: target.serverGeneratedTypesPath,
169
+ publicPath: target.publicGeneratedTypesPath,
145
170
  manifestVersion: manifest.manifestVersion,
146
171
  };
147
172
  }
148
- await writeTextFileAtomic(target.generatedTypesPath, buildGeneratedTypesContents(manifest));
173
+ const rendered = renderGeneratedTypesForManifest(manifest);
174
+ await Promise.all([
175
+ writeTextFileAtomic(target.serverGeneratedTypesPath, rendered.serverContents),
176
+ writeTextFileAtomic(target.publicGeneratedTypesPath, rendered.publicContents),
177
+ ]);
149
178
  await writeTextFileAtomic(target.typegenMetadataPath, buildTypegenMetadataContents(new Date(), identity));
150
179
  return {
151
180
  written: true,
152
- path: target.generatedTypesPath,
181
+ path: target.serverGeneratedTypesPath,
182
+ serverPath: target.serverGeneratedTypesPath,
183
+ publicPath: target.publicGeneratedTypesPath,
153
184
  manifestVersion: manifest.manifestVersion,
154
185
  };
155
186
  }
@@ -0,0 +1,13 @@
1
+ import type { Env, Secret } from "./types.js";
2
+ declare module "./types.js" {
3
+ interface BarekeyGeneratedTypeMap {
4
+ PRIVATE_TOKEN: Env<Secret, string, never, "private">;
5
+ }
6
+ }
7
+ declare module "./public-types.js" {
8
+ interface BarekeyPublicGeneratedTypeMap {
9
+ PUBLIC_THEME: Env<Secret, "light" | "dark", never, "public">;
10
+ }
11
+ }
12
+ export {};
13
+ //# sourceMappingURL=key-types.typecheck.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"key-types.typecheck.d.ts","sourceRoot":"","sources":["../src/key-types.typecheck.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAa9C,OAAO,QAAQ,YAAY,CAAC;IAC1B,UAAU,uBAAuB;QAC/B,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;KACtD;CACF;AAED,OAAO,QAAQ,mBAAmB,CAAC;IACjC,UAAU,6BAA6B;QACrC,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;KAC9D;CACF;AAyCD,OAAO,EAAE,CAAC"}
@@ -0,0 +1,5 @@
1
+ const privateKnownHandle = client.get("PRIVATE_TOKEN");
2
+ const privateUnknownHandle = client.get("SOME_RUNTIME_KEY");
3
+ const publicKnownHandle = publicClient.get("PUBLIC_THEME");
4
+ const publicUnknownHandle = publicClient.get("SOME_RUNTIME_KEY");
5
+ export {};
@@ -0,0 +1,35 @@
1
+ import { BarekeyEnvHandle } from "./handle.js";
2
+ import type { BarekeyPublicGeneratedTypeMap, BarekeyPublicKey, 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 BarekeyPublicKey>(name: TKey, options?: BarekeyGetOptions): BarekeyEnvHandle<TKey extends BarekeyPublicKnownKey ? BarekeyPublicGeneratedTypeMap[TKey] : unknown>;
25
+ private getRuntimeContext;
26
+ private buildDefinitionCacheKey;
27
+ private buildEvaluationCacheKey;
28
+ private fetchDefinitions;
29
+ private ensureRequirementsValidated;
30
+ private getStaticDefinition;
31
+ private resolveStaticValue;
32
+ private resolveDynamicValue;
33
+ private resolveEvaluatedValue;
34
+ }
35
+ //# 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,gBAAgB,EAChB,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,gBAAgB,EAC/B,IAAI,EAAE,IAAI,EACV,OAAO,CAAC,EAAE,iBAAiB,GAC1B,gBAAgB,CACjB,IAAI,SAAS,qBAAqB,GAAG,6BAA6B,CAAC,IAAI,CAAC,GAAG,OAAO,CACnF;YAOa,iBAAiB;IAa/B,OAAO,CAAC,uBAAuB;IAI/B,OAAO,CAAC,uBAAuB;YAejB,gBAAgB;YAqBhB,2BAA2B;YA4B3B,mBAAmB;YAiBnB,kBAAkB;YAQlB,mBAAmB;YAkCnB,qBAAqB;CAUpC"}
@@ -0,0 +1,150 @@
1
+ import { VariableNotFoundError } from "./errors.js";
2
+ import { BarekeyEnvHandle } from "./handle.js";
3
+ import { evaluateDefinition, parseDeclaredValue, validateDynamicOptions, } from "./internal/evaluate.js";
4
+ import { postJson } from "./internal/http.js";
5
+ import { MemoryCache } from "./internal/cache.js";
6
+ import { validateRequirements } from "./internal/requirements.js";
7
+ import { resolvePublicRuntimeContext, } from "./internal/public-runtime.js";
8
+ import { resolveTtlMilliseconds } from "./internal/ttl.js";
9
+ function createDefaultFetch() {
10
+ if (typeof globalThis.fetch === "function") {
11
+ return globalThis.fetch.bind(globalThis);
12
+ }
13
+ return (async () => {
14
+ throw new Error("fetch is not available in this runtime.");
15
+ });
16
+ }
17
+ export class PublicBarekeyClient {
18
+ options;
19
+ fetchFn;
20
+ definitionCache = new MemoryCache();
21
+ evaluationCache = new MemoryCache();
22
+ runtimeContextPromise = null;
23
+ requirementsPromise = null;
24
+ constructor(options = {}) {
25
+ this.options = options;
26
+ this.fetchFn = createDefaultFetch();
27
+ }
28
+ get(name, options) {
29
+ return new BarekeyEnvHandle(async () => await this.resolveEvaluatedValue(name, options));
30
+ }
31
+ async getRuntimeContext() {
32
+ if (this.runtimeContextPromise === null) {
33
+ const runtimeContextPromise = resolvePublicRuntimeContext(this.options);
34
+ runtimeContextPromise.catch(() => {
35
+ if (this.runtimeContextPromise === runtimeContextPromise) {
36
+ this.runtimeContextPromise = null;
37
+ }
38
+ });
39
+ this.runtimeContextPromise = runtimeContextPromise;
40
+ }
41
+ return await this.runtimeContextPromise;
42
+ }
43
+ buildDefinitionCacheKey(context, name) {
44
+ return [context.organization, context.project, context.environment, name].join("|");
45
+ }
46
+ buildEvaluationCacheKey(context, name, options) {
47
+ return [
48
+ context.organization,
49
+ context.project,
50
+ context.environment,
51
+ name,
52
+ options?.seed ?? "",
53
+ options?.key ?? "",
54
+ ].join("|");
55
+ }
56
+ async fetchDefinitions(names) {
57
+ const context = await this.getRuntimeContext();
58
+ const response = await postJson({
59
+ fetchFn: this.fetchFn,
60
+ baseUrl: context.baseUrl,
61
+ path: "/v1/public/env/definitions",
62
+ payload: {
63
+ orgSlug: context.organization,
64
+ projectSlug: context.project,
65
+ stageSlug: context.environment,
66
+ ...(names === undefined ? {} : { names }),
67
+ },
68
+ });
69
+ for (const definition of response.definitions) {
70
+ this.definitionCache.set(this.buildDefinitionCacheKey(context, definition.name), definition);
71
+ }
72
+ return response.definitions;
73
+ }
74
+ async ensureRequirementsValidated() {
75
+ const context = await this.getRuntimeContext();
76
+ const requirements = context.requirements;
77
+ if (requirements === undefined) {
78
+ return;
79
+ }
80
+ if (this.requirementsPromise === null) {
81
+ const requirementsPromise = (async () => {
82
+ const definitions = await this.fetchDefinitions();
83
+ const values = {};
84
+ for (const definition of definitions) {
85
+ const evaluated = await evaluateDefinition(definition);
86
+ values[definition.name] = parseDeclaredValue(evaluated.value, evaluated.declaredType);
87
+ }
88
+ await validateRequirements(requirements, values);
89
+ })();
90
+ requirementsPromise.catch(() => {
91
+ if (this.requirementsPromise === requirementsPromise) {
92
+ this.requirementsPromise = null;
93
+ }
94
+ });
95
+ this.requirementsPromise = requirementsPromise;
96
+ }
97
+ await this.requirementsPromise;
98
+ }
99
+ async getStaticDefinition(name) {
100
+ await this.ensureRequirementsValidated();
101
+ const context = await this.getRuntimeContext();
102
+ const cacheKey = this.buildDefinitionCacheKey(context, name);
103
+ const cached = this.definitionCache.get(cacheKey);
104
+ if (cached !== null) {
105
+ return cached;
106
+ }
107
+ const definitions = await this.fetchDefinitions([name]);
108
+ const resolved = definitions[0];
109
+ if (resolved === undefined) {
110
+ throw new VariableNotFoundError();
111
+ }
112
+ return resolved;
113
+ }
114
+ async resolveStaticValue(name, options) {
115
+ const definition = await this.getStaticDefinition(name);
116
+ return await evaluateDefinition(definition, options);
117
+ }
118
+ async resolveDynamicValue(name, options) {
119
+ await this.ensureRequirementsValidated();
120
+ const context = await this.getRuntimeContext();
121
+ const cacheKey = this.buildEvaluationCacheKey(context, name, options);
122
+ const dynamic = options?.dynamic;
123
+ const dynamicTtlMs = dynamic !== undefined && dynamic !== true
124
+ ? resolveTtlMilliseconds(dynamic.ttl, "dynamic.ttl")
125
+ : null;
126
+ if (dynamic !== true) {
127
+ const cached = this.evaluationCache.getRecord(cacheKey);
128
+ if (cached !== null && dynamicTtlMs !== null && Date.now() - cached.storedAtMs <= dynamicTtlMs) {
129
+ return cached.value;
130
+ }
131
+ }
132
+ const freshDefinitions = await this.fetchDefinitions([name]);
133
+ const freshDefinition = freshDefinitions[0];
134
+ if (freshDefinition === undefined) {
135
+ throw new VariableNotFoundError();
136
+ }
137
+ const resolved = await evaluateDefinition(freshDefinition, options);
138
+ if (dynamicTtlMs !== null) {
139
+ this.evaluationCache.set(cacheKey, resolved);
140
+ }
141
+ return resolved;
142
+ }
143
+ async resolveEvaluatedValue(name, options) {
144
+ validateDynamicOptions(options);
145
+ if (options?.dynamic === undefined) {
146
+ return await this.resolveStaticValue(name, options);
147
+ }
148
+ return await this.resolveDynamicValue(name, options);
149
+ }
150
+ }
@@ -0,0 +1,27 @@
1
+ export type { AB, BarekeyCoerceTarget, BarekeyDeclaredType, BarekeyDecision, BarekeyErrorCode, BarekeyEvaluatedValue, BarekeyGetOptions, BarekeyJsonConfig, BarekeyResolvedKind, BarekeyRolloutFunction, BarekeyRolloutMatchedRule, BarekeyRolloutMilestone, BarekeyStandardSchemaPathSegment, BarekeyStandardSchemaResult, BarekeyStandardSchemaV1, BarekeyTemporalInstant, BarekeyTemporalInstantLike, BarekeyTtlInput, BarekeyTypegenResult, BarekeyVariableDefinition, EaseInOut, Env, Linear, Secret, Step, } from "./types.js";
2
+ import type { BarekeyJsonConfig, BarekeyLiteralString, BarekeyStandardSchemaV1 } from "./types.js";
3
+ export interface BarekeyPublicGeneratedTypeMap {
4
+ }
5
+ export type BarekeyPublicKnownKey = Extract<keyof BarekeyPublicGeneratedTypeMap, string>;
6
+ export type BarekeyPublicKey = BarekeyPublicKnownKey | BarekeyLiteralString;
7
+ type BarekeyPublicBaseClientOptions = {
8
+ requirements?: BarekeyStandardSchemaV1;
9
+ baseUrl?: string;
10
+ };
11
+ export type PublicBarekeyClientOptions = (BarekeyPublicBaseClientOptions & {
12
+ organization: string;
13
+ project: string;
14
+ environment: string;
15
+ json?: never;
16
+ }) | (BarekeyPublicBaseClientOptions & {
17
+ json: BarekeyJsonConfig;
18
+ organization?: never;
19
+ project?: never;
20
+ environment?: never;
21
+ }) | (BarekeyPublicBaseClientOptions & {
22
+ organization?: never;
23
+ project?: never;
24
+ environment?: never;
25
+ json?: never;
26
+ });
27
+ //# sourceMappingURL=public-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"public-types.d.ts","sourceRoot":"","sources":["../src/public-types.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,EAAE,EACF,mBAAmB,EACnB,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,sBAAsB,EACtB,yBAAyB,EACzB,uBAAuB,EACvB,gCAAgC,EAChC,2BAA2B,EAC3B,uBAAuB,EACvB,sBAAsB,EACtB,0BAA0B,EAC1B,eAAe,EACf,oBAAoB,EACpB,yBAAyB,EACzB,SAAS,EACT,GAAG,EACH,MAAM,EACN,MAAM,EACN,IAAI,GACL,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EACV,iBAAiB,EACjB,oBAAoB,EACpB,uBAAuB,EACxB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,6BAA6B;CAAG;AAEjD,MAAM,MAAM,qBAAqB,GAAG,OAAO,CAAC,MAAM,6BAA6B,EAAE,MAAM,CAAC,CAAC;AAEzF,MAAM,MAAM,gBAAgB,GAAG,qBAAqB,GAAG,oBAAoB,CAAC;AAE5E,KAAK,8BAA8B,GAAG;IACpC,YAAY,CAAC,EAAE,uBAAuB,CAAC;IACvC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAClC,CAAC,8BAA8B,GAAG;IAChC,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,KAAK,CAAC;CACd,CAAC,GACF,CAAC,8BAA8B,GAAG;IAChC,IAAI,EAAE,iBAAiB,CAAC;IACxB,YAAY,CAAC,EAAE,KAAK,CAAC;IACrB,OAAO,CAAC,EAAE,KAAK,CAAC;IAChB,WAAW,CAAC,EAAE,KAAK,CAAC;CACrB,CAAC,GACF,CAAC,8BAA8B,GAAG;IAChC,YAAY,CAAC,EAAE,KAAK,CAAC;IACrB,OAAO,CAAC,EAAE,KAAK,CAAC;IAChB,WAAW,CAAC,EAAE,KAAK,CAAC;IACpB,IAAI,CAAC,EAAE,KAAK,CAAC;CACd,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ export { PublicBarekeyClient } from "./public-client.js";
2
+ export { BarekeyEnvHandle } from "./handle.js";
3
+ export { BarekeyError, BillingUnavailableError, CoerceFailedError, DeviceCodeExpiredError, DeviceCodeNotFoundError, EvaluationFailedError, FsNotAvailableError, InvalidConfigurationProvidedError, InvalidCredentialsProvidedError, InvalidDynamicOptionsError, InvalidJsonError, InvalidOrgScopeError, InvalidRefreshTokenError, InvalidRequestError, NetworkError, NoConfigurationProvidedError, NoCredentialsProvidedError, OrgScopeInvalidError, RequirementsValidationFailedError, SdkModuleNotFoundError, TemporalNotAvailableError, TypegenReadFailedError, TypegenUnsupportedSdkError, TypegenWriteFailedError, UnauthorizedError, UnknownError, UsageLimitExceededError, UserCodeInvalidError, VariableNotFoundError, createBarekeyErrorFromCode, docsUrlForErrorCode, formatBarekeyErrorMessage, isBarekeyErrorCode, normalizeErrorCode, } from "./errors.js";
4
+ export type { AB, BarekeyCoerceTarget, BarekeyDeclaredType, BarekeyDecision, BarekeyErrorCode, BarekeyEvaluatedValue, BarekeyGetOptions, BarekeyJsonConfig, BarekeyLiteralString, BarekeyResolvedKind, BarekeyRolloutFunction, BarekeyRolloutMatchedRule, BarekeyRolloutMilestone, BarekeyStandardSchemaV1, BarekeyTemporalInstant, BarekeyTemporalInstantLike, BarekeyTtlInput, BarekeyVariableDefinition, EaseInOut, Env, Linear, Secret, Step, } from "./types.js";
5
+ export type { BarekeyPublicGeneratedTypeMap, BarekeyPublicKey, BarekeyPublicKnownKey, PublicBarekeyClientOptions, } from "./public-types.js";
6
+ //# sourceMappingURL=public.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"public.d.ts","sourceRoot":"","sources":["../src/public.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EACL,YAAY,EACZ,uBAAuB,EACvB,iBAAiB,EACjB,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,EACrB,mBAAmB,EACnB,iCAAiC,EACjC,+BAA+B,EAC/B,0BAA0B,EAC1B,gBAAgB,EAChB,oBAAoB,EACpB,wBAAwB,EACxB,mBAAmB,EACnB,YAAY,EACZ,4BAA4B,EAC5B,0BAA0B,EAC1B,oBAAoB,EACpB,iCAAiC,EACjC,sBAAsB,EACtB,yBAAyB,EACzB,sBAAsB,EACtB,0BAA0B,EAC1B,uBAAuB,EACvB,iBAAiB,EACjB,YAAY,EACZ,uBAAuB,EACvB,oBAAoB,EACpB,qBAAqB,EACrB,0BAA0B,EAC1B,mBAAmB,EACnB,yBAAyB,EACzB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,aAAa,CAAC;AAErB,YAAY,EACV,EAAE,EACF,mBAAmB,EACnB,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EACjB,oBAAoB,EACpB,mBAAmB,EACnB,sBAAsB,EACtB,yBAAyB,EACzB,uBAAuB,EACvB,uBAAuB,EACvB,sBAAsB,EACtB,0BAA0B,EAC1B,eAAe,EACf,yBAAyB,EACzB,SAAS,EACT,GAAG,EACH,MAAM,EACN,MAAM,EACN,IAAI,GACL,MAAM,YAAY,CAAC;AAEpB,YAAY,EACV,6BAA6B,EAC7B,gBAAgB,EAChB,qBAAqB,EACrB,0BAA0B,GAC3B,MAAM,mBAAmB,CAAC"}
package/dist/public.js ADDED
@@ -0,0 +1,3 @@
1
+ export { PublicBarekeyClient } from "./public-client.js";
2
+ export { BarekeyEnvHandle } from "./handle.js";
3
+ export { BarekeyError, BillingUnavailableError, CoerceFailedError, DeviceCodeExpiredError, DeviceCodeNotFoundError, EvaluationFailedError, FsNotAvailableError, InvalidConfigurationProvidedError, InvalidCredentialsProvidedError, InvalidDynamicOptionsError, InvalidJsonError, InvalidOrgScopeError, InvalidRefreshTokenError, InvalidRequestError, NetworkError, NoConfigurationProvidedError, NoCredentialsProvidedError, OrgScopeInvalidError, RequirementsValidationFailedError, SdkModuleNotFoundError, TemporalNotAvailableError, TypegenReadFailedError, TypegenUnsupportedSdkError, TypegenWriteFailedError, UnauthorizedError, UnknownError, UsageLimitExceededError, UserCodeInvalidError, VariableNotFoundError, createBarekeyErrorFromCode, docsUrlForErrorCode, formatBarekeyErrorMessage, isBarekeyErrorCode, normalizeErrorCode, } from "./errors.js";