Skip to content

Commit bae6188

Browse files
changed api key field on RecordScanner to be able to accept either a plain key as a string or an object containing the key and the header name
1 parent 1dbf8e3 commit bae6188

File tree

1 file changed

+6
-21
lines changed

1 file changed

+6
-21
lines changed

sdk/src/record-scanner.ts

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ import { RegistrationRequest } from "./models/record-scanner/registrationRequest
4141
class RecordScanner implements RecordProvider {
4242
account?: Account;
4343
readonly url: string;
44-
private apiKey?: string;
44+
private apiKey?: { header: string, value: string };
4545
private uuid?: string;
4646

47-
constructor(url: string, account?: Account, apiKey?: string) {
47+
constructor(url: string, account?: Account, apiKey?: string | { header: string, value: string }) {
4848
this.account = account;
4949
this.url = url;
50-
this.apiKey = apiKey;
50+
this.apiKey = typeof apiKey === "string" ? { header: "X-Provable-API-Key", value: apiKey } : apiKey;
5151
}
5252

5353
/**
@@ -65,8 +65,8 @@ class RecordScanner implements RecordProvider {
6565
*
6666
* @param {string} apiKey The API key to use for the record scanner.
6767
*/
68-
async setApiKey(apiKey: string): Promise<void> {
69-
this.apiKey = apiKey;
68+
async setApiKey(apiKey: string | { header: string, value: string }): Promise<void> {
69+
this.apiKey = typeof apiKey === "string" ? { header: "X-Provable-API-Key", value: apiKey } : apiKey;
7070
}
7171

7272
/**
@@ -299,7 +299,7 @@ class RecordScanner implements RecordProvider {
299299
private async request(req: Request): Promise<Response> {
300300
try {
301301
if (this.apiKey) {
302-
req.headers.set("X-Provable-API-Key", this.apiKey);
302+
req.headers.set(this.apiKey.header, this.apiKey.value);
303303
}
304304
const response = await fetch(req);
305305

@@ -313,21 +313,6 @@ class RecordScanner implements RecordProvider {
313313
throw error;
314314
}
315315
}
316-
317-
/**
318-
* Helper function to build a query string from the records filter and response filter.
319-
*
320-
* @param {RecordSearchParams} recordsFilter The filter to use to find the records.
321-
* @param {RecordsResponseFilter} responseFilter The filter to use to filter the response.
322-
* @returns {string} The query string.
323-
*/
324-
private buildQueryString(recordsFilter: RecordsFilter, responseFilter: RecordsResponseFilter): string {
325-
return Object.entries({ ...recordsFilter, ...responseFilter })
326-
.map(([key, value]) => {
327-
return `${key}=${Array.isArray(value) ? value.join(",") : value}`
328-
})
329-
.join("&");
330-
}
331316
}
332317

333318
export { RecordScanner };

0 commit comments

Comments
 (0)