diff --git a/lib/regions.ts b/lib/regions.ts index 8bdfd07..24b7ae5 100644 --- a/lib/regions.ts +++ b/lib/regions.ts @@ -1,14 +1,12 @@ export class Region { readonly trackUrl: string; readonly apiUrl: string; - readonly trackPushUrl?: string; - constructor(trackUrl: string, apiUrl: string, trackPushUrl?: string) { + constructor(trackUrl: string, apiUrl: string) { this.trackUrl = trackUrl; this.apiUrl = apiUrl; - this.trackPushUrl = trackPushUrl; } } -export const RegionUS = new Region('https://track.customer.io/api/v1', 'https://api.customer.io/v1', 'https://track.customer.io/push'); -export const RegionEU = new Region('https://track-eu.customer.io/api/v1', 'https://api-eu.customer.io/v1', 'https://track-eu.customer.io/push'); +export const RegionUS = new Region('https://track.customer.io/api/v1', 'https://api.customer.io/v1'); +export const RegionEU = new Region('https://track-eu.customer.io/api/v1', 'https://api-eu.customer.io/v1'); diff --git a/lib/track.ts b/lib/track.ts index 9698f64..0bfc2f5 100644 --- a/lib/track.ts +++ b/lib/track.ts @@ -4,14 +4,7 @@ import { Region, RegionUS } from './regions'; import { isEmpty } from './utils'; import { IdentifierType } from './types'; -type TrackDefaults = RequestOptions & { region: Region; url?: string; apiUrl?: string; trackPushUrl?: string }; - -class MissingConfigError extends Error { - constructor(param: string) { - super(param); - this.message = `${param} is required`; - } -} +type TrackDefaults = RequestOptions & { region: Region; url?: string; apiUrl?: string; }; class MissingParamError extends Error { constructor(param: string) { @@ -27,7 +20,6 @@ export class TrackClient { request: Request; trackRoot: string; apiRoot: string; - trackPushRoot?: string; constructor(siteid: BasicAuth['siteid'], apikey: BasicAuth['apikey'], defaults: Partial = {}) { if (defaults.region && !(defaults.region instanceof Region)) { @@ -41,7 +33,6 @@ export class TrackClient { this.trackRoot = this.defaults.url ? this.defaults.url : this.defaults.region.trackUrl; this.apiRoot = this.defaults.apiUrl ? this.defaults.apiUrl : this.defaults.region.apiUrl; - this.trackPushRoot = this.defaults.trackPushUrl ? this.defaults.trackPushUrl : this.defaults.region.trackPushUrl; } identify(customerId: string | number, data: RequestData = {}) { @@ -108,11 +99,7 @@ export class TrackClient { } trackPush(data: PushRequestData = {}) { - if (isEmpty(this.trackPushRoot)) { - throw new MissingConfigError('trackPushRoot'); - - } - return this.request.post(`${this.trackPushRoot}/events`, data); + return this.request.post(`${this.trackRoot}/push/events`, data); } addDevice(customerId: string | number, device_id: string, platform: string, data = {}) { diff --git a/test/track.ts b/test/track.ts index c0c0bab..86b0a49 100644 --- a/test/track.ts +++ b/test/track.ts @@ -24,7 +24,6 @@ test('constructor sets necessary variables', (t) => { t.is(t.context.client.apikey, 'abc'); t.is(t.context.client.trackRoot, RegionUS.trackUrl); t.is(t.context.client.apiRoot, RegionUS.apiUrl); - t.is(t.context.client.trackPushRoot, RegionUS.trackPushUrl); t.truthy(t.context.client.request); t.is(t.context.client.request.siteid, '123'); @@ -39,7 +38,6 @@ test('constructor sets correct URL for different regions', (t) => { t.is(client.apikey, 'abc'); t.is(client.trackRoot, region.trackUrl); t.is(client.apiRoot, region.apiUrl); - t.is(client.trackPushRoot, region.trackPushUrl); t.truthy(client.request); t.is(client.request.siteid, '123'); @@ -48,13 +46,12 @@ test('constructor sets correct URL for different regions', (t) => { }); test('constructor sets correct URL for custom URLs', (t) => { - let client = new TrackClient('123', 'abc', { url: 'https://example.com/url', apiUrl: 'https://example.com/apiUrl', trackPushUrl: 'https://example.com/push' }); + let client = new TrackClient('123', 'abc', { url: 'https://example.com/url', apiUrl: 'https://example.com/apiUrl' }); t.is(client.siteid, '123'); t.is(client.apikey, 'abc'); t.is(client.trackRoot, 'https://example.com/url'); t.is(client.apiRoot, 'https://example.com/apiUrl'); - t.is(client.trackPushRoot, 'https://example.com/push'); t.truthy(client.request); t.is(client.request.siteid, '123'); @@ -139,7 +136,7 @@ test('#trackPush works', (t) => { sinon.stub(t.context.client.request, 'post'); t.context.client.trackPush(); t.truthy( - (t.context.client.request.post as SinonStub).calledWith(`${RegionUS.trackPushUrl}/events`, {}), + (t.context.client.request.post as SinonStub).calledWith(`${RegionUS.trackUrl}/push/events`, {}), ); t.context.client.trackPush({ @@ -149,7 +146,7 @@ test('#trackPush works', (t) => { timestamp: 1613063089 }); t.truthy( - (t.context.client.request.post as SinonStub).calledWith(`${RegionUS.trackPushUrl}/events`, { + (t.context.client.request.post as SinonStub).calledWith(`${RegionUS.trackUrl}/push/events`, { delivery_id: "RPILAgUBcRhIBqSfeiIwdIYJKxTY", event: "opened", device_id: "CIO-Delivery-Token from the notification", @@ -158,12 +155,6 @@ test('#trackPush works', (t) => { ); }); -test('#trackPush throws error if trackPushRoot is missing', (t) => { - t.context.client = new TrackClient('123', 'abc', { region: new Region('https://example.com/url', 'https://example.com/apiUrl')}); - sinon.stub(t.context.client.request, 'post'); - t.throws(() => t.context.client.trackPush(), { message: 'trackPushRoot is required' }); -}); - ID_INPUTS.forEach(([input, expected]) => { test(`#trackPageView works for ${input}`, (t) => { sinon.stub(t.context.client.request, 'post');