@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.
- package/dist/chunk-CRACFEJ4.js +17 -0
- package/dist/chunk-CRACFEJ4.js.map +1 -0
- package/dist/{chunk-GRVV7NLV.js → chunk-N3WBC2VS.js} +218 -28
- package/dist/chunk-N3WBC2VS.js.map +1 -0
- package/dist/chunk-V6WO67RO.js +311 -0
- package/dist/chunk-V6WO67RO.js.map +1 -0
- package/dist/client/index.cjs +1393 -372
- package/dist/client/index.cjs.map +1 -1
- package/dist/client/index.d.cts +526 -10
- package/dist/client/index.d.ts +526 -10
- package/dist/client/index.js +1464 -88
- package/dist/client/index.js.map +1 -1
- package/dist/requirement-BEO42QOr.d.cts +387 -0
- package/dist/requirement-BEO42QOr.d.ts +387 -0
- package/dist/server/index.cjs +459 -36
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.cts +56 -4
- package/dist/server/index.d.ts +56 -4
- package/dist/server/index.js +69 -37
- package/dist/server/index.js.map +1 -1
- package/dist/shared/index.cjs +375 -0
- package/dist/shared/index.cjs.map +1 -0
- package/dist/shared/index.d.cts +35 -0
- package/dist/shared/index.d.ts +35 -0
- package/dist/{client/core → shared}/index.js +38 -19
- package/dist/shared/index.js.map +1 -0
- package/package.json +7 -22
- package/dist/RequirementItem-BpkJQep8.d.ts +0 -37
- package/dist/RequirementItem-BvwsFu9e.d.cts +0 -37
- 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 +0 -412
- 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/chunk-YJQMJFA7.js +0 -16
- package/dist/chunk-YJQMJFA7.js.map +0 -1
- package/dist/client/components/index.cjs +0 -1107
- package/dist/client/components/index.cjs.map +0 -1
- package/dist/client/components/index.d.cts +0 -121
- package/dist/client/components/index.d.ts +0 -121
- package/dist/client/components/index.js +0 -586
- package/dist/client/components/index.js.map +0 -1
- package/dist/client/core/index.cjs +0 -961
- package/dist/client/core/index.cjs.map +0 -1
- package/dist/client/core/index.d.cts +0 -23
- package/dist/client/core/index.d.ts +0 -23
- package/dist/client/core/index.js.map +0 -1
- package/dist/client/hooks/index.cjs +0 -233
- package/dist/client/hooks/index.cjs.map +0 -1
- package/dist/client/hooks/index.d.cts +0 -33
- package/dist/client/hooks/index.d.ts +0 -33
- package/dist/client/hooks/index.js +0 -19
- package/dist/client/hooks/index.js.map +0 -1
- package/dist/coinlist-client-B_dJkbwB.d.ts +0 -283
- package/dist/coinlist-client-DBKa6j3f.d.cts +0 -283
- 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/requirement-CxbdY8l4.d.cts +0 -202
- package/dist/requirement-fJsQ3f9_.d.ts +0 -202
- 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
|
@@ -20,14 +20,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/server/index.ts
|
|
21
21
|
var server_exports = {};
|
|
22
22
|
__export(server_exports, {
|
|
23
|
-
AuthorizationCode: () => AuthorizationCode,
|
|
24
|
-
ClientId: () => ClientId,
|
|
25
|
-
ClientSecret: () => ClientSecret,
|
|
26
|
-
CodeChallenge: () => CodeChallenge,
|
|
27
|
-
CodeVerifier: () => CodeVerifier,
|
|
28
|
-
OAuthRefreshToken: () => OAuthRefreshToken,
|
|
29
|
-
OAuthSession: () => OAuthSession,
|
|
30
|
-
RedirectUri: () => RedirectUri,
|
|
31
23
|
createCoinListServer: () => createCoinListServer
|
|
32
24
|
});
|
|
33
25
|
module.exports = __toCommonJS(server_exports);
|
|
@@ -175,9 +167,10 @@ var Request = {
|
|
|
175
167
|
concatAttributes
|
|
176
168
|
};
|
|
177
169
|
|
|
178
|
-
// src/shared/api/frontline.ts
|
|
170
|
+
// src/shared/api/frontline/config.ts
|
|
179
171
|
var PUBLIC_API_BASE_URL = "https://api.coinlist.co";
|
|
180
172
|
var HEADER_API_VERSION = "X-API-Version";
|
|
173
|
+
var HEADER_IDEMPOTENCY_KEY = "Idempotency-Key";
|
|
181
174
|
var API_VERSION = "2025-10-17";
|
|
182
175
|
|
|
183
176
|
// src/shared/api/http-client.ts
|
|
@@ -249,6 +242,67 @@ var HttpClient = class {
|
|
|
249
242
|
}
|
|
250
243
|
};
|
|
251
244
|
|
|
245
|
+
// src/shared/api/middleware/attach-session-middleware.ts
|
|
246
|
+
function attachSessionMiddleware(fetchAccessToken) {
|
|
247
|
+
return async (request) => {
|
|
248
|
+
if (!Attributes.isProtected(request.attributes)) {
|
|
249
|
+
return request;
|
|
250
|
+
}
|
|
251
|
+
const accessToken = await fetchAccessToken(false);
|
|
252
|
+
if (accessToken === null) {
|
|
253
|
+
return request;
|
|
254
|
+
}
|
|
255
|
+
return {
|
|
256
|
+
...request,
|
|
257
|
+
headers: {
|
|
258
|
+
...request.headers ?? {},
|
|
259
|
+
Authorization: `Bearer ${accessToken.value}`
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// src/shared/utils.ts
|
|
266
|
+
function getUUIDv4() {
|
|
267
|
+
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
268
|
+
return crypto.randomUUID();
|
|
269
|
+
}
|
|
270
|
+
if (typeof crypto !== "undefined" && typeof crypto.getRandomValues === "function") {
|
|
271
|
+
const bytes = new Uint8Array(16);
|
|
272
|
+
crypto.getRandomValues(bytes);
|
|
273
|
+
bytes[6] = bytes[6] & 15 | 64;
|
|
274
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
275
|
+
const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0"));
|
|
276
|
+
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("")}`;
|
|
277
|
+
}
|
|
278
|
+
return `${Date.now()}-${Math.random().toString(36).slice(2, 12)}`;
|
|
279
|
+
}
|
|
280
|
+
function notBlankStringOrNull(value) {
|
|
281
|
+
if (value?.trim()) {
|
|
282
|
+
return value;
|
|
283
|
+
} else {
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// src/shared/api/middleware/idempotency-key.ts
|
|
289
|
+
var idempotencyKeyMiddleware = async (request) => {
|
|
290
|
+
if (!Attributes.isIdempotent(request.attributes)) {
|
|
291
|
+
return request;
|
|
292
|
+
}
|
|
293
|
+
const existingHeaders = request.headers ?? {};
|
|
294
|
+
if (existingHeaders[HEADER_IDEMPOTENCY_KEY]) {
|
|
295
|
+
return request;
|
|
296
|
+
}
|
|
297
|
+
return {
|
|
298
|
+
...request,
|
|
299
|
+
headers: {
|
|
300
|
+
...existingHeaders,
|
|
301
|
+
[HEADER_IDEMPOTENCY_KEY]: getUUIDv4()
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
};
|
|
305
|
+
|
|
252
306
|
// src/shared/api/middleware/request-retry.ts
|
|
253
307
|
var MAX_ATTEMPTS = 3;
|
|
254
308
|
var INITIAL_DELAY_MS = 300;
|
|
@@ -284,13 +338,44 @@ function defaultDelay(ms) {
|
|
|
284
338
|
}
|
|
285
339
|
var requestRetryMiddleware = createRequestRetryMiddleware();
|
|
286
340
|
|
|
287
|
-
// src/
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
341
|
+
// src/shared/api/middleware/session-renewal.ts
|
|
342
|
+
function renewSessionMiddleware(fetchAccessToken) {
|
|
343
|
+
return async ({ request, response, retry }) => {
|
|
344
|
+
if (response.status !== 401) {
|
|
345
|
+
return response;
|
|
346
|
+
}
|
|
347
|
+
if (!Attributes.isProtected(request.attributes)) {
|
|
348
|
+
return response;
|
|
349
|
+
}
|
|
350
|
+
if (Attributes.wasRenewAttempted(request.attributes)) {
|
|
351
|
+
return response;
|
|
352
|
+
}
|
|
353
|
+
const newToken = await fetchAccessToken(true);
|
|
354
|
+
if (newToken) {
|
|
355
|
+
const nextRequest = Request.concatAttributes(
|
|
356
|
+
request,
|
|
357
|
+
Attributes.renewAttempted(true)
|
|
358
|
+
);
|
|
359
|
+
return retry(nextRequest);
|
|
360
|
+
} else {
|
|
361
|
+
return response;
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// src/shared/api/authenticated-api-client.ts
|
|
367
|
+
var AuthenticatedApiClient = class {
|
|
368
|
+
constructor(config, fetchAccessToken, additionalBeforeRequest = []) {
|
|
369
|
+
this.httpClient = new HttpClient(config, {
|
|
370
|
+
beforeRequest: [
|
|
371
|
+
attachSessionMiddleware(fetchAccessToken),
|
|
372
|
+
...additionalBeforeRequest,
|
|
373
|
+
idempotencyKeyMiddleware
|
|
374
|
+
],
|
|
375
|
+
afterRequest: [
|
|
376
|
+
renewSessionMiddleware(fetchAccessToken),
|
|
377
|
+
requestRetryMiddleware
|
|
378
|
+
]
|
|
294
379
|
});
|
|
295
380
|
}
|
|
296
381
|
async send(request) {
|
|
@@ -303,6 +388,315 @@ var Api = class {
|
|
|
303
388
|
}
|
|
304
389
|
};
|
|
305
390
|
|
|
391
|
+
// src/server/api/api.server.ts
|
|
392
|
+
var Api = class {
|
|
393
|
+
constructor(config, fetchAccessToken) {
|
|
394
|
+
this.client = new AuthenticatedApiClient(config, fetchAccessToken);
|
|
395
|
+
}
|
|
396
|
+
async send(request) {
|
|
397
|
+
return this.client.send(request);
|
|
398
|
+
}
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
// src/shared/api/pagination.ts
|
|
402
|
+
var Cursor = (value) => value;
|
|
403
|
+
async function fetchAllPages(fetchPage, baseParams) {
|
|
404
|
+
const items = [];
|
|
405
|
+
let cursor = null;
|
|
406
|
+
do {
|
|
407
|
+
const params = {
|
|
408
|
+
...baseParams ?? {},
|
|
409
|
+
after: cursor ?? void 0
|
|
410
|
+
};
|
|
411
|
+
const page = await fetchPage(params);
|
|
412
|
+
items.push(...page.data);
|
|
413
|
+
cursor = page.startingAfter;
|
|
414
|
+
} while (cursor);
|
|
415
|
+
return items;
|
|
416
|
+
}
|
|
417
|
+
var PaginatedResponse = {
|
|
418
|
+
fromDto: (dto, itemMapper) => ({
|
|
419
|
+
data: dto.data.map(itemMapper),
|
|
420
|
+
startingAfter: dto.starting_after ? Cursor(dto.starting_after) : null,
|
|
421
|
+
startingBefore: dto.starting_before ? Cursor(dto.starting_before) : null
|
|
422
|
+
})
|
|
423
|
+
};
|
|
424
|
+
var PaginationParams = {
|
|
425
|
+
toQueryParams: (params) => {
|
|
426
|
+
const queryParams = {};
|
|
427
|
+
if (params.after) {
|
|
428
|
+
queryParams.starting_after = params.after;
|
|
429
|
+
}
|
|
430
|
+
if (params.before) {
|
|
431
|
+
queryParams.starting_before = params.before;
|
|
432
|
+
}
|
|
433
|
+
if (params.limit) {
|
|
434
|
+
queryParams.limit = params.limit;
|
|
435
|
+
}
|
|
436
|
+
return queryParams;
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
// src/shared/types/offer.ts
|
|
441
|
+
var OfferId = (value) => value;
|
|
442
|
+
var OfferSlug = (value) => value;
|
|
443
|
+
var Offer = {
|
|
444
|
+
fromDto: (dto) => ({
|
|
445
|
+
id: OfferId(dto.id),
|
|
446
|
+
slug: OfferSlug(dto.slug),
|
|
447
|
+
tagline: notBlankStringOrNull(dto.tagline),
|
|
448
|
+
bannerUrl: notBlankStringOrNull(dto.banner_url),
|
|
449
|
+
logoUrl: notBlankStringOrNull(dto.logo_url),
|
|
450
|
+
startsAt: new Date(dto.starts_at),
|
|
451
|
+
endsAt: new Date(dto.ends_at)
|
|
452
|
+
})
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
// src/shared/types/asset.ts
|
|
456
|
+
var AssetId = (value) => value;
|
|
457
|
+
var AssetCode = (value) => value;
|
|
458
|
+
var Asset = {
|
|
459
|
+
fromDto: (dto) => ({
|
|
460
|
+
id: AssetId(dto.id),
|
|
461
|
+
code: AssetCode(dto.code),
|
|
462
|
+
name: dto.name,
|
|
463
|
+
fractionalDigits: dto.fractional_digits
|
|
464
|
+
})
|
|
465
|
+
};
|
|
466
|
+
|
|
467
|
+
// src/shared/types/offer-detail.ts
|
|
468
|
+
var OfferOptionId = (value) => value;
|
|
469
|
+
var OfferOptionSlug = (value) => value;
|
|
470
|
+
var OfferDetail = {
|
|
471
|
+
fromDto: (dto) => {
|
|
472
|
+
if (!Array.isArray(dto.funding_assets)) {
|
|
473
|
+
throw new Error(`funding_assets must be an array`);
|
|
474
|
+
}
|
|
475
|
+
if (!Array.isArray(dto.options)) {
|
|
476
|
+
throw new Error(`options must be an array`);
|
|
477
|
+
}
|
|
478
|
+
if (!Array.isArray(dto.terms)) {
|
|
479
|
+
throw new Error(`terms must be an array`);
|
|
480
|
+
}
|
|
481
|
+
if (!Array.isArray(dto.links)) {
|
|
482
|
+
throw new Error(`links must be an array`);
|
|
483
|
+
}
|
|
484
|
+
if (!Array.isArray(dto.faqs)) {
|
|
485
|
+
throw new Error(`faqs must be an array`);
|
|
486
|
+
}
|
|
487
|
+
if (!Array.isArray(dto.milestones)) {
|
|
488
|
+
throw new Error(`milestones must be an array`);
|
|
489
|
+
}
|
|
490
|
+
return {
|
|
491
|
+
id: OfferId(dto.id),
|
|
492
|
+
slug: OfferSlug(dto.slug),
|
|
493
|
+
name: dto.name,
|
|
494
|
+
asset: Asset.fromDto(dto.asset),
|
|
495
|
+
fundingAssets: dto.funding_assets.map(Asset.fromDto),
|
|
496
|
+
about: notBlankStringOrNull(dto.about),
|
|
497
|
+
tagline: notBlankStringOrNull(dto.tagline),
|
|
498
|
+
bannerUrl: notBlankStringOrNull(dto.banner_url),
|
|
499
|
+
logoUrl: notBlankStringOrNull(dto.logo_url),
|
|
500
|
+
category: notBlankStringOrNull(dto.category),
|
|
501
|
+
startsAt: new Date(dto.starts_at),
|
|
502
|
+
endsAt: new Date(dto.ends_at),
|
|
503
|
+
faqs: dto.faqs.map(FaqItem.fromDto),
|
|
504
|
+
links: dto.links.map(Link.fromDto),
|
|
505
|
+
milestones: dto.milestones.map(Milestone.fromDto),
|
|
506
|
+
options: dto.options.map(OfferOption.fromDto),
|
|
507
|
+
terms: dto.terms.map(TermItem.fromDto)
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
};
|
|
511
|
+
var OfferOption = {
|
|
512
|
+
fromDto: (dto) => ({
|
|
513
|
+
id: OfferOptionId(dto.id),
|
|
514
|
+
slug: OfferOptionSlug(dto.slug),
|
|
515
|
+
bidIncrement: dto.bid_increment,
|
|
516
|
+
floorPriceUsd: dto.floor_price_usd,
|
|
517
|
+
minimumPurchaseUsd: dto.minimum_purchase_usd,
|
|
518
|
+
priceUsd: dto.price_usd,
|
|
519
|
+
saleAgreementUrl: notBlankStringOrNull(dto.sale_agreement_url),
|
|
520
|
+
totalTokenSupply: dto.total_token_supply
|
|
521
|
+
})
|
|
522
|
+
};
|
|
523
|
+
var FaqItem = {
|
|
524
|
+
fromDto: (dto) => ({
|
|
525
|
+
question: notBlankStringOrNull(dto.question),
|
|
526
|
+
answer: notBlankStringOrNull(dto.answer)
|
|
527
|
+
})
|
|
528
|
+
};
|
|
529
|
+
var Link = {
|
|
530
|
+
fromDto: (dto) => ({
|
|
531
|
+
label: notBlankStringOrNull(dto.label),
|
|
532
|
+
url: notBlankStringOrNull(dto.url)
|
|
533
|
+
})
|
|
534
|
+
};
|
|
535
|
+
var TermItem = {
|
|
536
|
+
fromDto: (dto) => ({
|
|
537
|
+
key: notBlankStringOrNull(dto.key),
|
|
538
|
+
value: notBlankStringOrNull(dto.value)
|
|
539
|
+
})
|
|
540
|
+
};
|
|
541
|
+
var Milestone = {
|
|
542
|
+
fromDto: (dto) => ({
|
|
543
|
+
name: notBlankStringOrNull(dto.name),
|
|
544
|
+
schedule: notBlankStringOrNull(dto.schedule),
|
|
545
|
+
status: dto.status
|
|
546
|
+
})
|
|
547
|
+
};
|
|
548
|
+
|
|
549
|
+
// src/shared/api/frontline/offers.ts
|
|
550
|
+
async function fetchOffers(api) {
|
|
551
|
+
return fetchAllPages((params) => fetchOffersPage(api, params));
|
|
552
|
+
}
|
|
553
|
+
async function fetchOffersPage(api, params) {
|
|
554
|
+
const queryParams = PaginationParams.toQueryParams(params);
|
|
555
|
+
const pageDto = await api.send({
|
|
556
|
+
method: "GET",
|
|
557
|
+
url: "/v1/offers",
|
|
558
|
+
queryParams,
|
|
559
|
+
attributes: Attributes.protected()
|
|
560
|
+
});
|
|
561
|
+
return PaginatedResponse.fromDto(pageDto, Offer.fromDto);
|
|
562
|
+
}
|
|
563
|
+
async function fetchOfferDetails(api, id) {
|
|
564
|
+
const dto = await api.send({
|
|
565
|
+
method: "GET",
|
|
566
|
+
url: `/v1/offers/${id}`,
|
|
567
|
+
attributes: Attributes.protected()
|
|
568
|
+
});
|
|
569
|
+
return OfferDetail.fromDto(dto);
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
// src/shared/types/participation.ts
|
|
573
|
+
var ParticipationId = (value) => value;
|
|
574
|
+
var Blockchain = (value) => value;
|
|
575
|
+
var WalletAddress = (value) => value;
|
|
576
|
+
var ParticipationsPaginationParams = {
|
|
577
|
+
toQueryParams: (params) => {
|
|
578
|
+
const queryParams = PaginationParams.toQueryParams(params);
|
|
579
|
+
if (params.offerId) {
|
|
580
|
+
queryParams["filters[0][field]"] = "offer_id";
|
|
581
|
+
queryParams["filters[0][op]"] = "==";
|
|
582
|
+
queryParams["filters[0][value]"] = params.offerId;
|
|
583
|
+
}
|
|
584
|
+
return queryParams;
|
|
585
|
+
}
|
|
586
|
+
};
|
|
587
|
+
var Participation = {
|
|
588
|
+
/** Maps API DTO shape into the SDK participation domain model. */
|
|
589
|
+
fromDto: (dto) => {
|
|
590
|
+
const walletAddress = notBlankStringOrNull(dto.wallet_address);
|
|
591
|
+
return {
|
|
592
|
+
id: ParticipationId(dto.id),
|
|
593
|
+
offerId: OfferId(dto.offer_id),
|
|
594
|
+
offerOptionId: OfferOptionId(dto.offer_option_id),
|
|
595
|
+
status: dto.status,
|
|
596
|
+
amount: dto.amount,
|
|
597
|
+
displayAmount: dto.amount_string,
|
|
598
|
+
asset: Asset.fromDto(dto.asset),
|
|
599
|
+
chain: Blockchain(dto.chain),
|
|
600
|
+
insertedAt: dto.inserted_at ? new Date(dto.inserted_at) : null,
|
|
601
|
+
updatedAt: dto.updated_at ? new Date(dto.updated_at) : null,
|
|
602
|
+
walletAddress: walletAddress ? WalletAddress(walletAddress) : null
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
};
|
|
606
|
+
var CreateParticipationParams = {
|
|
607
|
+
/** Maps participation creation params into API DTO payload. */
|
|
608
|
+
toDto: (params) => ({
|
|
609
|
+
offer_id: params.offerId,
|
|
610
|
+
offer_option_id: params.offerOptionId,
|
|
611
|
+
chain: params.chain,
|
|
612
|
+
wallet_address: params.walletAddress,
|
|
613
|
+
amount: params.amount,
|
|
614
|
+
asset_id: params.assetId,
|
|
615
|
+
approval_transaction_hash: params.approvalTransactionHash
|
|
616
|
+
})
|
|
617
|
+
};
|
|
618
|
+
|
|
619
|
+
// src/shared/api/frontline/participations.ts
|
|
620
|
+
async function fetchParticipations(api, offerId) {
|
|
621
|
+
return fetchAllPages(
|
|
622
|
+
(params) => fetchParticipationsPage(api, params),
|
|
623
|
+
{ offerId }
|
|
624
|
+
);
|
|
625
|
+
}
|
|
626
|
+
async function fetchParticipationsPage(api, params) {
|
|
627
|
+
const pageDto = await api.send({
|
|
628
|
+
method: "GET",
|
|
629
|
+
url: "/v1/participations",
|
|
630
|
+
queryParams: ParticipationsPaginationParams.toQueryParams(params),
|
|
631
|
+
attributes: Attributes.protected()
|
|
632
|
+
});
|
|
633
|
+
return PaginatedResponse.fromDto(pageDto, Participation.fromDto);
|
|
634
|
+
}
|
|
635
|
+
async function fetchParticipation(api, id) {
|
|
636
|
+
const dto = await api.send({
|
|
637
|
+
method: "GET",
|
|
638
|
+
url: `/v1/participations/${id}`,
|
|
639
|
+
attributes: Attributes.protected()
|
|
640
|
+
});
|
|
641
|
+
return Participation.fromDto(dto);
|
|
642
|
+
}
|
|
643
|
+
async function createParticipation(api, params) {
|
|
644
|
+
const dto = await api.send({
|
|
645
|
+
method: "POST",
|
|
646
|
+
url: "/v1/participations",
|
|
647
|
+
body: CreateParticipationParams.toDto(params),
|
|
648
|
+
attributes: Attributes.protected()
|
|
649
|
+
});
|
|
650
|
+
return Participation.fromDto(dto);
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
// src/shared/types/requirement.ts
|
|
654
|
+
var RequirementId = (value) => value;
|
|
655
|
+
var Requirement = {
|
|
656
|
+
fromDto: (dto) => ({
|
|
657
|
+
id: RequirementId(dto.id),
|
|
658
|
+
type: dto.type,
|
|
659
|
+
details: dto.details
|
|
660
|
+
})
|
|
661
|
+
};
|
|
662
|
+
var RequirementStatusInfo = {
|
|
663
|
+
fromStatusesDto: (dto) => Object.entries(dto.statuses).map(([id, status]) => ({
|
|
664
|
+
id: RequirementId(id),
|
|
665
|
+
status
|
|
666
|
+
}))
|
|
667
|
+
};
|
|
668
|
+
|
|
669
|
+
// src/shared/api/frontline/requirements.ts
|
|
670
|
+
async function fetchOfferRequirements(api, offerId) {
|
|
671
|
+
const response = await api.send({
|
|
672
|
+
method: "GET",
|
|
673
|
+
url: `/v1/offers/${offerId}/requirements`,
|
|
674
|
+
attributes: Attributes.protected()
|
|
675
|
+
});
|
|
676
|
+
return Object.fromEntries(
|
|
677
|
+
Object.entries(response.options).map(([optionId, list]) => [
|
|
678
|
+
optionId,
|
|
679
|
+
list.data.map(Requirement.fromDto)
|
|
680
|
+
])
|
|
681
|
+
);
|
|
682
|
+
}
|
|
683
|
+
async function fetchRequirementStatuses(api, offerId) {
|
|
684
|
+
const response = await api.send({
|
|
685
|
+
method: "GET",
|
|
686
|
+
url: `/v1/offers/${offerId}/requirements/statuses`,
|
|
687
|
+
attributes: Attributes.protected()
|
|
688
|
+
});
|
|
689
|
+
return RequirementStatusInfo.fromStatusesDto(response);
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
// src/shared/types/errors.ts
|
|
693
|
+
var NotAuthenticatedError = class extends Error {
|
|
694
|
+
constructor(message = "The user is not authenticated. Go through the OAuth flow first!") {
|
|
695
|
+
super(message);
|
|
696
|
+
this.name = "NotAuthenticatedError";
|
|
697
|
+
}
|
|
698
|
+
};
|
|
699
|
+
|
|
306
700
|
// src/shared/types/oauth-session.ts
|
|
307
701
|
var OAuthRefreshToken = (value) => value;
|
|
308
702
|
var OAuthSession = {
|
|
@@ -326,10 +720,13 @@ var CoinListServerImpl = class {
|
|
|
326
720
|
this.baseUrl = _config.baseUrl ?? PUBLIC_API_BASE_URL;
|
|
327
721
|
this.accessTokenExpiryBufferSeconds = _config.accessTokenExpiryBufferSeconds ?? ACCESS_TOKEN_EXPIRY_BUFFER_SECONDS;
|
|
328
722
|
this.strict = _config.strict ?? false;
|
|
329
|
-
this.api = new Api(
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
723
|
+
this.api = new Api(
|
|
724
|
+
{
|
|
725
|
+
baseUrl: this.baseUrl,
|
|
726
|
+
xApiVersion: API_VERSION
|
|
727
|
+
},
|
|
728
|
+
(_refresh) => this.accessToken()
|
|
729
|
+
);
|
|
333
730
|
}
|
|
334
731
|
async completeOAuth(code, codeVerifier) {
|
|
335
732
|
const sessionDto = await this.api.send({
|
|
@@ -407,28 +804,54 @@ var CoinListServerImpl = class {
|
|
|
407
804
|
await this._config.sessionStore.setSession(null);
|
|
408
805
|
}
|
|
409
806
|
}
|
|
807
|
+
async ensureAuthenticated() {
|
|
808
|
+
const token = await this.accessToken();
|
|
809
|
+
if (token === null) {
|
|
810
|
+
throw new NotAuthenticatedError();
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
async fetchOffers() {
|
|
814
|
+
await this.ensureAuthenticated();
|
|
815
|
+
return fetchOffers(this.api);
|
|
816
|
+
}
|
|
817
|
+
async fetchOffersPage(params) {
|
|
818
|
+
await this.ensureAuthenticated();
|
|
819
|
+
return fetchOffersPage(this.api, params);
|
|
820
|
+
}
|
|
821
|
+
async fetchOfferDetails(id) {
|
|
822
|
+
await this.ensureAuthenticated();
|
|
823
|
+
return fetchOfferDetails(this.api, id);
|
|
824
|
+
}
|
|
825
|
+
async fetchParticipations(offerId) {
|
|
826
|
+
await this.ensureAuthenticated();
|
|
827
|
+
return fetchParticipations(this.api, offerId);
|
|
828
|
+
}
|
|
829
|
+
async fetchParticipationsPage(params) {
|
|
830
|
+
await this.ensureAuthenticated();
|
|
831
|
+
return fetchParticipationsPage(this.api, params);
|
|
832
|
+
}
|
|
833
|
+
async fetchParticipation(id) {
|
|
834
|
+
await this.ensureAuthenticated();
|
|
835
|
+
return fetchParticipation(this.api, id);
|
|
836
|
+
}
|
|
837
|
+
async createParticipation(params) {
|
|
838
|
+
await this.ensureAuthenticated();
|
|
839
|
+
return createParticipation(this.api, params);
|
|
840
|
+
}
|
|
841
|
+
async fetchOfferRequirements(offerId) {
|
|
842
|
+
await this.ensureAuthenticated();
|
|
843
|
+
return fetchOfferRequirements(this.api, offerId);
|
|
844
|
+
}
|
|
845
|
+
async fetchRequirementStatuses(offerId) {
|
|
846
|
+
await this.ensureAuthenticated();
|
|
847
|
+
return fetchRequirementStatuses(this.api, offerId);
|
|
848
|
+
}
|
|
410
849
|
};
|
|
411
850
|
function createCoinListServer(config) {
|
|
412
851
|
return new CoinListServerImpl(config);
|
|
413
852
|
}
|
|
414
|
-
|
|
415
|
-
// src/shared/types/oauth.ts
|
|
416
|
-
var AuthorizationCode = (value) => value;
|
|
417
|
-
var CodeVerifier = (value) => value;
|
|
418
|
-
var CodeChallenge = (value) => value;
|
|
419
|
-
var RedirectUri = (value) => value;
|
|
420
|
-
var ClientId = (value) => value;
|
|
421
|
-
var ClientSecret = (value) => value;
|
|
422
853
|
// Annotate the CommonJS export names for ESM import in node:
|
|
423
854
|
0 && (module.exports = {
|
|
424
|
-
AuthorizationCode,
|
|
425
|
-
ClientId,
|
|
426
|
-
ClientSecret,
|
|
427
|
-
CodeChallenge,
|
|
428
|
-
CodeVerifier,
|
|
429
|
-
OAuthRefreshToken,
|
|
430
|
-
OAuthSession,
|
|
431
|
-
RedirectUri,
|
|
432
855
|
createCoinListServer
|
|
433
856
|
});
|
|
434
857
|
//# sourceMappingURL=index.cjs.map
|