@coinlist-co/react 0.3.0 → 0.5.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.
Files changed (71) hide show
  1. package/dist/chunk-CRACFEJ4.js +17 -0
  2. package/dist/chunk-CRACFEJ4.js.map +1 -0
  3. package/dist/{chunk-GRVV7NLV.js → chunk-N3WBC2VS.js} +218 -28
  4. package/dist/chunk-N3WBC2VS.js.map +1 -0
  5. package/dist/chunk-V6WO67RO.js +311 -0
  6. package/dist/chunk-V6WO67RO.js.map +1 -0
  7. package/dist/client/index.cjs +1393 -372
  8. package/dist/client/index.cjs.map +1 -1
  9. package/dist/client/index.d.cts +526 -10
  10. package/dist/client/index.d.ts +526 -10
  11. package/dist/client/index.js +1464 -88
  12. package/dist/client/index.js.map +1 -1
  13. package/dist/requirement-BEO42QOr.d.cts +387 -0
  14. package/dist/requirement-BEO42QOr.d.ts +387 -0
  15. package/dist/server/index.cjs +459 -36
  16. package/dist/server/index.cjs.map +1 -1
  17. package/dist/server/index.d.cts +56 -4
  18. package/dist/server/index.d.ts +56 -4
  19. package/dist/server/index.js +69 -37
  20. package/dist/server/index.js.map +1 -1
  21. package/dist/shared/index.cjs +375 -0
  22. package/dist/shared/index.cjs.map +1 -0
  23. package/dist/shared/index.d.cts +35 -0
  24. package/dist/shared/index.d.ts +35 -0
  25. package/dist/{client/core → shared}/index.js +38 -19
  26. package/dist/shared/index.js.map +1 -0
  27. package/package.json +7 -22
  28. package/dist/RequirementItem-BpkJQep8.d.ts +0 -37
  29. package/dist/RequirementItem-BvwsFu9e.d.cts +0 -37
  30. package/dist/chunk-GRVV7NLV.js.map +0 -1
  31. package/dist/chunk-IADBIDY6.js +0 -76
  32. package/dist/chunk-IADBIDY6.js.map +0 -1
  33. package/dist/chunk-IDCROXPS.js +0 -412
  34. package/dist/chunk-IDCROXPS.js.map +0 -1
  35. package/dist/chunk-P4DTIPEX.js +0 -623
  36. package/dist/chunk-P4DTIPEX.js.map +0 -1
  37. package/dist/chunk-V5M7SA3C.js +0 -161
  38. package/dist/chunk-V5M7SA3C.js.map +0 -1
  39. package/dist/chunk-YJQMJFA7.js +0 -16
  40. package/dist/chunk-YJQMJFA7.js.map +0 -1
  41. package/dist/client/components/index.cjs +0 -1107
  42. package/dist/client/components/index.cjs.map +0 -1
  43. package/dist/client/components/index.d.cts +0 -121
  44. package/dist/client/components/index.d.ts +0 -121
  45. package/dist/client/components/index.js +0 -586
  46. package/dist/client/components/index.js.map +0 -1
  47. package/dist/client/core/index.cjs +0 -961
  48. package/dist/client/core/index.cjs.map +0 -1
  49. package/dist/client/core/index.d.cts +0 -23
  50. package/dist/client/core/index.d.ts +0 -23
  51. package/dist/client/core/index.js.map +0 -1
  52. package/dist/client/hooks/index.cjs +0 -233
  53. package/dist/client/hooks/index.cjs.map +0 -1
  54. package/dist/client/hooks/index.d.cts +0 -33
  55. package/dist/client/hooks/index.d.ts +0 -33
  56. package/dist/client/hooks/index.js +0 -19
  57. package/dist/client/hooks/index.js.map +0 -1
  58. package/dist/coinlist-client-B_dJkbwB.d.ts +0 -283
  59. package/dist/coinlist-client-DBKa6j3f.d.cts +0 -283
  60. package/dist/newtype-yKTvFdg_.d.cts +0 -6
  61. package/dist/newtype-yKTvFdg_.d.ts +0 -6
  62. package/dist/oauth-session-DgItaMKN.d.cts +0 -56
  63. package/dist/oauth-session-DnKDI5ou.d.ts +0 -56
  64. package/dist/requirement-CxbdY8l4.d.cts +0 -202
  65. package/dist/requirement-fJsQ3f9_.d.ts +0 -202
  66. package/dist/useCoinListOffers-C5lBlzcC.d.ts +0 -27
  67. package/dist/useCoinListOffers-CguwXaCX.d.cts +0 -27
  68. package/dist/useCoinListRequirements-BECx1cIw.d.ts +0 -31
  69. package/dist/useCoinListRequirements-CX2gV9gJ.d.cts +0 -31
  70. package/dist/useCompleteCoinListOAuth-BRhAqD4_.d.cts +0 -55
  71. package/dist/useCompleteCoinListOAuth-DEZpHjd6.d.ts +0 -55
