@http-forge/core 0.4.4 → 0.4.6

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.
@@ -183,6 +183,13 @@ export declare class FolderCollectionStore implements ICollectionStore {
183
183
  */
184
184
  private sortItemsByOrder;
185
185
  private findItemPath;
186
+ /**
187
+ * Build the on-disk slug path (root → item) for the given item id by walking the
188
+ * in-memory collection tree. Each segment is resolved via idToSlugMap so it matches
189
+ * the folder names produced during save. Returns undefined if the item is not found
190
+ * or any ancestor lacks a known slug.
191
+ */
192
+ private buildSlugPath;
186
193
  private findItemById;
187
194
  private deleteItemFromTree;
188
195
  }
@@ -105,6 +105,15 @@ export declare function sortItemsByOrder<T extends {
105
105
  * Recursively search for a directory named targetSlug under basePath.
106
106
  */
107
107
  export declare function searchForItemPath(basePath: string, targetSlug: string): string | undefined;
108
+ /**
109
+ * Recursively search for the directory whose metadata id equals targetId.
110
+ *
111
+ * Ids are globally unique, whereas slugs are de-duplicated only among siblings — so two
112
+ * items with the same name in different folders share a leaf slug. Resolving by id (reading
113
+ * each candidate's metadata) guarantees that only the directory belonging to that exact id
114
+ * is matched, regardless of slug collisions.
115
+ */
116
+ export declare function searchForItemPathById(basePath: string, targetId: string): string | undefined;
108
117
  /**
109
118
  * Generate a slug from a name.
110
119
  * Handles HTTP method prefixes, version indicators (T7, 1.5), path parameters,
@@ -65,6 +65,7 @@ export declare class ConfigService implements IConfigService {
65
65
  getResultsPath(): string;
66
66
  getSuitesPath(): string;
67
67
  getModulePaths(): string[];
68
+ getScriptScope(): 'shared' | 'isolated';
68
69
  getWorkspacePath(): string;
69
70
  reload(): void;
70
71
  configExists(): boolean;
@@ -35,6 +35,15 @@ export interface RequestConfig {
35
35
  export interface ScriptsConfig {
36
36
  /** Paths to search for importable modules (relative to workspace) */
37
37
  modulePaths: string[];
38
+ /**
39
+ * Script scope mode.
40
+ * - 'shared' (default): all script levels run in one shared scope; var/function
41
+ * declarations leak across levels and across pre-request/post-response phases.
42
+ * Lowest overhead; preserves existing behavior.
43
+ * - 'isolated': each script level runs in its own scope (Postman-compatible). State
44
+ * must pass through pm.variables / pm.environment / pm.globals.
45
+ */
46
+ scope?: 'shared' | 'isolated';
38
47
  }
39
48
  /**
40
49
  * Runner configuration
@@ -201,6 +210,8 @@ export interface IConfigService {
201
210
  getSuitesPath(): string;
202
211
  /** Get resolved module paths for script imports */
203
212
  getModulePaths(): string[];
213
+ /** Get the script scope mode ('shared' default, or 'isolated' for Postman parity) */
214
+ getScriptScope(): 'shared' | 'isolated';
204
215
  /** Get the workspace root path */
205
216
  getWorkspacePath(): string;
206
217
  /** Reload configuration from disk */
@@ -113,7 +113,7 @@ export declare class EnvironmentConfigService implements IEnvironmentConfigServi
113
113
  private getEnvLocalConfigPath;
114
114
  private loadFolderConfigs;
115
115
  /**
116
- * Create a VariableResolver pre-loaded with environment + session variables.
116
+ * Create a VariableResolver pre-loaded with environment variables.
117
117
  */
118
118
  private createResolver;
119
119
  private saveFolderSharedConfig;
