@algolia/client-personalization
Advanced tools
Comparing version 4.14.1 to 5.0.0-alpha.1
@@ -6,45 +6,281 @@ 'use strict'; | ||
var clientCommon = require('@algolia/client-common'); | ||
var transporter = require('@algolia/transporter'); | ||
var requesterCommon = require('@algolia/requester-common'); | ||
var requesterNodeHttp = require('@algolia/requester-node-http'); | ||
const createPersonalizationClient = options => { | ||
const region = options.region || 'us'; | ||
const auth = clientCommon.createAuth(clientCommon.AuthMode.WithinHeaders, options.appId, options.apiKey); | ||
const transporter$1 = transporter.createTransporter({ | ||
hosts: [{ url: `personalization.${region}.algolia.com` }], | ||
// This file is generated, manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. | ||
const apiClientVersion = '5.0.0-alpha.1'; | ||
const REGIONS = ['eu', 'us']; | ||
function getDefaultHosts(region) { | ||
const url = 'personalization.{region}.algolia.com'.replace('{region}', region); | ||
return [{ url, accept: 'readWrite', protocol: 'https' }]; | ||
} | ||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type | ||
function createPersonalizationClient({ appId: appIdOption, apiKey: apiKeyOption, authMode, algoliaAgents, region: regionOption, ...options }) { | ||
const auth = clientCommon.createAuth(appIdOption, apiKeyOption, authMode); | ||
const transporter = clientCommon.createTransporter({ | ||
hosts: getDefaultHosts(regionOption), | ||
...options, | ||
headers: { | ||
algoliaAgent: clientCommon.getAlgoliaAgent({ | ||
algoliaAgents, | ||
client: 'Personalization', | ||
version: apiClientVersion, | ||
}), | ||
baseHeaders: { | ||
'content-type': 'text/plain', | ||
...auth.headers(), | ||
...{ 'content-type': 'application/json' }, | ||
...options.headers, | ||
...options.baseHeaders, | ||
}, | ||
queryParameters: { | ||
baseQueryParameters: { | ||
...auth.queryParameters(), | ||
...options.queryParameters, | ||
...options.baseQueryParameters, | ||
}, | ||
}); | ||
return clientCommon.addMethods({ appId: options.appId, transporter: transporter$1 }, options.methods); | ||
}; | ||
const getPersonalizationStrategy = (base) => { | ||
return (requestOptions) => { | ||
return base.transporter.read({ | ||
method: requesterCommon.MethodEnum.Get, | ||
path: '1/strategies/personalization', | ||
}, requestOptions); | ||
return { | ||
transporter, | ||
/** | ||
* Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system. | ||
*/ | ||
get _ua() { | ||
return transporter.algoliaAgent.value; | ||
}, | ||
/** | ||
* Adds a `segment` to the `x-algolia-agent` sent with every requests. | ||
* | ||
* @param segment - The algolia agent (user-agent) segment to add. | ||
* @param version - The version of the agent. | ||
*/ | ||
addAlgoliaAgent(segment, version) { | ||
transporter.algoliaAgent.add({ segment, version }); | ||
}, | ||
/** | ||
* This method allow you to send requests to the Algolia REST API. | ||
* | ||
* @summary Send requests to the Algolia REST API. | ||
* @param del - The del object. | ||
* @param del.path - The path of the API endpoint to target, anything after the /1 needs to be specified. | ||
* @param del.parameters - Query parameters to be applied to the current query. | ||
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions. | ||
*/ | ||
del({ path, parameters }, requestOptions) { | ||
if (!path) { | ||
throw new Error('Parameter `path` is required when calling `del`.'); | ||
} | ||
const requestPath = '/1{path}'.replace('{path}', path); | ||
const headers = {}; | ||
const queryParameters = parameters ? parameters : {}; | ||
const request = { | ||
method: 'DELETE', | ||
path: requestPath, | ||
queryParameters, | ||
headers, | ||
}; | ||
return transporter.request(request, requestOptions); | ||
}, | ||
/** | ||
* Delete the user profile and all its associated data. Returns, as part of the response, a date until which the data can safely be considered as deleted for the given user. This means 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 for the deletion request to be fully processed. | ||
* | ||
* @summary Delete a user profile. | ||
* @param deleteUserProfile - The deleteUserProfile object. | ||
* @param deleteUserProfile.userToken - UserToken representing the user for which to fetch the Personalization profile. | ||
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions. | ||
*/ | ||
deleteUserProfile({ userToken }, requestOptions) { | ||
if (!userToken) { | ||
throw new Error('Parameter `userToken` is required when calling `deleteUserProfile`.'); | ||
} | ||
const requestPath = '/1/profiles/{userToken}'.replace('{userToken}', encodeURIComponent(userToken)); | ||
const headers = {}; | ||
const queryParameters = {}; | ||
const request = { | ||
method: 'DELETE', | ||
path: requestPath, | ||
queryParameters, | ||
headers, | ||
}; | ||
return transporter.request(request, requestOptions); | ||
}, | ||
/** | ||
* This method allow you to send requests to the Algolia REST API. | ||
* | ||
* @summary Send requests to the Algolia REST API. | ||
* @param get - The get object. | ||
* @param get.path - The path of the API endpoint to target, anything after the /1 needs to be specified. | ||
* @param get.parameters - Query parameters to be applied to the current query. | ||
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions. | ||
*/ | ||
get({ path, parameters }, requestOptions) { | ||
if (!path) { | ||
throw new Error('Parameter `path` is required when calling `get`.'); | ||
} | ||
const requestPath = '/1{path}'.replace('{path}', path); | ||
const headers = {}; | ||
const queryParameters = parameters ? parameters : {}; | ||
const request = { | ||
method: 'GET', | ||
path: requestPath, | ||
queryParameters, | ||
headers, | ||
}; | ||
return transporter.request(request, requestOptions); | ||
}, | ||
/** | ||
* The strategy contains information on the events and facets that impact user profiles and personalized search results. | ||
* | ||
* @summary Get the current strategy. | ||
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions. | ||
*/ | ||
getPersonalizationStrategy(requestOptions) { | ||
const requestPath = '/1/strategies/personalization'; | ||
const headers = {}; | ||
const queryParameters = {}; | ||
const request = { | ||
method: 'GET', | ||
path: requestPath, | ||
queryParameters, | ||
headers, | ||
}; | ||
return transporter.request(request, requestOptions); | ||
}, | ||
/** | ||
* Get the user profile built from Personalization strategy. The profile is structured by facet name used in the strategy. Each facet value is mapped to its score. Each score represents the user affinity for a specific facet value given the userToken past events and the Personalization strategy defined. Scores are bounded to 20. The last processed event timestamp is provided using the ISO 8601 format for debugging purposes. | ||
* | ||
* @summary Get a user profile. | ||
* @param getUserTokenProfile - The getUserTokenProfile object. | ||
* @param getUserTokenProfile.userToken - UserToken representing the user for which to fetch the Personalization profile. | ||
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions. | ||
*/ | ||
getUserTokenProfile({ userToken }, requestOptions) { | ||
if (!userToken) { | ||
throw new Error('Parameter `userToken` is required when calling `getUserTokenProfile`.'); | ||
} | ||
const requestPath = '/1/profiles/personalization/{userToken}'.replace('{userToken}', encodeURIComponent(userToken)); | ||
const headers = {}; | ||
const queryParameters = {}; | ||
const request = { | ||
method: 'GET', | ||
path: requestPath, | ||
queryParameters, | ||
headers, | ||
}; | ||
return transporter.request(request, requestOptions); | ||
}, | ||
/** | ||
* This method allow you to send requests to the Algolia REST API. | ||
* | ||
* @summary Send requests to the Algolia REST API. | ||
* @param post - The post object. | ||
* @param post.path - The path of the API endpoint to target, anything after the /1 needs to be specified. | ||
* @param post.parameters - Query parameters to be applied to the current query. | ||
* @param post.body - The parameters to send with the custom request. | ||
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions. | ||
*/ | ||
post({ path, parameters, body }, requestOptions) { | ||
if (!path) { | ||
throw new Error('Parameter `path` is required when calling `post`.'); | ||
} | ||
const requestPath = '/1{path}'.replace('{path}', path); | ||
const headers = {}; | ||
const queryParameters = parameters ? parameters : {}; | ||
const request = { | ||
method: 'POST', | ||
path: requestPath, | ||
queryParameters, | ||
headers, | ||
data: body ? body : {}, | ||
}; | ||
return transporter.request(request, requestOptions); | ||
}, | ||
/** | ||
* This method allow you to send requests to the Algolia REST API. | ||
* | ||
* @summary Send requests to the Algolia REST API. | ||
* @param put - The put object. | ||
* @param put.path - The path of the API endpoint to target, anything after the /1 needs to be specified. | ||
* @param put.parameters - Query parameters to be applied to the current query. | ||
* @param put.body - The parameters to send with the custom request. | ||
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions. | ||
*/ | ||
put({ path, parameters, body }, requestOptions) { | ||
if (!path) { | ||
throw new Error('Parameter `path` is required when calling `put`.'); | ||
} | ||
const requestPath = '/1{path}'.replace('{path}', path); | ||
const headers = {}; | ||
const queryParameters = parameters ? parameters : {}; | ||
const request = { | ||
method: 'PUT', | ||
path: requestPath, | ||
queryParameters, | ||
headers, | ||
data: body ? body : {}, | ||
}; | ||
return transporter.request(request, requestOptions); | ||
}, | ||
/** | ||
* A strategy defines the events and facets that impact user profiles and personalized search results. | ||
* | ||
* @summary Set a new strategy. | ||
* @param personalizationStrategyParams - The personalizationStrategyParams object. | ||
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions. | ||
*/ | ||
setPersonalizationStrategy(personalizationStrategyParams, requestOptions) { | ||
if (!personalizationStrategyParams) { | ||
throw new Error('Parameter `personalizationStrategyParams` is required when calling `setPersonalizationStrategy`.'); | ||
} | ||
if (!personalizationStrategyParams.eventScoring) { | ||
throw new Error('Parameter `personalizationStrategyParams.eventScoring` is required when calling `setPersonalizationStrategy`.'); | ||
} | ||
if (!personalizationStrategyParams.facetScoring) { | ||
throw new Error('Parameter `personalizationStrategyParams.facetScoring` is required when calling `setPersonalizationStrategy`.'); | ||
} | ||
if (!personalizationStrategyParams.personalizationImpact) { | ||
throw new Error('Parameter `personalizationStrategyParams.personalizationImpact` is required when calling `setPersonalizationStrategy`.'); | ||
} | ||
const requestPath = '/1/strategies/personalization'; | ||
const headers = {}; | ||
const queryParameters = {}; | ||
const request = { | ||
method: 'POST', | ||
path: requestPath, | ||
queryParameters, | ||
headers, | ||
data: personalizationStrategyParams, | ||
}; | ||
return transporter.request(request, requestOptions); | ||
}, | ||
}; | ||
}; | ||
} | ||
const setPersonalizationStrategy = (base) => { | ||
return (personalizationStrategy, requestOptions) => { | ||
return base.transporter.write({ | ||
method: requesterCommon.MethodEnum.Post, | ||
path: '1/strategies/personalization', | ||
data: personalizationStrategy, | ||
}, requestOptions); | ||
}; | ||
}; | ||
// This file is generated, manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. | ||
function personalizationClient(appId, apiKey, region, options) { | ||
if (!appId || typeof appId !== 'string') { | ||
throw new Error('`appId` is missing.'); | ||
} | ||
if (!apiKey || typeof apiKey !== 'string') { | ||
throw new Error('`apiKey` is missing.'); | ||
} | ||
if (!region) { | ||
throw new Error('`region` is missing.'); | ||
} | ||
if (region && (typeof region !== 'string' || !REGIONS.includes(region))) { | ||
throw new Error(`\`region\` must be one of the following: ${REGIONS.join(', ')}`); | ||
} | ||
return createPersonalizationClient({ | ||
appId, | ||
apiKey, | ||
region, | ||
timeouts: { | ||
connect: clientCommon.DEFAULT_CONNECT_TIMEOUT_NODE, | ||
read: clientCommon.DEFAULT_READ_TIMEOUT_NODE, | ||
write: clientCommon.DEFAULT_WRITE_TIMEOUT_NODE, | ||
}, | ||
requester: requesterNodeHttp.createHttpRequester(), | ||
algoliaAgents: [{ segment: 'Node.js', version: process.versions.node }], | ||
responsesCache: clientCommon.createNullCache(), | ||
requestsCache: clientCommon.createNullCache(), | ||
hostsCache: clientCommon.createMemoryCache(), | ||
...options, | ||
}); | ||
} | ||
exports.createPersonalizationClient = createPersonalizationClient; | ||
exports.getPersonalizationStrategy = getPersonalizationStrategy; | ||
exports.setPersonalizationStrategy = setPersonalizationStrategy; | ||
exports.apiClientVersion = apiClientVersion; | ||
exports.personalizationClient = personalizationClient; |
@@ -1,2 +0,2 @@ | ||
// eslint-disable-next-line functional/immutable-data, import/no-commonjs | ||
// eslint-disable-next-line import/no-commonjs,import/extensions | ||
module.exports = require('./dist/client-personalization.cjs.js'); |
{ | ||
"name": "@algolia/client-personalization", | ||
"version": "4.14.1", | ||
"private": false, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/algolia/algoliasearch-client-javascript.git" | ||
}, | ||
"version": "5.0.0-alpha.1", | ||
"description": "JavaScript client for client-personalization", | ||
"repository": "algolia/algoliasearch-client-javascript", | ||
"license": "MIT", | ||
"sideEffects": false, | ||
"author": "Algolia", | ||
"main": "index.js", | ||
"module": "dist/client-personalization.esm.js", | ||
"types": "dist/client-personalization.d.ts", | ||
"jsdelivr": "dist/client-personalization.umd.js", | ||
"unpkg": "dist/client-personalization.umd.js", | ||
"module": "dist/client-personalization.esm.node.js", | ||
"browser": "dist/client-personalization.umd.js", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"dist", | ||
"model", | ||
"index.js", | ||
"dist" | ||
"index.d.ts" | ||
], | ||
"scripts": { | ||
"clean": "rm -rf ./dist" | ||
}, | ||
"dependencies": { | ||
"@algolia/client-common": "4.14.1", | ||
"@algolia/requester-common": "4.14.1", | ||
"@algolia/transporter": "4.14.1" | ||
"@algolia/client-common": "5.0.0-alpha.1", | ||
"@algolia/requester-browser-xhr": "5.0.0-alpha.1", | ||
"@algolia/requester-node-http": "5.0.0-alpha.1" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "16.11.45", | ||
"typescript": "4.7.4" | ||
}, | ||
"engines": { | ||
"node": ">= 14.0.0" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
101154
40
1952
1
20
2
2
1
2
+ Added@algolia/client-common@5.0.0-alpha.1(transitive)
+ Added@algolia/requester-browser-xhr@5.0.0-alpha.1(transitive)
+ Added@algolia/requester-node-http@5.0.0-alpha.1(transitive)
- Removed@algolia/requester-common@4.14.1
- Removed@algolia/transporter@4.14.1
- Removed@algolia/cache-common@4.14.1(transitive)
- Removed@algolia/client-common@4.14.1(transitive)
- Removed@algolia/logger-common@4.14.1(transitive)
- Removed@algolia/requester-common@4.14.1(transitive)
- Removed@algolia/transporter@4.14.1(transitive)