@mesub/react 0.0.0-stage → 0.1.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.
@@ -0,0 +1,152 @@
1
+ import * as react from 'react';
2
+ import { ReactNode, ButtonHTMLAttributes, HTMLAttributes } from 'react';
3
+
4
+ /**
5
+ * What the merchant's routes serve, as `@mesub/node` writes it: snake case,
6
+ * dates as ISO strings, chain numbers as strings.
7
+ */
8
+ /** What Mesub knows of a plan's token. Never the merchant's words. */
9
+ interface MesubToken {
10
+ symbol: string | null;
11
+ name: string | null;
12
+ logo_url: string | null;
13
+ verified: boolean;
14
+ }
15
+ /** A plan, as `GET /plans/:slug` serves it. */
16
+ interface MesubPlan {
17
+ slug: string;
18
+ name: string;
19
+ description: string | null;
20
+ project_name: string;
21
+ logo_url: string | null;
22
+ amount: string;
23
+ amount_display: string;
24
+ decimals: number;
25
+ symbol: string | null;
26
+ mint: string;
27
+ token?: MesubToken | null | undefined;
28
+ amount_usd?: string | null | undefined;
29
+ period_hours: number;
30
+ network: 'devnet' | 'mainnet-beta';
31
+ status: 'active' | 'sunset';
32
+ available: boolean;
33
+ ends_at: string | null;
34
+ }
35
+ type MesubSubscriptionStatus = 'pending' | 'active' | 'cancelled' | 'unpaid' | 'stopped' | 'ended' | 'failed' | 'expired' | 'superseded';
36
+ /** Why charges are held back: the merchant's own setup by name, `mesub` for any cause of Mesub's. */
37
+ type MesubBlockedReason = 'puller_not_allowed' | 'receiver_not_allowed' | 'receiver_account_missing' | 'receiver_account_frozen' | 'mint_gone' | 'mesub';
38
+ /**
39
+ * Why a `stopped` one stopped (Mesub-io/backend#402): every retry failed, the
40
+ * Free date to pay by passed, or the wallet closed the account that lets
41
+ * Mesub charge it, for good. A newer one may come.
42
+ */
43
+ type MesubStopReason = 'out_of_retries' | 'retry_deadline_passed' | 'authority_closed';
44
+ /** A subscription of the signed-in customer, as `GET /subscriptions` lists it. */
45
+ interface MesubSubscription {
46
+ id: string;
47
+ status: MesubSubscriptionStatus;
48
+ paused: boolean;
49
+ end_reason: string | null;
50
+ late_reason: string | null;
51
+ stop_reason?: MesubStopReason | null;
52
+ access: boolean;
53
+ payment_status: 'paid' | 'late' | 'none';
54
+ blocked_since?: string | null;
55
+ blocked_reason?: MesubBlockedReason | null;
56
+ plan: string | null;
57
+ wallet: string;
58
+ current_period_start: string | null;
59
+ current_period_end: string | null;
60
+ next_charge_at: string | null;
61
+ next_retry_at: string | null;
62
+ retry_deadline: string | null;
63
+ access_until: string | null;
64
+ closable?: boolean;
65
+ closable_from?: string | null;
66
+ created_at: string;
67
+ confirmed_at: string | null;
68
+ }
69
+ /** What a subscription allows now. */
70
+ type MesubAction = 'cancel' | 'resume' | 'close';
71
+
72
+ type FetchLike = (input: string, init: RequestInit) => Promise<Response>;
73
+
74
+ /** A Wallet Standard chain, such as `solana:mainnet` or `solana:devnet`. */
75
+ type SolanaChain = `solana:${string}`;
76
+
77
+ type MesubTheme = 'light' | 'dark' | 'auto';
78
+ /** Where a subscribe stands: `open` is the dialog up with nothing being signed. */
79
+ type SubscribeState = 'idle' | 'open' | 'signing' | 'confirming' | 'subscribed';
80
+
81
+ interface MesubProviderProps {
82
+ endpoint: string;
83
+ chain?: SolanaChain | undefined;
84
+ fetch?: FetchLike | undefined;
85
+ theme?: MesubTheme | undefined;
86
+ manageUrl?: string | null | undefined;
87
+ children?: ReactNode;
88
+ }
89
+ /** Says where the merchant's routes are, and renders the one dialog the hooks open. */
90
+ declare function MesubProvider({ endpoint, chain, fetch, theme, manageUrl, children, }: MesubProviderProps): react.JSX.Element;
91
+
92
+ interface UseSubscribeOptions {
93
+ onSubscribed?: ((subscription: MesubSubscription) => void) | undefined;
94
+ }
95
+ /** What `useSubscribe()` returns. */
96
+ interface UseSubscribeResult {
97
+ state: SubscribeState;
98
+ subscription: MesubSubscription | null;
99
+ signature: string | null;
100
+ subscribe(): Promise<MesubSubscription | null>;
101
+ }
102
+ /** The subscribe flow, for a button of your own: `subscribe()` opens the Mesub checkout. */
103
+ declare function useSubscribe(plan: string, options?: UseSubscribeOptions): UseSubscribeResult;
104
+ interface SubscribeButtonProps extends UseSubscribeOptions, ButtonHTMLAttributes<HTMLButtonElement> {
105
+ plan: string;
106
+ }
107
+ /**
108
+ * Opens the Mesub checkout for a plan. Busy is aria-disabled, not disabled, so
109
+ * the keyboard focus stays on it; only subscribed disables it.
110
+ */
111
+ declare const SubscribeButton: react.ForwardRefExoticComponent<SubscribeButtonProps & react.RefAttributes<HTMLButtonElement>>;
112
+
113
+ /** A subscription the customer holds, with what it allows now. */
114
+ interface MesubHeldSubscription extends MesubSubscription {
115
+ action: MesubAction | null;
116
+ payable: boolean;
117
+ }
118
+ /** What a "Pay now" came to, in the words the widget shows. */
119
+ interface PayNowResult {
120
+ ok: boolean;
121
+ message: string;
122
+ retryAfter?: number;
123
+ }
124
+ /** What `useSubscriptions()` returns. */
125
+ interface UseSubscriptionsResult {
126
+ state: 'loading' | 'ready' | 'signed-out' | 'error';
127
+ subscriptions: MesubHeldSubscription[];
128
+ error: string | null;
129
+ reload(): Promise<void>;
130
+ payNow(id: string): Promise<PayNowResult>;
131
+ manage(id: string): Promise<MesubSubscription | null>;
132
+ }
133
+ /** The signed-in customer's subscriptions, read from the merchant's server, and what each allows. */
134
+ declare function useSubscriptions(): UseSubscriptionsResult;
135
+ interface ManageSubscriptionsProps extends HTMLAttributes<HTMLDivElement> {
136
+ onChanged?: ((subscription: MesubSubscription) => void) | undefined;
137
+ }
138
+ /**
139
+ * The signed-in customer's subscriptions, each with its status, its next date
140
+ * and the one thing it allows now. Styled by its data-mesub-* attributes.
141
+ */
142
+ declare function ManageSubscriptions({ onChanged, ...rest }: ManageSubscriptionsProps): react.JSX.Element;
143
+ interface ManageButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
144
+ plan?: string | undefined;
145
+ }
146
+ /**
147
+ * Opens the customer's subscription to a plan in the Mesub window: how it
148
+ * stands, what comes next, what was charged, and cancel, resume or close.
149
+ */
150
+ declare const ManageButton: react.ForwardRefExoticComponent<ManageButtonProps & react.RefAttributes<HTMLButtonElement>>;
151
+
152
+ export { type FetchLike, ManageButton, type ManageButtonProps, ManageSubscriptions, type ManageSubscriptionsProps, type MesubAction, type MesubBlockedReason, type MesubHeldSubscription, type MesubPlan, MesubProvider, type MesubProviderProps, type MesubStopReason, type MesubSubscription, type MesubSubscriptionStatus, type MesubTheme, type MesubToken, type PayNowResult, type SolanaChain, SubscribeButton, type SubscribeButtonProps, type SubscribeState, type UseSubscribeOptions, type UseSubscribeResult, type UseSubscriptionsResult, useSubscribe, useSubscriptions };
@@ -0,0 +1,152 @@
1
+ import * as react from 'react';
2
+ import { ReactNode, ButtonHTMLAttributes, HTMLAttributes } from 'react';
3
+
4
+ /**
5
+ * What the merchant's routes serve, as `@mesub/node` writes it: snake case,
6
+ * dates as ISO strings, chain numbers as strings.
7
+ */
8
+ /** What Mesub knows of a plan's token. Never the merchant's words. */
9
+ interface MesubToken {
10
+ symbol: string | null;
11
+ name: string | null;
12
+ logo_url: string | null;
13
+ verified: boolean;
14
+ }
15
+ /** A plan, as `GET /plans/:slug` serves it. */
16
+ interface MesubPlan {
17
+ slug: string;
18
+ name: string;
19
+ description: string | null;
20
+ project_name: string;
21
+ logo_url: string | null;
22
+ amount: string;
23
+ amount_display: string;
24
+ decimals: number;
25
+ symbol: string | null;
26
+ mint: string;
27
+ token?: MesubToken | null | undefined;
28
+ amount_usd?: string | null | undefined;
29
+ period_hours: number;
30
+ network: 'devnet' | 'mainnet-beta';
31
+ status: 'active' | 'sunset';
32
+ available: boolean;
33
+ ends_at: string | null;
34
+ }
35
+ type MesubSubscriptionStatus = 'pending' | 'active' | 'cancelled' | 'unpaid' | 'stopped' | 'ended' | 'failed' | 'expired' | 'superseded';
36
+ /** Why charges are held back: the merchant's own setup by name, `mesub` for any cause of Mesub's. */
37
+ type MesubBlockedReason = 'puller_not_allowed' | 'receiver_not_allowed' | 'receiver_account_missing' | 'receiver_account_frozen' | 'mint_gone' | 'mesub';
38
+ /**
39
+ * Why a `stopped` one stopped (Mesub-io/backend#402): every retry failed, the
40
+ * Free date to pay by passed, or the wallet closed the account that lets
41
+ * Mesub charge it, for good. A newer one may come.
42
+ */
43
+ type MesubStopReason = 'out_of_retries' | 'retry_deadline_passed' | 'authority_closed';
44
+ /** A subscription of the signed-in customer, as `GET /subscriptions` lists it. */
45
+ interface MesubSubscription {
46
+ id: string;
47
+ status: MesubSubscriptionStatus;
48
+ paused: boolean;
49
+ end_reason: string | null;
50
+ late_reason: string | null;
51
+ stop_reason?: MesubStopReason | null;
52
+ access: boolean;
53
+ payment_status: 'paid' | 'late' | 'none';
54
+ blocked_since?: string | null;
55
+ blocked_reason?: MesubBlockedReason | null;
56
+ plan: string | null;
57
+ wallet: string;
58
+ current_period_start: string | null;
59
+ current_period_end: string | null;
60
+ next_charge_at: string | null;
61
+ next_retry_at: string | null;
62
+ retry_deadline: string | null;
63
+ access_until: string | null;
64
+ closable?: boolean;
65
+ closable_from?: string | null;
66
+ created_at: string;
67
+ confirmed_at: string | null;
68
+ }
69
+ /** What a subscription allows now. */
70
+ type MesubAction = 'cancel' | 'resume' | 'close';
71
+
72
+ type FetchLike = (input: string, init: RequestInit) => Promise<Response>;
73
+
74
+ /** A Wallet Standard chain, such as `solana:mainnet` or `solana:devnet`. */
75
+ type SolanaChain = `solana:${string}`;
76
+
77
+ type MesubTheme = 'light' | 'dark' | 'auto';
78
+ /** Where a subscribe stands: `open` is the dialog up with nothing being signed. */
79
+ type SubscribeState = 'idle' | 'open' | 'signing' | 'confirming' | 'subscribed';
80
+
81
+ interface MesubProviderProps {
82
+ endpoint: string;
83
+ chain?: SolanaChain | undefined;
84
+ fetch?: FetchLike | undefined;
85
+ theme?: MesubTheme | undefined;
86
+ manageUrl?: string | null | undefined;
87
+ children?: ReactNode;
88
+ }
89
+ /** Says where the merchant's routes are, and renders the one dialog the hooks open. */
90
+ declare function MesubProvider({ endpoint, chain, fetch, theme, manageUrl, children, }: MesubProviderProps): react.JSX.Element;
91
+
92
+ interface UseSubscribeOptions {
93
+ onSubscribed?: ((subscription: MesubSubscription) => void) | undefined;
94
+ }
95
+ /** What `useSubscribe()` returns. */
96
+ interface UseSubscribeResult {
97
+ state: SubscribeState;
98
+ subscription: MesubSubscription | null;
99
+ signature: string | null;
100
+ subscribe(): Promise<MesubSubscription | null>;
101
+ }
102
+ /** The subscribe flow, for a button of your own: `subscribe()` opens the Mesub checkout. */
103
+ declare function useSubscribe(plan: string, options?: UseSubscribeOptions): UseSubscribeResult;
104
+ interface SubscribeButtonProps extends UseSubscribeOptions, ButtonHTMLAttributes<HTMLButtonElement> {
105
+ plan: string;
106
+ }
107
+ /**
108
+ * Opens the Mesub checkout for a plan. Busy is aria-disabled, not disabled, so
109
+ * the keyboard focus stays on it; only subscribed disables it.
110
+ */
111
+ declare const SubscribeButton: react.ForwardRefExoticComponent<SubscribeButtonProps & react.RefAttributes<HTMLButtonElement>>;
112
+
113
+ /** A subscription the customer holds, with what it allows now. */
114
+ interface MesubHeldSubscription extends MesubSubscription {
115
+ action: MesubAction | null;
116
+ payable: boolean;
117
+ }
118
+ /** What a "Pay now" came to, in the words the widget shows. */
119
+ interface PayNowResult {
120
+ ok: boolean;
121
+ message: string;
122
+ retryAfter?: number;
123
+ }
124
+ /** What `useSubscriptions()` returns. */
125
+ interface UseSubscriptionsResult {
126
+ state: 'loading' | 'ready' | 'signed-out' | 'error';
127
+ subscriptions: MesubHeldSubscription[];
128
+ error: string | null;
129
+ reload(): Promise<void>;
130
+ payNow(id: string): Promise<PayNowResult>;
131
+ manage(id: string): Promise<MesubSubscription | null>;
132
+ }
133
+ /** The signed-in customer's subscriptions, read from the merchant's server, and what each allows. */
134
+ declare function useSubscriptions(): UseSubscriptionsResult;
135
+ interface ManageSubscriptionsProps extends HTMLAttributes<HTMLDivElement> {
136
+ onChanged?: ((subscription: MesubSubscription) => void) | undefined;
137
+ }
138
+ /**
139
+ * The signed-in customer's subscriptions, each with its status, its next date
140
+ * and the one thing it allows now. Styled by its data-mesub-* attributes.
141
+ */
142
+ declare function ManageSubscriptions({ onChanged, ...rest }: ManageSubscriptionsProps): react.JSX.Element;
143
+ interface ManageButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
144
+ plan?: string | undefined;
145
+ }
146
+ /**
147
+ * Opens the customer's subscription to a plan in the Mesub window: how it
148
+ * stands, what comes next, what was charged, and cancel, resume or close.
149
+ */
150
+ declare const ManageButton: react.ForwardRefExoticComponent<ManageButtonProps & react.RefAttributes<HTMLButtonElement>>;
151
+
152
+ export { type FetchLike, ManageButton, type ManageButtonProps, ManageSubscriptions, type ManageSubscriptionsProps, type MesubAction, type MesubBlockedReason, type MesubHeldSubscription, type MesubPlan, MesubProvider, type MesubProviderProps, type MesubStopReason, type MesubSubscription, type MesubSubscriptionStatus, type MesubTheme, type MesubToken, type PayNowResult, type SolanaChain, SubscribeButton, type SubscribeButtonProps, type SubscribeState, type UseSubscribeOptions, type UseSubscribeResult, type UseSubscriptionsResult, useSubscribe, useSubscriptions };