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: optional config object for topic, auth, storage, leaderboard clients #1442

Merged
merged 1 commit into from
Oct 7, 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
16 changes: 14 additions & 2 deletions packages/client-sdk-nodejs/src/auth-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,28 @@ import {AbstractAuthClient} from '@gomomento/sdk-core/dist/src/internal/clients/
import {AuthClientProps} from './auth-client-props';
import {AuthClientAllProps} from './internal/auth-client-all-props';
import {getDefaultCredentialProvider} from '@gomomento/sdk-core';
import {AuthClientConfiguration, AuthClientConfigurations} from '.';

export class AuthClient extends AbstractAuthClient implements IAuthClient {
constructor(props: AuthClientProps) {
constructor(props?: AuthClientProps) {
const allProps: AuthClientAllProps = {
...props,
configuration:
props?.configuration ?? getDefaultAuthClientConfiguration(),
credentialProvider:
props.credentialProvider ?? getDefaultCredentialProvider(),
props?.credentialProvider ?? getDefaultCredentialProvider(),
};
const authClient = new InternalAuthClient(allProps);

super({createAuthClient: () => authClient});
}
}

function getDefaultAuthClientConfiguration(): AuthClientConfiguration {
const config = AuthClientConfigurations.Default.latest();
const logger = config.getLoggerFactory().getLogger('AuthClient');
logger.info(
'No configuration provided to AuthClient. Using latest "Default" configuration, suitable for development. For production use, consider specifying an explicit configuration.'
);
return config;
}
13 changes: 9 additions & 4 deletions packages/client-sdk-nodejs/src/preview-leaderboard-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ export class PreviewLeaderboardClient implements ILeaderboardClient {
private readonly dataClient: ILeaderboardDataClient;
private readonly configuration: LeaderboardConfiguration;

constructor(props: LeaderboardClientProps) {
constructor(props?: LeaderboardClientProps) {
const configuration =
props.configuration ?? getDefaultLeaderboardConfiguration();
props?.configuration ?? getDefaultLeaderboardConfiguration();
const allProps: LeaderboardClientAllProps = {
configuration: configuration,
credentialProvider:
props.credentialProvider ?? getDefaultCredentialProvider(),
props?.credentialProvider ?? getDefaultCredentialProvider(),
};
this.configuration = configuration;

Expand Down Expand Up @@ -70,5 +70,10 @@ export class PreviewLeaderboardClient implements ILeaderboardClient {
}

function getDefaultLeaderboardConfiguration(): LeaderboardConfiguration {
return LeaderboardConfigurations.Laptop.latest();
const config = LeaderboardConfigurations.Laptop.latest();
const logger = config.getLoggerFactory().getLogger('LeaderboardClient');
logger.info(
'No configuration provided to LeaderboardClient. Using default "Laptop" configuration, suitable for development. For production use, consider specifying an explicit configuration.'
);
return config;
}
16 changes: 11 additions & 5 deletions packages/client-sdk-nodejs/src/preview-storage-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ export class PreviewStorageClient
extends AbstractStorageClient
implements IStorageClient
{
constructor(props: StorageClientProps) {
constructor(props?: StorageClientProps) {
const allProps: StorageClientAllProps = {
configuration: props.configuration ?? getDefaultStorageConfiguration(),
configuration:
props?.configuration ?? getDefaultStorageClientConfiguration(),
credentialProvider:
props.credentialProvider ?? getDefaultCredentialProvider(),
props?.credentialProvider ?? getDefaultCredentialProvider(),
};

const controlClient: IStorageControlClient = createControlClient(allProps);
Expand All @@ -48,6 +49,11 @@ function createDataClient(props: StorageClientAllProps): IStorageDataClient {
return new StorageDataClient(props);
}

function getDefaultStorageConfiguration(): StorageConfiguration {
return StorageConfigurations.Laptop.latest();
function getDefaultStorageClientConfiguration(): StorageConfiguration {
const config = StorageConfigurations.Laptop.latest();
const logger = config.getLoggerFactory().getLogger('StorageClient');
logger.info(
'No configuration provided to StorageClient. Using default "Laptop" configuration, suitable for development. For production use, consider specifying an explicit configuration.'
);
return config;
}
13 changes: 9 additions & 4 deletions packages/client-sdk-nodejs/src/topic-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ export class TopicClient extends AbstractTopicClient {
/**
* Creates an instance of TopicClient.
*/
constructor(props: TopicClientProps) {
constructor(props?: TopicClientProps) {
const allProps: TopicClientAllProps = {
credentialProvider:
props.credentialProvider ?? getDefaultCredentialProvider(),
props?.credentialProvider ?? getDefaultCredentialProvider(),
configuration:
props.configuration ?? getDefaultTopicClientConfiguration(),
props?.configuration ?? getDefaultTopicClientConfiguration(),
};

const numClients = allProps.configuration
Expand All @@ -40,5 +40,10 @@ export class TopicClient extends AbstractTopicClient {
}

function getDefaultTopicClientConfiguration(): TopicConfiguration {
return TopicConfigurations.Default.latest();
const config = TopicConfigurations.Default.latest();
const logger = config.getLoggerFactory().getLogger('TopicClient');
logger.info(
'No configuration provided to TopicClient. Using latest "Default" configuration, suitable for development. For production use, consider specifying an explicit configuration.'
);
return config;
}
4 changes: 2 additions & 2 deletions packages/client-sdk-web/src/auth-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import {AuthClientAllProps} from './internal/auth-client-all-props';
import {getDefaultCredentialProvider} from '@gomomento/sdk-core';

export class AuthClient extends AbstractAuthClient {
constructor(props: AuthClientProps) {
constructor(props?: AuthClientProps) {
const createAuthClient = (): IAuthClient => {
const allProps: AuthClientAllProps = {
...props,
credentialProvider:
props.credentialProvider ?? getDefaultCredentialProvider(),
props?.credentialProvider ?? getDefaultCredentialProvider(),
};
return new InternalWebGrpcAuthClient(allProps);
};
Expand Down
13 changes: 9 additions & 4 deletions packages/client-sdk-web/src/preview-leaderboard-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import {LeaderboardClientAllProps} from './internal/leaderboard-client-all-props
export class PreviewLeaderboardClient implements ILeaderboardClient {
private dataClient: ILeaderboardDataClient;

constructor(props: LeaderboardClientProps) {
constructor(props?: LeaderboardClientProps) {
const allProps: LeaderboardClientAllProps = {
configuration:
props.configuration ?? getDefaultLeaderboardConfiguration(),
props?.configuration ?? getDefaultLeaderboardConfiguration(),
credentialProvider:
props.credentialProvider ?? getDefaultCredentialProvider(),
props?.credentialProvider ?? getDefaultCredentialProvider(),
};
this.dataClient = new LeaderboardDataClient(allProps);
}
Expand All @@ -46,5 +46,10 @@ export class PreviewLeaderboardClient implements ILeaderboardClient {
}

function getDefaultLeaderboardConfiguration(): LeaderboardConfiguration {
return LeaderboardConfigurations.Laptop.latest();
const config = LeaderboardConfigurations.Laptop.latest();
const logger = config.getLoggerFactory().getLogger('LeaderboardClient');
logger.info(
'No configuration provided to LeaderboardClient. Using default "Laptop" configuration, suitable for development. For production use, consider specifying an explicit configuration.'
);
return config;
}
8 changes: 4 additions & 4 deletions packages/client-sdk-web/src/preview-storage-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ export class PreviewStorageClient
{
private readonly _configuration: StorageConfiguration;

constructor(props: StorageClientProps) {
constructor(props?: StorageClientProps) {
const allProps: StorageClientAllProps = {
configuration:
props.configuration ?? getDefaultStorageClientConfiguration(),
props?.configuration ?? getDefaultStorageClientConfiguration(),
credentialProvider:
props.credentialProvider ?? getDefaultCredentialProvider(),
props?.credentialProvider ?? getDefaultCredentialProvider(),
};
const controlClient: IStorageControlClient = createControlClient(allProps);
const dataClient: IStorageDataClient = createDataClient(allProps);
Expand Down Expand Up @@ -63,7 +63,7 @@ function getDefaultStorageClientConfiguration(): StorageConfiguration {
const config = StorageConfigurations.Default.latest();
const logger = config.getLoggerFactory().getLogger('StorageClient');
logger.info(
'No configuration provided to StorageClient. Using default configuration. For production use, consider specifying an explicit configuration.'
'No configuration provided to StorageClient. Using latest "Default" configuration, suitable for development. For production use, consider specifying an explicit configuration.'
);
return config;
}
13 changes: 9 additions & 4 deletions packages/client-sdk-web/src/topic-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ export class TopicClient extends AbstractTopicClient {
/**
* Creates an instance of TopicClient.
*/
constructor(props: TopicClientProps) {
constructor(props?: TopicClientProps) {
const configuration =
props.configuration ?? getDefaultTopicClientConfiguration();
props?.configuration ?? getDefaultTopicClientConfiguration();
const allProps: TopicClientAllProps = {
configuration: configuration,
credentialProvider:
props.credentialProvider ?? getDefaultCredentialProvider(),
props?.credentialProvider ?? getDefaultCredentialProvider(),
};

super(
Expand All @@ -34,5 +34,10 @@ export class TopicClient extends AbstractTopicClient {
}

function getDefaultTopicClientConfiguration(): TopicConfiguration {
return TopicConfigurations.Default.latest();
const config = TopicConfigurations.Default.latest();
const logger = config.getLoggerFactory().getLogger('TopicClient');
logger.info(
'No configuration provided to TopicClient. Using latest "Default" configuration, suitable for development. For production use, consider specifying an explicit configuration.'
);
return config;
}
Loading