auravia-connect 1.0.0 → 1.0.2

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.
@@ -6,6 +6,7 @@ type ClientConfig = {
6
6
  mockFallback?: boolean;
7
7
  debug?: boolean;
8
8
  mockStrategy?: "prefer-mock" | "prefer-network";
9
+ autoMock?: boolean;
9
10
  };
10
11
  type ApiResponse<T = any> = {
11
12
  ok: boolean;
@@ -2,6 +2,27 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createClient = createClient;
4
4
  function createClient(defaultConfig = {}) {
5
+ // ===============================
6
+ // 🔥 AUTO MOCK GENERATOR
7
+ // ===============================
8
+ function generateAutoMock(url) {
9
+ // simple intelligent guess
10
+ if (url.includes("/users")) {
11
+ return {
12
+ id: generators.number(),
13
+ name: generators.text(),
14
+ active: generators.boolean()
15
+ };
16
+ }
17
+ if (url.includes("/status")) {
18
+ return { status: "ok" };
19
+ }
20
+ // default fallback
21
+ return {
22
+ id: generators.number(),
23
+ message: generators.text()
24
+ };
25
+ }
5
26
  // ===============================
6
27
  // 🔥 INTERCEPTORS
7
28
  // ===============================
@@ -207,6 +228,24 @@ function createClient(defaultConfig = {}) {
207
228
  }
208
229
  debugLog("✗ request failed");
209
230
  debugLog("⏱", Date.now() - startTime + "ms");
231
+ // ===============================
232
+ // 🔥 AUTO MOCK MODE
233
+ // ===============================
234
+ if (defaultConfig.autoMock) {
235
+ debugLog("⚡ auto mock generated");
236
+ let data = generateAutoMock(config.url);
237
+ let autoResponse = {
238
+ ok: true,
239
+ status: 200,
240
+ data,
241
+ error: null
242
+ };
243
+ for (const interceptor of responseInterceptors) {
244
+ autoResponse = await interceptor.fn(autoResponse);
245
+ }
246
+ debugLog("⏱", Date.now() - startTime + "ms");
247
+ return autoResponse;
248
+ }
210
249
  return {
211
250
  ok: false,
212
251
  status: 500,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "auravia-connect",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Smart frontend-backend connector with built-in mocking and fallback",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -8,12 +8,15 @@
8
8
  "files": [
9
9
  "dist"
10
10
  ],
11
+
11
12
  "exports": {
12
- ".": {
13
- "require": "./dist/index.js",
14
- "types": "./dist/index.d.ts"
15
- }
16
- },
13
+ ".": {
14
+ "require": "./dist/index.js",
15
+ "import": "./dist/index.js",
16
+ "default": "./dist/index.js",
17
+ "types": "./dist/index.d.ts"
18
+ }
19
+ },
17
20
  "scripts": {
18
21
  "build": "tsc"
19
22
  },