@moonpay/platform-sdk-core 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +18 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +18 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -14,7 +14,7 @@ interface ClientContext {
|
|
|
14
14
|
fetch(url: string, options?: RequestInit): Promise<Response>;
|
|
15
15
|
}
|
|
16
16
|
interface ClientContextOptions {
|
|
17
|
-
/** Base URL for the MoonPay Platform API
|
|
17
|
+
/** Base URL for the MoonPay Platform API; non-MoonPay origins fall back to the production default (DEVXP-1294). */
|
|
18
18
|
apiBaseUrl?: string;
|
|
19
19
|
}
|
|
20
20
|
declare function createClientContext(options?: ClientContextOptions): ClientContext;
|
package/dist/index.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ interface ClientContext {
|
|
|
14
14
|
fetch(url: string, options?: RequestInit): Promise<Response>;
|
|
15
15
|
}
|
|
16
16
|
interface ClientContextOptions {
|
|
17
|
-
/** Base URL for the MoonPay Platform API
|
|
17
|
+
/** Base URL for the MoonPay Platform API; non-MoonPay origins fall back to the production default (DEVXP-1294). */
|
|
18
18
|
apiBaseUrl?: string;
|
|
19
19
|
}
|
|
20
20
|
declare function createClientContext(options?: ClientContextOptions): ClientContext;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
// src/api/client-context.ts
|
|
2
|
+
var DEFAULT_API_BASE_URL = "https://api.moonpay.com";
|
|
3
|
+
function isTrustedMoonPayUrl(value) {
|
|
4
|
+
let hostname;
|
|
5
|
+
let protocol;
|
|
6
|
+
try {
|
|
7
|
+
({ hostname, protocol } = new URL(value));
|
|
8
|
+
} catch {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
if (hostname === "localhost" || hostname === "127.0.0.1")
|
|
12
|
+
return true;
|
|
13
|
+
if (protocol !== "https:")
|
|
14
|
+
return false;
|
|
15
|
+
return hostname === "moonpay.com" || hostname.endsWith(".moonpay.com") || hostname === "moonpay.dev" || hostname.endsWith(".moonpay.dev") || hostname === "moonpay-dev.com" || hostname.endsWith(".moonpay-dev.com") || hostname === "moonpaycloud.com" || hostname.endsWith(".moonpaycloud.com");
|
|
16
|
+
}
|
|
2
17
|
function createClientContext(options = {}) {
|
|
3
|
-
const
|
|
18
|
+
const apiBaseUrl = options.apiBaseUrl && isTrustedMoonPayUrl(options.apiBaseUrl) ? options.apiBaseUrl : DEFAULT_API_BASE_URL;
|
|
4
19
|
let _accessToken = "";
|
|
5
20
|
let _clientToken = "";
|
|
6
21
|
return {
|
|
@@ -17,14 +32,14 @@ function createClientContext(options = {}) {
|
|
|
17
32
|
_clientToken = token;
|
|
18
33
|
},
|
|
19
34
|
fetch(url, options2) {
|
|
35
|
+
const resolvedUrl = url.startsWith("http") ? url : `${apiBaseUrl}${url}`;
|
|
20
36
|
const headers = {
|
|
21
37
|
"Content-Type": "application/json",
|
|
22
38
|
...options2?.headers
|
|
23
39
|
};
|
|
24
|
-
if (_accessToken) {
|
|
40
|
+
if (_accessToken && isTrustedMoonPayUrl(resolvedUrl)) {
|
|
25
41
|
headers.Authorization = `Bearer ${_accessToken}`;
|
|
26
42
|
}
|
|
27
|
-
const resolvedUrl = url.startsWith("http") ? url : `${apiBaseUrl}${url}`;
|
|
28
43
|
return fetch(resolvedUrl, { ...options2, headers });
|
|
29
44
|
}
|
|
30
45
|
};
|