@bereasoftware/nexa 1.2.0 → 1.3.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bereasoftware/nexa",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "type": "module",
5
5
  "main": "./dist/nexa.cjs.js",
6
6
  "module": "./dist/nexa.es.js",
@@ -16,12 +16,6 @@
16
16
  "import": "./dist/nexa.es.js",
17
17
  "require": "./dist/nexa.cjs.js",
18
18
  "default": "./dist/nexa.umd.js"
19
- },
20
- "./testing": {
21
- "types": "./dist/types/index.d.ts",
22
- "import": "./dist/nexa.es.js",
23
- "require": "./dist/nexa.cjs.js",
24
- "default": "./dist/nexa.umd.js"
25
19
  }
26
20
  },
27
21
  "files": [
@@ -31,6 +25,7 @@
31
25
  "registry": "https://registry.npmjs.org/",
32
26
  "access": "public"
33
27
  },
28
+ "packageManager": "pnpm@10.21.0",
34
29
  "keywords": [
35
30
  "http",
36
31
  "client",
@@ -53,8 +48,6 @@
53
48
  "author": "John Andrade <johnandrade@bereasoft.com>",
54
49
  "license": "MIT",
55
50
  "description": "Nexa is a TypeScript HTTP client library that combines the power of fetch with the convenience of axios, while adhering to SOLID principles. It provides a flexible and extensible API for making HTTP requests, handling retries, caching, and more.",
56
- "about": "Nexa is designed to be a modern, type-safe HTTP client that simplifies the process of making API requests in TypeScript. It offers features such as request and response interceptors, automatic retries with exponential backoff, caching mechanisms, and a result type for better error handling. With support for both ESM and CommonJS, Nexa can be easily integrated into any TypeScript project.",
57
- "homepage": "https://github.com/Berea-Soft/nexa",
58
51
  "maintainers": [
59
52
  {
60
53
  "name": "John Andrade",
@@ -79,32 +72,45 @@
79
72
  "> 1%"
80
73
  ],
81
74
  "scripts": {
82
- "dev": "vite",
83
- "build": "tsc && vite build",
75
+ "dev": "vite --config playground/vite.config.ts",
76
+ "build": "tsc -p tsconfig.build.json && vite build",
84
77
  "test": "vitest run",
85
78
  "test:watch": "vitest",
86
79
  "test:ui": "vitest --ui",
87
80
  "test:coverage": "vitest run --coverage",
88
- "lint": "tsc --noEmit",
89
- "prepublishOnly": "npm run build"
81
+ "lint": "eslint \"src/**/*.ts\" --max-warnings=0",
82
+ "lint:fix": "eslint \"src/**/*.ts\" --fix",
83
+ "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
84
+ "format:check": "prettier --check \"src/**/*.ts\" \"test/**/*.ts\"",
85
+ "typecheck": "tsc --noEmit",
86
+ "benchmark": "node scripts/benchmark.mjs",
87
+ "prepare": "echo \"husky ready\"",
88
+ "prepublishOnly": "pnpm build"
90
89
  },
91
90
  "devDependencies": {
92
- "@microsoft/api-extractor": "^7.58.5",
93
91
  "@semantic-release/changelog": "^6.0.3",
94
92
  "@semantic-release/git": "^10.0.1",
95
93
  "@semantic-release/github": "^12.0.6",
96
94
  "@semantic-release/npm": "^13.1.5",
97
- "@types/cookie-parser": "^1.4.10",
98
- "@types/node": "^25.6.0",
99
- "@vitest/coverage-v8": "^4.1.4",
100
- "@vitest/ui": "^4.1.4",
95
+ "@types/node": "^25.5.0",
96
+ "@typescript-eslint/eslint-plugin": "^8.0.0",
97
+ "@typescript-eslint/parser": "^8.0.0",
98
+ "@vitest/coverage-v8": "^4.1.2",
99
+ "@vitest/ui": "^4.1.2",
100
+ "eslint": "^9.0.0",
101
+ "husky": "^9.0.0",
102
+ "lint-staged": "^15.0.0",
103
+ "prettier": "^3.0.0",
101
104
  "semantic-release": "^25.0.3",
102
- "typescript": "~6.0.3",
103
- "vite": "^8.0.8",
104
- "vite-plugin-dts": "^4.5.4",
105
- "vitest": "^4.1.4"
105
+ "typescript": "~6.0.2",
106
+ "vite": "^8.0.3",
107
+ "vitest": "^4.1.2"
108
+ },
109
+ "lint-staged": {
110
+ "*.ts": [
111
+ "prettier --write",
112
+ "eslint --fix --max-warnings=0"
113
+ ]
106
114
  },
107
- "dependencies": {
108
- "npm": "^11.12.1"
109
- }
115
+ "dependencies": {}
110
116
  }
Binary file
@@ -1,5 +0,0 @@
1
- /**
2
- * Testing utilities for Nexa HTTP Client
3
- */
4
- export { createMockClient, MockAdapter } from './mock-client.js';
5
- export type { MockResponse, MockClientOptions } from './mock-client.js';
@@ -1,152 +0,0 @@
1
- import { IHttpClient, HttpRequestConfig } from '../types/index.js';
2
- /**
3
- * Configuration for a mocked response
4
- */
5
- export interface MockResponse {
6
- /** HTTP status code (default: 200) */
7
- status?: number;
8
- /** HTTP status text (default: 'OK') */
9
- statusText?: string;
10
- /** Response headers (default: { 'content-type': 'application/json' }) */
11
- headers?: Record<string, string>;
12
- /** Response body (will be JSON.stringified if object/array) */
13
- data?: any;
14
- /** Optional delay in milliseconds before responding */
15
- delay?: number;
16
- /** Throw a network error instead of returning a response */
17
- networkError?: boolean;
18
- /** Error message for network error */
19
- errorMessage?: string;
20
- }
21
- /**
22
- * Options for creating a mock client
23
- */
24
- export interface MockClientOptions {
25
- /** Base URL to match against (optional) */
26
- baseURL?: string;
27
- /** Default delay for all responses (optional) */
28
- delay?: number;
29
- /** Whether to pass through unmatched requests to original adapter (default: false) */
30
- passthrough?: boolean;
31
- }
32
- /**
33
- * Route builder returned by onGet(), onPost(), etc.
34
- * Allows fluent API like mockAdapter.onGet('/users').reply(200, users)
35
- */
36
- declare class RouteBuilder {
37
- private adapter;
38
- private method;
39
- private urlPattern;
40
- constructor(adapter: MockAdapter, method: string, urlPattern: string | RegExp);
41
- /**
42
- * Configure a response for this route
43
- */
44
- reply(status: number, data?: any, headers?: Record<string, string>): MockAdapter;
45
- reply(response: MockResponse): MockAdapter;
46
- /**
47
- * Configure a response that will only be used once
48
- */
49
- replyOnce(status: number, data?: any, headers?: Record<string, string>): MockAdapter;
50
- replyOnce(response: MockResponse): MockAdapter;
51
- /**
52
- * Configure a network error for this route
53
- */
54
- networkError(errorMessage?: string): MockAdapter;
55
- /**
56
- * Configure a timeout error for this route
57
- */
58
- timeout(): MockAdapter;
59
- }
60
- /**
61
- * Mock adapter that intercepts HTTP requests and returns configured responses.
62
- * Similar to axios-mock-adapter.
63
- */
64
- export declare class MockAdapter {
65
- private routes;
66
- private originalAdapter?;
67
- private mockClient;
68
- private options;
69
- private defaultResponse;
70
- /**
71
- * Create a new MockAdapter and attach it to a client.
72
- * The original client is not modified. Instead, a new client with the mock adapter is created.
73
- * Use the `client` property to access the mock-enabled client.
74
- */
75
- constructor(client: IHttpClient, options?: MockClientOptions);
76
- /**
77
- * Get the mock-enabled client
78
- */
79
- get client(): IHttpClient;
80
- /**
81
- * Create a mock adapter that can be used as a standalone adapter.
82
- * This adapter can be set on any HttpClient via config.adapter.
83
- */
84
- createAdapter(): (input: RequestInfo, init?: RequestInit) => Promise<Response>;
85
- /**
86
- * Add a route for GET requests
87
- */
88
- onGet(urlPattern: string | RegExp): RouteBuilder;
89
- /**
90
- * Add a route for POST requests
91
- */
92
- onPost(urlPattern: string | RegExp): RouteBuilder;
93
- /**
94
- * Add a route for PUT requests
95
- */
96
- onPut(urlPattern: string | RegExp): RouteBuilder;
97
- /**
98
- * Add a route for PATCH requests
99
- */
100
- onPatch(urlPattern: string | RegExp): RouteBuilder;
101
- /**
102
- * Add a route for DELETE requests
103
- */
104
- onDelete(urlPattern: string | RegExp): RouteBuilder;
105
- /**
106
- * Add a route for any HTTP method
107
- */
108
- onAny(urlPattern: string | RegExp): RouteBuilder;
109
- /**
110
- * Add a route with a specific HTTP method and response
111
- */
112
- addRoute(method: string, urlPattern: string | RegExp, response: MockResponse | ((config: HttpRequestConfig) => MockResponse | Promise<MockResponse>), options?: {
113
- times?: number;
114
- }): this;
115
- /**
116
- * Reset all mock routes
117
- */
118
- reset(): void;
119
- /**
120
- * Restore original adapter (if any)
121
- */
122
- restore(): void;
123
- /**
124
- * Helper to create a response configuration
125
- */
126
- static reply(status: number, data?: any, headers?: Record<string, string>): MockResponse;
127
- /**
128
- * Helper to create a network error response
129
- */
130
- static networkError(message?: string): MockResponse;
131
- private findMatchingRoute;
132
- }
133
- /**
134
- * Create a mock client with axios-mock-adapter-like API
135
- *
136
- * @example
137
- * ```typescript
138
- * import { createHttpClient } from '@bereasoftware/nexa';
139
- * import { createMockClient } from '@bereasoftware/nexa/testing';
140
- *
141
- * const client = createHttpClient({ baseURL: 'https://api.example.com' });
142
- * const mockClient = createMockClient(client);
143
- *
144
- * mockClient.onGet('/users').reply(200, [{ id: 1 }]);
145
- * mockClient.onPost('/users').reply(201, { id: 2 });
146
- *
147
- * // Use mockClient.client for making requests
148
- * const result = await mockClient.client.get('/users');
149
- * ```
150
- */
151
- export declare function createMockClient(client: IHttpClient, options?: MockClientOptions): MockAdapter;
152
- export {};