0.0.0-beta.10 • Published 9 months ago

statsig-on-prem v0.0.0-beta.10

Weekly downloads
-
License
ISC
Repository
-
Last release
9 months ago

Statsig On-Premise (beta)

An on-premise solution for managing Statsig configs independently from Statsig Console.

Example: Bootstrap

Bootstrap Statsig SDK using Statsig on-prem to generate a specs JSON

import { StatsigOnPrem, StatsigStorageExample } from "statsig-on-prem";
import StatsigSDK from "statsig-node";

const storage = new StatsigStorageExample();
const statsig = new StatsigOnPrem(storage);
const sdkKey = "secret-key";

await statsig.initialize();
await statsig.registerSDKKey(sdkKey);
await statsig.createGate("test-gate", { enabled: true });

const configSpecs = await statsig.getConfigSpecs(sdkKey);
await StatsigSDK.initialize(sdkKey, {
  bootstrapValues: JSON.stringify(configSpecs),
});

StatsigSDK.checkGateSync({ userID: "123" }, "test-gate"));
StatsigSDK.shutdown();

Example: Data Adapter

Incorporate Statsig on-prem with a data adapter to serve updates to the Statsig SDK

import { StatsigOnPrem, StatsigStorageExample } from "statsig-on-prem";
import StatsigSDK, { IDataAdapter, AdapterResponse, DataAdapterKey } from "statsig-node";

class ExampleDataAdapter implements IDataAdapter {
  public constructor(private statsigOnPrem: StatsigOnPrem, private sdkKey: string) {}

  public async get(key: string): Promise<AdapterResponse> {
    if (key === DataAdapterKey.Rulesets) {
      return { result: JSON.stringify(statsigOnPrem.getConfigSpecs(this.sdkKey)) };
    } else if (key === DataAdapterKey.IDLists {
      return { error: new Error("ID Lists not supported") };
    } else {
      return { error: new Error("Should never occur");
    }
  }

  public supportsPollingUpdatesFor(key: string): boolean {
    if (key === DataAdapterKey.Rulesets) {
      return true;
    } else {
      return false;
    }
  }

  public async set(
    key: string,
    value: string,
    time?: number | undefined
  ): Promise<void> { /* no-op */ }

  public async initialize(): Promise<void> { /* no-op */ }

  public async shutdown(): Promise<void> { /* no-op */ }
}

const storage = new StatsigStorageExample();
const statsig = new StatsigOnPrem(storage);
const sdkKey = "secret-key";

await statsig.initialize();
await statsig.registerSDKKey(sdkKey);
await statsig.createGate("test-gate", { enabled: true });

await StatsigSDK.initialize(sdkKey, {
  dataAdapter: new ExampleDataAdapter(statsig, sdkKey),
});

StatsigSDK.checkGateSync({ userID: "123" }, "test-gate"));
StatsigSDK.shutdown();
0.0.0-beta.17

9 months ago

0.0.0-beta.18

9 months ago

0.0.0-beta.16

9 months ago

0.0.0-beta.15

9 months ago

0.0.0-beta.14

9 months ago

0.0.0-beta.11

10 months ago

0.0.0-beta.10

10 months ago

0.0.0-beta.13

10 months ago

0.0.0-beta.12

10 months ago

0.0.0-beta.9

12 months ago

0.0.0-beta.8

1 year ago

0.0.0-beta.7

1 year ago

0.0.0-beta.5

1 year ago

0.0.0-beta.6

1 year ago

0.0.0-beta.4

2 years ago

0.0.0-beta.3

2 years ago

0.0.0-beta.2

2 years ago

0.0.0-beta.1

2 years ago

0.0.0-beta.0

2 years ago