openai-api-mock 0.1.32 → 0.1.33

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,45 @@
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
+
17
+ export interface MockControl {
18
+ /**
19
+ * Indicates if mocking is currently active
20
+ */
21
+ isActive: boolean;
22
+ /**
23
+ * Stops all active mocks
24
+ */
25
+ stopMocking: () => void;
26
+ /**
27
+ * Adds a custom endpoint mock
28
+ * @param method - HTTP method (GET, POST, etc.)
29
+ * @param path - Endpoint path (will be appended to api.openai.com)
30
+ * @param handler - Function to handle the request and return response
31
+ */
32
+ addCustomEndpoint: (
33
+ method: string,
34
+ path: string,
35
+ handler: (uri: string, body: any) => [number, any] | Promise<[number, any]>
36
+ ) => void;
37
+ }
38
+
39
+ /**
40
+ * Sets up mocking for OpenAI API responses
41
+ * @param force - If true, forces mocking regardless of environment. If false, only mocks in development
42
+ * @param options - Configuration options for the mock behavior
43
+ * @returns Object with control methods for the mock
44
+ */
45
+ 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.33",
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
+ }