recker 1.0.26 → 1.0.27-next.1cb21f8
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/dist/browser/browser/cache.d.ts +40 -0
- package/dist/browser/browser/cache.js +199 -0
- package/dist/browser/browser/crypto.d.ts +24 -0
- package/dist/browser/browser/crypto.js +80 -0
- package/dist/browser/browser/index.d.ts +31 -0
- package/dist/browser/browser/index.js +31 -0
- package/dist/browser/browser/recker.d.ts +26 -0
- package/dist/browser/browser/recker.js +61 -0
- package/dist/browser/cache/basic-file-storage.d.ts +12 -0
- package/dist/browser/cache/basic-file-storage.js +50 -0
- package/dist/browser/cache/memory-limits.d.ts +20 -0
- package/dist/browser/cache/memory-limits.js +96 -0
- package/dist/browser/cache/memory-storage.d.ts +132 -0
- package/dist/browser/cache/memory-storage.js +454 -0
- package/dist/browser/cache.d.ts +40 -0
- package/dist/browser/cache.js +199 -0
- package/dist/browser/constants/http-status.d.ts +73 -0
- package/dist/browser/constants/http-status.js +156 -0
- package/dist/browser/cookies/memory-cookie-jar.d.ts +30 -0
- package/dist/browser/cookies/memory-cookie-jar.js +210 -0
- package/dist/browser/core/client.d.ts +118 -0
- package/dist/browser/core/client.js +667 -0
- package/dist/browser/core/errors.d.ts +142 -0
- package/dist/browser/core/errors.js +308 -0
- package/dist/browser/core/index.d.ts +5 -0
- package/dist/browser/core/index.js +5 -0
- package/dist/browser/core/request-promise.d.ts +23 -0
- package/dist/browser/core/request-promise.js +82 -0
- package/dist/browser/core/request.d.ts +20 -0
- package/dist/browser/core/request.js +76 -0
- package/dist/browser/core/response.d.ts +34 -0
- package/dist/browser/core/response.js +178 -0
- package/dist/browser/crypto.d.ts +24 -0
- package/dist/browser/crypto.js +80 -0
- package/dist/browser/index.d.ts +31 -0
- package/dist/browser/index.js +31 -0
- package/dist/browser/plugins/auth/api-key.d.ts +8 -0
- package/dist/browser/plugins/auth/api-key.js +27 -0
- package/dist/browser/plugins/auth/auth0.d.ts +33 -0
- package/dist/browser/plugins/auth/auth0.js +94 -0
- package/dist/browser/plugins/auth/aws-sigv4.d.ts +10 -0
- package/dist/browser/plugins/auth/aws-sigv4.js +88 -0
- package/dist/browser/plugins/auth/azure-ad.d.ts +48 -0
- package/dist/browser/plugins/auth/azure-ad.js +152 -0
- package/dist/browser/plugins/auth/basic.d.ts +7 -0
- package/dist/browser/plugins/auth/basic.js +13 -0
- package/dist/browser/plugins/auth/bearer.d.ts +8 -0
- package/dist/browser/plugins/auth/bearer.js +17 -0
- package/dist/browser/plugins/auth/cognito.d.ts +45 -0
- package/dist/browser/plugins/auth/cognito.js +208 -0
- package/dist/browser/plugins/auth/digest.d.ts +8 -0
- package/dist/browser/plugins/auth/digest.js +100 -0
- package/dist/browser/plugins/auth/firebase.d.ts +32 -0
- package/dist/browser/plugins/auth/firebase.js +195 -0
- package/dist/browser/plugins/auth/github-app.d.ts +36 -0
- package/dist/browser/plugins/auth/github-app.js +170 -0
- package/dist/browser/plugins/auth/google-service-account.d.ts +49 -0
- package/dist/browser/plugins/auth/google-service-account.js +172 -0
- package/dist/browser/plugins/auth/index.d.ts +15 -0
- package/dist/browser/plugins/auth/index.js +15 -0
- package/dist/browser/plugins/auth/mtls.d.ts +37 -0
- package/dist/browser/plugins/auth/mtls.js +140 -0
- package/dist/browser/plugins/auth/oauth2.d.ts +8 -0
- package/dist/browser/plugins/auth/oauth2.js +26 -0
- package/dist/browser/plugins/auth/oidc.d.ts +55 -0
- package/dist/browser/plugins/auth/oidc.js +222 -0
- package/dist/browser/plugins/auth/okta.d.ts +47 -0
- package/dist/browser/plugins/auth/okta.js +157 -0
- package/dist/browser/plugins/auth.d.ts +1 -0
- package/dist/browser/plugins/auth.js +1 -0
- package/dist/browser/plugins/cache.d.ts +15 -0
- package/dist/browser/plugins/cache.js +486 -0
- package/dist/browser/plugins/circuit-breaker.d.ts +13 -0
- package/dist/browser/plugins/circuit-breaker.js +100 -0
- package/dist/browser/plugins/compression.d.ts +4 -0
- package/dist/browser/plugins/compression.js +130 -0
- package/dist/browser/plugins/cookie-jar.d.ts +5 -0
- package/dist/browser/plugins/cookie-jar.js +72 -0
- package/dist/browser/plugins/dedup.d.ts +5 -0
- package/dist/browser/plugins/dedup.js +35 -0
- package/dist/browser/plugins/graphql.d.ts +13 -0
- package/dist/browser/plugins/graphql.js +58 -0
- package/dist/browser/plugins/grpc-web.d.ts +79 -0
- package/dist/browser/plugins/grpc-web.js +261 -0
- package/dist/browser/plugins/hls.d.ts +105 -0
- package/dist/browser/plugins/hls.js +395 -0
- package/dist/browser/plugins/jsonrpc.d.ts +75 -0
- package/dist/browser/plugins/jsonrpc.js +143 -0
- package/dist/browser/plugins/logger.d.ts +13 -0
- package/dist/browser/plugins/logger.js +108 -0
- package/dist/browser/plugins/odata.d.ts +181 -0
- package/dist/browser/plugins/odata.js +564 -0
- package/dist/browser/plugins/pagination.d.ts +16 -0
- package/dist/browser/plugins/pagination.js +105 -0
- package/dist/browser/plugins/rate-limit.d.ts +15 -0
- package/dist/browser/plugins/rate-limit.js +162 -0
- package/dist/browser/plugins/retry.d.ts +14 -0
- package/dist/browser/plugins/retry.js +116 -0
- package/dist/browser/plugins/scrape.d.ts +21 -0
- package/dist/browser/plugins/scrape.js +82 -0
- package/dist/browser/plugins/server-timing.d.ts +7 -0
- package/dist/browser/plugins/server-timing.js +24 -0
- package/dist/browser/plugins/soap.d.ts +72 -0
- package/dist/browser/plugins/soap.js +347 -0
- package/dist/browser/plugins/xml.d.ts +9 -0
- package/dist/browser/plugins/xml.js +194 -0
- package/dist/browser/plugins/xsrf.d.ts +9 -0
- package/dist/browser/plugins/xsrf.js +48 -0
- package/dist/browser/recker.d.ts +26 -0
- package/dist/browser/recker.js +61 -0
- package/dist/browser/runner/request-runner.d.ts +46 -0
- package/dist/browser/runner/request-runner.js +89 -0
- package/dist/browser/scrape/document.d.ts +44 -0
- package/dist/browser/scrape/document.js +210 -0
- package/dist/browser/scrape/element.d.ts +49 -0
- package/dist/browser/scrape/element.js +176 -0
- package/dist/browser/scrape/extractors.d.ts +16 -0
- package/dist/browser/scrape/extractors.js +357 -0
- package/dist/browser/scrape/types.d.ts +108 -0
- package/dist/browser/scrape/types.js +1 -0
- package/dist/browser/transport/fetch.d.ts +11 -0
- package/dist/browser/transport/fetch.js +143 -0
- package/dist/browser/transport/undici.d.ts +38 -0
- package/dist/browser/transport/undici.js +897 -0
- package/dist/browser/types/ai.d.ts +267 -0
- package/dist/browser/types/ai.js +1 -0
- package/dist/browser/types/index.d.ts +351 -0
- package/dist/browser/types/index.js +1 -0
- package/dist/browser/types/logger.d.ts +16 -0
- package/dist/browser/types/logger.js +66 -0
- package/dist/browser/types/udp.d.ts +138 -0
- package/dist/browser/types/udp.js +1 -0
- package/dist/browser/utils/agent-manager.d.ts +29 -0
- package/dist/browser/utils/agent-manager.js +160 -0
- package/dist/browser/utils/body.d.ts +10 -0
- package/dist/browser/utils/body.js +148 -0
- package/dist/browser/utils/charset.d.ts +15 -0
- package/dist/browser/utils/charset.js +169 -0
- package/dist/browser/utils/concurrency.d.ts +20 -0
- package/dist/browser/utils/concurrency.js +120 -0
- package/dist/browser/utils/dns.d.ts +6 -0
- package/dist/browser/utils/dns.js +26 -0
- package/dist/browser/utils/header-parser.d.ts +94 -0
- package/dist/browser/utils/header-parser.js +617 -0
- package/dist/browser/utils/html-cleaner.d.ts +1 -0
- package/dist/browser/utils/html-cleaner.js +21 -0
- package/dist/browser/utils/link-header.d.ts +69 -0
- package/dist/browser/utils/link-header.js +190 -0
- package/dist/browser/utils/optional-require.d.ts +19 -0
- package/dist/browser/utils/optional-require.js +105 -0
- package/dist/browser/utils/progress.d.ts +8 -0
- package/dist/browser/utils/progress.js +82 -0
- package/dist/browser/utils/request-pool.d.ts +22 -0
- package/dist/browser/utils/request-pool.js +101 -0
- package/dist/browser/utils/sse.d.ts +7 -0
- package/dist/browser/utils/sse.js +67 -0
- package/dist/browser/utils/streaming.d.ts +17 -0
- package/dist/browser/utils/streaming.js +84 -0
- package/dist/browser/utils/try-fn.d.ts +3 -0
- package/dist/browser/utils/try-fn.js +59 -0
- package/dist/browser/utils/user-agent.d.ts +44 -0
- package/dist/browser/utils/user-agent.js +100 -0
- package/dist/browser/utils/whois.d.ts +32 -0
- package/dist/browser/utils/whois.js +246 -0
- package/dist/browser/websocket/client.d.ts +65 -0
- package/dist/browser/websocket/client.js +313 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +143 -3
- package/dist/cli/tui/shell.d.ts +1 -0
- package/dist/cli/tui/shell.js +157 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/scrape/extractors.js +2 -1
- package/dist/scrape/types.d.ts +2 -1
- package/dist/seo/analyzer.d.ts +42 -0
- package/dist/seo/analyzer.js +715 -0
- package/dist/seo/index.d.ts +5 -0
- package/dist/seo/index.js +2 -0
- package/dist/seo/rules/accessibility.d.ts +2 -0
- package/dist/seo/rules/accessibility.js +128 -0
- package/dist/seo/rules/content.d.ts +2 -0
- package/dist/seo/rules/content.js +236 -0
- package/dist/seo/rules/images.d.ts +2 -0
- package/dist/seo/rules/images.js +180 -0
- package/dist/seo/rules/index.d.ts +20 -0
- package/dist/seo/rules/index.js +72 -0
- package/dist/seo/rules/links.d.ts +2 -0
- package/dist/seo/rules/links.js +150 -0
- package/dist/seo/rules/meta.d.ts +2 -0
- package/dist/seo/rules/meta.js +523 -0
- package/dist/seo/rules/mobile.d.ts +2 -0
- package/dist/seo/rules/mobile.js +71 -0
- package/dist/seo/rules/performance.d.ts +2 -0
- package/dist/seo/rules/performance.js +246 -0
- package/dist/seo/rules/schema.d.ts +2 -0
- package/dist/seo/rules/schema.js +54 -0
- package/dist/seo/rules/security.d.ts +2 -0
- package/dist/seo/rules/security.js +147 -0
- package/dist/seo/rules/structural.d.ts +2 -0
- package/dist/seo/rules/structural.js +155 -0
- package/dist/seo/rules/technical.d.ts +2 -0
- package/dist/seo/rules/technical.js +223 -0
- package/dist/seo/rules/thresholds.d.ts +196 -0
- package/dist/seo/rules/thresholds.js +118 -0
- package/dist/seo/rules/types.d.ts +191 -0
- package/dist/seo/rules/types.js +11 -0
- package/dist/seo/types.d.ts +160 -0
- package/dist/seo/types.js +1 -0
- package/dist/transport/fetch.d.ts +7 -1
- package/dist/transport/fetch.js +58 -76
- package/dist/utils/columns.d.ts +14 -0
- package/dist/utils/columns.js +69 -0
- package/package.json +34 -2
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
export const JsonRpcErrorCodes = {
|
|
2
|
+
PARSE_ERROR: -32700,
|
|
3
|
+
INVALID_REQUEST: -32600,
|
|
4
|
+
METHOD_NOT_FOUND: -32601,
|
|
5
|
+
INVALID_PARAMS: -32602,
|
|
6
|
+
INTERNAL_ERROR: -32603,
|
|
7
|
+
SERVER_ERROR: -32000,
|
|
8
|
+
};
|
|
9
|
+
export class JsonRpcException extends Error {
|
|
10
|
+
code;
|
|
11
|
+
data;
|
|
12
|
+
constructor(error) {
|
|
13
|
+
super(error.message);
|
|
14
|
+
this.name = 'JsonRpcException';
|
|
15
|
+
this.code = error.code;
|
|
16
|
+
this.data = error.data;
|
|
17
|
+
}
|
|
18
|
+
static isParseError(error) {
|
|
19
|
+
return error.code === JsonRpcErrorCodes.PARSE_ERROR;
|
|
20
|
+
}
|
|
21
|
+
static isInvalidRequest(error) {
|
|
22
|
+
return error.code === JsonRpcErrorCodes.INVALID_REQUEST;
|
|
23
|
+
}
|
|
24
|
+
static isMethodNotFound(error) {
|
|
25
|
+
return error.code === JsonRpcErrorCodes.METHOD_NOT_FOUND;
|
|
26
|
+
}
|
|
27
|
+
static isInvalidParams(error) {
|
|
28
|
+
return error.code === JsonRpcErrorCodes.INVALID_PARAMS;
|
|
29
|
+
}
|
|
30
|
+
static isInternalError(error) {
|
|
31
|
+
return error.code === JsonRpcErrorCodes.INTERNAL_ERROR;
|
|
32
|
+
}
|
|
33
|
+
static isServerError(error) {
|
|
34
|
+
return error.code >= -32099 && error.code <= -32000;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export class JsonRpcClient {
|
|
38
|
+
client;
|
|
39
|
+
options;
|
|
40
|
+
idCounter = 0;
|
|
41
|
+
constructor(client, options) {
|
|
42
|
+
this.client = client;
|
|
43
|
+
this.options = {
|
|
44
|
+
endpoint: options.endpoint,
|
|
45
|
+
requestOptions: options.requestOptions ?? {},
|
|
46
|
+
autoId: options.autoId ?? true,
|
|
47
|
+
idGenerator: options.idGenerator ?? (() => ++this.idCounter),
|
|
48
|
+
throwOnError: options.throwOnError ?? true,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
async call(method, params, options) {
|
|
52
|
+
const id = this.options.autoId ? this.options.idGenerator() : null;
|
|
53
|
+
const request = {
|
|
54
|
+
jsonrpc: '2.0',
|
|
55
|
+
method,
|
|
56
|
+
id,
|
|
57
|
+
};
|
|
58
|
+
if (params !== undefined) {
|
|
59
|
+
request.params = params;
|
|
60
|
+
}
|
|
61
|
+
const response = await this.sendRequest(request, options);
|
|
62
|
+
if (response.error) {
|
|
63
|
+
if (this.options.throwOnError) {
|
|
64
|
+
throw new JsonRpcException(response.error);
|
|
65
|
+
}
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
return response.result;
|
|
69
|
+
}
|
|
70
|
+
async notify(method, params, options) {
|
|
71
|
+
const request = {
|
|
72
|
+
jsonrpc: '2.0',
|
|
73
|
+
method,
|
|
74
|
+
};
|
|
75
|
+
if (params !== undefined) {
|
|
76
|
+
request.params = params;
|
|
77
|
+
}
|
|
78
|
+
await this.client.post(this.options.endpoint, {
|
|
79
|
+
...this.options.requestOptions,
|
|
80
|
+
...options,
|
|
81
|
+
json: request,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
async batch(requests, options) {
|
|
85
|
+
const batchRequests = requests.map((req, index) => ({
|
|
86
|
+
jsonrpc: '2.0',
|
|
87
|
+
method: req.method,
|
|
88
|
+
params: req.params,
|
|
89
|
+
id: req.id ?? (this.options.autoId ? this.options.idGenerator() : index),
|
|
90
|
+
}));
|
|
91
|
+
const response = await this.client.post(this.options.endpoint, {
|
|
92
|
+
...this.options.requestOptions,
|
|
93
|
+
...options,
|
|
94
|
+
json: batchRequests,
|
|
95
|
+
});
|
|
96
|
+
const responses = await response.json();
|
|
97
|
+
const errors = responses
|
|
98
|
+
.filter((r) => !!r.error)
|
|
99
|
+
.map((r) => r.error);
|
|
100
|
+
return {
|
|
101
|
+
responses,
|
|
102
|
+
errors,
|
|
103
|
+
hasErrors: errors.length > 0,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
getFromBatch(batch, id) {
|
|
107
|
+
const response = batch.responses.find((r) => r.id === id);
|
|
108
|
+
if (response?.error && this.options.throwOnError) {
|
|
109
|
+
throw new JsonRpcException(response.error);
|
|
110
|
+
}
|
|
111
|
+
return response?.result;
|
|
112
|
+
}
|
|
113
|
+
proxy() {
|
|
114
|
+
return new Proxy({}, {
|
|
115
|
+
get: (_, method) => {
|
|
116
|
+
return (...args) => {
|
|
117
|
+
if (args.length === 1 && typeof args[0] === 'object' && args[0] !== null && !Array.isArray(args[0])) {
|
|
118
|
+
return this.call(method, args[0]);
|
|
119
|
+
}
|
|
120
|
+
return this.call(method, args);
|
|
121
|
+
};
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
async sendRequest(request, options) {
|
|
126
|
+
const response = await this.client.post(this.options.endpoint, {
|
|
127
|
+
...this.options.requestOptions,
|
|
128
|
+
...options,
|
|
129
|
+
json: request,
|
|
130
|
+
});
|
|
131
|
+
return response.json();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
export function createJsonRpcClient(client, options) {
|
|
135
|
+
return new JsonRpcClient(client, options);
|
|
136
|
+
}
|
|
137
|
+
export function jsonrpc() {
|
|
138
|
+
return (client) => {
|
|
139
|
+
client.jsonrpc = (endpoint, options) => {
|
|
140
|
+
return createJsonRpcClient(client, { endpoint, ...options });
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Plugin, ReckerRequest } from '../types/index.js';
|
|
2
|
+
import { Logger } from '../types/logger.js';
|
|
3
|
+
export interface LoggerPluginOptions {
|
|
4
|
+
logger?: Logger;
|
|
5
|
+
level?: 'debug' | 'info';
|
|
6
|
+
showHeaders?: boolean;
|
|
7
|
+
showBody?: boolean;
|
|
8
|
+
showTimings?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function loggerPlugin(options?: LoggerPluginOptions): Plugin;
|
|
11
|
+
export declare function toCurl(req: ReckerRequest): string;
|
|
12
|
+
export type { Logger } from '../types/logger.js';
|
|
13
|
+
export { consoleLogger, silentLogger, createLevelLogger } from '../types/logger.js';
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { consoleLogger } from '../types/logger.js';
|
|
2
|
+
export function loggerPlugin(options = {}) {
|
|
3
|
+
const log = options.logger || consoleLogger;
|
|
4
|
+
const level = options.level || 'info';
|
|
5
|
+
const showHeaders = options.showHeaders || false;
|
|
6
|
+
const showBody = options.showBody || false;
|
|
7
|
+
const showTimings = options.showTimings !== false;
|
|
8
|
+
const timers = new WeakMap();
|
|
9
|
+
const logFn = level === 'debug' ? log.debug.bind(log) : log.info.bind(log);
|
|
10
|
+
return (client) => {
|
|
11
|
+
client.beforeRequest((req) => {
|
|
12
|
+
timers.set(req, performance.now());
|
|
13
|
+
const logData = {
|
|
14
|
+
type: 'request',
|
|
15
|
+
method: req.method,
|
|
16
|
+
url: req.url,
|
|
17
|
+
};
|
|
18
|
+
if (showHeaders) {
|
|
19
|
+
const headers = {};
|
|
20
|
+
req.headers.forEach((v, k) => {
|
|
21
|
+
if (k.toLowerCase() === 'authorization') {
|
|
22
|
+
headers[k] = '[REDACTED]';
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
headers[k] = v;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
logData.headers = headers;
|
|
29
|
+
}
|
|
30
|
+
if (showBody && req.body) {
|
|
31
|
+
if (typeof req.body === 'string') {
|
|
32
|
+
try {
|
|
33
|
+
logData.body = JSON.parse(req.body);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
logData.body = req.body;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
logData.body = '[Stream/Binary]';
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
logFn(logData, `→ ${req.method} ${req.url}`);
|
|
44
|
+
});
|
|
45
|
+
client.afterResponse((req, res) => {
|
|
46
|
+
const start = timers.get(req);
|
|
47
|
+
const duration = start ? Math.round(performance.now() - start) : 0;
|
|
48
|
+
const logData = {
|
|
49
|
+
type: 'response',
|
|
50
|
+
method: req.method,
|
|
51
|
+
url: req.url,
|
|
52
|
+
status: res.status,
|
|
53
|
+
statusText: res.statusText,
|
|
54
|
+
ok: res.ok,
|
|
55
|
+
duration,
|
|
56
|
+
};
|
|
57
|
+
if (showHeaders) {
|
|
58
|
+
const headers = {};
|
|
59
|
+
res.headers.forEach((v, k) => (headers[k] = v));
|
|
60
|
+
logData.headers = headers;
|
|
61
|
+
}
|
|
62
|
+
if (showTimings && res.timings) {
|
|
63
|
+
logData.timings = res.timings;
|
|
64
|
+
}
|
|
65
|
+
const contentLength = res.headers.get('content-length');
|
|
66
|
+
if (contentLength) {
|
|
67
|
+
logData.size = parseInt(contentLength, 10);
|
|
68
|
+
}
|
|
69
|
+
logFn(logData, `← ${res.status} ${req.method} ${req.url} (${duration}ms)`);
|
|
70
|
+
});
|
|
71
|
+
client.onError((err, req) => {
|
|
72
|
+
const start = timers.get(req);
|
|
73
|
+
const duration = start ? Math.round(performance.now() - start) : 0;
|
|
74
|
+
log.error({
|
|
75
|
+
type: 'error',
|
|
76
|
+
method: req.method,
|
|
77
|
+
url: req.url,
|
|
78
|
+
error: err.message,
|
|
79
|
+
errorName: err.name,
|
|
80
|
+
duration,
|
|
81
|
+
}, `✖ ${req.method} ${req.url} - ${err.message}`);
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
export function toCurl(req) {
|
|
86
|
+
const parts = ['curl'];
|
|
87
|
+
if (req.method !== 'GET') {
|
|
88
|
+
parts.push(`-X ${req.method}`);
|
|
89
|
+
}
|
|
90
|
+
parts.push(`'${req.url}'`);
|
|
91
|
+
req.headers.forEach((value, key) => {
|
|
92
|
+
const displayValue = key.toLowerCase() === 'authorization' ? '[REDACTED]' : value;
|
|
93
|
+
parts.push(`-H '${key}: ${displayValue}'`);
|
|
94
|
+
});
|
|
95
|
+
if (req.body) {
|
|
96
|
+
if (typeof req.body === 'string') {
|
|
97
|
+
parts.push(`-d '${req.body}'`);
|
|
98
|
+
}
|
|
99
|
+
else if (req.body instanceof URLSearchParams) {
|
|
100
|
+
parts.push(`-d '${req.body.toString()}'`);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
parts.push(`-d '[Body]'`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return parts.join(' \\\n ');
|
|
107
|
+
}
|
|
108
|
+
export { consoleLogger, silentLogger, createLevelLogger } from '../types/logger.js';
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import type { Client } from '../core/client.js';
|
|
2
|
+
import type { RequestOptions } from '../types/index.js';
|
|
3
|
+
export interface ODataOptions {
|
|
4
|
+
serviceRoot: string;
|
|
5
|
+
version?: '4.0' | '4.01';
|
|
6
|
+
maxPageSize?: number;
|
|
7
|
+
requestOptions?: RequestOptions;
|
|
8
|
+
}
|
|
9
|
+
export interface ODataQueryOptions {
|
|
10
|
+
$select?: string | string[];
|
|
11
|
+
$expand?: string | string[] | ExpandOption[];
|
|
12
|
+
$filter?: string | FilterExpression;
|
|
13
|
+
$orderby?: string | OrderByOption[];
|
|
14
|
+
$top?: number;
|
|
15
|
+
$skip?: number;
|
|
16
|
+
$count?: boolean;
|
|
17
|
+
$search?: string;
|
|
18
|
+
$format?: 'json' | 'xml' | 'atom';
|
|
19
|
+
[key: string]: unknown;
|
|
20
|
+
}
|
|
21
|
+
export interface ExpandOption {
|
|
22
|
+
property: string;
|
|
23
|
+
select?: string[];
|
|
24
|
+
expand?: ExpandOption[];
|
|
25
|
+
filter?: string | FilterExpression;
|
|
26
|
+
orderby?: string | OrderByOption[];
|
|
27
|
+
top?: number;
|
|
28
|
+
skip?: number;
|
|
29
|
+
count?: boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface OrderByOption {
|
|
32
|
+
property: string;
|
|
33
|
+
direction?: 'asc' | 'desc';
|
|
34
|
+
}
|
|
35
|
+
export interface FilterExpression {
|
|
36
|
+
and?: FilterExpression[];
|
|
37
|
+
or?: FilterExpression[];
|
|
38
|
+
not?: FilterExpression;
|
|
39
|
+
eq?: [string, unknown];
|
|
40
|
+
ne?: [string, unknown];
|
|
41
|
+
gt?: [string, unknown];
|
|
42
|
+
ge?: [string, unknown];
|
|
43
|
+
lt?: [string, unknown];
|
|
44
|
+
le?: [string, unknown];
|
|
45
|
+
contains?: [string, string];
|
|
46
|
+
startswith?: [string, string];
|
|
47
|
+
endswith?: [string, string];
|
|
48
|
+
raw?: string;
|
|
49
|
+
}
|
|
50
|
+
export interface ODataResponse<T = unknown> {
|
|
51
|
+
'@odata.context'?: string;
|
|
52
|
+
'@odata.count'?: number;
|
|
53
|
+
'@odata.nextLink'?: string;
|
|
54
|
+
value?: T[];
|
|
55
|
+
[key: string]: unknown;
|
|
56
|
+
}
|
|
57
|
+
export interface ODataEntityResponse<T = unknown> extends ODataResponse<T> {
|
|
58
|
+
'@odata.etag'?: string;
|
|
59
|
+
}
|
|
60
|
+
export interface ODataError {
|
|
61
|
+
error: {
|
|
62
|
+
code: string;
|
|
63
|
+
message: string;
|
|
64
|
+
target?: string;
|
|
65
|
+
details?: Array<{
|
|
66
|
+
code: string;
|
|
67
|
+
message: string;
|
|
68
|
+
target?: string;
|
|
69
|
+
}>;
|
|
70
|
+
innererror?: {
|
|
71
|
+
message?: string;
|
|
72
|
+
type?: string;
|
|
73
|
+
stacktrace?: string;
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
export declare class ODataException extends Error {
|
|
78
|
+
readonly code: string;
|
|
79
|
+
readonly target?: string;
|
|
80
|
+
readonly details?: Array<{
|
|
81
|
+
code: string;
|
|
82
|
+
message: string;
|
|
83
|
+
target?: string;
|
|
84
|
+
}>;
|
|
85
|
+
readonly innererror?: {
|
|
86
|
+
message?: string;
|
|
87
|
+
type?: string;
|
|
88
|
+
stacktrace?: string;
|
|
89
|
+
};
|
|
90
|
+
constructor(error: ODataError['error']);
|
|
91
|
+
}
|
|
92
|
+
export declare class ODataQueryBuilder<T = unknown> {
|
|
93
|
+
private client;
|
|
94
|
+
private entitySet;
|
|
95
|
+
private entityKey?;
|
|
96
|
+
private queryOptions;
|
|
97
|
+
private requestOptions?;
|
|
98
|
+
constructor(client: ODataClient, entitySet: string);
|
|
99
|
+
key(key: string | number | Record<string, unknown>): this;
|
|
100
|
+
select(...properties: string[]): this;
|
|
101
|
+
expand(...properties: (string | ExpandOption)[]): this;
|
|
102
|
+
filter(filter: string | FilterExpression | ((builder: FilterBuilder) => FilterBuilder)): this;
|
|
103
|
+
orderBy(property: string, direction?: 'asc' | 'desc'): this;
|
|
104
|
+
top(count: number): this;
|
|
105
|
+
skip(count: number): this;
|
|
106
|
+
count(include?: boolean): this;
|
|
107
|
+
search(term: string): this;
|
|
108
|
+
custom(key: string, value: unknown): this;
|
|
109
|
+
options(options: RequestOptions): this;
|
|
110
|
+
get(): Promise<ODataResponse<T>>;
|
|
111
|
+
getAll(): AsyncGenerator<T, void, unknown>;
|
|
112
|
+
toUrl(): string;
|
|
113
|
+
}
|
|
114
|
+
export declare class FilterBuilder {
|
|
115
|
+
private parts;
|
|
116
|
+
eq(property: string, value: unknown): this;
|
|
117
|
+
ne(property: string, value: unknown): this;
|
|
118
|
+
gt(property: string, value: unknown): this;
|
|
119
|
+
ge(property: string, value: unknown): this;
|
|
120
|
+
lt(property: string, value: unknown): this;
|
|
121
|
+
le(property: string, value: unknown): this;
|
|
122
|
+
contains(property: string, value: string): this;
|
|
123
|
+
startswith(property: string, value: string): this;
|
|
124
|
+
endswith(property: string, value: string): this;
|
|
125
|
+
isNull(property: string): this;
|
|
126
|
+
isNotNull(property: string): this;
|
|
127
|
+
in(property: string, values: unknown[]): this;
|
|
128
|
+
and(): this;
|
|
129
|
+
or(): this;
|
|
130
|
+
not(): this;
|
|
131
|
+
group(builder: (b: FilterBuilder) => FilterBuilder): this;
|
|
132
|
+
raw(expression: string): this;
|
|
133
|
+
build(): string;
|
|
134
|
+
private formatValue;
|
|
135
|
+
private escapeString;
|
|
136
|
+
}
|
|
137
|
+
export declare class ODataClient {
|
|
138
|
+
private client;
|
|
139
|
+
private options;
|
|
140
|
+
constructor(client: Client, options: ODataOptions);
|
|
141
|
+
query<T = unknown>(entitySet: string): ODataQueryBuilder<T>;
|
|
142
|
+
get<T = unknown>(entitySet: string, key?: string | number | Record<string, unknown>, queryOptions?: ODataQueryOptions, requestOptions?: RequestOptions): Promise<ODataResponse<T>>;
|
|
143
|
+
getById<T = unknown>(entitySet: string, key: string | number | Record<string, unknown>, queryOptions?: ODataQueryOptions, requestOptions?: RequestOptions): Promise<T>;
|
|
144
|
+
getNextPage<T = unknown>(nextLink: string): Promise<ODataResponse<T>>;
|
|
145
|
+
create<T = unknown>(entitySet: string, entity: Partial<T>, requestOptions?: RequestOptions): Promise<T>;
|
|
146
|
+
update<T = unknown>(entitySet: string, key: string | number | Record<string, unknown>, entity: Partial<T>, requestOptions?: RequestOptions): Promise<T>;
|
|
147
|
+
replace<T = unknown>(entitySet: string, key: string | number | Record<string, unknown>, entity: T, requestOptions?: RequestOptions): Promise<T>;
|
|
148
|
+
delete(entitySet: string, key: string | number | Record<string, unknown>, requestOptions?: RequestOptions): Promise<void>;
|
|
149
|
+
action<T = unknown>(action: string, params?: Record<string, unknown>, requestOptions?: RequestOptions): Promise<T>;
|
|
150
|
+
function<T = unknown>(func: string, params?: Record<string, unknown>, requestOptions?: RequestOptions): Promise<T>;
|
|
151
|
+
batch(requests: Array<{
|
|
152
|
+
method: string;
|
|
153
|
+
url: string;
|
|
154
|
+
body?: unknown;
|
|
155
|
+
headers?: Record<string, string>;
|
|
156
|
+
}>, requestOptions?: RequestOptions): Promise<Array<{
|
|
157
|
+
status: number;
|
|
158
|
+
body: unknown;
|
|
159
|
+
}>>;
|
|
160
|
+
getMetadata(): Promise<string>;
|
|
161
|
+
buildUrl(entitySet: string, key?: string | number | Record<string, unknown>, queryOptions?: ODataQueryOptions): string;
|
|
162
|
+
private getHeaders;
|
|
163
|
+
private request;
|
|
164
|
+
private handleResponse;
|
|
165
|
+
private formatKey;
|
|
166
|
+
private formatKeyValue;
|
|
167
|
+
private buildQueryString;
|
|
168
|
+
private formatExpand;
|
|
169
|
+
private formatExpandOption;
|
|
170
|
+
private formatOrderBy;
|
|
171
|
+
private formatFilterExpression;
|
|
172
|
+
private formatFilterValue;
|
|
173
|
+
private parseBatchResponse;
|
|
174
|
+
}
|
|
175
|
+
export declare function createODataClient(client: Client, options: ODataOptions): ODataClient;
|
|
176
|
+
export declare function odata(): (client: Client) => void;
|
|
177
|
+
declare module '../core/client.js' {
|
|
178
|
+
interface Client {
|
|
179
|
+
odata(serviceRoot: string, options?: Omit<ODataOptions, 'serviceRoot'>): ODataClient;
|
|
180
|
+
}
|
|
181
|
+
}
|