openai-api-mock 0.1.32 → 0.1.34

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