1+ import { z } from 'zod' ;
2+
13export enum TierIds {
24 HOBBY = 'hobby-tier' ,
35 PRO = 'pro-tier' ,
@@ -7,18 +9,42 @@ export enum TierIds {
79export const DOCS_URL = 'https://docs.opensaas.sh' ;
810export const BLOG_URL = 'https://docs.opensaas.sh/blog' ;
911
10- //get this link at https://dashboard.stripe.com/test/settings/billing/portal
11- const isDev = process . env . NODE_ENV !== 'production' ;
12- const customerPortalTestUrl = '<your-stripe-customer-portal-link>' ;
13- const customerPortalProdUrl = undefined ; // TODO: add before deploying to production
12+ const isDevEnv = process . env . NODE_ENV !== 'production' ;
13+ const customerPortalTestUrl = 'https://cool.com' ; // TODO: find your test url at https://dashboard.stripe.com/test/settings/billing/portal
14+ const customerPortalProdUrl = 'https://cool.com' ; // TODO: add before deploying to production
15+
16+ export const STRIPE_CUSTOMER_PORTAL_LINK = isDevEnv
17+ ? customerPortalTestUrl
18+ : customerPortalProdUrl ;
19+
20+ checkStripePortalLinksExist ( { customerPortalTestUrl, customerPortalProdUrl } ) ;
1421
15- export const STRIPE_CUSTOMER_PORTAL_LINK = isDev ? customerPortalTestUrl : customerPortalProdUrl ;
22+ type StripePortalUrls = {
23+ customerPortalTestUrl : string | undefined ;
24+ customerPortalProdUrl : string | undefined ;
25+ } ;
1626
17- checkStripePortalLinkExists ( STRIPE_CUSTOMER_PORTAL_LINK ) ;
27+ function checkStripePortalLinksExist ( links : StripePortalUrls ) {
28+ const schema = z . string ( ) . url ( ) ;
29+ const testResult = schema . safeParse ( links . customerPortalTestUrl ) ;
30+ const prodResult = schema . safeParse ( links . customerPortalProdUrl ) ;
31+ let consoleMsg = {
32+ color : '\x1b[33m%s\x1b[0m' ,
33+ msg : '' ,
34+ } ;
1835
19- function checkStripePortalLinkExists ( link : string | undefined ) {
20- if ( ! link ) {
21- if ( isDev ) console . warn ( '\x1b[31m%s\x1b[0m' , '⚠️ STRIPE_CUSTOMER_PORTAL_LINK is not defined.' ) ;
22- if ( ! isDev ) throw new Error ( '🚫 STRIPE_CUSTOMER_PORTAL_LINK is not defined' ) ;
23- }
36+ if ( testResult . success && prodResult . success ) {
37+ consoleMsg . color = '\x1b[32m%s\x1b[0m' ;
38+ consoleMsg . msg =
39+ '✅ Both STRIPE_CUSTOMER_PORTAL_LINK links defined' ;
40+ } else if ( ! testResult . success && ! prodResult . success ) {
41+ consoleMsg . msg =
42+ '⛔️ STRIPE_CUSTOMER_PORTAL_LINK is not defined' ;
43+ } else if ( ! testResult . success ) {
44+ consoleMsg . msg = '⛔️ STRIPE_CUSTOMER_PORTAL_LINK is not defined for test env' ;
45+ } else {
46+ consoleMsg . msg =
47+ '⛔️ STRIPE_CUSTOMER_PORTAL_LINK is not defined for prod env' ;
48+ }
49+ console . log ( consoleMsg . color , consoleMsg . msg ) ;
2450}
0 commit comments