hanzio 1.1.0 → 1.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 (55) hide show
  1. package/README.md +70 -4
  2. package/dist/api-wrapper/builders.d.ts +13 -2
  3. package/dist/api-wrapper/errors.d.ts +1 -0
  4. package/dist/api-wrapper/headers.d.ts +2 -1
  5. package/dist/api-wrapper/transport.d.ts +8 -5
  6. package/dist/api-wrapper/types.d.ts +1 -0
  7. package/dist/cache/index.d.ts +26 -0
  8. package/dist/secrets/core.d.ts +47 -0
  9. package/dist/secrets/deadline.d.ts +6 -0
  10. package/dist/secrets/environment.d.ts +9 -0
  11. package/dist/secrets/errors.d.ts +11 -0
  12. package/dist/secrets/index.d.ts +13 -25
  13. package/dist/secrets/infisical-cli.d.ts +6 -0
  14. package/dist/secrets/infisical-config.d.ts +17 -0
  15. package/dist/secrets/infisical-session.d.ts +4 -0
  16. package/dist/secrets/infisical.d.ts +8 -13
  17. package/dist/secrets/loaders.d.ts +5 -12
  18. package/dist/secrets/vite.d.ts +7 -3
  19. package/dist/secrets/worker-loader.d.ts +9 -0
  20. package/dist/secrets/worker.d.ts +3 -0
  21. package/dist/src/api-wrapper/index.js +152 -122
  22. package/dist/src/index.js +3173 -2713
  23. package/dist/src/jwt/index.js +2 -2
  24. package/dist/src/p-queue/index.js +3 -3
  25. package/dist/src/secrets/index.js +670 -402
  26. package/dist/src/secrets/infisical.js +451 -168
  27. package/dist/src/secrets/loaders.js +467 -174
  28. package/dist/src/secrets/vite.js +33 -11
  29. package/dist/src/secrets/worker.js +275 -0
  30. package/dist/src/sitemap/index.js +1 -1
  31. package/dist/src/zod/index.js +7 -7
  32. package/dist/typedswitch/index.d.ts +9 -5
  33. package/package.json +12 -3
  34. package/src/api-wrapper/builders.ts +68 -43
  35. package/src/api-wrapper/create-client.ts +82 -62
  36. package/src/api-wrapper/errors.ts +10 -0
  37. package/src/api-wrapper/headers.ts +14 -1
  38. package/src/api-wrapper/redaction.ts +1 -0
  39. package/src/api-wrapper/transport.ts +34 -38
  40. package/src/api-wrapper/types.ts +1 -0
  41. package/src/cache/index.ts +228 -61
  42. package/src/secrets/core.ts +348 -0
  43. package/src/secrets/deadline.ts +69 -0
  44. package/src/secrets/environment.ts +69 -0
  45. package/src/secrets/errors.ts +29 -0
  46. package/src/secrets/index.ts +79 -210
  47. package/src/secrets/infisical-cli.ts +99 -0
  48. package/src/secrets/infisical-config.ts +70 -0
  49. package/src/secrets/infisical-session.ts +42 -0
  50. package/src/secrets/infisical.ts +214 -66
  51. package/src/secrets/loaders.ts +24 -48
  52. package/src/secrets/vite.ts +44 -15
  53. package/src/secrets/worker-loader.ts +56 -0
  54. package/src/secrets/worker.ts +4 -0
  55. package/src/typedswitch/index.ts +80 -69
package/README.md CHANGED
@@ -218,26 +218,51 @@ await promiseTimeout(250)
218
218
  `defineSecretSet` loads a typed set of required secrets from `process.env` or
219
219
  Infisical before the rest of the program starts.
220
220
 
