@http-forge/core 0.1.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 (66) hide show
  1. package/README.md +500 -0
  2. package/dist/container.d.ts +146 -0
  3. package/dist/container.d.ts.map +1 -0
  4. package/dist/implementations/cookie-jar.d.ts +97 -0
  5. package/dist/implementations/cookie-jar.d.ts.map +1 -0
  6. package/dist/implementations/cookie-utils.d.ts +78 -0
  7. package/dist/implementations/cookie-utils.d.ts.map +1 -0
  8. package/dist/implementations/data-file-parser.d.ts +71 -0
  9. package/dist/implementations/data-file-parser.d.ts.map +1 -0
  10. package/dist/implementations/fetch-http-client.d.ts +19 -0
  11. package/dist/implementations/fetch-http-client.d.ts.map +1 -0
  12. package/dist/implementations/index.d.ts +22 -0
  13. package/dist/implementations/index.d.ts.map +1 -0
  14. package/dist/implementations/interceptor-chain.d.ts +262 -0
  15. package/dist/implementations/interceptor-chain.d.ts.map +1 -0
  16. package/dist/implementations/module-loader.d.ts +74 -0
  17. package/dist/implementations/module-loader.d.ts.map +1 -0
  18. package/dist/implementations/native-http-client.d.ts +72 -0
  19. package/dist/implementations/native-http-client.d.ts.map +1 -0
  20. package/dist/implementations/node-file-system.d.ts +52 -0
  21. package/dist/implementations/node-file-system.d.ts.map +1 -0
  22. package/dist/implementations/request-history.d.ts +73 -0
  23. package/dist/implementations/request-history.d.ts.map +1 -0
  24. package/dist/implementations/request-preprocessor.d.ts +78 -0
  25. package/dist/implementations/request-preprocessor.d.ts.map +1 -0
  26. package/dist/implementations/variable-interpolator.d.ts +55 -0
  27. package/dist/implementations/variable-interpolator.d.ts.map +1 -0
  28. package/dist/implementations/vm2-script-runner.d.ts +76 -0
  29. package/dist/implementations/vm2-script-runner.d.ts.map +1 -0
  30. package/dist/index.d.ts +27 -0
  31. package/dist/index.d.ts.map +1 -0
  32. package/dist/index.js +46 -0
  33. package/dist/index.mjs +46 -0
  34. package/dist/interfaces/cookie.d.ts +101 -0
  35. package/dist/interfaces/cookie.d.ts.map +1 -0
  36. package/dist/interfaces/history.d.ts +117 -0
  37. package/dist/interfaces/history.d.ts.map +1 -0
  38. package/dist/interfaces/index.d.ts +170 -0
  39. package/dist/interfaces/index.d.ts.map +1 -0
  40. package/dist/interfaces/types.d.ts +308 -0
  41. package/dist/interfaces/types.d.ts.map +1 -0
  42. package/dist/parsers/http-forge-parser.d.ts +35 -0
  43. package/dist/parsers/http-forge-parser.d.ts.map +1 -0
  44. package/dist/parsers/index.d.ts +7 -0
  45. package/dist/parsers/index.d.ts.map +1 -0
  46. package/dist/services/collection-loader.d.ts +52 -0
  47. package/dist/services/collection-loader.d.ts.map +1 -0
  48. package/dist/services/environment-resolver.d.ts +91 -0
  49. package/dist/services/environment-resolver.d.ts.map +1 -0
  50. package/dist/services/folder-collection-loader.d.ts +91 -0
  51. package/dist/services/folder-collection-loader.d.ts.map +1 -0
  52. package/dist/services/forge-env.d.ts +166 -0
  53. package/dist/services/forge-env.d.ts.map +1 -0
  54. package/dist/services/index.d.ts +20 -0
  55. package/dist/services/index.d.ts.map +1 -0
  56. package/dist/services/parser-registry.d.ts +49 -0
  57. package/dist/services/parser-registry.d.ts.map +1 -0
  58. package/dist/services/request-executor.d.ts +86 -0
  59. package/dist/services/request-executor.d.ts.map +1 -0
  60. package/dist/services/script-pipeline.d.ts +43 -0
  61. package/dist/services/script-pipeline.d.ts.map +1 -0
  62. package/dist/services/script-session.d.ts +66 -0
  63. package/dist/services/script-session.d.ts.map +1 -0
  64. package/dist/services/url-builder.d.ts +60 -0
  65. package/dist/services/url-builder.d.ts.map +1 -0
  66. package/package.json +65 -0
