Skip to content

feat(clients): retrieve hosts from spec file #111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 2, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ FROM node:$NODE_VERSION-alpine

ENV DOCKER=true

RUN apk add openjdk11 maven jq bash perl
RUN apk add openjdk11 maven jq bash perl yq
ENV JAVA_HOME=/usr/lib/jvm/default-jvm

# Java formatter
Expand Down
21 changes: 21 additions & 0 deletions base.tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": false,
"suppressImplicitAnyIndexErrors": true,
"target": "ES6",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"strict": true,
"moduleResolution": "node",
"removeComments": true,
"sourceMap": true,
"noLib": false,
"declaration": true,
"lib": ["dom", "es6", "es5", "dom.iterable", "scripthost"],
"outDir": "dist",
"typeRoots": ["node_modules/@types"],
"types": ["node"],
"resolveJsonModule": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,16 @@ export class AbtestingApi {
constructor(
appId: string,
apiKey: string,
region: 'de' | 'us',
region?: 'de' | 'us',
options?: { requester?: Requester; hosts?: Host[] }
) {
if (!appId) {
throw new Error('`appId` is missing.');
}

if (!apiKey) {
throw new Error('`apiKey` is missing.');
}
if (!region) {
throw new Error('`region` is missing.');
}

this.setAuthentication({ appId, apiKey });

Expand All @@ -82,10 +80,12 @@ export class AbtestingApi {
});
}

