Skip to content

Commit 99c78c6

Browse files
Migrate Identity API Client to TypeScript
1 parent c16c104 commit 99c78c6

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

src/identityApiClient.interfaces.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { IdentityApiData, MPID, UserIdentities } from '@mparticle/web-sdk';
22
import {
33
IdentityCallback,
4+
IdentityResultBody,
45
IIdentityResponse,
56
} from './identity-user-interfaces';
67
import {
@@ -29,9 +30,9 @@ export interface IIdentityApiClient {
2930
getUploadUrl: (method: IdentityAPIMethod, mpid: MPID) => string;
3031
getIdentityResponseFromFetch: (
3132
response: Response,
32-
responseBody: string
33+
responseBody: IdentityResultBody
3334
) => IIdentityResponse;
34-
getIdentityResponseFromXHR: (response: Response) => IIdentityResponse;
35+
getIdentityResponseFromXHR: (response: XMLHttpRequest) => IIdentityResponse;
3536
}
3637

3738
// https://go.mparticle.com/work/SQDSDKS-6568
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ import { sendAliasRequest } from './aliasRequestApiClient';
33
import { FetchUploader, XHRUploader } from './uploaders';
44
import { CACHE_HEADER } from './identity-utils';
55
import { parseNumber } from './utils';
6+
import { IIdentityApiClient } from './identityApiClient.interfaces';
67

78
var HTTPCodes = Constants.HTTPCodes,
89
Messages = Constants.Messages;
910

1011
const { Modify } = Constants.IdentityMethods;
1112

12-
export default function IdentityAPIClient(mpInstance) {
13+
export default function IdentityAPIClient(this: IIdentityApiClient, mpInstance) {
1314
this.sendAliasRequest = async function(aliasRequest, callback) {
1415
await sendAliasRequest(mpInstance, aliasRequest, callback);
1516
};
@@ -74,7 +75,7 @@ export default function IdentityAPIClient(mpInstance) {
7475
responseBody
7576
);
7677
} else {
77-
identityResponse = this.getIdentityResponseFromXHR(response);
78+
identityResponse = this.getIdentityResponseFromXHR(response as unknown as XMLHttpRequest);
7879
}
7980

8081
verbose(
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import IdentityApiClient from '../../src/identityApiClient';
2+
import { MParticleWebSDK } from '../../src/sdkRuntimeModels';
3+
4+
describe('Identity Api Client', () => {
5+
describe('#getUploadUrl', () => {
6+
it.only('should generate an upload url with defaults', () => {
7+
const mockSDK = ({
8+
_Helpers: {
9+
createServiceUrl: () => 'https://identity.mparticle.com/',
10+
},
11+
_Store: {
12+
},
13+
_Persistence: {
14+
},
15+
} as unknown) as MParticleWebSDK;
16+
17+
const identityApiClient = new IdentityApiClient(mockSDK);
18+
19+
const url = identityApiClient.getUploadUrl();
20+
expect(url).toBe('https://identity.mparticle.com/v1/identify');
21+
});
22+
});
23+
describe('#sendIdentityRequest', () => {
24+
25+
});
26+
});

0 commit comments

Comments
 (0)