recker 1.0.2-0 → 1.0.3
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 +0 -2
- package/README.md +121 -72
- package/dist/cache/memory-storage.d.ts.map +1 -1
- package/dist/cache/memory-storage.js +7 -1
- package/dist/constants/http-status.d.ts +74 -0
- package/dist/constants/http-status.d.ts.map +1 -0
- package/dist/constants/http-status.js +156 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +6 -6
- package/dist/cookies/memory-cookie-jar.d.ts +31 -0
- package/dist/cookies/memory-cookie-jar.d.ts.map +1 -0
- package/dist/cookies/memory-cookie-jar.js +210 -0
- package/dist/core/client.d.ts +9 -0
- package/dist/core/client.d.ts.map +1 -1
- package/dist/core/client.js +252 -53
- package/dist/core/errors.d.ts +18 -2
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/errors.js +66 -5
- package/dist/core/index.d.ts +6 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +5 -0
- package/dist/core/request-promise.d.ts.map +1 -1
- package/dist/core/request-promise.js +8 -2
- package/dist/core/request.d.ts +7 -1
- package/dist/core/request.d.ts.map +1 -1
- package/dist/core/request.js +32 -0
- package/dist/core/response.d.ts +2 -0
- package/dist/core/response.d.ts.map +1 -1
- package/dist/core/response.js +44 -19
- package/dist/events/request-events.d.ts +48 -0
- package/dist/events/request-events.d.ts.map +1 -0
- package/dist/events/request-events.js +85 -0
- package/dist/index.d.ts +28 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +28 -2
- package/dist/mcp/client.d.ts.map +1 -1
- package/dist/mcp/client.js +16 -5
- package/dist/mcp/contract.d.ts +77 -0
- package/dist/mcp/contract.d.ts.map +1 -0
- package/dist/mcp/contract.js +278 -0
- package/dist/mcp/types.d.ts +1 -0
- package/dist/mcp/types.d.ts.map +1 -1
- package/dist/plugins/auth.d.ts +45 -0
- package/dist/plugins/auth.d.ts.map +1 -0
- package/dist/plugins/auth.js +268 -0
- package/dist/plugins/cache.d.ts +7 -1
- package/dist/plugins/cache.d.ts.map +1 -1
- package/dist/plugins/cache.js +470 -49
- package/dist/plugins/circuit-breaker.js +1 -1
- package/dist/plugins/compression.d.ts.map +1 -1
- package/dist/plugins/compression.js +3 -3
- package/dist/plugins/dedup.d.ts.map +1 -1
- package/dist/plugins/dedup.js +2 -1
- package/dist/plugins/graphql.d.ts +4 -3
- package/dist/plugins/graphql.d.ts.map +1 -1
- package/dist/plugins/graphql.js +24 -5
- package/dist/plugins/grpc-web.d.ts +80 -0
- package/dist/plugins/grpc-web.d.ts.map +1 -0
- package/dist/plugins/grpc-web.js +261 -0
- package/dist/plugins/har-player.d.ts.map +1 -1
- package/dist/plugins/har-player.js +11 -2
- package/dist/plugins/hls.d.ts +33 -0
- package/dist/plugins/hls.d.ts.map +1 -0
- package/dist/plugins/hls.js +225 -0
- package/dist/plugins/http2-push.d.ts +64 -0
- package/dist/plugins/http2-push.d.ts.map +1 -0
- package/dist/plugins/http2-push.js +274 -0
- package/dist/plugins/http3.d.ts +76 -0
- package/dist/plugins/http3.d.ts.map +1 -0
- package/dist/plugins/http3.js +231 -0
- package/dist/plugins/interface-rotator.d.ts +10 -0
- package/dist/plugins/interface-rotator.d.ts.map +1 -0
- package/dist/plugins/interface-rotator.js +57 -0
- package/dist/plugins/jsonrpc.d.ts +76 -0
- package/dist/plugins/jsonrpc.d.ts.map +1 -0
- package/dist/plugins/jsonrpc.js +143 -0
- package/dist/plugins/logger.d.ts +8 -5
- package/dist/plugins/logger.d.ts.map +1 -1
- package/dist/plugins/logger.js +66 -30
- package/dist/plugins/odata.d.ts +182 -0
- package/dist/plugins/odata.d.ts.map +1 -0
- package/dist/plugins/odata.js +561 -0
- package/dist/plugins/retry.d.ts +1 -0
- package/dist/plugins/retry.d.ts.map +1 -1
- package/dist/plugins/retry.js +26 -2
- package/dist/plugins/scrape.d.ts +22 -0
- package/dist/plugins/scrape.d.ts.map +1 -0
- package/dist/plugins/scrape.js +87 -0
- package/dist/plugins/soap.d.ts +73 -0
- package/dist/plugins/soap.d.ts.map +1 -0
- package/dist/plugins/soap.js +347 -0
- package/dist/plugins/user-agent.d.ts +8 -0
- package/dist/plugins/user-agent.d.ts.map +1 -0
- package/dist/plugins/user-agent.js +46 -0
- package/dist/plugins/xml.d.ts +10 -0
- package/dist/plugins/xml.d.ts.map +1 -0
- package/dist/plugins/xml.js +194 -0
- package/dist/presets/anthropic.d.ts +7 -0
- package/dist/presets/anthropic.d.ts.map +1 -0
- package/dist/presets/anthropic.js +17 -0
- package/dist/presets/azure-openai.d.ts +9 -0
- package/dist/presets/azure-openai.d.ts.map +1 -0
- package/dist/presets/azure-openai.js +25 -0
- package/dist/presets/cloudflare.d.ts +13 -0
- package/dist/presets/cloudflare.d.ts.map +1 -0
- package/dist/presets/cloudflare.js +39 -0
- package/dist/presets/cohere.d.ts +6 -0
- package/dist/presets/cohere.d.ts.map +1 -0
- package/dist/presets/cohere.js +16 -0
- package/dist/presets/deepseek.d.ts +6 -0
- package/dist/presets/deepseek.d.ts.map +1 -0
- package/dist/presets/deepseek.js +16 -0
- package/dist/presets/digitalocean.d.ts +6 -0
- package/dist/presets/digitalocean.d.ts.map +1 -0
- package/dist/presets/digitalocean.js +16 -0
- package/dist/presets/discord.d.ts +7 -0
- package/dist/presets/discord.d.ts.map +1 -0
- package/dist/presets/discord.js +17 -0
- package/dist/presets/fireworks.d.ts +6 -0
- package/dist/presets/fireworks.d.ts.map +1 -0
- package/dist/presets/fireworks.js +16 -0
- package/dist/presets/gemini.d.ts +6 -0
- package/dist/presets/gemini.d.ts.map +1 -0
- package/dist/presets/gemini.js +16 -0
- package/dist/presets/github.d.ts +7 -0
- package/dist/presets/github.d.ts.map +1 -0
- package/dist/presets/github.js +17 -0
- package/dist/presets/gitlab.d.ts +7 -0
- package/dist/presets/gitlab.d.ts.map +1 -0
- package/dist/presets/gitlab.js +16 -0
- package/dist/presets/groq.d.ts +6 -0
- package/dist/presets/groq.d.ts.map +1 -0
- package/dist/presets/groq.js +16 -0
- package/dist/presets/huggingface.d.ts +6 -0
- package/dist/presets/huggingface.d.ts.map +1 -0
- package/dist/presets/huggingface.js +16 -0
- package/dist/presets/index.d.ts +28 -0
- package/dist/presets/index.d.ts.map +1 -0
- package/dist/presets/index.js +27 -0
- package/dist/presets/linear.d.ts +6 -0
- package/dist/presets/linear.d.ts.map +1 -0
- package/dist/presets/linear.js +16 -0
- package/dist/presets/mistral.d.ts +6 -0
- package/dist/presets/mistral.d.ts.map +1 -0
- package/dist/presets/mistral.js +16 -0
- package/dist/presets/notion.d.ts +7 -0
- package/dist/presets/notion.d.ts.map +1 -0
- package/dist/presets/notion.js +17 -0
- package/dist/presets/openai.d.ts +8 -0
- package/dist/presets/openai.d.ts.map +1 -0
- package/dist/presets/openai.js +23 -0
- package/dist/presets/perplexity.d.ts +6 -0
- package/dist/presets/perplexity.d.ts.map +1 -0
- package/dist/presets/perplexity.js +16 -0
- package/dist/presets/registry.d.ts +20 -0
- package/dist/presets/registry.d.ts.map +1 -0
- package/dist/presets/registry.js +311 -0
- package/dist/presets/replicate.d.ts +6 -0
- package/dist/presets/replicate.d.ts.map +1 -0
- package/dist/presets/replicate.js +16 -0
- package/dist/presets/slack.d.ts +6 -0
- package/dist/presets/slack.d.ts.map +1 -0
- package/dist/presets/slack.js +16 -0
- package/dist/presets/stripe.d.ts +8 -0
- package/dist/presets/stripe.d.ts.map +1 -0
- package/dist/presets/stripe.js +23 -0
- package/dist/presets/supabase.d.ts +7 -0
- package/dist/presets/supabase.d.ts.map +1 -0
- package/dist/presets/supabase.js +18 -0
- package/dist/presets/together.d.ts +6 -0
- package/dist/presets/together.d.ts.map +1 -0
- package/dist/presets/together.js +16 -0
- package/dist/presets/twilio.d.ts +7 -0
- package/dist/presets/twilio.d.ts.map +1 -0
- package/dist/presets/twilio.js +17 -0
- package/dist/presets/vercel.d.ts +7 -0
- package/dist/presets/vercel.d.ts.map +1 -0
- package/dist/presets/vercel.js +23 -0
- package/dist/presets/xai.d.ts +7 -0
- package/dist/presets/xai.d.ts.map +1 -0
- package/dist/presets/xai.js +17 -0
- package/dist/protocols/ftp.d.ts +63 -0
- package/dist/protocols/ftp.d.ts.map +1 -0
- package/dist/protocols/ftp.js +388 -0
- package/dist/protocols/index.d.ts +4 -0
- package/dist/protocols/index.d.ts.map +1 -0
- package/dist/protocols/index.js +3 -0
- package/dist/protocols/sftp.d.ts +65 -0
- package/dist/protocols/sftp.d.ts.map +1 -0
- package/dist/protocols/sftp.js +346 -0
- package/dist/protocols/telnet.d.ts +50 -0
- package/dist/protocols/telnet.d.ts.map +1 -0
- package/dist/protocols/telnet.js +139 -0
- package/dist/runner/request-runner.d.ts.map +1 -1
- package/dist/runner/request-runner.js +1 -0
- package/dist/scrape/document.d.ts +44 -0
- package/dist/scrape/document.d.ts.map +1 -0
- package/dist/scrape/document.js +198 -0
- package/dist/scrape/element.d.ts +50 -0
- package/dist/scrape/element.d.ts.map +1 -0
- package/dist/scrape/element.js +176 -0
- package/dist/scrape/extractors.d.ts +17 -0
- package/dist/scrape/extractors.d.ts.map +1 -0
- package/dist/scrape/extractors.js +356 -0
- package/dist/scrape/index.d.ts +5 -0
- package/dist/scrape/index.d.ts.map +1 -0
- package/dist/scrape/index.js +3 -0
- package/dist/scrape/types.d.ts +108 -0
- package/dist/scrape/types.d.ts.map +1 -0
- package/dist/scrape/types.js +1 -0
- package/dist/testing/index.d.ts +3 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +1 -0
- package/dist/testing/mock.d.ts +58 -0
- package/dist/testing/mock.d.ts.map +1 -0
- package/dist/testing/mock.js +252 -0
- package/dist/transport/fetch.d.ts.map +1 -1
- package/dist/transport/fetch.js +12 -4
- package/dist/transport/undici.d.ts +17 -1
- package/dist/transport/undici.d.ts.map +1 -1
- package/dist/transport/undici.js +708 -47
- package/dist/types/index.d.ts +111 -10
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -1
- package/dist/types/logger.d.ts +17 -0
- package/dist/types/logger.d.ts.map +1 -0
- package/dist/types/logger.js +66 -0
- package/dist/utils/agent-manager.d.ts.map +1 -1
- package/dist/utils/agent-manager.js +20 -4
- package/dist/utils/body.d.ts.map +1 -1
- package/dist/utils/body.js +14 -2
- package/dist/utils/charset.d.ts +16 -0
- package/dist/utils/charset.d.ts.map +1 -0
- package/dist/utils/charset.js +169 -0
- package/dist/utils/client-pool.d.ts +21 -0
- package/dist/utils/client-pool.d.ts.map +1 -0
- package/dist/utils/client-pool.js +49 -0
- package/dist/utils/concurrency.d.ts.map +1 -1
- package/dist/utils/concurrency.js +8 -4
- package/dist/utils/dns-toolkit.d.ts +13 -0
- package/dist/utils/dns-toolkit.d.ts.map +1 -0
- package/dist/utils/dns-toolkit.js +48 -0
- package/dist/utils/doh.d.ts.map +1 -1
- package/dist/utils/doh.js +16 -3
- package/dist/utils/download.d.ts +15 -0
- package/dist/utils/download.d.ts.map +1 -0
- package/dist/utils/download.js +44 -0
- package/dist/utils/env-proxy.d.ts +13 -0
- package/dist/utils/env-proxy.d.ts.map +1 -0
- package/dist/utils/env-proxy.js +105 -0
- package/dist/utils/header-parser.d.ts +15 -1
- package/dist/utils/header-parser.d.ts.map +1 -1
- package/dist/utils/header-parser.js +161 -1
- package/dist/utils/link-header.d.ts +70 -0
- package/dist/utils/link-header.d.ts.map +1 -0
- package/dist/utils/link-header.js +190 -0
- package/dist/utils/progress.d.ts +7 -2
- package/dist/utils/progress.d.ts.map +1 -1
- package/dist/utils/progress.js +48 -15
- package/dist/utils/rdap.d.ts +17 -0
- package/dist/utils/rdap.d.ts.map +1 -0
- package/dist/utils/rdap.js +32 -0
- package/dist/utils/request-pool.d.ts.map +1 -1
- package/dist/utils/request-pool.js +4 -3
- package/dist/utils/sse.d.ts.map +1 -1
- package/dist/utils/sse.js +8 -2
- package/dist/utils/status-codes.d.ts +84 -0
- package/dist/utils/status-codes.d.ts.map +1 -0
- package/dist/utils/status-codes.js +204 -0
- package/dist/utils/streaming.d.ts.map +1 -1
- package/dist/utils/streaming.js +1 -0
- package/dist/utils/tls-inspector.d.ts +21 -0
- package/dist/utils/tls-inspector.d.ts.map +1 -0
- package/dist/utils/tls-inspector.js +39 -0
- package/dist/utils/try-fn.d.ts.map +1 -1
- package/dist/utils/try-fn.js +11 -5
- package/dist/utils/upload.d.ts +1 -0
- package/dist/utils/upload.d.ts.map +1 -1
- package/dist/utils/upload.js +20 -3
- package/dist/utils/user-agent.d.ts +9 -9
- package/dist/utils/user-agent.js +9 -9
- package/dist/utils/whois.d.ts.map +1 -1
- package/dist/utils/whois.js +11 -2
- package/dist/websocket/client.d.ts +29 -1
- package/dist/websocket/client.d.ts.map +1 -1
- package/dist/websocket/client.js +145 -13
- package/package.json +45 -8
|
@@ -0,0 +1,561 @@
|
|
|
1
|
+
export class ODataException extends Error {
|
|
2
|
+
code;
|
|
3
|
+
target;
|
|
4
|
+
details;
|
|
5
|
+
innererror;
|
|
6
|
+
constructor(error) {
|
|
7
|
+
super(error.message);
|
|
8
|
+
this.name = 'ODataException';
|
|
9
|
+
this.code = error.code;
|
|
10
|
+
this.target = error.target;
|
|
11
|
+
this.details = error.details;
|
|
12
|
+
this.innererror = error.innererror;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export class ODataQueryBuilder {
|
|
16
|
+
client;
|
|
17
|
+
entitySet;
|
|
18
|
+
entityKey;
|
|
19
|
+
queryOptions = {};
|
|
20
|
+
requestOptions;
|
|
21
|
+
constructor(client, entitySet) {
|
|
22
|
+
this.client = client;
|
|
23
|
+
this.entitySet = entitySet;
|
|
24
|
+
}
|
|
25
|
+
key(key) {
|
|
26
|
+
this.entityKey = key;
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
select(...properties) {
|
|
30
|
+
this.queryOptions.$select = properties;
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
expand(...properties) {
|
|
34
|
+
const hasExpandOptions = properties.some((p) => typeof p !== 'string');
|
|
35
|
+
if (hasExpandOptions) {
|
|
36
|
+
this.queryOptions.$expand = properties;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
this.queryOptions.$expand = properties;
|
|
40
|
+
}
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
filter(filter) {
|
|
44
|
+
if (typeof filter === 'function') {
|
|
45
|
+
const builder = new FilterBuilder();
|
|
46
|
+
this.queryOptions.$filter = filter(builder).build();
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
this.queryOptions.$filter = filter;
|
|
50
|
+
}
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
orderBy(property, direction = 'asc') {
|
|
54
|
+
const existing = this.queryOptions.$orderby;
|
|
55
|
+
const option = { property, direction };
|
|
56
|
+
if (Array.isArray(existing)) {
|
|
57
|
+
existing.push(option);
|
|
58
|
+
}
|
|
59
|
+
else if (existing) {
|
|
60
|
+
this.queryOptions.$orderby = [{ property: existing, direction: 'asc' }, option];
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
this.queryOptions.$orderby = [option];
|
|
64
|
+
}
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
top(count) {
|
|
68
|
+
this.queryOptions.$top = count;
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
skip(count) {
|
|
72
|
+
this.queryOptions.$skip = count;
|
|
73
|
+
return this;
|
|
74
|
+
}
|
|
75
|
+
count(include = true) {
|
|
76
|
+
this.queryOptions.$count = include;
|
|
77
|
+
return this;
|
|
78
|
+
}
|
|
79
|
+
search(term) {
|
|
80
|
+
this.queryOptions.$search = term;
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
custom(key, value) {
|
|
84
|
+
this.queryOptions[key] = value;
|
|
85
|
+
return this;
|
|
86
|
+
}
|
|
87
|
+
options(options) {
|
|
88
|
+
this.requestOptions = options;
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
91
|
+
async get() {
|
|
92
|
+
return this.client.get(this.entitySet, this.entityKey, this.queryOptions, this.requestOptions);
|
|
93
|
+
}
|
|
94
|
+
async *getAll() {
|
|
95
|
+
let response = await this.get();
|
|
96
|
+
while (response.value) {
|
|
97
|
+
for (const item of response.value) {
|
|
98
|
+
yield item;
|
|
99
|
+
}
|
|
100
|
+
if (response['@odata.nextLink']) {
|
|
101
|
+
response = await this.client.getNextPage(response['@odata.nextLink']);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
toUrl() {
|
|
109
|
+
return this.client.buildUrl(this.entitySet, this.entityKey, this.queryOptions);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
export class FilterBuilder {
|
|
113
|
+
parts = [];
|
|
114
|
+
eq(property, value) {
|
|
115
|
+
this.parts.push(`${property} eq ${this.formatValue(value)}`);
|
|
116
|
+
return this;
|
|
117
|
+
}
|
|
118
|
+
ne(property, value) {
|
|
119
|
+
this.parts.push(`${property} ne ${this.formatValue(value)}`);
|
|
120
|
+
return this;
|
|
121
|
+
}
|
|
122
|
+
gt(property, value) {
|
|
123
|
+
this.parts.push(`${property} gt ${this.formatValue(value)}`);
|
|
124
|
+
return this;
|
|
125
|
+
}
|
|
126
|
+
ge(property, value) {
|
|
127
|
+
this.parts.push(`${property} ge ${this.formatValue(value)}`);
|
|
128
|
+
return this;
|
|
129
|
+
}
|
|
130
|
+
lt(property, value) {
|
|
131
|
+
this.parts.push(`${property} lt ${this.formatValue(value)}`);
|
|
132
|
+
return this;
|
|
133
|
+
}
|
|
134
|
+
le(property, value) {
|
|
135
|
+
this.parts.push(`${property} le ${this.formatValue(value)}`);
|
|
136
|
+
return this;
|
|
137
|
+
}
|
|
138
|
+
contains(property, value) {
|
|
139
|
+
this.parts.push(`contains(${property},'${this.escapeString(value)}')`);
|
|
140
|
+
return this;
|
|
141
|
+
}
|
|
142
|
+
startswith(property, value) {
|
|
143
|
+
this.parts.push(`startswith(${property},'${this.escapeString(value)}')`);
|
|
144
|
+
return this;
|
|
145
|
+
}
|
|
146
|
+
endswith(property, value) {
|
|
147
|
+
this.parts.push(`endswith(${property},'${this.escapeString(value)}')`);
|
|
148
|
+
return this;
|
|
149
|
+
}
|
|
150
|
+
isNull(property) {
|
|
151
|
+
this.parts.push(`${property} eq null`);
|
|
152
|
+
return this;
|
|
153
|
+
}
|
|
154
|
+
isNotNull(property) {
|
|
155
|
+
this.parts.push(`${property} ne null`);
|
|
156
|
+
return this;
|
|
157
|
+
}
|
|
158
|
+
in(property, values) {
|
|
159
|
+
const formatted = values.map((v) => this.formatValue(v)).join(',');
|
|
160
|
+
this.parts.push(`${property} in (${formatted})`);
|
|
161
|
+
return this;
|
|
162
|
+
}
|
|
163
|
+
and() {
|
|
164
|
+
if (this.parts.length > 0) {
|
|
165
|
+
this.parts.push('and');
|
|
166
|
+
}
|
|
167
|
+
return this;
|
|
168
|
+
}
|
|
169
|
+
or() {
|
|
170
|
+
if (this.parts.length > 0) {
|
|
171
|
+
this.parts.push('or');
|
|
172
|
+
}
|
|
173
|
+
return this;
|
|
174
|
+
}
|
|
175
|
+
not() {
|
|
176
|
+
this.parts.push('not');
|
|
177
|
+
return this;
|
|
178
|
+
}
|
|
179
|
+
group(builder) {
|
|
180
|
+
const inner = new FilterBuilder();
|
|
181
|
+
const result = builder(inner).build();
|
|
182
|
+
this.parts.push(`(${result})`);
|
|
183
|
+
return this;
|
|
184
|
+
}
|
|
185
|
+
raw(expression) {
|
|
186
|
+
this.parts.push(expression);
|
|
187
|
+
return this;
|
|
188
|
+
}
|
|
189
|
+
build() {
|
|
190
|
+
return this.parts.join(' ');
|
|
191
|
+
}
|
|
192
|
+
formatValue(value) {
|
|
193
|
+
if (value === null)
|
|
194
|
+
return 'null';
|
|
195
|
+
if (typeof value === 'string')
|
|
196
|
+
return `'${this.escapeString(value)}'`;
|
|
197
|
+
if (typeof value === 'boolean')
|
|
198
|
+
return value.toString();
|
|
199
|
+
if (typeof value === 'number')
|
|
200
|
+
return value.toString();
|
|
201
|
+
if (value instanceof Date)
|
|
202
|
+
return value.toISOString();
|
|
203
|
+
if (typeof value === 'object')
|
|
204
|
+
return JSON.stringify(value);
|
|
205
|
+
return String(value);
|
|
206
|
+
}
|
|
207
|
+
escapeString(str) {
|
|
208
|
+
return str.replace(/'/g, "''");
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
export class ODataClient {
|
|
212
|
+
client;
|
|
213
|
+
options;
|
|
214
|
+
constructor(client, options) {
|
|
215
|
+
this.client = client;
|
|
216
|
+
this.options = {
|
|
217
|
+
serviceRoot: options.serviceRoot.replace(/\/$/, ''),
|
|
218
|
+
version: options.version ?? '4.0',
|
|
219
|
+
maxPageSize: options.maxPageSize ?? 100,
|
|
220
|
+
requestOptions: options.requestOptions ?? {},
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
query(entitySet) {
|
|
224
|
+
return new ODataQueryBuilder(this, entitySet);
|
|
225
|
+
}
|
|
226
|
+
async get(entitySet, key, queryOptions, requestOptions) {
|
|
227
|
+
const url = this.buildUrl(entitySet, key, queryOptions);
|
|
228
|
+
const response = await this.request('GET', url, undefined, requestOptions);
|
|
229
|
+
return response;
|
|
230
|
+
}
|
|
231
|
+
async getById(entitySet, key, queryOptions, requestOptions) {
|
|
232
|
+
const response = await this.get(entitySet, key, queryOptions, requestOptions);
|
|
233
|
+
return response;
|
|
234
|
+
}
|
|
235
|
+
async getNextPage(nextLink) {
|
|
236
|
+
const response = await this.client.get(nextLink, {
|
|
237
|
+
...this.options.requestOptions,
|
|
238
|
+
headers: this.getHeaders(),
|
|
239
|
+
});
|
|
240
|
+
return this.handleResponse(response);
|
|
241
|
+
}
|
|
242
|
+
async create(entitySet, entity, requestOptions) {
|
|
243
|
+
const url = this.buildUrl(entitySet);
|
|
244
|
+
return this.request('POST', url, entity, requestOptions);
|
|
245
|
+
}
|
|
246
|
+
async update(entitySet, key, entity, requestOptions) {
|
|
247
|
+
const url = this.buildUrl(entitySet, key);
|
|
248
|
+
return this.request('PATCH', url, entity, requestOptions);
|
|
249
|
+
}
|
|
250
|
+
async replace(entitySet, key, entity, requestOptions) {
|
|
251
|
+
const url = this.buildUrl(entitySet, key);
|
|
252
|
+
return this.request('PUT', url, entity, requestOptions);
|
|
253
|
+
}
|
|
254
|
+
async delete(entitySet, key, requestOptions) {
|
|
255
|
+
const url = this.buildUrl(entitySet, key);
|
|
256
|
+
await this.request('DELETE', url, undefined, requestOptions);
|
|
257
|
+
}
|
|
258
|
+
async action(action, params, requestOptions) {
|
|
259
|
+
const url = `${this.options.serviceRoot}/${action}`;
|
|
260
|
+
return this.request('POST', url, params, requestOptions);
|
|
261
|
+
}
|
|
262
|
+
async function(func, params, requestOptions) {
|
|
263
|
+
let url = `${this.options.serviceRoot}/${func}`;
|
|
264
|
+
if (params && Object.keys(params).length > 0) {
|
|
265
|
+
const paramString = Object.entries(params)
|
|
266
|
+
.map(([k, v]) => `${k}=${this.formatKeyValue(v)}`)
|
|
267
|
+
.join(',');
|
|
268
|
+
url += `(${paramString})`;
|
|
269
|
+
}
|
|
270
|
+
return this.request('GET', url, undefined, requestOptions);
|
|
271
|
+
}
|
|
272
|
+
async batch(requests, requestOptions) {
|
|
273
|
+
const boundary = `batch_${Date.now()}_${Math.random().toString(36).slice(2)}`;
|
|
274
|
+
const batchUrl = `${this.options.serviceRoot}/$batch`;
|
|
275
|
+
let body = '';
|
|
276
|
+
for (const req of requests) {
|
|
277
|
+
body += `--${boundary}\r\n`;
|
|
278
|
+
body += 'Content-Type: application/http\r\n';
|
|
279
|
+
body += 'Content-Transfer-Encoding: binary\r\n\r\n';
|
|
280
|
+
body += `${req.method} ${req.url} HTTP/1.1\r\n`;
|
|
281
|
+
if (req.headers) {
|
|
282
|
+
for (const [key, value] of Object.entries(req.headers)) {
|
|
283
|
+
body += `${key}: ${value}\r\n`;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
if (req.body) {
|
|
287
|
+
body += 'Content-Type: application/json\r\n\r\n';
|
|
288
|
+
body += JSON.stringify(req.body);
|
|
289
|
+
}
|
|
290
|
+
body += '\r\n';
|
|
291
|
+
}
|
|
292
|
+
body += `--${boundary}--\r\n`;
|
|
293
|
+
const response = await this.client.post(batchUrl, body, {
|
|
294
|
+
...this.options.requestOptions,
|
|
295
|
+
...requestOptions,
|
|
296
|
+
headers: {
|
|
297
|
+
...this.getHeaders(),
|
|
298
|
+
'Content-Type': `multipart/mixed; boundary=${boundary}`,
|
|
299
|
+
...requestOptions?.headers,
|
|
300
|
+
},
|
|
301
|
+
});
|
|
302
|
+
const responseText = await response.text();
|
|
303
|
+
return this.parseBatchResponse(responseText);
|
|
304
|
+
}
|
|
305
|
+
async getMetadata() {
|
|
306
|
+
const response = await this.client.get(`${this.options.serviceRoot}/$metadata`, {
|
|
307
|
+
...this.options.requestOptions,
|
|
308
|
+
headers: {
|
|
309
|
+
Accept: 'application/xml',
|
|
310
|
+
},
|
|
311
|
+
});
|
|
312
|
+
return response.text();
|
|
313
|
+
}
|
|
314
|
+
buildUrl(entitySet, key, queryOptions) {
|
|
315
|
+
let url = `${this.options.serviceRoot}/${entitySet}`;
|
|
316
|
+
if (key !== undefined) {
|
|
317
|
+
url += `(${this.formatKey(key)})`;
|
|
318
|
+
}
|
|
319
|
+
if (queryOptions) {
|
|
320
|
+
const params = this.buildQueryString(queryOptions);
|
|
321
|
+
if (params) {
|
|
322
|
+
url += `?${params}`;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
return url;
|
|
326
|
+
}
|
|
327
|
+
getHeaders() {
|
|
328
|
+
return {
|
|
329
|
+
'Accept': 'application/json',
|
|
330
|
+
'Content-Type': 'application/json',
|
|
331
|
+
'OData-Version': this.options.version,
|
|
332
|
+
'OData-MaxVersion': '4.01',
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
async request(method, url, body, requestOptions) {
|
|
336
|
+
const options = {
|
|
337
|
+
...this.options.requestOptions,
|
|
338
|
+
...requestOptions,
|
|
339
|
+
throwHttpErrors: false,
|
|
340
|
+
headers: {
|
|
341
|
+
...this.getHeaders(),
|
|
342
|
+
...requestOptions?.headers,
|
|
343
|
+
},
|
|
344
|
+
};
|
|
345
|
+
let response;
|
|
346
|
+
switch (method) {
|
|
347
|
+
case 'GET':
|
|
348
|
+
response = await this.client.get(url, options);
|
|
349
|
+
break;
|
|
350
|
+
case 'POST':
|
|
351
|
+
response = await this.client.post(url, body, options);
|
|
352
|
+
break;
|
|
353
|
+
case 'PUT':
|
|
354
|
+
response = await this.client.put(url, body, options);
|
|
355
|
+
break;
|
|
356
|
+
case 'PATCH':
|
|
357
|
+
response = await this.client.patch(url, body, options);
|
|
358
|
+
break;
|
|
359
|
+
case 'DELETE':
|
|
360
|
+
response = await this.client.delete(url, options);
|
|
361
|
+
break;
|
|
362
|
+
default:
|
|
363
|
+
throw new Error(`Unsupported method: ${method}`);
|
|
364
|
+
}
|
|
365
|
+
return this.handleResponse(response);
|
|
366
|
+
}
|
|
367
|
+
async handleResponse(response) {
|
|
368
|
+
if (response.status === 204) {
|
|
369
|
+
return undefined;
|
|
370
|
+
}
|
|
371
|
+
const data = await response.json();
|
|
372
|
+
if (!response.ok) {
|
|
373
|
+
const error = data;
|
|
374
|
+
if (error.error) {
|
|
375
|
+
throw new ODataException(error.error);
|
|
376
|
+
}
|
|
377
|
+
throw new Error(`OData request failed: ${response.status}`);
|
|
378
|
+
}
|
|
379
|
+
return data;
|
|
380
|
+
}
|
|
381
|
+
formatKey(key) {
|
|
382
|
+
if (typeof key === 'string') {
|
|
383
|
+
return `'${key.replace(/'/g, "''")}'`;
|
|
384
|
+
}
|
|
385
|
+
if (typeof key === 'number') {
|
|
386
|
+
return key.toString();
|
|
387
|
+
}
|
|
388
|
+
return Object.entries(key)
|
|
389
|
+
.map(([k, v]) => `${k}=${this.formatKeyValue(v)}`)
|
|
390
|
+
.join(',');
|
|
391
|
+
}
|
|
392
|
+
formatKeyValue(value) {
|
|
393
|
+
if (typeof value === 'string')
|
|
394
|
+
return `'${value.replace(/'/g, "''")}'`;
|
|
395
|
+
if (value === null)
|
|
396
|
+
return 'null';
|
|
397
|
+
if (value instanceof Date)
|
|
398
|
+
return value.toISOString();
|
|
399
|
+
return String(value);
|
|
400
|
+
}
|
|
401
|
+
buildQueryString(options) {
|
|
402
|
+
const params = [];
|
|
403
|
+
if (options.$select) {
|
|
404
|
+
const select = Array.isArray(options.$select) ? options.$select.join(',') : options.$select;
|
|
405
|
+
params.push(`$select=${encodeURIComponent(select)}`);
|
|
406
|
+
}
|
|
407
|
+
if (options.$expand) {
|
|
408
|
+
const expand = this.formatExpand(options.$expand);
|
|
409
|
+
params.push(`$expand=${encodeURIComponent(expand)}`);
|
|
410
|
+
}
|
|
411
|
+
if (options.$filter) {
|
|
412
|
+
const filter = typeof options.$filter === 'string'
|
|
413
|
+
? options.$filter
|
|
414
|
+
: this.formatFilterExpression(options.$filter);
|
|
415
|
+
params.push(`$filter=${encodeURIComponent(filter)}`);
|
|
416
|
+
}
|
|
417
|
+
if (options.$orderby) {
|
|
418
|
+
const orderby = this.formatOrderBy(options.$orderby);
|
|
419
|
+
params.push(`$orderby=${encodeURIComponent(orderby)}`);
|
|
420
|
+
}
|
|
421
|
+
if (options.$top !== undefined) {
|
|
422
|
+
params.push(`$top=${options.$top}`);
|
|
423
|
+
}
|
|
424
|
+
if (options.$skip !== undefined) {
|
|
425
|
+
params.push(`$skip=${options.$skip}`);
|
|
426
|
+
}
|
|
427
|
+
if (options.$count !== undefined) {
|
|
428
|
+
params.push(`$count=${options.$count}`);
|
|
429
|
+
}
|
|
430
|
+
if (options.$search) {
|
|
431
|
+
params.push(`$search=${encodeURIComponent(options.$search)}`);
|
|
432
|
+
}
|
|
433
|
+
if (options.$format) {
|
|
434
|
+
params.push(`$format=${options.$format}`);
|
|
435
|
+
}
|
|
436
|
+
for (const [key, value] of Object.entries(options)) {
|
|
437
|
+
if (!key.startsWith('$') && value !== undefined) {
|
|
438
|
+
params.push(`${key}=${encodeURIComponent(String(value))}`);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
return params.join('&');
|
|
442
|
+
}
|
|
443
|
+
formatExpand(expand) {
|
|
444
|
+
if (typeof expand === 'string')
|
|
445
|
+
return expand;
|
|
446
|
+
if (Array.isArray(expand)) {
|
|
447
|
+
return expand.map((e) => {
|
|
448
|
+
if (typeof e === 'string')
|
|
449
|
+
return e;
|
|
450
|
+
return this.formatExpandOption(e);
|
|
451
|
+
}).join(',');
|
|
452
|
+
}
|
|
453
|
+
return '';
|
|
454
|
+
}
|
|
455
|
+
formatExpandOption(option) {
|
|
456
|
+
let result = option.property;
|
|
457
|
+
const nested = [];
|
|
458
|
+
if (option.select)
|
|
459
|
+
nested.push(`$select=${option.select.join(',')}`);
|
|
460
|
+
if (option.filter) {
|
|
461
|
+
const filter = typeof option.filter === 'string'
|
|
462
|
+
? option.filter
|
|
463
|
+
: this.formatFilterExpression(option.filter);
|
|
464
|
+
nested.push(`$filter=${filter}`);
|
|
465
|
+
}
|
|
466
|
+
if (option.orderby)
|
|
467
|
+
nested.push(`$orderby=${this.formatOrderBy(option.orderby)}`);
|
|
468
|
+
if (option.top !== undefined)
|
|
469
|
+
nested.push(`$top=${option.top}`);
|
|
470
|
+
if (option.skip !== undefined)
|
|
471
|
+
nested.push(`$skip=${option.skip}`);
|
|
472
|
+
if (option.count !== undefined)
|
|
473
|
+
nested.push(`$count=${option.count}`);
|
|
474
|
+
if (option.expand)
|
|
475
|
+
nested.push(`$expand=${this.formatExpand(option.expand)}`);
|
|
476
|
+
if (nested.length > 0) {
|
|
477
|
+
result += `(${nested.join(';')})`;
|
|
478
|
+
}
|
|
479
|
+
return result;
|
|
480
|
+
}
|
|
481
|
+
formatOrderBy(orderby) {
|
|
482
|
+
if (typeof orderby === 'string')
|
|
483
|
+
return orderby;
|
|
484
|
+
return orderby.map((o) => `${o.property} ${o.direction ?? 'asc'}`).join(',');
|
|
485
|
+
}
|
|
486
|
+
formatFilterExpression(filter) {
|
|
487
|
+
if (filter.raw)
|
|
488
|
+
return filter.raw;
|
|
489
|
+
const parts = [];
|
|
490
|
+
if (filter.eq)
|
|
491
|
+
parts.push(`${filter.eq[0]} eq ${this.formatFilterValue(filter.eq[1])}`);
|
|
492
|
+
if (filter.ne)
|
|
493
|
+
parts.push(`${filter.ne[0]} ne ${this.formatFilterValue(filter.ne[1])}`);
|
|
494
|
+
if (filter.gt)
|
|
495
|
+
parts.push(`${filter.gt[0]} gt ${this.formatFilterValue(filter.gt[1])}`);
|
|
496
|
+
if (filter.ge)
|
|
497
|
+
parts.push(`${filter.ge[0]} ge ${this.formatFilterValue(filter.ge[1])}`);
|
|
498
|
+
if (filter.lt)
|
|
499
|
+
parts.push(`${filter.lt[0]} lt ${this.formatFilterValue(filter.lt[1])}`);
|
|
500
|
+
if (filter.le)
|
|
501
|
+
parts.push(`${filter.le[0]} le ${this.formatFilterValue(filter.le[1])}`);
|
|
502
|
+
if (filter.contains)
|
|
503
|
+
parts.push(`contains(${filter.contains[0]},'${filter.contains[1]}')`);
|
|
504
|
+
if (filter.startswith)
|
|
505
|
+
parts.push(`startswith(${filter.startswith[0]},'${filter.startswith[1]}')`);
|
|
506
|
+
if (filter.endswith)
|
|
507
|
+
parts.push(`endswith(${filter.endswith[0]},'${filter.endswith[1]}')`);
|
|
508
|
+
if (filter.and) {
|
|
509
|
+
const andParts = filter.and.map((f) => this.formatFilterExpression(f));
|
|
510
|
+
parts.push(`(${andParts.join(' and ')})`);
|
|
511
|
+
}
|
|
512
|
+
if (filter.or) {
|
|
513
|
+
const orParts = filter.or.map((f) => this.formatFilterExpression(f));
|
|
514
|
+
parts.push(`(${orParts.join(' or ')})`);
|
|
515
|
+
}
|
|
516
|
+
if (filter.not) {
|
|
517
|
+
parts.push(`not (${this.formatFilterExpression(filter.not)})`);
|
|
518
|
+
}
|
|
519
|
+
return parts.join(' and ');
|
|
520
|
+
}
|
|
521
|
+
formatFilterValue(value) {
|
|
522
|
+
if (value === null)
|
|
523
|
+
return 'null';
|
|
524
|
+
if (typeof value === 'string')
|
|
525
|
+
return `'${value.replace(/'/g, "''")}'`;
|
|
526
|
+
if (typeof value === 'boolean')
|
|
527
|
+
return value.toString();
|
|
528
|
+
if (typeof value === 'number')
|
|
529
|
+
return value.toString();
|
|
530
|
+
if (value instanceof Date)
|
|
531
|
+
return value.toISOString();
|
|
532
|
+
return String(value);
|
|
533
|
+
}
|
|
534
|
+
parseBatchResponse(responseText) {
|
|
535
|
+
const results = [];
|
|
536
|
+
const boundaryMatch = responseText.match(/--batch[^\r\n]+/);
|
|
537
|
+
if (!boundaryMatch)
|
|
538
|
+
return results;
|
|
539
|
+
const boundary = boundaryMatch[0];
|
|
540
|
+
const parts = responseText.split(boundary).slice(1, -1);
|
|
541
|
+
for (const part of parts) {
|
|
542
|
+
const statusMatch = part.match(/HTTP\/\d\.\d\s+(\d+)/);
|
|
543
|
+
const bodyMatch = part.match(/\r\n\r\n({[\s\S]*})/);
|
|
544
|
+
results.push({
|
|
545
|
+
status: statusMatch ? parseInt(statusMatch[1], 10) : 0,
|
|
546
|
+
body: bodyMatch ? JSON.parse(bodyMatch[1]) : null,
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
return results;
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
export function createODataClient(client, options) {
|
|
553
|
+
return new ODataClient(client, options);
|
|
554
|
+
}
|
|
555
|
+
export function odata() {
|
|
556
|
+
return (client) => {
|
|
557
|
+
client.odata = (serviceRoot, options) => {
|
|
558
|
+
return createODataClient(client, { serviceRoot, ...options });
|
|
559
|
+
};
|
|
560
|
+
};
|
|
561
|
+
}
|
package/dist/plugins/retry.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export interface RetryOptions {
|
|
|
9
9
|
statusCodes?: number[];
|
|
10
10
|
shouldRetry?: (error: unknown) => boolean;
|
|
11
11
|
onRetry?: (attempt: number, error: unknown, delay: number) => void;
|
|
12
|
+
respectRetryAfter?: boolean;
|
|
12
13
|
}
|
|
13
14
|
export declare function retry(options?: RetryOptions): Plugin;
|
|
14
15
|
//# sourceMappingURL=retry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../src/plugins/retry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAGvD,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,aAAa,GAAG,cAAc,CAAC;AAExE,MAAM,WAAW,YAAY;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;IAC1C,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../src/plugins/retry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAGvD,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,aAAa,GAAG,cAAc,CAAC;AAExE,MAAM,WAAW,YAAY;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;IAC1C,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAMnE,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AA4ED,wBAAgB,KAAK,CAAC,OAAO,GAAE,YAAiB,GAAG,MAAM,CA2FxD"}
|
package/dist/plugins/retry.js
CHANGED
|
@@ -23,14 +23,29 @@ function calculateDelay(attempt, baseDelay, maxDelay, strategy, useJitter) {
|
|
|
23
23
|
}
|
|
24
24
|
return Math.max(0, Math.floor(calculatedDelay));
|
|
25
25
|
}
|
|
26
|
+
function parseRetryAfter(headerValue) {
|
|
27
|
+
if (!headerValue)
|
|
28
|
+
return undefined;
|
|
29
|
+
const seconds = parseInt(headerValue, 10);
|
|
30
|
+
if (!isNaN(seconds) && seconds >= 0) {
|
|
31
|
+
return seconds * 1000;
|
|
32
|
+
}
|
|
33
|
+
const date = Date.parse(headerValue);
|
|
34
|
+
if (!isNaN(date)) {
|
|
35
|
+
const delay = date - Date.now();
|
|
36
|
+
return delay > 0 ? delay : undefined;
|
|
37
|
+
}
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
26
40
|
export function retry(options = {}) {
|
|
27
41
|
const maxAttempts = options.maxAttempts || 3;
|
|
28
42
|
const baseDelay = options.delay || 1000;
|
|
29
|
-
const maxDelay = options.maxDelay ||
|
|
43
|
+
const maxDelay = options.maxDelay || 30000;
|
|
30
44
|
const backoffStrategy = options.backoff || 'exponential';
|
|
31
45
|
const useJitter = options.jitter !== false;
|
|
32
46
|
const statusCodes = options.statusCodes || [408, 429, 500, 502, 503, 504];
|
|
33
47
|
const onRetry = options.onRetry;
|
|
48
|
+
const respectRetryAfter = options.respectRetryAfter !== false;
|
|
34
49
|
const defaultShouldRetry = (error) => {
|
|
35
50
|
if (error instanceof NetworkError)
|
|
36
51
|
return true;
|
|
@@ -54,7 +69,16 @@ export function retry(options = {}) {
|
|
|
54
69
|
attempt++;
|
|
55
70
|
const res = await next(req);
|
|
56
71
|
if (attempt < maxAttempts && !res.ok && statusCodes.includes(res.status)) {
|
|
57
|
-
|
|
72
|
+
let delayMs;
|
|
73
|
+
if (respectRetryAfter) {
|
|
74
|
+
const retryAfterDelay = parseRetryAfter(res.headers.get('Retry-After'));
|
|
75
|
+
delayMs = retryAfterDelay !== undefined
|
|
76
|
+
? Math.min(retryAfterDelay, maxDelay)
|
|
77
|
+
: calculateDelay(attempt, baseDelay, maxDelay, backoffStrategy, useJitter);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
delayMs = calculateDelay(attempt, baseDelay, maxDelay, backoffStrategy, useJitter);
|
|
81
|
+
}
|
|
58
82
|
const err = new HttpError(res, req);
|
|
59
83
|
if (onRetry) {
|
|
60
84
|
onRetry(attempt, err, delayMs);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ReckerResponse } from '../types/index.js';
|
|
2
|
+
import type { RequestPromise } from '../core/request-promise.js';
|
|
3
|
+
import type { ScrapeOptions, ExtractionSchema, ExtractedLink, ExtractedImage, ExtractedMeta, OpenGraphData, TwitterCardData, JsonLdData, ExtractedForm, ExtractedTable, ExtractedScript, ExtractedStyle, LinkExtractionOptions, ImageExtractionOptions } from '../scrape/types.js';
|
|
4
|
+
export interface ScrapePromise<T> extends Promise<T> {
|
|
5
|
+
scrape(options?: ScrapeOptions): Promise<import('../scrape/document.js').ScrapeDocument>;
|
|
6
|
+
links(options?: LinkExtractionOptions): Promise<ExtractedLink[]>;
|
|
7
|
+
images(options?: ImageExtractionOptions): Promise<ExtractedImage[]>;
|
|
8
|
+
meta(): Promise<ExtractedMeta>;
|
|
9
|
+
openGraph(): Promise<OpenGraphData>;
|
|
10
|
+
twitterCard(): Promise<TwitterCardData>;
|
|
11
|
+
jsonLd(): Promise<JsonLdData[]>;
|
|
12
|
+
forms(selector?: string): Promise<ExtractedForm[]>;
|
|
13
|
+
tables(selector?: string): Promise<ExtractedTable[]>;
|
|
14
|
+
scripts(): Promise<ExtractedScript[]>;
|
|
15
|
+
styles(): Promise<ExtractedStyle[]>;
|
|
16
|
+
extract<R extends Record<string, unknown>>(schema: ExtractionSchema): Promise<R>;
|
|
17
|
+
}
|
|
18
|
+
export declare function scrape<T extends ReckerResponse>(promise: RequestPromise<T> | Promise<T>): ScrapePromise<T>;
|
|
19
|
+
export declare function parseHtml(html: string, options?: ScrapeOptions): Promise<import('../scrape/document.js').ScrapeDocument>;
|
|
20
|
+
export declare function scrapeResponse(promise: Promise<ReckerResponse>, options?: ScrapeOptions): Promise<import('../scrape/document.js').ScrapeDocument>;
|
|
21
|
+
export type { ScrapeOptions, ExtractionSchema, ExtractedLink, ExtractedImage, ExtractedMeta, OpenGraphData, TwitterCardData, JsonLdData, ExtractedForm, ExtractedFormField, ExtractedTable, ExtractedScript, ExtractedStyle, LinkExtractionOptions, ImageExtractionOptions, } from '../scrape/types.js';
|
|
22
|
+
//# sourceMappingURL=scrape.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scrape.d.ts","sourceRoot":"","sources":["../../src/plugins/scrape.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,KAAK,EACV,aAAa,EACb,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,aAAa,EACb,aAAa,EACb,eAAe,EACf,UAAU,EACV,aAAa,EACb,cAAc,EACd,eAAe,EACf,cAAc,EACd,qBAAqB,EACrB,sBAAsB,EACvB,MAAM,oBAAoB,CAAC;AAsB5B,MAAM,WAAW,aAAa,CAAC,CAAC,CAAE,SAAQ,OAAO,CAAC,CAAC,CAAC;IAIlD,MAAM,CAAC,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,OAAO,uBAAuB,EAAE,cAAc,CAAC,CAAC;IAKzF,KAAK,CAAC,OAAO,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;IAKjE,MAAM,CAAC,OAAO,CAAC,EAAE,sBAAsB,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;IAKpE,IAAI,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC;IAK/B,SAAS,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC;IAKpC,WAAW,IAAI,OAAO,CAAC,eAAe,CAAC,CAAC;IAKxC,MAAM,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;IAKhC,KAAK,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;IAKnD,MAAM,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;IAKrD,OAAO,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC,CAAC;IAKtC,MAAM,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;IAKpC,OAAO,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CAClF;AA2BD,wBAAgB,MAAM,CAAC,CAAC,SAAS,cAAc,EAC7C,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GACtC,aAAa,CAAC,CAAC,CAAC,CA8ElB;AAcD,wBAAsB,SAAS,CAC7B,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,OAAO,uBAAuB,EAAE,cAAc,CAAC,CAGzD;AAaD,wBAAsB,cAAc,CAClC,OAAO,EAAE,OAAO,CAAC,cAAc,CAAC,EAChC,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,OAAO,uBAAuB,EAAE,cAAc,CAAC,CAQzD;AAGD,YAAY,EACV,aAAa,EACb,gBAAgB,EAChB,aAAa,EACb,cAAc,EACd,aAAa,EACb,aAAa,EACb,eAAe,EACf,UAAU,EACV,aAAa,EACb,kBAAkB,EAClB,cAAc,EACd,eAAe,EACf,cAAc,EACd,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,oBAAoB,CAAC"}
|