0.3.0 • Published 4 years ago

@metomic/alias-core v0.3.0

Weekly downloads
1
License
-
Repository
-
Last release
4 years ago

alias-core

What is this?

Client-side (web) javascript library and UI elements that create a metomic alias for a given email.

When should I use it?

Probably only if you're writing a library that provides metomic alias functionality in your chosen framework.

For an example, see @metomic/alias-react

How do I use it?

You probably don't want to - there's likely a higher level library. But if you're sure:

importing

import {
  Alias, 
  EncryptionOverlay,
  AliasToggle
} from '@metomic/alias-core

constructing an alias (no ui)

Alias({ appId: 'zx123' }).secure("an-email@somewhere.com")
  .then( ... )

mutably binding to an input element

const run  = Alias.dom.bindToInput(appId, purpose, inputElement, (state) => {
  /* optional state-change callback here. Options:
   state = { status: 'loading' }
   state = { status: 'error', error: 'error' }
   state = { status: 'complete', result: 'alias@metomic' }
   state = { status: 'reset', result: 'original-email' }
  */
})

run(true) // performs securing action on input
run(false) // reverts securing action on input

manually managing entire flow

  const overlay = Alias.dom.createOverlayController(inputEl)
  const { doToggle } = createSecuringContext(appId, purpose, inputEl, function onStateChange(state){
    // deal with states
    overlay.setActive(state === 'loading')
  })


  doToggle(true) // triggers securing action on input
  doToggle(false) // reverts securing action on input
  
0.3.0

4 years ago