Skip to content
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 0 additions & 90 deletions src/aliasRequestApiClient.ts

This file was deleted.

5 changes: 4 additions & 1 deletion src/apiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ export default function APIClient(
this.queueEventForBatchUpload(event);
}

if (event.EventName !== Types.MessageType.AppStateTransition) {
// https://go.mparticle.com/work/SQDSDKS-6935
// While Event Name is 'usually' a string, there are some cases where it is a number
// in that it could be a type of MessageType Enum
if (event.EventName as unknown as number !== Types.MessageType.AppStateTransition) {
if (kitBlocker && kitBlocker.kitBlockingEnabled) {
event = kitBlocker.createBlockedEvent(event);
}
Expand Down
4 changes: 2 additions & 2 deletions src/audienceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
FetchUploader,
XHRUploader,
AsyncUploader,
fetchPayload
IFetchPayload
} from './uploaders';
import Audience from './audience';

Expand Down Expand Up @@ -38,7 +38,7 @@ export default class AudienceManager {
public async sendGetUserAudienceRequest(mpid: string, callback: (userAudiences: IAudienceMemberships) => void) {
this.logger.verbose('Fetching user audiences from server');

const fetchPayload: fetchPayload = {
const fetchPayload: IFetchPayload = {
method: 'GET',
headers: {
Accept: '*/*',
Expand Down
50 changes: 28 additions & 22 deletions src/batchUploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { Batch } from '@mparticle/event-models';
import Constants from './constants';
import { SDKEvent, MParticleWebSDK, SDKLoggerApi } from './sdkRuntimeModels';
import { convertEvents } from './sdkToEventsApiConverter';
import Types from './types';
import { MessageType } from './types';
import { getRampNumber, isEmpty } from './utils';
import { SessionStorageVault, LocalStorageVault } from './vault';
import {
AsyncUploader,
FetchUploader,
XHRUploader,
fetchPayload,
IFetchPayload,
} from './uploaders';
import { IMParticleUser } from './identity-user-interfaces';

Expand Down Expand Up @@ -167,29 +167,35 @@ export class BatchUploader {
* @param event event that should be queued
*/
public queueEvent(event: SDKEvent): void {
if (!isEmpty(event)) {
this.eventsQueuedForProcessing.push(event);
if (this.offlineStorageEnabled && this.eventVault) {
this.eventVault.store(this.eventsQueuedForProcessing);
}
this.mpInstance.Logger.verbose(
`Queuing event: ${JSON.stringify(event)}`
);
this.mpInstance.Logger.verbose(
`Queued event count: ${this.eventsQueuedForProcessing.length}`
);
if (isEmpty(event)) {
return;
}

// TODO: Remove this check once the v2 code path is removed
// https://go.mparticle.com/work/SQDSDKS-3720
if (
!this.batchingEnabled ||
Types.TriggerUploadType[event.EventDataType]
) {
this.prepareAndUpload(false, false);
}
const { verbose } = this.mpInstance.Logger;

this.eventsQueuedForProcessing.push(event);
if (this.offlineStorageEnabled && this.eventVault) {
this.eventVault.store(this.eventsQueuedForProcessing);
}

verbose(`Queuing event: ${JSON.stringify(event)}`);
verbose(`Queued event count: ${this.eventsQueuedForProcessing.length}`);

if (this.shouldTriggerImmediateUpload(event.EventDataType)) {
this.prepareAndUpload(false, false);
}
}

// https://go.mparticle.com/work/SQDSDKS-3720
private shouldTriggerImmediateUpload (eventDataType: number): boolean {
const priorityEvents = [
MessageType.Commerce,
MessageType.UserIdentityChange,
] as const;

return !this.batchingEnabled || priorityEvents.includes(eventDataType as typeof priorityEvents[number]);
};

/**
* This implements crucial logic to:
* - bucket pending events by MPID, and then by Session, and upload individual batches for each bucket.
Expand Down Expand Up @@ -366,7 +372,7 @@ export class BatchUploader {
logger.verbose(`Batch count: ${uploads.length}`);

for (let i = 0; i < uploads.length; i++) {
const fetchPayload: fetchPayload = {
const fetchPayload: IFetchPayload = {
method: 'POST',
headers: {
Accept: BatchUploader.CONTENT_TYPE,
Expand Down
4 changes: 2 additions & 2 deletions src/configAPIClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { Dictionary } from './utils';
import {
AsyncUploader,
fetchPayload,
IFetchPayload,
FetchUploader,
XHRUploader,
} from './uploaders';
Expand Down Expand Up @@ -125,7 +125,7 @@ export default function ConfigAPIClient(

this.getSDKConfiguration = async (): Promise<IConfigResponse> => {
let configResponse: IConfigResponse;
const fetchPayload: fetchPayload = {
const fetchPayload: IFetchPayload = {
method: 'get',
headers: {
Accept: 'text/plain;charset=UTF-8',
Expand Down
8 changes: 8 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ const Constants = {
Login: 'login',
Identify: 'identify',
},

Environment: {
Development: 'development',
Production: 'production',
},
} as const;

export default Constants;
Expand All @@ -196,4 +201,7 @@ export const MILLIS_IN_ONE_SEC = 1000;
export const HTTP_OK = 200 as const;
export const HTTP_ACCEPTED = 202 as const;
export const HTTP_BAD_REQUEST = 400 as const;
export const HTTP_UNAUTHORIZED = 401 as const;
export const HTTP_FORBIDDEN = 403 as const;
export const HTTP_NOT_FOUND = 404 as const;
export const HTTP_SERVER_ERROR = 500 as const;
Loading
Loading