221
+ When both `INFISICAL_CLIENT_ID` and `INFISICAL_CLIENT_SECRET` are set, it uses
222
+ Infisical's HTTP API. If either is missing, it uses your signed-in Infisical CLI
223
+ session. For local development, install the CLI and run
224
+ `infisical login --domain=https://eu.infisical.com` (or your configured
225
+ `siteUrl`). See the [secrets documentation](src/secrets/README.md) for details.
226
+
221
227
  ```ts
222
228
  import { defineSecretSet } from 'hanzio/secrets'
223
229
 
224
230
  export const backendSecrets = await defineSecretSet(
225
231
  ['DATABASE_URL', 'APP_SECRET'] as const,
226
- { projectId: 'infisical-project-id' }
232
+ {
233
+ organizationId: 'infisical-organization-id',
234
+ projectId: 'infisical-project-id'
235
+ }
227
236
  )
228
237
 
229
238
  const databaseUrl = backendSecrets.secret('DATABASE_URL')
230
239
  ```
231
240
 
241
+ The required `organizationId` scopes the CLI session per secret set, allowing projects
242
+ in different organizations to run together without switching the active CLI
243
+ organization. This flow reads the CLI user token and fetches secrets over HTTP;
244
+ tokens remain in memory. Use `writeToProcessEnv: false` for multiple sets in one
245
+ process. Both `organizationId` and `projectId` are required for Infisical loading.
246
+
232
247
  For Vite config, `viteSecretSetPlugin(secretSet)` exposes the loaded values as
233
248
  `import.meta.env.*` replacements. Use `getViteDefine(secretSet)` if you need the
