Skip to main content

afrikdp

Official Node.js client for the AfriKDP Publishing API — publishing infrastructure for Africa. Upload a book once, sell it everywhere, without building storage, checkout, or delivery yourself.

Requires Node.js 18+ (uses native fetch, FormData, and Blob — no dependencies).

Install

npm install afrikdp

Quick start

const AfriKDP = require('afrikdp');
// or: import AfriKDP from 'afrikdp';

const client = new AfriKDP({ secretKey: process.env.AFRIKDP_SECRET_KEY });

const book = await client.uploadBook({
  title: 'Ubuntu',
  description: 'A short reflection on community and shared humanity.',
  price: 2500, // whole currency units — 2500 = ₦2,500. 0 = free.
  currency: 'NGN',
  file: './ubuntu.pdf',
  cover: './cover.jpg',
});

console.log(book.book_id, book.slug);
// → bk_8937  ubuntu-8937a1c2

That's it — AfriKDP stores the file, generates the book's slug, and it's ready to sell.

Two kinds of keys

Key Used for Where it belongs
sk_live_... (secret) Uploading/updating books, webhooks, distribution Your server only
pk_live_... (public) Listing/fetching books, checkout, verify Safe in a browser, but this package is meant for your backend
// Full access
const client = new AfriKDP({ secretKey: 'sk_live_...' });

// Read-only — fine if this process should never be able to upload/edit
const client = new AfriKDP({ publicKey: 'pk_live_...' });

If you pass a secretKey, it's used for everything (including reads). Pass only a publicKey if you deliberately want a read-only client.

Uploading a book

const result = await client.uploadBook({
  title: 'Ubuntu',
  description: '...',
  price: 2500,
  currency: 'NGN',          // optional, defaults to NGN
  file: './ubuntu.pdf',     // a file path, or a Buffer
  cover: './cover.jpg',     // optional — a file path, or a Buffer
  visibility: 'public',     // 'public' | 'private' | 'unlisted'
  externalBookId: 'my-db-id-123', // optional — your own ID, for mapping back
});

Updating a book

Editing a book that already exists on AfriKDP — only send the fields that changed:

await client.updateBook('bk_8937', { price: 3000 });

// Replacing the file too:
await client.updateBook('bk_8937', {
  price: 3000,
  file: './ubuntu-v2.pdf',
});

Listing and fetching books

const books = await client.listBooks();
const one = await client.getBook('bk_8937');

Author sub-accounts (enterprise)

If you're a platform with your own authors — Afara has its authors, a school has its teachers — each one can get their own AfriKDP wallet. A book uploaded under an author's authorId pays that author directly; the sale never touches your organization's own wallet.

// Create the author once (do this when the real author signs up on your platform)
const { author } = await client.createAuthor({ name: 'Florence Cook', email: 'florence@example.com' });

// Any book uploaded with this authorId pays Florence directly
await client.uploadBook({
  title: 'Embracing Sankofa',
  description: '...',
  price: 2500,
  file: './sankofa.pdf',
  authorId: author.id,
});

// Florence's own earnings
const wallet = await client.getAuthorWallet(author.id);
console.log(wallet.balance);

// Florence requests a payout
await client.requestAuthorWithdrawal(author.id, {
  amount: 2000,
  bankName: 'GTBank',
  accountNumber: '0123456789',
  accountName: 'Florence Cook',
});

Don't pass authorId at all if you're a solo creator — every sale keeps crediting your organization's own wallet exactly as before. Nothing changes for that case.

Checkout (server-side)

Most integrations should use the browser SDK for checkout — it opens a branded modal and handles Paystack's inline popup for you. Use this only if you're building your own checkout UI:

const order = await client.checkout({
  bookId: 'bk_8937',
  buyerEmail: 'reader@example.com',
  buyerCountry: 'NG', // optional
});

if (order.free) {
  // order.order_id is already paid — go straight to getDownloadLink()
} else {
  // order.reference, order.amount, order.paystack_public_key
  // → hand these to Paystack's inline.js in the browser
}

After the buyer pays:

const result = await client.verifyPayment(order.reference);
if (result.status === 'paid') {
  const { download_url } = await client.getDownloadLink(result.order_id);
  // download_url is valid for 2 minutes
}

Distribution

const marketplace = await client.createMarketplace({
  marketplaceName: "Sarah's Bookstore",
  domain: 'books.sarah.com',
  visibility: 'private',
});

await client.pushDistribution({
  bookId: 'bk_8937',
  marketplaceIds: [marketplace.marketplace.id],
});

Webhooks

const hook = await client.registerWebhook({
  url: 'https://yoursite.com/hooks/afrikdp',
  events: ['book.created', 'sale.completed'],
});
console.log(hook.secret); // shown once — store it now

Verifying an incoming webhook (use the raw request body, not a re-parsed object):

const AfriKDP = require('afrikdp');

app.post('/hooks/afrikdp', express.raw({ type: 'application/json' }), (req, res) => {
  const signature = req.headers['x-afrikdp-signature'];
  const valid = AfriKDP.verifyWebhookSignature(req.body, signature, process.env.AFRIKDP_WEBHOOK_SECRET);
  if (!valid) return res.status(401).send('Invalid signature');

  const event = JSON.parse(req.body);
  // handle event.event, event.data
  res.sendStatus(200);
});

Error handling

Every method throws AfriKDPError on a non-2xx response:

const { AfriKDPError } = require('afrikdp');

try {
  await client.uploadBook({ /* ... */ });
} catch (err) {
  if (err instanceof AfriKDPError) {
    console.error(err.status, err.message, err.body);
  }
}

TypeScript

Type definitions are included — no @types package needed.

Configuration

new AfriKDP({
  secretKey: 'sk_live_...',
  apiBase: 'https://api-afrikdp.onrender.com/v1', // optional override
});

License

MIT

Metadata

Release files for afrikdp 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for afrikdp 1.1.0
File Size Uploaded Provenance Actions
afrikdp-1.1.0.tar.gz 10.4 kB Without provenance Details for afrikdp-1.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for afrikdp 1.1.0
File Interpreter ABI Platform Actions
afrikdp-1.1.0-py3-none-any.whl Python 3 none any Details for afrikdp-1.1.0-py3-none-any.whl

Total release size: 19.3 kB

Release files / afrikdp-1.1.0.tar.gz

Download URL afrikdp-1.1.0.tar.gz
Size 10.4 kB
Tags Source
SHA-256 checksum
How to use checksums
769490a5b0cff20b0ff330c1f54f97f7b249320a2c4d40aeaeba08d9d5bfee25
BLAKE2b-256 checksum
How to use checksums
3051b2f803a4e3589687f7d2eabd78b04f60903376a5043a31ac08ecdd569c88
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.0

Release files / afrikdp-1.1.0-py3-none-any.whl

Download URL afrikdp-1.1.0-py3-none-any.whl
Size 8.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
33457321743ace833a7ae4ddebe440192c258996780292d0687887e56d6f4c7a
BLAKE2b-256 checksum
How to use checksums
de1f30d81ddca76ae5dde98f96d5b18f7877484e54b450d633a77083424b5d5f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.0

Security for afrikdp 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page