@amos.com/amos-js 0.9.14 → 0.9.15

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/src/types.ts CHANGED
@@ -330,71 +330,28 @@ export type Appearance = {
330
330
  };
331
331
 
332
332
  /**
333
- * Inline style bag sent through `postMessage` to the wallet-button iframe.
333
+ * Apple's `<apple-pay-button>` attributes. `@types/applepayjs` only
334
+ * covers `ApplePaySession`, so this bag is the custom element's HTML
335
+ * attributes plus inner `style`. Posted as-is on `buttonProps`.
334
336
  *
335
- * Matches the serializable subset of a CSSStyleDeclaration / React
336
- * `CSSProperties` object (string or number values). Custom properties such
337
- * as `--apple-pay-button-height` are allowed.
338
- */
339
- export type WalletButtonStyle = {
340
- [property: string]: string | number | undefined;
341
- };
342
-
343
- /**
344
- * `buttonstyle` attribute on Apple's `<apple-pay-button>`.
345
- *
346
- * @see https://developer.apple.com/documentation/apple_pay_on_the_web/apple-pay-button
347
- */
348
- export type ApplePayButtonStyle = "black" | "white" | "white-outline";
349
-
350
- /**
351
- * `type` attribute on Apple's `<apple-pay-button>`.
352
- *
353
- * @see https://developer.apple.com/documentation/apple_pay_on_the_web/apple-pay-button
354
- */
355
- export type ApplePayButtonType =
356
- | "plain"
357
- | "buy"
358
- | "set-up"
359
- | "donate"
360
- | "check-out"
361
- | "book"
362
- | "subscribe"
363
- | "reload"
364
- | "add-money"
365
- | "top-up"
366
- | "order"
367
- | "rent"
368
- | "support"
369
- | "contribute"
370
- | "tip";
371
-
372
- /**
373
- * Visual props for Apple's `<apple-pay-button>`, using Apple's attribute
374
- * names. Applied inside the Amos embed iframe.
337
+ * Omitted fields keep the painted button's defaults. Height belongs on
338
+ * the mount `height` option.
375
339
  *
376
340
  * @see https://developer.apple.com/documentation/apple_pay_on_the_web/apple-pay-button
377
341
  */
378
342
  export type ApplePayButtonElementProps = {
379
- /**
380
- * Stretch the button to the iframe width while preserving its default
381
- * compact size when omitted.
382
- *
383
- * @default false
384
- */
385
- fullWidth?: boolean;
386
343
  /**
387
344
  * Apple Pay button color.
388
345
  *
389
346
  * @default "black"
390
347
  */
391
- buttonstyle?: ApplePayButtonStyle;
348
+ buttonstyle?: string;
392
349
  /**
393
350
  * Apple Pay button label / verb.
394
351
  *
395
352
  * @default "plain"
396
353
  */
397
- type?: ApplePayButtonType;
354
+ type?: string;
398
355
  /**
399
356
  * BCP 47 locale for the button label (e.g. `"en-US"`).
400
357
  *
@@ -402,140 +359,34 @@ export type ApplePayButtonElementProps = {
402
359
  */
403
360
  locale?: string;
404
361
  /**
405
- * Inline style for the `<apple-pay-button>`. Height is controlled with
406
- * `--apple-pay-button-height` (Apple ignores CSS `height`). Width uses
407
- * `--apple-pay-button-width` or CSS `width`.
362
+ * Inline style for the `<apple-pay-button>`. Omitted keys keep fill
363
+ * (`width: 100%` and `--apple-pay-button-width`).
408
364
  */
409
- style?: WalletButtonStyle;
365
+ style?: Record<string, string | number | undefined>;
410
366
  };
411
367
 
412
368
  /**
413
- * Visual props for Google's Pay button, using `@google-pay/button-react`
414
- * / Google Pay API names. Applied inside the Amos embed iframe.
369
+ * Google Pay button visuals: {@link google.payments.api.ButtonOptions}
370
+ * without the fields that cannot go through `postMessage`, plus inner
371
+ * `style`. Posted as-is on `buttonProps`.
372
+ *
373
+ * Omitted fields keep the painted button's defaults (`buttonType:
374
+ * "plain"`, `buttonSizeMode: "fill"`). Height belongs on the mount
375
+ * `height` option.
415
376
  *
416
377
  * @see https://developers.google.com/pay/api/web/guides/resources/customize
417
378
  */
