Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@ vi.mock('algoliasearch', () => ({
}));

const server = setupServer(
http.post(
'https://generative-us.algolia.com//delete/shopping_guides/',
() => {
return HttpResponse.json({ status: 'success' });
}
)
http.post('https://generative-us.algolia.com/1/delete/guides/', () => {
return HttpResponse.json({ status: 'success' });
})
);

describe('createClient', () => {
Expand Down
34 changes: 15 additions & 19 deletions packages/generative-experiences-api-client/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { algoliasearch } from 'algoliasearch';
import type { FacetFilters } from 'algoliasearch';
import { algoliasearch } from 'algoliasearch';
import type { PlainSearchParameters } from 'algoliasearch-helper';

import { getObjectIDs, getObjects } from './helpers/records';
import {
GenerationSource,
ProductsComparisonOptions,
RequestParameters,
Guide,
GuideContentOptions,
GuideContentOptionsForGenerated,
Expand All @@ -15,6 +13,8 @@ import {
GuideHeadlinesOptionsForCombined,
GuideHeadlinesOptionsForGenerated,
GuideHeadlinesOptionsForIndex,
ProductsComparisonOptions,
RequestParameters,
TasksResponse,
} from './types';
import { version } from './version';
Expand Down Expand Up @@ -128,15 +128,15 @@ export function createClient(opts: CreateClientOptions) {
} while (
(
await this.request({
path: `/task/${taskID}/status`,
path: `/1/task/${taskID}/status`,
headers,
options: requestOptions,
})
).completed === false
);

return await this.request({
path: `/task/${taskID}/result`,
path: `/1/task/${taskID}/result`,
headers,
options: requestOptions,
});
Expand All @@ -156,7 +156,7 @@ export function createClient(opts: CreateClientOptions) {
};

const { taskID } = await this.request({
path: '/generate/shopping_guides_headlines',
path: '/1/generate/headlines',
body: {
index_name: this.options.indexName,
output_index_name: this._outputIndexName(),
Expand All @@ -173,11 +173,7 @@ export function createClient(opts: CreateClientOptions) {
},

async generateContent(
{
objectID,
type = 'shopping_guide',
...options
}: Omit<GuideContentOptionsForGenerated, 'source'>,
{ objectID, ...options }: Omit<GuideContentOptionsForGenerated, 'source'>,
requestOptions?: RequestParameters
) {
if (!this.options.writeAPIKey) {
Expand All @@ -189,7 +185,7 @@ export function createClient(opts: CreateClientOptions) {
};

const { taskID } = await this.request({
path: `/generate/${type}_content/${objectID}`,
path: `/1/generate/guide_content/${objectID}`,
body: {
index_name: this.options.indexName,
output_index_name: this._outputIndexName(),
Expand Down Expand Up @@ -219,7 +215,7 @@ export function createClient(opts: CreateClientOptions) {
};

const { taskID } = await this.request({
path: '/generate/products_comparison',
path: '/1/generate/products_comparison',
body: {
object_ids: objectIDs,
index_name: this.options.indexName,
Expand Down Expand Up @@ -459,7 +455,7 @@ export function createClient(opts: CreateClientOptions) {
};

return await this.request({
path: '/vote',
path: '/1/vote',
body: {
index_name: this.options.indexName,
output_index_name: this._outputIndexName(),
Expand Down Expand Up @@ -489,7 +485,7 @@ export function createClient(opts: CreateClientOptions) {
};

return await this.request({
path: '/delete/shopping_guides',
path: '/1/delete/guides',
body: {
object_ids: objectIDs,
index_name: this._outputIndexName(),
Expand All @@ -516,7 +512,7 @@ export function createClient(opts: CreateClientOptions) {
};

return await this.request({
path: '/delete/shopping_guides_content',
path: '/1/delete/guides_content',
body: {
object_ids: objectIDs,
index_name: this._outputIndexName(),
Expand Down Expand Up @@ -547,7 +543,7 @@ export function createClient(opts: CreateClientOptions) {
'X-Algolia-API-Key': this.options.writeAPIKey,
};
return await this.request({
path: '/update/shopping_guide',
path: '/1/update/guide',
body: {
object_id: objectID,
data,
Expand All @@ -574,7 +570,7 @@ export function createClient(opts: CreateClientOptions) {
};

return await this.request({
path: '/create/shopping_guides_index/',
path: '/1/create/guides_index/',
body: {
index_name: indexName,
},
Expand All @@ -595,7 +591,7 @@ export function createClient(opts: CreateClientOptions) {
'X-Algolia-API-Key': this.options.writeAPIKey,
};
return await this.request({
path: '/tasks',
path: '/1/tasks',
headers,
options: {
...requestOptions,
Expand Down