@moonpay/platform-sdk-core 1.29.0 → 1.30.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
@@ -171,7 +171,41 @@ interface UrlBuilderOptions {
171
171
  }
172
172
  /** Build a frame URL with query parameters. */
173
173
  declare function buildFrameUrl(path: string, query?: Record<string, unknown>, options?: UrlBuilderOptions): string;
174
- /** Theming options honoured by every visible MoonPay frame. */
174
+ /** A 6-digit hex color, with or without the leading `#` (e.g. `'FF6B00'`). */
175
+ type HexColor = string;
176
+ /**
177
+ * Fine-grained theme overrides, sent as the `customTheme` query param. Every
178
+ * field is optional; omitted fields keep the frame's default. The frame drops
179
+ * the whole object if it is invalid or over 4 KB once serialized.
180
+ */
181
+ interface CustomTheme {
182
+ /** Named radius scale applied across the frame. Frame default: `'m'`. */
183
+ borderRadius?: 'none' | 's' | 'm' | 'l' | 'full';
184
+ /**
185
+ * Locks the frame to a color scheme. Frame default: `'auto'` (follows the
186
+ * customer's OS preference). `ThemeOptions.appearance` wins when both are set.
187
+ */
188
+ colorScheme?: 'auto' | 'light' | 'dark';
189
+ /** Finer controls for how the palette is derived from `brandColor`. */
190
+ palette?: {
191
+ /** Minimum text/background contrast. Frame default: `'AA'` (4.5:1). */
192
+ minContrastRatio?: 'AA' | 'AAA';
193
+ /** Base colors for the success, error and warning palettes. */
194
+ semanticColors?: {
195
+ positive?: HexColor;
196
+ negative?: HexColor;
197
+ caution?: HexColor;
198
+ };
199
+ };
200
+ }
201
+ /**
202
+ * Theming options for visible MoonPay frames.
203
+ *
204
+ * `appearance` is honoured by every visible frame. `brandColor` and
205
+ * `customTheme` are honoured by the auth, widget, buy button (including the
206
+ * deprecated Apple Pay, Google Pay and buy frames) and customer export frames;
207
+ * the connect, add card, challenge and reset frames ignore them for now.
208
+ */
175
209
  interface ThemeOptions {
176
210
  /**
177
211
  * Frame appearance. Emitted as the `theme` query param that MoonPay frames
@@ -179,17 +213,27 @@ interface ThemeOptions {
179
213
  * preference when omitted.
180
214
  */
181
215
  appearance?: 'light' | 'dark';
216
+ /**
217
+ * Partner brand color that seeds the frame's whole palette, light and dark.
218
+ * Emitted as the `brandColor` query param. Accepts hex (`'FF6B00'`,
219
+ * `'#FF6B00'`, `'0xFF6B00'`) or a CSS color function (`'rgb(255,107,0)'`).
220
+ * Values the frame can't parse are ignored and the default MoonPay theme applies.
221
+ */
222
+ brandColor?: string;
223
+ /** Border radius, color scheme and palette overrides. Applies alongside `brandColor`. */
224
+ customTheme?: CustomTheme;
182
225
  }
183
226
  /**
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.
227
+ * Query params for a theme: `appearance` → `theme`, plus `brandColor` and a
228
+ * JSON-serialized `customTheme`. Unset options are left out, so the result
229
+ * spreads cleanly into a frame URL's query object.
187
230
  */
188
231
  declare function themeParams(theme?: ThemeOptions): Record<string, string>;
189
232
  /**
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.
233
+ * Set the theme query params on an already-built frame URL from a
234
+ * client-level theme. Each param is only set when the URL doesn't already
235
+ * carry it, so a per-frame (or partner-embedded) value always wins over the
236
+ * client default.
193
237
  */
194
238
  declare function applyThemeParam(url: string, theme?: ThemeOptions): string;
195
239
  /**
@@ -405,4 +449,4 @@ declare function isTrustedFrameOrigin(origin: string): boolean;
405
449
  */
406
450
  declare function isTrustedFrameUrl(value: string): boolean;
407
451
 
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 };
452
+ 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, isSecureRandomAvailable, isTrustedFrameOrigin, isTrustedFrameUrl, listTransactions, presentationParams, simulateBankTransfer, submitCustomerFiles, submitCustomerKyc, submitIdentityFiles, themeParams, updateIdentity, verifyIdentity };
package/dist/index.d.ts CHANGED
@@ -171,7 +171,41 @@ interface UrlBuilderOptions {
171
171
  }
172
172
  /** Build a frame URL with query parameters. */
173
173
  declare function buildFrameUrl(path: string, query?: Record<string, unknown>, options?: UrlBuilderOptions): string;
