@orpc/client 0.0.0-next.bb2589d → 0.0.0-next.bbe55b7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -22
- package/dist/adapters/fetch/index.d.mts +30 -10
- package/dist/adapters/fetch/index.d.ts +30 -10
- package/dist/adapters/fetch/index.mjs +25 -8
- package/dist/adapters/message-port/index.d.mts +80 -0
- package/dist/adapters/message-port/index.d.ts +80 -0
- package/dist/adapters/message-port/index.mjs +87 -0
- package/dist/adapters/standard/index.d.mts +6 -5
- package/dist/adapters/standard/index.d.ts +6 -5
- package/dist/adapters/standard/index.mjs +4 -2
- package/dist/adapters/websocket/index.d.mts +29 -0
- package/dist/adapters/websocket/index.d.ts +29 -0
- package/dist/adapters/websocket/index.mjs +47 -0
- package/dist/index.d.mts +96 -21
- package/dist/index.d.ts +96 -21
- package/dist/index.mjs +55 -8
- package/dist/plugins/index.d.mts +123 -17
- package/dist/plugins/index.d.ts +123 -17
- package/dist/plugins/index.mjs +233 -38
- package/dist/shared/client.BH1AYT_p.d.mts +83 -0
- package/dist/shared/client.BH1AYT_p.d.ts +83 -0
- package/dist/shared/client.BLtwTQUg.mjs +40 -0
- package/dist/shared/{client.Dc8eXpCj.d.ts → client.BxV-mzeR.d.ts} +10 -9
- package/dist/shared/{client.FvDtk0Vr.d.ts → client.CPgZaUox.d.mts} +14 -14
- package/dist/shared/{client.DpICn1BD.mjs → client.CbpS8v0E.mjs} +63 -20
- package/dist/shared/{client.CRWEpqLB.mjs → client.Cy4wXye7.mjs} +37 -41
- package/dist/shared/{client.DXvQo1nS.d.mts → client.D8lMmWVC.d.mts} +10 -9
- package/dist/shared/{client.Bt2hFtM_.d.mts → client.De8SW4Kw.d.ts} +14 -14
- package/package.json +16 -5
- package/dist/shared/client.CipPQkhk.d.mts +0 -29
- package/dist/shared/client.CipPQkhk.d.ts +0 -29
package/dist/plugins/index.d.mts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { Value } from '@orpc/shared';
|
|
2
|
-
import { StandardHeaders, StandardRequest } from '@orpc/standard-server';
|
|
3
|
-
import {
|
|
4
|
-
import { a as
|
|
1
|
+
import { Value, Promisable } from '@orpc/shared';
|
|
2
|
+
import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
3
|
+
import { BatchResponseMode } from '@orpc/standard-server/batch';
|
|
4
|
+
import { S as StandardLinkClientInterceptorOptions, a as StandardLinkPlugin, b as StandardLinkOptions, c as StandardLinkInterceptorOptions } from '../shared/client.CPgZaUox.mjs';
|
|
5
|
+
import { b as ClientContext } from '../shared/client.BH1AYT_p.mjs';
|
|
5
6
|
|
|
6
7
|
interface BatchLinkPluginGroup<T extends ClientContext> {
|
|
7
8
|
condition(options: StandardLinkClientInterceptorOptions<T>): boolean;
|
|
@@ -16,25 +17,31 @@ interface BatchLinkPluginOptions<T extends ClientContext> {
|
|
|
16
17
|
*
|
|
17
18
|
* @default 10
|
|
18
19
|
*/
|
|
19
|
-
maxSize?: Value<number
|
|
20
|
+
maxSize?: Value<Promisable<number>, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
|
|
21
|
+
/**
|
|
22
|
+
* The batch response mode.
|
|
23
|
+
*
|
|
24
|
+
* @default 'streaming'
|
|
25
|
+
*/
|
|
26
|
+
mode?: Value<BatchResponseMode, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
|
|
20
27
|
/**
|
|
21
28
|
* Defines the URL to use for the batch request.
|
|
22
29
|
*
|
|
23
30
|
* @default the URL of the first request in the batch + '/__batch__'
|
|
24
31
|
*/
|
|
25
|
-
url?: Value<string | URL
|
|
32
|
+
url?: Value<Promisable<string | URL>, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
|
|
26
33
|
/**
|
|
27
34
|
* The maximum length of the URL.
|
|
28
35
|
*
|
|
29
36
|
* @default 2083
|
|
30
37
|
*/
|
|
31
|
-
maxUrlLength?: Value<number
|
|
38
|
+
maxUrlLength?: Value<Promisable<number>, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
|
|
32
39
|
/**
|
|
33
40
|
* Defines the HTTP headers to use for the batch request.
|
|
34
41
|
*
|
|
35
42
|
* @default The same headers of all requests in the batch
|
|
36
43
|
*/
|
|
37
|
-
headers?: Value<StandardHeaders
|
|
44
|
+
headers?: Value<Promisable<StandardHeaders>, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
|
|
38
45
|
/**
|
|
39
46
|
* Map the batch request items before sending them.
|
|
40
47
|
*
|
|
@@ -51,6 +58,12 @@ interface BatchLinkPluginOptions<T extends ClientContext> {
|
|
|
51
58
|
*/
|
|
52
59
|
exclude?: (options: StandardLinkClientInterceptorOptions<T>) => boolean;
|
|
53
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* The Batch Requests Plugin allows you to combine multiple requests and responses into a single batch,
|
|
63
|
+
* reducing the overhead of sending each one separately.
|
|
64
|
+
*
|
|
65
|
+
* @see {@link https://orpc.unnoq.com/docs/plugins/batch-requests Batch Requests Plugin Docs}
|
|
66
|
+
*/
|
|
54
67
|
declare class BatchLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
55
68
|
#private;
|
|
56
69
|
private readonly groups;
|
|
@@ -60,9 +73,42 @@ declare class BatchLinkPlugin<T extends ClientContext> implements StandardLinkPl
|
|
|
60
73
|
private readonly batchHeaders;
|
|
61
74
|
private readonly mapRequestItem;
|
|
62
75
|
private readonly exclude;
|
|
76
|
+
private readonly mode;
|
|
63
77
|
private pending;
|
|
64
78
|
order: number;
|
|
65
|
-
constructor(options: BatchLinkPluginOptions<T
|
|
79
|
+
constructor(options: NoInfer<BatchLinkPluginOptions<T>>);
|
|
80
|
+
init(options: StandardLinkOptions<T>): void;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
interface DedupeRequestsPluginGroup<T extends ClientContext> {
|
|
84
|
+
condition(options: StandardLinkClientInterceptorOptions<T>): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* The context used for the rest of the request lifecycle.
|
|
87
|
+
*/
|
|
88
|
+
context: T;
|
|
89
|
+
}
|
|
90
|
+
interface DedupeRequestsPluginOptions<T extends ClientContext> {
|
|
91
|
+
/**
|
|
92
|
+
* To enable deduplication, a request must match at least one defined group.
|
|
93
|
+
* Requests that fall into the same group are considered for deduplication together.
|
|
94
|
+
*/
|
|
95
|
+
groups: readonly [DedupeRequestsPluginGroup<T>, ...DedupeRequestsPluginGroup<T>[]];
|
|
96
|
+
/**
|
|
97
|
+
* Filters requests to dedupe
|
|
98
|
+
*
|
|
99
|
+
* @default (({ request }) => request.method === 'GET')
|
|
100
|
+
*/
|
|
101
|
+
filter?: (options: StandardLinkClientInterceptorOptions<T>) => boolean;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Prevents duplicate requests by deduplicating similar ones to reduce server load.
|
|
105
|
+
*
|
|
106
|
+
* @see {@link https://orpc.unnoq.com/docs/plugins/dedupe-requests Dedupe Requests Plugin}
|
|
107
|
+
*/
|
|
108
|
+
declare class DedupeRequestsPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
109
|
+
#private;
|
|
110
|
+
order: number;
|
|
111
|
+
constructor(options: NoInfer<DedupeRequestsPluginOptions<T>>);
|
|
66
112
|
init(options: StandardLinkOptions<T>): void;
|
|
67
113
|
}
|
|
68
114
|
|
|
@@ -78,59 +124,118 @@ interface ClientRetryPluginContext {
|
|
|
78
124
|
*
|
|
79
125
|
* @default 0
|
|
80
126
|
*/
|
|
81
|
-
retry?: Value<number
|
|
127
|
+
retry?: Value<Promisable<number>, [StandardLinkInterceptorOptions<ClientRetryPluginContext>]>;
|
|
82
128
|
/**
|
|
83
129
|
* Delay (in ms) before retrying.
|
|
84
130
|
*
|
|
85
131
|
* @default (o) => o.lastEventRetry ?? 2000
|
|
86
132
|
*/
|
|
87
|
-
retryDelay?: Value<number
|
|
133
|
+
retryDelay?: Value<Promisable<number>, [ClientRetryPluginAttemptOptions<ClientRetryPluginContext>]>;
|
|
88
134
|
/**
|
|
89
135
|
* Determine should retry or not.
|
|
90
136
|
*
|
|
91
137
|
* @default true
|
|
92
138
|
*/
|
|
93
|
-
shouldRetry?: Value<boolean
|
|
139
|
+
shouldRetry?: Value<Promisable<boolean>, [ClientRetryPluginAttemptOptions<ClientRetryPluginContext>]>;
|
|
94
140
|
/**
|
|
95
141
|
* The hook called when retrying, and return the unsubscribe function.
|
|
96
142
|
*/
|
|
97
|
-
onRetry?: (options: ClientRetryPluginAttemptOptions<ClientRetryPluginContext>) => void | (() => void);
|
|
143
|
+
onRetry?: (options: ClientRetryPluginAttemptOptions<ClientRetryPluginContext>) => void | ((isSuccess: boolean) => void);
|
|
98
144
|
}
|
|
99
145
|
declare class ClientRetryPluginInvalidEventIteratorRetryResponse extends Error {
|
|
100
146
|
}
|
|
101
147
|
interface ClientRetryPluginOptions {
|
|
102
148
|
default?: ClientRetryPluginContext;
|
|
103
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* The Client Retry Plugin enables retrying client calls when errors occur.
|
|
152
|
+
*
|
|
153
|
+
* @see {@link https://orpc.unnoq.com/docs/plugins/client-retry Client Retry Plugin Docs}
|
|
154
|
+
*/
|
|
104
155
|
declare class ClientRetryPlugin<T extends ClientRetryPluginContext> implements StandardLinkPlugin<T> {
|
|
105
156
|
private readonly defaultRetry;
|
|
106
157
|
private readonly defaultRetryDelay;
|
|
107
158
|
private readonly defaultShouldRetry;
|
|
108
159
|
private readonly defaultOnRetry;
|
|
160
|
+
order: number;
|
|
109
161
|
constructor(options?: ClientRetryPluginOptions);
|
|
110
162
|
init(options: StandardLinkOptions<T>): void;
|
|
111
163
|
}
|
|
112
164
|
|
|
165
|
+
interface RetryAfterPluginOptions<T extends ClientContext> {
|
|
166
|
+
/**
|
|
167
|
+
* Override condition to determine whether to retry or not.
|
|
168
|
+
*
|
|
169
|
+
* @default ((response) => response.status === 429 || response.status === 503)
|
|
170
|
+
*/
|
|
171
|
+
condition?: Value<boolean, [
|
|
172
|
+
response: StandardLazyResponse,
|
|
173
|
+
options: StandardLinkClientInterceptorOptions<T>
|
|
174
|
+
]>;
|
|
175
|
+
/**
|
|
176
|
+
* Maximum attempts before giving up retries.
|
|
177
|
+
*
|
|
178
|
+
* @default 3
|
|
179
|
+
*/
|
|
180
|
+
maxAttempts?: Value<number, [
|
|
181
|
+
response: StandardLazyResponse,
|
|
182
|
+
options: StandardLinkClientInterceptorOptions<T>
|
|
183
|
+
]>;
|
|
184
|
+
/**
|
|
185
|
+
* Maximum timeout in milliseconds to wait before giving up retries.
|
|
186
|
+
*
|
|
187
|
+
* @default 5 * 60 * 1000 (5 minutes)
|
|
188
|
+
*/
|
|
189
|
+
timeout?: Value<number, [
|
|
190
|
+
response: StandardLazyResponse,
|
|
191
|
+
options: StandardLinkClientInterceptorOptions<T>
|
|
192
|
+
]>;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* The Retry After Plugin automatically retries requests based on server `Retry-After` headers.
|
|
196
|
+
* This is particularly useful for handling rate limiting and temporary server unavailability.
|
|
197
|
+
*
|
|
198
|
+
* @see {@link https://orpc.unnoq.com/docs/plugins/retry-after Retry After Plugin Docs}
|
|
199
|
+
*/
|
|
200
|
+
declare class RetryAfterPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
201
|
+
private readonly condition;
|
|
202
|
+
private readonly maxAttempts;
|
|
203
|
+
private readonly timeout;
|
|
204
|
+
order: number;
|
|
205
|
+
constructor(options?: RetryAfterPluginOptions<T>);
|
|
206
|
+
init(options: StandardLinkOptions<T>): void;
|
|
207
|
+
private parseRetryAfterHeader;
|
|
208
|
+
private delayExecution;
|
|
209
|
+
}
|
|
210
|
+
|
|
113
211
|
interface SimpleCsrfProtectionLinkPluginOptions<T extends ClientContext> {
|
|
114
212
|
/**
|
|
115
213
|
* The name of the header to check.
|
|
116
214
|
*
|
|
117
215
|
* @default 'x-csrf-token'
|
|
118
216
|
*/
|
|
119
|
-
headerName?: Value<string
|
|
217
|
+
headerName?: Value<Promisable<string>, [options: StandardLinkClientInterceptorOptions<T>]>;
|
|
120
218
|
/**
|
|
121
219
|
* The value of the header to check.
|
|
122
220
|
*
|
|
123
221
|
* @default 'orpc'
|
|
124
222
|
*
|
|
125
223
|
*/
|
|
126
|
-
headerValue?: Value<string
|
|
224
|
+
headerValue?: Value<Promisable<string>, [options: StandardLinkClientInterceptorOptions<T>]>;
|
|
127
225
|
/**
|
|
128
226
|
* Exclude a procedure from the plugin.
|
|
129
227
|
*
|
|
130
228
|
* @default false
|
|
131
229
|
*/
|
|
132
|
-
exclude?: Value<boolean
|
|
230
|
+
exclude?: Value<Promisable<boolean>, [options: StandardLinkClientInterceptorOptions<T>]>;
|
|
133
231
|
}
|
|
232
|
+
/**
|
|
233
|
+
* This plugin adds basic Cross-Site Request Forgery (CSRF) protection to your oRPC application.
|
|
234
|
+
* It helps ensure that requests to your procedures originate from JavaScript code,
|
|
235
|
+
* not from other sources like standard HTML forms or direct browser navigation.
|
|
236
|
+
*
|
|
237
|
+
* @see {@link https://orpc.unnoq.com/docs/plugins/simple-csrf-protection Simple CSRF Protection Plugin Docs}
|
|
238
|
+
*/
|
|
134
239
|
declare class SimpleCsrfProtectionLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
135
240
|
private readonly headerName;
|
|
136
241
|
private readonly headerValue;
|
|
@@ -140,4 +245,5 @@ declare class SimpleCsrfProtectionLinkPlugin<T extends ClientContext> implements
|
|
|
140
245
|
init(options: StandardLinkOptions<T>): void;
|
|
141
246
|
}
|
|
142
247
|
|
|
143
|
-
export { BatchLinkPlugin,
|
|
248
|
+
export { BatchLinkPlugin, ClientRetryPlugin, ClientRetryPluginInvalidEventIteratorRetryResponse, DedupeRequestsPlugin, RetryAfterPlugin, SimpleCsrfProtectionLinkPlugin };
|
|
249
|
+
export type { BatchLinkPluginGroup, BatchLinkPluginOptions, ClientRetryPluginAttemptOptions, ClientRetryPluginContext, ClientRetryPluginOptions, DedupeRequestsPluginGroup, DedupeRequestsPluginOptions, RetryAfterPluginOptions, SimpleCsrfProtectionLinkPluginOptions };
|
package/dist/plugins/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { Value } from '@orpc/shared';
|
|
2
|
-
import { StandardHeaders, StandardRequest } from '@orpc/standard-server';
|
|
3
|
-
import {
|
|
4
|
-
import { a as
|
|
1
|
+
import { Value, Promisable } from '@orpc/shared';
|
|
2
|
+
import { StandardHeaders, StandardRequest, StandardLazyResponse } from '@orpc/standard-server';
|
|
3
|
+
import { BatchResponseMode } from '@orpc/standard-server/batch';
|
|
4
|
+
import { S as StandardLinkClientInterceptorOptions, a as StandardLinkPlugin, b as StandardLinkOptions, c as StandardLinkInterceptorOptions } from '../shared/client.De8SW4Kw.js';
|
|
5
|
+
import { b as ClientContext } from '../shared/client.BH1AYT_p.js';
|
|
5
6
|
|
|
6
7
|
interface BatchLinkPluginGroup<T extends ClientContext> {
|
|
7
8
|
condition(options: StandardLinkClientInterceptorOptions<T>): boolean;
|
|
@@ -16,25 +17,31 @@ interface BatchLinkPluginOptions<T extends ClientContext> {
|
|
|
16
17
|
*
|
|
17
18
|
* @default 10
|
|
18
19
|
*/
|
|
19
|
-
maxSize?: Value<number
|
|
20
|
+
maxSize?: Value<Promisable<number>, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
|
|
21
|
+
/**
|
|
22
|
+
* The batch response mode.
|
|
23
|
+
*
|
|
24
|
+
* @default 'streaming'
|
|
25
|
+
*/
|
|
26
|
+
mode?: Value<BatchResponseMode, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
|
|
20
27
|
/**
|
|
21
28
|
* Defines the URL to use for the batch request.
|
|
22
29
|
*
|
|
23
30
|
* @default the URL of the first request in the batch + '/__batch__'
|
|
24
31
|
*/
|
|
25
|
-
url?: Value<string | URL
|
|
32
|
+
url?: Value<Promisable<string | URL>, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
|
|
26
33
|
/**
|
|
27
34
|
* The maximum length of the URL.
|
|
28
35
|
*
|
|
29
36
|
* @default 2083
|
|
30
37
|
*/
|
|
31
|
-
maxUrlLength?: Value<number
|
|
38
|
+
maxUrlLength?: Value<Promisable<number>, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
|
|
32
39
|
/**
|
|
33
40
|
* Defines the HTTP headers to use for the batch request.
|
|
34
41
|
*
|
|
35
42
|
* @default The same headers of all requests in the batch
|
|
36
43
|
*/
|
|
37
|
-
headers?: Value<StandardHeaders
|
|
44
|
+
headers?: Value<Promisable<StandardHeaders>, [readonly [StandardLinkClientInterceptorOptions<T>, ...StandardLinkClientInterceptorOptions<T>[]]]>;
|
|
38
45
|
/**
|
|
39
46
|
* Map the batch request items before sending them.
|
|
40
47
|
*
|
|
@@ -51,6 +58,12 @@ interface BatchLinkPluginOptions<T extends ClientContext> {
|
|
|
51
58
|
*/
|
|
52
59
|
exclude?: (options: StandardLinkClientInterceptorOptions<T>) => boolean;
|
|
53
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* The Batch Requests Plugin allows you to combine multiple requests and responses into a single batch,
|
|
63
|
+
* reducing the overhead of sending each one separately.
|
|
64
|
+
*
|
|
65
|
+
* @see {@link https://orpc.unnoq.com/docs/plugins/batch-requests Batch Requests Plugin Docs}
|
|
66
|
+
*/
|
|
54
67
|
declare class BatchLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
55
68
|
#private;
|
|
56
69
|
private readonly groups;
|
|
@@ -60,9 +73,42 @@ declare class BatchLinkPlugin<T extends ClientContext> implements StandardLinkPl
|
|
|
60
73
|
private readonly batchHeaders;
|
|
61
74
|
private readonly mapRequestItem;
|
|
62
75
|
private readonly exclude;
|
|
76
|
+
private readonly mode;
|
|
63
77
|
private pending;
|
|
64
78
|
order: number;
|
|
65
|
-
constructor(options: BatchLinkPluginOptions<T
|
|
79
|
+
constructor(options: NoInfer<BatchLinkPluginOptions<T>>);
|
|
80
|
+
init(options: StandardLinkOptions<T>): void;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
interface DedupeRequestsPluginGroup<T extends ClientContext> {
|
|
84
|
+
condition(options: StandardLinkClientInterceptorOptions<T>): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* The context used for the rest of the request lifecycle.
|
|
87
|
+
*/
|
|
88
|
+
context: T;
|
|
89
|
+
}
|
|
90
|
+
interface DedupeRequestsPluginOptions<T extends ClientContext> {
|
|
91
|
+
/**
|
|
92
|
+
* To enable deduplication, a request must match at least one defined group.
|
|
93
|
+
* Requests that fall into the same group are considered for deduplication together.
|
|
94
|
+
*/
|
|
95
|
+
groups: readonly [DedupeRequestsPluginGroup<T>, ...DedupeRequestsPluginGroup<T>[]];
|
|
96
|
+
/**
|
|
97
|
+
* Filters requests to dedupe
|
|
98
|
+
*
|
|
99
|
+
* @default (({ request }) => request.method === 'GET')
|
|
100
|
+
*/
|
|
101
|
+
filter?: (options: StandardLinkClientInterceptorOptions<T>) => boolean;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Prevents duplicate requests by deduplicating similar ones to reduce server load.
|
|
105
|
+
*
|
|
106
|
+
* @see {@link https://orpc.unnoq.com/docs/plugins/dedupe-requests Dedupe Requests Plugin}
|
|
107
|
+
*/
|
|
108
|
+
declare class DedupeRequestsPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
109
|
+
#private;
|
|
110
|
+
order: number;
|
|
111
|
+
constructor(options: NoInfer<DedupeRequestsPluginOptions<T>>);
|
|
66
112
|
init(options: StandardLinkOptions<T>): void;
|
|
67
113
|
}
|
|
68
114
|
|
|
@@ -78,59 +124,118 @@ interface ClientRetryPluginContext {
|
|
|
78
124
|
*
|
|
79
125
|
* @default 0
|
|
80
126
|
*/
|
|
81
|
-
retry?: Value<number
|
|
127
|
+
retry?: Value<Promisable<number>, [StandardLinkInterceptorOptions<ClientRetryPluginContext>]>;
|
|
82
128
|
/**
|
|
83
129
|
* Delay (in ms) before retrying.
|
|
84
130
|
*
|
|
85
131
|
* @default (o) => o.lastEventRetry ?? 2000
|
|
86
132
|
*/
|
|
87
|
-
retryDelay?: Value<number
|
|
133
|
+
retryDelay?: Value<Promisable<number>, [ClientRetryPluginAttemptOptions<ClientRetryPluginContext>]>;
|
|
88
134
|
/**
|
|
89
135
|
* Determine should retry or not.
|
|
90
136
|
*
|
|
91
137
|
* @default true
|
|
92
138
|
*/
|
|
93
|
-
shouldRetry?: Value<boolean
|
|
139
|
+
shouldRetry?: Value<Promisable<boolean>, [ClientRetryPluginAttemptOptions<ClientRetryPluginContext>]>;
|
|
94
140
|
/**
|
|
95
141
|
* The hook called when retrying, and return the unsubscribe function.
|
|
96
142
|
*/
|
|
97
|
-
onRetry?: (options: ClientRetryPluginAttemptOptions<ClientRetryPluginContext>) => void | (() => void);
|
|
143
|
+
onRetry?: (options: ClientRetryPluginAttemptOptions<ClientRetryPluginContext>) => void | ((isSuccess: boolean) => void);
|
|
98
144
|
}
|
|
99
145
|
declare class ClientRetryPluginInvalidEventIteratorRetryResponse extends Error {
|
|
100
146
|
}
|
|
101
147
|
interface ClientRetryPluginOptions {
|
|
102
148
|
default?: ClientRetryPluginContext;
|
|
103
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* The Client Retry Plugin enables retrying client calls when errors occur.
|
|
152
|
+
*
|
|
153
|
+
* @see {@link https://orpc.unnoq.com/docs/plugins/client-retry Client Retry Plugin Docs}
|
|
154
|
+
*/
|
|
104
155
|
declare class ClientRetryPlugin<T extends ClientRetryPluginContext> implements StandardLinkPlugin<T> {
|
|
105
156
|
private readonly defaultRetry;
|
|
106
157
|
private readonly defaultRetryDelay;
|
|
107
158
|
private readonly defaultShouldRetry;
|
|
108
159
|
private readonly defaultOnRetry;
|
|
160
|
+
order: number;
|
|
109
161
|
constructor(options?: ClientRetryPluginOptions);
|
|
110
162
|
init(options: StandardLinkOptions<T>): void;
|
|
111
163
|
}
|
|
112
164
|
|
|
165
|
+
interface RetryAfterPluginOptions<T extends ClientContext> {
|
|
166
|
+
/**
|
|
167
|
+
* Override condition to determine whether to retry or not.
|
|
168
|
+
*
|
|
169
|
+
* @default ((response) => response.status === 429 || response.status === 503)
|
|
170
|
+
*/
|
|
171
|
+
condition?: Value<boolean, [
|
|
172
|
+
response: StandardLazyResponse,
|
|
173
|
+
options: StandardLinkClientInterceptorOptions<T>
|
|
174
|
+
]>;
|
|
175
|
+
/**
|
|
176
|
+
* Maximum attempts before giving up retries.
|
|
177
|
+
*
|
|
178
|
+
* @default 3
|
|
179
|
+
*/
|
|
180
|
+
maxAttempts?: Value<number, [
|
|
181
|
+
response: StandardLazyResponse,
|
|
182
|
+
options: StandardLinkClientInterceptorOptions<T>
|
|
183
|
+
]>;
|
|
184
|
+
/**
|
|
185
|
+
* Maximum timeout in milliseconds to wait before giving up retries.
|
|
186
|
+
*
|
|
187
|
+
* @default 5 * 60 * 1000 (5 minutes)
|
|
188
|
+
*/
|
|
189
|
+
timeout?: Value<number, [
|
|
190
|
+
response: StandardLazyResponse,
|
|
191
|
+
options: StandardLinkClientInterceptorOptions<T>
|
|
192
|
+
]>;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* The Retry After Plugin automatically retries requests based on server `Retry-After` headers.
|
|
196
|
+
* This is particularly useful for handling rate limiting and temporary server unavailability.
|
|
197
|
+
*
|
|
198
|
+
* @see {@link https://orpc.unnoq.com/docs/plugins/retry-after Retry After Plugin Docs}
|
|
199
|
+
*/
|
|
200
|
+
declare class RetryAfterPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
201
|
+
private readonly condition;
|
|
202
|
+
private readonly maxAttempts;
|
|
203
|
+
private readonly timeout;
|
|
204
|
+
order: number;
|
|
205
|
+
constructor(options?: RetryAfterPluginOptions<T>);
|
|
206
|
+
init(options: StandardLinkOptions<T>): void;
|
|
207
|
+
private parseRetryAfterHeader;
|
|
208
|
+
private delayExecution;
|
|
209
|
+
}
|
|
210
|
+
|
|
113
211
|
interface SimpleCsrfProtectionLinkPluginOptions<T extends ClientContext> {
|
|
114
212
|
/**
|
|
115
213
|
* The name of the header to check.
|
|
116
214
|
*
|
|
117
215
|
* @default 'x-csrf-token'
|
|
118
216
|
*/
|
|
119
|
-
headerName?: Value<string
|
|
217
|
+
headerName?: Value<Promisable<string>, [options: StandardLinkClientInterceptorOptions<T>]>;
|
|
120
218
|
/**
|
|
121
219
|
* The value of the header to check.
|
|
122
220
|
*
|
|
123
221
|
* @default 'orpc'
|
|
124
222
|
*
|
|
125
223
|
*/
|
|
126
|
-
headerValue?: Value<string
|
|
224
|
+
headerValue?: Value<Promisable<string>, [options: StandardLinkClientInterceptorOptions<T>]>;
|
|
127
225
|
/**
|
|
128
226
|
* Exclude a procedure from the plugin.
|
|
129
227
|
*
|
|
130
228
|
* @default false
|
|
131
229
|
*/
|
|
132
|
-
exclude?: Value<boolean
|
|
230
|
+
exclude?: Value<Promisable<boolean>, [options: StandardLinkClientInterceptorOptions<T>]>;
|
|
133
231
|
}
|
|
232
|
+
/**
|
|
233
|
+
* This plugin adds basic Cross-Site Request Forgery (CSRF) protection to your oRPC application.
|
|
234
|
+
* It helps ensure that requests to your procedures originate from JavaScript code,
|
|
235
|
+
* not from other sources like standard HTML forms or direct browser navigation.
|
|
236
|
+
*
|
|
237
|
+
* @see {@link https://orpc.unnoq.com/docs/plugins/simple-csrf-protection Simple CSRF Protection Plugin Docs}
|
|
238
|
+
*/
|
|
134
239
|
declare class SimpleCsrfProtectionLinkPlugin<T extends ClientContext> implements StandardLinkPlugin<T> {
|
|
135
240
|
private readonly headerName;
|
|
136
241
|
private readonly headerValue;
|
|
@@ -140,4 +245,5 @@ declare class SimpleCsrfProtectionLinkPlugin<T extends ClientContext> implements
|
|
|
140
245
|
init(options: StandardLinkOptions<T>): void;
|
|
141
246
|
}
|
|
142
247
|
|
|
143
|
-
export { BatchLinkPlugin,
|
|
248
|
+
export { BatchLinkPlugin, ClientRetryPlugin, ClientRetryPluginInvalidEventIteratorRetryResponse, DedupeRequestsPlugin, RetryAfterPlugin, SimpleCsrfProtectionLinkPlugin };
|
|
249
|
+
export type { BatchLinkPluginGroup, BatchLinkPluginOptions, ClientRetryPluginAttemptOptions, ClientRetryPluginContext, ClientRetryPluginOptions, DedupeRequestsPluginGroup, DedupeRequestsPluginOptions, RetryAfterPluginOptions, SimpleCsrfProtectionLinkPluginOptions };
|