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

feat: pass spec header so global segments can be toggled #335

Merged
merged 1 commit into from
Jun 6, 2022
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
3 changes: 3 additions & 0 deletions src/repository/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { StorageProvider } from './storage-provider';
import { UnleashEvents } from '../events';
import { Segment } from '../strategy/strategy';

const SUPPORTED_SPEC_VERSION = '4.2.0';

export interface RepositoryInterface extends EventEmitter {
getToggle(name: string): FeatureInterface;
getToggles(): FeatureInterface[];
Expand Down Expand Up @@ -263,6 +265,7 @@ Message: ${err.message}`,
instanceId: this.instanceId,
headers,
httpOptions: this.httpOptions,
supportedSpecVersion: SUPPORTED_SPEC_VERSION,
});

if (res.status === 304) {
Expand Down
8 changes: 7 additions & 1 deletion src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface GetRequestOptions extends RequestOptions {
etag?: string;
appName?: string;
instanceId?: string;
supportedSpecVersion?: string;
httpOptions?: HttpOptions;
}

Expand Down Expand Up @@ -47,6 +48,7 @@ export const buildHeaders = (
etag?: string,
contentType?: string,
custom?: CustomHeaders,
specVersionSupported?: string,
): Record<string, string> => {
const head: Record<string, string> = {};
if (appName) {
Expand All @@ -62,6 +64,9 @@ export const buildHeaders = (
if (contentType) {
head['Content-Type'] = contentType;
}
if (specVersionSupported) {
head['Unleash-Client-Spec'] = specVersionSupported;
}
if (custom) {
Object.assign(head, custom);
}
Expand Down Expand Up @@ -94,12 +99,13 @@ export const get = ({
instanceId,
headers,
httpOptions,
supportedSpecVersion,
}: GetRequestOptions) =>
fetch(url, {
method: 'GET',
timeout: timeout || 10_000,
agent: httpOptions?.agent || getDefaultAgent,
headers: buildHeaders(appName, instanceId, etag, undefined, headers),
headers: buildHeaders(appName, instanceId, etag, undefined, headers, supportedSpecVersion),
retry: {
retries: 2,
maxTimeout: timeout || 10_000,
Expand Down
2 changes: 1 addition & 1 deletion src/unleash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export class Unleash extends EventEmitter {
}
if (result.name) {
this.countVariant(name, result.name);
}
}
this.count(name, result.enabled);

return result;
Expand Down