# Build an idempotency key from an event

Join a scope, a business id and a version into one stable, colon-separated key.

Canonical: https://1loc.dev/email/build-an-idempotency-key/
Version: 1.0.0
Runtime: JavaScript · Node.js 22 / modern browsers
Verification: Local fixtures; no external services
Updated: 2026-10-28

## Implementation

```javascript
function idempotencyKey({ scope, id, version }) { return [scope, id, version].map(part => encodeURIComponent(String(part))).join(':'); }
```

## Input

```json
{
  "scope": "order-confirmation",
  "id": "8812",
  "version": 1
}
```

## Expected output

```json
"order-confirmation:8812:1"
```

## Edge case

Input:
```json
{
  "scope": "welcome",
  "id": "user:42",
  "version": 2
}
```
Output:
```json
"welcome:user%3A42:2"
```

## Limits

- Derive the key from the business event, never from time or randomness: a retry must send the same key.
- Oveyon accepts 1–190 printable ASCII characters without spaces, as the Idempotency-Key header or the idempotencyKey body field. Encoding keeps every part inside that set.

The lab validates types and size before calling this function. Add equivalent validation at your own trust boundary.

## Source and license

Author: Oveyon, written for this edition; not part of the original 1loc collection.
Copyright (c) 2026 Oveyon
License: MIT — https://1loc.dev/licenses/
Maintainer: Oveyon
