Skip to content

Commit 53b1172

Browse files
authored
Accept IUser instead of User in the public API (#80)
* Accept IUser instead of User in the public API * Bump version
1 parent fc86e1f commit 53b1172

File tree

8 files changed

+21
-21
lines changed

8 files changed

+21
-21
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "configcat-react",
3-
"version": "5.0.2",
3+
"version": "5.0.3",
44
"scripts": {
55
"build": "npm run build:esm && npm run build:cjs",
66
"build:esm": "tsc -p tsconfig.build.esm.json && gulp esm",

sandbox/src/stories/Hoc.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import React, { useState } from 'react';
2-
import { ConfigCatProvider, LogLevel, withConfigCatClient, type WithConfigCatClientProps, User } from 'configcat-react';
2+
import { ConfigCatProvider, LogLevel, withConfigCatClient, type WithConfigCatClientProps, type IUser } from 'configcat-react';
33

44

55
export class HocComponent extends React.Component<
6-
{ featureFlagKey: string, user?: User } & WithConfigCatClientProps,
6+
{ featureFlagKey: string, user?: IUser } & WithConfigCatClientProps,
77
{ isEnabled: boolean, loading: boolean }
88
> {
9-
constructor(props: { featureFlagKey: string, user?: User } & WithConfigCatClientProps) {
9+
constructor(props: { featureFlagKey: string, user?: IUser } & WithConfigCatClientProps) {
1010
super(props);
1111

1212
this.state = { isEnabled: false, loading: true };

sandbox/src/stories/Hook.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { useCallback, useState } from 'react';
2-
import { useConfigCatClient, useFeatureFlag, ConfigCatProvider, LogLevel, User } from 'configcat-react';
2+
import { useConfigCatClient, useFeatureFlag, ConfigCatProvider, LogLevel, type IUser } from 'configcat-react';
33

44
export const HookComponent = (args: { featureFlagKey: string }) => {
55
const client = useConfigCatClient();
6-
const userObject = new User('asdad121212sd');
6+
const userObject: IUser = { identifier: 'asdad121212sd' };
77
const { value: isFeatureEnabled, loading } = useFeatureFlag(args.featureFlagKey, false, userObject);
88

99
return (

sandbox/src/stories/MultipleConfigCatConfigs.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ConfigCatProvider, useFeatureFlag, User, withConfigCatClient } from 'configcat-react';
1+
import { ConfigCatProvider, useFeatureFlag, withConfigCatClient, type IUser } from 'configcat-react';
22
import { HocComponent} from './Hoc';
33

44

@@ -9,7 +9,7 @@ const CC_SDK = {
99
SHARED:"TODO - INSERT SDKKEY"
1010
};
1111

12-
const userObject = new User('microFrontendUser1');
12+
const userObject: IUser = { identifier: 'microFrontendUser1' };
1313

1414
export const C1 = (args: { featureFlagKey: string, providerId: string }) => {
1515

src/ConfigCatHOC.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
"use client";
22

3-
import type { IConfigCatClient, SettingTypeOf, SettingValue, User } from "@configcat/sdk";
3+
import type { IConfigCatClient, SettingTypeOf, SettingValue, IUser } from "@configcat/sdk";
44
import React from "react";
55
import { type ConfigCatContextData, getConfigCatContext } from "./ConfigCatContext";
66
import { createConfigCatProviderError } from "./ConfigCatProvider";
77

88
export type GetValueType = <T extends SettingValue>(
99
key: string,
1010
defaultValue: T,
11-
user?: User
11+
user?: IUser
1212
) => Promise<SettingTypeOf<T>>;
1313

1414
const getValueFunction = (client: IConfigCatClient) => {
15-
return async function <T extends SettingValue>(key: string, defaultValue: T, user?: User) {
15+
return async function <T extends SettingValue>(key: string, defaultValue: T, user?: IUser) {
1616
return await client.getValueAsync(key, defaultValue, user);
1717
};
1818
};

src/ConfigCatHooks.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"use client";
22

3-
import type { IConfigCatClient, SettingTypeOf, SettingValue, User } from "@configcat/sdk";
3+
import type { IConfigCatClient, SettingTypeOf, SettingValue, IUser } from "@configcat/sdk";
44
import { useContext, useEffect, useState } from "react";
55
import { getConfigCatContext } from "./ConfigCatContext";
66
import { createConfigCatProviderError } from "./ConfigCatProvider";
77

8-
function useFeatureFlag<T extends SettingValue>(key: string, defaultValue: T, user?: User, providerId?: string): {
8+
function useFeatureFlag<T extends SettingValue>(key: string, defaultValue: T, user?: IUser, providerId?: string): {
99
value: SettingTypeOf<T>;
1010
loading: boolean;
1111
} {

src/ConfigCatProvider.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import type { ClientCacheState, Config, EvaluationDetails, HookEvents, IAutoPollOptions, IConfigCatClient, IConfigCatClientSnapshot, ILazyLoadingOptions, IManualPollOptions, RefreshResult, SettingKeyValue, SettingTypeOf, SettingValue, User } from "@configcat/sdk";
3+
import type { ClientCacheState, Config, EvaluationDetails, HookEvents, IAutoPollOptions, IConfigCatClient, IConfigCatClientSnapshot, ILazyLoadingOptions, IManualPollOptions, IUser, RefreshResult, SettingKeyValue, SettingTypeOf, SettingValue } from "@configcat/sdk";
44
import { Internals, LocalStorageConfigCache, PollingMode, XmlHttpRequestConfigFetcher } from "@configcat/sdk";
55
import React, { Component, type PropsWithChildren } from "react";
66
import { type ConfigCatContextData, ensureConfigCatContext } from "./ConfigCatContext";
@@ -124,19 +124,19 @@ export function createConfigCatProviderError(methodName: string, providerId?: st
124124
class ConfigCatClientStub implements IConfigCatClient {
125125
readonly isOffline = true;
126126

127-
getValueAsync<T extends SettingValue>(_key: string, _defaultValue: T, _user?: User): Promise<SettingTypeOf<T>> {
127+
getValueAsync<T extends SettingValue>(_key: string, _defaultValue: T, _user?: IUser): Promise<SettingTypeOf<T>> {
128128
throw serverContextNotSupported();
129129
}
130-
getValueDetailsAsync<T extends SettingValue>(_key: string, _defaultValue: T, _user?: User): Promise<EvaluationDetails<SettingTypeOf<T>>> {
130+
getValueDetailsAsync<T extends SettingValue>(_key: string, _defaultValue: T, _user?: IUser): Promise<EvaluationDetails<SettingTypeOf<T>>> {
131131
throw serverContextNotSupported();
132132
}
133133
getAllKeysAsync(): Promise<string[]> {
134134
throw serverContextNotSupported();
135135
}
136-
getAllValuesAsync(_user?: User): Promise<SettingKeyValue<SettingValue>[]> {
136+
getAllValuesAsync(_user?: IUser): Promise<SettingKeyValue<SettingValue>[]> {
137137
throw serverContextNotSupported();
138138
}
139-
getAllValueDetailsAsync(_user?: User): Promise<EvaluationDetails<SettingValue>[]> {
139+
getAllValueDetailsAsync(_user?: IUser): Promise<EvaluationDetails<SettingValue>[]> {
140140
throw serverContextNotSupported();
141141
}
142142
getKeyAndValueAsync(_variationId: string): Promise<SettingKeyValue<SettingValue> | null> {
@@ -151,7 +151,7 @@ class ConfigCatClientStub implements IConfigCatClient {
151151
snapshot(): IConfigCatClientSnapshot {
152152
throw serverContextNotSupported();
153153
}
154-
setDefaultUser(_defaultUser: User): void {
154+
setDefaultUser(_defaultUser: IUser): void {
155155
throw serverContextNotSupported();
156156
}
157157
clearDefaultUser(): void {

0 commit comments

Comments
 (0)