174
- /** Theming options honoured by every visible MoonPay frame. */
174
+ /** A 6-digit hex color, with or without the leading `#` (e.g. `'FF6B00'`). */
175
+ type HexColor = string;
176
+ /**
177
+ * Fine-grained theme overrides, sent as the `customTheme` query param. Every
178
+ * field is optional; omitted fields keep the frame's default. The frame drops
179
+ * the whole object if it is invalid or over 4 KB once serialized.
180
+ */
181
+ interface CustomTheme {
182
+ /** Named radius scale applied across the frame. Frame default: `'m'`. */
183
+ borderRadius?: 'none' | 's' | 'm' | 'l' | 'full';
184
+ /**
185
+ * Locks the frame to a color scheme. Frame default: `'auto'` (follows the
186
+ * customer's OS preference). `ThemeOptions.appearance` wins when both are set.
187
+ */
188
+ colorScheme?: 'auto' | 'light' | 'dark';
189
+ /** Finer controls for how the palette is derived from `brandColor`. */
190
+ palette?: {
191
+ /** Minimum text/background contrast. Frame default: `'AA'` (4.5:1). */
192
+ minContrastRatio?: 'AA' | 'AAA';
193
+ /** Base colors for the success, error and warning palettes. */
194
+ semanticColors?: {
195
+ positive?: HexColor;
196
+ negative?: HexColor;
197
+ caution?: HexColor;
198
+ };
199
+ };
200
+ }
201
+ /**
202
+ * Theming options for visible MoonPay frames.
203
+ *
204
+ * `appearance` is honoured by every visible frame. `brandColor` and
205
+ * `customTheme` are honoured by the auth, widget, buy button (including the
206
+ * deprecated Apple Pay, Google Pay and buy frames) and customer export frames;
207
+ * the connect, add card, challenge and reset frames ignore them for now.
208
+ */
175
209
  interface ThemeOptions {
176
210
  /**
177
211
  * Frame appearance. Emitted as the `theme` query param that MoonPay frames
@@ -179,17 +213,27 @@ interface ThemeOptions {
179
213
  * preference when omitted.
180
214
  */
181
215
  appearance?: 'light' | 'dark';
216
+ /**
217
+ * Partner brand color that seeds the frame's whole palette, light and dark.
218
+ * Emitted as the `brandColor` query param. Accepts hex (`'FF6B00'`,
219
+ * `'#FF6B00'`, `'0xFF6B00'`) or a CSS color function (`'rgb(255,107,0)'`).
220
+ * Values the frame can't parse are ignored and the default MoonPay theme applies.
221
+ */
222
+ brandColor?: string;
223
+ /** Border radius, color scheme and palette overrides. Applies alongside `brandColor`. */
224
+ customTheme?: CustomTheme;
182
225
  }
183
226
  /**
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.
227
+ * Query params for a theme: `appearance` → `theme`, plus `brandColor` and a
228
+ * JSON-serialized `customTheme`. Unset options are left out, so the result
229
+ * spreads cleanly into a frame URL's query object.
187
230
  */
188
231
  declare function themeParams(theme?: ThemeOptions): Record<string, string>;
189
232
  /**
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.
233
+ * Set the theme query params on an already-built frame URL from a
234
+ * client-level theme. Each param is only set when the URL doesn't already
235
+ * carry it, so a per-frame (or partner-embedded) value always wins over the
236
+ * client default.
193
237
  */
194
238
  declare function applyThemeParam(url: string, theme?: ThemeOptions): string;
195
239
  /**
@@ -405,4 +449,4 @@ declare function isTrustedFrameOrigin(origin: string): boolean;
405
449
  */
406
450
  declare function isTrustedFrameUrl(value: string): boolean;
407
451
 
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 };
452
+ 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, isSecureRandomAvailable, isTrustedFrameOrigin, isTrustedFrameUrl, listTransactions, presentationParams, simulateBankTransfer, submitCustomerFiles, submitCustomerKyc, submitIdentityFiles, themeParams, updateIdentity, verifyIdentity };
package/dist/index.js CHANGED
@@ -1679,13 +1679,20 @@ function buildFrameUrl(path, query = {}, options = {}) {
1679
1679
  return url.href;
1680
1680
  }
1681
1681
  function themeParams(theme) {
1682
- return theme?.appearance ? { theme: theme.appearance } : {};
1682
+ const params = {};
1683
+ if (theme?.appearance) params.theme = theme.appearance;
1684
+ if (theme?.brandColor) params.brandColor = theme.brandColor;
1685
+ if (theme?.customTheme) params.customTheme = JSON.stringify(theme.customTheme);
1686
+ return params;
1683
1687
  }
1684
1688
  function applyThemeParam(url, theme) {
1685
- if (!theme?.appearance) return url;
1689
+ const params = Object.entries(themeParams(theme));
1690
+ if (params.length === 0) return url;
1686
1691
  const parsed = new URL(url);
1687
- if (!parsed.searchParams.has("theme")) {
1688
- parsed.searchParams.set("theme", theme.appearance);
1692
+ for (const [key, value] of params) {
1693
+ if (!parsed.searchParams.has(key)) {
1694
+ parsed.searchParams.set(key, value);
1695
+ }
1689
1696
  }
1690
1697
  return parsed.href;
1691
1698
  }