getDefaultHosts(region: 'de' | 'us'): Host[] {
getDefaultHosts(region?: 'de' | 'us'): Host[] {
const regionHost = region ? `.${region}.` : '.';

return [
{
url: `analytics.${region}.algolia.com`,
url: `analytics${regionHost}algolia.com`,
accept: 'readWrite',
protocol: 'https',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,13 @@ export class AnalyticsApi {
constructor(
appId: string,
apiKey: string,
region: 'de' | 'us',
region?: 'de' | 'us',
options?: { requester?: Requester; hosts?: Host[] }
) {
if (!appId) {
throw new Error('`appId` is missing.');
}

if (!apiKey) {
throw new Error('`apiKey` is missing.');
}
Expand All @@ -94,10 +95,12 @@ export class AnalyticsApi {
});
}

getDefaultHosts(region: 'de' | 'us' = 'us'): Host[] {
getDefaultHosts(region?: 'de' | 'us'): Host[] {
const regionHost = region ? `.${region}.` : '.';

return [
{
url: `analytics.${region}.algolia.com`,
url: `analytics${regionHost}algolia.com`,
accept: 'readWrite',
protocol: 'https',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,21 @@ export class InsightsApi {
constructor(
appId: string,
apiKey: string,
region?: 'de' | 'us',
options?: { requester?: Requester; hosts?: Host[] }
) {
if (!appId) {
throw new Error('`appId` is missing.');
}

if (!apiKey) {
throw new Error('`apiKey` is missing.');
}

this.setAuthentication({ appId, apiKey });

this.transporter = new Transporter({
hosts: options?.hosts ?? this.getDefaultHosts(),
hosts: options?.hosts ?? this.getDefaultHosts(region),
baseHeaders: {
'content-type': 'application/x-www-form-urlencoded',
},
Expand All @@ -76,9 +78,15 @@ export class InsightsApi {
});
}

getDefaultHosts(): Host[] {
getDefaultHosts(region?: 'de' | 'us'): Host[] {
const regionHost = region ? `.${region}.` : '.';

return [
{ url: 'insights.algolia.io', accept: 'readWrite', protocol: 'https' },
{
url: `insights${regionHost}algolia.io`,
accept: 'readWrite',
protocol: 'https',
},
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ export class PersonalizationApi {
if (!appId) {
throw new Error('`appId` is missing.');
}

if (!apiKey) {
throw new Error('`apiKey` is missing.');
}

if (!region) {
throw new Error('`region` is missing.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ export class QuerySuggestionsApi {
if (!appId) {
throw new Error('`appId` is missing.');
}

if (!apiKey) {
throw new Error('`apiKey` is missing.');
}

if (!region) {
throw new Error('`region` is missing.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export class SearchApi {
if (!appId) {
throw new Error('`appId` is missing.');
}

if (!apiKey) {
throw new Error('`apiKey` is missing.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ export class SourcesApi {
region: 'de' | 'us',
options?: { requester?: Requester; hosts?: Host[] }
) {
if (!appId) {
throw new Error('`appId` is missing.');
}

if (!apiKey) {
throw new Error('`apiKey` is missing.');
}

if (!region) {
throw new Error('`region` is missing.');
}

this.setAuthentication({ appId, apiKey });

this.transporter = new Transporter({
Expand All @@ -70,7 +82,7 @@ export class SourcesApi {
});
}

getDefaultHosts(region: 'de' | 'us' = 'us'): Host[] {
getDefaultHosts(region: 'de' | 'us'): Host[] {
return [
{
url: `data.${region}.algolia.com`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export class RecommendApi {
if (!appId) {
throw new Error('`appId` is missing.');
}

if (!apiKey) {
throw new Error('`apiKey` is missing.');
}
Expand Down
43 changes: 21 additions & 22 deletions openapitools.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json",
"generator-cli": {
"version": "5.3.0",
"version": "5.4.0",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've upgraded when trying inlined options, it was not successful but let's upgrade it anyway

"generators": {
"javascript-search": {
"generatorName": "typescript-node",
Expand All @@ -19,9 +19,7 @@
"supportsES6": true,
"npmName": "@algolia/client-search",
"packageVersion": "5.0.0",

"packageName": "@algolia/client-search",
"isSearchHost": true
"packageName": "@algolia/client-search"
}
},
"javascript-recommend": {
Expand All @@ -40,9 +38,7 @@
"supportsES6": true,
"npmName": "@algolia/recommend",
"packageVersion": "5.0.0",

"packageName": "@algolia/recommend",
"isSearchHost": true
"packageName": "@algolia/recommend"
}
},
"javascript-personalization": {
Expand All @@ -60,11 +56,11 @@
"supportsES6": true,
"npmName": "@algolia/client-personalization",
"packageVersion": "5.0.0",

"packageName": "@algolia/client-personalization",
"hasRegionalHost": true,
"isEuHost": true,
"host": "personalization"
"host": "personalization",
"topLevelDomain": "com"
}
},
"javascript-analytics": {
Expand All @@ -82,12 +78,12 @@
"supportsES6": true,
"npmName": "@algolia/client-analytics",
"packageVersion": "5.0.0",

"packageName": "@algolia/client-analytics",
"hasRegionalHost": true,
"fallbackToAliasHost": true,
"isDeHost": true,
"fallbackToUS": true,
"host": "analytics"
"host": "analytics",
"topLevelDomain": "com"
}
},
"javascript-insights": {
Expand All @@ -105,9 +101,12 @@
"supportsES6": true,
"npmName": "@algolia/client-insights",
"packageVersion": "5.0.0",

"packageName": "@algolia/client-insights",
"host": "insights"
"host": "insights",
"topLevelDomain": "io",
"hasRegionalHost": true,
"fallbackToAliasHost": true,
"isDeHost": true
}
},
"javascript-abtesting": {
Expand All @@ -125,11 +124,12 @@
"supportsES6": true,
"npmName": "@algolia/client-abtesting",
"packageVersion": "5.0.0",

"packageName": "@algolia/client-abtesting",
"hasRegionalHost": true,
"fallbackToAliasHost": true,
"isDeHost": true,
"host": "analytics"
"host": "analytics",
"topLevelDomain": "com"
}
},
"javascript-query-suggestions": {
Expand All @@ -147,11 +147,11 @@
"supportsES6": true,
"npmName": "@algolia/client-query-suggestions",
"packageVersion": "5.0.0",

"packageName": "@algolia/client-query-suggestions",
"hasRegionalHost": true,
"isEuHost": true,
"host": "query-suggestions"
"host": "query-suggestions",
"topLevelDomain": "com"
}
},
"javascript-sources": {
Expand All @@ -169,11 +169,11 @@
"supportsES6": true,
"npmName": "@algolia/client-sources",
"packageVersion": "0.0.1",

"packageName": "@algolia/client-sources",
"hasRegionalHost": true,
"isDeHost": true,
"host": "data"
"host": "data",
"topLevelDomain": "com"
}
},
"java-search": {
Expand All @@ -195,10 +195,9 @@
"sourceFolder": "algoliasearch-core",
"java8": true,
"dateLibrary": "java8",

"packageName": "algoliasearch-client-java-2"
}
}
}
}
}
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"workspaces": [
"clients/algoliasearch-client-javascript/*",
"playground/javascript/",
"tests/"
"tests/",
"scripts/"
],
"scripts": {
"build:clients": "./scripts/multiplexer.sh ${2:-nonverbose} ./scripts/builds/clients.sh ${0:-all} ${1:-all}",
Expand All @@ -29,7 +30,7 @@
"github-actions:lint": "eslint --ext=yml .github/"
},
"devDependencies": {
"@openapitools/openapi-generator-cli": "2.4.18",
"@openapitools/openapi-generator-cli": "2.4.26",
"@redocly/openapi-cli": "1.0.0-beta.79",
"@typescript-eslint/eslint-plugin": "5.5.0",
"@typescript-eslint/parser": "5.5.0",
Expand Down
17 changes: 2 additions & 15 deletions playground/javascript/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
{
"extends": "../base.tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": false,
"suppressImplicitAnyIndexErrors": true,
"target": "ES6",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"strict": true,
"moduleResolution": "node",
"removeComments": true,
"sourceMap": true,
"noLib": false,
"declaration": true,
"lib": ["dom", "es6", "es5", "dom.iterable", "scripthost"],
"outDir": "dist",
"typeRoots": ["node_modules/@types"]
"outDir": "dist"
},
"include": ["*.ts"]
}
Loading