@moonpay/platform-sdk-core 1.6.0 → 1.7.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 CHANGED
@@ -18,9 +18,10 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod2) => __copyProps(__defProp({}, "__esModule", { value: true }), mod2);
19
19
 
20
20
  // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
23
  FRAME_PATHS: () => FRAME_PATHS,
24
+ TRUSTED_FRAME_ORIGIN_PATTERNS: () => TRUSTED_FRAME_ORIGIN_PATTERNS,
24
25
  apiFetch: () => apiFetch,
25
26
  applyThemeParam: () => applyThemeParam,
26
27
  buildFrameUrl: () => buildFrameUrl,
@@ -32,18 +33,24 @@ __export(src_exports, {
32
33
  deletePaymentMethod: () => deletePaymentMethod,
33
34
  generateKeyPair: () => generateKeyPair,
34
35
  getAssets: () => getAssets,
36
+ getCustomer: () => getCustomer,
37
+ getCustomerUploadUrl: () => getCustomerUploadUrl,
35
38
  getIdentity: () => getIdentity,
36
39
  getIdentityUploadUrl: () => getIdentityUploadUrl,
37
40
  getPaymentMethods: () => getPaymentMethods,
38
41
  getQuote: () => getQuote,
39
42
  getTransaction: () => getTransaction,
43
+ isTrustedFrameOrigin: () => isTrustedFrameOrigin,
44
+ isTrustedFrameUrl: () => isTrustedFrameUrl,
40
45
  listTransactions: () => listTransactions,
46
+ submitCustomerFiles: () => submitCustomerFiles,
47
+ submitCustomerKyc: () => submitCustomerKyc,
41
48
  submitIdentityFiles: () => submitIdentityFiles,
42
49
  themeParams: () => themeParams,
43
50
  updateIdentity: () => updateIdentity,
44
51
  verifyIdentity: () => verifyIdentity
45
52
  });
46
- module.exports = __toCommonJS(src_exports);
53
+ module.exports = __toCommonJS(index_exports);
47
54
 
48
55
  // src/api/client-context.ts
49
56
  var DEFAULT_API_BASE_URL = "https://api.moonpay.com";
@@ -55,10 +62,8 @@ function isTrustedMoonPayUrl(value) {
55
62
  } catch {
56
63
  return false;
57
64
  }
58
- if (hostname === "localhost" || hostname === "127.0.0.1")
59
- return true;
60
- if (protocol !== "https:")
61
- return false;
65
+ if (hostname === "localhost" || hostname === "127.0.0.1") return true;
66
+ if (protocol !== "https:") return false;
62
67
  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");
63
68
  }
