Skip to content

Commit e043259

Browse files
committed
chore(sdk): split context update type fixes into separate PR
1 parent 506e85a commit e043259

10 files changed

Lines changed: 16 additions & 178 deletions

File tree

‎.changeset/gentle-context-updates.md‎

Lines changed: 0 additions & 7 deletions
This file was deleted.

‎packages/browser-sdk/src/client.ts‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,7 @@ import { deepEqual } from "fast-equals";
22

33
import { BulkEvent, BulkQueue } from "./bulkQueue";
44
import { API_BASE_URL, APP_BASE_URL, IS_SERVER, SDK_VERSION } from "./config";
5-
import {
6-
CompanyContext,
7-
ContextValue,
8-
ReflagContext,
9-
ReflagDeprecatedContext,
10-
UserContext,
11-
} from "./context";
5+
import { ReflagContext, ReflagDeprecatedContext } from "./context";
126
import {
137
AutoFeedback,
148
Feedback,
@@ -850,7 +844,7 @@ export class ReflagClient {
850844
*
851845
* @param user
852846
*/
853-
async updateUser(user: Partial<UserContext>) {
847+
async updateUser(user: { [key: string]: string | number | undefined }) {
854848
const newUserContext = {
855849
...this.context.user,
856850
...user,
@@ -874,7 +868,7 @@ export class ReflagClient {
874868
*
875869
* @param company The company details.
876870
*/
877-
async updateCompany(company: Partial<CompanyContext>) {
871+
async updateCompany(company: { [key: string]: string | number | undefined }) {
878872
const newCompanyContext = {
879873
...this.context.company,
880874
...company,
@@ -898,7 +892,9 @@ export class ReflagClient {
898892
*
899893
* @param otherContext Additional context.
900894
*/
901-
async updateOtherContext(otherContext: Record<string, ContextValue>) {
895+
async updateOtherContext(otherContext: {
896+
[key: string]: string | number | undefined;
897+
}) {
902898
const newOtherContext = {
903899
...this.context.other,
904900
...otherContext,

‎packages/browser-sdk/test/client.test.ts‎

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { http, HttpResponse } from "msw";
22
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
33

44
import { ReflagClient } from "../src/client";
5-
import { CompanyContext, ContextValue, UserContext } from "../src/context";
65
import { FlagsClient } from "../src/flag/flags";
76
import { HttpClient } from "../src/httpClient";
87
import { deferred } from "./deferred";
@@ -67,37 +66,6 @@ describe("ReflagClient", () => {
6766
vi.unstubAllGlobals();
6867
});
6968

70-
it("accepts JSON-compatible values in user, company and other context updates", async () => {
71-
const user: UserContext = {
72-
id: "user1",
73-
enabled: true,
74-
tags: ["beta", 1, null],
75-
preferences: { theme: "dark", omitted: undefined },
76-
cleared: null,
77-
};
78-
const company: CompanyContext = {
79-
id: "company1",
80-
enterprise: false,
81-
settings: { regions: ["eu", "us"] },
82-
};
83-
const other: Record<string, ContextValue> = {
84-
preview: true,
85-
settings: { locale: "en" },
86-
};
87-
88-
await client.updateUser(user);
89-
await client.updateCompany(company);
90-
await client.updateOtherContext(other);
91-
await client.updateUser({ enabled: false });
92-
93-
expect(client.getContext()).toEqual({
94-
user: { ...user, enabled: false },
95-
company,
96-
other,
97-
});
98-
expect(flagClientSetContext).toHaveBeenLastCalledWith(client.getContext());
99-
});
100-
10169
describe("updateUser", () => {
10270
it("should update the user context", async () => {
10371
// and send new user data and trigger flag update

‎packages/react-sdk/src/index.tsx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ export type ReflagProps = ReflagPropsBase &
536536
* Context which is not related to a user or a company.
537537
* @deprecated Use `context` instead, this property will be removed in the next major version
538538
*/
539-
otherContext?: ReflagContext["other"];
539+
otherContext?: Record<string, string | number | undefined>;
540540
};
541541

542542
/**
@@ -935,7 +935,7 @@ export function useSendFeedback() {
935935
*/
936936
export function useUpdateUser() {
937937
const client = useClient();
938-
return (opts: Parameters<ReflagClient["updateUser"]>[0]) =>
938+
return (opts: { [key: string]: string | number | undefined }) =>
939939
client.updateUser(opts);
940940
}
941941

@@ -955,7 +955,7 @@ export function useUpdateUser() {
955955
export function useUpdateCompany() {
956956
const client = useClient();
957957

958-
return (opts: Parameters<ReflagClient["updateCompany"]>[0]) =>
958+
return (opts: { [key: string]: string | number | undefined }) =>
959959
client.updateCompany(opts);
960960
}
961961

@@ -975,7 +975,7 @@ export function useUpdateCompany() {
975975
*/
976976
export function useUpdateOtherContext() {
977977
const client = useClient();
978-
return (opts: Parameters<ReflagClient["updateOtherContext"]>[0]) =>
978+
return (opts: { [key: string]: string | number | undefined }) =>
979979
client.updateOtherContext(opts);
980980
}
981981

‎packages/react-sdk/test/context-update-types.tsx‎

Lines changed: 0 additions & 57 deletions
This file was deleted.

‎packages/react-sdk/tsconfig.type-tests.json‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,5 @@
77
"@reflag/react-sdk": ["./src/index.tsx"]
88
}
99
},
10-
"include": [
11-
"src",
12-
"test/opt-in-types.tsx",
13-
"test/flag-updated-types.tsx",
14-
"test/context-update-types.tsx"
15-
]
10+
"include": ["src", "test/opt-in-types.tsx", "test/flag-updated-types.tsx"]
1611
}

‎packages/vue-sdk/src/hooks.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ export function useSendFeedback() {
278278
*/
279279
export function useUpdateUser() {
280280
const client = useClient();
281-
return (opts: Parameters<ReflagClient["updateUser"]>[0]) =>
281+
return (opts: { [key: string]: string | number | undefined }) =>
282282
client.updateUser(opts);
283283
}
284284

@@ -304,7 +304,7 @@ export function useUpdateUser() {
304304
*/
305305
export function useUpdateCompany() {
306306
const client = useClient();
307-
return (opts: Parameters<ReflagClient["updateCompany"]>[0]) =>
307+
return (opts: { [key: string]: string | number | undefined }) =>
308308
client.updateCompany(opts);
309309
}
310310

@@ -330,7 +330,7 @@ export function useUpdateCompany() {
330330
*/
331331
export function useUpdateOtherContext() {
332332
const client = useClient();
333-
return (opts: Parameters<ReflagClient["updateOtherContext"]>[0]) =>
333+
return (opts: { [key: string]: string | number | undefined }) =>
334334
client.updateOtherContext(opts);
335335
}
336336

‎packages/vue-sdk/src/types.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export type ReflagProps = ReflagInitOptionsBase &
161161
* Context which is not related to a user or a company.
162162
* @deprecated Use `context` instead, this property will be removed in the next major version
163163
*/
164-
otherContext?: ReflagContext["other"];
164+
otherContext?: Record<string, string | number | undefined>;
165165
};
166166

167167
/**

‎packages/vue-sdk/test/context-update-types.ts‎

Lines changed: 0 additions & 57 deletions
This file was deleted.

‎packages/vue-sdk/tsconfig.type-tests.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
"@reflag/vue-sdk": ["./src/index.ts"]
88
}
99
},
10-
"include": ["src", "test/opt-in-types.ts", "test/context-update-types.ts"]
10+
"include": ["src", "test/opt-in-types.ts"]
1111
}

0 commit comments

Comments
 (0)