@churnkey/react 0.6.5 → 0.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.
Files changed (35) hide show
  1. package/dist/{chunk-W47U2HRC.cjs → chunk-4ZAJYXG2.cjs} +7 -6
  2. package/dist/chunk-4ZAJYXG2.cjs.map +1 -0
  3. package/dist/{chunk-F6IP3LGK.js → chunk-BODEVZ3K.js} +189 -10
  4. package/dist/chunk-BODEVZ3K.js.map +1 -0
  5. package/dist/{chunk-EYIGZLVT.js → chunk-GH5EKETT.js} +6 -3
  6. package/dist/chunk-GH5EKETT.js.map +1 -0
  7. package/dist/{chunk-XHXG43PW.js → chunk-KS3RWFRH.js} +4 -3
  8. package/dist/chunk-KS3RWFRH.js.map +1 -0
  9. package/dist/{chunk-WVSNF3TN.cjs → chunk-M6Z3BHEH.cjs} +6 -2
  10. package/dist/chunk-M6Z3BHEH.cjs.map +1 -0
  11. package/dist/{chunk-H5IHOYUF.cjs → chunk-SWEPUHIN.cjs} +192 -9
  12. package/dist/chunk-SWEPUHIN.cjs.map +1 -0
  13. package/dist/core.cjs +30 -14
  14. package/dist/core.d.cts +22 -6
  15. package/dist/core.d.ts +22 -6
  16. package/dist/core.js +2 -2
  17. package/dist/headless.cjs +3 -3
  18. package/dist/headless.d.cts +4 -1
  19. package/dist/headless.d.ts +4 -1
  20. package/dist/headless.js +2 -2
  21. package/dist/index.cjs +235 -161
  22. package/dist/index.cjs.map +1 -1
  23. package/dist/index.d.cts +14 -14
  24. package/dist/index.d.ts +14 -14
  25. package/dist/index.js +125 -67
  26. package/dist/index.js.map +1 -1
  27. package/dist/{step-graph-Dee2cFLK.d.cts → step-graph-s1L1wV-P.d.cts} +181 -1
  28. package/dist/{step-graph-Dee2cFLK.d.ts → step-graph-s1L1wV-P.d.ts} +181 -1
  29. package/package.json +1 -1
  30. package/dist/chunk-EYIGZLVT.js.map +0 -1
  31. package/dist/chunk-F6IP3LGK.js.map +0 -1
  32. package/dist/chunk-H5IHOYUF.cjs.map +0 -1
  33. package/dist/chunk-W47U2HRC.cjs.map +0 -1
  34. package/dist/chunk-WVSNF3TN.cjs.map +0 -1
  35. package/dist/chunk-XHXG43PW.js.map +0 -1
@@ -1,5 +1,131 @@
1
1
  import { ReactNode, ReactElement, ComponentType } from 'react';
2
2
 