@@ -77,6 +77,15 @@ export declare class EnvironmentResolver implements IEnvironmentStore {
77
77
  * Set a global variable
78
78
  */
79
79
  setGlobal(key: string, value: string): void;
80
+ /**
81
+ * Remove a session global variable. File-defined globals (globalVariables)
82
+ * are defaults and cannot be deleted here — only session overrides are removed.
83
+ */
84
+ unsetGlobal(key: string): void;
85
+ /**
86
+ * Clear all session global variables. File-defined globals are left intact.
87
+ */
88
+ clearGlobals(): void;
80
89
  /**
81
90
  * Resolve environment for execution
82
91
  */
@@ -30,8 +30,8 @@
30
30
  * env.get('token'); // 'abc'
31
31
  * ```
32
32
  */
33
- import { EnvironmentResolver } from './environment-resolver';
34
33
  import type { IEnvironmentStore, IVariableInterpolator } from '../../types/environment-config';
34
+ import { EnvironmentResolver } from './environment-resolver';
35
35
  /**
36
36
  * ForgeEnv interface - the public API for environment management
37
37
  */
@@ -69,6 +69,22 @@ export interface IForgeEnv {
69
69
  * Get list of available environment names
70
70
  */
71
71
  getEnvironments(): string[];
72
+ /**
73
+ * Get all global variables (environment-agnostic variable layer)
74
+ */
75
+ getGlobals(): Record<string, string>;
76
+ /**
77
+ * Set a global variable value
78
+ */
79
+ setGlobal(key: string, value: string): void;
80
+ /**
81
+ * Remove a global variable
82
+ */
83
+ unsetGlobal(key: string): void;
84
+ /**
85
+ * Clear all (session) global variables
86
+ */
87
+ clearGlobals(): void;
72
88
  /**
73
89
  * Resolve {{variable}} placeholders in a string
74
90
  */
@@ -127,6 +143,23 @@ export declare class ForgeEnv implements IForgeEnv {
127
143
  * Get list of available environment names
128
144
  */
129
145
  getEnvironments(): string[];
146
+ /**
147
+ * Get all global variables. Globals are the lowest-priority, environment-agnostic
148
+ * variable layer — treated like environment variables with no environment scope.
149
+ */
150
+ getGlobals(): Record<string, string>;
151
+ /**
152
+ * Set a global variable value.
153
+ */
154
+ setGlobal(key: string, value: string): void;
155
+ /**
156
+ * Remove a (session) global variable.
157
+ */
158
+ unsetGlobal(key: string): void;
159
+ /**
160
+ * Clear all (session) global variables.
161
+ */
162
+ clearGlobals(): void;
130
163
  /**
131
164
  * Resolve {{variable}} placeholders
132
165
  */
@@ -28,13 +28,12 @@ export interface VariableResolverConfig {
28
28
  globals: Record<string, string>;
29
29
  collectionVariables: Record<string, string>;
30
30
  environmentVariables: Record<string, string>;
31
- sessionVariables: Record<string, string>;
32
31
  variables: Record<string, string>;
33
32
  }
34
33
  /**
35
34
  * Variable Resolver - Resolves {{varName}} patterns in strings and objects
36
35
  * Uses a 5-step pipeline: $dynamic → filter chains → simple lookup → JS expressions → passthrough
37
- * Variable precedence: globals > collection > environment > session > request > extra
36
+ * Variable precedence: globals > collection > environment > request > extra
38
37
  */
39
38
  export declare class VariableResolver {
40
39
  private readonly allVariables;
@@ -61,6 +61,7 @@ export declare class RequestExecutor {
61
61
  preprocessor?: IRequestPreprocessor | undefined, options?: {
62
62
  forgeRoot?: string;
63
63
  scriptExecutor?: IScriptExecutor;
64
+ scriptScope?: 'shared' | 'isolated';
64
65
  });
65
66
  /**
66
67
  * Execute a request with full pipeline
@@ -61,7 +61,6 @@ export interface CommonScriptContext {
61
61
  variables: Record<string, string>;
62
62
  collectionVariables?: Record<string, string>;
63
63
  globals?: Record<string, string>;
64
- sessionVariables?: Record<string, string>;
65
64
  environmentVariables?: Record<string, string>;
66
65
  environmentName?: string;
67
66
  sendRequest?: (options: any) => Promise<any>;
@@ -70,6 +69,7 @@ export interface CommonScriptContext {
70
69
  iterationCount?: number;
71
70
  iterationData?: Record<string, any>;
72
71
  onEnvironmentChange?: (action: 'set' | 'unset' | 'clear', key?: string, value?: string) => void;
72
+ onGlobalsChange?: (action: 'set' | 'unset' | 'clear', key?: string, value?: string) => void;
73
73
  }
74
74
  /**
75
75
  * Script execution context for pre-request scripts
@@ -95,7 +95,6 @@ export interface PreRequestScriptResult {
95
95
  modifiedVariables?: Record<string, string>;
96
96
  modifiedCollectionVariables?: Record<string, string>;
97
97
  modifiedGlobals?: Record<string, string>;
98
- modifiedSessionVariables?: Record<string, string>;
99
98
  modifiedEnvironmentVariables?: Record<string, string>;
100
99
  consoleOutput?: string[];
101
100
  /** Postman-compatible: pm.execution.setNextRequest() value. null = stop runner. */
@@ -110,7 +109,8 @@ export interface PostResponseScriptResult {
110
109
  testResults: TestAssertion[];
111
110
  consoleOutput?: string[];
112
111
  modifiedEnvironmentVariables?: Record<string, string>;
113
- modifiedSessionVariables?: Record<string, string>;
112
+ modifiedGlobals?: Record<string, string>;
113
+ modifiedCollectionVariables?: Record<string, string>;
114
114
  /** Postman-compatible: pm.execution.setNextRequest() value. null = stop runner. */
115
115
  nextRequest?: string | null;
116
116
  /** Postman-compatible: pm.visualizer.set(template, data) output */
@@ -16,6 +16,8 @@ import { CommonScriptContext, IRequestScriptSession, PostResponseScriptResult, P
16
16
  export interface SessionDependencies {
17
17
  createVM: (ctx: any, scriptConsole: any) => vm.Context;
18
18
  createCommonContext: (context: CommonScriptContext, eventName: 'prerequest' | 'test') => any;
19
+ /** When true, each script level runs in its own scope (Postman-compatible). */
20
+ isolateScripts?: boolean;
19
21
  }
20
22
  /**
21
23
  * Request Script Session Implementation
@@ -22,8 +22,9 @@ import { IRequestScriptSession, IScriptExecutor, PreRequestScriptContext } from
22
22
  export declare class ScriptExecutor implements IScriptExecutor {
23
23
  private readonly httpService?;
24
24
  private readonly secretRegistry?;
25
+ private readonly scopeMode;
25
26
  private readonly moduleLoader;
26
- constructor(httpService?: IHttpRequestService | undefined, modulePaths?: string[], secretRegistry?: SecretResolverRegistry | undefined);
27
+ constructor(httpService?: IHttpRequestService | undefined, modulePaths?: string[], secretRegistry?: SecretResolverRegistry | undefined, scopeMode?: 'shared' | 'isolated');
27
28
  /**
28
29
  * Create a request execution session
29
30
  * Factory method implementing IScriptExecutor
@@ -54,6 +55,13 @@ export declare class ScriptExecutor implements IScriptExecutor {
54
55
  * Create a basic variable scope with get/set/has/unset/clear/toObject
55
56
  */
56
57
  private createVariableScope;
58
+ /**
59
+ * Create the globals scope with change callbacks.
60
+ * Globals are a special, environment-agnostic variable layer, so they are
61
+ * persisted live through the same push-callback mechanism as environment
62
+ * variables (see createEnvironmentScope) rather than a post-hoc diff.
63
+ */
64
+ private createGlobalsScope;
57
65
  /**
58
66
  * Create merged variable scope (Postman-style cascading lookup)
59
67
  */
@@ -13,10 +13,17 @@ export interface ConsoleMessage {
13
13
  args: any[];
14
14
  }
15
15
  /**
16
- * Concatenate multiple scripts into one with clear separators
17
- * Enables variables defined in earlier scripts to be accessible in later scripts
18
- */
19
- export declare function concatenateScripts(scripts: string | string[]): string;
16
+ * Concatenate multiple scripts into one program.
17
+ *
18
+ * - shared (default): scripts are joined into one scope, so variables/functions declared
19
+ * in an earlier script are visible to later scripts (and, via var/function hoisting onto
20
+ * the shared VM global, to the post-response phase).
21
+ * - isolated: each script unit is wrapped in its own async IIFE, so its var/const/let/function
22
+ * declarations cannot collide within a phase or leak across phases (Postman parity). The
23
+ * whole batch is wrapped in one outer async IIFE so top-level `await` inside any unit works
24
+ * and the program resolves to an awaitable promise.
25
+ */
26
+ export declare function concatenateScripts(scripts: string | string[], isolate?: boolean): string;
20
27
  /**
21
28
  * Check if an object has changed from its original value
22
29
  * Uses JSON serialization for deep comparison
@@ -227,8 +227,6 @@ export interface FullResultDetails {
227
227
  modifiedEnvironmentVariables?: Record<string, string>;
228
228
  /** Collection variables modified by scripts */
229
229
  modifiedCollectionVariables?: Record<string, string>;
230
- /** Session variables modified by scripts */
231
- modifiedSessionVariables?: Record<string, string>;
232
230
  /** pm.execution.setNextRequest() value */
233
231
  nextRequest?: string | null;
234
232
  /** pm.visualizer.set() payload */
@@ -218,7 +218,6 @@ export interface ExecutionVariables {
218
218
  variables: Record<string, string>;
219
219
  collectionVariables?: Record<string, string>;
220
220
  globals?: Record<string, string>;
221
- sessionVariables?: Record<string, string>;
222
221
  environmentVariables?: Record<string, string>;
223
222
  }
224
223
  /**
@@ -619,7 +618,6 @@ export interface ExecutionResult {
619
618
  modifiedVariables?: Record<string, string>;
620
619
  modifiedEnvironmentVariables?: Record<string, string>;
621
620
  modifiedCollectionVariables?: Record<string, string>;
622
- modifiedSessionVariables?: Record<string, string>;
623
621
  error?: string;
624
622
  /** Folder path of the request within its collection (slash-separated; empty for root) */
625
623
  folderPath?: string;
@@ -10,7 +10,8 @@
10
10
  export declare function sanitizeName(name: string): string;
11
11
  /**
12
12
  * Generate a unique identifier.
13
- * Uses timestamp + random string for uniqueness.
13
+ * Combines a base-36 timestamp, a per-process monotonic counter, and a random
14
+ * suffix so ids created in the same millisecond are still distinct.
14
15
  * Optional prefix is sanitized and prepended.
15
16
  */
16
17
  export declare function generateId(prefix?: string): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@http-forge/core",
3
- "version": "0.4.4",
3
+ "version": "0.4.6",
4
4
  "description": "Headless HTTP testing engine with Postman collection support, dynamic variables, and script-based automation.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",