@daflan/keyward-core
v0.0.9
Published
Platform-agnostic types and key registry for Keyward
Readme
@daflan/keyward-core
Platform-agnostic types and key registry for Keyward. This package contains the shared foundation used by all platform implementations.
Install
yarn add @daflan/keyward-coreMost users should install a platform package (@daflan/keyward-platform-web, @daflan/keyward-capacitor) instead. This package is for building custom integrations or platform backends.
What's Inside
Scopeenum:User,Device,GlobalStorageKeyDefinterface:{ key: string, scope: Scope }KeywardBackendinterface: storage engine contract (get/set/remove/keys/clear)KeyRegistryclass: resolves scoped keys to prefixed strings
Usage
import { Scope, KeyRegistry } from '@daflan/keyward-core';
import type { StorageKeyDef } from '@daflan/keyward-core';
const registry = new KeyRegistry();
registry.setUserId('user_507f1f');
const keyDef: StorageKeyDef = { key: 'auth_token', scope: Scope.User };
registry.resolve(keyDef); // => "u/user_507f1f/auth_token"
const deviceKey: StorageKeyDef = { key: 'install_id', scope: Scope.Device };
registry.resolve(deviceKey); // => "d/install_id"
const globalKey: StorageKeyDef = { key: 'language', scope: Scope.Global };
registry.resolve(globalKey); // => "language"