[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dependency on API key #386

Merged
merged 1 commit into from
May 6, 2024
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
12 changes: 6 additions & 6 deletions src/contentFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {Token} from './token';
import {BASE_ENDPOINT_URL, CLIENT_LIBRARY} from './constants';
import {formatMessage} from './error';
import {Logger, NullLogger} from './logging';
import {ApiKey} from './apiKey';
import type {ApiKey} from './apiKey';

export type ErrorResponse = {
type: string,
Expand Down Expand Up @@ -84,7 +84,7 @@ export type Configuration = {

type InternalConfiguration = {
appId?: string,
apiKey?: ApiKey,
apiKey?: string,
};

export class ContentFetcher {
Expand All @@ -102,9 +102,9 @@ export class ContentFetcher {
}

const {baseEndpointUrl} = configuration;
const apiKey = configuration.apiKey !== undefined
? ApiKey.from(configuration.apiKey)
: undefined;
const apiKey = typeof configuration.apiKey === 'object'
? configuration.apiKey.getIdentifier()
: configuration.apiKey;
marcospassos marked this conversation as resolved.
Show resolved Hide resolved

// eslint-disable-next-line prefer-template -- Better readability
const baseEndpoint = (baseEndpointUrl ?? BASE_ENDPOINT_URL).replace(/\/+$/, '')
Expand Down Expand Up @@ -193,7 +193,7 @@ export class ContentFetcher {
}

if (apiKey !== undefined) {
headers['X-Api-Key'] = apiKey.getIdentifier();
headers['X-Api-Key'] = apiKey;
}

const payload: FetchPayload = {
Expand Down
12 changes: 6 additions & 6 deletions src/evaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {BASE_ENDPOINT_URL, CLIENT_LIBRARY, MAX_QUERY_LENGTH} from './constants';
import {formatMessage} from './error';
import {getLength, getLocation, Location} from './sourceLocation';
import {Logger, NullLogger} from './logging';
import {ApiKey} from './apiKey';
import type {ApiKey} from './apiKey';

export type Campaign = {
name?: string,
Expand Down Expand Up @@ -102,7 +102,7 @@ export type Configuration = {

type InternalConfiguration = {
appId?: string,
apiKey?: ApiKey,
apiKey?: string,
};

export class Evaluator {
Expand All @@ -120,9 +120,9 @@ export class Evaluator {
}

const {baseEndpointUrl} = configuration;
const apiKey = configuration.apiKey !== undefined
? ApiKey.from(configuration.apiKey)
: undefined;
const apiKey = typeof configuration.apiKey === 'object'
? configuration.apiKey.getIdentifier()
: configuration.apiKey;

// eslint-disable-next-line prefer-template -- Better readability
this.endpoint = (baseEndpointUrl ?? BASE_ENDPOINT_URL).replace(/\/+$/, '')
Expand Down Expand Up @@ -254,7 +254,7 @@ export class Evaluator {
headers['X-Client-Library'] = CLIENT_LIBRARY;

if (apiKey !== undefined) {
headers['X-Api-Key'] = apiKey.getIdentifier();
headers['X-Api-Key'] = apiKey;
} else if (appId !== undefined) {
headers['X-App-Id'] = appId;
}
Expand Down
2 changes: 1 addition & 1 deletion test/contentFetcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('A content fetcher', () => {
'00000000-0000-0000-0000-000000000000',
'302e020100300506032b6570042204206d0e45033d54aa3231fcef9f0eaa1ff559a68884dbcc8931181b312f90513261',
);
const plainTextApiKey = parsedApiKey.export();
const plainTextApiKey = parsedApiKey.getIdentifier();

const contentId = 'hero-banner';
const content = {
Expand Down
2 changes: 1 addition & 1 deletion test/evaluator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('An evaluator', () => {
'00000000-0000-0000-0000-000000000000',
'302e020100300506032b6570042204206d0e45033d54aa3231fcef9f0eaa1ff559a68884dbcc8931181b312f90513261',
);
const plainTextApiKey = parsedApiKey.export();
const plainTextApiKey = parsedApiKey.getIdentifier();

const query = 'user\'s name';
const requestMatcher: MockOptions = {
Expand Down