Skip to content

Commit b1ff69e

Browse files
authored
fix(client): remove sensitive data from body (#42)
* remove sensitive data from body * cleanup * update bundlesize * update routes * update language code * update routes * update client host
1 parent 0fb4881 commit b1ff69e

File tree

7 files changed

+80
-45
lines changed

7 files changed

+80
-45
lines changed

bundlesize.config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
"files": [
33
{
44
"path": "packages/generative-experiences-api-client/dist/index.js",
5-
"maxSize": "27.57 kB"
5+
"maxSize": "27.59 kB"
66
},
77
{
88
"path": "packages/generative-experiences-api-client/dist/index.umd.js",
9-
"maxSize": "11.53 kB"
9+
"maxSize": "11.55 kB"
1010
},
1111
{
1212
"path": "packages/generative-experiences-vdom/dist/index.js",

examples/playground/src/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ const client = createClient(options);
3939
// .then((response) => console.log(response));
4040

4141
// test generate headlines
42-
// commerceClient.generateHeadlines({
42+
// client.generateHeadlines({
4343
// category: 'category',
4444
// tone: 'natural',
45-
// language_code: 'en_US',
45+
// language_code: 'english',
4646
// });
4747

4848
// test generate content for a headline
@@ -63,7 +63,7 @@ function ComponentTest() {
6363

6464
const { content, status: contentStatus } = useShoppingGuidesContent({
6565
client,
66-
objectID: '123',
66+
objectID: '1234',
6767
showImmediate: true,
6868
onlyPublished: false,
6969
});

packages/generative-experiences-api-client/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ client
9191
| `nbHeadlines` | `number \| undefined` | 4 | The number of headlines to display. | - |
9292
| `source` | `'combined' \| 'generated' \| 'index'` | `index` | The source of the headlines. | - |
9393
| `tone` | `'natural' \| 'friendly' \| 'professional'` | `natural` | The model will use a specific tone when provided. | - |
94-
| `language_code` | `'en_US' \| 'de_DE' \| 'fr_FR'` | `en_US` | The language code used for generating headlines. | - |
94+
| `language_code` | `'english' \| 'german' \| 'french'` | `english` | The language code used for generating headlines. | - |
9595
| `content_to_avoid` | `string` | - | The content that the model should avoid when generating headlines. | - |
9696
| `onlyPublished` | `boolean` | `true` | Only display published guides. | - |
9797

@@ -143,7 +143,7 @@ client
143143
| `source` | `'combined' \| 'generated' \| 'index'` | `index` | The source of the content. | - |
144144
| `type` | `'shopping_guide' \| 'category_guide'` | `shopping_guide` | The type of guide to generate. | Used if `source` is `generated` |
145145
| `tone` | `'natural' \| 'friendly' \| 'professional'` | `natural` | The model will use a specific tone when provided. | - |
146-
| `language_code` | `'en_US' \| 'de_DE' \| 'fr_FR'` | `en_US` | The language code used for generating content. | - |
146+
| `language_code` | `'english' \| 'german' \| 'french'` | `english` | The language code used for generating content. | - |
147147
| `content_to_avoid` | `string` | - | The content that the model should avoid when generating headlines. | - |
148148
| `onlyPublished` | `boolean` | `true` | Only display published guides. | - |
149149

packages/generative-experiences-api-client/src/client.ts

Lines changed: 70 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export type CreateClientOptions = {
4848
writeAPIKey?: string;
4949
};
5050

51-
export const DEFAULT_HOST = 'https://generative-ai.algolia.com';
51+
export const DEFAULT_HOST = 'https://conversational-ai-prod.algolia.com';
5252

5353
export function createClient(opts: CreateClientOptions) {
5454
if (!opts.appId) {
@@ -82,21 +82,20 @@ export function createClient(opts: CreateClientOptions) {
8282
async request({
8383
path,
8484
body,
85+
headers = {},
8586
options = {},
8687
}: {
8788
path: string;
8889
body?: Record<string, unknown>;
90+
headers: Record<string, unknown>;
8991
options?: RequestInit;
9092
}) {
9193
const response = await fetch(this.options.host + path, {
9294
body: body && JSON.stringify(body),
9395
...options,
9496
headers: {
9597
...(body ? { 'Content-Type': 'application/json' } : {}),
96-
'X-Algolia-Application-Id': this.options.appId,
97-
'X-Algolia-API-Key': body?.output_api_key
98-
? String(body?.output_api_key)
99-
: '',
98+
...headers,
10099
...options.headers,
101100
},
102101
});
@@ -115,6 +114,7 @@ export function createClient(opts: CreateClientOptions) {
115114

116115
async waitTask(
117116
{ taskID }: { taskID: string },
117+
headers: Record<string, unknown>,
118118
requestOptions?: RequestParameters
119119
) {
120120
do {
@@ -124,14 +124,16 @@ export function createClient(opts: CreateClientOptions) {
124124
} while (
125125
(
126126
await this.request({
127-
path: `/task/${taskID}/status/`,
127+
path: `/task/${taskID}/status`,
128+
headers,
128129
options: requestOptions,
129130
})
130131
).completed === false
131132
);
132133

133134
return await this.request({
134-
path: `/task/${taskID}/result/`,
135+
path: `/task/${taskID}/result`,
136+
headers,
135137
options: requestOptions,
136138
});
137139
},
@@ -144,22 +146,26 @@ export function createClient(opts: CreateClientOptions) {
144146
throw new Error('Missing writeAPIKey');
145147
}
146148

149+
const headers = {
150+
'X-Algolia-Application-Id': this.options.appId,
151+
'X-Algolia-API-Key': this.options.writeAPIKey,
152+
};
153+
147154
const { taskID } = await this.request({
148-
path: '/generate/shopping_guides_headlines/',
155+
path: '/generate/shopping_guides_headlines',
149156
body: {
150157
index_name: this.options.indexName,
151-
output_application_id: this.options.appId,
152-
output_api_key: this.options.writeAPIKey,
153158
output_index_name: this._outputIndexName(),
154159
...options,
155160
},
161+
headers,
156162
options: {
157163
method: 'POST',
158164
...requestOptions,
159165
},
160166
});
161167

162-
return await this.waitTask({ taskID }, requestOptions);
168+
return await this.waitTask({ taskID }, headers, requestOptions);
163169
},
164170

165171
async generateContent(
@@ -173,23 +179,26 @@ export function createClient(opts: CreateClientOptions) {
173179
if (!this.options.writeAPIKey) {
174180
throw new Error('Missing writeAPIKey');
175181
}
182+
const headers = {
183+
'X-Algolia-Application-Id': this.options.appId,
184+
'X-Algolia-API-Key': this.options.writeAPIKey,
185+
};
176186

177187
const { taskID } = await this.request({
178-
path: `/generate/${type}_content/${objectID}/`,
188+
path: `/generate/${type}_content/${objectID}`,
179189
body: {
180190
index_name: this.options.indexName,
181-
output_application_id: this.options.appId,
182-
output_api_key: this.options.writeAPIKey,
183191
output_index_name: this._outputIndexName(),
184192
...options,
185193
},
194+
headers,
186195
options: {
187196
method: 'POST',
188197
...requestOptions,
189198
},
190199
});
191200

192-
return await this.waitTask({ taskID }, requestOptions);
201+
return await this.waitTask({ taskID }, headers, requestOptions);
193202
},
194203

195204
async generateComparison(
@@ -200,23 +209,27 @@ export function createClient(opts: CreateClientOptions) {
200209
throw new Error('Missing writeAPIKey');
201210
}
202211

212+
const headers = {
213+
'X-Algolia-Application-Id': this.options.appId,
214+
'X-Algolia-API-Key': this.options.writeAPIKey,
215+
};
216+
203217
const { taskID } = await this.request({
204-
path: '/generate/products_comparison/',
218+
path: '/generate/products_comparison',
205219
body: {
206220
object_ids: objectIDs,
207221
index_name: this.options.indexName,
208-
output_application_id: this.options.appId,
209-
output_api_key: this.options.writeAPIKey,
210222
output_index_name: this._outputIndexName(),
211223
...options,
212224
},
225+
headers,
213226
options: {
214227
method: 'POST',
215228
...requestOptions,
216229
},
217230
});
218231

219-
return await this.waitTask({ taskID }, requestOptions);
232+
return await this.waitTask({ taskID }, headers, requestOptions);
220233
},
221234

222235
async getHeadlines(
@@ -394,18 +407,22 @@ export function createClient(opts: CreateClientOptions) {
394407
voteTarget: 'content' | 'headline';
395408
userToken: string;
396409
}) {
410+
const headers = {
411+
'X-Algolia-Application-Id': this.options.appId,
412+
'X-Algolia-API-Key': this.options.searchOnlyAPIKey,
413+
};
414+
397415
return await this.request({
398-
path: '/vote/',
416+
path: '/vote',
399417
body: {
400418
index_name: this.options.indexName,
401-
output_application_id: this.options.appId,
402-
output_api_key: this.options.searchOnlyAPIKey,
403419
output_index_name: this._outputIndexName(),
404420
object_ids: objectIDs,
405421
vote_type: voteType,
406422
vote_target: voteTarget,
407423
user_token: userToken,
408424
},
425+
headers,
409426
options: {
410427
method: 'POST',
411428
},
@@ -420,14 +437,18 @@ export function createClient(opts: CreateClientOptions) {
420437
throw new Error('Missing writeAPIKey');
421438
}
422439

440+
const headers = {
441+
'X-Algolia-Application-Id': this.options.appId,
442+
'X-Algolia-API-Key': this.options.writeAPIKey,
443+
};
444+
423445
return await this.request({
424-
path: '/delete/shopping_guides/',
446+
path: '/delete/shopping_guides',
425447
body: {
426448
object_ids: objectIDs,
427-
output_application_id: this.options.appId,
428-
output_api_key: this.options.writeAPIKey,
429449
index_name: this._outputIndexName(),
430450
},
451+
headers,
431452
options: {
432453
method: 'POST',
433454
...requestOptions,
@@ -443,14 +464,18 @@ export function createClient(opts: CreateClientOptions) {
443464
throw new Error('Missing writeAPIKey');
444465
}
445466

467+
const headers = {
468+
'X-Algolia-Application-Id': this.options.appId,
469+
'X-Algolia-API-Key': this.options.writeAPIKey,
470+
};
471+
446472
return await this.request({
447-
path: '/delete/shopping_guides_content/',
473+
path: '/delete/shopping_guides_content',
448474
body: {
449475
object_ids: objectIDs,
450-
output_application_id: this.options.appId,
451-
output_api_key: this.options.writeAPIKey,
452476
index_name: this._outputIndexName(),
453477
},
478+
headers,
454479
options: {
455480
method: 'POST',
456481
...requestOptions,
@@ -471,16 +496,18 @@ export function createClient(opts: CreateClientOptions) {
471496
if (!this.options.writeAPIKey) {
472497
throw new Error('Missing writeAPIKey');
473498
}
474-
499+
const headers = {
500+
'X-Algolia-Application-Id': this.options.appId,
501+
'X-Algolia-API-Key': this.options.writeAPIKey,
502+
};
475503
return await this.request({
476-
path: '/update/shopping_guide/',
504+
path: '/update/shopping_guide',
477505
body: {
478506
object_id: objectID,
479507
data,
480-
output_application_id: this.options.appId,
481-
output_api_key: this.options.writeAPIKey,
482508
index_name: this._outputIndexName(),
483509
},
510+
headers,
484511
options: {
485512
method: 'POST',
486513
...requestOptions,
@@ -495,14 +522,17 @@ export function createClient(opts: CreateClientOptions) {
495522
if (!this.options.writeAPIKey) {
496523
throw new Error('Missing writeAPIKey');
497524
}
525+
const headers = {
526+
'X-Algolia-Application-Id': this.options.appId,
527+
'X-Algolia-API-Key': this.options.writeAPIKey,
528+
};
498529

499530
return await this.request({
500531
path: '/create/shopping_guides_index/',
501532
body: {
502-
output_application_id: this.options.appId,
503-
output_api_key: this.options.writeAPIKey,
504533
index_name: indexName,
505534
},
535+
headers,
506536
options: {
507537
method: 'POST',
508538
...requestOptions,
@@ -514,8 +544,13 @@ export function createClient(opts: CreateClientOptions) {
514544
_args: unknown,
515545
requestOptions?: RequestParameters
516546
): Promise<TasksResponse> {
547+
const headers = {
548+
'X-Algolia-Application-Id': this.options.appId,
549+
'X-Algolia-API-Key': this.options.writeAPIKey,
550+
};
517551
return await this.request({
518-
path: '/tasks/',
552+
path: '/tasks',
553+
headers,
519554
options: {
520555
...requestOptions,
521556
},

packages/generative-experiences-api-client/src/types/shopping-guides-content.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export type ShoppingGuideContentRequestParameters = {
2424
*/
2525
generated_at?: number;
2626
/**
27-
* @default 'en_US'
27+
* @default 'english'
2828
*/
2929
language_code?: string;
3030
/**

packages/generative-experiences-api-client/src/types/shopping-guides-headlines.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export type ShoppingGuideHeadlinesRequestParameters = {
2626
*/
2727
search_parameters?: PlainSearchParameters;
2828
/**
29-
* @default 'en_US'
29+
* @default 'english'
3030
*/
3131
language_code?: string;
3232
/**

packages/generative-experiences-api-client/src/types/shopping-guides-product-comparison.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export type ProductsComparisonOptions = {
55
*/
66
generated_at?: number;
77
/**
8-
* @default 'en_US'
8+
* @default 'english'
99
*/
1010
language_code?: string;
1111
/**

0 commit comments

Comments
 (0)