@algolia/client-common
Advanced tools
Comparing version 5.0.0-alpha.101 to 5.0.0-alpha.102
@@ -18,12 +18,26 @@ function createAuth(appId, apiKey, authMode = 'WithinHeaders') { | ||
host, | ||
searchParams: urlSearchParams, | ||
search, | ||
pathname | ||
}) { | ||
const algoliaAgent = urlSearchParams.get('x-algolia-agent') || ''; | ||
const urlSearchParams = search.split('?'); | ||
if (urlSearchParams.length === 1) { | ||
return { | ||
host, | ||
algoliaAgent: '', | ||
searchParams: undefined, | ||
path: pathname | ||
}; | ||
} | ||
const splitSearchParams = urlSearchParams[1].split('&'); | ||
let algoliaAgent = ''; | ||
const searchParams = {}; | ||
for (const [k, v] of urlSearchParams) { | ||
if (k === 'x-algolia-agent') { | ||
continue; | ||
} | ||
searchParams[k] = v; | ||
if (splitSearchParams.length > 0) { | ||
splitSearchParams.forEach(param => { | ||
const [key, value] = param.split('='); | ||
if (key === 'x-algolia-agent') { | ||
algoliaAgent = value; | ||
return; | ||
} | ||
searchParams[key] = value; | ||
}); | ||
} | ||
@@ -53,3 +67,3 @@ return { | ||
host, | ||
algoliaAgent: encodeURIComponent(algoliaAgent), | ||
algoliaAgent, | ||
searchParams | ||
@@ -376,3 +390,3 @@ }; | ||
const queryParametersAsString = serializeQueryParameters(queryParameters); | ||
let url = `${host.protocol}://${host.url}/${path.charAt(0) === '/' ? path.substr(1) : path}`; | ||
let url = `${host.protocol}://${host.url}${host.port ? `:${host.port}` : ''}/${path.charAt(0) === '/' ? path.substr(1) : path}`; | ||
if (queryParametersAsString.length) { | ||
@@ -385,3 +399,3 @@ url += `?${queryParametersAsString}`; | ||
const isObjectOrArray = value => Object.prototype.toString.call(value) === '[object Object]' || Object.prototype.toString.call(value) === '[object Array]'; | ||
return Object.keys(parameters).map(key => `${key}=${encodeURIComponent(isObjectOrArray(parameters[key]) ? JSON.stringify(parameters[key]) : parameters[key])}`).join('&'); | ||
return Object.keys(parameters).map(key => `${key}=${encodeURIComponent(isObjectOrArray(parameters[key]) ? JSON.stringify(parameters[key]) : parameters[key]).replaceAll('+', '%20')}`).join('&'); | ||
} | ||
@@ -388,0 +402,0 @@ function serializeData(request, requestOptions) { |
@@ -14,2 +14,6 @@ export type Host = { | ||
protocol: 'http' | 'https'; | ||
/** | ||
* The port of the host URL. | ||
*/ | ||
port?: number; | ||
}; | ||
@@ -16,0 +20,0 @@ export type StatefulHost = Host & { |
{ | ||
"name": "@algolia/client-common", | ||
"version": "5.0.0-alpha.101", | ||
"version": "5.0.0-alpha.102", | ||
"description": "Common package for the Algolia JavaScript API client.", | ||
@@ -25,4 +25,4 @@ "repository": "algolia/algoliasearch-client-javascript", | ||
"@babel/preset-typescript": "7.23.3", | ||
"@types/jest": "29.5.11", | ||
"@types/node": "20.11.0", | ||
"@types/jest": "29.5.12", | ||
"@types/node": "20.11.19", | ||
"jest": "29.7.0", | ||
@@ -29,0 +29,0 @@ "jest-environment-jsdom": "29.7.0", |
@@ -10,14 +10,29 @@ import type { EchoResponse, EndRequest, Requester, Response } from './types'; | ||
host, | ||
searchParams: urlSearchParams, | ||
search, | ||
pathname, | ||
}: URL): Pick<EchoResponse, 'algoliaAgent' | 'host' | 'path' | 'searchParams'> { | ||
const algoliaAgent = urlSearchParams.get('x-algolia-agent') || ''; | ||
const urlSearchParams = search.split('?'); | ||
if (urlSearchParams.length === 1) { | ||
return { | ||
host, | ||
algoliaAgent: '', | ||
searchParams: undefined, | ||
path: pathname, | ||
}; | ||
} | ||
const splitSearchParams = urlSearchParams[1].split('&'); | ||
let algoliaAgent = ''; | ||
const searchParams: Record<string, string> = {}; | ||
for (const [k, v] of urlSearchParams) { | ||
if (k === 'x-algolia-agent') { | ||
continue; | ||
} | ||
if (splitSearchParams.length > 0) { | ||
splitSearchParams.forEach((param) => { | ||
const [key, value] = param.split('='); | ||
if (key === 'x-algolia-agent') { | ||
algoliaAgent = value; | ||
return; | ||
} | ||
searchParams[k] = v; | ||
searchParams[key] = value; | ||
}); | ||
} | ||
@@ -48,3 +63,3 @@ | ||
host, | ||
algoliaAgent: encodeURIComponent(algoliaAgent), | ||
algoliaAgent, | ||
searchParams, | ||
@@ -51,0 +66,0 @@ }; |
@@ -33,3 +33,3 @@ import type { | ||
const queryParametersAsString = serializeQueryParameters(queryParameters); | ||
let url = `${host.protocol}://${host.url}/${ | ||
let url = `${host.protocol}://${host.url}${host.port ? `:${host.port}` : ''}/${ | ||
path.charAt(0) === '/' ? path.substr(1) : path | ||
@@ -57,3 +57,3 @@ }`; | ||
: parameters[key] | ||
)}` | ||
).replaceAll('+', '%20')}` | ||
) | ||
@@ -60,0 +60,0 @@ .join('&'); |
@@ -16,2 +16,7 @@ export type Host = { | ||
protocol: 'http' | 'https'; | ||
/** | ||
* The port of the host URL. | ||
*/ | ||
port?: number; | ||
}; | ||
@@ -18,0 +23,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
141537
3872