arthron 1.2.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,138 @@
1
- import { S as UploadProgressEvent, a as logging, c as bearerAuth, i as retry, l as BearerAuthOptions, n as timeout, o as LogEvent, r as TimeoutOptions, s as LoggingOptions, t as uploadProgress, x as RetryOptions } from "./index-C3lylSNd.cjs";
2
- export { type BearerAuthOptions, type LogEvent, type LoggingOptions, type RetryOptions, type TimeoutOptions, type UploadProgressEvent, bearerAuth, logging, retry, timeout, uploadProgress };
1
+ import { f as RetryOptions, m as UploadProgressEvent, p as TimeoutOptions, r as Plugin } from "./shared.cjs";
2
+ //#region src/plugins/bearer-auth/bearer-auth.types.d.ts
3
+ type BearerAuthOptions = {
4
+ /**
5
+ * The origins the token may go to, as a list of URLs of which only the
6
+ * origin counts, so your `baseURL` works as is: `tokenOrigins: [API]`. A
7
+ * request anywhere else — a CDN, a URL taken from a response body — is
8
+ * sent without the token.
9
+ */
10
+ tokenOrigins: readonly string[];
11
+ /**
12
+ * Returns the current access token; called on every attempt. `null`,
13
+ * `undefined` or `""` sends no `authorization` header.
14
+ */
15
+ accessTokenFn: () => string | null | undefined | Promise<string | null | undefined>;
16
+ /**
17
+ * Refreshes the session after a 401, so the next `accessTokenFn()`
18
+ * returns the new token; the call is then redone once.
19
+ * Concurrent 401s share one refresh, and a call whose token was already
20
+ * replaced retries without one. Throw when the refresh fails — every waiting call
21
+ * rejects with that error. A request it starts through the same client
22
+ * before its first `await` goes out as with `meta: { bearerAuth: false }`
23
+ * (no token, no refresh on its 401); one started after an `await` needs
24
+ * that meta itself, or its 401 would wait for the refresh it is part of.
25
+ * Without `refreshFn`, or for a `ReadableStream` body (already read, so it
26
+ * cannot be resent), a 401 is thrown as is.
27
+ */
28
+ refreshFn?: () => Promise<void>;
29
+ };
30
+ //#endregion
31
+ //#region src/plugins/bearer-auth/bearer-auth.d.ts
32
+ /**
33
+ * Bearer-token auth. A request interceptor sets `authorization: Bearer
34
+ * <token>` on every attempt to `tokenOrigins`; with `refreshFn`, a middleware turns a
35
+ * 401 into one refresh and one more try. Concurrent 401s share the refresh
36
+ * (with refresh-token rotation, parallel refreshes revoke each other), and a
37
+ * call whose token was replaced meanwhile just retries. A call opts out with
38
+ * `meta: { bearerAuth: false }`.
39
+ */
40
+ export declare function bearerAuth(options: BearerAuthOptions): Plugin;
41
+ //#endregion
42
+ //#region src/plugins/logging/logging.types.d.ts
43
+ /**
44
+ * One step of a call, as `logging({ onEvent })` receives it. `url` is the
45
+ * request URL with its query and userinfo removed — the value
46
+ * `ArthronError.toJSON()` calls `url`. `duration` is in ms, retries
47
+ * included.
48
+ */
49
+ type LogEvent = {
50
+ phase: "start";
51
+ method: string;
52
+ url: string;
53
+ } | {
54
+ phase: "success";
55
+ method: string;
56
+ url: string;
57
+ status: number;
58
+ duration: number;
59
+ } | {
60
+ phase: "error";
61
+ method: string;
62
+ url: string;
63
+ /** HTTP status for an ArthronError (0 = network); undefined for anything else. */
64
+ status: number | undefined;
65
+ duration: number;
66
+ error: unknown;
67
+ };
68
+ type LoggingOptions = {
69
+ /** Default `true`. The library never reads `NODE_ENV` — pass `isDev` yourself. */
70
+ enabled?: boolean;
71
+ logger?: Pick<Console, "log" | "error">;
72
+ /** Receive structured events instead of the default console lines. */
73
+ onEvent?: (event: LogEvent) => void;
74
+ /**
75
+ * Default `false`. `true` reports a call that timed out before its response
76
+ * arrived — a `TimeoutError`, from `timeout()` or `AbortSignal.timeout()` —
77
+ * as an error event, `status` undefined. A timeout while the body is read
78
+ * rejects that read instead: the call has already logged its success.
79
+ * Other cancellations are never reported.
80
+ */
81
+ timeouts?: boolean;
82
+ };
83
+ //#endregion
84
+ //#region src/plugins/logging/logging.d.ts
85
+ /**
86
+ * One event when a request starts, one when it settles, with status and
87
+ * elapsed time. Wraps the whole call, so retries are included in the time.
88
+ * Default output is a console line per event; pass `onEvent` to get the
89
+ * structured event instead. Cancellations are not reported, timeouts only
90
+ * with `timeouts: true`.
91
+ */
92
+ export declare function logging(options?: LoggingOptions): Plugin;
93
+ //#endregion
94
+ //#region src/plugins/retry/retry.d.ts
95
+ /**
96
+ * Retry on network errors and the configured statuses by calling `next`
97
+ * again — the whole attempt (request interceptors included) is re-run.
98
+ * Only `ArthronError` is considered; cancellation and plugin bugs pass through.
99
+ * A call can turn it off or override its options with `meta.retry`.
100
+ */
101
+ export declare function retry(options?: RetryOptions): Plugin;
102
+ //#endregion
103
+ //#region src/plugins/timeout/timeout.d.ts
104
+ /**
105
+ * Abort the request when it takes longer than `ms` — counted from the start
106
+ * of the attempt until the body has been fully read, so a server that sends
107
+ * headers and then stalls still trips it. `timeout({ idle })` instead aborts
108
+ * once no data has arrived for that long, and never cuts off a stream that
109
+ * keeps flowing; `timeout({ total, idle })` does both. Rejects with a
110
+ * `TimeoutError` (a `DOMException`, like `AbortSignal.timeout()` would give);
111
+ * it is not an `ArthronError`, so error interceptors and `retry` leave it
112
+ * alone.
113
+ *
114
+ * A call can lift the deadlines or change them with `meta.timeout`.
115
+ *
116
+ * Deadlines are timers on an AbortController — not `AbortSignal.timeout`,
117
+ * since the idle one restarts — joined to the caller's signal with
118
+ * `AbortSignal.any`.
119
+ */
120
+ export declare function timeout(ms: number): Plugin;
121
+ export declare function timeout(options: TimeoutOptions): Plugin;
122
+ //#endregion
123
+ //#region src/plugins/upload-progress/upload-progress.d.ts
124
+ /**
125
+ * Does nothing by itself — only a call that passes `meta.uploadProgress`
126
+ * reports upload progress. On such a call it changes how that one attempt
127
+ * is sent: over XMLHttpRequest in a browser, with a counted body in Node.
128
+ * Every other call, on this client too, goes out exactly as before.
129
+ *
130
+ * Progress needs the runtime's own fetch: with a client `fetchFn`, another
131
+ * plugin's fetchFn, or a runtime that is neither (Deno, Bun, Cloudflare
132
+ * Workers, a service worker), the call is sent as usual without progress.
133
+ * Put it last in `plugins`: the call's signal carries a throwing callback's
134
+ * error, and an interceptor after it that replaces the signal would cut it.
135
+ */
136
+ export declare function uploadProgress(): Plugin;
137
+ //#endregion
138
+ export type { BearerAuthOptions, LogEvent, LoggingOptions, RetryOptions, TimeoutOptions, UploadProgressEvent };
@@ -1,2 +1,138 @@
1
- import { S as UploadProgressEvent, a as logging, c as bearerAuth, i as retry, l as BearerAuthOptions, n as timeout, o as LogEvent, r as TimeoutOptions, s as LoggingOptions, t as uploadProgress, x as RetryOptions } from "./index-C3lylSNd.mjs";
2
- export { type BearerAuthOptions, type LogEvent, type LoggingOptions, type RetryOptions, type TimeoutOptions, type UploadProgressEvent, bearerAuth, logging, retry, timeout, uploadProgress };
1
+ import { f as RetryOptions, m as UploadProgressEvent, p as TimeoutOptions, r as Plugin } from "./shared.mjs";
2
+ //#region src/plugins/bearer-auth/bearer-auth.types.d.ts
3
+ type BearerAuthOptions = {
4
+ /**
5
+ * The origins the token may go to, as a list of URLs of which only the
6
+ * origin counts, so your `baseURL` works as is: `tokenOrigins: [API]`. A
7
+ * request anywhere else — a CDN, a URL taken from a response body — is
8
+ * sent without the token.
9
+ */
10
+ tokenOrigins: readonly string[];
11
+ /**
12
+ * Returns the current access token; called on every attempt. `null`,
13
+ * `undefined` or `""` sends no `authorization` header.
14
+ */
15
+ accessTokenFn: () => string | null | undefined | Promise<string | null | undefined>;
16
+ /**
17
+ * Refreshes the session after a 401, so the next `accessTokenFn()`
18
+ * returns the new token; the call is then redone once.
19
+ * Concurrent 401s share one refresh, and a call whose token was already
20
+ * replaced retries without one. Throw when the refresh fails — every waiting call
21
+ * rejects with that error. A request it starts through the same client
22
+ * before its first `await` goes out as with `meta: { bearerAuth: false }`
23
+ * (no token, no refresh on its 401); one started after an `await` needs
24
+ * that meta itself, or its 401 would wait for the refresh it is part of.
25
+ * Without `refreshFn`, or for a `ReadableStream` body (already read, so it
26
+ * cannot be resent), a 401 is thrown as is.
27
+ */
28
+ refreshFn?: () => Promise<void>;
29
+ };
30
+ //#endregion
31
+ //#region src/plugins/bearer-auth/bearer-auth.d.ts
32
+ /**
33
+ * Bearer-token auth. A request interceptor sets `authorization: Bearer
34
+ * <token>` on every attempt to `tokenOrigins`; with `refreshFn`, a middleware turns a
35
+ * 401 into one refresh and one more try. Concurrent 401s share the refresh
36
+ * (with refresh-token rotation, parallel refreshes revoke each other), and a
37
+ * call whose token was replaced meanwhile just retries. A call opts out with
38
+ * `meta: { bearerAuth: false }`.
39
+ */
40
+ export declare function bearerAuth(options: BearerAuthOptions): Plugin;
41
+ //#endregion
42
+ //#region src/plugins/logging/logging.types.d.ts
43
+ /**
44
+ * One step of a call, as `logging({ onEvent })` receives it. `url` is the
45
+ * request URL with its query and userinfo removed — the value
46
+ * `ArthronError.toJSON()` calls `url`. `duration` is in ms, retries
47
+ * included.
48
+ */
49
+ type LogEvent = {
50
+ phase: "start";
51
+ method: string;
52
+ url: string;
53
+ } | {
54
+ phase: "success";
55
+ method: string;
56
+ url: string;
57
+ status: number;
58
+ duration: number;
59
+ } | {
60
+ phase: "error";
61
+ method: string;
62
+ url: string;
63
+ /** HTTP status for an ArthronError (0 = network); undefined for anything else. */
64
+ status: number | undefined;
65
+ duration: number;
66
+ error: unknown;
67
+ };
68
+ type LoggingOptions = {
69
+ /** Default `true`. The library never reads `NODE_ENV` — pass `isDev` yourself. */
70
+ enabled?: boolean;
71
+ logger?: Pick<Console, "log" | "error">;
72
+ /** Receive structured events instead of the default console lines. */
73
+ onEvent?: (event: LogEvent) => void;
74
+ /**
75
+ * Default `false`. `true` reports a call that timed out before its response
76
+ * arrived — a `TimeoutError`, from `timeout()` or `AbortSignal.timeout()` —
77
+ * as an error event, `status` undefined. A timeout while the body is read
78
+ * rejects that read instead: the call has already logged its success.
79
+ * Other cancellations are never reported.
80
+ */
81
+ timeouts?: boolean;
82
+ };
83
+ //#endregion
84
+ //#region src/plugins/logging/logging.d.ts
85
+ /**
86
+ * One event when a request starts, one when it settles, with status and
87
+ * elapsed time. Wraps the whole call, so retries are included in the time.
88
+ * Default output is a console line per event; pass `onEvent` to get the
89
+ * structured event instead. Cancellations are not reported, timeouts only
90
+ * with `timeouts: true`.
91
+ */
92
+ export declare function logging(options?: LoggingOptions): Plugin;
93
+ //#endregion
94
+ //#region src/plugins/retry/retry.d.ts
95
+ /**
96
+ * Retry on network errors and the configured statuses by calling `next`
97
+ * again — the whole attempt (request interceptors included) is re-run.
98
+ * Only `ArthronError` is considered; cancellation and plugin bugs pass through.
99
+ * A call can turn it off or override its options with `meta.retry`.
100
+ */
101
+ export declare function retry(options?: RetryOptions): Plugin;
102
+ //#endregion
103
+ //#region src/plugins/timeout/timeout.d.ts
104
+ /**
105
+ * Abort the request when it takes longer than `ms` — counted from the start
106
+ * of the attempt until the body has been fully read, so a server that sends
107
+ * headers and then stalls still trips it. `timeout({ idle })` instead aborts
108
+ * once no data has arrived for that long, and never cuts off a stream that
109
+ * keeps flowing; `timeout({ total, idle })` does both. Rejects with a
110
+ * `TimeoutError` (a `DOMException`, like `AbortSignal.timeout()` would give);
111
+ * it is not an `ArthronError`, so error interceptors and `retry` leave it
112
+ * alone.
113
+ *
114
+ * A call can lift the deadlines or change them with `meta.timeout`.
115
+ *
116
+ * Deadlines are timers on an AbortController — not `AbortSignal.timeout`,
117
+ * since the idle one restarts — joined to the caller's signal with
118
+ * `AbortSignal.any`.
119
+ */
120
+ export declare function timeout(ms: number): Plugin;
121
+ export declare function timeout(options: TimeoutOptions): Plugin;
122
+ //#endregion
123
+ //#region src/plugins/upload-progress/upload-progress.d.ts
124
+ /**
125
+ * Does nothing by itself — only a call that passes `meta.uploadProgress`
126
+ * reports upload progress. On such a call it changes how that one attempt
127
+ * is sent: over XMLHttpRequest in a browser, with a counted body in Node.
128
+ * Every other call, on this client too, goes out exactly as before.
129
+ *
130
+ * Progress needs the runtime's own fetch: with a client `fetchFn`, another
131
+ * plugin's fetchFn, or a runtime that is neither (Deno, Bun, Cloudflare
132
+ * Workers, a service worker), the call is sent as usual without progress.
133
+ * Put it last in `plugins`: the call's signal carries a throwing callback's
134
+ * error, and an interceptor after it that replaces the signal would cut it.
135
+ */
136
+ export declare function uploadProgress(): Plugin;
137
+ //#endregion
138
+ export type { BearerAuthOptions, LogEvent, LoggingOptions, RetryOptions, TimeoutOptions, UploadProgressEvent };