diff --git a/src/aliasRequestApiClient.ts b/src/aliasRequestApiClient.ts index f4ac2cd5..011ac542 100644 --- a/src/aliasRequestApiClient.ts +++ b/src/aliasRequestApiClient.ts @@ -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; @@ -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 { const { verbose, error } = mpInstance.Logger; const { invokeAliasCallback } = mpInstance._Helpers; const { aliasUrl } = mpInstance._Store.SDKConfig; diff --git a/src/identityApiClient.interfaces.ts b/src/identityApiClient.interfaces.ts new file mode 100644 index 00000000..bbea6585 --- /dev/null +++ b/src/identityApiClient.interfaces.ts @@ -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; + sendIdentityRequest: ( + identityApiRequest: IIdentityRequest, + method: IdentityAPIMethod, + callback: IdentityCallback, + originalIdentityApiData: IdentityApiData, + parseIdentityResponse: IIdentity['parseIdentityResponse'], + mpid: MPID, + knownIdentities: UserIdentities + ) => Promise; + 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; diff --git a/test/src/tests-aliasRequestApiClient.ts b/test/src/tests-aliasRequestApiClient.ts index b40567e0..10e47e6e 100644 --- a/test/src/tests-aliasRequestApiClient.ts +++ b/test/src/tests-aliasRequestApiClient.ts @@ -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 {