nuxt-custom-fetch 2.1.1 → 2.1.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
@@ -71,25 +71,6 @@ export declare class CustomFetch {
71
71
  post<DataT, ErrorT = Error | null>(url: NitroFetchRequest, config?: HTTPConfig, options?: AsyncDataOptions<DataT>): CustomFetchReturnValue<DataT, ErrorT>
72
72
  }
73
73
 
74
- export interface OnRequestType {
75
- request: FetchRequest
76
- options: FetchOptions
77
- }
78
- export interface OnRequestErrorType {
79
- request: FetchRequest
80
- options: FetchOptions
81
- error: FetchError
82
- }
83
- export interface OnResponseType {
84
- request: FetchRequest
85
- options: FetchOptions
86
- response: FetchResponse<any>
87
- }
88
- export interface OnResponseErrorType {
89
- request: FetchRequest
90
- options: FetchOptions
91
- response: FetchResponse<any>
92
- }
93
74
  export type FetchMethod = 'options' | 'GET' | 'POST' | 'get' | 'HEAD' | 'PATCH' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'post' | 'head' | 'patch' | 'put' | 'delete' | 'connect' | 'trace' | undefined
94
75
  export interface HTTPConfig extends Omit<FetchOptions, 'method'> {
95
76
  key?: string
package/dist/module.d.mts CHANGED
@@ -2,6 +2,6 @@ import * as _nuxt_schema from '@nuxt/schema';
2
2
 
3
3
  interface ModuleOptions {
4
4
  }
5
- declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;
5
+ declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
6
6
 
7
7
  export { type ModuleOptions, _default as default };
package/dist/module.d.ts CHANGED
@@ -2,6 +2,6 @@ import * as _nuxt_schema from '@nuxt/schema';
2
2
 
3
3
  interface ModuleOptions {
4
4
  }
5
- declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;
5
+ declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
6
6
 
7
7
  export { type ModuleOptions, _default as default };
package/dist/module.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "nuxt-custom-fetch",
3
3
  "configKey": "customFetch",
4
- "version": "2.1.1",
4
+ "version": "2.1.2",
5
5
  "builder": {
6
- "@nuxt/module-builder": "0.7.0",
6
+ "@nuxt/module-builder": "0.8.4",
7
7
  "unbuild": "unknown"
8
8
  }
9
9
  }
@@ -1,5 +1,5 @@
1
- import { hash } from "ohash";
2
1
  import { createError, reactive, ref, toValue, unref, useAsyncData, useNuxtApp } from "#imports";
2
+ import { hash } from "ohash";
3
3
  function Noop() {
4
4
  }