64
69
  function createClientContext(options = {}) {
@@ -108,17 +113,37 @@ async function apiFetch(ctx, path, options) {
108
113
  return (0, import_result.ok)(data);
109
114
  }
110
115
 
116
+ // src/api/customer.ts
117
+ async function getCustomer(ctx, id) {
118
+ return apiFetch(ctx, `/platform/v1/customers/${encodeURIComponent(id)}`);
119
+ }
120
+ async function submitCustomerKyc(ctx, id, body) {
121
+ return apiFetch(ctx, `/platform/v1/customers/${encodeURIComponent(id)}/kyc`, {
122
+ method: "PATCH",
123
+ body: JSON.stringify(body)
124
+ });
125
+ }
126
+ async function getCustomerUploadUrl(ctx, id, body) {
127
+ return apiFetch(
128
+ ctx,
129
+ `/platform/v1/customers/${encodeURIComponent(id)}/files/upload-url`,
130
+ { method: "POST", body: JSON.stringify(body) }
131
+ );
132
+ }
133
+ async function submitCustomerFiles(ctx, id, body) {
134
+ return apiFetch(ctx, `/platform/v1/customers/${encodeURIComponent(id)}/files`, {
135
+ method: "POST",
136
+ body: JSON.stringify(body)
137
+ });
138
+ }
139
+
111
140
  // src/api/get-assets.ts
112
141
  async function getAssets(ctx, params = {}) {
113
142
  const searchParams = new URLSearchParams();
114
- if (params.source)
115
- searchParams.set("source", params.source);
116
- if (params.code)
117
- searchParams.set("code", params.code);
118
- if (params.cursor)
119
- searchParams.set("cursor", params.cursor);
120
- if (params.limit != null)
121
- searchParams.set("limit", String(params.limit));
143
+ if (params.source) searchParams.set("source", params.source);
144
+ if (params.code) searchParams.set("code", params.code);
145
+ if (params.cursor) searchParams.set("cursor", params.cursor);
146
+ if (params.limit != null) searchParams.set("limit", String(params.limit));
122
147
  const query = searchParams.toString();
123
148
  const path = `/platform/v1/assets${query ? `?${query}` : ""}`;
124
149
  return apiFetch(ctx, path);
@@ -135,14 +160,10 @@ async function getQuote(ctx, params) {
135
160
  // src/api/get-transactions.ts
136
161
  async function listTransactions(ctx, params = {}) {
137
162
  const searchParams = new URLSearchParams();
138
- if (params.startDate)
139
- searchParams.set("startDate", params.startDate);
140
- if (params.endDate)
141
- searchParams.set("endDate", params.endDate);
142
- if (params.cursor)
143
- searchParams.set("cursor", params.cursor);
144
- if (params.limit != null)
145
- searchParams.set("limit", String(params.limit));
163
+ if (params.startDate) searchParams.set("startDate", params.startDate);
164
+ if (params.endDate) searchParams.set("endDate", params.endDate);
165
+ if (params.cursor) searchParams.set("cursor", params.cursor);
166
+ if (params.limit != null) searchParams.set("limit", String(params.limit));
146
167
  const query = searchParams.toString();
147
168
  const path = `/platform/v1/transactions${query ? `?${query}` : ""}`;
148
169
  return apiFetch(ctx, path);
@@ -245,6 +266,10 @@ function createClientCore(options) {
245
266
  listTransactions: (params) => listTransactions(ctx, params),
246
267
  getTransaction: (id) => getTransaction(ctx, id),
247
268
  deletePaymentMethod: (id) => deletePaymentMethod(ctx, id),
269
+ getCustomer: (id) => getCustomer(ctx, id),
270
+ submitCustomerKyc: (id, body) => submitCustomerKyc(ctx, id, body),
271
+ getCustomerUploadUrl: (id, body) => getCustomerUploadUrl(ctx, id, body),
272
+ submitCustomerFiles: (id, body) => submitCustomerFiles(ctx, id, body),
248
273
  createIdentity: (body) => createIdentity(ctx, body),
249
274
  getIdentity: (id) => getIdentity(ctx, id),
250
275
  updateIdentity: (id, body) => updateIdentity(ctx, id, body),
@@ -1582,8 +1607,7 @@ function createFrameOrchestrator(options) {
1582
1607
  }
1583
1608
  }, handshakeTimeout);
1584
1609
  const unsubHandshake = transport.onMessage((msg) => {
1585
- if (msg.meta?.channelId !== channelId)
1586
- return;
1610
+ if (msg.meta?.channelId !== channelId) return;
1587
1611
  if (!handshakeComplete && msg.kind === import_protocol.HANDSHAKE_REQUEST_KIND) {
1588
1612
  handshakeComplete = true;
1589
1613
  clearTimeout(timer);
@@ -1609,8 +1633,7 @@ function createFrameOrchestrator(options) {
1609
1633
  messageHandlers.push(handler);
1610
1634
  return () => {
1611
1635
  const idx = messageHandlers.indexOf(handler);
1612
- if (idx >= 0)
1613
- messageHandlers.splice(idx, 1);
1636
+ if (idx >= 0) messageHandlers.splice(idx, 1);
1614
1637
  };
1615
1638
  },
1616
1639
  dispose() {
@@ -1624,6 +1647,26 @@ function createFrameOrchestrator(options) {
1624
1647
  });
1625
1648
  }
1626
1649
 
1650
+ // src/frames/frame-origin.ts
1651
+ var TRUSTED_FRAME_ORIGIN_PATTERNS = [
1652
+ /^https:\/\/([a-zA-Z0-9-]+\.)*moonpay\.com$/,
1653
+ /^https:\/\/([a-zA-Z0-9-]+\.)*moonpaycloud\.com$/,
1654
+ /^https:\/\/([a-zA-Z0-9-]+\.)*preview\.moonpay-dev\.com$/,
1655
+ /^http:\/\/localhost(:\d+)?$/
1656
+ ];
1657
+ function isTrustedFrameOrigin(origin) {
1658
+ return TRUSTED_FRAME_ORIGIN_PATTERNS.some((pattern) => pattern.test(origin));
1659
+ }
1660
+ function isTrustedFrameUrl(value) {
1661
+ let origin;
1662
+ try {
1663
+ ({ origin } = new URL(value));
1664
+ } catch {
1665
+ return false;
1666
+ }
1667
+ return isTrustedFrameOrigin(origin);
1668
+ }
1669
+
1627
1670
  // src/frames/url-builder.ts
1628
1671
  var FRAME_PATHS = {
1629
1672
  connect: "/platform/v1/connect",
@@ -1636,12 +1679,12 @@ var FRAME_PATHS = {
1636
1679
  buyButton: "/platform/v1/buy-button",
1637
1680
  challenge: "/platform/v1/challenge",
1638
1681
  addCard: "/platform/v1/add-card",
1639
- reset: "/platform/v1/reset"
1682
+ reset: "/platform/v1/reset",
1683
+ customerExport: "/v2/customer-export"
1640
1684
  };
1641
1685
  var DEFAULT_FRAME_BASE_URL = "https://platform.moonpay.com";
1642
1686
  function stringifyQueryValue(value) {
1643
- if (value == null)
1644
- return null;
1687
+ if (value == null) return null;
1645
1688
  if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
1646
1689
  return String(value);
1647
1690
  }
@@ -1665,8 +1708,7 @@ function themeParams(theme) {
1665
1708
  return theme?.appearance ? { theme: theme.appearance } : {};
1666
1709
  }
1667
1710
  function applyThemeParam(url, theme) {
1668
- if (!theme?.appearance)
1669
- return url;
1711
+ if (!theme?.appearance) return url;
1670
1712
  const parsed = new URL(url);
1671
1713
  if (!parsed.searchParams.has("theme")) {
1672
1714
  parsed.searchParams.set("theme", theme.appearance);