@hyperttp/interceptors 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.
- package/index.d.ts +4 -0
- package/{dist/index.d.ts.map → index.d.ts.map} +1 -1
- package/index.js +3 -0
- package/index.js.map +1 -0
- package/package.json +6 -11
- package/plugin.d.ts +15 -0
- package/plugin.d.ts.map +1 -0
- package/plugin.js +40 -0
- package/plugin.js.map +1 -0
- package/{dist/types → types}/interceptors.d.ts +5 -5
- package/types/interceptors.d.ts.map +1 -0
- package/{dist/utils → utils}/InterceptorManager.d.ts +6 -18
- package/utils/InterceptorManager.d.ts.map +1 -0
- package/{dist/utils → utils}/InterceptorManager.js +10 -14
- package/utils/InterceptorManager.js.map +1 -0
- package/LICENSE +0 -21
- package/README.md +0 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.js +0 -3
- package/dist/index.js.map +0 -1
- package/dist/plugin.d.ts +0 -17
- package/dist/plugin.d.ts.map +0 -1
- package/dist/plugin.js +0 -36
- package/dist/plugin.js.map +0 -1
- package/dist/types/interceptors.d.ts.map +0 -1
- package/dist/utils/InterceptorManager.d.ts.map +0 -1
- package/dist/utils/InterceptorManager.js.map +0 -1
- /package/{dist/types → types}/interceptors.js +0 -0
- /package/{dist/types → types}/interceptors.js.map +0 -0
package/index.d.ts
ADDED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,cAAc,+BAA+B,CAAC;AAC9C,mBAAmB,yBAAyB,CAAC"}
|
package/index.js
ADDED
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,cAAc,+BAA+B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyperttp/interceptors",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"main": "./
|
|
6
|
-
"types": "./
|
|
7
|
-
"files": [
|
|
8
|
-
"dist"
|
|
9
|
-
],
|
|
5
|
+
"main": "./index.js",
|
|
6
|
+
"types": "./index.d.ts",
|
|
10
7
|
"keywords": [
|
|
11
8
|
"hyperttp"
|
|
12
9
|
],
|
|
@@ -17,9 +14,7 @@
|
|
|
17
14
|
"url": "git+https://github.com/IT-IF-OR/hyperttp-interceptors.git"
|
|
18
15
|
},
|
|
19
16
|
"peerDependencies": {
|
|
20
|
-
"typescript": "^5"
|
|
21
|
-
|
|
22
|
-
"dependencies": {
|
|
23
|
-
"@hyperttp/core": "^1.0.5"
|
|
17
|
+
"typescript": "^5",
|
|
18
|
+
"@hyperttp/core": "^1"
|
|
24
19
|
}
|
|
25
|
-
}
|
|
20
|
+
}
|
package/plugin.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { HyperPlugin } from "@hyperttp/core";
|
|
2
|
+
import { InterceptorManager } from "./utils/InterceptorManager.js";
|
|
3
|
+
export type Method = "GET" | "POST" | "PUT" | "PATCH" | "OPTIONS" | "DELETE" | "HEAD";
|
|
4
|
+
declare module "@hyperttp/core" {
|
|
5
|
+
interface HyperCore {
|
|
6
|
+
interceptors?: InterceptorManager;
|
|
7
|
+
}
|
|
8
|
+
interface HyperttpPluginsExtension {
|
|
9
|
+
interceptors?: {
|
|
10
|
+
enabled?: boolean;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export declare function withInterceptors(): HyperPlugin;
|
|
15
|
+
//# sourceMappingURL=plugin.d.ts.map
|
package/plugin.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EAIZ,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAEnE,MAAM,MAAM,MAAM,GACd,KAAK,GACL,MAAM,GACN,KAAK,GACL,OAAO,GACP,SAAS,GACT,QAAQ,GACR,MAAM,CAAC;AAEX,OAAO,QAAQ,gBAAgB,CAAC;IAC9B,UAAU,SAAS;QACjB,YAAY,CAAC,EAAE,kBAAkB,CAAC;KACnC;IAED,UAAU,wBAAwB;QAChC,YAAY,CAAC,EAAE;YAAE,OAAO,CAAC,EAAE,OAAO,CAAA;SAAE,CAAC;KACtC;CACF;AAED,wBAAgB,gBAAgB,IAAI,WAAW,CA4C9C"}
|
package/plugin.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { InterceptorManager } from "./utils/InterceptorManager.js";
|
|
2
|
+
export function withInterceptors() {
|
|
3
|
+
let manager;
|
|
4
|
+
return {
|
|
5
|
+
name: "hyperttp-interceptors",
|
|
6
|
+
phase: "PREPARE",
|
|
7
|
+
enabled: (config) => !!config.interceptors?.enabled,
|
|
8
|
+
setup(core) {
|
|
9
|
+
manager = new InterceptorManager();
|
|
10
|
+
core.interceptors = manager;
|
|
11
|
+
},
|
|
12
|
+
wrapDispatch: (next) => {
|
|
13
|
+
return async (req) => {
|
|
14
|
+
const modifiedReqData = await manager.applyRequest({
|
|
15
|
+
url: req.url,
|
|
16
|
+
method: req.method,
|
|
17
|
+
headers: req.headers,
|
|
18
|
+
body: req.body,
|
|
19
|
+
});
|
|
20
|
+
const finalReq = {
|
|
21
|
+
...req,
|
|
22
|
+
...modifiedReqData,
|
|
23
|
+
method: (modifiedReqData.method ?? req.method),
|
|
24
|
+
};
|
|
25
|
+
const response = await next(finalReq);
|
|
26
|
+
const interceptedResponseData = await manager.applyResponse({
|
|
27
|
+
status: response.status,
|
|
28
|
+
headers: response.headers,
|
|
29
|
+
body: response.body,
|
|
30
|
+
url: response.url ?? req.url,
|
|
31
|
+
});
|
|
32
|
+
return {
|
|
33
|
+
...response,
|
|
34
|
+
...interceptedResponseData,
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=plugin.js.map
|
package/plugin.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAqBnE,MAAM,UAAU,gBAAgB;IAC9B,IAAI,OAA2B,CAAC;IAEhC,OAAO;QACL,IAAI,EAAE,uBAAuB;QAC7B,KAAK,EAAE,SAAS;QAChB,OAAO,EAAE,CAAC,MAAyB,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,YAAY,EAAE,OAAO;QAEtE,KAAK,CAAC,IAAI;YACR,OAAO,GAAG,IAAI,kBAAkB,EAAE,CAAC;YACnC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC;QAC9B,CAAC;QAED,YAAY,EAAE,CAAC,IAAI,EAAE,EAAE;YACrB,OAAO,KAAK,EAAK,GAAoB,EAA4B,EAAE;gBACjE,MAAM,eAAe,GAAG,MAAM,OAAO,CAAC,YAAY,CAAC;oBACjD,GAAG,EAAE,GAAG,CAAC,GAAG;oBACZ,MAAM,EAAE,GAAG,CAAC,MAAM;oBAClB,OAAO,EAAE,GAAG,CAAC,OAAO;oBACpB,IAAI,EAAE,GAAG,CAAC,IAAI;iBACf,CAAC,CAAC;gBAEH,MAAM,QAAQ,GAAoB;oBAChC,GAAG,GAAG;oBACN,GAAG,eAAe;oBAClB,MAAM,EAAE,CAAC,eAAe,CAAC,MAAM,IAAI,GAAG,CAAC,MAAM,CAAW;iBACzD,CAAC;gBAEF,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAI,QAAQ,CAAC,CAAC;gBAEzC,MAAM,uBAAuB,GAAG,MAAM,OAAO,CAAC,aAAa,CAAC;oBAC1D,MAAM,EAAE,QAAQ,CAAC,MAAM;oBACvB,OAAO,EAAE,QAAQ,CAAC,OAAO;oBACzB,IAAI,EAAE,QAAQ,CAAC,IAAI;oBACnB,GAAG,EAAE,QAAQ,CAAC,GAAG,IAAI,GAAG,CAAC,GAAG;iBAC7B,CAAC,CAAC;gBAEH,OAAO;oBACL,GAAG,QAAQ;oBACX,GAAG,uBAAuB;iBAC3B,CAAC;YACJ,CAAC,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
export interface InterceptorOptions {
|
|
2
2
|
/**
|
|
3
|
-
* @ru Включить
|
|
4
|
-
* @en Enable
|
|
3
|
+
* @ru Включить перехватчики
|
|
4
|
+
* @en Enable interceptors
|
|
5
5
|
*/
|
|
6
6
|
enabled?: boolean;
|
|
7
7
|
}
|
|
8
8
|
export type RequestInterceptor = (config: {
|
|
9
9
|
url: string;
|
|
10
10
|
method: string;
|
|
11
|
-
headers: Record<string, string>;
|
|
11
|
+
headers: Record<string, string | string[]>;
|
|
12
12
|
body?: any;
|
|
13
13
|
}) => any | Promise<any>;
|
|
14
14
|
export type ResponseInterceptor = (response: {
|
|
15
15
|
status: number;
|
|
16
|
-
headers: Record<string,
|
|
17
|
-
body:
|
|
16
|
+
headers: Record<string, string | string[]>;
|
|
17
|
+
body: any;
|
|
18
18
|
url: string;
|
|
19
19
|
}) => any | Promise<any>;
|
|
20
20
|
/**
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interceptors.d.ts","sourceRoot":"","sources":["../../src/types/interceptors.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,MAAM,kBAAkB,GAAG,CAAC,MAAM,EAAE;IACxC,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;IAC3C,IAAI,CAAC,EAAE,GAAG,CAAC;CACZ,KAAK,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;AAEzB,MAAM,MAAM,mBAAmB,GAAG,CAAC,QAAQ,EAAE;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;IAC3C,IAAI,EAAE,GAAG,CAAC;IACV,GAAG,EAAE,MAAM,CAAC;CACb,KAAK,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;AAEzB;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,GAAG,GAAG,IAAI,GAAG,SAAS,CAAC"}
|
|
@@ -1,60 +1,48 @@
|
|
|
1
1
|
import { RequestInterceptor, ResponseInterceptor, RequestBodyData } from "../types/interceptors.js";
|
|
2
2
|
/**
|
|
3
3
|
* @class InterceptorManager
|
|
4
|
-
* @en Manages registration and sequential execution of request and response interceptors.
|
|
5
4
|
* @ru Управляет регистрацией и последовательным выполнением перехватчиков запроса и ответа.
|
|
6
5
|
*/
|
|
7
6
|
export declare class InterceptorManager {
|
|
8
7
|
private requestInterceptors;
|
|
9
8
|
private responseInterceptors;
|
|
10
9
|
/**
|
|
11
|
-
* @en Adds a request interceptor to the chain.
|
|
12
10
|
* @ru Добавляет перехватчик запроса в цепочку.
|
|
13
|
-
* @param interceptor Function that modifies request config before execution.
|
|
14
11
|
*/
|
|
15
12
|
addRequest(interceptor: RequestInterceptor): void;
|
|
16
13
|
/**
|
|
17
|
-
* @en Adds a response interceptor to the chain.
|
|
18
14
|
* @ru Добавляет перехватчик ответа в цепочку.
|
|
19
|
-
* @param interceptor Function that modifies response after execution.
|
|
20
15
|
*/
|
|
21
16
|
addResponse(interceptor: ResponseInterceptor): void;
|
|
22
17
|
/**
|
|
23
|
-
* @en Sequentially applies all registered request interceptors.
|
|
24
18
|
* @ru Последовательно применяет все перехватчики к конфигурации запроса.
|
|
25
|
-
* @param config Initial request configuration.
|
|
26
|
-
* @returns Modified request configuration after all interceptors.
|
|
27
19
|
*/
|
|
28
20
|
applyRequest(config: {
|
|
29
21
|
url: string;
|
|
30
22
|
method: string;
|
|
31
|
-
headers: Record<string, string>;
|
|
23
|
+
headers: Record<string, string | string[]>;
|
|
32
24
|
body?: RequestBodyData;
|
|
33
25
|
}): Promise<{
|
|
34
26
|
url: string;
|
|
35
27
|
method: string;
|
|
36
|
-
headers: Record<string, string>;
|
|
28
|
+
headers: Record<string, string | string[]>;
|
|
37
29
|
body?: RequestBodyData;
|
|
38
30
|
}>;
|
|
39
31
|
/**
|
|
40
|
-
* @en Sequentially applies all registered response interceptors.
|
|
41
32
|
* @ru Последовательно применяет все перехватчики к ответу.
|
|
42
|
-
* @param response Raw HTTP response object.
|
|
43
|
-
* @returns Modified response after all interceptors.
|
|
44
33
|
*/
|
|
45
34
|
applyResponse(response: {
|
|
46
35
|
status: number;
|
|
47
|
-
headers: Record<string,
|
|
48
|
-
body:
|
|
36
|
+
headers: Record<string, string | string[]>;
|
|
37
|
+
body: any;
|
|
49
38
|
url: string;
|
|
50
39
|
}): Promise<{
|
|
51
40
|
status: number;
|
|
52
|
-
headers: Record<string,
|
|
53
|
-
body:
|
|
41
|
+
headers: Record<string, string | string[]>;
|
|
42
|
+
body: any;
|
|
54
43
|
url: string;
|
|
55
44
|
}>;
|
|
56
45
|
/**
|
|
57
|
-
* @en Removes all registered interceptors.
|
|
58
46
|
* @ru Очищает все зарегистрированные перехватчики.
|
|
59
47
|
*/
|
|
60
48
|
clear(): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InterceptorManager.d.ts","sourceRoot":"","sources":["../../src/utils/InterceptorManager.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,eAAe,EAChB,MAAM,0BAA0B,CAAC;AAElC;;;GAGG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,mBAAmB,CAA4B;IACvD,OAAO,CAAC,oBAAoB,CAA6B;IAEzD;;OAEG;IACH,UAAU,CAAC,WAAW,EAAE,kBAAkB,GAAG,IAAI;IAIjD;;OAEG;IACH,WAAW,CAAC,WAAW,EAAE,mBAAmB,GAAG,IAAI;IAInD;;OAEG;IACG,YAAY,CAAC,MAAM,EAAE;QACzB,GAAG,EAAE,MAAM,CAAC;QACZ,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;QAC3C,IAAI,CAAC,EAAE,eAAe,CAAC;KACxB;aAJM,MAAM;gBACH,MAAM;iBACL,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;eACnC,eAAe;;IAexB;;OAEG;IACG,aAAa,CAAC,QAAQ,EAAE;QAC5B,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;QAC3C,IAAI,EAAE,GAAG,CAAC;QACV,GAAG,EAAE,MAAM,CAAC;KACb;gBAJS,MAAM;iBACL,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;cACpC,GAAG;aACJ,MAAM;;IAeb;;OAEG;IACH,KAAK,IAAI,IAAI;CAId"}
|
|
@@ -1,57 +1,53 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @class InterceptorManager
|
|
3
|
-
* @en Manages registration and sequential execution of request and response interceptors.
|
|
4
3
|
* @ru Управляет регистрацией и последовательным выполнением перехватчиков запроса и ответа.
|
|
5
4
|
*/
|
|
6
5
|
export class InterceptorManager {
|
|
7
6
|
requestInterceptors = [];
|
|
8
7
|
responseInterceptors = [];
|
|
9
8
|
/**
|
|
10
|
-
* @en Adds a request interceptor to the chain.
|
|
11
9
|
* @ru Добавляет перехватчик запроса в цепочку.
|
|
12
|
-
* @param interceptor Function that modifies request config before execution.
|
|
13
10
|
*/
|
|
14
11
|
addRequest(interceptor) {
|
|
15
12
|
this.requestInterceptors.push(interceptor);
|
|
16
13
|
}
|
|
17
14
|
/**
|
|
18
|
-
* @en Adds a response interceptor to the chain.
|
|
19
15
|
* @ru Добавляет перехватчик ответа в цепочку.
|
|
20
|
-
* @param interceptor Function that modifies response after execution.
|
|
21
16
|
*/
|
|
22
17
|
addResponse(interceptor) {
|
|
23
18
|
this.responseInterceptors.push(interceptor);
|
|
24
19
|
}
|
|
25
20
|
/**
|
|
26
|
-
* @en Sequentially applies all registered request interceptors.
|
|
27
21
|
* @ru Последовательно применяет все перехватчики к конфигурации запроса.
|
|
28
|
-
* @param config Initial request configuration.
|
|
29
|
-
* @returns Modified request configuration after all interceptors.
|
|
30
22
|
*/
|
|
31
23
|
async applyRequest(config) {
|
|
32
24
|
if (this.requestInterceptors.length === 0)
|
|
33
25
|
return config;
|
|
34
26
|
let result = config;
|
|
35
27
|
for (const interceptor of this.requestInterceptors) {
|
|
36
|
-
|
|
28
|
+
const nextConfig = await interceptor(result);
|
|
29
|
+
if (nextConfig) {
|
|
30
|
+
result = nextConfig;
|
|
31
|
+
}
|
|
37
32
|
}
|
|
38
33
|
return result;
|
|
39
34
|
}
|
|
40
35
|
/**
|
|
41
|
-
* @en Sequentially applies all registered response interceptors.
|
|
42
36
|
* @ru Последовательно применяет все перехватчики к ответу.
|
|
43
|
-
* @param response Raw HTTP response object.
|
|
44
|
-
* @returns Modified response after all interceptors.
|
|
45
37
|
*/
|
|
46
38
|
async applyResponse(response) {
|
|
39
|
+
if (this.responseInterceptors.length === 0)
|
|
40
|
+
return response;
|
|
47
41
|
let result = response;
|
|
48
42
|
for (const interceptor of this.responseInterceptors) {
|
|
49
|
-
|
|
43
|
+
const nextResponse = await interceptor(result);
|
|
44
|
+
if (nextResponse) {
|
|
45
|
+
result = nextResponse;
|
|
46
|
+
}
|
|
50
47
|
}
|
|
51
48
|
return result;
|
|
52
49
|
}
|
|
53
50
|
/**
|
|
54
|
-
* @en Removes all registered interceptors.
|
|
55
51
|
* @ru Очищает все зарегистрированные перехватчики.
|
|
56
52
|
*/
|
|
57
53
|
clear() {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"InterceptorManager.js","sourceRoot":"","sources":["../../src/utils/InterceptorManager.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,MAAM,OAAO,kBAAkB;IACrB,mBAAmB,GAAyB,EAAE,CAAC;IAC/C,oBAAoB,GAA0B,EAAE,CAAC;IAEzD;;OAEG;IACH,UAAU,CAAC,WAA+B;QACxC,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAC7C,CAAC;IAED;;OAEG;IACH,WAAW,CAAC,WAAgC;QAC1C,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAC9C,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,YAAY,CAAC,MAKlB;QACC,IAAI,IAAI,CAAC,mBAAmB,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,MAAM,CAAC;QACzD,IAAI,MAAM,GAAG,MAAM,CAAC;QAEpB,KAAK,MAAM,WAAW,IAAI,IAAI,CAAC,mBAAmB,EAAE,CAAC;YACnD,MAAM,UAAU,GAAG,MAAM,WAAW,CAAC,MAAM,CAAC,CAAC;YAC7C,IAAI,UAAU,EAAE,CAAC;gBACf,MAAM,GAAG,UAAU,CAAC;YACtB,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,aAAa,CAAC,QAKnB;QACC,IAAI,IAAI,CAAC,oBAAoB,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,QAAQ,CAAC;QAC5D,IAAI,MAAM,GAAG,QAAQ,CAAC;QAEtB,KAAK,MAAM,WAAW,IAAI,IAAI,CAAC,oBAAoB,EAAE,CAAC;YACpD,MAAM,YAAY,GAAG,MAAM,WAAW,CAAC,MAAM,CAAC,CAAC;YAC/C,IAAI,YAAY,EAAE,CAAC;gBACjB,MAAM,GAAG,YAAY,CAAC;YACxB,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,mBAAmB,GAAG,EAAE,CAAC;QAC9B,IAAI,CAAC,oBAAoB,GAAG,EAAE,CAAC;IACjC,CAAC;CACF"}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 IT IF OR
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/README.md
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
# hyperttp-interceptors
|
package/dist/index.d.ts
DELETED
package/dist/index.js
DELETED
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACnE,cAAc,+BAA+B,CAAC"}
|
package/dist/plugin.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { HyperCore, HyperPlugin } from "@hyperttp/core";
|
|
2
|
-
import { InterceptorManager } from "./utils/InterceptorManager.js";
|
|
3
|
-
interface InterceptorHyperCore extends HyperCore {
|
|
4
|
-
interceptors?: InterceptorManager;
|
|
5
|
-
}
|
|
6
|
-
export type Method = "GET" | "POST" | "PUT" | "PATCH" | "OPTIONS" | "DELETE" | "HEAD";
|
|
7
|
-
export declare function withInterceptors(client: HyperCore): InterceptorHyperCore;
|
|
8
|
-
declare module "@hyperttp/core" {
|
|
9
|
-
interface HyperttpPluginsExtension {
|
|
10
|
-
interceptors?: {
|
|
11
|
-
enabled: boolean;
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
export declare const InterceptorsPlugin: HyperPlugin;
|
|
16
|
-
export {};
|
|
17
|
-
//# sourceMappingURL=plugin.d.ts.map
|
package/dist/plugin.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,WAAW,EAGZ,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAEnE,UAAU,oBAAqB,SAAQ,SAAS;IAC9C,YAAY,CAAC,EAAE,kBAAkB,CAAC;CACnC;AAED,MAAM,MAAM,MAAM,GACd,KAAK,GACL,MAAM,GACN,KAAK,GACL,OAAO,GACP,SAAS,GACT,QAAQ,GACR,MAAM,CAAC;AAEX,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,GAAG,oBAAoB,CAiCxE;AAED,OAAO,QAAQ,gBAAgB,CAAC;IAC9B,UAAU,wBAAwB;QAChC,YAAY,CAAC,EAAE;YAAE,OAAO,EAAE,OAAO,CAAA;SAAE,CAAC;KACrC;CACF;AAED,eAAO,MAAM,kBAAkB,EAAE,WAKhC,CAAC"}
|
package/dist/plugin.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { InterceptorManager } from "./utils/InterceptorManager.js";
|
|
2
|
-
export function withInterceptors(client) {
|
|
3
|
-
const manager = new InterceptorManager();
|
|
4
|
-
const originalDispatch = client.dispatch;
|
|
5
|
-
client.dispatch = async (req) => {
|
|
6
|
-
const requestUrl = typeof req.url === "string" ? req.url : req.url.getURL();
|
|
7
|
-
const modifiedReq = await manager.applyRequest({
|
|
8
|
-
url: requestUrl,
|
|
9
|
-
method: req.method,
|
|
10
|
-
headers: req.headers,
|
|
11
|
-
body: req.body,
|
|
12
|
-
});
|
|
13
|
-
const response = await originalDispatch({
|
|
14
|
-
...req,
|
|
15
|
-
...modifiedReq,
|
|
16
|
-
method: (modifiedReq.method ?? req.method),
|
|
17
|
-
});
|
|
18
|
-
const interceptedResponse = await manager.applyResponse({
|
|
19
|
-
status: response.status,
|
|
20
|
-
headers: response.headers,
|
|
21
|
-
body: response.body,
|
|
22
|
-
url: response.url ?? requestUrl,
|
|
23
|
-
});
|
|
24
|
-
return interceptedResponse;
|
|
25
|
-
};
|
|
26
|
-
const extended = client;
|
|
27
|
-
extended.interceptors = manager;
|
|
28
|
-
return extended;
|
|
29
|
-
}
|
|
30
|
-
export const InterceptorsPlugin = {
|
|
31
|
-
name: "hyperttp-interceptors",
|
|
32
|
-
phase: "PREPARE",
|
|
33
|
-
enabled: (config) => !!config.interceptors?.enabled,
|
|
34
|
-
apply: (client) => withInterceptors(client),
|
|
35
|
-
};
|
|
36
|
-
//# sourceMappingURL=plugin.js.map
|
package/dist/plugin.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAenE,MAAM,UAAU,gBAAgB,CAAC,MAAiB;IAChD,MAAM,OAAO,GAAG,IAAI,kBAAkB,EAAE,CAAC;IACzC,MAAM,gBAAgB,GAAG,MAAM,CAAC,QAAQ,CAAC;IAEzC,MAAM,CAAC,QAAQ,GAAG,KAAK,EAAK,GAAoB,EAAc,EAAE;QAC9D,MAAM,UAAU,GAAG,OAAO,GAAG,CAAC,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;QAE5E,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC,YAAY,CAAC;YAC7C,GAAG,EAAE,UAAU;YACf,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,IAAI,EAAE,GAAG,CAAC,IAAI;SACf,CAAC,CAAC;QAEH,MAAM,QAAQ,GAAG,MAAM,gBAAgB,CAAC;YACtC,GAAG,GAAG;YACN,GAAG,WAAW;YACd,MAAM,EAAE,CAAC,WAAW,CAAC,MAAM,IAAI,GAAG,CAAC,MAAM,CAAW;SACrD,CAAC,CAAC;QAEH,MAAM,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ACH,KAAK,IAAI,IAAI;CAId"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"InterceptorManager.js","sourceRoot":"","sources":["../../src/utils/InterceptorManager.ts"],"names":[],"mappings":"AAMA;;;;GAIG;AACH,MAAM,OAAO,kBAAkB;IACrB,mBAAmB,GAAyB,EAAE,CAAC;IAC/C,oBAAoB,GAA0B,EAAE,CAAC;IAEzD;;;;OAIG;IACH,UAAU,CAAC,WAA+B;QACxC,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAC7C,CAAC;IAED;;;;OAIG;IACH,WAAW,CAAC,WAAgC;QAC1C,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAC9C,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,YAAY,CAAC,MAKlB;QACC,IAAI,IAAI,CAAC,mBAAmB,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,MAAM,CAAC;QACzD,IAAI,MAAM,GAAG,MAAM,CAAC;QAEpB,KAAK,MAAM,WAAW,IAAI,IAAI,CAAC,mBAAmB,EAAE,CAAC;YACnD,MAAM,GAAG,MAAM,WAAW,CAAC,MAAM,CAAC,CAAC;QACrC,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,aAAa,CAAC,QAKnB;QACC,IAAI,MAAM,GAAG,QAAQ,CAAC;QAEtB,KAAK,MAAM,WAAW,IAAI,IAAI,CAAC,oBAAoB,EAAE,CAAC;YACpD,MAAM,GAAG,MAAM,WAAW,CAAC,MAAM,CAAC,CAAC;QACrC,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;;OAGG;IACH,KAAK;QACH,IAAI,CAAC,mBAAmB,GAAG,EAAE,CAAC;QAC9B,IAAI,CAAC,oBAAoB,GAAG,EAAE,CAAC;IACjC,CAAC;CACF"}
|
|
File without changes
|
|
File without changes
|