@@ -0,0 +1,17 @@
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
+ export {
10
+ AuthorizationCode,
11
+ CodeVerifier,
12
+ CodeChallenge,
13
+ RedirectUri,
14
+ ClientId,
15
+ ClientSecret
16
+ };
17
+ //# sourceMappingURL=chunk-CRACFEJ4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/shared/types/oauth.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"],"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;","names":[]}
@@ -1,10 +1,32 @@
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;
1
+ import {
2
+ CreateParticipationParams,
3
+ Offer,
4
+ OfferDetail,
5
+ PaginatedResponse,
6
+ PaginationParams,
7
+ Participation,
8
+ ParticipationsPaginationParams,
9
+ Requirement,
10
+ RequirementStatusInfo,
11
+ fetchAllPages,
12
+ getUUIDv4
13
+ } from "./chunk-V6WO67RO.js";
14
+
15
+ // src/shared/api/frontline/config.ts
16
+ var PUBLIC_API_BASE_URL = "https://api.coinlist.co";
17
+ var HEADER_API_VERSION = "X-API-Version";
18
+ var HEADER_USER_AGENT = "User-Agent";
19
+ var HEADER_IDEMPOTENCY_KEY = "Idempotency-Key";
20
+ var API_VERSION = "2025-10-17";
21
+ var COINLIST_BASE_URL = "https://coinlist.co";
22
+ var OAUTH_PAGE_PATH = "/oauth/authorize";
23
+ var SUPPORT_NEW_TICKET_URL = "https://support.coinlist.co/support/tickets/new";
24
+ var VERIFY_IDENTITY_PATH = "/verify-identity";
25
+ var VERIFY_IDENTITY_VERIFIED_PATH = "/verify-identity/identity_verified";
26
+ var VERIFY_IDENTITY_PROOF_OF_ADDRESS_PATH = "/verify-identity/proof_of_address";
27
+ var VERIFY_IDENTITY_SOURCE_OF_FUNDS_PATH = "/verify-identity/source_of_funds";
28
+ var VERIFY_IDENTITY_ACCREDITATION_PATH = "/verify-identity/accreditation_full";
29
+ var WALLET_PATH = "/wallet";
8
30
 
9
31
  // src/shared/api/http-attributes.ts
10
32
  var empty = {};
@@ -149,13 +171,85 @@ var Request = {
149
171
  concatAttributes
150
172
  };
151
173
 
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";
174
+ // src/shared/api/frontline/offers.ts
175
+ async function fetchOffers(api) {
176
+ return fetchAllPages((params) => fetchOffersPage(api, params));
177
+ }
178
+ async function fetchOffersPage(api, params) {
179
+ const queryParams = PaginationParams.toQueryParams(params);
180
+ const pageDto = await api.send({
181
+ method: "GET",
182
+ url: "/v1/offers",
183
+ queryParams,
184
+ attributes: Attributes.protected()
185
+ });
186
+ return PaginatedResponse.fromDto(pageDto, Offer.fromDto);
187
+ }
188
+ async function fetchOfferDetails(api, id) {
189
+ const dto = await api.send({
190
+ method: "GET",
191
+ url: `/v1/offers/${id}`,
192
+ attributes: Attributes.protected()
193
+ });
194
+ return OfferDetail.fromDto(dto);
195
+ }
196
+
197
+ // src/shared/api/frontline/participations.ts
198
+ async function fetchParticipations(api, offerId) {
199
+ return fetchAllPages(
200
+ (params) => fetchParticipationsPage(api, params),
201
+ { offerId }
202
+ );
203
+ }
204
+ async function fetchParticipationsPage(api, params) {
205
+ const pageDto = await api.send({
206
+ method: "GET",
207
+ url: "/v1/participations",
208
+ queryParams: ParticipationsPaginationParams.toQueryParams(params),
209
+ attributes: Attributes.protected()
210
+ });
211
+ return PaginatedResponse.fromDto(pageDto, Participation.fromDto);
212
+ }
213
+ async function fetchParticipation(api, id) {
214
+ const dto = await api.send({
215
+ method: "GET",
216
+ url: `/v1/participations/${id}`,
217
+ attributes: Attributes.protected()
218
+ });
219
+ return Participation.fromDto(dto);
220
+ }
221
+ async function createParticipation(api, params) {
222
+ const dto = await api.send({
223
+ method: "POST",
224
+ url: "/v1/participations",
225
+ body: CreateParticipationParams.toDto(params),
226
+ attributes: Attributes.protected()
227
+ });
228
+ return Participation.fromDto(dto);
229
+ }
230
+
231
+ // src/shared/api/frontline/requirements.ts
232
+ async function fetchOfferRequirements(api, offerId) {
233
+ const response = await api.send({
234
+ method: "GET",
235
+ url: `/v1/offers/${offerId}/requirements`,
236
+ attributes: Attributes.protected()
237
+ });
238
+ return Object.fromEntries(
239
+ Object.entries(response.options).map(([optionId, list]) => [
240
+ optionId,
241
+ list.data.map(Requirement.fromDto)
242
+ ])
243
+ );
244
+ }
245
+ async function fetchRequirementStatuses(api, offerId) {
246
+ const response = await api.send({
247
+ method: "GET",
248
+ url: `/v1/offers/${offerId}/requirements/statuses`,
249
+ attributes: Attributes.protected()
250
+ });
251
+ return RequirementStatusInfo.fromStatusesDto(response);
252
+ }
159
253
 
