Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

usps-webhooks

БесплатноЗапускает вложенные скриптыНе проверен

Receive and verify USPS webhooks (Subscriptions - Tracking API v3.2). Use when setting up USPS tracking webhook handlers, debugging X-HMAC signature…

hookdeckот hookdeck★ 104 звезды на GitHub

Об этом скилле

USPS Webhooks

USPS delivers webhooks through the Subscriptions - Tracking API (v3.2). You create a subscription (POST /subscriptions) with a listenerURL, a 32-char secret, adminNotification emails and filterProperties (a Mailer ID or a tracking number, plus trackingEventTypes). USPS then POSTs a notification to your listener URL when there is new scan activity.

When to Use This Skill

  • How do I receive USPS tracking webhooks?
  • How do I verify the USPS X-HMAC webhook signature?
  • How do I create a USPS tracking subscription?
  • How do I handle USPS tracking scans and trackingEvents?
  • Why is my USPS webhook signature verification failing?

Verification (core)

USPS signs timestamp + payload — the notification envelope's timestamp field concatenated with the raw, stringified payload field — with HMAC-SHA256 keyed on your subscription secret, and sends the Base64 digest in the X-HMAC header (deprecated alias: hmac-header).

You must parse the envelope to read timestamp and payload, then compute the HMAC over their concatenation. Do not re-serialize the inner payload — sign the raw string exactly as received. Compare timing-safe.

The OAuth2 token (used to create subscriptions) is not sent on delivery. Per-message authenticity comes from the X-HMAC signature and/or IP allowlisting. If you set no secret and no IP allowlist, there is no per-message verification.

When USPS_WEBHOOK_SECRET is unset, a subscription created without a secret sends no X-HMAC header at all — there is nothing to verify. Do not pass the missing secret into createHmac / hmac.new; that throws and turns a configuration problem into an opaque 500. The examples here branch explicitly: they log a one-time warning that notifications are being processed with no per-message verification (and that IP allowlisting should be used instead), then process the delivery. Swap that branch for a rejection if your deployment cannot rely on an allowlist — see references/verification.md.

Node:

const crypto = require('crypto');

function verifyUspsSignature(timestamp, payload, hmacHeader, secret) {
  if (!hmacHeader || !secret) return false; // nothing to verify against
  const expected = crypto
    .createHmac('sha256', secret)
    .update(timestamp + payload) // payload = raw stringified JSON, unmodified
    .digest('base64');
  try {
    return crypto.timingSafeEqual(Buffer.from(hmacHeader), Buffer.from(expected));
  } catch {
    return false; // length mismatch = invalid
  }
}

Python:

import hmac, hashlib, base64

def verify_usps_signature(timestamp: str, payload: str, hmac_header: str, secret: str) -> bool:
    if not hmac_header or not secret:  # nothing to verify against
        return False
    expected = base64.b64encode(
        hmac.new(secret.encode(), (timestamp + payload).encode(), hashlib.sha256).digest()
    ).decode()
    return hmac.compare_digest(hmac_header, expected)

For complete handlers with route wiring, event dispatch, and tests, see:

Notification Envelope

USPS's Tracking Subscription Event example, with payload shortened here:

{
  "subscriptionId": "123456789",
  "subscriptionType": "TRACKING",
  "timestamp": "2024-12-27T19:05:42.747Z",
  "payload": "{\"trackingNumber\":\"12345678\",\"status\":\"Delivered, Front Door/Porch\",\"trackingEvents\":[{\"eventCode\":\"01\",\"eventType\":\"Delivered, Front Door/Porch\",\"GMTTimestamp\":\"2025-02-07T17:55:12Z\"}]}"
}

subscriptionId, subscriptionType, timestamp and payload are required; links is optional. payload is a stringified JSON: JSON.parse() it after verification. The HMAC is computed over timestamp + payload using the raw payload string (not the parsed object).

What Arrives

USPS has no event-name enum. subscriptionType names the topic, and both documented tracking examples carry TRACKING. Which updates arrive is set when you create the subscription, in filterProperties.trackingEventTypes:

Filter Sends
ALL_UPDATES (default) Every new tracking update, except package delays
DELIVERY_ACTIVITY Deliveries, delays, and actions needed (e.g. Schedule Redelivery or Pickup)
PACKAGE_DELAYED Package delays
SCAN_EVENT_EXTRACT (MID subscriptions only) Every update in the Detailed Scan format, which adds mailer, address and electronic file fields

The filter is not sent on the notification and can't be edited later, so if your code needs to know which shape it got, record each subscription's filter against its subscriptionId.

Inside a tracking payload:

  • status is free text such as Delivered, Front Door/Porch, so don't switch on exact status strings.
  • trackingEvents[] holds scans. `
Полный SKILL.md на GitHub

Установить usps-webhooks в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

examples/express/.env.exampleexamples/express/README.mdexamples/express/package.jsonexamples/express/src/index.jsexamples/fastapi/.env.exampleexamples/fastapi/README.mdexamples/fastapi/main.pyexamples/fastapi/requirements.txtexamples/fastapi/test_webhook.pyexamples/nextjs/.env.exampleexamples/nextjs/README.mdexamples/nextjs/app/webhooks/usps/route.tsexamples/nextjs/package.jsonexamples/nextjs/vitest.config.tsreferences/overview.mdreferences/setup.mdreferences/verification.md

FAQ

Что делает скилл usps-webhooks?

Receive and verify USPS webhooks (Subscriptions - Tracking API v3.2). Use when setting up USPS tracking webhook handlers, debugging X-HMAC signature verification, creating tracking subscriptions, or handling package tracking events, retries and subscription suspension.

Как установить скилл usps-webhooks?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл usps-webhooks запускает скрипты?

Да, скилл несёт исполняемые скрипты. Проверь исходник перед установкой.

Похожие скиллы

Сравнить usps-webhooks с