Files
indee-demo/backend/README.md
Dorian 023653eec5 docs: update README and improve zap handling in webhooks and services
- Added a production checklist for Zaps (Lightning) in README.md, detailing necessary steps for historic zap visibility.
- Enhanced comments in webhooks.service.ts to clarify zap handling and webhook requirements for BTCPay Server.
- Improved logging in zaps.service.ts to provide more detailed information on zap payouts and recorded stats.
- Updated error handling in zaps.service.ts to ensure robust logging if zap stats recording fails.
- Refined getZapStats method in indeehub-api.service.ts to clarify mock data usage in development.

These changes improve documentation and enhance the handling of zap-related functionalities across the application.
2026-02-14 16:35:21 +00:00

286 lines
6.7 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
![](/.swm/images/IH-banner.png)
# What is indeehub-api?
`indeehub-api` is the IndeeHub API Backend repository.\
What stories will you tell? 
# Table of Contents
- [Quickstart Guides](#quickstart-guides)
- [MacOS Quickstart](#macos-quickstart)
- [Linux (Unix) Quickstart](#linux-unix-quickstart)
- [Windows Quickstart](#windows-quickstart)
- [Overview](#overview)
- [Requirements](#requirements)
- [Devtool dependencies](#devtool-dependencies)
- [Installed packages](#installed-packages)
- [Running the API](#running-the-api)
- [Recommended VSCode Extensions](#recommended-vscode-extensions)
- [Running DB Migrations](#running-db-migrations)
- [Running Stripe Webhooks locally](#running-stripe-webhooks-locally)
- [SonarQube](#sonarqube)
# Quickstart Guides
## MacOS Quickstart
### Install NVM
```zsh
brew update
brew install nvm
mkdir ~/.nvm
echo "export NVM_DIR=~/.nvm\nsource \$(brew --prefix nvm)/nvm.sh" >> .zshrc
source ~/.zshrc
```
### Install dependencies
```zsh
nvm install # this will install the node version set in .nvmrc (lts/hydrogen)
npm i
cp .env.example .env # Add the environment variables
```
## Linux (Unix) Quickstart
### Install NVM
```bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
```
### Install dependencies
```bash
nvm install # this will install the node version set in .nvmrc (lts/hydrogen)
npm i
cp .env.example .env # And add the environment variables
```
## Windows Quickstart
To avoid EOL and other Windows-related issues, we recommend installing WSL 2 and running the repository on a Linux distro of your choice.
Follow this guide to install WSL: [https://learn.microsoft.com/en-us/windows/wsl/install](https://github.com/IndeeHub/indeehub-frontend/tree/main#macos-quickstart)                    
## Overview
- **TypeScript**: A typed superset of JavaScript designed with large-scale applications in mind.
- **ESLint**: Static code analysis to help find problems within a codebase.
- **Prettier**: An opinionated code formatted.
- **Nest.js**: A progressive Node.js framework for building efficient, reliable, and scalable server-side applications.
- **Swagger**: A tool that helps design, build, document, and consume RESTful Web services.
- **TypeORM**: An ORM that can run in NodeJS and can be used with TypeScript.
- **Cypress**: End-to-end testing framework for web applications.
- **Commitizen**: Conventional commit messages CLI.
### **Requirements**
- **NodeJS 18+**
- **npm (or equivalent)**
Notes:
- We recommend the use of Commitizen to use conventional commit messages and linting before commits.
### **Devtool dependencies**
- **Cypress**: End-to-end testing framework for web applications.
### Installed Packages
- @aws-sdk/client-s3
- @nestjs/common
- @nestjs/config
- @nestjs/core
- @nestjs/passport
- @nestjs/platform-express
- @nestjs/schedule
- @nestjs/swagger
- @nestjs/typeorm
- @sendgrid/mail
- @smithy/hash-node
- @smithy/protocol-http
- @zbd/node
- amazon-cognito-identity-js
- aws-jwt-verify
- axios
- class-transformer
- class-validator
- jwks-rsa
- moment
- passport
- passport-jwt
- pg
- reflect-metadata
- rxjs
- stripe
- typeorm
- typeorm-naming-strategies
**DevDependencies**
- @nestjs/cli
- @nestjs/schematics
- @nestjs/testing
- @types/express
- @types/jest
- @types/node
- @types/supertest
- @typescript-eslint/eslint-plugin
- @typescript-eslint/parser
- eslint
- eslint-config-prettier
- eslint-plugin-prettier
- jest
- prettier
- source-map-support
- supertest
- ts-jest
- ts-loader
- ts-node
- tsconfig-paths
- typescript
 
# **Running the API**
```bash
npm run start:dev
# Or if you want to use the debug tool
npm run start:debug
```
# Running DB Migrations
```bash
npm run build
npm run typeorm:generate-migration --name=add-your-migration-name # will generate it based on the differences between the entities and the DB Schema
npm run typeorm:create-migration --name=add-your-migration-name # will create a blank migration
npm run build # after you finish the migrations
npm run typeorm:run-migrations # will apply the migrations to the current DB
```
# Zaps (Lightning) production checklist
For historic zaps to show on film cards and in the movie modal:
1. **Migrations** The `zap_stats` table is created by migration `1762000000000-add-zap-stats`. The Dockerfile runs migrations on startup; if you deploy without Docker, run `npm run typeorm:run-migrations` once.
2. **BTCPay webhook** In BTCPay Server: Store → Webhooks → Add webhook. Set the URL to `https://your-domain/api/webhooks/btcpay` (or `/api/webhooks/btcpay-webhook`). Subscribe to **Invoice settled**. Without this, zap payments are not recorded.
3. **Backend logs** After a zap is paid you should see: `Zap payout completed: <invoiceId> — stats recorded for project <projectId>` and `Zap stats saved: project <id> total N zaps, M sats`. If you see `Failed to record zap stats`, check that the `zap_stats` table exists.
4. **API** `GET /zaps/stats?projectIds=id1,id2` must be reachable (e.g. `https://your-domain/api/zaps/stats?projectIds=...`). It is not cached and does not require auth.
&nbsp;
# Running Stripe Webhooks locally
## Installing Stripe CLI
### MacOS
```zsh
brew install stripe/stripe-cli/stripe
```
### Windows
```bash
scoop bucket add stripe https://github.com/stripe/scoop-stripe-cli.git
scoop install stripe
```
### Linux
```bash
curl -s https://packages.stripe.dev/api/security/keypair/stripe-cli-gpg/public | gpg --dearmor | sudo tee /usr/share/keyrings/stripe.gpg
echo "deb [signed-by=/usr/share/keyrings/stripe.gpg] https://packages.stripe.dev/stripe-cli-debian-local stable main" | sudo tee -a /etc/apt/sources.list.d/stripe.list
sudo apt update
sudo apt install stripe
```
## Log in to CLI
```bash
stripe login
Your pairing code is: enjoy-enough-outwit-win
This pairing code verifies your authentication with Stripe.
Press Enter to open the browser or visit https://dashboard.stripe.com/stripecli/confirm_auth?t=THQdJfL3x12udFkNorJL8OF1iFlN8Az1
```
## Start webhook listener
```
stripe listen --forward-to localhost:4242/webhook
```
It will output your endpoint secret, and add it to the .env file.
# SonarQube
[![Quality gate](https://sonarqube.indeehub.studio/api/project_badges/quality_gate?project=IndeeHub_indeehub-api_53ec3bbb-4a99-40e6-9de4-ae1acf6b125d&token=sqb_b1e2bd689935a9954f40e4b584689c226f741f3e)](https://sonarqube.indeehub.studio/dashboard?id=IndeeHub_indeehub-api_53ec3bbb-4a99-40e6-9de4-ae1acf6b125d)