@appconfiger/core
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

idempotender core

This is the javascript library for fetching configurations from AWS AppConfig.

TODO: add timeout waiting for fetch app config

Usage

Example: Check if feature flag is enabled

  • Create function
import appconfiger from '@appconfiger/core';

const asession = await appconfiger({
  applicationId: "tifgo2h",
  configurationProfileId: "dy2ta4b",
  environmentId: "olevrb8",
  ttl: 300,
});

function sumNumbers(value1: number, value2 number): number {

  if(asession.featureFlagEnabled('use-new-strategy')) {
    console.log('This is the NEW strategy!');
    return value1 + value2;
  }

  console.log('This is the OLD strategy!');
  return value2 + value1;
}

Example: Get custom configuration contents

  • This will make the function always add a certain value defined in the attributes of a feature flag as a configurable tweak to the summing function.

  • Create function

import { startAppConfiger } from '@appconfiger/core';

const asession = await startAppConfiger({
  applicationId: "tifgo2h",
  configurationProfileId: "dy2ta4b",
  environmentId: "olevrb8",
  pollingInterval: 300,
});

function sumNumbers(value1: number, value2 number): number {
  const customTweaks = asession.featureFlag('custom-tweaks');
  if(customTweaks.enabled) {
    return value1 + value2 + customTweaks.alwaysAdd;
  }
  return value2 + value1;
}

Reference

  • Config attributes:

    • applicationId

      • ApplicationIdentifier as in AWS AppConfig. Required
    • configurationProfileId

      • ConfigurationProfileIdentifier as in AWS AppConfig. Required
    • environmentId

      • EnvironmentId as in AWS AppConfig. Required
    • pollingInterval

      • Time in seconds for polling for new configuration updates

      • In the meanwhile a cached version of the configuration is returned

      • Defaults to 300

Functions

  • featureFlag(name:string)

    • Returns the feature flag contents, or null, if it doesn't exist.

    • All feature flags have the attribute enabled and if you defined custom attributes to it, you can access them in the returned object.

  • featureFlagEnabled(name:string)

    • Returns true if feature flag exists and is enabled.

    • Returns false if feature flag is disabled or if it doesn't exist.

  • contents()

    • Returns the raw configuration profile contents with attribute contentType and configuration.

      • If contentType is "application/json", configuration attribute is automatically parsed to a javascript object
    • In case configurationProfileId is of type Feature Flag, it will return all feature flags along with all its attributes.

    • If its FreeForm, the raw contents will be returned (maybe a JSON object, yml or plain text).

Readme

Keywords

none

Package Sidebar

Install

npm i @appconfiger/core

Weekly Downloads

1

Version

0.0.3

License

MIT

Unpacked Size

747 kB

Total Files

6

Last publish

Collaborators

  • flaviostutz