openai-api-mock 0.2.3 → 0.3.1
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.
- package/LICENSE.md +21 -21
- package/README.md +333 -335
- package/dist/index.cjs +471 -451
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +471 -451
- package/dist/index.js.map +1 -1
- package/index.d.ts +76 -76
- package/package.json +69 -69
package/index.d.ts
CHANGED
|
@@ -1,76 +1,76 @@
|
|
|
1
|
-
export interface MockOptions {
|
|
2
|
-
/**
|
|
3
|
-
* When true, randomly simulates API errors
|
|
4
|
-
*/
|
|
5
|
-
includeErrors?: boolean;
|
|
6
|
-
/**
|
|
7
|
-
* Adds artificial delay to responses in milliseconds
|
|
8
|
-
*/
|
|
9
|
-
latency?: number;
|
|
10
|
-
/**
|
|
11
|
-
* Logs incoming requests to console for debugging
|
|
12
|
-
*/
|
|
13
|
-
logRequests?: boolean;
|
|
14
|
-
/**
|
|
15
|
-
* Seed value for consistent/deterministic responses
|
|
16
|
-
*/
|
|
17
|
-
seed?: number | string;
|
|
18
|
-
/**
|
|
19
|
-
* Whether to use predefined fixed response templates
|
|
20
|
-
*/
|
|
21
|
-
useFixedResponses?: boolean;
|
|
22
|
-
/**
|
|
23
|
-
* Base URL for the OpenAI API or OpenAI-compatible service
|
|
24
|
-
* @default 'https://api.openai.com'
|
|
25
|
-
*/
|
|
26
|
-
baseUrl?: string;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface MockControl {
|
|
30
|
-
/**
|
|
31
|
-
* Indicates if mocking is currently active
|
|
32
|
-
*/
|
|
33
|
-
isActive: boolean;
|
|
34
|
-
/**
|
|
35
|
-
* Stops all active mocks
|
|
36
|
-
*/
|
|
37
|
-
stopMocking: () => void;
|
|
38
|
-
/**
|
|
39
|
-
* Resets the faker seed to ensure consistent outputs for subsequent requests
|
|
40
|
-
*/
|
|
41
|
-
setSeed: (seed: number | string) => void;
|
|
42
|
-
/**
|
|
43
|
-
* Resets faker to use random values (removes deterministic behavior)
|
|
44
|
-
*/
|
|
45
|
-
resetSeed: () => void;
|
|
46
|
-
/**
|
|
47
|
-
* Get available response templates
|
|
48
|
-
*/
|
|
49
|
-
getResponseTemplates: () => Record<string, any>;
|
|
50
|
-
/**
|
|
51
|
-
* Create a custom response template
|
|
52
|
-
*/
|
|
53
|
-
createResponseTemplate: (
|
|
54
|
-
templateType: string,
|
|
55
|
-
overrides?: Record<string, any>,
|
|
56
|
-
) => Record<string, any>;
|
|
57
|
-
/**
|
|
58
|
-
* Adds a custom endpoint mock
|
|
59
|
-
* @param method - HTTP method (GET, POST, etc.)
|
|
60
|
-
* @param path - Endpoint path (will be appended to the configured base URL)
|
|
61
|
-
* @param handler - Function to handle the request and return response
|
|
62
|
-
*/
|
|
63
|
-
addCustomEndpoint: (
|
|
64
|
-
method: string,
|
|
65
|
-
path: string,
|
|
66
|
-
handler: (uri: string, body: any) => [number, any] | Promise<[number, any]>,
|
|
67
|
-
) => void;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Sets up mocking for OpenAI API responses
|
|
72
|
-
* @param force - If true, forces mocking regardless of environment. If false, only mocks in development
|
|
73
|
-
* @param options - Configuration options for the mock behavior
|
|
74
|
-
* @returns Object with control methods for the mock
|
|
75
|
-
*/
|
|
76
|
-
export function mockOpenAIResponse(force?: boolean, options?: MockOptions): MockControl;
|
|
1
|
+
export interface MockOptions {
|
|
2
|
+
/**
|
|
3
|
+
* When true, randomly simulates API errors
|
|
4
|
+
*/
|
|
5
|
+
includeErrors?: boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Adds artificial delay to responses in milliseconds
|
|
8
|
+
*/
|
|
9
|
+
latency?: number;
|
|
10
|
+
/**
|
|
11
|
+
* Logs incoming requests to console for debugging
|
|
12
|
+
*/
|
|
13
|
+
logRequests?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Seed value for consistent/deterministic responses
|
|
16
|
+
*/
|
|
17
|
+
seed?: number | string;
|
|
18
|
+
/**
|
|
19
|
+
* Whether to use predefined fixed response templates
|
|
20
|
+
*/
|
|
21
|
+
useFixedResponses?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Base URL for the OpenAI API or OpenAI-compatible service
|
|
24
|
+
* @default 'https://api.openai.com'
|
|
25
|
+
*/
|
|
26
|
+
baseUrl?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface MockControl {
|
|
30
|
+
/**
|
|
31
|
+
* Indicates if mocking is currently active
|
|
32
|
+
*/
|
|
33
|
+
isActive: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Stops all active mocks
|
|
36
|
+
*/
|
|
37
|
+
stopMocking: () => void;
|
|
38
|
+
/**
|
|
39
|
+
* Resets the faker seed to ensure consistent outputs for subsequent requests
|
|
40
|
+
*/
|
|
41
|
+
setSeed: (seed: number | string) => void;
|
|
42
|
+
/**
|
|
43
|
+
* Resets faker to use random values (removes deterministic behavior)
|
|
44
|
+
*/
|
|
45
|
+
resetSeed: () => void;
|
|
46
|
+
/**
|
|
47
|
+
* Get available response templates
|
|
48
|
+
*/
|
|
49
|
+
getResponseTemplates: () => Record<string, any>;
|
|
50
|
+
/**
|
|
51
|
+
* Create a custom response template
|
|
52
|
+
*/
|
|
53
|
+
createResponseTemplate: (
|
|
54
|
+
templateType: string,
|
|
55
|
+
overrides?: Record<string, any>,
|
|
56
|
+
) => Record<string, any>;
|
|
57
|
+
/**
|
|
58
|
+
* Adds a custom endpoint mock
|
|
59
|
+
* @param method - HTTP method (GET, POST, etc.)
|
|
60
|
+
* @param path - Endpoint path (will be appended to the configured base URL)
|
|
61
|
+
* @param handler - Function to handle the request and return response
|
|
62
|
+
*/
|
|
63
|
+
addCustomEndpoint: (
|
|
64
|
+
method: string,
|
|
65
|
+
path: string,
|
|
66
|
+
handler: (uri: string, body: any) => [number, any] | Promise<[number, any]>,
|
|
67
|
+
) => void;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Sets up mocking for OpenAI API responses
|
|
72
|
+
* @param force - If true, forces mocking regardless of environment. If false, only mocks in development
|
|
73
|
+
* @param options - Configuration options for the mock behavior
|
|
74
|
+
* @returns Object with control methods for the mock
|
|
75
|
+
*/
|
|
76
|
+
export function mockOpenAIResponse(force?: boolean, options?: MockOptions): MockControl;
|
package/package.json
CHANGED
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "openai-api-mock",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "A Node.js module for mocking OpenAI-compatible API responses in a development environment with consistency mechanisms for deterministic testing",
|
|
5
|
-
"repository": {
|
|
6
|
-
"type": "git",
|
|
7
|
-
"url": "git+https://github.com/chihebnabil/openai-api-mock.git"
|
|
8
|
-
},
|
|
9
|
-
"type": "module",
|
|
10
|
-
"types": "./index.d.ts",
|
|
11
|
-
"keywords": [
|
|
12
|
-
"openai",
|
|
13
|
-
"mock",
|
|
14
|
-
"api",
|
|
15
|
-
"development",
|
|
16
|
-
"testing",
|
|
17
|
-
"chatgpt",
|
|
18
|
-
"interceptor",
|
|
19
|
-
"sandbox",
|
|
20
|
-
"fake",
|
|
21
|
-
"mocking",
|
|
22
|
-
"ai",
|
|
23
|
-
"artificial intelligence",
|
|
24
|
-
"machine learning",
|
|
25
|
-
"deterministic",
|
|
26
|
-
"consistency",
|
|
27
|
-
"seeding",
|
|
28
|
-
"templates"
|
|
29
|
-
],
|
|
30
|
-
"scripts": {
|
|
31
|
-
"build": "vite build",
|
|
32
|
-
"pretest": "npm run build",
|
|
33
|
-
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
|
|
34
|
-
"coverage": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage",
|
|
35
|
-
"prepublishOnly": "npm run build",
|
|
36
|
-
"format": "prettier --write .",
|
|
37
|
-
"format:check": "prettier --check .",
|
|
38
|
-
"format:src": "prettier --write src/**/*.js __tests__/**/*.js"
|
|
39
|
-
},
|
|
40
|
-
"author": "Chiheb Nabil",
|
|
41
|
-
"license": "MIT",
|
|
42
|
-
"main": "./dist/index.cjs",
|
|
43
|
-
"module": "./dist/index.js",
|
|
44
|
-
"exports": {
|
|
45
|
-
".": {
|
|
46
|
-
"types": "./index.d.ts",
|
|
47
|
-
"require": "./dist/index.cjs",
|
|
48
|
-
"import": "./dist/index.js"
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
"files": [
|
|
52
|
-
"dist",
|
|
53
|
-
"index.d.ts"
|
|
54
|
-
],
|
|
55
|
-
"dependencies": {
|
|
56
|
-
"@faker-js/faker": "^10.0.0",
|
|
57
|
-
"nock": "^14.0.0"
|
|
58
|
-
},
|
|
59
|
-
"devDependencies": {
|
|
60
|
-
"jest": "^30.0.0",
|
|
61
|
-
"node-fetch": "^3.3.2",
|
|
62
|
-
"openai": "^
|
|
63
|
-
"prettier": "^3.0.0",
|
|
64
|
-
"vite": "^7.0.0"
|
|
65
|
-
},
|
|
66
|
-
"engines": {
|
|
67
|
-
"node": ">=18.0.0"
|
|
68
|
-
}
|
|
69
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "openai-api-mock",
|
|
3
|
+
"version": "0.3.1",
|
|
4
|
+
"description": "A Node.js module for mocking OpenAI-compatible API responses in a development environment with consistency mechanisms for deterministic testing",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/chihebnabil/openai-api-mock.git"
|
|
8
|
+
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"types": "./index.d.ts",
|
|
11
|
+
"keywords": [
|
|
12
|
+
"openai",
|
|
13
|
+
"mock",
|
|
14
|
+
"api",
|
|
15
|
+
"development",
|
|
16
|
+
"testing",
|
|
17
|
+
"chatgpt",
|
|
18
|
+
"interceptor",
|
|
19
|
+
"sandbox",
|
|
20
|
+
"fake",
|
|
21
|
+
"mocking",
|
|
22
|
+
"ai",
|
|
23
|
+
"artificial intelligence",
|
|
24
|
+
"machine learning",
|
|
25
|
+
"deterministic",
|
|
26
|
+
"consistency",
|
|
27
|
+
"seeding",
|
|
28
|
+
"templates"
|
|
29
|
+
],
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "vite build",
|
|
32
|
+
"pretest": "npm run build",
|
|
33
|
+
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
|
|
34
|
+
"coverage": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage",
|
|
35
|
+
"prepublishOnly": "npm run build",
|
|
36
|
+
"format": "prettier --write .",
|
|
37
|
+
"format:check": "prettier --check .",
|
|
38
|
+
"format:src": "prettier --write src/**/*.js __tests__/**/*.js"
|
|
39
|
+
},
|
|
40
|
+
"author": "Chiheb Nabil",
|
|
41
|
+
"license": "MIT",
|
|
42
|
+
"main": "./dist/index.cjs",
|
|
43
|
+
"module": "./dist/index.js",
|
|
44
|
+
"exports": {
|
|
45
|
+
".": {
|
|
46
|
+
"types": "./index.d.ts",
|
|
47
|
+
"require": "./dist/index.cjs",
|
|
48
|
+
"import": "./dist/index.js"
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"files": [
|
|
52
|
+
"dist",
|
|
53
|
+
"index.d.ts"
|
|
54
|
+
],
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@faker-js/faker": "^10.0.0",
|
|
57
|
+
"nock": "^14.0.0"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"jest": "^30.0.0",
|
|
61
|
+
"node-fetch": "^3.3.2",
|
|
62
|
+
"openai": "^6.0.0",
|
|
63
|
+
"prettier": "^3.0.0",
|
|
64
|
+
"vite": "^7.0.0"
|
|
65
|
+
},
|
|
66
|
+
"engines": {
|
|
67
|
+
"node": ">=18.0.0"
|
|
68
|
+
}
|
|
69
|
+
}
|