418
- export type GooglePayButtonElementProps = {
379
+ export type GooglePayButtonElementProps = Omit<
380
+ google.payments.api.ButtonOptions,
381
+ "onClick" | "buttonRootNode" | "allowedPaymentMethods"
382
+ > & {
419
383
  /**
420
- * Stretch the button to the iframe width while preserving its default
421
- * compact size when omitted.
422
- *
423
- * @default false
384
+ * Inline style for the Google Pay button wrapper. Omitted keys keep
385
+ * fill (`width: 100%`).
424
386
  */
425
- fullWidth?: boolean;
426
- /**
427
- * Button label / verb.
428
- *
429
- * @default "short"
430
- */
431
- buttonType?: google.payments.api.ButtonType;
432
- /** Button color. */
433
- buttonColor?: google.payments.api.ButtonColor;
434
- /** Corner radius in pixels (0–20). */
435
- buttonRadius?: number;
436
- /**
437
- * `"fill"` stretches the button to the container width; `"static"`
438
- * uses Google's default size.
439
- */
440
- buttonSizeMode?: google.payments.api.ButtonSizeMode;
441
- /** BCP 47 locale for the button label (e.g. `"en"`). */
442
- buttonLocale?: string;
443
- /** Whether the button draws a border. */
444
- buttonBorderType?: google.payments.api.ButtonBorderType;
445
- /**
446
- * Inline style for the Google Pay button wrapper. Use `height` /
447
- * `width` here (unlike Apple Pay, Google honors CSS `height`).
448
- */
449
- style?: WalletButtonStyle;
387
+ style?: Record<string, string | number | undefined>;
450
388
  };
451
389
 
452
- /**
453
- * Keep only JSON-cloneable string/number declarations from a style object
454
- * before sending it through `postMessage`.
455
- */
456
- export function serializeWalletButtonStyle(
457
- style: WalletButtonStyle | undefined,
458
- ): Record<string, string | number> | undefined {
459
- if (!style || typeof style !== "object") {
460
- return undefined;
461
- }
462
-
463
- const result: Record<string, string | number> = {};
464
- for (const [key, value] of Object.entries(style)) {
465
- if (typeof value === "string") {
466
- if (value.length === 0) {
467
- continue;
468
- }
469
- result[key] = value;
470
- continue;
471
- }
472
- if (typeof value === "number" && Number.isFinite(value)) {
473
- result[key] = value;
474
- }
475
- }
476
-
477
- return Object.keys(result).length > 0 ? result : undefined;
478
- }
479
-
480
- export function pickApplePayButtonElementProps(
481
- options: ApplePayButtonElementProps,
482
- ): ApplePayButtonElementProps {
483
- const props: ApplePayButtonElementProps = {};
484
- if (options.fullWidth !== undefined) {
485
- props.fullWidth = options.fullWidth;
486
- }
487
- if (options.buttonstyle !== undefined) {
488
- props.buttonstyle = options.buttonstyle;
489
- }
490
- if (options.type !== undefined) {
491
- props.type = options.type;
492
- }
493
- if (options.locale !== undefined) {
494
- props.locale = options.locale;
495
- }
496
- if (options.style !== undefined) {
497
- const style = serializeWalletButtonStyle(options.style);
498
- if (style) {
499
- props.style = style;
500
- }
501
- }
502
- return props;
503
- }
504
-
505
- export function pickGooglePayButtonElementProps(
506
- options: GooglePayButtonElementProps,
507
- ): GooglePayButtonElementProps {
508
- const props: GooglePayButtonElementProps = {};
509
- if (options.fullWidth !== undefined) {
510
- props.fullWidth = options.fullWidth;
511
- }
512
- if (options.buttonType !== undefined) {
513
- props.buttonType = options.buttonType;
514
- }
515
- if (options.buttonColor !== undefined) {
516
- props.buttonColor = options.buttonColor;
517
- }
518
- if (options.buttonRadius !== undefined) {
519
- props.buttonRadius = options.buttonRadius;
520
- }
521
- if (options.buttonSizeMode !== undefined) {
522
- props.buttonSizeMode = options.buttonSizeMode;
523
- }
524
- if (options.buttonLocale !== undefined) {
525
- props.buttonLocale = options.buttonLocale;
526
- }
527
- if (options.buttonBorderType !== undefined) {
528
- props.buttonBorderType = options.buttonBorderType;
529
- }
530
- if (options.style !== undefined) {
531
- const style = serializeWalletButtonStyle(options.style);
532
- if (style) {
533
- props.style = style;
534
- }
535
- }
536
- return props;
537
- }
538
-
539
390
  /**
540
391
  * Typed `postMessage` payloads exchanged between the host page and the
541
392
  * embedded Amos iframe.
@@ -570,17 +421,15 @@ export type Message =
570
421
  appearance: Appearance;
571
422
  }
572
423
  | {
573
- /**
574
- * Parent → embed: visual options for the Apple Pay button. Nested
575
- * under `props` so Apple's `type` attribute does not collide with
576
- * this message discriminant.
577
- */
424
+ /** Parent → embed: visual options for the Apple Pay button. */
578
425
  type: "UPDATE_APPLE_PAY_BUTTON";
426
+ height?: string;
579
427
  props: ApplePayButtonElementProps;
580
428
  }
581
429
  | {
582
430
  /** Parent → embed: visual options for the Google Pay button. */
583
431
  type: "UPDATE_GOOGLE_PAY_BUTTON";
432
+ height?: string;
584
433
  props: GooglePayButtonElementProps;
585
434
  }
586
435
  | {