Skip to content

Commit bf5203e

Browse files
authored
feat(clients): retrieve hosts from spec file (#111)
1 parent a29c4d5 commit bf5203e

File tree

24 files changed

+307
-164
lines changed

24 files changed

+307
-164
lines changed

base.tsconfig.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"noImplicitAny": false,
5+
"suppressImplicitAnyIndexErrors": true,
6+
"target": "ES6",
7+
"allowSyntheticDefaultImports": true,
8+
"esModuleInterop": true,
9+
"strict": true,
10+
"moduleResolution": "node",
11+
"removeComments": true,
12+
"sourceMap": true,
13+
"noLib": false,
14+
"declaration": true,
15+
"lib": ["ESNext"],
16+
"outDir": "dist",
17+
"typeRoots": ["node_modules/@types"],
18+
"types": ["node"],
19+
"resolveJsonModule": true
20+
}
21+
}

clients/algoliasearch-client-javascript/client-abtesting/src/abtestingApi.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,16 @@ export class AbtestingApi {
5252
constructor(
5353
appId: string,
5454
apiKey: string,
55-
region: 'de' | 'us',
55+
region?: 'de' | 'us',
5656
options?: { requester?: Requester; hosts?: Host[] }
5757
) {
5858
if (!appId) {
5959
throw new Error('`appId` is missing.');
6060
}
61+
6162
if (!apiKey) {
6263
throw new Error('`apiKey` is missing.');
6364
}
64-
if (!region) {
65-
throw new Error('`region` is missing.');
66-
}
6765

6866
this.setAuthentication({ appId, apiKey });
6967

@@ -82,10 +80,12 @@ export class AbtestingApi {
8280
});
8381
}
8482

