recker 1.0.2-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/LICENSE +21 -0
- package/README.md +109 -0
- package/dist/cache/file-storage.d.ts +13 -0
- package/dist/cache/file-storage.d.ts.map +1 -0
- package/dist/cache/file-storage.js +50 -0
- package/dist/cache/memory-storage.d.ts +10 -0
- package/dist/cache/memory-storage.d.ts.map +1 -0
- package/dist/cache/memory-storage.js +29 -0
- package/dist/cache/redis-storage.d.ts +16 -0
- package/dist/cache/redis-storage.d.ts.map +1 -0
- package/dist/cache/redis-storage.js +25 -0
- package/dist/constants.d.ts +19 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +18 -0
- package/dist/contract/index.d.ts +32 -0
- package/dist/contract/index.d.ts.map +1 -0
- package/dist/contract/index.js +67 -0
- package/dist/core/client.d.ts +107 -0
- package/dist/core/client.d.ts.map +1 -0
- package/dist/core/client.js +475 -0
- package/dist/core/errors.d.ts +19 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +34 -0
- package/dist/core/request-promise.d.ts +24 -0
- package/dist/core/request-promise.d.ts.map +1 -0
- package/dist/core/request-promise.js +77 -0
- package/dist/core/request.d.ts +15 -0
- package/dist/core/request.d.ts.map +1 -0
- package/dist/core/request.js +44 -0
- package/dist/core/response.d.ts +33 -0
- package/dist/core/response.d.ts.map +1 -0
- package/dist/core/response.js +154 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +39 -0
- package/dist/mcp/client.d.ts +59 -0
- package/dist/mcp/client.d.ts.map +1 -0
- package/dist/mcp/client.js +195 -0
- package/dist/mcp/index.d.ts +3 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +2 -0
- package/dist/mcp/types.d.ts +151 -0
- package/dist/mcp/types.d.ts.map +1 -0
- package/dist/mcp/types.js +1 -0
- package/dist/plugins/cache.d.ts +10 -0
- package/dist/plugins/cache.d.ts.map +1 -0
- package/dist/plugins/cache.js +72 -0
- package/dist/plugins/circuit-breaker.d.ts +14 -0
- package/dist/plugins/circuit-breaker.d.ts.map +1 -0
- package/dist/plugins/circuit-breaker.js +100 -0
- package/dist/plugins/compression.d.ts +5 -0
- package/dist/plugins/compression.d.ts.map +1 -0
- package/dist/plugins/compression.js +128 -0
- package/dist/plugins/cookie-jar.d.ts +6 -0
- package/dist/plugins/cookie-jar.d.ts.map +1 -0
- package/dist/plugins/cookie-jar.js +72 -0
- package/dist/plugins/dedup.d.ts +6 -0
- package/dist/plugins/dedup.d.ts.map +1 -0
- package/dist/plugins/dedup.js +34 -0
- package/dist/plugins/graphql.d.ts +13 -0
- package/dist/plugins/graphql.d.ts.map +1 -0
- package/dist/plugins/graphql.js +39 -0
- package/dist/plugins/har-player.d.ts +7 -0
- package/dist/plugins/har-player.d.ts.map +1 -0
- package/dist/plugins/har-player.js +53 -0
- package/dist/plugins/har-recorder.d.ts +7 -0
- package/dist/plugins/har-recorder.d.ts.map +1 -0
- package/dist/plugins/har-recorder.js +67 -0
- package/dist/plugins/logger.d.ts +11 -0
- package/dist/plugins/logger.d.ts.map +1 -0
- package/dist/plugins/logger.js +72 -0
- package/dist/plugins/pagination.d.ts +17 -0
- package/dist/plugins/pagination.d.ts.map +1 -0
- package/dist/plugins/pagination.js +105 -0
- package/dist/plugins/proxy-rotator.d.ts +8 -0
- package/dist/plugins/proxy-rotator.d.ts.map +1 -0
- package/dist/plugins/proxy-rotator.js +35 -0
- package/dist/plugins/rate-limit.d.ts +8 -0
- package/dist/plugins/rate-limit.d.ts.map +1 -0
- package/dist/plugins/rate-limit.js +57 -0
- package/dist/plugins/retry.d.ts +14 -0
- package/dist/plugins/retry.d.ts.map +1 -0
- package/dist/plugins/retry.js +92 -0
- package/dist/plugins/server-timing.d.ts +8 -0
- package/dist/plugins/server-timing.d.ts.map +1 -0
- package/dist/plugins/server-timing.js +24 -0
- package/dist/plugins/xsrf.d.ts +10 -0
- package/dist/plugins/xsrf.d.ts.map +1 -0
- package/dist/plugins/xsrf.js +48 -0
- package/dist/runner/request-runner.d.ts +47 -0
- package/dist/runner/request-runner.d.ts.map +1 -0
- package/dist/runner/request-runner.js +89 -0
- package/dist/transport/fetch.d.ts +6 -0
- package/dist/transport/fetch.d.ts.map +1 -0
- package/dist/transport/fetch.js +153 -0
- package/dist/transport/undici.d.ts +23 -0
- package/dist/transport/undici.d.ts.map +1 -0
- package/dist/transport/undici.js +218 -0
- package/dist/types/index.d.ts +251 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +1 -0
- package/dist/utils/agent-manager.d.ts +29 -0
- package/dist/utils/agent-manager.d.ts.map +1 -0
- package/dist/utils/agent-manager.js +133 -0
- package/dist/utils/body.d.ts +11 -0
- package/dist/utils/body.d.ts.map +1 -0
- package/dist/utils/body.js +136 -0
- package/dist/utils/cert.d.ts +12 -0
- package/dist/utils/cert.d.ts.map +1 -0
- package/dist/utils/cert.js +32 -0
- package/dist/utils/concurrency.d.ts +21 -0
- package/dist/utils/concurrency.d.ts.map +1 -0
- package/dist/utils/concurrency.js +116 -0
- package/dist/utils/dns.d.ts +7 -0
- package/dist/utils/dns.d.ts.map +1 -0
- package/dist/utils/dns.js +26 -0
- package/dist/utils/doh.d.ts +3 -0
- package/dist/utils/doh.d.ts.map +1 -0
- package/dist/utils/doh.js +35 -0
- package/dist/utils/header-parser.d.ts +81 -0
- package/dist/utils/header-parser.d.ts.map +1 -0
- package/dist/utils/header-parser.js +457 -0
- package/dist/utils/html-cleaner.d.ts +2 -0
- package/dist/utils/html-cleaner.d.ts.map +1 -0
- package/dist/utils/html-cleaner.js +21 -0
- package/dist/utils/logger.d.ts +33 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +160 -0
- package/dist/utils/progress.d.ts +4 -0
- package/dist/utils/progress.d.ts.map +1 -0
- package/dist/utils/progress.js +49 -0
- package/dist/utils/request-pool.d.ts +23 -0
- package/dist/utils/request-pool.d.ts.map +1 -0
- package/dist/utils/request-pool.js +100 -0
- package/dist/utils/sse.d.ts +8 -0
- package/dist/utils/sse.d.ts.map +1 -0
- package/dist/utils/sse.js +62 -0
- package/dist/utils/streaming.d.ts +18 -0
- package/dist/utils/streaming.d.ts.map +1 -0
- package/dist/utils/streaming.js +83 -0
- package/dist/utils/task-pool.d.ts +38 -0
- package/dist/utils/task-pool.js +104 -0
- package/dist/utils/try-fn.d.ts +4 -0
- package/dist/utils/try-fn.d.ts.map +1 -0
- package/dist/utils/try-fn.js +53 -0
- package/dist/utils/upload.d.ts +10 -0
- package/dist/utils/upload.d.ts.map +1 -0
- package/dist/utils/upload.js +45 -0
- package/dist/utils/user-agent.d.ts +45 -0
- package/dist/utils/user-agent.d.ts.map +1 -0
- package/dist/utils/user-agent.js +100 -0
- package/dist/utils/whois.d.ts +15 -0
- package/dist/utils/whois.d.ts.map +1 -0
- package/dist/utils/whois.js +159 -0
- package/dist/websocket/client.d.ts +38 -0
- package/dist/websocket/client.d.ts.map +1 -0
- package/dist/websocket/client.js +184 -0
- package/package.json +100 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
export interface JsonRpcRequest {
|
|
2
|
+
jsonrpc: '2.0';
|
|
3
|
+
id?: string | number;
|
|
4
|
+
method: string;
|
|
5
|
+
params?: Record<string, unknown> | unknown[];
|
|
6
|
+
}
|
|
7
|
+
export interface JsonRpcResponse<T = unknown> {
|
|
8
|
+
jsonrpc: '2.0';
|
|
9
|
+
id: string | number;
|
|
10
|
+
result?: T;
|
|
11
|
+
error?: JsonRpcError;
|
|
12
|
+
}
|
|
13
|
+
export interface JsonRpcError {
|
|
14
|
+
code: number;
|
|
15
|
+
message: string;
|
|
16
|
+
data?: unknown;
|
|
17
|
+
}
|
|
18
|
+
export interface JsonRpcNotification {
|
|
19
|
+
jsonrpc: '2.0';
|
|
20
|
+
method: string;
|
|
21
|
+
params?: Record<string, unknown> | unknown[];
|
|
22
|
+
}
|
|
23
|
+
export interface MCPServerInfo {
|
|
24
|
+
name: string;
|
|
25
|
+
version: string;
|
|
26
|
+
protocolVersion?: string;
|
|
27
|
+
capabilities?: MCPCapabilities;
|
|
28
|
+
}
|
|
29
|
+
export interface MCPCapabilities {
|
|
30
|
+
tools?: {
|
|
31
|
+
listChanged?: boolean;
|
|
32
|
+
};
|
|
33
|
+
resources?: {
|
|
34
|
+
subscribe?: boolean;
|
|
35
|
+
listChanged?: boolean;
|
|
36
|
+
};
|
|
37
|
+
prompts?: {
|
|
38
|
+
listChanged?: boolean;
|
|
39
|
+
};
|
|
40
|
+
sampling?: Record<string, unknown>;
|
|
41
|
+
logging?: Record<string, unknown>;
|
|
42
|
+
}
|
|
43
|
+
export interface MCPTool {
|
|
44
|
+
name: string;
|
|
45
|
+
description?: string;
|
|
46
|
+
inputSchema: {
|
|
47
|
+
type: 'object';
|
|
48
|
+
properties?: Record<string, unknown>;
|
|
49
|
+
required?: string[];
|
|
50
|
+
[key: string]: unknown;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export interface MCPToolCall {
|
|
54
|
+
name: string;
|
|
55
|
+
arguments?: Record<string, unknown>;
|
|
56
|
+
}
|
|
57
|
+
export interface MCPToolResult {
|
|
58
|
+
content: MCPContent[];
|
|
59
|
+
isError?: boolean;
|
|
60
|
+
}
|
|
61
|
+
export interface MCPResource {
|
|
62
|
+
uri: string;
|
|
63
|
+
name: string;
|
|
64
|
+
description?: string;
|
|
65
|
+
mimeType?: string;
|
|
66
|
+
}
|
|
67
|
+
export interface MCPResourceContent {
|
|
68
|
+
uri: string;
|
|
69
|
+
mimeType?: string;
|
|
70
|
+
text?: string;
|
|
71
|
+
blob?: string;
|
|
72
|
+
}
|
|
73
|
+
export interface MCPPrompt {
|
|
74
|
+
name: string;
|
|
75
|
+
description?: string;
|
|
76
|
+
arguments?: MCPPromptArgument[];
|
|
77
|
+
}
|
|
78
|
+
export interface MCPPromptArgument {
|
|
79
|
+
name: string;
|
|
80
|
+
description?: string;
|
|
81
|
+
required?: boolean;
|
|
82
|
+
}
|
|
83
|
+
export interface MCPPromptMessage {
|
|
84
|
+
role: 'user' | 'assistant';
|
|
85
|
+
content: MCPContent;
|
|
86
|
+
}
|
|
87
|
+
export type MCPContent = MCPTextContent | MCPImageContent | MCPResourceContent;
|
|
88
|
+
export interface MCPTextContent {
|
|
89
|
+
type: 'text';
|
|
90
|
+
text: string;
|
|
91
|
+
}
|
|
92
|
+
export interface MCPImageContent {
|
|
93
|
+
type: 'image';
|
|
94
|
+
data: string;
|
|
95
|
+
mimeType: string;
|
|
96
|
+
}
|
|
97
|
+
export type MCPMethod = 'initialize' | 'ping' | 'tools/list' | 'tools/call' | 'resources/list' | 'resources/read' | 'resources/subscribe' | 'resources/unsubscribe' | 'prompts/list' | 'prompts/get' | 'sampling/createMessage' | 'logging/setLevel';
|
|
98
|
+
export interface MCPInitializeRequest {
|
|
99
|
+
protocolVersion: string;
|
|
100
|
+
capabilities: Partial<MCPCapabilities>;
|
|
101
|
+
clientInfo: {
|
|
102
|
+
name: string;
|
|
103
|
+
version: string;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
export interface MCPInitializeResponse {
|
|
107
|
+
protocolVersion: string;
|
|
108
|
+
capabilities: MCPCapabilities;
|
|
109
|
+
serverInfo: MCPServerInfo;
|
|
110
|
+
}
|
|
111
|
+
export interface MCPToolsListResponse {
|
|
112
|
+
tools: MCPTool[];
|
|
113
|
+
}
|
|
114
|
+
export interface MCPToolsCallRequest {
|
|
115
|
+
name: string;
|
|
116
|
+
arguments?: Record<string, unknown>;
|
|
117
|
+
}
|
|
118
|
+
export interface MCPResourcesListResponse {
|
|
119
|
+
resources: MCPResource[];
|
|
120
|
+
}
|
|
121
|
+
export interface MCPResourcesReadRequest {
|
|
122
|
+
uri: string;
|
|
123
|
+
}
|
|
124
|
+
export interface MCPResourcesReadResponse {
|
|
125
|
+
contents: MCPResourceContent[];
|
|
126
|
+
}
|
|
127
|
+
export interface MCPPromptsListResponse {
|
|
128
|
+
prompts: MCPPrompt[];
|
|
129
|
+
}
|
|
130
|
+
export interface MCPPromptsGetRequest {
|
|
131
|
+
name: string;
|
|
132
|
+
arguments?: Record<string, unknown>;
|
|
133
|
+
}
|
|
134
|
+
export interface MCPPromptsGetResponse {
|
|
135
|
+
description?: string;
|
|
136
|
+
messages: MCPPromptMessage[];
|
|
137
|
+
}
|
|
138
|
+
export type MCPNotification = 'notifications/initialized' | 'notifications/progress' | 'notifications/message' | 'notifications/resources/updated' | 'notifications/resources/list_changed' | 'notifications/tools/list_changed' | 'notifications/prompts/list_changed';
|
|
139
|
+
export interface MCPProgressNotification {
|
|
140
|
+
progressToken: string | number;
|
|
141
|
+
progress: number;
|
|
142
|
+
total?: number;
|
|
143
|
+
}
|
|
144
|
+
export interface MCPTransportOptions {
|
|
145
|
+
endpoint: string;
|
|
146
|
+
headers?: Record<string, string>;
|
|
147
|
+
timeout?: number;
|
|
148
|
+
retries?: number;
|
|
149
|
+
transport?: any;
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/mcp/types.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,EAAE,CAAC;CAC9C;AAED,MAAM,WAAW,eAAe,CAAC,CAAC,GAAG,OAAO;IAC1C,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,CAAC,CAAC;IACX,KAAK,CAAC,EAAE,YAAY,CAAC;CACtB;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,E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AAEzC,MAAM,WAAW,uBAAuB;IACtC,aAAa,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAGD,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,GAAG,CAAC;CACjB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { CacheStorage, CacheStrategy, Plugin, ReckerRequest } from '../types/index.js';
|
|
2
|
+
export interface CacheOptions {
|
|
3
|
+
storage?: CacheStorage;
|
|
4
|
+
strategy?: CacheStrategy;
|
|
5
|
+
ttl?: number;
|
|
6
|
+
methods?: string[];
|
|
7
|
+
keyGenerator?: (req: ReckerRequest) => string;
|
|
8
|
+
}
|
|
9
|
+
export declare function cache(options?: CacheOptions): Plugin;
|
|
10
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/plugins/cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAc,MAAM,EAAE,aAAa,EAAkB,MAAM,mBAAmB,CAAC;AAInH,MAAM,WAAW,YAAY;IAC3B,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,aAAa,KAAK,MAAM,CAAC;CAC/C;AAED,wBAAgB,KAAK,CAAC,OAAO,GAAE,YAAiB,GAAG,MAAM,CAgGxD"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { HttpResponse } from '../core/response.js';
|
|
2
|
+
import { MemoryStorage } from '../cache/memory-storage.js';
|
|
3
|
+
export function cache(options = {}) {
|
|
4
|
+
const storage = options.storage || new MemoryStorage();
|
|
5
|
+
const strategy = options.strategy || 'cache-first';
|
|
6
|
+
const ttl = options.ttl || 60 * 1000;
|
|
7
|
+
const methods = options.methods || ['GET'];
|
|
8
|
+
const generateKey = options.keyGenerator || ((req) => {
|
|
9
|
+
return `${req.method}:${req.url}`;
|
|
10
|
+
});
|
|
11
|
+
const cacheMiddleware = async (req, next) => {
|
|
12
|
+
if (!methods.includes(req.method)) {
|
|
13
|
+
return next(req);
|
|
14
|
+
}
|
|
15
|
+
const key = generateKey(req);
|
|
16
|
+
if (strategy === 'network-only') {
|
|
17
|
+
return next(req);
|
|
18
|
+
}
|
|
19
|
+
const cachedEntry = await storage.get(key);
|
|
20
|
+
if (cachedEntry) {
|
|
21
|
+
if (strategy === 'cache-first' || strategy === 'stale-while-revalidate') {
|
|
22
|
+
const cachedResponse = new Response(cachedEntry.body, {
|
|
23
|
+
status: cachedEntry.status,
|
|
24
|
+
statusText: cachedEntry.statusText,
|
|
25
|
+
headers: cachedEntry.headers,
|
|
26
|
+
});
|
|
27
|
+
const reckerResponse = new HttpResponse(cachedResponse);
|
|
28
|
+
if (strategy === 'stale-while-revalidate') {
|
|
29
|
+
(async () => {
|
|
30
|
+
try {
|
|
31
|
+
const freshResponse = await next(req);
|
|
32
|
+
if (freshResponse.ok) {
|
|
33
|
+
const text = await freshResponse.text();
|
|
34
|
+
const headers = {};
|
|
35
|
+
freshResponse.headers.forEach((v, k) => headers[k] = v);
|
|
36
|
+
await storage.set(key, {
|
|
37
|
+
status: freshResponse.status,
|
|
38
|
+
statusText: freshResponse.statusText,
|
|
39
|
+
headers: headers,
|
|
40
|
+
body: text,
|
|
41
|
+
timestamp: Date.now(),
|
|
42
|
+
}, ttl);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
console.error('Background cache revalidation failed', err);
|
|
47
|
+
}
|
|
48
|
+
})();
|
|
49
|
+
}
|
|
50
|
+
return reckerResponse;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const response = await next(req);
|
|
54
|
+
if (response.ok) {
|
|
55
|
+
const clonedResponse = response.raw.clone();
|
|
56
|
+
const text = await clonedResponse.text();
|
|
57
|
+
const headers = {};
|
|
58
|
+
response.headers.forEach((v, k) => headers[k] = v);
|
|
59
|
+
await storage.set(key, {
|
|
60
|
+
status: response.status,
|
|
61
|
+
statusText: response.statusText,
|
|
62
|
+
headers: headers,
|
|
63
|
+
body: text,
|
|
64
|
+
timestamp: Date.now(),
|
|
65
|
+
}, ttl);
|
|
66
|
+
}
|
|
67
|
+
return response;
|
|
68
|
+
};
|
|
69
|
+
return (client) => {
|
|
70
|
+
client.use(cacheMiddleware);
|
|
71
|
+
};
|
|
72
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Plugin, ReckerResponse } from '../types/index.js';
|
|
2
|
+
export interface CircuitBreakerOptions {
|
|
3
|
+
threshold?: number;
|
|
4
|
+
resetTimeout?: number;
|
|
5
|
+
shouldTrip?: (error: any, response?: ReckerResponse) => boolean;
|
|
6
|
+
onStateChange?: (state: CircuitState, service: string) => void;
|
|
7
|
+
}
|
|
8
|
+
export type CircuitState = 'CLOSED' | 'OPEN' | 'HALF_OPEN';
|
|
9
|
+
export declare class CircuitBreakerError extends Error {
|
|
10
|
+
service: string;
|
|
11
|
+
constructor(service: string);
|
|
12
|
+
}
|
|
13
|
+
export declare function circuitBreaker(options?: CircuitBreakerOptions): Plugin;
|
|
14
|
+
//# sourceMappingURL=circuit-breaker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"circuit-breaker.d.ts","sourceRoot":"","sources":["../../src/plugins/circuit-breaker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAiB,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAE1E,MAAM,WAAW,qBAAqB;IAEpC,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,QAAQ,CAAC,EAAE,cAAc,KAAK,OAAO,CAAC;IAEhE,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CAChE;AAED,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,MAAM,GAAG,WAAW,CAAC;AAQ3D,qBAAa,mBAAoB,SAAQ,KAAK;IACzB,OAAO,EAAE,MAAM;gBAAf,OAAO,EAAE,MAAM;CAInC;AAED,wBAAgB,cAAc,CAAC,OAAO,GAAE,qBAA0B,GAAG,MAAM,CA6G1E"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
export class CircuitBreakerError extends Error {
|
|
2
|
+
service;
|
|
3
|
+
constructor(service) {
|
|
4
|
+
super(`Circuit breaker is OPEN for ${service}`);
|
|
5
|
+
this.service = service;
|
|
6
|
+
this.name = 'CircuitBreakerError';
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export function circuitBreaker(options = {}) {
|
|
10
|
+
const threshold = options.threshold || 5;
|
|
11
|
+
const resetTimeout = options.resetTimeout || 30000;
|
|
12
|
+
const circuits = new Map();
|
|
13
|
+
const getCircuitKey = (req) => {
|
|
14
|
+
try {
|
|
15
|
+
return new URL(req.url).hostname;
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return 'unknown';
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const shouldTrip = options.shouldTrip || ((err, res) => {
|
|
22
|
+
if (res)
|
|
23
|
+
return res.status >= 500;
|
|
24
|
+
return true;
|
|
25
|
+
});
|
|
26
|
+
return (client) => {
|
|
27
|
+
client.beforeRequest((req) => {
|
|
28
|
+
const key = getCircuitKey(req);
|
|
29
|
+
let stats = circuits.get(key);
|
|
30
|
+
if (!stats) {
|
|
31
|
+
stats = { failures: 0, lastFailureTime: 0, state: 'CLOSED' };
|
|
32
|
+
circuits.set(key, stats);
|
|
33
|
+
}
|
|
34
|
+
if (stats.state === 'OPEN') {
|
|
35
|
+
const now = Date.now();
|
|
36
|
+
if (now - stats.lastFailureTime > resetTimeout) {
|
|
37
|
+
stats.state = 'HALF_OPEN';
|
|
38
|
+
if (options.onStateChange)
|
|
39
|
+
options.onStateChange('HALF_OPEN', key);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
throw new CircuitBreakerError(key);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
client.afterResponse((req, res) => {
|
|
47
|
+
const key = getCircuitKey(req);
|
|
48
|
+
const stats = circuits.get(key);
|
|
49
|
+
if (!stats)
|
|
50
|
+
return;
|
|
51
|
+
const isFailure = shouldTrip(null, res);
|
|
52
|
+
if (isFailure) {
|
|
53
|
+
handleFailure(stats, key);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
handleSuccess(stats, key);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
client.onError((err, req) => {
|
|
60
|
+
if (err instanceof CircuitBreakerError) {
|
|
61
|
+
throw err;
|
|
62
|
+
}
|
|
63
|
+
const key = getCircuitKey(req);
|
|
64
|
+
const stats = circuits.get(key);
|
|
65
|
+
if (!stats)
|
|
66
|
+
return;
|
|
67
|
+
const isFailure = shouldTrip(err, undefined);
|
|
68
|
+
if (isFailure) {
|
|
69
|
+
handleFailure(stats, key);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
function handleSuccess(stats, key) {
|
|
73
|
+
if (stats.state === 'HALF_OPEN') {
|
|
74
|
+
stats.state = 'CLOSED';
|
|
75
|
+
stats.failures = 0;
|
|
76
|
+
if (options.onStateChange)
|
|
77
|
+
options.onStateChange('CLOSED', key);
|
|
78
|
+
}
|
|
79
|
+
else if (stats.state === 'CLOSED') {
|
|
80
|
+
stats.failures = 0;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function handleFailure(stats, key) {
|
|
84
|
+
stats.failures++;
|
|
85
|
+
stats.lastFailureTime = Date.now();
|
|
86
|
+
if (stats.state === 'HALF_OPEN') {
|
|
87
|
+
stats.state = 'OPEN';
|
|
88
|
+
if (options.onStateChange)
|
|
89
|
+
options.onStateChange('OPEN', key);
|
|
90
|
+
}
|
|
91
|
+
else if (stats.state === 'CLOSED') {
|
|
92
|
+
if (stats.failures >= threshold) {
|
|
93
|
+
stats.state = 'OPEN';
|
|
94
|
+
if (options.onStateChange)
|
|
95
|
+
options.onStateChange('OPEN', key);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Middleware, CompressionOptions } from '../types/index.js';
|
|
2
|
+
export type CompressionAlgorithm = 'gzip' | 'deflate' | 'br';
|
|
3
|
+
export declare function compression(options?: CompressionOptions): Middleware;
|
|
4
|
+
export declare function createCompressionMiddleware(config: boolean | CompressionOptions): Middleware | null;
|
|
5
|
+
//# sourceMappingURL=compression.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compression.d.ts","sourceRoot":"","sources":["../../src/plugins/compression.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAMnE,MAAM,MAAM,oBAAoB,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;AAiI7D,wBAAgB,WAAW,CAAC,OAAO,GAAE,kBAAuB,GAAG,UAAU,CAoExE;AAKD,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,OAAO,GAAG,kBAAkB,GACnC,UAAU,GAAG,IAAI,CAUnB"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { gzip, deflate, brotliCompress } from 'node:zlib';
|
|
2
|
+
import { promisify } from 'node:util';
|
|
3
|
+
const gzipAsync = promisify(gzip);
|
|
4
|
+
const deflateAsync = promisify(deflate);
|
|
5
|
+
const brotliAsync = promisify(brotliCompress);
|
|
6
|
+
function isCompressible(contentType) {
|
|
7
|
+
if (!contentType)
|
|
8
|
+
return true;
|
|
9
|
+
const compressibleTypes = [
|
|
10
|
+
'text/',
|
|
11
|
+
'application/json',
|
|
12
|
+
'application/xml',
|
|
13
|
+
'application/javascript',
|
|
14
|
+
'application/x-www-form-urlencoded'
|
|
15
|
+
];
|
|
16
|
+
return compressibleTypes.some(type => contentType.includes(type));
|
|
17
|
+
}
|
|
18
|
+
function getBodySize(body) {
|
|
19
|
+
if (!body)
|
|
20
|
+
return 0;
|
|
21
|
+
if (typeof body === 'string') {
|
|
22
|
+
return Buffer.byteLength(body, 'utf8');
|
|
23
|
+
}
|
|
24
|
+
if (body instanceof Buffer) {
|
|
25
|
+
return body.length;
|
|
26
|
+
}
|
|
27
|
+
if (body instanceof ArrayBuffer) {
|
|
28
|
+
return body.byteLength;
|
|
29
|
+
}
|
|
30
|
+
if (body instanceof Blob) {
|
|
31
|
+
return body.size;
|
|
32
|
+
}
|
|
33
|
+
if (typeof body === 'object') {
|
|
34
|
+
try {
|
|
35
|
+
return Buffer.byteLength(JSON.stringify(body), 'utf8');
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return 0;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return 0;
|
|
42
|
+
}
|
|
43
|
+
function toBuffer(body) {
|
|
44
|
+
if (!body)
|
|
45
|
+
return null;
|
|
46
|
+
if (Buffer.isBuffer(body)) {
|
|
47
|
+
return body;
|
|
48
|
+
}
|
|
49
|
+
if (typeof body === 'string') {
|
|
50
|
+
return Buffer.from(body, 'utf8');
|
|
51
|
+
}
|
|
52
|
+
if (body instanceof ArrayBuffer) {
|
|
53
|
+
return Buffer.from(body);
|
|
54
|
+
}
|
|
55
|
+
if (typeof body === 'object') {
|
|
56
|
+
try {
|
|
57
|
+
return Buffer.from(JSON.stringify(body), 'utf8');
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
async function compress(data, algorithm) {
|
|
66
|
+
switch (algorithm) {
|
|
67
|
+
case 'gzip':
|
|
68
|
+
return await gzipAsync(data);
|
|
69
|
+
case 'deflate':
|
|
70
|
+
return await deflateAsync(data);
|
|
71
|
+
case 'br':
|
|
72
|
+
return await brotliAsync(data);
|
|
73
|
+
default:
|
|
74
|
+
throw new Error(`Unsupported compression algorithm: ${algorithm}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
export function compression(options = {}) {
|
|
78
|
+
const { algorithm = 'gzip', threshold = 1024, force = false, methods = ['POST', 'PUT', 'PATCH'] } = options;
|
|
79
|
+
return async (req, next) => {
|
|
80
|
+
const shouldCompress = methods.includes(req.method);
|
|
81
|
+
if (!shouldCompress || !req.body) {
|
|
82
|
+
return next(req);
|
|
83
|
+
}
|
|
84
|
+
if (req.headers.has('Content-Encoding')) {
|
|
85
|
+
return next(req);
|
|
86
|
+
}
|
|
87
|
+
const contentType = req.headers.get('Content-Type');
|
|
88
|
+
if (!isCompressible(contentType)) {
|
|
89
|
+
return next(req);
|
|
90
|
+
}
|
|
91
|
+
const bodySize = getBodySize(req.body);
|
|
92
|
+
if (!force && bodySize < threshold) {
|
|
93
|
+
return next(req);
|
|
94
|
+
}
|
|
95
|
+
const buffer = toBuffer(req.body);
|
|
96
|
+
if (!buffer) {
|
|
97
|
+
return next(req);
|
|
98
|
+
}
|
|
99
|
+
try {
|
|
100
|
+
const compressed = await compress(buffer, algorithm);
|
|
101
|
+
if (!force && compressed.length >= buffer.length) {
|
|
102
|
+
return next(req);
|
|
103
|
+
}
|
|
104
|
+
const newHeaders = new Headers(req.headers);
|
|
105
|
+
newHeaders.set('Content-Encoding', algorithm);
|
|
106
|
+
newHeaders.set('Content-Length', compressed.length.toString());
|
|
107
|
+
const compressedReq = {
|
|
108
|
+
...req,
|
|
109
|
+
body: compressed,
|
|
110
|
+
headers: newHeaders
|
|
111
|
+
};
|
|
112
|
+
return next(compressedReq);
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
console.error('Compression failed:', error);
|
|
116
|
+
return next(req);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
export function createCompressionMiddleware(config) {
|
|
121
|
+
if (!config) {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
if (config === true) {
|
|
125
|
+
return compression();
|
|
126
|
+
}
|
|
127
|
+
return compression(config);
|
|
128
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cookie-jar.d.ts","sourceRoot":"","sources":["../../src/plugins/cookie-jar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAiC,MAAM,mBAAmB,CAAC;AAE1E,MAAM,WAAW,gBAAgB;IAE/B,KAAK,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC7B;AAMD,wBAAgB,SAAS,CAAC,OAAO,GAAE,gBAAqB,GAAG,MAAM,CAsGhE"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
export function cookieJar(options = {}) {
|
|
2
|
+
const store = new Map();
|
|
3
|
+
if (options.store) {
|
|
4
|
+
if (options.store instanceof Map) {
|
|
5
|
+
store.set('*', options.store);
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
return (client) => {
|
|
9
|
+
client.beforeRequest((req) => {
|
|
10
|
+
const url = new URL(req.url);
|
|
11
|
+
const hostname = url.hostname;
|
|
12
|
+
const cookieList = [];
|
|
13
|
+
const addCookies = (domainStore) => {
|
|
14
|
+
if (domainStore) {
|
|
15
|
+
domainStore.forEach((value, key) => {
|
|
16
|
+
cookieList.push(`${key}=${value}`);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
addCookies(store.get(hostname));
|
|
21
|
+
for (const [domain, domainStore] of store.entries()) {
|
|
22
|
+
if (domain !== '*' && domain !== hostname && hostname.endsWith(domain)) {
|
|
23
|
+
addCookies(domainStore);
|
|
24
|
+
}
|
|
25
|
+
if (domain === '*') {
|
|
26
|
+
addCookies(domainStore);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (cookieList.length > 0) {
|
|
30
|
+
const existing = req.headers.get('cookie');
|
|
31
|
+
const newCookies = cookieList.join('; ');
|
|
32
|
+
req.headers.set('cookie', existing ? `${existing}; ${newCookies}` : newCookies);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
client.afterResponse((req, res) => {
|
|
36
|
+
const setCookie = res.headers.get('set-cookie');
|
|
37
|
+
if (!setCookie)
|
|
38
|
+
return;
|
|
39
|
+
const url = new URL(req.url);
|
|
40
|
+
let domain = url.hostname;
|
|
41
|
+
const cookies = splitCookies(setCookie);
|
|
42
|
+
cookies.forEach(cookieStr => {
|
|
43
|
+
const parts = cookieStr.split(';');
|
|
44
|
+
const [nameValue] = parts;
|
|
45
|
+
if (!nameValue)
|
|
46
|
+
return;
|
|
47
|
+
const [key, ...valParts] = nameValue.split('=');
|
|
48
|
+
if (!key)
|
|
49
|
+
return;
|
|
50
|
+
const value = valParts.join('=').trim();
|
|
51
|
+
let specificDomain = domain;
|
|
52
|
+
const domainPart = parts.find(p => p.trim().toLowerCase().startsWith('domain='));
|
|
53
|
+
if (domainPart) {
|
|
54
|
+
const d = domainPart.split('=')[1]?.trim();
|
|
55
|
+
if (d)
|
|
56
|
+
specificDomain = d;
|
|
57
|
+
}
|
|
58
|
+
if (!store.has(specificDomain)) {
|
|
59
|
+
store.set(specificDomain, new Map());
|
|
60
|
+
}
|
|
61
|
+
const domainStore = store.get(specificDomain);
|
|
62
|
+
domainStore.set(key.trim(), value);
|
|
63
|
+
if (options.store) {
|
|
64
|
+
options.store.set(key.trim(), value);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function splitCookies(header) {
|
|
71
|
+
return header.split(/,(?=\s*[a-zA-Z0-9_]+=[^;])/g);
|
|
72
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dedup.d.ts","sourceRoot":"","sources":["../../src/plugins/dedup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,MAAM,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEtE,MAAM,WAAW,YAAY;IAC3B,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,aAAa,KAAK,MAAM,CAAC;CAC/C;AAED,wBAAgB,KAAK,CAAC,OAAO,GAAE,YAAiB,GAAG,MAAM,CAiExD"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export function dedup(options = {}) {
|
|
2
|
+
const pendingRequests = new Map();
|
|
3
|
+
const generateKey = options.keyGenerator || ((req) => {
|
|
4
|
+
return `${req.method}:${req.url}`;
|
|
5
|
+
});
|
|
6
|
+
const dedupMiddleware = async (req, next) => {
|
|
7
|
+
if (req.method !== 'GET' && req.method !== 'HEAD') {
|
|
8
|
+
return next(req);
|
|
9
|
+
}
|
|
10
|
+
const key = generateKey(req);
|
|
11
|
+
if (pendingRequests.has(key)) {
|
|
12
|
+
const response = await pendingRequests.get(key);
|
|
13
|
+
return response.clone();
|
|
14
|
+
}
|
|
15
|
+
const promise = next(req)
|
|
16
|
+
.then((res) => {
|
|
17
|
+
return res;
|
|
18
|
+
})
|
|
19
|
+
.finally(() => {
|
|
20
|
+
pendingRequests.delete(key);
|
|
21
|
+
});
|
|
22
|
+
pendingRequests.set(key, promise);
|
|
23
|
+
try {
|
|
24
|
+
const response = await promise;
|
|
25
|
+
return response.clone ? response.clone() : response;
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
throw err;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
return (client) => {
|
|
32
|
+
client.use(dedupMiddleware);
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Plugin, ReckerResponse } from '../types/index.js';
|
|
2
|
+
import { Client } from '../core/client.js';
|
|
3
|
+
export declare class GraphQLError extends Error {
|
|
4
|
+
errors: any[];
|
|
5
|
+
response: ReckerResponse;
|
|
6
|
+
constructor(errors: any[], response: ReckerResponse);
|
|
7
|
+
}
|
|
8
|
+
export interface GraphQLOptions {
|
|
9
|
+
throwOnErrors?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function graphqlPlugin(options?: GraphQLOptions): Plugin;
|
|
12
|
+
export declare function graphql<T = any>(client: Client, query: string, variables?: Record<string, any>, options?: any): Promise<T>;
|
|
13
|
+
//# sourceMappingURL=graphql.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["../../src/plugins/graphql.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAA6B,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACtF,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,qBAAa,YAAa,SAAQ,KAAK;IAClB,MAAM,EAAE,GAAG,EAAE;IAAS,QAAQ,EAAE,cAAc;gBAA9C,MAAM,EAAE,GAAG,EAAE,EAAS,QAAQ,EAAE,cAAc;CAIlE;AAED,MAAM,WAAW,cAAc;IAE7B,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAOD,wBAAgB,aAAa,CAAC,OAAO,GAAE,cAAmB,GAAG,MAAM,CA4BlE;AAQD,wBAAsB,OAAO,CAAC,CAAC,GAAG,GAAG,EACjC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,SAAS,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,EACnC,OAAO,GAAE,GAAQ,GAClB,OAAO,CAAC,CAAC,CAAC,CAIZ"}
|