@@ -17,6 +17,10 @@ import {
1717 type UsageResult ,
1818 type UsageSeriesParams ,
1919 type CurrentPlan ,
20+ type ApplyCouponDealResponse ,
21+ type CouponDiagnosticsResponse ,
22+ type ListCouponDealsResponse ,
23+ type ResolveCouponCustomerResponse ,
2024} from "@trigger.dev/platform" ;
2125import { createCache , DefaultStatefulContext , Namespace } from "@unkey/cache" ;
2226import { createLRUMemoryStore } from "@internal/cache" ;
@@ -778,6 +782,103 @@ export async function triggerInitialDeployment(
778782 }
779783}
780784
785+ export async function listCouponDeals ( ) : Promise < ListCouponDealsResponse > {
786+ if ( ! client ) throw new Error ( "Platform client not configured" ) ;
787+
788+ const [ error , result ] = await tryCatch ( client . listCouponDeals ( ) ) ;
789+
790+ if ( error ) {
791+ logger . error ( "Error listing coupon deals" , { error } ) ;
792+ throw error ;
793+ }
794+
795+ if ( ! result . success ) {
796+ logger . error ( "Error listing coupon deals - no success" , { error : result . error } ) ;
797+ throw new Error ( result . error ?? "Failed to list coupon deals" ) ;
798+ }
799+
800+ return result ;
801+ }
802+
803+ export async function refreshCouponDeals ( ) : Promise < ListCouponDealsResponse > {
804+ if ( ! client ) throw new Error ( "Platform client not configured" ) ;
805+
806+ const [ error , result ] = await tryCatch ( client . refreshCouponDeals ( ) ) ;
807+
808+ if ( error ) {
809+ logger . error ( "Error refreshing coupon deals" , { error } ) ;
810+ throw error ;
811+ }
812+
813+ if ( ! result . success ) {
814+ logger . error ( "Error refreshing coupon deals - no success" , { error : result . error } ) ;
815+ throw new Error ( result . error ?? "Failed to refresh coupon deals" ) ;
816+ }
817+
818+ return result ;
819+ }
820+
821+ export async function resolveCouponCustomer (
822+ stripeEmail : string
823+ ) : Promise < ResolveCouponCustomerResponse > {
824+ if ( ! client ) throw new Error ( "Platform client not configured" ) ;
825+
826+ const [ error , result ] = await tryCatch ( client . resolveCouponCustomer ( stripeEmail ) ) ;
827+
828+ if ( error ) {
829+ logger . error ( "Error resolving coupon customer" , { error } ) ;
830+ throw error ;
831+ }
832+
833+ if ( ! result . success ) {
834+ logger . error ( "Error resolving coupon customer - no success" , { error : result . error } ) ;
835+ throw new Error ( result . error ?? "Failed to resolve coupon customer" ) ;
836+ }
837+
838+ return result ;
839+ }
840+
841+ // Returns the full discriminated result rather than throwing on !success so the
842+ // admin route can branch on `code` ("already_applied", "no_subscription",
843+ // "unknown_deal", etc.) and surface precise UI messages.
844+ export async function applyCouponDeal ( input : {
845+ orgId : string ;
846+ dealKey : string ;
847+ } ) : Promise < ApplyCouponDealResponse > {
848+ if ( ! client ) throw new Error ( "Platform client not configured" ) ;
849+
850+ const [ error , result ] = await tryCatch ( client . applyCouponDeal ( input ) ) ;
851+
852+ if ( error ) {
853+ logger . error ( "Error applying coupon deal" , { input, error } ) ;
854+ throw error ;
855+ }
856+
857+ if ( ! result . success ) {
858+ logger . warn ( "Coupon deal apply unsuccessful" , { input, error : result . error } ) ;
859+ }
860+
861+ return result ;
862+ }
863+
864+ export async function getCouponDiagnostics ( ) : Promise < CouponDiagnosticsResponse > {
865+ if ( ! client ) throw new Error ( "Platform client not configured" ) ;
866+
867+ const [ error , result ] = await tryCatch ( client . getCouponDiagnostics ( ) ) ;
868+
869+ if ( error ) {
870+ logger . error ( "Error getting coupon diagnostics" , { error } ) ;
871+ throw error ;
872+ }
873+
874+ if ( ! result . success ) {
875+ logger . error ( "Error getting coupon diagnostics - no success" , { error : result . error } ) ;
876+ throw new Error ( result . error ?? "Failed to get coupon diagnostics" ) ;
877+ }
878+
879+ return result ;
880+ }
881+
781882function isCloud ( ) : boolean {
782883 const acceptableHosts = [
783884 "https://cloud.trigger.dev" ,
0 commit comments