160
254
  // src/shared/api/http-client.ts
161
255
  var HttpClient = class {
@@ -226,6 +320,44 @@ var HttpClient = class {
226
320
  }
227
321
  };
228
322
 
323
+ // src/shared/api/middleware/attach-session-middleware.ts
324
+ function attachSessionMiddleware(fetchAccessToken) {
325
+ return async (request) => {
326
+ if (!Attributes.isProtected(request.attributes)) {
327
+ return request;
328
+ }
329
+ const accessToken = await fetchAccessToken(false);
330
+ if (accessToken === null) {
331
+ return request;
332
+ }
333
+ return {
334
+ ...request,
335
+ headers: {
336
+ ...request.headers ?? {},
337
+ Authorization: `Bearer ${accessToken.value}`
338
+ }
339
+ };
340
+ };
341
+ }
342
+
343
+ // src/shared/api/middleware/idempotency-key.ts
344
+ var idempotencyKeyMiddleware = async (request) => {
345
+ if (!Attributes.isIdempotent(request.attributes)) {
346
+ return request;
347
+ }
348
+ const existingHeaders = request.headers ?? {};
349
+ if (existingHeaders[HEADER_IDEMPOTENCY_KEY]) {
350
+ return request;
351
+ }
352
+ return {
353
+ ...request,
354
+ headers: {
355
+ ...existingHeaders,
356
+ [HEADER_IDEMPOTENCY_KEY]: getUUIDv4()
357
+ }
358
+ };
359
+ };
360
+
229
361
  // src/shared/api/middleware/request-retry.ts
230
362
  var MAX_ATTEMPTS = 3;
231
363
  var INITIAL_DELAY_MS = 300;
@@ -261,22 +393,80 @@ function defaultDelay(ms) {
261
393
  }
262
394
  var requestRetryMiddleware = createRequestRetryMiddleware();
263
395
 
396
+ // src/shared/api/middleware/session-renewal.ts
397
+ function renewSessionMiddleware(fetchAccessToken) {
398
+ return async ({ request, response, retry }) => {
399
+ if (response.status !== 401) {
400
+ return response;
401
+ }
402
+ if (!Attributes.isProtected(request.attributes)) {
403
+ return response;
404
+ }
405
+ if (Attributes.wasRenewAttempted(request.attributes)) {
406
+ return response;
407
+ }
408
+ const newToken = await fetchAccessToken(true);
409
+ if (newToken) {
410
+ const nextRequest = Request.concatAttributes(
411
+ request,
412
+ Attributes.renewAttempted(true)
413
+ );
414
+ return retry(nextRequest);
415
+ } else {
416
+ return response;
417
+ }
418
+ };
419
+ }
420
+
421
+ // src/shared/api/authenticated-api-client.ts
422
+ var AuthenticatedApiClient = class {
423
+ constructor(config, fetchAccessToken, additionalBeforeRequest = []) {
424
+ this.httpClient = new HttpClient(config, {
425
+ beforeRequest: [
426
+ attachSessionMiddleware(fetchAccessToken),
427
+ ...additionalBeforeRequest,
428
+ idempotencyKeyMiddleware
429
+ ],
430
+ afterRequest: [
431
+ renewSessionMiddleware(fetchAccessToken),
432
+ requestRetryMiddleware
433
+ ]
434
+ });
435
+ }
436
+ async send(request) {
437
+ const response = await this.httpClient.send(request);
438
+ if (response.status >= 200 && response.status < 300) {
439
+ return response.body;
440
+ } else {
441
+ throw new HttpError(response);
442
+ }
443
+ }
444
+ };
445
+
264
446
  export {
265
- Attributes,
266
- HttpError,
267
- Request,
268
447
  PUBLIC_API_BASE_URL,
269
448
  HEADER_USER_AGENT,
270
- HEADER_IDEMPOTENCY_KEY,
271
449
  API_VERSION,
272
- COINLIST_OAUTH_PAGE_URL,
273
- HttpClient,
274
- requestRetryMiddleware,
275
- AuthorizationCode,
276
- CodeVerifier,
277
- CodeChallenge,
278
- RedirectUri,
279
- ClientId,
280
- ClientSecret
450
+ COINLIST_BASE_URL,
451
+ OAUTH_PAGE_PATH,
452
+ SUPPORT_NEW_TICKET_URL,
453
+ VERIFY_IDENTITY_PATH,
454
+ VERIFY_IDENTITY_VERIFIED_PATH,
455
+ VERIFY_IDENTITY_PROOF_OF_ADDRESS_PATH,
456
+ VERIFY_IDENTITY_SOURCE_OF_FUNDS_PATH,
457
+ VERIFY_IDENTITY_ACCREDITATION_PATH,
458
+ WALLET_PATH,
459
+ Attributes,
460
+ HttpError,
461
+ AuthenticatedApiClient,
462
+ fetchOffers,
463
+ fetchOffersPage,
464
+ fetchOfferDetails,
465
+ fetchParticipations,
466
+ fetchParticipationsPage,
467
+ fetchParticipation,
468
+ createParticipation,
469
+ fetchOfferRequirements,
470
+ fetchRequirementStatuses
281
471
  };
