@moonpay/platform-sdk-core 1.29.0 → 1.31.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.d.cts CHANGED
@@ -4,7 +4,8 @@ import { IdentityFileUploadUrlRequestBody, IdentityFileUploadUrl, SubmitIdentity
4
4
  import { Result } from '@moonpay/platform-protocol/result';
5
5
  import { ListAssetsResponse, GetQuoteParams, Quote, TransactionWithStages, Transaction, PaginationInfo, ListPaymentMethodsQuery, ListPaymentMethodsResponse, SimulateBankTransferParams } from '@moonpay/platform-protocol/api';
6
6
  import { ProtocolMessage } from '@moonpay/platform-protocol/protocol';
7
- import { DecryptedCredentials } from '@moonpay/platform-protocol/models/connection';
7
+ import { DecryptedCredentials, Connection } from '@moonpay/platform-protocol/models/connection';
8
+ import * as AuthFrame from '@moonpay/platform-protocol/frames/auth';
8
9
 
9
10
  /** Internal state container for authenticated API access. */
10
11
  interface ClientContext {
@@ -171,7 +172,41 @@ interface UrlBuilderOptions {
171
172
  }
172
173
  /** Build a frame URL with query parameters. */
173
174
  declare function buildFrameUrl(path: string, query?: Record<string, unknown>, options?: UrlBuilderOptions): string;
174
- /** Theming options honoured by every visible MoonPay frame. */
175
+ /** A 6-digit hex color, with or without the leading `#` (e.g. `'FF6B00'`). */
176
+ type HexColor = string;
177
+ /**
178
+ * Fine-grained theme overrides, sent as the `customTheme` query param. Every
179
+ * field is optional; omitted fields keep the frame's default. The frame drops
180
+ * the whole object if it is invalid or over 4 KB once serialized.
181
+ */
182
+ interface CustomTheme {
183
+ /** Named radius scale applied across the frame. Frame default: `'m'`. */
184
+ borderRadius?: 'none' | 's' | 'm' | 'l' | 'full';
185
+ /**
186
+ * Locks the frame to a color scheme. Frame default: `'auto'` (follows the
187
+ * customer's OS preference). `ThemeOptions.appearance` wins when both are set.
188
+ */
189
+ colorScheme?: 'auto' | 'light' | 'dark';
190
+ /** Finer controls for how the palette is derived from `brandColor`. */
191
+ palette?: {
192
+ /** Minimum text/background contrast. Frame default: `'AA'` (4.5:1). */
193
+ minContrastRatio?: 'AA' | 'AAA';
194
+ /** Base colors for the success, error and warning palettes. */
195
+ semanticColors?: {
196
+ positive?: HexColor;
197
+ negative?: HexColor;
198
+ caution?: HexColor;
199
+ };
200
+ };
201
+ }
202
+ /**
203
+ * Theming options for visible MoonPay frames.
204
+ *
205
+ * `appearance` is honoured by every visible frame. `brandColor` and
206
+ * `customTheme` are honoured by the auth, widget, buy button (including the
207
+ * deprecated Apple Pay, Google Pay and buy frames) and customer export frames;
208
+ * the connect, add card, challenge and reset frames ignore them for now.
209
+ */
175
210
  interface ThemeOptions {
176
211
  /**
177
212
  * Frame appearance. Emitted as the `theme` query param that MoonPay frames
@@ -179,17 +214,27 @@ interface ThemeOptions {
179
214
  * preference when omitted.
180
215
  */
181
216
  appearance?: 'light' | 'dark';
217
+ /**
218
+ * Partner brand color that seeds the frame's whole palette, light and dark.
219
+ * Emitted as the `brandColor` query param. Accepts hex (`'FF6B00'`,
220
+ * `'#FF6B00'`, `'0xFF6B00'`) or a CSS color function (`'rgb(255,107,0)'`).
221
+ * Values the frame can't parse are ignored and the default MoonPay theme applies.
222
+ */
223
+ brandColor?: string;
224
+ /** Border radius, color scheme and palette overrides. Applies alongside `brandColor`. */
225
+ customTheme?: CustomTheme;
182
226
  }
183
227
  /**
184
- * Query params for a theme, mapping `appearance` → the `theme` param the
185
- * frames actually read. Returns `{}` when no appearance is set, so it spreads
186
- * cleanly into a frame URL's query object.
228
+ * Query params for a theme: `appearance` → `theme`, plus `brandColor` and a
229
+ * JSON-serialized `customTheme`. Unset options are left out, so the result
230
+ * spreads cleanly into a frame URL's query object.
187
231
  */
188
232
  declare function themeParams(theme?: ThemeOptions): Record<string, string>;
189
233
  /**
190
- * Set the `theme` query param on an already-built frame URL from a
191
- * client-level theme — unless the URL already carries one, so a per-frame
192
- * (or partner-embedded) theme always wins over the client default.
234
+ * Set the theme query params on an already-built frame URL from a
235
+ * client-level theme. Each param is only set when the URL doesn't already
236
+ * carry it, so a per-frame (or partner-embedded) value always wins over the
237
+ * client default.
193
238
  */
194
239
  declare function applyThemeParam(url: string, theme?: ThemeOptions): string;
195
240
  /**
@@ -351,6 +396,13 @@ declare function generateKeyPair(): KeyPair;
351
396
  */
352
397
  declare function isSecureRandomAvailable(): boolean;
353
398
 
399
+ /**
400
+ * Whether an auth frame `complete` payload is a sign-in result to forward to
401
+ * the partner. `connectionRequired` is excluded: the customer has just
402
+ * authenticated, so it is never a valid outcome of the auth frame.
403
+ */
404
+ declare function isAuthResult(connection: Connection): connection is AuthFrame.MessageMap['complete'];
405
+
354
406
  interface FrameOrchestratorOptions {
355
407
  transport: FrameTransport;
356
408
  channelId: string;
@@ -405,4 +457,4 @@ declare function isTrustedFrameOrigin(origin: string): boolean;
405
457
  */
406
458
  declare function isTrustedFrameUrl(value: string): boolean;
407
459
 
408
- export { type ClientContext, type ClientContextOptions, type CoreClient, type CoreClientOptions, type Credentials, FRAME_PATHS, type FrameHandle, type FrameOptions, type FrameOrchestratorOptions, type FrameTransport, type GetCredentialsError, type GetPaymentMethodsParams, type KeyPair, type ListAssetsParams, type ListTransactionsParams, type PresentationMode, TRUSTED_FRAME_ORIGIN_PATTERNS, type ThemeOptions, type UrlBuilderOptions, apiFetch, applyClientTokenParam, applyPresentationParam, applyResumeParam, applyThemeParam, buildFrameUrl, createClientContext, createClientCore, createFrameOrchestrator, createIdentity, decryptCredentials, deletePaymentMethod, generateKeyPair, getAssets, getCustomer, getCustomerUploadUrl, getIdentity, getIdentityUploadUrl, getPaymentMethods, getQuote, getTransaction, isSecureRandomAvailable, isTrustedFrameOrigin, isTrustedFrameUrl, listTransactions, presentationParams, simulateBankTransfer, submitCustomerFiles, submitCustomerKyc, submitIdentityFiles, themeParams, updateIdentity, verifyIdentity };
460
+ export { type ClientContext, type ClientContextOptions, type CoreClient, type CoreClientOptions, type Credentials, type CustomTheme, FRAME_PATHS, type FrameHandle, type FrameOptions, type FrameOrchestratorOptions, type FrameTransport, type GetCredentialsError, type GetPaymentMethodsParams, type HexColor, type KeyPair, type ListAssetsParams, type ListTransactionsParams, type PresentationMode, TRUSTED_FRAME_ORIGIN_PATTERNS, type ThemeOptions, type UrlBuilderOptions, apiFetch, applyClientTokenParam, applyPresentationParam, applyResumeParam, applyThemeParam, buildFrameUrl, createClientContext, createClientCore, createFrameOrchestrator, createIdentity, decryptCredentials, deletePaymentMethod, generateKeyPair, getAssets, getCustomer, getCustomerUploadUrl, getIdentity, getIdentityUploadUrl, getPaymentMethods, getQuote, getTransaction, isAuthResult, isSecureRandomAvailable, isTrustedFrameOrigin, isTrustedFrameUrl, listTransactions, presentationParams, simulateBankTransfer, submitCustomerFiles, submitCustomerKyc, submitIdentityFiles, themeParams, updateIdentity, verifyIdentity };
package/dist/index.d.ts CHANGED
@@ -4,7 +4,8 @@ import { IdentityFileUploadUrlRequestBody, IdentityFileUploadUrl, SubmitIdentity
4
4
  import { Result } from '@moonpay/platform-protocol/result';
5
5
  import { ListAssetsResponse, GetQuoteParams, Quote, TransactionWithStages, Transaction, PaginationInfo, ListPaymentMethodsQuery, ListPaymentMethodsResponse, SimulateBankTransferParams } from '@moonpay/platform-protocol/api';
6
6
  import { ProtocolMessage } from '@moonpay/platform-protocol/protocol';
7
- import { DecryptedCredentials } from '@moonpay/platform-protocol/models/connection';
7
+ import { DecryptedCredentials, Connection } from '@moonpay/platform-protocol/models/connection';
8
+ import * as AuthFrame from '@moonpay/platform-protocol/frames/auth';
8
9
 
9
10
  /** Internal state container for authenticated API access. */
10
11
  interface ClientContext {
@@ -171,7 +172,41 @@ interface UrlBuilderOptions {
171
172
  }
172
173
  /** Build a frame URL with query parameters. */
173
174
  declare function buildFrameUrl(path: string, query?: Record<string, unknown>, options?: UrlBuilderOptions): string;
174
- /** Theming options honoured by every visible MoonPay frame. */
175
+ /** A 6-digit hex color, with or without the leading `#` (e.g. `'FF6B00'`). */
176
+ type HexColor = string;
177
+ /**
178
+ * Fine-grained theme overrides, sent as the `customTheme` query param. Every
179
+ * field is optional; omitted fields keep the frame's default. The frame drops
180
+ * the whole object if it is invalid or over 4 KB once serialized.
181
+ */
182
+ interface CustomTheme {
183
+ /** Named radius scale applied across the frame. Frame default: `'m'`. */
184
+ borderRadius?: 'none' | 's' | 'm' | 'l' | 'full';
185
+ /**
186
+ * Locks the frame to a color scheme. Frame default: `'auto'` (follows the
187
+ * customer's OS preference). `ThemeOptions.appearance` wins when both are set.
188
+ */
189
+ colorScheme?: 'auto' | 'light' | 'dark';
190
+ /** Finer controls for how the palette is derived from `brandColor`. */
191
+ palette?: {
192
+ /** Minimum text/background contrast. Frame default: `'AA'` (4.5:1). */
193
+ minContrastRatio?: 'AA' | 'AAA';
194
+ /** Base colors for the success, error and warning palettes. */
195
+ semanticColors?: {
196
+ positive?: HexColor;
197
+ negative?: HexColor;
198
+ caution?: HexColor;
199
+ };
200
+ };
201
+ }
202
+ /**
203
+ * Theming options for visible MoonPay frames.
204
+ *
205
+ * `appearance` is honoured by every visible frame. `brandColor` and
206
+ * `customTheme` are honoured by the auth, widget, buy button (including the
207
+ * deprecated Apple Pay, Google Pay and buy frames) and customer export frames;
208
+ * the connect, add card, challenge and reset frames ignore them for now.
209
+ */
175
210
  interface ThemeOptions {
176
211
  /**
177
212
  * Frame appearance. Emitted as the `theme` query param that MoonPay frames
@@ -179,17 +214,27 @@ interface ThemeOptions {
179
214
  * preference when omitted.
180
215
  */
181
216
  appearance?: 'light' | 'dark';
217
+ /**
218
+ * Partner brand color that seeds the frame's whole palette, light and dark.
219
+ * Emitted as the `brandColor` query param. Accepts hex (`'FF6B00'`,
220
+ * `'#FF6B00'`, `'0xFF6B00'`) or a CSS color function (`'rgb(255,107,0)'`).
221
+ * Values the frame can't parse are ignored and the default MoonPay theme applies.
222
+ */
223
+ brandColor?: string;
224
+ /** Border radius, color scheme and palette overrides. Applies alongside `brandColor`. */
225
+ customTheme?: CustomTheme;
182
226
  }
183
227
  /**
184
- * Query params for a theme, mapping `appearance` → the `theme` param the
185
- * frames actually read. Returns `{}` when no appearance is set, so it spreads
186
- * cleanly into a frame URL's query object.
228
+ * Query params for a theme: `appearance` → `theme`, plus `brandColor` and a
229
+ * JSON-serialized `customTheme`. Unset options are left out, so the result
230
+ * spreads cleanly into a frame URL's query object.
187
231
  */
188
232
  declare function themeParams(theme?: ThemeOptions): Record<string, string>;
189
233
  /**
190
- * Set the `theme` query param on an already-built frame URL from a
191
- * client-level theme — unless the URL already carries one, so a per-frame
192
- * (or partner-embedded) theme always wins over the client default.
234
+ * Set the theme query params on an already-built frame URL from a
235
+ * client-level theme. Each param is only set when the URL doesn't already
236
+ * carry it, so a per-frame (or partner-embedded) value always wins over the
237
+ * client default.
193
238
  */
194
239
  declare function applyThemeParam(url: string, theme?: ThemeOptions): string;
195
240
  /**
@@ -351,6 +396,13 @@ declare function generateKeyPair(): KeyPair;
351
396
  */
352
397
  declare function isSecureRandomAvailable(): boolean;
353
398
 
399
+ /**
400
+ * Whether an auth frame `complete` payload is a sign-in result to forward to
401
+ * the partner. `connectionRequired` is excluded: the customer has just
402
+ * authenticated, so it is never a valid outcome of the auth frame.
403
+ */
404
+ declare function isAuthResult(connection: Connection): connection is AuthFrame.MessageMap['complete'];
405
+
354
406
  interface FrameOrchestratorOptions {
355
407
  transport: FrameTransport;
356
408
  channelId: string;
@@ -405,4 +457,4 @@ declare function isTrustedFrameOrigin(origin: string): boolean;
405
457
  */
406
458
  declare function isTrustedFrameUrl(value: string): boolean;
407
459
 
408
- export { type ClientContext, type ClientContextOptions, type CoreClient, type CoreClientOptions, type Credentials, FRAME_PATHS, type FrameHandle, type FrameOptions, type FrameOrchestratorOptions, type FrameTransport, type GetCredentialsError, type GetPaymentMethodsParams, type KeyPair, type ListAssetsParams, type ListTransactionsParams, type PresentationMode, TRUSTED_FRAME_ORIGIN_PATTERNS, type ThemeOptions, type UrlBuilderOptions, apiFetch, applyClientTokenParam, applyPresentationParam, applyResumeParam, applyThemeParam, buildFrameUrl, createClientContext, createClientCore, createFrameOrchestrator, createIdentity, decryptCredentials, deletePaymentMethod, generateKeyPair, getAssets, getCustomer, getCustomerUploadUrl, getIdentity, getIdentityUploadUrl, getPaymentMethods, getQuote, getTransaction, isSecureRandomAvailable, isTrustedFrameOrigin, isTrustedFrameUrl, listTransactions, presentationParams, simulateBankTransfer, submitCustomerFiles, submitCustomerKyc, submitIdentityFiles, themeParams, updateIdentity, verifyIdentity };
460
+ export { type ClientContext, type ClientContextOptions, type CoreClient, type CoreClientOptions, type Credentials, type CustomTheme, FRAME_PATHS, type FrameHandle, type FrameOptions, type FrameOrchestratorOptions, type FrameTransport, type GetCredentialsError, type GetPaymentMethodsParams, type HexColor, type KeyPair, type ListAssetsParams, type ListTransactionsParams, type PresentationMode, TRUSTED_FRAME_ORIGIN_PATTERNS, type ThemeOptions, type UrlBuilderOptions, apiFetch, applyClientTokenParam, applyPresentationParam, applyResumeParam, applyThemeParam, buildFrameUrl, createClientContext, createClientCore, createFrameOrchestrator, createIdentity, decryptCredentials, deletePaymentMethod, generateKeyPair, getAssets, getCustomer, getCustomerUploadUrl, getIdentity, getIdentityUploadUrl, getPaymentMethods, getQuote, getTransaction, isAuthResult, isSecureRandomAvailable, isTrustedFrameOrigin, isTrustedFrameUrl, listTransactions, presentationParams, simulateBankTransfer, submitCustomerFiles, submitCustomerKyc, submitIdentityFiles, themeParams, updateIdentity, verifyIdentity };
package/dist/index.js CHANGED
@@ -1564,6 +1564,19 @@ function isSecureRandomAvailable() {
1564
1564
  return typeof globalThis.crypto?.getRandomValues === "function";
1565
1565
  }
1566
1566
 
1567
+ // src/frames/auth-result.ts
1568
+ import { ConnectionStatus } from "@moonpay/platform-protocol/models/connection";
1569
+ var AUTH_RESULT_STATUSES = /* @__PURE__ */ new Set([
1570
+ ConnectionStatus.active,
1571
+ ConnectionStatus.pending,
1572
+ ConnectionStatus.termsAcceptanceRequired,
1573
+ ConnectionStatus.unavailable,
1574
+ ConnectionStatus.failed
1575
+ ]);
1576
+ function isAuthResult(connection) {
1577
+ return AUTH_RESULT_STATUSES.has(connection.status);
1578
+ }
1579
+
1567
1580
  // src/frames/frame-orchestrator.ts
1568
1581
  import {
1569
1582
  HANDSHAKE_ACK_KIND,
@@ -1679,13 +1692,20 @@ function buildFrameUrl(path, query = {}, options = {}) {
1679
1692
  return url.href;
1680
1693
  }
1681
1694
  function themeParams(theme) {
1682
- return theme?.appearance ? { theme: theme.appearance } : {};
1695
+ const params = {};
1696
+ if (theme?.appearance) params.theme = theme.appearance;
1697
+ if (theme?.brandColor) params.brandColor = theme.brandColor;
1698
+ if (theme?.customTheme) params.customTheme = JSON.stringify(theme.customTheme);
1699
+ return params;
1683
1700
  }
1684
1701
  function applyThemeParam(url, theme) {
1685
- if (!theme?.appearance) return url;
1702
+ const params = Object.entries(themeParams(theme));
1703
+ if (params.length === 0) return url;
1686
1704
  const parsed = new URL(url);
1687
- if (!parsed.searchParams.has("theme")) {
1688
- parsed.searchParams.set("theme", theme.appearance);
1705
+ for (const [key, value] of params) {
1706
+ if (!parsed.searchParams.has(key)) {
1707
+ parsed.searchParams.set(key, value);
1708
+ }
1689
1709
  }
1690
1710
  return parsed.href;
1691
1711
  }
@@ -1740,6 +1760,7 @@ export {
1740
1760
  getPaymentMethods,
1741
1761
  getQuote,
1742
1762
  getTransaction,
1763
+ isAuthResult,
1743
1764
  isSecureRandomAvailable,
1744
1765
  isTrustedFrameOrigin,
1745
1766
  isTrustedFrameUrl,