Skip to content

Commit 5e397d0

Browse files
committed
update custom headers assignment logic and values; add gen flag functionality back for future deprecation
1 parent 40a8c0b commit 5e397d0

File tree

5 files changed

+26
-11
lines changed

5 files changed

+26
-11
lines changed

packages/data-connect/src/api/DataConnect.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ import {
3333
} from '../core/FirebaseAuthProvider';
3434
import { QueryManager } from '../core/QueryManager';
3535
import { logDebug, logError } from '../logger';
36-
import { CallerSdkType, CallerSdkTypeEnum, DataConnectTransport, TransportClass } from '../network';
36+
import {
37+
CallerSdkType,
38+
CallerSdkTypeEnum,
39+
DataConnectTransport,
40+
TransportClass
41+
} from '../network';
3742
import { RESTTransport } from '../network/transport/rest';
3843

3944
import { MutationManager } from './Mutation';
@@ -91,6 +96,7 @@ export class DataConnect {
9196
private _transportClass: TransportClass | undefined;
9297
private _transportOptions?: TransportOptions;
9398
private _authTokenProvider?: AuthTokenProvider;
99+
_isUsingGeneratedSdk: boolean = false;
94100
_callerSdkType: CallerSdkType = CallerSdkTypeEnum.Base;
95101
private _appCheckTokenProvider?: AppCheckTokenProvider;
96102
// @internal
@@ -111,6 +117,12 @@ export class DataConnect {
111117
}
112118
}
113119
// @internal
120+
_useGeneratedSdk(): void {
121+
if (!this._isUsingGeneratedSdk) {
122+
this._isUsingGeneratedSdk = true;
123+
}
124+
}
125+
// @internal
114126
_setCallerSdkType(callerSdkType: CallerSdkType): void {
115127
this._callerSdkType = callerSdkType;
116128
}
@@ -162,6 +174,7 @@ export class DataConnect {
162174
this._authTokenProvider,
163175
this._appCheckTokenProvider,
164176
undefined,
177+
this._isUsingGeneratedSdk,
165178
this._callerSdkType
166179
);
167180
if (this._transportOptions) {

packages/data-connect/src/network/fetch.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,13 @@ export function initializeFetch(fetchImpl: typeof fetch): void {
2727
}
2828
function getGoogApiClientValue(_callerSdkType: CallerSdkType): string {
2929
let str = 'gl-js/ fire/' + SDK_VERSION;
30-
if (_callerSdkType !== CallerSdkTypeEnum.Base) {
30+
if (_callerSdkType === CallerSdkTypeEnum.Generated) {
3131
str += ' js/gen';
32+
} else if (_callerSdkType !== CallerSdkTypeEnum.Base) {
33+
str += ' js/' + _callerSdkType.toLowerCase();
3234
}
3335
return str;
3436
}
35-
function getWebFrameworkValue(
36-
_callerSdkType: CallerSdkType
37-
): string {
38-
return _callerSdkType + "/";
39-
}
4037
export interface DataConnectFetchBody<T> {
4138
name: string;
4239
operationName: string;
@@ -49,16 +46,15 @@ export function dcFetch<T, U>(
4946
appId: string | null,
5047
accessToken: string | null,
5148
appCheckToken: string | null,
49+
_isUsingGen: boolean,
5250
_callerSdkType: CallerSdkType
5351
): Promise<{ data: T; errors: Error[] }> {
5452
if (!connectFetch) {
5553
throw new DataConnectError(Code.OTHER, 'No Fetch Implementation detected!');
5654
}
5755
const headers: HeadersInit = {
5856
'Content-Type': 'application/json',
59-
'X-Goog-Api-Client': getGoogApiClientValue(_callerSdkType),
60-
'X-Firebase-DataConnect-Web-Frameworks':
61-
getWebFrameworkValue(_callerSdkType)
57+
'X-Goog-Api-Client': getGoogApiClientValue(_callerSdkType)
6258
};
6359
if (accessToken) {
6460
headers['X-Firebase-Auth-Token'] = accessToken;

packages/data-connect/src/network/transport/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,6 @@ export type TransportClass = new (
6767
authProvider?: AuthTokenProvider,
6868
appCheckProvider?: AppCheckTokenProvider,
6969
transportOptions?: TransportOptions,
70-
_callerSdkType?: CallerSdkType
70+
_isUsingGen?: boolean,
71+
_callerSdkType?: CallerSdkType
7172
) => DataConnectTransport;

packages/data-connect/src/network/transport/rest.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export class RESTTransport implements DataConnectTransport {
4343
private authProvider?: AuthTokenProvider | undefined,
4444
private appCheckProvider?: AppCheckTokenProvider | undefined,
4545
transportOptions?: TransportOptions | undefined,
46+
private _isUsingGen = false,
4647
private _callerSdkType: CallerSdkType = CallerSdkTypeEnum.Base,
4748
) {
4849
if (transportOptions) {
@@ -180,6 +181,7 @@ export class RESTTransport implements DataConnectTransport {
180181
this.appId,
181182
this._accessToken,
182183
this._appCheckToken,
184+
this._isUsingGen,
183185
this._callerSdkType
184186
)
185187
);
@@ -205,6 +207,7 @@ export class RESTTransport implements DataConnectTransport {
205207
this.appId,
206208
this._accessToken,
207209
this._appCheckToken,
210+
this._isUsingGen,
208211
this._callerSdkType
209212
);
210213
});

packages/data-connect/test/unit/fetch.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ describe('fetch', () => {
5252
null,
5353
null,
5454
null,
55+
false,
5556
CallerSdkTypeEnum.Base
5657
)
5758
).to.eventually.be.rejectedWith(message);
@@ -75,6 +76,7 @@ describe('fetch', () => {
7576
null,
7677
null,
7778
null,
79+
false,
7880
CallerSdkTypeEnum.Base
7981
)
8082
).to.eventually.be.rejectedWith(JSON.stringify(json));

0 commit comments

Comments
 (0)