@@ -14,6 +14,8 @@ import * as telegram from '../utils/telegram';
1414import { TelegramBotURLs } from '../utils/telegram' ;
1515import PromoCodeService , { PromoCodeError , PromoCodeErrorCode , PromoCodePreviewResult } from '../utils/promoCodeService' ;
1616import { publish } from '../rabbitmq' ;
17+ import type { Utm } from '@hawk.so/types' ;
18+ import { validateUtmParams } from '../utils/utm/utm' ;
1719
1820/**
1921 * The amount we will debit to confirm the subscription.
@@ -30,13 +32,7 @@ interface ComposePaymentArgs {
3032 tariffPlanId : string ;
3133 shouldSaveCard ?: boolean ;
3234 promoCode ?: string ;
33- promoUtm ?: {
34- source ?: string ;
35- medium ?: string ;
36- campaign ?: string ;
37- content ?: string ;
38- term ?: string ;
39- } ;
35+ promoUtm ?: Utm ;
4036 } ;
4137}
4238
@@ -47,13 +43,7 @@ interface PreviewPromoCodeArgs {
4743 input : {
4844 workspaceId : string ;
4945 value : string ;
50- utm ?: {
51- source ?: string ;
52- medium ?: string ;
53- campaign ?: string ;
54- content ?: string ;
55- term ?: string ;
56- } ;
46+ utm ?: Utm ;
5747 } ;
5848}
5949
@@ -132,7 +122,8 @@ export default {
132122 finalAmount ?: number ;
133123 discountAmount ?: number ;
134124 } > {
135- const { workspaceId, tariffPlanId, shouldSaveCard, promoCode, promoUtm } = input ;
125+ const { workspaceId, tariffPlanId, shouldSaveCard, promoCode } = input ;
126+ const promoUtm = validateUtmParams ( input . promoUtm ) ;
136127
137128 if ( ! workspaceId || ! tariffPlanId || ! user ?. id ) {
138129 throw new UserInputError ( 'No workspaceId, tariffPlanId or user id provided' ) ;
@@ -186,7 +177,7 @@ export default {
186177 originalAmount : pricing . originalAmount ,
187178 finalAmount : pricing . finalAmount ,
188179 discountAmount : pricing . discountAmount ,
189- promoUtm,
180+ ... ( promoUtm && Object . keys ( promoUtm ) . length > 0 ? { promoUtm } : { } ) ,
190181 } ;
191182 } catch ( error ) {
192183 throwPromoCodeGraphQLError ( error ) ;
@@ -361,7 +352,7 @@ debug: ${Boolean(workspace.isDebug)}`
361352 } ;
362353 }
363354
364- await promoCodeService . applyGrantPlan ( input . value , user . id , workspace , input . utm ) ;
355+ await promoCodeService . applyGrantPlan ( input . value , user . id , workspace , validateUtmParams ( input . utm ) ) ;
365356
366357 await publish ( 'cron-tasks' , 'cron-tasks/limiter' , JSON . stringify ( {
367358 type : 'unblock-workspace' ,
0 commit comments