Skip to content

Commit 810a5e3

Browse files
committed
Pass in SDK version & correctly send GET request params
1 parent 8756e15 commit 810a5e3

File tree

16 files changed

+71
-32
lines changed

16 files changed

+71
-32
lines changed

packages-exp/auth-exp/src/api/account_management/account.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ describe('deleteAccount', () => {
4242
expect(mock.calls[0].request).to.eql(request);
4343
expect(mock.calls[0].method).to.eq('POST');
4444
expect(mock.calls[0].headers).to.eql({
45-
'Content-Type': 'application/json'
45+
'Content-Type': 'application/json',
46+
'X-Client-Version': 'testSDK/0.0.0'
4647
});
4748
});
4849

@@ -94,7 +95,8 @@ describe('deleteLinkedAccounts', () => {
9495
expect(mock.calls[0].request).to.eql(request);
9596
expect(mock.calls[0].method).to.eq('POST');
9697
expect(mock.calls[0].headers).to.eql({
97-
'Content-Type': 'application/json'
98+
'Content-Type': 'application/json',
99+
'X-Client-Version': 'testSDK/0.0.0'
98100
});
99101
});
100102

@@ -145,7 +147,8 @@ describe('getAccountInfo', () => {
145147
expect(mock.calls[0].request).to.eql(request);
146148
expect(mock.calls[0].method).to.eq('POST');
147149
expect(mock.calls[0].headers).to.eql({
148-
'Content-Type': 'application/json'
150+
'Content-Type': 'application/json',
151+
'X-Client-Version': 'testSDK/0.0.0'
149152
});
150153
});
151154

packages-exp/auth-exp/src/api/account_management/email_and_password.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ describe('resetPassword', () => {
4545
expect(mock.calls[0].request).to.eql(request);
4646
expect(mock.calls[0].method).to.eq('POST');
4747
expect(mock.calls[0].headers).to.eql({
48-
'Content-Type': 'application/json'
48+
'Content-Type': 'application/json',
49+
'X-Client-Version': 'testSDK/0.0.0'
4950
});
5051
});
5152

@@ -96,7 +97,8 @@ describe('updateEmailPassword', () => {
9697
expect(mock.calls[0].request).to.eql(request);
9798
expect(mock.calls[0].method).to.eq('POST');
9899
expect(mock.calls[0].headers).to.eql({
99-
'Content-Type': 'application/json'
100+
'Content-Type': 'application/json',
101+
'X-Client-Version': 'testSDK/0.0.0'
100102
});
101103
});
102104

packages-exp/auth-exp/src/api/account_management/mfa.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ describe('startEnrollPhoneMfa', () => {
5050
expect(mock.calls[0].request).to.eql(request);
5151
expect(mock.calls[0].method).to.eq('POST');
5252
expect(mock.calls[0].headers).to.eql({
53-
'Content-Type': 'application/json'
53+
'Content-Type': 'application/json',
54+
'X-Client-Version': 'testSDK/0.0.0'
5455
});
5556
});
5657

@@ -104,7 +105,8 @@ describe('enrollPhoneMfa', () => {
104105
expect(mock.calls[0].request).to.eql(request);
105106
expect(mock.calls[0].method).to.eq('POST');
106107
expect(mock.calls[0].headers).to.eql({
107-
'Content-Type': 'application/json'
108+
'Content-Type': 'application/json',
109+
'X-Client-Version': 'testSDK/0.0.0'
108110
});
109111
});
110112

@@ -154,7 +156,8 @@ describe('withdrawMfa', () => {
154156
expect(mock.calls[0].request).to.eql(request);
155157
expect(mock.calls[0].method).to.eq('POST');
156158
expect(mock.calls[0].headers).to.eql({
157-
'Content-Type': 'application/json'
159+
'Content-Type': 'application/json',
160+
'X-Client-Version': 'testSDK/0.0.0'
158161
});
159162
});
160163

packages-exp/auth-exp/src/api/account_management/profile.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ describe('updateProfile', () => {
4747
expect(mock.calls[0].request).to.eql(request);
4848
expect(mock.calls[0].method).to.eq('POST');
4949
expect(mock.calls[0].headers).to.eql({
50-
'Content-Type': 'application/json'
50+
'Content-Type': 'application/json',
51+
'X-Client-Version': 'testSDK/0.0.0'
5152
});
5253
});
5354

