@coinlist-co/react 0.2.0 → 0.4.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.
- package/dist/RequirementItem-B-MvcxSr.d.cts +37 -0
- package/dist/RequirementItem-DcYot2uC.d.ts +37 -0
- package/dist/chunk-EHZ6PIGN.js +414 -0
- package/dist/chunk-EHZ6PIGN.js.map +1 -0
- package/dist/chunk-NC45IO63.js +777 -0
- package/dist/chunk-NC45IO63.js.map +1 -0
- package/dist/chunk-RIFATQB5.js +257 -0
- package/dist/chunk-RIFATQB5.js.map +1 -0
- package/dist/chunk-UGJUTRXC.js +304 -0
- package/dist/chunk-UGJUTRXC.js.map +1 -0
- package/dist/client/components/index.cjs +473 -10
- package/dist/client/components/index.cjs.map +1 -1
- package/dist/client/components/index.d.cts +80 -12
- package/dist/client/components/index.d.ts +80 -12
- package/dist/client/components/index.js +243 -243
- package/dist/client/components/index.js.map +1 -1
- package/dist/client/core/index.cjs +349 -202
- package/dist/client/core/index.cjs.map +1 -1
- package/dist/client/core/index.d.cts +4 -4
- package/dist/client/core/index.d.ts +4 -4
- package/dist/client/core/index.js +16 -14
- package/dist/client/hooks/index.cjs +133 -16
- package/dist/client/hooks/index.cjs.map +1 -1
- package/dist/client/hooks/index.d.cts +102 -8
- package/dist/client/hooks/index.d.ts +102 -8
- package/dist/client/hooks/index.js +11 -9
- package/dist/client/index.cjs +591 -210
- package/dist/client/index.cjs.map +1 -1
- package/dist/client/index.d.cts +7 -6
- package/dist/client/index.d.ts +7 -6
- package/dist/client/index.js +41 -17
- package/dist/client/styles.css +1 -1
- package/dist/coinlist-client-BSxpqylo.d.ts +158 -0
- package/dist/coinlist-client-Cah5c_aF.d.cts +158 -0
- package/dist/participation-DMMEDxON.d.cts +185 -0
- package/dist/participation-E-bT-GXJ.d.ts +185 -0
- package/dist/requirement-XWT0T_zO.d.cts +205 -0
- package/dist/requirement-XWT0T_zO.d.ts +205 -0
- package/dist/server/index.cjs +519 -14
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.cts +73 -4
- package/dist/server/index.d.ts +73 -4
- package/dist/server/index.js +116 -20
- package/dist/server/index.js.map +1 -1
- package/dist/useCoinListRequirements-B5-ZPOMz.d.ts +80 -0
- package/dist/useCoinListRequirements-Cuc32Tqw.d.cts +80 -0
- package/package.json +4 -4
- package/dist/chunk-32GOUV3L.js +0 -118
- package/dist/chunk-32GOUV3L.js.map +0 -1
- package/dist/chunk-G3B4RLXP.js +0 -76
- package/dist/chunk-G3B4RLXP.js.map +0 -1
- package/dist/chunk-GRVV7NLV.js +0 -282
- package/dist/chunk-GRVV7NLV.js.map +0 -1
- package/dist/chunk-Z5RFQOMS.js +0 -560
- package/dist/chunk-Z5RFQOMS.js.map +0 -1
- package/dist/coinlist-client-20v7fJSW.d.ts +0 -394
- package/dist/coinlist-client-Ds86ycAg.d.cts +0 -394
- package/dist/newtype-yKTvFdg_.d.cts +0 -6
- package/dist/newtype-yKTvFdg_.d.ts +0 -6
- package/dist/oauth-session-DgItaMKN.d.cts +0 -56
- package/dist/oauth-session-DnKDI5ou.d.ts +0 -56
- package/dist/offer-D6p_Ijme.d.cts +0 -30
- package/dist/offer-DnFEFJw9.d.ts +0 -30
- package/dist/useCoinListOffers-DIdOb5hB.d.ts +0 -27
- package/dist/useCoinListOffers-DvJxu6qj.d.cts +0 -27
- package/dist/useCompleteCoinListOAuth-C359mp_k.d.cts +0 -55
- package/dist/useCompleteCoinListOAuth-wZX3o8r2.d.ts +0 -55
package/dist/chunk-GRVV7NLV.js
DELETED
|
@@ -1,282 +0,0 @@
|
|
|
1
|
-
// src/shared/types/oauth.ts
|
|
2
|
-
var AuthorizationCode = (value) => value;
|
|
3
|
-
var CodeVerifier = (value) => value;
|
|
4
|
-
var CodeChallenge = (value) => value;
|
|
5
|
-
var RedirectUri = (value) => value;
|
|
6
|
-
var ClientId = (value) => value;
|
|
7
|
-
var ClientSecret = (value) => value;
|
|
8
|
-
|
|
9
|
-
// src/shared/api/http-attributes.ts
|
|
10
|
-
var empty = {};
|
|
11
|
-
var concat = (left, right) => ({
|
|
12
|
-
...left,
|
|
13
|
-
...right
|
|
14
|
-
});
|
|
15
|
-
var concatAll = (...items) => {
|
|
16
|
-
let result = empty;
|
|
17
|
-
for (const item of items) {
|
|
18
|
-
result = concat(result, item);
|
|
19
|
-
}
|
|
20
|
-
return result;
|
|
21
|
-
};
|
|
22
|
-
var protectedRequest = () => ({ protected: true });
|
|
23
|
-
var userAgent = () => ({ userAgent: true });
|
|
24
|
-
var idempotencyKey = () => ({
|
|
25
|
-
idempotencyKey: true
|
|
26
|
-
});
|
|
27
|
-
var retryAttempt = (attempt) => ({
|
|
28
|
-
retryAttempt: attempt
|
|
29
|
-
});
|
|
30
|
-
var renewAttempted = (value) => ({
|
|
31
|
-
renewAttempted: value
|
|
32
|
-
});
|
|
33
|
-
var isProtected = (attrs) => attrs?.protected === true;
|
|
34
|
-
var needUserAgent = (attrs) => attrs?.userAgent === true;
|
|
35
|
-
var isIdempotent = (attrs) => attrs?.idempotencyKey === true;
|
|
36
|
-
var getRetryAttempt = (attrs) => attrs?.retryAttempt ?? 0;
|
|
37
|
-
var wasRenewAttempted = (attrs) => attrs?.renewAttempted === true;
|
|
38
|
-
var Attributes = {
|
|
39
|
-
empty,
|
|
40
|
-
concat,
|
|
41
|
-
concatAll,
|
|
42
|
-
protected: protectedRequest,
|
|
43
|
-
isProtected,
|
|
44
|
-
userAgent,
|
|
45
|
-
needUserAgent,
|
|
46
|
-
idempotencyKey,
|
|
47
|
-
isIdempotent,
|
|
48
|
-
retryAttempt,
|
|
49
|
-
getRetryAttempt,
|
|
50
|
-
renewAttempted,
|
|
51
|
-
wasRenewAttempted
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
// src/shared/api/http.ts
|
|
55
|
-
var HttpError = class extends Error {
|
|
56
|
-
constructor(response) {
|
|
57
|
-
super(`Request failed with ${response.status} status`);
|
|
58
|
-
this.name = "HttpError";
|
|
59
|
-
this.response = response;
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
async function makeRequest(request) {
|
|
63
|
-
const headers = {
|
|
64
|
-
Accept: "application/json",
|
|
65
|
-
...request.method === "POST" && request.body !== void 0 ? { "Content-Type": "application/json" } : {},
|
|
66
|
-
...request.headers ?? {}
|
|
67
|
-
};
|
|
68
|
-
const init = {
|
|
69
|
-
method: request.method,
|
|
70
|
-
headers,
|
|
71
|
-
...request.redirect !== void 0 ? { redirect: request.redirect } : {}
|
|
72
|
-
};
|
|
73
|
-
if (request.method === "POST" && request.body !== void 0) {
|
|
74
|
-
init.body = JSON.stringify(request.body);
|
|
75
|
-
}
|
|
76
|
-
const response = await fetch(
|
|
77
|
-
buildUrlWithQueryParams(request.url, request.queryParams),
|
|
78
|
-
init
|
|
79
|
-
);
|
|
80
|
-
const responseHeaders = headersToRecord(response.headers);
|
|
81
|
-
if (response.status === 204 || response.status === 205) {
|
|
82
|
-
return {
|
|
83
|
-
status: response.status,
|
|
84
|
-
body: null,
|
|
85
|
-
headers: responseHeaders
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
if (response.status >= 300 && response.status < 400) {
|
|
89
|
-
await response.text();
|
|
90
|
-
return {
|
|
91
|
-
status: response.status,
|
|
92
|
-
body: null,
|
|
93
|
-
headers: responseHeaders
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
const text = await response.text();
|
|
97
|
-
const body = text ? JSON.parse(text) : null;
|
|
98
|
-
return {
|
|
99
|
-
status: response.status,
|
|
100
|
-
body,
|
|
101
|
-
headers: responseHeaders
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
function buildUrlWithQueryParams(url, queryParams) {
|
|
105
|
-
if (!queryParams) {
|
|
106
|
-
return url;
|
|
107
|
-
}
|
|
108
|
-
const searchParams = new URLSearchParams();
|
|
109
|
-
for (const [key, value] of Object.entries(queryParams)) {
|
|
110
|
-
if (value === void 0 || value === null) {
|
|
111
|
-
continue;
|
|
112
|
-
}
|
|
113
|
-
if (Array.isArray(value)) {
|
|
114
|
-
for (const item of value) {
|
|
115
|
-
if (item === void 0 || item === null) {
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
searchParams.append(key, String(item));
|
|
119
|
-
}
|
|
120
|
-
continue;
|
|
121
|
-
}
|
|
122
|
-
searchParams.append(key, String(value));
|
|
123
|
-
}
|
|
124
|
-
const queryString = searchParams.toString();
|
|
125
|
-
if (!queryString) {
|
|
126
|
-
return url;
|
|
127
|
-
}
|
|
128
|
-
return url.includes("?") ? `${url}&${queryString}` : `${url}?${queryString}`;
|
|
129
|
-
}
|
|
130
|
-
function headersToRecord(headers) {
|
|
131
|
-
const record = {};
|
|
132
|
-
headers.forEach((value, key) => {
|
|
133
|
-
record[key.toLowerCase()] = value;
|
|
134
|
-
});
|
|
135
|
-
return record;
|
|
136
|
-
}
|
|
137
|
-
function concatAttributes(request, attrs) {
|
|
138
|
-
const nextAttributes = Attributes.concat(
|
|
139
|
-
request.attributes ?? Attributes.empty,
|
|
140
|
-
attrs
|
|
141
|
-
);
|
|
142
|
-
const nextRequest = {
|
|
143
|
-
...request,
|
|
144
|
-
attributes: nextAttributes
|
|
145
|
-
};
|
|
146
|
-
return nextRequest;
|
|
147
|
-
}
|
|
148
|
-
var Request = {
|
|
149
|
-
concatAttributes
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
// src/shared/api/frontline.ts
|
|
153
|
-
var PUBLIC_API_BASE_URL = "https://api.coinlist.co";
|
|
154
|
-
var HEADER_API_VERSION = "X-API-Version";
|
|
155
|
-
var HEADER_USER_AGENT = "User-Agent";
|
|
156
|
-
var HEADER_IDEMPOTENCY_KEY = "Idempotency-Key";
|
|
157
|
-
var API_VERSION = "2025-10-17";
|
|
158
|
-
var COINLIST_OAUTH_PAGE_URL = "https://coinlist.co/oauth/authorize";
|
|
159
|
-
|
|
160
|
-
// src/shared/api/http-client.ts
|
|
161
|
-
var HttpClient = class {
|
|
162
|
-
constructor(config, middleware = {}) {
|
|
163
|
-
this.config = config;
|
|
164
|
-
this.middleware = middleware;
|
|
165
|
-
}
|
|
166
|
-
async send(request) {
|
|
167
|
-
return this.runRequestWithAfterMiddleware(request);
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Runs beforeRequest, executeRequest, then the full afterRequest middleware
|
|
171
|
-
* chain. Used by send() and by the retry() callback so that when a
|
|
172
|
-
* middleware calls retry(), the retried response also goes through all
|
|
173
|
-
* afterRequest middleware (e.g. session renewal, retry). Middleware
|
|
174
|
-
* must use request.attributes.retryAttempt (or similar) to avoid infinite
|
|
175
|
-
* recursion when they trigger retries.
|
|
176
|
-
*/
|
|
177
|
-
async runRequestWithAfterMiddleware(request) {
|
|
178
|
-
const preparedRequest = await this.runBeforeRequestMiddleware(
|
|
179
|
-
this.withClientDefaults(request)
|
|
180
|
-
);
|
|
181
|
-
let response = await this.executeRequest(preparedRequest);
|
|
182
|
-
for (const middleware of this.middleware.afterRequest ?? []) {
|
|
183
|
-
response = await middleware({
|
|
184
|
-
request: preparedRequest,
|
|
185
|
-
response,
|
|
186
|
-
retry: (nextRequest = preparedRequest) => this.runRequestWithAfterMiddleware(nextRequest)
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
return response;
|
|
190
|
-
}
|
|
191
|
-
withClientDefaults(request) {
|
|
192
|
-
const url = this.resolveUrl(request.url);
|
|
193
|
-
const headers = {
|
|
194
|
-
...request.headers ?? {},
|
|
195
|
-
[HEADER_API_VERSION]: this.config.xApiVersion
|
|
196
|
-
};
|
|
197
|
-
return {
|
|
198
|
-
...request,
|
|
199
|
-
url,
|
|
200
|
-
headers
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* Resolves a request URL against the client's baseUrl.
|
|
205
|
-
*
|
|
206
|
-
* @internal Public only for testing. Do not use in application code; use
|
|
207
|
-
* {@link HttpClient.send} with a path and the client will resolve the URL.
|
|
208
|
-
*/
|
|
209
|
-
resolveUrl(url) {
|
|
210
|
-
if (url.startsWith("http://") || url.startsWith("https://")) {
|
|
211
|
-
return url;
|
|
212
|
-
}
|
|
213
|
-
const base = this.config.baseUrl.replace(/\/$/, "");
|
|
214
|
-
const path = url.startsWith("/") ? url : `/${url}`;
|
|
215
|
-
return base + path;
|
|
216
|
-
}
|
|
217
|
-
async runBeforeRequestMiddleware(initialRequest) {
|
|
218
|
-
let request = initialRequest;
|
|
219
|
-
for (const middleware of this.middleware.beforeRequest ?? []) {
|
|
220
|
-
request = await middleware(request);
|
|
221
|
-
}
|
|
222
|
-
return request;
|
|
223
|
-
}
|
|
224
|
-
executeRequest(request) {
|
|
225
|
-
return makeRequest(request);
|
|
226
|
-
}
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
// src/shared/api/middleware/request-retry.ts
|
|
230
|
-
var MAX_ATTEMPTS = 3;
|
|
231
|
-
var INITIAL_DELAY_MS = 300;
|
|
232
|
-
var MAX_DELAY_MS = 2e3;
|
|
233
|
-
var RETRYABLE_4XX = /* @__PURE__ */ new Set([408, 409, 429]);
|
|
234
|
-
function isRetryableStatus(status) {
|
|
235
|
-
return status >= 500 && status < 600 || RETRYABLE_4XX.has(status);
|
|
236
|
-
}
|
|
237
|
-
function getRetryDelayMs(attempt) {
|
|
238
|
-
return Math.min(INITIAL_DELAY_MS * 2 ** (attempt - 1), MAX_DELAY_MS);
|
|
239
|
-
}
|
|
240
|
-
function createRequestRetryMiddleware(options = {}) {
|
|
241
|
-
const delayFn = options.delayFn ?? defaultDelay;
|
|
242
|
-
return async ({ request, response, retry }) => {
|
|
243
|
-
if (!isRetryableStatus(response.status)) {
|
|
244
|
-
return response;
|
|
245
|
-
}
|
|
246
|
-
const currentAttempt = Attributes.getRetryAttempt(request.attributes);
|
|
247
|
-
if (currentAttempt >= MAX_ATTEMPTS - 1) {
|
|
248
|
-
return response;
|
|
249
|
-
}
|
|
250
|
-
const nextAttempt = currentAttempt + 1;
|
|
251
|
-
await delayFn(getRetryDelayMs(nextAttempt));
|
|
252
|
-
const nextRequest = Request.concatAttributes(
|
|
253
|
-
request,
|
|
254
|
-
Attributes.retryAttempt(nextAttempt)
|
|
255
|
-
);
|
|
256
|
-
return retry(nextRequest);
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
function defaultDelay(ms) {
|
|
260
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
261
|
-
}
|
|
262
|
-
var requestRetryMiddleware = createRequestRetryMiddleware();
|
|
263
|
-
|
|
264
|
-
export {
|
|
265
|
-
Attributes,
|
|
266
|
-
HttpError,
|
|
267
|
-
Request,
|
|
268
|
-
PUBLIC_API_BASE_URL,
|
|
269
|
-
HEADER_USER_AGENT,
|
|
270
|
-
HEADER_IDEMPOTENCY_KEY,
|
|
271
|
-
API_VERSION,
|
|
272
|
-
COINLIST_OAUTH_PAGE_URL,
|
|
273
|
-
HttpClient,
|
|
274
|
-
requestRetryMiddleware,
|
|
275
|
-
AuthorizationCode,
|
|
276
|
-
CodeVerifier,
|
|
277
|
-
CodeChallenge,
|
|
278
|
-
RedirectUri,
|
|
279
|
-
ClientId,
|
|
280
|
-
ClientSecret
|
|
281
|
-
};
|
|
282
|
-
//# sourceMappingURL=chunk-GRVV7NLV.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/shared/types/oauth.ts","../src/shared/api/http-attributes.ts","../src/shared/api/http.ts","../src/shared/api/frontline.ts","../src/shared/api/http-client.ts","../src/shared/api/middleware/request-retry.ts"],"sourcesContent":["import type { Newtype } from '@/shared/types/newtype';\n\nexport type AuthorizationCode = Newtype<string, 'AuthorizationCode'>;\nexport const AuthorizationCode = (value: string): AuthorizationCode =>\n value as AuthorizationCode;\n\nexport type CodeVerifier = Newtype<string, 'CodeVerifier'>;\nexport const CodeVerifier = (value: string): CodeVerifier =>\n value as CodeVerifier;\n\nexport type CodeChallenge = Newtype<string, 'CodeChallenge'>;\nexport const CodeChallenge = (value: string): CodeChallenge =>\n value as CodeChallenge;\n\nexport type RedirectUri = Newtype<string, 'RedirectUri'>;\nexport const RedirectUri = (value: string): RedirectUri => value as RedirectUri;\n\nexport type ClientId = Newtype<string, 'ClientId'>;\nexport const ClientId = (value: string): ClientId => value as ClientId;\n\nexport type ClientSecret = Newtype<string, 'ClientSecret'>;\nexport const ClientSecret = (value: string): ClientSecret =>\n value as ClientSecret;\n","export type HttpRequestAttributes = {\n protected?: boolean;\n userAgent?: boolean;\n idempotencyKey?: boolean;\n /** Zero-based attempt index: 0 = first request, 1 = first retry, etc. */\n retryAttempt?: number;\n renewAttempted?: boolean;\n};\n\nexport type Attributes = Readonly<HttpRequestAttributes>;\n\nconst empty: Attributes = {};\n\nconst concat = (left: Attributes, right: Attributes): Attributes => ({\n ...left,\n ...right,\n});\n\nconst concatAll = (...items: Attributes[]): Attributes => {\n let result = empty;\n for (const item of items) {\n result = concat(result, item);\n }\n return result;\n};\n\nconst protectedRequest = (): Attributes => ({ protected: true });\nconst userAgent = (): Attributes => ({ userAgent: true });\nconst idempotencyKey = (): Attributes => ({\n idempotencyKey: true,\n});\n\n/** Returns attributes with the given retry attempt (zero-based). */\nconst retryAttempt = (attempt: number): Attributes => ({\n retryAttempt: attempt,\n});\nconst renewAttempted = (value: boolean): Attributes => ({\n renewAttempted: value,\n});\n\nconst isProtected = (attrs?: HttpRequestAttributes): boolean =>\n attrs?.protected === true;\nconst needUserAgent = (attrs?: HttpRequestAttributes): boolean =>\n attrs?.userAgent === true;\nconst isIdempotent = (attrs?: HttpRequestAttributes): boolean =>\n attrs?.idempotencyKey === true;\nconst getRetryAttempt = (attrs?: HttpRequestAttributes): number =>\n attrs?.retryAttempt ?? 0;\nconst wasRenewAttempted = (attrs?: HttpRequestAttributes): boolean =>\n attrs?.renewAttempted === true;\n\nexport const Attributes = {\n empty,\n concat,\n concatAll,\n protected: protectedRequest,\n isProtected,\n userAgent,\n needUserAgent,\n idempotencyKey,\n isIdempotent,\n retryAttempt,\n getRetryAttempt,\n renewAttempted,\n wasRenewAttempted,\n} as const;\n","import {\n Attributes,\n type HttpRequestAttributes,\n} from '@/shared/api/http-attributes';\n\nexport type HttpClientConfig = {\n baseUrl: string;\n xApiVersion: string;\n};\n\nexport type QueryParamValue = string | number | boolean | null | undefined;\nexport type QueryParamValues = QueryParamValue | QueryParamValue[];\n\nexport type HttpRequest<TBody = unknown> =\n | {\n method: 'GET';\n url: string;\n queryParams?: Record<string, QueryParamValues>;\n headers?: Record<string, string>;\n attributes?: HttpRequestAttributes;\n redirect?: RequestRedirect;\n }\n | {\n method: 'POST';\n url: string;\n queryParams?: Record<string, QueryParamValues>;\n headers?: Record<string, string>;\n body: TBody;\n attributes?: HttpRequestAttributes;\n redirect?: RequestRedirect;\n };\nexport type HttpResponse<TBody = unknown> = {\n status: number;\n headers?: Record<string, string>;\n body: TBody | null;\n};\n\nexport class HttpError<TBody = unknown> extends Error {\n readonly response: HttpResponse<TBody>;\n\n constructor(response: HttpResponse<TBody>) {\n super(`Request failed with ${response.status} status`);\n this.name = 'HttpError';\n this.response = response;\n }\n}\n\nexport async function makeRequest<TResponse = unknown>(\n request: HttpRequest\n): Promise<HttpResponse<TResponse>> {\n const headers: Record<string, string> = {\n Accept: 'application/json',\n ...(request.method === 'POST' && request.body !== undefined\n ? { 'Content-Type': 'application/json' }\n : {}),\n ...(request.headers ?? {}),\n };\n\n const init: RequestInit = {\n method: request.method,\n headers,\n ...(request.redirect !== undefined ? { redirect: request.redirect } : {}),\n };\n\n if (request.method === 'POST' && request.body !== undefined) {\n init.body = JSON.stringify(request.body);\n }\n\n const response = await fetch(\n buildUrlWithQueryParams(request.url, request.queryParams),\n init\n );\n const responseHeaders = headersToRecord(response.headers);\n\n if (response.status === 204 || response.status === 205) {\n return {\n status: response.status,\n body: null,\n headers: responseHeaders,\n };\n }\n\n if (response.status >= 300 && response.status < 400) {\n await response.text();\n return {\n status: response.status,\n body: null,\n headers: responseHeaders,\n };\n }\n\n const text = await response.text();\n const body = text ? (JSON.parse(text) as TResponse) : null;\n\n return {\n status: response.status,\n body,\n headers: responseHeaders,\n };\n}\n\nfunction buildUrlWithQueryParams(\n url: string,\n queryParams?: Record<string, QueryParamValues>\n): string {\n if (!queryParams) {\n return url;\n }\n\n const searchParams = new URLSearchParams();\n\n for (const [key, value] of Object.entries(queryParams)) {\n if (value === undefined || value === null) {\n continue;\n }\n\n if (Array.isArray(value)) {\n for (const item of value) {\n if (item === undefined || item === null) {\n continue;\n }\n searchParams.append(key, String(item));\n }\n continue;\n }\n\n searchParams.append(key, String(value));\n }\n\n const queryString = searchParams.toString();\n if (!queryString) {\n return url;\n }\n\n return url.includes('?') ? `${url}&${queryString}` : `${url}?${queryString}`;\n}\n\nfunction headersToRecord(headers: Headers): Record<string, string> {\n const record: Record<string, string> = {};\n headers.forEach((value, key) => {\n record[key.toLowerCase()] = value;\n });\n return record;\n}\n\nfunction concatAttributes(\n request: HttpRequest,\n attrs: Attributes\n): HttpRequest {\n const nextAttributes = Attributes.concat(\n request.attributes ?? Attributes.empty,\n attrs\n );\n const nextRequest: typeof request = {\n ...request,\n attributes: nextAttributes,\n };\n return nextRequest;\n}\n\nexport const Request = {\n concatAttributes,\n};\n","export const PUBLIC_API_BASE_URL = 'https://api.coinlist.co';\nexport const HEADER_API_VERSION = 'X-API-Version';\nexport const HEADER_USER_AGENT = 'User-Agent';\nexport const HEADER_IDEMPOTENCY_KEY = 'Idempotency-Key';\nexport const API_VERSION = '2025-10-17';\n\nexport const COINLIST_OAUTH_PAGE_URL = 'https://coinlist.co/oauth/authorize';\n","import { HEADER_API_VERSION } from '@/shared/api/frontline';\nimport type {\n HttpClientConfig,\n HttpRequest,\n HttpResponse,\n} from '@/shared/api/http';\nimport { makeRequest } from '@/shared/api/http';\n\nexport type BeforeRequestMiddleware = (\n request: HttpRequest\n) => Promise<HttpRequest>;\n\nexport type AfterRequestMiddleware = (args: {\n request: HttpRequest;\n response: HttpResponse<unknown>;\n retry: (request?: HttpRequest) => Promise<HttpResponse<unknown>>;\n}) => Promise<HttpResponse<unknown>>;\n\nexport type HttpClientMiddleware = {\n beforeRequest?: BeforeRequestMiddleware[];\n afterRequest?: AfterRequestMiddleware[];\n};\n\nexport class HttpClient {\n constructor(\n readonly config: HttpClientConfig,\n readonly middleware: HttpClientMiddleware = {}\n ) {}\n\n async send<TResponse = unknown>(\n request: HttpRequest\n ): Promise<HttpResponse<TResponse>> {\n return this.runRequestWithAfterMiddleware<TResponse>(request);\n }\n\n /**\n * Runs beforeRequest, executeRequest, then the full afterRequest middleware\n * chain. Used by send() and by the retry() callback so that when a\n * middleware calls retry(), the retried response also goes through all\n * afterRequest middleware (e.g. session renewal, retry). Middleware\n * must use request.attributes.retryAttempt (or similar) to avoid infinite\n * recursion when they trigger retries.\n */\n private async runRequestWithAfterMiddleware<TResponse = unknown>(\n request: HttpRequest\n ): Promise<HttpResponse<TResponse>> {\n const preparedRequest = await this.runBeforeRequestMiddleware(\n this.withClientDefaults(request)\n );\n let response = await this.executeRequest<TResponse>(preparedRequest);\n\n for (const middleware of this.middleware.afterRequest ?? []) {\n response = (await middleware({\n request: preparedRequest,\n response,\n retry: (nextRequest = preparedRequest) =>\n this.runRequestWithAfterMiddleware(nextRequest) as Promise<\n HttpResponse<TResponse>\n >,\n })) as HttpResponse<TResponse>;\n }\n\n return response;\n }\n\n private withClientDefaults(request: HttpRequest): HttpRequest {\n const url = this.resolveUrl(request.url);\n const headers = {\n ...(request.headers ?? {}),\n [HEADER_API_VERSION]: this.config.xApiVersion,\n };\n\n return {\n ...request,\n url,\n headers,\n };\n }\n\n /**\n * Resolves a request URL against the client's baseUrl.\n *\n * @internal Public only for testing. Do not use in application code; use\n * {@link HttpClient.send} with a path and the client will resolve the URL.\n */\n resolveUrl(url: string): string {\n // If already absolute, use as-is.\n if (url.startsWith('http://') || url.startsWith('https://')) {\n return url;\n }\n // Otherwise append path to baseUrl so base path (e.g. /api) is preserved.\n const base = this.config.baseUrl.replace(/\\/$/, '');\n const path = url.startsWith('/') ? url : `/${url}`;\n return base + path;\n }\n\n private async runBeforeRequestMiddleware(\n initialRequest: HttpRequest\n ): Promise<HttpRequest> {\n let request = initialRequest;\n for (const middleware of this.middleware.beforeRequest ?? []) {\n request = await middleware(request);\n }\n\n return request;\n }\n\n private executeRequest<TResponse = unknown>(\n request: HttpRequest\n ): Promise<HttpResponse<TResponse>> {\n return makeRequest<TResponse>(request);\n }\n}\n","import { Request } from '@/shared/api/http';\nimport { Attributes } from '@/shared/api/http-attributes';\nimport type { AfterRequestMiddleware } from '@/shared/api/http-client';\n\nconst MAX_ATTEMPTS = 3;\nconst INITIAL_DELAY_MS = 300;\nconst MAX_DELAY_MS = 2000;\n\nconst RETRYABLE_4XX = new Set([408, 409, 429]);\n\nexport function isRetryableStatus(status: number): boolean {\n return (status >= 500 && status < 600) || RETRYABLE_4XX.has(status);\n}\n\nfunction getRetryDelayMs(attempt: number): number {\n return Math.min(INITIAL_DELAY_MS * 2 ** (attempt - 1), MAX_DELAY_MS);\n}\n\nexport type RequestRetryMiddlewareOptions = {\n /**\n * Optional delay function. Defaults to real setTimeout-based delay.\n * Use a no-op (e.g. () => Promise.resolve()) in tests to avoid slow tests.\n */\n delayFn?: (ms: number) => Promise<void>;\n};\n\n/**\n * Creates the request retry after-request middleware. Inject a no-op delayFn\n * in tests to avoid real delays (unit testing best practice).\n */\nexport function createRequestRetryMiddleware(\n options: RequestRetryMiddlewareOptions = {}\n): AfterRequestMiddleware {\n const delayFn = options.delayFn ?? defaultDelay;\n\n return async ({ request, response, retry }) => {\n if (!isRetryableStatus(response.status)) {\n return response;\n }\n\n const currentAttempt = Attributes.getRetryAttempt(request.attributes);\n if (currentAttempt >= MAX_ATTEMPTS - 1) {\n return response;\n }\n\n const nextAttempt = currentAttempt + 1;\n await delayFn(getRetryDelayMs(nextAttempt));\n\n const nextRequest = Request.concatAttributes(\n request,\n Attributes.retryAttempt(nextAttempt)\n );\n return retry(nextRequest);\n };\n}\n\nfunction defaultDelay(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\n/**\n * Retries the request up to 3 times with exponential backoff when the response\n * has a retryable status (5xx server errors). Uses request.attributes.retryAttempt\n * to decide delay and whether to retry, so the middleware does not loop when\n * retry() runs the full HTTP middleware chain again.\n */\nexport const requestRetryMiddleware: AfterRequestMiddleware =\n createRequestRetryMiddleware();\n"],"mappings":";AAGO,IAAM,oBAAoB,CAAC,UAChC;AAGK,IAAM,eAAe,CAAC,UAC3B;AAGK,IAAM,gBAAgB,CAAC,UAC5B;AAGK,IAAM,cAAc,CAAC,UAA+B;AAGpD,IAAM,WAAW,CAAC,UAA4B;AAG9C,IAAM,eAAe,CAAC,UAC3B;;;ACXF,IAAM,QAAoB,CAAC;AAE3B,IAAM,SAAS,CAAC,MAAkB,WAAmC;AAAA,EACnE,GAAG;AAAA,EACH,GAAG;AACL;AAEA,IAAM,YAAY,IAAI,UAAoC;AACxD,MAAI,SAAS;AACb,aAAW,QAAQ,OAAO;AACxB,aAAS,OAAO,QAAQ,IAAI;AAAA,EAC9B;AACA,SAAO;AACT;AAEA,IAAM,mBAAmB,OAAmB,EAAE,WAAW,KAAK;AAC9D,IAAM,YAAY,OAAmB,EAAE,WAAW,KAAK;AACvD,IAAM,iBAAiB,OAAmB;AAAA,EACxC,gBAAgB;AAClB;AAGA,IAAM,eAAe,CAAC,aAAiC;AAAA,EACrD,cAAc;AAChB;AACA,IAAM,iBAAiB,CAAC,WAAgC;AAAA,EACtD,gBAAgB;AAClB;AAEA,IAAM,cAAc,CAAC,UACnB,OAAO,cAAc;AACvB,IAAM,gBAAgB,CAAC,UACrB,OAAO,cAAc;AACvB,IAAM,eAAe,CAAC,UACpB,OAAO,mBAAmB;AAC5B,IAAM,kBAAkB,CAAC,UACvB,OAAO,gBAAgB;AACzB,IAAM,oBAAoB,CAAC,UACzB,OAAO,mBAAmB;AAErB,IAAM,aAAa;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAW;AAAA,E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