@@ -4,7 +4,7 @@ import { Preferences } from '@capacitor/preferences';
44import type { M , Q } from '$lib/gira-api/api-types' ;
55import type { Mutation , Query } from '$lib/gira-api/api-types' ;
66import { encryptedFirebaseToken , token } from '$lib/account' ;
7- import { GIRA_API_URL } from '$lib/constants' ;
7+ import { GIRA_API_URL , GIRA_WS_URL } from '$lib/constants' ;
88import { httpRequestWithRetry } from '$lib/utils' ;
99
1010export const knownErrors : Record < string , { message ?: string , retry : boolean } > = {
@@ -25,31 +25,47 @@ export const knownErrors: Record<string, { message?: string, retry: boolean }> =
2525} ;
2626
2727async function mutate < T extends ( keyof Mutation ) [ ] > ( body :any ) : Promise < M < T > > {
28+ const firebaseToken = get ( encryptedFirebaseToken ) ;
29+ const baseUrl = firebaseToken ? GIRA_API_URL : GIRA_WS_URL . replace ( 'wss' , 'https' ) ;
30+
31+ const headers : Record < string , string > = {
32+ 'User-Agent' : 'Gira/3.4.3 (Android 34)' ,
33+ 'content-type' : 'application/json' ,
34+ 'authorization' : `Bearer ${ get ( token ) ?. accessToken } ` ,
35+ } ;
36+
37+ if ( firebaseToken ) {
38+ headers [ 'x-firebase-token' ] = firebaseToken ;
39+ }
40+
2841 const options = {
29- url : GIRA_API_URL + '/graphql' ,
42+ url : baseUrl + '/graphql' ,
3043 method : 'post' ,
31- headers : {
32- 'User-Agent' : 'Gira/3.4.3 (Android 34)' ,
33- 'content-type' : 'application/json' ,
34- 'authorization' : `Bearer ${ get ( token ) ?. accessToken } ` ,
35- 'x-firebase-token' : `${ get ( encryptedFirebaseToken ) } ` ,
36- } ,
44+ headers,
3745 data : body ,
3846 } ;
3947 const res = await httpRequestWithRetry ( options , true ) ;
4048 return res ?. data . data as Promise < M < T > > ;
4149}
4250
4351async function query < T extends ( keyof Query ) [ ] > ( body :any ) : Promise < Q < T > > {
52+ const firebaseToken = get ( encryptedFirebaseToken ) ;
53+ const baseUrl = firebaseToken ? GIRA_API_URL : GIRA_WS_URL . replace ( 'wss' , 'https' ) ;
54+
55+ const headers : Record < string , string > = {
56+ 'User-Agent' : 'Gira/3.4.3 (Android 34)' ,
57+ 'content-type' : 'application/json' ,
58+ 'authorization' : `Bearer ${ get ( token ) ?. accessToken } ` ,
59+ } ;
60+
61+ if ( firebaseToken ) {
62+ headers [ 'x-firebase-token' ] = firebaseToken ;
63+ }
64+
4465 const options = {
45- url : GIRA_API_URL + '/graphql' ,
66+ url : baseUrl + '/graphql' ,
4667 method : 'post' ,
47- headers : {
48- 'User-Agent' : 'Gira/3.4.3 (Android 34)' ,
49- 'content-type' : 'application/json' ,
50- 'authorization' : `Bearer ${ get ( token ) ?. accessToken } ` ,
51- 'x-firebase-token' : `${ get ( encryptedFirebaseToken ) } ` ,
52- } ,
68+ headers,
5369 data : body ,
5470 } ;
5571 const res = await httpRequestWithRetry ( options , true ) ;
0 commit comments