@donotdev/billing 0.0.5 → 0.0.7
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/components/SecurityNotice.d.ts.map +1 -1
- package/dist/components/SecurityNotice.js +1 -1
- package/dist/components/StripeCheckoutButton.d.ts.map +1 -1
- package/dist/components/StripeCheckoutButton.js +1 -1
- package/dist/components/SubscriptionManager.d.ts +6 -2
- package/dist/components/SubscriptionManager.d.ts.map +1 -1
- package/dist/components/SubscriptionManager.js +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/useBillingAuth.d.ts +24 -0
- package/dist/useBillingAuth.d.ts.map +1 -0
- package/dist/useBillingAuth.js +1 -0
- package/dist/useStripeBilling.d.ts.map +1 -1
- package/dist/useStripeBilling.js +1 -1
- package/package.json +9 -9
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { BillingAuthState } from './useStripeBilling';
|
|
2
|
+
/**
|
|
3
|
+
* Returns a BillingAuthState object by reading auth state internally.
|
|
4
|
+
*
|
|
5
|
+
* - If @donotdev/auth installed -> uses real useAuth hook
|
|
6
|
+
* - If not installed -> returns degraded state (null user, 'degraded' status)
|
|
7
|
+
*
|
|
8
|
+
* This removes the need for consumers to pass authState to every billing component.
|
|
9
|
+
*
|
|
10
|
+
* @returns BillingAuthState with user and status
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* // Inside a billing component:
|
|
15
|
+
* const authState = useBillingAuth();
|
|
16
|
+
* const checkout = useStripeBilling('checkout', authState);
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @version 0.0.1
|
|
20
|
+
* @since 0.0.7
|
|
21
|
+
* @author AMBROISE PARK Consulting
|
|
22
|
+
*/
|
|
23
|
+
export declare function useBillingAuth(): BillingAuthState;
|
|
24
|
+
//# sourceMappingURL=useBillingAuth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useBillingAuth.d.ts","sourceRoot":"","sources":["../src/useBillingAuth.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAU3D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,cAAc,IAAI,gBAAgB,CAWjD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import*as u from"@donotdev/auth";import{FEATURE_STATUS as s}from"@donotdev/core";const t=u?.useAuth;function e(){return t?{user:t("user"),status:t("status")}:{user:null,status:s.DEGRADED}}export{e as useBillingAuth};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStripeBilling.d.ts","sourceRoot":"","sources":["../src/useStripeBilling.ts"],"names":[],"mappings":"AA8CA,OAAO,KAAK,EACV,QAAQ,EACR,UAAU,EAIV,aAAa,
|
|
1
|
+
{"version":3,"file":"useStripeBilling.d.ts","sourceRoot":"","sources":["../src/useStripeBilling.ts"],"names":[],"mappings":"AA8CA,OAAO,KAAK,EACV,QAAQ,EACR,UAAU,EAIV,aAAa,EACd,MAAM,gBAAgB,CAAC;AA4CxB;;;;;;;GAOG;AACH,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,QAAQ,GAAG,IAAI,CAAC;IACtB,MAAM,EAAE,aAAa,CAAC;CACvB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkEG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,UAAU,EACzD,GAAG,EAAE,CAAC,EACN,SAAS,CAAC,EAAE,gBAAgB,GAC3B,UAAU,CAAC,CAAC,CAAC,CA8Tf"}
|
package/dist/useStripeBilling.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{useState as
|
|
1
|
+
"use client";import{useState as S,useCallback as i,useRef as _}from"react";import{DEGRADED_BILLING_API as P,FEATURE_STATUS as m,isClient as R,isDev as k,handleError as l,getPlatformEnvVar as q,hasProvider as W,getProvider as Y,FRAMEWORK_FEATURES as H,redirectToExternalUrlWithErrorHandling as V,useFeatureConsent as Z,useOverlay as U}from"@donotdev/core";async function h(o){if(W("callable")){const d=Y("callable");return{callable:async E=>({data:await d.call(o,E)}),functions:null,region:null}}const{getFirebaseFunctions:f,httpsCallable:t}=await import("@donotdev/firebase"),b=q("FIREBASE_FUNCTIONS_REGION")||"europe-west1",u=await f(b);return{callable:t(u,o),functions:u,region:b}}function z(o,f){const t=f?.user??null,u=(f?.status??m.DEGRADED)===m.READY,d=Z(H.BILLING),[E,n]=S(!1),[C,s]=S(null),w=U("showRedirectOverlay"),p=U("hideRedirectOverlay"),g=_(!1),F=i(async r=>{if(!R()||!d)throw new Error("Billing not available in SSR or consent required");if(!t){const e=l(new Error("User must be authenticated"),{userMessage:"Please sign in to continue with checkout.",severity:"warning"});throw s(e.message),e}n(!0),s(null),w("stripe-checkout");try{const{callable:e}=await h("createCheckoutSession"),a=t.providerData?.find(G=>G.providerId==="github.com"),c=a?.displayName,I=a?.uid,M={priceId:r.priceId,userEmail:t.email||"",customerEmail:t.email||"",metadata:{...c&&{githubDisplayName:c},...I&&{githubUid:I},...r.metadata},successUrl:r.successUrl||`${typeof window<"u"?window.location.origin:""}/billing/success`,cancelUrl:r.cancelUrl||(typeof window<"u"?window.location.href:""),allowPromotionCodes:r.allowPromotionCodes??!0,mode:r.mode};k();const T=await e(M),{sessionId:B,sessionUrl:v}=T.data;if(!v)throw new Error("No checkout URL received from server");return g.current=!1,{sessionId:B,sessionUrl:v,success:!0,error:void 0}}catch(e){if(p(),g.current){const a=e instanceof Error?e:new Error("Checkout failed");throw s(a.message),a}else{const a=l(e,{userMessage:"Unable to start checkout. Please try again or contact support if the problem persists.",context:{priceId:r.priceId,mode:r.mode},severity:"error"});throw s(a.message),g.current=!0,a}}finally{n(!1)}},[t,d,w,p]),A=i(async()=>{if(!t)throw new Error("User must be authenticated");n(!0),s(null);try{const{callable:r}=await h("cancelSubscription");return(await r({})).data}catch(r){const e=l(r,{userMessage:"Failed to cancel subscription. Please try again or contact support.",context:{operation:"cancelSubscription",userId:t.id},severity:"error"});throw s(e.message),e}finally{n(!1)}},[t]),D=i(async(r,e)=>{if(!t)throw new Error("User must be authenticated");n(!0),s(null);try{const{callable:a}=await h("changePlan");return(await a({newPriceId:r,billingConfigKey:e})).data}catch(a){const c=l(a,{userMessage:"Failed to change plan. Please try again or contact support.",context:{operation:"changePlan",userId:t.id,newPriceId:r,billingConfigKey:e},severity:"error"});throw s(c.message),c}finally{n(!1)}},[t]),N=i(async()=>{if(!t)throw new Error("User must be authenticated");n(!0),s(null);try{const{callable:r}=await h("refreshSubscriptionStatus");await r({})}catch(r){const e=l(r,{userMessage:"Failed to refresh subscription status. Please try again.",context:{operation:"refreshStatus",userId:t.id},severity:"error"});throw s(e.message),e}finally{n(!1)}},[t]),O=i(async r=>{if(!t)throw new Error("User must be authenticated");n(!0),s(null),w("stripe-portal");try{const{callable:e}=await h("createCustomerPortal"),a=await e({returnUrl:r||(typeof window<"u"?window.location.href:"")});await V(a.data.url,{},"Failed to redirect to customer portal")}catch(e){p();const a=l(e,{userMessage:"Failed to open customer portal. Please try again or contact support.",context:{operation:"openCustomerPortal",userId:t.id},severity:"error"});throw s(a.message),a}finally{n(!1)}},[t,w,p]),x=i(()=>{s(null),g.current=!1},[]),y={checkout:F,cancelSubscription:A,changePlan:D,refreshStatus:N,openCustomerPortal:O,clearError:x};if(!R()||!d)return P[o];const L=u?m.READY:m.INITIALIZING;return o==="status"?L:o==="isAvailable"?!!u:o==="error"?C:o==="loading"?E:o in y?y[o]:P[o]}export{z as useStripeBilling};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@donotdev/billing",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
@@ -33,14 +33,14 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@donotdev/auth": "^0.0.
|
|
37
|
-
"@donotdev/components": "^0.0.
|
|
38
|
-
"@donotdev/core": "^0.0.
|
|
39
|
-
"@donotdev/firebase": "^0.0.
|
|
40
|
-
"lucide-react": "^0.
|
|
41
|
-
"react": "^19.2.
|
|
42
|
-
"react-dom": "^19.2.
|
|
43
|
-
"stripe": "^20.1
|
|
36
|
+
"@donotdev/auth": "^0.0.7",
|
|
37
|
+
"@donotdev/components": "^0.0.17",
|
|
38
|
+
"@donotdev/core": "^0.0.24",
|
|
39
|
+
"@donotdev/firebase": "^0.0.10",
|
|
40
|
+
"lucide-react": "^0.574.0",
|
|
41
|
+
"react": "^19.2.4",
|
|
42
|
+
"react-dom": "^19.2.4",
|
|
43
|
+
"stripe": "^20.3.1"
|
|
44
44
|
},
|
|
45
45
|
"peerDependenciesMeta": {},
|
|
46
46
|
"keywords": [
|