npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@qte/nest-firebase-chat

v1.7.3

Published

@qte/nest-firebase-chat is a powerful NestJS module that facilitates the integration of chat functionality in your NestJS applications using Firebase Firestore.

Downloads

61

Readme

@qte/nest-firebase-chat

@qte/nest-firebase-chat is a powerful NestJS module that facilitates the integration of chat functionality in your NestJS applications using Firebase Firestore.

Prerequisites

Before proceeding, ensure that Firestore is enabled in your Firebase project and you have created a service account with Firestore Admin permissions.

Installation

Use npm to install the module:

npm install @qte/nest-firebase-chat

How to Use

Step 1: Import the NestFirebaseChatsModule

Import the NestFirebaseChatsModule into your root module (e.g., AppModule):

import { Module } from '@nestjs/common'
import { AppController } from './app.controller'
import { AppService } from './app.service'
import { ConfigModule } from '@nestjs/config'
import { NestFirebaseChatsModule } from '@qte/nest-firebase-chat'
import config from './config/configuration'

@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal: true,
      load: [config],
    }),
    NestFirebaseChatsModule.forRootAsync({
      imports: [ConfigModule],
      useFactory: () => ({
        credentials: {
          projectId: process.env.FIREBASE_PROJECT_ID,
          clientEmail: process.env.FIREBASE_CLIENT_EMAIL,
          privateKey: process.env.FIREBASE_PRIVATE_KEY,
        },
      }),
    }),
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

Step 2: Utilize NestFirebaseChatsService

You can use the NestFirebaseChatsService within your service or controller to interact with the chat functionality:

import { Body, Controller, Param, Get } from '@nestjs/common'
import { NestFirebaseChatsService } from '@qte/nest-firebase-chat'

@Controller()
export class AppController {
  constructor(private firebaseChats: NestFirebaseChatsService) {}

  @Get('chats/:chatId')
  getChat(@Param('chatId') chatId: string) {
    return this.firebaseChats.getChat(chatId)
  }

  // Add more routes as needed
}

Firestore Collection Schema

Ensure your Firestore collection structure aligns with the following schema for the module to operate correctly.

├── users
│   └── userId
│       ├── name (string)
│       └── avatar (URL string)
└── chats
    └── chatId
        ├── creatorId (string)
        ├── creatorRef (reference to user document)
        ├── memberIds (array of references to user documents)
        ├── searchIndex (string concatenated of member names and chat name)
        ├── name (string)
        ├── lastMessage (reference to message document)
        ├── createdAt (ISO string)
        ├── updatedAt (ISO string)
        ├── members
        │     └── memberId
        │         ├── memberRef (reference to user document)
        │         └── createdAt (ISO string)
        └── messages
            └── messageId
                ├── senderId (string)
                ├── senderRef (reference to user document)
                ├── content (string)
                ├── readByIds (array of references to user documents)
                ├── createdAt (ISO string)
                ├── updatedAt (ISO string)
                └── files
                    └── fileId
                        ├── url (URL string)
                        └── createdAt (ISO string)

Features

The library provides a robust set of functions for creating a backend chat service using Firestore.

| Method Name | Input Parameters | Description | Returns | | -------------------------- | ----------------------------------------------------------------------- | -------------------------------------------------- | ---------------------------------------------- | | getChat | chatId: string | Fetches a chat by its ID | Promise<Chat & { chatId: string }> | | getChatsByUser | userId: string, take?: number, skip?: number, searchQuery?: string | Fetches a list of chats for a user with pagination | Promise<(Chat & { chatId: string })[]> | | getChatByUserCount | userId: string | Fetches the count of chats for a user | Promise<{ count: number }> | | getUnreadChatByUserCount | userId: string | Fetches the count of unread chats for a user | Promise<{ count: number }> | | createChat | userId: string, name?: string, userIds: string[] | Creates a new chat | Promise<string> | | deleteChat | chatId: string | Deletes a chat by its ID | Promise<void> | | getMessage | chatId: string, messageId: string | Fetches a message from a chat by its ID | Promise<Message & { messageId: string }> | | getMessages | chatId: string, take?: number, skip?: number | Fetches messages from a chat with pagination | Promise<(Message & { messageId: string })[]> | | getMessageCount | chatId: string | Fetches the count of messages in a chat | Promise<{ count: number }> | | sendMessage | chatId: string, userId: string, content?: string, files?: string[] | Sends a message in a chat | Promise<string> | | updateMessage | chatId: string, messageId: string, content?: string, files?: string[] | Updates a message in a chat | Promise<Message & { messageId: string }> | | markMessageAsRead | chatId: string, userId: string, messageId: string | Marks a message as read | Promise<Message & { messageId: string }> | | markMessagesAsRead | chatId: string, userId: string, messageIds: string[] | Marks multiple messages as read | Promise<(Message & { messageId: string })[]> | | deleteMessage | chatId: string, messageId: string | Deletes a message from a chat | Promise<void> | | createUser | userId: string, name: string, avatar?: string | Creates a new user | Promise<string> | | clearUser | userId: string | Clears a user's data | Promise<void> | | addUserToChat | chatId: string, userId: string | Adds a user to a chat | Promise<Chat & { chatId: string }> | | addUsersToChat | chatId: string, userIds: string[] | Adds multiple users to a chat | Promise<Chat & { chatId: string }> | | removeUserFromChat | chatId: string, userId: string | Removes a user from a chat | Promise<Chat & { chatId: string }> | | removeUsersFromChat | chatId: string, userIds: string[] | Removes multiple users from a chat | Promise<Chat & { chatId: string }> |

License

This module is licensed under the MIT License.

Issues

If you encounter any problems or have feature suggestions, please create an issue.


Get started with integrating Firebase Firestore chat into your NestJS application with @qte/nest-firebase-chat. Happy coding!