Skip to content

feat: straightforward client init with apiKey and appId #7

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 3 commits into from
Nov 15, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 6 additions & 3 deletions app.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { SearchApi } from 'algoliasearch-client-javascript';
import { searchClient } from './searchClient';

const client = new SearchApi();
const appId = process.env.ALGOLIA_APPLICATION_ID_1 || '**** APP_ID *****';
const apiKey = process.env.ALGOLIA_ADMIN_KEY_1 || '**** API_KEY *****';
// Init client with appId and apiKey
const client = new searchClient(appId, apiKey);

async function testClient() {
// test openapi gen
try {
const res = await client.multipleQueries('R2IYF7ETH7', 'e1e920e59f457ec70473486171c1d3b6', {
const res = await client.multipleQueries({
requests: [
{
indexName: 'docsearch',
Expand Down
2 changes: 0 additions & 2 deletions openapi_spec/paths/indexes/batch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ post:
operationId: batch
summary: Performs multiple write operations in a single API call
parameters:
- $ref: '../../parameters.yml#/AppId'
- $ref: '../../parameters.yml#/ApiKey'
- $ref: '../../parameters.yml#/IndexName'
requestBody:
required: true
Expand Down
3 changes: 0 additions & 3 deletions openapi_spec/paths/indexes/multipleQueries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ post:
- search
operationId: multipleQueries
summary: Get search results for the given requests.
parameters:
- $ref: '../../parameters.yml#/AppId'
- $ref: '../../parameters.yml#/ApiKey'
requestBody:
required: true
content:
Expand Down
2 changes: 0 additions & 2 deletions openapi_spec/paths/indexes/saveObject.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ post:
summary: Save object
description: Add an object to the index, automatically assigning it an object ID
parameters:
- $ref: '../../parameters.yml#/AppId'
- $ref: '../../parameters.yml#/ApiKey'
- $ref: '../../parameters.yml#/IndexName'
requestBody:
required: true
Expand Down
2 changes: 0 additions & 2 deletions openapi_spec/paths/indexes/search.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ post:
operationId: search
summary: Get search results
parameters:
- $ref: '../../parameters.yml#/AppId'
- $ref: '../../parameters.yml#/ApiKey'
- $ref: '../../parameters.yml#/IndexName'
requestBody:
$ref: '../../schemas/SearchParams.yml'
Expand Down
78 changes: 0 additions & 78 deletions output/client-search/searchApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,10 @@ export class SearchApi {
/**
*
* @summary Performs multiple write operations in a single API call
* @param xAlgoliaApplicationId Algolia appID
* @param xAlgoliaAPIKey Algolia API key
* @param indexName The index in which to perform the request
* @param batchObject
*/
public async batch(
xAlgoliaApplicationId: string,
xAlgoliaAPIKey: string,
indexName: string,
batchObject: BatchObject,
options: { headers: { [name: string]: string } } = { headers: {} }
Expand All @@ -107,20 +103,6 @@ export class SearchApi {
}
let localVarFormParams: any = {};

// verify required parameter 'xAlgoliaApplicationId' is not null or undefined
if (xAlgoliaApplicationId === null || xAlgoliaApplicationId === undefined) {
throw new Error(
'Required parameter xAlgoliaApplicationId was null or undefined when calling batch.'
);
}

// verify required parameter 'xAlgoliaAPIKey' is not null or undefined
if (xAlgoliaAPIKey === null || xAlgoliaAPIKey === undefined) {
throw new Error(
'Required parameter xAlgoliaAPIKey was null or undefined when calling batch.'
);
}

// verify required parameter 'indexName' is not null or undefined
if (indexName === null || indexName === undefined) {
throw new Error('Required parameter indexName was null or undefined when calling batch.');
Expand All @@ -131,14 +113,6 @@ export class SearchApi {
throw new Error('Required parameter batchObject was null or undefined when calling batch.');
}

localVarHeaderParams['X-Algolia-Application-Id'] = ObjectSerializer.serialize(
xAlgoliaApplicationId,
'string'
);
localVarHeaderParams['X-Algolia-API-Key'] = ObjectSerializer.serialize(
xAlgoliaAPIKey,
'string'
);
(<any>Object).assign(localVarHeaderParams, options.headers);

let localVarUseFormData = false;
Expand Down Expand Up @@ -192,13 +166,9 @@ export class SearchApi {
/**
*
* @summary Get search results for the given requests.
* @param xAlgoliaApplicationId Algolia appID
* @param xAlgoliaAPIKey Algolia API key
* @param multipleQueriesObject
*/
public async multipleQueries(
xAlgoliaApplicationId: string,
xAlgoliaAPIKey: string,
multipleQueriesObject: MultipleQueriesObject,
options: { headers: { [name: string]: string } } = { headers: {} }
): Promise<{ response: http.IncomingMessage; body: MultipleQueriesResponse }> {
Expand All @@ -214,35 +184,13 @@ export class SearchApi {
}
let localVarFormParams: any = {};

// verify required parameter 'xAlgoliaApplicationId' is not null or undefined
if (xAlgoliaApplicationId === null || xAlgoliaApplicationId === undefined) {
throw new Error(
'Required parameter xAlgoliaApplicationId was null or undefined when calling multipleQueries.'
);
}

// verify required parameter 'xAlgoliaAPIKey' is not null or undefined
if (xAlgoliaAPIKey === null || xAlgoliaAPIKey === undefined) {
throw new Error(
'Required parameter xAlgoliaAPIKey was null or undefined when calling multipleQueries.'
);
}

// verify required parameter 'multipleQueriesObject' is not null or undefined
if (multipleQueriesObject === null || multipleQueriesObject === undefined) {
throw new Error(
'Required parameter multipleQueriesObject was null or undefined when calling multipleQueries.'
);
}

localVarHeaderParams['X-Algolia-Application-Id'] = ObjectSerializer.serialize(
xAlgoliaApplicationId,
'string'
);
localVarHeaderParams['X-Algolia-API-Key'] = ObjectSerializer.serialize(
xAlgoliaAPIKey,
'string'
);
(<any>Object).assign(localVarHeaderParams, options.headers);

let localVarUseFormData = false;
Expand Down Expand Up @@ -296,14 +244,10 @@ export class SearchApi {
/**
* Add an object to the index, automatically assigning it an object ID
* @summary Save object
* @param xAlgoliaApplicationId Algolia appID
* @param xAlgoliaAPIKey Algolia API key
* @param indexName The index in which to perform the request
* @param requestBody
*/
public async saveObject(
xAlgoliaApplicationId: string,
xAlgoliaAPIKey: string,
indexName: string,
requestBody: { [key: string]: object },
options: { headers: { [name: string]: string } } = { headers: {} }
Expand All @@ -325,20 +269,6 @@ export class SearchApi {
}
let localVarFormParams: any = {};

// verify required parameter 'xAlgoliaApplicationId' is not null or undefined
if (xAlgoliaApplicationId === null || xAlgoliaApplicationId === undefined) {
throw new Error(
'Required parameter xAlgoliaApplicationId was null or undefined when calling saveObject.'
);
}

// verify required parameter 'xAlgoliaAPIKey' is not null or undefined
if (xAlgoliaAPIKey === null || xAlgoliaAPIKey === undefined) {
throw new Error(
'Required parameter xAlgoliaAPIKey was null or undefined when calling saveObject.'
);
}

// verify required parameter 'indexName' is not null or undefined
if (indexName === null || indexName === undefined) {
throw new Error(
Expand All @@ -353,14 +283,6 @@ export class SearchApi {
);
}

localVarHeaderParams['X-Algolia-Application-Id'] = ObjectSerializer.serialize(
xAlgoliaApplicationId,
'string'
);
localVarHeaderParams['X-Algolia-API-Key'] = ObjectSerializer.serialize(
xAlgoliaAPIKey,
'string'
);
(<any>Object).assign(localVarHeaderParams, options.headers);

let localVarUseFormData = false;
Expand Down
11 changes: 11 additions & 0 deletions searchClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { SearchApi } from 'algoliasearch-client-javascript';

export class searchClient extends SearchApi {
public constructor(appId: string, apiKey: string) {
super();

this.defaultHeaders['X-Algolia-Application-Id'] = appId;
this.defaultHeaders['X-Algolia-API-Key'] = apiKey;
this.basePath = 'https://' + appId + '-1.algolianet.com';
}
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
"outDir": "dist",
"typeRoots": ["node_modules/@types"]
},
"include": ["app.ts"]
"include": ["searchClient.ts", "app.ts"]
}
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,11 @@ __metadata:

"algoliasearch-client-javascript@file:output/::locator=%40algolia%2Fautomation-javascript-client%40workspace%3A.":
version: 5.0.0
resolution: "algoliasearch-client-javascript@file:output/#output/::hash=9f2500&locator=%40algolia%2Fautomation-javascript-client%40workspace%3A."
resolution: "algoliasearch-client-javascript@file:output/#output/::hash=5e44d1&locator=%40algolia%2Fautomation-javascript-client%40workspace%3A."
dependencies:
"@types/request": ^2.48.7
request: ^2.81.0
checksum: 4a413d1bbbeeaf41a9e4f75a2e9f8be6b827439a80099c57ae0d2b2387da9563ff416133c028989fe17eaa95025e248f8f586d78a08f903819eacae536f73b0b
checksum: 324b24f6828b13f4d863425274de41987bcd006e3950379d01fb822308ef0cab02ca07e21297697fccd1b6aa5b3784f92f5f4f74550da0f4a61921d1fe18e7b0
languageName: node
linkType: hard

Expand Down