282
- //# sourceMappingURL=chunk-GRVV7NLV.js.map
472
+ //# sourceMappingURL=chunk-N3WBC2VS.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/shared/api/frontline/config.ts","../src/shared/api/http-attributes.ts","../src/shared/api/http.ts","../src/shared/api/frontline/offers.ts","../src/shared/api/frontline/participations.ts","../src/shared/api/frontline/requirements.ts","../src/shared/api/http-client.ts","../src/shared/api/middleware/attach-session-middleware.ts","../src/shared/api/middleware/idempotency-key.ts","../src/shared/api/middleware/request-retry.ts","../src/shared/api/middleware/session-renewal.ts","../src/shared/api/authenticated-api-client.ts"],"sourcesContent":["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_BASE_URL = 'https://coinlist.co';\nexport const OAUTH_PAGE_PATH = '/oauth/authorize';\n\nexport const SUPPORT_NEW_TICKET_URL =\n 'https://support.coinlist.co/support/tickets/new';\n\nexport const VERIFY_IDENTITY_PATH = '/verify-identity';\nexport const VERIFY_IDENTITY_VERIFIED_PATH =\n '/verify-identity/identity_verified';\nexport const VERIFY_IDENTITY_PROOF_OF_ADDRESS_PATH =\n '/verify-identity/proof_of_address';\nexport const VERIFY_IDENTITY_SOURCE_OF_FUNDS_PATH =\n '/verify-identity/source_of_funds';\nexport const VERIFY_IDENTITY_ACCREDITATION_PATH =\n '/verify-identity/accreditation_full';\nexport const WALLET_PATH = '/wallet';\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","import { Attributes } from '@/shared/api/http-attributes';\nimport type { Sender } from '@/shared/api/http-client';\nimport {\n fetchAllPages,\n PaginatedResponse,\n type PaginatedResponseDto,\n PaginationParams,\n} from '@/shared/api/pagination';\nimport type { OfferDto } from '@/shared/types/dto/offer';\nimport type { OfferDetailDto } from '@/shared/types/dto/offer-detail';\nimport { Offer, type OfferId } from '@/shared/types/offer';\nimport { OfferDetail } from '@/shared/types/offer-detail';\n\nexport async function fetchOffers(api: Sender): Promise<Offer[]> {\n return fetchAllPages((params) => fetchOffersPage(api, params));\n}\n\nexport async function fetchOffersPage(\n api: Sender,\n params: PaginationParams\n): Promise<PaginatedResponse<Offer>> {\n const queryParams = PaginationParams.toQueryParams(params);\n const pageDto = await api.send<PaginatedResponseDto<OfferDto>>({\n method: 'GET',\n url: '/v1/offers',\n queryParams,\n attributes: Attributes.protected(),\n });\n return PaginatedResponse.fromDto(pageDto, Offer.fromDto);\n}\n\nexport async function fetchOfferDetails(\n api: Sender,\n id: OfferId\n): Promise<OfferDetail> {\n const dto = await api.send<OfferDetailDto>({\n method: 'GET',\n url: `/v1/offers/${id}`,\n attributes: Attributes.protected(),\n });\n return OfferDetail.fromDto(dto);\n}\n","import { Attributes } from '@/shared/api/http-attributes';\nimport type { Sender } from '@/shared/api/http-client';\nimport {\n fetchAllPages,\n PaginatedResponse,\n type PaginatedResponseDto,\n} from '@/shared/api/pagination';\nimport type { ParticipationDto } from '@/shared/types/dto/participation';\nimport type { OfferId } from '@/shared/types/offer';\nimport {\n CreateParticipationParams,\n Participation,\n type ParticipationId,\n ParticipationsPaginationParams,\n} from '@/shared/types/participation';\n\nexport async function fetchParticipations(\n api: Sender,\n offerId?: OfferId\n): Promise<Participation[]> {\n return fetchAllPages<Participation, ParticipationsPaginationParams>(\n (params) => fetchParticipationsPage(api, params),\n { offerId }\n );\n}\n\nexport async function fetchParticipationsPage(\n api: Sender,\n params: ParticipationsPaginationParams\n): Promise<PaginatedResponse<Participation>> {\n const pageDto = await api.send<PaginatedResponseDto<ParticipationDto>>({\n method: 'GET',\n url: '/v1/participations',\n queryParams: ParticipationsPaginationParams.toQueryParams(params),\n attributes: Attributes.protected(),\n });\n return PaginatedResponse.fromDto(pageDto, Participation.fromDto);\n}\n\nexport async function fetchParticipation(\n api: Sender,\n id: ParticipationId\n): Promise<Participation> {\n const dto = await api.send<ParticipationDto>({\n method: 'GET',\n url: `/v1/participations/${id}`,\n attributes: Attributes.protected(),\n });\n return Participation.fromDto(dto);\n}\n\nexport async function createParticipation(\n api: Sender,\n params: CreateParticipationParams\n): Promise<Participation> {\n const dto = await api.send<ParticipationDto>({\n method: 'POST',\n url: '/v1/participations',\n body: CreateParticipationParams.toDto(params),\n attributes: Attributes.protected(),\n });\n return Participation.fromDto(dto);\n}\n","import { Attributes } from '@/shared/api/http-attributes';\nimport type { Sender } from '@/shared/api/http-client';\nimport type {\n OfferRequirementsDto,\n RequirementStatusesDto,\n} from '@/shared/types/dto/requirement';\nimport type { OfferId } from '@/shared/types/offer';\nimport type { OfferOptionId } from '@/shared/types/offer-detail';\nimport { Requirement, RequirementStatusInfo } from '@/shared/types/requirement';\n\nexport async function fetchOfferRequirements(\n api: Sender,\n offerId: OfferId\n): Promise<Record<OfferOptionId, Requirement[]>> {\n const response = await api.send<OfferRequirementsDto>({\n method: 'GET',\n url: `/v1/offers/${offerId}/requirements`,\n attributes: Attributes.protected(),\n });\n return Object.fromEntries(\n Object.entries(response.options).map(([optionId, list]) => [\n optionId,\n list.data.map(Requirement.fromDto),\n ])\n );\n}\n\nexport async function fetchRequirementStatuses(\n api: Sender,\n offerId: OfferId\n): Promise<RequirementStatusInfo[]> {\n const response = await api.send<RequirementStatusesDto>({\n method: 'GET',\n url: `/v1/offers/${offerId}/requirements/statuses`,\n attributes: Attributes.protected(),\n });\n return RequirementStatusInfo.fromStatusesDto(response);\n}\n","import { HEADER_API_VERSION } from '@/shared/api/frontline/config';\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\n/**\n * Structural interface satisfied by both {@link AuthenticatedApiClient} and\n * {@link ApiClient}. Used by the shared frontline API functions so they can\n * be called from either the client or server without any browser dependencies.\n */\nexport interface Sender {\n send<T>(request: HttpRequest): Promise<T>;\n}\n","import type { HttpRequest } from '@/shared/api/http';\nimport { Attributes } from '@/shared/api/http-attributes';\nimport type { BeforeRequestMiddleware } from '@/shared/api/http-client';\nimport type { OAuthAccessToken } from '@/shared/types/oauth-session';\n\nexport function attachSessionMiddleware(\n fetchAccessToken: (refresh: boolean) => Promise<OAuthAccessToken | null>\n): BeforeRequestMiddleware {\n return async (request: HttpRequest): Promise<HttpRequest> => {\n if (!Attributes.isProtected(request.attributes)) {\n return request;\n }\n\n const accessToken = await fetchAccessToken(false);\n if (accessToken === null) {\n return request;\n }\n\n return {\n ...request,\n headers: {\n ...(request.headers ?? {}),\n Authorization: `Bearer ${accessToken.value}`,\n },\n };\n };\n}\n","import { HEADER_IDEMPOTENCY_KEY } from '@/shared/api/frontline/config';\nimport type { HttpRequest } from '@/shared/api/http';\nimport { Attributes } from '@/shared/api/http-attributes';\nimport type { BeforeRequestMiddleware } from '@/shared/api/http-client';\nimport { getUUIDv4 } from '@/shared/utils';\n\nexport const idempotencyKeyMiddleware: BeforeRequestMiddleware = async (\n request: HttpRequest\n): Promise<HttpRequest> => {\n if (!Attributes.isIdempotent(request.attributes)) {\n return request;\n }\n\n const existingHeaders = request.headers ?? {};\n if (existingHeaders[HEADER_IDEMPOTENCY_KEY]) {\n return request;\n }\n\n return {\n ...request,\n headers: {\n ...existingHeaders,\n [HEADER_IDEMPOTENCY_KEY]: getUUIDv4(),\n },\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","import { Request } from '@/shared/api/http';\nimport { Attributes } from '@/shared/api/http-attributes';\nimport type { AfterRequestMiddleware } from '@/shared/api/http-client';\nimport type { OAuthAccessToken } from '@/shared/types/oauth-session';\n\nexport function renewSessionMiddleware(\n fetchAccessToken: (refresh: boolean) => Promise<OAuthAccessToken | null>\n): AfterRequestMiddleware {\n return async ({ request, response, retry }) => {\n if (response.status !== 401) {\n return response;\n }\n if (!Attributes.isProtected(request.attributes)) {\n return response;\n }\n if (Attributes.wasRenewAttempted(request.attributes)) {\n return response;\n }\n\n const newToken = await fetchAccessToken(true);\n if (newToken) {\n const nextRequest = Request.concatAttributes(\n request,\n Attributes.renewAttempted(true)\n );\n return retry(nextRequest);\n } else {\n return response;\n }\n };\n}\n","import type { HttpClientConfig, HttpRequest } from '@/shared/api/http';\nimport { HttpError } from '@/shared/api/http';\nimport type { BeforeRequestMiddleware } from '@/shared/api/http-client';\nimport { HttpClient } from '@/shared/api/http-client';\nimport { attachSessionMiddleware } from '@/shared/api/middleware/attach-session-middleware';\nimport { idempotencyKeyMiddleware } from '@/shared/api/middleware/idempotency-key';\nimport { requestRetryMiddleware } from '@/shared/api/middleware/request-retry';\nimport { renewSessionMiddleware } from '@/shared/api/middleware/session-renewal';\nimport type { OAuthAccessToken } from '@/shared/types/oauth-session';\n\n/**\n * Isomorphic HTTP client with session attachment, session renewal on 401,\n * idempotency key injection, and request retry. Works in both browser and\n * Node/server environments. Pass `additionalBeforeRequest` to inject\n * environment-specific middleware (e.g. `userAgentMiddleware` on the client).\n */\nexport class AuthenticatedApiClient {\n private readonly httpClient: HttpClient;\n\n constructor(\n config: HttpClientConfig,\n fetchAccessToken: (refresh: boolean) => Promise<OAuthAccessToken | null>,\n additionalBeforeRequest: BeforeRequestMiddleware[] = []\n ) {\n this.httpClient = new HttpClient(config, {\n beforeRequest: [\n attachSessionMiddleware(fetchAccessToken),\n ...additionalBeforeRequest,\n idempotencyKeyMiddleware,\n ],\n afterRequest: [\n renewSessionMiddleware(fetchAccessToken),\n requestRetryMiddleware,\n ],\n });\n }\n\n async send<TResponse>(request: HttpRequest): Promise<TResponse> {\n const response = await this.httpClient.send<TResponse>(request);\n if (response.status >= 200 && response.status < 300) {\n return response.body as TResponse;\n } else {\n throw new HttpError(response);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAAO,IAAM,sBAAsB;AAC5B,IAAM,qBAAqB;AAC3B,IAAM,oBAAoB;AAC1B,IAAM,yBAAyB;AAC/B,IAAM,cAAc;AAEpB,IAAM,oBAAoB;AAC1B,IAAM,kBAAkB;AAExB,IAAM,yBACX;AAEK,IAAM,uBAAuB;AAC7B,IAAM,gCACX;AACK,IAAM,wCACX;AACK,IAAM,uCACX;AACK,IAAM,qCACX;AACK,IAAM,cAAc;;;ACV3B,IAAM,QAAoB,CAAC;AAE3B,IAAM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;AAAA,QACb,wBAAwB,gBAAgB;AAAA,QACxC,GAAG;AAAA,QACH;AAAA,MACF;AAAA,MACA,cAAc;AAAA,QACZ,uBAAuB,gBAAgB;AAAA,QACvC;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEA,MAAM,KAAgB,SAA0C;AAC9D,UAAM,WAAW,MAAM,KAAK,WAAW,KAAgB,OAAO;AAC9D,QAAI,SAAS,UAAU,OAAO,SAAS,SAAS,KAAK;AACnD,aAAO,SAAS;AAAA,IAClB,OAAO;AACL,YAAM,IAAI,UAAU,QAAQ;AAAA,IAC9B;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,311 @@
1
+ // src/shared/api/pagination.ts
2
+ var Cursor = (value) => value;
3
+ async function fetchAllPages(fetchPage, baseParams) {
4
+ const items = [];
5
+ let cursor = null;
6
+ do {
7
+ const params = {
8
+ ...baseParams ?? {},
9
+ after: cursor ?? void 0
10
+ };
11
+ const page = await fetchPage(params);
12
+ items.push(...page.data);
13
+ cursor = page.startingAfter;
14
+ } while (cursor);
15
+ return items;
16
+ }
17
+ var PaginatedResponse = {
18
+ fromDto: (dto, itemMapper) => ({
19
+ data: dto.data.map(itemMapper),
20
+ startingAfter: dto.starting_after ? Cursor(dto.starting_after) : null,
21
+ startingBefore: dto.starting_before ? Cursor(dto.starting_before) : null
22
+ })
23
+ };
24
+ var PaginationParams = {
25
+ toQueryParams: (params) => {
26
+ const queryParams = {};
27
+ if (params.after) {
28
+ queryParams.starting_after = params.after;
29
+ }
30
+ if (params.before) {
31
+ queryParams.starting_before = params.before;
32
+ }
33
+ if (params.limit) {
34
+ queryParams.limit = params.limit;
35
+ }
36
+ return queryParams;
37
+ }
38
+ };
39
+
40
+ // src/shared/utils.ts
41
+ async function sha256(data) {
42
+ const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
43
+ const buffer = bytes.buffer.slice(
44
+ bytes.byteOffset,
45
+ bytes.byteOffset + bytes.byteLength
46
+ );
47
+ return crypto.subtle.digest("SHA-256", buffer);
48
+ }
49
+ function arrayBufferToBase64Url(buffer, padding = true) {
50
+ const bytes = new Uint8Array(buffer);
51
+ let binary = "";
52
+ for (let i = 0; i < bytes.length; i++) {
53
+ binary += String.fromCharCode(bytes[i]);
54
+ }
55
+ let base64 = btoa(binary);
56
+ base64 = base64.replace(/\+/g, "-").replace(/\//g, "_");
57
+ if (!padding) {
58
+ base64 = base64.replace(/=+$/, "");
59
+ }
60
+ return base64;
61
+ }
62
+ function generateSecureRandomBase64Url(byteLength) {
63
+ const bytes = new Uint8Array(byteLength);
64
+ crypto.getRandomValues(bytes);
65
+ const buffer = bytes.buffer;
66
+ return arrayBufferToBase64Url(buffer, false);
67
+ }
68
+ function getUUIDv4() {
69
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
70
+ return crypto.randomUUID();
71
+ }
72
+ if (typeof crypto !== "undefined" && typeof crypto.getRandomValues === "function") {
73
+ const bytes = new Uint8Array(16);
74
+ crypto.getRandomValues(bytes);
75
+ bytes[6] = bytes[6] & 15 | 64;
76
+ bytes[8] = bytes[8] & 63 | 128;
77
+ const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0"));
78
+ return `${hex.slice(0, 4).join("")}-${hex.slice(4, 6).join("")}-${hex.slice(6, 8).join("")}-${hex.slice(8, 10).join("")}-${hex.slice(10, 16).join("")}`;
79
+ }
80
+ return `${Date.now()}-${Math.random().toString(36).slice(2, 12)}`;
81
+ }
82
+ function notBlankStringOrNull(value) {
83
+ if (value?.trim()) {
84
+ return value;
85
+ } else {
86
+ return null;
87
+ }
88
+ }
89
+
90
+ // src/shared/types/offer.ts
91
+ var OfferId = (value) => value;
92
+ var OfferSlug = (value) => value;
93
+ var Offer = {
94
+ fromDto: (dto) => ({
95
+ id: OfferId(dto.id),
96
+ slug: OfferSlug(dto.slug),
97
+ tagline: notBlankStringOrNull(dto.tagline),
98
+ bannerUrl: notBlankStringOrNull(dto.banner_url),
99
+ logoUrl: notBlankStringOrNull(dto.logo_url),
100
+ startsAt: new Date(dto.starts_at),
101
+ endsAt: new Date(dto.ends_at)
102
+ })
103
+ };
104
+
105
+ // src/shared/types/asset.ts
106
+ var AssetId = (value) => value;
107
+ var AssetCode = (value) => value;
108
+ var Asset = {
109
+ fromDto: (dto) => ({
110
+ id: AssetId(dto.id),
111
+ code: AssetCode(dto.code),
112
+ name: dto.name,
113
+ fractionalDigits: dto.fractional_digits
114
+ })
115
+ };
116
+
117
+ // src/shared/types/offer-detail.ts
118
+ var OfferOptionId = (value) => value;
119
+ var OfferOptionSlug = (value) => value;
120
+ var OfferDetail = {
121
+ fromDto: (dto) => {
122
+ if (!Array.isArray(dto.funding_assets)) {
123
+ throw new Error(`funding_assets must be an array`);
124
+ }
125
+ if (!Array.isArray(dto.options)) {
126
+ throw new Error(`options must be an array`);
127
+ }
128
+ if (!Array.isArray(dto.terms)) {
129
+ throw new Error(`terms must be an array`);
130
+ }
131
+ if (!Array.isArray(dto.links)) {
132
+ throw new Error(`links must be an array`);
133
+ }
134
+ if (!Array.isArray(dto.faqs)) {
135
+ throw new Error(`faqs must be an array`);
136
+ }
137
+ if (!Array.isArray(dto.milestones)) {
138
+ throw new Error(`milestones must be an array`);
139
+ }
140
+ return {
141
+ id: OfferId(dto.id),
142
+ slug: OfferSlug(dto.slug),
143
+ name: dto.name,
144
+ asset: Asset.fromDto(dto.asset),
145
+ fundingAssets: dto.funding_assets.map(Asset.fromDto),
146
+ about: notBlankStringOrNull(dto.about),
147
+ tagline: notBlankStringOrNull(dto.tagline),
148
+ bannerUrl: notBlankStringOrNull(dto.banner_url),
149
+ logoUrl: notBlankStringOrNull(dto.logo_url),
150
+ category: notBlankStringOrNull(dto.category),
151
+ startsAt: new Date(dto.starts_at),
152
+ endsAt: new Date(dto.ends_at),
153
+ faqs: dto.faqs.map(FaqItem.fromDto),
154
+ links: dto.links.map(Link.fromDto),
155
+ milestones: dto.milestones.map(Milestone.fromDto),
156
+ options: dto.options.map(OfferOption.fromDto),
157
+ terms: dto.terms.map(TermItem.fromDto)
158
+ };
159
+ }
160
+ };
161
+ var OfferOption = {
162
+ fromDto: (dto) => ({
163
+ id: OfferOptionId(dto.id),
164
+ slug: OfferOptionSlug(dto.slug),
165
+ bidIncrement: dto.bid_increment,
166
+ floorPriceUsd: dto.floor_price_usd,
167
+ minimumPurchaseUsd: dto.minimum_purchase_usd,
168
+ priceUsd: dto.price_usd,
169
+ saleAgreementUrl: notBlankStringOrNull(dto.sale_agreement_url),
170
+ totalTokenSupply: dto.total_token_supply
171
+ })
172
+ };
173
+ var FaqItem = {
174
+ fromDto: (dto) => ({
175
+ question: notBlankStringOrNull(dto.question),
176
+ answer: notBlankStringOrNull(dto.answer)
177
+ })
178
+ };
179
+ var Link = {
180
+ fromDto: (dto) => ({
181
+ label: notBlankStringOrNull(dto.label),
182
+ url: notBlankStringOrNull(dto.url)
183
+ })
184
+ };
185
+ var TermItem = {
186
+ fromDto: (dto) => ({
187
+ key: notBlankStringOrNull(dto.key),
188
+ value: notBlankStringOrNull(dto.value)
189
+ })
190
+ };
191
+ var Milestone = {
192
+ fromDto: (dto) => ({
193
+ name: notBlankStringOrNull(dto.name),
194
+ schedule: notBlankStringOrNull(dto.schedule),
195
+ status: dto.status
196
+ })
197
+ };
198
+
199
+ // src/shared/types/participation.ts
200
+ var ParticipationId = (value) => value;
201
+ var Blockchain = (value) => value;
202
+ var WalletAddress = (value) => value;
203
+ var ParticipationsPaginationParams = {
204
+ toQueryParams: (params) => {
205
+ const queryParams = PaginationParams.toQueryParams(params);
206
+ if (params.offerId) {
207
+ queryParams["filters[0][field]"] = "offer_id";
208
+ queryParams["filters[0][op]"] = "==";
209
+ queryParams["filters[0][value]"] = params.offerId;
210
+ }
211
+ return queryParams;
212
+ }
213
+ };
214
+ var Participation = {
215
+ /** Maps API DTO shape into the SDK participation domain model. */
216
+ fromDto: (dto) => {
217
+ const walletAddress = notBlankStringOrNull(dto.wallet_address);
218
+ return {
219
+ id: ParticipationId(dto.id),
220
+ offerId: OfferId(dto.offer_id),
221
+ offerOptionId: OfferOptionId(dto.offer_option_id),
222
+ status: dto.status,
223
+ amount: dto.amount,
224
+ displayAmount: dto.amount_string,
225
+ asset: Asset.fromDto(dto.asset),
226
+ chain: Blockchain(dto.chain),
227
+ insertedAt: dto.inserted_at ? new Date(dto.inserted_at) : null,
228
+ updatedAt: dto.updated_at ? new Date(dto.updated_at) : null,
229
+ walletAddress: walletAddress ? WalletAddress(walletAddress) : null
230
+ };
231
+ }
232
+ };
233
+ var CreateParticipationParams = {
234
+ /** Maps participation creation params into API DTO payload. */
235
+ toDto: (params) => ({
236
+ offer_id: params.offerId,
237
+ offer_option_id: params.offerOptionId,
238
+ chain: params.chain,
239
+ wallet_address: params.walletAddress,
240
+ amount: params.amount,
241
+ asset_id: params.assetId,
242
+ approval_transaction_hash: params.approvalTransactionHash
243
+ })
244
+ };
245
+
246
+ // src/shared/types/requirement.ts
247
+ var RequirementId = (value) => value;
248
+ var Requirement = {
249
+ fromDto: (dto) => ({
250
+ id: RequirementId(dto.id),
251
+ type: dto.type,
252
+ details: dto.details
253
+ })
254
+ };
255
+ var RequirementStatusInfo = {
256
+ fromStatusesDto: (dto) => Object.entries(dto.statuses).map(([id, status]) => ({
257
+ id: RequirementId(id),
258
+ status
259
+ }))
260
+ };
261
+
262
+ // src/shared/types/errors.ts
263
+ var NotImplementedError = class extends Error {
264
+ constructor(message = "Not implemented yet") {
265
+ super(message);
266
+ this.name = "NotImplementedError";
267
+ }
268
+ };
269
+ var NotAuthenticatedError = class extends Error {
270
+ constructor(message = "The user is not authenticated. Go through the OAuth flow first!") {
271
+ super(message);
272
+ this.name = "NotAuthenticatedError";
273
+ }
274
+ };
275
+
276
+ export {
277
+ sha256,
278
+ arrayBufferToBase64Url,
279
+ generateSecureRandomBase64Url,
280
+ getUUIDv4,
281
+ Cursor,
282
+ fetchAllPages,
283
+ PaginatedResponse,
284
+ PaginationParams,
285
+ OfferId,
286
+ OfferSlug,
287
+ Offer,
288
+ AssetId,
289
+ AssetCode,
290
+ Asset,
291
+ OfferOptionId,
292
+ OfferOptionSlug,
293
+ OfferDetail,
294
+ OfferOption,
295
+ FaqItem,
296
+ Link,
297
+ TermItem,
298
+ Milestone,
299
+ ParticipationId,
300
+ Blockchain,
301
+ WalletAddress,
302
+ ParticipationsPaginationParams,
303
+ Participation,
304
+ CreateParticipationParams,
305
+ RequirementId,
306
+ Requirement,
307
+ RequirementStatusInfo,
308
+ NotImplementedError,
309
+ NotAuthenticatedError
310
+ };
311
+ //# sourceMappingURL=chunk-V6WO67RO.js.map