@http-forge/core 1.0.5 → 1.0.7

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.
@@ -42,6 +42,17 @@ export declare class FolderCollectionStore implements ICollectionStore {
42
42
  * one item does not re-scan the whole collection folder for every lookup.
43
43
  */
44
44
  private itemPathIndex;
45
+ /**
46
+ * Whether the startup freshness check has already been performed this session.
47
+ * After the first load, we trust the cache (file watcher handles external changes).
48
+ */
49
+ private startupFreshnessChecked;
50
+ /**
51
+ * Directory for serialized collection metadata caches. Lives inside the
52
+ * collections directory as `.cache/` so it is self-contained and already
53
+ * covered by the existing `.gitignore` (`.cache/`).
54
+ */
55
+ private cacheDir;
45
56
  /**
46
57
  * When true, `loadRequestFromDir` delegates to the light loader
47
58
  * (metadata only). Set only inside `loadAllLight()`; never left on.
@@ -93,6 +104,38 @@ export declare class FolderCollectionStore implements ICollectionStore {
93
104
  * Load a collection from a folder
94
105
  */
95
106
  private loadCollectionFromFolder;
107
+ /**
108
+ * Get the cache directory, creating it if needed.
109
+ */
110
+ private getCacheDir;
111
+ /**
112
+ * Get the cache file path for a collection.
113
+ */
114
+ private getCachePath;
115
+ /**
116
+ * Try to load a collection from cache. Returns undefined on miss/stale/corrupt.
117
+ * Uses collection.json's mtime as the freshness key.
118
+ */
119
+ private loadCollectionFromCache;
120
+ /**
121
+ * Collect item id → slug mappings from the in-memory tree.
122
+ */
123
+ private collectItemSlugs;
124
+ /**
125
+ * Write the collection cache asynchronously (fire-and-forget).
126
+ * Uses collection.json's mtime as the freshness key.
127
+ */
128
+ private saveCollectionToCache;
129
+ /**
130
+ * Compute the maximum mtime of all files in a collection directory tree.
131
+ * Used as a freshness key for the cache: if any file was modified externally,
132
+ * the max mtime will be newer than the cached value.
133
+ */
134
+ private computeMaxMtime;
135
+ /**
136
+ * Invalidate (delete) the cache for a collection.
137
+ */
138
+ private invalidateCollectionCache;
96
139
  /**
97
140
  * Load items from a directory
98
141
  */
@@ -17,6 +17,7 @@
17
17
  import { IHttpClient } from '../../types/platform';
18
18
  import { HttpRequest, HttpResponse, RequestSettings } from '../../types/types';
19
19
  import { ProxyConfig } from '../config/config.interface';
20
+ import type { SecretResolverRegistry } from '../secrets/secret-resolver-registry';
20
21
  /**
21
22
  * Default request settings
22
23
  * Same as plugin's DEFAULT_REQUEST_SETTINGS from shared/constants.ts
@@ -36,6 +37,11 @@ export type RequestSettingsSource = Partial<RequestSettings> | (() => Partial<Re
36
37
  * May be a static config object or a provider function for live config reloads.
37
38
  */
38
39
  export type ProxySource = ProxyConfig | null | undefined | (() => ProxyConfig | null | undefined);
40
+ /**
41
+ * Source of the secret resolver registry for {@link NodeHttpClient}.
42
+ * May be a provider function for live config reloads.
43
+ */
44
+ export type SecretRegistrySource = SecretResolverRegistry | null | undefined | (() => SecretResolverRegistry | null | undefined);
39
45
  /**
40
46
  * Native HTTP client using Node.js http/https modules
41
47
  *
@@ -44,9 +50,10 @@ export type ProxySource = ProxyConfig | null | undefined | (() => ProxyConfig |
44
50
  export declare class NodeHttpClient implements IHttpClient {
45
51
  private readonly resolveDefaults;
46
52
  private readonly resolveProxy;
53
+ private readonly resolveSecretRegistry;
47
54
  private version;
48
55
  private readonly basePath;
49
- constructor(defaultSettings?: RequestSettingsSource, basePath?: string, proxySource?: ProxySource);
56
+ constructor(defaultSettings?: RequestSettingsSource, basePath?: string, proxySource?: ProxySource, secretRegistrySource?: SecretRegistrySource);
50
57
  /** Current default settings, resolved fresh from the configured source. */
51
58
  private get settings();
52
59
  /**
@@ -10,13 +10,14 @@
10
10
  * e.g. {{secret:aws/myapp/prod/db-password}}
11
11
  * {{secret:aws/myapp/prod/api-key#field}} (JSON secret field)
12
12
  */
13
- import type { AwsSecretsConfig, ISecretResolver } from '../../types/secret-resolver';
14
- export declare class AwsSecretResolver implements ISecretResolver {
13
+ import type { AwsSecretsConfig } from '../../types/secret-resolver';
14
+ import { BaseSecretResolver } from './base-secret-resolver';
15
+ export declare class AwsSecretResolver extends BaseSecretResolver {
15
16
  readonly providerName = "aws";
16
17
  private readonly region;
17
18
  private readonly profile;
18
19
  private readonly moduleRequire;
19
20
  private sdk?;
20
21
  constructor(config: AwsSecretsConfig, moduleRequire?: (name: string) => any);
21
- resolve(path: string): Promise<string | undefined>;
22
+ protected fetchRaw(secretId: string): Promise<string | undefined>;
22
23
  }
@@ -10,12 +10,13 @@
10
10
  *
11
11
  * Config requires vaultUrl, e.g. "https://myvault.vault.azure.net"
12
12
  */
13
- import type { AzureKeyVaultConfig, ISecretResolver } from '../../types/secret-resolver';
14
- export declare class AzureKeyVaultResolver implements ISecretResolver {
13
+ import type { AzureKeyVaultConfig } from '../../types/secret-resolver';
14
+ import { BaseSecretResolver } from './base-secret-resolver';
15
+ export declare class AzureKeyVaultResolver extends BaseSecretResolver {
15
16
  readonly providerName = "azure";
16
17
  private readonly vaultUrl;
17
18
  private readonly moduleRequire;
18
19
  private client?;
19
20
  constructor(config: AzureKeyVaultConfig, moduleRequire?: (name: string) => any);
20
- resolve(path: string): Promise<string | undefined>;
21
+ protected fetchRaw(secretName: string, _jsonPath?: string): Promise<string | undefined>;
21
22
  }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Base Secret Resolver — universal caching + JSON path resolution.
3
+ *
4
+ * Specific providers (AWS, Azure, GCP, Vault, ...) extend this class and
5
+ * implement only `fetchRaw(secretName)`, which retrieves the raw secret string
6
+ * from the backing store. All shared logic lives here:
7
+ *
8
+ * - TTL-based caching of raw secret strings (cross-request, per instance)
9
+ * - Universal JSON path resolution with dot-notation and array indices:
10
+ * {{secret:alias/secret-name}} → raw string
11
+ * {{secret:alias/secret-name.field}} → JSON field (nested)
12
+ * {{secret:alias/secret-name.items[0].id}} → array index traversal
13
+ * {{secret:alias/secret-name#field}} → legacy #field (still supported)
14
+ * - Conversion of resolved values to strings
15
+ *
16
+ * Providers never parse JSON or manage cache themselves.
17
+ */
18
+ export interface SecretCacheEntry {
19
+ value: string;
20
+ expiresAt: number;
21
+ }
22
+ export declare abstract class BaseSecretResolver {
23
+ readonly abstract providerName: string;
24
+ /** Default TTL: 5 minutes. Override via constructor option. */
25
+ protected readonly ttlMs: number;
26
+ private readonly cache;
27
+ constructor(options?: {
28
+ cacheTtlMs?: number;
29
+ });
30
+ /**
31
+ * Public entry point. Handles caching, path splitting, JSON parsing and
32
+ * traversal. Providers implement `fetchRaw` only.
33
+ */
34
+ resolve(secretPath: string): Promise<string | undefined>;
35
+ /**
36
+ * Provider-specific raw string retrieval. Implement in subclasses.
37
+ * Must return the raw secret payload as a string (possibly JSON).
38
+ */
39
+ protected abstract fetchRaw(secretName: string, jsonPath?: string): Promise<string | undefined>;
40
+ /**
41
+ * Clear the cache (e.g. on config reload or manual refresh).
42
+ */
43
+ clearCache(): void;
44
+ }
45
+ /**
46
+ * Traverse a parsed JSON value using a dot-notation path with array indices.
47
+ * Supports: "a.b", "a[0]", "a.b[0].c", "items[2][1]".
48
+ */
49
+ export declare function traverseJsonPath(obj: any, path: string): any;
@@ -14,13 +14,14 @@
14
14
  * Prerequisites: none (uses Node.js built-in https)
15
15
  */
16
16
  import type { ClientRequest, IncomingMessage, RequestOptions } from 'http';
17
- import type { DopplerConfig, ISecretResolver } from '../../types/secret-resolver';
17
+ import type { DopplerConfig } from '../../types/secret-resolver';
18
+ import { BaseSecretResolver } from './base-secret-resolver';
18
19
  type DopplerRequestFn = (url: string, options: RequestOptions, callback: (res: IncomingMessage) => void) => ClientRequest;
19
- export declare class DopplerResolver implements ISecretResolver {
20
+ export declare class DopplerResolver extends BaseSecretResolver {
20
21
  readonly providerName = "doppler";
21
22
  private readonly token;
22
23
  private readonly requestFn;
23
24
  constructor(config: DopplerConfig, requestFn?: DopplerRequestFn);
24
- resolve(path: string): Promise<string | undefined>;
25
+ protected fetchRaw(secretName: string, _jsonPath?: string): Promise<string | undefined>;
25
26
  }
26
27
  export {};
@@ -11,12 +11,13 @@
11
11
  * Config: { "provider": "gcp", "projectId": "my-project" }
12
12
  * projectId falls back to GOOGLE_CLOUD_PROJECT / GCLOUD_PROJECT env vars.
13
13
  */
14
- import type { GcpSecretsConfig, ISecretResolver } from '../../types/secret-resolver';
15
- export declare class GcpSecretResolver implements ISecretResolver {
14
+ import type { GcpSecretsConfig } from '../../types/secret-resolver';
15
+ import { BaseSecretResolver } from './base-secret-resolver';
16
+ export declare class GcpSecretResolver extends BaseSecretResolver {
16
17
  readonly providerName = "gcp";
17
18
  private readonly projectId;
18
19
  private readonly moduleRequire;
19
20
  private client?;
20
21
  constructor(config: GcpSecretsConfig, moduleRequire?: (name: string) => any);
21
- resolve(path: string): Promise<string | undefined>;
22
+ protected fetchRaw(secretName: string, _jsonPath?: string): Promise<string | undefined>;
22
23
  }
@@ -14,12 +14,13 @@
14
14
  * The path format after the provider prefix: <mount>/<path>#<field>
15
15
  * If no field is specified and the secret has a single key "value", that is returned.
16
16
  */
17
- import type { HashiCorpVaultConfig, ISecretResolver } from '../../types/secret-resolver';
18
- export declare class HashiCorpVaultResolver implements ISecretResolver {
17
+ import type { HashiCorpVaultConfig } from '../../types/secret-resolver';
18
+ import { BaseSecretResolver } from './base-secret-resolver';
19
+ export declare class HashiCorpVaultResolver extends BaseSecretResolver {
19
20
  readonly providerName = "vault";
20
21
  private readonly address;
21
22
  private readonly mountPath;
22
23
  private readonly namespace;
23
24
  constructor(config: HashiCorpVaultConfig);
24
- resolve(path: string): Promise<string | undefined>;
25
+ protected fetchRaw(secretPath: string, jsonPath?: string): Promise<string | undefined>;
25
26
  }
@@ -19,12 +19,13 @@
19
19
  * configured; otherwise this falls back to the 1Password CLI (`op`). If the SDK
20
20
  * package is missing, the CLI is also used with the configured account.
21
21
  */
22
- import type { ISecretResolver, OnePasswordConfig } from '../../types/secret-resolver';
22
+ import type { OnePasswordConfig } from '../../types/secret-resolver';
23
+ import { BaseSecretResolver } from './base-secret-resolver';
23
24
  type ExecFileLike = (file: string, args: string[], options: Record<string, unknown>) => Promise<{
24
25
  stdout: string;
25
26
  stderr?: string;
26
27
  }>;
27
- export declare class OnePasswordResolver implements ISecretResolver {
28
+ export declare class OnePasswordResolver extends BaseSecretResolver {
28
29
  readonly providerName = "1password";
29
30
  private readonly defaultVault;
30
31
  private readonly account;
@@ -33,7 +34,7 @@ export declare class OnePasswordResolver implements ISecretResolver {
33
34
  private sdkClientPromise?;
34
35
  private sdkAuthKey?;
35
36
  constructor(config: OnePasswordConfig, moduleRequire?: (name: string) => any, execFileFn?: ExecFileLike);
36
- resolve(path: string): Promise<string | undefined>;
37
+ protected fetchRaw(secretName: string, _jsonPath?: string): Promise<string | undefined>;
37
38
  private tryResolveSdk;
38
39
  private getSdkClient;
39
40
  private resolveViaCli;
@@ -36,6 +36,11 @@ export declare class SecretResolverRegistry {
36
36
  * suitable for injection as extraVariables into VariableResolver.
37
37
  */
38
38
  resolveSecretTokens(input: any, cache?: Map<string, string>): Promise<Record<string, string>>;
39
+ /**
40
+ * Clear all cached secret values across all providers.
41
+ * Called at the start of each run so stale secrets aren't reused.
42
+ */
43
+ clearCache(): void;
39
44
  /** Whether any providers are configured */
40
45
  get hasProviders(): boolean;
41
46
  /**
@@ -16,7 +16,9 @@
16
16
  "xml2js": "^0.6.2",
17
17
  "tv4": "^1.3.0",
18
18
  "ajv": "^8.17.1",
19
- "cheerio": "^1.1.2"
19
+ "cheerio": "^1.1.2",
20
+ "@aws-sdk/client-secrets-manager": "^3.1021.0",
21
+ "@google-cloud/secret-manager": "^7.2.0"
20
22
  },
21
23
  "devDependencies": {
22
24
  "@types/node": "^20.0.0",
@@ -22,6 +22,7 @@ export interface ISecretResolver {
22
22
  /**
23
23
  * Resolve a secret by its provider-relative path.
24
24
  * @param path The path after the provider prefix, e.g. "myapp/prod/apiKey"
25
+ * or "myapp/prod/apiKey.nested.key" for JSON path traversal.
25
26
  * @returns The plaintext secret value, or undefined if not found
26
27
  */
27
28
  resolve(path: string): Promise<string | undefined>;
@@ -29,6 +30,10 @@ export interface ISecretResolver {
29
30
  * Human-readable provider name, e.g. "aws", "azure", "vault", "1password"
30
31
  */
31
32
  readonly providerName: string;
33
+ /**
34
+ * Clear the in-memory cache for this resolver (optional).
35
+ */
36
+ clearCache?(): void;
32
37
  }
33
38
  export interface AwsSecretsConfig {
34
39
  provider: 'aws';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@http-forge/core",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "Headless Postman-compatible API testing engine for Node.js, CI/CD, OpenAPI workflows, and HTTP Forge automation",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",