85-
getDefaultHosts(region: 'de' | 'us'): Host[] {
83+
getDefaultHosts(region?: 'de' | 'us'): Host[] {
84+
const regionHost = region ? `.${region}.` : '.';
85+
8686
return [
8787
{
88-
url: `analytics.${region}.algolia.com`,
88+
url: `analytics${regionHost}algolia.com`,
8989
accept: 'readWrite',
9090
protocol: 'https',
9191
},

clients/algoliasearch-client-javascript/client-analytics/src/analyticsApi.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,13 @@ export class AnalyticsApi {
6767
constructor(
6868
appId: string,
6969
apiKey: string,
70-
region: 'de' | 'us',
70+
region?: 'de' | 'us',
7171
options?: { requester?: Requester; hosts?: Host[] }
7272
) {
7373
if (!appId) {
7474
throw new Error('`appId` is missing.');
7575
}
76+
7677
if (!apiKey) {
7778
throw new Error('`apiKey` is missing.');
7879
}
@@ -94,10 +95,12 @@ export class AnalyticsApi {
9495
});
9596
}
9697

97-
getDefaultHosts(region: 'de' | 'us' = 'us'): Host[] {
98+
getDefaultHosts(region?: 'de' | 'us'): Host[] {
99+
const regionHost = region ? `.${region}.` : '.';
100+
98101
return [
99102
{
100-
url: `analytics.${region}.algolia.com`,
103+
url: `analytics${regionHost}algolia.com`,
101104
accept: 'readWrite',
102105
protocol: 'https',
103106
},

clients/algoliasearch-client-javascript/client-insights/src/insightsApi.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,21 @@ export class InsightsApi {
5050
constructor(
5151
appId: string,
5252
apiKey: string,
53+
region?: 'de' | 'us',
5354
options?: { requester?: Requester; hosts?: Host[] }
5455
) {
5556
if (!appId) {
5657
throw new Error('`appId` is missing.');
5758
}
59+
5860
if (!apiKey) {
5961
throw new Error('`apiKey` is missing.');
6062
}
6163

6264
this.setAuthentication({ appId, apiKey });
6365

6466
this.transporter = new Transporter({
65-
hosts: options?.hosts ?? this.getDefaultHosts(),
67+
hosts: options?.hosts ?? this.getDefaultHosts(region),
6668
baseHeaders: {
6769
'content-type': 'application/x-www-form-urlencoded',
6870
},
@@ -76,9 +78,15 @@ export class InsightsApi {
7678
});
7779
}
7880

79-
getDefaultHosts(): Host[] {
81+
getDefaultHosts(region?: 'de' | 'us'): Host[] {
82+
const regionHost = region ? `.${region}.` : '.';
83+
8084
return [
81-
{ url: 'insights.algolia.io', accept: 'readWrite', protocol: 'https' },
85+
{
86+
url: `insights${regionHost}algolia.io`,
87+
accept: 'readWrite',
88+
protocol: 'https',
89+
},
8290
];
8391
}
8492

clients/algoliasearch-client-javascript/client-personalization/src/personalizationApi.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@ export class PersonalizationApi {
5858
if (!appId) {
5959
throw new Error('`appId` is missing.');
6060
}
61+
6162
if (!apiKey) {
6263
throw new Error('`apiKey` is missing.');
6364
}
65+
6466
if (!region) {
6567
throw new Error('`region` is missing.');
6668
}

clients/algoliasearch-client-javascript/client-query-suggestions/src/querySuggestionsApi.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,11 @@ export class QuerySuggestionsApi {
6060
if (!appId) {
6161
throw new Error('`appId` is missing.');
6262
}
63+
6364
if (!apiKey) {
6465
throw new Error('`apiKey` is missing.');
6566
}
67+
6668
if (!region) {
6769
throw new Error('`region` is missing.');
6870
}

clients/algoliasearch-client-javascript/client-search/src/searchApi.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ export class SearchApi {
109109
if (!appId) {
110110
throw new Error('`appId` is missing.');
111111
}
112+
112113
if (!apiKey) {
113114
throw new Error('`apiKey` is missing.');
114115
}

clients/algoliasearch-client-javascript/client-sources/src/sourcesApi.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ export class SourcesApi {
5353
region: 'de' | 'us',
5454
options?: { requester?: Requester; hosts?: Host[] }
5555
) {
56+
if (!appId) {
57+
throw new Error('`appId` is missing.');
58+
}
59+
60+
if (!apiKey) {
61+
throw new Error('`apiKey` is missing.');
62+
}
63+
64+
if (!region) {
65+
throw new Error('`region` is missing.');
66+
}
67+
5668
this.setAuthentication({ appId, apiKey });
5769

5870
this.transporter = new Transporter({
@@ -70,7 +82,7 @@ export class SourcesApi {
7082
});
7183
}
7284

73-
getDefaultHosts(region: 'de' | 'us' = 'us'): Host[] {
85+
getDefaultHosts(region: 'de' | 'us'): Host[] {
7486
return [
7587
{
7688
url: `data.${region}.algolia.com`,

clients/algoliasearch-client-javascript/recommend/src/recommendApi.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export class RecommendApi {
5555
if (!appId) {
5656
throw new Error('`appId` is missing.');
5757
}
58+
5859
if (!apiKey) {
5960
throw new Error('`apiKey` is missing.');
6061
}

openapitools.json

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json",
33
"generator-cli": {
4-
"version": "5.3.0",
4+
"version": "5.4.0",
55
"generators": {
66
"javascript-search": {
77
"generatorName": "typescript-node",
@@ -19,9 +19,7 @@
1919
"supportsES6": true,
2020
"npmName": "@algolia/client-search",
2121
"packageVersion": "5.0.0",
22-
23-
"packageName": "@algolia/client-search",
24-
"isSearchHost": true
22+
"packageName": "@algolia/client-search"
2523
}
2624
},
2725
"javascript-recommend": {
@@ -40,9 +38,7 @@
4038
"supportsES6": true,
4139
"npmName": "@algolia/recommend",
4240
"packageVersion": "5.0.0",
43-
44-
"packageName": "@algolia/recommend",
45-
"isSearchHost": true
41+
"packageName": "@algolia/recommend"
4642
}
4743
},
4844
"javascript-personalization": {
@@ -60,11 +56,11 @@
6056
"supportsES6": true,
6157
"npmName": "@algolia/client-personalization",
6258
"packageVersion": "5.0.0",
63-
6459
"packageName": "@algolia/client-personalization",
6560
"hasRegionalHost": true,
6661
"isEuHost": true,
67-
"host": "personalization"
62+
"host": "personalization",
63+
"topLevelDomain": "com"
6864
}
6965
},
7066
"javascript-analytics": {
@@ -82,12 +78,12 @@
8278
"supportsES6": true,
8379
"npmName": "@algolia/client-analytics",
8480
"packageVersion": "5.0.0",
85-
8681
"packageName": "@algolia/client-analytics",
82+
"fallbackToAliasHost": true,
8783
"hasRegionalHost": true,
8884
"isDeHost": true,
89-
"fallbackToUS": true,
90-
"host": "analytics"
85+
"host": "analytics",
86+
"topLevelDomain": "com"
9187
}
9288
},
9389
"javascript-insights": {
@@ -105,9 +101,12 @@
105101
"supportsES6": true,
106102
"npmName": "@algolia/client-insights",
107103
"packageVersion": "5.0.0",
108-
109104
"packageName": "@algolia/client-insights",
110-
"host": "insights"
105+
"fallbackToAliasHost": true,
106+
"hasRegionalHost": true,
107+
"isDeHost": true,
108+
"host": "insights",
109+
"topLevelDomain": "io"
111110
}
112111
},
113112
"javascript-abtesting": {
@@ -125,11 +124,12 @@
125124
"supportsES6": true,
126125
"npmName": "@algolia/client-abtesting",
127126
"packageVersion": "5.0.0",
128-
129127
"packageName": "@algolia/client-abtesting",
130128
"hasRegionalHost": true,
129+
"fallbackToAliasHost": true,
131130
"isDeHost": true,
132-
"host": "analytics"
131+
"host": "analytics",
132+
"topLevelDomain": "com"
133133
}
134134
},
135135
"javascript-query-suggestions": {
@@ -147,11 +147,11 @@
147147
"supportsES6": true,
148148
"npmName": "@algolia/client-query-suggestions",
149149
"packageVersion": "5.0.0",
150-
151150
"packageName": "@algolia/client-query-suggestions",
152151
"hasRegionalHost": true,
153152
"isEuHost": true,
154-
"host": "query-suggestions"
153+
"host": "query-suggestions",
154+
"topLevelDomain": "com"
155155
}
156156
},
157157
"javascript-sources": {
@@ -169,11 +169,11 @@
169169
"supportsES6": true,
170170
"npmName": "@algolia/client-sources",
171171
"packageVersion": "0.0.1",
172-
173172
"packageName": "@algolia/client-sources",
174173
"hasRegionalHost": true,
175174
"isDeHost": true,
176-
"host": "data"
175+
"host": "data",
176+
"topLevelDomain": "com"
177177
}
178178
},
179179
"java-search": {
@@ -195,10 +195,9 @@
195195
"sourceFolder": "algoliasearch-core",
196196
"java8": true,
197197
"dateLibrary": "java8",
198-
199198
"packageName": "algoliasearch-client-java-2"
200199
}
201200
}
202201
}
203202
}
204-
}
203+
}

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"workspaces": [
55
"clients/algoliasearch-client-javascript/*",
66
"playground/javascript/",
7-
"tests/"
7+
"tests/",
8+
"scripts/"
89
],
910
"scripts": {
1011
"build:clients": "./scripts/multiplexer.sh ${2:-nonverbose} ./scripts/builds/clients.sh ${0:-all} ${1:-all}",
@@ -29,7 +30,7 @@
2930
"github-actions:lint": "eslint --ext=yml .github/"
3031
},
3132
"devDependencies": {
32-
"@openapitools/openapi-generator-cli": "2.4.18",
33+
"@openapitools/openapi-generator-cli": "2.4.26",
3334
"@redocly/openapi-cli": "1.0.0-beta.79",
3435
"@typescript-eslint/eslint-plugin": "5.5.0",
3536
"@typescript-eslint/parser": "5.5.0",

playground/javascript/tsconfig.json

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,7 @@
11
{
2+
"extends": "../base.tsconfig.json",
23
"compilerOptions": {
3-
"module": "commonjs",
4-
"noImplicitAny": false,
5-
"suppressImplicitAnyIndexErrors": true,
6-
"target": "ES6",
7-
"allowSyntheticDefaultImports": true,
8-
"esModuleInterop": true,
9-
"strict": true,
10-
"moduleResolution": "node",
11-
"removeComments": true,
12-
"sourceMap": true,
13-
"noLib": false,
14-
"declaration": true,
15-
"lib": ["dom", "es6", "es5", "dom.iterable", "scripthost"],
16-
"outDir": "dist",
17-
"typeRoots": ["node_modules/@types"]
4+
"outDir": "dist"
185
},
196
"include": ["*.ts"]
207
}

scripts/generate.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,16 @@ run_pre_gen() {
4444
echo "> Running pre-gen script for $GENERATOR..."
4545
$pregen $CLIENT
4646
fi
47+
48+
# Sets the hosts option to the `openapitools.json` config file
49+
yarn workspace scripts setHostsOptions $LANGUAGE $CLIENT
4750
}
4851

4952
generate_client() {
5053
echo "> Generating code for $GENERATOR..."
54+
5155
CMD="yarn openapi-generator-cli generate --generator-key $GENERATOR"
56+
5257
if [[ $VERBOSE == "true" ]]; then
5358
$CMD
5459
else

0 commit comments

Comments
 (0)