5
5
  function generateOptionSegments(opts) {
@@ -64,7 +64,7 @@ export class CustomFetch {
64
64
  config.baseURL = config?.baseURL || this.baseURL;
65
65
  Object.assign(config, this.baseConfig(config));
66
66
  const { onRequest, onRequestError, onResponse, onResponseError, offline, handler, useHandler, immutableKey, ...restAjaxConfig } = config;
67
- if (process.client && navigator && !navigator.onLine) {
67
+ if (import.meta.client && navigator && !navigator.onLine) {
68
68
  if (offline) {
69
69
  offline();
70
70
  }
@@ -73,29 +73,48 @@ export class CustomFetch {
73
73
  const _config = reactive({ ...restAjaxConfig });
74
74
  const defaultOptions = {
75
75
  onRequest(ctx) {
76
- [interceptors.onRequest, onRequest].forEach((fn) => fn?.(ctx));
76
+ [interceptors.onRequest, onRequest].forEach((fns) => {
77
+ if (Array.isArray(fns)) {
78
+ fns.forEach((fn) => fn?.(ctx));
79
+ } else {
80
+ fns?.(ctx);
81
+ }
82
+ });
77
83
  },
78
84
  onRequestError(ctx) {
79
- [interceptors.onRequestError, onRequestError].forEach((fn) => fn?.(ctx));
85
+ [interceptors.onRequestError, onRequestError].forEach((fns) => {
86
+ if (Array.isArray(fns)) {
87
+ fns.forEach((fn) => fn?.(ctx));
88
+ } else {
89
+ fns?.(ctx);
90
+ }
91
+ });
80
92
  throw createError({
81
- statusCode: ctx.error.statusCode,
93
+ statusCode: 400,
82
94
  statusMessage: ctx.error.message,
83
95
  message: ctx.error.message,
84
96
  fatal: true
85
97
  });
86
98
  },
87
99
  onResponse(ctx) {
88
- if (interceptors.onResponse) {
89
- interceptors.onResponse(ctx);
90
- }
91
- if (onResponse) {
92
- onResponse(ctx);
93
- }
100
+ [interceptors.onResponse, onResponse].forEach((fns) => {
101
+ if (Array.isArray(fns)) {
102
+ fns.forEach((fn) => fn?.(ctx));
103
+ } else {
104
+ fns?.(ctx);
105
+ }
106
+ });
94
107
  },
95
108
  onResponseError(ctx) {
96
- [interceptors.onResponseError, onResponseError].forEach((fn) => fn?.(ctx));
109
+ [interceptors.onResponseError, onResponseError].forEach((fns) => {
110
+ if (Array.isArray(fns)) {
111
+ fns.forEach((fn) => fn?.(ctx));
112
+ } else {
113
+ fns?.(ctx);
114
+ }
115
+ });
97
116
  throw createError({
98
- statusCode: ctx.response.status,
117
+ statusCode: 500,
99
118
  statusMessage: ctx.request.toString(),
100
119
  message: ctx.response._data,
101
120
  fatal: true
@@ -1,29 +1,12 @@
1
- import type { FetchError, FetchOptions, FetchRequest, FetchResponse } from 'ofetch';
1
+ import type { FetchOptions } from 'ofetch';
2
+ export type { FetchContext, FetchResponse } from 'ofetch';
2
3
  export type PickFrom<T, K extends Array<string>> = T extends Array<any> ? T : T extends Record<string, any> ? (keyof T extends K[number] ? T : K[number] extends never ? T : Pick<T, K[number]>) : T;
3
4
  export type KeysOf<T> = Array<T extends T ? (keyof T extends string ? keyof T : never) : never>;
4
- export interface OnRequestType {
5
- request: FetchRequest;
6
- options: FetchOptions;
7
- }
8
- export interface OnRequestErrorType {
9
- request: FetchRequest;
10
- options: FetchOptions;
11
- error: FetchError;
12
- }
13
- export interface OnResponseType {
14
- request: FetchRequest;
15
- options: FetchOptions;
16
- response: FetchResponse<any>;
17
- }
18
- export interface OnResponseErrorType {
19
- request: FetchRequest;
20
- options: FetchOptions;
21
- response: FetchResponse<any>;
22
- }
23
5
  export type FetchMethod = 'options' | 'GET' | 'POST' | 'get' | 'HEAD' | 'PATCH' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'post' | 'head' | 'patch' | 'put' | 'delete' | 'connect' | 'trace' | undefined;
24
6
  export interface HTTPConfig extends Omit<FetchOptions, 'method'> {
25
7
  key?: string;
26
8
  immutableKey?: boolean;
9
+ interceptors?: Interceptors;
27
10
  baseURL?: string;
28
11
  useHandler?: boolean;
29
12
  handler?: (params: Record<string, any>) => Record<string, any>;
package/dist/types.d.mts CHANGED
@@ -1,16 +1 @@
1
-
2
- import type { ModuleOptions } from './module.js'
3
-
4
-
5
- declare module '@nuxt/schema' {
6
- interface NuxtConfig { ['customFetch']?: Partial<ModuleOptions> }
7
- interface NuxtOptions { ['customFetch']?: ModuleOptions }
8
- }
9
-
10
- declare module 'nuxt/schema' {
11
- interface NuxtConfig { ['customFetch']?: Partial<ModuleOptions> }
12
- interface NuxtOptions { ['customFetch']?: ModuleOptions }
13
- }
14
-
15
-
16
- export type { ModuleOptions, default } from './module.js'
1
+ export { type ModuleOptions, default } from './module.js'
package/dist/types.d.ts CHANGED
@@ -1,16 +1 @@
1
-
2
- import type { ModuleOptions } from './module'
3
-
4
-
5
- declare module '@nuxt/schema' {
6
- interface NuxtConfig { ['customFetch']?: Partial<ModuleOptions> }
7
- interface NuxtOptions { ['customFetch']?: ModuleOptions }
8
- }
9
-
10
- declare module 'nuxt/schema' {
11
- interface NuxtConfig { ['customFetch']?: Partial<ModuleOptions> }
12
- interface NuxtOptions { ['customFetch']?: ModuleOptions }
13
- }
14
-
15
-
16
- export type { ModuleOptions, default } from './module'
1
+ export { type ModuleOptions, default } from './module'
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-custom-fetch",
3
3
  "type": "module",
4
- "version": "2.1.1",
4
+ "version": "2.1.2",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -22,7 +22,7 @@
22
22
  "prepack": "nuxt-module-build build",
23
23
  "dev": "nuxi dev playground",
24
24
  "dev:build": "nuxi build playground",
25
- "dev:prepare": "nuxt-module-build --stub && nuxi prepare playground",
25
+ "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
26
26
  "echo:husky": "echo 'npx lint-staged' > .husky/pre-commit && echo 'npx --no-install commitlint --edit \"$1\"' > .husky/commit-msg",
27
27
  "lint": "eslint .",
28
28
  "lint:fix": "eslint . --fix",
@@ -36,24 +36,24 @@
36
36
  }
37
37
  },
38
38
  "dependencies": {
39
- "@nuxt/kit": "^3.12.1",
40
- "ohash": "^1.1.3",
41
- "typescript": "^5.4.5"
39
+ "@nuxt/kit": "^3.14.1592",
40
+ "ohash": "^1.1.4"
42
41
  },
43
42
  "devDependencies": {
44
- "@antfu/eslint-config": "^2.21.1",
45
- "@commitlint/cli": "^19.3.0",
46
- "@commitlint/config-conventional": "^19.2.2",
47
- "@nuxt/module-builder": "^0.7.1",
48
- "@nuxt/schema": "^3.12.1",
49
- "@types/node": "^20.14.2",
50
- "changelogen": "^0.5.5",
51
- "commitizen": "^4.3.0",
52
- "cz-git": "^1.9.3",
53
- "eslint": "^9.4.0",
54
- "husky": "^9.0.11",
55
- "lint-staged": "^15.2.7",
56
- "nuxt": "^3.12.1"
43
+ "@antfu/eslint-config": "^3.11.2",
44
+ "@commitlint/cli": "^19.6.0",
45
+ "@commitlint/config-conventional": "^19.6.0",
46
+ "@nuxt/module-builder": "^0.8.4",
47
+ "@nuxt/schema": "^3.14.1592",
48
+ "@types/node": "^22.10.1",
49
+ "changelogen": "^0.5.7",
50
+ "commitizen": "^4.3.1",
51
+ "cz-git": "^1.11.0",
52
+ "eslint": "^9.16.0",
53
+ "husky": "^9.1.7",
54
+ "lint-staged": "^15.2.10",
55
+ "nuxt": "^3.14.1592",
56
+ "typescript": "^5.6.3"
57
57
  },
58
58
  "husky": {
59
59
  "hooks": {