@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
|
@@ -1,961 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/client/core/index.ts
|
|
21
|
-
var core_exports = {};
|
|
22
|
-
__export(core_exports, {
|
|
23
|
-
AuthorizationCode: () => AuthorizationCode,
|
|
24
|
-
Blockchain: () => Blockchain,
|
|
25
|
-
ClientId: () => ClientId,
|
|
26
|
-
ClientSecret: () => ClientSecret,
|
|
27
|
-
CodeChallenge: () => CodeChallenge,
|
|
28
|
-
CodeVerifier: () => CodeVerifier,
|
|
29
|
-
CreateParticipationParams: () => CreateParticipationParams,
|
|
30
|
-
Cursor: () => Cursor,
|
|
31
|
-
FaqItem: () => FaqItem,
|
|
32
|
-
Link: () => Link,
|
|
33
|
-
Milestone: () => Milestone,
|
|
34
|
-
OAuthRefreshToken: () => OAuthRefreshToken,
|
|
35
|
-
OAuthSession: () => OAuthSession,
|
|
36
|
-
Offer: () => Offer,
|
|
37
|
-
OfferDetail: () => OfferDetail,
|
|
38
|
-
OfferId: () => OfferId,
|
|
39
|
-
OfferOption: () => OfferOption,
|
|
40
|
-
OfferOptionId: () => OfferOptionId,
|
|
41
|
-
OfferOptionSlug: () => OfferOptionSlug,
|
|
42
|
-
OfferSlug: () => OfferSlug,
|
|
43
|
-
PaginatedResponse: () => PaginatedResponse,
|
|
44
|
-
PaginationParams: () => PaginationParams,
|
|
45
|
-
Participation: () => Participation,
|
|
46
|
-
ParticipationId: () => ParticipationId,
|
|
47
|
-
ParticipationsPaginationParams: () => ParticipationsPaginationParams,
|
|
48
|
-
RedirectUri: () => RedirectUri,
|
|
49
|
-
TermItem: () => TermItem,
|
|
50
|
-
User: () => User,
|
|
51
|
-
UserEmail: () => UserEmail,
|
|
52
|
-
UserId: () => UserId,
|
|
53
|
-
WalletAddress: () => WalletAddress,
|
|
54
|
-
createCoinListClient: () => createCoinListClient,
|
|
55
|
-
fetchAllPages: () => fetchAllPages
|
|
56
|
-
});
|
|
57
|
-
module.exports = __toCommonJS(core_exports);
|
|
58
|
-
|
|
59
|
-
// src/shared/api/http-attributes.ts
|
|
60
|
-
var empty = {};
|
|
61
|
-
var concat = (left, right) => ({
|
|
62
|
-
...left,
|
|
63
|
-
...right
|
|
64
|
-
});
|
|
65
|
-
var concatAll = (...items) => {
|
|
66
|
-
let result = empty;
|
|
67
|
-
for (const item of items) {
|
|
68
|
-
result = concat(result, item);
|
|
69
|
-
}
|
|
70
|
-
return result;
|
|
71
|
-
};
|
|
72
|
-
var protectedRequest = () => ({ protected: true });
|
|
73
|
-
var userAgent = () => ({ userAgent: true });
|
|
74
|
-
var idempotencyKey = () => ({
|
|
75
|
-
idempotencyKey: true
|
|
76
|
-
});
|
|
77
|
-
var retryAttempt = (attempt) => ({
|
|
78
|
-
retryAttempt: attempt
|
|
79
|
-
});
|
|
80
|
-
var renewAttempted = (value) => ({
|
|
81
|
-
renewAttempted: value
|
|
82
|
-
});
|
|
83
|
-
var isProtected = (attrs) => attrs?.protected === true;
|
|
84
|
-
var needUserAgent = (attrs) => attrs?.userAgent === true;
|
|
85
|
-
var isIdempotent = (attrs) => attrs?.idempotencyKey === true;
|
|
86
|
-
var getRetryAttempt = (attrs) => attrs?.retryAttempt ?? 0;
|
|
87
|
-
var wasRenewAttempted = (attrs) => attrs?.renewAttempted === true;
|
|
88
|
-
var Attributes = {
|
|
89
|
-
empty,
|
|
90
|
-
concat,
|
|
91
|
-
concatAll,
|
|
92
|
-
protected: protectedRequest,
|
|
93
|
-
isProtected,
|
|
94
|
-
userAgent,
|
|
95
|
-
needUserAgent,
|
|
96
|
-
idempotencyKey,
|
|
97
|
-
isIdempotent,
|
|
98
|
-
retryAttempt,
|
|
99
|
-
getRetryAttempt,
|
|
100
|
-
renewAttempted,
|
|
101
|
-
wasRenewAttempted
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
// src/client/core/api/middleware/attach-session-middleware.ts
|
|
105
|
-
function attachSessionMiddleware(fetchAccessToken) {
|
|
106
|
-
return async (request) => {
|
|
107
|
-
if (!Attributes.isProtected(request.attributes)) {
|
|
108
|
-
return request;
|
|
109
|
-
}
|
|
110
|
-
const accessToken = await fetchAccessToken(false);
|
|
111
|
-
if (accessToken === null) {
|
|
112
|
-
return request;
|
|
113
|
-
}
|
|
114
|
-
return {
|
|
115
|
-
...request,
|
|
116
|
-
headers: {
|
|
117
|
-
...request.headers ?? {},
|
|
118
|
-
Authorization: `Bearer ${accessToken.value}`
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// src/shared/api/http.ts
|
|
125
|
-
var HttpError = class extends Error {
|
|
126
|
-
constructor(response) {
|
|
127
|
-
super(`Request failed with ${response.status} status`);
|
|
128
|
-
this.name = "HttpError";
|
|
129
|
-
this.response = response;
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
async function makeRequest(request) {
|
|
133
|
-
const headers = {
|
|
134
|
-
Accept: "application/json",
|
|
135
|
-
...request.method === "POST" && request.body !== void 0 ? { "Content-Type": "application/json" } : {},
|
|
136
|
-
...request.headers ?? {}
|
|
137
|
-
};
|
|
138
|
-
const init = {
|
|
139
|
-
method: request.method,
|
|
140
|
-
headers,
|
|
141
|
-
...request.redirect !== void 0 ? { redirect: request.redirect } : {}
|
|
142
|
-
};
|
|
143
|
-
if (request.method === "POST" && request.body !== void 0) {
|
|
144
|
-
init.body = JSON.stringify(request.body);
|
|
145
|
-
}
|
|
146
|
-
const response = await fetch(
|
|
147
|
-
buildUrlWithQueryParams(request.url, request.queryParams),
|
|
148
|
-
init
|
|
149
|
-
);
|
|
150
|
-
const responseHeaders = headersToRecord(response.headers);
|
|
151
|
-
if (response.status === 204 || response.status === 205) {
|
|
152
|
-
return {
|
|
153
|
-
status: response.status,
|
|
154
|
-
body: null,
|
|
155
|
-
headers: responseHeaders
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
if (response.status >= 300 && response.status < 400) {
|
|
159
|
-
await response.text();
|
|
160
|
-
return {
|
|
161
|
-
status: response.status,
|
|
162
|
-
body: null,
|
|
163
|
-
headers: responseHeaders
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
const text = await response.text();
|
|
167
|
-
const body = text ? JSON.parse(text) : null;
|
|
168
|
-
return {
|
|
169
|
-
status: response.status,
|
|
170
|
-
body,
|
|
171
|
-
headers: responseHeaders
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
function buildUrlWithQueryParams(url, queryParams) {
|
|
175
|
-
if (!queryParams) {
|
|
176
|
-
return url;
|
|
177
|
-
}
|
|
178
|
-
const searchParams = new URLSearchParams();
|
|
179
|
-
for (const [key, value] of Object.entries(queryParams)) {
|
|
180
|
-
if (value === void 0 || value === null) {
|
|
181
|
-
continue;
|
|
182
|
-
}
|
|
183
|
-
if (Array.isArray(value)) {
|
|
184
|
-
for (const item of value) {
|
|
185
|
-
if (item === void 0 || item === null) {
|
|
186
|
-
continue;
|
|
187
|
-
}
|
|
188
|
-
searchParams.append(key, String(item));
|
|
189
|
-
}
|
|
190
|
-
continue;
|
|
191
|
-
}
|
|
192
|
-
searchParams.append(key, String(value));
|
|
193
|
-
}
|
|
194
|
-
const queryString = searchParams.toString();
|
|
195
|
-
if (!queryString) {
|
|
196
|
-
return url;
|
|
197
|
-
}
|
|
198
|
-
return url.includes("?") ? `${url}&${queryString}` : `${url}?${queryString}`;
|
|
199
|
-
}
|
|
200
|
-
function headersToRecord(headers) {
|
|
201
|
-
const record = {};
|
|
202
|
-
headers.forEach((value, key) => {
|
|
203
|
-
record[key.toLowerCase()] = value;
|
|
204
|
-
});
|
|
205
|
-
return record;
|
|
206
|
-
}
|
|
207
|
-
function concatAttributes(request, attrs) {
|
|
208
|
-
const nextAttributes = Attributes.concat(
|
|
209
|
-
request.attributes ?? Attributes.empty,
|
|
210
|
-
attrs
|
|
211
|
-
);
|
|
212
|
-
const nextRequest = {
|
|
213
|
-
...request,
|
|
214
|
-
attributes: nextAttributes
|
|
215
|
-
};
|
|
216
|
-
return nextRequest;
|
|
217
|
-
}
|
|
218
|
-
var Request = {
|
|
219
|
-
concatAttributes
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
// src/client/core/api/middleware/session-renewal.ts
|
|
223
|
-
function renewSessionMiddleware(fetchAccessToken) {
|
|
224
|
-
return async ({ request, response, retry }) => {
|
|
225
|
-
if (response.status !== 401) {
|
|
226
|
-
return response;
|
|
227
|
-
}
|
|
228
|
-
if (!Attributes.isProtected(request.attributes)) {
|
|
229
|
-
return response;
|
|
230
|
-
}
|
|
231
|
-
if (Attributes.wasRenewAttempted(request.attributes)) {
|
|
232
|
-
return response;
|
|
233
|
-
}
|
|
234
|
-
const newToken = await fetchAccessToken(true);
|
|
235
|
-
if (newToken) {
|
|
236
|
-
const nextRequest = Request.concatAttributes(
|
|
237
|
-
request,
|
|
238
|
-
Attributes.renewAttempted(true)
|
|
239
|
-
);
|
|
240
|
-
return retry(nextRequest);
|
|
241
|
-
} else {
|
|
242
|
-
return response;
|
|
243
|
-
}
|
|
244
|
-
};
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
// src/shared/utils.ts
|
|
248
|
-
async function sha256(data) {
|
|
249
|
-
const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
|
|
250
|
-
const buffer = bytes.buffer.slice(
|
|
251
|
-
bytes.byteOffset,
|
|
252
|
-
bytes.byteOffset + bytes.byteLength
|
|
253
|
-
);
|
|
254
|
-
return crypto.subtle.digest("SHA-256", buffer);
|
|
255
|
-
}
|
|
256
|
-
function arrayBufferToBase64Url(buffer, padding = true) {
|
|
257
|
-
const bytes = new Uint8Array(buffer);
|
|
258
|
-
let binary = "";
|
|
259
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
260
|
-
binary += String.fromCharCode(bytes[i]);
|
|
261
|
-
}
|
|
262
|
-
let base64 = btoa(binary);
|
|
263
|
-
base64 = base64.replace(/\+/g, "-").replace(/\//g, "_");
|
|
264
|
-
if (!padding) {
|
|
265
|
-
base64 = base64.replace(/=+$/, "");
|
|
266
|
-
}
|
|
267
|
-
return base64;
|
|
268
|
-
}
|
|
269
|
-
function generateSecureRandomBase64Url(byteLength) {
|
|
270
|
-
const bytes = new Uint8Array(byteLength);
|
|
271
|
-
crypto.getRandomValues(bytes);
|
|
272
|
-
const buffer = bytes.buffer;
|
|
273
|
-
return arrayBufferToBase64Url(buffer, false);
|
|
274
|
-
}
|
|
275
|
-
function getUUIDv4() {
|
|
276
|
-
if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
|
|
277
|
-
return crypto.randomUUID();
|
|
278
|
-
}
|
|
279
|
-
if (typeof crypto !== "undefined" && typeof crypto.getRandomValues === "function") {
|
|
280
|
-
const bytes = new Uint8Array(16);
|
|
281
|
-
crypto.getRandomValues(bytes);
|
|
282
|
-
bytes[6] = bytes[6] & 15 | 64;
|
|
283
|
-
bytes[8] = bytes[8] & 63 | 128;
|
|
284
|
-
const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0"));
|
|
285
|
-
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("")}`;
|
|
286
|
-
}
|
|
287
|
-
return `${Date.now()}-${Math.random().toString(36).slice(2, 12)}`;
|
|
288
|
-
}
|
|
289
|
-
function notBlankStringOrNull(value) {
|
|
290
|
-
if (value?.trim()) {
|
|
291
|
-
return value;
|
|
292
|
-
} else {
|
|
293
|
-
return null;
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
// src/client/core/api/middleware/device-id.ts
|
|
298
|
-
var DEVICE_ID_KEY = "coinlist.device_id";
|
|
299
|
-
function getDeviceId() {
|
|
300
|
-
let deviceId = localStorage.getItem(DEVICE_ID_KEY);
|
|
301
|
-
if (!deviceId) {
|
|
302
|
-
deviceId = getUUIDv4();
|
|
303
|
-
localStorage.setItem(DEVICE_ID_KEY, deviceId);
|
|
304
|
-
}
|
|
305
|
-
return deviceId;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
// src/shared/api/frontline.ts
|
|
309
|
-
var PUBLIC_API_BASE_URL = "https://api.coinlist.co";
|
|
310
|
-
var HEADER_API_VERSION = "X-API-Version";
|
|
311
|
-
var HEADER_USER_AGENT = "User-Agent";
|
|
312
|
-
var HEADER_IDEMPOTENCY_KEY = "Idempotency-Key";
|
|
313
|
-
var API_VERSION = "2025-10-17";
|
|
314
|
-
var COINLIST_OAUTH_PAGE_URL = "https://coinlist.co/oauth/authorize";
|
|
315
|
-
|
|
316
|
-
// src/client/core/api/middleware/user-agent.ts
|
|
317
|
-
var userAgentMiddleware = async (request) => {
|
|
318
|
-
if (!Attributes.needUserAgent(request.attributes)) {
|
|
319
|
-
return request;
|
|
320
|
-
}
|
|
321
|
-
const userAgent2 = generateUserAgent();
|
|
322
|
-
return {
|
|
323
|
-
...request,
|
|
324
|
-
headers: {
|
|
325
|
-
...request.headers ?? {},
|
|
326
|
-
[HEADER_USER_AGENT]: userAgent2
|
|
327
|
-
}
|
|
328
|
-
};
|
|
329
|
-
};
|
|
330
|
-
function generateUserAgent() {
|
|
331
|
-
const appInfo = `CoinList/1.0`;
|
|
332
|
-
const deviceInfo = "Web Browser";
|
|
333
|
-
const devicePlatform = "DevicePlatform web";
|
|
334
|
-
const deviceAppId = "DeviceAppID co.coinlist.sdk";
|
|
335
|
-
const deviceId = getDeviceId();
|
|
336
|
-
const finalDeviceId = `DeviceID ${deviceId}`;
|
|
337
|
-
return `${appInfo} (${deviceInfo}; ${devicePlatform}; ${deviceAppId}; ${finalDeviceId})`;
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
// src/shared/api/http-client.ts
|
|
341
|
-
var HttpClient = class {
|
|
342
|
-
constructor(config, middleware = {}) {
|
|
343
|
-
this.config = config;
|
|
344
|
-
this.middleware = middleware;
|
|
345
|
-
}
|
|
346
|
-
async send(request) {
|
|
347
|
-
return this.runRequestWithAfterMiddleware(request);
|
|
348
|
-
}
|
|
349
|
-
/**
|
|
350
|
-
* Runs beforeRequest, executeRequest, then the full afterRequest middleware
|
|
351
|
-
* chain. Used by send() and by the retry() callback so that when a
|
|
352
|
-
* middleware calls retry(), the retried response also goes through all
|
|
353
|
-
* afterRequest middleware (e.g. session renewal, retry). Middleware
|
|
354
|
-
* must use request.attributes.retryAttempt (or similar) to avoid infinite
|
|
355
|
-
* recursion when they trigger retries.
|
|
356
|
-
*/
|
|
357
|
-
async runRequestWithAfterMiddleware(request) {
|
|
358
|
-
const preparedRequest = await this.runBeforeRequestMiddleware(
|
|
359
|
-
this.withClientDefaults(request)
|
|
360
|
-
);
|
|
361
|
-
let response = await this.executeRequest(preparedRequest);
|
|
362
|
-
for (const middleware of this.middleware.afterRequest ?? []) {
|
|
363
|
-
response = await middleware({
|
|
364
|
-
request: preparedRequest,
|
|
365
|
-
response,
|
|
366
|
-
retry: (nextRequest = preparedRequest) => this.runRequestWithAfterMiddleware(nextRequest)
|
|
367
|
-
});
|
|
368
|
-
}
|
|
369
|
-
return response;
|
|
370
|
-
}
|
|
371
|
-
withClientDefaults(request) {
|
|
372
|
-
const url = this.resolveUrl(request.url);
|
|
373
|
-
const headers = {
|
|
374
|
-
...request.headers ?? {},
|
|
375
|
-
[HEADER_API_VERSION]: this.config.xApiVersion
|
|
376
|
-
};
|
|
377
|
-
return {
|
|
378
|
-
...request,
|
|
379
|
-
url,
|
|
380
|
-
headers
|
|
381
|
-
};
|
|
382
|
-
}
|
|
383
|
-
/**
|
|
384
|
-
* Resolves a request URL against the client's baseUrl.
|
|
385
|
-
*
|
|
386
|
-
* @internal Public only for testing. Do not use in application code; use
|
|
387
|
-
* {@link HttpClient.send} with a path and the client will resolve the URL.
|
|
388
|
-
*/
|
|
389
|
-
resolveUrl(url) {
|
|
390
|
-
if (url.startsWith("http://") || url.startsWith("https://")) {
|
|
391
|
-
return url;
|
|
392
|
-
}
|
|
393
|
-
const base = this.config.baseUrl.replace(/\/$/, "");
|
|
394
|
-
const path = url.startsWith("/") ? url : `/${url}`;
|
|
395
|
-
return base + path;
|
|
396
|
-
}
|
|
397
|
-
async runBeforeRequestMiddleware(initialRequest) {
|
|
398
|
-
let request = initialRequest;
|
|
399
|
-
for (const middleware of this.middleware.beforeRequest ?? []) {
|
|
400
|
-
request = await middleware(request);
|
|
401
|
-
}
|
|
402
|
-
return request;
|
|
403
|
-
}
|
|
404
|
-
executeRequest(request) {
|
|
405
|
-
return makeRequest(request);
|
|
406
|
-
}
|
|
407
|
-
};
|
|
408
|
-
|
|
409
|
-
// src/shared/api/middleware/idempotency-key.ts
|
|
410
|
-
var idempotencyKeyMiddleware = async (request) => {
|
|
411
|
-
if (!Attributes.isIdempotent(request.attributes)) {
|
|
412
|
-
return request;
|
|
413
|
-
}
|
|
414
|
-
const existingHeaders = request.headers ?? {};
|
|
415
|
-
if (existingHeaders[HEADER_IDEMPOTENCY_KEY]) {
|
|
416
|
-
return request;
|
|
417
|
-
}
|
|
418
|
-
return {
|
|
419
|
-
...request,
|
|
420
|
-
headers: {
|
|
421
|
-
...existingHeaders,
|
|
422
|
-
[HEADER_IDEMPOTENCY_KEY]: getUUIDv4()
|
|
423
|
-
}
|
|
424
|
-
};
|
|
425
|
-
};
|
|
426
|
-
|
|
427
|
-
// src/shared/api/middleware/request-retry.ts
|
|
428
|
-
var MAX_ATTEMPTS = 3;
|
|
429
|
-
var INITIAL_DELAY_MS = 300;
|
|
430
|
-
var MAX_DELAY_MS = 2e3;
|
|
431
|
-
var RETRYABLE_4XX = /* @__PURE__ */ new Set([408, 409, 429]);
|
|
432
|
-
function isRetryableStatus(status) {
|
|
433
|
-
return status >= 500 && status < 600 || RETRYABLE_4XX.has(status);
|
|
434
|
-
}
|
|
435
|
-
function getRetryDelayMs(attempt) {
|
|
436
|
-
return Math.min(INITIAL_DELAY_MS * 2 ** (attempt - 1), MAX_DELAY_MS);
|
|
437
|
-
}
|
|
438
|
-
function createRequestRetryMiddleware(options = {}) {
|
|
439
|
-
const delayFn = options.delayFn ?? defaultDelay;
|
|
440
|
-
return async ({ request, response, retry }) => {
|
|
441
|
-
if (!isRetryableStatus(response.status)) {
|
|
442
|
-
return response;
|
|
443
|
-
}
|
|
444
|
-
const currentAttempt = Attributes.getRetryAttempt(request.attributes);
|
|
445
|
-
if (currentAttempt >= MAX_ATTEMPTS - 1) {
|
|
446
|
-
return response;
|
|
447
|
-
}
|
|
448
|
-
const nextAttempt = currentAttempt + 1;
|
|
449
|
-
await delayFn(getRetryDelayMs(nextAttempt));
|
|
450
|
-
const nextRequest = Request.concatAttributes(
|
|
451
|
-
request,
|
|
452
|
-
Attributes.retryAttempt(nextAttempt)
|
|
453
|
-
);
|
|
454
|
-
return retry(nextRequest);
|
|
455
|
-
};
|
|
456
|
-
}
|
|
457
|
-
function defaultDelay(ms) {
|
|
458
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
459
|
-
}
|
|
460
|
-
var requestRetryMiddleware = createRequestRetryMiddleware();
|
|
461
|
-
|
|
462
|
-
// src/client/core/api/api-client.ts
|
|
463
|
-
var ApiClient = class {
|
|
464
|
-
constructor(config, fetchAccessToken) {
|
|
465
|
-
this.config = config;
|
|
466
|
-
this.fetchAccessToken = fetchAccessToken;
|
|
467
|
-
this.httpClient = new HttpClient(this.config, {
|
|
468
|
-
beforeRequest: [
|
|
469
|
-
attachSessionMiddleware(this.fetchAccessToken),
|
|
470
|
-
userAgentMiddleware,
|
|
471
|
-
idempotencyKeyMiddleware
|
|
472
|
-
],
|
|
473
|
-
afterRequest: [
|
|
474
|
-
renewSessionMiddleware(this.fetchAccessToken),
|
|
475
|
-
requestRetryMiddleware
|
|
476
|
-
]
|
|
477
|
-
});
|
|
478
|
-
}
|
|
479
|
-
async send(request) {
|
|
480
|
-
const response = await this.httpClient.send(request);
|
|
481
|
-
if (response.status >= 200 && response.status < 300) {
|
|
482
|
-
return response.body;
|
|
483
|
-
} else {
|
|
484
|
-
throw new HttpError(response);
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
};
|
|
488
|
-
|
|
489
|
-
// src/shared/api/pagination.ts
|
|
490
|
-
var Cursor = (value) => value;
|
|
491
|
-
async function fetchAllPages(fetchPage, baseParams) {
|
|
492
|
-
const items = [];
|
|
493
|
-
let cursor = null;
|
|
494
|
-
do {
|
|
495
|
-
const params = {
|
|
496
|
-
...baseParams ?? {},
|
|
497
|
-
after: cursor ?? void 0
|
|
498
|
-
};
|
|
499
|
-
const page = await fetchPage(params);
|
|
500
|
-
items.push(...page.data);
|
|
501
|
-
cursor = page.startingAfter;
|
|
502
|
-
} while (cursor);
|
|
503
|
-
return items;
|
|
504
|
-
}
|
|
505
|
-
var PaginatedResponse = {
|
|
506
|
-
fromDto: (dto, itemMapper) => ({
|
|
507
|
-
data: dto.data.map(itemMapper),
|
|
508
|
-
startingAfter: dto.starting_after ? Cursor(dto.starting_after) : null,
|
|
509
|
-
startingBefore: dto.starting_before ? Cursor(dto.starting_before) : null
|
|
510
|
-
})
|
|
511
|
-
};
|
|
512
|
-
var PaginationParams = {
|
|
513
|
-
toQueryParams: (params) => {
|
|
514
|
-
const queryParams = {};
|
|
515
|
-
if (params.after) {
|
|
516
|
-
queryParams.starting_after = params.after;
|
|
517
|
-
}
|
|
518
|
-
if (params.before) {
|
|
519
|
-
queryParams.starting_before = params.before;
|
|
520
|
-
}
|
|
521
|
-
if (params.limit) {
|
|
522
|
-
queryParams.limit = params.limit;
|
|
523
|
-
}
|
|
524
|
-
return queryParams;
|
|
525
|
-
}
|
|
526
|
-
};
|
|
527
|
-
|
|
528
|
-
// src/shared/types/errors.ts
|
|
529
|
-
var NotAuthenticatedError = class extends Error {
|
|
530
|
-
constructor(message = "The user is not authenticated. Go through the OAuth flow first!") {
|
|
531
|
-
super(message);
|
|
532
|
-
this.name = "NotAuthenticatedError";
|
|
533
|
-
}
|
|
534
|
-
};
|
|
535
|
-
|
|
536
|
-
// src/shared/types/oauth.ts
|
|
537
|
-
var AuthorizationCode = (value) => value;
|
|
538
|
-
var CodeVerifier = (value) => value;
|
|
539
|
-
var CodeChallenge = (value) => value;
|
|
540
|
-
var RedirectUri = (value) => value;
|
|
541
|
-
var ClientId = (value) => value;
|
|
542
|
-
var ClientSecret = (value) => value;
|
|
543
|
-
|
|
544
|
-
// src/shared/types/offer.ts
|
|
545
|
-
var OfferId = (value) => value;
|
|
546
|
-
var OfferSlug = (value) => value;
|
|
547
|
-
var Offer = {
|
|
548
|
-
fromDto: (dto) => ({
|
|
549
|
-
id: OfferId(dto.id),
|
|
550
|
-
slug: OfferSlug(dto.slug),
|
|
551
|
-
tagline: notBlankStringOrNull(dto.tagline),
|
|
552
|
-
bannerUrl: notBlankStringOrNull(dto.banner_url),
|
|
553
|
-
logoUrl: notBlankStringOrNull(dto.logo_url),
|
|
554
|
-
startsAt: new Date(dto.starts_at),
|
|
555
|
-
endsAt: new Date(dto.ends_at)
|
|
556
|
-
})
|
|
557
|
-
};
|
|
558
|
-
|
|
559
|
-
// src/shared/types/asset.ts
|
|
560
|
-
var AssetId = (value) => value;
|
|
561
|
-
var AssetCode = (value) => value;
|
|
562
|
-
var Asset = {
|
|
563
|
-
fromDto: (dto) => ({
|
|
564
|
-
id: AssetId(dto.id),
|
|
565
|
-
code: AssetCode(dto.code),
|
|
566
|
-
name: dto.name,
|
|
567
|
-
fractionalDigits: dto.fractional_digits
|
|
568
|
-
})
|
|
569
|
-
};
|
|
570
|
-
|
|
571
|
-
// src/shared/types/offer-detail.ts
|
|
572
|
-
var OfferOptionId = (value) => value;
|
|
573
|
-
var OfferOptionSlug = (value) => value;
|
|
574
|
-
var OfferDetail = {
|
|
575
|
-
fromDto: (dto) => {
|
|
576
|
-
if (!Array.isArray(dto.funding_assets)) {
|
|
577
|
-
throw new Error(`funding_assets must be an array`);
|
|
578
|
-
}
|
|
579
|
-
if (!Array.isArray(dto.options)) {
|
|
580
|
-
throw new Error(`options must be an array`);
|
|
581
|
-
}
|
|
582
|
-
if (!Array.isArray(dto.terms)) {
|
|
583
|
-
throw new Error(`terms must be an array`);
|
|
584
|
-
}
|
|
585
|
-
if (!Array.isArray(dto.links)) {
|
|
586
|
-
throw new Error(`links must be an array`);
|
|
587
|
-
}
|
|
588
|
-
if (!Array.isArray(dto.faqs)) {
|
|
589
|
-
throw new Error(`faqs must be an array`);
|
|
590
|
-
}
|
|
591
|
-
if (!Array.isArray(dto.milestones)) {
|
|
592
|
-
throw new Error(`milestones must be an array`);
|
|
593
|
-
}
|
|
594
|
-
return {
|
|
595
|
-
id: OfferId(dto.id),
|
|
596
|
-
slug: OfferSlug(dto.slug),
|
|
597
|
-
name: dto.name,
|
|
598
|
-
asset: Asset.fromDto(dto.asset),
|
|
599
|
-
fundingAssets: dto.funding_assets.map(Asset.fromDto),
|
|
600
|
-
about: notBlankStringOrNull(dto.about),
|
|
601
|
-
tagline: notBlankStringOrNull(dto.tagline),
|
|
602
|
-
bannerUrl: notBlankStringOrNull(dto.banner_url),
|
|
603
|
-
logoUrl: notBlankStringOrNull(dto.logo_url),
|
|
604
|
-
category: notBlankStringOrNull(dto.category),
|
|
605
|
-
startsAt: new Date(dto.starts_at),
|
|
606
|
-
endsAt: new Date(dto.ends_at),
|
|
607
|
-
faqs: dto.faqs.map(FaqItem.fromDto),
|
|
608
|
-
links: dto.links.map(Link.fromDto),
|
|
609
|
-
milestones: dto.milestones.map(Milestone.fromDto),
|
|
610
|
-
options: dto.options.map(OfferOption.fromDto),
|
|
611
|
-
terms: dto.terms.map(TermItem.fromDto)
|
|
612
|
-
};
|
|
613
|
-
}
|
|
614
|
-
};
|
|
615
|
-
var OfferOption = {
|
|
616
|
-
fromDto: (dto) => ({
|
|
617
|
-
id: OfferOptionId(dto.id),
|
|
618
|
-
slug: OfferOptionSlug(dto.slug),
|
|
619
|
-
bidIncrement: dto.bid_increment,
|
|
620
|
-
floorPriceUsd: dto.floor_price_usd,
|
|
621
|
-
minimumPurchaseUsd: dto.minimum_purchase_usd,
|
|
622
|
-
priceUsd: dto.price_usd,
|
|
623
|
-
saleAgreementUrl: notBlankStringOrNull(dto.sale_agreement_url),
|
|
624
|
-
totalTokenSupply: dto.total_token_supply
|
|
625
|
-
})
|
|
626
|
-
};
|
|
627
|
-
var FaqItem = {
|
|
628
|
-
fromDto: (dto) => ({
|
|
629
|
-
question: notBlankStringOrNull(dto.question),
|
|
630
|
-
answer: notBlankStringOrNull(dto.answer)
|
|
631
|
-
})
|
|
632
|
-
};
|
|
633
|
-
var Link = {
|
|
634
|
-
fromDto: (dto) => ({
|
|
635
|
-
label: notBlankStringOrNull(dto.label),
|
|
636
|
-
url: notBlankStringOrNull(dto.url)
|
|
637
|
-
})
|
|
638
|
-
};
|
|
639
|
-
var TermItem = {
|
|
640
|
-
fromDto: (dto) => ({
|
|
641
|
-
key: notBlankStringOrNull(dto.key),
|
|
642
|
-
value: notBlankStringOrNull(dto.value)
|
|
643
|
-
})
|
|
644
|
-
};
|
|
645
|
-
var Milestone = {
|
|
646
|
-
fromDto: (dto) => ({
|
|
647
|
-
name: notBlankStringOrNull(dto.name),
|
|
648
|
-
schedule: notBlankStringOrNull(dto.schedule),
|
|
649
|
-
status: dto.status
|
|
650
|
-
})
|
|
651
|
-
};
|
|
652
|
-
|
|
653
|
-
// src/shared/types/participation.ts
|
|
654
|
-
var ParticipationId = (value) => value;
|
|
655
|
-
var Blockchain = (value) => value;
|
|
656
|
-
var WalletAddress = (value) => value;
|
|
657
|
-
var ParticipationsPaginationParams = {
|
|
658
|
-
toQueryParams: (params) => {
|
|
659
|
-
const queryParams = PaginationParams.toQueryParams(params);
|
|
660
|
-
if (params.offerId) {
|
|
661
|
-
queryParams["filters[0][field]"] = "offer_id";
|
|
662
|
-
queryParams["filters[0][op]"] = "==";
|
|
663
|
-
queryParams["filters[0][value]"] = params.offerId;
|
|
664
|
-
}
|
|
665
|
-
return queryParams;
|
|
666
|
-
}
|
|
667
|
-
};
|
|
668
|
-
var Participation = {
|
|
669
|
-
/** Maps API DTO shape into the SDK participation domain model. */
|
|
670
|
-
fromDto: (dto) => {
|
|
671
|
-
const walletAddress = notBlankStringOrNull(dto.wallet_address);
|
|
672
|
-
return {
|
|
673
|
-
id: ParticipationId(dto.id),
|
|
674
|
-
offerId: OfferId(dto.offer_id),
|
|
675
|
-
offerOptionId: OfferOptionId(dto.offer_option_id),
|
|
676
|
-
status: dto.status,
|
|
677
|
-
amount: dto.amount,
|
|
678
|
-
displayAmount: dto.amount_string,
|
|
679
|
-
asset: Asset.fromDto(dto.asset),
|
|
680
|
-
chain: Blockchain(dto.chain),
|
|
681
|
-
insertedAt: dto.inserted_at ? new Date(dto.inserted_at) : null,
|
|
682
|
-
updatedAt: dto.updated_at ? new Date(dto.updated_at) : null,
|
|
683
|
-
walletAddress: walletAddress ? WalletAddress(walletAddress) : null
|
|
684
|
-
};
|
|
685
|
-
}
|
|
686
|
-
};
|
|
687
|
-
var CreateParticipationParams = {
|
|
688
|
-
/** Maps participation creation params into API DTO payload. */
|
|
689
|
-
toDto: (params) => ({
|
|
690
|
-
offer_id: params.offerId,
|
|
691
|
-
offer_option_id: params.offerOptionId,
|
|
692
|
-
chain: params.chain,
|
|
693
|
-
wallet_address: params.walletAddress,
|
|
694
|
-
amount: params.amount,
|
|
695
|
-
asset_id: params.assetId,
|
|
696
|
-
approval_transaction_hash: params.approvalTransactionHash
|
|
697
|
-
})
|
|
698
|
-
};
|
|
699
|
-
|
|
700
|
-
// src/shared/types/requirement.ts
|
|
701
|
-
var RequirementId = (value) => value;
|
|
702
|
-
var Requirement = {
|
|
703
|
-
fromDto: (dto) => ({
|
|
704
|
-
id: RequirementId(dto.id),
|
|
705
|
-
type: dto.type,
|
|
706
|
-
details: dto.details
|
|
707
|
-
})
|
|
708
|
-
};
|
|
709
|
-
var RequirementStatusInfo = {
|
|
710
|
-
fromStatusesDto: (dto) => Object.entries(dto.statuses).map(([id, status]) => ({
|
|
711
|
-
id: RequirementId(id),
|
|
712
|
-
status
|
|
713
|
-
}))
|
|
714
|
-
};
|
|
715
|
-
|
|
716
|
-
// src/client/core/coinlist-client.ts
|
|
717
|
-
var OAUTH_STATE_KEY = "coinlist.oauth_state";
|
|
718
|
-
var OAUTH_CODE_VERIFIER_KEY = "coinlist.oauth_code_verifier";
|
|
719
|
-
var CoinListClientImpl = class {
|
|
720
|
-
constructor(_config) {
|
|
721
|
-
this._config = _config;
|
|
722
|
-
/** Cached access token: undefined = loading, null = no token, AccessToken = logged in */
|
|
723
|
-
this._accessToken = void 0;
|
|
724
|
-
this.api = new ApiClient(
|
|
725
|
-
{
|
|
726
|
-
baseUrl: _config.baseUrl || PUBLIC_API_BASE_URL,
|
|
727
|
-
xApiVersion: API_VERSION
|
|
728
|
-
},
|
|
729
|
-
this.fetchAccessToken.bind(this)
|
|
730
|
-
);
|
|
731
|
-
}
|
|
732
|
-
async init() {
|
|
733
|
-
await this.fetchAccessToken(true);
|
|
734
|
-
return this.getAuthState();
|
|
735
|
-
}
|
|
736
|
-
async fetchAccessToken(refresh) {
|
|
737
|
-
if (!refresh && this._accessToken !== void 0) return this._accessToken;
|
|
738
|
-
try {
|
|
739
|
-
const accessToken = await this._config.getAccessToken();
|
|
740
|
-
this._accessToken = accessToken;
|
|
741
|
-
return accessToken;
|
|
742
|
-
} catch (_) {
|
|
743
|
-
this._accessToken = null;
|
|
744
|
-
return null;
|
|
745
|
-
}
|
|
746
|
-
}
|
|
747
|
-
getAuthState() {
|
|
748
|
-
if (this._accessToken === void 0) {
|
|
749
|
-
return "unknown";
|
|
750
|
-
}
|
|
751
|
-
return this._accessToken !== null ? "logged-in" : "logged-out";
|
|
752
|
-
}
|
|
753
|
-
async startOAuth() {
|
|
754
|
-
const state = generateSecureRandomBase64Url(32);
|
|
755
|
-
const codeVerifier = generateSecureRandomBase64Url(32);
|
|
756
|
-
const codeChallengeRaw = await sha256(codeVerifier);
|
|
757
|
-
const codeChallenge = arrayBufferToBase64Url(codeChallengeRaw, false);
|
|
758
|
-
sessionStorage.setItem(OAUTH_STATE_KEY, state);
|
|
759
|
-
sessionStorage.setItem(OAUTH_CODE_VERIFIER_KEY, codeVerifier);
|
|
760
|
-
const params = new URLSearchParams({
|
|
761
|
-
client_id: this._config.clientId,
|
|
762
|
-
response_type: "code",
|
|
763
|
-
redirect_uri: this._config.redirectUri,
|
|
764
|
-
code_challenge: codeChallenge,
|
|
765
|
-
code_challenge_method: "S256",
|
|
766
|
-
state
|
|
767
|
-
});
|
|
768
|
-
const oauthPageUrl = this._config.authorizationPageUrl ?? COINLIST_OAUTH_PAGE_URL;
|
|
769
|
-
const url = `${oauthPageUrl}?${params.toString()}`;
|
|
770
|
-
window.location.href = url;
|
|
771
|
-
}
|
|
772
|
-
completeOAuth() {
|
|
773
|
-
const params = new URLSearchParams(window.location.search);
|
|
774
|
-
const coinlistError = params.get("error");
|
|
775
|
-
if (coinlistError) {
|
|
776
|
-
return { type: "error", reason: "user_canceled" };
|
|
777
|
-
}
|
|
778
|
-
const stateParam = params.get("state");
|
|
779
|
-
if (!stateParam) {
|
|
780
|
-
return { type: "error", reason: "missing_state" };
|
|
781
|
-
}
|
|
782
|
-
const storedState = sessionStorage.getItem(OAUTH_STATE_KEY);
|
|
783
|
-
if (storedState === null || storedState !== stateParam) {
|
|
784
|
-
return { type: "error", reason: "invalid_state" };
|
|
785
|
-
}
|
|
786
|
-
const codeParam = params.get("code");
|
|
787
|
-
if (!codeParam) {
|
|
788
|
-
return { type: "error", reason: "missing_code" };
|
|
789
|
-
}
|
|
790
|
-
const codeVerifierValue = sessionStorage.getItem(OAUTH_CODE_VERIFIER_KEY);
|
|
791
|
-
if (!codeVerifierValue) {
|
|
792
|
-
return { type: "error", reason: "missing_code_verifier" };
|
|
793
|
-
}
|
|
794
|
-
return {
|
|
795
|
-
type: "ok",
|
|
796
|
-
code: AuthorizationCode(codeParam),
|
|
797
|
-
codeVerifier: CodeVerifier(codeVerifierValue)
|
|
798
|
-
};
|
|
799
|
-
}
|
|
800
|
-
logout() {
|
|
801
|
-
this._accessToken = null;
|
|
802
|
-
}
|
|
803
|
-
async fetchAllOffers() {
|
|
804
|
-
this.ensureAuthenticated();
|
|
805
|
-
return await fetchAllPages(this.fetchOffersPage.bind(this));
|
|
806
|
-
}
|
|
807
|
-
async fetchOffersPage(params) {
|
|
808
|
-
this.ensureAuthenticated();
|
|
809
|
-
const queryParams = PaginationParams.toQueryParams(params);
|
|
810
|
-
if (this._config.sandbox) {
|
|
811
|
-
queryParams.sandbox = true;
|
|
812
|
-
}
|
|
813
|
-
const pageDto = await this.api.send({
|
|
814
|
-
method: "GET",
|
|
815
|
-
url: "/v1/offers",
|
|
816
|
-
queryParams,
|
|
817
|
-
attributes: Attributes.protected()
|
|
818
|
-
});
|
|
819
|
-
return PaginatedResponse.fromDto(pageDto, Offer.fromDto);
|
|
820
|
-
}
|
|
821
|
-
async fetchOfferDetails(id) {
|
|
822
|
-
this.ensureAuthenticated();
|
|
823
|
-
const offerDetailDto = await this.api.send({
|
|
824
|
-
method: "GET",
|
|
825
|
-
url: `/v1/offers/${id}`,
|
|
826
|
-
attributes: Attributes.protected()
|
|
827
|
-
});
|
|
828
|
-
return OfferDetail.fromDto(offerDetailDto);
|
|
829
|
-
}
|
|
830
|
-
async fetchAllParticipations(offerId) {
|
|
831
|
-
this.ensureAuthenticated();
|
|
832
|
-
return await fetchAllPages(
|
|
833
|
-
this.fetchParticipationsPage.bind(this),
|
|
834
|
-
{ offerId }
|
|
835
|
-
);
|
|
836
|
-
}
|
|
837
|
-
async fetchParticipationsPage(params) {
|
|
838
|
-
this.ensureAuthenticated();
|
|
839
|
-
const pageDto = await this.api.send(
|
|
840
|
-
{
|
|
841
|
-
method: "GET",
|
|
842
|
-
url: "/v1/participations",
|
|
843
|
-
queryParams: ParticipationsPaginationParams.toQueryParams(params),
|
|
844
|
-
attributes: Attributes.protected()
|
|
845
|
-
}
|
|
846
|
-
);
|
|
847
|
-
return PaginatedResponse.fromDto(pageDto, Participation.fromDto);
|
|
848
|
-
}
|
|
849
|
-
async fetchParticipation(id) {
|
|
850
|
-
this.ensureAuthenticated();
|
|
851
|
-
const participationDto = await this.api.send({
|
|
852
|
-
method: "GET",
|
|
853
|
-
url: `/v1/participations/${id}`,
|
|
854
|
-
attributes: Attributes.protected()
|
|
855
|
-
});
|
|
856
|
-
return Participation.fromDto(participationDto);
|
|
857
|
-
}
|
|
858
|
-
async createParticipation(params) {
|
|
859
|
-
this.ensureAuthenticated();
|
|
860
|
-
const participationDto = await this.api.send({
|
|
861
|
-
method: "POST",
|
|
862
|
-
url: "/v1/participations",
|
|
863
|
-
body: CreateParticipationParams.toDto(params),
|
|
864
|
-
attributes: Attributes.protected()
|
|
865
|
-
});
|
|
866
|
-
return Participation.fromDto(participationDto);
|
|
867
|
-
}
|
|
868
|
-
async fetchOfferRequirements(offerId) {
|
|
869
|
-
this.ensureAuthenticated();
|
|
870
|
-
const response = await this.api.send({
|
|
871
|
-
method: "GET",
|
|
872
|
-
url: `/v1/offers/${offerId}/requirements`,
|
|
873
|
-
attributes: Attributes.protected()
|
|
874
|
-
});
|
|
875
|
-
return Object.fromEntries(
|
|
876
|
-
Object.entries(response.options).map(([optionId, list]) => [
|
|
877
|
-
optionId,
|
|
878
|
-
list.data.map(Requirement.fromDto)
|
|
879
|
-
])
|
|
880
|
-
);
|
|
881
|
-
}
|
|
882
|
-
async fetchRequirementStatuses(offerId) {
|
|
883
|
-
this.ensureAuthenticated();
|
|
884
|
-
const response = await this.api.send({
|
|
885
|
-
method: "GET",
|
|
886
|
-
url: `/v1/offers/${offerId}/requirements/statuses`,
|
|
887
|
-
attributes: Attributes.protected()
|
|
888
|
-
});
|
|
889
|
-
return RequirementStatusInfo.fromStatusesDto(response);
|
|
890
|
-
}
|
|
891
|
-
ensureAuthenticated() {
|
|
892
|
-
if (this.getAuthState() !== "logged-in") {
|
|
893
|
-
throw new NotAuthenticatedError();
|
|
894
|
-
}
|
|
895
|
-
}
|
|
896
|
-
};
|
|
897
|
-
function createCoinListClient(config) {
|
|
898
|
-
return new CoinListClientImpl(config);
|
|
899
|
-
}
|
|
900
|
-
|
|
901
|
-
// src/shared/types/oauth-session.ts
|
|
902
|
-
var OAuthRefreshToken = (value) => value;
|
|
903
|
-
var OAuthSession = {
|
|
904
|
-
fromDto: (dto) => {
|
|
905
|
-
const expiresAt = new Date(Date.now() + dto.expires_in * 1e3);
|
|
906
|
-
return {
|
|
907
|
-
accessToken: {
|
|
908
|
-
value: dto.access_token,
|
|
909
|
-
expiresAt
|
|
910
|
-
},
|
|
911
|
-
...dto.refresh_token != null && dto.refresh_token !== "" ? { refreshToken: OAuthRefreshToken(dto.refresh_token) } : void 0
|
|
912
|
-
};
|
|
913
|
-
}
|
|
914
|
-
};
|
|
915
|
-
|
|
916
|
-
// src/shared/types/user.ts
|
|
917
|
-
var UserId = (value) => value;
|
|
918
|
-
var UserEmail = (value) => value;
|
|
919
|
-
var User = {
|
|
920
|
-
fromDto: (dto) => ({
|
|
921
|
-
id: UserId(dto.id),
|
|
922
|
-
email: UserEmail(dto.email)
|
|
923
|
-
})
|
|
924
|
-
};
|
|
925
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
926
|
-
0 && (module.exports = {
|
|
927
|
-
AuthorizationCode,
|
|
928
|
-
Blockchain,
|
|
929
|
-
ClientId,
|
|
930
|
-
ClientSecret,
|
|
931
|
-
CodeChallenge,
|
|
932
|
-
CodeVerifier,
|
|
933
|
-
CreateParticipationParams,
|
|
934
|
-
Cursor,
|
|
935
|
-
FaqItem,
|
|
936
|
-
Link,
|
|
937
|
-
Milestone,
|
|
938
|
-
OAuthRefreshToken,
|
|
939
|
-
OAuthSession,
|
|
940
|
-
Offer,
|
|
941
|
-
OfferDetail,
|
|
942
|
-
OfferId,
|
|
943
|
-
OfferOption,
|
|
944
|
-
OfferOptionId,
|
|
945
|
-
OfferOptionSlug,
|
|
946
|
-
OfferSlug,
|
|
947
|
-
PaginatedResponse,
|
|
948
|
-
PaginationParams,
|
|
949
|
-
Participation,
|
|
950
|
-
ParticipationId,
|
|
951
|
-
ParticipationsPaginationParams,
|
|
952
|
-
RedirectUri,
|
|
953
|
-
TermItem,
|
|
954
|
-
User,
|
|
955
|
-
UserEmail,
|
|
956
|
-
UserId,
|
|
957
|
-
WalletAddress,
|
|
958
|
-
createCoinListClient,
|
|
959
|
-
fetchAllPages
|
|
960
|
-
});
|
|
961
|
-
//# sourceMappingURL=index.cjs.map
|