nuxt-custom-fetch 2.3.0 → 2.3.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.
package/README.md CHANGED
@@ -100,6 +100,7 @@ export const getInfo = (params: Record<string, any>) =>
100
100
  ```ts
101
101
  // index.vue
102
102
  import { getInfo } from './ajax'
103
+
103
104
  const { data, error, pending } = await getInfo({
104
105
  sign: 123
105
106
  })
package/dist/module.d.mts CHANGED
@@ -4,4 +4,5 @@ interface ModuleOptions {
4
4
  }
5
5
  declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
6
6
 
7
- export { type ModuleOptions, _default as default };
7
+ export { _default as default };
8
+ export type { ModuleOptions };
package/dist/module.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "nuxt-custom-fetch",
3
3
  "configKey": "customFetch",
4
- "version": "2.3.0",
4
+ "version": "2.3.2",
5
5
  "builder": {
6
- "@nuxt/module-builder": "0.8.4",
6
+ "@nuxt/module-builder": "1.0.1",
7
7
  "unbuild": "unknown"
8
8
  }
9
9
  }
@@ -69,9 +69,15 @@ export class CustomFetch {
69
69
  Object.assign(config, this.baseConfig(config));
70
70
  const generateOptionSegmentsWithConfig = generateOptionSegments(config);
71
71
  if (this.showLogs && import.meta.client) {
72
- console.warn("[Custom Fetch] `Request:`", url, " `Query:`", serialize(generateOptionSegmentsWithConfig), " `Body:`", serialize(config.body));
72
+ let bodyLogs;
73
+ try {
74
+ bodyLogs = serialize(config.body);
75
+ } catch (error) {
76
+ console.warn("[Custom Fetch] couldn't serialize `Body:`", error);
77
+ }
78
+ console.warn("[Custom Fetch] `Request:`", url, " `Query:`", serialize(generateOptionSegmentsWithConfig), " `Body:`", bodyLogs);
73
79
  }
74
- const { onRequest, onRequestError, onResponse, onResponseError, offline, handler, useHandler, immutableKey, ...restAjaxConfig } = config;
80
+ const { onRequest, onRequestError, onResponse, onResponseError, offline, handler, useHandler, showLogs, immutableKey, ...restAjaxConfig } = config;
75
81
  if (import.meta.client && navigator && !navigator.onLine) {
76
82
  if (offline) {
77
83
  offline();
@@ -80,53 +86,37 @@ export class CustomFetch {
80
86
  const interceptors = this.interceptors;
81
87
  const _config = reactive({ ...restAjaxConfig });
82
88
  const defaultOptions = {
83
- onRequest(ctx) {
84
- [interceptors.onRequest, onRequest].forEach((fns) => {
85
- if (Array.isArray(fns)) {
86
- fns.forEach((fn) => fn?.(ctx));
87
- } else {
88
- fns?.(ctx);
89
+ async onRequest(ctx) {
90
+ const allFns = [interceptors.onRequest, onRequest].flat();
91
+ for (const fn of allFns) {
92
+ if (fn) {
93
+ await fn(ctx);
89
94
  }
90
- });
95
+ }
91
96
  },
92
- onRequestError(ctx) {
93
- [interceptors.onRequestError, onRequestError].forEach((fns) => {
94
- if (Array.isArray(fns)) {
95
- fns.forEach((fn) => fn?.(ctx));
96
- } else {
97
- fns?.(ctx);
97
+ async onRequestError(ctx) {
98
+ const allFns = [interceptors.onRequestError, onRequestError].flat();
99
+ for (const fn of allFns) {
100
+ if (fn) {
101
+ await fn(ctx);
98
102
  }
99
- });
100
- throw createError({
101
- statusCode: 400,
102
- statusMessage: ctx.error.message,
103
- message: ctx.error.message,
104
- fatal: true
105
- });
103
+ }
106
104
  },
107
- onResponse(ctx) {
108
- [interceptors.onResponse, onResponse].forEach((fns) => {
109
- if (Array.isArray(fns)) {
110
- fns.forEach((fn) => fn?.(ctx));
111
- } else {
112
- fns?.(ctx);
105
+ async onResponse(ctx) {
106
+ const allFns = [interceptors.onResponse, onResponse].flat();
107
+ for (const fn of allFns) {
108
+ if (fn) {
109
+ await fn(ctx);
113
110
  }
114
- });
111
+ }
115
112
  },
116
- onResponseError(ctx) {
117
- [interceptors.onResponseError, onResponseError].forEach((fns) => {
118
- if (Array.isArray(fns)) {
119
- fns.forEach((fn) => fn?.(ctx));
120
- } else {
121
- fns?.(ctx);
113
+ async onResponseError(ctx) {
114
+ const allFns = [interceptors.onResponseError, onResponseError].flat();
115
+ for (const fn of allFns) {
116
+ if (fn) {
117
+ await fn(ctx);
122
118
  }
123
- });
124
- throw createError({
125
- statusCode: 500,
126
- statusMessage: ctx.request.toString(),
127
- message: ctx.response._data,
128
- fatal: true
129
- });
119
+ }
130
120
  }
131
121
  };
132
122
  const hashValue = ["custom_fetch:", url];
package/dist/types.d.mts CHANGED
@@ -1 +1,3 @@
1
- export { type ModuleOptions, default } from './module.js'
1
+ export { default } from './module.mjs'
2
+
3
+ export { type ModuleOptions } from './module.mjs'
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-custom-fetch",
3
3
  "type": "module",
4
- "version": "2.3.0",
4
+ "version": "2.3.2",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -9,12 +9,11 @@
9
9
  },
10
10
  "exports": {
11
11
  ".": {
12
- "import": "./dist/module.mjs",
13
- "require": "./dist/module.cjs"
12
+ "import": "./dist/module.mjs"
14
13
  }
15
14
  },
16
- "main": "./dist/module.cjs",
17
- "types": "./dist/types.d.ts",
15
+ "main": "./dist/module.mjs",
16
+ "types": "./dist/types.d.mts",
18
17
  "files": [
19
18
  "dist"
20
19
  ],
@@ -36,25 +35,25 @@
36
35
  }
37
36
  },
38
37
  "dependencies": {
39
- "@nuxt/kit": "^3.16.1",
38
+ "@nuxt/kit": "^3.16.2",
40
39
  "ohash": "^2.0.11"
41
40
  },
42
41
  "devDependencies": {
43
- "@antfu/eslint-config": "^4.10.1",
42
+ "@antfu/eslint-config": "^4.12.0",
44
43
  "@commitlint/cli": "^19.8.0",
45
44
  "@commitlint/config-conventional": "^19.8.0",
46
- "@nuxt/module-builder": "^0.8.4",
47
- "@nuxt/schema": "^3.16.1",
48
- "@types/node": "^22.13.10",
45
+ "@nuxt/module-builder": "^1.0.1",
46
+ "@nuxt/schema": "^3.16.2",
47
+ "@types/node": "^22.14.1",
49
48
  "changelogen": "^0.6.1",
50
49
  "commitizen": "^4.3.1",
51
50
  "cz-git": "^1.11.1",
52
- "eslint": "^9.22.0",
51
+ "eslint": "^9.24.0",
53
52
  "husky": "^9.1.7",
54
- "lint-staged": "^15.5.0",
53
+ "lint-staged": "^15.5.1",
55
54
  "nitro": "npm:nitropack",
56
- "nuxt": "^3.16.1",
57
- "typescript": "5.8.2"
55
+ "nuxt": "^3.16.2",
56
+ "typescript": "5.8.3"
58
57
  },
59
58
  "husky": {
60
59
  "hooks": {
package/dist/module.cjs DELETED
@@ -1,5 +0,0 @@
1
- module.exports = function(...args) {
2
- return import('./module.mjs').then(m => m.default.call(this, ...args))
3
- }
4
- const _meta = module.exports.meta = require('./module.json')
5
- module.exports.getMeta = () => Promise.resolve(_meta)
package/dist/module.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import * as _nuxt_schema from '@nuxt/schema';
2
-
3
- interface ModuleOptions {
4
- }
5
- declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
6
-
7
- export { type ModuleOptions, _default as default };
package/dist/types.d.ts DELETED
@@ -1 +0,0 @@
1
- export { type ModuleOptions, default } from './module'