packages-exp/auth-exp/src/api/authentication/create_auth_uri.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ describe('createAuthUri', () => {
4545
expect(mock.calls[0].request).to.eql(request);
4646
expect(mock.calls[0].method).to.eq('POST');
4747
expect(mock.calls[0].headers).to.eql({
48-
'Content-Type': 'application/json'
48+
'Content-Type': 'application/json',
49+
'X-Client-Version': 'testSDK/0.0.0'
4950
});
5051
});
5152

packages-exp/auth-exp/src/api/authentication/custom_token.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ describe('signInWithCustomToken', () => {
5151
expect(mock.calls[0].request).to.eql(request);
5252
expect(mock.calls[0].method).to.eq('POST');
5353
expect(mock.calls[0].headers).to.eql({
54-
'Content-Type': 'application/json'
54+
'Content-Type': 'application/json',
55+
'X-Client-Version': 'testSDK/0.0.0'
5556
});
5657
});
5758

packages-exp/auth-exp/src/api/authentication/email_and_password.test.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ describe('signInWithPassword', () => {
5757
expect(mock.calls[0].request).to.eql(request);
5858
expect(mock.calls[0].method).to.eq('POST');
5959
expect(mock.calls[0].headers).to.eql({
60-
'Content-Type': 'application/json'
60+
'Content-Type': 'application/json',
61+
'X-Client-Version': 'testSDK/0.0.0'
6162
});
6263
});
6364

@@ -106,7 +107,8 @@ describe('sendOobCode', () => {
106107
expect(mock.calls[0].request).to.eql(request);
107108
expect(mock.calls[0].method).to.eq('POST');
108109
expect(mock.calls[0].headers).to.eql({
109-
'Content-Type': 'application/json'
110+
'Content-Type': 'application/json',
111+
'X-Client-Version': 'testSDK/0.0.0'
110112
});
111113
});
112114

@@ -154,7 +156,8 @@ describe('sendOobCode', () => {
154156
expect(mock.calls[0].request).to.eql(request);
155157
expect(mock.calls[0].method).to.eq('POST');
156158
expect(mock.calls[0].headers).to.eql({
157-
'Content-Type': 'application/json'
159+
'Content-Type': 'application/json',
160+
'X-Client-Version': 'testSDK/0.0.0'
158161
});
159162
});
160163

@@ -204,7 +207,8 @@ describe('sendOobCode', () => {
204207
expect(mock.calls[0].request).to.eql(request);
205208
expect(mock.calls[0].method).to.eq('POST');
206209
expect(mock.calls[0].headers).to.eql({
207-
'Content-Type': 'application/json'
210+
'Content-Type': 'application/json',
211+
'X-Client-Version': 'testSDK/0.0.0'
208212
});
209213
});
210214

packages-exp/auth-exp/src/api/authentication/email_link.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ describe('signInWithEmailLink', () => {
4747
expect(mock.calls[0].request).to.eql(request);
4848
expect(mock.calls[0].method).to.eq('POST');
4949
expect(mock.calls[0].headers).to.eql({
50-
'Content-Type': 'application/json'
50+
'Content-Type': 'application/json',
51+
'X-Client-Version': 'testSDK/0.0.0'
5152
});
5253
});
5354

packages-exp/auth-exp/src/api/authentication/idp.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ describe('signInWithIdp', () => {
4848
expect(mock.calls[0].request).to.eql(request);
4949
expect(mock.calls[0].method).to.eq('POST');
5050
expect(mock.calls[0].headers).to.eql({
51-
'Content-Type': 'application/json'
51+
'Content-Type': 'application/json',
52+
'X-Client-Version': 'testSDK/0.0.0'
5253
});
5354
});
5455

packages-exp/auth-exp/src/api/authentication/mfa.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ describe('startSignInPhoneMfa', () => {
5050
expect(mock.calls[0].request).to.eql(request);
5151
expect(mock.calls[0].method).to.eq('POST');
5252
expect(mock.calls[0].headers).to.eql({
53-
'Content-Type': 'application/json'
53+
'Content-Type': 'application/json',
54+
'X-Client-Version': 'testSDK/0.0.0'
5455
});
5556
});
5657

@@ -105,7 +106,8 @@ describe('finalizeSignInPhoneMfa', () => {
105106
expect(mock.calls[0].request).to.eql(request);
106107
expect(mock.calls[0].method).to.eq('POST');
107108
expect(mock.calls[0].headers).to.eql({
108-
'Content-Type': 'application/json'
109+
'Content-Type': 'application/json',
110+
'X-Client-Version': 'testSDK/0.0.0'
109111
});
110112
});
111113

