Skip to content

Commit

Permalink
refactor: Add Type interfaces for identity api client (#945)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexs-mparticle authored Nov 8, 2024
1 parent 957749b commit d019fe0
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/aliasRequestApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { MParticleWebSDK } from "./sdkRuntimeModels";
import Constants from './constants';
import { FetchUploader, XHRUploader } from './uploaders';
import { HTTP_ACCEPTED, HTTP_OK } from "./constants";
import { IIdentityApiClientSendAliasRequest } from "./identityApiClient.interfaces";


const { HTTPCodes, Messages } = Constants;
Expand All @@ -11,7 +12,7 @@ interface IAliasResponseBody {
message?: string
}

export async function sendAliasRequest (mpInstance: MParticleWebSDK, aliasRequest: IAliasRequest, aliasCallback: IAliasCallback) {
export const sendAliasRequest: IIdentityApiClientSendAliasRequest = async function (mpInstance: MParticleWebSDK, aliasRequest: IAliasRequest, aliasCallback: IAliasCallback): Promise<void> {
const { verbose, error } = mpInstance.Logger;
const { invokeAliasCallback } = mpInstance._Helpers;
const { aliasUrl } = mpInstance._Store.SDKConfig;
Expand Down
44 changes: 44 additions & 0 deletions src/identityApiClient.interfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { IdentityApiData, MPID, UserIdentities } from '@mparticle/web-sdk';
import {
IdentityCallback,
IIdentityResponse,
} from './identity-user-interfaces';
import {
IAliasRequest,
IAliasCallback,
IIdentityRequest,
IdentityAPIMethod,
IIdentity,
} from './identity.interfaces';
import { MParticleWebSDK } from './sdkRuntimeModels';

export interface IIdentityApiClient {
sendAliasRequest: (
aliasRequest: IAliasRequest,
aliasCallback: IAliasCallback
) => Promise<void>;
sendIdentityRequest: (
identityApiRequest: IIdentityRequest,
method: IdentityAPIMethod,
callback: IdentityCallback,
originalIdentityApiData: IdentityApiData,
parseIdentityResponse: IIdentity['parseIdentityResponse'],
mpid: MPID,
knownIdentities: UserIdentities
) => Promise<void>;
getUploadUrl: (method: IdentityAPIMethod, mpid: MPID) => string;
getIdentityResponseFromFetch: (
response: Response,
responseBody: string
) => IIdentityResponse;
getIdentityResponseFromXHR: (response: Response) => IIdentityResponse;
}

// https://go.mparticle.com/work/SQDSDKS-6568
// https://go.mparticle.com/work/SQDSDKS-6679
// Combine with `sendIdentityRequest` above once module is fully migrated
export type IIdentityApiClientSendAliasRequest = (
mpInstance: MParticleWebSDK,
aliasRequest: IAliasRequest,
aliasCallback: IAliasCallback
) => Promise<void>;
2 changes: 1 addition & 1 deletion test/src/tests-aliasRequestApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { urls, apiKey, MPConfig, testMPID } from './config/constants';
import { MParticleWebSDK } from '../../src/sdkRuntimeModels';
import { expect } from 'chai';
import { sendAliasRequest } from '../../src/aliasRequestApiClient';
import { IAliasCallback, IAliasRequest } from '../../src/identity.interfaces';
import { IAliasRequest } from '../../src/identity.interfaces';
import { HTTP_ACCEPTED, HTTP_BAD_REQUEST, HTTP_FORBIDDEN, HTTP_OK } from '../../src/constants';

declare global {
Expand Down

0 comments on commit d019fe0

Please sign in to comment.