# @incognitus/client-web-core

> Incognitus core web client

Latest version **1.0.1** (published 2021-01-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install @incognitus/client-web-core
pnpm add @incognitus/client-web-core
yarn add @incognitus/client-web-core
bun add @incognitus/client-web-core
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2021-01-09 |
| First published | 2020-12-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 20.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Incognitus |
| Maintainers | stummej, incognitus-admin |
| Keywords | feature-flags, feature-toggle, feature, toggle, flags, incognitus |

## Links

- npm: https://www.npmjs.com/package/@incognitus/client-web-core
- Repository: git@github.com:Incognitus-Io/client-web-core
- Homepage: https://github.com/Incognitus-Io/client-web-core#readme
- Issues: https://github.com/Incognitus-IO/client-web-core/issues
- npm.io page: https://npm.io/package/@incognitus/client-web-core

## Recent versions

- 1.0.1 (latest) — 2021-01-09
- 1.0.1-pre.4 (next) — 2021-01-01
- 1.0.1-pre.3 — 2020-12-24
- 1.0.1-pre.1 — 2020-12-14
- 1.0.0 — 2020-12-14
- 1.0.0-pre.15 — 2020-12-14
- 0.1.1-pre.14 — 2020-12-14
- 0.1.1-pre.13 — 2020-12-14
- 0.1.1-pre.12 — 2020-12-14
- 0.1.1-pre.10 — 2020-12-14
- 0.1.1-pre.6 — 2020-12-13
- 0.1.0-pre.5 — 2020-12-13
- 0.1.0-pre.4 — 2020-12-13
- 0.1.1-pre.0 — 2020-12-13

## README

# Incognitus Feature Flag (web core)

![Continuous Integration](https://github.com/Incognitus-Io/client-web-core/workflows/Continuous%20Integration/badge.svg)
[![codecov](https://codecov.io/gh/Incognitus-Io/client-web-core/branch/master/graph/badge.svg?token=BNC9RERF0K)](https://codecov.io/gh/Incognitus-Io/client-web-core)
[![npm version](https://badge.fury.io/js/%40incognitus%2Fclient-web-core.svg)](https://badge.fury.io/js/%40incognitus%2Fclient-web-core)

## Integrating Incognitus

## Initializing the service

Before you're able to use the service you'll need to initialize with your tenant and application IDs.

#### index.ts

Initialize Incognitus service

```typescript
import { IncognitusService } from '@incognitus/client-web-core';

const IncognitusService.initialize({
  tenantId: '{your tenant key}',
  applicationId: '{your app id}',
});
```

| Key           | Description               |
| ------------- | ------------------------- |
| tenantId      | Your tenant id            |
| applicationId | The id of the application |

## Checking features

```typescript
import { IncognitusService } from '@incognitus/client-web-core';

const svc = IncognitusService.instance;

const foobar = async () => {
  if (await svc.isEnabled('{feature name}')) {
    return 'new feature text';
  }
  return 'old feature text';
};
```

## Methods

| Method                               | Description                                                 |
| ------------------------------------ | ----------------------------------------------------------- |
| IncognitusService.initialize(config) | Initializes the service (must be called first)              |
| IncognitusService.instance           | The shared instance of the service                          |
| svc.isEnabled(featureName)           | Checks if the flag is enabled                               |
| svc.isDisabled(featureName)          | Check if the flag is disabled                               |
| svc.getFeature(featureName)          | Fetches the feature from the server and returns it's status |
| svc.getAllFeatures()                 | Fetches all features and stores them in the cache           |

## Caching

Currently all known feature flags are cached when the app initializes. New features that are not found
in the cache are retrieved on-demand. The cache stays in place until the app is reloaded or by calling the `getAllFeatures()` method on the service.

### Future Caching Stories

- Save verified cache to local storage
- Provide hard cache refresh (wipe cache if fails)
- Provide soft cache refresh (keep cache if fails)
- Customizable cache refresh times
- Option to disable cache

---
_Source: https://npm.io/package/@incognitus/client-web-core · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
