@unifold/core 0.1.71 → 0.1.73
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/README.md +9 -0
- package/dist/index.d.mts +463 -57
- package/dist/index.d.ts +463 -57
- package/dist/index.js +307 -125
- package/dist/index.mjs +297 -125
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -40,7 +40,70 @@ function generatePrefixedKSUID(prefix) {
|
|
|
40
40
|
return `${prefix}_${generateKSUID()}`;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
// src/lib/client-headers.ts
|
|
44
|
+
var SDK_VERSION = true ? "0.1.73" : "0.0.0-dev";
|
|
45
|
+
var CLIENT_VERSION_HEADER = "x-unifold-client-version";
|
|
46
|
+
var CLIENT_USER_AGENT_HEADER = "x-unifold-client-user-agent";
|
|
47
|
+
function detectRuntime() {
|
|
48
|
+
if (typeof navigator !== "undefined") {
|
|
49
|
+
const nav = navigator;
|
|
50
|
+
return {
|
|
51
|
+
lang: "js",
|
|
52
|
+
// The browser already sends its real `User-Agent` automatically, so we
|
|
53
|
+
// keep this compact rather than duplicating the full UA string.
|
|
54
|
+
langVersion: nav.platform || "browser",
|
|
55
|
+
platform: nav.platform || "browser"
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
const proc = globalThis.process;
|
|
60
|
+
if (proc?.versions?.node) {
|
|
61
|
+
return {
|
|
62
|
+
lang: "node",
|
|
63
|
+
langVersion: proc.versions.node,
|
|
64
|
+
platform: `${proc.platform ?? "unknown"} ${proc.arch ?? ""}`.trim()
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
} catch {
|
|
68
|
+
}
|
|
69
|
+
return { lang: "js", langVersion: "unknown", platform: "unknown" };
|
|
70
|
+
}
|
|
71
|
+
var cachedHeaders;
|
|
72
|
+
function getClientHeaders() {
|
|
73
|
+
if (cachedHeaders) {
|
|
74
|
+
return cachedHeaders;
|
|
75
|
+
}
|
|
76
|
+
const runtime = detectRuntime();
|
|
77
|
+
const userAgent = {
|
|
78
|
+
bindings_version: SDK_VERSION,
|
|
79
|
+
lang: runtime.lang,
|
|
80
|
+
lang_version: runtime.langVersion,
|
|
81
|
+
platform: runtime.platform,
|
|
82
|
+
publisher: "unifold"
|
|
83
|
+
};
|
|
84
|
+
cachedHeaders = {
|
|
85
|
+
[CLIENT_VERSION_HEADER]: `unifold-js/${SDK_VERSION}`,
|
|
86
|
+
[CLIENT_USER_AGENT_HEADER]: JSON.stringify(userAgent)
|
|
87
|
+
};
|
|
88
|
+
return cachedHeaders;
|
|
89
|
+
}
|
|
90
|
+
|
|
43
91
|
// src/lib/api.ts
|
|
92
|
+
function apiFetch(input, init = {}) {
|
|
93
|
+
let clientHeaders = {};
|
|
94
|
+
try {
|
|
95
|
+
clientHeaders = getClientHeaders();
|
|
96
|
+
} catch {
|
|
97
|
+
clientHeaders = {};
|
|
98
|
+
}
|
|
99
|
+
return globalThis.fetch(input, {
|
|
100
|
+
...init,
|
|
101
|
+
headers: {
|
|
102
|
+
...clientHeaders,
|
|
103
|
+
...init.headers
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
44
107
|
var API_BASE_URL = (() => {
|
|
45
108
|
try {
|
|
46
109
|
return process.env.NEXT_PUBLIC_API_BASE_URL || "https://api.unifold.io";
|
|
@@ -125,7 +188,7 @@ async function createDepositAddress(overrides, publishableKey) {
|
|
|
125
188
|
};
|
|
126
189
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
127
190
|
validatePublishableKey(pk);
|
|
128
|
-
const response = await
|
|
191
|
+
const response = await apiFetch(`${API_BASE_URL}/v1/public/deposit_addresses`, {
|
|
129
192
|
method: "POST",
|
|
130
193
|
headers: {
|
|
131
194
|
accept: "application/json",
|
|
@@ -149,7 +212,7 @@ async function createDepositAddress(overrides, publishableKey) {
|
|
|
149
212
|
async function getDepositAddress(params, publishableKey) {
|
|
150
213
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
151
214
|
validatePublishableKey(pk);
|
|
152
|
-
const response = await
|
|
215
|
+
const response = await apiFetch(`${API_BASE_URL}/v1/public/deposit_addresses/existing`, {
|
|
153
216
|
method: "POST",
|
|
154
217
|
headers: {
|
|
155
218
|
accept: "application/json",
|
|
@@ -183,7 +246,7 @@ async function queryExecutions(externalUserId, publishableKey, actionType = "dep
|
|
|
183
246
|
external_user_id: externalUserId,
|
|
184
247
|
action_type: actionType
|
|
185
248
|
};
|
|
186
|
-
const response = await
|
|
249
|
+
const response = await apiFetch(`${API_BASE_URL}/v1/public/direct_executions/query`, {
|
|
187
250
|
method: "POST",
|
|
188
251
|
headers: {
|
|
189
252
|
accept: "application/json",
|
|
@@ -200,7 +263,7 @@ async function queryExecutions(externalUserId, publishableKey, actionType = "dep
|
|
|
200
263
|
async function pollDirectExecutions(request, publishableKey) {
|
|
201
264
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
202
265
|
validatePublishableKey(pk);
|
|
203
|
-
const response = await
|
|
266
|
+
const response = await apiFetch(`${API_BASE_URL}/v1/public/direct_executions/poll`, {
|
|
204
267
|
method: "POST",
|
|
205
268
|
headers: {
|
|
206
269
|
accept: "application/json",
|
|
@@ -226,7 +289,7 @@ async function getSupportedDestinationTokens(publishableKey, options) {
|
|
|
226
289
|
if (qs) {
|
|
227
290
|
url = `${url}?${qs}`;
|
|
228
291
|
}
|
|
229
|
-
const response = await
|
|
292
|
+
const response = await apiFetch(url, {
|
|
230
293
|
method: "GET",
|
|
231
294
|
headers: {
|
|
232
295
|
accept: "application/json",
|
|
@@ -255,7 +318,7 @@ async function getSupportedDepositTokens(publishableKey, options) {
|
|
|
255
318
|
if (qs) {
|
|
256
319
|
url = `${url}?${qs}`;
|
|
257
320
|
}
|
|
258
|
-
const response = await
|
|
321
|
+
const response = await apiFetch(url, {
|
|
259
322
|
method: "GET",
|
|
260
323
|
headers: {
|
|
261
324
|
accept: "application/json",
|
|
@@ -275,7 +338,7 @@ async function getTokenMetadata(request, publishableKey) {
|
|
|
275
338
|
chainId: request.chain_id,
|
|
276
339
|
tokenAddress: request.token_address
|
|
277
340
|
});
|
|
278
|
-
const response = await
|
|
341
|
+
const response = await apiFetch(`${API_BASE_URL}/v1/public/tokens/token?${params.toString()}`, {
|
|
279
342
|
method: "GET",
|
|
280
343
|
headers: {
|
|
281
344
|
accept: "application/json",
|
|
@@ -300,7 +363,7 @@ function getPreferredIconUrl(iconUrls, preferredFormat = "svg") {
|
|
|
300
363
|
async function getFiatCurrencies(publishableKey) {
|
|
301
364
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
302
365
|
validatePublishableKey(pk);
|
|
303
|
-
const response = await
|
|
366
|
+
const response = await apiFetch(`${API_BASE_URL}/v1/public/onramps/fiat_currencies`, {
|
|
304
367
|
method: "GET",
|
|
305
368
|
headers: {
|
|
306
369
|
accept: "application/json",
|
|
@@ -321,7 +384,7 @@ async function getFiatExchangeRates(options = {}, publishableKey) {
|
|
|
321
384
|
}
|
|
322
385
|
const queryString = params.toString();
|
|
323
386
|
const url = `${API_BASE_URL}/v1/public/exchange_rates/fiat_currencies${queryString ? `?${queryString}` : ""}`;
|
|
324
|
-
const response = await
|
|
387
|
+
const response = await apiFetch(url, {
|
|
325
388
|
method: "GET",
|
|
326
389
|
headers: {
|
|
327
390
|
accept: "application/json",
|
|
@@ -336,7 +399,7 @@ async function getFiatExchangeRates(options = {}, publishableKey) {
|
|
|
336
399
|
async function getOnrampQuotes(request, publishableKey) {
|
|
337
400
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
338
401
|
validatePublishableKey(pk);
|
|
339
|
-
const response = await
|
|
402
|
+
const response = await apiFetch(`${API_BASE_URL}/v1/public/onramps/quotes`, {
|
|
340
403
|
method: "POST",
|
|
341
404
|
headers: {
|
|
342
405
|
accept: "application/json",
|
|
@@ -353,7 +416,7 @@ async function getOnrampQuotes(request, publishableKey) {
|
|
|
353
416
|
async function createOnrampSession(request, publishableKey) {
|
|
354
417
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
355
418
|
validatePublishableKey(pk);
|
|
356
|
-
const response = await
|
|
419
|
+
const response = await apiFetch(`${API_BASE_URL}/v1/public/onramps/sessions`, {
|
|
357
420
|
method: "POST",
|
|
358
421
|
headers: {
|
|
359
422
|
accept: "application/json",
|
|
@@ -376,7 +439,7 @@ async function getBankTransferProviders(publishableKey, options = {}) {
|
|
|
376
439
|
}
|
|
377
440
|
const queryString = params.toString();
|
|
378
441
|
const url = `${API_BASE_URL}/v1/public/onramps/bank_transfer/providers${queryString ? `?${queryString}` : ""}`;
|
|
379
|
-
const response = await
|
|
442
|
+
const response = await apiFetch(url, {
|
|
380
443
|
method: "GET",
|
|
381
444
|
headers: {
|
|
382
445
|
accept: "application/json",
|
|
@@ -388,21 +451,57 @@ async function getBankTransferProviders(publishableKey, options = {}) {
|
|
|
388
451
|
}
|
|
389
452
|
return response.json();
|
|
390
453
|
}
|
|
391
|
-
|
|
454
|
+
var usesLegacyWalletPayRoutes = false;
|
|
455
|
+
async function fetchWalletPayRoute(current, legacy) {
|
|
456
|
+
if (usesLegacyWalletPayRoutes && legacy) {
|
|
457
|
+
return apiFetch(legacy.url, legacy.init);
|
|
458
|
+
}
|
|
459
|
+
const response = await apiFetch(current.url, current.init);
|
|
460
|
+
if (response.status !== 404 || !legacy) return response;
|
|
461
|
+
usesLegacyWalletPayRoutes = true;
|
|
462
|
+
return apiFetch(legacy.url, legacy.init);
|
|
463
|
+
}
|
|
464
|
+
async function getWalletPayProviders(method, publishableKey) {
|
|
392
465
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
393
466
|
validatePublishableKey(pk);
|
|
394
|
-
const
|
|
395
|
-
const response = await fetch(url, {
|
|
467
|
+
const init = {
|
|
396
468
|
method: "GET",
|
|
397
469
|
headers: {
|
|
398
470
|
accept: "application/json",
|
|
399
471
|
"x-publishable-key": pk
|
|
400
472
|
}
|
|
401
|
-
}
|
|
473
|
+
};
|
|
474
|
+
const response = await fetchWalletPayRoute(
|
|
475
|
+
{
|
|
476
|
+
url: `${API_BASE_URL}/v1/public/onramps/wallet_pay/providers?payment_method_type=${method}`,
|
|
477
|
+
init
|
|
478
|
+
},
|
|
479
|
+
method === "apple_pay" ? { url: `${API_BASE_URL}/v1/public/onramps/apple_pay/providers`, init } : null
|
|
480
|
+
);
|
|
402
481
|
if (!response.ok) {
|
|
403
|
-
throw new Error(
|
|
482
|
+
throw new Error(
|
|
483
|
+
`Failed to fetch ${WALLET_PAY_LABEL[method]} providers: ${response.statusText}`
|
|
484
|
+
);
|
|
404
485
|
}
|
|
405
|
-
|
|
486
|
+
const payload = await response.json();
|
|
487
|
+
return {
|
|
488
|
+
// The route this can fall back to reports the same values under the older
|
|
489
|
+
// `payment_methods` name, so fold both into one field rather than making
|
|
490
|
+
// callers know which generation of the API answered.
|
|
491
|
+
data: (payload.data ?? []).map((provider) => {
|
|
492
|
+
const { payment_methods: legacy, payment_method_types: current, ...rest } = provider;
|
|
493
|
+
return {
|
|
494
|
+
...rest,
|
|
495
|
+
payment_method_types: current ?? legacy ?? []
|
|
496
|
+
};
|
|
497
|
+
})
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
function getApplePayProviders(publishableKey) {
|
|
501
|
+
return getWalletPayProviders("apple_pay", publishableKey);
|
|
502
|
+
}
|
|
503
|
+
function getGooglePayProviders(publishableKey) {
|
|
504
|
+
return getWalletPayProviders("google_pay", publishableKey);
|
|
406
505
|
}
|
|
407
506
|
function getOnrampSessionStartUrl(request, publishableKey) {
|
|
408
507
|
const params = new URLSearchParams();
|
|
@@ -438,7 +537,7 @@ async function getDefaultOnrampToken(params, publishableKey) {
|
|
|
438
537
|
queryParams.append("token_address", params.token_address);
|
|
439
538
|
queryParams.append("chain_id", params.chain_id);
|
|
440
539
|
queryParams.append("chain_type", params.chain_type);
|
|
441
|
-
const response = await
|
|
540
|
+
const response = await apiFetch(
|
|
442
541
|
`${API_BASE_URL}/v1/public/onramps/default_token?${queryParams.toString()}`,
|
|
443
542
|
{
|
|
444
543
|
method: "GET",
|
|
@@ -454,7 +553,7 @@ async function getDefaultOnrampToken(params, publishableKey) {
|
|
|
454
553
|
return response.json();
|
|
455
554
|
}
|
|
456
555
|
async function getTokenChains() {
|
|
457
|
-
const response = await
|
|
556
|
+
const response = await apiFetch(`${API_BASE_URL}/v1/public/tokens/chains`, {
|
|
458
557
|
method: "GET",
|
|
459
558
|
headers: {
|
|
460
559
|
accept: "application/json"
|
|
@@ -488,7 +587,7 @@ async function getProjectConfig(publishableKey, options) {
|
|
|
488
587
|
}
|
|
489
588
|
const queryString = params.toString();
|
|
490
589
|
const url = `${API_BASE_URL}/v1/public/projects/config${queryString ? `?${queryString}` : ""}`;
|
|
491
|
-
const response = await
|
|
590
|
+
const response = await apiFetch(url, {
|
|
492
591
|
method: "GET",
|
|
493
592
|
headers: {
|
|
494
593
|
accept: "application/json",
|
|
@@ -504,7 +603,7 @@ async function getProjectConfig(publishableKey, options) {
|
|
|
504
603
|
async function getPublicIncident(publishableKey) {
|
|
505
604
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
506
605
|
validatePublishableKey(pk);
|
|
507
|
-
const response = await
|
|
606
|
+
const response = await apiFetch(`${API_BASE_URL}/v1/public/projects/incident`, {
|
|
508
607
|
method: "GET",
|
|
509
608
|
headers: {
|
|
510
609
|
accept: "application/json",
|
|
@@ -517,7 +616,7 @@ async function getPublicIncident(publishableKey) {
|
|
|
517
616
|
return response.json();
|
|
518
617
|
}
|
|
519
618
|
async function getIpAddress() {
|
|
520
|
-
const response = await
|
|
619
|
+
const response = await apiFetch(`${API_BASE_URL}/v1/public/ip_address`, {
|
|
521
620
|
method: "GET",
|
|
522
621
|
headers: {
|
|
523
622
|
accept: "application/json"
|
|
@@ -537,7 +636,7 @@ async function getAddressBalances(address, chainType, publishableKey) {
|
|
|
537
636
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
538
637
|
validatePublishableKey(pk);
|
|
539
638
|
const url = `${API_BASE_URL}/v1/public/addresses/balances`;
|
|
540
|
-
const response = await
|
|
639
|
+
const response = await apiFetch(url, {
|
|
541
640
|
method: "POST",
|
|
542
641
|
headers: {
|
|
543
642
|
"Content-Type": "application/json",
|
|
@@ -558,7 +657,7 @@ async function getAddressBalances(address, chainType, publishableKey) {
|
|
|
558
657
|
async function getExternalWallets(publishableKey) {
|
|
559
658
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
560
659
|
validatePublishableKey(pk);
|
|
561
|
-
const response = await
|
|
660
|
+
const response = await apiFetch(`${API_BASE_URL}/v1/public/external_wallets`, {
|
|
562
661
|
method: "GET",
|
|
563
662
|
headers: {
|
|
564
663
|
accept: "application/json",
|
|
@@ -574,7 +673,7 @@ async function getExternalWallets(publishableKey) {
|
|
|
574
673
|
async function getWalletMobileDeepLink(wallet, depositAddresses, publishableKey, amountUsd) {
|
|
575
674
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
576
675
|
validatePublishableKey(pk);
|
|
577
|
-
const response = await
|
|
676
|
+
const response = await apiFetch(`${API_BASE_URL}/v1/public/external_wallets/mobile_deeplink`, {
|
|
578
677
|
method: "POST",
|
|
579
678
|
headers: {
|
|
580
679
|
"Content-Type": "application/json",
|
|
@@ -597,7 +696,7 @@ async function getAddressBalance(address, chainType, chainId, tokenAddress, publ
|
|
|
597
696
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
598
697
|
validatePublishableKey(pk);
|
|
599
698
|
const url = `${API_BASE_URL}/v1/public/addresses/balance`;
|
|
600
|
-
const response = await
|
|
699
|
+
const response = await apiFetch(url, {
|
|
601
700
|
method: "POST",
|
|
602
701
|
headers: {
|
|
603
702
|
"Content-Type": "application/json",
|
|
@@ -620,7 +719,7 @@ async function getAddressBalance(address, chainType, chainId, tokenAddress, publ
|
|
|
620
719
|
async function verifyRecipientAddress(request, publishableKey) {
|
|
621
720
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
622
721
|
validatePublishableKey(pk);
|
|
623
|
-
const response = await
|
|
722
|
+
const response = await apiFetch(`${API_BASE_URL}/v1/public/addresses/verify`, {
|
|
624
723
|
method: "POST",
|
|
625
724
|
headers: {
|
|
626
725
|
accept: "application/json",
|
|
@@ -646,7 +745,7 @@ async function verifyRecipientAddress(request, publishableKey) {
|
|
|
646
745
|
async function checkHypercoreActivation(request, publishableKey) {
|
|
647
746
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
648
747
|
validatePublishableKey(pk);
|
|
649
|
-
const response = await
|
|
748
|
+
const response = await apiFetch(`${API_BASE_URL}/v1/public/addresses/hypercore/activation`, {
|
|
650
749
|
method: "POST",
|
|
651
750
|
headers: {
|
|
652
751
|
accept: "application/json",
|
|
@@ -669,7 +768,7 @@ async function getExchanges(query, publishableKey) {
|
|
|
669
768
|
if (query?.destination_network) params.append("destination_network", query.destination_network);
|
|
670
769
|
const queryString = params.toString();
|
|
671
770
|
const url = `${API_BASE_URL}/v1/public/onramps/exchanges${queryString ? `?${queryString}` : ""}`;
|
|
672
|
-
const response = await
|
|
771
|
+
const response = await apiFetch(url, {
|
|
673
772
|
method: "GET",
|
|
674
773
|
headers: {
|
|
675
774
|
accept: "application/json",
|
|
@@ -685,7 +784,7 @@ async function getExchanges(query, publishableKey) {
|
|
|
685
784
|
async function createExchangeSession(request, publishableKey) {
|
|
686
785
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
687
786
|
validatePublishableKey(pk);
|
|
688
|
-
const response = await
|
|
787
|
+
const response = await apiFetch(`${API_BASE_URL}/v1/public/onramps/exchanges/sessions`, {
|
|
689
788
|
method: "POST",
|
|
690
789
|
headers: {
|
|
691
790
|
accept: "application/json",
|
|
@@ -723,7 +822,7 @@ function getExchangeSessionStartUrl(request, publishableKey) {
|
|
|
723
822
|
async function getIntegrationExchanges(publishableKey) {
|
|
724
823
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
725
824
|
validatePublishableKey(pk);
|
|
726
|
-
const response = await
|
|
825
|
+
const response = await apiFetch(`${API_BASE_URL}/v1/public/integrations/oauth/exchanges`, {
|
|
727
826
|
method: "GET",
|
|
728
827
|
headers: {
|
|
729
828
|
accept: "application/json",
|
|
@@ -738,7 +837,7 @@ async function getIntegrationExchanges(publishableKey) {
|
|
|
738
837
|
async function startIntegrationOAuth(publishableKey) {
|
|
739
838
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
740
839
|
validatePublishableKey(pk);
|
|
741
|
-
const response = await
|
|
840
|
+
const response = await apiFetch(`${API_BASE_URL}/v1/public/integrations/oauth/coinbase/start`, {
|
|
742
841
|
method: "POST",
|
|
743
842
|
headers: {
|
|
744
843
|
accept: "application/json",
|
|
@@ -758,7 +857,7 @@ var IntegrationProvider = /* @__PURE__ */ ((IntegrationProvider2) => {
|
|
|
758
857
|
async function authenticateIntegrationOAuth(params, publishableKey) {
|
|
759
858
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
760
859
|
validatePublishableKey(pk);
|
|
761
|
-
const response = await
|
|
860
|
+
const response = await apiFetch(`${API_BASE_URL}/v1/public/integrations/oauth/authenticate`, {
|
|
762
861
|
method: "POST",
|
|
763
862
|
headers: {
|
|
764
863
|
accept: "application/json",
|
|
@@ -775,7 +874,7 @@ async function authenticateIntegrationOAuth(params, publishableKey) {
|
|
|
775
874
|
async function refreshIntegrationToken(accessToken, publishableKey) {
|
|
776
875
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
777
876
|
validatePublishableKey(pk);
|
|
778
|
-
const response = await
|
|
877
|
+
const response = await apiFetch(`${API_BASE_URL}/v1/public/integrations/token/refresh`, {
|
|
779
878
|
method: "POST",
|
|
780
879
|
headers: {
|
|
781
880
|
accept: "application/json",
|
|
@@ -792,7 +891,7 @@ async function refreshIntegrationToken(accessToken, publishableKey) {
|
|
|
792
891
|
async function revokeIntegrationToken(accessToken, publishableKey) {
|
|
793
892
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
794
893
|
validatePublishableKey(pk);
|
|
795
|
-
await
|
|
894
|
+
await apiFetch(`${API_BASE_URL}/v1/public/integrations/token/revoke`, {
|
|
796
895
|
method: "POST",
|
|
797
896
|
headers: {
|
|
798
897
|
accept: "application/json",
|
|
@@ -806,7 +905,7 @@ async function revokeIntegrationToken(accessToken, publishableKey) {
|
|
|
806
905
|
async function getIntegrationHoldings(provider, accessToken, publishableKey) {
|
|
807
906
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
808
907
|
validatePublishableKey(pk);
|
|
809
|
-
const response = await
|
|
908
|
+
const response = await apiFetch(`${API_BASE_URL}/v1/public/integrations/holdings`, {
|
|
810
909
|
method: "POST",
|
|
811
910
|
headers: {
|
|
812
911
|
accept: "application/json",
|
|
@@ -826,7 +925,7 @@ async function getIntegrationHoldings(provider, accessToken, publishableKey) {
|
|
|
826
925
|
async function createIntegrationTransfer(params, publishableKey) {
|
|
827
926
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
828
927
|
validatePublishableKey(pk);
|
|
829
|
-
const response = await
|
|
928
|
+
const response = await apiFetch(`${API_BASE_URL}/v1/public/integrations/transfers`, {
|
|
830
929
|
method: "POST",
|
|
831
930
|
headers: {
|
|
832
931
|
accept: "application/json",
|
|
@@ -846,7 +945,7 @@ async function confirmIntegrationTransfer(transferId, accessToken, mfaCode, publ
|
|
|
846
945
|
validatePublishableKey(pk);
|
|
847
946
|
const body = { access_token: accessToken };
|
|
848
947
|
if (mfaCode) body.mfa_code = mfaCode;
|
|
849
|
-
const response = await
|
|
948
|
+
const response = await apiFetch(
|
|
850
949
|
`${API_BASE_URL}/v1/public/integrations/transfers/${transferId}/confirm`,
|
|
851
950
|
{
|
|
852
951
|
method: "POST",
|
|
@@ -867,15 +966,18 @@ async function confirmIntegrationTransfer(transferId, accessToken, mfaCode, publ
|
|
|
867
966
|
async function getIntegrationTransferDefaultToken(params, publishableKey) {
|
|
868
967
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
869
968
|
validatePublishableKey(pk);
|
|
870
|
-
const response = await
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
969
|
+
const response = await apiFetch(
|
|
970
|
+
`${API_BASE_URL}/v1/public/integrations/transfers/default_token`,
|
|
971
|
+
{
|
|
972
|
+
method: "POST",
|
|
973
|
+
headers: {
|
|
974
|
+
accept: "application/json",
|
|
975
|
+
"x-publishable-key": pk,
|
|
976
|
+
"Content-Type": "application/json"
|
|
977
|
+
},
|
|
978
|
+
body: JSON.stringify(params)
|
|
979
|
+
}
|
|
980
|
+
);
|
|
879
981
|
if (!response.ok) {
|
|
880
982
|
const err = await response.json().catch(() => ({ message: response.statusText }));
|
|
881
983
|
throw new Error(`Failed to get transfer default token: ${err.message || response.statusText}`);
|
|
@@ -885,7 +987,7 @@ async function getIntegrationTransferDefaultToken(params, publishableKey) {
|
|
|
885
987
|
async function buildSolanaTransaction(request, publishableKey) {
|
|
886
988
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
887
989
|
validatePublishableKey(pk);
|
|
888
|
-
const response = await
|
|
990
|
+
const response = await apiFetch(`${API_BASE_URL}/v1/public/transactions/solana/build`, {
|
|
889
991
|
method: "POST",
|
|
890
992
|
headers: {
|
|
891
993
|
accept: "application/json",
|
|
@@ -903,7 +1005,7 @@ async function buildSolanaTransaction(request, publishableKey) {
|
|
|
903
1005
|
async function sendSolanaTransaction(request, publishableKey) {
|
|
904
1006
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
905
1007
|
validatePublishableKey(pk);
|
|
906
|
-
const response = await
|
|
1008
|
+
const response = await apiFetch(`${API_BASE_URL}/v1/public/transactions/solana/send`, {
|
|
907
1009
|
method: "POST",
|
|
908
1010
|
headers: {
|
|
909
1011
|
accept: "application/json",
|
|
@@ -921,7 +1023,7 @@ async function sendSolanaTransaction(request, publishableKey) {
|
|
|
921
1023
|
async function retrievePaymentIntent(clientSecret, publishableKey) {
|
|
922
1024
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
923
1025
|
validatePublishableKey(pk);
|
|
924
|
-
const response = await
|
|
1026
|
+
const response = await apiFetch(`${API_BASE_URL}/v1/public/payment_intents/retrieve`, {
|
|
925
1027
|
method: "POST",
|
|
926
1028
|
headers: {
|
|
927
1029
|
accept: "application/json",
|
|
@@ -939,7 +1041,7 @@ async function retrievePaymentIntent(clientSecret, publishableKey) {
|
|
|
939
1041
|
async function listPaymentIntentExecutions(clientSecret, publishableKey) {
|
|
940
1042
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
941
1043
|
validatePublishableKey(pk);
|
|
942
|
-
const response = await
|
|
1044
|
+
const response = await apiFetch(`${API_BASE_URL}/v1/public/payment_intents/executions`, {
|
|
943
1045
|
method: "POST",
|
|
944
1046
|
headers: {
|
|
945
1047
|
accept: "application/json",
|
|
@@ -959,7 +1061,7 @@ async function listPaymentIntentExecutions(clientSecret, publishableKey) {
|
|
|
959
1061
|
async function getDepositQuote(request, publishableKey) {
|
|
960
1062
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
961
1063
|
validatePublishableKey(pk);
|
|
962
|
-
const response = await
|
|
1064
|
+
const response = await apiFetch(`${API_BASE_URL}/v1/public/quotes`, {
|
|
963
1065
|
method: "POST",
|
|
964
1066
|
headers: {
|
|
965
1067
|
accept: "application/json",
|
|
@@ -978,7 +1080,7 @@ async function getDepositQuote(request, publishableKey) {
|
|
|
978
1080
|
async function buildHypercoreTransaction(request, publishableKey) {
|
|
979
1081
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
980
1082
|
validatePublishableKey(pk);
|
|
981
|
-
const response = await
|
|
1083
|
+
const response = await apiFetch(`${API_BASE_URL}/v1/public/transactions/hypercore/build`, {
|
|
982
1084
|
method: "POST",
|
|
983
1085
|
headers: {
|
|
984
1086
|
accept: "application/json",
|
|
@@ -998,7 +1100,7 @@ async function buildHypercoreTransaction(request, publishableKey) {
|
|
|
998
1100
|
async function getCashAppLimits(currency = "usd", publishableKey) {
|
|
999
1101
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1000
1102
|
validatePublishableKey(pk);
|
|
1001
|
-
const response = await
|
|
1103
|
+
const response = await apiFetch(
|
|
1002
1104
|
`${API_BASE_URL}/v1/public/onramps/cashapp/limits?currency=${encodeURIComponent(currency)}`,
|
|
1003
1105
|
{
|
|
1004
1106
|
method: "GET",
|
|
@@ -1017,7 +1119,7 @@ async function getCashAppLimits(currency = "usd", publishableKey) {
|
|
|
1017
1119
|
async function createCashAppSession(request, publishableKey) {
|
|
1018
1120
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1019
1121
|
validatePublishableKey(pk);
|
|
1020
|
-
const response = await
|
|
1122
|
+
const response = await apiFetch(`${API_BASE_URL}/v1/public/onramps/cashapp/sessions`, {
|
|
1021
1123
|
method: "POST",
|
|
1022
1124
|
headers: {
|
|
1023
1125
|
accept: "application/json",
|
|
@@ -1035,7 +1137,7 @@ async function createCashAppSession(request, publishableKey) {
|
|
|
1035
1137
|
async function getCashAppSessionStatus(externalId, publishableKey) {
|
|
1036
1138
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1037
1139
|
validatePublishableKey(pk);
|
|
1038
|
-
const response = await
|
|
1140
|
+
const response = await apiFetch(
|
|
1039
1141
|
`${API_BASE_URL}/v1/public/onramps/cashapp/sessions/${encodeURIComponent(externalId)}/status`,
|
|
1040
1142
|
{
|
|
1041
1143
|
method: "GET",
|
|
@@ -1063,7 +1165,7 @@ async function stripeGetDefaultToken(params, publishableKey) {
|
|
|
1063
1165
|
});
|
|
1064
1166
|
if (params.countryCode) query.append("country_code", params.countryCode);
|
|
1065
1167
|
if (params.subdivisionCode) query.append("subdivision_code", params.subdivisionCode);
|
|
1066
|
-
const response = await
|
|
1168
|
+
const response = await apiFetch(
|
|
1067
1169
|
`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/default_token?${query.toString()}`,
|
|
1068
1170
|
{
|
|
1069
1171
|
method: "GET",
|
|
@@ -1104,7 +1206,7 @@ function throwStripeError(prefix, response, error) {
|
|
|
1104
1206
|
async function stripeGetConfig(publishableKey) {
|
|
1105
1207
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1106
1208
|
validatePublishableKey(pk);
|
|
1107
|
-
const response = await
|
|
1209
|
+
const response = await apiFetch(`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/config`, {
|
|
1108
1210
|
method: "GET",
|
|
1109
1211
|
headers: {
|
|
1110
1212
|
accept: "application/json",
|
|
@@ -1120,7 +1222,7 @@ async function stripeGetConfig(publishableKey) {
|
|
|
1120
1222
|
async function stripeCreateAuthIntent(email, publishableKey) {
|
|
1121
1223
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1122
1224
|
validatePublishableKey(pk);
|
|
1123
|
-
const response = await
|
|
1225
|
+
const response = await apiFetch(`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/oauth/start`, {
|
|
1124
1226
|
method: "POST",
|
|
1125
1227
|
headers: {
|
|
1126
1228
|
accept: "application/json",
|
|
@@ -1135,17 +1237,20 @@ async function stripeCreateAuthIntent(email, publishableKey) {
|
|
|
1135
1237
|
}
|
|
1136
1238
|
return response.json();
|
|
1137
1239
|
}
|
|
1138
|
-
async function stripeExchangeTokens(authIntentId, publishableKey) {
|
|
1240
|
+
async function stripeExchangeTokens(authIntentId, publishableKey, cryptoCustomerId) {
|
|
1139
1241
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1140
1242
|
validatePublishableKey(pk);
|
|
1141
|
-
const response = await
|
|
1243
|
+
const response = await apiFetch(`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/oauth/token`, {
|
|
1142
1244
|
method: "POST",
|
|
1143
1245
|
headers: {
|
|
1144
1246
|
accept: "application/json",
|
|
1145
1247
|
"x-publishable-key": pk,
|
|
1146
1248
|
"Content-Type": "application/json"
|
|
1147
1249
|
},
|
|
1148
|
-
body: JSON.stringify({
|
|
1250
|
+
body: JSON.stringify({
|
|
1251
|
+
auth_intent_id: authIntentId,
|
|
1252
|
+
...cryptoCustomerId ? { crypto_customer_id: cryptoCustomerId } : {}
|
|
1253
|
+
})
|
|
1149
1254
|
});
|
|
1150
1255
|
if (!response.ok) {
|
|
1151
1256
|
const error = await response.json().catch(() => ({ message: response.statusText }));
|
|
@@ -1156,7 +1261,7 @@ async function stripeExchangeTokens(authIntentId, publishableKey) {
|
|
|
1156
1261
|
async function stripeRefreshToken(refreshToken, publishableKey) {
|
|
1157
1262
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1158
1263
|
validatePublishableKey(pk);
|
|
1159
|
-
const response = await
|
|
1264
|
+
const response = await apiFetch(`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/oauth/token/refresh`, {
|
|
1160
1265
|
method: "POST",
|
|
1161
1266
|
headers: {
|
|
1162
1267
|
accept: "application/json",
|
|
@@ -1174,7 +1279,7 @@ async function stripeRefreshToken(refreshToken, publishableKey) {
|
|
|
1174
1279
|
async function stripeGetCustomer(customerId, oauthToken, publishableKey) {
|
|
1175
1280
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1176
1281
|
validatePublishableKey(pk);
|
|
1177
|
-
const response = await
|
|
1282
|
+
const response = await apiFetch(
|
|
1178
1283
|
`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/customers/${encodeURIComponent(customerId)}`,
|
|
1179
1284
|
{
|
|
1180
1285
|
method: "GET",
|
|
@@ -1194,7 +1299,7 @@ async function stripeGetCustomer(customerId, oauthToken, publishableKey) {
|
|
|
1194
1299
|
async function stripeListWallets(customerId, oauthToken, publishableKey) {
|
|
1195
1300
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1196
1301
|
validatePublishableKey(pk);
|
|
1197
|
-
const response = await
|
|
1302
|
+
const response = await apiFetch(
|
|
1198
1303
|
`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/customers/${encodeURIComponent(customerId)}/wallet_addresses`,
|
|
1199
1304
|
{
|
|
1200
1305
|
method: "GET",
|
|
@@ -1214,7 +1319,7 @@ async function stripeListWallets(customerId, oauthToken, publishableKey) {
|
|
|
1214
1319
|
async function stripeListPaymentTokens(customerId, oauthToken, publishableKey) {
|
|
1215
1320
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1216
1321
|
validatePublishableKey(pk);
|
|
1217
|
-
const response = await
|
|
1322
|
+
const response = await apiFetch(
|
|
1218
1323
|
`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/customers/${encodeURIComponent(customerId)}/payment_tokens`,
|
|
1219
1324
|
{
|
|
1220
1325
|
method: "GET",
|
|
@@ -1236,7 +1341,7 @@ async function stripeListPaymentTokens(customerId, oauthToken, publishableKey) {
|
|
|
1236
1341
|
async function stripeCreateSession(request, oauthToken, publishableKey) {
|
|
1237
1342
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1238
1343
|
validatePublishableKey(pk);
|
|
1239
|
-
const response = await
|
|
1344
|
+
const response = await apiFetch(`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/sessions`, {
|
|
1240
1345
|
method: "POST",
|
|
1241
1346
|
headers: {
|
|
1242
1347
|
accept: "application/json",
|
|
@@ -1263,7 +1368,7 @@ async function stripeCreateSession(request, oauthToken, publishableKey) {
|
|
|
1263
1368
|
async function stripeConfirmSession(sessionId, oauthToken, request, publishableKey) {
|
|
1264
1369
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1265
1370
|
validatePublishableKey(pk);
|
|
1266
|
-
const response = await
|
|
1371
|
+
const response = await apiFetch(
|
|
1267
1372
|
`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/sessions/${encodeURIComponent(sessionId)}/confirm`,
|
|
1268
1373
|
{
|
|
1269
1374
|
method: "POST",
|
|
@@ -1285,7 +1390,7 @@ async function stripeConfirmSession(sessionId, oauthToken, request, publishableK
|
|
|
1285
1390
|
async function stripeRefreshQuote(sessionId, oauthToken, publishableKey) {
|
|
1286
1391
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1287
1392
|
validatePublishableKey(pk);
|
|
1288
|
-
const response = await
|
|
1393
|
+
const response = await apiFetch(
|
|
1289
1394
|
`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/sessions/${encodeURIComponent(sessionId)}/quote/refresh`,
|
|
1290
1395
|
{
|
|
1291
1396
|
method: "POST",
|
|
@@ -1305,7 +1410,7 @@ async function stripeRefreshQuote(sessionId, oauthToken, publishableKey) {
|
|
|
1305
1410
|
async function stripeGetSession(sessionId, oauthToken, publishableKey) {
|
|
1306
1411
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1307
1412
|
validatePublishableKey(pk);
|
|
1308
|
-
const response = await
|
|
1413
|
+
const response = await apiFetch(
|
|
1309
1414
|
`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/sessions/${encodeURIComponent(sessionId)}`,
|
|
1310
1415
|
{
|
|
1311
1416
|
method: "GET",
|
|
@@ -1331,7 +1436,7 @@ async function stripeGetQuotes(request, oauthToken, publishableKey) {
|
|
|
1331
1436
|
"Content-Type": "application/json"
|
|
1332
1437
|
};
|
|
1333
1438
|
if (oauthToken) headers["x-stripe-oauth-token"] = oauthToken;
|
|
1334
|
-
const response = await
|
|
1439
|
+
const response = await apiFetch(`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/quotes`, {
|
|
1335
1440
|
method: "POST",
|
|
1336
1441
|
headers,
|
|
1337
1442
|
body: JSON.stringify({
|
|
@@ -1357,7 +1462,7 @@ async function stripeGetTransactionLimits(params, oauthToken, publishableKey) {
|
|
|
1357
1462
|
});
|
|
1358
1463
|
if (params.destinationTag) query.append("destination_tag", params.destinationTag);
|
|
1359
1464
|
if (params.refresh) query.append("refresh", "true");
|
|
1360
|
-
const response = await
|
|
1465
|
+
const response = await apiFetch(
|
|
1361
1466
|
`${API_BASE_URL}${HEADLESS_STRIPE_BASE}/transaction_limits?${query.toString()}`,
|
|
1362
1467
|
{
|
|
1363
1468
|
method: "GET",
|
|
@@ -1377,7 +1482,7 @@ async function stripeGetTransactionLimits(params, oauthToken, publishableKey) {
|
|
|
1377
1482
|
async function sendHypercoreTransaction(request, publishableKey) {
|
|
1378
1483
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1379
1484
|
validatePublishableKey(pk);
|
|
1380
|
-
const response = await
|
|
1485
|
+
const response = await apiFetch(`${API_BASE_URL}/v1/public/transactions/hypercore/send`, {
|
|
1381
1486
|
method: "POST",
|
|
1382
1487
|
headers: {
|
|
1383
1488
|
accept: "application/json",
|
|
@@ -1397,7 +1502,7 @@ async function sendHypercoreTransaction(request, publishableKey) {
|
|
|
1397
1502
|
async function getCoinbaseLegalAgreements(publishableKey) {
|
|
1398
1503
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1399
1504
|
validatePublishableKey(pk);
|
|
1400
|
-
const response = await
|
|
1505
|
+
const response = await apiFetch(
|
|
1401
1506
|
`${API_BASE_URL}/v1/public/onramps/headless/coinbase/legal_agreements`,
|
|
1402
1507
|
{
|
|
1403
1508
|
method: "GET",
|
|
@@ -1422,7 +1527,7 @@ async function jsonOrThrow(response, label) {
|
|
|
1422
1527
|
async function createOnrampVerificationSession(request, publishableKey) {
|
|
1423
1528
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1424
1529
|
validatePublishableKey(pk);
|
|
1425
|
-
const response = await
|
|
1530
|
+
const response = await apiFetch(`${API_BASE_URL}${VERIFICATION_BASE}`, {
|
|
1426
1531
|
method: "POST",
|
|
1427
1532
|
headers: {
|
|
1428
1533
|
accept: "application/json",
|
|
@@ -1436,7 +1541,7 @@ async function createOnrampVerificationSession(request, publishableKey) {
|
|
|
1436
1541
|
async function postVerificationAction(id, factor, action, body, publishableKey) {
|
|
1437
1542
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1438
1543
|
validatePublishableKey(pk);
|
|
1439
|
-
const response = await
|
|
1544
|
+
const response = await apiFetch(
|
|
1440
1545
|
`${API_BASE_URL}${VERIFICATION_BASE}/${encodeURIComponent(id)}/${factor}/${action}`,
|
|
1441
1546
|
{
|
|
1442
1547
|
method: "POST",
|
|
@@ -1471,7 +1576,7 @@ async function verifyOnrampVerificationOtp(id, factor, clientSecret, code, publi
|
|
|
1471
1576
|
async function exchangeOnrampVerificationToken(id, clientSecret, publishableKey) {
|
|
1472
1577
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1473
1578
|
validatePublishableKey(pk);
|
|
1474
|
-
const response = await
|
|
1579
|
+
const response = await apiFetch(
|
|
1475
1580
|
`${API_BASE_URL}${VERIFICATION_BASE}/${encodeURIComponent(id)}/token`,
|
|
1476
1581
|
{
|
|
1477
1582
|
method: "POST",
|
|
@@ -1493,100 +1598,157 @@ async function getOnrampVerificationSession(id, clientSecret, publishableKey) {
|
|
|
1493
1598
|
validatePublishableKey(pk);
|
|
1494
1599
|
const url = new URL(`${API_BASE_URL}${VERIFICATION_BASE}/${encodeURIComponent(id)}`);
|
|
1495
1600
|
url.searchParams.set("client_secret", clientSecret);
|
|
1496
|
-
const response = await
|
|
1601
|
+
const response = await apiFetch(url.toString(), {
|
|
1497
1602
|
method: "GET",
|
|
1498
1603
|
headers: { accept: "application/json", "x-publishable-key": pk }
|
|
1499
1604
|
});
|
|
1500
1605
|
return jsonOrThrow(response, "Failed to fetch verification session");
|
|
1501
1606
|
}
|
|
1502
|
-
|
|
1607
|
+
var WALLET_PAY_LABEL = {
|
|
1608
|
+
apple_pay: "Apple Pay",
|
|
1609
|
+
google_pay: "Google Pay"
|
|
1610
|
+
};
|
|
1611
|
+
function isWalletPayLimitReached(response) {
|
|
1503
1612
|
return response.limits.some((l) => l.remaining === "0");
|
|
1504
1613
|
}
|
|
1505
|
-
function
|
|
1614
|
+
function getWalletPayLimitUpgradeStatus(response) {
|
|
1506
1615
|
const opt = response.limit_upgrade_options?.[0];
|
|
1507
1616
|
if (!opt || typeof opt.status !== "string") return null;
|
|
1508
1617
|
return opt.status;
|
|
1509
1618
|
}
|
|
1510
|
-
|
|
1619
|
+
var isApplePayLimitReached = isWalletPayLimitReached;
|
|
1620
|
+
var isGooglePayLimitReached = isWalletPayLimitReached;
|
|
1621
|
+
var getApplePayLimitUpgradeStatus = getWalletPayLimitUpgradeStatus;
|
|
1622
|
+
var getGooglePayLimitUpgradeStatus = getWalletPayLimitUpgradeStatus;
|
|
1623
|
+
async function getCoinbaseWalletPayLimits(phone, publishableKey, signal) {
|
|
1511
1624
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1512
1625
|
validatePublishableKey(pk);
|
|
1513
|
-
const
|
|
1514
|
-
|
|
1515
|
-
{
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1626
|
+
const init = {
|
|
1627
|
+
method: "POST",
|
|
1628
|
+
headers: {
|
|
1629
|
+
accept: "application/json",
|
|
1630
|
+
"x-publishable-key": pk,
|
|
1631
|
+
"Content-Type": "application/json"
|
|
1632
|
+
},
|
|
1633
|
+
body: JSON.stringify({ phone }),
|
|
1634
|
+
signal
|
|
1635
|
+
};
|
|
1636
|
+
const base = `${API_BASE_URL}/v1/public/onramps/headless/coinbase`;
|
|
1637
|
+
const response = await fetchWalletPayRoute(
|
|
1638
|
+
{ url: `${base}/limits`, init },
|
|
1639
|
+
{ url: `${base}/apple_pay/limits`, init }
|
|
1525
1640
|
);
|
|
1526
|
-
const raw = await jsonOrThrow(response, "Failed to fetch
|
|
1641
|
+
const raw = await jsonOrThrow(response, "Failed to fetch guest checkout limits");
|
|
1527
1642
|
return {
|
|
1528
1643
|
limits: raw.limits,
|
|
1529
1644
|
limit_upgrade_options: raw.limit_upgrade_options,
|
|
1530
|
-
limit_reached:
|
|
1531
|
-
upgrade_status:
|
|
1645
|
+
limit_reached: isWalletPayLimitReached(raw),
|
|
1646
|
+
upgrade_status: getWalletPayLimitUpgradeStatus(raw)
|
|
1532
1647
|
};
|
|
1533
1648
|
}
|
|
1534
|
-
|
|
1649
|
+
var getCoinbaseApplePayLimits = getCoinbaseWalletPayLimits;
|
|
1650
|
+
async function requestCoinbaseWalletPayLimitUpgrade(request, publishableKey, signal) {
|
|
1535
1651
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1536
1652
|
validatePublishableKey(pk);
|
|
1537
|
-
const
|
|
1538
|
-
|
|
1539
|
-
{
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1653
|
+
const init = {
|
|
1654
|
+
method: "POST",
|
|
1655
|
+
headers: {
|
|
1656
|
+
accept: "application/json",
|
|
1657
|
+
"x-publishable-key": pk,
|
|
1658
|
+
"Content-Type": "application/json"
|
|
1659
|
+
},
|
|
1660
|
+
body: JSON.stringify(request),
|
|
1661
|
+
signal
|
|
1662
|
+
};
|
|
1663
|
+
const base = `${API_BASE_URL}/v1/public/onramps/headless/coinbase`;
|
|
1664
|
+
const response = await fetchWalletPayRoute(
|
|
1665
|
+
{ url: `${base}/limits/upgrade`, init },
|
|
1666
|
+
{ url: `${base}/apple_pay/limits/upgrade`, init }
|
|
1549
1667
|
);
|
|
1550
1668
|
return jsonOrThrow(
|
|
1551
1669
|
response,
|
|
1552
|
-
"Failed to request
|
|
1670
|
+
"Failed to request a guest checkout limit upgrade"
|
|
1553
1671
|
);
|
|
1554
1672
|
}
|
|
1555
|
-
|
|
1673
|
+
var requestCoinbaseApplePayLimitUpgrade = requestCoinbaseWalletPayLimitUpgrade;
|
|
1674
|
+
async function createCoinbaseWalletPaySession(method, request, onrampToken, publishableKey, signal) {
|
|
1556
1675
|
const pk = publishableKey || DEFAULT_PUBLISHABLE_KEY;
|
|
1557
1676
|
validatePublishableKey(pk);
|
|
1558
|
-
const
|
|
1559
|
-
|
|
1677
|
+
const headers = {
|
|
1678
|
+
accept: "application/json",
|
|
1679
|
+
"x-publishable-key": pk,
|
|
1680
|
+
"Content-Type": "application/json",
|
|
1681
|
+
"x-onramp-token": onrampToken
|
|
1682
|
+
};
|
|
1683
|
+
const { payment_method_type: _unused, ...fields } = request;
|
|
1684
|
+
const base = `${API_BASE_URL}/v1/public/onramps/headless/coinbase`;
|
|
1685
|
+
const response = await fetchWalletPayRoute(
|
|
1560
1686
|
{
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
}
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1687
|
+
url: `${base}/sessions`,
|
|
1688
|
+
init: {
|
|
1689
|
+
method: "POST",
|
|
1690
|
+
headers,
|
|
1691
|
+
body: JSON.stringify({ ...fields, payment_method_type: method }),
|
|
1692
|
+
signal
|
|
1693
|
+
}
|
|
1694
|
+
},
|
|
1695
|
+
method === "apple_pay" ? {
|
|
1696
|
+
url: `${base}/apple_pay/sessions`,
|
|
1697
|
+
init: { method: "POST", headers, body: JSON.stringify(fields), signal }
|
|
1698
|
+
} : null
|
|
1571
1699
|
);
|
|
1572
1700
|
return jsonOrThrow(
|
|
1573
1701
|
response,
|
|
1574
|
-
|
|
1702
|
+
`Failed to create ${WALLET_PAY_LABEL[method]} session`
|
|
1575
1703
|
);
|
|
1576
1704
|
}
|
|
1705
|
+
function createCoinbaseApplePaySession(request, onrampToken, publishableKey, signal) {
|
|
1706
|
+
return createCoinbaseWalletPaySession("apple_pay", request, onrampToken, publishableKey, signal);
|
|
1707
|
+
}
|
|
1708
|
+
function createCoinbaseGooglePaySession(request, onrampToken, publishableKey, signal) {
|
|
1709
|
+
return createCoinbaseWalletPaySession("google_pay", request, onrampToken, publishableKey, signal);
|
|
1710
|
+
}
|
|
1577
1711
|
|
|
1578
1712
|
// src/lib/events.ts
|
|
1579
1713
|
var DepositEventType = /* @__PURE__ */ ((DepositEventType2) => {
|
|
1580
1714
|
DepositEventType2["ONRAMP_SESSION_CREATED"] = "onramp_session.created";
|
|
1581
1715
|
DepositEventType2["DIRECT_EXECUTION_SUCCEEDED"] = "direct_execution.succeeded";
|
|
1716
|
+
DepositEventType2["DIRECT_EXECUTION_FAILED"] = "direct_execution.failed";
|
|
1717
|
+
DepositEventType2["METHOD_SELECTED"] = "deposit.method_selected";
|
|
1718
|
+
DepositEventType2["TOKEN_SELECTED"] = "deposit.token_selected";
|
|
1719
|
+
DepositEventType2["WALLET_SELECTED"] = "deposit.wallet_selected";
|
|
1720
|
+
DepositEventType2["PROVIDER_SELECTED"] = "deposit.provider_selected";
|
|
1721
|
+
DepositEventType2["VERIFICATION_STARTED"] = "deposit.verification_started";
|
|
1722
|
+
DepositEventType2["VERIFICATION_COMPLETED"] = "deposit.verification_completed";
|
|
1723
|
+
DepositEventType2["VERIFICATION_FAILED"] = "deposit.verification_failed";
|
|
1724
|
+
DepositEventType2["ACCOUNT_CONNECTION_STARTED"] = "deposit.account_connection_started";
|
|
1725
|
+
DepositEventType2["ACCOUNT_CONNECTED"] = "deposit.account_connected";
|
|
1726
|
+
DepositEventType2["ACCOUNT_CONNECTION_FAILED"] = "deposit.account_connection_failed";
|
|
1727
|
+
DepositEventType2["WALLET_CONNECTION_STARTED"] = "deposit.wallet_connection_started";
|
|
1728
|
+
DepositEventType2["WALLET_CONNECTED"] = "deposit.wallet_connected";
|
|
1729
|
+
DepositEventType2["WALLET_CONNECTION_FAILED"] = "deposit.wallet_connection_failed";
|
|
1730
|
+
DepositEventType2["FLOW_STARTED"] = "deposit.flow_started";
|
|
1731
|
+
DepositEventType2["FLOW_FAILED"] = "deposit.flow_failed";
|
|
1732
|
+
DepositEventType2["LIMIT_REACHED"] = "deposit.limit_reached";
|
|
1582
1733
|
return DepositEventType2;
|
|
1583
1734
|
})(DepositEventType || {});
|
|
1584
1735
|
var WithdrawEventType = /* @__PURE__ */ ((WithdrawEventType2) => {
|
|
1585
1736
|
WithdrawEventType2["DIRECT_EXECUTION_SUCCEEDED"] = "direct_execution.succeeded";
|
|
1737
|
+
WithdrawEventType2["DIRECT_EXECUTION_FAILED"] = "direct_execution.failed";
|
|
1738
|
+
WithdrawEventType2["TOKEN_SELECTED"] = "withdraw.token_selected";
|
|
1739
|
+
WithdrawEventType2["FLOW_STARTED"] = "withdraw.flow_started";
|
|
1586
1740
|
return WithdrawEventType2;
|
|
1587
1741
|
})(WithdrawEventType || {});
|
|
1588
1742
|
var CheckoutEventType = /* @__PURE__ */ ((CheckoutEventType2) => {
|
|
1589
1743
|
CheckoutEventType2["PAYMENT_INTENT_SUCCEEDED"] = "payment_intent.succeeded";
|
|
1744
|
+
CheckoutEventType2["METHOD_SELECTED"] = "checkout.method_selected";
|
|
1745
|
+
CheckoutEventType2["TOKEN_SELECTED"] = "checkout.token_selected";
|
|
1746
|
+
CheckoutEventType2["WALLET_SELECTED"] = "checkout.wallet_selected";
|
|
1747
|
+
CheckoutEventType2["WALLET_CONNECTION_STARTED"] = "checkout.wallet_connection_started";
|
|
1748
|
+
CheckoutEventType2["WALLET_CONNECTED"] = "checkout.wallet_connected";
|
|
1749
|
+
CheckoutEventType2["WALLET_CONNECTION_FAILED"] = "checkout.wallet_connection_failed";
|
|
1750
|
+
CheckoutEventType2["FLOW_STARTED"] = "checkout.flow_started";
|
|
1751
|
+
CheckoutEventType2["FLOW_FAILED"] = "checkout.flow_failed";
|
|
1590
1752
|
return CheckoutEventType2;
|
|
1591
1753
|
})(CheckoutEventType || {});
|
|
1592
1754
|
|
|
@@ -2566,6 +2728,8 @@ export {
|
|
|
2566
2728
|
confirmIntegrationTransfer,
|
|
2567
2729
|
createCashAppSession,
|
|
2568
2730
|
createCoinbaseApplePaySession,
|
|
2731
|
+
createCoinbaseGooglePaySession,
|
|
2732
|
+
createCoinbaseWalletPaySession,
|
|
2569
2733
|
createDepositAddress,
|
|
2570
2734
|
createExchangeSession,
|
|
2571
2735
|
createIntegrationTransfer,
|
|
@@ -2587,6 +2751,7 @@ export {
|
|
|
2587
2751
|
getChainName,
|
|
2588
2752
|
getCoinbaseApplePayLimits,
|
|
2589
2753
|
getCoinbaseLegalAgreements,
|
|
2754
|
+
getCoinbaseWalletPayLimits,
|
|
2590
2755
|
getDefaultOnrampToken,
|
|
2591
2756
|
getDepositAddress,
|
|
2592
2757
|
getDepositQuote,
|
|
@@ -2595,6 +2760,8 @@ export {
|
|
|
2595
2760
|
getExternalWallets,
|
|
2596
2761
|
getFiatCurrencies,
|
|
2597
2762
|
getFiatExchangeRates,
|
|
2763
|
+
getGooglePayLimitUpgradeStatus,
|
|
2764
|
+
getGooglePayProviders,
|
|
2598
2765
|
getIconUrl,
|
|
2599
2766
|
getIconUrlWithCdn,
|
|
2600
2767
|
getIntegrationExchanges,
|
|
@@ -2613,9 +2780,13 @@ export {
|
|
|
2613
2780
|
getTokenMetadata,
|
|
2614
2781
|
getWalletByChainType,
|
|
2615
2782
|
getWalletMobileDeepLink,
|
|
2783
|
+
getWalletPayLimitUpgradeStatus,
|
|
2784
|
+
getWalletPayProviders,
|
|
2616
2785
|
i18n,
|
|
2617
2786
|
isApplePayLimitReached,
|
|
2618
2787
|
isDepositAddressValidationError,
|
|
2788
|
+
isGooglePayLimitReached,
|
|
2789
|
+
isWalletPayLimitReached,
|
|
2619
2790
|
listPaymentIntentExecutions,
|
|
2620
2791
|
mapDirectExecution,
|
|
2621
2792
|
mapWalletToDepositAddress,
|
|
@@ -2623,6 +2794,7 @@ export {
|
|
|
2623
2794
|
queryExecutions,
|
|
2624
2795
|
refreshIntegrationToken,
|
|
2625
2796
|
requestCoinbaseApplePayLimitUpgrade,
|
|
2797
|
+
requestCoinbaseWalletPayLimitUpgrade,
|
|
2626
2798
|
retrievePaymentIntent,
|
|
2627
2799
|
revokeIntegrationToken,
|
|
2628
2800
|
sendHypercoreTransaction,
|