@indiegateway/node
v0.1.4
Published
IndieGateway Node SDK — HTTP client, webhook verify, entitlement helpers for non-custodial on-chain paywalls
Maintainers
Readme
@indiegateway/node
Merchant SDK for IndieGateway — HTTP client, webhook entry, pure entitlement helpers.
import { indieGateway, indieGatewayEnums } from '@indiegateway/node';
const { AccessDurationUnit, AccessType, NativeCryptoNetwork, ProjectWebhookEvent } =
indieGatewayEnums;
const gateway = indieGateway.createClient({
url: process.env.INDIEGATEWAY_URL!,
projectId: process.env.INDIEGATEWAY_PROJECT_ID!,
apiSecret: process.env.INDIEGATEWAY_API_SECRET!,
});
await gateway.startNativeCryptoCheckout({
external_user_id: 'user_123',
plan_key: 'pro',
network: NativeCryptoNetwork.Bsc,
access_type: AccessType.FixedTerm,
access_duration_value: 1,
access_duration_unit: AccessDurationUnit.Months,
});
// Webhook HTTP route: verify HMAC → parse → your handler
await indieGateway.handleIncomingWebhook(rawBody, signature, webhookSecret, {
[ProjectWebhookEvent.PaymentSucceeded]: async (event) => {
const parsed = indieGateway.helpers.parsePaymentSucceeded(event);
if (!parsed.ok) return;
const current = await db.getEntitlement(parsed.fields.externalUserId);
const next = indieGateway.helpers.applyPayment(current, {
checkoutId: parsed.fields.checkoutId,
planKey: parsed.fields.planKey,
accessEndsAt: parsed.fields.accessEndsAt,
occurredAt: parsed.fields.occurredAt,
sortOrder: /* your monotonic order */,
limits: /* from your plan cache */,
});
await db.saveEntitlement(parsed.fields.externalUserId, next);
},
});| | |
|--|--|
| createClient | HTTP: public-config, checkout, abandon, recover, … |
| handleIncomingWebhook | webhook route (verify + dispatch) |
| helpers.* | parse / apply / isActive / getActive — no DB |
| indieGatewayEnums / IndieGatewayTypes | enums / types |
Secrets stay in your server env. Low-level HMAC/dispatch helpers are not part of the public API.
