{"id":20926102,"url":"https://github.com/starhoshi/mission-completed","last_synced_at":"2025-07-13T15:37:03.375Z","repository":{"id":57298358,"uuid":"121093361","full_name":"starhoshi/mission-completed","owner":"starhoshi","description":"Stop processing even if Cloud Functions fires multiple times.","archived":false,"fork":false,"pushed_at":"2018-04-04T07:37:32.000Z","size":363,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-02T04:34:55.456Z","etag":null,"topics":["cloudfunctions","firebase","firestore","javascript","npm","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/starhoshi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-11T06:33:00.000Z","updated_at":"2020-01-10T09:59:15.000Z","dependencies_parsed_at":"2022-09-06T03:31:15.373Z","dependency_job_id":null,"html_url":"https://github.com/starhoshi/mission-completed","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/starhoshi%2Fmission-completed","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/starhoshi%2Fmission-completed/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/starhoshi%2Fmission-completed/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/starhoshi%2Fmission-completed/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/starhoshi","download_url":"https://codeload.github.com/starhoshi/mission-completed/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253859571,"owners_count":21975130,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloudfunctions","firebase","firestore","javascript","npm","typescript"],"created_at":"2024-11-18T20:36:48.226Z","updated_at":"2025-05-13T17:33:21.104Z","avatar_url":"https://github.com/starhoshi.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/starhoshi/mission-completed/master/docs/logo.png\" /\u003e\n\u003c/p\u003e\n\n# mission-completed\n\n[![npm version](https://badge.fury.io/js/mission-completed.svg)](https://badge.fury.io/js/mission-completed)\n[![Build Status](https://travis-ci.org/starhoshi/mission-completed.svg?branch=master)](https://travis-ci.org/starhoshi/mission-completed)\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/bb251ccd81c148cda6cf7322da394e3a)](https://www.codacy.com/app/kensuke1751/mission-completed?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=starhoshi/mission-completed\u0026amp;utm_campaign=Badge_Grade)\n[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)\n\n\u003e Note: Trigger events are delivered at least once, which means that rarely, spurious duplicates may occur.\n\u003e https://cloud.google.com/functions/docs/concepts/events-triggers#triggers\n\nCloud Functions rarely fire multiple times.\nIf __multiple payment occurs__, it is a big problem!!\n\nmission-completed uses __transactions__ to prevent multiple trigger events.\n\nIf you try to set the completed flag to true many times, CompletedError will be returned.\n\n```ts\nawait Mission.markCompleted(ref, id) // first: success\nawait Mission.markCompleted(ref, id) // second: throw CompletedError\n```\n\nResults are saved like this.\n\n\u003cimg src=\"https://raw.githubusercontent.com/starhoshi/mission-completed/master/docs/result.png\" width='70%' /\u003e\n\n## Install\n\n```\nyarn install mission-completed\n```\n\n## Usage\n\nThis sample is written in TypeScript.\n\n### 1. Initialize\n\nInitialize event-response in your index.ts.\n\n```ts\nimport * as Mission from 'mission-completed'\nimport * as functions from 'firebase-functions'\n\nMission.initialize(functions.config().firebase)\n```\n\n### 2. mark completed in Cloud Functions\n\nIf mission has already been completed, throw CompletedError in `Mission.markCompleted(event.data.ref, 'updateUser')`.\n\n```ts\nexports.updateUser = functions.firestore.document('users/{userId}')\n  .onCreate(async event =\u003e {\n    try {\n      await Mission.markCompleted(event.data.ref, 'updateUser')\n    } catch (error) {\n      if (error.constructor === Mission.CompletedError) {\n        console.error(error, 'Mission has already been completed.')\n        return Promise.reject(error)\n      }\n    }\n\n    await event.data.ref.update({updated: true})\n\n    return undefined\n})\n```\n\nThis will continue the initial process, but the simultaneous firing process will stop with CompletedError.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstarhoshi%2Fmission-completed","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstarhoshi%2Fmission-completed","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstarhoshi%2Fmission-completed/lists"}