@lableb/javascript-sdk
Version:
Lableb cloud search client for javascript
44 lines (34 loc) • 1.42 kB
text/typescript
import { LablebDocument } from '../../core/lableb-client/lableb-client.type';
import { customIdentity, customPickBy } from '../../utils';
import { GlobalRequestOptions } from '../main/main.request.type';
import { buildIndexingRequestSchema } from './indexing.schema';
import { IndexingRequestParams, IndexingRequestResult } from './indexing.request.type';
export async function buildIndexingRequest(this: GlobalRequestOptions, params: IndexingRequestParams): Promise<IndexingRequestResult> {
const validatedParams = await buildIndexingRequestSchema
.validate(
customPickBy({
indexName: params.indexName || this?.indexName || process.env.GLOBAL_DEFAULT_INDEX_NAME,
platformName: params.platformName || this?.platformName,
indexingAPIKey: params.indexingAPIKey || this?.indexingAPIKey,
documents: params.documents,
}, customIdentity)
);
const {
indexName,
platformName,
indexingAPIKey,
documents,
} = validatedParams;
return {
method: 'POST',
url: `${process.env.API_BASE_URL}/projects/${platformName}/indices/${indexName}/documents`,
params: customPickBy(
{
apikey: indexingAPIKey,
},
customIdentity
),
headers: {},
body: documents as LablebDocument[],
}
}