-
Notifications
You must be signed in to change notification settings - Fork 227
Expand file tree
/
Copy pathcreatePersonalizationClient.ts
More file actions
37 lines (31 loc) · 991 Bytes
/
createPersonalizationClient.ts
File metadata and controls
37 lines (31 loc) · 991 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import {
addMethods,
AuthMode,
ClientTransporterOptions,
createAuth,
CreateClient,
} from '@algolia/client-common';
import { createTransporter } from '@algolia/transporter';
import { PersonalizationClient, PersonalizationClientOptions } from '.';
export const createPersonalizationClient: CreateClient<
PersonalizationClient,
PersonalizationClientOptions & ClientTransporterOptions
> = options => {
const region = options.region || 'us';
const auth = createAuth(AuthMode.WithinHeaders, options.appId, options.apiKey);
const transporter = createTransporter({
hosts: [{ url: `personalization.${region}.algolia.com` }],
...options,
headers: {
...auth.headers(),
...{ 'content-type': 'application/json' },
...options.headers,
},
queryParameters: {
...auth.queryParameters(),
...options.queryParameters,
},
data: auth.data(),
});
return addMethods({ appId: options.appId, transporter }, options.methods);
};