arthron 1.1.0 → 2.0.1

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,129 @@
1
- import { a as LogEvent, b as RetryOptions, c as BearerAuthOptions, i as logging, n as TimeoutOptions, o as LoggingOptions, r as retry, s as bearerAuth, t as timeout } from "./index-Bz1P80JN.cjs";
2
- export { type BearerAuthOptions, type LogEvent, type LoggingOptions, type RetryOptions, type TimeoutOptions, bearerAuth, logging, retry, timeout };
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
+ //#endregion
76
+ //#region src/plugins/logging/logging.d.ts
77
+ /**
78
+ * One event when a request starts, one when it settles, with status and
79
+ * elapsed time. Wraps the whole call, so retries are included in the time.
80
+ * Default output is a console line per event; pass `onEvent` to get the
81
+ * structured event instead. Cancellations are not reported.
82
+ */
83
+ export declare function logging(options?: LoggingOptions): Plugin;
84
+ //#endregion
85
+ //#region src/plugins/retry/retry.d.ts
86
+ /**
87
+ * Retry on network errors and the configured statuses by calling `next`
88
+ * again — the whole attempt (request interceptors included) is re-run.
89
+ * Only `ArthronError` is considered; cancellation and plugin bugs pass through.
90
+ * A call can turn it off or override its options with `meta.retry`.
91
+ */
92
+ export declare function retry(options?: RetryOptions): Plugin;
93
+ //#endregion
94
+ //#region src/plugins/timeout/timeout.d.ts
95
+ /**
96
+ * Abort the request when it takes longer than `ms` — counted from the start
97
+ * of the attempt until the body has been fully read, so a server that sends
98
+ * headers and then stalls still trips it. `timeout({ idle })` instead aborts
99
+ * once no data has arrived for that long, and never cuts off a stream that
100
+ * keeps flowing; `timeout({ total, idle })` does both. Rejects with a
101
+ * `TimeoutError` (a `DOMException`, like `AbortSignal.timeout()` would give);
102
+ * it is not an `ArthronError`, so error interceptors and `retry` leave it
103
+ * alone.
104
+ *
105
+ * A call can lift the deadlines or change them with `meta.timeout`.
106
+ *
107
+ * Deadlines are timers on an AbortController — not `AbortSignal.timeout`,
108
+ * since the idle one restarts — joined to the caller's signal with
109
+ * `AbortSignal.any`.
110
+ */
111
+ export declare function timeout(ms: number): Plugin;
112
+ export declare function timeout(options: TimeoutOptions): Plugin;
113
+ //#endregion
114
+ //#region src/plugins/upload-progress/upload-progress.d.ts
115
+ /**
116
+ * Does nothing by itself — only a call that passes `meta.uploadProgress`
117
+ * reports upload progress. On such a call it changes how that one attempt
118
+ * is sent: over XMLHttpRequest in a browser, with a counted body in Node.
119
+ * Every other call, on this client too, goes out exactly as before.
120
+ *
121
+ * Progress needs the runtime's own fetch: with a client `fetchFn`, another
122
+ * plugin's fetchFn, or a runtime that is neither (Deno, Bun, Cloudflare
123
+ * Workers, a service worker), the call is sent as usual without progress.
124
+ * Put it last in `plugins`: the call's signal carries a throwing callback's
125
+ * error, and an interceptor after it that replaces the signal would cut it.
126
+ */
127
+ export declare function uploadProgress(): Plugin;
128
+ //#endregion
129
+ export type { BearerAuthOptions, LogEvent, LoggingOptions, RetryOptions, TimeoutOptions, UploadProgressEvent };
@@ -1,2 +1,129 @@
1
- import { a as LogEvent, b as RetryOptions, c as BearerAuthOptions, i as logging, n as TimeoutOptions, o as LoggingOptions, r as retry, s as bearerAuth, t as timeout } from "./index-Bz1P80JN.mjs";
2
- export { type BearerAuthOptions, type LogEvent, type LoggingOptions, type RetryOptions, type TimeoutOptions, bearerAuth, logging, retry, timeout };
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
+ //#endregion
76
+ //#region src/plugins/logging/logging.d.ts
77
+ /**
78
+ * One event when a request starts, one when it settles, with status and
79
+ * elapsed time. Wraps the whole call, so retries are included in the time.
80
+ * Default output is a console line per event; pass `onEvent` to get the
81
+ * structured event instead. Cancellations are not reported.
82
+ */
83
+ export declare function logging(options?: LoggingOptions): Plugin;
84
+ //#endregion
85
+ //#region src/plugins/retry/retry.d.ts
86
+ /**
87
+ * Retry on network errors and the configured statuses by calling `next`
88
+ * again — the whole attempt (request interceptors included) is re-run.
89
+ * Only `ArthronError` is considered; cancellation and plugin bugs pass through.
90
+ * A call can turn it off or override its options with `meta.retry`.
91
+ */
92
+ export declare function retry(options?: RetryOptions): Plugin;
93
+ //#endregion
94
+ //#region src/plugins/timeout/timeout.d.ts
95
+ /**
96
+ * Abort the request when it takes longer than `ms` — counted from the start
97
+ * of the attempt until the body has been fully read, so a server that sends
98
+ * headers and then stalls still trips it. `timeout({ idle })` instead aborts
99
+ * once no data has arrived for that long, and never cuts off a stream that
100
+ * keeps flowing; `timeout({ total, idle })` does both. Rejects with a
101
+ * `TimeoutError` (a `DOMException`, like `AbortSignal.timeout()` would give);
102
+ * it is not an `ArthronError`, so error interceptors and `retry` leave it
103
+ * alone.
104
+ *
105
+ * A call can lift the deadlines or change them with `meta.timeout`.
106
+ *
107
+ * Deadlines are timers on an AbortController — not `AbortSignal.timeout`,
108
+ * since the idle one restarts — joined to the caller's signal with
109
+ * `AbortSignal.any`.
110
+ */
111
+ export declare function timeout(ms: number): Plugin;
112
+ export declare function timeout(options: TimeoutOptions): Plugin;
113
+ //#endregion
114
+ //#region src/plugins/upload-progress/upload-progress.d.ts
115
+ /**
116
+ * Does nothing by itself — only a call that passes `meta.uploadProgress`
117
+ * reports upload progress. On such a call it changes how that one attempt
118
+ * is sent: over XMLHttpRequest in a browser, with a counted body in Node.
119
+ * Every other call, on this client too, goes out exactly as before.
120
+ *
121
+ * Progress needs the runtime's own fetch: with a client `fetchFn`, another
122
+ * plugin's fetchFn, or a runtime that is neither (Deno, Bun, Cloudflare
123
+ * Workers, a service worker), the call is sent as usual without progress.
124
+ * Put it last in `plugins`: the call's signal carries a throwing callback's
125
+ * error, and an interceptor after it that replaces the signal would cut it.
126
+ */
127
+ export declare function uploadProgress(): Plugin;
128
+ //#endregion
129
+ export type { BearerAuthOptions, LogEvent, LoggingOptions, RetryOptions, TimeoutOptions, UploadProgressEvent };