mithaq
v1.0.0
Published
Official Node.js SDK for the Mithaq Partner API — generate, analyze, and lawyer-notarize Kuwaiti legal documents as an API.
Maintainers
Readme
mithaq — Node.js SDK
Official Node.js client for the Mithaq Partner API — generate, refine, analyze, and lawyer-notarize Kuwaiti legal documents from your own product, white-label.
Zero dependencies. Node 18+ (uses the global fetch/FormData/Blob and node:crypto). Ships with TypeScript types.
Install
npm install mithaqQuickstart
import { Mithaq } from 'mithaq';
const mithaq = new Mithaq(process.env.MITHAQ_KEY); // mthq_test_… for the free sandbox
// Generate a document and wait for it (the SDK handles the async job):
const doc = await mithaq.generateAndWait({
mode: 'template',
service: 'policies',
typeId: 'privacy_app',
fields: { businessName: 'متجر النخيل', businessDescription: 'متجر تمور إلكتروني' },
lang: 'ar',
});
console.log(doc.title);
console.log(doc.content); // markdownIn production, prefer webhooks over polling:
const { jobId } = await mithaq.generate({ mode: 'scratch', instructions: '…' }, 'order-1001');
// … receive the document_ready webhook, then:
const document = await mithaq.getDocument(documentId);Verifying webhooks
import express from 'express';
import { Mithaq } from 'mithaq';
const app = express();
app.use(express.raw({ type: 'application/json' })); // need the RAW body
app.post('/webhooks/mithaq', (req, res) => {
const raw = req.body.toString('utf8');
const ok = Mithaq.verifyWebhook(raw, req.headers['x-mithaq-signature'], process.env.MITHAQ_WEBHOOK_SECRET);
if (!ok) return res.sendStatus(400);
const event = JSON.parse(raw); // { id, type, createdAt, data }
res.sendStatus(200); // respond 2xx within 10s
});Notes
- Sandbox: keys prefixed
mthq_test_produce watermarked SPECIMEN output, never bill, and simulate notarization (SPECIMEN — no real lawyer or signature) — build the whole flow for free. - Idempotency: pass an idempotency key on any write; a retry replays the original response (no duplicate jobs/charges).
- Errors: non-2xx responses throw
MithaqErrorwith.status,.code, and the full.body. - Base URL: override with
new Mithaq(key, { baseUrl })for staging.
Full reference: https://www.trymithaq.net/developers · OpenAPI: https://www.trymithaq.net/openapi.yaml
License
MIT
