@coinlist-co/react 0.3.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-BvwsFu9e.d.cts → RequirementItem-B-MvcxSr.d.cts} +3 -3
- package/dist/{RequirementItem-BpkJQep8.d.ts → RequirementItem-DcYot2uC.d.ts} +3 -3
- package/dist/{chunk-IDCROXPS.js → chunk-EHZ6PIGN.js} +6 -4
- 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 +60 -59
- package/dist/client/components/index.cjs.map +1 -1
- package/dist/client/components/index.d.cts +40 -22
- package/dist/client/components/index.d.ts +40 -22
- package/dist/client/components/index.js +34 -62
- package/dist/client/components/index.js.map +1 -1
- package/dist/client/core/index.cjs +308 -222
- 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 +14 -14
- package/dist/client/hooks/index.cjs +87 -13
- package/dist/client/hooks/index.cjs.map +1 -1
- package/dist/client/hooks/index.d.cts +102 -9
- package/dist/client/hooks/index.d.ts +102 -9
- package/dist/client/hooks/index.js +9 -9
- package/dist/client/index.cjs +465 -237
- package/dist/client/index.cjs.map +1 -1
- package/dist/client/index.d.cts +7 -8
- package/dist/client/index.d.ts +7 -8
- package/dist/client/index.js +24 -18
- package/dist/{coinlist-client-B_dJkbwB.d.ts → coinlist-client-BSxpqylo.d.ts} +13 -138
- package/dist/{coinlist-client-DBKa6j3f.d.cts → coinlist-client-Cah5c_aF.d.cts} +13 -138
- package/dist/participation-DMMEDxON.d.cts +185 -0
- package/dist/participation-E-bT-GXJ.d.ts +185 -0
- package/dist/{requirement-CxbdY8l4.d.cts → requirement-XWT0T_zO.d.cts} +5 -2
- package/dist/{requirement-fJsQ3f9_.d.ts → requirement-XWT0T_zO.d.ts} +5 -2
- 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 +1 -1
- package/dist/chunk-GRVV7NLV.js +0 -282
- package/dist/chunk-GRVV7NLV.js.map +0 -1
- package/dist/chunk-IADBIDY6.js +0 -76
- package/dist/chunk-IADBIDY6.js.map +0 -1
- package/dist/chunk-IDCROXPS.js.map +0 -1
- package/dist/chunk-P4DTIPEX.js +0 -623
- package/dist/chunk-P4DTIPEX.js.map +0 -1
- package/dist/chunk-V5M7SA3C.js +0 -161
- package/dist/chunk-V5M7SA3C.js.map +0 -1
- 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/useCoinListOffers-C5lBlzcC.d.ts +0 -27
- package/dist/useCoinListOffers-CguwXaCX.d.cts +0 -27
- package/dist/useCoinListRequirements-BECx1cIw.d.ts +0 -31
- package/dist/useCoinListRequirements-CX2gV9gJ.d.cts +0 -31
- package/dist/useCompleteCoinListOAuth-BRhAqD4_.d.cts +0 -55
- package/dist/useCompleteCoinListOAuth-DEZpHjd6.d.ts +0 -55
package/dist/server/index.cjs
CHANGED
|
@@ -21,14 +21,40 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var server_exports = {};
|
|
22
22
|
__export(server_exports, {
|
|
23
23
|
AuthorizationCode: () => AuthorizationCode,
|
|
24
|
+
Blockchain: () => Blockchain,
|
|
24
25
|
ClientId: () => ClientId,
|
|
25
26
|
ClientSecret: () => ClientSecret,
|
|
26
27
|
CodeChallenge: () => CodeChallenge,
|
|
27
28
|
CodeVerifier: () => CodeVerifier,
|
|
29
|
+
CreateParticipationParams: () => CreateParticipationParams,
|
|
30
|
+
Cursor: () => Cursor,
|
|
31
|
+
FaqItem: () => FaqItem,
|
|
32
|
+
Link: () => Link,
|
|
33
|
+
Milestone: () => Milestone,
|
|
34
|
+
NotAuthenticatedError: () => NotAuthenticatedError,
|
|
35
|
+
NotImplementedError: () => NotImplementedError,
|
|
28
36
|
OAuthRefreshToken: () => OAuthRefreshToken,
|
|
29
37
|
OAuthSession: () => OAuthSession,
|
|
38
|
+
Offer: () => Offer,
|
|
39
|
+
OfferDetail: () => OfferDetail,
|
|
40
|
+
OfferId: () => OfferId,
|
|
41
|
+
OfferOption: () => OfferOption,
|
|
42
|
+
OfferOptionId: () => OfferOptionId,
|
|
43
|
+
OfferOptionSlug: () => OfferOptionSlug,
|
|
44
|
+
OfferSlug: () => OfferSlug,
|
|
45
|
+
PaginatedResponse: () => PaginatedResponse,
|
|
46
|
+
PaginationParams: () => PaginationParams,
|
|
47
|
+
Participation: () => Participation,
|
|
48
|
+
ParticipationId: () => ParticipationId,
|
|
49
|
+
ParticipationsPaginationParams: () => ParticipationsPaginationParams,
|
|
30
50
|
RedirectUri: () => RedirectUri,
|
|
31
|
-
|
|
51
|
+
Requirement: () => Requirement,
|
|
52
|
+
RequirementId: () => RequirementId,
|
|
53
|
+
RequirementStatusInfo: () => RequirementStatusInfo,
|
|
54
|
+
TermItem: () => TermItem,
|
|
55
|
+
WalletAddress: () => WalletAddress,
|
|
56
|
+
createCoinListServer: () => createCoinListServer,
|
|
57
|
+
fetchAllPages: () => fetchAllPages
|
|
32
58
|
});
|
|
33
59
|
module.exports = __toCommonJS(server_exports);
|
|
34
60
|
|
|
@@ -175,9 +201,10 @@ var Request = {
|
|
|
175
201
|
concatAttributes
|
|
176
202
|
};
|
|
177
203
|
|
|
178
|
-
// src/shared/api/frontline.ts
|
|
204
|
+
// src/shared/api/frontline/index.ts
|
|
179
205
|
var PUBLIC_API_BASE_URL = "https://api.coinlist.co";
|
|
180
206
|
var HEADER_API_VERSION = "X-API-Version";
|
|
207
|
+
var HEADER_IDEMPOTENCY_KEY = "Idempotency-Key";
|
|
181
208
|
var API_VERSION = "2025-10-17";
|
|
182
209
|
|
|
183
210
|
// src/shared/api/http-client.ts
|
|
@@ -249,6 +276,67 @@ var HttpClient = class {
|
|
|
249
276
|
}
|
|
250
277
|
};
|
|
251
278
|
|
|
279
|
+
// src/shared/api/middleware/attach-session-middleware.ts
|
|
280
|
+
function attachSessionMiddleware(fetchAccessToken) {
|
|
281
|
+
return async (request) => {
|
|
282
|
+
if (!Attributes.isProtected(request.attributes)) {
|
|
283
|
+
return request;
|
|
284
|
+
}
|
|
285
|
+
const accessToken = await fetchAccessToken(false);
|
|
286
|
+
if (accessToken === null) {
|
|
287
|
+
return request;
|
|
288
|
+
}
|
|
289
|
+
return {
|
|
290
|
+
...request,
|
|
291
|
+
headers: {
|
|
292
|
+
...request.headers ?? {},
|
|
293
|
+
Authorization: `Bearer ${accessToken.value}`
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// src/shared/utils.ts
|
|
300
|
+
function getUUIDv4() {
|
|
301
|
+
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
302
|
+
return crypto.randomUUID();
|
|
303
|
+
}
|
|
304
|
+
if (typeof crypto !== "undefined" && typeof crypto.getRandomValues === "function") {
|
|
305
|
+
const bytes = new Uint8Array(16);
|
|
306
|
+
crypto.getRandomValues(bytes);
|
|
307
|
+
bytes[6] = bytes[6] & 15 | 64;
|
|
308
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
309
|
+
const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0"));
|
|
310
|
+
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("")}`;
|
|
311
|
+
}
|
|
312
|
+
return `${Date.now()}-${Math.random().toString(36).slice(2, 12)}`;
|
|
313
|
+
}
|
|
314
|
+
function notBlankStringOrNull(value) {
|
|
315
|
+
if (value?.trim()) {
|
|
316
|
+
return value;
|
|
317
|
+
} else {
|
|
318
|
+
return null;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// src/shared/api/middleware/idempotency-key.ts
|
|
323
|
+
var idempotencyKeyMiddleware = async (request) => {
|
|
324
|
+
if (!Attributes.isIdempotent(request.attributes)) {
|
|
325
|
+
return request;
|
|
326
|
+
}
|
|
327
|
+
const existingHeaders = request.headers ?? {};
|
|
328
|
+
if (existingHeaders[HEADER_IDEMPOTENCY_KEY]) {
|
|
329
|
+
return request;
|
|
330
|
+
}
|
|
331
|
+
return {
|
|
332
|
+
...request,
|
|
333
|
+
headers: {
|
|
334
|
+
...existingHeaders,
|
|
335
|
+
[HEADER_IDEMPOTENCY_KEY]: getUUIDv4()
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
};
|
|
339
|
+
|
|
252
340
|
// src/shared/api/middleware/request-retry.ts
|
|
253
341
|
var MAX_ATTEMPTS = 3;
|
|
254
342
|
var INITIAL_DELAY_MS = 300;
|
|
@@ -284,13 +372,44 @@ function defaultDelay(ms) {
|
|
|
284
372
|
}
|
|
285
373
|
var requestRetryMiddleware = createRequestRetryMiddleware();
|
|
286
374
|
|
|
287
|
-
// src/
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
375
|
+
// src/shared/api/middleware/session-renewal.ts
|
|
376
|
+
function renewSessionMiddleware(fetchAccessToken) {
|
|
377
|
+
return async ({ request, response, retry }) => {
|
|
378
|
+
if (response.status !== 401) {
|
|
379
|
+
return response;
|
|
380
|
+
}
|
|
381
|
+
if (!Attributes.isProtected(request.attributes)) {
|
|
382
|
+
return response;
|
|
383
|
+
}
|
|
384
|
+
if (Attributes.wasRenewAttempted(request.attributes)) {
|
|
385
|
+
return response;
|
|
386
|
+
}
|
|
387
|
+
const newToken = await fetchAccessToken(true);
|
|
388
|
+
if (newToken) {
|
|
389
|
+
const nextRequest = Request.concatAttributes(
|
|
390
|
+
request,
|
|
391
|
+
Attributes.renewAttempted(true)
|
|
392
|
+
);
|
|
393
|
+
return retry(nextRequest);
|
|
394
|
+
} else {
|
|
395
|
+
return response;
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
// src/shared/api/authenticated-api-client.ts
|
|
401
|
+
var AuthenticatedApiClient = class {
|
|
402
|
+
constructor(config, fetchAccessToken, additionalBeforeRequest = []) {
|
|
403
|
+
this.httpClient = new HttpClient(config, {
|
|
404
|
+
beforeRequest: [
|
|
405
|
+
attachSessionMiddleware(fetchAccessToken),
|
|
406
|
+
...additionalBeforeRequest,
|
|
407
|
+
idempotencyKeyMiddleware
|
|
408
|
+
],
|
|
409
|
+
afterRequest: [
|
|
410
|
+
renewSessionMiddleware(fetchAccessToken),
|
|
411
|
+
requestRetryMiddleware
|
|
412
|
+
]
|
|
294
413
|
});
|
|
295
414
|
}
|
|
296
415
|
async send(request) {
|
|
@@ -303,6 +422,321 @@ var Api = class {
|
|
|
303
422
|
}
|
|
304
423
|
};
|
|
305
424
|
|
|
425
|
+
// src/server/api/api.server.ts
|
|
426
|
+
var Api = class {
|
|
427
|
+
constructor(config, fetchAccessToken) {
|
|
428
|
+
this.client = new AuthenticatedApiClient(config, fetchAccessToken);
|
|
429
|
+
}
|
|
430
|
+
async send(request) {
|
|
431
|
+
return this.client.send(request);
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
|
|
435
|
+
// src/shared/api/pagination.ts
|
|
436
|
+
var Cursor = (value) => value;
|
|
437
|
+
async function fetchAllPages(fetchPage, baseParams) {
|
|
438
|
+
const items = [];
|
|
439
|
+
let cursor = null;
|
|
440
|
+
do {
|
|
441
|
+
const params = {
|
|
442
|
+
...baseParams ?? {},
|
|
443
|
+
after: cursor ?? void 0
|
|
444
|
+
};
|
|
445
|
+
const page = await fetchPage(params);
|
|
446
|
+
items.push(...page.data);
|
|
447
|
+
cursor = page.startingAfter;
|
|
448
|
+
} while (cursor);
|
|
449
|
+
return items;
|
|
450
|
+
}
|
|
451
|
+
var PaginatedResponse = {
|
|
452
|
+
fromDto: (dto, itemMapper) => ({
|
|
453
|
+
data: dto.data.map(itemMapper),
|
|
454
|
+
startingAfter: dto.starting_after ? Cursor(dto.starting_after) : null,
|
|
455
|
+
startingBefore: dto.starting_before ? Cursor(dto.starting_before) : null
|
|
456
|
+
})
|
|
457
|
+
};
|
|
458
|
+
var PaginationParams = {
|
|
459
|
+
toQueryParams: (params) => {
|
|
460
|
+
const queryParams = {};
|
|
461
|
+
if (params.after) {
|
|
462
|
+
queryParams.starting_after = params.after;
|
|
463
|
+
}
|
|
464
|
+
if (params.before) {
|
|
465
|
+
queryParams.starting_before = params.before;
|
|
466
|
+
}
|
|
467
|
+
if (params.limit) {
|
|
468
|
+
queryParams.limit = params.limit;
|
|
469
|
+
}
|
|
470
|
+
return queryParams;
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
|
|
474
|
+
// src/shared/types/offer.ts
|
|
475
|
+
var OfferId = (value) => value;
|
|
476
|
+
var OfferSlug = (value) => value;
|
|
477
|
+
var Offer = {
|
|
478
|
+
fromDto: (dto) => ({
|
|
479
|
+
id: OfferId(dto.id),
|
|
480
|
+
slug: OfferSlug(dto.slug),
|
|
481
|
+
tagline: notBlankStringOrNull(dto.tagline),
|
|
482
|
+
bannerUrl: notBlankStringOrNull(dto.banner_url),
|
|
483
|
+
logoUrl: notBlankStringOrNull(dto.logo_url),
|
|
484
|
+
startsAt: new Date(dto.starts_at),
|
|
485
|
+
endsAt: new Date(dto.ends_at)
|
|
486
|
+
})
|
|
487
|
+
};
|
|
488
|
+
|
|
489
|
+
// src/shared/types/asset.ts
|
|
490
|
+
var AssetId = (value) => value;
|
|
491
|
+
var AssetCode = (value) => value;
|
|
492
|
+
var Asset = {
|
|
493
|
+
fromDto: (dto) => ({
|
|
494
|
+
id: AssetId(dto.id),
|
|
495
|
+
code: AssetCode(dto.code),
|
|
496
|
+
name: dto.name,
|
|
497
|
+
fractionalDigits: dto.fractional_digits
|
|
498
|
+
})
|
|
499
|
+
};
|
|
500
|
+
|
|
501
|
+
// src/shared/types/offer-detail.ts
|
|
502
|
+
var OfferOptionId = (value) => value;
|
|
503
|
+
var OfferOptionSlug = (value) => value;
|
|
504
|
+
var OfferDetail = {
|
|
505
|
+
fromDto: (dto) => {
|
|
506
|
+
if (!Array.isArray(dto.funding_assets)) {
|
|
507
|
+
throw new Error(`funding_assets must be an array`);
|
|
508
|
+
}
|
|
509
|
+
if (!Array.isArray(dto.options)) {
|
|
510
|
+
throw new Error(`options must be an array`);
|
|
511
|
+
}
|
|
512
|
+
if (!Array.isArray(dto.terms)) {
|
|
513
|
+
throw new Error(`terms must be an array`);
|
|
514
|
+
}
|
|
515
|
+
if (!Array.isArray(dto.links)) {
|
|
516
|
+
throw new Error(`links must be an array`);
|
|
517
|
+
}
|
|
518
|
+
if (!Array.isArray(dto.faqs)) {
|
|
519
|
+
throw new Error(`faqs must be an array`);
|
|
520
|
+
}
|
|
521
|
+
if (!Array.isArray(dto.milestones)) {
|
|
522
|
+
throw new Error(`milestones must be an array`);
|
|
523
|
+
}
|
|
524
|
+
return {
|
|
525
|
+
id: OfferId(dto.id),
|
|
526
|
+
slug: OfferSlug(dto.slug),
|
|
527
|
+
name: dto.name,
|
|
528
|
+
asset: Asset.fromDto(dto.asset),
|
|
529
|
+
fundingAssets: dto.funding_assets.map(Asset.fromDto),
|
|
530
|
+
about: notBlankStringOrNull(dto.about),
|
|
531
|
+
tagline: notBlankStringOrNull(dto.tagline),
|
|
532
|
+
bannerUrl: notBlankStringOrNull(dto.banner_url),
|
|
533
|
+
logoUrl: notBlankStringOrNull(dto.logo_url),
|
|
534
|
+
category: notBlankStringOrNull(dto.category),
|
|
535
|
+
startsAt: new Date(dto.starts_at),
|
|
536
|
+
endsAt: new Date(dto.ends_at),
|
|
537
|
+
faqs: dto.faqs.map(FaqItem.fromDto),
|
|
538
|
+
links: dto.links.map(Link.fromDto),
|
|
539
|
+
milestones: dto.milestones.map(Milestone.fromDto),
|
|
540
|
+
options: dto.options.map(OfferOption.fromDto),
|
|
541
|
+
terms: dto.terms.map(TermItem.fromDto)
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
};
|
|
545
|
+
var OfferOption = {
|
|
546
|
+
fromDto: (dto) => ({
|
|
547
|
+
id: OfferOptionId(dto.id),
|
|
548
|
+
slug: OfferOptionSlug(dto.slug),
|
|
549
|
+
bidIncrement: dto.bid_increment,
|
|
550
|
+
floorPriceUsd: dto.floor_price_usd,
|
|
551
|
+
minimumPurchaseUsd: dto.minimum_purchase_usd,
|
|
552
|
+
priceUsd: dto.price_usd,
|
|
553
|
+
saleAgreementUrl: notBlankStringOrNull(dto.sale_agreement_url),
|
|
554
|
+
totalTokenSupply: dto.total_token_supply
|
|
555
|
+
})
|
|
556
|
+
};
|
|
557
|
+
var FaqItem = {
|
|
558
|
+
fromDto: (dto) => ({
|
|
559
|
+
question: notBlankStringOrNull(dto.question),
|
|
560
|
+
answer: notBlankStringOrNull(dto.answer)
|
|
561
|
+
})
|
|
562
|
+
};
|
|
563
|
+
var Link = {
|
|
564
|
+
fromDto: (dto) => ({
|
|
565
|
+
label: notBlankStringOrNull(dto.label),
|
|
566
|
+
url: notBlankStringOrNull(dto.url)
|
|
567
|
+
})
|
|
568
|
+
};
|
|
569
|
+
var TermItem = {
|
|
570
|
+
fromDto: (dto) => ({
|
|
571
|
+
key: notBlankStringOrNull(dto.key),
|
|
572
|
+
value: notBlankStringOrNull(dto.value)
|
|
573
|
+
})
|
|
574
|
+
};
|
|
575
|
+
var Milestone = {
|
|
576
|
+
fromDto: (dto) => ({
|
|
577
|
+
name: notBlankStringOrNull(dto.name),
|
|
578
|
+
schedule: notBlankStringOrNull(dto.schedule),
|
|
579
|
+
status: dto.status
|
|
580
|
+
})
|
|
581
|
+
};
|
|
582
|
+
|
|
583
|
+
// src/shared/api/frontline/offers.ts
|
|
584
|
+
async function fetchAllOffers(api) {
|
|
585
|
+
return fetchAllPages((params) => fetchOffersPage(api, params));
|
|
586
|
+
}
|
|
587
|
+
async function fetchOffersPage(api, params) {
|
|
588
|
+
const queryParams = PaginationParams.toQueryParams(params);
|
|
589
|
+
const pageDto = await api.send({
|
|
590
|
+
method: "GET",
|
|
591
|
+
url: "/v1/offers",
|
|
592
|
+
queryParams,
|
|
593
|
+
attributes: Attributes.protected()
|
|
594
|
+
});
|
|
595
|
+
return PaginatedResponse.fromDto(pageDto, Offer.fromDto);
|
|
596
|
+
}
|
|
597
|
+
async function fetchOfferDetails(api, id) {
|
|
598
|
+
const dto = await api.send({
|
|
599
|
+
method: "GET",
|
|
600
|
+
url: `/v1/offers/${id}`,
|
|
601
|
+
attributes: Attributes.protected()
|
|
602
|
+
});
|
|
603
|
+
return OfferDetail.fromDto(dto);
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
// src/shared/types/participation.ts
|
|
607
|
+
var ParticipationId = (value) => value;
|
|
608
|
+
var Blockchain = (value) => value;
|
|
609
|
+
var WalletAddress = (value) => value;
|
|
610
|
+
var ParticipationsPaginationParams = {
|
|
611
|
+
toQueryParams: (params) => {
|
|
612
|
+
const queryParams = PaginationParams.toQueryParams(params);
|
|
613
|
+
if (params.offerId) {
|
|
614
|
+
queryParams["filters[0][field]"] = "offer_id";
|
|
615
|
+
queryParams["filters[0][op]"] = "==";
|
|
616
|
+
queryParams["filters[0][value]"] = params.offerId;
|
|
617
|
+
}
|
|
618
|
+
return queryParams;
|
|
619
|
+
}
|
|
620
|
+
};
|
|
621
|
+
var Participation = {
|
|
622
|
+
/** Maps API DTO shape into the SDK participation domain model. */
|
|
623
|
+
fromDto: (dto) => {
|
|
624
|
+
const walletAddress = notBlankStringOrNull(dto.wallet_address);
|
|
625
|
+
return {
|
|
626
|
+
id: ParticipationId(dto.id),
|
|
627
|
+
offerId: OfferId(dto.offer_id),
|
|
628
|
+
offerOptionId: OfferOptionId(dto.offer_option_id),
|
|
629
|
+
status: dto.status,
|
|
630
|
+
amount: dto.amount,
|
|
631
|
+
displayAmount: dto.amount_string,
|
|
632
|
+
asset: Asset.fromDto(dto.asset),
|
|
633
|
+
chain: Blockchain(dto.chain),
|
|
634
|
+
insertedAt: dto.inserted_at ? new Date(dto.inserted_at) : null,
|
|
635
|
+
updatedAt: dto.updated_at ? new Date(dto.updated_at) : null,
|
|
636
|
+
walletAddress: walletAddress ? WalletAddress(walletAddress) : null
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
};
|
|
640
|
+
var CreateParticipationParams = {
|
|
641
|
+
/** Maps participation creation params into API DTO payload. */
|
|
642
|
+
toDto: (params) => ({
|
|
643
|
+
offer_id: params.offerId,
|
|
644
|
+
offer_option_id: params.offerOptionId,
|
|
645
|
+
chain: params.chain,
|
|
646
|
+
wallet_address: params.walletAddress,
|
|
647
|
+
amount: params.amount,
|
|
648
|
+
asset_id: params.assetId,
|
|
649
|
+
approval_transaction_hash: params.approvalTransactionHash
|
|
650
|
+
})
|
|
651
|
+
};
|
|
652
|
+
|
|
653
|
+
// src/shared/api/frontline/participations.ts
|
|
654
|
+
async function fetchAllParticipations(api, offerId) {
|
|
655
|
+
return fetchAllPages(
|
|
656
|
+
(params) => fetchParticipationsPage(api, params),
|
|
657
|
+
{ offerId }
|
|
658
|
+
);
|
|
659
|
+
}
|
|
660
|
+
async function fetchParticipationsPage(api, params) {
|
|
661
|
+
const pageDto = await api.send({
|
|
662
|
+
method: "GET",
|
|
663
|
+
url: "/v1/participations",
|
|
664
|
+
queryParams: ParticipationsPaginationParams.toQueryParams(params),
|
|
665
|
+
attributes: Attributes.protected()
|
|
666
|
+
});
|
|
667
|
+
return PaginatedResponse.fromDto(pageDto, Participation.fromDto);
|
|
668
|
+
}
|
|
669
|
+
async function fetchParticipation(api, id) {
|
|
670
|
+
const dto = await api.send({
|
|
671
|
+
method: "GET",
|
|
672
|
+
url: `/v1/participations/${id}`,
|
|
673
|
+
attributes: Attributes.protected()
|
|
674
|
+
});
|
|
675
|
+
return Participation.fromDto(dto);
|
|
676
|
+
}
|
|
677
|
+
async function createParticipation(api, params) {
|
|
678
|
+
const dto = await api.send({
|
|
679
|
+
method: "POST",
|
|
680
|
+
url: "/v1/participations",
|
|
681
|
+
body: CreateParticipationParams.toDto(params),
|
|
682
|
+
attributes: Attributes.protected()
|
|
683
|
+
});
|
|
684
|
+
return Participation.fromDto(dto);
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
// src/shared/types/requirement.ts
|
|
688
|
+
var RequirementId = (value) => value;
|
|
689
|
+
var Requirement = {
|
|
690
|
+
fromDto: (dto) => ({
|
|
691
|
+
id: RequirementId(dto.id),
|
|
692
|
+
type: dto.type,
|
|
693
|
+
details: dto.details
|
|
694
|
+
})
|
|
695
|
+
};
|
|
696
|
+
var RequirementStatusInfo = {
|
|
697
|
+
fromStatusesDto: (dto) => Object.entries(dto.statuses).map(([id, status]) => ({
|
|
698
|
+
id: RequirementId(id),
|
|
699
|
+
status
|
|
700
|
+
}))
|
|
701
|
+
};
|
|
702
|
+
|
|
703
|
+
// src/shared/api/frontline/requirements.ts
|
|
704
|
+
async function fetchOfferRequirements(api, offerId) {
|
|
705
|
+
const response = await api.send({
|
|
706
|
+
method: "GET",
|
|
707
|
+
url: `/v1/offers/${offerId}/requirements`,
|
|
708
|
+
attributes: Attributes.protected()
|
|
709
|
+
});
|
|
710
|
+
return Object.fromEntries(
|
|
711
|
+
Object.entries(response.options).map(([optionId, list]) => [
|
|
712
|
+
optionId,
|
|
713
|
+
list.data.map(Requirement.fromDto)
|
|
714
|
+
])
|
|
715
|
+
);
|
|
716
|
+
}
|
|
717
|
+
async function fetchRequirementStatuses(api, offerId) {
|
|
718
|
+
const response = await api.send({
|
|
719
|
+
method: "GET",
|
|
720
|
+
url: `/v1/offers/${offerId}/requirements/statuses`,
|
|
721
|
+
attributes: Attributes.protected()
|
|
722
|
+
});
|
|
723
|
+
return RequirementStatusInfo.fromStatusesDto(response);
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
// src/shared/types/errors.ts
|
|
727
|
+
var NotImplementedError = class extends Error {
|
|
728
|
+
constructor(message = "Not implemented yet") {
|
|
729
|
+
super(message);
|
|
730
|
+
this.name = "NotImplementedError";
|
|
731
|
+
}
|
|
732
|
+
};
|
|
733
|
+
var NotAuthenticatedError = class extends Error {
|
|
734
|
+
constructor(message = "The user is not authenticated. Go through the OAuth flow first!") {
|
|
735
|
+
super(message);
|
|
736
|
+
this.name = "NotAuthenticatedError";
|
|
737
|
+
}
|
|
738
|
+
};
|
|
739
|
+
|
|
306
740
|
// src/shared/types/oauth-session.ts
|
|
307
741
|
var OAuthRefreshToken = (value) => value;
|
|
308
742
|
var OAuthSession = {
|
|
@@ -326,10 +760,13 @@ var CoinListServerImpl = class {
|
|
|
326
760
|
this.baseUrl = _config.baseUrl ?? PUBLIC_API_BASE_URL;
|
|
327
761
|
this.accessTokenExpiryBufferSeconds = _config.accessTokenExpiryBufferSeconds ?? ACCESS_TOKEN_EXPIRY_BUFFER_SECONDS;
|
|
328
762
|
this.strict = _config.strict ?? false;
|
|
329
|
-
this.api = new Api(
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
763
|
+
this.api = new Api(
|
|
764
|
+
{
|
|
765
|
+
baseUrl: this.baseUrl,
|
|
766
|
+
xApiVersion: API_VERSION
|
|
767
|
+
},
|
|
768
|
+
(_refresh) => this.accessToken()
|
|
769
|
+
);
|
|
333
770
|
}
|
|
334
771
|
async completeOAuth(code, codeVerifier) {
|
|
335
772
|
const sessionDto = await this.api.send({
|
|
@@ -407,6 +844,48 @@ var CoinListServerImpl = class {
|
|
|
407
844
|
await this._config.sessionStore.setSession(null);
|
|
408
845
|
}
|
|
409
846
|
}
|
|
847
|
+
async ensureAuthenticated() {
|
|
848
|
+
const token = await this.accessToken();
|
|
849
|
+
if (token === null) {
|
|
850
|
+
throw new NotAuthenticatedError();
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
async fetchAllOffers() {
|
|
854
|
+
await this.ensureAuthenticated();
|
|
855
|
+
return fetchAllOffers(this.api);
|
|
856
|
+
}
|
|
857
|
+
async fetchOffersPage(params) {
|
|
858
|
+
await this.ensureAuthenticated();
|
|
859
|
+
return fetchOffersPage(this.api, params);
|
|
860
|
+
}
|
|
861
|
+
async fetchOfferDetails(id) {
|
|
862
|
+
await this.ensureAuthenticated();
|
|
863
|
+
return fetchOfferDetails(this.api, id);
|
|
864
|
+
}
|
|
865
|
+
async fetchAllParticipations(offerId) {
|
|
866
|
+
await this.ensureAuthenticated();
|
|
867
|
+
return fetchAllParticipations(this.api, offerId);
|
|
868
|
+
}
|
|
869
|
+
async fetchParticipationsPage(params) {
|
|
870
|
+
await this.ensureAuthenticated();
|
|
871
|
+
return fetchParticipationsPage(this.api, params);
|
|
872
|
+
}
|
|
873
|
+
async fetchParticipation(id) {
|
|
874
|
+
await this.ensureAuthenticated();
|
|
875
|
+
return fetchParticipation(this.api, id);
|
|
876
|
+
}
|
|
877
|
+
async createParticipation(params) {
|
|
878
|
+
await this.ensureAuthenticated();
|
|
879
|
+
return createParticipation(this.api, params);
|
|
880
|
+
}
|
|
881
|
+
async fetchOfferRequirements(offerId) {
|
|
882
|
+
await this.ensureAuthenticated();
|
|
883
|
+
return fetchOfferRequirements(this.api, offerId);
|
|
884
|
+
}
|
|
885
|
+
async fetchRequirementStatuses(offerId) {
|
|
886
|
+
await this.ensureAuthenticated();
|
|
887
|
+
return fetchRequirementStatuses(this.api, offerId);
|
|
888
|
+
}
|
|
410
889
|
};
|
|
411
890
|
function createCoinListServer(config) {
|
|
412
891
|
return new CoinListServerImpl(config);
|
|
@@ -422,13 +901,39 @@ var ClientSecret = (value) => value;
|
|
|
422
901
|
// Annotate the CommonJS export names for ESM import in node:
|
|
423
902
|
0 && (module.exports = {
|
|
424
903
|
AuthorizationCode,
|
|
904
|
+
Blockchain,
|
|
425
905
|
ClientId,
|
|
426
906
|
ClientSecret,
|
|
427
907
|
CodeChallenge,
|
|
428
908
|
CodeVerifier,
|
|
909
|
+
CreateParticipationParams,
|
|
910
|
+
Cursor,
|
|
911
|
+
FaqItem,
|
|
912
|
+
Link,
|
|
913
|
+
Milestone,
|
|
914
|
+
NotAuthenticatedError,
|
|
915
|
+
NotImplementedError,
|
|
429
916
|
OAuthRefreshToken,
|
|
430
917
|
OAuthSession,
|
|
918
|
+
Offer,
|
|
919
|
+
OfferDetail,
|
|
920
|
+
OfferId,
|
|
921
|
+
OfferOption,
|
|
922
|
+
OfferOptionId,
|
|
923
|
+
OfferOptionSlug,
|
|
924
|
+
OfferSlug,
|
|
925
|
+
PaginatedResponse,
|
|
926
|
+
PaginationParams,
|
|
927
|
+
Participation,
|
|
928
|
+
ParticipationId,
|
|
929
|
+
ParticipationsPaginationParams,
|
|
431
930
|
RedirectUri,
|
|
432
|
-
|
|
931
|
+
Requirement,
|
|
932
|
+
RequirementId,
|
|
933
|
+
RequirementStatusInfo,
|
|
934
|
+
TermItem,
|
|
935
|
+
WalletAddress,
|
|
936
|
+
createCoinListServer,
|
|
937
|
+
fetchAllPages
|
|
433
938
|
});
|
|
434
939
|
//# sourceMappingURL=index.cjs.map
|