@@ -34,6 +34,22 @@ export const httpV2 = axios.create({
3434 baseURL : import . meta. env . VITE_API_V2 ,
3535} ) ;
3636
37+ export const httpV2App = axios . create ( {
38+ baseURL : import . meta. env . VITE_API_V2 ,
39+ } ) ;
40+
41+ function getAppJwt ( ) : string {
42+ let appJwt = httpTokens . appJwt ;
43+ if ( ! appJwt && typeof window !== 'undefined' && window . useAppStore ) {
44+ const appToken = window . useAppStore . getState ( ) ?. currentApp ?. appToken ;
45+ if ( appToken ) {
46+ appJwt = appToken ;
47+ httpTokens . appJwt = appToken ;
48+ }
49+ }
50+ return appJwt || '' ;
51+ }
52+
3753const AUTH_WHITELIST : Array < string | RegExp > = [
3854 '/users/login-with-email' ,
3955 '/users/login' ,
@@ -101,6 +117,14 @@ function attachAuthInterceptors(client: AxiosInstance) {
101117attachAuthInterceptors ( http ) ;
102118attachAuthInterceptors ( httpV2 ) ;
103119
120+ httpV2App . interceptors . request . use ( ( config ) => {
121+ config . headers = config . headers || { } ;
122+ if ( ! ( config . headers as any ) . Authorization ) {
123+ ( config . headers as any ) . Authorization = getAppJwt ( ) ;
124+ }
125+ return config ;
126+ } , null ) ;
127+
104128export const refreshToken = async ( ) => {
105129 try {
106130 const response = await http . post ( '/users/login/refresh' , null , {
@@ -528,6 +552,33 @@ export function deleteDefaultRooms(appId: string, chatJid: string) {
528552 } ) ;
529553}
530554
555+ export function httpBroadcastChatsV2 (
556+ payload : {
557+ text : string ;
558+ allRooms ?: boolean ;
559+ chatNames ?: string [ ] ;
560+ chatIds ?: string [ ] ;
561+ metadata ?: any ;
562+ dryRun ?: boolean ;
563+ } ,
564+ opts ?: { appToken ?: string }
565+ ) {
566+ const cfg = opts ?. appToken
567+ ? { headers : { Authorization : opts . appToken } }
568+ : undefined ;
569+ return httpV2App . post ( '/chats/broadcast' , payload , cfg ) ;
570+ }
571+
572+ export function httpGetBroadcastChatsJobV2 (
573+ jobId : string ,
574+ opts ?: { appToken ?: string }
575+ ) {
576+ const cfg = opts ?. appToken
577+ ? { headers : { Authorization : opts . appToken } }
578+ : undefined ;
579+ return httpV2App . get ( `/chats/broadcast/${ jobId } ` , cfg ) ;
580+ }
581+
531582export const sendHSFormData = async (
532583 appId : string ,
533584 formId : string ,
0 commit comments