@nozle-js/react 0.9.0 → 0.10.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.ts CHANGED
@@ -1,8 +1,75 @@
1
1
  import * as React from 'react';
2
- import React__default, { ReactNode } from 'react';
2
+ import React__default, { ReactNode, CSSProperties } from 'react';
3
3
 
4
- interface CompletedCheckoutResult {
5
- type: 'completed';
4
+ /** A short-lived customer-portal credential issued by the merchant's backend. */
5
+ interface BillingPortalSession {
6
+ token: string;
7
+ /** Nozle Core base URL, without /graphql. Defaults to https://api.nozle.app/core. */
8
+ apiUrl?: string;
9
+ }
10
+ type CreateBillingPortalSession = (options: {
11
+ signal: AbortSignal;
12
+ }) => Promise<BillingPortalSession>;
13
+ declare class BillingPortalError extends Error {
14
+ readonly code: "session" | "unauthorized" | "request" | "changed";
15
+ constructor(code: "session" | "unauthorized" | "request" | "changed");
16
+ }
17
+
18
+ type CancellationOperation = "cancel" | "uncancel";
19
+ interface CancellationSubscription {
20
+ /** Core UUID, distinct from the external subscription identifier. */
21
+ id: string;
22
+ externalId: string;
23
+ name: string;
24
+ status: string;
25
+ endingAt: string | null;
26
+ pendingPlanName?: string | null;
27
+ }
28
+ interface CancellationPreview {
29
+ operation: CancellationOperation;
30
+ effectiveAt: string;
31
+ renewalAt: string | null;
32
+ }
33
+ interface CancellationInput {
34
+ /** External subscription identifier. The merchant authenticates the customer separately. */
35
+ subscriptionId: string;
36
+ operation: CancellationOperation;
37
+ signal: AbortSignal;
38
+ }
39
+ interface CancellationApplyInput extends CancellationInput {
40
+ idempotencyKey: string;
41
+ /** Required for cancellation; the server must reject a changed access-end date. */
42
+ expectedEffectiveAt?: string;
43
+ }
44
+ interface CancellationActions {
45
+ preview: (input: CancellationInput) => Promise<CancellationPreview>;
46
+ apply: (input: CancellationApplyInput) => Promise<unknown>;
47
+ }
48
+ interface CancellationControlProps {
49
+ subscription: CancellationSubscription;
50
+ actions: CancellationActions;
51
+ /** Read persisted state after every attempt, including an ambiguous network failure. */
52
+ refresh: (signal: AbortSignal) => Promise<CancellationSubscription | null>;
53
+ onChanged?: () => void;
54
+ onError?: (error: BillingPortalError) => void;
55
+ locale?: string;
56
+ timezone?: string;
57
+ nonce?: string;
58
+ }
59
+ /** Customer cancellation UI. All mutations go through the merchant's authenticated callbacks. */
60
+ declare function CancellationControl(props: CancellationControlProps): React.JSX.Element;
61
+
62
+ interface CheckoutSubscriptionResult {
63
+ external_entity_id?: string;
64
+ external_subscription_id?: string;
65
+ checkout_id?: string;
66
+ effective_at?: string;
67
+ renewal_at?: string | null;
68
+ amount_due_cents?: number | string;
69
+ currency?: string;
70
+ }
71
+ interface CompletedCheckoutResult extends CheckoutSubscriptionResult {
72
+ type: "completed";
6
73
  status: string;
7
74
  payment_source?: string;
8
75
  subscription_id?: string;
@@ -11,14 +78,16 @@ interface CompletedCheckoutResult {
11
78
  amount_cents?: number;
12
79
  currency?: string;
13
80
  }
14
- interface ScheduledCheckoutResult {
15
- type: 'scheduled';
81
+ interface ScheduledCheckoutResult extends CheckoutSubscriptionResult {
82
+ type: "scheduled";
16
83
  status: string;
17
84
  subscription_id?: string;
18
85
  plan_code?: string;
86
+ effective_at?: string;
87
+ pending_subscription_id?: string;
19
88
  }
20
89
  interface RazorpayCheckoutResult {
21
- type: 'razorpay';
90
+ type: "razorpay";
22
91
  checkout_id: string;
23
92
  key_id: string;
24
93
  order_id: string;
@@ -31,12 +100,12 @@ interface RazorpayCheckoutResult {
31
100
  mandate_max_amount_cents?: number;
32
101
  }
33
102
  interface ProcessingCheckoutResult {
34
- type: 'processing';
103
+ type: "processing";
35
104
  checkout_id: string;
36
105
  status: string;
37
106
  }
38
107
  interface HostedCheckoutResult {
39
- type: 'hosted';
108
+ type: "hosted";
40
109
  payment_url: string;
41
110
  checkout_id?: string;
42
111
  }
@@ -47,9 +116,9 @@ interface RazorpayVerification {
47
116
  }
48
117
  interface CheckoutStatus {
49
118
  checkout_id: string;
50
- provider: 'razorpay';
51
- status: 'processing' | 'awaiting_payment' | 'succeeded' | 'failed' | 'expired' | 'needs_review';
52
- fulfillment_status: 'pending' | 'processing' | 'succeeded';
119
+ provider: "razorpay" | "stripe";
120
+ status: "processing" | "awaiting_payment" | "succeeded" | "failed" | "expired" | "needs_review";
121
+ fulfillment_status: "pending" | "processing" | "succeeded";
53
122
  amount_cents?: number;
54
123
  currency?: string;
55
124
  invoice_id?: string | null;
@@ -59,10 +128,18 @@ interface CheckoutStatus {
59
128
  type VerifyCheckout = (checkoutId: string, verification: RazorpayVerification) => Promise<CheckoutStatus>;
60
129
  type GetCheckoutStatus = (checkoutId: string) => Promise<CheckoutStatus>;
61
130
  type CheckoutResult = {
62
- type: 'stripe';
131
+ type: "stripe";
63
132
  url?: string;
64
133
  clientSecret?: string;
65
134
  client_secret?: string;
135
+ publishable_key?: string;
136
+ stripe_account?: string;
137
+ checkout_id?: string;
138
+ invoice_id?: string;
139
+ amount_cents?: number;
140
+ currency?: string;
141
+ external_entity_id?: string;
142
+ external_subscription_id?: string;
66
143
  } | RazorpayCheckoutResult | ProcessingCheckoutResult | HostedCheckoutResult | CompletedCheckoutResult | ScheduledCheckoutResult | {
67
144
  url: string;
68
145
  };
@@ -71,6 +148,10 @@ interface CreateCheckoutInput {
71
148
  returnUrl: string;
72
149
  idempotencyKey?: string;
73
150
  registerMandate?: boolean;
151
+ /** Select the customer's external subscription for a plan change. */
152
+ subscriptionId?: string;
153
+ /** Opaque, server-issued confirmation for the displayed quote. */
154
+ quoteId?: string;
74
155
  }
75
156
  type CreateCheckout = (input: CreateCheckoutInput) => Promise<CheckoutResult>;
76
157
  interface NozleClient {
@@ -98,6 +179,108 @@ declare function useOptionalBillingContext(): BillingContextValue | null;
98
179
  declare function useBillingContext(): BillingContextValue;
99
180
  declare function useNozleClient(): NozleClient;
100
181
 
182
+ interface PortalPlan {
183
+ code: string;
184
+ name: string;
185
+ amountCents: string | number;
186
+ currency: string;
187
+ interval: string;
188
+ }
189
+ type PlanChangeOperation = "upgrade" | "downgrade";
190
+ interface PlanChangeState {
191
+ subscriptionId: string;
192
+ status: string;
193
+ currentPlan: PortalPlan;
194
+ endingAt: string | null;
195
+ pendingChange: {
196
+ id: string;
197
+ plan: PortalPlan;
198
+ effectiveAt: string;
199
+ } | null;
200
+ eligiblePlans: Array<PortalPlan & {
201
+ operation: PlanChangeOperation;
202
+ }>;
203
+ blockedReason: string | null;
204
+ checkout: CheckoutResult | null;
205
+ checkoutStatus: "none" | "awaiting_payment" | "processing" | "succeeded" | "failed" | "expired" | "needs_review";
206
+ }
207
+ interface PlanChangePreview {
208
+ operation: PlanChangeOperation;
209
+ timing: "immediate" | "end_of_period";
210
+ currency: string;
211
+ creditAmountCents: string | number;
212
+ debitAmountCents: string | number;
213
+ netAmountCents: string | number;
214
+ amountDueNowCents: string | number;
215
+ amountDueAtEffectiveCents: string | number;
216
+ effectiveAt: string;
217
+ renewalAt: string | null;
218
+ quoteToken: string;
219
+ }
220
+ interface PlanChangeInput {
221
+ subscriptionId: string;
222
+ signal: AbortSignal;
223
+ }
224
+ interface PlanChangePreviewInput extends PlanChangeInput {
225
+ targetPlanCode: string;
226
+ }
227
+ interface PlanChangeApplyInput extends PlanChangePreviewInput {
228
+ quoteToken: string;
229
+ idempotencyKey: string;
230
+ returnUrl: string;
231
+ }
232
+ interface PlanChangeWithdrawInput extends PlanChangeInput {
233
+ pendingChangeId: string;
234
+ idempotencyKey: string;
235
+ }
236
+ interface PlanChangeActions {
237
+ load: (input: PlanChangeInput) => Promise<PlanChangeState>;
238
+ status: (input: PlanChangeInput) => Promise<PlanChangeState>;
239
+ preview: (input: PlanChangePreviewInput) => Promise<PlanChangePreview>;
240
+ apply: (input: PlanChangeApplyInput) => Promise<CheckoutResult>;
241
+ withdraw: (input: PlanChangeWithdrawInput) => Promise<unknown>;
242
+ /** Merchant callbacks scoped to this selected subscription. */
243
+ verifyCheckout?: (input: PlanChangeInput & {
244
+ checkoutId: string;
245
+ verification: RazorpayVerification;
246
+ }) => Promise<CheckoutStatus>;
247
+ getCheckoutStatus?: (input: PlanChangeInput & {
248
+ checkoutId: string;
249
+ }) => Promise<CheckoutStatus>;
250
+ }
251
+ interface PlanChangeControlProps {
252
+ subscriptionId: string;
253
+ /** Change when another control updates this subscription; in-flight request keys are preserved. */
254
+ refreshKey?: string;
255
+ actions: PlanChangeActions;
256
+ onChanged?: () => void;
257
+ onError?: (error: BillingPortalError) => void;
258
+ returnUrl?: string;
259
+ locale?: string;
260
+ timezone?: string;
261
+ nonce?: string;
262
+ }
263
+ /** Payment-backed upgrades and scheduled downgrades for one external subscription. */
264
+ declare function PlanChangeControl(props: PlanChangeControlProps): React.JSX.Element;
265
+
266
+ interface BillingPortalProps {
267
+ /** Stable callback to an authenticated merchant endpoint. Never accept customer identity from browser input. */
268
+ createSession: CreateBillingPortalSession;
269
+ /** Optional authenticated merchant callbacks enabling cancel/keep controls. */
270
+ cancellationActions?: CancellationActions;
271
+ /** Optional authenticated merchant callbacks for upgrades and scheduled downgrades. */
272
+ planChangeActions?: PlanChangeActions;
273
+ /** Formats amounts and dates. Interface copy is currently English. */
274
+ locale?: string;
275
+ className?: string;
276
+ style?: CSSProperties;
277
+ /** CSP nonce for the component's scoped stylesheet. No Tailwind setup is required. */
278
+ nonce?: string;
279
+ onError?: (error: BillingPortalError) => void;
280
+ }
281
+ /** Native React customer portal. Uses customer-scoped GraphQL, with no iframe or global auth storage. */
282
+ declare function BillingPortal({ createSession, cancellationActions, planChangeActions, locale, className, style, nonce, onError, }: BillingPortalProps): React.JSX.Element;
283
+
101
284
  interface Plan$1 {
102
285
  code: string;
103
286
  name: string;
@@ -231,7 +414,7 @@ declare global {
231
414
  }
232
415
  }
233
416
 
234
- interface CheckoutButtonProps extends Omit<RazorpayActions, 'verifyCheckout' | 'getCheckoutStatus'> {
417
+ interface CheckoutButtonProps extends Omit<RazorpayActions, "verifyCheckout" | "getCheckoutStatus"> {
235
418
  planCode: string;
236
419
  returnUrl?: string;
237
420
  label?: string;
@@ -291,6 +474,10 @@ interface ProviderCheckoutProps {
291
474
  onProcessing?: (status: CheckoutStatus) => void;
292
475
  onError?: (error: Error) => void;
293
476
  className?: string;
477
+ returnUrl?: string;
478
+ verifyCheckout?: VerifyCheckout;
479
+ getCheckoutStatus?: GetCheckoutStatus;
480
+ onDismiss?: () => void;
294
481
  }
295
482
  type CheckoutProps = StripeCheckoutProps | ProviderCheckoutProps;
296
483
  declare function Checkout(props: CheckoutProps): React__default.JSX.Element;
@@ -300,12 +487,26 @@ interface ProrationPreview {
300
487
  debit: number;
301
488
  net: number;
302
489
  nextBillingDate: string;
490
+ /** Currency of legacy major-unit preview amounts. Defaults to USD for existing integrations. */
491
+ currency?: string;
303
492
  }
304
493
  interface UpgradeModalProps {
305
494
  isOpen: boolean;
306
495
  planCode: string;
307
496
  returnUrl?: string;
497
+ subscriptionId?: string;
498
+ quoteId?: string;
499
+ idempotencyKey?: string;
308
500
  preview?: ProrationPreview;
501
+ locale?: string;
502
+ title?: string;
503
+ confirmLabel?: string;
504
+ confirmDisabled?: boolean;
505
+ busy?: boolean;
506
+ nonce?: string;
507
+ children?: React__default.ReactNode;
508
+ /** Authenticated merchant action. Allows the same confirmation UI without BillingProvider. */
509
+ onSubmit?: () => Promise<void>;
309
510
  onStripeClientSecret?: (clientSecret: string) => void;
310
511
  onCheckoutStarted?: () => void;
311
512
  onCompleted?: () => void;
@@ -314,11 +515,14 @@ interface UpgradeModalProps {
314
515
  onCancel?: () => void;
315
516
  onError?: (error: Error) => void;
316
517
  }
317
- declare function UpgradeModal({ isOpen, planCode, returnUrl, preview, onStripeClientSecret, onCheckoutStarted, onCompleted, onScheduled, onConfirm, onCancel, onError, }: UpgradeModalProps): React__default.ReactElement | null;
518
+ declare function UpgradeModal(props: UpgradeModalProps): React__default.ReactElement | null;
318
519
 
319
520
  interface UpgradeButtonProps {
320
521
  planCode: string;
321
522
  returnUrl?: string;
523
+ subscriptionId?: string;
524
+ quoteId?: string;
525
+ idempotencyKey?: string;
322
526
  preview?: ProrationPreview;
323
527
  label?: string;
324
528
  className?: string;
@@ -329,7 +533,7 @@ interface UpgradeButtonProps {
329
533
  onUpgraded?: () => void;
330
534
  onError?: (error: Error) => void;
331
535
  }
332
- declare function UpgradeButton({ planCode, returnUrl, preview, label, className, style, onStripeClientSecret, onCheckoutStarted, onDowngradeScheduled, onUpgraded, onError, }: UpgradeButtonProps): React__default.ReactElement;
536
+ declare function UpgradeButton({ planCode, returnUrl, subscriptionId, quoteId, idempotencyKey, preview, label, className, style, onStripeClientSecret, onCheckoutStarted, onDowngradeScheduled, onUpgraded, onError, }: UpgradeButtonProps): React__default.ReactElement;
333
537
 
334
538
  /**
335
539
  * Presentational entitlement gate. The merchant backend owns entitlement
@@ -527,4 +731,4 @@ interface PaymentMethodDisplayProps {
527
731
  }
528
732
  declare function PaymentMethodDisplay({ paymentMethod, onUpdatePaymentMethod, updateHref, }: PaymentMethodDisplayProps): React.JSX.Element;
529
733
 
530
- export { BillingContext, type BillingContextValue, BillingProvider, type BillingProviderProps, type Plan$1 as CatalogPlan, Checkout, CheckoutButton, type CheckoutButtonProps, type CheckoutProps, type CheckoutResult, type CheckoutStatus, type ComparisonFeature, type CompletedCheckoutResult, type CreateCheckout, type CreateCheckoutInput, FeatureGate, type FeatureGateProps, type GetCheckoutStatus, type HostedCheckoutResult, LockedOverlay, type LockedOverlayProps, type NozleClient, type PaymentMethod, PaymentMethodDisplay, type PaymentMethodDisplayProps, type Plan, PlanBadge, type PlanBadgeProps, PlanCard, type PlanCardProps, PlanComparison, type PlanComparisonProps, PlanGate, type PlanGateProps, type PricingPlan, PricingTable, type PricingTableProps, type ProcessingCheckoutResult, type ProrationPreview, type RazorpayCheckoutResult, type RazorpayVerification, type ScheduledCheckoutResult, UpgradeButton, type UpgradeButtonProps, UpgradeModal, type UpgradeModalProps, UpgradePrompt, type UpgradePromptProps, UsageAlert, type UsageAlertFeature, type UsageAlertProps, UsageDashboard, type UsageDashboardFeature, type UsageDashboardProps, UsageGate, type UsageGateProps, UsageMeter, type UsageMeterProps, type UseCheckoutResult, type UseCheckoutResult$1 as UseCheckoutSessionResult, type VerifyCheckout, getUsageMeterColor, useBillingContext, useCheckout, useCheckout$1 as useCheckoutSession, useNozleClient, useOptionalBillingContext, usePlans };
734
+ export { BillingContext, type BillingContextValue, BillingPortal, BillingPortalError, type BillingPortalProps, type BillingPortalSession, BillingProvider, type BillingProviderProps, type CancellationActions, type CancellationApplyInput, CancellationControl, type CancellationControlProps, type CancellationInput, type CancellationOperation, type CancellationPreview, type CancellationSubscription, type Plan$1 as CatalogPlan, Checkout, CheckoutButton, type CheckoutButtonProps, type CheckoutProps, type CheckoutResult, type CheckoutStatus, type CheckoutSubscriptionResult, type ComparisonFeature, type CompletedCheckoutResult, type CreateBillingPortalSession, type CreateCheckout, type CreateCheckoutInput, FeatureGate, type FeatureGateProps, type GetCheckoutStatus, type HostedCheckoutResult, LockedOverlay, type LockedOverlayProps, type NozleClient, type PaymentMethod, PaymentMethodDisplay, type PaymentMethodDisplayProps, type Plan, PlanBadge, type PlanBadgeProps, PlanCard, type PlanCardProps, type PlanChangeActions, type PlanChangeApplyInput, PlanChangeControl, type PlanChangeControlProps, type PlanChangeInput, type PlanChangeOperation, type PlanChangePreview, type PlanChangePreviewInput, type PlanChangeState, type PlanChangeWithdrawInput, PlanComparison, type PlanComparisonProps, PlanGate, type PlanGateProps, type PortalPlan, type PricingPlan, PricingTable, type PricingTableProps, type ProcessingCheckoutResult, type ProrationPreview, type RazorpayCheckoutResult, type RazorpayVerification, type ScheduledCheckoutResult, UpgradeButton, type UpgradeButtonProps, UpgradeModal, type UpgradeModalProps, UpgradePrompt, type UpgradePromptProps, UsageAlert, type UsageAlertFeature, type UsageAlertProps, UsageDashboard, type UsageDashboardFeature, type UsageDashboardProps, UsageGate, type UsageGateProps, UsageMeter, type UsageMeterProps, type UseCheckoutResult, type UseCheckoutResult$1 as UseCheckoutSessionResult, type VerifyCheckout, getUsageMeterColor, useBillingContext, useCheckout, useCheckout$1 as useCheckoutSession, useNozleClient, useOptionalBillingContext, usePlans };