0.1.5 • Published 4 months ago

@eoussama/firemitt v0.1.5

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
4 months ago

Description

Firemitt is an intermediate package designed to simplify and streamline the integration process with Fireguard (A firebase middleman app). It offers a suite of helper methods and classes to manage configurations, events, and authentication in a more efficient and less error-prone way. This package is particularly useful for developers working with Fireguard authentication processes and event handling in web applications. Specifially ones under the manifest v3 restrictions.

Features

  • Simplified Authentication: The FiremittHelper.auth method abstracts the complexities of authentication, making it straightforward to implement.
  • Event Management: Leverage EventHelper to send and receive custom events.
  • Dynamic Configuration: ConfigHelper dynamically configures and validates settings for Fireguard integration.

Installation

npm install firemitt

Usage

Authentication

The FiremittHelper.auth method is the cornerstone of the Firemitt package. It facilitates authentication by opening a new window and handling the authentication process, including success and error handling.

Here's a basic example of how to use it:

import { FiremittHelper } from 'firemitt';

const options = {

  // You can use either this or replace the URL with a self-hosted Fireguard instance.
  url: 'https://ouss.es/fireguard',
  
  // Optional
  pos: {
    y: 50,
    x: (window.screen.width / 2) - 500
  },
  
  // Optional
  dim: {
    width: 450,
    height: 260
  },

  fireguard: {
    name: 'My App Name',

    // Optional
    logo: 'https://url/to/your/logo/image',

    // Optional
    theme: {
      text: 'grey',
      primary: '#ee16cc',
      secondary: '#ff12ee'
    }
    
    // Your web app's Firebase configuration
    firebase: {
      appId: '',
      apiKey: '',
      projectId: '',
      authDomain: '',
      measurementId: '',
      storageBucket: '',
      messagingSenderId: ''
    }
  }
}

FiremittHelper.auth(options)
  .then(token => {
    console.log('Authentication successful!', token);
  })
  .catch(error => {
    console.error('Authentication failed:', error);
  });

This method will open a new window pointing to the URL specified in the options. It listens for authentication success or failure events and resolves or rejects the promise accordingly.

You can use the URL in the example above or place the URL for your self-hosted Fireguard instance.

Configuration

Firemitt allows you to pass configurations that allows you to customize Fireguard further.

TFiremittOptions

PropertyTypeDescription
urlstringThe URL of the Fireguard instance.
posPartial<TPos>Optional, partial position configuration.
dimPartial<TDim>Optional, partial dimension configuration.
configPartial<TFireguardOptions>Optional, partial Fireguard configuration.

TDim

PropertyTypeDescription
widthnumberThe width dimension of the popup window in pixels.
heightnumberThe height dimension of the popup window in pixels.

TPos

PropertyTypeDescription
xnumberThe x-coordinate of the popup window.
ynumberThe y-coordinate of the popup window.

TFireguardOptions

PropertyTypeDescription
namestringThe name of your application.
firebaseTFirebaseConfigYour Firebase configuration.
themePartial<TTheme>Optional theme settings.

TTheme

PropertyTypeDescription
textstringThe color used for text elements.
primarystringThe primary color of the theme.
secondarystringThe secondary color of the theme.

TFirebaseConfig

PropertyTypeDescription
appIdstringThe unique identifier for the Firebase application.
apiKeystringThe API key used for authenticating requests from the app.
projectIdstringThe globally unique identifier for the Firebase project.
authDomainstringThe domain used for Firebase Authentication.
measurementIdstringThe identifier for Google Analytics for Firebase.
storageBucketstringThe Google Cloud Storage bucket for Firebase Storage.
messagingSenderIdstringThe sender ID for Firebase Cloud Messaging.

You can read more in details in the docs.

Contributing

Contributions to Firemitt are always welcome. Please read our contributing guidelines and code of conduct before making a pull request.

0.1.5

4 months ago

0.1.4

4 months ago

0.1.1

4 months ago

0.1.0

4 months ago