234
- raw `define` object. Import Vite helpers from `hanzio/secrets/vite` so browser
235
- bundles do not pull in the Infisical SDK.
249
+ raw `define` object. Vite helpers accept only `VITE_` keys by default; use an
250
+ explicit `publicKeys` list to select public values from a mixed set. Import
251
+ these helpers from `hanzio/secrets/vite`.
252
+
253
+ The helper supports `auth: 'auto' | 'http' | 'cli'`, `secretPath`, deadlines,
254
+ cancellation, optional schema validation, per-key source metadata, and
255
+ `writeToProcessEnv: false` for isolated sets. Use `hanzio/secrets/worker` for
256
+ Cloudflare bindings without Node compatibility. See the
257
+ [migration notes](src/secrets/README.md#migration-notes) for stricter environment
258
+ validation and browser exposure rules.
236
259
 
237
260
  ### Cache
238
261
 
239
262
  `cacheFunction` wraps sync or async functions with TTL caching and request
240
- deduplication.
263
+ deduplication. With `refreshInBackground: true`, stale entries are served
264
+ immediately while a background refresh updates the cache
265
+ (stale-while-revalidate).
241
266
 
242
267
  ```ts
243
268
  import { cacheFunction } from 'hanzio'
@@ -252,6 +277,47 @@ const user = await getUser('user_1')
252
277
  getUser.clearCache()
253
278
  ```
254
279
 
280
+ #### External stores (e.g. Redis)
281
+
282
+ By default entries live in an in-memory `Map`. Pass a `store` to keep entries
283
+ in an external cache instead. A store implements `get`, `set`, and `delete`
284
+ (plus an optional `clear`, used by `clearCache`); hanzio never imports the
285
+ underlying client, so any backend works. Serialization is the adapter's
286
+ responsibility, and the `ttlMs` passed to `set` maps to the store's native
287
+ expiry. External stores are only supported for async functions.
288
+
289
+ ```ts
290
+ import { cacheFunction, type CacheStore, type CacheStoreEntry } from 'hanzio'
291
+ import Redis from 'ioredis'
292
+
293
+ const redis = new Redis()
294
+
295
+ const redisStore: CacheStore = {
296
+ get: async (key) => {
297
+ const raw = await redis.get(key)
298
+ return raw ? (JSON.parse(raw) as CacheStoreEntry) : undefined
299
+ },
300
+ set: async (key, entry, ttlMs) => {
301
+ await redis.set(key, JSON.stringify(entry), 'PX', ttlMs)
302
+ },
303
+ delete: async (key) => {
304
+ await redis.del(key)
305
+ }
306
+ }
307
+
308
+ const getUser = cacheFunction({
309
+ name: 'getUser',
310
+ fn: async (id: string) => ({ id, name: 'Ada' }),
311
+ cacheTimeMs: 60_000,
312
+ store: redisStore,
313
+ onStoreError: (error) => console.error('cache store failed', error)
314
+ })
315
+ ```
316
+
317
+ Store failures never break the cached function: on a failed `get` or `set`
318
+ the wrapped function falls back to calling `fn` directly, and the optional
319
+ `onStoreError` callback is invoked.
320
+
255
321
  ### State Machine
256
322
 
257
323
  `SimpleStateMachine` models typed states, actions, validation, and action
@@ -1,11 +1,22 @@
1
1
  import { type ConfigError } from './errors';
2
2
  import type { ApiErrorContext, BaseApiUrl, PathParams, QueryParams } from './shared';
3
3
  import type { ApiEndpoint } from './types';
4
- export declare function buildUrl(endpoint: ApiEndpoint, params: PathParams | undefined, reqQuery: QueryParams | undefined, baseApiUrls: Record<string, BaseApiUrl>, defaultBaseApiUrl: string | undefined, url: string | undefined, configError: (msg: string) => ConfigError): {
4
+ export type BuildUrlOptions = {
5
+ endpoint: ApiEndpoint;
6
+ params: PathParams | undefined;
7
+ queryParams: Record<string, string>;
8
+ baseApiUrls: Record<string, BaseApiUrl>;
9
+ defaultBaseApiUrl: string | undefined;
10
+ url: string | undefined;
11
+ doNotEncodeQueryParams?: boolean;
12
+ configError: (msg: string) => ConfigError;
13
+ };
14
+ export declare function formatQueryString(queryParams: Record<string, string>, doNotEncode?: boolean): string;
15
+ export declare function buildUrl(options: BuildUrlOptions): {
5
16
  finalUrl: string;
6
17
  fullUrl: string;
7
18
  };
8
- export declare function buildQueryParamsRaw(endpoint: ApiEndpoint, query: QueryParams | undefined): Record<string, string>;
19
+ export declare function buildPathParams(endpoint: ApiEndpoint, params: PathParams | undefined, ctx: (over?: Partial<ApiErrorContext>) => ApiErrorContext): PathParams | undefined;
9
20
  export declare function buildQueryParams(endpoint: ApiEndpoint, query: QueryParams | undefined, ctx: (over?: Partial<ApiErrorContext>) => ApiErrorContext): Record<string, string>;
10
21
  export declare function buildRequestBody(endpoint: ApiEndpoint, body: unknown, ctx: (over?: Partial<ApiErrorContext>) => ApiErrorContext): unknown;
11
22
  export declare function buildHeaders(endpoint: ApiEndpoint, headers: Record<string, string> | undefined, defaultHeaders: Record<string, string>, ctx: (over?: Partial<ApiErrorContext>) => ApiErrorContext): Record<string, string>;
@@ -61,3 +61,4 @@ export declare const isNetworkError: (e: unknown) => e is NetworkError;
61
61
  export declare const isRequestAbortedError: (e: unknown) => e is RequestAbortedError;
62
62
  export declare const isConfigError: (e: unknown) => e is ConfigError;
63
63
  export declare const isActionError: (e: unknown) => e is ActionError;
64
+ export declare function isNonRetryableApiError(error: unknown): boolean;
@@ -1,3 +1,4 @@
1
+ import type { ConfigError } from './errors';
1
2
  /**
2
3
  * Normalize headers to canonical case so lookups are deterministic. Later
3
4
  * occurrences of the same header (case-insensitive) win.
@@ -5,5 +6,5 @@
5
6
  export declare function normalizeHeaders(headers: Record<string, string>): Record<string, string>;
6
7
  export declare function getHeader(headers: Record<string, string>, name: string): string | undefined;
7
8
  export declare function hasJsonContentType(headers: Record<string, string>): boolean;
8
- export declare function buildFetchBody(body: unknown, headers: Record<string, string>): RequestInit['body'];
9
+ export declare function buildFetchBody(body: unknown, headers: Record<string, string>, configError?: (msg: string) => ConfigError): RequestInit['body'];
9
10
  export declare function getHeadersAsObject(headers: Headers): Record<string, string>;
@@ -3,11 +3,9 @@ import type { ApiEndpoint, OnResponseContext, OnRetryContext, RetryContext } fro
3
3
  import type { ApiErrorContext, HttpMethod } from './shared';
4
4
  export type RequestConfig = {
5
5
  method: HttpMethod;
6
- url: string;
7
- queryParams: Record<string, string>;
6
+ fullUrl: string;
8
7
  body: unknown;
9
8
  headers: Record<string, string>;
10
- doNotEncodeQueryParams?: boolean;
11
9
  timeoutMs?: number;
12
10
  fetchFn: typeof fetch;
13
11
  userSignal?: AbortSignal;
@@ -24,6 +22,7 @@ export declare function getRetryDelay(params: {
24
22
  retryDelay: number | ((attempt: number) => number);
25
23
  attempt: number;
26
24
  response?: Response;
25
+ maxRetryDelayMs?: number;
27
26
  }): number;
28
27
  export declare function shouldAttemptRetryOnError(error: unknown): boolean;
29
28
  export declare function shouldAttemptRetryOnHttp(retryCtx: RetryContext): boolean;
@@ -31,7 +30,8 @@ type MakeRequestArgs<TValidated> = {
31
30
  config: RequestConfig;
32
31
  maxRetries: number;
33
32
  retryDelay: number | ((attempt: number) => number);
34
- validateFn: (response: Response) => Promise<TValidated>;
33
+ maxRetryDelayMs?: number;
34
+ validateFn: (response: Response, attempt: number) => Promise<TValidated>;
35
35
  shouldRetry: (context: RetryContext) => boolean;
36
36
  logger?: Pick<Console, 'debug'>;
37
37
  ctx: (over?: Partial<ApiErrorContext>) => ApiErrorContext;
@@ -47,6 +47,9 @@ export declare function makeRequestWithRetry<TValidated>(args: MakeRequestArgs<T
47
47
  retryCount: number;
48
48
  httpStatus: number;
49
49
  }>;
50
- export declare function validateAndTransformResponse<T extends z.ZodType>(endpoint: ApiEndpoint<z.ZodType | undefined, z.ZodType | undefined, z.ZodType | undefined, z.ZodType | undefined, T>, response: Response, ctx: (over?: Partial<ApiErrorContext>) => ApiErrorContext): Promise<z.infer<T>>;
50
+ export declare function validateAndTransformResponse<T extends z.ZodType>(endpoint: ApiEndpoint<z.ZodType | undefined, z.ZodType | undefined, z.ZodType | undefined, z.ZodType | undefined, T>, response: Response, ctx: (over?: Partial<ApiErrorContext>) => ApiErrorContext): Promise<{
51
+ data: z.infer<T>;
52
+ responseSizeBytes: number;
53
+ }>;
51
54
  export declare function defaultShouldRetry(ctx: RetryContext): boolean;
52
55
  export {};
@@ -136,6 +136,7 @@ export interface ApiClientConfig<T extends Record<string, ApiEndpoint>, A extend
136
136
  timeoutMs?: number;
137
137
  retries?: number;
138
138
  retryDelayMs?: number | ((attempt: number) => number);
139
+ maxRetryDelayMs?: number;
139
140
  shouldRetry?: (context: RetryContext) => boolean;
140
141
  logger?: Pick<Console, 'debug' | 'error'>;
141
142
  fetch?: typeof fetch;
@@ -3,6 +3,23 @@ type CachedFunction<T extends AnyFunction> = {
3
3
  (...args: Parameters<T>): ReturnType<T>;
4
4
  clearCache: () => void;
5
5
  };
6
+ export type CacheStoreEntry = {
7
+ value: unknown;
8
+ timestamp: number;
9
+ };
10
+ /**
11
+ * Contract for external cache stores (e.g. a Redis adapter).
12
+ * Serialization is the adapter's responsibility; this library never imports
13
+ * the underlying client.
14
+ */
15
+ export type CacheStore = {
16
+ get: (key: string) => Promise<CacheStoreEntry | undefined>;
17
+ /** `ttlMs` maps to the store's native expiry (e.g. Redis `PX`). */
18
+ set: (key: string, entry: CacheStoreEntry, ttlMs: number) => Promise<void>;
19
+ delete: (key: string) => Promise<void>;
20
+ /** Optional; called by clearCache when defined. */
21
+ clear?: () => Promise<void>;
22
+ };
6
23
  export type CacheFunctionOptions<T extends AnyFunction> = {
7
24
  name: string;
8
25
  fn: T;
@@ -14,6 +31,15 @@ export type CacheFunctionOptions<T extends AnyFunction> = {
14
31
  onBackgroundRefreshError?: (error: unknown, context: {
15
32
  name: string;
16
33
  }) => void;
34
+ /**
35
+ * External cache store (e.g. a Redis adapter). Only supported for async
36
+ * functions; when omitted the built-in in-memory cache is used.
37
+ */
38
+ store?: ReturnType<T> extends Promise<unknown> ? CacheStore : never;
39
+ /** Called when a store get/set/delete/clear fails (default: silent). */
40
+ onStoreError?: (error: unknown, context: {
41
+ name: string;
42
+ }) => void;
17
43
  };
18
44
  export declare function cacheFunction<T extends AnyFunction>(options: CacheFunctionOptions<T>): CachedFunction<T>;
19
45
  export {};
@@ -0,0 +1,47 @@
1
+ import { type SecretRequestOptions } from './deadline';
2
+ import { type EnvironmentVariables, type SecretEnvironmentOption } from './environment';
3
+ export type { SecretEnvironment, SecretEnvironmentOption } from './environment';
4
+ export { SecretLoadError } from './errors';
5
+ export type SecretLogAttributes = {
6
+ readonly environment: string;
7
+ readonly count: number;
8
+ readonly durationMs: number;
9
+ readonly source?: string;
10
+ readonly sources?: Readonly<Record<string, number>>;
11
+ readonly code?: string;
12
+ };
13
+ export type SecretLogger = {
14
+ info: (message: string, attributes: SecretLogAttributes) => void;
15
+ error: (message: string, attributes: SecretLogAttributes) => void;
16
+ };
17
+ export type SecretSchema<K extends string, Parsed> = {
18
+ parseAsync: (values: Record<K, string>) => Promise<Parsed>;
19
+ };
20
+ export type CommonSecretSetOptions<K extends string, Parsed = Record<K, string>> = SecretRequestOptions & {
21
+ readonly environment?: SecretEnvironmentOption;
22
+ readonly writeToProcessEnv?: boolean;
23
+ readonly logger?: SecretLogger | false;
24
+ readonly schema?: SecretSchema<K, Parsed>;
25
+ };
26
+ export type CustomLoaderDefineSecretSetOptions<K extends string, Parsed = Record<K, string>> = CommonSecretSetOptions<K, Parsed> & {
27
+ readonly loader: SecretSetLoader<K>;
28
+ };
29
+ export type SecretSetLoaderContext<K extends string> = {
30
+ readonly keys: readonly K[];
31
+ readonly environment: string;
32
+ readonly signal?: AbortSignal;
33
+ readonly timeoutMs?: number;
34
+ /** Report the source actually selected by a dynamic loader. */
35
+ readonly reportSource?: (source: string) => void;
36
+ };
37
+ export type SecretSetLoader<K extends string> = ((context: SecretSetLoaderContext<K>) => Promise<Partial<Record<K, string>>>) & {
38
+ readonly source?: string;
39
+ };
40
+ export type SecretSet<K extends string, Parsed = Record<K, string>> = {
41
+ secret: (key: K) => string;
42
+ secrets: () => Record<K, string>;
43
+ parsed: () => Parsed;
44
+ sources: () => Record<K, string>;
45
+ reload: (options?: SecretRequestOptions) => Promise<SecretSet<K, Parsed>>;
46
+ };
47
+ export declare function defineSecretSet<const Keys extends readonly string[], Parsed = Record<Keys[number], string>>(keys: Keys, options: CustomLoaderDefineSecretSetOptions<Keys[number], Parsed>, environmentVariables?: EnvironmentVariables): Promise<SecretSet<Keys[number], Parsed>>;
@@ -0,0 +1,6 @@
1
+ export type SecretRequestOptions = {
2
+ readonly timeoutMs?: number;
3
+ readonly signal?: AbortSignal;
4
+ };
5
+ /** One deadline includes authentication, retries, body reads, and validation. */
6
+ export declare function withSecretDeadline<T>(options: SecretRequestOptions, operation: (signal: AbortSignal) => Promise<T>): Promise<T>;
@@ -0,0 +1,9 @@
1
+ export type SecretEnvironment = 'dev' | 'staging' | 'prod';
2
+ export type SecretEnvironmentOption = SecretEnvironment | {
3
+ readonly slug: string;
4
+ } | (() => SecretEnvironment | {
5
+ readonly slug: string;
6
+ });
7
+ export type EnvironmentVariables = Record<string, string | undefined>;
8
+ export declare function getProcessEnvironment(): EnvironmentVariables | undefined;
9
+ export declare function resolveSecretEnvironment(option?: SecretEnvironmentOption, env?: EnvironmentVariables): string;
@@ -0,0 +1,11 @@
1
+ export type SecretErrorCode = 'CONFIGURATION' | 'AUTHENTICATION' | 'HTTP' | 'CLI' | 'VALIDATION' | 'MISSING_SECRETS' | 'TIMEOUT' | 'ABORTED' | 'LOADER';
2
+ /** Contains only safe diagnostic metadata; never attach underlying errors. */
3
+ export declare class SecretLoadError extends Error {
4
+ readonly code: SecretErrorCode;
5
+ readonly operation?: string;
6
+ readonly status?: number;
7
+ constructor(code: SecretErrorCode, message: string, details?: {
8
+ operation?: string;
9
+ status?: number;
10
+ });
11
+ }
@@ -1,30 +1,18 @@
1
- export type SecretEnvironment = 'dev' | 'staging' | 'prod';
2
- export type SecretEnvironmentOption = SecretEnvironment | (() => SecretEnvironment);
3
- export type InfisicalDefineSecretSetOptions = {
4
- readonly projectId: string;
5
- readonly siteUrl?: string;
6
- readonly environment?: SecretEnvironmentOption;
1
+ import { type CommonSecretSetOptions, type CustomLoaderDefineSecretSetOptions, type SecretSet } from './core';
2
+ import { type SecretEnvironment } from './environment';
3
+ import { type InfisicalAuthMode } from './infisical';
4
+ import { type InfisicalProjectOptions } from './infisical-config';
5
+ export * from './core';
6
+ export * from './infisical';
7
+ export * from './loaders';
8
+ export * from './vite';
9
+ export type { SecretRequestOptions } from './deadline';
10
+ export type InfisicalDefineSecretSetOptions<K extends string = string, Parsed = Record<K, string>> = CommonSecretSetOptions<K, Parsed> & InfisicalProjectOptions & {
11
+ readonly auth?: InfisicalAuthMode;
7
12
  readonly clientIdEnvKey?: string;
8
13
  readonly clientSecretEnvKey?: string;
9
14
  readonly loader?: undefined;
10
15
  };
11
- export type CustomLoaderDefineSecretSetOptions<SecretKey extends string> = {
12
- readonly loader: SecretSetLoader<SecretKey>;
13
- readonly environment?: SecretEnvironmentOption;
14
- };
15
- export type DefineSecretSetOptions<SecretKey extends string> = InfisicalDefineSecretSetOptions | CustomLoaderDefineSecretSetOptions<SecretKey>;
16
- export type SecretSetLoaderContext<SecretKey extends string> = {
17
- readonly keys: readonly SecretKey[];
18
- readonly environment: SecretEnvironment;
19
- };
20
- export type SecretSetLoader<SecretKey extends string> = (context: SecretSetLoaderContext<SecretKey>) => Promise<Partial<Record<SecretKey, string>>>;
21
- export type SecretSet<SecretKey extends string> = {
22
- secret: (key: SecretKey) => string;
23
- secrets: () => Record<SecretKey, string>;
24
- reload: () => Promise<SecretSet<SecretKey>>;
25
- };
26
- export * from './infisical';
27
- export * from './loaders';
28
- export * from './vite';
16
+ export type DefineSecretSetOptions<K extends string, Parsed = Record<K, string>> = InfisicalDefineSecretSetOptions<K, Parsed> | CustomLoaderDefineSecretSetOptions<K, Parsed>;
29
17
  export declare function getSecretEnvironment(): SecretEnvironment;
30
- export declare function defineSecretSet<const SecretKeys extends readonly string[]>(keys: SecretKeys, options: DefineSecretSetOptions<SecretKeys[number]>): Promise<SecretSet<SecretKeys[number]>>;
18
+ export declare function defineSecretSet<const Keys extends readonly string[], Parsed = Record<Keys[number], string>>(keys: Keys, options: DefineSecretSetOptions<Keys[number], Parsed>): Promise<SecretSet<Keys[number], Parsed>>;
@@ -0,0 +1,6 @@
1
+ import type { SecretRequestOptions } from './deadline';
2
+ /** Read the active CLI session without a shell or credential-bearing errors. */
3
+ export declare function readInfisicalCliToken(options: SecretRequestOptions & {
4
+ siteUrl: string;
5
+ signal: AbortSignal;
6
+ }): Promise<string>;
@@ -0,0 +1,17 @@
1
+ import type { SecretRequestOptions } from './deadline';
2
+ /** Project scope shared by the public Infisical loaders. */
3
+ export type InfisicalProjectOptions = {
4
+ readonly projectId: string;
5
+ /** Scope CLI user authentication; machine identities already have an organization. */
6
+ readonly organizationId: string;
7
+ readonly siteUrl?: string;
8
+ readonly secretPath?: string;
9
+ };
10
+ export type InfisicalScope<K extends string> = InfisicalProjectOptions & SecretRequestOptions & {
11
+ readonly keys: readonly K[];
12
+ readonly environment: string;
13
+ readonly siteUrl: string;
14
+ };
15
+ export declare function validateInfisicalScope(options: InfisicalScope<string>): void;
16
+ /** Validate at configuration time, including for JavaScript callers and local-only loads. */
17
+ export declare function validateInfisicalOrganizationId(organizationId: unknown): void;
@@ -0,0 +1,4 @@
1
+ /** Read routing metadata only. JWT signature and permissions are verified by Infisical. */
2
+ export declare function parseInfisicalSessionToken(token: string): {
3
+ organizationId?: string;
4
+ };
@@ -1,19 +1,14 @@
1
- import type { SecretEnvironment } from '.';
1
+ import { type InfisicalScope } from './infisical-config';
2
2
  export declare const DEFAULT_INFISICAL_SITE_URL = "https://eu.infisical.com";
3
- export declare function fetchInfisicalSecrets<SecretKey extends string>({ keys, projectId, environment, siteUrl, clientId, clientSecret }: {
4
- readonly keys: readonly SecretKey[];
5
- readonly projectId: string;
6
- readonly environment: SecretEnvironment;
7
- readonly siteUrl: string;
3
+ export type InfisicalAuthMode = 'auto' | 'http' | 'cli';
4
+ export declare function fetchInfisicalSecrets<K extends string>(options: InfisicalScope<K> & {
8
5
  readonly clientId: string;
9
6
  readonly clientSecret: string;
10
- }): Promise<Partial<Record<SecretKey, string>>>;
11
- export type LoadInfisicalSecretsFromEnvOptions<SecretKey extends string> = {
12
- readonly keys: readonly SecretKey[];
13
- readonly projectId: string;
14
- readonly environment: SecretEnvironment;
15
- readonly siteUrl: string;
7
+ }): Promise<Partial<Record<K, string>>>;
8
+ export type LoadInfisicalSecretsFromEnvOptions<K extends string> = InfisicalScope<K> & {
16
9
  readonly clientIdEnvKey: string;
17
10
  readonly clientSecretEnvKey: string;
11
+ readonly auth?: InfisicalAuthMode;
12
+ readonly reportSource?: (source: string) => void;
18
13
  };
19
- export declare function loadInfisicalSecrets<SecretKey extends string>({ keys, projectId, environment, siteUrl, clientIdEnvKey, clientSecretEnvKey }: LoadInfisicalSecretsFromEnvOptions<SecretKey>): Promise<Partial<Record<SecretKey, string>>>;
14
+ export declare function loadInfisicalSecrets<K extends string>(options: LoadInfisicalSecretsFromEnvOptions<K>): Promise<Partial<Record<K, string>>>;
@@ -1,16 +1,9 @@
1
- import type { SecretSetLoader, SecretSetLoaderContext } from './index';
2
- /**
3
- * Reads secrets from a Cloudflare Worker `env` bindings object (or any similar
4
- * `Record`), for Workers where `process.env` is not populated. Pass the same
5
- * object you get as `env` in your fetch handler, or values you’d read from
6
- * `import { env } from "cloudflare:workers"` in your Worker bundle — this
7
- * package does not import that module.
8
- */
9
- export declare function cloudflareWorkerEnvLoader<SecretKey extends string>(workerEnv: Record<string, unknown>): SecretSetLoader<SecretKey>;
10
- export declare function infisicalLoader<SecretKey extends string>(config: {
11
- readonly projectId: string;
1
+ import { type InfisicalProjectOptions } from './infisical-config';
2
+ import type { SecretSetLoader, SecretSetLoaderContext } from './core';
3
+ export { cloudflareWorkerEnvLoader } from './worker-loader';
4
+ export declare function infisicalLoader<SecretKey extends string>(config: InfisicalProjectOptions & {
12
5
  readonly clientId: string;
13
6
  readonly clientSecret: string;
14
- readonly siteUrl?: string;
7
+ readonly timeoutMs?: number;
15
8
  }): SecretSetLoader<SecretKey>;
16
9
  export declare function processEnvLoader<SecretKey extends string>(_ctx: SecretSetLoaderContext<SecretKey>): Promise<Partial<Record<SecretKey, string>>>;
@@ -1,9 +1,13 @@
1
- import type { SecretSet } from '.';
1
+ import type { SecretSet } from './core';
2
2
  export type ViteSecretSetPlugin = {
3
3
  name: string;
4
4
  config: () => {
5
5
  define: Record<string, string>;
6
6
  };
7
7
  };
8
- export declare function getViteDefine<SecretKey extends string>(secretSet: SecretSet<SecretKey>): Record<string, string>;
9
- export declare function viteSecretSetPlugin<SecretKey extends string>(secretSet: SecretSet<SecretKey>): ViteSecretSetPlugin;
8
+ export type ViteSecretSetOptions<K extends string> = {
9
+ /** Explicit acknowledgement that these values may be shipped to browsers. */
10
+ readonly publicKeys?: readonly K[];
11
+ };
12
+ export declare function getViteDefine<K extends string>(secretSet: Pick<SecretSet<K, unknown>, 'secrets'>, options?: ViteSecretSetOptions<K>): Record<string, string>;
13
+ export declare function viteSecretSetPlugin<K extends string>(secretSet: Pick<SecretSet<K, unknown>, 'secrets'>, options?: ViteSecretSetOptions<K>): ViteSecretSetPlugin;
@@ -0,0 +1,9 @@
1
+ import type { SecretSetLoader } from './core';
2
+ /**
3
+ * Reads secrets from a Cloudflare Worker `env` bindings object (or any similar
4
+ * `Record`), for Workers where `process.env` is not populated. Pass the same
5
+ * object you get as `env` in your fetch handler, or values you’d read from
6
+ * `import { env } from "cloudflare:workers"` in your Worker bundle — this
7
+ * package does not import that module.
8
+ */
9
+ export declare function cloudflareWorkerEnvLoader<SecretKey extends string>(workerEnv: Record<string, unknown>): SecretSetLoader<SecretKey>;
@@ -0,0 +1,3 @@
1
+ export * from './core';
2
+ export { cloudflareWorkerEnvLoader } from './worker-loader';
3
+ export type { SecretRequestOptions } from './deadline';