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

Provide a lightweight and simple way to configure SDK #4

Closed
RomanReznichenko opened this issue Mar 21, 2022 · 0 comments · Fixed by #1
Closed

Provide a lightweight and simple way to configure SDK #4

RomanReznichenko opened this issue Mar 21, 2022 · 0 comments · Fixed by #1
Assignees
Labels
Type: enhancement New feature or request.

Comments

@RomanReznichenko
Copy link
Contributor

RomanReznichenko commented Mar 21, 2022

The SDK should provide a convenient way to be configured. The configuration could be passed into the client constructors. However, the configuration must be a single instance to coordinate settings across the whole library.

class Configuration {
  get container(): DependencyContainer {
    return container;
  }

  constructor() {
    this.container.register(
      Configuration,
      { useValue: this }
    );
  }
  
  // implementation
}

const configuration = new Configuration();
const configuration2 = container.resolve(Configuration);

expect(configuration2).toBe(configuration);

The configuration should use a certain number of credential providers to obtain credentials from different sources such as rc dotfiles and environment variables:

export interface Credentials {
  readonly id: string;
  readonly token: string;
}

export interface CredentialProvider {
  get(): Promise<Credentials | undefined>;
}

However, it should preserve the ability to pass an instance of Credentials manually:

class Configuration {
 constrcutor(options: { 
   // ...
   credentials?: Credentials;
   credentialProviders?: CredentialProvider[];
 }) {}
}

While using rc dotfile it should perform JSON schema validation to throw an exception if the config doesn't meet certain validation rules. It also might be helpful when we decide to provide autocomplete while using IDE or any other editor like VSCode.

Finally, the configuration should obtain the SDK version and expose this information to the client in some way. Depending on the build process we can inline this information while bundling source files or read it from the package.json.

@RomanReznichenko RomanReznichenko changed the title Add configuration module feat: add configuration module Mar 21, 2022
@derevnjuk derevnjuk changed the title feat: add configuration module Provide a lightweight and simple way to configure SDK Mar 21, 2022
@derevnjuk derevnjuk added the Type: enhancement New feature or request. label Mar 21, 2022
RomanReznichenko added a commit to RomanReznichenko/secbox-sdk-js that referenced this issue Apr 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: enhancement New feature or request.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants