Skip to content

Commit

Permalink
Merge pull request #5136 from gooddata/mkn-f1-491
Browse files Browse the repository at this point in the history
fix: earlyAccess flags
  • Loading branch information
scavnickyj authored Jul 17, 2024
2 parents 5636008 + 08b1fd4 commit bdb6260
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
27 changes: 13 additions & 14 deletions libs/sdk-backend-tiger/src/backend/features/hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ async function getFeatureHubData(
context: FeatureContext,
state?: HubServiceState[string],
): Promise<AxiosResponse<FeatureHubResponse>> {
const featureHubFlags: string[] = [];
if (context.organizationId) {
featureHubFlags.push(`organizationId=${encodeURIComponent(context.organizationId)}`);
}
if (context.earlyAccessValues?.length > 0) {
featureHubFlags.push(
`earlyAccess=${context.earlyAccessValues
.filter(Boolean)
.map((v) => encodeURIComponent(v))
.join(";")}`,
);
}
return axios.get("/features", {
method: "GET",
baseURL: host,
Expand All @@ -97,20 +109,7 @@ async function getFeatureHubData(
timeout: FH_TIMEOUT,
headers: {
"Content-type": "application/json",
"X-FeatureHub": Object.keys(context)
.reduce((prev, item) => {
const value = context[item as keyof typeof context];
if (value === undefined || value === "") {
return prev;
}

const parsed = Array.isArray(value)
? value.map((v) => `${item}[]=${encodeURIComponent(v)}`)
: [`${item}=${encodeURIComponent(value)}`];

return [...prev, ...parsed];
}, [] as Array<string>)
.join(","),
"X-FeatureHub": featureHubFlags.join(","),
...(state ? { "if-none-match": state.etag } : {}),
},
validateStatus: (status) => {
Expand Down
6 changes: 3 additions & 3 deletions libs/sdk-backend-tiger/src/backend/features/test/hub.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe("live features", () => {
baseURL: "/",
headers: {
"Content-type": "application/json",
"X-FeatureHub": "earlyAccessValues[]=omega,organizationId=test-org",
"X-FeatureHub": "organizationId=test-org,earlyAccess=omega",
"if-none-match": expect.anything(),
},
method: "GET",
Expand All @@ -86,7 +86,7 @@ describe("live features", () => {
baseURL: "/",
headers: {
"Content-type": "application/json",
"X-FeatureHub": "earlyAccessValues[]=beta,organizationId=org",
"X-FeatureHub": "organizationId=org,earlyAccess=beta",
"if-none-match": expect.anything(),
},
method: "GET",
Expand All @@ -107,7 +107,7 @@ describe("live features", () => {
baseURL: "/",
headers: {
"Content-type": "application/json",
"X-FeatureHub": "earlyAccessValues[]=omega,organizationId=test-org",
"X-FeatureHub": "organizationId=test-org,earlyAccess=omega",
"if-none-match": expect.anything(),
},
method: "GET",
Expand Down

0 comments on commit bdb6260

Please sign in to comment.