Skip to content

Commit

Permalink
feat(javascript): add addUserAgent method (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcuts committed Feb 22, 2022
1 parent 85f7e0b commit acdd483
Show file tree
Hide file tree
Showing 30 changed files with 98 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"description": "JavaScript client for @algolia/client-abtesting",
"repository": "algolia/algoliasearch-client-javascript",
"author": "Algolia",
"private": true,
"license": "MIT",
"main": "index.js",
"module": "dist/client-abtesting.esm.node.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ function getDefaultHosts(region?: Region): Host[] {
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export const createAbtestingApi = (
export function createAbtestingApi(
options: CreateClientOptions & { region?: Region }
) => {
) {
const auth = createAuth(options.appId, options.apiKey, options.authMode);
const transporter = new Transporter({
hosts: options?.hosts ?? getDefaultHosts(options.region),
Expand All @@ -48,6 +48,10 @@ export const createAbtestingApi = (
requester: options.requester,
});

function addUserAgent(segment: string, version?: string): void {
transporter.userAgent.add({ segment, version });
}

/**
* Creates a new A/B test with provided configuration. You can set an A/B test on two different indices with different settings, or on the same index with different search parameters by providing a customSearchParameters setting on one of the variants.
*
Expand Down Expand Up @@ -222,8 +226,15 @@ export const createAbtestingApi = (
});
}

return { addABTests, deleteABTest, getABTest, listABTests, stopABTest };
};
return {
addUserAgent,
addABTests,
deleteABTest,
getABTest,
listABTests,
stopABTest,
};
}

export type AbtestingApi = ReturnType<typeof createAbtestingApi>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"description": "JavaScript client for @algolia/client-analytics",
"repository": "algolia/algoliasearch-client-javascript",
"author": "Algolia",
"private": true,
"license": "MIT",
"main": "index.js",
"module": "dist/client-analytics.esm.node.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ function getDefaultHosts(region?: Region): Host[] {
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export const createAnalyticsApi = (
export function createAnalyticsApi(
options: CreateClientOptions & { region?: Region }
) => {
) {
const auth = createAuth(options.appId, options.apiKey, options.authMode);
const transporter = new Transporter({
hosts: options?.hosts ?? getDefaultHosts(options.region),
Expand All @@ -63,6 +63,10 @@ export const createAnalyticsApi = (
requester: options.requester,
});

function addUserAgent(segment: string, version?: string): void {
transporter.userAgent.add({ segment, version });
}

/**
* Returns the average click position. The endpoint returns a value for the complete given time range, as well as a value per day.
*
Expand Down Expand Up @@ -1104,6 +1108,7 @@ export const createAnalyticsApi = (
}

return {
addUserAgent,
getAverageClickPosition,
getClickPositions,
getClickThroughRate,
Expand All @@ -1122,7 +1127,7 @@ export const createAnalyticsApi = (
getTopSearches,
getUsersCount,
};
};
}

export type AnalyticsApi = ReturnType<typeof createAnalyticsApi>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"description": "Common package for the Algolia JavaScript API client.",
"repository": "algolia/algoliasearch-client-javascript",
"author": "Algolia",
"private": true,
"license": "MIT",
"main": "dist/client-common.cjs.node.js",
"module": "dist/client-common.esm.node.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class Transporter {
private baseHeaders: Headers;
private baseQueryParameters: QueryParameters;
private hostsCache: Cache;
private userAgent: UserAgent;
userAgent: UserAgent;
private timeouts: Timeouts;
private requester: Requester;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"description": "JavaScript client for @algolia/client-insights",
"repository": "algolia/algoliasearch-client-javascript",
"author": "Algolia",
"private": true,
"license": "MIT",
"main": "index.js",
"module": "dist/client-insights.esm.node.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ function getDefaultHosts(region?: Region): Host[] {
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export const createInsightsApi = (
export function createInsightsApi(
options: CreateClientOptions & { region?: Region }
) => {
) {
const auth = createAuth(options.appId, options.apiKey, options.authMode);
const transporter = new Transporter({
hosts: options?.hosts ?? getDefaultHosts(options.region),
Expand All @@ -46,6 +46,10 @@ export const createInsightsApi = (
requester: options.requester,
});

function addUserAgent(segment: string, version?: string): void {
transporter.userAgent.add({ segment, version });
}

/**
* This command pushes an array of events.
*
Expand Down Expand Up @@ -83,7 +87,7 @@ export const createInsightsApi = (
});
}

return { pushEvents };
};
return { addUserAgent, pushEvents };
}

export type InsightsApi = ReturnType<typeof createInsightsApi>;
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"description": "JavaScript client for @algolia/client-personalization",
"repository": "algolia/algoliasearch-client-javascript",
"author": "Algolia",
"private": true,
"license": "MIT",
"main": "index.js",
"module": "dist/client-personalization.esm.node.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ function getDefaultHosts(region: Region): Host[] {
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export const createPersonalizationApi = (
export function createPersonalizationApi(
options: CreateClientOptions & { region: Region }
) => {
) {
const auth = createAuth(options.appId, options.apiKey, options.authMode);
const transporter = new Transporter({
hosts: options?.hosts ?? getDefaultHosts(options.region),
Expand All @@ -46,6 +46,10 @@ export const createPersonalizationApi = (
requester: options.requester,
});

function addUserAgent(segment: string, version?: string): void {
transporter.userAgent.add({ segment, version });
}

/**
* Returns, as part of the response, a date until which the data can safely be considered as deleted for the given user. This means that if you send events for the given user before this date, they will be ignored. Any data received after the deletedUntil date will start building a new user profile. It might take a couple hours before for the deletion request to be fully processed.
*
Expand Down Expand Up @@ -183,12 +187,13 @@ export const createPersonalizationApi = (
}

return {
addUserAgent,
deleteUserProfile,
getPersonalizationStrategy,
getUserTokenProfile,
setPersonalizationStrategy,
};
};
}

export type PersonalizationApi = ReturnType<typeof createPersonalizationApi>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"description": "JavaScript client for @algolia/client-predict",
"repository": "algolia/algoliasearch-client-javascript",
"author": "Algolia",
"private": true,
"license": "MIT",
"main": "index.js",
"module": "dist/client-predict.esm.node.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function getDefaultHosts(): Host[] {
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export const createPredictApi = (options: CreateClientOptions) => {
export function createPredictApi(options: CreateClientOptions) {
const auth = createAuth(options.appId, options.apiKey, options.authMode);
const transporter = new Transporter({
hosts: options?.hosts ?? getDefaultHosts(),
Expand All @@ -40,6 +40,10 @@ export const createPredictApi = (options: CreateClientOptions) => {
requester: options.requester,
});

function addUserAgent(segment: string, version?: string): void {
transporter.userAgent.add({ segment, version });
}

/**
* Get predictions, properties (raw, computed or custom) and segments (computed or custom) for a user profile.
*
Expand Down Expand Up @@ -83,8 +87,8 @@ export const createPredictApi = (options: CreateClientOptions) => {
});
}

return { fetchUserProfile };
};
return { addUserAgent, fetchUserProfile };
}

export type PredictApi = ReturnType<typeof createPredictApi>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"description": "JavaScript client for @algolia/client-query-suggestions",
"repository": "algolia/algoliasearch-client-javascript",
"author": "Algolia",
"private": true,
"license": "MIT",
"main": "index.js",
"module": "dist/client-query-suggestions.esm.node.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ function getDefaultHosts(region: Region): Host[] {
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export const createQuerySuggestionsApi = (
export function createQuerySuggestionsApi(
options: CreateClientOptions & { region: Region }
) => {
) {
const auth = createAuth(options.appId, options.apiKey, options.authMode);
const transporter = new Transporter({
hosts: options?.hosts ?? getDefaultHosts(options.region),
Expand All @@ -48,6 +48,10 @@ export const createQuerySuggestionsApi = (
requester: options.requester,
});

function addUserAgent(segment: string, version?: string): void {
transporter.userAgent.add({ segment, version });
}

/**
* Create a configuration of a Query Suggestions index. There\'s a limit of 100 configurations per application.
*
Expand Down Expand Up @@ -284,6 +288,7 @@ export const createQuerySuggestionsApi = (
}

return {
addUserAgent,
createConfig,
deleteConfig,
getAllConfigs,
Expand All @@ -292,7 +297,7 @@ export const createQuerySuggestionsApi = (
getLogFile,
updateConfig,
};
};
}

export type QuerySuggestionsApi = ReturnType<typeof createQuerySuggestionsApi>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"description": "JavaScript client for @algolia/client-search",
"repository": "algolia/algoliasearch-client-javascript",
"author": "Algolia",
"private": true,
"license": "MIT",
"main": "index.js",
"module": "dist/client-search.esm.node.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function getDefaultHosts(appId: string): Host[] {
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export const createSearchApi = (options: CreateClientOptions) => {
export function createSearchApi(options: CreateClientOptions) {
const auth = createAuth(options.appId, options.apiKey, options.authMode);
const transporter = new Transporter({
hosts: options?.hosts ?? getDefaultHosts(options.appId),
Expand All @@ -124,6 +124,10 @@ export const createSearchApi = (options: CreateClientOptions) => {
requester: options.requester,
});

function addUserAgent(segment: string, version?: string): void {
transporter.userAgent.add({ segment, version });
}

/**
* Add a new API Key with specific permissions/restrictions.
*
Expand Down Expand Up @@ -2393,6 +2397,7 @@ export const createSearchApi = (options: CreateClientOptions) => {
}

return {
addUserAgent,
addApiKey,
addOrUpdateObject,
appendSource,
Expand Down Expand Up @@ -2451,7 +2456,7 @@ export const createSearchApi = (options: CreateClientOptions) => {
setSettings,
updateApiKey,
};
};
}

export type SearchApi = ReturnType<typeof createSearchApi>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"description": "JavaScript client for @algolia/client-sources",
"repository": "algolia/algoliasearch-client-javascript",
"author": "Algolia",
"private": true,
"license": "MIT",
"main": "index.js",
"module": "dist/client-sources.esm.node.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ function getDefaultHosts(region: Region): Host[] {
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
export const createSourcesApi = (
export function createSourcesApi(
options: CreateClientOptions & { region: Region }
) => {
) {
const auth = createAuth(options.appId, options.apiKey, options.authMode);
const transporter = new Transporter({
hosts: options?.hosts ?? getDefaultHosts(options.region),
Expand All @@ -44,6 +44,10 @@ export const createSourcesApi = (
requester: options.requester,
});

function addUserAgent(segment: string, version?: string): void {
transporter.userAgent.add({ segment, version });
}

/**
* Add an ingestion job that will fetch data from an URL.
*
Expand Down Expand Up @@ -91,7 +95,7 @@ export const createSourcesApi = (
});
}

return { postIngestUrl };
};
return { addUserAgent, postIngestUrl };
}

export type SourcesApi = ReturnType<typeof createSourcesApi>;
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"description": "JavaScript client for @algolia/recommend",
"repository": "algolia/algoliasearch-client-javascript",
"author": "Algolia",
"private": true,
"license": "MIT",
"main": "index.js",
"module": "dist/recommend.esm.node.js",
Expand Down
Loading

0 comments on commit acdd483

Please sign in to comment.