@@ -0,0 +1,166 @@
1
+ /**
2
+ * ForgeEnv - Unified Environment Service
3
+ *
4
+ * Combines environment variable storage with template resolution.
5
+ * This is the main interface for generated API clients to use.
6
+ *
7
+ * Features:
8
+ * - Variable storage (get/set)
9
+ * - Template resolution: {{variable}}
10
+ * - Path parameter resolution: :param, :param(regex), :param?
11
+ * - Object deep resolution
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * import { ForgeEnv } from '@http-forge/core';
16
+ *
17
+ * const env = ForgeEnv.create({
18
+ * baseUrl: 'https://api.example.com',
19
+ * apiKey: 'secret123',
20
+ * });
21
+ *
22
+ * // Template resolution
23
+ * env.resolve('{{baseUrl}}/users'); // 'https://api.example.com/users'
24
+ *
25
+ * // Path parameter resolution
26
+ * env.resolvePath('{{baseUrl}}/users/:id', { id: '123' }); // 'https://api.example.com/users/123'
27
+ *
28
+ * // Set/get variables
29
+ * env.set('token', 'abc');
30
+ * env.get('token'); // 'abc'
31
+ * ```
32
+ */
33
+ import { IEnvironmentStore, IVariableInterpolator } from '../interfaces';
34
+ import { EnvironmentResolver } from './environment-resolver';
35
+ /**
36
+ * ForgeEnv interface - the public API for environment management
37
+ */
38
+ export interface IForgeEnv {
39
+ /**
40
+ * Get a variable value
41
+ */
42
+ get(key: string): string | undefined;
43
+ /**
44
+ * Set a variable value
45
+ */
46
+ set(key: string, value: string): void;
47
+ /**
48
+ * Check if a variable exists
49
+ */
50
+ has(key: string): boolean;
51
+ /**
52
+ * Delete a variable
53
+ */
54
+ delete(key: string): void;
55
+ /**
56
+ * Get all variables
57
+ */
58
+ getAll(): Record<string, string>;
59
+ /**
60
+ * Get the active environment name (e.g., 'dev', 'sit', 'prod')
61
+ */
62
+ getActiveEnvironment(): string | undefined;
63
+ /**
64
+ * Set the active environment by name
65
+ * @param name - Environment name (e.g., 'dev', 'sit', 'prod')
66
+ */
67
+ setActiveEnvironment(name: string): void;
68
+ /**
69
+ * Get list of available environment names
70
+ */
71
+ getEnvironments(): string[];
72
+ /**
73
+ * Resolve {{variable}} placeholders in a string
74
+ */
75
+ resolve(template: string): string;
76
+ /**
77
+ * Resolve {{variable}} and :pathParam placeholders in a URL
78
+ */
79
+ resolvePath(urlPattern: string, params?: Record<string, string>): string;
80
+ /**
81
+ * Build a complete URL with variables, path params, and query params
82
+ */
83
+ buildUrl(urlPattern: string, options?: {
84
+ params?: Record<string, string>;
85
+ query?: Record<string, string>;
86
+ }): string;
87
+ /**
88
+ * Resolve variables in an object recursively (deep)
89
+ */
90
+ resolveObject<T>(obj: T): T;
91
+ /**
92
+ * Extract variable names from a template string
93
+ */
94
+ extractVariables(template: string): string[];
95
+ /**
96
+ * Extract path parameter names from a URL pattern
97
+ */
98
+ extractPathParams(urlPattern: string): string[];
99
+ }
100
+ /**
101
+ * ForgeEnv implementation
102
+ */
103
+ export declare class ForgeEnv implements IForgeEnv {
104
+ private readonly envStore;
105
+ private readonly interpolator;
106
+ private readonly urlBuilder;
107
+ constructor(envStore: IEnvironmentStore, interpolator?: IVariableInterpolator);
108
+ get(key: string): string | undefined;
109
+ set(key: string, value: string): void;
110
+ has(key: string): boolean;
111
+ delete(key: string): void;
112
+ getAll(): Record<string, string>;
113
+ /**
114
+ * Get the active environment name (e.g., 'dev', 'sit', 'prod')
115
+ */
116
+ getActiveEnvironment(): string | undefined;
117
+ /**
118
+ * Set the active environment by name
119
+ * @example
120
+ * ```typescript
121
+ * env.setActiveEnvironment('sit'); // Switch to SIT environment
122
+ * env.get('baseUrl'); // Now returns SIT's baseUrl
123
+ * ```
124
+ */
125
+ setActiveEnvironment(name: string): void;
126
+ /**
127
+ * Get list of available environment names
128
+ */
129
+ getEnvironments(): string[];
130
+ /**
131
+ * Resolve {{variable}} placeholders
132
+ */
133
+ resolve(template: string): string;
134
+ /**
135
+ * Resolve {{variable}} and :pathParam placeholders in a URL
136
+ */
137
+ resolvePath(urlPattern: string, params?: Record<string, string>): string;
138
+ /**
139
+ * Build a complete URL with all substitutions
140
+ */
141
+ buildUrl(urlPattern: string, options?: {
142
+ params?: Record<string, string>;
143
+ query?: Record<string, string>;
144
+ }): string;
145
+ /**
146
+ * Resolve variables in an object recursively
147
+ */
148
+ resolveObject<T>(obj: T): T;
149
+ /**
150
+ * Extract variable names from a template
151
+ */
152
+ extractVariables(template: string): string[];
153
+ /**
154
+ * Extract path parameter names from a URL pattern
155
+ */
156
+ extractPathParams(urlPattern: string): string[];
157
+ /**
158
+ * Create ForgeEnv from a simple variables object
159
+ */
160
+ static create(variables?: Record<string, string>): ForgeEnv;
161
+ /**
162
+ * Create ForgeEnv from an existing EnvironmentResolver
163
+ */
164
+ static fromResolver(resolver: EnvironmentResolver): ForgeEnv;
165
+ }
166
+ //# sourceMappingURL=forge-env.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"forge-env.d.ts","sourceRoot":"","sources":["../../src/services/forge-env.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAGH,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAG7D;;GAEG;AACH,MAAM,WAAW,SAAS;IACtB;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IAErC;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAEtC;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;IAE1B;;OAEG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAE1B;;OAEG;IACH,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEjC;;OAEG;IACH,oBAAoB,IAAI,MAAM,GAAG,SAAS,CAAC;IAE3C;;;OAGG;IACH,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAEzC;;OAEG;IACH,eAAe,IAAI,MAAM,EAAE,CAAC;IAE5B;;OAEG;IACH,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;IAElC;;OAEG;IACH,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,C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CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM;IAIjC;;OAEG;IACH,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GAAG,MAAM;IAI5E;;OAEG;IACH,QAAQ,CACJ,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE;QACL,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAChC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KAC7B,GACP,MAAM;IAST;;OAEG;IACH,aAAa,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC;IAI3B;;OAEG;IACH,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE;IAI5C;;OAEG;IACH,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE;IAQ/C;;OAEG;IACH,MAAM,CAAC,MAAM,CAAC,SAAS,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GAAG,QAAQ;IAK/D;;OAEG;IACH,MAAM,CAAC,YAAY,CAAC,QAAQ,EAAE,mBAAmB,GAAG,QAAQ;CAG/D"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Core Services
3
+ *
4
+ * Export all service classes
5
+ */
6
+ export { CollectionLoader } from './collection-loader';
7
+ export type { LoadOptions } from './collection-loader';
8
+ export { EnvironmentResolver } from './environment-resolver';
9
+ export type { Environment, EnvironmentConfig } from './environment-resolver';
10
+ export { FolderCollectionLoader } from './folder-collection-loader';
11
+ export { ForgeEnv } from './forge-env';
12
+ export type { IForgeEnv } from './forge-env';
13
+ export { ParserRegistry } from './parser-registry';
14
+ export { RequestExecutor } from './request-executor';
15
+ export type { ExecuteOptions, ExecuteResult } from './request-executor';
16
+ export { ScriptPipeline } from './script-pipeline';
17
+ export { ScriptSession } from './script-session';
18
+ export { UrlBuilder } from './url-builder';
19
+ export type { IUrlBuilder } from './url-builder';
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,YAAY,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC7E,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,YAAY,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,YAAY,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Parser Registry Service
3
+ *
4
+ * Open/Closed Principle: New parsers can be added without modifying existing code
5
+ * Single Responsibility: Manage collection parser registration and lookup
6
+ */
7
+ import { ICollectionParser } from '../interfaces';
8
+ /**
9
+ * Registry for collection parsers
10
+ * Allows registering parsers for different collection formats
11
+ */
12
+ export declare class ParserRegistry {
13
+ private parsers;
14
+ /**
15
+ * Register a parser for a format
16
+ * @param format Format identifier (e.g., 'http-forge', 'postman', 'insomnia')
17
+ * @param parser Parser implementation
18
+ */
19
+ register(format: string, parser: ICollectionParser): void;
20
+ /**
21
+ * Get a parser by format
22
+ * @param format Format identifier
23
+ * @returns Parser or undefined if not found
24
+ */
25
+ get(format: string): ICollectionParser | undefined;
26
+ /**
27
+ * Check if a parser is registered for a format
28
+ * @param format Format identifier
29
+ */
30
+ has(format: string): boolean;
31
+ /**
32
+ * Get all registered format names
33
+ */
34
+ getFormats(): string[];
35
+ /**
36
+ * Try to detect format and find appropriate parser
37
+ * @param content Raw file content
38
+ * @returns Parser and detected format, or null if not recognized
39
+ */
40
+ detect(content: string): {
41
+ parser: ICollectionParser;
42
+ format: string;
43
+ } | null;
44
+ /**
45
+ * Clear all registered parsers
46
+ */
47
+ clear(): void;
48
+ }
49
+ //# sourceMappingURL=parser-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parser-registry.d.ts","sourceRoot":"","sources":["../../src/services/parser-registry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAElD;;;GAGG;AACH,qBAAa,cAAc;IACvB,OAAO,CAAC,OAAO,CAA6C;IAE5D;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,GAAG,IAAI;IAIzD;;;;OAIG;IACH,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,iBAAiB,GAAG,SAAS;IAIlD;;;OAGG;IACH,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAI5B;;OAEG;IACH,UAAU,IAAI,MAAM,EAAE;IAItB;;;;OAIG;IACH,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG;QAAE,MAAM,EAAE,iBAAiB,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI;IAS7E;;OAEG;IACH,KAAK,IAAI,IAAI;CAGhB"}
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Request Executor Service (Facade Pattern)
3
+ *
4
+ * Single Responsibility: Orchestrate the complete request execution flow
5
+ * Facade Pattern: Provides simplified interface to complex subsystem
6
+ */
7
+ import { IHttpClient, IRequestPreprocessor } from '../interfaces';
8
+ import { HttpRequest, HttpResponse, RequestOverrides, ScriptResult, UnifiedCollection, UnifiedRequest } from '../interfaces/types';
9
+ import { IForgeEnv } from './forge-env';
10
+ import { ScriptPipeline } from './script-pipeline';
11
+ /**
12
+ * Options for request execution
13
+ */
14
+ export interface ExecuteOptions {
15
+ /** Environment to use (defaults to active) */
16
+ environment?: string;
17
+ /** Override request properties */
18
+ overrides?: RequestOverrides;
19
+ /** Skip pre-request scripts */
20
+ skipPreRequest?: boolean;
21
+ /** Skip post-response scripts */
22
+ skipPostResponse?: boolean;
23
+ /** Additional variables to merge */
24
+ additionalVariables?: Record<string, string>;
25
+ /** Timeout override */
26
+ timeout?: number;
27
+ }
28
+ /**
29
+ * Complete execution result
30
+ */
31
+ export interface ExecuteResult {
32
+ /** The HTTP response */
33
+ response: HttpResponse;
34
+ /** Pre-request script result */
35
+ preRequestResult?: ScriptResult;
36
+ /** Post-response script result (tests) */
37
+ postResponseResult?: ScriptResult;
38
+ /** Total execution time (ms) */
39
+ totalTime: number;
40
+ /** The final request after interpolation and script modifications */
41
+ finalRequest: HttpRequest;
42
+ /** Variables after execution */
43
+ variables: {
44
+ environment: Record<string, string>;
45
+ local: Record<string, string>;
46
+ };
47
+ }
48
+ /**
49
+ * Request Executor - Main execution engine
50
+ */
51
+ export declare class RequestExecutor {
52
+ private readonly httpClient;
53
+ private readonly forgeEnv;
54
+ private readonly scriptPipeline;
55
+ private readonly preprocessor?;
56
+ private moduleLoader?;
57
+ constructor(httpClient: IHttpClient, forgeEnv: IForgeEnv, scriptPipeline: ScriptPipeline, preprocessor?: IRequestPreprocessor | undefined, options?: {
58
+ forgeRoot?: string;
59
+ });
60
+ /**
61
+ * Execute a request with full pipeline
62
+ * Uses ScriptSession for shared VM context between pre-request and post-response scripts
63
+ */
64
+ execute(request: UnifiedRequest, collection: UnifiedCollection, options?: ExecuteOptions): Promise<ExecuteResult>;
65
+ /**
66
+ * Execute a simple request without collection context
67
+ */
68
+ executeSimple(request: HttpRequest, options?: {
69
+ variables?: Record<string, string>;
70
+ timeout?: number;
71
+ }): Promise<HttpResponse>;
72
+ /**
73
+ * Build HttpRequest from UnifiedRequest
74
+ */
75
+ private buildHttpRequest;
76
+ /**
77
+ * Interpolate variables in request using ForgeEnv
78
+ * Handles both {{variable}} and :pathParam patterns in URL
79
+ */
80
+ private interpolateRequest;
81
+ /**
82
+ * Create script context
83
+ */
84
+ private createScriptContext;
85
+ }
86
+ //# sourceMappingURL=request-executor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-executor.d.ts","sourceRoot":"","sources":["../../src/services/request-executor.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,EACH,WAAW,EACX,YAAY,EACZ,gBAAgB,EAEhB,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACjB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAY,SAAS,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGnD;;GAEG;AACH,MAAM,WAAW,cAAc;IAC3B,8CAA8C;IAC9C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kCAAkC;IAClC,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B,+BAA+B;IAC/B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,iCAAiC;IACjC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,oCAAoC;IACpC,mBAAmB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7C,uBAAuB;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IA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B;IAkB1B;;OAEG;IACH,OAAO,CAAC,mBAAmB;CAoB9B"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Script Pipeline Service
3
+ *
4
+ * Single Responsibility: Manage script execution chain
5
+ */
6
+ import { IScriptPipeline, IScriptRunner } from '../interfaces';
7
+ import { ScriptContext, ScriptResult, UnifiedCollection, UnifiedFolder, UnifiedRequest } from '../interfaces/types';
8
+ /**
9
+ * Script pipeline that executes scripts in proper order
10
+ */
11
+ export declare class ScriptPipeline implements IScriptPipeline {
12
+ private readonly scriptRunner;
13
+ constructor(scriptRunner: IScriptRunner);
14
+ /**
15
+ * Build script chain for a request
16
+ * Returns scripts in execution order: collection → folders → request
17
+ */
18
+ buildChain(request: UnifiedRequest, collection: UnifiedCollection, folderPath?: UnifiedFolder[]): {
19
+ preRequest: string[];
20
+ postResponse: string[];
21
+ };
22
+ /**
23
+ * Execute pre-request scripts
24
+ * Returns combined result with all modifications
25
+ */
26
+ executePreRequest(scripts: string[], context: ScriptContext): Promise<ScriptResult>;
27
+ /**
28
+ * Execute post-response scripts (tests)
29
+ * Returns combined result with all assertions
30
+ */
31
+ executePostResponse(scripts: string[], context: ScriptContext): Promise<ScriptResult>;
32
+ /**
33
+ * Find the folder path from collection root to a request
34
+ * Returns array of folders in order from root to parent
35
+ */
36
+ findFolderPath(collection: UnifiedCollection, requestId: string): UnifiedFolder[];
37
+ /**
38
+ * Execute full script pipeline for a request
39
+ * Convenience method that builds chain and executes scripts
40
+ */
41
+ execute(request: UnifiedRequest, collection: UnifiedCollection, context: ScriptContext, phase: 'preRequest' | 'postResponse'): Promise<ScriptResult>;
42
+ }
43
+ //# sourceMappingURL=script-pipeline.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"script-pipeline.d.ts","sourceRoot":"","sources":["../../src/services/script-pipeline.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EACH,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,aAAa,EACb,cAAc,EACjB,MAAM,qBAAqB,CAAC;AAE7B;;GAEG;AACH,qBAAa,cAAe,YAAW,eAAe;IACtC,OAAO,CAAC,QAAQ,CAAC,YAAY;gBAAZ,YAAY,EAAE,aAAa;IAExD;;;OAGG;IACH,UAAU,CACN,OAAO,EAAE,cAAc,EACvB,UAAU,EAAE,iBAAiB,EAC7B,UAAU,GAAE,aAAa,EAAO,GACjC;QAAE,UAAU,EAAE,MAAM,EAAE,CAAC;QAAC,YAAY,EAAE,MAAM,EAAE,CAAA;KAAE;IAiCnD;;;OAGG;IACG,iBAAiB,CACnB,OAAO,EAAE,MAAM,EAAE,EACjB,OAAO,EAAE,aAAa,GACvB,OAAO,CAAC,YAAY,CAAC;IAWxB;;;OAGG;IACG,mBAAmB,CACrB,OAAO,EAAE,MAAM,EAAE,EACjB,OAAO,EAAE,aAAa,GACvB,OAAO,CAAC,YAAY,CAAC;IAWxB;;;OAGG;IACH,cAAc,CACV,UAAU,EAAE,iBAAiB,EAC7B,SAAS,EAAE,MAAM,GAClB,aAAa,EAAE;IAwBlB;;;OAGG;IACG,OAAO,CACT,OAAO,EAAE,cAAc,EACvB,UAAU,EAAE,iBAAiB,EAC7B,OAAO,EAAE,aAAa,EACtB,KAAK,EAAE,YAAY,GAAG,cAAc,GACrC,OAAO,CAAC,YAAY,CAAC;CAU3B"}
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Script Session
3
+ *
4
+ * Single Responsibility: Manage shared VM context between pre-request and post-response scripts
5
+ *
6
+ * This class creates a single VM sandbox that persists across both script phases,
7
+ * allowing JavaScript variables declared in pre-request to be accessible in post-response.
8
+ * This matches Postman's behavior for per-request script execution.
9
+ */
10
+ import { ModuleLoader } from '../implementations/module-loader';
11
+ import { IHttpClient } from '../interfaces';
12
+ import { HttpResponse, ScriptContext, ScriptResult } from '../interfaces/types';
13
+ /**
14
+ * Script Session - manages shared VM context for request execution
15
+ */
16
+ export declare class ScriptSession {
17
+ private readonly context;
18
+ private readonly options;
19
+ private vm;
20
+ private consoleMessages;
21
+ private assertions;
22
+ private modifiedRequest;
23
+ private modifiedGlobals;
24
+ private modifiedCollectionVariables;
25
+ private modifiedEnvironment;
26
+ private modifiedVariables;
27
+ private ctx;
28
+ constructor(context: ScriptContext, options?: {
29
+ timeout?: number;
30
+ httpClient?: IHttpClient;
31
+ moduleLoader?: ModuleLoader;
32
+ });
33
+ /**
34
+ * Initialize the shared VM context
35
+ */
36
+ private initializeVM;
37
+ /**
38
+ * Execute pre-request scripts
39
+ */
40
+ executePreRequest(scripts: string[]): Promise<ScriptResult>;
41
+ /**
42
+ * Execute post-response scripts
43
+ */
44
+ executePostResponse(scripts: string[], response: HttpResponse): Promise<ScriptResult>;
45
+ /**
46
+ * Get the modified request after pre-request scripts
47
+ */
48
+ getModifiedRequest(): {
49
+ url: string;
50
+ method: string;
51
+ headers: Record<string, string>;
52
+ body: any;
53
+ };
54
+ /**
55
+ * Dispose the session
56
+ */
57
+ dispose(): void;
58
+ private createRequestObject;
59
+ private createResponseObject;
60
+ private createVariableScope;
61
+ private createEnvironmentScope;
62
+ private createMergedVariableScope;
63
+ private createSendRequest;
64
+ private createBuiltinOnlyRequire;
65
+ }
66
+ //# sourceMappingURL=script-session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"script-session.d.ts","sourceRoot":"","sources":["../../src/services/script-session.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAUH,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,YAAY,EAAiB,MAAM,qBAAqB,CAAC;AA4D/F;;GAEG;AACH,qBAAa,aAAa;IAqBlB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,OAAO;IArB5B,OAAO,CAAC,EAAE,CAAmB;IAC7B,OAAO,CAAC,eAAe,CAAwB;IAC/C,OAAO,CAAC,UAAU,CAAuB;IAGzC,OAAO,CAAC,eAAe,CAKrB;IACF,OAAO,CAAC,eAAe,CAAyB;IAChD,OAAO,CAAC,2BAA2B,CAAyB;IAC5D,OAAO,CAAC,mBAAmB,CAAyB;IACpD,OAAO,CAAC,iBAAiB,CAAyB;IAGlD,OAAO,CAAC,GAAG,CAAM;gBAGI,OAAO,EAAE,aAAa,EACtB,OAAO,GAAE;QACtB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,UAAU,CAAC,EAAE,WAAW,CAAC;QACzB,YAAY,CAAC,EAAE,YAAY,CAAC;KAC1B;IAoBV;;OAEG;IACH,OAAO,CAAC,YAAY;IAyHpB;;OAEG;IACG,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,YAAY,CAAC;IAqCjE;;OAEG;IACG,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;IA4C3F;;OAEG;IACH,kBAAkB;aA7PT,MAAM;gBACH,MAAM;iBACL,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;cACzB,GAAG;;IA8Pb;;OAEG;IACH,OAAO,IAAI,IAAI;IASf,OAAO,CAAC,mBAAmB;IAiD3B,OAAO,CAAC,oBAAoB;IAoH5B,OAAO,CAAC,mBAAmB;IAW3B,OAAO,CAAC,sBAAsB;IAY9B,OAAO,CAAC,yBAAyB;IAiCjC,OAAO,CAAC,iBAAiB;IAqCzB,OAAO,CAAC,wBAAwB;CAqBnC"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * URL Builder Service
3
+ *
4
+ * Single Responsibility: Build URLs with variable and path parameter substitution
5
+ *
6
+ * Handles:
7
+ * - Template variable replacement: {{variable}}
8
+ * - Path parameter replacement: :param, :param(regex), :param?
9
+ * - Query string building and merging
10
+ */
11
+ import { IVariableInterpolator } from '../interfaces';
12
+ /**
13
+ * URL Builder interface
14
+ */
15
+ export interface IUrlBuilder {
16
+ /**
17
+ * Build a complete URL with variable and path parameter substitution
18
+ * @param urlPattern - URL pattern with {{vars}} and :params
19
+ * @param variables - Variables for {{var}} replacement
20
+ * @param params - Path parameters for :param replacement
21
+ * @param query - Query parameters to append
22
+ */
23
+ buildUrl(urlPattern: string, variables: Record<string, string>, params?: Record<string, string>, query?: Record<string, string>): string;
24
+ /**
25
+ * Replace only path parameters (:param) in a URL
26
+ */
27
+ replacePathParams(url: string, params: Record<string, string>): string;
28
+ /**
29
+ * Extract path parameter names from a URL pattern
30
+ */
31
+ extractPathParams(urlPattern: string): string[];
32
+ }
33
+ /**
34
+ * URL Builder implementation
35
+ */
36
+ export declare class UrlBuilder implements IUrlBuilder {
37
+ private readonly interpolator;
38
+ constructor(interpolator: IVariableInterpolator);
39
+ /**
40
+ * Build a complete URL with all substitutions
41
+ */
42
+ buildUrl(urlPattern: string, variables: Record<string, string>, params?: Record<string, string>, query?: Record<string, string>): string;
43
+ /**
44
+ * Replace path parameters in URL
45
+ * Supports:
46
+ * - :param - required parameter
47
+ * - :param? - optional parameter
48
+ * - :param(regex) - parameter with validation regex (regex is ignored, just for documentation)
49
+ */
50
+ replacePathParams(url: string, params: Record<string, string>): string;
51
+ /**
52
+ * Extract path parameter names from a URL pattern
53
+ */
54
+ extractPathParams(urlPattern: string): string[];
55
+ /**
56
+ * Append query parameters to URL
57
+ */
58
+ private appendQueryParams;
59
+ }
60
+ //# sourceMappingURL=url-builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url-builder.d.ts","sourceRoot":"","sources":["../../src/services/url-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAEtD;;GAEG;AACH,MAAM,WAAW,WAAW;IACxB;;;;;;OAMG;IACH,QAAQ,CACJ,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACjC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC/B,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B,MAAM,CAAC;IAEV;;OAEG;IACH,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC;IAEvE;;OAEG;IACH,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CACnD;AAED;;GAEG;AACH,qBAAa,UAAW,YAAW,WAAW;IAC9B,OAAO,CAAC,QAAQ,CAAC,YAAY;gBAAZ,YAAY,EAAE,qBAAqB;IAEhE;;OAEG;IACH,QAAQ,CACJ,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACjC,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,EACnC,KAAK,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAM,GACnC,MAAM;IAaT;;;;;;OAMG;IACH,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM;IAwDtE;;OAEG;IACH,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE;IAY/C;;OAEG;IACH,OAAO,CAAC,iBAAiB;CA0C5B"}
package/package.json ADDED
@@ -0,0 +1,65 @@
1
+ {
2
+ "name": "@http-forge/core",
3
+ "version": "0.1.0",
4
+ "description": "HTTP Forge Core - API Test Execution Engine",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.mjs",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md"
18
+ ],
19
+ "scripts": {
20
+ "build": "npm run clean && node esbuild.config.js",
21
+ "build:prod": "npm run clean && node esbuild.config.js --production",
22
+ "prepublishOnly": "npm run build:prod",
23
+ "dev": "tsup --watch",
24
+ "test": "vitest",
25
+ "test:coverage": "vitest --coverage",
26
+ "lint": "eslint src",
27
+ "clean": "rimraf dist"
28
+ },
29
+ "keywords": [
30
+ "http",
31
+ "api",
32
+ "testing",
33
+ "postman",
34
+ "collection",
35
+ "http-forge"
36
+ ],
37
+ "author": "Henry Huang",
38
+ "license": "MIT",
39
+ "repository": {
40
+ "type": "git",
41
+ "url": "https://github.com/hsl1230/http-forge",
42
+ "directory": "packages/core"
43
+ },
44
+ "engines": {
45
+ "node": ">=18.0.0"
46
+ },
47
+ "dependencies": {
48
+ "ajv": "^8.12.0",
49
+ "lodash": "^4.17.21",
50
+ "moment": "^2.30.1",
51
+ "tv4": "^1.3.0",
52
+ "uuid": "^9.0.1",
53
+ "vm2": "^3.9.19"
54
+ },
55
+ "devDependencies": {
56
+ "@types/lodash": "^4.14.202",
57
+ "@types/node": "^20.10.0",
58
+ "@types/tv4": "^1.2.33",
59
+ "@types/uuid": "^9.0.7",
60
+ "rimraf": "^5.0.5",
61
+ "tsup": "^8.0.1",
62
+ "typescript": "^5.3.0",
63
+ "vitest": "^1.1.0"
64
+ }
65
+ }