3
+ /** Both timing variants of a message. Which one renders is decided by the
4
+ * flow's effective cancel timing (`FlowState.cancelAtPeriodEnd`). */
5
+ interface TimingVariants {
6
+ immediate: string;
7
+ atPeriodEnd: string;
8
+ }
9
+ /**
10
+ * A message that may differ by cancellation timing. Plain strings render
11
+ * as-is in both cases; pass the object form when the wording should change
12
+ * (e.g. "Cancel" vs "Turn off auto-renew").
13
+ */
14
+ type TimingAware = string | TimingVariants;
15
+ /** Success-screen copy for one accepted offer type. */
16
+ interface SavedOfferCopy {
17
+ title: string;
18
+ description: string;
19
+ }
20
+ interface CancelFlowMessages {
21
+ common: {
22
+ continue: string;
23
+ back: string;
24
+ close: string;
25
+ done: string;
26
+ processing: string;
27
+ tryAgain: string;
28
+ loading: string;
29
+ loadError: string;
30
+ error: string;
31
+ day: string;
32
+ days: string;
33
+ month: string;
34
+ months: string;
35
+ };
36
+ survey: {
37
+ title: string;
38
+ followupPlaceholder: string;
39
+ followupAriaLabel: string;
40
+ };
41
+ feedback: {
42
+ title: string;
43
+ placeholder: string;
44
+ /** Used instead of `placeholder` when the step sets `minLength`. Supports `{minLength}`. */
45
+ placeholderWithMin: string;
46
+ };
47
+ confirm: {
48
+ title: string;
49
+ lossesLabel: string;
50
+ cta: TimingAware;
51
+ goBack: string;
52
+ /** Shown between the description and the confirm button. Supports
53
+ * `{periodEnd}`. The default immediate variant is empty, which
54
+ * suppresses the notice for immediate timing; empty OVERRIDE values are
55
+ * dropped like any blank override, so to remove the notice entirely
56
+ * replace the `Confirm` component or hide it via
57
+ * `classNames.periodEndNotice`. */
58
+ periodEndNotice: TimingAware;
59
+ };
60
+ success: {
61
+ saved: {
62
+ /** Generic fallback — used for offer types without their own entry
63
+ * (contact, redirect, custom types). */
64
+ title: string;
65
+ description: string;
66
+ discount: SavedOfferCopy;
67
+ pause: SavedOfferCopy & {
68
+ /** Used instead of `description` when the resume date is known
69
+ * (the built-in pause UI always supplies it). Supports `{resumeDate}`. */
70
+ resumeDescription: string;
71
+ };
72
+ trial_extension: SavedOfferCopy;
73
+ plan_change: SavedOfferCopy;
74
+ rebate: SavedOfferCopy;
75
+ };
76
+ cancelled: {
77
+ title: TimingAware;
78
+ description: TimingAware;
79
+ };
80
+ };
81
+ offer: {
82
+ limitedTimeEyebrow: string;
83
+ pauseEyebrow: string;
84
+ newEndDateLabel: string;
85
+ currentPlanBadge: string;
86
+ /** CTA when a plan is selected in a plan-change offer. Supports `{planName}`. */
87
+ switchToCta: string;
88
+ rebate: {
89
+ paidLabel: string;
90
+ moneyBackLabel: string;
91
+ /** Tax parenthetical after the money-back label. Supports `{amount}`. */
92
+ inclTax: string;
93
+ netLabel: string;
94
+ };
95
+ };
96
+ }
97
+ /**
98
+ * Recursive partial of the catalog for overrides. Timing-aware fields also
99
+ * accept a plain string (applies to both timings) or a partial variant pair
100
+ * (the missing variant keeps the base value).
101
+ */
102
+ type MessagesPatch<T = CancelFlowMessages> = {
103
+ [K in keyof T]?: T[K] extends string ? string : T[K] extends TimingAware ? string | Partial<TimingVariants> : MessagesPatch<T[K]>;
104
+ };
105
+ interface I18nConfig {
106
+ /** UI language. Defaults to the browser language, falling back to `'en'`. */
107
+ locale?: string;
108
+ /** Per-locale message overrides, e.g. `{ en: { confirm: { cta: 'Turn off auto-renew' } } }`. */
109
+ messages?: Record<string, MessagesPatch>;
110
+ }
111
+ declare const defaultMessages: CancelFlowMessages;
112
+ /**
113
+ * Pick the string for the flow's effective cancel timing. `null` (timing
114
+ * unknown — local mode) behaves like period-end, matching the default the
115
+ * cancel action itself uses.
116
+ */
117
+ declare function selectTiming(value: TimingAware, cancelAtPeriodEnd: boolean | null): string;
118
+ /** Replace `{name}` tokens. Unknown tokens are left in place. */
119
+ declare function formatMessage(template: string, vars: Record<string, string | number>): string;
120
+ /**
121
+ * Resolve the full catalog for a locale. Layers, lowest to highest: built-in
122
+ * defaults, then `orgMessages` (dashboard-configured overrides delivered on
123
+ * the token-mode config), then the config's own per-locale messages — the
124
+ * developer's overrides always end up on top. Both per-language layers run
125
+ * through the same locale fallback chain.
126
+ */
127
+ declare function buildMessages(i18n?: I18nConfig, orgMessages?: Record<string, MessagesPatch>): CancelFlowMessages;
128
+
3
129
  interface DirectAddress {
4
130
  line1?: string;
5
131
  line2?: string;
@@ -444,10 +570,14 @@ interface ModalProps {
444
570
  interface CloseButtonProps {
445
571
  onClose: () => void;
446
572
  className?: string;
573
+ /** Accessible label. Defaults to "Close". */
574
+ label?: string;
447
575
  }
448
576
  interface BackButtonProps {
449
577
  onBack: () => void;
450
578
  className?: string;
579
+ /** Visible label. Defaults to "Back". */
580
+ label?: string;
451
581
  }
452
582
  interface SurveyStepProps {
453
583
  title: string;
@@ -464,6 +594,8 @@ interface SurveyStepProps {
464
594
  onNext: () => void;
465
595
  classNames?: SurveyClassNames;
466
596
  components?: Partial<ComponentOverrides>;
597
+ /** Resolved message catalog. Default components fall back to `defaultMessages` when absent. */
598
+ messages?: CancelFlowMessages;
467
599
  }
468
600
  interface OfferStepProps {
469
601
  title?: string;
@@ -486,6 +618,8 @@ interface OfferStepProps {
486
618
  * implementations can ignore this.
487
619
  */
488
620
  components?: Partial<ComponentOverrides>;
621
+ /** Resolved message catalog. Default components fall back to `defaultMessages` when absent. */
622
+ messages?: CancelFlowMessages;
489
623
  }
490
624
  interface FeedbackStepProps {
491
625
  title: string;
@@ -499,6 +633,8 @@ interface FeedbackStepProps {
499
633
  onChange: (text: string) => void;
500
634
  onSubmit: () => void;
501
635
  classNames?: FeedbackClassNames;
636
+ /** Resolved message catalog. Default components fall back to `defaultMessages` when absent. */
637
+ messages?: CancelFlowMessages;
502
638
  }
503
639
  interface ConfirmStepProps {
504
640
  title: string;
@@ -509,20 +645,33 @@ interface ConfirmStepProps {
509
645
  lossesLabel?: string;
510
646
  confirmLabel: string;
511
647
  goBackLabel: string;
648
+ /**
649
+ * Timing-resolved access notice ("Your access continues until June 14, 2026."),
650
+ * rendered between the loss list and the confirm button. Absent when the
651
+ * period end is unknown or the resolved message is empty.
652
+ */
653
+ periodEndNotice?: string;
512
654
  onConfirm: () => Promise<void>;
513
655
  onGoBack: () => void;
514
656
  isProcessing: boolean;
515
657
  classNames?: ConfirmClassNames;
658
+ /** Resolved message catalog. Default components fall back to `defaultMessages` when absent. */
659
+ messages?: CancelFlowMessages;
516
660
  }
517
661
  interface SuccessStepProps {
518
662
  outcome: 'saved' | 'cancelled';
519
663
  offer?: OfferDecision;
664
+ /** The accepted offer (consumer-facing shape, incl. any accept result).
665
+ * Present when outcome is 'saved'. */
666
+ acceptedOffer?: AcceptedOffer;
520
667
  title: string;
521
668
  description?: string;
522
669
  customer: DirectCustomer | null;
523
670
  subscriptions: DirectSubscription[];
524
671
  onClose: () => void;
525
672
  classNames?: SuccessClassNames;
673
+ /** Resolved message catalog. Default components fall back to `defaultMessages` when absent. */
674
+ messages?: CancelFlowMessages;
526
675
  }
527
676
  interface ReasonButtonProps {
528
677
  reason: ReasonConfig;
@@ -537,10 +686,21 @@ interface FlowState {
537
686
  followupResponse: string;
538
687
  feedback: string;
539
688
  outcome: 'saved' | 'cancelled' | null;
689
+ /** The offer the customer accepted, set alongside outcome 'saved'. Drives
690
+ * per-offer success copy; `null` until then and for cancellations. */
691
+ acceptedOffer: AcceptedOffer | null;
540
692
  isProcessing: boolean;
541
693
  error: Error | null;
542
694
  customer: DirectCustomer | null;
543
695
  subscriptions: DirectSubscription[];
696
+ /**
697
+ * Effective cancel timing for this flow: the server-resolved value per
698
+ * blueprint (token mode), else the developer's `cancelAtPeriodEnd`
699
+ * declaration (local mode), else `null` — unknown. Drives timing-aware
700
+ * messages; `null` reads as period-end, matching the default the cancel
701
+ * action uses.
702
+ */
703
+ cancelAtPeriodEnd: boolean | null;
544
704
  }
545
705
  declare const MODES: readonly ["live", "test", "sandbox"];
546
706
  /**
@@ -574,6 +734,22 @@ interface FlowConfig extends FlowCallbacks {
574
734
  * this field.
575
735
  */
576
736
  mode?: Mode;
737
+ /**
738
+ * Locale and message overrides for the SDK's own strings (buttons, loading
739
+ * and confirmation chrome). Flow content — step titles, offer copy — is
740
+ * authored in the dashboard and localized server-side; override it there or
741
+ * via `steps`. Read once at mount, like `steps`.
742
+ */
743
+ i18n?: I18nConfig;
744
+ /**
745
+ * Local-mode declaration of your billing behavior: does cancellation take
746
+ * effect at the end of the billing period (`true`) or immediately
747
+ * (`false`)? Drives timing-aware messages and the confirm step's
748
+ * access-until notice. In token mode this is ignored: the server-resolved
749
+ * value is authoritative, and if the server omits it the timing is treated
750
+ * as unknown rather than falling back to this declaration.
751
+ */
752
+ cancelAtPeriodEnd?: boolean;
577
753
  }
578
754
  type OfferCallback = (offer: AcceptedOffer, customer: DirectCustomer | null) => Promise<void> | void;
579
755
  type CancelCallback = (customer: DirectCustomer | null) => Promise<void> | void;
@@ -617,6 +793,10 @@ interface CancelFlowProps extends FlowCallbacks {
617
793
  apiBaseUrl?: string;
618
794
  /** See FlowConfig.mode. Ignored in token mode (the token is authoritative). */
619
795
  mode?: Mode;
796
+ /** See FlowConfig.i18n. */
797
+ i18n?: I18nConfig;
798
+ /** See FlowConfig.cancelAtPeriodEnd. Local mode only; the token config wins. */
799
+ cancelAtPeriodEnd?: boolean;
620
800
  appearance?: Appearance;
621
801
  classNames?: StructuralClassNames;
622
802
  components?: Partial<ComponentOverrides>;
@@ -649,4 +829,4 @@ interface ResolvedStep {
649
829
  classNames?: unknown;
650
830
  }
651
831
 
652
- export type { SuccessStep as $, AcceptedOffer as A, BackButtonProps as B, CancelFlowProps as C, DirectAddress as D, FlowState as E, FeedbackStepProps as F, Mode as G, OfferClassNames as H, OfferConfig as I, OfferCopy as J, OfferDecision as K, OfferStep as L, ModalProps as M, PlanChangeOffer as N, OfferStepProps as O, PauseOffer as P, PlanOption as Q, ReasonButtonProps as R, SuccessStepProps as S, ReasonConfig as T, RebateOffer as U, RedirectOffer as V, ResolvedStep as W, Step as X, StructuralClassNames as Y, SubscriptionStatus as Z, SuccessClassNames as _, ConfirmStepProps as a, SurveyClassNames as a0, SurveyStep as a1, TrialExtensionOffer as a2, SurveyStepProps as b, CloseButtonProps as c, Appearance as d, AppearanceVariables as e, BuiltInOfferConfig as f, BuiltInStep as g, BuiltInStepType as h, ComponentOverrides as i, ConfirmClassNames as j, ConfirmStep as k, ContactOffer as l, CustomComponents as m, CustomOfferConfig as n, CustomOfferProps as o, CustomStepConfig as p, CustomStepProps as q, DirectCoupon as r, DirectCustomer as s, DirectPrice as t, DirectSubscription as u, DirectSubscriptionItem as v, DiscountOffer as w, FeedbackClassNames as x, FeedbackStep as y, FlowConfig as z };
832
+ export { type Step as $, type AcceptedOffer as A, type BackButtonProps as B, type CancelFlowProps as C, type DirectAddress as D, type FlowConfig as E, type FeedbackStepProps as F, type FlowState as G, type MessagesPatch as H, type I18nConfig as I, type Mode as J, type OfferClassNames as K, type OfferConfig as L, type ModalProps as M, type OfferCopy as N, type OfferStepProps as O, type OfferDecision as P, type OfferStep as Q, type ReasonButtonProps as R, type SuccessStepProps as S, type PauseOffer as T, type PlanChangeOffer as U, type PlanOption as V, type ReasonConfig as W, type RebateOffer as X, type RedirectOffer as Y, type ResolvedStep as Z, type SavedOfferCopy as _, type ConfirmStepProps as a, type StructuralClassNames as a0, type SubscriptionStatus as a1, type SuccessClassNames as a2, type SuccessStep as a3, type SurveyClassNames as a4, type SurveyStep as a5, type TimingAware as a6, type TimingVariants as a7, type TrialExtensionOffer as a8, buildMessages as a9, defaultMessages as aa, formatMessage as ab, selectTiming as ac, type SurveyStepProps as b, type CloseButtonProps as c, type Appearance as d, type AppearanceVariables as e, type BuiltInOfferConfig as f, type BuiltInStep as g, type BuiltInStepType as h, type CancelFlowMessages as i, type ComponentOverrides as j, type ConfirmClassNames as k, type ConfirmStep as l, type ContactOffer as m, type CustomComponents as n, type CustomOfferConfig as o, type CustomOfferProps as p, type CustomStepConfig as q, type CustomStepProps as r, type DirectCoupon as s, type DirectCustomer as t, type DirectPrice as u, type DirectSubscription as v, type DirectSubscriptionItem as w, type DiscountOffer as x, type FeedbackClassNames as y, type FeedbackStep as z };
@@ -1,5 +1,131 @@
1
1
  import { ReactNode, ReactElement, ComponentType } from 'react';
2
2
 
3
+ /** Both timing variants of a message. Which one renders is decided by the
4
+ * flow's effective cancel timing (`FlowState.cancelAtPeriodEnd`). */
5
+ interface TimingVariants {
6
+ immediate: string;
7
+ atPeriodEnd: string;
8
+ }
9
+ /**
10
+ * A message that may differ by cancellation timing. Plain strings render
11
+ * as-is in both cases; pass the object form when the wording should change
12
+ * (e.g. "Cancel" vs "Turn off auto-renew").
13
+ */
14
+ type TimingAware = string | TimingVariants;
15
+ /** Success-screen copy for one accepted offer type. */
16
+ interface SavedOfferCopy {
17
+ title: string;
18
+ description: string;
19
+ }
20
+ interface CancelFlowMessages {
21
+ common: {
22
+ continue: string;
23
+ back: string;
24
+ close: string;
25
+ done: string;
26
+ processing: string;
27
+ tryAgain: string;
28
+ loading: string;
29
+ loadError: string;
30
+ error: string;
31
+ day: string;
32
+ days: string;
33
+ month: string;
34
+ months: string;
35
+ };
36
+ survey: {
37
+ title: string;
38
+ followupPlaceholder: string;
39
+ followupAriaLabel: string;
40
+ };
41
+ feedback: {
42
+ title: string;
43
+ placeholder: string;
44
+ /** Used instead of `placeholder` when the step sets `minLength`. Supports `{minLength}`. */
45
+ placeholderWithMin: string;
46
+ };
47
+ confirm: {
48
+ title: string;
49
+ lossesLabel: string;
50
+ cta: TimingAware;
51
+ goBack: string;
52
+ /** Shown between the description and the confirm button. Supports
53
+ * `{periodEnd}`. The default immediate variant is empty, which
54
+ * suppresses the notice for immediate timing; empty OVERRIDE values are
55
+ * dropped like any blank override, so to remove the notice entirely
56
+ * replace the `Confirm` component or hide it via
57
+ * `classNames.periodEndNotice`. */
58
+ periodEndNotice: TimingAware;
59
+ };
60
+ success: {
61
+ saved: {
62
+ /** Generic fallback — used for offer types without their own entry
63
+ * (contact, redirect, custom types). */
64
+ title: string;
65
+ description: string;
66
+ discount: SavedOfferCopy;
67
+ pause: SavedOfferCopy & {
68
+ /** Used instead of `description` when the resume date is known
69
+ * (the built-in pause UI always supplies it). Supports `{resumeDate}`. */
70
+ resumeDescription: string;
71
+ };
72
+ trial_extension: SavedOfferCopy;
73
+ plan_change: SavedOfferCopy;
74
+ rebate: SavedOfferCopy;
75
+ };
76
+ cancelled: {
77
+ title: TimingAware;
78
+ description: TimingAware;
79
+ };
80
+ };
81
+ offer: {
82
+ limitedTimeEyebrow: string;
83
+ pauseEyebrow: string;
84
+ newEndDateLabel: string;
85
+ currentPlanBadge: string;
86
+ /** CTA when a plan is selected in a plan-change offer. Supports `{planName}`. */
87
+ switchToCta: string;
88
+ rebate: {
89
+ paidLabel: string;
90
+ moneyBackLabel: string;
91
+ /** Tax parenthetical after the money-back label. Supports `{amount}`. */
92
+ inclTax: string;
93
+ netLabel: string;
94
+ };
95
+ };
96
+ }
97
+ /**
98
+ * Recursive partial of the catalog for overrides. Timing-aware fields also
99
+ * accept a plain string (applies to both timings) or a partial variant pair
100
+ * (the missing variant keeps the base value).
101
+ */
102
+ type MessagesPatch<T = CancelFlowMessages> = {
103
+ [K in keyof T]?: T[K] extends string ? string : T[K] extends TimingAware ? string | Partial<TimingVariants> : MessagesPatch<T[K]>;
104
+ };
105
+ interface I18nConfig {
106
+ /** UI language. Defaults to the browser language, falling back to `'en'`. */
107
+ locale?: string;
108
+ /** Per-locale message overrides, e.g. `{ en: { confirm: { cta: 'Turn off auto-renew' } } }`. */
109
+ messages?: Record<string, MessagesPatch>;
110
+ }
111
+ declare const defaultMessages: CancelFlowMessages;
112
+ /**
113
+ * Pick the string for the flow's effective cancel timing. `null` (timing
114
+ * unknown — local mode) behaves like period-end, matching the default the
115
+ * cancel action itself uses.
116
+ */
117
+ declare function selectTiming(value: TimingAware, cancelAtPeriodEnd: boolean | null): string;
118
+ /** Replace `{name}` tokens. Unknown tokens are left in place. */
119
+ declare function formatMessage(template: string, vars: Record<string, string | number>): string;
120
+ /**
121
+ * Resolve the full catalog for a locale. Layers, lowest to highest: built-in
122
+ * defaults, then `orgMessages` (dashboard-configured overrides delivered on
123
+ * the token-mode config), then the config's own per-locale messages — the
124
+ * developer's overrides always end up on top. Both per-language layers run
125
+ * through the same locale fallback chain.
126
+ */
127
+ declare function buildMessages(i18n?: I18nConfig, orgMessages?: Record<string, MessagesPatch>): CancelFlowMessages;
128
+
3
129
  interface DirectAddress {
4
130
  line1?: string;
5
131
  line2?: string;
@@ -444,10 +570,14 @@ interface ModalProps {
444
570
  interface CloseButtonProps {
445
571
  onClose: () => void;
446
572
  className?: string;
573
+ /** Accessible label. Defaults to "Close". */
574
+ label?: string;
447
575
  }
448
576
  interface BackButtonProps {
449
577
  onBack: () => void;
450
578
  className?: string;
579
+ /** Visible label. Defaults to "Back". */
580
+ label?: string;
451
581
  }
452
582
  interface SurveyStepProps {
453
583
  title: string;
@@ -464,6 +594,8 @@ interface SurveyStepProps {
464
594
  onNext: () => void;
465
595
  classNames?: SurveyClassNames;
466
596
  components?: Partial<ComponentOverrides>;
597
+ /** Resolved message catalog. Default components fall back to `defaultMessages` when absent. */
598
+ messages?: CancelFlowMessages;
467
599
  }
468
600
  interface OfferStepProps {
469
601
  title?: string;
@@ -486,6 +618,8 @@ interface OfferStepProps {
486
618
  * implementations can ignore this.
487
619
  */
488
620
  components?: Partial<ComponentOverrides>;
621
+ /** Resolved message catalog. Default components fall back to `defaultMessages` when absent. */
622
+ messages?: CancelFlowMessages;
489
623
  }
490
624
  interface FeedbackStepProps {
491
625
  title: string;
@@ -499,6 +633,8 @@ interface FeedbackStepProps {
499
633
  onChange: (text: string) => void;
500
634
  onSubmit: () => void;
501
635
  classNames?: FeedbackClassNames;
636
+ /** Resolved message catalog. Default components fall back to `defaultMessages` when absent. */
637
+ messages?: CancelFlowMessages;
502
638
  }
503
639
  interface ConfirmStepProps {
504
640
  title: string;
@@ -509,20 +645,33 @@ interface ConfirmStepProps {
509
645
  lossesLabel?: string;
510
646
  confirmLabel: string;
511
647
  goBackLabel: string;
648
+ /**
649
+ * Timing-resolved access notice ("Your access continues until June 14, 2026."),
650
+ * rendered between the loss list and the confirm button. Absent when the
651
+ * period end is unknown or the resolved message is empty.
652
+ */
653
+ periodEndNotice?: string;
512
654
  onConfirm: () => Promise<void>;
513
655
  onGoBack: () => void;
514
656
  isProcessing: boolean;
515
657
  classNames?: ConfirmClassNames;
658
+ /** Resolved message catalog. Default components fall back to `defaultMessages` when absent. */
659
+ messages?: CancelFlowMessages;
516
660
  }
517
661
  interface SuccessStepProps {
518
662
  outcome: 'saved' | 'cancelled';
519
663
  offer?: OfferDecision;
664
+ /** The accepted offer (consumer-facing shape, incl. any accept result).
665
+ * Present when outcome is 'saved'. */
666
+ acceptedOffer?: AcceptedOffer;
520
667
  title: string;
521
668
  description?: string;
522
669
  customer: DirectCustomer | null;
523
670
  subscriptions: DirectSubscription[];
524
671
  onClose: () => void;
525
672
  classNames?: SuccessClassNames;
673
+ /** Resolved message catalog. Default components fall back to `defaultMessages` when absent. */
674
+ messages?: CancelFlowMessages;
526
675
  }
527
676
  interface ReasonButtonProps {
528
677
  reason: ReasonConfig;
@@ -537,10 +686,21 @@ interface FlowState {
537
686
  followupResponse: string;
538
687
  feedback: string;
539
688
  outcome: 'saved' | 'cancelled' | null;
689
+ /** The offer the customer accepted, set alongside outcome 'saved'. Drives
690
+ * per-offer success copy; `null` until then and for cancellations. */
691
+ acceptedOffer: AcceptedOffer | null;
540
692
  isProcessing: boolean;
541
693
  error: Error | null;
542
694
  customer: DirectCustomer | null;
543
695
  subscriptions: DirectSubscription[];
696
+ /**
697
+ * Effective cancel timing for this flow: the server-resolved value per
698
+ * blueprint (token mode), else the developer's `cancelAtPeriodEnd`
699
+ * declaration (local mode), else `null` — unknown. Drives timing-aware
700
+ * messages; `null` reads as period-end, matching the default the cancel
701
+ * action uses.
702
+ */
703
+ cancelAtPeriodEnd: boolean | null;
544
704
  }
545
705
  declare const MODES: readonly ["live", "test", "sandbox"];
546
706
  /**
@@ -574,6 +734,22 @@ interface FlowConfig extends FlowCallbacks {
574
734
  * this field.
575
735
  */
576
736
  mode?: Mode;
737
+ /**
738
+ * Locale and message overrides for the SDK's own strings (buttons, loading
739
+ * and confirmation chrome). Flow content — step titles, offer copy — is
740
+ * authored in the dashboard and localized server-side; override it there or
741
+ * via `steps`. Read once at mount, like `steps`.
742
+ */
743
+ i18n?: I18nConfig;
744
+ /**
745
+ * Local-mode declaration of your billing behavior: does cancellation take
746
+ * effect at the end of the billing period (`true`) or immediately
747
+ * (`false`)? Drives timing-aware messages and the confirm step's
748
+ * access-until notice. In token mode this is ignored: the server-resolved
749
+ * value is authoritative, and if the server omits it the timing is treated
750
+ * as unknown rather than falling back to this declaration.
751
+ */
752
+ cancelAtPeriodEnd?: boolean;
577
753
  }
578
754
  type OfferCallback = (offer: AcceptedOffer, customer: DirectCustomer | null) => Promise<void> | void;
579
755
  type CancelCallback = (customer: DirectCustomer | null) => Promise<void> | void;
@@ -617,6 +793,10 @@ interface CancelFlowProps extends FlowCallbacks {
617
793
  apiBaseUrl?: string;
618
794
  /** See FlowConfig.mode. Ignored in token mode (the token is authoritative). */
619
795
  mode?: Mode;
796
+ /** See FlowConfig.i18n. */
797
+ i18n?: I18nConfig;
798
+ /** See FlowConfig.cancelAtPeriodEnd. Local mode only; the token config wins. */
799
+ cancelAtPeriodEnd?: boolean;
620
800
  appearance?: Appearance;
621
801
  classNames?: StructuralClassNames;
622
802
  components?: Partial<ComponentOverrides>;
@@ -649,4 +829,4 @@ interface ResolvedStep {
649
829
  classNames?: unknown;
650
830
  }
651
831
 
652
- export type { SuccessStep as $, AcceptedOffer as A, BackButtonProps as B, CancelFlowProps as C, DirectAddress as D, FlowState as E, FeedbackStepProps as F, Mode as G, OfferClassNames as H, OfferConfig as I, OfferCopy as J, OfferDecision as K, OfferStep as L, ModalProps as M, PlanChangeOffer as N, OfferStepProps as O, PauseOffer as P, PlanOption as Q, ReasonButtonProps as R, SuccessStepProps as S, ReasonConfig as T, RebateOffer as U, RedirectOffer as V, ResolvedStep as W, Step as X, StructuralClassNames as Y, SubscriptionStatus as Z, SuccessClassNames as _, ConfirmStepProps as a, SurveyClassNames as a0, SurveyStep as a1, TrialExtensionOffer as a2, SurveyStepProps as b, CloseButtonProps as c, Appearance as d, AppearanceVariables as e, BuiltInOfferConfig as f, BuiltInStep as g, BuiltInStepType as h, ComponentOverrides as i, ConfirmClassNames as j, ConfirmStep as k, ContactOffer as l, CustomComponents as m, CustomOfferConfig as n, CustomOfferProps as o, CustomStepConfig as p, CustomStepProps as q, DirectCoupon as r, DirectCustomer as s, DirectPrice as t, DirectSubscription as u, DirectSubscriptionItem as v, DiscountOffer as w, FeedbackClassNames as x, FeedbackStep as y, FlowConfig as z };
832
+ export { type Step as $, type AcceptedOffer as A, type BackButtonProps as B, type CancelFlowProps as C, type DirectAddress as D, type FlowConfig as E, type FeedbackStepProps as F, type FlowState as G, type MessagesPatch as H, type I18nConfig as I, type Mode as J, type OfferClassNames as K, type OfferConfig as L, type ModalProps as M, type OfferCopy as N, type OfferStepProps as O, type OfferDecision as P, type OfferStep as Q, type ReasonButtonProps as R, type SuccessStepProps as S, type PauseOffer as T, type PlanChangeOffer as U, type PlanOption as V, type ReasonConfig as W, type RebateOffer as X, type RedirectOffer as Y, type ResolvedStep as Z, type SavedOfferCopy as _, type ConfirmStepProps as a, type StructuralClassNames as a0, type SubscriptionStatus as a1, type SuccessClassNames as a2, type SuccessStep as a3, type SurveyClassNames as a4, type SurveyStep as a5, type TimingAware as a6, type TimingVariants as a7, type TrialExtensionOffer as a8, buildMessages as a9, defaultMessages as aa, formatMessage as ab, selectTiming as ac, type SurveyStepProps as b, type CloseButtonProps as c, type Appearance as d, type AppearanceVariables as e, type BuiltInOfferConfig as f, type BuiltInStep as g, type BuiltInStepType as h, type CancelFlowMessages as i, type ComponentOverrides as j, type ConfirmClassNames as k, type ConfirmStep as l, type ContactOffer as m, type CustomComponents as n, type CustomOfferConfig as o, type CustomOfferProps as p, type CustomStepConfig as q, type CustomStepProps as r, type DirectCoupon as s, type DirectCustomer as t, type DirectPrice as u, type DirectSubscription as v, type DirectSubscriptionItem as w, type DiscountOffer as x, type FeedbackClassNames as y, type FeedbackStep as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@churnkey/react",
3
- "version": "0.6.5",
3
+ "version": "0.7.0",
4
4
  "description": "Production-ready cancel flow for React. Drop-in component, headless hook, or full customization. Works standalone or with Churnkey for AI-powered retention.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/core/format.ts"],"names":[],"mappings":";AAIA,IAAM,uBAAA,uBAAmD,GAAA,CAAI;AAAA,EAC3D,KAAA;AAAA,EACA,KAAA;AAAA,EACA,KAAA;AAAA,EACA,KAAA;AAAA,EACA,KAAA;AAAA,EACA,KAAA;AAAA,EACA,KAAA;AAAA,EACA,KAAA;AAAA,EACA,KAAA;AAAA,EACA,KAAA;AAAA,EACA,KAAA;AAAA,EACA,KAAA;AAAA,EACA,KAAA;AAAA,EACA,KAAA;AAAA,EACA,KAAA;AAAA,EACA;AACF,CAAC,CAAA;AAID,IAAM,wBAAA,mBAAgD,IAAI,GAAA,CAAI,CAAC,KAAA,EAAO,KAAA,EAAO,KAAA,EAAO,KAAA,EAAO,KAAA,EAAO,KAAA,EAAO,KAAK,CAAC,CAAA;AAExG,SAAS,sBAAsB,QAAA,EAA2B;AAC/D,EAAA,OAAO,uBAAA,CAAwB,GAAA,CAAI,QAAA,CAAS,WAAA,EAAa,CAAA;AAC3D;AAEO,SAAS,uBAAuB,QAAA,EAA2B;AAChE,EAAA,OAAO,wBAAA,CAAyB,GAAA,CAAI,QAAA,CAAS,WAAA,EAAa,C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CAAA,EAAI,gBAAA,KAAqB,CAAA,GAAI,OAAA,GAAU,QAAQ,CAAA,CAAA,GACtE,EAAA;AACV,EAAA,OAAO,IAAA,GAAO,CAAA,EAAG,MAAM,CAAA,CAAA,EAAI,IAAI,CAAA,CAAA,GAAK,MAAA;AACtC","file":"chunk-EYIGZLVT.js","sourcesContent":["import type { DirectSubscription } from './types'\n\n// Currencies whose smallest unit equals one major unit (no fractional part).\n// Stripe and most billing providers store these without an implicit /100.\nconst ZERO_DECIMAL_CURRENCIES: ReadonlySet<string> = new Set([\n 'BIF',\n 'CLP',\n 'DJF',\n 'GNF',\n 'JPY',\n 'KMF',\n 'KRW',\n 'MGA',\n 'PYG',\n 'RWF',\n 'UGX',\n 'VND',\n 'VUV',\n 'XAF',\n 'XOF',\n 'XPF',\n])\n\n// Middle-Eastern currencies that use three fractional digits (1000 divisor).\n// Without this bucket, JOD/KWD amounts would be off by 10x in display.\nconst THREE_DECIMAL_CURRENCIES: ReadonlySet<string> = new Set(['BHD', 'IQD', 'JOD', 'KWD', 'LYD', 'OMR', 'TND'])\n\nexport function isZeroDecimalCurrency(currency: string): boolean {\n return ZERO_DECIMAL_CURRENCIES.has(currency.toUpperCase())\n}\n\nexport function isThreeDecimalCurrency(currency: string): boolean {\n return THREE_DECIMAL_CURRENCIES.has(currency.toUpperCase())\n}\n\n/**\n * Smallest-unit divisor for a currency. 1 for zero-decimal (JPY), 1000 for\n * three-decimal (KWD), 100 for everything else. Used to convert provider\n * amounts (which are always in the smallest unit) into the major unit for\n * display.\n */\nexport function getCurrencyDivisor(currency = 'USD'): number {\n if (isZeroDecimalCurrency(currency)) return 1\n if (isThreeDecimalCurrency(currency)) return 1000\n return 100\n}\n\n/**\n * Converts a Direct.Price.amount.value (smallest currency unit) into the\n * major unit used for display.\n */\nexport function convertFromMinorUnits(value: number, currency = 'USD'): number {\n return value / getCurrencyDivisor(currency)\n}\n\n/**\n * Format an amount already in the major unit. Uses `narrowSymbol` so output\n * reads \"$29\" rather than \"US$29\", and trims trailing zero fractions so\n * whole amounts render compactly.\n */\nexport function formatPrice(amount: number, currency = 'USD', locale?: string): string {\n try {\n const formatted = new Intl.NumberFormat(locale, {\n style: 'currency',\n currency,\n currencyDisplay: 'narrowSymbol',\n }).format(amount)\n return formatted.replace(/[.,]00$/, '')\n } catch {\n return `${currency} ${amount.toFixed(2)}`\n }\n}\n\n/** Convenience: format a Direct-shape minor-unit amount in one call. */\nexport function formatPriceFromMinor(value: number, currency = 'USD', locale?: string): string {\n return formatPrice(convertFromMinorUnits(value, currency), currency, locale)\n}\n\nexport function calculateDiscountedPrice(originalPrice: number, percentOff: number): number {\n return originalPrice * (1 - percentOff / 100)\n}\n\n// ─── Dates ────────────────────────────────────────────────────────────────\n\n/** \"Apr 30, 2026\" — used for resume dates and other full-date contexts. */\nexport function formatShortDate(date: Date, locale?: string): string {\n return date.toLocaleDateString(locale, { month: 'short', day: 'numeric', year: 'numeric' })\n}\n\n/** \"Apr 30\" — used when the year is implied by context. */\nexport function formatMonthDay(date: Date, locale?: string): string {\n return date.toLocaleDateString(locale, { month: 'short', day: 'numeric' })\n}\n\n/** \"April 30\" — long month form for prominent date displays. */\nexport function formatMonthDayLong(date: Date, locale?: string): string {\n return date.toLocaleDateString(locale, { month: 'long', day: 'numeric' })\n}\n\n/**\n * Long-form access period end (\"June 14, 2026\") for the first subscription's\n * current period. Returns null for canceled subscriptions, missing periods,\n * and unparseable dates so Confirm can drop the \"access continues until\"\n * notice cleanly instead of rendering \"Invalid Date\".\n */\nexport function formatPeriodEnd(\n subscriptions: DirectSubscription[] | null | undefined,\n locale?: string,\n): string | null {\n const status = subscriptions?.[0]?.status\n if (!status || !('currentPeriod' in status) || !status.currentPeriod?.end) return null\n const end = status.currentPeriod.end\n const d = end instanceof Date ? end : new Date(end)\n if (Number.isNaN(d.getTime())) return null\n return d.toLocaleDateString(locale, { month: 'long', day: 'numeric', year: 'numeric' })\n}\n\n// ─── Discount phrasing ─────────────────────────────────────────────────────\n\n/**\n * Renders the discount as a single human-readable sentence:\n * \"25% off for 3 months\" / \"$5 off your next renewal\" / \"20% off for life\"\n *\n * Mirrors the embed's couponToString helper so SDK and embed use the same\n * phrasing for the same offer shape.\n */\nexport function discountPhrase(opts: {\n percentOff?: number\n /** Smallest currency unit (cents for USD). */\n amountOff?: number\n currency?: string\n duration?: 'once' | 'repeating' | 'forever'\n durationInMonths?: number\n}): string {\n const { percentOff, amountOff, currency, duration, durationInMonths } = opts\n const amount =\n percentOff != null\n ? `${percentOff}% off`\n : amountOff != null\n ? `${formatPriceFromMinor(amountOff, currency)} off`\n : 'discount'\n const tail =\n duration === 'once'\n ? 'your next renewal'\n : duration === 'forever'\n ? 'for life'\n : durationInMonths\n ? `for ${durationInMonths} ${durationInMonths === 1 ? 'month' : 'months'}`\n : ''\n return tail ? `${amount} ${tail}` : amount\n}\n"]}