packages-exp/auth-exp/src/api/authentication/recaptcha.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ describe('getRecaptchaParams', () => {
4040
expect(mock.calls[0].request).to.be.undefined;
4141
expect(mock.calls[0].method).to.eq('GET');
4242
expect(mock.calls[0].headers).to.eql({
43-
'Content-Type': 'application/json'
43+
'Content-Type': 'application/json',
44+
'X-Client-Version': 'testSDK/0.0.0'
4445
});
4546
});
4647

packages-exp/auth-exp/src/api/authentication/sign_up.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ describe('signUp', () => {
4848
expect(mock.calls[0].request).to.eql(request);
4949
expect(mock.calls[0].method).to.eq('POST');
5050
expect(mock.calls[0].headers).to.eql({
51-
'Content-Type': 'application/json'
51+
'Content-Type': 'application/json',
52+
'X-Client-Version': 'testSDK/0.0.0'
5253
});
5354
});
5455

packages-exp/auth-exp/src/api/authentication/sms.test.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ describe('sendPhoneVerificationCode', () => {
5151
expect(mock.calls[0].request).to.eql(request);
5252
expect(mock.calls[0].method).to.eq('POST');
5353
expect(mock.calls[0].headers).to.eql({
54-
'Content-Type': 'application/json'
54+
'Content-Type': 'application/json',
55+
'X-Client-Version': 'testSDK/0.0.0'
5556
});
5657
});
5758

@@ -110,7 +111,8 @@ describe('signInWithPhoneNumber', () => {
110111
expect(mock.calls[0].request).to.eql(request);
111112
expect(mock.calls[0].method).to.eq('POST');
112113
expect(mock.calls[0].headers).to.eql({
113-
'Content-Type': 'application/json'
114+
'Content-Type': 'application/json',
115+
'X-Client-Version': 'testSDK/0.0.0'
114116
});
115117
});
116118

@@ -168,7 +170,8 @@ describe('linkWithPhoneNumber', () => {
168170
expect(mock.calls[0].request).to.eql(request);
169171
expect(mock.calls[0].method).to.eq('POST');
170172
expect(mock.calls[0].headers).to.eql({
171-
'Content-Type': 'application/json'
173+
'Content-Type': 'application/json',
174+
'X-Client-Version': 'testSDK/0.0.0'
172175
});
173176
});
174177

@@ -228,7 +231,8 @@ describe('verifyPhoneNumberForExisting', () => {
228231
});
229232
expect(mock.calls[0].method).to.eq('POST');
230233
expect(mock.calls[0].headers).to.eql({
231-
'Content-Type': 'application/json'
234+
'Content-Type': 'application/json',
235+
'X-Client-Version': 'testSDK/0.0.0'
232236
});
233237
});
234238

packages-exp/auth-exp/src/api/index.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,29 @@ export async function performApiRequest<T, V>(
6262
): Promise<V> {
6363
const errorMap = { ...SERVER_ERROR_MAP, ...customErrorMap };
6464
try {
65-
const body = request
66-
? {
65+
let body = {};
66+
const params: { [key: string]: string } = {
67+
key: auth.config.apiKey
68+
};
69+
if (request) {
70+
if (method === HttpMethod.GET) {
71+
Object.assign(params, request);
72+
} else {
73+
body = {
6774
body: JSON.stringify(request)
68-
}
69-
: {};
75+
};
76+
}
77+
}
78+
79+
const queryString = Object.keys(params).map(key => `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`).join('&');
80+
7081
const response = await fetch(
71-
`${auth.config.apiScheme}://${auth.config.apiHost}${path}?key=${auth.config.apiKey}`,
82+
`${auth.config.apiScheme}://${auth.config.apiHost}${path}?${queryString}`,
7283
{
7384
method,
7485
headers: {
75-
'Content-Type': 'application/json'
86+
'Content-Type': 'application/json',
87+
'X-Client-Version': auth.config.sdkClientVersion
7688
},
7789
referrerPolicy: 'no-referrer',
7890
...body

packages-exp/auth-exp/src/model/auth.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export interface Config {
2626
apiKey: ApiKey;
2727
apiHost: string;
2828
apiScheme: string;
29+
sdkClientVersion: string;
2930
authDomain?: AuthDomain;
3031
}
3132

packages-exp/auth-exp/test/api/helper.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ export const mockAuth: Auth = {
2828
config: {
2929
apiKey: 'test-api-key',
3030
apiHost: TEST_HOST,
31-
apiScheme: TEST_SCHEME
31+
apiScheme: TEST_SCHEME,
32+
sdkClientVersion: 'testSDK/0.0.0'
3233
}
3334
};
3435

0 commit comments

Comments
 (0)