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