# @discue/idempotent-firebase-functions

> Implementation of idempotent functions for firebase to prevent duplicate execution of events.

Latest version **0.2.0** (published 2023-06-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install @discue/idempotent-firebase-functions
pnpm add @discue/idempotent-firebase-functions
yarn add @discue/idempotent-firebase-functions
bun add @discue/idempotent-firebase-functions
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2023-06-10 |
| First published | 2023-06-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 10.2 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | Stefan Pfaffel |
| Maintainers | stfsy |
| Keywords | firebase, functions, google, gcp, idempotent, idempotency |

## Links

- npm: https://www.npmjs.com/package/@discue/idempotent-firebase-functions
- Repository: https://github.com/discue/idempotent-firebase-functions
- Homepage: https://github.com/discue/idempotent-firebase-functions#readme
- Issues: https://github.com/discue/idempotent-firebase-functions/issues
- npm.io page: https://npm.io/package/@discue/idempotent-firebase-functions

## Dependencies (2)

- [firebase-admin](https://npm.io/package/firebase-admin.md) ^11.9.0
- [firebase-tools](https://npm.io/package/firebase-tools.md) ^12.3.1

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.2.0 (latest) — 2023-06-10
- 0.1.0 — 2023-06-10

## README

<p align="center">
<a href="https://www.discue.io/" target="_blank" rel="noopener noreferrer"><img width="128" src="https://www.discue.io/icons-fire-no-badge-square/web/icon-192.png" alt="Vue logo">
</a>
</p>

<br/>
<div align="center">

[![GitHub tag](https://img.shields.io/github/tag/@discue/idempotent-firebase-functions?include_prereleases=&sort=semver&color=blue)](https://github.com/@discue/idempotent-firebase-functions/releases/)
[![Latest Stable Version](https://img.shields.io/npm/v/@discue/idempotent-firebase-functions.svg)](https://www.npmjs.com/package/@discue/idempotent-firebase-functions)
[![License](https://img.shields.io/npm/l/@discue/idempotent-firebase-functions.svg)](https://www.npmjs.com/package/@discue/idempotent-firebase-functions)
<br/>
[![NPM Downloads](https://img.shields.io/npm/dt/@discue/idempotent-firebase-functions.svg)](https://www.npmjs.com/package/@discue/idempotent-firebase-functions)
[![NPM Downloads](https://img.shields.io/npm/dm/@discue/idempotent-firebase-functions.svg)](https://www.npmjs.com/package/@discue/idempotent-firebase-functions)
<br/>
[![contributions - welcome](https://img.shields.io/badge/contributions-welcome-blue)](/CONTRIBUTING.md "Go to contributions doc")
[![Made with Node.js](https://img.shields.io/badge/Node.js->=12-blue?logo=node.js&logoColor=white)](https://nodejs.org "Go to Node.js homepage")

</div>

# idempotent-firebase-functions

Because firebase does not guarentee firestore events get [triggered only once](https://cloud.google.com/functions/docs/calling/cloud-firestore#limitations), we need to ensure idempotency ourselves. This module provides helper functions to create [idempotent functions](https://cloud.google.com/blog/products/serverless/cloud-functions-pro-tips-building-idempotent-functions) easily. 

## Components
- [Function Lease](README_IDEMPOTENT_FUNCTION_LEASE.md)
- [Idempotent Function](README_IDEMPOTENT_FUNCTIONS.md)

## Example
### Examples

```javascript
import { onDocumentWritten } from 'firebase-functions/v2/firestore';
import { idempotentFunction } from '@discue/idempotent-firebase-functions';
import handler from './handler.js'

const DOCUMENT_PATH = 'api_clients/{apiClientId}/queues/{queueId}/messages/{messageId}'
// handler function will only be called once per firebase event id
// effectively making it an idempotent function
export const written = onDocumentWritten(DOCUMENT_PATH, idempotentFunction(handler))
```

## Installation
```bash
npm install @discue/idempotent-firebase-functions
```

## Run E2E Tests

To run tests, run the following command

```bash
./test-e2e.sh
```

## License

[MIT](https://choosealicense.com/licenses/mit/)

---
_Source: https://npm.io/package/@discue/idempotent-firebase-functions · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
