Skip to content

Commit

Permalink
Merge pull request #119 from adjust/DSM-3000-url-strategy
Browse files Browse the repository at this point in the history
[DSM-3000] Rework URL strategy
  • Loading branch information
YaraMatkova authored Jul 19, 2024
2 parents 51378f9 + ebe8da8 commit d09f1a5
Show file tree
Hide file tree
Showing 13 changed files with 426 additions and 262 deletions.
41 changes: 32 additions & 9 deletions dist/adjust-latest.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,22 @@ declare namespace Adjust {
state: string
}

/**
* @deprecated
*/
type UrlStartegyLiterals = 'china' | 'india';

interface UrlStrategyConfig {
/** The country or countries of data residence, or the endpoints to which you want to send SDK traffic. */
domains: Array<string>;

/** Whether the source should prefix a subdomain. */
useSubdomains: boolean;

/** Whether the domain should be used for data residency. */
isDataResidency?: boolean;
}

interface InitOptions {

/** Required to initialise SDK instance, please make sure to provide valid app token. */
Expand All @@ -122,19 +138,27 @@ declare namespace Adjust {
eventDeduplicationListLimit?: number;

/** Optional. By default all requests go to Adjust's endpoints. You are able to redirect all requests to your custom
* endpoint. */
* endpoint.
*
* @deprecated use {@link urlStrategy} property instead
*/
customUrl?: string;

/** Optional. The data residency feature allows you to choose the country in which Adjust will store your data. This
* is useful if you are operating in a country with strict privacy requirements. When you set up data residency,
* Adjust will store your data in a data center located in the region your have chosen. */
* Adjust will store your data in a data center located in the region your have chosen.
*
* @deprecated use {@link urlStrategy} property instead
*/
dataResidency?: 'EU' | 'TR' | 'US';

/** Optional. The Adjust SDK can use the url strategy setting to prioritise regional endpoints. */
urlStrategy?: 'india' | 'china';
/** Optional. The URL strategy feature allows you to set either:
* - The country in which Adjust stores your data (data residency).
* - The endpoint to which the Adjust SDK sends traffic (URL strategy).*/
// TODO: place a link to updated docs in this warning, see https://adjustcom.atlassian.net/browse/DSM-3071
urlStrategy?: UrlStartegyLiterals | UrlStrategyConfig;

/**
* Optional. A custom namespace for SDK data storage. If not set then default one is used.
/** Optional. A custom namespace for SDK data storage. If not set then default one is used.
* It's useful when there are multiple applications on the same domain to allow SDK distinguish storages and don't
* mix the data up.
*
Expand Down Expand Up @@ -169,8 +193,7 @@ declare namespace Adjust {
*/
logLevel?: LogLevel;

/**
* Optional. Query selector to define html container if you want to see your logs directly on the screen. This could
/** Optional. Query selector to define html container if you want to see your logs directly on the screen. This could
* be useful when testing on mobile devices.
*
* @example
Expand Down Expand Up @@ -214,7 +237,7 @@ declare namespace Adjust {
/**
* Returns a promise which resolves when current attribution information becomes available
*/
function waitForAttribution(): Promise<AttributionMapT>
function waitForAttribution(): Promise<Attribution>

/**
* Get web_uuid - a unique ID of user generated per subdomain and per browser
Expand Down
50 changes: 31 additions & 19 deletions src/sdk/__mocks__/url-strategy.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
import type { BaseUrlsMap, UrlStrategy } from '../url-strategy'
import { BaseUrlsMap } from '../url-strategy'

const urlStrategyModule = jest.requireActual('../url-strategy')
type Endpoints = keyof typeof testEndpoints

const testEndpoints = {
default: { app: 'app.default', gdpr: '' },
india: { app: 'app.india', gdpr: '' },
china: { app: 'app.china', gdpr: '' }
export const testEndpoints = {
default: 'default',
world: 'world',
}

const singleEndpoint = { default: { app: 'app', gdpr: 'gdpr' } }

export const mockEndpoints = {
endpoints: testEndpoints,
singleEndpoint
export const singleEndpoint = {
default: 'default'
}

export function urlStrategyRetries<T>(
sendRequest: (urls: BaseUrlsMap) => Promise<T>,
endpoints: Partial<Record<UrlStrategy, BaseUrlsMap>> = mockEndpoints.endpoints
) {
return urlStrategyModule.urlStrategyRetries(sendRequest, endpoints)
}
export function getBaseUrlsIterator(endpoints: Partial<Record<Endpoints, string>> = singleEndpoint) {
const _urls = [] as BaseUrlsMap[]

for (const i in endpoints) {
const urlMap = {
app: 'app.' + i,
gdpr: 'gdpr.' + i
}
_urls.push(urlMap)
}

let _counter = 0

export function getBaseUrlsIterator(endpoints: Partial<Record<UrlStrategy, BaseUrlsMap>> = mockEndpoints.singleEndpoint) {
return urlStrategyModule.getBaseUrlsIterator(endpoints)
return {
next: () => {
if (_counter < _urls.length) {
return { value: _urls[_counter++], done: false }
} else {
return { value: undefined, done: true }
}
},
reset: () => {
_counter = 0
}
}
}
4 changes: 2 additions & 2 deletions src/sdk/__tests__/activity-state.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ describe('activity state functionality', () => {

describe('async waitForWebUUID function', () => {
it('resolves when web_uuid cached', async () => {
await expect(ActivityState.default.waitForWebUUID()).resolves.toEqual('some-uuid');
await expect(ActivityState.default.waitForWebUUID()).resolves.toBe('some-uuid');
})

it('resolves when receives attribution with pub-sub', async () => {
Expand All @@ -349,7 +349,7 @@ describe('activity state functionality', () => {

publish(PUB_SUB_EVENTS.WEB_UUID_CREATED, 'new_web_uuid');

await expect(webUuidPromise).resolves.toEqual('new_web_uuid');
await expect(webUuidPromise).resolves.toBe('new_web_uuid');
})
})
})
Expand Down
2 changes: 1 addition & 1 deletion src/sdk/__tests__/event.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const appOptions = {
function expectRequest (requestConfig, timestamp) {

const fullConfig = {
endpoint: 'app',
endpoint: 'app.default',
...requestConfig,
params: {
attempts: 1,
Expand Down
2 changes: 1 addition & 1 deletion src/sdk/__tests__/gdpr-forget-device.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function expectRequest () {
}

const fullConfig = {
endpoint: 'gdpr',
endpoint: 'gdpr.default',
...requestConfig,
params: {
attempts: 1,
Expand Down
4 changes: 2 additions & 2 deletions src/sdk/__tests__/main/main.storage-not-available.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ const mockGetType = () => STORAGE_TYPES.NO_STORAGE
jest.mock('../../storage/storage', () => ({
init: () => mockInit(),
getType: () => mockGetType()
}
))
})
)

describe('main entry point - test instance initiation when storage is not available', () => {

Expand Down
Loading

0 comments on commit d09f1a5

Please sign in to comment.